Search code examples
pythonoptimizationbinarylinearization

Linearize if statement in MILP constraint


I am trying to solve an optimization problem in which one of the constraints is : x*y=0, where x and y are decision variables and only x or y can be positive. In other words, if x!=0 then y=0 and if y!=0 then x=0. Please help


Solution

    • Assumption: x and y are nonnegative

    • Infer upper-bounds UB_x and UB_y for x, y

    • Introduce new boolean variable b

    • Add constraints:

      x <= (1-b) * UB_x
      y <= b * UB_y