Cihan Altay's Touching Numbers Puzzle - XPRESS-MP model
MODEL Altay
Size=10
TABLES
N(Size,Size) ! N(i,j) = number of squares touching if digit (i-1) is to
! the immediate left of digit (j-1)
DATA
N(1,1)= 0,2,4,3,3,4,5,2,5,4
N(2,1)= 1,0,1,1,0,1,1,0,1,1
N(3,1)= 4,2,0,3,3,4,4,2,4,4
N(4,1)= 5,2,4,0,3,4,5,2,5,4
N(5,1)= 5,2,4,3,0,4,5,2,5,4
N(6,1)= 4,1,4,3,2,0,4,1,4,3
N(7,1)= 4,1,4,3,2,3,0,1,4,3
N(8,1)= 5,2,4,3,3,4,5,0,5,4
N(9,1)= 5,2,4,3,3,4,5,2,0,4
N(10,1)= 5,2,4,3,3,4,5,2,5,0
VARIABLES
X(Size,Size) ! X(i,j) = 1 if digit (i-1) is to the immediate left of digit (j-1)
! 0 otherwise
Z(Size) ! variables to avoid circular sets
CONSTRAINTS
! Maximize score
Maxscore: sum(i=1:Size,j=1:Size) (i+j-2)*N(i,j)*X(i,j) $
! Each digit to the immediate left of no more than one other
Lcon(i=1:Size): sum(j=1:Size) X(i,j) < 1
! Each digit to the immediate right of no more than one other
Rcon(j=1:Size): sum(i=1:Size) X(i,j) < 1
! No circular sets
Circ(i=1:Size,j=1:Size): Z(i)-Z(j)+Size*X(i,j) < Size-1
! Exactly nine adjacencies required
Nine: sum(i=1:Size,j=1:Size) X(i,j) = 9
BOUNDS
X(i=1:Size,j=1:Size) .bv.
GENERATE
print X
print Z