本文整理汇总了Python中pyscipopt.Model.write方法的典型用法代码示例。如果您正苦于以下问题:Python Model.write方法的具体用法?Python Model.write怎么用?Python Model.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyscipopt.Model
的用法示例。
在下文中一共展示了Model.write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mils_fl
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import write [as 别名]
def mils_fl(T,P,f,g,c,d,h,M):
"""
mils_fl: facility location formulation for the multi-item lot-sizing problem
Requires more variables, but gives a better solution because LB is
better than the standard formulation. It can be used as a
heuristic method that is sometimes better than relax-and-fix.
Parameters:
- T: number of periods
- P: set of products
- f[t,p]: set-up costs (on period t, for product p)
- g[t,p]: set-up times
- c[t,p]: variable costs
- d[t,p]: demand values
- h[t,p]: holding costs
- M[t]: resource upper bound on period t
Returns a model, ready to be solved.
"""
Ts = range(1,T+1)
model = Model("multi-item lotsizing -- facility location formulation")
y,X = {},{}
for p in P:
for t in Ts:
y[t,p] = model.addVar(vtype="B", name="y(%s,%s)"%(t,p))
for s in range(1,t+1):
X[s,t,p] = model.addVar(name="X(%s,%s,%s)"%(s,t,p))
for t in Ts:
# capacity constraints
model.addCons(quicksum(X[t,s,p] for s in range(t,T+1) for p in P) + \
quicksum(g[t,p]*y[t,p] for p in P) <= M[t],
"Capacity(%s)"%(t))
for p in P:
# demand satisfaction constraints
model.addCons(quicksum(X[s,t,p] for s in range(1,t+1)) == d[t,p], "Demand(%s,%s)"%(t,p))
# connection constraints
for s in range(1,t+1):
model.addCons(X[s,t,p] <= d[t,p] * y[s,p], "Connect(%s,%s,%s)"%(s,t,p))
C = {} # variable costs plus holding costs
for p in P:
for s in Ts:
sumC = 0
for t in range(s,T+1):
C[s,t,p] = (c[s,p] + sumC)
sumC += h[t,p]
model.setObjective(quicksum(f[t,p]*y[t,p] for t in Ts for p in P) + \
quicksum(C[s,t,p]*X[s,t,p] for t in Ts for p in P for s in range(1,t+1)),
"minimize")
model.data = y,X
model.write("tmp.lp")
return model