Linear Programming Shadow Price Not Correct
Answered## I write a Linear Programming code using python as follows: ##
m = Model()
t15 = m.addVar(name="t15",lb = 0,ub = float('inf'))
t14 = m.addVar(name="t14",lb = 0,ub = float('inf'))
t13 = m.addVar(name="t13",lb = 0,ub = float('inf'))
t12 = m.addVar(name="t12",lb = 0,ub = float('inf'))
t11 = m.addVar(name="t11",lb = 0,ub = float('inf'))
t8 = m.addVar(name="t8",lb = 0,ub = float('inf'))
theta14 = m.addVar(name="theta14",lb = 0,ub = 1)
theta13 = m.addVar(name="theta13",lb = 0,ub = 1)
theta12 = m.addVar(name="theta12",lb = 0,ub = 1)
theta11 = m.addVar(name="theta11",lb = 0,ub = 1)
theta10 = m.addVar(name="theta10",lb = 0,ub = 1)
theta9 = m.addVar(name="theta9",lb = 0,ub = 1)
theta8 = m.addVar(name="theta8",lb = 0,ub = 1)
theta5 = m.addVar(name="theta5",lb = 0,ub = 1)
m.setObjective(- t15, GRB.MAXIMIZE)
cs1 = m.addConstr(-t15 + t14 - 5.03818075*theta14 <= -10.0763615, "c1")
cs2 = m.addConstr(-t14 + t13 - 10.7154514*theta13 <= -21.4309028, "c2")
cs3 = m.addConstr(-t14 + t12 - 14.5188343*theta12 <= -29.0376686, "c3")
cs4 = m.addConstr(-t13 - 494.2427975*theta10 <= -1030.985595, "c4")
cs5 = m.addConstr(-t13 - 1046.20334*theta9 <= -2126.50668, "c5")
cs6 = m.addConstr(-t13 + t8 - 2987.223575*theta8 <= -5974.44715, "c6")
cs7 = m.addConstr(-t12 + t11 - 1184.100035*theta11 <= -2368.20007, "c7")
cs8 = m.addConstr(-t11 <= -34.1, "c8")
cs9 = m.addConstr(-t11 - 440.3886735*theta5 <= -898.277347, "c9")
cs10 = m.addConstr(-t11 <= -30, "c10")
cs11 = m.addConstr(-t8 - 440.3886735*theta5 <= -898.277347, "c11")
cs12 = m.addConstr(theta5 + theta8 + theta9 + theta10 + theta11 + theta12 + theta13 + theta14 <= 1, "c12")
m.optimize()
obj_value = m.objVal
shadow = m.getAttr('Pi', m.getConstrs())
RHS = np.array([-10.0763615,-21.4309028,-29.0376686,-1030.985595,-2126.50668,-5974.44715,-2368.20007,-34.1,-898.277347,-30,-898.277347,1])
## The program output is: ##
Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (mac64)
Thread count: 4 physical cores, 8 logical processors, using up to 8 threads
Optimize a model with 12 rows, 14 columns and 33 nonzeros
Model fingerprint: 0xe80ea2bf
Coefficient statistics:
Matrix range [1e+00, 3e+03]
Objective range [1e+00, 1e+00]
Bounds range [1e+00, 1e+00]
RHS range [1e+00, 6e+03]
Presolve removed 12 rows and 14 columns
Presolve time: 0.01s
Presolve: All rows and columns removed
Iteration Objective Primal Inf. Dual Inf. Time
0 -3.9170082e+03 0.000000e+00 2.951578e+01 0s
Extra simplex iterations after uncrush: 1
1 -3.9170082e+03 0.000000e+00 0.000000e+00 0s
Solved in 1 iterations and 0.01 seconds
Optimal objective -3.917008186e+03
## The shadow price output is:##
shadow
[1.0, 1.0, -0.0, 0.0, 0.0, 1.0, 0.0, 0.0, -0.0, 0.0, 1.0, 440.3886735]
## However, the inner product of shadow and RHS is: ##
np.inner(shadow,RHS)
-6463.843087799999
## which is not equal to the optimal objective value -3.9170082e+03, why is the shadow price not correct? Thank you. ##
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
This was already discussed in Issue with dual values for continuous model.
0
Post is closed for comments.
Comments
2 comments