model sudoku uses "mmxprs"; !gain access to the Xpress-Optimizer solver !sample declarations section declarations s1 = 1..3 s2 = 4..6 s3 = 7..9 s = s1+s2+s3 x: array(s,s,s) of mpvar end-declarations costo := sum(i,j,k in s) 0*x(i,j,k) forall(j,k in s) do sum(i in s) x(i,j,k) = 1 end-do forall(i,k in s) do sum(j in s) x(i,j,k) = 1 end-do forall(i,j in s) do sum(k in s) x(i,j,k) = 1 end-do forall(k in s) do sum(i in s1,j in s1) x(i,j,k) = 1 sum(i in s1,j in s2) x(i,j,k) = 1 sum(i in s1,j in s3) x(i,j,k) = 1 sum(i in s2,j in s1) x(i,j,k) = 1 sum(i in s2,j in s2) x(i,j,k) = 1 sum(i in s2,j in s3) x(i,j,k) = 1 sum(i in s3,j in s1) x(i,j,k) = 1 sum(i in s3,j in s2) x(i,j,k) = 1 sum(i in s3,j in s3) x(i,j,k) = 1 end-do forall(i,j,k in s) x(i,j,k) is_binary x(1,1,8)=1 x(2,1,3)=1 x(3,1,4)=1 x(6,1,2)=1 x(8,1,1)=1 x(5,2,4)=1 x(2,3,7)=1 x(5,3,3)=1 x(2,4,8)=1 x(4,4,3)=1 x(6,4,7)=1 x(7,4,5)=1 x(9,4,6)=1 x(3,5,7)=1 x(4,5,5)=1 x(1,6,5)=1 x(5,6,8)=1 x(6,6,4)=1 x(7,7,4)=1 x(4,8,6)=1 x(5,8,1)=1 x(8,8,3)=1 x(3,9,1)=1 x(6,9,8)=1 x(7,9,7)=1 minimize(costo) writeln("Begin running model") forall(i,j,k in s) do if(getsol(x(i,j,k)))=1 then writeln(i,"",j,"",k," ",getsol(x(i,j,k))) end-if end-do writeln("End running model") end-model