Skip to main content

swiglpk - Simple swig bindings for the GNU Linear Programming Kit

Project description

PyPI License Build Status AppVeyor Status

Why?

swiglpk is not a high-level wrapper for GLPK (take a look at optlang if you are interested in a python-based mathematical programming language). It just provides plain vanilla swig bindings to the underlying C library. In constrast to other GLPK wrappers for python (e.g. PyGLPK, Python-GLPK, ctypes-glpk, ecyglpki etc.) it is fairly version agnostic: it will try to guess the location of the glpk.h header file (using which glpsol) and then compile the extension for your particular GLPK installation.

Dependencies

  • GLPK (swiglpk has been tested with versions 4.45 and 4.52 on OS X)

  • swig (swiglpk has been tested tested with version 3.0.2 on OS X)

If you’re on OS X, swig and GLPK can easily be installed with homebrew.

brew install swig glpk

If you’re using ubuntu linux, you can install swig and GLPK using apt-get.

apt-get install glpk-utils libglpk-dev swig

Installation

python setup.py install

Example

Running the following (slightly adapted) example from the GLPK manual

from swiglpk import *

ia = intArray(1+1000); ja = intArray(1+1000);
ar = doubleArray(1+1000);
lp = glp_create_prob();
glp_set_prob_name(lp, "sample");
glp_set_obj_dir(lp, GLP_MAX);
glp_add_rows(lp, 3);
glp_set_row_name(lp, 1, "p");
glp_set_row_bnds(lp, 1, GLP_UP, 0.0, 100.0);
glp_set_row_name(lp, 2, "q");
glp_set_row_bnds(lp, 2, GLP_UP, 0.0, 600.0);
glp_set_row_name(lp, 3, "r");
glp_set_row_bnds(lp, 3, GLP_UP, 0.0, 300.0);
glp_add_cols(lp, 3);
glp_set_col_name(lp, 1, "x1");
glp_set_col_bnds(lp, 1, GLP_LO, 0.0, 0.0);
glp_set_obj_coef(lp, 1, 10.0);
glp_set_col_name(lp, 2, "x2");
glp_set_col_bnds(lp, 2, GLP_LO, 0.0, 0.0);
glp_set_obj_coef(lp, 2, 6.0);
glp_set_col_name(lp, 3, "x3");
glp_set_col_bnds(lp, 3, GLP_LO, 0.0, 0.0);
glp_set_obj_coef(lp, 3, 4.0);
ia[1] = 1; ja[1] = 1; ar[1] = 1.0; # a[1,1] = 1
ia[2] = 1; ja[2] = 2; ar[2] = 1.0; # a[1,2] = 1
ia[3] = 1; ja[3] = 3; ar[3] = 1.0; # a[1,3] = 1
ia[4] = 2; ja[4] = 1; ar[4] = 10.0; # a[2,1] = 10
ia[5] = 3; ja[5] = 1; ar[5] = 2.0; # a[3,1] = 2
ia[6] = 2; ja[6] = 2; ar[6] = 4.0; # a[2,2] = 4
ia[7] = 3; ja[7] = 2; ar[7] = 2.0; # a[3,2] = 2
ia[8] = 2; ja[8] = 3; ar[8] = 5.0; # a[2,3] = 5
ia[9] = 3; ja[9] = 3; ar[9] = 6.0; # a[3,3] = 6
glp_load_matrix(lp, 9, ia, ja, ar);
glp_simplex(lp, None);
Z = glp_get_obj_val(lp);
x1 = glp_get_col_prim(lp, 1);
x2 = glp_get_col_prim(lp, 2);
x3 = glp_get_col_prim(lp, 3);
print("\nZ = %g; x1 = %g; x2 = %g; x3 = %g\n" % (Z, x1, x2, x3))
glp_delete_prob(lp);

… will produce the following output (the example can also be found at examples/example.py):

GLPK Simplex Optimizer, v4.52
3 rows, 3 columns, 9 non-zeros
*     0: obj =   0.000000000e+00  infeas =  0.000e+00 (0)
*     2: obj =   7.333333333e+02  infeas =  0.000e+00 (0)
OPTIMAL LP SOLUTION FOUND

Z = 733.333; x1 = 33.3333; x2 = 66.6667; x3 = 0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

swiglpk-1.3.3rc1-cp35-cp35m-manylinux1_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.5m

swiglpk-1.3.3rc1-cp35-cp35m-manylinux1_i686.whl (1.7 MB view details)

Uploaded CPython 3.5m

swiglpk-1.3.3rc1-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (830.2 kB view details)

Uploaded CPython 3.5m macOS 10.10+ intel macOS 10.10+ x86-64 macOS 10.6+ intel macOS 10.9+ intel macOS 10.9+ x86-64

swiglpk-1.3.3rc1-cp34-cp34m-manylinux1_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.4m

swiglpk-1.3.3rc1-cp34-cp34m-manylinux1_i686.whl (1.7 MB view details)

