How to write a Mixed Integer program for a streak?

121 Views Asked by At

I have a list x(variable in MIP) of outcomes.

x = [1,-1,-1,-1,1,1,-1,1,1,1,1,-1,1,-1,-1,1]

1 represent a win and -1 represent a loss. In this case the max winning streak is 4 and max losing streak is 3, thus overall max streak is 4.

How can we formulate an MIP where the objective is to minimize maximum overall streak?

How should the constraints look like?

1

There are 1 best solutions below

6
On BEST ANSWER

Let $z$ represent the maximum streak length. The problem is to minimize $z$ subject to \begin{align} z &\ge k\left(\sum_{j=t}^{t+k-1} x_j - k + 1\right) &&\text{for all $k,t$}\tag1\\ z &\ge k\left(-\sum_{j=t}^{t+k-1} x_j - k + 1\right) &&\text{for all $k,t$}\tag2 \end{align} Constraint $(1)$ forces $z\ge k$ if $x_t=\dots=x_{t+k-1}=1$. Constraint $(2)$ forces $z\ge k$ if $x_t=\dots=x_{t+k-1}=-1$.


For the other part, just take $x_j = a_j b_j$, where $a_j,b_j,x_j\in\{-1,1\}$ and the value of each $a_j$ is known.