3

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.

ooo
  • 1,589
  • 4
  • 12
  • I haven't checked your formulation, but what value of M did you use, and how did you choose that value? – Mark L. Stone Jan 31 '20 at 19:37
  • I am choosing $ M = 1000$ which is higher than the upper bound of the problem – ooo Jan 31 '20 at 19:42
  • Perhaps you should spell out exactly in what way(s) the result is different than you expected. – Mark L. Stone Jan 31 '20 at 20:19
  • Is $\delta$ a constant or variable? Is it nonnegative, strictly positive or what? – prubin Jan 31 '20 at 21:29
  • constant, $\delta = 0.000001$ small value – ooo Jan 31 '20 at 21:30
  • I cannot make any sense of your constraints. Consider, for example, the case where $z=1$. The second to last constraint is automatically true; the last forces $k_1=k_2=1$, which makes constraints 1 and three nonbinding. Now set $A=B$ and $x=y=0$. That satisfies constraints 2 and 4, but according to your problem statement, it should not be a feasible solution. – prubin Jan 31 '20 at 21:34
  • 1
    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. – RobPratt Jan 31 '20 at 21:36
  • ok, I have updated them in the question. – ooo Jan 31 '20 at 21:43
  • Is it fine now..? – ooo Jan 31 '20 at 21:52
  • I'm not seeing any errors, so maybe. – prubin Jan 31 '20 at 22:31

1 Answers1

3

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}

RobPratt
  • 32,006
  • 1
  • 44
  • 84