CyLP
raw JSON → 0.94.0 verified Fri May 01 auth: no python
CyLP is a Python interface for the COIN-OR Linear Programming (CLP), COIN-OR Branch and Cut (CBC), and COIN-OR Cut Generation Library (CGL) solvers. It provides a modeling layer similar to PuLP but directly wraps the COIN-OR solvers for efficient linear and mixed-integer programming. Version 0.94.0 is current; release cadence is intermittent.
pip install cylp Common errors
error ImportError: cannot import name 'CyClpSimplex' from 'cylp' ↓
cause Commonly occurs when using the wrong import path; CyClpSimplex is in the cylp.cy submodule.
fix
Use 'from cylp.cy import CyClpSimplex' instead of 'from cylp import CyClpSimplex'.
error AttributeError: 'CyClpSimplex' object has no attribute 'primalVariableSolution' ↓
cause This attribute exists only after solving with a model set via setModel. If solving directly with matrix input, use getColSolution/getRowPrice instead.
fix
After calling solver.primal(), access solution via solver.primalVariableSolution if using CyLPModel; otherwise use solver.getColSolution().
error RuntimeError: CoinAssert or incorrect argument ↓
cause Often caused by passing invalid column indices (0-based) when API expects 1-based indices.
fix
Ensure column/row indices start from 1, not 0. For example, in addColumn, the column numbers are 1-indexed.
Warnings
deprecated The 'cylp.py.modeling.CyLPModel' approach is older; newer examples use 'CyClpSimplex' directly with matrix input. The modeling module may see less development. ↓
fix For new code, consider using CyClpSimplex.addColumn/addRow methods or switch to a more actively maintained package like PuLP if needed.
gotcha Installation from source requires Cython, NumPy, and a compatible C++ compiler. Pre-built wheels may not be available for all platforms (e.g., Python 3.11+ or ARM). ↓
fix Use 'pip install cylp' and if it fails, ensure build dependencies are installed. Check PyPI for wheel availability.
breaking In versions prior to 0.90, the import path was 'cylp.CyClpSimplex' not 'cylp.cy.CyClpSimplex'. Code written for old versions will break. ↓
fix Update imports: change 'from cylp import CyClpSimplex' to 'from cylp.cy import CyClpSimplex'.
gotcha The CyLP modeling layer (CyLPModel) uses 1-indexed variable IDs internally. Supplying 0-based indices may cause silent errors. ↓
fix Always use 1-based indexing when referring to variable IDs in lower-level API calls.
Install
pip install cython numpy pyscipopt # build deps often needed Imports
- CyClpSimplex wrong
from cylp import CyClpSimplexcorrectfrom cylp.cy import CyClpSimplex - CbcModel wrong
from cylp import CbcModelcorrectfrom cylp.cy import CbcModel
Quickstart
from cylp.cy import CyClpSimplex
from cylp.py.modeling.CyLPModel import CyLPModel, CyLPArray
model = CyLPModel()
x = model.addVariable('x', 1)
y = model.addVariable('y', 1)
model += 2*x + 3*y <= 10
model += x - y >= 1
model.objective = x + 2*y
solver = CyClpSimplex()
solver.setModel(model)
solver.primal()
print('x =', solver.primalVariableSolution['x'])
print('y =', solver.primalVariableSolution['y'])