Skip to main content

A Python interface for CLP, CBC, and CGL

Project description

Important Notice

To comply with PEP8 we decided to rename the package name from CyLP to cylp, which was long overdue. It affects the package name ONLY and a simple replace can make your program work with the new settings. Thank you for your understanding.

What is CyLP?

CyLP is a Python interface to COIN-ORs Linear and mixed-integer program solvers (CLP, CBC, and CGL). CyLPs 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 CyLPs easy modeling facility. Please find examples in the documentation.

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’hopital 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

Installation

The easiest way to install CyLP is by using the binaries. If that’s not possible you may always compile it from source.

Requirements

CyLP needs Numpy (www.numpy.org) and Scipy (www.scipy.org). If you wish to install CyLP from source, you will also need to compile Cbc. Details of this process is given below.

Binary Installation

If you have setuptools installed you may run:

$ easy_install cylp

If a binary is available for your architecture it will be installed. Otherwise you will see an error telling you to specify where to find a Cbc installation. That’s because easy_install is trying to compile the source. In this case you’ll have to compile Cbc and set and environment variable to point to it before calling easy_install again. The details are given in the Installing from source section.

Installing from source

STEP 1:

Install CBC (http://www.coin-or.org/download/source/Cbc/). CyLP can be compiled against Cbc version 2.8.5. Please go to the installation directory and run:

$ ./configure
$ make
$ make install
STEP 2:

Create an environment variable called COIN_INSTALL_DIR pointing to your installation of Coin. For example:

$ export COIN_INSTALL_DIR=/Users/mehdi/Cbc-2.8.5

You may also add this line to your ~/.bash_rc or ~/.profile to make it persistent.

STEP 3:

Install CyLP. Go to CyLP’s root directory and run:

$ python setup.py install
STEP 4 (LINUX):

In linux you might also need to add COIN’s lib directory to LD_LIBRARY_PATH as follows:

$ export LD_LIBRARY_PATH=/path/to/Cbc-2.8.5/lib:$LD_LIBRARY_PATH"
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']

Documentation

You may access CyLP’s documentation:

  1. Online : Please visit http://mpy.github.io/cylpdoc/

  2. Offline : To install CyLP’s documentation in your repository, you need Sphinx (http://sphinx.pocoo.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.

Bitdeli badge githalytics.com

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.2.3.6.tar.gz (1.0 MB view details)

Uploaded Source

Built Distributions

cylp-0.2.3.6.win32-py2.7.exe (4.1 MB view details)

Uploaded Source

cylp-0.2.3.6-py2.7-win32.egg (4.0 MB view details)

Uploaded Egg

cylp-0.2.3.6-py2.7-macosx-10.6-x86_64.egg (12.3 MB view details)

Uploaded Egg

cylp-0.2.3.6-py2.7-linux-x86_64.egg (15.5 MB view details)

Uploaded Egg

File details

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

File metadata

  • Download URL: cylp-0.2.3.6.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cylp-0.2.3.6.tar.gz
Algorithm Hash digest
SHA256 3db87b204e47d2f9727b75b08773a27d21ab07caed531f588efaf4edb28bc847
MD5 189b9c0ba97bd2e4e4196ed44610913b
BLAKE2b-256 609090d2e23a6423d7461d34bedaf05978787f23b64b82d3619430ed10e468e9

See more details on using hashes here.

File details

Details for the file cylp-0.2.3.6.win32-py2.7.exe.

File metadata

File hashes

Hashes for cylp-0.2.3.6.win32-py2.7.exe
Algorithm Hash digest
SHA256 5f7c4d9b1ca36a4902907ead07b0a86122a9ce11022455b4700690de4356dab4
MD5 8e86067bcf665e0a1593ade90c65c776
BLAKE2b-256 03e068efa08c7baceab97adf09e5c7702a6c46791255bb89e1da4154b1628bbd

See more details on using hashes here.

File details

Details for the file cylp-0.2.3.6-py2.7-win32.egg.

File metadata

File hashes

Hashes for cylp-0.2.3.6-py2.7-win32.egg
Algorithm Hash digest
SHA256 62c4c9ae99677c45a41916da7c3967205a3cc55602c2cf344bfadca4779e6a1e
MD5 a51c680cffd76cf350774ac4ac40c708
BLAKE2b-256 1317bbf2c9e155b3e47b853d2c586576bbc4edb7045c476fcca3db24d147cc70

See more details on using hashes here.

File details

Details for the file cylp-0.2.3.6-py2.7-macosx-10.6-x86_64.egg.

File metadata

File hashes

Hashes for cylp-0.2.3.6-py2.7-macosx-10.6-x86_64.egg
Algorithm Hash digest
SHA256 0cb62f6fbf366bc62127d546cd73ca58344111a2e23d2006b9009130c8b91405
MD5 8dfa724c58b70d5efdd4e0d1fe37e42d
BLAKE2b-256 b5cb61d5e96d5db2f76b1c0849a10d668d820887500aaca26de8681f79dc8df5

See more details on using hashes here.

File details

Details for the file cylp-0.2.3.6-py2.7-linux-x86_64.egg.

File metadata

File hashes

Hashes for cylp-0.2.3.6-py2.7-linux-x86_64.egg
Algorithm Hash digest
SHA256 b97b0a515f30c6fcfab66d62a687682fe3f9c2771be105aa24cc2b7109e710f2
MD5 50aa3ff0f02d2f35696554cc367569ff
BLAKE2b-256 5aa015feeaa7987e29ef9f7b645c7af1c56c31abc58f83f655f91418a3f80f10

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