PuLP

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.

63 个版本 Python >=3.10
J.S. Roy <"S.A. Mitchell" <pulp@stuartmitchell.com>, Franco Peschiera <pchtsp@gmail.com>>
安装
pip install PuLP
poetry add PuLP
pipenv install PuLP
conda install PuLP
描述

pulp


.. image:: https://travis-ci.org/coin-or/pulp.svg?branch=master :target: https://travis-ci.org/coin-or/pulp .. image:: https://img.shields.io/pypi/v/pulp :target: https://pypi.org/project/PuLP/ :alt: PyPI .. image:: https://img.shields.io/pypi/dm/pulp :target: https://pypi.org/project/PuLP/ :alt: 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 <https://coin-or.github.io/pulp/>_.

PuLP is part of the COIN-OR project <https://www.coin-or.org/>_.

Installation

PuLP requires Python 3.10 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 <https://pypi.python.org/pypi/PuLP>_.

Installing solvers

PuLP can use a variety of solvers. The default solver is the COIN-OR CBC solver via the COIN_CMD API. Install CBC with::

python -m pip install pulp[cbc]

If CBC is not available on your system, PuLP falls back to other solvers such as the legacy bundled CBC (PULP_CBC_CMD) or GLPK.

To install 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[cbc]
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]

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 <https://coin-or.github.io/pulp/guides/how_to_configure_solvers.html>_.

Quickstart

Create a problem first, then add variables with add_variable (variables are owned by the model). To create a variable x with 0 ≤ x ≤ 3 and a binary variable y::

 from pulp import *
 prob = LpProblem("myProblem", LpMinimize)
 x = prob.add_variable("x", 0, 3)
 y = prob.add_variable("y", cat="Binary")

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 solver (CBC via COIN_CMD when installed with pulp[cbc])::

 status = prob.solve()

To solve explicitly with CBC::

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

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 [a1x1, a2x2, ..., 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 <https://coin-or.github.io/pulp/CaseStudies/index.html>_ and pure code examples are available in examples/ directory <https://github.com/coin-or/pulp/tree/master/examples>_ .

The examples use the default solver (CBC via COIN_CMD when available). 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 <https://coin-or.github.io/pulp/guides/how_to_configure_solvers.html>_.

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

Building the documentation

The PuLP documentation is built with Sphinx <https://www.sphinx-doc.org>. We recommended using a virtual environment <https://docs.python.org/3/library/venv.html> 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 <https://coin-or.github.io/pulp/develop/contribute.html>_.

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

Copyright and License

PuLP is distributed under an MIT license.

 Copyright J.S. Roy, 2003-2005
 Copyright Stuart A. Mitchell
 See the LICENSE file for copyright information.

.. _Python: http://www.python.org/

.. _GLPK: http://www.gnu.org/software/glpk/glpk.html .. _CBC: https://github.com/coin-or/Cbc .. _CPLEX: http://www.cplex.com/ .. _GUROBI: http://www.gurobi.com/ .. _MOSEK: https://www.mosek.com/ .. _XPRESS: https://www.fico.com/es/products/fico-xpress-solver .. _CHOCO: https://choco-solver.org/ .. _MIPCL: http://mipcl-cpp.appspot.com/ .. _SCIP: https://www.scipopt.org/ .. _HiGHS: https://highs.dev .. _FSCIP: https://ug.zib.de

版本列表
4.0.0a9 2026-05-27
4.0.0a8 2026-05-22
4.0.0a6 2026-04-29
4.0.0a5 2026-04-16
4.0.0a4 2026-04-14
4.0.0a3 2026-04-11
4.0.0a2 2026-04-06
4.0.0a12 2026-06-19
4.0.0a11 2026-06-19
4.0.0a10 2026-06-17
3.3.2 2026-05-25
3.3.1 2026-05-05
3.3.0 2025-09-18
3.2.2 2025-07-29
3.2.1 2025-05-29
3.2.0 2025-05-29
3.1.1 2025-03-24
3.0.2 2025-02-20
3.0.1 2025-02-20
3.0.0 2025-02-19
2.9.0 2024-07-12
2.8.0 2024-01-12
2.7.0 2022-11-03
2.6.0 2021-12-04
2.5.1 2021-09-28
2.5.0 2021-08-11
2.4 2020-12-16
2.3.1 2020-10-22
2.3 2020-08-04
2.2 2020-07-04
2.1 2020-04-05
2.0 2019-11-23
1.6.10 2019-05-14
1.6.9 2018-10-24
1.6.8 2017-07-16
1.6.7 2017-07-10
1.6.6 2017-07-09
1.6.5 2017-02-23
1.6.4 2017-02-23
1.6.2 2017-02-06
1.6.1 2015-12-25
1.6.0 2015-06-09
1.5.9 2015-04-18
1.5.8 2015-04-04
1.5.7 2015-03-31
1.5.6 2014-02-24
1.5.4 2013-03-21
1.5.3 2012-06-07
1.5.2 2012-05-17
1.5.1 2012-02-26
1.5.0 2012-01-17
1.4.9 2011-10-01
1.4.8 2011-04-15
1.4.7 2010-01-28
1.4.6 2010-01-25
1.4.5 2010-01-25
1.4.4 2010-01-24
1.4.3 2010-01-05
1.4.2 2009-12-31
1.4.1 2009-11-06
1.1
0.1.0 2026-04-06