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.CLARABEL(mip=True, msg=True, timeLimit=None, threads=None, logPath=None, **solverParams)
Bases:
LpSolver_APIThe 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
DefaultSolveris available (after a solve) inprob.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'xsubject toAx + s = b, withsin 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
callbackgiven to solve (called with Clarabel’sDefaultInfoon every iteration) returns True; returns theDefaultSolution.
- findSolutionValues(lp: LpProblem, result: Any = None) tuple[constants.LpSolveStatus, bool]
- Parameters:
result – the
DefaultSolutionthatcallSolver()returned
- logPathSilencesMsg: bool = True
True when handing the solver a
logPathsends its output to the file instead of the console, socapture_log()has to echo the log back afterwards to keepmsg=Truebehaving 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:
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, randomSeed=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.
randomSeed (int) – random seed passed to CBC (
-randomSeed) for reproducible results
- 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
logPathsends its output to the file instead of the console, socapture_log()has to echo the log back afterwards to keepmsg=Truebehaving 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).
variableNamesare names as they appear in the solution file (column order). Whenrename=TrueonwriteMPS, passpulp_names_in_column_orderfromwriteMPSso 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.
- class pulp.apis.COPT(mip=True, msg=True, timeLimit=None, gapRel=None, warmStart=False, logPath=None, **solverParams)
Bases:
LpSolver_APIThe 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.solverModelwith the edits made tolpsince 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
callbackgiven to solve
- canUpdate(lp)
Whether
actualResolve()may updatelp.solverModelin place withapplyChanges()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_CMDThe 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:
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:
LpSolver_APIThe 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.solverModelwith the edits made since the last solve and solve it again from its current basis; build it from scratch if it cannot be updated (seecanUpdate()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.solverModelwith the edits made tolpsince 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 updatelp.solverModelin place withapplyChanges()instead of building it again.
- changeEpgap(epgap=0.0001)
Change cplex solver integer bound gap tolerence
- closeLogFile()
Detaches cplex from the
logPathfile 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
logPathsends its output to the file instead of the console, socapture_log()has to echo the log back afterwards to keepmsg=Truebehaving 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
- 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_APIThe 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) –
threadsor additional parameters forCpSolver.parameters
- buildSolverModel(lp: LpProblem) None
Takes the pulp lp model and translates it into a CP-SAT model.
The CP-SAT variable with index
jislp.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)thatcallSolver()returned
- name = 'CPSAT'
- class pulp.apis.CUOPT(mip=True, msg=True, timeLimit=None, gapRel=None, warmStart=False, logPath=None, **solverParams)
Bases:
LpSolver_APIThe 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_APIThe 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
CyCbcModelwhen the problem was solved as a MIP, aCyClpSimplexotherwise.- 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) orallowableGap(Cbc);resolveMethod("primal"or"dual") forces Clp’s simplex on a resolve, chosen from the changes otherwise;perturbationis Clp’s (setPerturbation, e.g. 50: always perturb), on every solve
- applyChanges(lp: LpProblem, changes: _rustcore.ModelChanges) None
Update the Clp model
lp.solverModelwith the edits made tolpsince 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_variablesincluded) 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
- 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
logPathsends its output to the file instead of the console, socapture_log()has to echo the log back afterwards to keepmsg=Truebehaving as the caller expects.
- 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': LpSolveStatus.Optimal, 'No Solution': LpSolveStatus.NotSolved}
- NO_SOLUTION_STATUSES = {LpSolveStatus.Unbounded, LpSolveStatus.Infeasible, LpSolveStatus.NotSolved}
- available()
True if the solver is available
- defaultPath()
- name = 'FSCIP_CMD'
- static parse_status(string: str) LpSolveStatus | 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_APIThe 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.solverModelis aGlopModel: 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.resolveto restart from the previous basisinterrupter – an
ortools.util.python.solve_interrupter.SolveInterrupter; calling itsinterrupt()(e.g. from another thread or from thecallbackgiven to solve) stops the solvesolverParams (dict) – fields of MathOpt’s
SolveParameters(e.g.iteration_limit,presolve=False,lp_algorithm="dual_simplex") or ofGlopParameters(e.g.use_dual_simplex,primal_feasibility_tolerance)
- applyChanges(lp: LpProblem, changes: _rustcore.ModelChanges) None
Update
lp.solverModelwith the edits made tolpsince 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.
- 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
callbackgiven 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 updatelp.solverModelin place withapplyChanges()instead of building it again.
- configureSolver(lp: LpProblem) None
Set the
SolveParametersoflp.solverModelfrom 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'
- 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, gapAbs=None, warmStart=False, logPath=None, env=None, envOptions=None, manageEnv=False, **solverParams)
Bases:
LpSolver_APIThe 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
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
- applyChanges(lp: LpProblem, changes: _rustcore.ModelChanges) None
Update
lp.solverModelwith the edits made tolpsince 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
- callSolver(lp, *, changes=None, **kwargs)
Solves the problem with gurobi, with the
callbackgiven to solve
- canUpdate(lp: LpProblem) bool
Whether
actualResolve()may updatelp.solverModelin place withapplyChanges()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
manageEnvis 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_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, 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.solverModelwith the edits made tolpsince 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
lpinto the solver’s model, stored inlp.solverModel, and configure it (seeconfigureSolver()).
- 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 updatelp.solverModelin place withapplyChanges()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_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:
- actualResolve(lp: LpProblem, **kwargs: Any) LpSolveStats
Solve
lpagain. Solvers that can updatelp.solverModelin 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(...).
- 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
actualSolveto return.- Parameters:
lp – the problem that was solved
status – why the solver stopped, a
LpSolveStatushas_solution – whether the solver handed back a feasible solution
start –
clocks()taken when the solve startedbest_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
Nonewhen this solver cannot produce one that orloge understands. A log the caller asked for throughlogPathis 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.
- 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
OBJSENSEand 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 afterbuildStats(), only for a solve where that negation happened.stats.objectiveis left alone: it comes fromlp.objective.value(), computed from the variable valuesbuildStats()already assigned back onto the original (un-negated) problem, so it is already in the problem’s sense.Mutates
statsin 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
logPathsends its output to the file instead of the console, socapture_log()has to echo the log back afterwards to keepmsg=Truebehaving as the caller expects.
- name = 'LpSolver'
- resolve(lp: LpProblem, **kwargs: Any) LpSolveStats
Solve
lpagain, updating the model the solver already holds when it can (seeactualResolve()), and describe how it went.
- 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:
LpSolverA 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.solverModelin place on a resolve also implementsapplyChanges()andcanUpdate().- Parameters:
- actualResolve(lp: LpProblem, **kwargs: Any) LpSolveStats
Update
lp.solverModelwith the edits made since the last solve and solve it again from its current basis; build it from scratch if it cannot be updated (seecanUpdate()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.solverModelwith the edits made tolpsince it was last solved (changes, from_take_changes()), keeping its basis.Raises
_RebuildNeededbefore touching the model if an edit cannot be replayed.
- buildSolverModel(lp: LpProblem) None
Translate
lpinto the solver’s model, stored inlp.solverModel, and configure it (seeconfigureSolver()).
- 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 updatelp.solverModelin place withapplyChanges()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:
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=None)
Bases:
LpSolver_APIMosek 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.
- 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_APIThe 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 + 1is the variable with idjand rowi + 1the constraint with idi.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,methormip_gap- applyChanges(lp: LpProblem, changes: _rustcore.ModelChanges) None
Update
lp.solverModelwith the edits made tolpsince 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 + 1is the variable with idj(as rowi + 1is the constraint with idi), 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 updatelp.solverModelin place withapplyChanges()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'
- class pulp.apis.SAS94(mip=True, msg=True, keepFiles=False, warmStart=False, timeLimit=None, **solverParams)
Bases:
SASsolver- Parameters:
- 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:
- 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:
- 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, duals=False)
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
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}
- available()
True if the solver is available
- defaultPath()
- name = 'SCIP_CMD'
- static readduals(logFile, solFile)
Read the output of
display dualsolutionfrom 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_APIThe SCIP Optimization Suite (via its python interface)
After calling solve, the model is in
problem.solverModel. Its variables, by index, followproblem.exported_variables()and its original constraints followproblem.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_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:
LpSolver_APIThe 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.solverModelwith the edits made tolpsince 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 updatelp.solverModelin place withapplyChanges()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_APICOIN 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.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: