5.371. sort
DESCRIPTION | LINKS | GRAPH |
- Origin
- Constraint
- Synonyms
, , .
- Arguments
- Restrictions
- Purpose
First, the variables of the collection correspond to a permutation of the variables of . Second, the variables of are sorted in increasing order.
- Example
-
The constraint holds since:
Values 1, 2, 5 and 9 have the same number of occurrences within both collections and . FigureΒ 5.371.1 illustrates this correspondence.
The items of collection are sorted in increasing order.
Figure 5.371.1. Illustration of the correspondence between the items of the and of the collections of the Example slot (note that the items of the are sorted in increasing order)
- All solutions
FigureΒ 5.371.2 gives all solutions to the following non ground instance of the constraint: , , , , , , , , , , .
Figure 5.371.2. All solutions corresponding to the non ground example of the constraint of the All solutions slot
- Typical
- Symmetries
Items of are permutable.
One and the same constant can be added to the attributes of all items of and .
- Arg. properties
Functional dependency: determined by .
- Usage
The main usage of the constraint, that was not foreseen when the constraint was invented, is its use in many reformulations. Many constraints involving one or several collections of variables become much simpler to express when the variables of these collections are sorted. In addition these reformulations typically have a size that is linear in the number of variables of the original constraint. This justifies why the constraint is considered to be a core constraint. As illustrative examples of these types of reformulations we successively consider the and the constraints:
- Remark
A variant of this constraint called was introduced inΒ [Zhou97]. In this variant an additional list of domain variables represents the permutation that allows to go from to .
- Algorithm
- Systems
sorting in Choco, sorted in Gecode, sort in MiniZinc, sorting in SICStus.
- See also
generalisation: Β ( parameter added).
implies: , .
- Keywords
characteristic of a constraint: core, sort.
combinatorial object: permutation.
constraint arguments: constraint between two collections of variables, pure functional dependency.
- Arc input(s)
- Arc generator
-
- Arc arity
- Arc constraint(s)
- Graph property(ies)
-
- Arc input(s)
- Arc generator
-
- Arc arity
- Arc constraint(s)
- Graph property(ies)
-
- Graph model
PartsΒ (A) andΒ (B) of FigureΒ 5.371.3 respectively show the initial and final graph associated with the first graph constraint of the Example slot. Since it uses the and graph properties, the source and sink vertices of this final graph are stressed with a double circle. Since there is a constraint on each connected component of the final graph we also show the different connected components. The constraint holds since:
Each connected component of the final graph of the first graph constraint has the same number of sources and of sinks.
The number of sources of the final graph of the first graph constraint is equal to .
The number of sinks of the final graph of the first graph constraint is equal to .
Finally the second graph constraint holds also since its corresponding final graph contains exactly arcs: all the inequalities constraints between consecutive variables of holds.
Figure 5.371.3. Initial and final graph of the constraint
(a) (b) - Signature
Consider the first graph constraint. Since the initial graph contains only sources and sinks, and since isolated vertices are eliminated from the final graph, we make the following observations:
Sources of the initial graph cannot become sinks of the final graph,
Sinks of the initial graph cannot become sources of the final graph.
From the previous observations and since we use the arc generator on the collections and , we have that the maximum number of sources and sinks of the final graph is respectively equal to and . Therefore we can rewrite to and simplify to . In a similar way, we can rewrite to and simplify to .
Consider now the second graph constraint. Since we use the arc generator with an arity of 2 on the collection, the maximum number of arcs of the final graph is equal to . Therefore we can rewrite the graph property to and simplify to .
- Quiz
Β Β
: checking whether a ground instance holds or not Β
: finding all solutions
Β