sets:
jihe1/1..9/;
jihe2/1..14/;
jihe3/1..4/;
jihe4(jihe1,jihe2);
jihe5(jihe1,jihe2,jihe3):x;
endsets
min=@sum(jihe4(i,j):(x(i,j,1)*x(i,j,2)+x(i,j,2)*x(i,j,3))+(x(i,j,3)*x(i,j,4)+x(i,j,4)*x(i,j,1)));
@for(jihe4(i,j):@sum(jihe3(k):x(i,j,k))=2);
@for(jihe4(i,j)|j#lt#14:x(i,j,3)*x(i,j+1,1)+(1-x(i,j,3))*(1-x(i,j+1,1))=1);
@for(jihe4(i,j)|i#lt#9:x(i,j,2)*x(i+1,j,4)+(1-x(i,j,2))*(1-x(i+1,j,4))=1);
@for(jihe5(i,j,k):@bin(x(i,j,k)));
end