[ library(gfd) | Reference Manual | Alphabetic Index ]
# <ConsistencyModule:> element(?Index, +Collection, ?Value)

Value is the Index'th element of the integer collection Collection.
*?Index*
- A (domain) variable or an integer (array notation accepted).
*+Collection*
- A non-empty collection of integers or (domain) variable.
*?Value*
- A (domain) variable or an integer (array notation accepted).

## Description

This constraint can be used in a variety of programs to state a
relation between two domain variables. Collection is a collection of
integers and the constraint states that its Index'th element is equal to
Value, i.e.

Collection_Index = Value

the domain of the other variable is updated accordingly. Index starts from 1.
Note that unlike the element constraint in IC, the values in Collection
can be domain variables as well as integers. Also note that the actual
Gecode constraint has an index that starts from 0 - a dummy element
is added to start of Collection to map Index to ECLiPSe style index
starting from 1. A version of this constraint that uses the native
Gecode indexing is element_g/3.

This constraint can be embedded in a constraint expression in its
functional form (without the last argument).

ConsistencyModule is the optional module specification to give the
consistency level for the propagation for this constraint:
gfd_bc for bounds consistency, and gfd_gac for domain (generalised arc)
consistency.

This constraint is known as element in the global constraint catalog,
and is implemented with Gecode's element() constraint.

### Fail Conditions

Fails if Value is not the Index'th element of Collection.
## Examples

[eclipse 2]: element(I, [1,3,6,3], V).
I = I{[1 .. 4]}
V = V{[1, 3, 6]}
[eclipse 2]: element(I, [1,3,6,3], V), V #\= 3.
I = I{[1, 3]}
V = V{[1, 6]}
[eclipse 2]: X :: [1..10], gfd_gac: element(I, [1,X,6,3], V), V #\= 3.
Z = Z{[1 .. 10]}
I = I{[1 .. 3]}
V = V{[1, 2, 4 .. 10]}

## See Also

element_g / 3, ic : element / 3, ic_symbolic : element / 3, ic_global : element / 3, fd : element / 3