graph_analysis
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
graph_analysis::algorithms::LPSolver Class Referenceabstract

#include <LPSolver.hpp>

Inheritance diagram for graph_analysis::algorithms::LPSolver:
Inheritance graph
[legend]

Classes

struct  KnownSolution
 

Public Types

enum  Status {
  STATUS_UNKNOWN, STATUS_OPTIMAL, STATUS_INFEASIBLE, STATUS_UNBOUNDED,
  INVALID_PROBLEM_DEFINITION, NO_SOLUTION_FOUND, SOLUTION_FOUND
}
 
enum  Type {
  UNKNOWN_LP_SOLVER, CBC_SOLVER, CLP_SOLVER, GLPK_SOLVER,
  SCIP_SOLVER, SOPLEX_SOLVER, GLPK_SOLVER_EMBEDDED, SCIP_SOLVER_EMBEDDED,
  SOPLEX_SOLVER_EMBEDDED, LP_SOLVER_TYPE_END
}
 
enum  ProblemFormat {
  UNKNOWN_PROBLEM_FORMAT = 0, CPLEX, GLPK, MPS,
  LP_PROBLEM_FORMAT_END
}
 
enum  SolutionType {
  UNKNOWN_SOLUTION_TYPE = 0, BASIC_SOLUTION, IPT_SOLUTION, MIP_SOLUTION,
  LP_SOLUTION_TYPE_END
}
 Solution types: basic, IPT = interior point, MIP = mixed integer. More...
 
typedef shared_ptr< LPSolver > Ptr
 

Public Member Functions

 LPSolver ()
 
virtual ~LPSolver ()
 
virtual LPSolver::Type getSolverType () const =0
 
bool loadProblem (const std::string &filename, ProblemFormat format=CPLEX)
 
virtual void saveProblem (const std::string &filename, ProblemFormat format=CPLEX) const =0
 
virtual void loadSolution (const std::string &filename, SolutionType format=BASIC_SOLUTION)=0
 
std::string saveProblemToTempfile (LPSolver::ProblemFormat format=CPLEX) const
 
std::string saveSolutionToTempfile (LPSolver::SolutionType format=BASIC_SOLUTION) const
 
virtual void saveSolution (const std::string &filename, LPSolver::SolutionType format=BASIC_SOLUTION) const =0
 
virtual double getObjectiveValue () const =0
 
virtual double getVariableValueByColumnIdx (uint32_t idx) const
 
std::string getVariableNameByColumnIdx (uint32_t idx) const
 
uint32_t getColumnIdxByVariableName (const std::string &varName) const
 
virtual Status run ()=0
 
virtual Status run (const std::string &problemFilename, LPSolver::ProblemFormat problemFormat=CPLEX, bool useCaching=false)=0
 
const std::string & getProblemFile () const
 
LPSolver::ProblemFormat getProblemFileFormat () const
 
const std::string & getSolutionFile () const
 
LPSolver::SolutionType getSolutionFileFormat () const
 
virtual std::vector< size_t > infeasibleConstraints () const
 
void setSolutionCacheSize (size_t size)
 
size_t getSolutionCacheSize () const
 
void resetSolutionCache ()
 

Static Public Member Functions

static LPSolver::Ptr getInstance (LPSolver::Type solverType)
 
static ProblemFormat getProblemFormatFromFileExtension (const std::string &extension)
 
static std::string getTempFilename (const std::string &suffix=".lp")
 

Static Public Attributes

static std::map< Status, std::string > StatusTxt
 
static std::map< Type, std::string > TypeTxt
 
static std::map< ProblemFormat, std::string > ProblemFormatTxt
 
static std::map< LPSolver::ProblemFormat, std::vector< std::string > > ProblemFormatExtensions
 

Protected Types

typedef std::map< std::string, KnownSolution > KnownSolutions
 

Protected Member Functions

virtual void doLoadProblem (const std::string &filename, ProblemFormat format=CPLEX)=0
 
