Skip to main content

swiglpk - Simple swig bindings for the GNU Linear Programming Kit

Project description

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.2.22-cp35-cp35m-manylinux1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.5m

swiglpk-1.2.22-cp35-cp35m-manylinux1_i686.whl (1.6 MB view details)

Uploaded CPython 3.5m

swiglpk-1.2.22-cp34-cp34m-win_amd64.whl (522.4 kB view details)

Uploaded CPython 3.4m Windows x86-64

swiglpk-1.2.22-cp34-cp34m-win32.whl (440.8 kB view details)

Uploaded CPython 3.4m Windows x86

swiglpk-1.2.22-cp34-cp34m-manylinux1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.4m

swiglpk-1.2.22-cp34-cp34m-manylinux1_i686.whl (1.6 MB view details)

Uploaded CPython 3.4m

swiglpk-1.2.22-cp27-cp27mu-manylinux1_x86_64.whl (1.7 MB view details)

Uploaded CPython 2.7mu

swiglpk-1.2.22-cp27-cp27mu-manylinux1_i686.whl (1.6 MB view details)

Uploaded CPython 2.7mu

swiglpk-1.2.22-cp27-cp27m-win_amd64.whl (523.5 kB view details)

Uploaded CPython 2.7m Windows x86-64

swiglpk-1.2.22-cp27-cp27m-win32.whl (440.2 kB view details)

Uploaded CPython 2.7m Windows x86

swiglpk-1.2.22-cp27-cp27m-manylinux1_x86_64.whl (1.7 MB view details)

Uploaded CPython 2.7m

swiglpk-1.2.22-cp27-cp27m-manylinux1_i686.whl (1.6 MB view details)

Uploaded CPython 2.7m

File details

Details for the file swiglpk-1.2.22-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.22-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 db2b89568e5ab01984108ac15b4f99c487fb54b74e7de1a3f40b1d93c99d6a50
MD5 b95751bf245b6b6a74fc85f160b712b2
BLAKE2b-256 4fa4258eed7cffad9e884c6c08b88e5eca15d8f182bd3e5cfb6d7e6353828336

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.22-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.22-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 9cf6ccd2adc78c219fdd92ce2a6c3f16dc0e293a6593d8864806a13dfca100ac
MD5 41f2d5a6776d46b766490df81bfea050
BLAKE2b-256 4dd1cf78dc9025dc2a821cefffd8b69909e3df219dc06a09fdf00f39131c0b2e

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.22-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.22-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 9100ad83828e5ba13b66f41704c94ad21e8fb793d443cc182574875cc12e4563
MD5 1aa6808b2fdc3fa162030f9abfd8903b
BLAKE2b-256 33891a080024540c3e3fcea473f2388ed35b50e550e6ea44146bdfe75277587f

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.22-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.22-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 1b58e897a5709977a5047e9820c1ab14c1c1cf72a8afc56e4b1123d3e87cbcf9
MD5 901f0c309ed7eeeadf21f3958fe144e1
BLAKE2b-256 9ed715224a385ce204eba65217fc81dcf05b04a0a22d7f7288a86e30377a0ba0

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.22-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.22-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b3355dbfc10329a83511b1bf9f8d404abd608398894cd2b48f81781c88dd2b61
MD5 f30d4d8b0a736b326e4935cbe4ee3145
BLAKE2b-256 626b8a72f5f257d9d3fb352a06b7b17d48743e93027662176860782a060932e2

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.22-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.22-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 782ba0b0161294c024981023e6c93b729c3a923e92334b29dab1fc51acc7ea6b
MD5 4662ad200a9be91b7661595ed0f5c139
BLAKE2b-256 f58f27fe353045cb74f95b6a119747d0f8723c9a4584674f3e288442bb2ef83a

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.22-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.22-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ea784dd0bf5633762fef8e34af49eb7515e20d782193d74624e1aa42d1fda679
MD5 39a740655e51dfd79fad5904df0e058b
BLAKE2b-256 b779dd3d5bda4d57e3682dcf43d96617c4cd18a733bc978a46977ee542b36c0d

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.22-cp27-cp27mu-manylinux1_i686.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.22-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 e4e5832000a5143fcfe183936caf07144ce2c634677b4d5a074c93eeb5d942a1
MD5 b713c62e9e5a814a8d3d61877068b211
BLAKE2b-256 c640f75df9bd1658f918a00d1f07efcf1fc73c86dde9a83b1345e9371af195ad

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.22-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.22-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 d93f3fbd21f77ad244cf6f4a54b3902e712c83c6fbec988c963aebcc09b03e43
MD5 6863bc20390d5337a66265783228d99d
BLAKE2b-256 cfc65421fa5ae33c847a3dfea471d8263ecfdf6840ae3e3fe31def6cd5346817

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.22-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.22-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 9e0d0818ff56247fb00585b065b8104af7ff7a4b33fb9767b34535226f473854
MD5 82bd854c2e4fe91e5df3a253b9e6982a
BLAKE2b-256 2a0544d869803fa0d5a59f4313d3ae5dfaf67280973ed0f7a797a13c294937ed

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.22-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.22-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 59c9d58fec64d6fa8d211ef5f4efe2b95b013cbd63c193284762b23146e88583
MD5 be60b04a7b1cc0a56ed73ccd6cae0c69
BLAKE2b-256 d234b185183a0d48d6f7b81c1843dcd68ed00f7fbdf48fb674d30368227ff072

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.22-cp27-cp27m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.22-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 1ad31e8949dd0f89edaff8bd6a43d17e45eab6f7a6ab687b875b452298bc5298
MD5 2c308edbb670d3361c1c5b2b90f1ebfc
BLAKE2b-256 24f5b07750528d046ccaea78f06f2e31b7a408dbb2d55e5953303a12e9e4ce4f

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