1

I have a variable $d_{i} \in \mathbb{Z}$ with an upper and lower bound. I also have a binary variable $v_{i}$ which I want to $=1$ if $d_{i} \geq 0$; else $v_{i} = 0$. How do I enforce this as a linear constraint?

I have seen this post but it is different to my problem as I have the inequality ($\geq$) whereas they merely have ($>$). I presume this changes the problem but please correct me if I am wrong as I am new to this.

I thought about adding a slack variable so that my constraint becomes like that in the post referenced; however, my problem is one of maximization and I do not want to include $-d_{i}$ in my maximization objective as it does not make sense for my problem.

Any help is much appreciated!

1 Answers1

1

Assuming that $L \le d_i < U$ with $L<0$ and $U>0$, you can add the following two constraints.

The following encodes "if $d_i \ge 0$ then $v_i=1$": $$U v_i - d_i > 0.$$

The following encodes "if $d_i < 0$ then $v_i=0$": $$ -L (1-v_i) + d_i \ge 0. $$

Steven
  • 29,724
  • 2
  • 29
  • 49