allDifferent
OPL function to constrain all integer variables in an array to have different values.
context | type |
---|---|
Model files (.mod) - Not allowed in a CPLEX® constraint block |
boolean (1 if the constraint is true, 0 otherwise) |
Syntax
allDifferent(int[ ]) allDifferent(dvar int[ ])
Description
This constraint implies that all the integer variables contained in the array given as an argument take different values. 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() )
Note: This constraint cannot be used in a meta-constraint.
Example
using CP;
int n = 5;
range R = 1..n;
dvar int x[R] in R;
subject to {
allDifferent(all (i in R : i%2 == 0) x[i] );
allDifferent(all (i in R : i%2 == 1) x[i] );
}