
###Sets###
set T ;
set K ;
set M ;
set N ;
set I ;
set I_A within I ;
set I_B within I ;
set J ;
set S ;
set H ;
set Q ;


###Parameters###
param cost_A {I} >= 0 ;
param cost_B {J} >= 0 ;
param cost_C {K} >= 0 ;
param C {Q} >= 0 ;
param cap {J} >= 0 ;
param E {H,S} >= 0 ;
param A {K,S} >= 0 ;
param D {S} >= 0 ;
param Demand {N} >= 0 ;


###VARIABLES###
var X {T,I} >= 0 ;
var B {T,I} >= 0 binary ;
var Z {K} >= 0 ;
var Y {T,K} >= 0 ;
var U {K,S} >= 0 ;
var W {K,J} >= 0 ;
var V {K} >= 0 ;
var G {K} >= 0 ;
var ZU {K} >= 0 ;
var DD {M,N} >= 0 integer ;
var PU {M,S} >= 0 ;
var SF {N,S} >= 0 ;
var F {N} >= 0 ;



###OBJECTIVE FUNCTION###
minimize total_cost:
  sum{i in I}(sum{t in T} cost_A[i] * B[t,i])
+ sum{i in I}(sum{t in T} 3 * X[t,i])
+ sum{k in K} 5 * Z[k]
+ sum{j in J}(sum{k in K} cost_B[j] * W[k,j])
+ sum{k in K} 15 * V[k]
+ cost_C[1] * G[1]
+ cost_C[2] * G[2] 
+ cost_C[3] * G[3] 
+ cost_C[4] * G[4] 
+ cost_C[5] * G[5] 
+ cost_C[6] * G[6] 
+ cost_C[7] * G[7] 
+ cost_C[8] * G[8] 


+ C[0] * DD[1,1]		
+ C[1] * DD[1,2]			+ C[1] * DD[2,2]		
+ C[2] * DD[1,3]			+ C[2] * DD[2,3]			+ C[0] * DD[3,3]		
+ C[3] * DD[1,4]			+ C[3] * DD[2,4]			+ C[1] * DD[3,4]		+ C[0] * DD[4,4]	
+ C[4] * DD[1,5]			+ C[4] * DD[2,5]			+ C[2] * DD[3,5]		+ C[1] * DD[4,5]	
+ C[5] * DD[1,6]			+ C[5] * DD[2,6]			+ C[3] * DD[3,6]		+ C[2] * DD[4,6]	
+ C[6] * DD[1,7]			+ C[6] * DD[2,7]			+ C[4] * DD[3,7]		+ C[3] * DD[4,7]	
+ C[7] * DD[1,8]			+ C[7] * DD[2,8]			+ C[5] * DD[3,8]		+ C[4] * DD[4,8]	
+ C[8] * DD[1,9]			+ C[8] * DD[2,9]			+ C[6] * DD[3,9]		+ C[5] * DD[4,9]	
+ C[9] * DD[1,10]			+ C[9] * DD[2,10]			+ C[7] * DD[3,10]		+ C[6] * DD[4,10]		
+ C[10] * DD[1,11]			+ C[10] * DD[2,11]			+ C[8] * DD[3,11]		+ C[7] * DD[4,11]
+ C[11] * DD[1,12]			+ C[11] * DD[2,12]			+ C[9] * DD[3,12]		+ C[8] * DD[4,12]
	   
	   
+ C[0] * DD[5,5]
+ C[1] * DD[5,6]			+ C[0] * DD[6,6]	
+ C[2] * DD[5,7]			+ C[1] * DD[6,7]			+ C[0] * DD[7,7]		
+ C[3] * DD[5,8] 			+ C[2] * DD[6,8]			+ C[1] * DD[7,8]		+ C[0] * DD[8,8]
+ C[4] * DD[5,9]			+ C[3] * DD[6,9]			+ C[2] * DD[7,9]		+ C[1] * DD[8,9]
+ C[5] * DD[5,10]			+ C[4] * DD[6,10]			+ C[3] * DD[7,10]		+ C[2] * DD[8,10]
+ C[6] * DD[5,11]			+ C[5] * DD[6,11]			+ C[4] * DD[7,11]		+ C[3] * DD[8,11]	
+ C[7] * DD[5,12] 			+ C[6] * DD[6,12]			+ C[5] * DD[7,12]		+ C[4] * DD[8,12] ;


