• Stars
    star
    2,058
  • Rank 22,467 (Top 0.5 %)
  • Language
    Python
  • License
    Other
  • Created over 9 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A python Linear Programming API

pulp

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

PuLP is an LP modeler written in Python. PuLP can generate MPS or LP files and call GLPK, COIN-OR CLP/CBC, CPLEX, GUROBI, MOSEK, XPRESS, CHOCO, MIPCL, HiGHS, SCIP/FSCIP to solve linear problems.

Installation

The easiest way to install pulp is via PyPi

If pip is available on your system:

python -m pip install pulp

Otherwise follow the download instructions on the PyPi page.

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

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

On Linux and OSX systems the tests must be run to make the default solver executable.

sudo pulptest

Examples

See the examples directory for examples.

PuLP requires Python 3.7 or newer.

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.

Documentation

Documentation is found on https://coin-or.github.io/pulp/.

Use LpVariable() to create new variables. To create a variable 0 <= x <= 3:

x = LpVariable("x", 0, 3)

To create a variable 0 <= y <= 1:

y = LpVariable("y", 0, 1)

Use LpProblem() to create new problems. Create "myProblem":

prob = LpProblem("myProblem", LpMinimize)

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

prob += x + y <= 2

If you add an expression (not a constraint), it will become the objective:

prob += -4*x + y

To solve with the default included solver:

status = prob.solve()

To use another sovler 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

Exported Classes:

  • LpProblem -- Container class for a Linear programming problem

  • LpVariable -- Variables that are added to constraints in the LP

  • LpConstraint -- A constraint of the general form

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

  • LpConstraintVar -- Used to construct a column of the model in column-wise modelling

Exported Functions:

  • value() -- Finds the value of a variable or expression
  • lpSum() -- given a list of the form [a1*x1, a2x2, ..., anxn] 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

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

cd pulp
python -m pip install -r requirements-dev.txt
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.

Comments, bug reports, patches and suggestions are welcome.

More Repositories

1

Ipopt

COIN-OR Interior Point Optimizer IPOPT
C++
1,082
star
2

Cbc

COIN-OR Branch-and-Cut solver
C++
620
star
3

python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Python
520
star
4

CppAD

A C++ Algorithmic Differentiation Package: Home Page
C++
375
star
5

Clp

COIN-OR Linear Programming Solver
C++
321
star
6

qpOASES

Open-source C++ implementation of the recently proposed online active set strategy
C++
261
star
7

rbfopt

RBFOpt library for black-box optimization
Python
181
star
8

CyLP

A Python interface to CLP, CBC, and CGL to solve LPs and MIPs.
JetBrains MPS
175
star
9

Gravity

Mathematical Modeling for Optimization and Machine Learning
C++
149
star
10

SHOT

A solver for mixed-integer nonlinear optimization problems
C++
118
star
11

COIN-OR-OptimizationSuite

A harness for building the bundled suite of interoperable optimization tools available in the COIN-OR repository.
Shell
105
star
12

Bonmin

Basic Open-source Nonlinear Mixed INteger programming
C++
103
star
13

ADOL-C

A Package for Automatic Differentiation of Algorithms Written in C/C++
C++
94
star
14

Cbc.old

This is a mirror of the subversion repository on COIN-OR
C++
88
star
15

minotaur

Minotaur Toolkit for Mixed-Integer Nonlinear Optimization
C++
68
star
16

GrUMPy

A Python library for visualizing algorithms for solving mathematical optimization problems.
Shell
60
star
17

SYMPHONY

SYMPHONY is an open-source solver, callable library, and development framework for mixed-integer linear programs (MILPs) written in C with a number of unique features
C
59
star
18

Couenne

Convex Over and Under Envelopes for Nonlinear Estimation
C++
55
star
19

jorlib

Java Operations Research Library
Java
54
star
20

Csdp

This is the working repository for the CSDP project. CSDP is a solver for semidefinite programming problems. It is a COIN-OR project.
C
52
star
21

MibS

A solver for mixed integer bilevel programs
JetBrains MPS
50
star
22

Osi

Open Solver Interface
C++
48
star
23

