https://github.com/stephane-caron/lpsolvers
Linear programming solvers in Python with a unified API
https://github.com/stephane-caron/lpsolvers
linear-programming numerical-optimization python solver
Last synced: 2 months ago
JSON representation
Linear programming solvers in Python with a unified API
- Host: GitHub
- URL: https://github.com/stephane-caron/lpsolvers
- Owner: stephane-caron
- License: lgpl-3.0
- Created: 2018-07-03T08:58:53.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2024-09-16T20:27:07.000Z (9 months ago)
- Last Synced: 2024-10-13T16:31:11.290Z (8 months ago)
- Topics: linear-programming, numerical-optimization, python, solver
- Language: Python
- Homepage:
- Size: 6.12 MB
- Stars: 23
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# LP Solvers for Python
[](https://github.com/stephane-caron/lpsolvers/actions)
[](https://stephane-caron.github.io/lpsolvers/)
[](https://coveralls.io/github/stephane-caron/lpsolvers?branch=main)
[](https://anaconda.org/conda-forge/lpsolvers)
[](https://pypi.org/project/lpsolvers/)Wrapper around Linear Programming (LP) solvers in Python, with a unified interface.
## Installation
### From conda-forge
```console
conda install -c conda-forge lpsolvers
```### From PyPI
To install the library and all available LP solvers at the same time:
```console
pip install lpsolvers[open_source_solvers]
```To install the library only, assuming LP solvers are installed separately: ``pip install lpsolvers``.
## Usage
The function [`solve_lp`](https://stephane-caron.github.io/lpsolvers//linear-programming.html#lpsolvers.solve_lp) is called with the ``solver`` keyword argument to select the backend solver. The linear program it solves is, in standard form:
$$
\begin{split}
\begin{array}{ll}
\mbox{minimize} &
c^T x \\
\mbox{subject to}
& G x \leq h \\
& A x = b
\end{array}
\end{split}
$$Vector inequalities are taken coordinate by coordinate.
## Example
To solve a linear program, build the matrices that define it and call the ``solve_lp`` function:
```python
from numpy import array
from lpsolvers import solve_lpc = array([1., 2., 3.])
G = array([[1., 2., -1.], [2., 0., 1.], [1., 2., 1.], [-1., -1., -1.]])
h = array([4., 1., 3., 2.])x = solve_lp(c, G, h, solver="cvxopt") # select solver here
print(f"LP solution: {x=}")
```This example outputs the solution ``[2.2, -0.8, -3.4]``.
## Solvers
The list of supported solvers currently includes:
- [cdd](https://github.com/mcmtroffaes/pycddlib)
- [CVXOPT](http://cvxopt.org/)
- [CVXPY](https://www.cvxpy.org/) (interface)
- [PDLP](https://developers.google.com/optimization/lp/pdlp_math)
- [ProxQP](https://github.com/Simple-Robotics/proxsuite#proxqp)