model:
sets:
zay/1..30/:d,w,f,M,l,o;
weather/1..3/:index_j;
desction/1,2/:x;
plac_x/1..27/:lx;
plac_y/1..27/:ly,a;
link(zay,weather):wr,Q,E,g;
link2(plac_x,plac_y):t;
endsets
data:
Q=0,1,0
0,1,0
1,0,0
0,0,1
1,0,0
0,1,0
0,0,1
1,0,0
0,1,0
0,1,0
0,0,1
0,1,0
1,0,0
0,1,0
0,1,0
0,1,0
0,0,1
0,0,1
0,1,0
0,1,0
1,0,0
1,0,0
0,1,0
1,0,0
0,0,1
0,1,0
1,0,0
1,0,0
0,1,0
0,1,0;
flag=0;
enddata
max=100000*flag+M(30);
@for(plac_y(u):a(u)=u);
@for(link2(u,n):@bin(t(u,n)));
@for(link(i,j):@bin(E(i,j)););
@for(zay(i):E(i,3)=0);
@for(zay(i):@sum(weather(j):E(i,j))=1);
@for(plac_x(u):@sum(plac_y(n):t(u,n))=1);
t(1,2)+t(1,25)>=1;
t(2,1)+t(2,3)>=1;
t(3,2)+t(3,25)+t(3,4)>=1;
t(4,3)+t(4,25)+t(4,24)+t(4,5)>=1;
t(5,4)+t(5,24)+t(5,6)>=1;
t(6,5)+t(6,24)+t(6,23)+t(6,7)>=1;
t(7,6)+t(7,22)+t(7,8)>=1;
t(8,7)+t(8,9)+t(8,22)>=1;
t(9,8)+t(9,21)+t(9,17)+t(9,16)+t(9,15)+t(9,10)+t(9,22)>=1;
t(10,9)+t(10,15)+t(10,13)+t(10,11)>=1;
t(11,10)+t(11,13)+t(11,14)>=1;
t(12,11)+t(12,13)+t(12,14)>=1;
t(13,11)+t(13,10)+t(13,15)+t(13,14)+t(13,12)>=1;
t(14,13)+t(14,15)+t(14,16)+t(14,12)>=1;
t(15,10)+t(15,9)+t(15,16)+t(15,13)+t(15,14)>=1;
t(16,15)+t(16,14)+t(16,9)+t(16,17)+t(16,18)>=1;
t(17,9)+t(17,16)+t(17,18)+t(17,21)>=1;
t(18,16)+t(18,17)+t(18,19)+t(18,20)>=1;
t(19,18)+t(19,20)>=1;
t(20,21)+t(20,18)+t(20,19)>=1;
t(21,23)+t(21,22)+t(21,9)+t(21,17)+t(21,20)+t(21,27)>=1;
t(22,23)+t(22,7)+t(22,8)+t(22,9)+t(22,17)+t(22,20)+t(22,21)>=1;
t(23,24)+t(23,6)+t(23,22)+t(23,21)+t(23,26)>=1;
t(24,25)+t(24,4)+t(24,5)+t(24,6)+t(24,23)+t(24,26)>=1;
t(25,1)+t(25,3)+t(25,4)+t(25,24)+t(25,26)>=1;
t(26,25)+t(26,24)+t(26,23)+t(26,27)>=1;
t(27,27)=1;
3*W0+2*f0<=1200;
@for(link(i,j):@gin(g(i,j)););
@bin(flag);
@gin(W0);
@gin(f0);
@BIN(E0);
@BIN(E1);
E1+E0=1;
M0=10000-5*W0-10*f0;
@for(zay(i):flag=@if(d(i)#eq#27,1,0);
@for(weather(j):g(i,j)=@if(d(i)#eq#15,g(i,j),0));
E(i,2)=@if(Q(i,3)#eq#1,1,1-E(i,1));
l(i)=@sum(plac_x(k):a(k)*t(1,k));
o(i)=@if(i#eq#1,0,1*t(d(i-1),1)+2*t(d(i-1),2)+3*t(d(i-1),3)+4*t(d(i-1),4)+5*t(d(i-1),5)+6*t(d(i-1),6)+7*t(d(i-1),7)+8*t(d(i-1),8)+9*t(d(i-1),9)+10*t(d(i-1),10)+11*t(d(i-1),11)+12*t(d(i-1),12)+13*t(d(i-1),13)+14*t(d(i-1),17)+15*t(d(i-1),15)+16*t(d(i-1),16)+17*t(d(i-1),17)+18*t(d(i-1),18)+19*t(d(i-1),19)+20*t(d(i-1),20)+21*t(d(i-1),21)+22*t(d(i-1),22)+23*t(d(i-1),23)+24*t(d(i-1),24)+25*t(d(i-1),25)+26*t(d(i-1),26)+27*t(d(i-1),27));
d(i)=@if(i#eq#1,E(i,1)*(l(i))+E(i,2)*1,(o(i)*E(i,1)+E(i,2)*d(i-1)));
M(i)=@if(i#eq#1,(10000-5*W0-10*f0),@if(d(i)#eq#27,M(i-1)+W(i-1)*2.5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30/:d,w,f,M,l,o;
weather/1..3/:index_j;
desction/1,2/:x;
plac_x/1..27/:lx;
plac_y/1..27/:ly,a;
link(zay,weather):wr,Q,E,g;
link2(plac_x,plac_y):t;
endsets
data:
Q=0,1,0
0,1,0
1,0,0
0,0,1
1,0,0
0,1,0
0,0,1
1,0,0
0,1,0
0,1,0
0,0,1
0,1,0
1,0,0
0,1,0
0,1,0
0,1,0
0,0,1
0,0,1
0,1,0
0,1,0
1,0,0
1,0,0
0,1,0
1,0,0
0,0,1
0,1,0
1,0,0
1,0,0
0,1,0
0,1,0;
flag=0;
enddata
max=100000*flag+M(30);
@for(plac_y(u):a(u)=u);
@for(link2(u,n):@bin(t(u,n)));
@for(link(i,j):@bin(E(i,j)););
@for(zay(i):E(i,3)=0);
@for(zay(i):@sum(weather(j):E(i,j))=1);
@for(plac_x(u):@sum(plac_y(n):t(u,n))=1);
t(1,2)+t(1,25)>=1;
t(2,1)+t(2,3)>=1;
t(3,2)+t(3,25)+t(3,4)>=1;
t(4,3)+t(4,25)+t(4,24)+t(4,5)>=1;
t(5,4)+t(5,24)+t(5,6)>=1;
t(6,5)+t(6,24)+t(6,23)+t(6,7)>=1;
t(7,6)+t(7,22)+t(7,8)>=1;
t(8,7)+t(8,9)+t(8,22)>=1;
t(9,8)+t(9,21)+t(9,17)+t(9,16)+t(9,15)+t(9,10)+t(9,22)>=1;
t(10,9)+t(10,15)+t(10,13)+t(10,11)>=1;
t(11,10)+t(11,13)+t(11,14)>=1;
t(12,11)+t(12,13)+t(12,14)>=1;
t(13,11)+t(13,10)+t(13,15)+t(13,14)+t(13,12)>=1;
t(14,13)+t(14,15)+t(14,16)+t(14,12)>=1;
t(15,10)+t(15,9)+t(15,16)+t(15,13)+t(15,14)>=1;
t(16,15)+t(16,14)+t(16,9)+t(16,17)+t(16,18)>=1;
t(17,9)+t(17,16)+t(17,18)+t(17,21)>=1;
t(18,16)+t(18,17)+t(18,19)+t(18,20)>=1;
t(19,18)+t(19,20)>=1;
t(20,21)+t(20,18)+t(20,19)>=1;
t(21,23)+t(21,22)+t(21,9)+t(21,17)+t(21,20)+t(21,27)>=1;
t(22,23)+t(22,7)+t(22,8)+t(22,9)+t(22,17)+t(22,20)+t(22,21)>=1;
t(23,24)+t(23,6)+t(23,22)+t(23,21)+t(23,26)>=1;
t(24,25)+t(24,4)+t(24,5)+t(24,6)+t(24,23)+t(24,26)>=1;
t(25,1)+t(25,3)+t(25,4)+t(25,24)+t(25,26)>=1;
t(26,25)+t(26,24)+t(26,23)+t(26,27)>=1;
t(27,27)=1;
3*W0+2*f0<=1200;
@for(link(i,j):@gin(g(i,j)););
@bin(flag);
@gin(W0);
@gin(f0);
@BIN(E0);
@BIN(E1);
E1+E0=1;
M0=10000-5*W0-10*f0;
@for(zay(i):flag=@if(d(i)#eq#27,1,0);
@for(weather(j):g(i,j)=@if(d(i)#eq#15,g(i,j),0));
E(i,2)=@if(Q(i,3)#eq#1,1,1-E(i,1));
l(i)=@sum(plac_x(k):a(k)*t(1,k));
o(i)=@if(i#eq#1,0,1*t(d(i-1),1)+2*t(d(i-1),2)+3*t(d(i-1),3)+4*t(d(i-1),4)+5*t(d(i-1),5)+6*t(d(i-1),6)+7*t(d(i-1),7)+8*t(d(i-1),8)+9*t(d(i-1),9)+10*t(d(i-1),10)+11*t(d(i-1),11)+12*t(d(i-1),12)+13*t(d(i-1),13)+14*t(d(i-1),17)+15*t(d(i-1),15)+16*t(d(i-1),16)+17*t(d(i-1),17)+18*t(d(i-1),18)+19*t(d(i-1),19)+20*t(d(i-1),20)+21*t(d(i-1),21)+22*t(d(i-1),22)+23*t(d(i-1),23)+24*t(d(i-1),24)+25*t(d(i-1),25)+26*t(d(i-1),26)+27*t(d(i-1),27));
d(i)=@if(i#eq#1,E(i,1)*(l(i))+E(i,2)*1,(o(i)*E(i,1)+E(i,2)*d(i-1)));
M(i)=@if(i#eq#1,(10000-5*W0-10*f0),@if(d(i)#eq#27,M(i-1)+W(i-1)*2.5+f(i-1)*5,@if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