## 5.313. sort

Origin
Constraint

$\mathrm{\pi \pi \pi \pi }\left(\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1},\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}\right)$

Synonyms

$\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$, $\mathrm{\pi \pi \pi \pi \pi \pi }$, $\mathrm{\pi \pi \pi \pi \pi \pi \pi }$.

Arguments
 $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi }-\mathrm{\pi \pi \pi \pi }\right)$ $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi }-\mathrm{\pi \pi \pi \pi }\right)$
Restrictions
 $|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}|=|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}|$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1},\mathrm{\pi \pi \pi }\right)$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2},\mathrm{\pi \pi \pi }\right)$
Purpose

The variables of the collection $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}$ correspond to the variables of $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}$ according to a permutation. The variables of $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}$ are also sorted in increasing order.

Example
$\left(\begin{array}{c}β©\begin{array}{c}\mathrm{\pi \pi \pi }-1,\hfill \\ \mathrm{\pi \pi \pi }-9,\hfill \\ \mathrm{\pi \pi \pi }-1,\hfill \\ \mathrm{\pi \pi \pi }-5,\hfill \\ \mathrm{\pi \pi \pi }-2,\hfill \\ \mathrm{\pi \pi \pi }-1\hfill \end{array}βͺ,\hfill \\ β©\begin{array}{c}\mathrm{\pi \pi \pi }-1,\hfill \\ \mathrm{\pi \pi \pi }-1,\hfill \\ \mathrm{\pi \pi \pi }-1,\hfill \\ \mathrm{\pi \pi \pi }-2,\hfill \\ \mathrm{\pi \pi \pi }-5,\hfill \\ \mathrm{\pi \pi \pi }-9\hfill \end{array}βͺ\hfill \end{array}\right)$

The $\mathrm{\pi \pi \pi \pi }$ constraint holds since:

• Values 1, 2, 5 and 9 have the same number of occurrences within both collections $\beta ©1,9,1,5,2,1\beta ͺ$ and $\beta ©1,1,1,2,5,9\beta ͺ$. FigureΒ 5.313.1 illustrates this correspondence.

• The items of collection $\beta ©1,1,1,2,5,9\beta ͺ$ are sorted in increasing order.

Symmetries
• Items of $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}$ are permutable.

• One and the same constant can be added to the $\mathrm{\pi \pi \pi }$ attributes of all items of $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}$ and $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}$.

Remark

A variant of this constraint was introduced inΒ [Zhou97]. In this variant an additional list of domain variables represents the permutation that allows to go from $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}$ to $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}$.

Algorithm
Systems

generalisation: $\mathrm{\pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$Β ($\mathrm{\pi Ώ\pi ΄\pi \pi Ό\pi \pi \pi °\pi \pi Έ\pi Ύ\pi ½}$ parameter added).

Keywords
Arc input(s)

$\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}$ $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}$

Arc generator
$\mathrm{\pi \pi  \pi \pi ·\pi \pi Ά\pi }$$\beta ¦\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }\mathtt{1},\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }\mathtt{2}\right)$

Arc arity
Arc constraint(s)
$\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }\mathtt{1}.\mathrm{\pi \pi \pi }=\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }\mathtt{2}.\mathrm{\pi \pi \pi }$
Graph property(ies)
 $\beta ’\text{for}\text{all}\text{connected}\text{components:}$$\mathrm{\pi \pi \pi \pi \pi \pi \pi }$$=$$\mathrm{\pi \pi \pi \pi \pi }$ $\beta ’$$\mathrm{\pi \pi \pi \pi \pi \pi \pi }$$=|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}|$ $\beta ’$$\mathrm{\pi \pi \pi \pi \pi }$$=|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}|$

Arc input(s)

$\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}$

Arc generator
$\mathrm{\pi \pi ΄\pi \pi »}$$\beta ¦\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }\mathtt{1},\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }\mathtt{2}\right)$

Arc arity
Arc constraint(s)
$\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }\mathtt{1}.\mathrm{\pi \pi \pi }\beta €\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi }\mathtt{2}.\mathrm{\pi \pi \pi }$
Graph property(ies)
$\mathrm{\pi \pi \pi \pi }$$=|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}|-1$

Graph model

PartsΒ (A) andΒ (B) of FigureΒ 5.313.2 respectively show the initial and final graph associated with the first graph constraint of the Example slot. Since it uses the $\mathrm{\pi \pi \pi \pi \pi \pi \pi }$ and $\mathrm{\pi \pi \pi \pi \pi }$ 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 $\mathrm{\pi \pi \pi \pi }$ 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 $|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}|$.

• The number of sinks of the final graph of the first graph constraint is equal to $|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}|$.

• Finally the second graph constraint holds also since its corresponding final graph contains exactly $|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}-1|$ arcs: all the inequalities constraints between consecutive variables of $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}$ holds.

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 $\mathrm{\pi \pi  \pi \pi ·\pi \pi Ά\pi }$ arc generator on the collections $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}$ and $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}$, we have that the maximum number of sources and sinks of the final graph is respectively equal to $|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}|$ and $|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}|$. Therefore we can rewrite $\mathrm{\pi \pi \pi \pi \pi \pi \pi }=|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}|$ to $\mathrm{\pi \pi \pi \pi \pi \pi \pi }\beta ₯|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{1}|$ and simplify $\underset{Μ²}{\stackrel{Β―}{\mathrm{\pi \pi \pi \pi \pi \pi \pi }}}$ to $\stackrel{Β―}{\mathrm{\pi \pi \pi \pi \pi \pi \pi }}$. In a similar way, we can rewrite $\mathrm{\pi \pi \pi \pi \pi }=|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}|$ to $\mathrm{\pi \pi \pi \pi \pi }\beta ₯|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}|$ and simplify $\underset{Μ²}{\stackrel{Β―}{\mathrm{\pi \pi \pi \pi \pi }}}$ to $\stackrel{Β―}{\mathrm{\pi \pi \pi \pi \pi }}$.

Consider now the second graph constraint. Since we use the $\mathrm{\pi \pi ΄\pi \pi »}$ arc generator with an arity of 2 on the $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}$ collection, the maximum number of arcs of the final graph is equal to $|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}|-1$. Therefore we can rewrite the graph property $\mathrm{\pi \pi \pi \pi }=|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}|-1$ to $\mathrm{\pi \pi \pi \pi }\beta ₯|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\mathtt{2}|-1$ and simplify $\underset{Μ²}{\stackrel{Β―}{\mathrm{\pi \pi \pi \pi }}}$ to $\stackrel{Β―}{\mathrm{\pi \pi \pi \pi }}$.