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 Distribution

swiglpk-1.2.12.tar.gz (32.9 kB view details)

Uploaded Source

Built Distributions

swiglpk-1.2.12-py3.5-linux-x86_64.egg (483.5 kB view details)

Uploaded Source

swiglpk-1.2.12-py3.4-linux-x86_64.egg (483.3 kB view details)

Uploaded Source

swiglpk-1.2.12-py3.3-linux-x86_64.egg (479.2 kB view details)

Uploaded Source

swiglpk-1.2.12-py2.7-linux-x86_64.egg (495.7 kB view details)

Uploaded Source

swiglpk-1.2.12-cp35-cp35m-manylinux1_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.5m

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

Uploaded CPython 3.5m

swiglpk-1.2.12-cp34-cp34m-win_amd64.whl (519.6 kB view details)

Uploaded CPython 3.4m Windows x86-64

swiglpk-1.2.12-cp34-cp34m-win32.whl (438.0 kB view details)

Uploaded CPython 3.4m Windows x86

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

Uploaded CPython 3.4m

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

Uploaded CPython 3.4m

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

Uploaded CPython 2.7mu

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

Uploaded CPython 2.7mu

swiglpk-1.2.12-cp27-cp27m-win_amd64.whl (520.7 kB view details)

Uploaded CPython 2.7m Windows x86-64

swiglpk-1.2.12-cp27-cp27m-win32.whl (437.4 kB view details)

Uploaded CPython 2.7m Windows x86

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

Uploaded CPython 2.7m

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

Uploaded CPython 2.7m

File details

Details for the file swiglpk-1.2.12.tar.gz.

File metadata

  • Download URL: swiglpk-1.2.12.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for swiglpk-1.2.12.tar.gz
Algorithm Hash digest
SHA256 ac85088e5920ba73785cc019d7e936e441f76d04b1c9189a2eb3f2c211006650
MD5 b697292878daf9aef7747053de874adc
BLAKE2b-256 ec82c1e19aa4e71920456aae06b0400a9543465e59ae1748a12fa2a90e4ec887

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.12-py3.5-linux-x86_64.egg.

File metadata

File hashes

Hashes for swiglpk-1.2.12-py3.5-linux-x86_64.egg
Algorithm Hash digest
SHA256 99751d8027a6612fcb4860ce54a7d84f7747c0831759f006f2495490c4dc3c5a
MD5 d3acb316ddd646c54f866af2c7b34f74
BLAKE2b-256 0176614de331de228df0592b3053a632353510e00969acd9b2c7e28b8c6184df

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.12-py3.4-linux-x86_64.egg.

File metadata

File hashes

Hashes for swiglpk-1.2.12-py3.4-linux-x86_64.egg
Algorithm Hash digest
SHA256 bc09530b99cb05532bfc981af448f405fc17e9d27e7fe08b6d2ad0789f7a34fa
MD5 5a77a776e631c65958af87954e57bc5a
BLAKE2b-256 06b1711017b66a5fcda6d759644980db1f480f69562b60ee8df567126bdf8f29

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.12-py3.3-linux-x86_64.egg.

File metadata

File hashes

Hashes for swiglpk-1.2.12-py3.3-linux-x86_64.egg
Algorithm Hash digest
SHA256 cc17cd71659e392b6979f83361c8821cf9075b9a16a64fe8f43aa0671bc518c9
MD5 45b63508189e120f95d3d9c318c19174
BLAKE2b-256 ad5159e327bf402687009e3a32a9c02e898aee78b9e236d3c1aae4d07c23fbef

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.12-py2.7-linux-x86_64.egg.

File metadata

File hashes

