Skip to main content

Linear programming solvers in Python with a unified API.

Project description

LP Solvers for Python

CI Documentation Coverage Conda version PyPI version

Wrapper around Linear Programming (LP) solvers in Python, with a unified interface.

Installation

From conda-forge

conda install -c conda-forge lpsolvers

From PyPI

To install the library and all available LP solvers at the same time:

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 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.])

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:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lpsolvers-2.1.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

lpsolvers-2.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file lpsolvers-2.1.0.tar.gz.

File metadata

  • Download URL: lpsolvers-2.1.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for lpsolvers-2.1.0.tar.gz
Algorithm Hash digest
SHA256 3b0bd30be974991592d36a3c70260a38b789253752d018d1ea3183b8033e09a1
MD5 24162a3feaecf08258a6f4560703a2ba
BLAKE2b-256 629fd232b8adb48947469c48cd9df6fcd91af1cfa3ce04bdf483bacc22f9a04f

See more details on using hashes here.

File details

Details for the file lpsolvers-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: lpsolvers-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for lpsolvers-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 664730d52af7227e022002e494800c1d8e9c2e839dcabcd246a611e7af23d5bf
MD5 4c589bc63251621112c1cb63057fe99a
BLAKE2b-256 aecdf1994cc2e52e925e8a4fc9723724622ef6ee5003ffa7b26c56b403fdb5ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page