/* Scheduling speakers in Picat. From Rina Dechter, Constraint Processing, page 72 Scheduling of 6 speakers in 6 slots. Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => N = 6, % number of speakers % the available slots Available = [ % Reasoning: [3,4,5,6], % 2) the only one with 6 after speaker F -> 1 [3,4], % 5) 3 or 4 [2,3,4,5], % 3) only with 5 after F -> 1 and A -> 6 [2,3,4], % 4) only with 2 after C -> 5 and F -> 1 [3,4], % 5) 3 or 4 [1,2,3,4,5,6] % 1) the only with 1 ], L = findall(X,$schedule_speakers(N,Available,X)), foreach(S in L) writeln(S) end, nl. schedule_speakers(N,Available,Xs) => % the alotted speaker slot Xs = new_list(N), Xs :: 1..N, all_different(Xs), foreach({X,A} in zip(Xs,Available)) element(_,A,X) end, solve([], Xs).