Status loadKnownSolution (const std::string &problemFilename)
 
void registerSolution (const std::string &problemFilename, const std::string &solutionFilename, Status status, SolutionType type)
 
const LPSolver::KnownSolutions::mapped_type & getRegisteredSolution (const std::string &problemFilename) const
 

Protected Attributes

std::string mProblemFile
 
LPSolver::ProblemFormat mProblemFileFormat
 
std::string mSolutionFile
 
LPSolver::SolutionType mSolutionFileFormat
 
size_t mSolutionCacheSize
 

Static Protected Attributes

static KnownSolutions msKnownSolutions
 

Detailed Description

General interface to call linear problem solvers

Member Typedef Documentation

◆ KnownSolutions

typedef std::map<std::string, KnownSolution> graph_analysis::algorithms::LPSolver::KnownSolutions
protected

◆ Ptr

Member Enumeration Documentation

◆ ProblemFormat

Enumerator
UNKNOWN_PROBLEM_FORMAT 
CPLEX 
GLPK 
MPS 
LP_PROBLEM_FORMAT_END 

◆ SolutionType

Solution types: basic, IPT = interior point, MIP = mixed integer.

Enumerator
UNKNOWN_SOLUTION_TYPE 
BASIC_SOLUTION 
IPT_SOLUTION 
MIP_SOLUTION 
LP_SOLUTION_TYPE_END 

◆ Status

Enumerator
STATUS_UNKNOWN 
STATUS_OPTIMAL 
STATUS_INFEASIBLE 
STATUS_UNBOUNDED 
INVALID_PROBLEM_DEFINITION 
NO_SOLUTION_FOUND 
SOLUTION_FOUND 

◆ Type

Enumerator
UNKNOWN_LP_SOLVER 
CBC_SOLVER 
CLP_SOLVER 
GLPK_SOLVER 
SCIP_SOLVER 
SOPLEX_SOLVER 
GLPK_SOLVER_EMBEDDED 
SCIP_SOLVER_EMBEDDED 
SOPLEX_SOLVER_EMBEDDED 
LP_SOLVER_TYPE_END 

Constructor & Destructor Documentation

◆ LPSolver()

graph_analysis::algorithms::LPSolver::LPSolver ( )

◆ ~LPSolver()

graph_analysis::algorithms::LPSolver::~LPSolver ( )
virtual

Member Function Documentation

◆ doLoadProblem()

virtual void graph_analysis::algorithms::LPSolver::doLoadProblem ( const std::string &  filename,
ProblemFormat  format = CPLEX 
)
protectedpure virtual

◆ getColumnIdxByVariableName()

uint32_t graph_analysis::algorithms::LPSolver::getColumnIdxByVariableName ( const std::string &  varName) const

Get the column index for the canonize variable name

Parameters
varNamecanonized variable name
Returns
the column index

◆ getInstance()

LPSolver::Ptr graph_analysis::algorithms::LPSolver::getInstance ( LPSolver::Type  solverType)
static

◆ getObjectiveValue()

virtual double graph_analysis::algorithms::LPSolver::getObjectiveValue ( ) const
pure virtual

◆ getProblemFile()

const std::string& graph_analysis::algorithms::LPSolver::getProblemFile ( ) const
inline

◆ getProblemFileFormat()

LPSolver::ProblemFormat graph_analysis::algorithms::LPSolver::getProblemFileFormat ( ) const
inline

◆ getProblemFormatFromFileExtension()

static ProblemFormat graph_analysis::algorithms::LPSolver::getProblemFormatFromFileExtension ( const std::string &  extension)
static

Get the problem format from an extension

◆ getRegisteredSolution()

const LPSolver::KnownSolutions::mapped_type & graph_analysis::algorithms::LPSolver::getRegisteredSolution ( const std::string &  problemFilename) const
protected

◆ getSolutionCacheSize()

