0

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.

Jihong
  • 127
  • 6

1 Answers1

3

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}
Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39
  • That was incredibly straight forward. I had something along the lines of: y >= (x1+x2+x3) - 3 + epsilon where epsilon was some very small value. but that ran into a similar issue as above. Thank you so much! – Jihong May 02 '22 at 15:43