The Constraint Programming Solver

GCC Predicate

  • 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:

variable-list

See the section Common Syntax Components.

set-of-numeric-triplets

The triplets less-than v comma l Subscript v Baseline comma u Subscript v Baseline greater-than provide, for each value v, the minimum l Subscript v and maximum u Subscript v number of times that v can be assigned to the variables in the variable-list. The PROC OPTMODEL option INTFUZZ= determines which values are rounded to integers.

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 StartSet upper X left-bracket 1 right-bracket comma ellipsis comma upper X left-bracket 6 right-bracket EndSet:

  • 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 upper X left-bracket 1 right-bracket equals 1 comma upper X left-bracket 2 right-bracket equals 1 comma upper X left-bracket 3 right-bracket equals 2 comma upper X left-bracket 4 right-bracket equals 3 comma upper X left-bracket 5 right-bracket equals 4, and upper X left-bracket 6 right-bracket equals 4 satisfies the constraint.

In general, a GCC constraint consists of a set of variables StartSet x 1 comma ellipsis comma x Subscript n Baseline EndSet and, for each value v in upper D equals union Underscript i equals 1 Overscript n Endscripts normal upper D normal o normal m left-parenthesis x Subscript i Baseline right-parenthesis, a pair of numbers l Subscript v and u Subscript v. A GCC is satisfied if and only if the number of times that a value v in D is assigned to the variables x 1 comma ellipsis comma x Subscript n Baseline is at least l Subscript v and at most u Subscript v.

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 StartSet 1 comma ellipsis comma 9 EndSet can be assigned to at most one of the variables upper X left-bracket 1 right-bracket comma ellipsis comma upper X left-bracket 9 right-bracket:

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 upper X left-bracket 1 right-bracket comma ellipsis comma upper X left-bracket 9 right-bracket 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>);
Last updated: April 14, 2021