本文整理汇总了Python中pyscipopt.Model.getObjective方法的典型用法代码示例。如果您正苦于以下问题:Python Model.getObjective方法的具体用法?Python Model.getObjective怎么用?Python Model.getObjective使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyscipopt.Model
的用法示例。
在下文中一共展示了Model.getObjective方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: solve
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import getObjective [as 别名]
def solve(self, integer=False):
'''
By default we solve a linear version of the column generation.
If integer is True than we solve the problem of finding the best
routes to be used without column generation.
'''
self.integer = integer
if self.patterns is None:
self.genInitialPatterns()
# Creating master Model:
master = Model("Master problem")
# Creating pricer:
master.setPresolve(SCIP_PARAMSETTING.OFF)
# Populating master model.
# Binary variables z_r indicating whether
# pattern r is used in the solution:
z = {}
for i, _ in enumerate(self.patterns):
z[i] = master.addVar(vtype="B" if integer else "C",
lb=0.0, ub=1.0, name="z_%d" % i)
# Set objective:
master.setObjective(quicksum(self.patCost(p)*z[i] for i, p in enumerate(self.patterns)),
"minimize")
print(master.getObjective())
clientCons = [None]*len(self.clientNodes)
for i, c in enumerate(self.clientNodes):
cons = master.addCons(
quicksum(self.isClientVisited(c, p)*z[i] for i, p in enumerate(self.patterns)) == 1,
"Consumer_%d" % c,
separate=False, modifiable=True)
clientCons[i] = cons
if not integer:
pricer = VRPpricer(z, clientCons, self.data, self.patterns,
self.data.costs, self.isClientVisited,
self.patCost, self.maxPatterns)
master.includePricer(pricer, "VRP pricer", "Identifying new routes")
self.pricer = pricer
self.master = master # Save master model.
master.optimize()