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
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.