hops
LinearProgramFactory.hpp
Go to the documentation of this file.
1 #ifndef HOPS_LINEARPROGRAMFACTORY_HPP
2 #define HOPS_LINEARPROGRAMFACTORY_HPP
3 
4 #include <Eigen/Core>
5 #include "LinearProgram.hpp"
8 #include <memory>
9 
10 namespace hops {
11  enum class LinearProgramSolver {
12  CLP,
13  GUROBI,
14  };
15 
16 #if defined(HOPS_CLP_FOUND) && defined(HOPS_GUROBI_FOUND)
17 
18  class LinearProgramFactory {
19  public:
20  template<typename Derived1, typename Derived2>
21  static std::unique_ptr<LinearProgram> createLinearProgram(
22  const Eigen::MatrixBase<Derived1> &A,
23  const Eigen::MatrixBase<Derived2> &b,
25  switch (solver) {
27  return std::make_unique<LinearProgramClpImpl>(A, b);
28  }
29  default: {
30  return std::make_unique<LinearProgramGurobiImpl>(A, b);
31  }
32  }
33  }
34  };
35 
36 #elif defined(HOPS_CLP_FOUND)
37 
38  class LinearProgramFactory {
39  public:
40  template<typename Derived1, typename Derived2>
41  static std::unique_ptr<LinearProgram> createLinearProgram(
42  const Eigen::MatrixBase<Derived1> &A,
43  const Eigen::MatrixBase<Derived2> &b,
45  switch (solver) {
47  return std::make_unique<LinearProgramClpImpl>(A, b);
48  }
49  default: {
50  throw std::runtime_error("Linear program solver was not found.");
51  }
52  }
53  }
54  };
55 
56 #elif defined(HOPS_GUROBI_FOUND)
57 
58  class LinearProgramFactory {
59  public:
60  template<typename Derived1, typename Derived2>
61  static std::unique_ptr<LinearProgram> createLinearProgram(
62  const Eigen::MatrixBase<Derived1> &A,
63  const Eigen::MatrixBase<Derived2> &b,
65  switch (solver) {
67  return std::make_unique<LinearProgramGurobiImpl>(A, b);
68  }
69  default: {
70  throw std::runtime_error("Linear program solver was not found.");
71  }
72  }
73  }
74  };
75 
76 #else
77 
79  public:
80  template<typename Derived1, typename Derived2>
81  static std::unique_ptr<LinearProgram> createLinearProgram(
82  const Eigen::MatrixBase<Derived1> &A,
83  const Eigen::MatrixBase<Derived2> &b,
85  (void)A;
86  (void)b;
87  (void)solver;
88  throw std::runtime_error("No linear program solver was found.");
89  }
90  };
91 
92 #endif //HOPS_CLP_FOUND && HOPS_GUROBI_FOUND
93 
94 }
95 
96 #endif //HOPS_LINEARPROGRAMFACTORY_HPP
hops::LinearProgramSolver::GUROBI
@ GUROBI
hops::LinearProgramSolver::CLP
@ CLP
hops::LinearProgramSolver
LinearProgramSolver
Definition: LinearProgramFactory.hpp:11
LinearProgramClpImpl.hpp
LinearProgramGurobiImpl.hpp
hops::LinearProgramFactory
Definition: LinearProgramFactory.hpp:78
hops
Definition: CsvReader.hpp:8
LinearProgram.hpp
hops::LinearProgramFactory::createLinearProgram
static std::unique_ptr< LinearProgram > createLinearProgram(const Eigen::MatrixBase< Derived1 > &A, const Eigen::MatrixBase< Derived2 > &b, LinearProgramSolver solver=LinearProgramSolver::CLP)
Definition: LinearProgramFactory.hpp:81