|
First allocation
Lower floor:
1 1 1
1 0 1
1 1 2
Upper floor:
3 2 3
2 0 1
3 1 3
Second allocation
Lower floor:
1 1 1
1 0 3
1 1 1
Upper floor:
2 3 3
3 0 1
3 3 2
Xpress-Mosel Model
model 'pilgrim'
! Description : The Riddle of the Pilgrims
! Source : Dudeney, H.E., (1949), The Canterbury Puzzles, 7th ed., Thomas Nelson and Sons.
! Date written : Mosel 19/4/03
! Written by : M J Chlond
uses 'mmxprs'
declarations
N = 1..2 ! solutions
F = 1..2 ! floors
R = 1..3 ! rows
C = 1..3 ! columns
x: array(N,F,R,C) of mpvar
! number of pilgrims in solution n
! on floor f, row r, column c
end-declarations
! any objective
any:= x(1,1,1,1)
! difference between solutions is 3 pilgrims
num:= sum(j in F,k in R,m in C) x(1,j,k,m) + 3 = sum(j in F,k in R,m in C) x(2,j,k,m)
! twice as many pilgrims on second floor as first floor
forall(i in N)
flr(i):= sum(k in R,m in C) 2*x(i,1,k,m) = sum(k in R,m in C) x(i,2,k,m)
! eleven on first and third rows (i.e. front and back sides)
forall(i in N,k in R | k <> 2)
relev(i,k):= sum(j in F,m in C) x(i,j,k,m) = 11
! eleven on first and third columnss (i.e. left and right sides)
forall(i in N,m in C | m <> 2)
celev(i,m):= sum(j in F,k in R) x(i,j,k,m) = 11
forall(i in N,j in F,k in R,m in C | k <> 2 or m <> 2) do
x(i,j,k,m) is_integer
! at least one pilgrim to a room
x(i,j,k,m) >= 1
! at most three pilgrims to a room
x(i,j,k,m) <= 3
end-do
! no pilgrims allocated to central cells
forall(i in N,j in F)
x(i,j,2,2) = 0
minimise(any)
forall(i in N) do
forall(j in F) do
forall(k in R) do
forall(m in C)
write(getsol(x(i,j,k,m)),' ')
writeln
end-do
end-do
end-do
end-model
|