Qontrol
GenericSolver.hpp
1 // This file is part of Qontrol, a quadratic optimization library to
2 // control robot.
3 //
4 // Copyright (C) 2023 Lucas Joseph <lucas.joseph@inria.fr>
5 //
6 // Qontrol is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 3 of
14 // the License, or (at your option) any later version.
15 //
16 // Qontrol is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Qontrol. If not, see <http://www.gnu.org/licenses/>.
24 
25 #pragma once
26 #include <Eigen/Dense>
27 #include <Qontrol/Model/GenericModel.hpp>
28 #include <Qontrol/Utils/Size.hpp>
29 #include <iostream>
30 #include <memory>
31 #include <exception>
32 namespace Qontrol {
34 namespace Solver {
35 
36  enum SolverImplType { qpOASES, OSQP, qpmad };
37 
42 struct qpData {
43  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
44  hessian;
45  Eigen::VectorXd gradient;
46  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
47  a_constraints;
48  Eigen::VectorXd lb_a;
49  Eigen::VectorXd ub_a;
50  Eigen::VectorXd solution;
51 };
52 
58 public:
59  GenericSolver(){};
60  ~GenericSolver(){};
68  virtual void configure(int optimization_vector_size) = 0;
69 
75  qpData getProblemData() { return qp_data_; };
76 
88  void checkProblem(qpData qp_data);
89 
95  virtual void resizeProblem(qpData qp_data) = 0;
96 
97  virtual bool solve(qpData qp_data) = 0;
98 
99  virtual Eigen::VectorXd getPrimalSolution() = 0;
100 
101 protected:
102  int number_of_variables;
103  int number_of_constraints;
104 
105 protected:
106  qpData qp_data_;
107 };
108 
109 
115 template <SolverImplType solver_lib> class Solver {};
116 } // namespace Solver
117 } // namespace Qontrol
Qontrol::Solver::qpData
Represents the data structured required by any qp solver.
Definition: GenericSolver.hpp:42
Qontrol::Solver::GenericSolver::checkProblem
void checkProblem(qpData qp_data)
Check if the problem size is consistent.
Definition: GenericSolver.cpp:6
Qontrol::Solver::GenericSolver
A generic solver class.
Definition: GenericSolver.hpp:57
Qontrol::Solver::Solver
Template specialization of the GenericSolver.
Definition: GenericSolver.hpp:115
Qontrol::Solver::GenericSolver::configure
virtual void configure(int optimization_vector_size)=0
Configure the qp solver.
Qontrol::Solver::GenericSolver::resizeProblem
virtual void resizeProblem(qpData qp_data)=0
Reset the problem to the new qpData size.
Qontrol::Solver::GenericSolver::getProblemData
qpData getProblemData()
Get the previous qpData.
Definition: GenericSolver.hpp:75