2.3.3.1. Simple graph constraint
To a simple graph constraint correspond several initial graphs, usually one, where all the initial graphs have the same vertices and arcs. Specifying more than one initial graph is usuallyAnother way of generating several initial graphs will be explained later on in the Arc input(s) slot. achieved by using the iterator (e.g.,Β see the definition of the constraint), which takes a collection and generates an initial graph for each item of . In this context, the arc constraints and/or graph properties of an initial graph may depend of the attributes of the item of from which they were generated. All arc constraints attached to a given arcAs we previously said, even though we have more than one initial graph, all vertices and arcs of the different initial graphs are identical. have to be pairwise mutually incompatible.Two arc constraints and are incompatible if there does not exist any tuple of values such that both and hold.
The graphs of a simple graph constraint are defined by the following slots:
An Arc input(s) slot, which consists of:
Either a sequence of collections . To each item of these collections corresponds a vertex of the initial graph (i.e., in this context we generate a single initial graph).
Either a list of sequences of collections. To each item of the collections of a given sequence corresponds a vertex of one of the initial graphs (i.e., in this context we generate one initial graph for each sequence This is for instance the case for the constraint.).
An Arc generator slot, which can be one or several expressionsUsually a single expression. of the following forms:
, where is one of the arc generators with a fixed arityAny arc generator different from and . defined in SectionΒ 2.3.2.3 on page 2.3.2.3, and denotes the item associated with the vertex of an arc. These items correspond to formal parametersSee the description of simple arithmetic expressions page 2.3.2.2.1. which can be used within an arc constraint. When the Arc input(s) slot consists of a single collection , represents an item of the collection . Otherwise, when , we must have and, in this context, represents an item of .
, where is one of the arc generators or . In this context, denotes a collection of items corresponding to the vertices of an arc of the initial graph. An arc constraint forces a restriction on the items of this collection.
EXAMPLE:
The constraint has the following Arc input(s) and Arc generator slots:
Its Arc input(s) slot refers to the collection.
Its Arc generator slot consists of .
In this context, is a collection of the same type as the collection. It corresponds to the variables associated with an arc of the initial graph.
When the Arc generator slot consists of expressions then these expressions have the form:
All leftmost part of the expressions must be the same since they will be involved in a single Arc constraint(s) slot. The constraint is an example of global constraint where more than one arc generator is used.
An Arc arity slot, which corresponds to the number of vertices of each arc of the initial graph. is either a strictly positive integer, an argument of the global constraint of type , or the character *. In this last case, this is used for denoting that all the arc constraints do not involve the same number of vertices. This is for instance the case when we use the arc generators or as in the or the constraints.
An Arc constraint(s) slot, which corresponds to a conjunction of arc constraintsUsually this conjunction consists of a single arc constraint. those were introduced in SectionΒ 2.3.2.2 on page 2.3.2.2.
A Graph property(ies) slot, which corresponds to one or several graph properties (see SectionΒ 2.3.2.4 on page 2.3.2.4) to be satisfied on the final graphs associated with an instantiated solution to the global constraint. To each initial graph corresponds one final graph obtained by removing all arcs for which the corresponding arc constraints do not hold as well as all vertices that do not have any arc.
We now give several examples of descriptions of simple graph constraints, starting from the constraint, which was introduced as a first example of global constraint that can be modelled by a graph property in SectionΒ 2.3.1 on page 2.3.1.
EXAMPLE: The constraint restricts to be the number of distinct values taken by the variables of the collection . Its meaning is described by a simple graph constraint corresponding to the following items:
- Arc input(s)Β Β Β Β Β Β Β Β :
- Arc generatorΒ Β Β Β Β Β :
- Arc arityΒ Β Β Β Β Β Β Β Β Β Β :
2
- Arc constraint(s)Β Β Β :
- Graph property(ies):
Since this description does not use the iterator we generate a single initial graph. Each vertex of this graph corresponds to one item of the collection. Since we use the arc generator we have an arc between each pair of vertices. An arc constraint corresponds to an equality constraint between the two variables that are associated with the extremities of the arc. Finally, the Graph property(ies) slot forces the final graph to have strongly connected components.
EXAMPLE: The constraint forces all variables of the collection to be assigned to 0 or 1. In addition, all variables assigned to value 1 appear contiguously. Its meaning is described by a simple graph constraint corresponding to the following items:
- Arc input(s)Β Β Β Β Β Β Β Β :
- Arc generatorΒ Β Β Β Β Β :
- Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β
- Arc arityΒ Β Β Β Β Β Β Β Β Β Β :
2
- Arc constraint(s)Β Β Β :
- Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β
- Graph property(ies):
Since this description does not use the iterator we generate a single initial graph. Each vertex of this graph corresponds to one item of the collection. Since we use the arc generator we generate an arc from item to item . In addition, since we use the arc generator, we generate also an arc from each item of the collection to itself.We use the arc generator in order to keep in the final graph those isolated variables assigned to 1. This is because isolated vertices with no arcs are always removed from the final graph. The effect of the arc constraint is to keep in the final graph those vertices for which the corresponding variable is assigned to 1. Adjacent variables assigned to 1 form a connected component of the final graph and the graph property forces to have at most one such group of adjacent variables assigned to 1.
EXAMPLE:
The constraint forces that each value be taken by exactly variables of the collection. Its meaning is described by a simple graph constraint corresponding to the following items:
- For all items of :
- Arc input(s)Β Β Β Β Β Β Β Β :
- Arc generatorΒ Β Β Β Β Β :
- Arc arityΒ Β Β Β Β Β Β Β Β Β Β :
1
- Arc constraint(s)Β Β Β :
- Graph property(ies):
Since this description uses the For all items of iterator on the collection we generate an initial graph for each item of the collection (i.e., one graph for each value). Each vertex of an initial graph corresponds to one item of the collection. Since we use the arc generator we have an arc for each vertex. For an initial graph associated with a value an arc constraint on a vertex corresponds to an equality constraint between the variable associated with and the value . Finally, the Graph property(ies) slot forces the final graph to have a given number of vertices (i.e., associated with the attribute ).