/*
Joshua and his rats puzzle in Picat.
From Martin Chlond Integer Programming Puzzles:
http://www.chlond.demon.co.uk/puzzles/puzzles2.html, puzzle nr. 12.
Description : Joshua and his rats
Source : Sole, T., (1988), The Ticket to Heaven, Penguin Books
"""
Joshua is a biology student. His project for this term is measuring the effect of an increase in
vitamin C in the diet of nine laboratory rats. Each rat will have a different diet supplement of 1 to 20
units. Fractions of a unit are not possible.
To get the maximum value for his experiment, Joshua has decided that for any group of three rats the
supplements should not be in arithmetic progression. In other words, for three rats chosen at random, the
biggest supplement less the middle supplement should be different from the middle supplement less the
smallest supplement. Thus, if two of the supplements were 7 and 13 units, no rat could have a supplement of
1, 10 or 19 units.
Find a set of supplements that Joshua could use.
(Sole)
"""
This model was inspired by the XPress Mosel model created by Martin Chlond.
http://www.chlond.demon.co.uk/puzzles/sol2s12.html
This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com
See also my Picat page: http://www.hakank.org/picat/
*/
import cp.
main => go.
go =>
Rat = 9,
X = new_list(Rat),
X :: 1..20,
D = new_array(Rat,Rat,Rat),
D :: 0..1,
Tot #= sum(X),
foreach(I in 2..Rat)
% X[I] #>= X[I-1]+1
X[I] #> X[I-1]
end,
foreach(I in 1..Rat,J in 1..Rat,K in 1..Rat, J < I, K < J)
% -X[I]+2*X[J]-X[K] + 19*D[I,J,K] #>= 1,
% -X[I]+2*X[J]-X[K] + 19*D[I,J,K] #<= 18
Tmp #= -X[I]+2*X[J]-X[K] + 19*D[I,J,K],
Tmp :: 1..18
end,
Vars = X ++ D.vars(),
solve($[min(Tot)], Vars),
println(tot=Tot),
println(x=X),
% println(d=D),
nl.