/* Wine cask puzzle in Picat. From Martin Chlond Integer Programming Puzzles: http://www.chlond.demon.co.uk/puzzles/puzzles1.html Description : Wine cask puzzle Source : M Kraitchik - Mathematical Recreations (p 31) This model was inspired by the XPress Mosel model created by Martin Chlond. http://www.chlond.demon.co.uk/puzzles/sol1s7.html This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import mip. main => go. /* {3,1,1,1,3} {2,1,3,1,2} {2,1,2,3,1} {1,3,2,1,2} {1,3,1,3,1} [31113,21312,21231,13212,13131] */ go => Nephew = 5, Casktype = 5, N = 1..Nephew, C = 1.. Casktype, Howfull = [ 0.0, 0.25, 0.5, 0.75, 1.0], Cdum = [10000.0, 1000.0, 100.0, 10.0, 1.0], X = new_array(Nephew,Casktype), X :: 1..10, Dtot = new_list(Nephew), Dtot :: 0.0..100000.0, foreach(I in N) sum([ X[I,J] : J in C]) #= 9.0 end, foreach(I in N) sum([Howfull[J]*X[I,J] : J in C]) #= 4.5 end, foreach(J in C) sum([X[I,J] : I in N]) #= 9.0 end, foreach(I in N) sum([Cdum[J]*X[I,J] : J in C]) #= Dtot[I] end, foreach(I in 2..Nephew) Dtot[I-1] - Dtot[I] #>= 1.0 end, Vars = X.vars ++ Dtot, println(vars=Vars), solve($[glpk],Vars), foreach(Row in X) println(Row) end, println(Dtot), nl, fail, nl. go => true.