Element Constraints for Variable Indexing
Introduces the element constraint in constraint programming, which lets a model express y = v[i] when the index i is itself a decision variable. Covers element constraints with constant arrays, with variable arrays, parallel element constraints for selection modeling, and using element constraints together with restrictions on the target to identify feasible indices.
Tutorial
The Element Constraint
In constraint programming, we often need to express the value at position of a list, where the index is itself a decision variable. Standard indexing requires to be a known integer at modeling time, but a solver only fixes at solve time.
The element constraint resolves this. Given an integer-valued list , an index variable , and a target variable , the call
enforces the relationship
The index is restricted to . Whenever the solver fixes to a particular value, is forced to equal the entry of at that position.
For example, the constraint
forces when , when , and when .
The same logical effect could be obtained with reified constraints, one per possible index value ( (), (), and so on). The element constraint is the compact, solver-friendly way to express the same idea.