0

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?

graphtheory123
  • 225
  • 1
  • 4

1 Answers1

3

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]$
RobPratt
  • 32,006
  • 1
  • 44
  • 84
  • Related: https://or.stackexchange.com/questions/33/in-an-integer-program-how-i-can-force-a-binary-variable-to-equal-1-if-some-cond/2632#2632 – RobPratt Apr 11 '23 at 23:05
  • 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 – graphtheory123 Apr 12 '23 at 00:35
  • Sorry, I had the roles of $i$ and $1-i$ reversed. Corrected now. – RobPratt Apr 12 '23 at 00:45