Given N binary variables \(x_{i},x_{i+1},..,x_{i+N}\) exactly \(min \le \alpha \le max\) variables can be equal to 1 and they have to be consecutives. For example \(\{x_{i} = x_{i+1} = x_{i+2} = 1\}\) is a valid solution while \(\{x_{i} = x_{i+1} = x_{i+3} = 1\}\) is not. Any possible way to model this constraint? 
To select \( \alpha \) contiguous variables, you can use an additional binary variable \( s_i \) (start) which is 1 if \( i \) is the initial variable. Then the following constraints should suffice:
\[x_0 = s_0\] Note that the last constraint is necessary otherwise it is possible to obtain undesired assignments, e.g., suppose \(\alpha = 2\) and \( N = 3 \), then \(x=1010\), \(s=0010\) is a feasible noncontiguous solution. I assumed your variables are indexed with \( i \) from 0 to \( N1 \), you might want to tune these indices. BTW, this reminds me of timeindexed scheduling formulations, I am curious: what are you modelling? 2
Thanks! (I will upvote you as soon as I have enough reputation). I am not modeling anything in particular, I am just making up possible scenarios as I want to get deeper into ILP. Did you know the answer by heart or is there any particular way to approach the modeling of particular constraints as this one. Latex Issue: my browser is not formatting $..$ as Latex. Not sure why, it works in similar websites.
(25 Jan '13, 04:51)
memecs
I used a similar formulation for a scheduling problem, I don't remember exactly how I came up with that but I suspect I obtained it after a few reasoning. However yours is an interesting question: how do we model certain constraints? How do we learn to do it? I think this site has many questions and answers about it...
(25 Jan '13, 05:16)
kr1zz
2
I am going to look for them then. By the way setting \(\sum_{i=0}^{N1}s_i = \lambda\) might lead to \(\lambda\) non adjacent blocks of consecutive \(x\)'s. Something like {0,0,1,1,1,0,0,1,1}. That's also pretty interesting.
(25 Jan '13, 08:06)
memecs
1
The LaTeX delimiters here are backslash( or backslash[ (and the corresponding closing delimiter). Also, all backslashes must be escaped (write two consecutive backslashes for each one you need).
(25 Jan '13, 16:03)
Paul Rubin ♦♦
@Xiaodong: you are wrong, it is not obvious! I am kidding, you are right, since constraint 3 does not apply to i=0 odd things can happen. I'll edit the post, thank you.
(28 Jan '13, 03:58)
kr1zz
After discussing with a colleague, I've got a question for you: do you think it would be useful (because it would lead to a tighter linear relaxation) to replace the second constraint with this? $$ \min \sum_{i=0}^{N1}s_i \leq \sum_{i=0}^{N1} x_i = \alpha \leq \max \sum_{i=0}^{N1}s_i $$ (note: min and max are constants, not the minimization or maximization operators)
(27 May '13, 10:15)
kr1zz
I suspect a presolver would convert this back to the original form. If not, it would make the matrix a bit denser. I don't see why the formulation would be tighter.
(27 May '13, 17:06)
Paul Rubin ♦♦
showing 5 of 8
show 3 more comments

The third constraint can be obtained somewhat automatically by rewriting in "conjunctive normal form" as follows:
A useful reference for this is:
answered 25 Jan '13, 13:27 Rob Pratt 