/* Rock Start Dressing Problem in Picat. From the presentation http://www.cse.unsw.edu.au/~cs4418/2010/Lectures/Constraints2.ppt (From the course "Knowledge Representation and Reasoning COMP4418" http://www.cse.unsw.edu.au/~cs4418/2010/index.html ) """ A rock star has - red, green, orange and blue shirts - pink and yellow ties - black, khaki, purple and blue pants - Fashion sense: A yellow tie only goes with red, green or blue shirts A pink tie only goes with blue shirts etc Find a satisfactory outfit. """ Here are the exact Fashion sense requirements: Pants Shirt ----------- khaki green blue red purple orange black blue Shirt Tie ---------- red yellow green yellow blue yellow blue pink Tie Pants ------------ yellow blue yellow black pink black pink purple pink khaki The three possible solutions: [shirt = red,tie = yellow,pants = blue] [shirt = blue,tie = pink,pants = black] [shirt = blue,tie = yellow,pants = black] This program 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 ?=> N = 9, Colors = 1..9, Colors = [Red,Green,Orange,Blue,Pink,Yellow,Black,Khaki,Purple], ColorsS = ["red","green","orange","blue","pink","yellow","black","khaki","purple"], ShirtDomain = [Red, Green, Orange, Blue], TieDomain = [Pink, Yellow], PantsDomain = [Black, Khaki, Purple, Blue], % requirements PantsShirt = [{Khaki, Green}, {Blue, Red}, {Purple, Orange}, {Black, Blue}], ShirtTie = [{Red, Yellow}, {Green, Yellow}, {Blue, Yellow}, {Blue, Pink}], TiePants = [{Yellow, Blue}, {Yellow, Black}, {Pink, Black}, {Pink, Purple}, {Pink, Khaki}], % decision variables Shirt :: ShirtDomain, Tie :: TieDomain, Pants :: PantsDomain, % Collect the different fashion sense into table_in/2 constraints. table_in({Pants, Shirt}, PantsShirt), table_in({Shirt, Tie }, ShirtTie ), table_in({Tie , Pants}, TiePants ), Vars = [Shirt,Tie,Pants], solve(Vars), println([shirt=ColorsS[Shirt],tie=ColorsS[Tie],pants=ColorsS[Pants]]), fail, nl. go => true.