## 5.103. cycle

Origin
Constraint

$\mathrm{\pi \pi ’\pi \pi \pi }\left(\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄},\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }\right)$

Arguments
 $\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}$ $\mathrm{\pi \pi \pi \pi }$ $\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi \pi \pi \pi \pi ‘}-\mathrm{\pi \pi \pi },\mathrm{\pi \pi \pi \pi }-\mathrm{\pi \pi \pi \pi }\right)$
Restrictions
 $\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}\beta ₯1$ $\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}\beta €|\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }|$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi },\left[\mathrm{\pi \pi \pi \pi \pi ‘},\mathrm{\pi \pi \pi \pi }\right]\right)$ $\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }.\mathrm{\pi \pi \pi \pi \pi ‘}\beta ₯1$ $\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }.\mathrm{\pi \pi \pi \pi \pi ‘}\beta €|\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }|$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi },\mathrm{\pi \pi \pi \pi \pi ‘}\right)$ $\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }.\mathrm{\pi \pi \pi \pi }\beta ₯1$ $\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }.\mathrm{\pi \pi \pi \pi }\beta €|\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }|$
Purpose

Consider a digraph $G$ described by the $\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }$ collection. $\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}$ is equal to the number of circuits for covering $G$ in such a way that each vertex of $G$ belongs to a single circuit. $\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}$ can also be interpreted as the number of cycles of the permutation associated with the successor variables of the $\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }$ collection.

Example
 $\left(\begin{array}{c}2,β©\begin{array}{cc}\mathrm{\pi \pi \pi \pi \pi ‘}-1\hfill & \mathrm{\pi \pi \pi \pi }-2,\hfill \\ \mathrm{\pi \pi \pi \pi \pi ‘}-2\hfill & \mathrm{\pi \pi \pi \pi }-1,\hfill \\ \mathrm{\pi \pi \pi \pi \pi ‘}-3\hfill & \mathrm{\pi \pi \pi \pi }-5,\hfill \\ \mathrm{\pi \pi \pi \pi \pi ‘}-4\hfill & \mathrm{\pi \pi \pi \pi }-3,\hfill \\ \mathrm{\pi \pi \pi \pi \pi ‘}-5\hfill & \mathrm{\pi \pi \pi \pi }-4\hfill \end{array}βͺ\hfill \end{array}\right)$ $\left(\begin{array}{c}1,β©\begin{array}{cc}\mathrm{\pi \pi \pi \pi \pi ‘}-1\hfill & \mathrm{\pi \pi \pi \pi }-2,\hfill \\ \mathrm{\pi \pi \pi \pi \pi ‘}-2\hfill & \mathrm{\pi \pi \pi \pi }-5,\hfill \\ \mathrm{\pi \pi \pi \pi \pi ‘}-3\hfill & \mathrm{\pi \pi \pi \pi }-1,\hfill \\ \mathrm{\pi \pi \pi \pi \pi ‘}-4\hfill & \mathrm{\pi \pi \pi \pi }-3,\hfill \\ \mathrm{\pi \pi \pi \pi \pi ‘}-5\hfill & \mathrm{\pi \pi \pi \pi }-4\hfill \end{array}βͺ\hfill \end{array}\right)$ $\left(\begin{array}{c}5,β©\begin{array}{cc}\mathrm{\pi \pi \pi \pi \pi ‘}-1\hfill & \mathrm{\pi \pi \pi \pi }-1,\hfill \\ \mathrm{\pi \pi \pi \pi \pi ‘}-2\hfill & \mathrm{\pi \pi \pi \pi }-2,\hfill \\ \mathrm{\pi \pi \pi \pi \pi ‘}-3\hfill & \mathrm{\pi \pi \pi \pi }-3,\hfill \\ \mathrm{\pi \pi \pi \pi \pi ‘}-4\hfill & \mathrm{\pi \pi \pi \pi }-4,\hfill \\ \mathrm{\pi \pi \pi \pi \pi ‘}-5\hfill & \mathrm{\pi \pi \pi \pi }-5\hfill \end{array}βͺ\hfill \end{array}\right)$
• In the first example we have the following 2 ($\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}=2$) cycles: $1\beta ¦2\beta ¦1$ and $3\beta ¦5\beta ¦4\beta ¦3$. Consequently, the corresponding $\mathrm{\pi \pi ’\pi \pi \pi }$ constraint holds.

• In the second example we have 1 ($\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}=1$) cycle: $1\beta ¦2\beta ¦5\beta ¦4\beta ¦3\beta ¦1$.

