The CLP Procedure

GCC Statement

  • GCC global_cardinality_constraint-1 <…global_cardinality_constraint-n>;

where global_cardinality_constraint is specified in the following form:

(variables) = ( left-parenthesis v 1 comma l 1 comma u 1 right-parenthesis <…left-parenthesis v Subscript n Baseline comma l Subscript n Baseline comma u Subscript n Baseline right-parenthesis> <DL= dl> <DU= du> )

v Subscript i is a value in the domain of one of the variables, and l Subscript i and u Subscript i are the lower and upper bounds on the number of variables assigned to v Subscript i. The values of dl and du are the lower and upper bounds on the number of variables assigned to values outside of StartSet v 1 comma ellipsis comma v Subscript n Baseline EndSet.

The GCC statement specifies one or more global cardinality constraints. A global cardinality constraint (GCC) is a constraint that 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 comma ellipsis comma n Endscripts upper D o 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.

For example, the constraint that is specified with the statements

var (x1-x6) = [1, 4];
gcc(x1-x6) = ((1, 1, 2) (2, 1, 3) (3, 1, 3) (4, 2, 3));

expresses that at least one but no more than two variables in x 1 comma ellipsis comma x 6 can have value 1, at least one and no more than three variables can have value 2 (or value 3), and at least two and no more than three variables can have value 4. For example, an assignment x 1 equals 1 comma x 2 equals 1 comma x 3 equals 2 comma x 4 equals 3 comma x 5 equals 4, and x 6 equals 4 satisfies the constraint.

If a global cardinality constraint has common lower or upper bounds for many of the values in D, the DL= and DU= options can be used to specify the common lower and upper bounds.

For example, the previous specification could also be written as

gcc(x1-x6) = ((1, 1, 2) (4, 2, 3) DL=1 DU=3);

You can also specify missing values for the lower and upper bounds. The values of dl and du are substituted as appropriate. The previous example can also be expressed as

gcc(x1-x6) = ((1, ., 2) (4, 2, .) DL=1 DU=3);

The following statements specify that each of the values in StartSet 1 comma ellipsis comma 9 EndSet can be assigned to at most one of the variables x 1 comma ellipsis comma x 9:

var (x1-x9) = [1, 9];
gcc(x1-x9) = (DL=0 DU=1);

Note that the preceding global cardinality constraint is equivalent to the alldifferent constraint that is expressed as:

var (x1-x9) = [1, 9];
alldiff(x1-x9);

If you do not specify the DL= and DU= options, the default lower and upper bound for any value in D that does not appear in the left-parenthesis v comma l comma u right-parenthesis format is 0 and the number of variables in the constraint, respectively.

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 x 1 comma ellipsis comma x 9 to even numbers between 0 and 10:

 var (x1-x9) = [0, 10];
 gcc(x1-x9) = ((1, 0, 0) (3, 0, 0) (5, 0, 0) (7, 0, 0) (9, 0, 0));

If the variable list is empty, the GCC constraint applies to all the variables.

Last updated: September 16, 2021