5.216. length_last_sequence

DESCRIPTIONLINKSAUTOMATON
Origin

Inspired by πšœπšπš›πšŽπšπšŒπš‘_πš™πšŠπšπš‘

Constraint

πš•πšŽπš—πšπšπš‘_πš•πšŠπšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽ(𝙻𝙴𝙽,πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚)

Arguments
π™»π™΄π™½πšπšŸπšŠπš›
πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚πšŒπš˜πš•πš•πšŽπšŒπšπš’πš˜πš—(πšŸπšŠπš›-πšπšŸπšŠπš›)
Restrictions
𝙻𝙴𝙽β‰₯0
𝙻𝙴𝙽≀|πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚|
πš›πšŽπššπšžπš’πš›πšŽπš(πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚,πšŸπšŠπš›)
Purpose

𝙻𝙴𝙽 is the length of the maximum sequence of variables that take the same value that contains the last variable of the collection πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚ (or 0 if the collection is empty).

Example
(1,4,4,4,5,5,4)
(6,4,4,4,4,4,4)
(5,2,4,4,4,4,4)

The first πš•πšŽπš—πšπšπš‘_πš•πšŠπšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽ constraint holds since the sequence associated with the last value of the collection πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚=〈4,4,4,5,5,4βŒͺ spans over a single variable.

Typical
𝙻𝙴𝙽<|πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚|
|πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚|>1
Symmetry

All occurrences of two distinct values of πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚.πšŸπšŠπš› can be swapped; all occurrences of a value of πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚.πšŸπšŠπš› can be renamed to any unused value.

Arg. properties

Functional dependency: 𝙻𝙴𝙽 determined by πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚.

Reformulation

Without loss of generality let assume that the collection πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚=〈V 1 ,V 2 ,β‹―,V n βŒͺ has more than one variable. By introducing 2Β·n-1 0-1 variables, the πš•πšŽπš—πšπšπš‘_πš•πšŠπšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽ(𝙻𝙴𝙽,πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚) constraint can be expressed in term of 2Β·n-1 reified constraints and one arithmetic constraint (i.e.,Β  a πšœπšžπš–_πšŒπšπš› constraint). We first introduce n-1 variables that are respectively set to 1 if and only if two given consecutive variables of the collection πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚ are equal:

Β Β Β B n-1,n ⇔V n-1 =V n ,

Β Β Β B n-2,n-1 ⇔V n-2 =V n-1 ,

Β Β Β β‹―β‹―β‹―β‹―β‹―β‹―β‹―β‹―β‹―

Β Β Β B 1,2 ⇔V 1 =V 2 .

We then introduce n variables A n ,A n-1 ,β‹―,A 1 that are respectively associated to the different sliding sequences ending on the last variable of the sequence V 1 V 2 β‹― V n . Variable A i is set to 1 if and only if V n =V n-1 =β‹―=V i :

Β Β Β A n =1,

Β Β Β A n-1 ⇔B n-1,n ∧A n ,

Β Β Β A n-2 ⇔B n-2,n-1 ∧A n-1 ,

Β Β Β β‹―β‹―β‹―β‹―β‹―β‹―β‹―β‹―β‹―

Β Β Β A 1 ⇔B 1,2 ∧A 2 .

Finally we state the following arithmetic constraint:

   𝙻𝙴𝙽=A n +A n-1 +β‹―+A 1 .

Counting
Length (n)2345678
Solutions9646257776117649209715243046721

Number of solutions for πš•πšŽπš—πšπšπš‘_πš•πšŠπšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽ: domains 0..n

ctrs/length_last_sequence-1-tikz

ctrs/length_last_sequence-2-tikz

Length (n)2345678
Total9646257776117649209715243046721
Parameter
value

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

Solution count for πš•πšŽπš—πšπšπš‘_πš•πšŠπšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽ: domains 0..n

ctrs/length_last_sequence-3-tikz

ctrs/length_last_sequence-4-tikz

See also

common keyword: πš•πšŽπš—πšπšπš‘_πšπš’πš›πšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽΒ (counting constraint,sequence).

Keywords

characteristic of a constraint: automaton, automaton with counters.

combinatorial object: sequence.

constraint arguments: reverse of a constraint, pure functional dependency.

constraint network structure: sliding cyclic(1) constraint network(2).

constraint type: value constraint, counting constraint.

filtering: glue matrix.

modelling: functional dependency.

Automaton

FigureΒ 5.216.1 depicts the automaton associated with the πš•πšŽπš—πšπšπš‘_πš•πšŠπšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽ constraint. To each pair of consecutive variables (πš…π™°πš i ,πš…π™°πš i+1 ) of the collection πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚ corresponds a signature variable S i . The following signature constraint links πš…π™°πš i , πš…π™°πš i+1 and S i : πš…π™°πš i = πš…π™°πš i+1 ⇔S i .

Figure 5.216.1. Automaton of the πš•πšŽπš—πšπšπš‘_πš•πšŠπšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽ constraint when |πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚|β‰₯2
ctrs/length_last_sequence-5-tikz
Figure 5.216.2. Hypergraph of the reformulation corresponding to the automaton of the πš•πšŽπš—πšπšπš‘_πš•πšŠπšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽ constraint
ctrs/length_last_sequence-6-tikz
Figure 5.216.3. Automaton of the reverse of the πš•πšŽπš—πšπšπš‘_πš•πšŠπšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽ constraint (i.e.,Β the πš•πšŽπš—πšπšπš‘_πšπš’πš›πšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽ constraint) when |πš…π™°πšπ™Έπ™°π™±π™»π™΄πš‚|β‰₯2 and corresponding glue matrix between πš•πšŽπš—πšπšπš‘_πš•πšŠπšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽ and its reverse πš•πšŽπš—πšπšπš‘_πšπš’πš›πšœπš_πšœπšŽπššπšžπšŽπš—πšŒπšŽ
ctrs/length_last_sequence-7-tikz