6
$\begingroup$

I am looking for a constraint to express the following:

IF W1 = 0 AND W2 = 0 THEN Y = 1
IF W1 = 0 AND W2 = 1 THEN Y = 1
IF W1 = 1 AND W2 = 0 THEN Y = 0
IF W1 = 1 AND W2 = 1 THEN Y <= 1

Variables W1, W2, Y are binaries. Y is determined by the aforementioned relations. So, I am looking for an expression Y(W1,W2) = ???

$\endgroup$
6
$\begingroup$

The following should work :

\begin{align*} 1-\omega_1 &\le y \\ \omega_1 - \omega_2 &\le 1- y \end{align*}

  • If $\omega_1 = 0$ and $\omega_2 \in \{0,1\}$, then the equations hold only if $y = 1$
  • If $\omega_1 = 1$ and $\omega_2 = 0$, then the equations hold only if $y = 0$
  • If $\omega_1 = 1$ and $\omega_2 = 1$, then the equations hold if $y \in \{ 0,1\}$
$\endgroup$
3
$\begingroup$

@Kuifje’s answer is correct. Here’s how you can obtain the constraints via conjunctive normal form. The first two propositions can be combined, and the fourth proposition is a tautology, so we want to enforce $$(\neg W_1\implies Y)\land ((W_1\land \neg W_2)\implies\neg Y).$$ Rewriting in conjunctive normal form yields $$ (W_1\lor Y)\land ((\neg W_1\lor W_2)\lor\neg Y)\\ (W_1+Y\ge 1)\land (1-W_1+W_2+1-Y\ge 1)\\ (Y\ge 1-W_1)\land (1-Y\ge W_1-W_2). $$

$\endgroup$
2
  • $\begingroup$ Kuifje's answer is indeed correct. Can you give the answer to the same setting but this time the first preposition reads: if W1 = 0 and W2 = 0 the Y = 0 ? $\endgroup$ – Clement Mar 5 '20 at 14:16
  • $\begingroup$ Please open a new question for that to avoid confusion. $\endgroup$ – RobPratt Mar 5 '20 at 14:21

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.