当前位置: 首页>>代码示例>>Python>>正文


Python Model.getDualsolLinear方法代码示例

本文整理汇总了Python中pyscipopt.Model.getDualsolLinear方法的典型用法代码示例。如果您正苦于以下问题:Python Model.getDualsolLinear方法的具体用法?Python Model.getDualsolLinear怎么用?Python Model.getDualsolLinear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyscipopt.Model的用法示例。


在下文中一共展示了Model.getDualsolLinear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: print

# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import getDualsolLinear [as 别名]
    ("Baga","Sweet"):1,
    ("Castelao","Dry"):0,
    ("Castelao","Medium"):0,
    ("Castelao","Sweet"):1
    }

# 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]))
    for i in c:
        print("dual of", c[i].name, ":", model.getDualsolLinear(c[i]))
else:
    print("Problem could not be solved to optimality")
开发者ID:fserra,项目名称:PySCIPOpt,代码行数:32,代码来源:lo_wines.py

示例2: print

# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import getDualsolLinear [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")
开发者ID:SCIP-Interfaces,项目名称:PySCIPOpt,代码行数:32,代码来源:lo_wines.py


注:本文中的pyscipopt.Model.getDualsolLinear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。