1
$\begingroup$

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$ ?

$\endgroup$
7
  • 3
    $\begingroup$ 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$. $\endgroup$
    – RobPratt
    Apr 6, 2022 at 21:12
  • $\begingroup$ Hugh, I will need to introduce another two binaries? That is frustrating. Thank you very much Rob. $\endgroup$
    – Clement
    Apr 6, 2022 at 21:35
  • $\begingroup$ 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. $\endgroup$
    – RobPratt
    Apr 6, 2022 at 21:42
  • 1
    $\begingroup$ $(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. $\endgroup$
    – RobPratt
    Apr 6, 2022 at 21:55
  • 1
    $\begingroup$ @RobPratt You should convert your comments to an answer. $\endgroup$
    – prubin
    Apr 6, 2022 at 22:47

1 Answer 1

5
$\begingroup$

Note that $P−1$ is binary and apply the formulation in

In an integer program, how I can force a binary variable to equal 1 if some condition holds?

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).$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.