def actualSolve(self, lp):
"""Solve a well formulated lp problem"""
if not self.executable(self.path):
raise PulpSolverError("PuLP: cannot execute "+self.path)
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, writeSOS = 1)
try: os.remove(tmpSol)
except: pass
cmd = self.path
cmd += ' ' + ' '.join(['%s=%s' % (key, value)
for key, value in self.options])
cmd += ' ResultFile=%s' % tmpSol
if lp.isMIP():
if not self.mip:
warnings.warn('GUROBI_CMD does not allow a problem to be relaxed')
cmd += ' %s' % tmpLp
if self.msg:
pipe = None
else:
pipe = open(os.devnull, 'w')
return_code = subprocess.call(cmd.split(), stdout = pipe, stderr = pipe)
if return_code != 0:
raise PulpSolverError("PuLP: Error while trying to execute "+self.path)
if not self.keepFiles:
try: os.remove(tmpLp)
except: pass
if not os.path.exists(tmpSol):
warnings.warn('GUROBI_CMD does provide good solution status of non optimal solutions')
status = LpStatusNotSolved
else:
status, values, reducedCosts, shadowPrices, slacks = self.readsol(tmpSol)
if not self.keepFiles:
try: os.remove(tmpSol)
except: pass
try: os.remove("gurobi.log")
except: pass
if status != LpStatusInfeasible:
lp.assignVarsVals(values)
lp.assignVarsDj(reducedCosts)
lp.assignConsPi(shadowPrices)
lp.assignConsSlack(slacks)
lp.status = status
return status
评论列表
文章目录