I am trying to solve a LP problem using PuLP on a Google Colab Notebook. To produce a sensitivity report, I want to use the '--ranges filename.txt'
option of the GLPK solver. I have installed both PuLP and GLPK as follows:
!pip install pulp
!apt-get install -y -qq glpk-utils
Here is a small example I'm trying to solve:
from pulp import *
prob = LpProblem('Test_Problem',LpMaximize) # Model
x1=LpVariable("x1",0,100) #Variables
x2=LpVariable("x2",0,100)
prob += 5*x1 + 10*x2 # Objective
prob += x1 + 5*x2 <= 500 #Constraints
prob += 2*x1 + 3*x2 <= 200
prob.solve(GLPK(options=[])) # Solve Without '--ranges sensitivity.txt'
print("Status : ", LpStatus[prob.status]) # Output
print("Objective : ", value(prob.objective))
for v in prob.variables():
print(v.name," : ", v.varValue)
This runs fine and gives me the desired output. However, if I use 'options' and change the following line
prob.solve(GLPK(options=['--ranges sensitivity.txt']))
I get this error:
/usr/local/lib/python3.6/dist-packages/pulp/apis/glpk_api.py in actualSolve(self, lp)
91
92 if not os.path.exists(tmpSol):
---> 93 raise PulpSolverError("PuLP: Error while executing "+self.path)
94 status, values = self.readsol(tmpSol)
95 lp.assignVarsVals(values)
PulpSolverError: PuLP: Error while executing glpsol
I have checked that the same code with 'options' works fine on my computer and produces the correct sensitivity.txt
file. But for some reason, it is not working on Colab. (I've installed GLPK using conda-forge in my laptop.)
What can I do to solve this?
Thanks!
The
options
argument to pass to GLPK_CMD need to have no spaces, so:Then it works. With your cases, GLPK gave an error without solving the problem saying: