The Constraint Programming Solver

ALLDIFF Predicate

The ALLDIFF predicate defines an all-different constraint, which defines a unique global constraint on a set of variables that requires all of them to be different from each other. A global constraint is equivalent to a conjunction of elementary constraints.

The syntax of the all-different constraint consists of one part, a variable-list, which is defined in the section Common Syntax Components. For example, the statements

var X{1..3} integer, A integer, B integer;
con AD1: alldiff({j in 1..3} X[j]);
con AD2: alldiff(A B);

are equivalent to

StartLayout 1st Row 1st Column upper X left-bracket 1 right-bracket 2nd Column not-equals 3rd Column upper X left-bracket 2 right-bracket normal upper A normal upper N normal upper D 2nd Row 1st Column upper X left-bracket 2 right-bracket 2nd Column not-equals 3rd Column upper X left-bracket 3 right-bracket normal upper A normal upper N normal upper D 3rd Row 1st Column upper X left-bracket 1 right-bracket 2nd Column not-equals 3rd Column upper X left-bracket 3 right-bracket normal upper A normal upper N normal upper D 4th Row 1st Column upper A 2nd Column not-equals 3rd Column upper B EndLayout

To apply the all-different constraint to all the variables, use the problem symbol _VAR_ as follows:

con alldiff(_VAR_);

For a description of problem symbols, see the section Problem Symbols in Chapter 9, The OPTMODEL Procedure.

Last updated: September 09, 2026