lpinterface
 All Classes Namespaces Files Functions Variables Enumerations Enumerator
lpinterface_soplex.hpp
1 #ifndef LPINTERFACE_LPINTERFACE_SOPLEX_H
2 #define LPINTERFACE_LPINTERFACE_SOPLEX_H
3 
4 #include <algorithm>
5 #include <memory>
6 #include <unordered_map>
7 
8 #include "soplex.h"
9 
10 #include "lpinterface/badge.hpp"
11 #include "lpinterface/common.hpp"
12 #include "lpinterface/data_objects.hpp"
13 #include "lpinterface/errors.hpp"
14 #include "lpinterface/lp.hpp"
15 #include "lpinterface/lpinterface.hpp"
16 #include "lpinterface/soplex/lphandle_soplex.hpp"
17 
18 namespace lpint {
19 
21  public:
22  SoplexSolver();
23 
24  explicit SoplexSolver(OptimizationType optim_type);
25 
26  bool parameter_supported(const Param param) const override;
27 
28  void set_parameter(const Param param, const int value) override;
29 
30  void set_parameter(const Param param, const double value) override;
31 
32  Status solve() override;
33 
34  Status solution_status() const override;
35 
36  const ILinearProgramHandle& linear_program() const override;
37 
39 
40  const Solution<double>& get_solution() const override;
41 
42  static Status translate_status(const soplex::SPxSolver::Status status);
43 
44  private:
45  std::shared_ptr<soplex::SoPlex> soplex_;
46 
47  LinearProgramHandleSoplex lp_handle_;
48 
49  Solution<double> solution_;
50 
51  static const std::unordered_map<Param, int> param_dict_;
52 
53  static const std::unordered_map<soplex::SPxSolver::Status, Status>
54  status_dict_;
55 };
56 
57 inline Status SoplexSolver::translate_status(
58  const soplex::SPxSolver::Status status) {
59  if (status == soplex::SPxSolver::Status::ERROR) {
60  throw SoplexException();
61  } else {
62  return status_dict_.count(status) ? status_dict_.at(status)
63  : throw UnknownStatusException(status);
64  }
65 }
66 
67 } // namespace lpint
68 
69 #endif // LPINTERFACE_LPINTERFACE_SOPLEX_H
void set_parameter(const Param param, const int value) override
Set an integer-valued parameter in the internal LP solver. This method will fail with LpError::Unsupp...
OptimizationType
Objective sense for an LP.
Definition: lp.hpp:17
Interface representing linear program formulation. This interface represents linear programs of the f...
Definition: lp.hpp:53
Status solution_status() const override
Query the LP solver for the solution status.
Definition: lpinterface_soplex.hpp:20
Definition: lphandle_soplex.hpp:19
bool parameter_supported(const Param param) const override
Check whether the solver backend supports the given parameter.
const Solution< double > & get_solution() const override
Get the solution of the linear program. This method will fail with LpError::ModelNotsolvedError if th...
Internal error occured in SoPlex.
Definition: errors.hpp:117
const ILinearProgramHandle & linear_program() const override
Get immutable access to the underlying Linear Program object.
Param
Enum class representing linear solver parameters. The linear solvers this library interfaces with hav...
Definition: parameter_type.hpp:12
Status
Enum class representing LP solution status.
Definition: errors.hpp:129
Status solve() override
Solve the linear program.
Interface to internal linear program solver. This interface is the most important interface within lp...
Definition: lpinterface.hpp:22