pulp.apis
Interface to Solvers¶

class
pulp.apis.
CHOCO_CMD
(path=None, keepFiles=False, mip=True, msg=True, options=None, timeLimit=None)¶ Bases:
pulp.apis.core.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)¶ 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

pulp.apis.
COIN
¶ alias of
pulp.apis.coin_api.COIN_CMD

class
pulp.apis.
COINMP_DLL
(mip=True, msg=True, options=None, timeLimit=None, *args, **kwargs)¶ Bases:
pulp.apis.core.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=””,

actualSolve
(lp)¶ Solve a well formulated lp problem

classmethod
available
()¶ True if the solver is available

name
= 'COINMP_DLL'¶

pulp.apis.
COINMP_DLL_load_dll
(path)¶ function that loads the DLL useful for debugging installation problems

class
pulp.apis.
COIN_CMD
(mip=True, msg=True, timeLimit=None, fracGap=None, maxSeconds=None, gapRel=None, gapAbs=None, presolve=None, cuts=None, strong=None, options=None, warmStart=False, keepFiles=False, path=None, threads=None, logPath=None, mip_start=False)¶ Bases:
pulp.apis.core.LpSolver_CMD
The COIN CLP/CBC LP solver now only uses cbc
 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
cuts (bool) – if True, adds gomory on knapsack on probing on
strong (bool) – if True, adds strong
fracGap (float) – deprecated for gapRel
maxSeconds (float) – deprecated for timeLimit
mip_start (bool) – deprecated for warmStart

actualSolve
(lp, **kwargs)¶ Solve a well formulated lp problem

available
()¶ True if the solver is available

copy
()¶ Make a copy of self

defaultPath
()¶

getOptions
()¶

get_status
(filename)¶

name
= 'COIN_CMD'¶

readsol_LP
(filename, lp, vs)¶ Read a CBC solution file generated from an lp (good names) returns status, values, reducedCosts, shadowPrices, slacks, sol_status

readsol_MPS
(filename, lp, vs, variablesNames, constraintsNames, objectiveName=None)¶ Read a CBC solution file generated from an mps or lp file (possible different names)

solve_CBC
(lp, use_mps=True)¶ Solve a MIP problem using CBC

writesol
(filename, lp, vs, variablesNames, constraintsNames)¶ Writes a CBC solution file generated from an mps / lp file (possible different names) returns True on success

pulp.apis.
CPLEX
¶ alias of
pulp.apis.cplex_api.CPLEX_CMD

class
pulp.apis.
CPLEX_CMD
(timelimit=None, 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, mip_start=False)¶ Bases:
pulp.apis.core.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.
mip_start (bool) – deprecated for warmStart
timelimit (float) – deprecated for timeLimit

actualSolve
(lp)¶ Solve a well formulated lp problem

available
()¶ True if the solver is available

defaultPath
()¶

getOptions
()¶

name
= 'CPLEX_CMD'¶

readsol
(filename)¶ Read a CPLEX solution file

writesol
(filename, vs)¶ Writes a CPLEX solution file

class
pulp.apis.
CPLEX_DLL
(mip=True, msg=True, options=None, timeLimit=None, *args, **kwargs)¶ Bases:
pulp.apis.core.LpSolver
The CPLEX LP/MIP solver (via a Dynamic library DLL  windows or SO  Linux)
This solver wraps the c library api of cplex. It has been tested against cplex 11. For api functions that have not been wrapped in this solver please use the ctypes library interface to the cplex api in CPLEX_DLL.lib
 Parameters

actualSolve
(lp)¶ Solve a well formulated lp problem

available
()¶ True if the solver is available

err
= OSError('We did not find the cplex library, be sure to add it to LD_LIBRARY_PATH')¶

pulp.apis.
CPLEX_DLL_load_dll
(path)¶ function that loads the DLL useful for debugging installation problems

pulp.apis.
CPLEX_DLL_unload_dll
(lib)¶

class
pulp.apis.
CPLEX_PY
(mip=True, msg=True, options=None, timeLimit=None, *args, **kwargs)¶ Bases:
pulp.apis.core.LpSolver
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

actualSolve
(lp)¶ Solve a well formulated lp problem

available
()¶ True if the solver is available

err
= ModuleNotFoundError("No module named 'cplex'")¶

name
= 'CPLEX_PY'¶

pulp.apis.
GLPK
¶ alias of
pulp.apis.glpk_api.GLPK_CMD

class
pulp.apis.
GLPK_CMD
(path=None, keepFiles=False, mip=True, msg=True, options=None, timeLimit=None)¶ Bases:
pulp.apis.core.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)¶ Solve a well formulated lp problem

available
()¶ True if the solver is available

defaultPath
()¶

name
= 'GLPK_CMD'¶

