• Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language JetBrains MPS
  • License
    Other
  • Created over 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Python interface to CLP, CBC, and CGL to solve LPs and MIPs.

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 and installation

On Windows: Installation as a binary wheel

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

$ python -m pip install cylp

On Linux/macOS: Installation as a binary wheel

Binary wheels are available for Linux and some versions of OS X for some versions of Python. To see if there is a wheel available for your platform, you can browse

https://pypi.org/project/cylp/#files

or just try:

$ python -m pip install cylp

In case this fails, it is most likely that there is no wheel for your platform. If you are on Linux, this can probably be addressed by switching to a supported Python version with, e.g., conda:

$ conda create -n cylp python=3.9
$ conda activate cylp

If all else fails, it is easy to install from source, but Cbc must be installed first, as detailed below. The easiest route for this is to use conda.

On Linux/macOS with conda: Installation from source

CyLP depends on NumPy and Cython as prerequisites for building from source (build-system requires). You will also need to install binaries for Cbc. The version should be 2.10 (recommended) or earlier (current master branch of Cbc will not work with this version of CyLP).

The following commands will create and activate a new conda environment with all these prerequisites installed:

$ conda create -n cylp coin-or-cbc cython numpy pkg-config scipy -c conda-forge
$ conda activate cylp

Now you can install CyLP from PyPI:

$ pip install --no-build-isolation cylp

(The option --no-build-isolation ensures that cylp uses the Python packages installed by conda in the build phase.)

Alternatively, if you have cloned CyLP from GitHub:

$ pip install --no-build-isolation .

On Linux/macOS with pip: Installation from source

First of all, you will need to install binaries for Cbc. The version should be 2.10 (recommended) or earlier (current master branch of Cbc will not work with this version of CyLP). You can install Cbc by either by installing with your system's 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 coinor-libcbc-dev on Ubuntu/Debian or coin-or-Cbc-devel on Fedora, or the corresponding package on your distribution.

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

    $ brew install cbc pkg-config

You should no longer need to build Cbc from source on any platform unless for some reason, none of the above recipes applies to you. If you do 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 (macOS).

Next, build and install CyLP:

$ python -m pip install cylp

This will build CyLP in an isolated environment that provides the build prerequisites and install it together with its runtime dependencies (install-requires), NumPy and SciPy <https://scipy.org>.

Testing your installation

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 (this is currently broken).

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 (https://www.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

The following software packages make use of CyLP:

  1. CVXPY, a Python-embedded modeling language for convex optimization problems, uses CyLP for interfacing to CBC, which is one of the supported mixed-integer solvers.

CyLP has been 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).
  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

More Repositories

1

pulp

A python Linear Programming API
Python
2,058
star
2

Ipopt

COIN-OR Interior Point Optimizer IPOPT
C++
1,082
star
3

Cbc

COIN-OR Branch-and-Cut solver
C++
620
star
4

python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Python
520
star
5

CppAD

A C++ Algorithmic Differentiation Package: Home Page
C++
375
star
6

Clp

COIN-OR Linear Programming Solver
C++
321
star
7

qpOASES

Open-source C++ implementation of the recently proposed online active set strategy
C++
261
star
8

rbfopt

RBFOpt library for black-box optimization
Python
181
star
9

Gravity

Mathematical Modeling for Optimization and Machine Learning
C++
149
star
10

SHOT

A solver for mixed-integer nonlinear optimization problems
C++
118
star
11

COIN-OR-OptimizationSuite

A harness for building the bundled suite of interoperable optimization tools available in the COIN-OR repository.
Shell
105
star
12

Bonmin

Basic Open-source Nonlinear Mixed INteger programming
C++
103
star
13

ADOL-C

A Package for Automatic Differentiation of Algorithms Written in C/C++
C++
94
star
14

Cbc.old

This is a mirror of the subversion repository on COIN-OR
C++
88
star
15

minotaur

Minotaur Toolkit for Mixed-Integer Nonlinear Optimization
C++
68
star
16

GrUMPy

A Python library for visualizing algorithms for solving mathematical optimization problems.
Shell
60
star
17

SYMPHONY

SYMPHONY is an open-source solver, callable library, and development framework for mixed-integer linear programs (MILPs) written in C with a number of unique features
C
59
star
18

Couenne

Convex Over and Under Envelopes for Nonlinear Estimation
C++
55
star
19

jorlib

Java Operations Research Library
Java
54
star
20