• In the third example we have the following 5 ($\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}=5$) cycles: $1\beta ¦1$, $2\beta ¦2$, $3\beta ¦3$, $4\beta ¦4$ and $5\beta ¦5$.

All solutions

FigureΒ 5.103.1 gives all solutions to the following non ground instance of the $\mathrm{\pi \pi ’\pi \pi \pi }$ constraint: $N\beta \left[1,2\right]$, ${V}_{1}\beta \left[2,4\right]$, ${V}_{2}\beta \left[2,3\right]$, ${V}_{3}\beta \left[1,6\right]$, ${V}_{4}\beta \left[2,5\right]$, ${V}_{5}\beta \left[2,3\right]$, ${V}_{6}\beta \left[1,6\right]$, $\mathrm{\pi \pi ’\pi \pi \pi }$$\left(N,\beta ©1{V}_{1},2{V}_{2},3{V}_{3},4{V}_{4},5{V}_{5},6{V}_{6}\beta ͺ\right)$.

Typical
 $\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}<|\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }|$ $|\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }|>2$
Symmetries
• Items of $\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }$ are permutable.

• Attributes of $\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }$ are permutable w.r.t. permutation $\left(\mathrm{\pi \pi \pi \pi \pi ‘},\mathrm{\pi \pi \pi \pi }\right)$ (permutation applied to all items).

Arg. properties

Functional dependency: $\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}$ determined by $\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }$.

Usage

The PhD thesis of ΓricΒ BourreauΒ [Bourreau99] mentions the following applications of extensions of the $\mathrm{\pi \pi ’\pi \pi \pi }$ constraint:

• The balanced Euler knight problem where one tries to cover a rectangular chessboard of size $NΒ·M$ by $C$ knights that all have to visit between $2Β·\beta \beta \left(NΒ·M\right)/C\beta /2\beta $ and $2Β·\beta \beta \left(NΒ·M\right)/C\beta /2\beta $ distinct locations. For some values of $N$, $M$ and $C$ there does not exist any solution to the previous problem. This is for instance the case when $N=M=C=6$. FigureΒ 5.103.2 depicts the graph associated with the $6\Gamma 6$ chessboard as well as examples of balanced solutions with respectively 1, 2, 3, 4 and 5 knights.

• Some pick-up delivery problems where a fleet of vehicles has to transport a set of orders. Each order is characterised by its initial location, its final destination and its weight. In addition one also has to take into account the capacity of the different vehicles.

Remark

In the original $\mathrm{\pi \pi ’\pi \pi \pi }$ constraint of CHIP the $\mathrm{\pi \pi \pi \pi \pi ‘}$ attribute was not explicitly present. It was implicitly defined as the position of a variable in a list.

In an early version of the CHIP there was a constraint named $\mathrm{\pi \pi \pi \pi \pi \pi \pi }$ that, from a declarative point of view, was equivalent to $\mathrm{\pi \pi ’\pi \pi \pi }\left(1,\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }\right)$. In ALICE [Lauriere78] the $\mathrm{\pi \pi \pi \pi \pi \pi \pi }$ constraint was also present.

Given a complete digraph of $n$ vertices as well as an unrestricted number of circuits $\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}$, the total number of solutions to the corresponding $\mathrm{\pi \pi ’\pi \pi \pi }$ constraint corresponds to the sequence A000142 of the On-Line Encyclopaedia of Integer SequencesΒ [Sloane10]. Given a complete digraph of $n$ vertices as well as a fixed number of circuits $\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}$ between 1 and $n$, the total number of solutions to the corresponding $\mathrm{\pi \pi ’\pi \pi \pi }$ constraint corresponds to the so called Stirling number of first kind.

Algorithm

Since all $\mathrm{\pi \pi \pi \pi }$ variables have to take distinct values one can reuse the algorithms associated with the $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint. A second necessary condition is to have no more than $\stackrel{Β―}{\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}}$ strongly connected components. Pruning for enforcing this condition, as soon as we have $\stackrel{Β―}{\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}}$ strongly connected components, can be done by forcing all strong bridges to belong to the final solution, since otherwise we would have more than $\stackrel{Β―}{\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}}$ strongly connected components. Since all the vertices of a circuit belong to the same strongly connected component an arc going from one strongly connected component to another strongly connected component has to be removed.

Reformulation

Let $n$ and ${s}_{1},{s}_{2},\beta ―,{s}_{n}$ respectively denotes the number of vertices (i.e., $|\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }|$) and the successor variables associated with vertices $1,2,\beta ―,n$. The $\mathrm{\pi \pi ’\pi \pi \pi }$ constraint can be reformulated as a conjunction of one $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraint, $nΒ·\left(n-1\right)$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi }$ constraints, $n$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi }$ constraints, and one $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint.

