3
$\begingroup$

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.

$\endgroup$
1

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
5
  • $\begingroup$ Thank You for your response. This solved the problem. The Lower Bound must be greater than both b and \pi to work , and the Upper Bound must be higher than both to work. Am I right? $\endgroup$ Jun 16, 2022 at 12:37
  • $\begingroup$ 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. $\endgroup$
    – prubin
    Jun 16, 2022 at 15:15
  • $\begingroup$ 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$ ? $\endgroup$ Jun 17, 2022 at 14:19
  • 1
    $\begingroup$ 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/…. $\endgroup$
    – prubin
    Jun 17, 2022 at 15:06
  • $\begingroup$ Thank you for your quick reply Professor , I was able to solve it :) You have been a great help ! $\endgroup$ Jun 17, 2022 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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