Dual Variable for Variable range constraint?

1,518 views
Skip to first unread message

David Belanger

unread,
Jan 26, 2012, 5:25:49 PM1/26/12
to Gurobi Optimization
I instantiated my variables using the following line:
newVar = model.addVar(0.0, 1.0, cost, GRB.CONTINUOUS, string)

This implicitly defines a constraint that newVar <= 1.
Is there a way to access the dual variable corresponding to this
constraint?

Alternatively, if I manually include the constraint that newVar <=1
using an additional call to model.addConstr, will this provide more
overhead in the solution process?

Christopher Maes

unread,
Jan 30, 2012, 10:28:53 AM1/30/12
to gur...@googlegroups.com
On Thu, Jan 26, 2012 at 5:25 PM, David Belanger
<david.b....@gmail.com> wrote:
> I instantiated my variables using the following line:
> newVar =  model.addVar(0.0, 1.0, cost, GRB.CONTINUOUS, string)
>
> This implicitly defines a constraint that newVar <= 1.
> Is there a way to access the dual variable corresponding to this
> constraint?

Hi David,

The dual variable for a range constraint on a variable (in a continuous
model) is related to that primal variable's reduced cost. It might be
helpful to
take a look at an textbook on linear programming for an exact definition
of a reduced cost. Sometimes the sign of the reduced cost, as it relates
to lower and upper bounds, can be a little tricky.

For example, in the simple model

minimize 3*x1 - 2*x2
st 0 <= x1,
x2 <= 1

You can access the dual variables associated with the constraints
0 <= x1 and x2 <=1 via the .RC attribute described here:

http://www.gurobi.com/doc/46/refman/node590.html#sec:Attributes

As in:

from gurobipy import *

m = Model("rc")

x1 = m.addVar(0.0, GRB.INFINITY, 3.0, GRB.CONTINUOUS, "x1")
x2 = m.addVar(-GRB.INFINITY, 1.0, -2.0, GRB.CONTINUOUS, "x2")

m.update()

m.optimize()

print "x1", x1.x, "rc", x1.rc
print "x2", x2.x, "rc", x2.rc

This is the same as the dual variable Pi you get by manually adding
constraints as in


from gurobipy import *

m = Model("pi")

x1 = m.addVar(-GRB.INFINITY, GRB.INFINITY, 3.0, GRB.CONTINUOUS, "x1")
x2 = m.addVar(-GRB.INFINITY, GRB.INFINITY, -2.0, GRB.CONTINUOUS, "x2")

m.update()

c0 = m.addConstr(0.0 <= x1, "c0")
c1 = m.addConstr(x2 <= 1.0, "c1")

m.optimize()

print "x1", x1.x, "rc", x1.rc
print "x2", x2.x, "rc", x2.rc

print "c0 pi", c0.pi
print "c1 pi", c1.pi

Hope that helps,
Chris

Message has been deleted

T.

unread,
Jan 16, 2014, 11:37:29 PM1/16/14
to gur...@googlegroups.com
Hi,

first of all, I do not see, why degeneracy should not allow to obtain dual information from the reduced cost vector. A dual value might be 0, but this should not be a problem.

Concerning ranged constraints, I have to say that I never used them, but the documentation says:

Note that adding a range constraint to the model adds both a new constraint and a new variable. If you are keeping a count of the variables in the model, remember to add one whenever you add a range.

Note also that range constraints are stored internally as equality constraints. We use the extra variable that is added with a range constraint to capture the range information. Thus, the Sense attribute on a range constraint will always be GRB_EQUAL.

So, it might be that you have to obtain the reduced cost value from this variable. But I'm not sure about this.

Or don't you mean ranged constraints, but only variables that have both lower and upper bounds?
Reply all
Reply to author
Forward
0 new messages