|
C is a knight and a werewolf, and A and B are both knaves and not werewolves.
Xpress-Mosel Model
model 'were2'
! Description : Werewolves II
! Source : Smullyan, R., (1978), What is the Name of this Book?, Prentice-Hall
! Date written : Xpress-MP 20/12/99, Mosel 19/4/03
! Written by : M J Chlond
uses 'mmxprs'
parameters
person = 3
end-parameters
declarations
x: array(1..person) of mpvar ! x(i) = 1 if person i is a knight, 0 if a knave
y: array(1..person) of mpvar ! y(i) = 1 if person i is a werewolf, 0 otherwise
end-declarations
any:= x(1)
! only one is a werewolf
pca:= sum(i in 1..person) y(i) = 1
! if statement 1 is true then set x(1) = 1, else 0
lca1:= y(1)-9*x(1) <= 0
lca2:= y(1)-x(1) >= 0
! if statement 2 is true then set x(2) = 1, else 0
lcb1:= y(2)-9*x(2) <= 0
lcb2:= y(2)-x(2) >= 0
! if statement 3 is true then set x(3) = 1, else 0
lcc1:= sum(i in 1..person) x(i)+9*x(3) >= 2
lcc2:= sum(i in 1..person) x(i)+9*x(3) <= 10
forall(i in 1..person) do
x(i) is_binary
y(i) is_binary
end-do
minimise(any)
! display results
forall(i in 1..person) do
write(getsol(x(i)),' ',getsol(y(i)))
writeln
end-do
end-model
|