The CLP Procedure

FOREACH Statement

FOREACH (array, type, <offset>) ;

where array must be defined by using an ARRAY statement, type is a keyword that determines the type of the constraint, and offset is an integer.

The FOREACH statement iteratively applies a constraint over an array of variables. The type of the constraint is determined by type. Currently, the only valid type keyword is DIFF. The optional offset parameter is an integer and is interpreted in the context of the constraint type. The default value of offset is zero.

The FOREACH statement that corresponds to the DIFF keyword iteratively applies the following constraint to each pair of variables in the array:

\[  \mr {\emph{variable\_ }}i + \mr {\emph{offset}} \times i \:  \ne \:  \mr {\emph{variable\_ }}j + \mr {\emph{offset}} \times j \:  \quad \forall \;  i \ne j, \;  i, j =1,\ldots ,\mr {\emph{array\_ dimension}}  \]

For example, the constraint that all $ (A[i] - i)$’s are pairwise distinct for an array $ A$ is expressed as

foreach (A, diff, -1);