## 5.215. length_first_sequence

Origin
Constraint

$\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }\left(\mathrm{\pi »\pi ΄\pi ½},\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\right)$

Arguments
 $\mathrm{\pi »\pi ΄\pi ½}$ $\mathrm{\pi \pi \pi \pi }$ $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }$ $\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 ½}\beta ₯0$ $\mathrm{\pi »\pi ΄\pi ½}\beta €|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }|$ $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi },\mathrm{\pi \pi \pi }\right)$
Purpose

$\mathrm{\pi »\pi ΄\pi ½}$ is the length of the maximum sequence of variables that take the same value that contains the first variable of the collection $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }$ (or 0 if the collection is empty).

Example
 $\left(3,β©4,4,4,5,5,4βͺ\right)$ $\left(6,β©4,4,4,4,4,4βͺ\right)$ $\left(5,β©4,4,4,4,4,1βͺ\right)$

The first $\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$ constraint holds since the sequence associated with the first value of the collection $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }=\beta ©4,4,4,5,5,4\beta ͺ$ spans over three consecutive variables.

Typical
 $\mathrm{\pi »\pi ΄\pi ½}<|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }|$ $|\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }|>1$
Symmetry

All occurrences of two distinct values of $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }.\mathrm{\pi \pi \pi }$ can be swapped; all occurrences of a value of $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }.\mathrm{\pi \pi \pi }$ can be renamed to any unused value.

Arg. properties

Functional dependency: $\mathrm{\pi »\pi ΄\pi ½}$ determined by $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }$.

Reformulation

Without loss of generality let assume that the collection $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }=\beta ©{V}_{1},{V}_{2},\beta ―,{V}_{n}\beta ͺ$ has more than one variable. By introducing $2Β·n-1$ 0-1 variables, the $\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$$\left(\mathrm{\pi »\pi ΄\pi ½},\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }\right)$ constraint can be expressed in term of $2Β·n-1$ reified constraints and one arithmetic constraint (i.e.,Β  a $\mathrm{\pi \pi \pi }_\mathrm{\pi \pi \pi }$ constraint). We first introduce $n-1$ variables that are respectively set to 1 if and only if two given consecutive variables of the collection $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }$ are equal:

Β Β Β ${B}_{1,2}\beta {V}_{1}={V}_{2}$,

Β Β Β ${B}_{2,3}\beta {V}_{2}={V}_{3}$,

Β Β Β $\beta ―\beta ―\beta ―\beta ―\beta ―\beta ―$

Β Β Β ${B}_{n-1,n}\beta {V}_{n-1}={V}_{n}$.

We then introduce $n$ variables ${A}_{1},{A}_{2},\beta ―,{A}_{n}$ that are respectively associated to the different sliding sequences starting on the first variable of the sequence ${V}_{1}{V}_{2}\beta ―{V}_{n}$. Variable ${A}_{i}$ is set to 1 if and only if ${V}_{1}={V}_{2}=\beta ―={V}_{i}$:

Β Β Β ${A}_{1}=1$,

Β Β Β ${A}_{2}\beta {B}_{1,2}\beta §{A}_{1},$

Β Β Β ${A}_{3}\beta {B}_{2,3}\beta §{A}_{2},$

Β Β Β $\beta ―\beta ―\beta ―\beta ―\beta ―\beta ―$

Β Β Β ${A}_{n}\beta {B}_{n-1,n}\beta §{A}_{n-1}$.

Finally we state the following arithmetic constraint:

Β Β Β $\mathrm{\pi »\pi ΄\pi ½}={A}_{1}+{A}_{2}+\beta ―+{A}_{n}$.

Counting
 Length ($n$) 2 3 4 5 6 7 8 Solutions 9 64 625 7776 117649 2097152 43046721

Number of solutions for $\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$: domains $0..n$

Length ($n$)2345678
Total9646257776117649209715243046721
 Parameter value

16485006480100842183500838263752
23121001080144062293764251528
3-420180205828672472392
4--530294358452488
5---6424485832
6----756648
7-----872
8------9

Solution count for $\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$: domains $0..n$

FigureΒ 5.215.1 depicts the automaton associated with the $\mathrm{\pi \pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi }_\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi }$ constraint. To each pair of consecutive variables $\left({\mathrm{\pi  \pi °\pi }}_{i},{\mathrm{\pi  \pi °\pi }}_{i+1}\right)$ of the collection $\mathrm{\pi  \pi °\pi \pi Έ\pi °\pi ±\pi »\pi ΄\pi }$ corresponds a signature variable ${S}_{i}$. The following signature constraint links ${\mathrm{\pi  \pi °\pi }}_{i}$, ${\mathrm{\pi  \pi °\pi }}_{i+1}$ and ${S}_{i}$: ${\mathrm{\pi  \pi °\pi }}_{i}={\mathrm{\pi  \pi °\pi }}_{i+1}\beta {S}_{i}$.