CoinUtils

COIN-OR Utilities
C++
44
star
24

Rehearse

Algebraic modeling library in C++ for linear optimization solvers
M4
42
star
25

prtpy

Number partitioning in Python
Python
42
star
26

Clp.old

This a mirror of the subversion repository on COIN-OR.
C++
36
star
27

GiMPy

A graph library containing pure Python implementations of a variety of graph algorithms
Python
33
star
28

coinbrew

COIN-OR build and installation script
Shell
26
star
29

metslib

An Open Source Tabu Search Metaheuristic framework in C++
C++
25
star
30

Bcp

Branch-Cut-Price Framework
C++
24
star
31

Cgl

Cut Generator Library
C++
21
star
32

VRPH

VRPH is an open source library of heuristics for the capacitated Vehicle Routing Problem (VRP).
C++
19
star
33

SYMPHONY.old

This a mirror of the subversion repository on COIN-OR.
C
16
star
34

Dip

DIP is a decomposition-based solver framework for mixed integer linear programs.
C++
15
star
35

Osi.old

This a mirror of the subversion repository on COIN-OR.
C++
11
star
36

Sonnet

A wrapper for COIN-OR mixed integer linear programming via OSI to Microsoft .NET
C#
10
star
37

Dip.old

This a mirror of the subversion repository on COIN-OR.
C++
10
star
38

CoinMP

C-API library for CLP, CBC, and CGL
Shell
9
star
39

Cmpl

<Coliop|Coin> Mathematical Programming Language
C++
9
star
40

CHiPPS-ALPS

This is the Abstract Library for Parallel Search (ALPS), the abstract base layer of the COIN-OR High Performance Parallel Search framework.
C++
8
star
41

FlopCpp

An open source algebraic modelling language implemented as a C++ class library
Shell
8
star
42

oBB

Overlapping Branch and Bound Algorithm
C++
8
star
43

GAMSlinks

Links between GAMS (General Algebraic Modeling System) and solvers
C++
8
star
44

DisCO

Discrete Conic Optimization Solver
C++
7
star
45

filterSD

a library for nonlinear optimization written in Fortran
Fortran
7
star
46

CoinUtils.old

This a mirror of the subversion repository on COIN-OR.
C++
7
star
47

Paver

Python scripts to do comparisons on solver performance
Python
7
star
48

Vol

A C++ implementation of the volume algorithm for linear programming
Shell
7
star
49

Couenne.old

This a mirror of the subversion repository on COIN-OR. For bugtracking and wiki, see website.
C++
7
star
50

CHiPPS-BLIS

This is the BiCePS Linear Integer Solver (BLIS), a parallel solver for mixed integer linear programs that is implemented on top of the BiCePS layer of the CHiPPS framework.
C++
6
star
51

jMarkov

Java framework for Markov-chain (MC) modelling
Java
5
star
52

yaposib

Python binding to coin-osi
C++
5
star
53

Cgl.old

This a mirror of the subversion repository on COIN-OR.
C++
4
star
54

metslib-examples

Examples for METSLib
C++
4
star
55

ROSE

Reformulation-Optimization Software Engine
C++
3
star
56

Smi

An API for stochastic programming problems.
Shell
3
star
57

DyLP

Dynamic Simplex solver
C
2
star
58

CoinMP.old

Mirror of the CoinMP project from https://projects.coin-or.org/svn/CoinMP
Shell
2
star
59

coin-or.github.io

COIN-OR General Documentation
HTML
2
star
60

Osi2

Open Solver Interface Version 2
C++
1
star
61

MOCHA

Algorithms and heuristics to solve multicriteria matroid optimization problems
M4
1
star
62

Cgc

Cgc is a collection of network representations to facilitate the development and implementation of network algorithms.
C++
1
star
63

OS

Optimization Services
C++
1
star
64

PFunc

Generic task-parallel library for C/C++
C++
1
star
65

NLPAPI

NLPAPI is a set of subroutines and data structures for defining nonlinear programming problems. It includes an interface to call LANCELOT to solve the problem (you need to get your own copy of LANCELOT), and an interface to IPOPT.
C
1
star