Skip to main content

sckit-glpk

Proof of concept Python wrappers for GLPK.

Installation

Should be an easy pip installation:

pip install scikit-glpk

A Python-compatible C compiler is required to build GLPK from source. By default a precompiled wheel is used during pip installation, so you don’t have to compile if you don’t want to. Wheels are available for Linux, Mac, and Windows for supported versions of Python.

Usage

There are a few things in this package:

  • glpk() : the wrappers over the solvers (basically acts like Python-friendly glpsol)

  • mpsread() : convert an MPS file to some matrices

  • mpswrite() : convert matrices to MPS file

  • lpwrite() : convert matrices to CPLEX LP file

from glpk import glpk, GLPK

res = glpk(
    c, A_ub, b_ub, A_eq, b_eq, bounds, solver, sense, maxit, timeout,
    basis_fac, message_level, disp, simplex_options, ip_options,
    mip_options)

from glpk import mpsread, mpswrite, lpwrite

c, A_ub, b_ub, A_eq, b_eq, bounds = mpsread(
    filename, fmt=GLPK.GLP_MPS_FILE, ret_glp_prob=False)

success = mpswrite(c, A_ub, b_ub, A_eq, b_eq, bounds, sense, filename, fmt)

success = lpwrite(c, A_ub, b_ub, A_eq, b_eq, bounds, sense, filename)

There’s lots of information in the docstrings for these functions, please check there for a complete listing and explanation.

Notice that glpk is the wrapper and GLPK acts as a namespace that holds constants.

bounds behaves the same as the scipy.optimize.linprog bounds argument. They are converted to GLPK-style bounds first thing.

GLPK stuffs

GLPK is installed with the module and a linprog-like wrapper is provided with a ctypes backend. A pared-down version of glpk-4.65 is vendored from here and compile instructions are scraped from the makefiles. I’ll try my best to support cross-platform pip installations. Wheels are current being built for Linux/Mac/Windows.

Background

The GNU Linear Programming Kit (GLPK) has simplex, interior-point, and MIP solvers all callable from a C library. We would like to be able to use these from within Python and be potentially included as a backend for scipy’s linprog function.

Note that there are several projects that aim for something like this, but which don’t match up for what I’m looking for:

  • python-glpk : no longer maintained (dead as of ~2013)

  • PyGLPK : GPL licensed

  • PyMathProg : GPL licensed, uses different conventions than that of linprog

  • Pyomo : Big, uses different conventions than that of linprog

  • CVXOPT : Big, GPL licensed

  • Sage : Big, GPL licensed

  • pulp : Calls glpsol from command line (writes problems, solutions to file instead of shared memory model – this is actually easy to do)

  • yaposib : seems dead? OSI-centric

  • ecyglpki : GPL licensed, dead?

  • swiglpk : GPL licensed, low level

  • optlang : sympy-like, cool project otherwise

Why do we want this?

GLPK has a lot of options that the current scipy solvers lack as well as robust MIP support (only basic in HiGHS). It is also a standard, well known solver in the optimization community. The only thing that I want that it lacks on an API level is robust support for column generation. Easy access to GLPK as a backend to linprog would be very welcome (to me at least). I also find access to a linprog LP description (c, A_ub, etc.) to MPS/LP file format convienent for interacting with other solvers such as HiGHS.

Approach

Since the underlying API is quite simple and written in C and only C, ctypes is a good fit for this.

GLPK is packaged but I may want to make it so the user can optionally specify where the installation is on a user’s computer (i.e., path to the shared library) so GLPK is not packaged with scikit-glpk and/or scipy. linprog could then presumably route the problem to the GLPK backend instead of HiGHS or the existing native python solvers.

The ctypes wrapper is required for integrating GLPK into the Python runtime. Instead of using MPS files to communicate problems and reading solutions from files, scipy.sparse.coo_matrix and numpy arrays can be passed directly to the library. More information can be extracted from GLPK this way as well (For example, there is no way to get iteration count except by reading directly from the underlying structs. It is only ever printed to stdout, no other way to get it).

Metadata

Release files for scikit-glpk 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scikit-glpk 0.5.0
File Size Uploaded
scikit-glpk-0.5.0.tar.gz 911.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for scikit-glpk 0.5.0
File
scikit_glpk-0.5.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
scikit_glpk-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
scikit_glpk-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.9+ x86-64 Details
scikit_glpk-0.5.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
scikit_glpk-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
scikit_glpk-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.9+ x86-64 Details
scikit_glpk-0.5.0-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
scikit_glpk-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
scikit_glpk-0.5.0-cp39-cp39-macosx_10_9_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.9+ x86-64 Details
scikit_glpk-0.5.0-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
scikit_glpk-0.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
scikit_glpk-0.5.0-cp38-cp38-macosx_10_9_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.9+ x86-64 Details

Total release size: 12.0 MB

Release files / scikit-glpk-0.5.0.tar.gz

Download URL scikit-glpk-0.5.0.tar.gz
Size 911.4 kB
Tags Source
SHA-256 checksum
How to use checksums
75a8b7f778de892fc61cc6383afd04ba1f7adac4be401a03dbf9165f40b627ff
BLAKE2b-256 checksum
How to use checksums
dfa2e2258dd3ba556c8da6c2f7c8bf12d938af4fa99d634a81bb65a627b35084
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / scikit_glpk-0.5.0-cp311-cp311-win_amd64.whl

