or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

constants-enums.mdcore-modeling.mdfile-io.mdindex.mdmathematical-operations.mdsolver-interfaces.mdutility-functions.md
tile.json

tessl/pypi-pulp

PuLP is a linear and mixed integer programming modeler that provides an intuitive Python interface for creating, manipulating, and solving mathematical optimization problems.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pulp@3.2.x

To install, run

npx @tessl/cli install tessl/pypi-pulp@3.2.0

index.mddocs/

PuLP

A comprehensive Python library for linear and mixed integer programming that provides an intuitive interface for creating, manipulating, and solving mathematical optimization problems. PuLP acts as a universal interface to multiple optimization solvers and can export problems to standard formats, making it highly reusable for operations research applications, resource allocation, scheduling problems, and mathematical optimization across various domains.

Package Information

  • Package Name: pulp
  • Language: Python
  • Installation: pip install pulp
  • Requires: Python 3.9+

Core Imports

import pulp

Common for modeling problems:

from pulp import *

This imports all PuLP classes, functions, constants, and solver interfaces.

Basic Usage

from pulp import *

# Create variables
x = LpVariable("x", 0, 3)  # 0 <= x <= 3
y = LpVariable("y", cat="Binary")  # Binary variable (0 or 1)

# Create problem
prob = LpProblem("MyProblem", LpMinimize)

# Add constraints
prob += x + y <= 2

# Set objective function
prob += -4*x + y

# Solve with default solver
status = prob.solve()

# Check solution
print(f"Status: {LpStatus[status]}")
print(f"x = {value(x)}")
print(f"y = {value(y)}")
print(f"Objective = {value(prob.objective)}")

Architecture

PuLP's modular architecture enables flexible mathematical optimization modeling:

  • Core Modeling: LpProblem containers manage variables, constraints, and objectives
  • Variables and Expressions: LpVariable and LpAffineExpression handle decision variables and linear combinations
  • Constraint System: LpConstraint manages mathematical relationships with various sense operators
  • Solver Interface: Universal interface to 25+ optimization solvers including open-source (CBC, GLPK, HiGHS) and commercial (CPLEX, Gurobi, Xpress) options
  • File I/O: Export capabilities to standard formats (MPS, LP files) for solver interoperability

This design allows PuLP to serve as the foundation for mathematical optimization in Python, providing solver-agnostic modeling with automatic solver selection and robust handling of both linear programming (LP) and mixed integer linear programming (MILP) problems.

Capabilities

Core Modeling Classes

Fundamental classes for creating and manipulating optimization problems including problem containers, decision variables, constraints, and linear expressions.

class LpProblem:
    def __init__(self, name="NoName", sense=LpMinimize): ...
    def solve(self, solver=None, **kwargs): ...
    def writeLP(self, filename): ...
    def writeMPS(self, filename): ...

class LpVariable:
    def __init__(self, name, lowBound=None, upBound=None, cat=LpContinuous, e=None): ...
    @classmethod
    def dicts(cls, name, indices, lowBound=None, upBound=None, cat=LpContinuous): ...
    def bounds(self, low, up): ...
    def value(self): ...

class LpConstraint:
    def __init__(self, e=None, sense=LpConstraintEQ, name=None, rhs=None): ...
    def changeRHS(self, RHS): ...

class LpAffineExpression:
    def __init__(self, e=None, constant=0.0, name=None): ...
    def addterm(self, var, coeff): ...
    def value(self): ...

Core Modeling

Mathematical Operations

Essential functions for building linear expressions and extracting solution values from optimization problems.

def lpSum(vector): ...
def lpDot(v1, v2): ...
def value(x): ...

Mathematical Operations

Solver Interfaces

Comprehensive collection of solver interfaces supporting open-source and commercial optimization solvers with automatic detection and configuration.

class PULP_CBC_CMD: ...  # Default CBC solver
class GLPK_CMD: ...      # GLPK command-line
class HiGHS_CMD: ...     # HiGHS solver
class CPLEX_CMD: ...     # CPLEX command-line
class GUROBI: ...        # Gurobi Python interface
class XPRESS: ...        # Xpress solver

def getSolver(solver, *args, **kwargs): ...
def listSolvers(onlyAvailable=False): ...

Solver Interfaces

Constants and Enums

Essential constants for variable categories, problem senses, constraint types, and status codes used throughout PuLP's modeling system.

# Variable categories
LpContinuous = "Continuous"
LpInteger = "Integer"
LpBinary = "Binary"

# Problem senses
LpMinimize = 1
LpMaximize = -1

# Status constants
LpStatusOptimal = 1
LpStatusInfeasible = -1
LpStatusUnbounded = -2

# Constraint senses
LpConstraintLE = -1  # <=
LpConstraintEQ = 0   # =
LpConstraintGE = 1   # >=

Constants and Enums

Utility Functions

Supporting functions for combinatorial operations, data structure manipulation, and system utilities that enhance PuLP's modeling capabilities.

def makeDict(headers, array, default=None): ...
def allcombinations(orgset, k): ...
def allpermutations(orgset, k): ...
def read_table(data, coerce_type, transpose=False): ...
def splitDict(data): ...

Utility Functions

File I/O and Data Formats

Functions and classes for reading and writing optimization problems in standard formats (MPS, LP) and handling structured problem data.

def readMPS(path, sense, dropConsNames=False): ...
def writeLP(prob, filename): ...
def writeMPS(prob, filename): ...

class Matrix: ...  # Sparse matrix support

File I/O

Testing

Built-in testing functionality for validating PuLP installation and solver availability.

def pulpTestAll(): ...  # Run comprehensive PuLP test suite

Types

# Core exception classes
class PulpError(Exception):
    """
    Base exception class for PuLP-related errors.
    Raised for general PuLP operational errors including modeling issues,
    data validation problems, and internal inconsistencies.
    """

class PulpSolverError(Exception):
    """
    Exception class for solver-specific errors.
    Raised when solver communication fails, solver returns unexpected results,
    or solver configuration issues occur.
    """

# Status dictionaries
LpStatus: dict  # Status code to string mappings
LpSolution: dict  # Solution status mappings
LpConstraintSenses: dict  # Constraint sense mappings