##################################
#
# This is the AMPL [1] formulation of the extended ILP given in Table 2
# adapted for the comparison with Vider-Shalit et al. [2].
# 
# [1] Fourer R, Gay DM, Kernighan BW (1990) A Modelling Language for Mathematical Programming.
#     Management Science 36:519-554.
# [2] Vider-Shalit T, Raffaeli S, Louzoun Y (2007) Virus-epitope vaccine design: informatic
#     matching the HLA-I polymorphism to the virus genome. Mol Immunol 44:1253-1261.
#
##################################

##################################
#
# SETS
#
##################################

# Observed MHC alleles
set A; 

# Target antigens
set Q;

# Candidate epitopes per antigen
set E_antigen {q in Q}; 

# All candidate epitopes
set E := setof {q in Q, e in E_antigen[q]} e;

# Pairs of overlapping epitopes
set O within {E,E}; 


##################################
#
# PARAMETERS
#
##################################

# Epitope conservation
param c {E}; 		

# Immunogenicity of an epitope with respect to an allele
param i {E, A}; 

# Number of epitopes to select
param k;				

# Probability of an MHC allele occuring in the target population
param p {A};		

# Antigen processing:
#	The formulation corresponding to the extended ILP given in the manuscript would be:
#
#	param p_AP {E}; # probability that an epitope will be produced during antigen processing
#
# Since we are given scores instead of probabilities, we use the following formulation	:
#
# Antigen processing score assigned to an epitope by the proteasomal cleavage matrix given 
# in the supplement of Vider-Shalit et al.
param s_AP {E};	

# Minimum number of epitopes from each antigen to be included
param t_A; 

# Antigen processing threshold 
param t_AP;

# Conservation threshold 
param t_C; 

# Minimum number of MHC alleles to be covered
param t_MHC; 

# Immunogenicity threshold
# The formulation corresponding to the extended ILP given in the manuscript would be:
#
# param t_I; 
#
# Since Vider-Shalit et al. use a specific immunogenicity threshold for each allele
# we use the following formulation:
param t_I { a in A }; 

##################################
#
# MORE SETS
#
##################################

# Set of epitopes, which when bound to an MHC allele a,
# display an immunogenicity greater than or equal to a given
# threshold t_I[a]
set I_allele { a in A } := { e in E: i[e,a] >= t_I[a] }; 

# Set of all sufficiently immunogenic epitopes
set I := setof {a in A, e in I_allele[a]} e;

##################################
#
# VARIABLES
#
##################################

# x[e] = 1 if epitope e belongs to the optimal set, otherwise x[e] = 0
var x {E} binary;

# y[a] = 1 if allele a is covered by the optimal set, otherwise y[a] = 0
var y {A} binary;

##################################
#
# OBJECTIVE
#
##################################

maximize Overall_Immunogenicity: 
	sum {e in E} x[e] * sum {a in A} p[a] * i[e,a];

##################################
#
# CONSTRAINTS
#
##################################

subject to Number_Of_Epitopes: 
	sum {e in E} x[e] = k;
	
subject to Epitope_Conservation_Threshold {e in E}:
	( 1 - c[e] ) * x[e] <= 1 - t_C;

subject to No_Epitope_Overlap { (e,r) in O }: 
	x[e] + x[r] <= 1;  

subject to Is_Allele_Covered {a in A}:
	sum {e in I_allele[a]} x[e] >= y[a];
	
subject to Allele_Coverage:
	sum {a in A} y[a] >= t_MHC;

subject to Antigen_Coverage {q in Q}:
	sum {e in (E_antigen[q] inter I) } x[e] >= t_A; 

subject to Antigen_Processing_Threshold {e in E}:
#
# The formulation corresponding to the extended ILP given in the manuscript would be:
#( 1 - p_AP[e] ) * x[e] <= ( 1 - t_AP );
#
# Since we are given scores from a proteasomal cleavage prediction method instead of
# probabilities, we use the following formulation:
#
# Select only epitopes with a proteasomal cleavage score greater or equal to t_AP
		s_AP[e] * x[e] >= t_AP * x[e];


end;