/* Photo problem in Picat. Port of SICStus Prolog model photo.pl """ FILE photo AUTHOR Greger Ottosson (greger@csd.uu.se) HISTORY greger - 1996-05-24 : Created. (Adapted from Oz program) """ This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> println("bb:"), time(photo(bb,[min],5,1)), time(photo(bb,[min],7,1)), time(photo(bb,[min],9,1)), % 0.031s println("iter:"), time(photo(bb,[min],9,1)), % 0.03s println("ff/split:"), time(photo(bb,[ff,split],9,1)), % 0.03s % slightly faster: println("degree/updown:"), time(photo(bb,[degree,split],9,1)), % 0.02s fail, nl. go => true. % From SICStus Prolog model photo.pl % """ % [min] is the best heuristic, bb the best optimization scheme. % Consistency = domain or bound are good, value is bad. % """ photo(bb, Lab, Size, NextTo) :- problem(Size, NextTo, L, Benefit), solve($[max(Benefit)|Lab], L), println($L-Benefit), nl. photo(iter, Lab, Size, NextTo) :- problem(Size, NextTo, L, Benefit), solve([down],[Benefit]), solve(Lab, L), println($L-Benefit), nl. problem(Size, NextTo, L, Benefit) :- L = [Alice,Bert|_], problem(Size, L, Pairs), L :: 1..Size, Bs = [], foreach([X,Y] in Pairs) ( NextTo==1 -> D #= X-Y, D in -1..1 #<=> B ; NextTo==2 -> abs(X-Y) #=< 1 #<=> B ; NextTo==3 -> X#=Y+1 #\ Y#=X+1 #<=> B ; true ), Bs := Bs ++ [B] end, sum(Bs) #= Benefit, Alice #< Bert, all_different(L). problem(5, [Alice,Bert,Chris,Deb,Evan], [[Alice,Chris], [Bert,Evan], [Chris,Deb], [Chris,Evan], [Deb,Alice], [Deb,Evan], [Evan,Alice], [Evan,Bert]]). problem(7, [Alain,Beatrice,Christian,Daniel,Eliane,Francois,Gerard], [[Beatrice,Gerard], [Beatrice,Eliane], [Beatrice,Christian], [Francois,Eliane], [Francois,Daniel], [Francois,Alain], [Alain,Daniel], [Gerard,Christian]]). problem(9, [A0,A1,A2,A3,A4,A5,A6,A7,A8], [[A0,A2], [A0,A4], [A0,A7], [A1,A4], [A1,A8], [A2,A3], [A2,A4], [A3,A0], [A3,A4], [A4,A5], [A4,A0], [A5,A0], [A5,A8], [A6,A2], [A6,A7], [A7,A8], [A7,A6]]).