next up previous index
Next: RIA: ECLiPSe Real Number Up: RANGE: A Basis For Previous: Attribute Structure   Index

Writing Higher Level Constraints

The following example can be taken as a scheme for how to write constraints on top of the facilities of this library. It is a greater-equal constraint for two variables:
ge(X, Y) :- % woken on change of bounds
var_range(X, _, XH),
    var_range(Y, YL, _),
    ( var(X),var(Y) ->
        suspend(ge(X,Y), 3, [X->wake_hi, Y->wake_lo])
    ;
        true),
    lwb(X, YL), upb(Y, XH), % impose new bounds
wake. % execute woken goals here
The constraint wakes when either the upper bound of X or the lower bound of Y changes, and imposes the consequences onto the other variable. When lwb/2 and upb/2 cause further bound changes, that may wake other goals (ie. they have the effect of schedule_suspensions/2) and we therefore have to invoke the waking scheduler wake/0 afterwards.



Warwick Harvey
2004-08-07