I have a binary indicator variable $i \in \{ 0, 1 \}$ and an integer variable $c \in \mathbb{Z}$. I am trying to come up with a formulation in which $i = 0$ if $c = 0$ and $i = 1$ if $c \neq 0$. However, I am having trouble accomplishing this. I tried formulating it as the minimum of two functions but that was not successful. I tried creating two different copies of $i$ (one for if $c < 0$ and one for if $c > 0$). However that did not prove fruitful either. I also tried formulating it using step functions combined with minimizing two functions. However that also failed. Is there a trick to deal with such programs?
1 Answer
Suppose $L \le c\le U$ for some constants $L$ and $U$. Introduce binary variables $x$ and $y$, and impose linear constraints \begin{align} L x + 0(1-i) + 1y \le c &\le -1 x + 0(1-i) + U y\\ x + (1-i) + y &= 1 \\ x, i, y &\in \{0,1\} \end{align} The three cases correspond to
- $(x,i,y)=(1,1,0)$ and $c\in[L,-1]$
- $(x,i,y)=(0,0,0)$ and $c = 0$
- $(x,i,y)=(0,1,1)$ and $c\in[1,U]$
-
-
$\begingroup$ I don't think I follow this. According to this, it would seem that if $c \in [L, -1]$, then it must be that $x = 1$ and hence $i = 0$. However, we want $i = 1$ in that case. We want $i = 1$ whenever $c\neq 0$ (regardless of whether $c$ is positive or negative). Could you please clarify if I have made a mistake? Thanks $\endgroup$ Apr 12 at 0:35
-
$\begingroup$ Sorry, I had the roles of $i$ and $1-i$ reversed. Corrected now. $\endgroup$– RobPrattApr 12 at 0:45