Search code examples
linear-programmingmixed-integer-programming

How to convert if else statement into Linear Programming constraints?


How to write the following if-else condition in Linear Programming?

If YR1 == 1 , then 20 <= XR1 <= 80, else XR1 = 0

YR1 is a binary variable, XR1 is a continuous variable.

I tried

20 - XR1 <= 1000 * (1 - YR1)
80 - XR1 <= 1000 * (1 - YR1)

XR1 - 20 <= 1000 * YR1

Is it correct? If not, how can I convert the statement to linear programming conditions?


Solution

  • XR1 is called a semi-continuous variable. It can be modeled as:

     20*YR1 <= XR1 <= 80*YR1
     YR1 ∈ {0,1}
     
    

    You need to split this into two inequalities.