/* Global constraint correspondence in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Ccorrespondence.html """ The variables of the TO collection correspond to the variables of the FROM collection according to the permutation expressed by PERMUTATION. Example ( <1, 9, 1, 5, 2, 1>, <6, 1, 3, 5, 4, 2>, <9, 1, 1, 2, 5, 1> ) As illustrated by Figure 4.65.1, the correspondence constraint holds since: * The first item FROM [1] .from=1 of collection FROM corresponds to the PERMUTATION [1].var=6th item of collection TO. * The second item FROM [2] .from=9 of collection FROM corresponds to the PERMUTATION [2].var=1th item of collection TO. * The third item FROM [3] .from=1 of collection FROM corresponds to the PERMUTATION [3].var=3th item of collection TO. * The fourth item FROM [4] .from=5 of collection FROM corresponds to the PERMUTATION [4].var=5th item of collection TO. * The fifth item FROM [5] .from=2 of collection FROM corresponds to the PERMUTATION [5].var=4th item of collection TO. * The sixth item FROM [6] .from=1 of collection FROM corresponds to the PERMUTATION [6].var=2th item of collection TO. """ 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 = 6, From = new_list(N), From :: 1..9, Permutation = new_list(N), Permutation :: 1..N, To = new_list(N), To :: 1..9, From = [1,9,1,5,2,1], % Permutation = [6,1,3,5,4,2], To = [9,1,1,2,5,1], correspondence(From, Permutation, To), Vars = From ++ Permutation ++ To, solve(Vars), println(from=From), println(permutation=Permutation), println(to=To), nl, fail, nl. go => true. % % correspondence(FROM, PERMUTATION, TO) % correspondence(From, Permutation, To) => all_different(Permutation), foreach(I in 1..From.len) % From[I] #= To[Permutation[I]] element(Permutation[I],To,From[I]) end.