pulp.apis Interface to Solvers

class pulp.apis.CHOCO_CMD(path=None, keepFiles=False, mip=True, msg=True, options=None, timeLimit=None)

Bases: LpSolver_CMD

The CHOCO_CMD solver

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • options (list) – list of additional options to pass to solver

  • keepFiles (bool) – if True, files are saved in the current directory and not deleted after solving

  • path (str) – path to the solver binary

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

available()

True if the solver is available

defaultPath()
name = 'CHOCO_CMD'
static readsol(filename)

Read a Choco solution file

class pulp.apis.CLARABEL(mip=True, msg=True, timeLimit=None, threads=None, logPath=None, **solverParams)

Bases: LpSolver_API

The Clarabel interior point solver (via its python interface).

Clarabel solves linear programs only: a problem with integer variables needs mip=False, which solves its LP relaxation. It has no warm start, so a resolve builds the model again.

The Clarabel DefaultSolver is available (after a solve) in prob.solverModel.

Parameters:
  • mip (bool) – if False, integer variables are relaxed to continuous ones; if True, a problem with integer variables cannot be solved

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • threads (int) – sets the maximum number of threads

  • logPath (str) – path to the log file; the log goes there instead of the console

  • solverParams (dict) – fields of Clarabel’s DefaultSettings (e.g. max_iter, tol_gap_rel, presolve_enable)

available()

True if the solver is available

buildSolverModel(lp: LpProblem) → None

Takes the pulp lp model and translates it into a Clarabel model: minimize q'x subject to Ax + s = b, with s in a cone.

Column j is the variable with id j and row i the constraint with id i, a >= row negated into a <= one. The finite variable bounds come after them, as rows too: Clarabel has no variable bounds.

callSolver(lp: LpProblem, *, changes: _rustcore.ModelChanges | None = None, **kwargs: Any) → Any

Solves the problem with Clarabel, stopping when the callback given to solve (called with Clarabel’s DefaultInfo on every iteration) returns True; returns the DefaultSolution.

findSolutionValues(lp: LpProblem, result: Any = None) → tuple[constants.LpSolveStatus, bool]
Parameters:

result – the DefaultSolution that callSolver() returned

logPathSilencesMsg: bool = True

True when handing the solver a logPath sends its output to the file instead of the console, so capture_log() has to echo the log back afterwards to keep msg=True behaving as the caller expects.

name = 'CLARABEL'
class pulp.apis.COINMP_DLL(mip: bool = True, msg: bool = True, options: list[str] | None = None, timeLimit: float | None = None, *args: Any, **kwargs: Any)

Bases: LpSolver

The COIN_MP LP MIP solver (via a DLL or linux so)

Parameters:
  • timeLimit (float) – The number of seconds before forcing the solver to exit

  • epgap – The fractional mip tolerance

  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • options (list)

  • timeLimit – maximum time for solver (in seconds)

  • args

  • kwargs – optional named options to pass to each solver, e.g. gapRel=0.1, gapAbs=10, logPath=””,

COIN_INT_LOGLEVEL = 7
COIN_REAL_MAXSECONDS = 16
COIN_REAL_MIPFRACGAP = 34
COIN_REAL_MIPMAXSEC = 19
actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

classmethod available()

True if the solver is available

lib: Any = None
name = 'COINMP_DLL'
class pulp.apis.COIN_CMD(mip=True, msg=True, timeLimit=None, gapRel=None, gapAbs=None, presolve=None, cuts=None, strong=None, options=None, warmStart=False, keepFiles=False, path=None, threads=None, logPath=None, timeMode='elapsed', maxNodes=None, randomSeed=None)

Bases: LpSolver_CMD

COIN-OR CBC invoked as a command-line executable.

The default binary is resolved from the optional cbcbox package (install pulp[cbc]) when present, otherwise from cbc / cbc.exe on PATH. Pass path= to use a specific CBC binary.

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • gapAbs (float) – absolute gap tolerance for the solver to stop

  • threads (int) – sets the maximum number of threads

  • options (list) – list of additional options to pass to solver

  • warmStart (bool) – if True, the solver will use the current value of variables as a start

  • keepFiles (bool) – if True, files are saved in the current directory and not deleted after solving

  • path (str) – path to the solver binary

  • logPath (str) – path to the log file

  • presolve (bool) – if True, adds presolve on, if False, adds presolve off

  • cuts (bool) – if True, adds gomory on knapsack on probing on, if False adds cuts off

  • strong (int) – number of variables to look at in strong branching (range is 0 to 2147483647)

  • timeMode (str) – “elapsed”: count wall-time to timeLimit; “cpu”: count cpu-time

  • maxNodes (int) – max number of nodes during branching. Stops the solving when reached.

  • randomSeed (int) – random seed passed to CBC (-randomSeed) for reproducible results

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

available()

True if the solver is available

copy()

Make a copy of self

defaultPath()
getOptions()
get_status(filename: str) → tuple[LpSolveStatus, bool]

Read why CBC stopped, and whether it has a solution, off the first line of its solution file, e.g. Stopped on time - objective value 12.

logPathSilencesMsg: bool = True

True when handing the solver a logPath sends its output to the file instead of the console, so capture_log() has to echo the log back afterwards to keep msg=True behaving as the caller expects.

name = 'COIN_CMD'
readsol_LP(filename: str, lp: LpProblem) → tuple[constants.LpSolveStatus, dict[str, float], dict[str, float], dict[str, float], dict[str, float], bool]

Read a CBC solution file generated from an lp (good names). Returns status, values, reducedCosts, shadowPrices, slacks, has_solution.

readsol_MPS(filename: str, lp: LpProblem, variableNames: list[str], constraintNames: list[str], objectiveName: str | None = None, pulp_names_in_column_order: list[str] | None = None) → tuple[constants.LpSolveStatus, dict[str, float], dict[str, float], dict[str, float], dict[str, float], bool]

Read a CBC solution file generated from an mps or lp file (possible different names).

variableNames are names as they appear in the solution file (column order). When rename=True on writeMPS, pass pulp_names_in_column_order from writeMPS so file tokens map back to PuLP variable names.

solve_CBC(lp: LpProblem, use_mps=True) → tuple[constants.LpSolveStatus, bool]

Solve a MIP problem using CBC; returns why it stopped and whether it has a solution.

writesol(filename: str, lp: LpProblem, variableNames: list[str], constraintNames: list[str]) → bool

Writes a CBC solution file generated from an mps / lp file (possible different names).

variableNames must be in the same column order as the model file (exported columns). Returns True on success.

class pulp.apis.COPT(mip=True, msg=True, timeLimit=None, gapRel=None, warmStart=False, logPath=None, **solverParams)

