本文整理汇总了Python中pyscipopt.Model.infinity方法的典型用法代码示例。如果您正苦于以下问题:Python Model.infinity方法的具体用法?Python Model.infinity怎么用?Python Model.infinity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyscipopt.Model
的用法示例。
在下文中一共展示了Model.infinity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: weber
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import infinity [as 别名]
def weber(I,x,y,w):
"""weber: model for solving the single source weber problem using soco.
Parameters:
- I: set of customers
- x[i]: x position of customer i
- y[i]: y position of customer i
- w[i]: weight of customer i
Returns a model, ready to be solved.
"""
model = Model("weber")
X,Y,z,xaux,yaux = {},{},{},{},{}
X = model.addVar(lb=-model.infinity(), vtype="C", name="X")
Y = model.addVar(lb=-model.infinity(), vtype="C", name="Y")
for i in I:
z[i] = model.addVar(vtype="C", name="z(%s)"%(i))
xaux[i] = model.addVar(lb=-model.infinity(), vtype="C", name="xaux(%s)"%(i))
yaux[i] = model.addVar(lb=-model.infinity(), vtype="C", name="yaux(%s)"%(i))
for i in I:
model.addCons(xaux[i]*xaux[i] + yaux[i]*yaux[i] <= z[i]*z[i], "MinDist(%s)"%(i))
model.addCons(xaux[i] == (x[i]-X), "xAux(%s)"%(i))
model.addCons(yaux[i] == (y[i]-Y), "yAux(%s)"%(i))
model.setObjective(quicksum(w[i]*z[i] for i in I), "minimize")
model.data = X,Y,z
return model
示例2: weber_MS
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import infinity [as 别名]
def weber_MS(I,J,x,y,w):
"""weber -- model for solving the weber problem using soco (multiple source version).
Parameters:
- I: set of customers
- J: set of potential facilities
- x[i]: x position of customer i
- y[i]: y position of customer i
- w[i]: weight of customer i
Returns a model, ready to be solved.
"""
M = max([((x[i]-x[j])**2 + (y[i]-y[j])**2) for i in I for j in I])
model = Model("weber - multiple source")
X,Y,v,u = {},{},{},{}
xaux,yaux,uaux = {},{},{}
for j in J:
X[j] = model.addVar(lb=-model.infinity(), vtype="C", name="X(%s)"%j)
Y[j] = model.addVar(lb=-model.infinity(), vtype="C", name="Y(%s)"%j)
for i in I:
v[i,j] = model.addVar(vtype="C", name="v(%s,%s)"%(i,j))
u[i,j] = model.addVar(vtype="B", name="u(%s,%s)"%(i,j))
xaux[i,j] = model.addVar(lb=-model.infinity(), vtype="C", name="xaux(%s,%s)"%(i,j))
yaux[i,j] = model.addVar(lb=-model.infinity(), vtype="C", name="yaux(%s,%s)"%(i,j))
uaux[i,j] = model.addVar(vtype="C", name="uaux(%s,%s)"%(i,j))
for i in I:
model.addCons(quicksum(u[i,j] for j in J) == 1, "Assign(%s)"%i)
for j in J:
model.addCons(xaux[i,j]*xaux[i,j] + yaux[i,j]*yaux[i,j] <= v[i,j]*v[i,j], "MinDist(%s,%s)"%(i,j))
model.addCons(xaux[i,j] == (x[i]-X[j]), "xAux(%s,%s)"%(i,j))
model.addCons(yaux[i,j] == (y[i]-Y[j]), "yAux(%s,%s)"%(i,j))
model.addCons(uaux[i,j] >= v[i,j] - M*(1-u[i,j]), "uAux(%s,%s)"%(i,j))
model.setObjective(quicksum(w[i]*uaux[i,j] for i in I for j in J), "minimize")
model.data = X,Y,v,u
return model