Reputation: 11389
I am using the PuLP library in Python to solve an MILP problem. I have run my problem successfully with the default solver (CBC). Now I would like to use PuLP with another solver (GLPK). How do I set up PuLP with GLPK?
I have done some research online and found information on how to use GLPK (e.g. with lp_prob.solve(pulp.GLPK_CMD())
) but haven't found information on how to actually set up PuLP with GLPK (or any other solver for that matter), so that it finds my GLPK installation. I have already installed GLPK seperately (but I didn't add it to my PATH environment variable).
I ran the command pulp.pulpTestAll()
and got:
Solver <class 'pulp.solvers.GLPK_CMD'> unavailable
I know that I should be getting a "passed" instead of an "unavailable" to be able to use it.
Upvotes: 3
Views: 7355
Reputation: 34
I had same problem, but is not related with glpk installation, is with solution file create, the message is confusim. My problem was I use numeric name for my variables, as '0238' ou '1342', I add a 'x' before it, then they looked like 'x0238'.
Upvotes: 1
Reputation: 11389
After reading in more detail the code and testing out some things, I finally found out how to use GLPK with PuLP, without changing anything in the PuLP package itself.
Your need to pass the path as an argument to GLPK_CMD in solve as follows (replace with your glpsol path):
lp_prob.solve(GLPK_CMD(path = 'C:\\Users\\username\\glpk-4.65\\w64\\glpsol.exe')
You can also pass options that way, e.g.
lp_prob.solve(GLPK_CMD(path = 'C:\\Users\\username\\glpk-4.65\\w64\\glpsol.exe', options = ["--mipgap", "0.01","--tmlim", "1000"])
Upvotes: 3