Search code examples
linear-programming

If it is possible to linearize no-else if statement as MIP constraint?


Assume that I have the following constraint:

IF d == 1 THEN x >= 1;

d : binary

x : integer

but there is no else, means that IF d == 0, there will be no constraint for x.

Is such constraint convertable to MIP linear constraint?


Solution

  • This can be generally modelled in mixed integer programming with a "Big M Constraint":

    from pulp import *
    
    d = LpVariable("d", cat='Binary')
    x = LpVariable("x", lowBound=0, cat='Integer')
    
    M = 100000
    
    constraint = x >= 1 - M * (1 - d)
    
    

    If d==1 it turns into x>=1, else it's x>=1-M where M is a suitably chosen large number.