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.3rc2.win-amd64-py3.5.exe (1.1 MB view details)

Uploaded Source

swiglpk-1.3.3rc2.win-amd64-py3.4.exe (735.5 kB view details)

Uploaded Source

swiglpk-1.3.3rc2.win-amd64-py3.3.exe (735.5 kB view details)

Uploaded Source

swiglpk-1.3.3rc2.win-amd64-py2.7.exe (737.6 kB view details)

Uploaded Source

swiglpk-1.3.3rc2.win32-py3.5.exe (907.2 kB view details)

Uploaded Source

swiglpk-1.3.3rc2.win32-py3.4.exe (631.8 kB view details)

Uploaded Source

swiglpk-1.3.3rc2.win32-py3.3.exe (631.8 kB view details)

Uploaded Source

swiglpk-1.3.3rc2.win32-py2.7.exe (630.9 kB view details)

Uploaded Source

swiglpk-1.3.3rc2-cp35-cp35m-win_amd64.whl (529.3 kB view details)

Uploaded CPython 3.5m Windows x86-64

swiglpk-1.3.3rc2-cp35-cp35m-win32.whl (445.2 kB view details)

Uploaded CPython 3.5m Windows x86

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

Uploaded CPython 3.5m

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

Uploaded CPython 3.5m

swiglpk-1.3.3rc2-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.3rc2-cp34-cp34m-win_amd64.whl (511.6 kB view details)

Uploaded CPython 3.4m Windows x86-64

swiglpk-1.3.3rc2-cp34-cp34m-win32.whl (439.1 kB view details)

Uploaded CPython 3.4m Windows x86

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

Uploaded CPython 3.4m

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

Uploaded CPython 3.4m

swiglpk-1.3.3rc2-cp33-cp33m-win_amd64.whl (511.7 kB view details)

Uploaded CPython 3.3m Windows x86-64

swiglpk-1.3.3rc2-cp33-cp33m-win32.whl (439.1 kB view details)

Uploaded CPython 3.3m Windows x86

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

Uploaded CPython 2.7mu

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

Uploaded CPython 2.7mu

swiglpk-1.3.3rc2-cp27-cp27m-win_amd64.whl (512.2 kB view details)

Uploaded CPython 2.7m Windows x86-64

swiglpk-1.3.3rc2-cp27-cp27m-win32.whl (433.1 kB view details)

Uploaded CPython 2.7m Windows x86

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

Uploaded CPython 2.7m

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

Uploaded CPython 2.7m