size_t graph_analysis::algorithms::LPSolver::getSolutionCacheSize ( ) const
inline

◆ getSolutionFile()

const std::string& graph_analysis::algorithms::LPSolver::getSolutionFile ( ) const
inline

◆ getSolutionFileFormat()

LPSolver::SolutionType graph_analysis::algorithms::LPSolver::getSolutionFileFormat ( ) const
inline

◆ getSolverType()

virtual LPSolver::Type graph_analysis::algorithms::LPSolver::getSolverType ( ) const
pure virtual

◆ getTempFilename()

std::string graph_analysis::algorithms::LPSolver::getTempFilename ( const std::string &  suffix = ".lp")
static

Get a temporary filename

Returns
temporary filename

◆ getVariableNameByColumnIdx()

std::string graph_analysis::algorithms::LPSolver::getVariableNameByColumnIdx ( uint32_t  idx) const

Get the canonized variable name for the given column index

Parameters
idxcolumn index
Returns
the variable name

◆ getVariableValueByColumnIdx()

double graph_analysis::algorithms::LPSolver::getVariableValueByColumnIdx ( uint32_t  idx) const
virtual

◆ infeasibleConstraints()

virtual std::vector<size_t> graph_analysis::algorithms::LPSolver::infeasibleConstraints ( ) const
inlinevirtual

Allow to return the set of infeasible constraint by a list of indices in the final solution

Reimplemented in graph_analysis::algorithms::lp::embedded::SoplexSolver.

◆ loadKnownSolution()

LPSolver::Status graph_analysis::algorithms::LPSolver::loadKnownSolution ( const std::string &  problemFilename)
protected

◆ loadProblem()

bool graph_analysis::algorithms::LPSolver::loadProblem ( const std::string &  filename,
ProblemFormat  format = CPLEX 
)

Load a problem based

Parameters
filenamefilename of the problem file
formatformat of the problem
Returns
if the problem is already known

◆ loadSolution()

virtual void graph_analysis::algorithms::LPSolver::loadSolution ( const std::string &  filename,
SolutionType  format = BASIC_SOLUTION 
)
pure virtual

◆ registerSolution()

void graph_analysis::algorithms::LPSolver::registerSolution ( const std::string &  problemFilename,
const std::string &  solutionFilename,
Status  status,
SolutionType  type 
)
protected

◆ resetSolutionCache()

void graph_analysis::algorithms::LPSolver::resetSolutionCache ( )
inline

◆ run() [1/2]

virtual Status graph_analysis::algorithms::LPSolver::run ( )
pure virtual

◆ run() [2/2]

virtual Status graph_analysis::algorithms::LPSolver::run ( const std::string &  problemFilename,
LPSolver::ProblemFormat  problemFormat = CPLEX,
bool  useCaching = false 
)
pure virtual

Run the solver with a given problem file

Parameters
problemFilenamefilename of the problem to solve
problemFormatformat of the problem to solver
useCachingTo use caching of problem and respective solutions set to True, otherwise False

Implemented in graph_analysis::algorithms::lp::embedded::GLPKSolver, graph_analysis::algorithms::lp::embedded::SoplexSolver, graph_analysis::algorithms::lp::embedded::ScipSolver, graph_analysis::algorithms::lp::CommandlineSolver, and graph_analysis::algorithms::lp::CommandlineSolver.

◆ saveProblem()

virtual void graph_analysis::algorithms::LPSolver::saveProblem ( const std::string &  filename,
ProblemFormat  format = CPLEX 
) const
pure virtual

◆ saveProblemToTempfile()

std::string graph_analysis::algorithms::LPSolver::saveProblemToTempfile ( LPSolver::ProblemFormat  format = CPLEX) const

Save the problem in a temporary file

Returns
the temporary file where the problem has been saved to

◆ saveSolution()

virtual void graph_analysis::algorithms::LPSolver::saveSolution ( const std::string &  filename,
LPSolver::SolutionType  format = BASIC_SOLUTION 
) const
pure virtual

