next up previous contents index
Next: The alldifferent constraint Up: Constraints on Arrays Previous: Constraints on Arrays

The for constraint

We some times want to impose constraints on each element in an array. DJ provides for constraints for this purpose. A for constraint has the following form:
   for (Enumerator, ... ,Enumerator) Constraint;
where Enumerator is an enumerator constraint. Let Vars be the set of variables apprearing in all the enumerator constraints. This statement means that for each tuple of values for vars that satisfies the enumerator constraints, Constraint must be satisfied.    

For example, the component declaration:

       dj Label lbs[3]{{text == "zero"},
                              {text == "one"},
                              {text == "two"}};
can be defined equivalently as follows:
       dj Label lbs[3];
       for (i in 0..2) {
           i==0 -> labs[i].text == "zero";
           i==1 -> labs[i].text == "one";
           i==2 -> labs[i].text == "two";
       }

When an enumerator constraint is an arithmetic constraint that cannot be tested because the variables involved have not yet been sufficiently instantiated, then the evaluation will be delayed until the constraint is testable.


Neng-Fa Zhou
1999-02-16