I am a newbie with python and optimization. I am getting some error, please help me resolve it. I tried running the below mentioned code in PyCharm where I am running Anaconda 3
from pulp import *
x = LpVariable("x", 0, 3)
y = LpVariable("y", 0, 1)
prob = LpProblem("myProblem", LpMinimize)
prob += x + y <= 2
prob += -4*x + y
status = prob.solve(GLPK(msg = 0))
value(x)
And I got an error
Traceback (most recent call last): File "D:/Projects/RH Analytics/RNN/TestPulp.py", line 10, in status = prob.solve(GLPK(msg = 0)) File "C:\Users\rahul.bajaj\AppData\Local\Continuum\Anaconda3\lib\site-packages\pulp\pulp.py", line 1643, in solve status = solver.actualSolve(self, **kwargs) File "C:\Users\rahul.bajaj\AppData\Local\Continuum\Anaconda3\lib\site-packages\pulp\solvers.py", line 346, in actualSolve raise PulpSolverError("PuLP: cannot execute "+self.path) pulp.solvers.PulpSolverError: PuLP: cannot execute glpsol.exe
Process finished with exit code 1
So I downloaded the glpk package from here, extracted from the zip file and placed it in a folder in C drive. In the path variable I added "C:\winglpk-4.57\glpk-4.57\w64".
But even now I am getting the same error when i run the program in the PyCharm IDE. Please help me sort out what am I missing.
pulp.pulpTestAll()
When you run this command, a list of tests will run and on 32nd line you see:
Solver pulp.solvers.GLPK_CMD unavailable
.
So try and download glpk-utils package then run
glpsol
.
It can be done from cmd as well, worked for me.
I had the same issue and I managed to solve it by renaming the variable. When the variable name in the code and the variable name declared in the argument of LpVariable()
are not the same, it works, otherwise i get the same error.
x = LpVariable('x', 0, 3) # This doesn't work
x = LpVariable('x_var', 0, 1) # This works
I don't know if that is just the case on my machine, since in the documentation they also use the same names for both variables, but it's worth a try.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With