-4

I am looking for a constraint to express the following:

IF W1 = 0 AND W2 = 0 THEN Y = 0
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.

Clement
  • 2,252
  • 7
  • 13

2 Answers2

6

As in your other question, the fourth proposition is a tautology. The other three propositions can be expressed as $$ ((\neg W_1 \land \neg W_2) \implies \neg Y) \land ((\neg W_1 \land W_2) \implies Y) \land ((W_1 \land \neg W_2) \implies \neg Y) $$ More simply, combine your first and third propositions and omit the fourth one to obtain $$ (\neg W_2 \implies \neg Y) \land ((\neg W_1 \land W_2) \implies Y) $$

Now rewrite in conjunctive normal form, by replacing $P \implies Q$ with $\neg P \lor Q$, pushing $\neg$ inwards, and distributing $\lor$ over $\land$: $$ (W_2 \lor \neg Y) \land ((W_1 \lor \neg W_2) \lor Y)\\ (W_2 + (1 - Y) \ge 1) \land (W_1 + (1 - W_2) + Y \ge 1)\\ (W_2 \ge Y) \land (W_1 + Y \ge W_2) $$

Several other examples are here.

A good reference for this is:

Raman, R. and I.E. Grossmann, Relation Between MILP Modelling and Logical Inference for Chemical Process Synthesis, Computers Chem. Engng. 15 (1991).

RobPratt
  • 32,006
  • 1
  • 44
  • 84
1

Regardless of Rob's comprehensive answer, the problem is a bit strange. The last constraint is always met, and in the others $W_1$ does not affect the result, almost. That's why I get the trivial solution $Y = W_2$. However, if $W_1 = W_2 = 1$, then $Y$ can take both 0 and 1.