Download URL scikit_glpk-0.5.0-cp311-cp311-win_amd64.whl
Size 533.3 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
ef84286b4d644a7e6944afa3e8cad97f2a4cd0f6d77b58911381919592013ca3
BLAKE2b-256 checksum
How to use checksums
492dbafe52d807e315ffc3ad5374addaf150e1e1ab5400ad810060371142100c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / scikit_glpk-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL scikit_glpk-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.7 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
88c770dddc5c357f8f94a75ddfdf4386d5b114a7daac6c7fdbc0b2fabee70025
BLAKE2b-256 checksum
How to use checksums
d381d281846aca979ba51ee9a5cecfa42ea9d22e6309f72c54d38a91d64f248f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / scikit_glpk-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl

Download URL scikit_glpk-0.5.0-cp311-cp311-macosx_10_9_x86_64.whl
Size 550.9 kB
Tags CPython 3.11 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
ddf4983af5ded2cc05d9951888ba72e4eb0bc5c91bf053f2d70d72dbaed0f8a2
BLAKE2b-256 checksum
How to use checksums
e97efcb1a27b24fdb1fc19c174fc11cbcf706e12a6bab095789188c44c17f2f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / scikit_glpk-0.5.0-cp310-cp310-win_amd64.whl

Download URL scikit_glpk-0.5.0-cp310-cp310-win_amd64.whl
Size 533.3 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
b5e8d30145f99191ed394a6d7ca9b1cb8ba988dd4a2b92a42cd7a32ff53208a9
BLAKE2b-256 checksum
How to use checksums
d589716bf9f0638f04cd33229af2f16ac2adbf50570d487e685de97b222302a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / scikit_glpk-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL scikit_glpk-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.7 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
deaae614f0b7043fb63e7b9e047bd1bd6c437fe00f31a9c24c884369d67997df
BLAKE2b-256 checksum
How to use checksums
66ac6e27792c3ca84a0b5eed4b47addf3fe0a0874dbd4ce921f1ae6ca111c3df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / scikit_glpk-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl

Download URL scikit_glpk-0.5.0-cp310-cp310-macosx_10_9_x86_64.whl
Size 550.9 kB
Tags CPython 3.10 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
701eb359917d554cfdcd9f3292e40cb7cccc7593fec29b3f042dca68935a6871
BLAKE2b-256 checksum
How to use checksums
8e58248e6bfc18f1414e7674bec3432f539714a54bfdc8d264f79ad24fb90c0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / scikit_glpk-0.5.0-cp39-cp39-win_amd64.whl

Download URL scikit_glpk-0.5.0-cp39-cp39-win_amd64.whl
Size 533.3 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
d62745be26fdaf57e9fd7909714aeaf1ff24518e9890dbd8ef6462147e25422e
BLAKE2b-256 checksum
How to use checksums
a1ae551f850e2f31ad32d94dff52269787a88ca5f315b12e9fbeec255f376053
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / scikit_glpk-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL scikit_glpk-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.7 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
272e79eb33ef8a2f4f54353683e1a691f434bb0d58099f34e47056db901a2f35
BLAKE2b-256 checksum
How to use checksums
21ea3a2986e687cb104456ce35e28708ede25fef16edcce9b88071c2b12f4974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / scikit_glpk-0.5.0-cp39-cp39-macosx_10_9_x86_64.whl

Download URL scikit_glpk-0.5.0-cp39-cp39-macosx_10_9_x86_64.whl
Size 550.9 kB
Tags CPython 3.9 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
28ba370b6d32cba1513b1481b6b2d80c1869c89fbe006d6f9a4befdb9d9ba61c
BLAKE2b-256 checksum
How to use checksums
17fc37c002fa0df9a4ef088e67b6bb46fb0f9e092c76fdda8a4fe6cb3f2c7c52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / scikit_glpk-0.5.0-cp38-cp38-win_amd64.whl

Download URL scikit_glpk-0.5.0-cp38-cp38-win_amd64.whl
Size 533.3 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
e4c2bca2d1feefcdab86dd45428de9ff11c45c84cea3ca29a86ee625ad8a6b42
BLAKE2b-256 checksum
How to use checksums
aea4132cb7ecd3ae03ec41d1747fa0be0f1100f8e6251392e93b0453e48f263f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / scikit_glpk-0.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL scikit_glpk-0.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.7 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
f1eaa0d237efe04d1d8bc0d54ae624086855af10759e9709da8bf23a2c785a6a
BLAKE2b-256 checksum
How to use checksums
ea4d7c1fe3bafc1907febd41211e49193642b4a911c0f75f595c7d71a0e4cfae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release files / scikit_glpk-0.5.0-cp38-cp38-macosx_10_9_x86_64.whl

Download URL scikit_glpk-0.5.0-cp38-cp38-macosx_10_9_x86_64.whl
Size 550.8 kB
Tags CPython 3.8 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
f04c82095ae50f78ca01e64bbe023cd272f584c19aace2ad46019e160cdc9a36
BLAKE2b-256 checksum
How to use checksums
1c53685fd050ac4391cc08bcd2fd23a1b15039fff03723d18f3e1c03a232303c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.5.0 This release

13 release files

0.4.4

44 release files

0.4.2

30 release files

0.3.1

37 release files

0.3.0

44 release files

0.2.2

33 release files

0.1.4

33 release files

0.1.3

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.5

2 release files

0.0.4

2 release files

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

0.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page