/* Global constraint lex_alldifferent in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Clex_alldifferent.html """ lex_alldifferent (VECTORS) Purpose All the vectors of the collection VECTORS are distinct. Two vectors (u1, u2, ..., un) and (v1, v2, ..., vn) are distinct if and only if there exists i in [1, n] such that ui != vi. Example ( < vec−〈5, 2, 3〉, vec−〈5, 2, 6〉, vec−〈5, 3, 3〉 > ) The lex_alldifferent constraint holds since: * The first vector <5, 2, 3> and the second vector <5, 2, 6> of the VECTORS collection differ in their third component (i.e., 3 != 6). * The first vector <5, 2, 3> and the third vector <5, 3, 3> of the VECTORS collection differ in their second component (i.e., 2 != 3). * The second vector <5, 2, 6> and the third vector <5, 3, 3> of the VECTORS collection differ in their second and third components (i.e., 2!=3 and 6!=3). """ Also see http://hakank.org/picat/lex2.pi 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 = 3, M = 3, X = new_array(M,N), X :: 1..6, % X = {{5,2,3}, % {5,2,6}, % {5,3,3}}, X = {{_,_,_}, {5,_,6}, {5,3,3}}, lex_alldifferent(X), solve(X), foreach(Row in X) println(Row) end, nl, fail, nl. go => true. lex_alldifferent(X) => Len = X[1].length, foreach(I in 2..X.length) lex_lt(X[I-1], X[I]) end.