ocra-recipes
Doxygen documentation for the ocra-recipes repository
CascadeQPSolver.h
Go to the documentation of this file.
1 
10 #ifndef _OCRABASE_CASCADE_QP_SOLVER_H_
11 #define _OCRABASE_CASCADE_QP_SOLVER_H_
12 
13 // includes
14 #include "ocra/optim/Solver.h"
16 #include "ocra/optim/Constraint.h"
19 #include "ocra/control/Task.h"
25 
26 #include <memory>
27 #include <map>
28 
34 namespace ocra
35 {
36 
37 /*
38 struct LevelConstraints
39 {
40  std::vector<Function*> _exclusion_constraints;
41  std::map<Function*,EqualZeroConstraintPtr<LinearFunction> > _allowed_constraints;
42 };
43 
44 class HierarchyConstraints
45 {
46  HierarchyConstraints(int level):_level(level){}
47  std::map<int,LevelConstraints> _level_constraints;
48 private:
49  const int _level;
50 };
51 */
58 {
59  static bool has_element(std::vector<const ocra::Function*>& v,const ocra::Function* e)
60  {
61  return std::find(v.begin(),v.end(),e) != v.end();
62  }
63 
64 public:
66 
67  CascadeQPSolver(const std::string& _ctrlName,
68  Model::Ptr _innerModel,
69  OneLevelSolver::Ptr _levelSolver,
70  bool _useReducedProblem);
71 
72  void addTask(Task::Ptr task);
73  void addSolver(OneLevelSolver::Ptr solver,int level);
74  OneLevelSolver::Ptr getSolver(int level);
75  virtual std::string toString();
76  const std::map<int,OneLevelSolver::Ptr >& getSolvers();
77  void updateHierarchicalContraints(int level);
78  int getNumberOfLevelsAbove(int current_level);
79 protected:
80  virtual void doSolve(void);
81  virtual void doPrepare(void);
82  virtual void doConclude();
83  virtual void printValuesAtSolution();
84  void excludeObjective(int at_level, const ocra::GenericObjective& obj);
86  std::shared_ptr<StandardObjectivesAndConstraints> own_obj;
87  std::vector<int> solverInitialized;
88  std::map<int,std::shared_ptr<StandardObjectivesAndConstraints> > std_obj;
89  OneLevelSolver::Ptr levelSolver;
91  Model::Ptr innerModel;
92 
93 private:
94  // NOTE : For each level, it contains a list of the n-1 * m constraints ( Each level can have m tasks, so we need to add m constraints from that level)
95  std::map<int, std::map<int,std::map<Function*,EqualZeroConstraintPtr<LinearFunction> > > > levelConstraints;
96  std::map<int, std::vector<const Function*> > _exclusion_constraints;
97  std::map<int,OneLevelSolver::Ptr > solvermap;
98  std::map<int,std::vector<Task::Ptr> > taskmap;
99  int highest_hierarchy_level;
100 };
101 }
102 
103 #endif //_OCRABASE_CASCADE_QP_SOLVER_H_
OneLevelSolver::Ptr levelSolver
virtual void doPrepare(void)
virtual void printValuesAtSolution()
int getNumberOfLevelsAbove(int current_level)
void excludeObjective(int at_level, const ocra::GenericObjective &obj)
Define the internal solver class that can be used in the wOcra controller.
std::shared_ptr< StandardObjectivesAndConstraints > own_obj
CascadeQPSolver(const std::string &_ctrlName, Model::Ptr _innerModel, OneLevelSolver::Ptr _levelSolver, bool _useReducedProblem)
#define DEFINE_CLASS_POINTER_TYPEDEFS(Class)
Definition: Macros.h:8
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Function class.
Definition: Function.h:77
Declaration file of the LinearFunction class.
OneLevelSolver::Ptr getSolver(int level)
Declaration file of the Solver class.
Declaration file of the Constraint class.
virtual void doSolve(void)
std::map< int, std::shared_ptr< StandardObjectivesAndConstraints > > std_obj
void updateHierarchicalContraints(int level)
Declaration file of the structures needed in CascadeQP.
Define base class that can be used as constraints in wOcra controller.
void addTask(Task::Ptr task)
Solver class.
Definition: Solver.h:70
std::vector< int > solverInitialized
void addSolver(OneLevelSolver::Ptr solver, int level)
Define base class that can be used as constraints in wOcra controller.
virtual std::string toString()
Declaration file of the QuadraticFunction class.
const std::map< int, OneLevelSolver::Ptr > & getSolvers()
CascadeQPSolver class.