###Constrains###
subject to constrian1 {i in I_A}: sum{ t in T } B[t,i] = 1 ;
subject to constrian2 {i in I_B}: sum{ t in T } B[t,i] <= 1 ;
subject to constrian3 {i in I, t in T}: X[t,i] <= 300 * B[t,i] ;

subject to constrian4 {k in K}: Z[k] = sum{t in T :t >= 1 and t <= k} Y[t,k] ;
subject to constrian5 {t in T}: sum{k in K :k >= t and k <= 8} Y[t,k] = (sum{i in I} X[t,i]) * 10 ;


################################ k=1 ###############################

subject to constrian7_1_1 {t in T , k in K , h in H , s in S , j in J}: 
U[1,1] = 0.9*(Y[1,1]*E[0,1]) + 0.8*(W[1,1]*A[1,1]) + 0.7*(V[1]*A[1,1]) + 0.8*G[1]*D[1] 
		          + 0.8*(W[1,2]*A[1,1]) ;     
     
subject to constrian7_1_2 {t in T , k in K , h in H , s in S , j in J}: 
U[1,2] = 0.9*(Y[1,1]*E[0,2]) + 0.8*(W[1,1]*A[1,2]) + 0.7*(V[1]*A[1,2]) + 0.8*G[1]*D[2] 
		          + 0.8*(W[1,2]*A[1,2]) ;           

subject to constrian7_1_3 {t in T , k in K , h in H , s in S , j in J}: 
U[1,3] = 0.9*(Y[1,1]*E[0,3]) + 0.8*(W[1,1]*A[1,3]) + 0.7*(V[1]*A[1,3]) + 0.8*G[1]*D[3] 
		            + 0.8*(W[1,2]*A[1,3]) ;           

################################ k=2 ###############################

subject to constrian7_2_1 {t in T , k in K , h in H , s in S , j in J}: 
U[2,1] = 0.9*(Y[1,2]*E[1,1]) + 0.8*(W[2,1]*A[2,1]) + 0.7*(V[2]*A[2,1]) + 0.8*G[2]*D[1] 
         + 0.9*(Y[2,2]*E[0,1]) + 0.8*(W[2,2]*A[2,1]) ;  

subject to constrian7_2_2 {t in T , k in K , h in H , s in S , j in J}: 
U[2,2] = 0.9*(Y[1,2]*E[1,2]) + 0.8*(W[2,1]*A[2,2]) + 0.7*(V[2]*A[2,2]) + 0.8*G[2]*D[2] 
         + 0.9*(Y[2,2]*E[0,2]) + 0.8*(W[2,2]*A[2,2]) ;  

subject to constrian7_2_3 {t in T , k in K , h in H , s in S , j in J}: 
U[2,3] = 0.9*(Y[1,2]*E[1,3]) + 0.8*(W[2,1]*A[2,3]) + 0.7*(V[2]*A[2,3]) + 0.8*G[2]*D[3] 
         + 0.9*(Y[2,2]*E[0,3]) + 0.8*(W[2,2]*A[2,3]) ;  

################################ k=3 ###############################

subject to constrian7_3_1 {t in T , k in K , h in H , s in S , j in J}: 
U[3,1] = 0.9*(Y[1,3]*E[2,1]) + 0.8*(W[3,1]*A[3,1]) + 0.7*(V[3]*A[3,1]) + 0.8*G[3]*D[1] 
         + 0.9*(Y[2,3]*E[1,1]) + 0.8*(W[3,2]*A[3,1])
         + 0.9*(Y[3,3]*E[0,1]) ;

