element
This function returns an element of a given array indexed by an integer expression for use in a constraint or another expression.
Syntax
floatExpr element(intExpr subscript, floatArray array)
intExpr element(intExpr subscript, intArray array)
intExpr element(intExpr subscript, intExprArray array)
Parameters
-
subscript: an integer expression used to subscript the array -
array: an array in which an element will be selected usingsubscript
Description
This function returns an expression for use in a constraint or other
expression. The semantics of this expression are: when subscript
takes the value i, then the value of the expression is equal to
array[i].
Example
In the following example, the element constraint is used to determine the index, in an array of 3 variables, constrained to assume different values, of the variable whose value is 1.
vars = [intVar(1..3),intVar(1..3), intVar(1..3)];
index = intVar(0..2);
alldiff(vars);
element(index,vars) == 1;