swiglpk-1.3.3rc2-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.3rc2.win-amd64-py3.5.exe.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2.win-amd64-py3.5.exe
Algorithm Hash digest
SHA256 b6f7f851b3b37f56a058d7594d4950e30bba561dc3780a49c64d4c0fcd409414
MD5 b6066977af2078acb6d082ed549ad458
BLAKE2b-256 937ca8d65afacbf7ac5752087302d2260f71f215c7e5e5fc9d869d66c351e6cf

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2.win-amd64-py3.4.exe.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2.win-amd64-py3.4.exe
Algorithm Hash digest
SHA256 f936d2621186560bf693d6a0eb704e315cf27add2b8ede2e5ff97a8cef858542
MD5 c39e1c620759ce27f549ad2205b9dc9a
BLAKE2b-256 1a80ed05d4f0bffa8202bf7b1c95b168d826fea44f5fe6b1ecaffdd7de03555e

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2.win-amd64-py3.3.exe.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2.win-amd64-py3.3.exe
Algorithm Hash digest
SHA256 43e213f2b732585d7d6d852fe07a60929704354682af2e6e07ede0147a4161b5
MD5 1183ad1a35ef810261aa669e72c27189
BLAKE2b-256 c14089387b5013769062a48747a8600141610823a87735b55b1af71895bf4121

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 60301f0adb0e1551341c5e85a60c8d4c4fd162c25749dc2c8badb6897482755b
MD5 cea4cfa62a34c9f7e41b8df91befee79
BLAKE2b-256 bc55790fe21d83ebc1a2ff1e325fd47ebf6b6216a77e46655eff220105e01b32

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2.win32-py3.5.exe.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2.win32-py3.5.exe
Algorithm Hash digest
SHA256 0018d22cc90a48111f43b2e35365c7ae50f6c4c986157c0fe961354872ac40f5
MD5 c0819a8d5b79b4bdd0a2ba1d7bbc4539
BLAKE2b-256 fc037f01a920d53bee9ab328aba44f986e4b91462f351086efb06b17c1d3b46c

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2.win32-py3.4.exe.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2.win32-py3.4.exe
Algorithm Hash digest
SHA256 7734b82e83e600e35596f6e83e63899511bbdeeb344f8ad2f5f826e688f74641
MD5 05c7a1e833667fd3a82912b832e443b8
BLAKE2b-256 d015282b251cb6a8605a582832025f5eed02d855ef8666a36b6f16ee3b9cb3cb

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2.win32-py3.3.exe.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2.win32-py3.3.exe
Algorithm Hash digest
SHA256 33891e38b4d751471946da68e4821cbde87bd84564773b9e7d38f50990817f5d
MD5 f71a05d4a024410a0ff71decd3535b4d
BLAKE2b-256 b3f5e99e118bb1436f5eb3512f3ebd3ab9545c7bb7a0fa02c55662b364f4141d

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2.win32-py2.7.exe.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2.win32-py2.7.exe
Algorithm Hash digest
SHA256 e2d8f4080e260a464310797119fc923b67c9784ca72382c5468f1f7f3f611318
MD5 5dc8d924982df75ce46311e492ea03aa
BLAKE2b-256 b3cc13c6c8baa68f26af67bd5e8fde6e23a328b4037912f651d6c115d7634838

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 9aa1825aca6392cfd37fec99b5de3e48bb6b72025029ce9d8fd7f3157ce545f6
MD5 c98dc1a9cc3c6eb73973c93bcd537a54
BLAKE2b-256 e70bdf320364ac16ffdc2066a1479d11cd674d2ab1e461a7f60d443136962830

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 879f2cd57592b4d0d7a94b5b541cf7a256b662edf71c160f1aaaa602904add1c
MD5 69c03ee4f8d90c493920a91234961cbf
BLAKE2b-256 35d60319c8431a859962187734a634af3c9f25db2f98c56e0c4d39c17c38bec2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 eeddec91b1dafade07dd11f5f89d5bc6eda81bde9909cecab97a582d1093757d
MD5 4f9ad4fe3d39ff026309f4bbc957a17a
BLAKE2b-256 32996288c7c6874b247d04164f20b8d30d033da2535407d1aa3b67bc6b79afab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 99078e3121eba2fc00596d72a0e1820eaec2a8978d80b083a9df9b91807c530d
MD5 ed3542f833aae121e660176c37b00e3f
BLAKE2b-256 3be5615ccf5d0b929eacb4583091f7777c4d4beb16937642d8e650a0c0717a94

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2-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.3rc2-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 292398aa118c07463aefc14a2b3cca3f9782b1cfa8f652b9dbbceee66c2c9341
MD5 7b2d6305214abdc60f7d18500c4bafec
BLAKE2b-256 eed1943896d53d9714ea5140d8ea973640cb18dad7d95586819aed37d65f9aa5

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 5a190645f0f27957e17205bc5955f59808ce9dd278e98d38b01b9478381d9250
MD5 ed7cd8a1624c980c96bb69fa471d4d30
BLAKE2b-256 be9061d57113c176b5ea92ba124bb56334f1880c32099699228661aa274ffccf

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 f4e8f771ccbd545dcc2a33649e10d4ad1bed3070592ee635ae9650d642372f39
MD5 c65e1478fd515d71a92bf962f06d2195
BLAKE2b-256 22798b2691b7b5ac096b518fc2c9c4e39ef07b187b8c0f979812be7d88bcdf18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7272213d6ea32b74508c3037fcce80cd11939bf0eae75d7dda7a7b800e1ebdd7
MD5 fc5ebd883a28c8a95b04a4b883db7e9d
BLAKE2b-256 6c58f38fb89e7ff6ef60c305f1439110e88e511c30af08dbb2dfd4ce45cce22f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 cf98a246416b75b583acc160c1ee2732e983f143eead8335e097c22ea913bb01
MD5 843291f0e1072c22174e74db8e87021b
BLAKE2b-256 f2fab7a93b4f9cb45b77ecd7bfa0ea9f2366958953ce790ab030ab9379a0b759

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2-cp33-cp33m-win_amd64.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp33-cp33m-win_amd64.whl
Algorithm Hash digest
SHA256 5e707703f2426a031b9816746f9b91459178577a245e37fc8958ea9e787db006
MD5 9cfab20b03c1daa891178e6466f52d67
BLAKE2b-256 a4ab45f41cfb03f5f9ff81cbb0504aa2a52ed691db63ffe7e251f34be18231e1

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2-cp33-cp33m-win32.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp33-cp33m-win32.whl
Algorithm Hash digest
SHA256 2abb4e32ce87c8e6a53921bb3dbfdef71d0cfaec1f9ab9a76045a7cb0a17e9ab
MD5 40d6897a35cee033465a7941fb92318d
BLAKE2b-256 a9193cc670fb5605186d3311be1d24c1c6097053c26d613f36bd19b9d7627f13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fdc4399916382770446cacb73d09b81dc789392b41ca548e5e8b4b1c3c3914fc
MD5 20679f085187d445b1d24990ea46a90a
BLAKE2b-256 1ba52db9c49fe1f5fe0a043ad0de63ae9ac1acc919a186df3edcb4e910df64f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 8cb1fede88e84f60ffe2b147d8dde5ea7a748d2cee4b5fc7e6ad3fd5ceb59641
MD5 f540d46cd235eb1b54966bce27ef526d
BLAKE2b-256 5b2b0cba67351e42581443df0a641e5e12e4a2e673d1eefb6fe8cb28f36f7382

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 1b1ad20758db59a1290dff31e58206f5e2c514cf34a2995efe75e84ccd2573e2
MD5 d68fba59824617415c259aa090348f02
BLAKE2b-256 2f8a0b70c52ce0ff933cc30437ad1826d776c1cb32183a32a33d9f1b7ccf819f

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 c9c219e476c6e888d3242e46d70ab309b9da3f0d7e3a5ad19f6b495f4a132d6c
MD5 4d2b7601c107b24af13ad7ab233546d5
BLAKE2b-256 261723c13def9d8b6f06f148be2d110841a00f27968594c489d8abf5e886f1dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a086bb8bc83c4ce38762ddce206e2c3cdd19d491d422a2c5e68807b51a86104c
MD5 4a408df5981d25b0dc881b2029c7dc3c
BLAKE2b-256 163f4a80f871e90c4a7bdf5c6d04be69b4d639f897ed37b9533d0734f51cf0a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swiglpk-1.3.3rc2-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 a5a4411e4b11b967ec485454a7620ea5943d48e10152debd4ace97740a403878
MD5 289e0e7e818cdfea98480285dbdfa6ae
BLAKE2b-256 ec0b998a2d0e6892738c429849433eecf60f435c4db9568570a3bd4058c493a4

See more details on using hashes here.

File details

Details for the file swiglpk-1.3.3rc2-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.3rc2-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 a0ca497f74634d5e873ae810da3e619fbf2af6239c4f870d3218a8632f56152d
MD5 af3033385d980241d7dc0c48255660b9
BLAKE2b-256 c151c9e31c018228937723f7f8ca71415940e9362144a8bac1b34c12c37c05ad

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