Lower and upper bound to a constraint

985 views
Skip to first unread message

Max Witteman

unread,
Sep 8, 2018, 5:35:52 PM9/8/18
to Gurobi Optimization
Dear community,

I would like to implement the following (easy) constraint: -1 >= xi^k >= -15. Unfortunately I don't know how to implement an upper and lower bound to the constraint. For the moment I added the following two constraints:
xi^k >= -15 and xi^k =< -1 which of course do the same as the one constraint. I have two questions: First of all I was wondering if it is possible to implement these two constraints in a single one using Python and Gurobi. Secondly, is the computational time negatively effected when using these two constraints instead of just one? 

Thanks for your time.

Tobias Achterberg

unread,
Sep 8, 2018, 5:40:15 PM9/8/18
to gur...@googlegroups.com
I guess that k is just an index, and you don't want to use the k'th power of xi. If so,
then your constraints are just bound constraints, and the easiest way to put them into the
model is to set the lower and upper bounds of the variables. In Python, you specify the
"lb" and "ub" parameters in the addVar() method, like this:

x[i,k] = model.addVar(lb=-15, ub=-1)

Actually, in your case you have to specify the bounds, because if you do not set the lower
bound explicitly, then it is assumed by default to be zero.


Best regards,

Tobias

Max Witteman

unread,
Sep 10, 2018, 12:45:38 AM9/10/18
to gur...@googlegroups.com
Thanks for your reaction. Unfortunately I made a mistake, the constraint is not just for one single decision variables but instead for a sum of different decision variables. Isn't there an option to include a lower and upper bound of a single constraint? Where the lower bound should be -1 >= and the upper bound >= -15.

With kind regards,

Max

Op za 8 sep. 2018 om 23:40 schreef 'Tobias Achterberg' via Gurobi Optimization <gur...@googlegroups.com>:
--

---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tobias Achterberg

unread,
Sep 10, 2018, 3:50:53 AM9/10/18
to gur...@googlegroups.com, Max Witteman
Yes, such constraints are called "range constraints". In Python, you would add those
constraints using model.addRange(), see
http://www.gurobi.com/documentation/8.0/refman/py_model_addrange.html. Alternatively, in
Python you can use the syntax

model.addConstr(x + y == [-15,-1])

But Gurobi does nothing smart with these constraints. When you add such constraints,
Gurobi immediately introduces an auxiliary slack variable and converts the left and right
hand side of the constraint into bounds of the slack variable. Thus, adding a range constraint

lhs <= ax <= rhs

is equivalent to

ax - s = lhs
0 <= s <= rhs-lhs

with an explicit slack variable s. I encourage you to avoid range constraints and instead
formulate the model yourself with explicit slack variables. This avoids the confusion that
after the addRange() call you suddenly have another variable in your model that you did
not add yourself using addVar().


Regards,

Tobias

Max Witteman

unread,
Sep 10, 2018, 12:23:54 PM9/10/18
to Gurobi Optimization
Thanks for your answer, I have another question regarding my model. I would like to add additional variables and constraint to my model after each iteration. It will look like this:
1. create model
2. solve model
3. add additional task?
  1. Yes - return to 1.
  2. No -  Terminating condition  
 However at the moment I'm recreating my model from scratch every new iteration. Which I believe is a waste since I will use almost  all the same DV's (same sequence but with a few more after each iteration), and for my four different sets of constraints I will only need to redefine constraint set (C2) and (C3) again from scratch, the other two will just need a small update. Unfortunately I receive the following error GurobiError: Variable not in model when I try to modify my existing model. Any thoughts on how I should do this?

With kind regards,

Max


Reply all
Reply to author
Forward
0 new messages