Re: [eclipse-clp-users] negate constraints

From: Thorsten Winterer <thorsten_winterer_at_web.de>
Date: Wed, 31 Mar 2010 15:58:33 +0200
Am 31.03.2010 15:18, schrieb Oliver Shycle:
> Another example for behavior I dont understand is the following:
> X #< 8 => greater_eight(Y)
>
> This raises the error "calling an undefined procedure greater_eight"
> even if it is defined. I gues that is because greater_eight/1 is not
> recognized as a constraint. The operator "=>" however expects a
> constraint?

here's an example how a constraint like "greater_eight(Y)" could be
expressed as a reified constraint:
(this could be beautified, but I think that this version shows the
mechanism quite clearly)

g8(X,Y) :-
    Y #:: 0..1,
    suspend(g8(X,Y,S), 4, [[X,Y]->constrained], S),
    g8(X,Y,S).

:- demon g8/3.

g8(X,Y,S) :-
    (
        get_min(X,Min),
        Min > 8
    ->
        Y #= 1,
        kill_suspension(S)
    ;
        get_max(X,Max),
        Max =< 8
    ->
        Y #= 0,
        kill_suspension(S)
    ;
        Y == 1
    ->
        X #> 8,
        kill_suspension(S)
    ;
        Y == 0
    ->
        X #=< 8,
        kill_suspension(S)
    ;
        % resuspend
        true
    ).


Then you get:

?- [X,Y] #:: 1..10, X #< 8 => g8(Y), X #= 1.
X = 1
Y = Y{[9, 10]}
Yes (0.00s cpu)
?- [X, Y] #:: 1 .. 10, X #< 8 => g8(Y), X #< 9.
X = X{1 .. 8}
Y = Y{1 .. 10}
There are 3 delayed goals.
Yes (0.00s cpu)
?- [X,Y] #:: 1..10, X #< 8 => g8(Y), X #< 9, X #<7.
X = X{1 .. 6}
Y = Y{[9, 10]}
Yes (0.00s cpu)
Received on Wed Mar 31 2010 - 13:58:51 CEST

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET