Linearization of if-then constraint

1k Views Asked by At

I'm trying to linearize a constraint of this form: if a == b then c = 1 where a and b are positive integers and c is a binary variable. I'm looking for a solution like this one https://math.stackexchange.com/questions/2792360/how-to-linearize-if-then-constraint which doesn't work in this case. Thanks to anyone who can help me.

1

There are 1 best solutions below

2
Erwin Kalvelagen On

The implication

 a = b => c = 1

 (a,b: integer variables, c: a binary variable)

can be re-stated as:

 c = 0 => a >= b + 1 
          or
          a <= b - 1

(Using that a,b are integers). An "or" needs an extra binary variable. So we can write:

 a >= b + 1 - M δ - M c
 a <= b - 1 + M (1-δ) + M c
 δ ∈ {0,1}

Here M is a large enough constant (to be chosen with care).