Assume I have two variables X and Y, I want to introduce a new variable Z with the following mapping:
IF X NOT EQUAL TO Y THEN Z = 1 ELSE Z = 0
Here, X and Y are both non-negative variables.
Thanks in advance.
Assume I have two variables X and Y, I want to introduce a new variable Z with the following mapping:
IF X NOT EQUAL TO Y THEN Z = 1 ELSE Z = 0
Here, X and Y are both non-negative variables.
Thanks in advance.
Copyright © 2021 JogjaFile Inc.
Suppose $X\in [0,M]$ and $Y\in [0,M]$, and introduce two additional binary variables (besides $Z$), $U$ and $V$, together with linear constraints: \begin{align} U + Z + V &= 1 \tag1\\ -MU + 0Z + 1V \le X-Y &\le -1U + 0Z + MV \tag2 \end{align} Constraint $(1)$ forces exactly one of $U$, $Z$, and $V$ to be $1$. Constraint $(2)$ enforces \begin{align} U=1 &\implies -M \le X-Y \le -1 &&(X<Y) \\ Z=1 &\implies 0 \le X-Y \le 0 &&(X=Y)\\ W=1 &\implies 1 \le X-Y \le M &&(X>Y)\\ \end{align}