Reputation: 13
Environment: Gurobi 8.1.1 + python3
I tried to build the following linear program model and print the dual price.
min 100 x + y
s.t. x + y >= 1 && 0 <= x, y <= 1
Following is the code:
from gurobipy import *
m = Model()
x = m.addVar(name='X', vtype=GRB.CONTINUOUS, ub=1, lb=0, obj=0)
y = m.addVar(name='Y', vtype=GRB.CONTINUOUS, ub=1, lb=0, obj=0) # first x then y
m.setObjective( x + 100 * y , sense=GRB.MINIMIZE )
m.addConstr( x + y >= 1 )
m.optimize()
print(m.getAttr('Pi', m.getConstrs()))
The output is 1.
But when the two variables are defined in different order, see the following code, the output is 100.
from gurobipy import *
m = Model()
y = m.addVar(name='Y', vtype=GRB.CONTINUOUS, ub=1, lb=0, obj=0)
x = m.addVar(name='X', vtype=GRB.CONTINUOUS, ub=1, lb=0, obj=0) # first y then x
m.setObjective( x + 100 * y , sense=GRB.MINIMIZE )
m.addConstr( x + y >= 1 )
m.optimize()
print(m.getAttr('Pi', m.getConstrs()))
Why are they different?
Upvotes: 1
Views: 129
Reputation: 6716
I guess this happens because all variables are eliminated in presolving and the simplex is not required to solve the problem. If you disable presolving the dual value is identical for both formulations: m.Params.Presolve = 0
edit:
This is actually due to degeneracy. Increasing the upper bounds of the variables removes the degeneracy. See the answer here.
Upvotes: 1