0
votes

I am relatively new to integer programming and (again) got stuck with the formulation of a constraint.

In my simplified model I have a (continous) variable with a lower bound LB below zero and an upper bound UB above zero. Now I want to assign the variable value to other variables depending on the value that the variable has taken.

The logic I want to express is the following:

LB > 0
UB > 0
-LB <= Variable1 <= UB

if Variable1 => 0:
    Variable2 = Variable1
    Variable3 = 0
else:
    Variable2 = 0
    Variable3 = abs(Variable1)

How can I describe this using linear (in)equalities?

I guess am a bit slow on the uptake..

Thanks in advance!

** Edit: For the modeling I am using Python, Pyomo and the newest Gurobi solver.

*** Edit: I have now formulated it the following way by the use of a binary variable. (I know it is quadratic but this can be linearized later):

LB > 0
UB > 0

-LB <= Variable1 <= UB
0 <= Variable2 <= UB
0 <= Variable3 <= LB
Variable4 = Variable2 * BinaryVariable - Variable3 * (1-BinaryVariable)

But now I still have to make sure that Variable3 is 0 if Variable2 is > 0 and vice versa.

Any ideas?

1
"mixed integer programming" .... "within ... reals" ... So is this integer programming, or floating point (pseudo-real)? Also what language/framework/platform/program are you talking about here? Expressing logic of any sort generally requires a particular language to be utilized. And what's wrong with the logic you've already expressed? What have you tried, and what isn't working about it? - twalberg
Oh, sorry, you are right! It is integer programming and the variables are continous (see my edit). I am searching for a way to describe this using (in)equalities. For the modeling I am using Python, Pyomo and the newest gurobi solver! - Cord Kaldemeyer

1 Answers

1
votes

First create a binary variable that equals 1 if Variable1 > 0 and 0 if Variable1 < 0:

Variable1 <= UB * BinaryVar
LB * (1 - BinaryVar) <= Variable1

(If Variable1 > 0, then BinaryVar must equal 1. If Variable1 < 0, then BinaryVar must equal 0. Note that if Variable1 = 0, then BinaryVar could equal 0 or 1, but that doesn't matter for your problem because if Variable1 = 0 then Variable2 = Variable3 = 0 and the constraints below work out OK.)

Now add constraints enforcing the values for Variable2 and Variable3:

Variable2 = Variable1 * BinaryVar
Variable3 = -Variable1 * (1 - BinaryVar)

These are quadratic constraints, which you can then linearize.

Linearization:

Variable2 <= UB * BinaryVar
Variable2 >= -LB * BinaryVar
Variable2 <= Variable1 + LB * (1 - BinaryVar)
Variable2 >= Variable1 - UB * (1 - BinaryVar)
Variable3 = Variable2 - Variable1