subject to constrian7_3_2 {t in T , k in K , h in H , s in S , j in J}: 
U[3,2] = 0.9*(Y[1,3]*E[2,2]) + 0.8*(W[3,1]*A[3,2]) + 0.7*(V[3]*A[3,2]) + 0.8*G[3]*D[2] 
         + 0.9*(Y[2,3]*E[1,2]) + 0.8*(W[3,2]*A[3,2])
         + 0.9*(Y[3,3]*E[0,2]) ;

subject to constrian7_3_3 {t in T , k in K , h in H , s in S , j in J}: 
U[3,3] = 0.9*(Y[1,3]*E[2,3]) + 0.8*(W[3,1]*A[3,3]) + 0.7*(V[3]*A[3,3]) + 0.8*G[3]*D[3] 
         + 0.9*(Y[2,3]*E[1,3]) + 0.8*(W[3,2]*A[3,3])
         + 0.9*(Y[3,3]*E[0,3]) ;

################################ k=4 ###############################

subject to constrian7_4_1 {t in T , k in K , h in H , s in S , j in J}: 
U[4,1] = 0.9*(Y[1,4]*E[3,1]) + 0.8*(W[4,1]*A[4,1]) + 0.7*(V[4]*A[4,1]) + 0.8*G[4]*D[1]
         + 0.9*(Y[2,4]*E[2,1]) + 0.8*(W[4,2]*A[4,1])
         + 0.9*(Y[3,4]*E[1,1])
         + 0.9*(Y[4,4]*E[0,1]) ;

subject to constrian7_4_2 {t in T , k in K , h in H , s in S , j in J}: 
U[4,2] = 0.9*(Y[1,4]*E[3,2]) + 0.8*(W[4,1]*A[4,2]) + 0.7*(V[4]*A[4,2]) + 0.8*G[4]*D[2]
         + 0.9*(Y[2,4]*E[2,2]) + 0.8*(W[4,2]*A[4,2])
         + 0.9*(Y[3,4]*E[1,2])
         + 0.9*(Y[4,4]*E[0,2]) ;

subject to constrian7_4_3 {t in T , k in K , h in H , s in S , j in J}: 
U[4,3] = 0.9*(Y[1,4]*E[3,3]) + 0.8*(W[4,1]*A[4,3]) + 0.7*(V[4]*A[4,3]) + 0.8*G[4]*D[3]
         + 0.9*(Y[2,4]*E[2,3]) + 0.8*(W[4,2]*A[4,3])
         + 0.9*(Y[3,4]*E[1,3])
         + 0.9*(Y[4,4]*E[0,3]) ;

################################ k=5 ###############################

subject to constrian7_5_1 {t in T , k in K , h in H , s in S , j in J}: 
U[5,1] = 0.9*(Y[1,5]*E[4,1]) + 0.8*(W[5,1]*A[5,1]) + 0.7*(V[5]*A[5,1]) + 0.8*G[5]*D[1]
         + 0.9*(Y[2,5]*E[3,1]) + 0.8*(W[5,2]*A[5,1])
         + 0.9*(Y[3,5]*E[2,1])         
         + 0.9*(Y[4,5]*E[1,1])
         + 0.9*(Y[5,5]*E[0,1]) ;

subject to constrian7_5_2 {t in T , k in K , h in H , s in S , j in J}: 
U[5,2] = 0.9*(Y[1,5]*E[4,2]) + 0.8*(W[5,1]*A[5,2]) + 0.7*(V[5]*A[5,2]) + 0.8*G[5]*D[2]
         + 0.9*(Y[2,5]*E[3,2]) + 0.8*(W[5,2]*A[5,2])
         + 0.9*(Y[3,5]*E[2,2])         
         + 0.9*(Y[4,5]*E[1,2])
         + 0.9*(Y[5,5]*E[0,2]) ;

