PyGLPK (Python GLPK) is a Python module that provides a comprehensive interface to the GNU Linear Programming Kit (GLPK). It allows Python users to model and solve linear programming (LP), mixed integer programming (MIP), and other related optimization problems. The current version is 0.4.8. It has a moderate release cadence, largely tied to maintenance and updates related to the underlying GLPK C library.
pip install glpkVerified import paths — ran on the pinned version, not inferred.
This quickstart defines and solves a simple linear programming problem with two continuous variables and three constraints. It demonstrates variable definition, objective function setup, constraint creation, solving the problem, and interpreting the results.
Install the GLPK C library for your operating system. For Debian/Ubuntu: `sudo apt-get install libglpk-dev`. For macOS (Homebrew): `brew install glpk`. For Windows, you typically need to build from source or use a pre-compiled binary and ensure it's in your system's PATH.
Always explicitly set `kind` (C, I, B for continuous, integer, binary respectively) and `lb` (lower bound) / `ub` (upper bound) for variables. Use `N` from `glpk` for infinity.
Use `if lp.status == GLPK.LP_OPT:` instead of `if lp.status == 5:` (or other magic numbers). Refer to GLPK documentation for all status constants.