Bases: LpSolver_API

The COPT Optimizer via its python interface

The COPT variables are available (after a solve) in var.solverVar Constraints in constraint.solverConstraint and the Model is in prob.solverModel

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • warmStart (bool) – if True, the solver will use the current value of variables as a start

  • logPath (str) – path to the log file

applyChanges(lp: LpProblem, changes: _rustcore.ModelChanges) → None

Update lp.solverModel with the edits made to lp since it was last solved (changes, from _take_changes()), keeping the basis.

Columns are variable ids and rows constraint ids, so new variables and constraints are appended in id order.

available()

True if the solver is available

buildSolverModel(lp)

Takes the pulp lp model and translates it into a COPT model

callSolver(lp, *, changes=None, **kwargs)

Solves the problem with COPT, with the callback given to solve

canUpdate(lp)

Whether actualResolve() may update lp.solverModel in place with applyChanges() instead of building it again.

configureSolver(lp: LpProblem) → None

Apply the time limit, gap and log file to lp.solverModel, again on every resolve so that options changed in between take effect.

createModel()

A new, empty COPT model with the solver parameters set.

findSolutionValues(lp, result=None)

Write the solution back into lp.

Parameters:

result – what callSolver() returned

Returns:

(status, has_solution)

name = 'COPT'
class pulp.apis.COPT_CMD(path=None, keepFiles=0, mip=True, msg=True, mip_start=False, warmStart=False, logfile=None, **params)

Bases: LpSolver_CMD

The COPT command-line solver

Initialize command-line solver

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated LP problem

This function borrowed implementation of CPLEX_CMD.actualSolve and GUROBI_CMD.actualSolve, with some modifications.

available()

True if ‘copt_cmd’ is available

defaultPath()

The default path of ‘copt_cmd’

name = 'COPT_CMD'
readsol(filename)

Read COPT solution file

writemst(filename, lpvars)

Write COPT MIP start file

class pulp.apis.COPT_DLL(mip: bool = True, msg: bool = True, options: list[str] | None = None, timeLimit: float | None = None, *args: Any, **kwargs: Any)

Bases: LpSolver

The COPT dynamic library solver

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • options (list)

  • timeLimit (float) – maximum time for solver (in seconds)

  • args

  • kwargs – optional named options to pass to each solver, e.g. gapRel=0.1, gapAbs=10, logPath=””,

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

available()

True if the solver is available

err = PulpSolverError('COPT_PULP: Failed to locate solver library, please refer to COPT manual for installation guide')
name = 'COPT_DLL'
pulp.apis.CPLEX

alias of CPLEX_CMD

class pulp.apis.CPLEX_CMD(mip=True, msg=True, timeLimit=None, gapRel=None, gapAbs=None, options=None, warmStart=False, keepFiles=False, path=None, threads=None, logPath=None, maxMemory=None, maxNodes=None)

Bases: LpSolver_CMD

The CPLEX LP solver

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • gapAbs (float) – absolute gap tolerance for the solver to stop

  • threads (int) – sets the maximum number of threads

  • options (list) – list of additional options to pass to solver

  • warmStart (bool) – if True, the solver will use the current value of variables as a start

  • keepFiles (bool) – if True, files are saved in the current directory and not deleted after solving

  • path (str) – path to the solver binary

  • logPath (str) – path to the log file

  • maxMemory (float) – max memory to use during the solving. Stops the solving when reached.

  • maxNodes (int) – max number of nodes during branching. Stops the solving when reached.

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem

available() → bool

True if the solver is available

defaultPath()
getOptions()
name = 'CPLEX_CMD'
static readsol(filename)

Read a CPLEX solution file

writesol(filename, vs)

Writes a CPLEX solution file

class pulp.apis.CPLEX_PY(mip=True, msg=True, timeLimit=None, gapRel=None, warmStart=False, logPath=None, threads=None, **solverParams)

Bases: LpSolver_API

The CPLEX LP/MIP solver (via a Python Binding)

This solver wraps the python api of cplex. It has been tested against cplex 12.3. For api functions that have not been wrapped in this solver please use the base cplex classes

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • warmStart (bool) – if True, the solver will use the current value of variables as a start

  • logPath (str) – path to the log file

  • threads (int) – number of threads to be used by CPLEX to solve a problem (default None uses all available)

  • solverParams (dict) – Additional parameters to set in the CPLEX solver.

Parameters should use dot notation as specified in the CPLEX documentation. The ‘parameters.’ prefix is optional. For example:

  • parameters.advance (or advance)

  • parameters.barrier.algorithm (or barrier.algorithm)

  • parameters.mip.strategy.probe (or mip.strategy.probe)

actualResolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Update lp.solverModel with the edits made since the last solve and solve it again from its current basis; build it from scratch if it cannot be updated (see canUpdate() and _take_changes()).

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem

Parameters:

kwargs – Optional callback — iterable of CPLEX callback classes to register during solve.

applyChanges(lp: LpProblem, changes: _rustcore.ModelChanges) → None

Update lp.solverModel with the edits made to lp since it was last solved (changes, from _take_changes()), keeping the basis.

Columns are variable ids and rows constraint ids, so new variables and constraints are appended in id order.

available()

True if the solver is available

buildSolverModel(lp: LpProblem) → None

Takes the pulp lp model and translates it into a cplex model.

Every variable is a column, used or not: column j is the variable with id j (as row i is the constraint with id i), so that a resolve only appends.

callSolver(lp: LpProblem, *, changes: _rustcore.ModelChanges | None = None, **kwargs: Any) → None

Solves the problem with cplex

Parameters:

kwargs – Optional callback — iterable of CPLEX callback classes to register during solve

canUpdate(lp: LpProblem) → bool

Whether actualResolve() may update lp.solverModel in place with applyChanges() instead of building it again.

changeEpgap(epgap=0.0001)

Change cplex solver integer bound gap tolerence

closeLogFile()

Detaches cplex from the logPath file opened by configureSolver and closes it

configureSolver(lp: LpProblem) → None

Apply the logging, gap, time limit, threads and solver parameters to lp.solverModel, again on every resolve so that options changed in between take effect.

findSolutionValues(*args, **kwargs)

Write the solution back into lp.

Parameters:

result – what callSolver() returned

Returns:

(status, has_solution)

get_all_params(*args, **kwargs)
get_changed_params(*args, **kwargs)
get_param(name: str)

Returns the value of a named parameter by searching within the instance’s parameters.

logPathSilencesMsg: bool = True

True when handing the solver a logPath sends its output to the file instead of the console, so capture_log() has to echo the log back afterwards to keep msg=True behaving as the caller expects.

name = 'CPLEX_PY'
search_param(*args, **kwargs)
setThreads(threads=None)

