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.14.tar.gz (32.9 kB view details)

Uploaded Source

Built Distributions

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

Uploaded Source

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

Uploaded Source

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

Uploaded Source

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

Uploaded Source

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

Uploaded CPython 3.5m

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

Uploaded CPython 3.5m

swiglpk-1.2.14-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 (165.6 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.2.14-cp34-cp34m-win_amd64.whl (519.6 kB view details)

Uploaded CPython 3.4m Windows x86-64

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

Uploaded CPython 3.4m Windows x86

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

Uploaded CPython 3.4m

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

Uploaded CPython 3.4m

swiglpk-1.2.14-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 (165.6 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.2.14-cp34-cp34m-macosx_10_5_x86_64.whl (98.3 kB view details)

Uploaded CPython 3.4m macOS 10.5+ x86-64

swiglpk-1.2.14-cp33-cp33m-manylinux1_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.3m

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

Uploaded CPython 2.7mu

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

Uploaded CPython 2.7mu

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

Uploaded CPython 2.7m Windows x86-64

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

Uploaded CPython 2.7m Windows x86

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

Uploaded CPython 2.7m

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

Uploaded CPython 2.7m

swiglpk-1.2.14-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 (170.5 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

swiglpk-1.2.14-cp27-cp27m-macosx_10_5_x86_64.whl (99.8 kB view details)

Uploaded CPython 2.7m macOS 10.5+ x86-64

File details

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

File metadata

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

File hashes

Hashes for swiglpk-1.2.14.tar.gz
Algorithm Hash digest
SHA256 da4a1300ce16529de2e41911d7eb620c62d20c0a2aa74fa614ce8c7a79afd366
MD5 e68e356e8626b817d63c2d93f621ce6c
BLAKE2b-256 b14e09906901ecd46ff73c8addcb54fcf1d899006c88ecf4574e37a8f52cd2bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-py3.5-linux-x86_64.egg
Algorithm Hash digest
SHA256 82058d6e43e8ef7ac804dd28534ce0dd8247a002640bb03a82b0ab1e5a28b573
MD5 10e05ba4ad385cc9f0f8b1fa1eeac15e
BLAKE2b-256 be85a3e7f29dea5a6d327dc0f2db52b880b1b9d33955b80e2a870be5c5f354b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-py3.4-linux-x86_64.egg
Algorithm Hash digest
SHA256 ba66cdcc53e310fb9c1c0e4b6e97701863cb3cdf9b30d544f4917ae9979d2067
MD5 7ac7862228bff197260cb18f4ad56b9e
BLAKE2b-256 46ec36149449c181dbf185bba3402f69c3e365053aa30714219eee956a7ba51f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-py3.3-linux-x86_64.egg
Algorithm Hash digest
SHA256 36d0c9e68bae8350f94901f78c239284f63707de71dfb0961c5d0fb7c7a23ba5
MD5 edef21287c658190b60d21ddd63b1b87
BLAKE2b-256 a4496cb0a5d2e190daba0f71980689a28f6d75abffd2bf7d78015851af428a7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-py2.7-linux-x86_64.egg
Algorithm Hash digest
SHA256 10a184f5790fbbc5a5eaf7c6c20d5437f36b0ab7ae883add48cf708f17947e27
MD5 0ce1a2c06001712270043f19ef0506de
BLAKE2b-256 5734fafa4aba2480bf4b1e89f246787c5a744471f3ea371e224c3c36c86be0a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2fe565770c6d7475c6419455e6d18a95c718599304f7ee4976b57b297dcff941
MD5 36c8ae858527c27854cb3801df1f4cf6
BLAKE2b-256 71bb62f538d969cb2e871e7086e39030279368746b6877724a62a9ffd8870bcb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 5d1a2ebab0b17e1725bd11960ca717e1dc18f050e905b80bd581ef69feee9ace
MD5 fd3f868136613e2244abd5770ee1aea1
BLAKE2b-256 c2bc10547a62e323a8da6490efb03d283a330d952a03d6d093f5efba871f6c69

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.14-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.2.14-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 6bad12571f61e484de089765127bcf2d7f510a2e7279234404ca51d9674e5721
MD5 e3b53ed3e0a1cc6fc466f39d68c32026
BLAKE2b-256 53bf9da2d69d6f822a8af627ba11b91190f7d5e1d06ac5f8caee3371eec0b819

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 f606803c87da57901f2d42e2f5f8823b561ed634db3c8345134639cf76b5e0f0
MD5 022de9a09b79f11cd8ac65297215b5b9
BLAKE2b-256 13395987cc3bfd4329b0c556886eb7f74c59f2ae4135eded12333b12b6bcb80d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 1a18efd3bcbe59c2b530297b08869addc0445b8f8f1c2a3b26fc5a348c3c7dcb
MD5 b4a3fc69a71152fa5862350687260d9a
BLAKE2b-256 7ff50049296feece0af1bfd761b55db2d8c2219645fca63e712c8e917fc63820

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 666f8936bde0e0ccb3085c03edd07e627f5f61275f86c51558f1a0ee8e80dea8
MD5 b2aab741d81999d5487e0366bf0b5935
BLAKE2b-256 77344db700c9d75461aaf36fdf0a31c4aa0d7768598366dcee678c21ab433c3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 2b0a7f1339b7ee14ed86f49c95de17ec7baeed1c5f7597e3bfac1a6c139c7a21
MD5 e2f8e2c7f4370bdf629076550afc83c5
BLAKE2b-256 855a2fe1d111933de93419e0d84dfa41338739b60f61c8c395677f7a05b4aae4

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.14-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.2.14-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 fb45489f547ec5125d51ec462c295739b2b3e9c310059365c39838153e035aa8
MD5 73acc58744406391beb16c3a52d8cd2c
BLAKE2b-256 2066dc15009849cca208fef119c0d6945b763e6a918754014e0de60589997ac3

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.14-cp34-cp34m-macosx_10_5_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp34-cp34m-macosx_10_5_x86_64.whl
Algorithm Hash digest
SHA256 4d17fb3e73fe6e67fad2f7c3e3691f6bb67624cca186583ba0de91f559e7c79a
MD5 6927f3666530f6da9591a9f253213ae0
BLAKE2b-256 53a9f8b3f3be4ca93d3e9044e4e9b65f1b0cbaf5bb4b12903ac84cce86161e2d

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.14-cp33-cp33m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp33-cp33m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cd72e637deedf7605f2315a0f1e199df0420aa7ca091a199d9f3034ff3e5abd6
MD5 6bcd2103cdb29ca89acf167c58f91a0f
BLAKE2b-256 19879dcc8a88348a9507c6f306685f0c10af4ced29feeaad1328c6511bc62f01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 1ca8e1ad5481dd1afedb8a7e368a98b17bf8cf9be9f9a86d16623df10dbc8aca
MD5 be990a6dfd747b0922239f24f4d278fa
BLAKE2b-256 218073fe6287d36deca09cfcbc47836aca193cdc51e13a54087e785c5a32181c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 75e971785b53df2760f2855eb73d88bf1322bb3f46a0b0f962cf28b04a50ee7b
MD5 9c1a1fadb05448aa3b000b3e61ba2b9d
BLAKE2b-256 456d520000b6a85398f5072b2cef15d07894ba6eb5bdc30b2bd728a55d6e42c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 6a7754b85948aa1eb463ab08a852a4638726ded4c898a52e2183cb4f826fc593
MD5 9bae1dc5a3b3c3e8af4abb460f9bdd06
BLAKE2b-256 c6fb332318b6fb4da64af4213e01bc6532bb0d26ecd930e5cdfba12d0567438f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 ba791295f2ac2e2de0680d9066b51ad3fe386f7a72588302758483711d327dab
MD5 d83d32e6a63b094a17bdb0e352800135
BLAKE2b-256 d22454ba8b5044e5faabc279fe442bc5a459bc4cce1d148b04a66a1b1b435299

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 738fc7705a72592ce78579d395e6e86c76b85b8d931aa2fa1b957bd6d73e8fa5
MD5 04248d54e92b8a35365f93e9919fc4cc
BLAKE2b-256 66cee860a5a4e26aa8510c77f007804ac25def46058a71bb75d18b5279c7d5ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 3f60df4d0b5de3c5e595b4de54fda63ef82ff9e03aa1c411b7477224ab079cb6
MD5 342dbadb77c5adea7f025b567c5faeb0
BLAKE2b-256 5ab27b1038c76be10cc2e5822b6e4a702f3385a1d8df5b5aa5a630eb7882bc7f

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.14-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.2.14-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 a2580c8f8423b4d66078a3ca6aaa660fcacf327887a8bff47e7f44ca62fadb2a
MD5 4911b0ba4b60a615c444f94965053529
BLAKE2b-256 b5b16660037107943a02e54b685c842a0cc529a86cc33baeed5e900fa6c5d4e9

See more details on using hashes here.

File details

Details for the file swiglpk-1.2.14-cp27-cp27m-macosx_10_5_x86_64.whl.

File metadata

File hashes

Hashes for swiglpk-1.2.14-cp27-cp27m-macosx_10_5_x86_64.whl
Algorithm Hash digest
SHA256 c0a123cef7925c9bc9a1c7e5ac66362f3679c5d1831db1f1da9786e4506da6ea
MD5 811f4c40d9881450bdf9fe0c2a100718
BLAKE2b-256 1c2ebd3c1cde9c96272bb40af4dee0e8df7bba6223514eec50b07435381ff87c

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