passagemath-glpk
raw JSON → 10.8.4 verified Mon Apr 27 auth: no python
passagemath-glpk provides a linear and mixed integer linear optimization backend using GLPK (GNU Linear Programming Kit) for the passagemath library. It enables the construction and solution of linear programming (LP) and mixed-integer linear programming (MILP) problems. Version 10.8.4 supports Python >=3.11,<3.15. The package is part of the passagemath ecosystem, which reimplements functionality previously provided by SageMath.
pip install passagemath-glpk Common errors
error ImportError: cannot import name 'GLPKBackend' from 'passagemath.glpk.backend' ↓
cause GLPKBackend not available if passagemath-glpk not installed or version mismatch.
fix
Run 'pip install passagemath-glpk' and ensure passagemath core is also installed.
error ValueError: solver 'GLPK' is not available ↓
cause The GLPK solver is not installed or not recognized by passagemath.
fix
Install passagemath-glpk: 'pip install passagemath-glpk'.
error TypeError: __init__() got an unexpected keyword argument 'solver' ↓
cause Using old SageMath-style instantiation without solver argument.
fix
Use 'MixedIntegerLinearProgram(solver='GLPK')' instead of 'MixedIntegerLinearProgram()'.
Warnings
breaking GLPKBackend import path changed from sage.numerical.backends.glpk_backend to passagemath.glpk.backend. ↓
fix Change import to 'from passagemath.glpk.backend import GLPKBackend'.
breaking MixedIntegerLinearProgram now requires 'solver' parameter; default may not be GLPK. In SageMath, default was GLPK. ↓
fix Explicitly pass solver='GLPK' when creating MixedIntegerLinearProgram.
gotcha GLPK backend may not be thread-safe; avoid concurrent solve calls. ↓
fix Serialize solve calls or use multiprocessing with separate processes.
Imports
- GLPKBackend wrong
from sage.numerical.backends.glpk_backend import GLPKBackendcorrectfrom passagemath.glpk.backend import GLPKBackend - MixedIntegerLinearProgram wrong
from sage.numerical.mip import MixedIntegerLinearProgramcorrectfrom passagemath.numerical.mip import MixedIntegerLinearProgram - GLPK wrong
from sage.numerical.backends.glpk_backend import GLPKBackendcorrectfrom passagemath.glpk.backend import GLPKBackend
Quickstart
from passagemath.numerical.mip import MixedIntegerLinearProgram
# Create MILP instance with GLPK backend
p = MixedIntegerLinearProgram(solver='GLPK')
# Define variables
x = p['x']
y = p['y']
# Add constraints
p.add_constraint(x + 2*y <= 4)
p.add_constraint(2*x + y <= 6)
# Set objective
p.set_objective(3*x + 4*y)
# Solve
p.solve()
# Get solution
print(f"x = {p.get_values(x)}")
print(f"y = {p.get_values(y)}")