alldifferent

Tags:

Updated:

alldifferent implements the constraint that all elements are different

Syntax

F = alldifferent(X)


Examples

The following example finds an integer vector with all numbers between 1 and 5.

x = intvar(5,1);
F = [alldifferent(x), 1<=x<=5];
optimize(F)
value(x)


Comments

Since alldifferent is implemented using a big-M approach, it is crucial that all involved variables have explicit bound constraints. Additionally, it only makes numerical sense to apply the operator on integer valued variables.

Applying alldifferent on a variable with $$n$$ variables will introduce $$n(n-1)/2$$ binary variables.