I want to write if-else condition in linear programming and the only method I can think of is using MIP. I have to write a binary variable called b so that
If a>2 then b=1 else (when a<=2) b=0
If my application, the solver can only use inclusive inequality.
Either > or < cannot be used.
First I do:
a>2 => b=1
I formulate this as:
a<=2+M*b
Using the big-M constraint Then I do:
a<=2 => b=0
I formulate this as:
a>=2-M*(1-b)
I want to have when a=2=>b=0 while in both cases a is unconstrained.
I could add a 0.01 term so that a<=2.01-M*b but why happens when a =2.001?
Is there any more neat way to achieve this?
Assuming $a$ is not integer, you cannot do exactly what you want. (This is a FAQ in integer programming.) What you can do is partition the domain of $a$ so that $a\le 2 \implies b=0$ and $a\ge 2+\epsilon \implies b=1$, where $\epsilon > 0$ is chosen small (but not so small that it looks like 0 to within floating point arithmetic tolerances). The cost of this is that the interval $(0,\epsilon)$ is removed from the domain of $a$.