[ library(gfd) | Reference Manual | Alphabetic Index ]

<ConsistencyModule:> gcc(+Bounds,+Vars)

Constrain the cardinality of each Value according to the specification in Bounds.
Bounds
A list of elements specifying the cardinality of values occurring in Vars of the form gcc(Low,High,Value) or occ(Occ,Value).
Vars
A collection of different (domain) variables or integers

Description

This constraint ensures that the cardinality (the number of occurrences) of values in Vars conforms to the specifications in Bounds. Bounds is a list of specifications in one of the following forms:

gcc(Low,High,Value)
where Value is an integer, a value that Vars is to be assigned to, and must occur only once as a Value in Bounds, and whose cardinality |Value| is specified by Low =< |Value| =< High, where Low and High are non-negative integers.
occ(Occ,Value)
where Value is an integer, a value that Vars is to be assigned to, and must occur only once as a Value in Bounds, and whose cardinality |Value| is specified by Occ. Occ is either a non-negative integer, or a domain variable whose domain are the possible cardinality for Value. Note that if Occ is a non-gfd domain variable, a type error would be raised.

Note that all values that Vars can take must be specified in Bounds.

ConsistencyModule is the optional module specification to give the consistency level for the propagation for this constraint: gfd_gac for generalised arc consistency (domain consistency), gfd_bc for bounds consistency, and gfd_vc for value consistency.

This constraint is known as global_cardinality (occ{} spec) and global_cardinality_low_up (gcc{} spec) in the Global Constraint Catalog, and is implemented using Gecode's count() constraint (variant with two IntVarArgs and an IntArgs). The semantics is different from that given in the catalog, which does not require all values that Vars can take be specified by Bounds.

Examples

[eclipse 2]: gcc([occ{occ:2,value:3},occ{occ:0,value:5},occ{occ:1,value:6}], 
                 [3,3,8,6]).  % fails -- value 8 not specified in Bounds

[eclipse 3]: gcc([occ{occ:2,value:3},occ{occ:0,value:5},occ{occ:1,value:6},
                 gcc{low:0,high:3,value:8}], [3,3,8,6]).  % succeed

See Also

fd_global_gac : gcc / 2, ic_global_gac : gcc / 2