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$ ?
Operations Research Stack Exchange is a question and answer site for operations research and analytics professionals, educators, and students. It only takes a minute to sign up.Sign up to join this community
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).$$