pythonpulpglpk

How to configure PuLP to call GLPK solver


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.


Solution

  • 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"])