graph_analysis
GLPKSolver.hpp
Go to the documentation of this file.
1 #ifndef GRAPH_ANALYSIS_ALGORITHMS_GLPK_SOLVER_HPP
2 #define GRAPH_ANALYSIS_ALGORITHMS_GLPK_SOLVER_HPP
3 
4 #include <glpk.h>
5 #include <string>
6 #include <stdexcept>
7 #include "../../LPSolver.hpp"
8 
9 namespace graph_analysis {
10 namespace algorithms {
11 namespace lp {
12 namespace embedded {
13 
18 class GLPKSolver : public LPSolver
19 {
20 public:
21  GLPKSolver();
22  GLPKSolver(const std::string& problemName);
23  virtual ~GLPKSolver();
24 
25  LPSolver::Type getSolverType() const override { return GLPK_SOLVER; }
26 
27  std::string getProblemName() const { return std::string( glp_get_prob_name(mpProblem) ) ; }
28 
29  void doLoadProblem(const std::string& filename, LPSolver::ProblemFormat format = CPLEX) override;
30 
31  void saveProblem(const std::string& filename, LPSolver::ProblemFormat format = CPLEX) const override;
32 
33  void loadSolution(const std::string& filename, LPSolver::SolutionType format = BASIC_SOLUTION) override;
34 
35  void saveSolution(const std::string& filename, LPSolver::SolutionType format = BASIC_SOLUTION) const override;
36 
37  double getObjectiveValue() const override { return glp_get_obj_val(mpProblem); };
38 
39  double getVariableValue(const std::string& varName) const;
40 
41  double getVariableValueByColumnIdx(uint32_t idx) const override;
42 
43  Status run() override { throw std::runtime_error("graph_analysis::algorithms::GLPKSolver::run not implemented"); }
44 
45  Status run(const std::string& problem, LPSolver::ProblemFormat problemFormat = CPLEX, bool useCaching = false) override;
46 
50  static int printHook(void* info, const char* s);
51 
52 protected:
53  glp_prob* mpProblem;
54 
57 };
58 
59 } // end namespace embedded
60 } // end namespace lp
61 } // end namespace algorithms
62 } // end namespace graph_analysis
63 #endif // GRAPH_ANALYSIS_ALGORITHMS_GLPK_SOLVER_HPP
graph_analysis::algorithms::LPSolver
Definition: LPSolver.hpp:15
graph_analysis::algorithms::lp::embedded::GLPKSolver::run
Status run() override
Definition: GLPKSolver.hpp:43
graph_analysis::algorithms::lp::embedded::GLPKSolver::loadSolution
void loadSolution(const std::string &filename, LPSolver::SolutionType format=BASIC_SOLUTION) override
Definition: GLPKSolver.cpp:112
graph_analysis::algorithms::lp::embedded::GLPKSolver::doLoadProblem
void doLoadProblem(const std::string &filename, LPSolver::ProblemFormat format=CPLEX) override
Definition: GLPKSolver.cpp:33
graph_analysis::algorithms::lp::embedded::GLPKSolver::getProblemName
std::string getProblemName() const
Definition: GLPKSolver.hpp:27
graph_analysis::algorithms::lp::embedded::GLPKSolver::~GLPKSolver
virtual ~GLPKSolver()
Definition: GLPKSolver.cpp:28
graph_analysis::algorithms::lp::embedded::GLPKSolver::getVariableValue
double getVariableValue(const std::string &varName) const
Definition: GLPKSolver.cpp:224
graph_analysis
Main namespace of the graph analysis library.
Definition: BFS.cpp:3
graph_analysis::algorithms::LPSolver::GLPK_SOLVER
@ GLPK_SOLVER
Definition: LPSolver.hpp:31
graph_analysis::algorithms::LPSolver::SolutionType
SolutionType
Solution types: basic, IPT = interior point, MIP = mixed integer.
Definition: LPSolver.hpp:46
graph_analysis::algorithms::lp::embedded::GLPKSolver::printHook
static int printHook(void *info, const char *s)
Definition: GLPKSolver.cpp:270
graph_analysis::algorithms::LPSolver::ProblemFormat
ProblemFormat
Definition: LPSolver.hpp:41
graph_analysis::algorithms::lp::embedded::GLPKSolver::getVariableValueByColumnIdx
double getVariableValueByColumnIdx(uint32_t idx) const override
Definition: GLPKSolver.cpp:235
graph_analysis::algorithms::lp::embedded::GLPKSolver::saveProblem
void saveProblem(const std::string &filename, LPSolver::ProblemFormat format=CPLEX) const override
Definition: GLPKSolver.cpp:59
graph_analysis::algorithms::lp::embedded::GLPKSolver::GLPKSolver
GLPKSolver()
Definition: GLPKSolver.cpp:11
graph_analysis::algorithms::lp::embedded::GLPKSolver::mpProblem
glp_prob * mpProblem
Definition: GLPKSolver.hpp:53
graph_analysis::algorithms::lp::embedded::GLPKSolver::translateSimplexReturnCode
Status translateSimplexReturnCode(int code)
Definition: GLPKSolver.cpp:139
graph_analysis::algorithms::lp::embedded::GLPKSolver::getSolverType
LPSolver::Type getSolverType() const override
Definition: GLPKSolver.hpp:25
graph_analysis::algorithms::lp::embedded::GLPKSolver::translateIntoptReturnCode
Status translateIntoptReturnCode(int code)
Definition: GLPKSolver.cpp:198
graph_analysis::algorithms::LPSolver::BASIC_SOLUTION
@ BASIC_SOLUTION
Definition: LPSolver.hpp:46
graph_analysis::algorithms::LPSolver::Status
Status
Definition: LPSolver.hpp:18
graph_analysis::algorithms::LPSolver::CPLEX
@ CPLEX
Definition: LPSolver.hpp:41
graph_analysis::algorithms::lp::embedded::GLPKSolver
Definition: GLPKSolver.hpp:18
graph_analysis::algorithms::lp::embedded::GLPKSolver::getObjectiveValue
double getObjectiveValue() const override
Definition: GLPKSolver.hpp:37
graph_analysis::algorithms::lp::embedded::GLPKSolver::saveSolution
void saveSolution(const std::string &filename, LPSolver::SolutionType format=BASIC_SOLUTION) const override
Definition: GLPKSolver.cpp:85
graph_analysis::algorithms::LPSolver::Type
Type
Definition: LPSolver.hpp:28