# On if then condition in linear programming?

I have variables $a,b\in\mathbb R$ and if $a>1$ I want $b=1$ or else $b=0$. Can this be encoded by linear programming (no integer variables)? Even $b<0.5$ and $b>0.5$ is ok.

• This may give some idea. Commented Apr 11, 2018 at 5:50
• LP feasible region is convex. Your region for $a,b \in R$ is not. Maybe you are looking for Integer Programming formulation? Commented Apr 11, 2018 at 17:36
• @Eugene can you explain why? Commented Apr 11, 2018 at 22:51
• You changed the question to a different one, in a way that invalidates the existing answer. That's not very polite to the person who took the time to write an answer to the original question.
– D.W.
Commented Apr 11, 2018 at 23:28
• @d.w. ok I will change. Commented Apr 12, 2018 at 0:19

The if then contraints can be written equivalently as

• If $b = 0$, then $a < 1$; and
• If $b = 1$, then $a \geq 1$.

Introduce a large number $M$ and add the following constraints:

$$b(M+1)-M \le a < b(M+1)+1.$$

EDIT: I assumed that $b$ is binary. If $a$ is bounded $a\in[L,U)$, we can write the constraints as:

$$b(-L+1)+L \le a < b(U-1)+1.$$

• how large should M be? also this takes $b\in\mathbb Z$. Commented Apr 11, 2018 at 16:33
• I assumed that $b$ is binary. For $M$, it depends on $a$. See my edits.
– zdm
Commented Apr 11, 2018 at 17:03
• there is an issue i think $a>1$ not $a\geq1$. What if $b=0\iff a\in[0,1]$ and $b=1\iff a>1$? Commented Apr 11, 2018 at 17:19