subject to constrian7_5_3 {t in T , k in K , h in H , s in S , j in J}: 
U[5,3] = 0.9*(Y[1,5]*E[4,3]) + 0.8*(W[5,1]*A[5,3]) + 0.7*(V[5]*A[5,3]) + 0.8*G[5]*D[3]
         + 0.9*(Y[2,5]*E[3,3]) + 0.8*(W[5,2]*A[5,3])
         + 0.9*(Y[3,5]*E[2,3])         
         + 0.9*(Y[4,5]*E[1,3])
         + 0.9*(Y[5,5]*E[0,3]) ;

################################ k=6 ###############################

subject to constrian7_6_1 {t in T , k in K , h in H , s in S , j in J}: 
U[6,1] = 0.9*(Y[1,6]*E[5,1]) + 0.8*(W[6,1]*A[6,1]) + 0.7*(V[6]*A[6,1]) + 0.8*G[6]*D[1]
         + 0.9*(Y[2,6]*E[4,1]) + 0.8*(W[6,2]*A[6,1])
         + 0.9*(Y[3,6]*E[3,1])         
         + 0.9*(Y[4,6]*E[2,1])
         + 0.9*(Y[5,6]*E[1,1])
         + 0.9*(Y[6,6]*E[0,1]) ;

subject to constrian7_6_2 {t in T , k in K , h in H , s in S , j in J}: 
U[6,2] = 0.9*(Y[1,6]*E[5,2]) + 0.8*(W[6,1]*A[6,2]) + 0.7*(V[6]*A[6,2]) + 0.8*G[6]*D[2]
         + 0.9*(Y[2,6]*E[4,2]) + 0.8*(W[6,2]*A[6,2])
         + 0.9*(Y[3,6]*E[3,2])         
         + 0.9*(Y[4,6]*E[2,2])
         + 0.9*(Y[5,6]*E[1,2])
         + 0.9*(Y[6,6]*E[0,2]) ;

subject to constrian7_6_3 {t in T , k in K , h in H , s in S , j in J}: 
U[6,3] = 0.9*(Y[1,6]*E[5,3]) + 0.8*(W[6,1]*A[6,3]) + 0.7*(V[6]*A[6,3]) + 0.8*G[6]*D[3]
         + 0.9*(Y[2,6]*E[4,3]) + 0.8*(W[6,2]*A[6,3])
         + 0.9*(Y[3,6]*E[3,3])         
         + 0.9*(Y[4,6]*E[2,3])
         + 0.9*(Y[5,6]*E[1,3])
         + 0.9*(Y[6,6]*E[0,3]) ;

################################ k=7 ###############################

subject to constrian7_7_1 {t in T , k in K , h in H , s in S , j in J}: 
U[7,1] = 0.9*(Y[1,7]*E[6,1]) + 0.8*(W[7,1]*A[7,1]) + 0.7*(V[7]*A[7,1]) + 0.8*G[7]*D[1]
         + 0.9*(Y[2,7]*E[5,1]) + 0.8*(W[7,2]*A[7,1])
         + 0.9*(Y[3,7]*E[4,1])         
         + 0.9*(Y[4,7]*E[3,1])
         + 0.9*(Y[5,7]*E[2,1])
         + 0.9*(Y[6,7]*E[1,1])
         + 0.9*(Y[7,7]*E[0,1]) ;

subject to constrian7_7_2 {t in T , k in K , h in H , s in S , j in J}: 
U[7,2] = 0.9*(Y[1,7]*E[6,2]) + 0.8*(W[7,1]*A[7,2]) + 0.7*(V[7]*A[7,2]) + 0.8*G[7]*D[2]
         + 0.9*(Y[2,7]*E[5,2]) + 0.8*(W[7,2]*A[7,2])
         + 0.9*(Y[3,7]*E[4,2])         
         + 0.9*(Y[4,7]*E[3,2])
         + 0.9*(Y[5,7]*E[2,2])
         + 0.9*(Y[6,7]*E[1,2])
         + 0.9*(Y[7,7]*E[0,2]) ;

