pulp.apis Interface to Solvers
- class pulp.apis.CHOCO_CMD(path=None, keepFiles=False, mip=True, msg=True, options=None, timeLimit=None)
Bases:
LpSolver_CMDThe 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
- available()
True if the solver is available
- defaultPath()
- name = 'CHOCO_CMD'
- static readsol(filename)
Read a Choco solution file
- 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:
LpSolverThe 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
- classmethod available()
True if the solver is available
- 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)
Bases:
LpSolver_CMDCOIN-OR CBC invoked as a command-line executable.
The default binary is resolved from the optional
cbcboxpackage (installpulp[cbc]) when present, otherwise fromcbc/cbc.exeonPATH. Passpath=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.
- available()
True if the solver is available
- copy()
Make a copy of self
- defaultPath()
- getOptions()
- get_status(filename)
- name = 'COIN_CMD'
- readsol_LP(filename: str, lp: LpProblem) tuple[int, dict[str, float], dict[str, float], dict[str, float], dict[str, float], int]
Read a CBC solution file generated from an lp (good names). Returns status, values, reducedCosts, shadowPrices, slacks, sol_status.
- readsol_MPS(filename: str, lp: LpProblem, variableNames: list[str], constraintNames: list[str], objectiveName: str | None = None) tuple[int, dict[str, float], dict[str, float], dict[str, float], dict[str, float], int]
Read a CBC solution file generated from an mps or lp file (possible different names). variableNames and constraintNames are lists in the same order as lp.variables() and lp.constraints().
- 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 and constraintNames are lists in the same order as lp.variables() and lp.constraints(). Returns True on success.
- class pulp.apis.COPT(mip=True, msg=True, timeLimit=None, gapRel=None, warmStart=False, logPath=None, **solverParams)
Bases:
LpSolverThe 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
- actualSolve(lp: LpProblem, **kwargs: Any) int
Solve a well formulated lp problem
creates a COPT model, variables and constraints and attaches them to the lp model which it then solves
- available()
True if the solver is available
- buildSolverModel(lp)
Takes the pulp lp model and translates it into a COPT model
- callSolver(lp, callback=None)
Solves the problem with COPT
- findSolutionValues(lp)
- 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_CMDThe COPT command-line solver
Initialize command-line solver
- actualSolve(lp: LpProblem, **kwargs: Any) int
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:
LpSolverThe COPT dynamic library solver
- Parameters:
- 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'
- 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_CMDThe 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.
- 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:
LpSolverThe 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)
- actualSolve(*args, **kwargs)
Solve a well formulated lp problem
- available()
True if the solver is available
- buildSolverModel(*args, **kwargs)
- callSolver(lp: LpProblem, callback: Iterable[type[cplex_t.callbacks.Callback]] | None = None)
Solves the problem with cplex
- Parameters:
callback – Optional list of CPLEX callback classes to register during solve
- changeEpgap(epgap=0.0001)
Change cplex solver integer bound gap tolerence
- findSolutionValues(*args, **kwargs)
- 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.
- 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
- setlogfile(fileobj)
sets the logfile for cplex output
- class pulp.apis.CUOPT(mip: bool = True, msg: bool = True, options: list[str] | None = None, timeLimit: float | None = None, *args: Any, **kwargs: Any)
Bases:
LpSolverThe CUOPT Optimizer via its python interface
- Parameters:
- available()
True if the solver is available
- name = 'CUOPT'
- class pulp.apis.CYLP(mip: bool = True, msg: bool = True, options: list[str] | None = None, timeLimit: float | None = None, *args: Any, **kwargs: Any)
Bases:
LpSolver- Parameters:
- available()
True if the solver is available
- name = 'CyLP'
- 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_CMDThe 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': 1, 'No Solution': 0}
- NO_SOLUTION_STATUSES = {-2, -1, 0}
- available()
True if the solver is available
- defaultPath()
- name = 'FSCIP_CMD'
- static readsol(filename)
Read a FSCIP solution file
- class pulp.apis.GLPK_CMD(path=None, keepFiles=False, mip=True, msg=True, options=None, timeLimit=None)
Bases:
LpSolver_CMDThe 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
- 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, warmStart=False, logPath=None, env=None, envOptions=None, manageEnv=False, **solverParams)
Bases:
LpSolverThe 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)
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
manageEnvis set to True, theGUROBIobject 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=Trueis required when setting license or connection parameters. TheenvOptionsargument 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.Envobject. 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
manageEnvis set to False (the default), theGUROBIobject 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
- actualSolve(lp: LpProblem, **kwargs: Any) int
Solve a well formulated lp problem
creates a gurobi model, variables and constraints and attaches them to the lp model which it then solves
- available()
True if the solver is available
- buildSolverModel(lp)
Takes the pulp lp model and translates it into a gurobi model
- callSolver(lp, callback=None)
Solves the problem with gurobi
- close()
Must be called when internal Gurobi model and/or environment requires disposing. The environment (default or otherwise) will be disposed only if
manageEnvis set to True.
- env = None
- findSolutionValues(lp, var_handles, constr_handles)
- 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_CMDThe 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
- 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, callbacksToActivate: list[HighsCallbackType] | None = None, **solverParams)
Bases:
LpSolver- 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
timeLimit (float) – maximum time for solver (in seconds)
solverParams (dict) – list of named options to pass directly to the HiGHS solver
callbacksToActivate – list of callback types to start
- available()
True if the solver is available
- buildSolverModel(lp)
- callSolver(lp)
- createAndConfigureSolver(lp)
- findSolutionValues(lp)
- 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_CMDThe 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
- available()
True if the solver is available
- defaultPath()
- 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:
objectA generic LP Solver
- Parameters:
- 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
- name = 'LpSolver'
- class pulp.apis.LpSolver_CMD(path: str | None = None, keepFiles: bool = False, *args: Any, **kwargs: Any)
Bases:
LpSolverA 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
LpSolverkwargs – parameters to pass to
LpSolver
- copy() LpSolver_CMD
Make a copy of self
- static executable(command: str) str | None
Checks that the solver command is executable, And returns the actual path to it.
- name = 'LpSolver_CMD'
- 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_CMDThe 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
- name = 'MIPCL_CMD'
- class pulp.apis.MOSEK(mip=True, msg=True, timeLimit: float | None = None, options: dict | None = None, task_file_name='', sol_type=bas)
Bases:
LpSolverMosek 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).
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.
- env = <mosek.Env object>
- findSolutionValues(lp)
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).
- name = 'MOSEK'
- putparam(par, val)
Pass the values of valid parameters to Mosek.
- setOutStream(text)
Sets the log-output stream.
- class pulp.apis.PYGLPK(mip: bool = True, msg: bool = True, options: list[str] | None = None, timeLimit: float | None = None, *args: Any, **kwargs: Any)
Bases:
LpSolverThe glpk LP/MIP solver (via its python interface)
Copyright Christophe-Marie Duquesne 2012
After calling solve, the model is in prob.solverModel. GLPK 1-based column/row indices are kept on the solver as
_var_handles/_constr_handles, indexed byvar.idandconstraint.id.- Parameters:
- available()
True if the solver is available
- name = 'PYGLPK'
- class pulp.apis.SAS94(mip=True, msg=True, warmStart=False, keepFiles=False, timeLimit=None, **solverParams)
Bases:
SASsolver- Parameters:
- available()
True if SAS94 is available.
- name = 'SAS94'
- class pulp.apis.SASCAS(mip=True, msg=True, warmStart=False, keepFiles=False, timeLimit=None, **solverParams)
Bases:
SASsolver- Parameters:
- available()
True if SASCAS is available.
- name = 'SASCAS'
- class pulp.apis.SASsolver(mip=True, msg=True, warmStart=False, keepFiles=False, timeLimit=None, **solverParams)
Bases:
LpSolver_CMD- Parameters:
- defaultPath()
- name = 'SASsolver'
- 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)
Bases:
LpSolver_CMDThe 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
- NO_SOLUTION_STATUSES = {-2, -1, 0}
- SCIP_STATUSES = {'gap limit reached': 1, '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}
- available()
True if the solver is available
- defaultPath()
- name = 'SCIP_CMD'
- static readsol(filename)
Read a SCIP solution file
- 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)
Bases:
LpSolverThe SCIP Optimization Suite (via its python interface)
After calling solve, the model is in
problem.solverModel. PySCIPOpt variable and constraint objects returned frombuildSolverModel()are indexed byvar.idandconstraint.idwhen reading the solution infindSolutionValues().- 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
- actualSolve(lp: LpProblem, **kwargs: Any) int
Solve a well formulated lp problem
creates a scip model, variables and constraints and attaches them to the lp model which it then solves
- available()
True if the solver is available
- buildSolverModel(lp)
Takes the pulp lp model and translates it into a scip model
- callSolver(lp)
Solves the problem with scip
- findSolutionValues(lp, var_handles, constr_handles)
- 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_CMDThe 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
- 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
- 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:
LpSolverThe 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
- available()
True if the solver is available
- buildSolverModel(lp)
Takes the pulp lp model and translates it into an xpress model
- callSolver(lp, prepare=None)
Run the low-level XPRESS solve (used from
actualSolve()).- Parameters:
prepare – a function that is called with lp as argument and allows final tweaks to lp.solverModel before the low level solve is started.
- findSolutionValues(lp)
- getAttribute(lp, which)
Get an arbitrary attribute for the model that was previously solved using actualSolve().
- name = 'XPRESS_PY'
- class pulp.apis.YAPOSIB(mip: bool = True, msg: bool = True, options: list[str] | None = None, timeLimit: float | None = None, *args: Any, **kwargs: Any)
Bases:
LpSolverCOIN 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
- Parameters:
- available()
True if the solver is available
- name = 'YAPOSIB'
- 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: