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.

  • 1
    $\begingroup$ With your previous question (which has been answered), you should be able to do this one easily. Otherwise you did not understand the previous one, obviously :) I suggest you give it a try and the community will guide you based on your try. $\endgroup$ – Kuifje Mar 5 '20 at 14:46
  • $\begingroup$ Well, I understand that the previous one is correct, but I am not good enough to get to the new one. $\endgroup$ – Clement Mar 5 '20 at 14:51
  • $\begingroup$ Do you understand @RobPratt's explanation ? If not, how do you relate both $Y$s in the two questions ? $\endgroup$ – Kuifje Mar 5 '20 at 14:55
  • $\begingroup$ Sorry, I am not familiar with what Rob was writting about. $\endgroup$ – Clement Mar 5 '20 at 15:00
  • $\begingroup$ Related: How to model If A≤B then Y=1, otherwise Y=0 $\endgroup$ – SecretAgentMan Mar 11 '20 at 17:09

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

  • $\begingroup$ Thanks, I will look into that. $\endgroup$ – Clement Mar 5 '20 at 15:34
  • $\begingroup$ Ok, I think I have got it. <br/> W1 + W2 => Y <br/> W1 - W2 => -Y <br/> W1 - W2 <= 1 - Y <br/> $\endgroup$ – Clement Mar 5 '20 at 17:01

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.


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.