{"id":21684,"library":"passagemath-glpk","title":"passagemath-glpk","description":"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.","status":"active","version":"10.8.4","language":"python","source_language":"en","source_url":"https://github.com/passagemath/passagemath-glpk","tags":["LP","MILP","GLPK","optimization","linear programming","mixed integer programming","backend","passagemath"],"install":[{"cmd":"pip install passagemath-glpk","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Core library providing MILP framework and LP/MILP problem class.","package":"passagemath","optional":false}],"imports":[{"note":"Old SageMath import path won't work; passagemath uses 'passagemath.glpk.backend'.","wrong":"from sage.numerical.backends.glpk_backend import GLPKBackend","symbol":"GLPKBackend","correct":"from passagemath.glpk.backend import GLPKBackend"},{"note":"SageMath import path replaced; use passagemath.numerical.mip.","wrong":"from sage.numerical.mip import MixedIntegerLinearProgram","symbol":"MixedIntegerLinearProgram","correct":"from passagemath.numerical.mip import MixedIntegerLinearProgram"},{"note":"Correct class is GLPKBackend; common mistake to use GLPK directly.","wrong":"from sage.numerical.backends.glpk_backend import GLPKBackend","symbol":"GLPK","correct":"from passagemath.glpk.backend import GLPKBackend"}],"quickstart":{"code":"from passagemath.numerical.mip import MixedIntegerLinearProgram\n\n# Create MILP instance with GLPK backend\np = MixedIntegerLinearProgram(solver='GLPK')\n\n# Define variables\nx = p['x']\ny = p['y']\n\n# Add constraints\np.add_constraint(x + 2*y <= 4)\np.add_constraint(2*x + y <= 6)\n\n# Set objective\np.set_objective(3*x + 4*y)\n\n# Solve\np.solve()\n\n# Get solution\nprint(f\"x = {p.get_values(x)}\")\nprint(f\"y = {p.get_values(y)}\")","lang":"python","description":"Quickstart example: solve a simple MILP using GLPK backend."},"warnings":[{"fix":"Change import to 'from passagemath.glpk.backend import GLPKBackend'.","message":"GLPKBackend import path changed from sage.numerical.backends.glpk_backend to passagemath.glpk.backend.","severity":"breaking","affected_versions":"Migrating from SageMath (any version) to passagemath-glpk >=10.8"},{"fix":"Explicitly pass solver='GLPK' when creating MixedIntegerLinearProgram.","message":"MixedIntegerLinearProgram now requires 'solver' parameter; default may not be GLPK. In SageMath, default was GLPK.","severity":"breaking","affected_versions":"passagemath-glpk >=10.0"},{"fix":"Serialize solve calls or use multiprocessing with separate processes.","message":"GLPK backend may not be thread-safe; avoid concurrent solve calls.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'pip install passagemath-glpk' and ensure passagemath core is also installed.","cause":"GLPKBackend not available if passagemath-glpk not installed or version mismatch.","error":"ImportError: cannot import name 'GLPKBackend' from 'passagemath.glpk.backend'"},{"fix":"Install passagemath-glpk: 'pip install passagemath-glpk'.","cause":"The GLPK solver is not installed or not recognized by passagemath.","error":"ValueError: solver 'GLPK' is not available"},{"fix":"Use 'MixedIntegerLinearProgram(solver='GLPK')' instead of 'MixedIntegerLinearProgram()'.","cause":"Using old SageMath-style instantiation without solver argument.","error":"TypeError: __init__() got an unexpected keyword argument 'solver'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}