Skip to main content

A Python interface for CLP, CBC, and CGL

Project description

CyLP

CyLP is a Python interface to COIN-OR’s Linear and mixed-integer program solvers (CLP, CBC, and CGL). CyLP’s unique feature is that you can use it to alter the solution process of the solvers from within Python. For example, you may define cut generators, branch-and-bound strategies, and primal/dual Simplex pivot rules completely in Python.

You may read your LP from an mps file or use the CyLP’s easy modeling facility. Please find examples in the documentation.

Docker

If you’re comfortable with Docker, you can get started right away with the container available on Dockerhub that comes with CyLP pre-installed.

https://hub.docker.com/repository/docker/coinor/cylp

Otherwise, read on.

Prerequisites

CyLP depends on Numpy (www.numpy.org) and Scipy (www.scipy.org). Please note that Numpy does need to be installed prior to installing CyLP, even though it is listed as a dependency in the setup.py file.

You will also need to install binaries for Cbc. The version should be 2.10 or earlier (current master branch of Cbc will not work with this version of CyLP). You can install Cbc by either by installing with a package manager, by downloading pre-built binaries, or by building yourself from source using coinbrew.

  1. To install Cbc in Linux, the easiest way is to use a package manager. Install either coinor-cbc and coin-or-libcbc-dev on Debian or coin-or-Cbc and coin-or-Cbc-devel on Fedora.

  2. On OS X, it is easiest to install Cbc with homebrew:

    $ brew tap coin-or-tools/coinor

    $ brew install coin-or-tools/coinor/cbc pkg-config

  3. On Windows, a binary wheel is available and it is not necessary to install Cbc.

If for some reason, you need to build from source, please go to the Cbc project page and follow the instructions there. After building and installing, make sure to either set the COIN_INSTALL_DIR variable to point to the installation or set PKG_CONFIG_PATH to point to the directory where the .pc files are installed. You may also need to set either LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OS X).

Installation

Once Numpy and Cbc are installed, simply do:

$ pip install cylp
Optional step:

If you want to run the doctests (i.e. make doctest in the doc directory) you should also define:

$ export CYLP_SOURCE_DIR=/Path/to/cylp

Now you can use CyLP in your python code. For example:

>>> from cylp.cy import CyClpSimplex
>>> s = CyClpSimplex()
>>> s.readMps('../input/netlib/adlittle.mps')
0
>>> s.initialSolve()
'optimal'
>>> round(s.objectiveValue, 3)
225494.963

Or simply go to CyLP and run:

$ python -m unittest discover

to run all CyLP unit tests.

Modeling Example

Here is an example of how to model with CyLP’s modeling facility:

import numpy as np
from cylp.cy import CyClpSimplex
from cylp.py.modeling.CyLPModel import CyLPArray

s = CyClpSimplex()

# Add variables
x = s.addVariable('x', 3)
y = s.addVariable('y', 2)

# Create coefficients and bounds
A = np.matrix([[1., 2., 0],[1., 0, 1.]])
B = np.matrix([[1., 0, 0], [0, 0, 1.]])
D = np.matrix([[1., 2.],[0, 1]])
a = CyLPArray([5, 2.5])
b = CyLPArray([4.2, 3])
x_u= CyLPArray([2., 3.5])

# Add constraints
s += A * x <= a
s += 2 <= B * x + D * y <= b
s += y >= 0
s += 1.1 <= x[1:3] <= x_u

# Set the objective function
c = CyLPArray([1., -2., 3.])
s.objective = c * x + 2 * y.sum()

# Solve using primal Simplex
s.primal()
print s.primalVariableSolution['x']

This is the expected output:

Clp0006I 0  Obj 1.1 Primal inf 2.8999998 (2) Dual inf 5.01e+10 (5) w.o. free dual inf (4)
Clp0006I 5  Obj 1.3
Clp0000I Optimal - objective value 1.3
[ 0.2  2.   1.1]

Documentation

You may access CyLP’s documentation:

  1. Online : Please visit http://coin-or.github.io/CyLP/

  2. Offline : To install CyLP’s documentation in your repository, you need Sphinx (http://sphinx-doc.org/). You can generate the documentation by going to cylp/doc and run make html or make latex and access the documentation under cylp/doc/build. You can also run make doctest to perform all the doctest.

Who uses CyLP

CyLP is being used in a wide range of practical and research fields. Some of the users include:

  1. PyArt, The Python ARM Radar Toolkit, used by Atmospheric Radiation Measurement (U.S. Department of energy). https://github.com/ARM-DOE/pyart

  2. Meteorological Institute University of Bonn.

  3. Sherbrooke university hospital (Centre hospitalier universitaire de Sherbrooke): CyLP is used for nurse scheduling.

  4. Maisonneuve-Rosemont hospital (L’hôpital HMR): CyLP is used for physician scheduling with preferences.

  5. Lehigh University: CyLP is used to teach mixed-integer cuts.

  6. IBM T. J. Watson research center

  7. Saarland University, Germany

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

cylp-0.91.2.tar.gz (1.4 MB view details)

Uploaded Source

Built Distributions

cylp-0.91.2-cp38-cp38-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.8Windows x86-64

cylp-0.91.2-cp37-cp37m-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.7mWindows x86-64

File details

Details for the file cylp-0.91.2.tar.gz.

File metadata

  • Download URL: cylp-0.91.2.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for cylp-0.91.2.tar.gz
Algorithm Hash digest
SHA256 1c49eba17548a44f7d7f202c27dae892aa5f4daaf7fcf0bbfdd1e9595008f840
MD5 66b95b4eddd33c6b591d3e292dd1a6d5
BLAKE2b-256 920b9b00f205a55add1564dc2137229d0857c535d510e24f5ad4bca7bd635cf2

See more details on using hashes here.

File details

Details for the file cylp-0.91.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: cylp-0.91.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for cylp-0.91.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 ad2e93effc002f0a15c638193e66430b0b7e34b139fb026d538412e0353924df
MD5 12d783f182a9ed3833ef0ce776f3c588
BLAKE2b-256 27791a2e2843969e577f17dcd12a7989dc32c30a8655e08f7ee21b984ccee944

See more details on using hashes here.

File details

Details for the file cylp-0.91.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: cylp-0.91.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for cylp-0.91.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 a077fe63e89202f334f2f7924e5d1b4e5a39362c1f82afcc9bc3882c980b7ae2
MD5 3fc822fa877a9467fc7a7b3871ac9760
BLAKE2b-256 749584265c8e7eb79e7796eb1c9eca1340c26936cbcbbc3829b16fb0da89a92f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page