Indexicals

Indexicals, which are adopted by many CLP(FD) compilers for compiling constraints, can be easily implemented by using action rules. Consider the indexical
      X in min(Y)+min(Z)..max(Y)+max(Z).
which ensures that the constraint X #= Y+Z is interval-consistent on X. The indexical is activated whenever a bound of Y or Z is updated. The following shows the implementation in action rules:
    'V in V+V'(X,Y,Z),{generated,ins(Y),bound(Y),ins(Z),bound(Z)} =>
          reduce_domain(X,Y,Z).

    reduce_domain(X,Y,Z) =>
          fd_min_max(Y,MinY,MaxY),
          fd_min_max(Z,MinZ,MaxZ),
          L is MinY+MinZ, U is MaxY+MaxZ,
          X in L..U.
The action reduce_domain(X,Y,Z) is executed whenever a variable is instantiated, or whenever a variable's bound is updated. The original indexical is equivalent to the following call:
    'V in V+V'(X,Y,Z)
Because of the existence of generated in the action rule, interval-consistency is also enforced on X when the constraint is generated.



Neng-Fa Zhou 2013-01-25