◆ saveSolutionToTempfile()

std::string graph_analysis::algorithms::LPSolver::saveSolutionToTempfile ( LPSolver::SolutionType  format = BASIC_SOLUTION) const

Save the solution in a temporary file

Returns
the temporary file where the solution has been saved to

◆ setSolutionCacheSize()

void graph_analysis::algorithms::LPSolver::setSolutionCacheSize ( size_t  size)
inline

Set the maximum size of the solution cache The cache will be cleared – if the size exceeds this cache size

Member Data Documentation

◆ mProblemFile

std::string graph_analysis::algorithms::LPSolver::mProblemFile
mutableprotected

Provide the current problem file and format after loadProblem has been called

◆ mProblemFileFormat

LPSolver::ProblemFormat graph_analysis::algorithms::LPSolver::mProblemFileFormat
mutableprotected

◆ msKnownSolutions

LPSolver::KnownSolutions graph_analysis::algorithms::LPSolver::msKnownSolutions
staticprotected

◆ mSolutionCacheSize

size_t graph_analysis::algorithms::LPSolver::mSolutionCacheSize
protected

◆ mSolutionFile

std::string graph_analysis::algorithms::LPSolver::mSolutionFile
mutableprotected

Provide the current solution file and format after loadSolution has been called

◆ mSolutionFileFormat

LPSolver::SolutionType graph_analysis::algorithms::LPSolver::mSolutionFileFormat
mutableprotected

◆ ProblemFormatExtensions

std::map< LPSolver::ProblemFormat, std::vector< std::string > > graph_analysis::algorithms::LPSolver::ProblemFormatExtensions
static
Initial value:
=
InitMap<LPSolver::ProblemFormat, std::vector<std::string> >
(LPSolver::CPLEX, {".lp"})
(LPSolver::GLPK, {".glpk"})
(LPSolver::MPS, {".mps"} )

◆ ProblemFormatTxt

std::map< LPSolver::ProblemFormat, std::string > graph_analysis::algorithms::LPSolver::ProblemFormatTxt
static
Initial value:
=
InitMap<LPSolver::ProblemFormat, std::string>
(LPSolver::UNKNOWN_PROBLEM_FORMAT, "unknown problem format")
(LPSolver::CPLEX, "CPLEX")
(LPSolver::GLPK, "GLPK")
(LPSolver::MPS, "MPS")

◆ StatusTxt

std::map< LPSolver::Status, std::string > graph_analysis::algorithms::LPSolver::StatusTxt
static
Initial value:
=
InitMap<LPSolver::Status, std::string>
(LPSolver::STATUS_UNKNOWN, "STATUS_UNKNOWN")
(LPSolver::STATUS_OPTIMAL, "STATUS_OPTIMAL")
(LPSolver::STATUS_INFEASIBLE,"STATUS_INFEASIBLE")
(LPSolver::STATUS_UNBOUNDED, "STATUS_UNBOUNDED")
(LPSolver::INVALID_PROBLEM_DEFINITION, "INVALID_PROBLEM_DEFINITION")
(LPSolver::NO_SOLUTION_FOUND, "NO_SOLUTION_FOUND")
(LPSolver::SOLUTION_FOUND, "SOLUTION_FOUND")

◆ TypeTxt

std::map< LPSolver::Type, std::string > graph_analysis::algorithms::LPSolver::TypeTxt
static
Initial value:
=
InitMap<LPSolver::Type, std::string>
(LPSolver::UNKNOWN_LP_SOLVER, "UNKNOWN_LP_SOLVER")
(LPSolver::CBC_SOLVER, "CBC_SOLVER")
(LPSolver::CLP_SOLVER, "CLP_SOLVER")
(LPSolver::GLPK_SOLVER, "GLPK_SOLVER")
(LPSolver::SCIP_SOLVER, "SCIP_SOLVER")
(LPSolver::SOPLEX_SOLVER, "SOPLEX_SOLVER")
(LPSolver::GLPK_SOLVER_EMBEDDED, "GLPK_SOLVER_EMBEDDED")
(LPSolver::SCIP_SOLVER_EMBEDDED, "SCIP_SOLVER_EMBEDDED")
(LPSolver::SOPLEX_SOLVER_EMBEDDED, "SOPLEX_SOLVER_EMBEDDED")
(LPSolver::LP_SOLVER_TYPE_END, "LP_SOLVER_TYPE_END")

