% The New Year's Party Problem % PROGRAM 6 in % http://www.cs.utexas.edu/users/vl/tag/seating_solutions :- sorts table; chair; guest. :- variables G,G1 :: guest; T :: table; C :: chair. :- constants 1..N :: table; 1..M :: chair; 1..N*M :: guest; likes(guest,guest), dislikes(guest,guest), assign_table(guest,table), assign_chair(guest,chair) :: cwAtomicFormula. % start with an arbitrary arrangement. assign_table(G,T) :- not (not assign_table(G,T)). assign_chair(G,C) :- not (not assign_chair(G,C)). % make sure that everyone sits at a chair at some table, :- not \/T: assign_table(G,T). :- not \/C: assign_chair(G,C). % that no two guests sit at the same chair, :- assign_table(G,T), assign_table(G1,T), assign_chair(G,C), assign_chair(G1,C), G < G1. % that the ones who like each other sit at the same table, :- not assign_table(G,T), likes(G,G1), assign_table(G1,T). % and that the ones who do not like each other do not sit at % the same table. :- assign_table(G,T), dislikes(G,G1), assign_table(G1,T). % display the arrangement only. :- show assign_table(G,T).