本文整理汇总了Python中pyscipopt.Model.getVarRedcost方法的典型用法代码示例。如果您正苦于以下问题:Python Model.getVarRedcost方法的具体用法?Python Model.getVarRedcost怎么用?Python Model.getVarRedcost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyscipopt.Model
的用法示例。
在下文中一共展示了Model.getVarRedcost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import getVarRedcost [as 别名]
}
# Create variables
x = {}
for j in Blends:
x[j] = model.addVar(vtype="C", name="x(%s)"%j)
# Create constraints
c = {}
for i in Grapes:
c[i] = model.addCons(quicksum(Use[i,j]*x[j] for j in Blends) <= Inventory[i], name="Use(%s)"%i)
# Objective
model.setObjective(quicksum(Profit[j]*x[j] for j in Blends), "maximize")
model.optimize()
if model.getStatus() == "optimal":
print("Optimal value:", model.getObjVal())
for j in x:
print(x[j].name, "=", model.getVal(x[j]), " (red. cost: ", model.getVarRedcost(x[j]), ")")
for i in c:
try:
dual = model.getDualsolLinear(c[i])
except:
dual = None
print("dual of", c[i].name, ":", dual)
else:
print("Problem could not be solved to optimality")