I have two variables $A$ and $B$, with $A$ being binary and $B$ is a real number where $B \ge 0$. My conditions are:

if B > 0
         A = 1
         A = 0

How to express this as a linear program? I have figured out one condition using the big-M method:

$MA \gt B$

which means that if $B>0$, then $A$ must be 1 to satisfy this constraint. However if $B=0$, then $A$ can be either 1 or 0, and I need another constraint. How to enforce $A$ to be 0 when $B=0$?


1 Answer 1


If you know the maximum value of $B$ then you can easily express all comparisons as described here: https://blog.adamfurmanek.pl/2015/09/12/ilp-part-4/

In your case you need the following:

$0 \le -B + MA \le M-1$

assuming that $M$ is big enough.


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