fixes to clpbn interface

This commit is contained in:
Vitor Santos Costa 2013-09-11 13:04:39 +01:00
parent 12d1e17dd3
commit b30f0eafdf

View File

@ -250,8 +250,8 @@ post( rel( A, Op, B), Space-Map, Reify):-
( var(B) -> l(B, IB, Map) ; integer(B) -> IB = B ), !, ( var(B) -> l(B, IB, Map) ; integer(B) -> IB = B ), !,
maplist(ll(Map), A, IL ), maplist(ll(Map), A, IL ),
gecode_arith_op( Op, GOP ), gecode_arith_op( Op, GOP ),
(var(Reify) -> Space += rel(IA, GOP, IB) ; (var(Reify) -> Space += rel(IL, GOP, IB) ;
Space += rel(IA, GOP, IB, Reify) ). Space += rel(IL, GOP, IB, Reify) ).
post( rel(A, Op, B), Space-Map, Reify):- post( rel(A, Op, B), Space-Map, Reify):-
( nonvar(A), ( A = _+_ ; A = _-_ ) ; ( nonvar(A), ( A = _+_ ; A = _-_ ) ;
nonvar(B), ( B = _ + _ ; B = _-_) ), !, nonvar(B), ( B = _ + _ ; B = _-_) ), !,
@ -276,7 +276,7 @@ post( rel(A, Op, B), Space-Map, Reify):-
equality(A1, NA1, Space-Map), equality(A1, NA1, Space-Map),
in_c(NA1, VA1, Space-Map), !, in_c(NA1, VA1, Space-Map), !,
equality(B, B1, Space-Map), equality(B, B1, Space-Map),
out_c(Name, VA1, B1, Space-Map, Reify). out_c(Name, VA1, B1, Op, Space-Map, Reify).
post( rel(A, Op, B), Space-Map, Reify):- post( rel(A, Op, B), Space-Map, Reify):-
nonvar(A), nonvar(A),
arith(A, Name), arith(A, Name),
@ -286,7 +286,7 @@ post( rel(A, Op, B), Space-Map, Reify):-
equality(A2, NA2, Space-Map), equality(A2, NA2, Space-Map),
in_c(NA2, VA2, Space-Map), in_c(NA2, VA2, Space-Map),
equality(B, B1, Space-Map), equality(B, B1, Space-Map),
out_c(Name, VA1, VA2, B1, Space-Map, Reify). out_c(Name, VA1, VA2, B1, Op, Space-Map, Reify).
post( scalar_product(Cs, L, Op, Out), Space-Map, Reify):- post( scalar_product(Cs, L, Op, Out), Space-Map, Reify):-
var(Out), !, var(Out), !,
maplist(ll(Map), [Out|L], [IOut|IL] ), maplist(ll(Map), [Out|L], [IOut|IL] ),
@ -409,63 +409,74 @@ equality(min( V1 , V2), NV, Env) :-
new_arith( (min), V1A, V2A, NV, Env). new_arith( (min), V1A, V2A, NV, Env).
% abs(X) #= 3 % abs(X) #= 3
out_c(Name, A1, B, Space-Map, Reify) :- out_c(Name, A1, B, Op, Space-Map, Reify) :-
integer(B), !, integer(B), !,
new_arith( Name, A1, NB, Space-Map), new_arith( Name, A1, NB, Space-Map),
gecode_arith_op( Op, BOP ),
l(NB, IB, Map), l(NB, IB, Map),
( var(Reify) -> ( var(Reify) ->
Space += rel(IB, 'IRT_EQ', B) Space += rel(IB, BOP, B)
; ;
Space += rel(IB, 'IRT_EQ', B, Reify) Space += rel(IB, BOP, B, Reify)
). ).
% abs(X) #= Cin[..] % abs(X) #= Cin[..]
out_c(Name, A1, B, Space-Map, Reify) :- out_c(Name, A1, B, (#=), Space-Map, Reify) :-
var(Reify), var(Reify),
l(B, IB, Map), !, l(B, IB, Map), !,
l(A1, IA1, Map), l(A1, IA1, Map),
G =.. [Name, IA1, IB], G =.. [Name, IA1, IB],
Space += G. Space += G.
% abs(X) #= Cin[..] <=> % abs(X) #= NEW
out_c(Name, A1, B, Space-Map, Reify) :- out_c(Name, A1, B, (#=), Space-Map, Reify) :-
nonvar(Reify), var(Reify), !,
new_arith( Name, A1, B, Space-Map).
% abs(X) #> NEW
out_c(Name, A1, B, Op, Space-Map, Reify) :-
l(B, IB0, Map), !, l(B, IB0, Map), !,
new_arith( Name, A1, NB, Space-Map), new_arith( Name, A1, NB, Space-Map),
l(NB, IB, Map), l(NB, IB, Map),
Space += rel(IB, 'IRT_EQ', IB0, Reify). gecode_arith_op( Op, BOP ),
% abs(X) #= NEW (
out_c(Name, A1, B, Space-Map, Reify) :- nonvar(Reify) ->
var(Reify), !, Space += rel(IB, BOP, IB0)
new_arith( Name, A1, B, Space-Map). ;
Space += rel(IB, BOP, IB0, Reify)
).
% X*Y #= 3 % X*Y #= 3
out_c(Name, A1, A2, B, Space-Map, Reify) :- out_c(Name, A1, A2, B, Op, Space-Map, Reify) :-
integer(B), !, integer(B), !,
new_arith( Name, A1, A2, NB, Space-Map), new_arith( Name, A1, A2, NB, Space-Map),
l(NB, IB, Map), l(NB, IB, Map),
gecode_arith_op( Op, BOP ),
( var(Reify) -> ( var(Reify) ->
Space += rel(IB, 'IRT_EQ', B) Space += rel(IB, BOP, B)
; ;
Space += rel(IB, 'IRT_EQ', B, Reify) Space += rel(IB, BOP, B, Reify)
). ).
% X*Y #= Cin[..] % X*Y #= Cin[..]
out_c(Name, A1, A2, B, Space-Map, Reify) :- out_c(Name, A1, A2, B, (#=), Space-Map, Reify) :-
var(Reify), var(Reify),
l(B, IB, Map), !, l(B, IB, Map), !,
l(A1, IA1, Map), l(A1, IA1, Map),
l(A2, IA2, Map), l(A2, IA2, Map),
G =.. [Name, IA1, IA2, IB], G =.. [Name, IA1, IA2, IB],
Space += G. Space += G.
% abs(X) #= NEW, cannot be reified
out_c(Name, A1, A2, B, (#=), Space-Map, Reify) :-
var(Reify), !,
new_arith( Name, A1, A2, B, Space-Map).
% min(X,Y) #= Cin[..] <=> % min(X,Y) #= Cin[..] <=>
out_c(Name, A1, A2, B, Space-Map, Reify) :- out_c(Name, A1, A2, B, Space-Map, Reify) :-
nonvar(Reify),
l(B, IB0, Map), !, l(B, IB0, Map), !,
new_arith( Name, A1, A2, NB, Space-Map), new_arith( Name, A1, A2, NB, Space-Map),
l(NB, IB, Map), l(NB, IB, Map),
Space += rel(IB, 'IRT_EQ', IB0, Reify). gecode_arith_op( Op, BOP ),
% abs(X) #= NEW, cannot be reified ( var(Reify) ->
out_c(Name, A1, A2, B, Space-Map, Reify) :- Space += rel(IB, BOP, IB0)
var(Reify), !, ;
new_arith( Name, A1, A2, B, Space-Map). Space += rel(IB, BOP, IB0, Reify)
).
new_arith( abs, V, NV, Space-Map) :- new_arith( abs, V, NV, Space-Map) :-
l(V, X, Min0, Max0, Map), l(V, X, Min0, Max0, Map),