Change cplex thread count used (None is default which uses all available resources)

setTimeLimit(timeLimit=0.0)

Make cplex limit the time it takes –added CBM 8/28/09

set_param(name: str, value)

Sets a parameter value using its name.

setlogfile(fileobj)

sets the logfile for cplex output

class pulp.apis.CPSAT(mip=True, msg=True, timeLimit=None, warmStart=False, logPath=None, **solverParams)

Bases: LpSolver_API

The OR-Tools CP-SAT solver (via its Python API).

CP-SAT requires finite lower and upper bounds on every variable. Continuous variables are converted to integer variables on [ceil(lowBound), floor(upBound)].

The CP-SAT model is available (after a solve) in prob.solverModel.

Parameters:
  • mip (bool) – ignored; CP-SAT always solves as a discrete model

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • warmStart (bool) – if True, pass current variable values as hints

  • logPath (str) – path to write the search log to

  • solverParams (dict) – threads or additional parameters for CpSolver.parameters

available() → bool

True if the solver is available

buildSolverModel(lp: LpProblem) → None

Takes the pulp lp model and translates it into a CP-SAT model.

The CP-SAT variable with index j is lp.exported_variables()[j].

callSolver(lp: LpProblem, *, changes: _rustcore.ModelChanges | None = None, **kwargs: Any) → tuple[Any, Any]

Solves the problem with CP-SAT and returns the solver and status.

findSolutionValues(lp: LpProblem, result: Any = None) → tuple[constants.LpSolveStatus, bool]
Parameters:

result – the (solver, status) that callSolver() returned

name = 'CPSAT'
class pulp.apis.CUOPT(mip=True, msg=True, timeLimit=None, gapRel=None, warmStart=False, logPath=None, **solverParams)

Bases: LpSolver_API

The CUOPT Optimizer via its python interface

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • warmStart (bool) – if True, the solver will use the current value of variables as a start

  • logPath (str) – path to the log file

  • solverParams – solver setting paramters for cuopt

available()

True if the solver is available

buildSolverModel(lp)

Takes the pulp lp model and translates it into a COPT model

callSolver(lp, *, changes=None, **kwargs)

Solves the problem with CUOPT and returns its solution

findSolutionValues(lp, result=None)
Parameters:

result – the solution that callSolver() returned

name = 'CUOPT'
class pulp.apis.CYLP(mip=True, msg=True, gapAbs=None, gapRel=None, threads=None, timeLimit=None, maxNodes=None, maxSolutions=None, maxIterations=None, presolve=None, logPath=None, **solverParams)

Bases: LpSolver_API

The CyLP solver: COIN-OR Clp (LP) and Cbc (MIP) through their cython bindings.

The CyLP model is available (after a solve) in lp.solverModel: a CyCbcModel when the problem was solved as a MIP, a CyClpSimplex otherwise.

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • gapAbs (float) – absolute gap tolerance for the solver to stop

  • threads (int) – sets the maximum number of threads

  • timeLimit (float) – maximum time for solver (in seconds), only used by Cbc: CyLP offers no time limit for Clp

  • maxNodes (int) – max number of nodes during branching, only used by Cbc

  • maxSolutions (int) – stop after finding this many solutions, only used by Cbc

  • maxIterations (int) – max number of simplex iterations, only used by Clp

  • presolve (bool) – if False, Clp solves without presolve, only used by Clp

  • logPath (str) – path to the log file; the log goes there instead of the console

  • solverParams (dict) – attributes of the Clp or Cbc model being solved, e.g. primalTolerance (Clp) or allowableGap (Cbc); resolveMethod ("primal" or "dual") forces Clp’s simplex on a resolve, chosen from the changes otherwise; perturbation is Clp’s (setPerturbation, e.g. 50: always perturb), on every solve

applyChanges(lp: LpProblem, changes: _rustcore.ModelChanges) → None

Update the Clp model lp.solverModel with the edits made to lp since it was last solved (changes, from _take_changes()), keeping the basis.

Clp cannot change an entry of the matrix: editing a coefficient of an existing variable in an existing constraint (remove_variables included) rebuilds it.

available()

True if the solver is available

buildSolverModel(lp: LpProblem) → None

Takes the pulp lp model and translates it into a CyLP model.

Every variable is a column, used or not: column j is the variable with id j (as row i is the constraint with id i), so that a resolve only appends.

callSolver(lp: LpProblem, *, changes: _rustcore.ModelChanges | None = None, **kwargs: Any) → None

Solves the problem with Cbc if it is a MIP, with Clp otherwise

canUpdate(lp: LpProblem) → bool

Only a Clp (LP) model is updated; Cbc (MIP) ones are built again.

findBestBound(lp: LpProblem) → float | None

The best bound Cbc proved on a MIP with a solution, in the problem’s sense, or None.

findSolutionValues(lp: LpProblem, result: Any = None) → tuple[constants.LpSolveStatus, bool]

Write the solution back into lp.

Parameters:

result – what callSolver() returned

Returns:

(status, has_solution)

static isCbcModel(lp: LpProblem) → bool

Whether lp.solverModel is a Cbc (MIP) model rather than a Clp (LP) one

logPathSilencesMsg: bool = True

True when handing the solver a logPath sends its output to the file instead of the console, so capture_log() has to echo the log back afterwards to keep msg=True behaving as the caller expects.

name = 'CyLP'
pulp.apis.FSCIP

alias of FSCIP_CMD

class pulp.apis.FSCIP_CMD(path=None, mip=True, keepFiles=False, msg=True, options=None, timeLimit=None, gapRel=None, gapAbs=None, maxNodes=None, threads=None, logPath=None)

Bases: LpSolver_CMD

The multi-threaded FiberSCIP version of the SCIP optimization solver

Parameters:
  • msg (bool) – if False, no log is shown

  • mip (bool) – if False, assume LP even if integer variables

  • options (list) – list of additional options to pass to solver

  • keepFiles (bool) – if True, files are saved in the current directory and not deleted after solving

  • path (str) – path to the solver binary

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • gapAbs (float) – absolute gap tolerance for the solver to stop

  • maxNodes (int) – max number of nodes during branching. Stops the solving when reached.

  • threads (int) – sets the maximum number of threads

  • logPath (str) – path to the log file

FSCIP_STATUSES = {'Final Solution': LpSolveStatus.Optimal, 'No Solution': LpSolveStatus.NotSolved}
NO_SOLUTION_STATUSES = {LpSolveStatus.Unbounded, LpSolveStatus.Infeasible, LpSolveStatus.NotSolved}
actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

available()

True if the solver is available

