1

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
else
         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$?

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
asm_nerd1
  • 229
  • 3
  • 8
  • 1
    I have no idea what you have in mind when you say you want to "express" programming code as linear program. – Raphael Nov 13 '17 at 14:54
  • See https://cs.stackexchange.com/q/67163/755. (Also loosely related: https://cs.stackexchange.com/q/12102/755 , https://cs.stackexchange.com/q/51025/755) – D.W. Nov 13 '17 at 22:29

1 Answers1

4

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.

user1543037
  • 386
  • 1
  • 2
  • 5