Giter VIP home page Giter VIP logo

swiglpk's Introduction

swiglpk

Plain python bindings for the GNU Linear Programming Kit (GLPK)

PyPI License Build 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. Furthermore, swiglpk provides binary wheels for all major platforms, which are always up-to-date with the most recent GLPK version (swiglpk versions follow GLPK versioning in the major and minor version digits to emphasize that).

Please show us some love by staring this repo if you find swiglpk useful!

Installation

pip install swiglpk

That's it. swiglpk comes with binary wheels for Windows, Mac, and Linux. No installation of third-party dependencies necessary.

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

Pretty ugly right? Consider using optlang for formulating and solving your optimization problems.

Documentation

You can find documentation on GLPK's C API here

Development

You still want to install it from source? Then you'll need to install the following dependencies first.

  • GLPK
  • swig

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

If you're on Windows, you are on your own (checkout the appveyor.yml config file for directions).

Then clone the repo and run the following. :

python setup.py install

swiglpk's People

Contributors

carrascomj avatar cdiener avatar dependabot[bot] avatar hredestig avatar jonathonfletcher avatar jonls avatar midnighter avatar phantomas1234 avatar viech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiglpk's Issues

Can't install swiglpk/cobrapy in Docker image

This is my docker file which fails when building.

FROM python:3.10 AS base
RUN pip install pipenv
RUN apt-get update && apt-get install -y --no-install-recommends gcc
RUN PIPENV_VENV_IN_PROJECT=1 
RUN pipenv install cobra

Any help would be appreciated. This happens for python images 3.9 and 3.8 as well. FYI, I've also created a similar issue in cobrapy

I get the following error message:

#8 7.649 Collecting swiglpk
#8 7.649   Downloading swiglpk-5.0.0.tar.gz (32 kB)
#8 7.649   Preparing metadata (setup.py): started
#8 7.649   Preparing metadata (setup.py): finished with status 'error'
#8 7.649 
  error: subprocess-exited-with-error
#8 7.649   
#8 7.649   × python setup.py egg_info did not run successfully.
#8 7.649   │ exit code: 1
#8 7.649   ╰─> [13 lines of output]
#8 7.649       Traceback (most recent call last):
#8 7.649         File "<string>", line 2, in <module>
#8 7.649         File "<pip-setuptools-caller>", line 34, in <module>
#8 7.649         File "/tmp/pip-install-f0og7wp6/swiglpk_0fbc9a0e2e46479c86d9d5d73d4c7b75/setup.py", line 52, in <module>
#8 7.649           glpk_header_dirname = find_glpk_header()
#8 7.649         File "/tmp/pip-install-f0og7wp6/swiglpk_0fbc9a0e2e46479c86d9d5d73d4c7b75/setup.py", line 35, in find_glpk_header
#8 7.649           glpsol_dirname = os.path.dirname(subprocess.check_output(['which', 'glpsol']))
#8 7.649         File "/usr/local/lib/python3.10/subprocess.py", line 420, in check_output
#8 7.649           return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
#8 7.649         File "/usr/local/lib/python3.10/subprocess.py", line 524, in run
#8 7.649           raise CalledProcessError(retcode, process.args,
#8 7.649       subprocess.CalledProcessError: Command '['which', 'glpsol']' returned non-zero exit status 1.
#8 7.649       Trying to determine glpk.h location
#8 7.649       [end of output]
#8 7.649   
#8 7.649   note: This error originates from a subprocess, and is likely not a problem with pip.
#8 7.649 error: metadata-generation-failed
#8 7.649 
#8 7.649 × Encountered error while generating package metadata.
#8 7.649 ╰─> See above for output.
#8 7.649 
#8 7.649 note: This is an issue with the package mentioned above, not pip.
#8 7.649 hint: See above for details.
#8 7.649 
This is likely caused by a bug in cobra. Report this to its maintainers.
#8 7.691✘ Installation Failed 

fails to install in python 3.10