subject to constrian7_7_3 {t in T , k in K , h in H , s in S , j in J}: 
U[7,3] = 0.9*(Y[1,7]*E[6,3]) + 0.8*(W[7,1]*A[7,3]) + 0.7*(V[7]*A[7,3]) + 0.8*G[7]*D[3]
         + 0.9*(Y[2,7]*E[5,3]) + 0.8*(W[7,2]*A[7,3])
         + 0.9*(Y[3,7]*E[4,3])         
         + 0.9*(Y[4,7]*E[3,3])
         + 0.9*(Y[5,7]*E[2,3])
         + 0.9*(Y[6,7]*E[1,3])
         + 0.9*(Y[7,7]*E[0,3]) ;

################################ k=8 ###############################

subject to constrian7_8_1 {t in T , k in K , h in H , s in S , j in J}: 
U[8,1] = 0.9*(Y[1,8]*E[7,1]) + 0.8*(W[8,1]*A[8,1]) + 0.7*(V[8]*A[8,1]) + 0.8*G[8]*D[1]
       + 0.9*(Y[2,8]*E[6,1]) + 0.8*(W[8,2]*A[8,1])
       + 0.9*(Y[3,8]*E[5,1])         
       + 0.9*(Y[4,8]*E[4,1])
       + 0.9*(Y[5,8]*E[3,1])
       + 0.9*(Y[6,8]*E[2,1])
       + 0.9*(Y[7,8]*E[1,1])
       + 0.9*(Y[8,8]*E[0,1]) ;

subject to constrian7_8_2 {t in T , k in K , h in H , s in S , j in J}: 
U[8,2] = 0.9*(Y[1,8]*E[7,2]) + 0.8*(W[8,1]*A[8,2]) + 0.7*(V[8]*A[8,2]) + 0.8*G[8]*D[2]
       + 0.9*(Y[2,8]*E[6,2]) + 0.8*(W[8,2]*A[8,2])
       + 0.9*(Y[3,8]*E[5,2])         
       + 0.9*(Y[4,8]*E[4,2])
       + 0.9*(Y[5,8]*E[3,2])
       + 0.9*(Y[6,8]*E[2,2])
       + 0.9*(Y[7,8]*E[1,2])
       + 0.9*(Y[8,8]*E[0,2]) ;

subject to constrian7_8_3 {t in T , k in K , h in H , s in S , j in J}: 
U[8,3] = 0.9*(Y[1,8]*E[7,3]) + 0.8*(W[8,1]*A[8,3]) + 0.7*(V[8]*A[8,3]) + 0.8*G[8]*D[3]
       + 0.9*(Y[2,8]*E[6,3]) + 0.8*(W[8,2]*A[8,3])
       + 0.9*(Y[3,8]*E[5,3])         
       + 0.9*(Y[4,8]*E[4,3])
       + 0.9*(Y[5,8]*E[3,3])
       + 0.9*(Y[6,8]*E[2,3])
       + 0.9*(Y[7,8]*E[1,3])
       + 0.9*(Y[8,8]*E[0,3]) ;
	   

subject to constrian8 {j in J}: sum{k in K} W[k,j] <= cap[j] ;
subject to constrian9 {k in K}: V[k] <= 2000 ;
subject to constrian10 {k in K}: G[k] <= 1000 ;
subject to constrian6 {k in K}: ZU[k] = sum{s in S} U[k,s] ;




subject to constrian11 {m in M, k in K :m=k}: ZU[k]/30000 = sum{n in N :n = m and n <= 12} DD[m,n] ;

subject to constrian12 {s in S, n in N :n<=8}: SF[n,s] = (sum{m in M :m = 1 and m <= n} DD[m,n] * PU[m,s]) * 30000 ;
subject to constrian13 {s in S, n in N :n>=9}: SF[n,s] = (sum{m in M :m = 1 and m <= 12} DD[m,n] * PU[m,s]) * 30000 ;

subject to constrian14 {s in S, k in K, m in M :k=m}: PU[m,s] = U[k,s]/ZU[k] ;
subject to constrian15 {n in N}: F[n] = sum{s in S} SF[n,s] ;

subject to constrian16 {n in N}: F[n] = Demand[n] ;














