Search code examples
integerlinear-programming

IF, THEN, ELSE Integer Constraint Problem


I've been stuck on formulating this logical constraint for a while. What I'm trying to translate into an integer constraint is:

if x1i + x2i + x3i is equal to 3, then yi is equal to 1, else yi is equal to 0.

I found out this kind of works:

x1i + x2i + x3i >= 3*yi, but in the case where x1i + x2i + x3i is equal to 3, then yi can take on values 0 or 1. I just want it to be strictly one in this case.

Any insights would be greatly appreciated.


Solution

  • From the context, I suspect the x variables are binary. So that will be my assumption. You are basically asking how to linearize the constraint:

     y = x1*x2*x3
    

    This equation can be reformulated as:

     y >= x1+x2+x3-2
     y <= x1
     y <= x2
     y <= x3
     y,x1,x2,x3 ∈ {0,1}