2.3.2.1. Collection generators
The vertices of the initial graph are usually directly generated from collections of
items that are arguments of the global constraint under consideration.
However, it sometimes happens that we would like to derive a new collection
from existing arguments of in order to produce the vertices
of the initial graph.
EXAMPLE:
This is for instance the case of the
constraint,
where and are domain variables that we would
like to group as a single item (with two attributes) of a new derived collection.
This is in fact done in order to generate the following initial graph:
The item as well as all items of constitute the
vertices,
There is an arc from to each item of the collection.
Β
We provide the following mechanism for deriving new collections:
In a first phase we declare the name of the new collection as well
as the names of its attributes and their respective types.
This is achieved exactly in the same way as those collections that
are used in the arguments of a global constraint (see page 2.2.2).
EXAMPLE:
Consider again the example of the
constraint.
The declaration
introduces a new collection called
where each item has an and a attribute.
Both attributes correspond to domain variables.
In a second phase we give a list of patterns that are used for generating
the items of the new collection.
A pattern
or
specifies for each attribute of the new collection
how to fill
it. is one of the comparison operators .
When omitted its default value is .
This is done by providing for each attribute
one of the following expression :
A constant.
An argument of the global constraint .
An expression , where is an attribute of a collection ,
such that is an argument of the global constraint or
a derived collection that was previously declared.
An expression of this form is called a direct reference to an attribute of a collection.
An expression , where is an attribute of a
collection , and is an attribute of a collection
such that is an argument of the global constraint or
a derived collection that was previously declared.
An expression of this form is called an indirect reference to an attribute of a collection.
This expression must be compatible with the type declaration of the corresponding attribute
of the new collection.
EXAMPLE:
We continue the example of the
constraint
and the derived collection
.
The pattern
indicates that:
The attribute of the collection will be
generated by using the argument of the constraint.
Since is a domain variable, it is compatible with the
declaration of the new collection.
The attribute of the collection will be
generated by using the argument of the constraint.
is also compatible with the declaration statement of the new collection.
We now describe how we use the pattern for generating the items of a derived
collection. We have the following two cases:
If the pattern
does not contain any direct or indirect reference to an attribute of a collection
then we generate a single item for such
pattern.In this first case the value of is irrelevant.
In this context the value of the attribute
corresponds to a constant, to an argument of the global constraint or to a new derived
collection.
If the pattern
,
where is one of the comparison operators ,
contains one or several direct or indirect references to an attribute of a
collectionThis collection is an argument of the global constraint or corresponds to
a newly derived collection. we denote by:
the set of indices of the positions corresponding to a direct reference to an attribute
of a collection within .
In this context, let
and
respectively denote
the corresponding collections and attributes.
the set of indices of the positions corresponding to an indirect reference to an attribute
of a collection within .
In this context, let
,
and
respectively denote
the corresponding collections, attributes of type collection and attributes.
Let ,
and
respectively denote
the indices sorted in increasing order of
, and .
For each combination of items
,
such that:
we generate an item of the new derived collection
defined by:
We illustrate this generation process on a set of examples.
Each example is described by providing:
The global constraint and its arguments,
The declaration of the new derived collection,
The pattern used for creating an item of the new collection,
The items generated by applying this pattern to the global constraint,
A comment about the generation process.
We first start with four examples that do not mention any references
to an attribute of a collection.
A box surrounds an argument of a global constraint that is mentioned in a generated item.
EXAMPLE
- :
- :
- Β Β Β Β Β Β Β Β Β :
- Β Β :
We generate a single item where the two attributes
and respectively take the first argument
and the third argument of the constraint.
EXAMPLE
- :
- :
- Β Β Β Β Β Β Β Β Β Β :
- Β Β :
We generate a single item where the three attributes ,
and take value 0.
EXAMPLE
- :
- :
- Β Β Β Β Β Β Β Β Β :
- Β Β :
We generate a single item where the unique attribute
takes the first argument of the constraint as its
value.
EXAMPLE
- :
- :
- Β Β Β Β Β Β Β Β Β :
- Β Β :
We generate a single item where the two attributes
and respectively take value 1
and the first argument of the constraint.
We continue with three examples that mention one or several direct references
to an attribute of some collections.
We now need to explicitly give the items of these collections in order
to generate the items of the derived collection.
EXAMPLE
- :
- :
- :
- :
- Β Β Β Β Β Β Β Β Β Β :
As defined in SectionΒ 2.2.2 on page 2.2.2,
is an implicit attribute corresponding to the
position of an item within a collection.
- Β Β :
The pattern mentions three references
, and
to the collections and used in
the arguments of the constraint.
such that
We use an equality since this is the default value
of the comparison operator when we do not use a pattern of the form
.
we generate an item
where:
This leads to the four items listed in the
field.
EXAMPLE
- :
- :
- :
- Β Β Β Β Β Β Β Β Β :
- Β Β :
The two patterns mention the references
,
,
and
of the collection used in
the arguments of the constraint.
,
we generate two items
,
where:
.
This leads to the eight items listed in the
field.
EXAMPLE
- :
- :
- :
- Β Β Β Β Β Β Β Β Β :
- Β Β :
The pattern mentions two references
and
to the collection used in
the arguments of the constraint.
,
such that
We use the comparison operator since we have a pattern
of the form .
we generate the item
where:
.
This leads to the six items listed in the
field.
Β
We finish with an example that mentions an indirect reference
to an attribute of a collection.
EXAMPLE
- :
- :
- :
- Β Β Β Β Β Β Β Β Β Β :
- Β Β :
The pattern mentions the indirect reference
of the collection used in the arguments of the
constraint.
,
we generate the item where:
.
This leads to the eight items listed in the
field.