本文整理汇总了Python中pyscipopt.Model.addConstr方法的典型用法代码示例。如果您正苦于以下问题:Python Model.addConstr方法的具体用法?Python Model.addConstr怎么用?Python Model.addConstr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyscipopt.Model
的用法示例。
在下文中一共展示了Model.addConstr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mctransp
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import addConstr [as 别名]
def mctransp(I,J,K,c,d,M):
"""mctransp -- model for solving the Multi-commodity Transportation Problem
Parameters:
- I: set of customers
- J: set of facilities
- K: set of commodities
- c[i,j,k]: unit transportation cost on arc (i,j) for commodity k
- d[i][k]: demand for commodity k at node i
- M[j]: capacity
Returns a model, ready to be solved.
"""
model = Model("multi-commodity transportation")
# Create variables
x = {}
for (i,j,k) in c:
x[i,j,k] = model.addVar(vtype="C", name="x(%s,%s,%s)" % (i,j,k), obj=c[i,j,k])
# todo
arcs = tuplelist([(i,j,k) for (i,j,k) in x])
# Demand constraints
for i in I:
for k in K:
model.addCons(sum(x[i,j,k] for (i,j,k) in arcs.select(i,"*",k)) == d[i,k], "Demand(%s,%s)" % (i,k))
# Capacity constraints
for j in J:
model.addConstr(sum(x[i,j,k] for (i,j,k) in arcs.select("*",j,"*")) <= M[j], "Capacity(%s)" % j)
model.data = x
return model