{"id":32178320,"url":"https://github.com/opencobra/swiglpk","last_synced_at":"2025-12-12T01:04:14.405Z","repository":{"id":19141826,"uuid":"22371961","full_name":"opencobra/swiglpk","owner":"opencobra","description":"Simple swig bindings for the GNU Linear Programming Kit","archived":false,"fork":false,"pushed_at":"2025-10-02T08:19:04.000Z","size":19945,"stargazers_count":29,"open_issues_count":4,"forks_count":10,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-10-21T20:53:28.949Z","etag":null,"topics":["modeling-language","optimization","python","scientific-computing","symbolic"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opencobra.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2014-07-29T07:53:57.000Z","updated_at":"2025-10-02T08:19:07.000Z","dependencies_parsed_at":"2023-11-06T14:37:26.626Z","dependency_job_id":"950753eb-6da8-4160-bf1b-212082fc3b26","html_url":"https://github.com/opencobra/swiglpk","commit_stats":{"total_commits":248,"total_committers":8,"mean_commits":31.0,"dds":0.5241935483870968,"last_synced_commit":"b2aacbecd8ea7be2c6406ac2d264c84be8999b8b"},"previous_names":["opencobra/swiglpk","biosustain/swiglpk"],"tags_count":73,"template":false,"template_full_name":null,"purl":"pkg:github/opencobra/swiglpk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencobra%2Fswiglpk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencobra%2Fswiglpk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencobra%2Fswiglpk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencobra%2Fswiglpk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opencobra","download_url":"https://codeload.github.com/opencobra/swiglpk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencobra%2Fswiglpk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280333496,"owners_count":26312845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["modeling-language","optimization","python","scientific-computing","symbolic"],"created_at":"2025-10-21T20:53:26.965Z","updated_at":"2025-10-21T20:53:30.851Z","avatar_url":"https://github.com/opencobra.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"swiglpk\n=======\n\n*Plain python bindings for the GNU Linear Programming Kit (GLPK)*\n\n|PyPI| |License| |Build Status|\n\nWhy?\n~~~~\n\n*swiglpk* is not a high-level wrapper for GLPK (take a look at\n`optlang \u003chttps://github.com/biosustain/optlang\u003e`__ if you are\ninterested in a python-based mathematical programming language). It just\nprovides plain vanilla `swig \u003chttp://www.swig.org/\u003e`__ bindings to the\nunderlying C library. In constrast to other GLPK wrappers for python\n(e.g. `PyGLPK \u003chttp://tfinley.net/software/pyglpk/\u003e`__,\n`Python-GLPK \u003chttp://www.dcc.fc.up.pt/~jpp/code/python-glpk/\u003e`__,\n`ctypes-glpk \u003chttps://code.google.com/p/ctypes-glpk/\u003e`__,\n`ecyglpki \u003chttps://github.com/equaeghe/ecyglpki\u003e`__ etc.) it is fairly\nversion agnostic: it will try to guess the location of the glpk.h header\nfile (using ``which glpsol``) and then compile the extension for your\nparticular GLPK installation. Furthermore, swiglpk provides binary wheels\nfor all major platforms, which are always up-to-date with the most\nrecent GLPK version (swiglpk versions follow GLPK versioning in the major\nand minor version digits to emphasize that).\n\nPlease show us some love by staring this repo if you find swiglpk useful!\n\nInstallation\n~~~~~~~~~~~~\n\n::\n\n    pip install swiglpk\n\nThat's it. swiglpk comes with binary wheels for Windows, Mac, and Linux. No installation of third-party dependencies necessary.\n\nExample\n~~~~~~~\n\nRunning the following (slightly adapted) example from the `GLPK\nmanual \u003chttp://kam.mff.cuni.cz/~elias/glpk.pdf\u003e`__ ...\n\n::\n\n    from swiglpk import *\n\n    ia = intArray(1+1000); ja = intArray(1+1000);\n    ar = doubleArray(1+1000);\n    lp = glp_create_prob();\n    glp_set_prob_name(lp, \"sample\");\n    glp_set_obj_dir(lp, GLP_MAX);\n    glp_add_rows(lp, 3);\n    glp_set_row_name(lp, 1, \"p\");\n    glp_set_row_bnds(lp, 1, GLP_UP, 0.0, 100.0);\n    glp_set_row_name(lp, 2, \"q\");\n    glp_set_row_bnds(lp, 2, GLP_UP, 0.0, 600.0);\n    glp_set_row_name(lp, 3, \"r\");\n    glp_set_row_bnds(lp, 3, GLP_UP, 0.0, 300.0);\n    glp_add_cols(lp, 3);\n    glp_set_col_name(lp, 1, \"x1\");\n    glp_set_col_bnds(lp, 1, GLP_LO, 0.0, 0.0);\n    glp_set_obj_coef(lp, 1, 10.0);\n    glp_set_col_name(lp, 2, \"x2\");\n    glp_set_col_bnds(lp, 2, GLP_LO, 0.0, 0.0);\n    glp_set_obj_coef(lp, 2, 6.0);\n    glp_set_col_name(lp, 3, \"x3\");\n    glp_set_col_bnds(lp, 3, GLP_LO, 0.0, 0.0);\n    glp_set_obj_coef(lp, 3, 4.0);\n    ia[1] = 1; ja[1] = 1; ar[1] = 1.0; # a[1,1] = 1\n    ia[2] = 1; ja[2] = 2; ar[2] = 1.0; # a[1,2] = 1\n    ia[3] = 1; ja[3] = 3; ar[3] = 1.0; # a[1,3] = 1\n    ia[4] = 2; ja[4] = 1; ar[4] = 10.0; # a[2,1] = 10\n    ia[5] = 3; ja[5] = 1; ar[5] = 2.0; # a[3,1] = 2\n    ia[6] = 2; ja[6] = 2; ar[6] = 4.0; # a[2,2] = 4\n    ia[7] = 3; ja[7] = 2; ar[7] = 2.0; # a[3,2] = 2\n    ia[8] = 2; ja[8] = 3; ar[8] = 5.0; # a[2,3] = 5\n    ia[9] = 3; ja[9] = 3; ar[9] = 6.0; # a[3,3] = 6\n    glp_load_matrix(lp, 9, ia, ja, ar);\n    glp_simplex(lp, None);\n    Z = glp_get_obj_val(lp);\n    x1 = glp_get_col_prim(lp, 1);\n    x2 = glp_get_col_prim(lp, 2);\n    x3 = glp_get_col_prim(lp, 3);\n    print(\"\\nZ = %g; x1 = %g; x2 = %g; x3 = %g\\n\" % (Z, x1, x2, x3))\n    glp_delete_prob(lp);\n\n... will produce the following output (the example can also be found at\nexamples/example.py):\n\n::\n\n    GLPK Simplex Optimizer, v4.52\n    3 rows, 3 columns, 9 non-zeros\n    *     0: obj =   0.000000000e+00  infeas =  0.000e+00 (0)\n    *     2: obj =   7.333333333e+02  infeas =  0.000e+00 (0)\n    OPTIMAL LP SOLUTION FOUND\n\n    Z = 733.333; x1 = 33.3333; x2 = 66.6667; x3 = 0\n\nPretty ugly right? Consider using `optlang \u003chttps://github.com/biosustain/optlang\u003e`__ for formulating and solving your optimization problems.\n\nDocumentation\n~~~~~~~~~~~~~\n\nYou can find documentation on GLPK's C API `here \u003chttp://kam.mff.cuni.cz/~elias/glpk.pdf\u003e`__\n\nDevelopment\n~~~~~~~~~~~\n\nYou still want to install it from source? Then you'll need to install the following\ndependencies first.\n\n-  GLPK\n-  swig\n\nIf you're on OS X, swig and GLPK can easily be installed with\n`homebrew \u003chttp://brew.sh/\u003e`__.\n\n::\n\n    brew install swig glpk\n\nIf you're using ubuntu linux, you can install swig and GLPK using\n``apt-get``.\n\n::\n\n    apt-get install glpk-utils libglpk-dev swig\n\nIf you're on Windows, you are on your own (checkout the `appveyor.yml \u003chttps://github.com/biosustain/swiglpk/blob/master/appveyor.yml\u003e`_ config file for directions).\n\nThen clone the repo and run the following.\n::\n\n    python setup.py install\n\n\n.. |PyPI| image:: https://img.shields.io/pypi/v/swiglpk.svg\n   :target: https://pypi.python.org/pypi/swiglpk\n.. |License| image:: https://img.shields.io/badge/License-GPL%20v3-blue.svg\n   :target: http://www.gnu.org/licenses/gpl-3.0\n.. |Build Status| image:: https://github.com/biosustain/swiglpk/actions/workflows/main.yml/badge.svg\n   :target: https://github.com/biosustain/swiglpk/actions/workflows/main.yml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencobra%2Fswiglpk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopencobra%2Fswiglpk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencobra%2Fswiglpk/lists"}