Hashes for swiglpk-1.2.12-py2.7-linux-x86_64.egg
Algorithm Hash digest
SHA256 8be3a8db0c5f96201179b12fbcc1f1baad407ceb3951709a284d2639900bb9c5
MD5 9eb25bbd173cdd63c9c968ea08d23572
BLAKE2b-256 9502e5298bcf0e0f3ce8525018865f5c10f3e3793756a14fc75558ea0c51082d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.12-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 38e03647220df8f0ec56732e2f724b6858c508edc4630ed6ffe46806643171f3
MD5 a55e55a9d0544196c1412e8635d80117
BLAKE2b-256 5050d62ba1a3843ac03a0dee6e1718ccf7c99d094613aff9678f2a5f6d0c2e6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.12-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 f3799dc25cadad6c4386f3d7c6ec19f2db147f625e9995a214bb208b9461200b
MD5 11979fc0e307b5eb724f30e246d94306
BLAKE2b-256 66674ac12d5e4f3da9cd4294fec679231a9308a12a06c914944b198e3b7fba4b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.12-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 ed2cf5d51c6d30649ae0ebaa0005a7cdc2fbb17deed9116fbc213365427a24f2
MD5 b019cd67ddaff8e125cb0cb9598b4f75
BLAKE2b-256 b727849e36235d0bd0065fe27f571b8e46ac3b984688332e4aedd6c818ed354b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.12-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 a1bc7c5c64118a0874ac9e13701fb4245603ea0e53288db4ab5a0c00b1f12e00
MD5 3cbd9538feb9be43aa5039220559b15a
BLAKE2b-256 2d8a0af2f106dc934504dd8600ea6a61a36cfee07736b291cd31b7fd6b78b555

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.12-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0224d32b99570afc9a85e63d33eaa81966b7b99b5199d5c1ff47aec89cac8bbb
MD5 b4e8e2611fabf69fe01ddb35ac002334
BLAKE2b-256 baa22193db70882e738474f7dd8013c0232d6888ecbf5401c589f81f9cb22f37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.12-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 15b2977ea9f219d7cfb84382fe6aab238c2b6690a919881aaac39b1b539bed25
MD5 228ea79653a07482a3d558d291b8a909
BLAKE2b-256 8b59b9b97f1e2b9b5369649f7a2a89d4044360fec1de621c4ca4091981a8483b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.12-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 57d07d8111e49ed4e2184aff6be7e0a27ab7b2355d9cd2fc06d0f90cd71231cf
MD5 6e6b37248284dad861ed5600d00640af
BLAKE2b-256 e9e6707ab74449e33bd9102adf56619b4840fcd54b392d95389fcfa24a9f9f12

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.12-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 cafa71d1e58998f7f19fd335b071eddb48403517ba9c0ec1e53672cb1284fee5
MD5 047fc2097da43efd482df8e73a61949a
BLAKE2b-256 d4e9505cd873c730a4a808809dc86a46db7f5c93aecf0bc83193bb9f3ed9e115

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.12-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 99fc03f1d966bc7d92e2a5992c45f72c2091c93a4453b8d6d0a345af53513824
MD5 1d050379f2ac32353360416228228222
BLAKE2b-256 47edb3ccf99fce62645da66e9b53d38881a4f5449f09e63f60e800270388e442

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.12-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 951cbca36286aeb60a4d0fbcc9b473736f8a4125cb958a650d1f5c9275afde52
MD5 19886aaeb1c1881fff35f147daf9846b
BLAKE2b-256 cf278de873b1d34bd45564459f580e14727b31930a83d7e5b2286da7fe4be70c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.12-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5e33e4e4a4eccd2c4e403f762c9b7a64c47b2116073fb8c4870af11b2144a3bb
MD5 a5e1bc25517b7e4b97e347ca4d8c2b99
BLAKE2b-256 45667cedfef2bdb79caf2393fb982a5fda57a793422f5370f01a71c991aba23e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.12-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 5f3d6d5bb61a2f3445e664d17ad3255d1eb7b71c388fc806753234a9ace5b3d4
MD5 a6592883931394b90708ba34853463c6
BLAKE2b-256 799e2899350bacaa2f189f5c4bc7fe35c87f4b06073ef5ad2815350568298b41

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