PuLP is a linear and mixed integer programming modeler that provides an intuitive Python interface for creating, manipulating, and solving mathematical optimization problems.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Comprehensive collection of solver interfaces supporting both open-source and commercial optimization solvers. PuLP provides a universal interface that abstracts solver-specific details while enabling access to advanced solver features.
PuLP automatically detects available solvers and provides a default solver for immediate use without configuration.
# Default solver instance (automatically detected)
LpSolverDefault: LpSolver # Pre-configured default solver
def getSolver(solver, *args, **kwargs):
"""
Instantiate a solver by name with optional parameters.
Parameters:
- solver (str): Solver name (e.g., 'PULP_CBC_CMD', 'GLPK_CMD')
- *args: Positional arguments for solver constructor
- **kwargs: Keyword arguments for solver constructor
Returns:
LpSolver: Configured solver instance
"""
def listSolvers(onlyAvailable=False):
"""
List all solver names known to PuLP.
Parameters:
- onlyAvailable (bool): If True, only list solvers that are available/installed
Returns:
list: List of solver name strings
"""
def getSolverFromDict(data):
"""
Create solver instance from dictionary configuration.
Parameters:
- data (dict): Solver configuration dictionary
Returns:
LpSolver: Configured solver instance
"""
def getSolverFromJson(filename):
"""
Create solver instance from JSON configuration file.
Parameters:
- filename (str): Path to JSON configuration file
Returns:
LpSolver: Configured solver instance
"""Usage examples:
# Use default solver
prob.solve() # Uses LpSolverDefault
# List available solvers
available = listSolvers(onlyAvailable=True)
print("Available solvers:", available)
# Get specific solver by name
cbc_solver = getSolver('PULP_CBC_CMD')
status = prob.solve(cbc_solver)Foundation classes that define the solver interface and provide common functionality for all solver implementations.
class LpSolver:
"""
Generic LP Solver base class providing the common interface for all solvers.
"""
def __init__(self, mip=True, msg=True, **kwargs):
"""
Initialize solver with basic options.
Parameters:
- mip (bool): Enable mixed integer programming support
- msg (bool): Enable solver output messages
- **kwargs: Additional solver-specific options
"""
def available(self):
"""
Check if the solver is available on the system.
Returns:
bool: True if solver can be used
"""
def solve(self, problem):
"""
Solve the given optimization problem.
Parameters:
- problem (LpProblem): Problem to solve
Returns:
int: Solution status code
"""
class LpSolver_CMD:
"""
Base class for command-line solvers that use subprocess calls.
"""
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs):
"""
Initialize command-line solver.
Parameters:
- path (str, optional): Path to solver executable
- keepFiles (bool): Keep temporary files for debugging
- mip (bool): Enable mixed integer programming
- msg (bool): Show solver output
"""
class PulpSolverError(Exception):
"""
Exception raised for solver-specific errors.
"""Free and open-source optimization solvers that provide robust performance for most optimization problems.
class PULP_CBC_CMD:
"""
PuLP's default CBC (COIN-OR Branch and Cut) solver.
Excellent for mixed integer linear programming problems.
"""
def __init__(self, path=None, keepFiles=False, mip=True, msg=True,
cuts=True, presolve=True, dual=True, strong=True, **kwargs): ...
class COIN_CMD:
"""
COIN-OR linear programming solver (CLP) via command line.
Fast for pure linear programming problems.
"""
def __init__(self, path=None, keepFiles=False, mip=False, msg=True, **kwargs): ...
class COINMP_DLL:
"""
COIN-OR solver via DLL interface for Windows systems.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...
class GLPK_CMD:
"""
GNU Linear Programming Kit command-line interface.
Well-established open-source solver with good documentation.
"""
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
class PYGLPK:
"""
GLPK Python interface for direct library calls.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...
class GLPK:
"""
Alias for GLPK_CMD - automatically selects best available GLPK interface.
"""
class HiGHS:
"""
HiGHS solver Python interface - modern high-performance open-source solver.
Excellent performance for both LP and MIP problems.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...
class HiGHS_CMD:
"""
HiGHS solver command-line interface.
"""
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
class CYLP:
"""
CyLP interface to COIN-OR solvers with advanced Python integration.
Provides access to low-level solver features.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...High-performance commercial optimization solvers for demanding applications requiring maximum speed and advanced features.
class CPLEX_CMD:
"""
IBM CPLEX command-line interface.
Industry-leading commercial solver for large-scale optimization.
"""
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
class CPLEX_PY:
"""
IBM CPLEX Python interface using the docplex library.
Direct API access to CPLEX features and parameters.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...
class CPLEX:
"""
Alias for CPLEX_CMD - automatically selects best available CPLEX interface.
"""
class GUROBI:
"""
Gurobi optimizer Python interface.
High-performance commercial solver with excellent Python integration.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...
class GUROBI_CMD:
"""
Gurobi optimizer command-line interface.
"""
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
class XPRESS:
"""
FICO Xpress optimizer Python interface.
Commercial solver with strong MIP performance.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...
class XPRESS_CMD:
"""
FICO Xpress command-line interface.
"""
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
class XPRESS_PY:
"""
FICO Xpress Python interface with direct library access.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...
class MOSEK:
"""
MOSEK optimization solver for linear, quadratic, and conic problems.
Specialized for continuous optimization with high accuracy.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...
class COPT:
"""
Cardinal Optimizer (COPT) Python interface.
Modern commercial solver with competitive performance.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...
class COPT_CMD:
"""
Cardinal Optimizer command-line interface.
"""
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
class COPT_DLL:
"""
Cardinal Optimizer DLL interface for Windows systems.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...Solvers for specific problem types, research applications, and specialized optimization domains.
class SCIP_CMD:
"""
SCIP (System for Constraint Integer Programming) command-line interface.
Academic solver excellent for constraint programming and MIP.
"""
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
class SCIP_PY:
"""
SCIP Python interface for direct library access.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...
class SCIP:
"""
Alias for SCIP_CMD - automatically selects best available SCIP interface.
"""
class FSCIP_CMD:
"""
Fast SCIP command-line interface - optimized version of SCIP.
"""
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
class FSCIP:
"""
Alias for FSCIP_CMD.
"""
class CHOCO_CMD:
"""
CHOCO constraint programming solver.
Specialized for constraint satisfaction and constraint optimization problems.
"""
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
class MIPCL_CMD:
"""
MIPCL (Mixed Integer Programming Class Library) command-line interface.
Academic mixed integer programming solver.
"""
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
class CUOPT:
"""
NVIDIA cuOpt GPU-accelerated optimization solver.
Specialized for large-scale routing and scheduling problems.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...Integration with SAS analytics platform for enterprise optimization workflows.
class SAS94:
"""
SAS 9.4 optimization solver interface.
Enterprise analytics platform integration.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...
class SASCAS:
"""
SAS Cloud Analytic Services (CAS) solver interface.
Cloud-based SAS optimization services.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...
class SASsolver:
"""
Base class for SAS solver implementations.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...Historical solver interfaces maintained for backward compatibility.
class YAPOSIB:
"""
YAPOSIB (Yet Another Python Optimization Solver Interface Binding).
Legacy interface for various solvers - deprecated in favor of direct interfaces.
"""
def __init__(self, mip=True, msg=True, **kwargs): ...# Basic solver usage
prob = LpProblem("Example", LpMinimize)
x = LpVariable("x", 0, 10)
prob += x
status = prob.solve() # Uses default solver
# Specify solver explicitly
status = prob.solve(PULP_CBC_CMD(msg=0)) # CBC without output
status = prob.solve(GLPK_CMD()) # GLPK solver
status = prob.solve(HiGHS()) # HiGHS solver
# Commercial solver with options
gurobi_solver = GUROBI(msg=True, timeLimit=3600)
if gurobi_solver.available():
status = prob.solve(gurobi_solver)
else:
print("Gurobi not available, using default")
status = prob.solve()
# Solver selection based on problem type
def select_solver(problem_size, has_integers=False):
if problem_size > 100000:
# Large problems - try commercial first
for solver_class in [GUROBI, CPLEX, XPRESS]:
solver = solver_class(msg=0)
if solver.available():
return solver
if has_integers:
# MIP problems - use CBC or HiGHS
return PULP_CBC_CMD(msg=0)
else:
# Pure LP - HiGHS is very fast
return HiGHS(msg=0)
# Dynamic solver configuration
solver_config = {
'solver_name': 'PULP_CBC_CMD',
'msg': False,
'cuts': True,
'presolve': True
}
solver = getSolver(**solver_config)
status = prob.solve(solver)
# Check solver availability
print("Available solvers:")
for solver_name in listSolvers(onlyAvailable=True):
print(f" {solver_name}")
# Solver performance comparison
import time
solvers_to_test = [PULP_CBC_CMD(), HiGHS(), GLPK_CMD()]
for solver in solvers_to_test:
if solver.available():
start = time.time()
status = prob.solve(solver)
elapsed = time.time() - start
print(f"{solver.__class__.__name__}: {elapsed:.3f}s, Status: {LpStatus[status]}")Install with Tessl CLI
npx tessl i tessl/pypi-pulp