Suppose we have $S=\{1,2,\ldots,n\}$, a binary variable $x$ and an integer $p$. I would like to model the following constraint using integer linear programming:If $x = 1$, then there must exists a unique $i\in S$ such that: $x_j=1$ for all $j\in\{i,i+1,\ldots,i+p-1\}$.How can I do this?
How to model this constraint using integer linear programming?
integer programming
Assuming $x_j$ are binary.The additional binary variable $y_i$ equals one if and only if when all $j$ are 1.$$\sum\limits_{j=i}^{i+p-1}x_j - p+1 \leq y_i \leq \frac{1}{p}\sum\limits_{j=i}^{i+p-1}x_j$$Then to have a unique $y_i$ equals one you add$$x \leq \sum_{i=1}^n y_i \leq (n-1)(1-x)+1$$