Skip to main content

Linear programming solvers in Python with a unified API.

Project description

LP Solvers for Python

CI Coverage Documentation PyPI version Status

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

Installation

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.0.0.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

lpsolvers-2.0.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lpsolvers-2.0.0.tar.gz
Algorithm Hash digest
SHA256 aff363e5e59c48b21a1c1da3ec6d010f2b5f6469bcbf4c8a83bb6f23da31656c
MD5 1779757cad03ae03903e191c9589e35d
BLAKE2b-256 103ac518f5bc28cdbcb02c941efc3c9c798c352cfbeaee3d5622ae2b82c6d4f6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for lpsolvers-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fffcecd52b7a40b782d9bd98577537d6a0ca98b5c5c37e0af8b32f96deba2406
MD5 94f59b5e8d857a4ffed718c85e6ca83d
BLAKE2b-256 b20090bb9cfacb29d058016498ece3fde40e37eb1a84088e42ef57e77ebb2b92

See more details on using hashes here.

Supported by

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