!@encoding CP1252 model Sudoku uses "mmxprs"; !gain access to the Xpress-Optimizer solver !sample declarations section declarations rows = 1..9 columns = 1..9 numbers = 1..9 sol: array(numbers,rows,columns) of mpvar useless:linctr end-declarations writeln("Begin running model") sol(8,1,1)=1 sol(5,1,6)=1 sol(3,2,1)=1 sol(7,2,3)=1 sol(8,2,4)=1 sol(4,3,1)=1 sol(7,3,5)=1 sol(1,3,9)=1 sol(3,4,4)=1 sol(5,4,5)=1 sol(6,4,8)=1 sol(4,5,2)=1 sol(3,5,3)=1 sol(8,5,6)=1 sol(1,5,8)=1 sol(2,6,1)=1 sol(7,6,4)=1 sol(4,6,6)=1 sol(8,6,9)=1 sol(5,7,4)=1 sol(4,7,7)=1 sol(7,7,9)=1 sol(1,8,1)=1 sol(3,8,8)=1 sol(6,9,4)=1 forall (i in rows, j in columns) sum(z in numbers) sol(z,i,j)=1 forall(z in numbers, i in rows) sum(j in columns) sol(z,i,j)=1 forall(z in numbers, j in columns) sum(i in rows) sol(z,i,j)=1 forall(z in numbers) forall (ii in [2,5,8], jj in [2,5,8]) sum(i in [ii-1,ii,ii+1]) sum(j in [jj-1,jj,jj+1]) sol(z,i,j)=1 forall (z in numbers, i in rows, j in columns) sol(z,i,j) is_binary maximize(useless) forall(i in rows) do writeln("") forall(j in columns) forall(z in numbers | getsol(sol(z,i,j))>0) write(z," ") end-do forall(z in numbers)do writeln("\n") forall(i in rows) do writeln("") forall(j in columns) write(getsol(sol(z,i,j))," ") end-do end-do writeln("\n\n End running model") end-model