Linear programming solvers in Python with a unified API
Project description
LP Solvers for Python
Wrapper around Linear Programming (LP) solvers in Python, with a unified interface.
Installation
The simplest way to install this module is:
sudo apt install libgmp-dev python3-dev
pip install lpsolvers
You can add the --user
parameter for a user-only installation.
Usage
The function solve_lp(c, G, h, A, b)
is called with the solver
keyword
argument to select the backend solver. The linear program it solves is, in
standard form:
min. c^T x
s.t. G x <= h
A x == b
Vector inequalities are taken coordinate by coordinate.
Solvers
The list of supported solvers currently includes:
Examples
To solve a linear program, build the matrices that define it and call the
solve_lp
function:
from numpy import array
from lpsolvers import solve_lp
c = array([1., 2., 3.])
G = array([[1., 2., -1.], [2., 0., 1.], [1., 2., 1.], [-1., -1., -1.]])
h = array([4., 1., 3., 2.])
print "LP solution:", solve_lp(c, G, h)
This example outputs the solution [2.2 -0.8 -3.4]
.
Upcoming changes
- Add CVXPY solver
- Type annotations
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for lpsolvers-0.9.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20d28a1e6f29c71e72f2f7847145fb75e06dfeb4673ce234833671b04035a8e7 |
|
MD5 | d03fec8693c6e3eed88b11528fd8919e |
|
BLAKE2b-256 | 9a90b3af7e542016d16b8419b7a06cba975dfd885231fc4a76fe647e8f05d00f |