/* Global constraint domain_constraint in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Cdomain_constraint.html """ domain_constraint(VAR,VALUES) Purpose Make the link between a domain variable VAR and those 0-1 variables that are associated with each potential value of VAR: The 0-1 variable associated with the value that is taken by variable VAR is equal to 1, while the remaining 0-1 variables are all equal to 0. Example ( 5, < var01-0 value-9, var01-1 value-5, var01-0 value-2, var01-0 value-7 > ) The domain_constraint holds since VAR=5 is set to the value corresponding to the 0-1 variable set to 1, while the other 0-1 variables are all set to 0. """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> N = 4, Var01 = new_list(N), Var01 :: 0..1, Values = new_list(N), Values :: 1..9, Val :: 1..9, domain_constraint(Val, Var01, Values), % Var01 = [0,1,0,0], Values = [9,5,2,7], Val #= 5, Vars = Var01 ++ Values ++ [Val], solve(Vars), println(var01=Var01), println(values=Values), println(val=Val), nl, fail, nl. go => true. domain_constraint(Val, Var01, Values) => sum(Var01) #= 1, sum([Var01[I] #= 1 #/\ Val #= Values[I] : I in 1..Var01.len]) #= 1.