# MILP constraint modelling

Lets assume $$x$$, $$y$$ are non negative continuous variables and $$P$$ an integer variable assuming either the value $$1$$ or the value $$2$$.

How could I possibly model the relation

If $$x = y$$ then $$P = 2$$ else $$P = 1$$ ?

• Note that $P-1$ is binary and apply or.stackexchange.com/a/2632/500 with your $x-y$ as $x$, $0$ as $b$, and $P-1$ as $y$. Apr 6 at 21:12
• Hugh, I will need to introduce another two binaries? That is frustrating. Thank you very much Rob. Apr 6 at 21:35
• Well, you can eliminate one of the additional binary variables by substitution if you want. Also, if you instead wanted to enforce only $P=2 \implies x=y$, you wouldn't need any new variables. Apr 6 at 21:42
• $(L_x - U_y)(2 - P) \le x -y \le (U_x - L_y)(2 - P)$, where $L$ and $U$ are lower and upper bounds on the variables. Apr 6 at 21:55
Note that $$P−1$$ is binary and apply the formulation in
with your $$x−y$$ as $$x$$, $$0$$ as $$b$$, and $$P−1$$ as $$y$$.
If you instead wanted to enforce only $$P=2 \implies x=y$$, you wouldn't need any new variables. Just let $$L$$ and $$U$$ be lower and upper bounds on the variables, and impose $$(L_x−U_y)(2−P) \le x − y \le (U_x−L_y)(2−P).$$