pulp.apis Interface to Solvers

class pulp.apis.CHOCO_CMD(path=None, keepFiles=0, *args, **kwargs)

Bases: pulp.apis.core.LpSolver_CMD

The CHOCO_CMD solver

Parameters
  • 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

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, mip_start=False, timeLimit=None, warmStart=False, *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) –

  • warmStart (bool) –

  • timeLimit – maximum time for solver

  • 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(fracGap=None, maxSeconds=None, *args, **kwargs)

Bases: pulp.apis.core.LpSolver_CMD

The COIN CLP/CBC LP solver now only uses cbc

Parameters
  • fracGap

  • maxSeconds

  • args

  • kwargs – includes presolve, cuts, strong

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, *args, **kwargs)

Bases: pulp.apis.core.LpSolver_CMD

The CPLEX LP solver

Parameters
  • 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

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, mip_start=False, timeLimit=None, warmStart=False, *args, **kwargs)

Bases: pulp.apis.core.LpSolver

The CPLEX LP/MIP solver PHANTOM Something went wrong!!!!

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

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

  • options (list) –

  • warmStart (bool) –

  • timeLimit (float) – maximum time for solver

  • 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

available()

True if the solver is available

name = 'CPLEX_DLL'
pulp.apis.CPLEX_DLL_load_dll(path)

function that loads the DLL useful for debugging installation problems

class pulp.apis.CPLEX_PY(epgap=None, logfilename=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

Initializes the CPLEX_PY solver.

@param mip: if False the solver will solve a MIP as an LP @param msg: displays information from the solver to stdout @param epgap: sets the integer bound gap @param logfilename: sets the filename of the cplex logfile

actualResolve(lp, **kwargs)

looks at which variables have been modified and changes them

actualSolve(lp, callback=None)

Solve a well formulated lp problem

creates a cplex 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 cplex model

callSolver(isMIP)

Solves the problem with cplex

changeEpgap(epgap=0.0001)

Change cplex solver integer bound gap tolerence

findSolutionValues(lp)
name = 'CPLEX_PY'
setTimeLimit(timeLimit=0.0)

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

setlogfile(fileobj)

sets the logfile for cplex output

pulp.apis.GLPK

alias of pulp.apis.glpk_api.GLPK_CMD

class pulp.apis.GLPK_CMD(path=None, keepFiles=0, *args, **kwargs)

Bases: pulp.apis.core.LpSolver_CMD

The GLPK LP solver

Parameters
  • 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

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, timeLimit=None, epgap=None, **solverParams)

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

Initializes the Gurobi 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: sets the maximum time for solution @param epgap: sets the integer bound gap

actualResolve(lp, callback=None)

Solve a well formulated lp problem

uses the old solver and modifies the rhs of the modified constraints

actualSolve(lp, callback=None)

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

findSolutionValues(lp)
name = 'GUROBI'
class pulp.apis.GUROBI_CMD(path=None, keepFiles=0, *args, **kwargs)

Bases: pulp.apis.core.LpSolver_CMD

The GUROBI_CMD solver

Parameters
  • 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

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, mip_start=False, timeLimit=None, warmStart=False, *args, **kwargs)

Bases: object

A generic LP Solver

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

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

  • options (list) –

  • warmStart (bool) –

  • timeLimit (float) – maximum time for solver

  • args

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

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

to_dict()
to_json(filename, *args, **kwargs)
class pulp.apis.LpSolver_CMD(path=None, keepFiles=0, *args, **kwargs)

Bases: pulp.apis.core.LpSolver

A generic command line LP Solver

Parameters
  • 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=0, *args, **kwargs)

Bases: pulp.apis.core.LpSolver_CMD

The MIPCL_CMD solver

Parameters
  • 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

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, mip_start=False, timeLimit=None, warmStart=False, *args, **kwargs)

Bases: pulp.apis.core.LpSolver

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

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

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

  • options (list) –

  • warmStart (bool) –

  • timeLimit (float) – maximum time for solver

  • args

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

actualSolve(lp, callback=None)

Solves a well-formulated lp problem.

available()

True if Mosek is available.

name = 'MOSEK'
class pulp.apis.PULP_CBC_CMD(path=None, *args, **kwargs)

Bases: pulp.apis.coin_api.COIN_CMD

This solver uses a precompiled version of cbc provided with the package

just loads up COIN_CMD with the path set

name = 'PULP_CBC_CMD'
pulp_cbc_path = '/home/pchtsp/Documents/resources/pulp/pulp/apis/../solverdir/cbc/linux/64/cbc'
class pulp.apis.PULP_CHOCO_CMD(path=None, *args, **kwargs)

Bases: pulp.apis.choco_api.CHOCO_CMD

This solver uses a packaged version of choco provided with the package

just loads up CHOCO_CMD with the path set

name = 'PULP_CHOCO_CMD'
pulp_choco_path = '/home/pchtsp/Documents/resources/pulp/pulp/apis/../solverdir/choco/choco-parsers-with-dependencies.jar'
class pulp.apis.PYGLPK(mip=True, msg=True, options=None, mip_start=False, timeLimit=None, warmStart=False, *args, **kwargs)

Bases: pulp.apis.core.LpSolver

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

Copyright Christophe-Marie 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
  • mip (bool) – if False, assume LP even if integer variables.

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

  • options (list) –

  • warmStart (bool) –

  • timeLimit (float) – maximum time for solver

  • args

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

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 Solver-related exceptions

pulp.apis.SCIP

alias of pulp.apis.scip_api.SCIP_CMD

class pulp.apis.SCIP_CMD(path=None, keepFiles=0, *args, **kwargs)

Bases: pulp.apis.core.LpSolver_CMD

The SCIP optimization solver

Parameters
  • 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

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()
name = 'SCIP_CMD'
static readsol(filename)

Read a SCIP solution file

class pulp.apis.XPRESS(maxSeconds=None, targetGap=None, heurFreq=None, heurStra=None, coverCuts=None, preSolve=None, *args, **kwargs)

Bases: pulp.apis.core.LpSolver_CMD

The XPRESS LP solver

Initializes the Xpress solver.

Parameters
  • maxSeconds – the maximum time that the Optimizer will run before it terminates

  • targetGap – global search will terminate if: abs(MIPOBJVAL - BESTBOUND) <= MIPRELSTOP * BESTBOUND

  • 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, mip_start=False, timeLimit=None, warmStart=False, *args, **kwargs)

Bases: pulp.apis.core.LpSolver

COIN OSI (via its python interface)

Copyright Christophe-Marie Duquesne 2012

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

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

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

  • options (list) –

  • warmStart (bool) –

  • timeLimit (float) – maximum time for solver

  • args

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

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 user-space 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.get_solver(solver, *args, **kwargs)

Instantiates a solver from its name

Parameters
  • solver (str) – solver name to create

  • args – additional arguments to the solver

  • kwargs – additional keyword arguments to the solver

Returns

solver of type LpSolver

pulp.apis.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

LpSolver

pulp.apis.get_solver_from_json(filename)

Instantiates a solver from a json file with its data

Parameters

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

Returns

a solver of type LpSolver

Return type

LpSolver

pulp.apis.initialize(filename, operating_system='linux', arch='64')

reads the configuration file to initialise the module

pulp.apis.list_solvers(onlyAvailable=False)

List the names of all the existing solvers in PuLP

Parameters

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

Returns

list of solver names

Return type

list

pulp.apis.mktemp(suffix='', prefix='tmp', dir=None)

User-callable 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.uuid4()

Generate a random UUID.