GCC (variable-list,set-of-numeric-triplets)
The GCC predicate specifies a global cardinality constraint (GCC), which sets the minimum and maximum number of times each value can be assigned to a group of variables.
The syntax of the GCC constraint consists of two parts:
Consider the following statements:
var X {1..6} >= 1 <= 4 integer; con Mycon: gcc(X, /<1,1,2>, <2,1,3>, <3,1,3>, <4,2,3>/);
These statements specify a constraint that expresses the following requirements about the values of variables :
The value 1 must appear at least once but no more than twice.
The value 2 must appear at least once but no more than three times.
The value 3 must appear at least once but no more than three times.
The value 4 must appear at least twice but no more than three times.
The assignment , and satisfies the constraint.
In general, a GCC constraint consists of a set of variables and, for each value v in , a pair of numbers and . A GCC is satisfied if and only if the number of times that a value v in D is assigned to the variables is at least and at most .
Values in the domain of variable-list that do not appear in any triplet are unconstrained. They can be assigned to as many of the variables in variable-list as needed to produce a feasible solution.
The following statements specify that each of the values in the set can be assigned to at most one of the variables :
var X {1..9} >= 1 <= 9 integer; con Mycon: gcc(X, setof{i in 1..9} <i,0,1>);
Note that the preceding global cardinality constraint is equivalent to the all-different constraint that is expressed as follows:
var X {1..9} >= 1 <= 9 integer; con Mycon: alldiff(X);
The global cardinality constraint also provides a convenient way to define disjoint domains for a set of variables. For example, the following syntax limits assignment of the variables to even numbers between 0 and 10:
var X {1..9} >= 0 <= 10 integer; con Mycon: gcc(X, setof{i in 1..9 by 2} <i,0,0>);