Pulp error +self.path

I am using python to read data from a .xlsm excel file. I have two files that are nearly identical and are saved in the same directory. When I give the python program one excel sheet, it correctly reads the data and solves the problem. However, with the other excel sheet I get the following error.

(I blocked out my name with ####)

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    solve("updated_excel.xlsm")
  File "C:\Documents and Settings\#####\My Documents\GlockNew.py", line 111, in solve
    prob.solve()
  File "C:\Python27\lib\site-packages\pulp-1.5.4-py2.7.egg\pulp\pulp.py", line 1614, in solve
    status = solver.actualSolve(self, **kwargs)
  File "C:\Python27\lib\site-packages\pulp-1.5.4-py2.7.egg\pulp\solvers.py", line 1276, in actualSolve
    return self.solve_CBC(lp, **kwargs)
  File "C:\Python27\lib\site-packages\pulp-1.5.4-py2.7.egg\pulp\solvers.py", line 1343, in solve_CBC
    raise PulpSolverError, "Pulp: Error while executing "+self.path
PulpSolverError: Pulp: Error while executing C:\Python27\lib\site-packages\pulp-1.5.4-py2.7.egg\pulp\solverdir\cbc.exe

I don't know what ""Pulp: Error while executing "+self.path" means, but both files are stored in the same directory, and the problem only appears once I try to solve the problem. Does anyone have an idea as to what can possible trigger such an error?

EDIT

After further debugging, I have found that the error lies in the solve_CBC method in the COIN_CMD class. The error occurs here:

if not os.path.exists(tmpSol):
    raise PulpSolverError, "Pulp: Error while executing "+self.path

When I run the solver for both excel sheets, they have the same value for tmpSol: 4528-pulp.sol

However, when I run it for one excel sheet os.path.exists(tmpSol) returns true, and for the other it returns false. How can that be- tmpSol has the same value both times?

Answers


The name is created using the process id, if you have some sort of batch job that launches both solver applications from one process then they will have the same name.


I experienced the same issue when launching multiple instances of the LPSolver class. The issue is caused by the following lines of code within the solvers.py file of pulp:

pid = os.getpid()
tmpLp = os.path.join(self.tmpDir, "%d-pulp.lp" % pid)
tmpMps = os.path.join(self.tmpDir, "%d-pulp.mps" % pid)
tmpSol = os.path.join(self.tmpDir, "%d-pulp.sol" % pid)

which appears in every solver. The problem is that these paths are deleted later on, but may coincide for different instances of the LPSolver class (as the variable pid is not unique).

The solution is to get a unique path for each instance of LPSolver, using, for example, the current time. Replacing the above lines by the following four will do the trick.

currentTime = time()
tmpLp = os.path.join(self.tmpDir, "%f3-pulp.lp" % currentTime)
tmpMps = os.path.join(self.tmpDir, "%f3-pulp.mps" % currentTime)
tmpSol = os.path.join(self.tmpDir, "%f3-pulp.sol" % currentTime)

Don't forget to

from time import time

Cheers, Tim


Need Your Help

Make wysiwyg editor in html

html wysiwyg

I will make a wysiwyg1 editor for html. I've made a text area, but how can I make a wysiwyg editor for it? I would be easy if the text area implement html tags like snippet below, but it doesn't. H...

Arabic language is not supported in CentOS

php linux unicode centos arabic

I am not able to save Arabic text when I moved my project to a new server (CentOS 6). The coding and database structure are the same. But in my new server it is printing just like ????.