本文整理汇总了Python中pyscipopt.Model.setRealParam方法的典型用法代码示例。如果您正苦于以下问题:Python Model.setRealParam方法的具体用法?Python Model.setRealParam怎么用?Python Model.setRealParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyscipopt.Model
的用法示例。
在下文中一共展示了Model.setRealParam方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: solve
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import setRealParam [as 别名]
def solve(self, timeLimit):
# Model for the vrp:
subMIP = Model("VRP-MTZ")
subMIP.setMinimize
subMIP.setRealParam("limits/time", timeLimit)
# Binary variables x_ij indicating whether the vehicle
# traverses edge (i, j)
x = {}
for i in self.data.nodes:
for j in self.data.nodes:
if i != j:
x[i, j] = subMIP.addVar(vtype="B", obj=self.data.costs[i, j], name="x_%d_%d" % (i, j))
# Non negative variables u_i indicating the demand served up to node i:
u = {}
for i in self.data.nodes:
u[i] = subMIP.addVar(vtype="C", lb=0, ub=self.data.cap, obj=0.0, name="u_%d" % i)
for j in self.clientNodes:
subMIP.addCons(quicksum(x[i, j] for i in self.data.nodes if i != j) == 1)
for h in self.clientNodes:
subMIP.addCons(quicksum(x[i, h] for i in self.data.nodes if i != h) ==
quicksum(x[h, i] for i in self.data.nodes if i != h))
for i in self.data.nodes:
for j in self.clientNodes:
if i != j:
subMIP.addCons(u[j] >= u[i] + self.data.demands[j]*x[i, j] - self.data.cap*(1 - x[i, j]))
subMIP.optimize()
self.model = subMIP
示例2: test_gastrans
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import setRealParam [as 别名]
#.........这里部分代码省略.........
("Petange", None, -1.919, 25.0, 66.2, 0.0 ), # 12
("Peronnes", 0.0, 0.96, 0.0, 66.2, 1.68 ), # 13
("Sinsin", 0.0, 0.0, 0.0, 63.0, 0.0 ), # 14
("Voeren", 20.344, 22.012, 50.0, 66.2, 1.68 ), # 15
("Wanze", 0.0, 0.0, 0.0, 66.2, 0.0 ), # 16
("Warnand", 0.0, 0.0, 0.0, 66.2, 0.0 ), # 17
("Zeebrugge", 8.87, 11.594, 0.0, 77.0, 2.28 ), # 18
("Zomergem", 0.0, 0.0, 0.0, 80.0, 0.0 ) # 19
]
arcs = [
# node1 node2 diameter length active */
( 18, 6, 890.0, 4.0, False ),
( 18, 6, 890.0, 4.0, False ),
( 6, 5, 890.0, 6.0, False ),
( 6, 5, 890.0, 6.0, False ),
( 5, 19, 890.0, 26.0, False ),
( 9, 1, 590.1, 43.0, False ),
( 1, 7, 590.1, 29.0, False ),
( 7, 19, 590.1, 19.0, False ),
( 19, 13, 890.0, 55.0, False ),
( 15, 3, 890.0, 5.0, True ),
( 15, 3, 395.0, 5.0, True ),
( 3, 8, 890.0, 20.0, False ),
( 3, 8, 395.0, 20.0, False ),
( 8, 17, 890.0, 25.0, False ),
( 8, 17, 395.0, 25.0, False ),
( 17, 11, 890.0, 42.0, False ),
( 11, 0, 890.0, 40.0, False ),
( 0, 13, 890.0, 5.0, False ),
( 13, 10, 890.0, 10.0, False ),
( 10, 4, 890.0, 25.0, False ),
( 17, 16, 395.5, 10.5, False ),
( 16, 14, 315.5, 26.0, True ),
( 14, 2, 315.5, 98.0, False ),
( 2, 12, 315.5, 6.0, False )
]
scip = Model()
# create flow variables
flow = {}
for arc in arcs:
flow[arc] = scip.addVar("flow_%s_%s"%(nodes[arc[0]][0],nodes[arc[1]][0]), # names of nodes in arc
lb = 0.0 if arc[4] else None) # no lower bound if not active
# pressure difference variables
pressurediff = {}
for arc in arcs:
pressurediff[arc] = scip.addVar("pressurediff_%s_%s"%(nodes[arc[0]][0],nodes[arc[1]][0]), # names of nodes in arc
lb = None)
# supply variables
supply = {}
for node in nodes:
supply[node] = scip.addVar("supply_%s"%(node[0]), lb = node[1], ub = node[2], obj = node[5])
# square pressure variables
pressure = {}
for node in nodes:
pressure[node] = scip.addVar("pressure_%s"%(node[0]), lb = node[3]**2, ub = node[4]**2)
# node balance constrains, for each node i: outflows - inflows = supply
for nid, node in enumerate(nodes):
# find arcs that go or end at this node
flowbalance = 0
for arc in arcs:
if arc[0] == nid: # arc is outgoing
flowbalance += flow[arc]
elif arc[1] == nid: # arc is incoming
flowbalance -= flow[arc]
else:
continue
scip.addCons(flowbalance == supply[node], name="flowbalance%s"%node[0])
# pressure difference constraints: pressurediff[node1 to node2] = pressure[node1] - pressure[node2]
for arc in arcs:
scip.addCons(pressurediff[arc] == pressure[nodes[arc[0]]] - pressure[nodes[arc[1]]], "pressurediffcons_%s_%s"%(nodes[arc[0]][0],nodes[arc[1]][0]))
# pressure loss constraints:
# active arc: flow[arc]^2 + coef * pressurediff[arc] <= 0.0
# regular pipes: flow[arc] * abs(flow[arc]) - coef * pressurediff[arc] == 0.0
# coef = 96.074830e-15*diameter(i)^5/(lambda*compressibility*temperatur*length(i)*density)
# lambda = (2*log10(3.7*diameter(i)/rugosity))^(-2)
from math import log10
for arc in arcs:
coef = 96.074830e-15 * arc[2]**5 * (2.0*log10(3.7*arc[2]/RUGOSITY))**2 / COMPRESSIBILITY / GASTEMP / arc[3] / DENSITY
if arc[4]: # active
scip.addCons(flow[arc]**2 + coef * pressurediff[arc] <= 0.0, "pressureloss_%s_%s"%(nodes[arc[0]][0],nodes[arc[1]][0]))
else:
scip.addCons(flow[arc]*abs(flow[arc]) - coef * pressurediff[arc] == 0.0, "pressureloss_%s_%s"%(nodes[arc[0]][0],nodes[arc[1]][0]))
scip.setRealParam('limits/time', 5)
scip.optimize()
if scip.getStatus() == 'timelimit':
pytest.skip()
assert abs(scip.getPrimalbound() - 89.08584) < 1.0e-9
示例3: Model
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import setRealParam [as 别名]
down, eq, up = self.model.branchVarVal(self.cont, 1.3)
self.model.chgVarLbNode(down, self.cont, -1.5)
self.model.chgVarUbNode(up, self.cont, 3.0)
self.was_called_val = True
down2, eq2, up2 = self.model.branchVar(self.integral)
self.was_called_int = True
self.model.createChild(6, 7)
return {"result": SCIP_RESULT.BRANCHED}
m = Model()
m.setIntParam("presolving/maxrounds", 0)
#m.setLongintParam("lp/rootiterlim", 3)
m.setRealParam("limits/time", 60)
x0 = m.addVar(lb=-2, ub=4)
r1 = m.addVar()
r2 = m.addVar()
y0 = m.addVar(lb=3)
t = m.addVar(lb=None)
l = m.addVar(vtype="I", lb=-9, ub=18)
u = m.addVar(vtype="I", lb=-3, ub=99)
more_vars = []
for i in range(1000):
more_vars.append(m.addVar(vtype="I", lb= -12, ub=40))
m.addCons(quicksum(v for v in more_vars) <= (40 - i) * quicksum(v for v in more_vars[::2]))
for i in range(1000):
示例4: getColumnFromMIP
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import setRealParam [as 别名]
def getColumnFromMIP(self, timeLimit):
def getPatternFromSolution(subMIP):
edges = []
for x in subMIP.getVars():
if "x" in x.name:
if subMIP.getVal(x) > 0.99:
i, j = x.name.split("_")[1:]
edges.append((int(i), int(j)))
return edges
# Storing the values of the dual solutions:
dualSols = {}
for c in self.cons:
i = int(c.name.split("_")[-1].strip())
dualSols[i] = self.model.getDualsolLinear(c)
# Model for the sub-problem:
subMIP = Model("VRP-Sub")
subMIP.setPresolve(SCIP_PARAMSETTING.OFF)
subMIP.setMinimize
subMIP.setRealParam("limits/time", timeLimit)
# Binary variables x_ij indicating whether the vehicle
# traverses edge (i, j)
x = {}
for i in self.data.nodes:
for j in self.data.nodes:
if i != j:
x[i, j] = subMIP.addVar(vtype="B", obj=self.data.costs[i, j] - (dualSols[i] if i in self.clientNodes else 0), name="x_%d_%d" % (i, j))
# Non negative variables u_i indicating the demand served up to node i:
u = {}
for i in self.data.nodes:
u[i] = subMIP.addVar(vtype="C", lb=0, ub=self.data.cap, obj=0.0, name="u_%d" % i)
for j in self.clientNodes:
subMIP.addCons(quicksum(x[i, j] for i in self.data.nodes if i != j) <= 1)
for h in self.clientNodes:
subMIP.addCons(quicksum(x[i, h] for i in self.data.nodes if i != h) ==
quicksum(x[h, i] for i in self.data.nodes if i != h))
for i in self.data.nodes:
for j in self.clientNodes:
if i != j:
subMIP.addCons(u[j] >= u[i] + self.data.demands[j]*x[i, j] - self.data.cap*(1 - x[i, j]))
subMIP.addCons(quicksum(x[self.data.depot, j] for j in self.clientNodes) <= 1)
subMIP.hideOutput()
subMIP.optimize()
mipSol = subMIP.getBestSol()
obj = subMIP.getSolObjVal(mipSol)
pattern = getPatternFromSolution(subMIP)
return obj, pattern