element
OPL function to return an indexed element
Purpose
OPL function to return the element
with index n.
| context | type |
|---|---|
| Model files (.mod) - not allowed in a CPLEX constraint block. |
int, float |
Syntax
element(*[range], int n) element(*[range], dexpr int n) element(*[range], dvar int n)
Note that *[range] cannot be a dexpr array.
Description
Returns the element whose index
is n in the flattened view of a map (indexed from
0 to size-1), from where the ranges are extracted. If you use the element function
on an integer array, the type returned is int, on
a float array the type returned is float.
This
function also works for integer arrays outside constraint blocks both
in CP and CPLEX models. You can use this function within IBM ILOG
Script statements by specifying the OPL namespace (Opl.xxx()).
Example
using CP;
{int} s={1,2,3};
int r1=element(all(i in s:i!=1)i,1);
assert r1==3;
dvar boolean x[1..5,1..5] in 0..1;
maximize sum (i,j in 1..5) x[i,j];
subject to
{
element(all(i,j in 1..5)x[i,j],12)==false;
}