Search code examples
algorithmlinear-programming

ILP: Exclusive range for variable


In an ILP, How can I write a constraint "X is not in the interval [Y, Y+10]" ?

Is it even possible?


Solution

  • You didn't say, but I'm assuming x and y are non-negative integers and that the range you indicate to avoid is inclusive of endpoints...

    You have an "or" condition there, so you will need to introduce a helper or "indicator" variable to handle the or condition, call it z, and a (constant) parameter for a reasonable upper bound on y, call it M:

    z ∈ {0, 1}  # 0 if below y, 1 if above y+10
    M > reasonable_upper_bound(y)
    

    Then 2 constraints based on that info to either constrain x to the lower set of values or the upper, excluding the interval (of disinterest):

    x <= (y - 1) + z * M
    x >= (y + 10 + 1) - (1 - z) * M    
    

    Truth Table:

           z=0      z=1
    x <=   y-1      ~M
    x >=   ~0       y + 11