How to define constraint for consecutive elements?

99 Views Asked by At

I have a sequence denoted by $\vec{x}=(x_1,\dots,x_M), x_i\in\{1,\dots,N\} $. The sequence $\vec{x}$ can later be encoded into another sequence $\vec{c}=(f(x_1),\dots,f(x_M)), f: \{1,\dots,N\} \mapsto \{1,\dots,L\}$. How to define a constraint so that the sequence $\vec{x}$ is valid only if after the encoding, $\vec{c}$ can have the same numbers if they are consecutive?

For example,

$M=N=5, L=3$

$\vec{c^1}=(3,3,1,2,2)$ is allowed, but

$\vec{c^2}=(3,1,3,2,2)$ is not allowed because the first and the third element is the same but not consecutive,

$\vec{c^3}=(3,3,2,2,2)$ is also allowed.

Thank You.

Edit: I was unclear on which variable to put the constraint on. I was meant to define the constraint on the sequence $\vec{x}$.

1

There are 1 best solutions below

6
On BEST ANSWER

$x_{i}$ is valid if $\nexists j < i$, for which $f(x_{j}) \neq f(x_{i})$, when $\exists k < j$, for which $f(x_{k}) = f(x_{i})$.