Skip to main content

PuLP is an LP modeler written in python. PuLP can generate MPS or LP files and call GLPK, COIN CLP/CBC, CPLEX, and GUROBI to solve linear problems.

Project description

https://travis-ci.org/coin-or/pulp.svg?branch=master PyPI PyPI - Downloads

PuLP is an linear and mixed integer programming modeler written in Python. With PuLP, it is simple to create MILP optimisation problems and solve them with the latest open-source (or proprietary) solvers. PuLP can generate MPS or LP files and call solvers such as GLPK, COIN-OR CLP/CBC, CPLEX, GUROBI, MOSEK, XPRESS, CHOCO, MIPCL, HiGHS, SCIP/FSCIP.

The documentation for PuLP can be found here.

PuLP is part of the COIN-OR project.

Installation

PuLP requires Python 3.9 or newer.

The easiest way to install PuLP is with pip. If pip is available on your system, type:

python -m pip install pulp

Otherwise follow the download instructions on the PyPi page.

Installing solvers

PuLP can use a variety of solvers. The default solver is the COIN-OR CBC solver, which is included with PuLP. If you want to use other solvers, PuLP offers a quick way to install most solvers via their pypi package (some require a commercial license for running or for running large models):

python -m pip install pulp[gurobi]
python -m pip install pulp[cplex]
python -m pip install pulp[xpress]
python -m pip install pulp[scip]
python -m pip install pulp[highs]
python -m pip install pulp[copt]
python -m pip install pulp[mosek]
python -m pip install pulp[cylp]
If you want to install all open source solvers (scip, highs, cylp), you can use the shortcut::

python -m pip install pulp[open_py]

For more information on how to install solvers, see the guide on configuring solvers.

Quickstart

Use LpVariable to create new variables. To create a variable x with 0 ≤ x ≤ 3:

from pulp import *
x = LpVariable("x", 0, 3)

To create a binary variable, y, with values either 0 or 1:

y = LpVariable("y", cat="Binary")

Use LpProblem to create new problems. Create a problem called “myProblem” like so:

prob = LpProblem("myProblem", LpMinimize)

Combine variables in order to create expressions and constraints, and then add them to the problem.:

prob += x + y <= 2

An expression is a constraint without a right-hand side (RHS) sense (one of =, <= or >=). If you add an expression to a problem, it will become the objective:

prob += -4*x + y

To solve the problem with the default included solver:

status = prob.solve()

If you want to try another solver to solve the problem:

status = prob.solve(GLPK(msg = 0))

Display the status of the solution:

LpStatus[status]
> 'Optimal'

You can get the value of the variables using value. ex:

value(x)
> 2.0

Essential Classes

  • LpProblem – Container class for a Linear or Integer programming problem

  • LpVariable – Variables that are added into constraints in the LP problem

  • LpConstraint – Constraints of the general form

    a1x1 + a2x2 + … + anxn (<=, =, >=) b

  • LpConstraintVar – A special type of constraint for constructing column of the model in column-wise modelling

Useful Functions

  • value() – Finds the value of a variable or expression

  • lpSum() – Given a list of the form [a1*x1, a2*x2, …, an*xn] will construct a linear expression to be used as a constraint or variable

  • lpDot() – Given two lists of the form [a1, a2, …, an] and [x1, x2, …, xn] will construct a linear expression to be used as a constraint or variable

More Examples

Several tutorial are given in documentation and pure code examples are available in examples/ directory .

The examples use the default solver (CBC). To use other solvers they must be available (installed and accessible). For more information on how to do that, see the guide on configuring solvers.

For Developers

If you want to install the latest version from GitHub you can run:

python -m pip install -U git+https://github.com/coin-or/pulp

On Linux and MacOS systems, you must run the tests to make the default solver executable:

sudo pulptest

Building the documentation

The PuLP documentation is built with Sphinx. We recommended using a virtual environment to build the documentation locally.

To build, run the following in a terminal window, in the PuLP root directory

python3 -m pip install --upgrade pip
pip install --group=dev .
cd doc
make html

A folder named html will be created inside the build/ directory. The home page for the documentation is doc/build/html/index.html which can be opened in a browser.

Contributing to PuLP

Instructions for making your first contribution to PuLP are given here.

Comments, bug reports, patches and suggestions are very welcome!

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

pulp-3.3.0.tar.gz (16.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pulp-3.3.0-py3-none-any.whl (16.4 MB view details)

Uploaded Python 3

File details

Details for the file pulp-3.3.0.tar.gz.

File metadata

  • Download URL: pulp-3.3.0.tar.gz
  • Upload date:
  • Size: 16.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pulp-3.3.0.tar.gz
Algorithm Hash digest
SHA256 7eb99b9ce7beeb8bbb7ea9d1c919f02f003ab7867e0d1e322f2f2c26dd31c8ba
MD5 cac0783529413ee1daf0c32229cd0094
BLAKE2b-256 161cd880b739b841a8aa81143091c9bdda5e72e226a660aa13178cb312d4b27f

See more details on using hashes here.

File details

Details for the file pulp-3.3.0-py3-none-any.whl.

File metadata

  • Download URL: pulp-3.3.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pulp-3.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd6ad2d63f196d1254eddf9dcff5cd224912c1f046120cb7c143c5b0eda63fae
MD5 c56a2b4085fe278d9921fa6dcde3bfc9
BLAKE2b-256 996c64cafaceea3f99927e84b38a362ec6a8f24f33061c90bda77dfe1cd4c3c6

See more details on using hashes here.

Supported by

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