From 23b860a977b68a3557f0aaeda7f035b6018133fd Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 11 Sep 2013 14:53:43 +0100 Subject: [PATCH] scalar_product and a fix --- library/gecode/clp_examples/test.yap | 7 +++++++ library/gecode/clpfd.yap | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/library/gecode/clp_examples/test.yap b/library/gecode/clp_examples/test.yap index 5090912f5..9934422ea 100644 --- a/library/gecode/clp_examples/test.yap +++ b/library/gecode/clp_examples/test.yap @@ -15,3 +15,10 @@ test2(X) :- X in 1..10, X / 4 #= 2, labeling([], [X]). +test3(A) :- + A = [X,Y,Z], + A ins 1..4, + Y #> 2, + lex_chain(A), + all_different(A), + labeling([], [X,Y,Z]). diff --git a/library/gecode/clpfd.yap b/library/gecode/clpfd.yap index c93a6a149..4ea0ed0bb 100644 --- a/library/gecode/clpfd.yap +++ b/library/gecode/clpfd.yap @@ -34,12 +34,12 @@ all_distinct/2, maximize/1, sum/3, + lex_chain/1, scalar_product/4, /* tuples_in/2, */ labeling/2 /*, label/1, indomain/1, - lex_chain/1, serialized/2, global_cardinality/2, global_cardinality/3, @@ -194,6 +194,9 @@ all_distinct( Cs, Xs ) :- scalar_product( Cs, Vs, Rels, X ) :- get_home(Env), post( scalar_product( Cs, Vs, Rels, X ), Env, _ ). +lex_chain( Cs ) :- + get_home(Env), + post( rel( Cs, '#=<' ), Env, _ ). labeling(_Opts, Xs) :- get_home(Space-Map), @@ -245,6 +248,12 @@ post( rel( sum(L), Op, Out), Space-Map, Reify):- Space += linear(IL, GOP, IOut, Reify) ). % [A,B,C,D] #< 3 +post( rel( A, Op), Space-Map, Reify):- + checklist( var, A ), !, + maplist(ll(Map), A, IL ), + gecode_arith_op( Op, GOP ), + (var(Reify) -> Space += rel(IL, GOP) ; + Space += rel(IL, GOP, IB) ). post( rel( A, Op, B), Space-Map, Reify):- checklist( var, A ), ( var(B) -> l(B, IB, Map) ; integer(B) -> IB = B ), !, @@ -327,7 +336,7 @@ post( all_distinct( Cs , Xs ), Space-Map, Reify) :- gecode_arith_op( (#=) , 'IRT_EQ' ). gecode_arith_op( (#\=) , 'IRT_NQ' ). -gecode_arith_op( (#>) , 'IRT_GE' ). +gecode_arith_op( (#>) , 'IRT_GR' ). gecode_arith_op( (#>=) , 'IRT_GQ' ). gecode_arith_op( (#<) , 'IRT_LE' ). gecode_arith_op( (#=<) , 'IRT_LQ' ).