wbc
QPSolver.hpp
Go to the documentation of this file.
1#ifndef WBC_SOLVERS_SOLVER_HPP
2#define WBC_SOLVERS_SOLVER_HPP
3
4#include <vector>
5#include <base/Eigen.hpp>
6#include <memory>
7#include <map>
8#include "QPSolverConfig.hpp"
9
10namespace wbc{
11
12class HierarchicalQP;
13
15protected:
17public:
18 QPSolver();
19 virtual ~QPSolver();
25 virtual void solve(const HierarchicalQP& hierarchical_qp, base::VectorXd &solver_output) = 0;
26
28 void reset(){configured=false;}
29};
30
31typedef std::shared_ptr<QPSolver> QPSolverPtr;
32
33template<typename T> QPSolver* createT(){return new T;}
34
36 typedef std::map<std::string, QPSolver*(*)()> QPSolverMap;
37
38 static QPSolver *createInstance(const std::string& name) {
39 QPSolverMap::iterator it = getQPSolverMap()->find(name);
40 if(it == getQPSolverMap()->end())
41 throw std::runtime_error("Failed to create instance of plugin " + name + ". Is the plugin registered?");
42 return it->second();
43 }
44
45 template<typename T>
46 static T* createInstance(const std::string& name){
47 QPSolver* tmp = createInstance(name);
48 T* ret = dynamic_cast<T*>(tmp);
49 return ret;
50 }
51
53 if(!qp_solver_map)
54 qp_solver_map = new QPSolverMap;
55 return qp_solver_map;
56 }
57
58 static void clear(){
59 qp_solver_map->clear();
60 }
61
62private:
63 static QPSolverMap *qp_solver_map;
64};
65
66template<typename T>
68 QPSolverRegistry(const std::string& name) {
69 QPSolverMap::iterator it = getQPSolverMap()->find(name);
70 if(it != getQPSolverMap()->end())
71 throw std::runtime_error("Failed to register plugin with name " + name + ". A plugin with the same name is already registered");
72 getQPSolverMap()->insert(std::make_pair(name, &createT<T>));
73 }
74};
75}
76
77#endif
Definition QPSolver.hpp:14
virtual ~QPSolver()
Definition QPSolver.cpp:8
bool configured
Definition QPSolver.hpp:16
virtual void solve(const HierarchicalQP &hierarchical_qp, base::VectorXd &solver_output)=0
solve Solve the given quadratic program
void reset()
reset Enforces reconfiguration at next call to solve()
Definition QPSolver.hpp:28
QPSolver()
Definition QPSolver.cpp:5
Definition ContactsAccelerationConstraint.cpp:3
QPSolver * createT()
Definition QPSolver.hpp:33
std::shared_ptr< QPSolver > QPSolverPtr
Definition QPSolver.hpp:31
Describes a hierarchy of quadratic programs.
Definition QuadraticProgram.hpp:57
Definition QPSolver.hpp:35
static T * createInstance(const std::string &name)
Definition QPSolver.hpp:46
static QPSolverMap * getQPSolverMap()
Definition QPSolver.hpp:52
std::map< std::string, QPSolver *(*)()> QPSolverMap
Definition QPSolver.hpp:36
static void clear()
Definition QPSolver.hpp:58
static QPSolver * createInstance(const std::string &name)
Definition QPSolver.hpp:38
Definition QPSolver.hpp:67
QPSolverRegistry(const std::string &name)
Definition QPSolver.hpp:68