'How to convert the following if conditions to Linear integer programming constraints?
These are the conditions:
if(x > 0)
{
y >= a;
z <= b;
}
It is quite easy to convert the conditions into Linear Programming constraints if x were binary variable. But I am not finding a way to do this.
Solution 1:[1]
You can do this in 2 steps
Step 1: Introduce a binary dummy variable
Since x
is continuous, we can introduce a binary 0/1
dummy variable. Let's call it x_positive
if x>0
then we want x_positive =1
. We can achieve that via the following constraint, where M
is a very large number.
x < x_positive * M
Note that this forces x_positive to become 1, if x is itself positive. If x is negative, x_positive
can be anything. (We can force it to be zero by adding it to the objective function with a tiny penalty of the appropriate sign.)
Step 2: Use the dummy variable to implement the next 2 constraints
In English: if x_positive = 1
, then y >= a
However, if x_positive = 0
, y can be anything (y > -inf
)
y > a - M (1 - x_positive)
Similarly,
if x_positive = 1
, then z <= b
z <= b + M * (1 - x_positive)
Both the linear constraints above will kick in if x>0 and will be trivially satisfied if x <=0.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ram Narasimhan |