0

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?

2
  • "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? Commented Feb 12, 2015 at 17:46
  • 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! Commented Feb 12, 2015 at 22:49

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

13 Comments

Thanks for your answer, grendelsdad! Your formulation seems logical to me. But if I put the equations in my model, the BinaryVar gets always set to 1 and Variable1, Variable2 and Variable3 are set to zero (or SomeValue*e-13). I have already checked if Variable1 stays within the upper and lower bounds which is the case. So far, I could not find the reason why this does't work...
The problem occurs with the second unequation (LB * (1 - BinaryVar) <= Variable1) if the value of Variable1 is negative. Then, the unequation cannot be fulfilled since LB * (1 - BinaryVar) can only be above or equal zero. I am already looking for a solution..
Formulating the second unequation to "-LB * (1 - BinaryVar) <= Variable1" should fix the problem but if I formulate it like this, the solver also sets the values for Variable1 either to zero, SomeValue x e-13 or -SomeValue x e-13 and in the case that Variable1 equals zero the values for the BinaryVariable get set randomly to 0/1. I guess the problem occurs in the case that Variable1 is exactly zero..
By the way, I have changed the question formulation to LB > 0, UB > 0 and -LB <= Variable1 <= UB since it is a bit more intuitive..
Interesting. In the formulation "LB > 0 / UB > 0 / -LB <= Variable1 <= UB / Variable1 <= UB * BinaryVar / -LB * (1 - BinaryVar) <= Variable1" the BinaryVariable gets set rightly in most cases. But somehow then the upper and lower boundaries UB/LB for Variable1 are not satisfied and values like SomeValue x e-15 or -SomeValue x e-15 occur. For these values, the value of BinaryVariable ist set wrongly..
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.