Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyomo can't locate GLPK solver

I'm trying to use the GLPK solver with Pyomo. I have a working model that's been tested, but keep getting an error saying GLPK can't be found.

WARNING: Could not locate the 'glpsol' executable, which is required for solver 'glpk'

I've installed glpk sucessfully. I also added the directory to my path variable so the executed can be called globally. I tested this with glpsol --help from my command line, and see the help info printed.

The below thread says it should be working, but alas, it is not.

How do you install glpk-solver along with pyomo in Winpython

Any ideas?

like image 929
Dylan Cross Avatar asked Aug 31 '15 16:08

Dylan Cross


2 Answers

This answer is late but I want to share the solution that worked for me.

solvername='glpk'

solverpath_folder='C:\\glpk\\w64' #does not need to be directly on c drive

solverpath_exe='C:\\glpk\\w64\\glpsol' #does not need to be directly on c drive

I used to do this:

sys.path.append(solverpath_folder)

solver=SolverFactory(solvername)

This works for the cbc solver in coin-or but it does not work for glpk. Then I tried something different:

solver=SolverFactory(solvername,executable=solverpath_exe)

This worked for both cbc and glpk. No idea why this works (I really didn't do anything else).

Version: Python 2.7 or Python 3.7 (tested both), glpk 4.65

like image 141
Guest Avatar answered Sep 20 '22 17:09

Guest


You can install glpk solver using this command -

brew install glpk

like image 20
ManJan Avatar answered Sep 21 '22 17:09

ManJan