本文整理汇总了Python中pyscipopt.Model.free方法的典型用法代码示例。如果您正苦于以下问题:Python Model.free方法的具体用法?Python Model.free怎么用?Python Model.free使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyscipopt.Model
的用法示例。
在下文中一共展示了Model.free方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pricerredcost
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import free [as 别名]
def pricerredcost(self):
# Retreiving the dual solutions
dualSolutions = []
for i, c in enumerate(self.data['cons']):
dualSolutions.append(self.model.getDualsolLinear(c))
# Building a MIP to solve the subproblem
subMIP = Model("CuttingStock-Sub")
# Turning off presolve
subMIP.setPresolve(SCIP_PARAMSETTING.OFF)
# Setting the verbosity level to 0
subMIP.hideOutput()
cutWidthVars = []
varNames = []
varBaseName = "CutWidth"
# Variables for the subMIP
for i in range(len(dualSolutions)):
varNames.append(varBaseName + "_" + str(i))
cutWidthVars.append(subMIP.addVar(varNames[i], vtype = "I", obj = -1.0 * dualSolutions[i]))
# Adding the knapsack constraint
knapsackCoeffs = {cutWidthVars[i] : self.data['widths'][i] for i in range(len(self.data['widths']))}
knapsackCons = subMIP.addCons(knapsackCoeffs, lhs = None, rhs = self.data['rollLength'])
# Solving the subMIP to generate the most negative reduced cost pattern
subMIP.optimize()
objval = 1 + subMIP.getObjVal()
# Adding the column to the master problem
if objval < -1e-08:
currentNumVar = len(self.data['var'])
# Creating new var; must set pricedVar to True
newVar = self.model.addVar("NewPattern_" + str(currentNumVar), vtype = "C", obj = 1.0, pricedVar = True)
# Adding the new variable to the constraints of the master problem
newPattern = []
for i, c in enumerate(self.data['cons']):
coeff = round(subMIP.getVal(cutWidthVars[i]))
self.model.addConsCoeff(c, newVar, coeff)
newPattern.append(coeff)
# Storing the new variable in the pricer data.
self.data['patterns'].append(newPattern)
self.data['var'].append(newVar)
# Freeing the subMIP
subMIP.free()
return {'result':SCIP_RESULT.SUCCESS}
示例2: test_niceqcqp
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import free [as 别名]
def test_niceqcqp():
s = Model()
x = s.addVar("x")
y = s.addVar("y")
s.addCons(x*x + y*y <= 2)
s.setObjective(x + y, sense='maximize')
s.optimize()
assert round(s.getVal(x)) == 1.0
assert round(s.getVal(y)) == 1.0
s.free()
示例3: test_niceqp
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import free [as 别名]
def test_niceqp():
s = Model()
x = s.addVar("x")
y = s.addVar("y")
s.addCons(x >= 2)
s.addCons(x*x <= y)
s.setObjective(y, sense='minimize')
s.optimize()
assert round(s.getVal(x)) == 2.0
assert round(s.getVal(y)) == 4.0
s.free()
示例4: test_nicelp
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import free [as 别名]
def test_nicelp():
# create solver instance
s = Model()
# add some variables
x = s.addVar("x", obj=1.0)
y = s.addVar("y", obj=2.0)
# add some constraint
s.addCons(x + 2*y >= 5)
# solve problem
s.optimize()
# print solution
assert round(s.getVal(x)) == 5.0
assert round(s.getVal(y)) == 0.0
s.free()
示例5: test_simplelp
# 需要导入模块: from pyscipopt import Model [as 别名]
# 或者: from pyscipopt.Model import free [as 别名]
def test_simplelp():
# create solver instance
s = Model()
# add some variables
x = s.addVar("x", vtype='C', obj=1.0)
y = s.addVar("y", vtype='C', obj=2.0)
# add some constraint
coeffs = {x: 1.0, y: 2.0}
s.addCons(coeffs, 5.0)
# solve problem
s.optimize()
# retrieving the best solution
solution = s.getBestSol()
# print solution
assert round(s.getVal(x, solution)) == 5.0
assert round(s.getVal(y, solution)) == 0.0
s.free()