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
To install the library and all open source LP solvers at the same time:
$ pip install lpsolvers[solvers]
To install the library only, assuming LP solvers are installed separately: pip install lpsolvers
.
Usage
The function 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:
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]
.
Solvers
The list of supported solvers currently includes:
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-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f05fecd424fb5fec3bc567be388cf2f7566bffedca6bd52576fab1812d66487 |
|
MD5 | d1d7d746bc27c09445913a36edd4c76b |
|
BLAKE2b-256 | 76457a6a2b3cf86ec3ca46262f0c15c77acc91356cd404fc26f1d225492c4136 |