如何计算 Gurobi 的影子价格 [英] How to calculate the shadow price in Gurobi
问题描述
我想在一个编程问题中分析Constraints中的边界是应该增加还是减少:下面是简化的问题.V[(i,t)]
是决策变量,S[i]
是输入.我想知道当增加一个单位 S[i]` 时 obj 是增加还是减少.我知道影子价格和边际成本可能是用于决策变量而不是输入.在 Gurobi 中,Dual value(也称为影子价格)可以使用 Pi 函数.
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()
推荐答案
有两种方式获取影子价格:(Python + Gurobi):
There are two ways to get the shadow price:(Python + Gurobi):
shadow_price = model.getAttr('Pi', model.getConstrs())
或
shadow_price = model.getAttr(GRB.Attr.Pi)
它将所有约束的影子价格依次返回到一个数组中.
It returns the shadow prices of all constraints in sequence into an array.
这篇关于如何计算 Gurobi 的影子价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!