/* Global constraints cond_lex_less cond_lex_lesseq cond_lex_greater cond_lex_greatereq in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Ccond_lex_less.html """ cond_lex_less(VECTOR1, VECTOR2, PREFERENCE_TABLE)% Purpose VECTOR1 and VECTOR2 are both assigned to the Ith and Jth items of the collection PREFERENCE_TABLE such that I < J. Example ( <1, 0>, <0, 0>, < tuple-<1, 0>, tuple-<0, 1>, tuple-<0, 0>, tuple-<1, 1> > ) The cond_lex_less constraint holds since VECTOR1 and VECTOR2 are respectively assigned to the first and third items of the collection PREFERENCE_TABLE. """ The other three constraints are defined in the analogous way: cond_lex_greater: http://www.emn.fr/x-info/sdemasse/gccat/Ccond_lex_greater.html cond_lex_greatereq: http://www.emn.fr/x-info/sdemasse/gccat/Ccond_lex_greatereq.html cond_lex_lesseq: http://www.emn.fr/x-info/sdemasse/gccat/Ccond_lex_lesseq.html 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, M = 2, Arr = new_array(N,M), Arr :: 0..1, V1 = new_list(M), V1 :: 0..1, V2 = new_list(M), V2 :: 0..1, Arr = {{1,0}, {0,1}, {0,0}, {1,1}}, V1 = [1,0], % V2 = [0,0], % cond_lex_less(V1, V2, Arr), % cond_lex_lesseq(V1, V2, Arr), cond_lex_greater(V1, V2, Arr), % cond_lex_greatereq(V1, V2, Arr), Vars = Arr.vars ++ V1 ++ V2, solve(Vars), println(arr=Arr), println(v1=V1), println(v2=V2), nl, fail, nl. go => true. cond_lex_less(Vec1, Vec2, A) => cond_lex_op(Vec1, Vec2, A, #<). cond_lex_lesseq(Vec1, Vec2, A) => cond_lex_op(Vec1, Vec2, A, #=<). cond_lex_greater(Vec1, Vec2, A) => cond_lex_op(Vec1, Vec2, A, #>). cond_lex_greatereq(Vec1, Vec2, A) => cond_lex_op(Vec1, Vec2, A, #>=). % % Generalized version of cond_lex_*/3. % cond_lex_op(Vec1, Vec2, A, Op) => P1 :: 1..A.len, P2 :: 1..A.len, foreach(J in 1..Vec1.len) % A[P1,J] #= Vec1[J] matrix_element(A,P1,J,Vec1[J]) end, foreach(J in 1..Vec2.len) % A[P2,J] #= Vec2[J] matrix_element(A,P2,J,Vec2[J]) end, call(Op,P1,P2).