readsol
(filename)¶ Read a GLPK solution file

class
pulp.apis.
GUROBI
(mip=True, msg=True, options=None, timeLimit=None, *args, **kwargs)¶ Bases:
pulp.apis.core.LpSolver
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

actualSolve
(lp, callback=None)¶ Solve a well formulated lp problem

available
()¶ True if the solver is available

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:
pulp.apis.core.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
mip_start (bool) – deprecated for warmStart

actualSolve
(lp)¶ 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.
LpSolver
(mip=True, msg=True, options=None, timeLimit=None, *args, **kwargs)¶ Bases:
object
A generic LP Solver
 Parameters

actualResolve
(lp, **kwargs)¶ uses existing problem information and solves the problem If it is not implelemented in the solver just solve again

actualSolve
(lp)¶ Solve a well formulated lp problem

available
()¶ True if the solver is available

copy
()¶ Make a copy of self

getCplexStyleArrays
(lp, senseDict=None, LpVarCategories=None, LpObjSenses=None, infBound=1e+20)¶ returns the arrays suitable to pass to a cdll Cplex or other solvers that are similar
Copyright (c) Stuart Mitchell 2007

name
= 'LpSolver'¶

solve
(lp)¶ Solve the problem lp

toDict
()¶

toJson
(filename, *args, **kwargs)¶

to_dict
()¶

to_json
(filename, *args, **kwargs)¶

class
pulp.apis.
LpSolver_CMD
(path=None, keepFiles=False, *args, **kwargs)¶ Bases:
pulp.apis.core.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
()¶ Make a copy of self

create_tmp_files
(name, *args)¶

defaultPath
()¶

delete_tmp_files
(*args)¶

static
executable
(command)¶ Checks that the solver command is executable, And returns the actual path to it.

static
executableExtension
(name)¶

name
= 'LpSolver_CMD'¶

setTmpDir
()¶ Set the tmpDir attribute to a reasonnable location for a temporary directory

class
pulp.apis.
MIPCL_CMD
(path=None, keepFiles=False, mip=True, msg=True, options=None, timeLimit=None)¶ Bases:
pulp.apis.core.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)¶ Solve a well formulated lp problem

available
()¶ True if the solver is available

defaultPath
()¶

name
= 'MIPCL_CMD'¶

static
readsol
(filename)¶ Read a MIPCL solution file

class
pulp.apis.
MOSEK
(mip=True, msg=True, options=None, timeLimit=None, *args, **kwargs)¶ Bases:
pulp.apis.core.LpSolver
Mosek lp and mip solver (via Mosek Optimizer API).
 Parameters

actualSolve
(lp, callback=None)¶ Solves a wellformulated lp problem.

available
()¶ True if Mosek is available.

name
= 'MOSEK'¶

class
pulp.apis.
PULP_CBC_CMD
(mip=True, msg=True, timeLimit=None, fracGap=None, maxSeconds=None, gapRel=None, gapAbs=None, presolve=None, cuts=None, strong=None, options=None, warmStart=False, keepFiles=False, path=None, threads=None, logPath=None, mip_start=False)¶ Bases:
pulp.apis.coin_api.COIN_CMD
This solver uses a precompiled version of cbc provided with the package
 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
cuts (bool) – if True, adds gomory on knapsack on probing on
strong (bool) – if True, adds strong
fracGap (float) – deprecated for gapRel
maxSeconds (float) – deprecated for timeLimit
mip_start (bool) – deprecated for warmStart

name
= 'PULP_CBC_CMD'¶

pulp_cbc_path
= '/home/runner/work/pulp/pulp/pulp/apis/../solverdir/cbc/linux/64/cbc'¶

class
pulp.apis.
PULP_CHOCO_CMD
(path=None, keepFiles=0, mip=True, msg=True, options=None, timeLimit=None)¶ Bases:
pulp.apis.choco_api.CHOCO_CMD
This solver uses a packaged version of choco provided with the package
 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

name
= 'PULP_CHOCO_CMD'¶

pulp_choco_path
= '/home/runner/work/pulp/pulp/pulp/apis/../solverdir/choco/chocoparserswithdependencies.jar'¶

class
pulp.apis.
PYGLPK
(mip=True, msg=True, options=None, timeLimit=None, *args, **kwargs)¶ Bases:
pulp.apis.core.LpSolver
The glpk LP/MIP solver (via its python interface)
Copyright ChristopheMarie Duquesne 2012
The glpk variables are available (after a solve) in var.solverVar The glpk constraints are available in constraint.solverConstraint The Model is in prob.solverModel
 Parameters

actualSolve
(lp, callback=None)¶ Solve a well formulated lp problem

available
()¶ True if the solver is available

name
= 'PYGLPK'¶

