I have two continuous variables $A$, $B$ and two binary variables $x$, $y$.

Condition: if $A = B \wedge x = 1 \wedge y=1$ then $z = 1$ else $z = 0$ from

My current attempt is:

\begin{align} A-B + \delta+x+y &\leq 2 + M \cdot k_1\\ B - A - \delta-x-y &\leq - 2 + M \cdot(1 - k_1)\\ B-A + \delta+x+y &\leq 2 + M \cdot k_2\\ A - B - \delta-x-y &\leq -2 + M \cdot(1 - k_2)\\ k_1 + k_2 - 1 &\leq z \\k_1 &\geq z \\k_2 &\geq z \end{align}

where $k_1, k_2$ are boolean variables, but I am not getting the expected result.

  • $\begingroup$ I haven't checked your formulation, but what value of M did you use, and how did you choose that value? $\endgroup$ – Mark L. Stone Jan 31 at 19:37
  • $\begingroup$ I am choosing $ M = 1000$ which is higher than the upper bound of the problem $\endgroup$ – anoop Jan 31 at 19:42
  • $\begingroup$ Perhaps you should spell out exactly in what way(s) the result is different than you expected. $\endgroup$ – Mark L. Stone Jan 31 at 20:19
  • $\begingroup$ Is $\delta$ a constant or variable? Is it nonnegative, strictly positive or what? $\endgroup$ – prubin Jan 31 at 21:29
  • 1
    $\begingroup$ The last two constraints are intended to enforce $z=1\implies (k_1=1 \land k_2=1)$, but it is better to instead have $z\le k_1$ and $z\le k_2$, with no big-M. $\endgroup$ – RobPratt Jan 31 at 21:36

You want to model $$z=1 \iff (A=B\land x=1 \land y=1).$$

To enforce $z=1 \implies (A=B\land x=1 \land y=1)$: \begin{align} -M(1-z) \le A - B &\le M(1-z)\\ z &\le x\\ z &\le y \end{align}

To enforce the converse $(A=B\land x=1 \land y=1) \implies z=1$, equivalently, $A>B\lor A<B\lor x=0 \lor y=0 \lor z=1$: \begin{align} B-A+\delta &\le M_1 (1-w_1)\\ A-B+\delta &\le M_2 (1-w_2)\\ w_1+w_2+(1-x)+(1-y) + z&\ge 1\\ w_1,w_2&\in\{0,1\} \end{align}

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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