Csdp

This is the working repository for the CSDP project. CSDP is a solver for semidefinite programming problems. It is a COIN-OR project.
C
52
star
21

MibS

A solver for mixed integer bilevel programs
JetBrains MPS
50
star
22

Osi

Open Solver Interface
C++
48
star
23

CoinUtils

COIN-OR Utilities
C++
44
star
24

Rehearse

Algebraic modeling library in C++ for linear optimization solvers
M4
42
star
25

prtpy

Number partitioning in Python
Python
42
star
26

Clp.old

This a mirror of the subversion repository on COIN-OR.
C++
36
star
27

GiMPy

A graph library containing pure Python implementations of a variety of graph algorithms
Python
33
star
28

coinbrew

COIN-OR build and installation script
Shell
26
star
29

metslib

An Open Source Tabu Search Metaheuristic framework in C++
C++
25
star
30

Bcp

Branch-Cut-Price Framework
C++
24
star
31

Cgl

Cut Generator Library
C++
21
star
32

VRPH

VRPH is an open source library of heuristics for the capacitated Vehicle Routing Problem (VRP).
C++
19
star
33

SYMPHONY.old

This a mirror of the subversion repository on COIN-OR.
C
16
star
34

Dip

DIP is a decomposition-based solver framework for mixed integer linear programs.
C++
15
star
35

Osi.old

This a mirror of the subversion repository on COIN-OR.
C++
11
star
36

Sonnet

A wrapper for COIN-OR mixed integer linear programming via OSI to Microsoft .NET
C#
10
star
37

Dip.old

This a mirror of the subversion repository on COIN-OR.
C++
10
star
38

CoinMP

C-API library for CLP, CBC, and CGL
Shell
9
star
39

Cmpl

<Coliop|Coin> Mathematical Programming Language
C++
9
star
40

CHiPPS-ALPS

This is the Abstract Library for Parallel Search (ALPS), the abstract base layer of the COIN-OR High Performance Parallel Search framework.
C++
8
star
41

FlopCpp

An open source algebraic modelling language implemented as a C++ class library
Shell
8
star
42

oBB

Overlapping Branch and Bound Algorithm
C++
8
star
43

GAMSlinks

Links between GAMS (General Algebraic Modeling System) and solvers
C++
8
star
44

DisCO

Discrete Conic Optimization Solver
C++
7
star
45

filterSD

a library for nonlinear optimization written in Fortran
Fortran
7
star
46

CoinUtils.old

This a mirror of the subversion repository on COIN-OR.
C++
7
star
47

Paver

Python scripts to do comparisons on solver performance
Python
7
star
48

Vol

A C++ implementation of the volume algorithm for linear programming
Shell
7
star
49

Couenne.old

This a mirror of the subversion repository on COIN-OR. For bugtracking and wiki, see website.
C++
7
star
50

CHiPPS-BLIS

This is the BiCePS Linear Integer Solver (BLIS), a parallel solver for mixed integer linear programs that is implemented on top of the BiCePS layer of the CHiPPS framework.
C++
6
star
51

jMarkov

Java framework for Markov-chain (MC) modelling
Java
5
star
52

yaposib

Python binding to coin-osi
C++
5
star
53

Cgl.old

This a mirror of the subversion repository on COIN-OR.
C++
4
star
54

metslib-examples

Examples for METSLib
C++
4
star
55

ROSE

Reformulation-Optimization Software Engine
C++
3
star
56

Smi

An API for stochastic programming problems.
Shell
3
star
57

DyLP

Dynamic Simplex solver
C
2
star
58

CoinMP.old

Mirror of the CoinMP project from https://projects.coin-or.org/svn/CoinMP
Shell
2
star
59

coin-or.github.io

COIN-OR General Documentation
HTML
2
star
60

Osi2

Open Solver Interface Version 2
C++
1
star
61

MOCHA

Algorithms and heuristics to solve multicriteria matroid optimization problems
M4
1
star
62

Cgc

Cgc is a collection of network representations to facilitate the development and implementation of network algorithms.
C++
1
star
63

OS

Optimization Services
C++
1
star
64

PFunc

Generic task-parallel library for C/C++
C++
1
star
65

NLPAPI

NLPAPI is a set of subroutines and data structures for defining nonlinear programming problems. It includes an interface to call LANCELOT to solve the problem (you need to get your own copy of LANCELOT), and an interface to IPOPT.
C
1
star