pulp.apis.
Parser
¶ alias of
configparser.ConfigParser

exception
pulp.apis.
PulpSolverError
¶ Bases:
pulp.constants.PulpError
Pulp Solverrelated exceptions

pulp.apis.
SCIP
¶ alias of
pulp.apis.scip_api.SCIP_CMD

class
pulp.apis.
SCIP_CMD
(path=None, keepFiles=False, mip=True, msg=True, options=None, timeLimit=None, maxNodes=None)¶ Bases:
pulp.apis.core.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)
maxNodes (int) – max number of nodes during branching. Stops the solving when reached.

NO_SOLUTION_STATUSES
= {2, 1, 0}¶

SCIP_STATUSES
= {'gap limit reached': 0, 'infeasible': 1, 'infeasible or unbounded': 0, 'memory limit reached': 0, 'node limit reached': 0, 'optimal solution found': 1, 'restart limit reached': 0, 'solution improvement limit reached': 0, 'solution limit reached': 0, 'stall node limit reached': 0, 'time limit reached': 0, 'total node limit reached': 0, 'unbounded': 2, 'unknown': 3, 'user interrupt': 0}¶

actualSolve
(lp)¶ Solve a well formulated lp problem

available
()¶ True if the solver is available

defaultPath
()¶

static
firstWithFilenoSupport
(*streams)¶

name
= 'SCIP_CMD'¶

static
readsol
(filename)¶ Read a SCIP solution file

class
pulp.apis.
XPRESS
(mip=True, msg=True, timeLimit=None, gapRel=None, options=None, keepFiles=False, path=None, maxSeconds=None, targetGap=None, heurFreq=None, heurStra=None, coverCuts=None, preSolve=None)¶ Bases:
pulp.apis.core.LpSolver_CMD
The XPRESS LP solver
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)
maxSeconds – deprecated for timeLimit
targetGap – deprecated for gapRel
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 http://tomopt.com/docs/xpress/tomlab_xpress008.php

actualSolve
(lp)¶ Solve a well formulated lp problem

available
()¶ True if the solver is available

defaultPath
()¶

name
= 'XPRESS'¶

static
readsol
(filename)¶ Read an XPRESS solution file

class
pulp.apis.
YAPOSIB
(mip=True, msg=True, options=None, timeLimit=None, *args, **kwargs)¶ Bases:
pulp.apis.core.LpSolver
COIN OSI (via its python interface)
Copyright ChristopheMarie 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
 Parameters

actualSolve
(lp, callback=None)¶ Solve a well formulated lp problem

available
()¶ True if the solver is available

name
= 'YAPOSIB'¶

pulp.apis.
clock
()¶ process_time() > float
Process time for profiling: sum of the kernel and userspace CPU time.

pulp.apis.
configSolvers
()¶ Configure the path the the solvers on the command line
Designed to configure the file locations of the solvers from the command line after installation

pulp.apis.
ctypesArrayFill
(myList, type=<class 'ctypes.c_double'>)¶ Creates a c array with ctypes from a python list type is the type of the c array

pulp.apis.
findCPLEX_DLL
()¶

pulp.apis.
getSolver
(solver, *args, **kwargs)¶ Instantiates a solver from its name

pulp.apis.
getSolverFromDict
(data)¶ 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

pulp.apis.
getSolverFromJson
(filename)¶ Instantiates a solver from a json file with its data

pulp.apis.
get_solver
(solver, *args, **kwargs)¶ Instantiates a solver from its name

pulp.apis.
get_solver_from_dict
(data)¶ 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

pulp.apis.
get_solver_from_json
(filename)¶ Instantiates a solver from a json file with its data

pulp.apis.
initialize
(filename, operating_system='linux', arch='64')¶ reads the configuration file to initialise the module

pulp.apis.
listSolvers
(onlyAvailable=False)¶ List the names of all the existing solvers in PuLP

pulp.apis.
list_solvers
(onlyAvailable=False)¶ List the names of all the existing solvers in PuLP

pulp.apis.
mktemp
(suffix='', prefix='tmp', dir=None)¶ Usercallable function to return a unique temporary file name. The file is not created.
Arguments are similar to mkstemp, except that the ‘text’ argument is not accepted, and suffix=None, prefix=None and bytes file names are not supported.
THIS FUNCTION IS UNSAFE AND SHOULD NOT BE USED. The file name may refer to a file that did not exist at some point, but by the time you get around to creating it, someone else may have beaten you to the punch.

pulp.apis.
setConfigInformation
(**keywords)¶ set the data in the configuration file at the moment will only edit things in [locations] the keyword value pairs come from the keywords dictionary

pulp.apis.
to_string
(_obj)¶

pulp.apis.
uuid4
()¶ Generate a random UUID.