defaultPath()
name = 'FSCIP_CMD'
static parse_objective(string: str) → float | None
static parse_status(string: str) → LpSolveStatus | None
static parse_variable(string: str) → tuple[str, float] | None
static readsol(filename)

Read a FSCIP solution file

class pulp.apis.GLOP(mip=True, msg=True, timeLimit=None, threads=None, logPath=None, warmStart=False, interrupter: Any = None, **solverParams)

Bases: LpSolver_API

The OR-Tools GLOP simplex LP solver (via the MathOpt Python API).

GLOP solves linear programs only: a problem with integer variables needs mip=False, which solves its LP relaxation.

The model is kept between solves, so resolve() updates it and restarts from the previous basis. prob.solverModel is a GlopModel: the MathOpt model, its incremental solver and the result of the last solve.

Parameters:
  • mip (bool) – if False, integer variables are relaxed to continuous ones; if True, a problem with integer variables cannot be solved

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • threads (int) – sets the maximum number of threads

  • logPath (str) – path to write the solver log to

  • warmStart (bool) – ignored, GLOP takes no starting solution; use prob.resolve to restart from the previous basis

  • interrupter – an ortools.util.python.solve_interrupter.SolveInterrupter; calling its interrupt() (e.g. from another thread or from the callback given to solve) stops the solve

  • solverParams (dict) – fields of MathOpt’s SolveParameters (e.g. iteration_limit, presolve=False, lp_algorithm="dual_simplex") or of GlopParameters (e.g. use_dual_simplex, primal_feasibility_tolerance)

applyChanges(lp: LpProblem, changes: _rustcore.ModelChanges) → None

Update lp.solverModel with the edits made to lp since it was last solved (changes, from _take_changes()). The incremental solver hands them to GLOP, which keeps its basis.

Variables and constraints keep their pulp ids in the MathOpt model.

available() → bool

True if the solver is available

buildSolverModel(lp: LpProblem) → None

Takes the pulp lp model and translates it into a MathOpt model solved by GLOP.

The whole model is written as one ModelProto: adding the variables, constraints and coefficients one by one costs far more.

callSolver(lp: LpProblem, *, changes: _rustcore.ModelChanges | None = None, **kwargs: Any) → None

Solves the problem with GLOP; the result is kept in lp.solverModel.

The callback given to solve is called with each batch of log lines (a list of str) as the solver writes them. GLOP has no other callbacks.

canUpdate(lp: LpProblem) → bool

Whether actualResolve() may update lp.solverModel in place with applyChanges() instead of building it again.

configureSolver(lp: LpProblem) → None

Set the SolveParameters of lp.solverModel from the options, again on every resolve so that options changed in between take effect.

findSolutionValues(lp: LpProblem, result: Any = None) → tuple[constants.LpSolveStatus, bool]

Reads the result of the last solve from lp.solverModel.

name = 'GLOP'
pulp.apis.GLPK

alias of GLPK_CMD

class pulp.apis.GLPK_CMD(path=None, keepFiles=False, mip=True, msg=True, options=None, timeLimit=None)

Bases: LpSolver_CMD

The GLPK LP solver

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • options (list) – list of additional options to pass to solver

  • keepFiles (bool) – if True, files are saved in the current directory and not deleted after solving

  • path (str) – path to the solver binary

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

available()

True if the solver is available

defaultPath()
name = 'GLPK_CMD'
readsol(outFile, solFile)

Read GLPK solution files

class pulp.apis.GUROBI(mip=True, msg=True, timeLimit=None, gapRel=None, gapAbs=None, warmStart=False, logPath=None, env=None, envOptions=None, manageEnv=False, **solverParams)

Bases: LpSolver_API

The Gurobi LP/MIP solver (via its python interface)

The Gurobi variables are available (after a solve) in var.solverVar Constraints in constraint.solverConstraint and the Model is in prob.solverModel

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • gapAbs (float) – absolute gap tolerance for the solver to stop

  • warmStart (bool) – if True, the solver will use the current value of variables as a start

  • logPath (str) – path to the log file

  • env (gp.Env) – Gurobi environment to use. Default None.

  • envOptions (dict) – environment options.

  • manageEnv (bool) – if False, assume the environment is handled by the user.

If manageEnv is set to True, the GUROBI object creates a local Gurobi environment and manages all associated Gurobi resources. Importantly, this enables Gurobi licenses to be freed and connections terminated when the .close() function is called (this function always disposes of the Gurobi model, and the environment):

solver = GUROBI(manageEnv=True)
prob.solve(solver)
solver.close() # Must be called to free Gurobi resources.
# All Gurobi models and environments are freed

manageEnv=True is required when setting license or connection parameters. The envOptions argument is used to pass parameters to the Gurobi environment. For example, to connect to a Gurobi Cluster Manager:

options = {
    "CSManager": "<url>",
    "CSAPIAccessID": "<access-id>",
    "CSAPISecret": "<api-key>",
}
solver = GUROBI(manageEnv=True, envOptions=options)
solver.close()
# Compute server connection terminated

Alternatively, one can also pass a gp.Env object. In this case, to be safe, one should still call .close() to dispose of the model:

with gp.Env(params=options) as env:
    # Pass environment as a parameter
    solver = GUROBI(env=env)
    prob.solve(solver)
    solver.close()
    # Still call `close` as this disposes the model which is required to correctly free env

If manageEnv is set to False (the default), the GUROBI object uses the global default Gurobi environment which will be freed once the object is deleted. In this case, one can still call .close() to dispose of the model:

solver = GUROBI()
prob.solve(solver)
# The global default environment and model remain active
solver.close()
# Only the global default environment remains active
applyChanges(lp: LpProblem, changes: _rustcore.ModelChanges) → None

Update lp.solverModel with the edits made to lp since it was last solved (changes, from _take_changes()), keeping the basis.

Columns are variable ids and rows constraint ids, so new variables and constraints are appended in id order.

available()

True if the solver is available

buildSolverModel(lp: LpProblem)

Takes the pulp lp model and translates it into a gurobi model

callSolver(lp, *, changes=None, **kwargs)

Solves the problem with gurobi, with the callback given to solve

canUpdate(lp: LpProblem) → bool

Whether actualResolve() may update lp.solverModel in place with applyChanges() instead of building it again.

close()

Must be called when internal Gurobi model and/or environment requires disposing. The environment (default or otherwise) will be disposed only if manageEnv is set to True.

configureSolver(lp: LpProblem) → None

Apply msg, the time limit, gap tolerances and log file to the model.

env = None
findSolutionValues(lp: LpProblem, result: Any = None)

Write the solution back into lp.

Parameters:

result – what callSolver() returned

Returns:

(status, has_solution)

