# Disjunctive Constraint , Using Binary Variable to Replace a If or condition

I am trying to use a binary variable based on an inequality. The value of binary variable $$q$$ is 1 or 0 based on the following equation.

[ $$q$$ = $$\begin{cases} 0,& \text{if } b \geq \pi ,\\ 1, & \text{otherwise} \end{cases}$$

Here, b and $$\pi$$ are real numbers. Sample value b = 20 , $$\pi$$ = 30.

I have tried to represent this by:

$$\begin{equation} q \geq \dfrac { (\pi - b )} {M} \end{equation}$$

$$\begin{equation} q \leq 1 + \dfrac { (\pi - b )} {M} \end{equation}$$

By using these two equations I am able to cover the cases for when $$b > \pi$$ and when $$b < \pi$$. Unfortunately I am unable to set $$q$$ as 0 when $$b=q$$ without violating other conditions.

The usual approach to this requires that $$b$$ be bounded, say $$L \le b \le U$$ for some constants $$L$$ and $$U.$$ You can come close to what you want with the following: $$b \ge \pi (1-q) + L q$$ $$b \le \pi q + U (1-q).$$ If $$b > \pi,$$ the second constraint forces $$q=0.$$ If $$b < \pi,$$ the first constraint forces $$q=1.$$ The tricky part comes when $$b=\pi,$$ in which case $$q$$ can be either 0 or 1. Because you cannot enforce a strict inequality in a MIP model, if you can't accept the ambiguity when $$b=\pi$$ then you can change the second constraint to $$b \le (\pi - \epsilon) q + U (1-q),$$ where $$\epsilon > 0$$ is a small constant. Now $$b\ge \pi \implies q=0,$$ $$b \le \pi-\epsilon \implies q = 1,$$ and $$\pi - \epsilon < b < \pi$$ is forbidden.
• I assume you meant "less" rather than "greater" for the lower bound, in which case you are right, with the following qualification. If $L > \pi$ or $U < \pi,$ $q$ is a constant and can be eliminated from the model.
• yes , thank you for the response. What if both b and $\pi$ are decision variables , is there any way to remove the non-linearity to model the binary variable q? i.e. model the binary variable q in a linear fashion to represent the inequality b $\geq \pi$ ? Jun 17, 2022 at 14:19
• You can linearize the product $\pi q$ with additional constraints. This is a FAQ on this forum. See, for instance, the accepted answer to or.stackexchange.com/questions/6028/….