Hi, I want to be able to solve a linear program that has constraints that are either zero or a range. An example below in LP\_Solve-like syntax shows what I want to do. This doesnt work. In general all the decision variables Qx can be 0 or a <= Qx <= b where a > 0 and b > a. All decision variables must be integers.


`max: 0.2 Q1 + 0.4 Q2 + 0.6 Q3 + 0.8 Q4 + 0.4 Q5 + 0.6 Q6 + 0.6 Q7 + 0.7 Q8;`


Q1 = 0 or Q1 >= 5;   

Q2 = 0 or Q2 >= 1;   

Q3 = 0 or Q3 >= 1;   

Q4 = 0 or Q4 >= 1;   

Q5 = 0 or Q5 >= 1;   

Q6 = 0 or Q6 >= 1;   

Q7 = 0 or Q7 >= 9;   

Q8 = 0 or Q8 >= 1;   

Q4 <= 30;   

Q1 + Q2 + Q3 + Q4 + Q5 + Q6 + Q7 + Q8 <= 50;   




How would I rewrite this to work? Is there a particular solver that should be used for this kind of task?



linear program with zeros
You can use the following modelling trick to transform you problem in a integer linear program: for each constraint of the type 
$$ Q\_i = 0 \text{ or } L\_i \le Q\_i \le M\_i$$
(on an integer variable $Q\_i$) introduce a new binary variable $B\_i$ and write 
$$ L\_i B\_i \le Q\_i \le M\_i B\_i $$
If, as in your example, you have no explicit value for $M\_i$, simply use a large upper bound on the values of $Q\_i$ (for example $50$ in your situation). Also, the constraint $Q\_i = 0 \text{ or } Q\_i \ge 1$ is redundant.
You can then solve the resulting program with any integer programming solver, such as lp\_solve or glpk.


By the way, the solution to your example is easily seen to be obtained with $Q\_4=30$ and $Q\_8=20$.


