How to calculate the shadow price in Gurobi

拟墨画扇 提交于 2021-02-10 07:07:58

问题


I want to analyze whether the boundary should increase or reduce in Constraints in a programming problem: The following is simplified problem. V[(i,t)]is decision variable and S[i] is input. I want to know if the obj increases or reduces when increasing one unit of S[i]`. I know may the shadow price and marginal cost are for decision variable not inputs. In Gurobi, Dual value (also known as the shadow price) can use the Pi function.

for t in range(T):
    for i in range(I):
        m.addConstr(V[(i,t)] <= Lambda*S[i])
        m.addConstr(other constrints without S[i])
obj =cf*quicksum(V[(i,0)] for i in range(I))+ cs*quicksum(S[i]for i in range(I))+...
m.setObjective(obj, GRB.MAXIMIZE)
m.optimize()

回答1:


There are two ways to get the shadow price:(Python + Gurobi):

shadow_price = model.getAttr('Pi', model.getConstrs())

or

shadow_price = model.getAttr(GRB.Attr.Pi)

It returns the shadow prices of all constraints in sequence into an array.



来源:https://stackoverflow.com/questions/49126492/how-to-calculate-the-shadow-price-in-gurobi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!