Issue with dual values for continuous model
AnsweredI have a continuous model with a linear objective function with a minimization sense.
My expectation of duality would be that given:
total = 0
for c in rm.getConstrs():
total += c.RHS * c.Pi
"total" would be equal to the objective value, if strong duality holds, or at least less than the objective value, if weak duality holds.
However,
print(total - rm.ObjVal)
751391.7872288637
Which has me pretty confused. The Objective value of my model is:
Optimal objective 1.099028532e+07
I'm optimizing with default parameters. Is Gurobi maybe not updating the dual values to the final value after finishing optimization? And if this is the case, can I force this update? Or am I missing something else entirely?
-
In theory your code is correct. However, in practice, models are not in standard form, i.e., there are also variable bounds and objective constants you have to consider . The following code should do the trick
total = m.ObjCon
for c in m.getConstrs():
total += c.RHS * c.Pi
for v in m.getVars():
if v.VBasis == -1:
total += v.RC * v.lb
if v.VBasis == -2:
total += v.RC * v.ubBest regards,
Jaromił1 -
I also had this problem, Jaromił is correct. Please use GRB_INFINITY to define the UB of the variable if it is implicitly bounded by some constraints elsewhere.
0
Please sign in to leave a comment.
Comments
2 comments