Registry / ai-ml / glpk
library0.4.8pypypiunverified

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 glpk
INSTALL
IMPORT
SIG · GLPK
G
glpk
ai-mlpythonv0.4.8
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GLPK
from glpk import GLPK
LP
from glpk import LP
Var
from glpk import Var
Term
from glpk import Term
N
from glpk import N
Represents infinity for variable bounds.
C
from glpk import C
Represents a continuous variable kind.
R
from glpk import R
Represents row/constraint.

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.

from glpk import LP, Var, N, C, GLPK # Create a new problem lp = LP() # Define variables x1 = lp.add_var(name='x1', lb=0.0, ub=N, kind=C) # lb=0, ub=infinity, continuous x2 = lp.add_var(name='x2', lb=0.0, ub=N, kind=C) # Set objective function (maximize 10*x1 + 6*x2) lp.obj.dir = LP.MAX lp.obj += 10 * x1 + 6 * x2 # Add constraints # Constraint 1: x1 + x2 <= 100 c1 = lp.add_row(name='c1') c1.add_term(x1, 1.0) c1.add_term(x2, 1.0) c1.upper_bound = 100.0 # Constraint 2: 7*x1 + 3*x2 <= 350 c2 = lp.add_row(name='c2') c2.add_term(x1, 7.0) c2.add_term(x2, 3.0) c2.upper_bound = 350.0 # Constraint 3: 3*x1 + 5*x2 <= 150 c3 = lp.add_row(name='c3') c3.add_term(x1, 3.0) c3.add_term(x2, 5.0) c3.upper_bound = 150.0 # Solve the problem lp.simplex() # Print results if lp.status == GLPK.LP_OPT: print(f"Status: Optimal") print(f"Objective value: {lp.obj.value:.2f}") print(f"x1 = {x1.value:.2f}") print(f"x2 = {x2.value:.2f}") elif lp.status == GLPK.LP_FEAS: print(f"Status: Feasible, but not necessarily optimal") print(f"Objective value: {lp.obj.value:.2f}") print(f"x1 = {x1.value:.2f}") print(f"x2 = {x2.value:.2f}") else: print(f"Status: Solver terminated with status code: {lp.status}") # Clean up lp.delete()
Debug
Known issues
gotchaPyGLPK requires the GLPK C library to be installed on your system BEFORE installing the Python package. The Python package is a wrapper; it does not install the underlying C library.
fix
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.
affects: All versions
gotchaBe mindful of variable types (continuous, integer, binary) and bounds. Incorrectly defined variables can lead to infeasible or unbounded solutions, or incorrect solver behavior.
fix
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.
affects: All versions
gotchaThe GLPK solver's status codes (e.g., `lp.status`) are integers. For clear and robust interpretation, always compare them against constants from the `glpk.GLPK` module (e.g., `GLPK.LP_OPT`, `GLPK.LP_FEAS`).
fix
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.
affects: All versions
Upgrade
Version history
0.4.8latest on PyPI · released Oct 7, 2024
Audit
Dependencies
GNU Linear Programming Kit (GLPK) C libraryrequiredPyGLPK is a wrapper around the GLPK C library and requires it to be pre-installed on the system. It is not automatically installed by pip.
Agent activity
20 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
glpk — pip install glpk · libregistry