initGurobi()
name = 'GUROBI'
class pulp.apis.GUROBI_CMD(mip=True, msg=True, timeLimit=None, gapRel=None, gapAbs=None, options=None, warmStart=False, keepFiles=False, path=None, threads=None, logPath=None, mip_start=False)

Bases: LpSolver_CMD

The GUROBI_CMD solver

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • gapAbs (float) – absolute gap tolerance for the solver to stop

  • threads (int) – sets the maximum number of threads

  • options (list) – list of additional options to pass to solver

  • warmStart (bool) – if True, the solver will use the current value of variables as a start

  • keepFiles (bool) – if True, files are saved in the current directory and not deleted after solving

  • path (str) – path to the solver binary

  • logPath (str) – path to the log file

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

available()

True if the solver is available

defaultPath()
getOptions()
name = 'GUROBI_CMD'
readsol(filename)

Read a Gurobi solution file

writesol(filename, vs)

Writes a GUROBI solution file

class pulp.apis.HiGHS(mip=True, msg=True, callbackTuple=None, gapAbs=None, gapRel=None, threads=None, timeLimit=None, logPath=None, warmStart=False, callbacksToActivate: list[highspy_t.cb.HighsCallbackType] | None = None, **solverParams)

Bases: LpSolver_API

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • callbackTuple (tuple) – Tuple of callback function and callbackValue (see tests for an example)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • gapAbs (float) – absolute gap tolerance for the solver to stop

  • threads (int) – sets the maximum number of threads

  • logPath (str) – path to the log file

  • timeLimit (float) – maximum time for solver (in seconds)

  • warmStart (bool) – if True, the solver will use the current value of variables as a start

  • solverParams (dict) – list of named options to pass directly to the HiGHS solver

  • callbacksToActivate – list of callback types to start

applyChanges(lp, changes)

Update lp.solverModel with the edits made to lp since it was last solved (changes, from _take_changes()), keeping the basis.

Columns are variable ids and rows constraint ids, so new variables and constraints are appended in id order.

available()

True if the solver is available

buildSolverModel(lp)

Translate lp into the solver’s model, stored in lp.solverModel, and configure it (see configureSolver()).

callSolver(lp, *, changes=None, **kwargs)

Solve lp.solverModel.

Parameters:
  • changes – the edits just replayed on the model by a resolve, None when it was built from scratch

  • kwargs – the arguments given to solve, e.g. callback

Returns:

whatever findSolutionValues() needs besides the model

canUpdate(lp)

Whether actualResolve() may update lp.solverModel in place with applyChanges() instead of building it again.

configureSolver(lp)

Apply the solver options to lp.solverModel, again on every resolve so that options changed in between take effect.

findBestBound(lp: LpProblem) → float | None

The best bound HiGHS proved on a MIP, in the problem’s sense, or None.

findSolutionValues(lp, result=None)

Write the solution back into lp.

Parameters:

result – what callSolver() returned

Returns:

(status, has_solution)

hscb = <module 'highspy._core.cb' from '/home/runner/work/pulp/pulp/.venv/lib/python3.12/site-packages/highspy/_core.cpython-312-x86_64-linux-gnu.so'>
name = 'HiGHS'
class pulp.apis.HiGHS_CMD(path=None, keepFiles=False, mip=True, msg=True, options=None, timeLimit=None, gapRel=None, gapAbs=None, threads=None, logPath=None, warmStart=False)

Bases: LpSolver_CMD

