next up previous contents index
Next: Reification Up: Programming Constraint Propagation Previous: A constraint interpreter   Contents   Index

Indexicals

Indexicals, which are adopted by many CLP(FD) compilers for compiling constraints, can be implemented easily by using delay clauses. Consider the indexical

    X in min(Y)+min(Z)..max(Y)+max(Z).
This indexical is a primitive constraint that excludes no-good values from the domain of X that do not lie in the range of min(Y)+min(Z)..max(Y)+max(Z). This constraint is reconsidered whenever a bound of Y or Z is updated. The following procedure implements the indexical:

    delay 'V in V+V'(X,Y,Z):-dvar(X) : 
          {ins(Y),min(Y),max(Y),ins(Z),min(Z),max(Z)},
          consistency_check_v_vv(X,Y,Z).
    'V in V+V'(X,Y,Z):-true : 
          consistency_check_v_vv(X,Y,Z).

     consistency_check_v_vv(X,Y,Z):-
          fd_min_max(Y,MinY,MaxY),
          fd_min_max(Z,MinZ,MaxZ),
          MinX is MinY+MinZ,
          MaxX is MaxY+MaxZ,
          X in MinX..MaxX.
The predicate call 'V in V+V'(X,Y,Z) propagates changes from Y and/or Z to X, but not vice versa.



Neng-Fa Zhou
1999-11-24