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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file swiglpk-1.2.13.tar.gz
.
File metadata
- Download URL: swiglpk-1.2.13.tar.gz
- Upload date:
- Size: 32.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1f41f12e82404c0e67da65c0cbe78433ed6a64a7f22246b753c54fc5db749a1 |
|
MD5 | db39c93146be59b17dacc9fd51ffe5e2 |
|
BLAKE2b-256 | 35ca56a2512d4eb500934cee20668da207cfab71f46b8180e946b112b8dcee17 |
File details
Details for the file swiglpk-1.2.13-py3.5-linux-x86_64.egg
.
File metadata
- Download URL: swiglpk-1.2.13-py3.5-linux-x86_64.egg
- Upload date:
- Size: 483.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e481c25494f3710870a5a73e9a3162685c23fd2b35ea4c282059cb2a1f1cc4ae |
|
MD5 | 0cf9c6a7dda6729938899f11dbad9ce7 |
|
BLAKE2b-256 | 663d80a9797481c68980442e71e5f13cc809fe8eeb1ce08f8212d67b20295aa3 |
File details
Details for the file swiglpk-1.2.13-py3.4-linux-x86_64.egg
.
File metadata
- Download URL: swiglpk-1.2.13-py3.4-linux-x86_64.egg
- Upload date:
- Size: 483.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e842ad4b83893f7105de6dfce7ab5fe68ff39b385c84023c3f37c8a1cacf95b4 |
|
MD5 | 1f54542f57dad309a1f38c6d80200917 |
|
BLAKE2b-256 | d5c89611d28beebe7456c2f37a4d5080670bb0e5cbfdc105e70d488ab1f45860 |
File details
Details for the file swiglpk-1.2.13-py3.3-linux-x86_64.egg
.
File metadata
- Download URL: swiglpk-1.2.13-py3.3-linux-x86_64.egg
- Upload date:
- Size: 479.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31b8462055bfecd3292993820ed983a54066fdb842f719e4e6d061df90be7c70 |
|
MD5 | 527a4479f41312c8a9b774cca033347f |
|
BLAKE2b-256 | 11844e1e2f53a8897b9d2393aadb22cab7329fc8a762628d63bd6b328065dd5a |
File details
Details for the file swiglpk-1.2.13-py2.7-linux-x86_64.egg
.
File metadata
- Download URL: swiglpk-1.2.13-py2.7-linux-x86_64.egg
- Upload date:
- Size: 495.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdc67f9717caafda12193181aacf0fd7252b03e510f3b3ecaf0dac5c34c35118 |
|
MD5 | 7ff8a08a2b23b17258cd8af373a903b7 |
|
BLAKE2b-256 | 373d7ca7a482b55611cdd21b5495e21e0bbe5e721c11ac3febc99142690a0e67 |
File details
Details for the file swiglpk-1.2.13-cp34-cp34m-win_amd64.whl
.
File metadata
- Download URL: swiglpk-1.2.13-cp34-cp34m-win_amd64.whl
- Upload date:
- Size: 519.6 kB
- Tags: CPython 3.4m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3be3e8d82ac6edcbab9e03288f72949389c6264ee178779413de7e2d7c3ec9f |
|
MD5 | a5e6fc2549c1f6d465542443832de084 |
|
BLAKE2b-256 | 4aa588da58d06fe285709b40fb00eaa417474d9c894781d9e06a5eabfb28bdaf |
File details
Details for the file swiglpk-1.2.13-cp34-cp34m-win32.whl
.
File metadata
- Download URL: swiglpk-1.2.13-cp34-cp34m-win32.whl
- Upload date:
- Size: 438.0 kB
- Tags: CPython 3.4m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2eeb5c7d5d6587390c70853369dbc3fce637273414e319cd9ac1d86f401d723d |
|
MD5 | c6aa78105fbc52f8ef92567e030b605e |
|
BLAKE2b-256 | ad13602bd6ee27f6536c29f45dfe12a2cca43d43f0973c410175477186968f2c |
File details
Details for the file swiglpk-1.2.13-cp27-cp27m-win_amd64.whl
.
File metadata
- Download URL: swiglpk-1.2.13-cp27-cp27m-win_amd64.whl
- Upload date:
- Size: 520.7 kB
- Tags: CPython 2.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ce8555ef1534753de856c4ab880b1c63f6c887bc330c405bc2b42c2133a7916 |
|
MD5 | c8b61dfdc2cb009c6104e2c433848a3d |
|
BLAKE2b-256 | c8db196e91068960a640dd62bbe4bf4aae4ff6d3bf5c049ea6ab72289386e5e7 |
File details
Details for the file swiglpk-1.2.13-cp27-cp27m-win32.whl
.
File metadata
- Download URL: swiglpk-1.2.13-cp27-cp27m-win32.whl
- Upload date:
- Size: 437.4 kB
- Tags: CPython 2.7m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08c6c9a35c6b2f4011b7b9e21d4be5044692b58e22dc8c05b89c016e82869d79 |
|
MD5 | d599d548a4f0568e8b5f3dc18900614e |
|
BLAKE2b-256 | 87fd2ca0d7c0f6e72d107bf0d93200c3f43f7f4afbaef5ff11b8ee9de2b8c156 |