The documentation for this class was generated from the following files:
graph_analysis::algorithms::LPSolver::INVALID_PROBLEM_DEFINITION
@ INVALID_PROBLEM_DEFINITION
Definition: LPSolver.hpp:22
graph_analysis::algorithms::LPSolver::STATUS_UNKNOWN
@ STATUS_UNKNOWN
Definition: LPSolver.hpp:18
graph_analysis::algorithms::LPSolver::SOPLEX_SOLVER
@ SOPLEX_SOLVER
Definition: LPSolver.hpp:33
graph_analysis::algorithms::LPSolver::SCIP_SOLVER
@ SCIP_SOLVER
Definition: LPSolver.hpp:32
graph_analysis::algorithms::LPSolver::UNKNOWN_PROBLEM_FORMAT
@ UNKNOWN_PROBLEM_FORMAT
Definition: LPSolver.hpp:41
graph_analysis::algorithms::LPSolver::GLPK
@ GLPK
Definition: LPSolver.hpp:41
graph_analysis::algorithms::LPSolver::GLPK_SOLVER
@ GLPK_SOLVER
Definition: LPSolver.hpp:31
graph_analysis::algorithms::LPSolver::SCIP_SOLVER_EMBEDDED
@ SCIP_SOLVER_EMBEDDED
Definition: LPSolver.hpp:35
graph_analysis::algorithms::LPSolver::CBC_SOLVER
@ CBC_SOLVER
Definition: LPSolver.hpp:29
graph_analysis::algorithms::LPSolver::STATUS_UNBOUNDED
@ STATUS_UNBOUNDED
Definition: LPSolver.hpp:21
graph_analysis::algorithms::LPSolver::MPS
@ MPS
Definition: LPSolver.hpp:41
graph_analysis::algorithms::LPSolver::UNKNOWN_LP_SOLVER
@ UNKNOWN_LP_SOLVER
Definition: LPSolver.hpp:28
graph_analysis::algorithms::LPSolver::LP_SOLVER_TYPE_END
@ LP_SOLVER_TYPE_END
Definition: LPSolver.hpp:37
graph_analysis::algorithms::LPSolver::NO_SOLUTION_FOUND
@ NO_SOLUTION_FOUND
Definition: LPSolver.hpp:23
graph_analysis::algorithms::LPSolver::CLP_SOLVER
@ CLP_SOLVER
Definition: LPSolver.hpp:30
graph_analysis::algorithms::LPSolver::SOLUTION_FOUND
@ SOLUTION_FOUND
Definition: LPSolver.hpp:24
graph_analysis::algorithms::LPSolver::STATUS_INFEASIBLE
@ STATUS_INFEASIBLE
Definition: LPSolver.hpp:20
graph_analysis::algorithms::LPSolver::GLPK_SOLVER_EMBEDDED
@ GLPK_SOLVER_EMBEDDED
Definition: LPSolver.hpp:34
graph_analysis::algorithms::LPSolver::CPLEX
@ CPLEX
Definition: LPSolver.hpp:41
graph_analysis::algorithms::LPSolver::STATUS_OPTIMAL
@ STATUS_OPTIMAL
Definition: LPSolver.hpp:19
graph_analysis::algorithms::LPSolver::SOPLEX_SOLVER_EMBEDDED
@ SOPLEX_SOLVER_EMBEDDED
Definition: LPSolver.hpp:36