1

I need to build a MILP (Mixed integer linear programming) constraint form this if-else statement: with beta is a constant.

if (a > b) then c = beta else c = 0

How can I build the statement to MILP constraint. Are there any techniques for solving this problem. Thank you.

LarrySnyder610
  • 2,277
  • 12
  • 24
nstball
  • 11
  • 1
  • 2

1 Answers1

5

I am assuming that a, b, and c are all decision variables here. To build your constraint, you need to add a new binary variable -- let's call it x -- that will equal 1 if a > b and 0 otherwise. You also need a large constant M. Then add the following constraints:

Mx >= a - b
M(1-x) >= b - a
x in {0,1}

The logic is: If a > b, then x must equal 1 by the first constraint (and x may equal 1 by the second constraint). If b > a, then 1-x must equal 1 by the second constraint, i.e., x must equal 0 (and x may equal 0 by the first constraint).

Next, we need a constraint that says, if x = 1, then c = beta, otherwise, c = 0:

c = beta * x

Note: The logic above allows c to equal either 0 or beta if a = b; the solver will decide. Do you need c to equal 0 if a = b?

Another note: In "big-M"-type formulations like this one, it's always best to keep M as small as possible while maintaining the validity of the constraints. In this case, this means setting M to the largest possible (or plausible) difference between a and b. If your model is small, it won't matter much, but if you have lots of these decision variables, then it can matter a lot.

LarrySnyder610
  • 2,277
  • 12
  • 24