/* Global constraint lex_chain_less in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Clex_chain_less.html """ lex_chain_less (VECTORS) Purpose For each pair of consecutive vectors VECTORi and VECTORi+1 of the VECTORS collection we have that VECTORi is lexicographically strictly less than VECTORi+1. Given two vectors, X and Y of n components, 〈X0, ..., Xn−1〉 and 〈Y0, ..., Yn−1〉, X is lexicographically strictly less than Y if and only if X0 , vec-<5, 2, 6, 2>, vec-<5, 2, 6, 3> > ) The lex_chain_less constraint holds since: * The first vector 〈5, 2, 3, 9〉 of the VECTORS collection is lexicographically strictly less than the second vector 〈5, 2, 6, 2〉 of the VECTORS collection. * The second vector 〈5, 2, 6, 2〉 of the VECTORS collection is lexicographically strictly less than the third vector 〈5, 2, 6, 3〉 of the VECTORS collection. """ 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 ?=> R = 3, C = 4, X = new_array(R,C), X :: 1..9, % X = {{5,2,3,9}, % {5,2,6,2}, % {5,2,6,3}}, X = {{5,2,3,9}, {_,_,_,_}, {5,2,6,3}}, lex_chain_less(X), solve(X), foreach(Row in X) println(Row) end, nl, fail, nl. go => true. lex_chain_less(X) => N = X.len, M = X[1].len, foreach(I in 2..N) lex_lt([X[I-1, J] : J in 1..M], [X[I, J] : J in 1..M]) end.