|
The third response is the true one.
Xpress-Mosel Model
model 'earthlin'
! Description : Earthlings
! Source : Poniachik, J. & L., (1998), Hard-to-solve Brainteasers, Sterling
! Date written : Xpress-MP 2/12/99, Mosel 19/4/03
! Written by : M J Chlond
uses 'mmxprs'
parameters
team = 3 ! 1 = Zaire, 2 = Uruguay, 3 = Spain
place = 3 ! 1st, 2nd or 3rd
type = 3 ! 1 = truth-teller, 2 = alternator, 3 = liar
state = 3 ! statements 1 = x(1,1)+x(2,2)+x(3,3)=3
! 2 = x(1,1)+x(3,2)+x(2,3)=3
! 3 = x(2,1)+x(3,2)+x(1,3)=3
end-parameters
declarations
T = 1..team
P = 1..place
E = 1..type
S = 1..state
x: array(T,P) of mpvar ! x(i,j) = 1 if team i in place j , 0 otherwise
y: array(S,E) of mpvar ! y(k,l) = 1 if statement k made by type l
d: array(S) of mpvar ! d(k) = number of truths in statement k
end-declarations
any:= x(1,1)
! each place one team
forall(j in P)
tecon(j):= sum(i in T) x(i,j) = 1
! each team one place
forall(i in T)
plcon(i):= sum(j in P) x(i,j) = 1
! each type makes one statement
forall(k in E)
tycon(k):= sum(l in S) y(k,l) = 1
! each statement made by one type
forall(l in S)
stcon(l):= sum(k in E) y(k,l) = 1
! d(i) = number of truths in statement i
setd1:= x(1,1)+x(2,2)+x(3,3) = d(1)
setd2:= x(1,1)+x(3,2)+x(2,3) = d(2)
setd3:= x(2,1)+x(3,2)+x(1,3) = d(3)
forall(k in S) do
! if statement k made by truthteller (i.e. d(k)=3 ) then y(k,1) = 1, else 0
sta(k):= d(k) - 3*y(k,1) >= 0
stb(k):= d(k) - 3*y(k,1) <= 2
! if statement k made by liar (i.e. d(k)=0 ) then y(k,3) = 1, else 0
sla(k):= d(k) + 3*y(k,3) <= 3
slb(k):= d(k) + y(k,3) >= 1
end-do
! assertion 1 and 3 either both true or both false for all statements
fta:= x(1,1)=x(3,3)
ftb:= x(1,1)=x(2,3)
ftc:= x(2,1)=x(1,3)
forall(i in T,j in P)
x(i,j) is_binary
forall(l in S,k in E)
y(l,k) is_binary
forall(l in S) do
d(l) is_integer
d(l) <= 3
end-do
minimise(any)
forall(i in T) do
forall(j in T)
write(getsol(x(i,j)),' ')
writeln
end-do
forall(l in S) do
forall(k in E)
write(getsol(y(l,k)),' ')
writeln
end-do
end-model
|