Counting
 Length ($n$) 2 3 4 5 6 7 8 9 10 Solutions 2 6 24 120 720 5040 40320 362880 3628800

Number of solutions for $\mathrm{\pi \pi ’\pi \pi \pi }$: domains $0..n$

Length ($n$)2345678910
Total26241207205040403203628803628800
 Parameter value

112624120720504040320362880
21311502741764130681095841026576
3-16352251624131321181241172700
4--11085735676967284723680
5---115175196022449269325
6----121322453663273
7-----1285469450
8------136870
9-------145
10--------1

Solution count for $\mathrm{\pi \pi ’\pi \pi \pi }$: domains $0..n$

related: $\mathrm{\pi \pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi ’\pi \pi \pi }$Β (counting number of cycles versus controlling how balanced the cycles are).

specialisation: $\mathrm{\pi \pi \pi \pi \pi \pi \pi }$Β ($\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}$ set to 1).

Keywords
Cond. implications

$\beta ’$ $\mathrm{\pi \pi ’\pi \pi \pi }\left(\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄},\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }\right)$

Β Β Β  withΒ  $\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}=1$

Β Β implies $\mathrm{\pi \pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi ’\pi \pi \pi }$$\left(\mathrm{\pi ±\pi °\pi »\pi °\pi ½\pi ²\pi ΄},\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }\right)$

Β Β Β  whenΒ  $\mathrm{\pi ±\pi °\pi »\pi °\pi ½\pi ²\pi ΄}=0$.

$\beta ’$ $\mathrm{\pi \pi ’\pi \pi \pi }\left(\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄},\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }\right)$

Β Β implies $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }:\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }\right)$.

Arc input(s)

$\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }$

Arc generator
$\mathrm{\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 }\mathtt{1},\mathrm{\pi \pi \pi \pi \pi }\mathtt{2}\right)$

Arc arity
Arc constraint(s)
$\mathrm{\pi \pi \pi \pi \pi }\mathtt{1}.\mathrm{\pi \pi \pi \pi }=\mathrm{\pi \pi \pi \pi \pi }\mathtt{2}.\mathrm{\pi \pi \pi \pi \pi ‘}$
Graph property(ies)
 $\beta ’$$\mathrm{\pi \pi \pi \pi \pi }$$=0$ $\beta ’$$\mathrm{\pi \pi \pi }$$=\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}$

Graph class
$\mathrm{\pi Ύ\pi ½\pi ΄}_\mathrm{\pi \pi \pi ²\pi ²}$

Graph model

From the restrictions and from the arc constraint, we deduce that we have a bijection from the successor variables to the values of interval $\left[1,|\mathrm{\pi ½\pi Ύ\pi ³\pi ΄\pi }|\right]$. With no explicit restrictions it would have been impossible to derive this property.

In order to express the binary constraint that links two vertices one has to make explicit the identifier of the vertices. This is why the $\mathrm{\pi \pi ’\pi \pi \pi }$ constraint considers objects that have two attributes:

• One fixed attribute $\mathrm{\pi \pi \pi \pi \pi ‘}$ that is the identifier of the vertex,

• One variable attribute $\mathrm{\pi \pi \pi \pi }$ that is the successor of the vertex.

The graph property $\mathrm{\pi \pi \pi \pi \pi }$ $=$ 0 is used in order to avoid having vertices that both do not belong to a circuit and have at least one successor located on a circuit. This concretely means that all vertices of the final graph should belong to a circuit.

PartsΒ (A) andΒ (B) of FigureΒ 5.103.3 respectively show the initial and final graph associated with the first example of the Example slot. Since we use the $\mathrm{\pi \pi \pi }$ graph property, we show the two connected components of the final graph. The constraint holds since all the vertices belong to a circuit (i.e., $\mathrm{\pi \pi \pi \pi \pi }$ $=$ 0) and since $\mathrm{\pi ½\pi ²\pi \pi ²\pi »\pi ΄}$ $=$ $\mathrm{\pi \pi \pi }$ $=$ 2.

Quiz

Β Β

$\mathrm{\pi \pi ’\pi \pi \pi }$: checking whether a ground instance holds or not Β

$\mathrm{\pi \pi ’\pi \pi \pi }$: finding all solutions Β

$\mathrm{\pi \pi ’\pi \pi \pi }$: identifying infeasible values Β

$\mathrm{\pi \pi ’\pi \pi \pi }$: variable-based degree of violation Β

$\mathrm{\pi \pi ’\pi \pi \pi }$: DeΒ Bruijn sequence Β

Β

Β

Β

Β