本文整理汇总了Python中pyscipopt.Model.addConsSOS2方法的典型用法代码示例。如果您正苦于以下问题:Python Model.addConsSOS2方法的具体用法?Python Model.addConsSOS2怎么用?Python Model.addConsSOS2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyscipopt.Model
的用法示例。
在下文中一共展示了Model.addConsSOS2方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: eld_complete
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import addConsSOS2 [as 别名]
def eld_complete(U,p_min,p_max,d,brk):
"""eld -- economic load dispatching in electricity generation
Parameters:
- U: set of generators (units)
- p_min[u]: minimum operating power for unit u
- p_max[u]: maximum operating power for unit u
- d: demand
- brk[k]: (x,y) coordinates of breakpoint k, k=0,...,K
Returns a model, ready to be solved.
"""
model = Model("Economic load dispatching")
p,F = {},{}
for u in U:
p[u] = model.addVar(lb=p_min[u], ub=p_max[u], name="p(%s)"%u) # capacity
F[u] = model.addVar(lb=0,name="fuel(%s)"%u)
# set fuel costs based on piecewise linear approximation
for u in U:
abrk = [X for (X,Y) in brk[u]]
bbrk = [Y for (X,Y) in brk[u]]
# convex combination part:
K = len(brk[u])-1
z = {}
for k in range(K+1):
z[k] = model.addVar(ub=1) # do not name variables for avoiding clash
model.addCons(p[u] == quicksum(abrk[k]*z[k] for k in range(K+1)))
model.addCons(F[u] == quicksum(bbrk[k]*z[k] for k in range(K+1)))
model.addCons(quicksum(z[k] for k in range(K+1)) == 1)
model.addConsSOS2([z[k] for k in range(K+1)])
# demand satisfaction
model.addCons(quicksum(p[u] for u in U) == d, "demand")
# objective
model.setObjective(quicksum(F[u] for u in U), "minimize")
model.data = p
return model