edit: the below was with python 3.10.0. It works fine with 3.9.7.

Not sure this is something you can address, but GitHub Actions fails to install swiglpk 5.0.3:

pip install -r requirements/ci-requirements.txt
[...]
ERROR: Could not find a version that satisfies the requirement swiglpk==5.0.3 (from versions: 0.1.0, 1.0.0, 1.2.12, 1.2.13, 1.2.14, 1.4.4, 1.5.0b0, 1.5.0, 1.5.1, 4.64.0b0, 4.65.0, 4.65.1, 5.0.0)
ERROR: No matching distribution found for swiglpk==5.0.3

where ci-requirements.txt contains:

swiglpk==5.0.3
    # via
    #   cobra
    #   optlang

Meanwhile, forcing version 5.0.0 in ci-requirements.txt results in:

Collecting swiglpk==5.0.0
  Downloading swiglpk-5.0.0.tar.gz (32 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'
  ERROR: Command errored out with exit status 1:
   command: /opt/hostedtoolcache/Python/3.10.0/x64/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-39pg8iv7/swiglpk_e7c0d6367e9b4cc9b9ebc51e1af871d9/setup.py'"'"'; __file__='"'"'/tmp/pip-install-39pg8iv7/swiglpk_e7c0d6367e9b4cc9b9ebc51e1af871d9/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-wkn7cwwj
       cwd: /tmp/pip-install-39pg8iv7/swiglpk_e7c0d6367e9b4cc9b9ebc51e1af871d9/
  Complete output (12 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-39pg8iv7/swiglpk_e7c0d6367e9b4cc9b9ebc51e1af871d9/setup.py", line 52, in <module>
      glpk_header_dirname = find_glpk_header()
    File "/tmp/pip-install-39pg8iv7/swiglpk_e7c0d6367e9b4cc9b9ebc51e1af871d9/setup.py", line 35, in find_glpk_header
      glpsol_dirname = os.path.dirname(subprocess.check_output(['which', 'glpsol']))
    File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/subprocess.py", line 420, in check_output
      return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
    File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/subprocess.py", line 524, in run
      raise CalledProcessError(retcode, process.args,
  subprocess.CalledProcessError: Command '['which', 'glpsol']' returned non-zero exit status 1.
  Trying to determine glpk.h location
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/9b/49/260f20672b1f11138e240df219deb496ab9d17a5b8f623334b7e49e1e089/swiglpk-5.0.0.tar.gz#sha256=7b1e30bc401ab1ed638253ac93da5757d47247bce390b0e614b6cddb8838d1f7 (from https://pypi.org/simple/swiglpk/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement swiglpk==5.0.0 (from versions: 0.1.0, 1.0.0, 1.2.12, 1.2.13, 1.2.14, 1.4.4, 1.5.0b0, 1.5.0, 1.5.1, 4.64.0b0, 4.65.0, 4.65.1, 5.0.0)
ERROR: No matching distribution found for swiglpk==5.0.0

Installation in Travis with Python 2.7

I'm having an issue installing swiglpk inside travis in Python 2.7, but it works fine in 3.5 and 3.6. See the failing tests here:

https://travis-ci.org/zakandrewking/escher/builds/263299781

The error is below. I tried recreating it locally (macOS), but everything ran fine. Can you see anything obvious that might be going wrong? Thanks!

    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/tmp/pip-build-uooetu/swiglpk/setup.py", line 53, in <module>
        copy_glpk_header()
      File "/tmp/pip-build-uooetu/swiglpk/setup.py", line 31, in copy_glpk_header
        glpsol_path = os.path.dirname(subprocess.check_output(['which', 'glpsol']))
      File "/opt/python/2.7.9/lib/python2.7/subprocess.py", line 573, in check_output
        raise CalledProcessError(retcode, cmd, output=output)
    subprocess.CalledProcessError: Command '['which', 'glpsol']' returned non-zero exit status 1
    Complete output from command python setup.py egg_info:
    Trying to determine glpk.h location
    
    Traceback (most recent call last):
    
      File "<string>", line 20, in <module>
    
      File "/tmp/pip-build-uooetu/swiglpk/setup.py", line 53, in <module>
    
        copy_glpk_header()
    
      File "/tmp/pip-build-uooetu/swiglpk/setup.py", line 31, in copy_glpk_header
    
        glpsol_path = os.path.dirname(subprocess.check_output(['which', 'glpsol']))
    
      File "/opt/python/2.7.9/lib/python2.7/subprocess.py", line 573, in check_output
    
        raise CalledProcessError(retcode, cmd, output=output)
    
    subprocess.CalledProcessError: Command '['which', 'glpsol']' returned non-zero exit status 1

python3.12.0 compatibility

When I want to install swiglpk into python 3.12.0, I get these errors:

Collecting swiglpk>=5.0.8 (from -r freeze3.12.0 (line 393))
  Using cached swiglpk-5.0.8.tar.gz (21 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  _ python setup.py egg_info did not run successfully.
  _ exit code: 1
  __> [28 lines of output]
      /tmp/pip-install-0mkifbyp/swiglpk_ac7d04677ff14906b252f9cdb9631c4d/versioneer.py:467: SyntaxWarning: invalid escape sequence '\s'
        LONG_VERSION_PY['git'] = '''
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-0mkifbyp/swiglpk_ac7d04677ff14906b252f9cdb9631c4d/setup.py", line 17$, in <module>
          version=versioneer.get_version(),
                  ^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-install-0mkifbyp/swiglpk_ac7d04677ff14906b252f9cdb9631c4d/versioneer.py", li$e 1405, in get_version
          return get_versions()["version"]
                 ^^^^^^^^^^^^^^
        File "/tmp/pip-install-0mkifbyp/swiglpk_ac7d04677ff14906b252f9cdb9631c4d/versioneer.py", li$e 1339, in get_versions
          cfg = get_config_from_root(root)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-install-0mkifbyp/swiglpk_ac7d04677ff14906b252f9cdb9631c4d/versioneer.py", li$e 399, in get_config_from_root
          parser = configparser.SafeConfigParser()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      AttributeError: module 'configparser' has no attribute 'SafeConfigParser'. Did you mean: 'Raw$onfigParser'?
      ==============================
      BUILDING SWIGLPK FROM SOURCE.
      If you are installing SWIGLPK via pip, this means that no wheels are offered for your platfor$ or Python version yet.
      This can be the case if you adopt a new Python version early.
      A source build requires GLPK, SWIG, and GMP (Linux/Mac) to be installed!
      ==============================
      Looking for glpk.h...
      Found glpk.h in /usr/include.
      Making sure SWIG is available...
      Found the swig executable.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

_ Encountered error while generating package metadata.
__> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

I'm on a OracleServer 8.8 kernel 4.18.0-477.27.1.el8_8.x86_64. I am happy to test and provide further information.

pip install fails with Python 3.8.0

When trying to install swigplk in a Python 3.8 virtual environment, the following error ensues:

Collecting swiglpk
  Using cached https://files.pythonhosted.org/packages/10/8d/6139114541e54413b68939f14cdf92d0d818ff4dfc09c005ed2dc835a6e4/swiglpk-4.65.0.tar.gz
Building wheels for collected packages: swiglpk
  Building wheel for swiglpk (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: venv/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-m9zzetfq/swiglpk/setup.py'"'"'; __file__='"'"'/tmp/pip-install-m9zzetfq/swiglpk/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-kio6btig --python-tag cp38
       cwd: /tmp/pip-install-m9zzetfq/swiglpk/
  Complete output (9 lines):
  Trying to determine glpk.h location
  glpk.h found at /usr/include/glpk.h
  running bdist_wheel
  running build_ext
  building 'swiglpk._swiglpk' extension
  swigging swiglpk/glpk.i to swiglpk/glpk_wrap.c
  swig -python -o swiglpk/glpk_wrap.c swiglpk/glpk.i
  unable to execute 'swig': No such file or directory
  error: command 'swig' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for swiglpk
  Running setup.py clean for swiglpk
Failed to build swiglpk
Installing collected packages: swiglpk
    Running setup.py install for swiglpk ... error
    ERROR: Command errored out with exit status 1:
     command: venv/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-m9zzetfq/swiglpk/setup.py'"'"'; __file__='"'"'/tmp/pip-install-m9zzetfq/swiglpk/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-wwowxn8f/install-record.txt --single-version-externally-managed --compile --install-headers venv/include/site/python3.8/swiglpk
         cwd: /tmp/pip-install-m9zzetfq/swiglpk/
    Complete output (10 lines):
    Trying to determine glpk.h location
    glpk.h found at /usr/include/glpk.h
    running install
    running build
    running build_ext
    building 'swiglpk._swiglpk' extension
    swigging swiglpk/glpk.i to swiglpk/glpk_wrap.c
    swig -python -o swiglpk/glpk_wrap.c swiglpk/glpk.i
    unable to execute 'swig': No such file or directory
    error: command 'swig' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: venv/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-m9zzetfq/swiglpk/setup.py'"'"'; __file__='"'"'/tmp/pip-install-m9zzetfq/swiglpk/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-wwowxn8f/install-record.txt --single-version-externally-managed --compile --install-headers venv/include/site/python3.8/swiglpk Check the logs for full command output.

Missing SDist for 5.0.x release (x!=0)

The SDist is missing on PyPI for 5.0.x, which has made it impossible to update in Pyodide for the 0.20 (Python 3.10!) release. 5.0.0 exactly seems to be the last one with an SDist. pipx run build --sdist should produce one for upload.

Support GLPK 5.0.

Installing swiglpk 4.56.1 on top of GLPK 5.0 works but import swiglpk fails:

ImportError: /usr/lib/python3.9/site-packages/swiglpk/_swiglpk.cpython-39-x86_64-linux-gnu.so: undefined symbol: glp_netgen_prob

This release mail explains the relevant change.

Depends on glpk headers

The README mentions that glpk-utils needs to be installed. On Debian based distributions (e.g., Ubuntu), the GLPK headers also need to be installed via the libglpk-dev package. I.e.,

apt-get install libglpk-dev

For references, the full set of packages I needed to install on Ubuntu was:

apt-get install glpk-utils libglpk-dev swig

No module named wheel.bdist_wheel

Error append when call python setup.py build

Can't build swiglpk without wheel.

I modified your setup.py to make it work (from line 58):
`
if os.name != 'nt':
from distutils.command.build import build
# from wheel.bdist_wheel import bdist_wheel

# class CustomBdistWheel(bdist_wheel):
#     def run(self):
#         print('I am actually run!')
#         self.run_command('build_ext')
#         bdist_wheel.run(self)

# custom_cmd_class['bdist_wheel'] = CustomBdistWheel

class CustomBuild(build):
    def run(self):
        self.run_command('build_ext')
        build.run(self)

custom_cmd_class['build'] = CustomBuild

`

Potential vulnerability in the C library which swiglpk depends on. Can you help upgrade to patch versions?

Hi, @phantomas1234 , @cdiener , I'd like to report a vulnerability issue in swiglpk_5.0.5.

Dependency Graph between Python and Shared Libraries

image

Issue Description

As shown in the above dependency graph, swiglpk_5.0.5 directly or transitively depends on 3 C libraries (.so). However, I noticed that one C library is vulnerable, containing the following CVEs:
libgmp-afec2dd4.so.10.2.0from C project gmp(version:6.1.0) exposed 1 vulnerabilities:
CVE-2021-43618

Suggested Vulnerability Patch Versions

No official patch version released, but gmp has fixed the vulnerability in patch.

Python build tools cannot report vulnerable C libraries, which may induce potential security issues to many downstream Python projects.
As a popular python package (swiglpk has 43,041 downloads per month), could you please upgrade the above shared libraries to their patch versions?

Thanks for your help~
Best regards,
Joe Gardner

There is no `which` on windows

When installing from source looking for glpk on windows the which glpsol step will fail since there is no which on windows (newer versions have where.exe which is similar).

Drop i686?

I wonder if we should still continue to support i686. Most modern OSs don't anymore and there should be very little hardware that uses it. But it does take up a large chunk of our wheel building and I'd rather spend this build time on building for ARM64. So I think we can drop it. Previous versions will still work on i686, this would only mean that no newer versions can be installed which should be okay for legacy hardware.

Failure to install wheel

I have some trouble installing the package from PyPI since the 1.0.0 release. When I install 1.2.0 on OSX it looks like this:

~. env/bin/activate
(env) ~ → pip install swiglpk
You are using pip version 7.0.3, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting swiglpk
Installing collected packages: swiglpk
Successfully installed swiglpk-1.2.0
(env) ~ → python
Python 2.7.10 (default, Aug 28 2015, 12:01:26) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import swiglpk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jon/env/lib/python2.7/site-packages/swiglpk.py", line 118, in <module>
    GLP_MAJOR_VERSION = _swiglpk.GLP_MAJOR_VERSION
AttributeError: 'module' object has no attribute 'GLP_MAJOR_VERSION'
>>>

Same error with 1.1.2 and 1.1.3. When I try to install 1.0.0 the bdist_wheel fails and then pip tries to install. For some reason that works fine. I can also do

(env) ~ → pip install swiglpk --no-cache-dir

and the resulting package works fine. It seems that the difference when using --no-cache-dir is that pip uses the install command of setup.py instead of bdist_wheel. For this reason I suspect that there is something up with the bdist_wheel setup.

A subtle oddity in Python 3.5 on Windows

This is a very subtle problem, it only occurs for Python 3.5 on Windows.
First of all, solve() should invoke swiglpk.glp_simplex() and print out some messages.
Then this weird exception never happens on other combinations of platforms and Python versions.
To install pymprog to replicate this, just do: pip install pymprog

Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> from pymprog import *
>>> begin('t')
model('t') is the default model.
>>> maximize(15*x + 10*y, 'profit')
Max profit: 15 * x + 10 * y
>>> x <= 3
0 <= x <= 3 continuous
>>> y <= 4
0 <= y <= 4 continuous
>>> x + y <= 5
R1: x + y <= 5
>>> solve()
>>> sensitivity()

PyMathProg 1.0 Sensitivity Report Created: 2016/12/14 Wed 12:30PM
================================================================================
Variable            Activity   Dual.Value     Obj.Coef   Range.From   Range.Till
--------------------------------------------------------------------------------
 x                         3            5           15           10          inf
*y                         2            0           10            0           15
StopIteration

During handling of the above exception, another exception occurred:

SystemError: <built-in function delete_doubleArray> returned a result with an error set

During handling of the above exception, another exception occurred:

SystemError: <built-in function delete_intArray> returned a result with an error set

During handling of the above exception, another exception occurred:

SystemError: <built-in function delete_doubleArray> returned a result with an error set

During handling of the above exception, another exception occurred:

SystemError: <built-in function delete_doubleArray> returned a result with an error set

During handling of the above exception, another exception occurred:

SystemError: <built-in function delete_intArray> returned a result with an error set

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    sensitivity()
  File "<string>", line 10, in sensitivity
  File "C:\Users\phbs\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pymprog.py", line 5580, in sensitivity
    me.sensit()
  File "C:\Users\phbs\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pymprog.py", line 5574, in sensit
    me.coef_ranges()
  File "C:\Users\phbs\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pymprog.py", line 5608, in coef_ranges
    for vals in me._viter(cols): print(fmt%vals)
SystemError: <built-in function delete_doubleArray> returned a result with an error set

How to pass int-array argument / How to use "glp_get_mat_row(...)"?

First of all: very interesting project. The basic stuff is already working for me.

How would i use int glp_get_mat_row(glp_prob *lp, int i, int ind[], double val[]);. GLPK API PDF

I don't have experience with SWIG, but after reading some stuff, i thought, i could pass any previously defined variable as argument and SWIG will take care. But everything i tried is failing.

Example A:

a = np.zeros(nnz, dtype=int)
b = np.zeros(nnz)
length = glp_get_mat_row(lp, 1, a, b)
# TypeError: in method 'glp_get_mat_row', argument 3 of type 'int []'

Example B:

a = []
b = []
length = glp_get_mat_row(lp, 1, a, b)
# TypeError: in method 'glp_get_mat_row', argument 3 of type 'int []'    

Example C:

a = None
b = None
length = glp_get_mat_row(lp, 1, a, b)
# WORKS, but of course i'm not retrieving the stuff i want to
# Only length is returned as documented in GLPKs API

Questions

  • Am i doing something wrong? Or is this something not implemented / buggy?

Sascha

Create benchmarks for swiglpk and decide on a C interface

Done: There is a comprehensive set of benchmarks (using e.g. pytest-benchmark that can be used to decide between C bindings.

Binding options in order of feasibility:

  • SWIG (current)
  • CFFI (Lasse has a running version)
  • ctypes
  • Cython
  • Boost Python

N.B.: A "bottleneck" with the current interface is to retrieve the flux values for all reactions from the solver. This could also be in part to using an OrderedDict in optlang.

Is possible build CBC from pure python?

Hi SWIGLPK team.
I'm working in my project and I want to use MIP and CBC in the browser with pyodide. MIP function good because is a pure pyrhon library, the problem is CBC. I had trying with cbcpy but the wheels are from specific OS. I know that this project is from GLPK, but I want to question if is possible build cbc whit native python wheels?

setup.py fails to locate an existing glpk.h in /usr/include.

Whenever a new version of Python is released, until you provide wheels, users installing via pip will have to compile swiglpk using setup.py. In #39 and #36 people were having issues because they do not have swig installed. Even with swig installed, installation can fail due to bad portability of setup.py as detailed below.

When I run python setup.py on 4.65.1, I get the following exception:

% python setup.py 
Trying to determine glpk.h location
glpk.h found at /include/glpk.h
Traceback (most recent call last):
  File "…/src/swiglpk/setup.py", line 57, in <module>
    copy_glpk_header()
  File "…/src/swiglpk/setup.py", line 48, in copy_glpk_header
    raise Exception('Could not find glpk.h! Maybe glpk or glpsol is not installed.')
Exception: Could not find glpk.h! Maybe glpk or glpsol is not installed.

The file glpk.h is installed but it is found in /usr/include/glpk.h as opposed to /include/glpk.h:

% ls /include/glpk.h
ls: cannot access '/include/glpk.h': No such file or directory
% ls /usr/include/glpk.h
/usr/include/glpk.h

The problem is in setup.py within copy_glpk_header. The function executes the which glpsol shell command, which on my installation of Arch Linux returns /bin/glpsol. Then, it replaces bin with include. However, while /bin is a symbolic link to /usr/bin where glpsol is actually installed, /include does not exist on Arch Linux. (The output glpk.h found at /include/glpk.h is wrong and should rather be Expecting glpk.h at /include/glpk.h.)

I'm not sure about the best way to locate glpk.h but I would suggest to first iterate over a list of common locations that includes the local directory and /usr/include/. If this fails, then you could still try to locate the header using which or even gcc.

Set up automatic swiglpk releases that follow the GLPK version numbers

Done:

  • Always compile GLPK with GMP support
  • Use a mechanism (like RSS) to trigger swiglpk builds when a new GLPK release happened (or set up a cron job that checks the GLPK FTP server for a new version once a day/week)
  • Use the GLPK release version as the version for the swiglpk package

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.