/* Panoz problem in Picat. From "How to Solve it With B-Prolog?" http://www.cs.nmsu.edu/ALP/2010/08/how-to-solve-it-with-b-prolog/ (Prolog Programming Contest 2010) """ Manhattan has several outlets of the famous Belgian bakery Panoz. During an experiment with a new kind of chocolate pastry, the old bakery has exploded. A new bakery will be built, somewhere in Manhattan, and this occasion is used to optimize the distribution of all the goodies. Clearly Panoz wants the location in Manhattan which minimizes the maximal (Manhattan) distance from the bakery to any outlet. Write a predicate panoz/2 whose queries look like ?- panoz(Outlets,Sol). where Sol is the location of the new bakery. The outlet coordinates Outlets are given as a list of tuples, e.g. [(0,1),(0,2),(4,0),(4,3)]. Here is a typical query and its answer: ?- panoz([(0,1),(0,2),(4,0),(4,3)],Sol). Sol = (2,2) Of course, Sol = (2,1) would also have been a good solution. """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. go => panoz([[0,1],[0,2],[4,0],[4,3]],Sol, Ds), writeln([sol=Sol,ds=Ds]), % find all optimal solutions panoz2([[0,1],[0,2],[4,0],[4,3]],Sols2,Ds), writeln(all_solutions=Sols2), nl. panoz(Ps, Sol, Ds) => Xs = [X : [X,_] in Ps], Ys = [Y : [_,Y] in Ps], X :: min(Xs)..max(Xs), Y :: min(Ys)..max(Ys), Ds #= max([max(X1-X,X-X1)+max(Y1-Y,Y-Y1) : [X1,Y1] in Ps]), solve([$min(Ds)],[X,Y]), Sol = [X,Y]. panoz2(Ps, Sols,Ds) => Xs = [X : [X,_] in Ps], Ys = [Y : [_,Y] in Ps], X :: min(Xs)..max(Xs), Y :: min(Ys)..max(Ys), Ds #= max([max(X1-X,X-X1)+max(Y1-Y,Y-Y1) : [X1,Y1] in Ps]), Sols = solve_all([X,Y]).