def actualSolve(self, lp):
"""Solve a well formulated lp problem"""
if not self.executable(self.path):
raise PulpSolverError("PuLP: cannot execute "+self.path)
# TODO: should we use tempfile instead?
if not self.keepFiles:
pid = os.getpid()
tmpLp = os.path.join(self.tmpDir, "%d-pulp.lp" % pid)
tmpSol = os.path.join(self.tmpDir, "%d-pulp.sol" % pid)
else:
tmpLp = lp.name + "-pulp.lp"
tmpSol = lp.name + "-pulp.sol"
lp.writeLP(tmpLp)
proc = [
'scip', '-c', 'read "%s"' % tmpLp, '-c', 'optimize',
'-c', 'write solution "%s"' % tmpSol, '-c', 'quit'
]
proc.extend(self.options)
if not self.msg:
proc.append('-q')
self.solution_time = clock()
subprocess.check_call(proc, stdout=sys.stdout, stderr=sys.stderr)
self.solution_time += clock()
if not os.path.exists(tmpSol):
raise PulpSolverError("PuLP: Error while executing "+self.path)
lp.status, values = self.readsol(tmpSol)
# Make sure to add back in any 0-valued variables SCIP leaves out.
finalVals = {}
for v in lp.variables():
finalVals[v.name] = values.get(v.name, 0.0)
lp.assignVarsVals(finalVals)
if not self.keepFiles:
for f in (tmpLp, tmpSol):
try:
os.remove(f)
except:
pass
return lp.status
评论列表
文章目录