The AllDifferent Constraint
Introduces the AllDifferent global constraint in CP-SAT: its syntax, its equivalence to pairwise inequalities, its propagation advantage, and its use in modeling rows, columns, and other 'distinct values' patterns in combinatorial problems.
Tutorial
The AllDifferent Constraint
The AllDifferent constraint forces a list of integer variables to take pairwise distinct values. In CP-SAT, we add it to a model with
This single call enforces for every pair of indices .
For example, suppose we declare three integer variables each with domain and add . Then must be a permutation of , giving feasible assignments:
Note: If the number of variables exceeds the size of the common domain, the constraint is infeasible. Four variables, all with domain , cannot all be distinct — by pigeonhole, at least two must coincide.