Uploaded CPython 3.4m

swiglpk-1.3.3rc1-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (830.2 kB view details)

Uploaded CPython 3.4m macOS 10.10+ intel macOS 10.10+ x86-64 macOS 10.6+ intel macOS 10.9+ intel macOS 10.9+ x86-64

swiglpk-1.3.3rc1-cp27-cp27mu-manylinux1_x86_64.whl (1.8 MB view details)

Uploaded CPython 2.7mu

swiglpk-1.3.3rc1-cp27-cp27mu-manylinux1_i686.whl (1.7 MB view details)

Uploaded CPython 2.7mu

swiglpk-1.3.3rc1-cp27-cp27m-manylinux1_x86_64.whl (1.8 MB view details)

Uploaded CPython 2.7m

swiglpk-1.3.3rc1-cp27-cp27m-manylinux1_i686.whl (1.7 MB view details)

Uploaded CPython 2.7m

swiglpk-1.3.3rc1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (833.4 kB view details)

Uploaded CPython 2.7m macOS 10.10+ intel macOS 10.10+ x86-64 macOS 10.6+ intel macOS 10.9+ intel macOS 10.9+ x86-64

File details

Details for the file swiglpk-1.3.3rc1-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 34ec6c8aa32645e47f3d8230dcd6003cd46204ba8278adc343a4139a10006db2
MD5 53d39c925cc3c3b5e05ca47be30e676a
BLAKE2b-256 f5ea5589e52397974ff94cee8c3739a24d85f1ed5444789309748a2d8e7265f1

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc1-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc1-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 332abe0a8e469a8aa97d18e63fa141b4a64962b79026bf1367bdd0732af5289f
MD5 115fd49e0b307b606220f37dbd92bfff
BLAKE2b-256 03f4c7f29f8f7399bfe2a865736036e9dea6ae699180fd60a02704a83c7f518b

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc1-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc1-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 2662a366b9b469aaa5bd774f34ddf4c12f7848fdd9f2f9bd9ef36c892c804409
MD5 b55b5bc258b33f9019a34db77419f37c
BLAKE2b-256 9fd159d1eba1a6fdc19d894618d29e472f0fe84cb8eb10dd360cdd299d2872b1

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc1-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 05627ccb9c622e85ac0ff88f10002703ec533eff44ea0558eb94c62941aa842d
MD5 ff466516bdfde1b6ef4106964d3b12aa
BLAKE2b-256 d5781b7417a642496d1396118033121b103a414e207af35aae3eafb517e372a7

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc1-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc1-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 9337e3f334cd59926c1981ebe943f5d19dd405cefce050a4fd952830e7bc7f92
MD5 d4bbff217ffa8536e6c502210993fffd
BLAKE2b-256 6e510207d6673b625fb77bf7000d9490b08d70df6a31f430660d5096e9a8dc74

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc1-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc1-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 720d1c21ad89a672dac9254306c40c935cefd822657bdb65ca30c45ee7c8f2a0
MD5 58ca02674b42d7b8fbd22c7d36a3f304
BLAKE2b-256 31f16e51f7d2fe7db49ed23bc0bfe0fa5af9dead6ecd4ae1482aff1ca3367bb1

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc1-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 89a04670c95b38ac1221452635b15536ba2311daa407e4814dfc4e5aae659f4e
MD5 989a3a87bac0f5351cff64b0b4e21244
BLAKE2b-256 7cab0b33713fdaee05f28ec195a7b5077c70b4c84e094ff6d6ff03eda20bc625

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc1-cp27-cp27mu-manylinux1_i686.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc1-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 37e1715092dd2da79515f4fd59ab008882896d31e5d979ad3b216d8077a71f13
MD5 20eca93e11c16fdf9b1068dbbc7682e2
BLAKE2b-256 9d665798ec6391a938d54bb885e80425523d4da8f01ad41cb718b22af9bb385f

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc1-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 32cd44c1018691b8d70aa95c49d0446a32c10c05ebb9065dddb99139e53d102c
MD5 82839b40a38dadb254d9707f717c0817
BLAKE2b-256 d15fa6b95626975d07ebe67cae558bc899a01ebfe15372f6e23dea9e3df00fae

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc1-cp27-cp27m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc1-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 da2b682e024b5760691b8b3bbfb6099672f58b16fc7a12a79f19cbee4607ff09
MD5 164d4f0167d6ea94ce404e1c9769f836
BLAKE2b-256 6ff7cb52bfcbf880c281eec0bd27fb7d79cd44d4fc4e3eb561dddaad7ae51b38

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 56a5876c90da511a489264e461e9188c13558117ca0aeccc26f789a47842208a
MD5 189e2cfd501ceeba52ed86e47d58a693
BLAKE2b-256 7d288c8eaf845ef4e44ca2647ba30baaf3182cda8fa37b164fd950a275e8fe5b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page