The HiGHS_CMD solver

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • gapAbs (float) – absolute gap tolerance for the solver to stop

  • options (list[str]) – list of additional options to pass to solver

  • keepFiles (bool) – if True, files are saved in the current directory and not deleted after solving

  • path (str) – path to the solver binary (you can get binaries for your platform from https://github.com/JuliaBinaryWrappers/HiGHS_jll.jl/releases, or else compile from source - https://highs.dev)

  • threads (int) – sets the maximum number of threads

  • logPath (str) – path to the log file

  • warmStart (bool) – if True, the solver will use the current value of variables as a start

SOLUTION_STYLE: int = 0
actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

available()

True if the solver is available

defaultPath()
name: str = 'HiGHS_CMD'
readsol(filename)

Read a HiGHS solution file

writesol(filename, lp)

Writes a HiGHS solution file

class pulp.apis.LpSolver(mip: bool = True, msg: bool = True, options: list[str] | None = None, timeLimit: float | None = None, *args: Any, **kwargs: Any)

Bases: object

A generic LP Solver

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • options (list)

  • timeLimit (float) – maximum time for solver (in seconds)

  • args

  • kwargs – optional named options to pass to each solver, e.g. gapRel=0.1, gapAbs=10, logPath=””,

actualResolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve lp again. Solvers that can update lp.solverModel in place, keeping its basis for a hot start, override this using _take_changes(); by default the model is built from scratch.

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

Implementations end with return self.buildStats(...).

available() → bool

True if the solver is available

buildStats(lp: LpProblem, status: int, has_solution: bool, *, start: tuple[float, float], best_bound: float | None = None) → LpSolveStats

Describe the solve that just finished, for actualSolve to return.

Parameters:
  • lp – the problem that was solved

  • status – why the solver stopped, a LpSolveStatus

  • has_solution – whether the solver handed back a feasible solution

  • start – clocks() taken when the solve started

  • best_bound – best bound the solver proved, if it reports one

capture_log() → Iterator[str | None]

Ensure a parseable solver log exists for the duration of the block.

Yields the path to the log file, or None when this solver cannot produce one that orloge understands. A log the caller asked for through logPath is used as-is and left in place; a log this method arranges itself goes to a temporary file that is removed on the way out, so read it before the block ends.

copy() → LpSolver

Make a copy of self

flipStatsSense(stats: LpSolveStats) → LpSolveStats

Undo a solver-side objective negation in stats built by buildStats().

Some solvers (e.g. COIN_CMD, which writes a maximize problem as an MPS file with no OBJSENSE and no -max, negating the objective instead) are handed the problem with its objective negated. Everything that solver then reports about the objective – its log, and any bound it proves – comes back with the opposite sign to the problem’s own sense, and needs flipping back. Call this once, right after buildStats(), only for a solve where that negation happened.

stats.objective is left alone: it comes from lp.objective.value(), computed from the variable values buildStats() already assigned back onto the original (un-negated) problem, so it is already in the problem’s sense.

Mutates stats in place and returns it, for convenient chaining.

getCplexStyleArrays(lp: LpProblem, senseDict: dict[int, str] | None = None, LpVarCategories: dict[str, str] | None = None, LpObjSenses: dict[int, int] | None = None, infBound: float = 1e+20) → tuple[Any, ...]

Return arrays suitable for a CDLL CPLEX-style API or similar solvers.

Copyright (c) Stuart Mitchell 2007

logPathSilencesMsg: bool = False

True when handing the solver a logPath sends its output to the file instead of the console, so capture_log() has to echo the log back afterwards to keep msg=True behaving as the caller expects.

name = 'LpSolver'
resolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve lp again, updating the model the solver already holds when it can (see actualResolve()), and describe how it went.

silent_remove(file: str | bytes | PathLike) → None
solve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve the problem lp and describe how it went.

toDict() → dict[str, Any]
toJson(filename: str, *args: Any, **kwargs: Any) → None
to_dict() → dict[str, Any]
to_json(filename: str, *args: Any, **kwargs: Any) → None
class pulp.apis.LpSolver_API(mip: bool = True, msg: bool = True, options: list[str] | None = None, timeLimit: float | None = None, *args: Any, **kwargs: Any)

Bases: LpSolver

A generic LP Solver driven through its python interface.

A solve goes through three steps, which can also be called one by one to reach the solver’s own model in between:

solver.buildSolverModel(lp)  # fills lp.solverModel
result = solver.callSolver(lp)
status, has_solution = solver.findSolutionValues(lp, result)

A solver that can update lp.solverModel in place on a resolve also implements applyChanges() and canUpdate().

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • options (list)

  • timeLimit (float) – maximum time for solver (in seconds)

  • args

  • kwargs – optional named options to pass to each solver, e.g. gapRel=0.1, gapAbs=10, logPath=””,

actualResolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Update lp.solverModel with the edits made since the last solve and solve it again from its current basis; build it from scratch if it cannot be updated (see canUpdate() and _take_changes()).

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Build the solver model, solve it and read the solution back.

applyChanges(lp: LpProblem, changes: _rustcore.ModelChanges) → None

Update lp.solverModel with the edits made to lp since it was last solved (changes, from _take_changes()), keeping its basis.

Raises _RebuildNeeded before touching the model if an edit cannot be replayed.

buildSolverModel(lp: LpProblem) → None

Translate lp into the solver’s model, stored in lp.solverModel, and configure it (see configureSolver()).

callSolver(lp: LpProblem, *, changes: _rustcore.ModelChanges | None = None, **kwargs: Any) → Any

Solve lp.solverModel.

Parameters:
  • changes – the edits just replayed on the model by a resolve, None when it was built from scratch

  • kwargs – the arguments given to solve, e.g. callback

Returns:

whatever findSolutionValues() needs besides the model

canUpdate(lp: LpProblem) → bool

Whether actualResolve() may update lp.solverModel in place with applyChanges() instead of building it again.

configureSolver(lp: LpProblem) → None

Apply the solver options to lp.solverModel, again on every resolve so that options changed in between take effect.

findBestBound(lp: LpProblem) → float | None

The best bound the solver proved, in the problem’s sense, or None.

findSolutionValues(lp: LpProblem, result: Any = None) → tuple[const.LpSolveStatus, bool]

Write the solution back into lp.

Parameters:

result – what callSolver() returned

Returns:

(status, has_solution)

name = 'LpSolver_API'
class pulp.apis.LpSolver_CMD(path: str | None = None, keepFiles: bool = False, *args: Any, **kwargs: Any)

Bases: LpSolver

A generic command line LP Solver

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • options (list) – list of additional options to pass to solver (format depends on the solver)

  • timeLimit (float) – maximum time for solver (in seconds)

  • path (str) – a path to the solver binary

  • keepFiles (bool) – if True, files are saved in the current directory and not deleted after solving

  • args – parameters to pass to LpSolver

  • kwargs – parameters to pass to LpSolver

copy() → LpSolver_CMD

Make a copy of self

create_tmp_files(name: str, *args: str) → Iterator[str]
defaultPath() → str
delete_tmp_files(*args: str) → None
static executable(command: str) → str | None

Checks that the solver command is executable, And returns the actual path to it.

static executableExtension(name: str) → str
get_pipe() → Any
name = 'LpSolver_CMD'
setTmpDir() → None

Set the tmpDir attribute to a reasonnable location for a temporary directory

class pulp.apis.MIPCL_CMD(path: str | None = None, keepFiles: bool = False, mip: bool = True, msg: bool = True, options: list[str] | None = None, timeLimit: float | None = None)

Bases: LpSolver_CMD

The MIPCL_CMD solver

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • options (list) – list of additional options to pass to solver

  • keepFiles (bool) – if True, files are saved in the current directory and not deleted after solving

  • path (str) – path to the solver binary

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

available() → bool

True if the solver is available

defaultPath() → str
name = 'MIPCL_CMD'
static readsol(filename: str) → tuple[LpSolveStatus, dict[str, float], bool]

Read a MIPCL solution file.

Returns why MIPCL stopped, the variable values and whether it has a solution.

class pulp.apis.MOSEK(mip=True, msg=True, timeLimit: float | None = None, options: dict | None = None, task_file_name='', sol_type=None)

Bases: LpSolver_API

Mosek lp and mip solver (via Mosek Optimizer API).

Initializes the Mosek solver.

Keyword arguments:

@param mip: If False, then solve MIP as LP.

@param msg: Enable Mosek log output.

@param float timeLimit: maximum time for solver (in seconds)

@param options: Accepts a dictionary of Mosek solver parameters. Ignore to

use default parameter values. Eg: options = {mosek.dparam.mio_max_time:30} sets the maximum time spent by the Mixed Integer optimizer to 30 seconds. Equivalently, one could also write: options = {“MSK_DPAR_MIO_MAX_TIME”:30} which uses the generic parameter name as used within the solver, instead of using an object from the Mosek Optimizer API (Python), as before.

@param task_file_name: Writes a Mosek task file of the given name. By default,

no task file will be written. Eg: task_file_name = “eg1.opf”.

@param sol_type: Mosek supports three types of solutions: mosek.soltype.bas

(Basic solution, default), mosek.soltype.itr (Interior-point solution) and mosek.soltype.itg (Integer solution). Default None uses mosek.soltype.bas.

For a full list of Mosek parameters (for the Mosek Optimizer API) and supported task file formats, please see https://docs.mosek.com/9.1/pythonapi/parameters.html#doc-all-parameter-list.

available()

True if Mosek is available.

buildSolverModel(lp, inf=1e+20)

Translate the problem into a Mosek task object, in lp.solverModel.

callSolver(lp, *, changes=None, **kwargs)

Solves the Mosek task and returns its termination code.

configureSolver(lp)

Pass the solver parameters to the Mosek task lp.solverModel.

env: Any = <mosek.Env object>
findSolutionValues(lp, result=None)

Read the solution values and status from the Mosek task object. Note: Since the status map from mosek.solsta to LpStatus is not exact, it is recommended that one enables the log output and then refer to Mosek documentation for a better understanding of the solution (especially in the case of mip problems).

Parameters:

result – the termination code that callSolver() returned

name = 'MOSEK'
static putparam(task, par, val)

Pass the values of valid parameters to the Mosek task.

setOutStream(text)

Sets the log-output stream.

static termination_status(trmcode, default)

Why MOSEK stopped early, read off the termination code of optimize().

class pulp.apis.PYGLPK(mip=True, msg=True, timeLimit=None, gapRel=None, **solverParams)

Bases: LpSolver_API

The glpk LP/MIP solver (via its python interface)

Copyright Christophe-Marie Duquesne 2012

After calling solve, the model is in prob.solverModel. GLPK indices are 1-based: column j + 1 is the variable with id j and row i + 1 the constraint with id i.

Initializes the glpk solver.

@param mip: if False the solver will solve a MIP as an LP @param msg: displays information from the solver to stdout @param timeLimit: not handled @param gapRel: not handled @param solverParams: fields of GLPK’s simplex (glp_smcp) or MIP

(glp_iocp) control parameters, e.g. it_lim, meth or mip_gap

applyChanges(lp: LpProblem, changes: _rustcore.ModelChanges) → None

Update lp.solverModel with the edits made to lp since it was last solved (changes, from _take_changes()), keeping the basis.

Columns are variable ids and rows constraint ids, so new variables and constraints are appended in id order.

available()

True if the solver is available

buildSolverModel(lp)

Takes the pulp lp model and translates it into a glpk model.

Every variable is a column, used or not: column j + 1 is the variable with id j (as row i + 1 is the constraint with id i), so that a resolve only appends.

callSolver(lp, *, changes=None, **kwargs)

Solves the problem with glpk

Parameters:

changes – on a resolve, start from the basis the model holds instead of building an advanced one

canUpdate(lp)

Whether actualResolve() may update lp.solverModel in place with applyChanges() instead of building it again.

findSolutionValues(lp, result=None)

Write the solution back into lp.

Parameters:

result – what callSolver() returned

Returns:

(status, has_solution)

hasMIPConstraints(solverModel)
name = 'PYGLPK'
exception pulp.apis.PulpSolverError

Bases: PulpError

Pulp Solver-related exceptions

class pulp.apis.SAS94(mip=True, msg=True, keepFiles=False, warmStart=False, timeLimit=None, **solverParams)

Bases: SASsolver

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • keepFiles (bool) – if False, mps and mst files will not be saved

  • warmStart (bool) – if False, no warmstart or initial primal solution provided

  • solverParams – SAS proc OPTMILP or OPTLP parameters

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

available()

True if SAS94 is available.

name = 'SAS94'
class pulp.apis.SASCAS(mip=True, msg=True, keepFiles=False, warmStart=False, timeLimit=None, **solverParams)

Bases: SASsolver

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • keepFiles (bool) – if False, mps and mst files will not be saved

  • warmStart (bool) – if False, no warmstart or initial primal solution provided

  • solverParams – SAS proc OPTMILP or OPTLP parameters

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

available()

True if the solver is available

name = 'SASCAS'
class pulp.apis.SASsolver(mip=True, msg=True, warmStart=False, keepFiles=False, timeLimit=None, **solverParams)

Bases: LpSolver_CMD

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • warmStart (bool) – if False, no warm start

  • keepFiles (bool) – if False, the generated mps mst files will be removed

  • solverParams – SAS proc OPTMILP or OPTLP parameters

defaultPath()
name = 'SASsolver'
pulp.apis.SCIP

alias of SCIP_CMD

class pulp.apis.SCIP_CMD(path=None, mip=True, keepFiles=False, msg=True, options=None, timeLimit=None, gapRel=None, gapAbs=None, maxNodes=None, logPath=None, threads=None, duals=False)

Bases: LpSolver_CMD

The SCIP optimization solver

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • options (list) – list of additional options to pass to solver

  • keepFiles (bool) – if True, files are saved in the current directory and not deleted after solving

  • path (str) – path to the solver binary

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • gapAbs (float) – absolute gap tolerance for the solver to stop

  • maxNodes (int) – max number of nodes during branching. Stops the solving when reached.

  • threads (int) – sets the maximum number of threads

  • logPath (str) – path to the log file

  • duals (bool) – if True and the problem is a pure LP, disable presolving and propagation so that dual values and reduced costs can be retrieved

SCIP_STATUSES = {'gap limit reached': LpSolveStatus.GapLimit, 'infeasible': LpSolveStatus.Infeasible, 'infeasible or unbounded': LpSolveStatus.Undefined, 'memory limit reached': LpSolveStatus.MemoryLimit, 'node limit reached': LpSolveStatus.NodeLimit, 'optimal solution found': LpSolveStatus.Optimal, 'restart limit reached': LpSolveStatus.Stopped, 'solution improvement limit reached': LpSolveStatus.SolutionLimit, 'solution limit reached': LpSolveStatus.SolutionLimit, 'stall node limit reached': LpSolveStatus.NodeLimit, 'time limit reached': LpSolveStatus.TimeLimit, 'total node limit reached': LpSolveStatus.NodeLimit, 'unbounded': LpSolveStatus.Unbounded, 'unknown': LpSolveStatus.Undefined, 'user interrupt': LpSolveStatus.Interrupted}
actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

available()

True if the solver is available

defaultPath()
name = 'SCIP_CMD'
static readduals(logFile, solFile)

Read the output of display dualsolution from a SCIP log file.

The duals are printed right after the solution file is written. Returns a dict of non-zero duals by constraint name (SCIP omits the zero ones).

static readsol(filename)

Read a SCIP solution file.

Returns why SCIP stopped, the variable values and whether it has a solution.

class pulp.apis.SCIP_PY(mip=True, msg=True, options=None, timeLimit=None, gapRel=None, gapAbs=None, maxNodes=None, logPath=None, threads=None, warmStart=False, duals=False)

Bases: LpSolver_API

The SCIP Optimization Suite (via its python interface)

After calling solve, the model is in problem.solverModel. Its variables, by index, follow problem.exported_variables() and its original constraints follow problem.constraints().

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • options (list) – list of additional options to pass to solver

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • gapAbs (float) – absolute gap tolerance for the solver to stop

  • maxNodes (int) – max number of nodes during branching. Stops the solving when reached.

  • logPath (str) – path to the log file

  • threads (int) – sets the maximum number of threads

  • warmStart (bool) – if True, the solver will use the current value of variables as a start

  • duals (bool) – if True and the problem is a pure LP, disable presolving and propagation so that dual values and reduced costs can be retrieved

available()

True if the solver is available

buildSolverModel(lp)

Takes the pulp lp model and translates it into a scip model

callSolver(lp, *, changes=None, **kwargs)

Solves the problem with scip

configureSolver(lp)

Apply the solver options to lp.solverModel

findSolutionValues(lp, result=None)

Write the solution back into lp.

Parameters:

result – what callSolver() returned

Returns:

(status, has_solution)

name = 'SCIP_PY'
class pulp.apis.XPRESS(mip=True, msg=True, timeLimit=None, gapRel=None, options=None, keepFiles=False, path=None, heurFreq=None, heurStra=None, coverCuts=None, preSolve=None, warmStart=False)

Bases: LpSolver_CMD

The XPRESS LP solver that uses the XPRESS command line tool in a subprocess

Initializes the Xpress solver.

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • heurFreq – the frequency at which heuristics are used in the tree search

  • heurStra – heuristic strategy

  • coverCuts – the number of rounds of lifted cover inequalities at the top node

  • preSolve – whether presolving should be performed before the main algorithm

  • options – Adding more options, e.g. options = [“NODESELECTION=1”, “HEURDEPTH=5”] More about Xpress options and control parameters please see https://www.fico.com/fico-xpress-optimization/docs/latest/solver/optimizer/HTML/chapter7.html

  • warmStart (bool) – if True, then use current variable values as start

actualSolve(lp: LpProblem, **kwargs: Any) → LpSolveStats

Solve a well formulated lp problem.

available()

True if the solver is available

defaultPath()
name = 'XPRESS'
static quote_path(path)

Quotes a path for the Xpress optimizer console, by wrapping it in double quotes and escaping the following characters, which would otherwise be interpreted by the Tcl shell: $ “ [

static readsol(filename, attrfile)

Read an XPRESS solution file

writeslxsol(name, *values)

Write a solution file in SLX format. The function can write multiple solutions to the same file, each solution must be passed as a list of (name,value) pairs. Solutions are written in the order specified and are given names “solutionN” where N is the index of the solution in the list.

Parameters:
  • name (string) – file name

  • values (list) – list of lists of (name,value) pairs

pulp.apis.XPRESS_CMD

alias of XPRESS

class pulp.apis.XPRESS_PY(mip=True, msg=True, timeLimit=None, gapRel=None, heurFreq=None, heurStra=None, coverCuts=None, preSolve=None, warmStart=None, export=None, options=None)

Bases: LpSolver_API

The XPRESS LP solver that uses XPRESS Python API

Initializes the Xpress solver.

Parameters:
  • mip (bool) – if False, assume LP even if integer variables

  • msg (bool) – if False, no log is shown

  • timeLimit (float) – maximum time for solver (in seconds)

  • gapRel (float) – relative gap tolerance for the solver to stop (in fraction)

  • heurFreq – the frequency at which heuristics are used in the tree search

  • heurStra – heuristic strategy

  • coverCuts – the number of rounds of lifted cover inequalities at the top node

  • preSolve – whether presolving should be performed before the main algorithm

  • warmStart (bool) – if set then use current variable values as warm start

  • export (string) – if set then the model will be exported to this file before solving

  • options – Adding more options. This is a list the elements of which are either (name,value) pairs or strings “name=value”. More about Xpress options and control parameters please see https://www.fico.com/fico-xpress-optimization/docs/latest/solver/optimizer/HTML/chapter7.html

applyChanges(lp: LpProblem, changes: _rustcore.ModelChanges) → None

Update lp.solverModel with the edits made to lp since it was last solved (changes, from _take_changes()), keeping the basis.

Columns are variable ids and rows constraint ids, so new variables and constraints are appended in id order.

available()

True if the solver is available

buildSolverModel(lp)

Takes the pulp lp model and translates it into an xpress model

callSolver(lp, *, changes=None, **kwargs)

Run the low-level XPRESS solve (used from actualSolve()).

Parameters:

kwargs – an optional prepare, a function that is called with lp as argument and allows final tweaks to lp.solverModel before the low level solve is started.

canUpdate(lp: LpProblem) → bool

Whether actualResolve() may update lp.solverModel in place with applyChanges() instead of building it again.

configureSolver(lp: LpProblem) → None

Apply the controls of this solver to lp.solverModel, again on every resolve so that controls changed in between take effect.

findSolutionValues(lp, result=None)

Write the solution back into lp.

Parameters:

result – what callSolver() returned

Returns:

(status, has_solution)

getAttribute(lp, which)

Get an arbitrary attribute for the model that was previously solved using actualSolve().

name = 'XPRESS_PY'
class pulp.apis.YAPOSIB(mip=True, msg=True, timeLimit=None, epgap=None, solverName=None, **solverParams)

Bases: LpSolver_API

COIN OSI (via its python interface)

Copyright Christophe-Marie Duquesne 2012

The yaposib variables are available (after a solve) in var.solverVar The yaposib constraints are available in constraint.solverConstraint The Model is in prob.solverModel

Initializes the yaposib solver.

@param mip: if False the solver will solve a MIP as

an LP

@param msg: displays information from the solver to

stdout

@param timeLimit: not supported @param epgap: not supported @param solverParams: not supported

available()

True if the solver is available

buildSolverModel(lp)

Takes the pulp lp model and translates it into a yaposib model

callSolver(lp, *, changes=None, **kwargs)

Solves the problem with yaposib

findSolutionValues(lp, result=None)

Write the solution back into lp.

Parameters:

result – what callSolver() returned

Returns:

(status, has_solution)

name = 'YAPOSIB'
pulp.apis.getSolver(solver: str, *args, **kwargs) → LpSolver

Instantiates a solver from its name

Parameters:
  • solver (str) – solver name to create

  • args – additional arguments to the solver

  • kwargs – additional keyword arguments to the solver

Returns:

solver of type LpSolver

pulp.apis.getSolverFromDict(data: dict[str, str | bool | float | int]) → LpSolver

Instantiates a solver from a dictionary with its data

Parameters:

data (dict) – a dictionary with, at least an “solver” key with the name of the solver to create

Returns:

a solver of type LpSolver

Raises:

PulpSolverError – if the dictionary does not have the “solver” key

Return type:

LpSolver

pulp.apis.getSolverFromJson(filename: str) → LpSolver

Instantiates a solver from a json file with its data

Parameters:

filename (str) – name of the json file to read

Returns:

a solver of type LpSolver

Return type:

LpSolver

pulp.apis.listSolvers(onlyAvailable: bool = False) → list[str]

List the names of all the existing solvers in PuLP

Parameters:

onlyAvailable (bool) – if True, only show the available solvers

Returns:

list of solver names

Return type:

list