2
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ Is $x$ a scalar or a vector? $\endgroup$ – Rodrigo de Azevedo Apr 11 '17 at 9:07
  • $\begingroup$ $x$ is a scalar $\endgroup$ – Zir Apr 12 '17 at 1:24
3
$\begingroup$

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 $$

$\endgroup$
  • $\begingroup$ Can be done hopefully better (tighter) if the objective is known. $\endgroup$ – Eugene Apr 10 '17 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.