ocra-recipes
Doxygen documentation for the ocra-recipes repository
NewtonSolver.h
Go to the documentation of this file.
1 
10 #ifndef _OCRABASE_NEWTON_SOLVER_H_
11 #define _OCRABASE_NEWTON_SOLVER_H_
12 
13 // includes
14 #include "Solver.h"
15 #include "ocra/optim/Buffer.h"
16 
17 namespace ocra
18 {
51  class NewtonSolver: public Solver
52  {
53  // ------------------------ structures --------------------------------------
54  public:
55  typedef Eigen::Map<MatrixXd> MatrixMap;
56  typedef Eigen::Map<VectorXd> VectorMap;
57 
58  struct eNewtonInfo
59  {
60  bool success;
63  bool smallAlpha;
64  int iter;
65  double residual;
66  };
67 
68  // ------------------------ constructors ------------------------------------
69  private:
70  NewtonSolver(const NewtonSolver&);
71  NewtonSolver& operator=(const NewtonSolver&);
72 
73  public:
74  NewtonSolver(bool fullNewton=true);
75 
76  // ------------------------ public interface --------------------------------
77  public:
83  void addObjective(GenericObjective& obj);
84  void removeObjective(Function& obj);
87 
88  void setAdaptativeAlpha(bool adapt);
89  bool getAdaptativeAlpha() const;
90  void setEpsilon(double eps);
91  double getEpsilon() const;
92  void setMaxIter(int maxIter);
93  int getMaxIter() const;
94  void set_x0(const VectorXd& x0);
95  const VectorXd& get_x0() const;
96 
97  void printValuesAtSolution();
98 
100  std::string toString();
101 
102  // ------------------------ protected methods -------------------------------
103  protected:
104  void doPrepare();
105  void doSolve();
106  void doConclude();
107 
108  // ------------------------ private methods ---------------------------------
109  private:
110  void initInfo();
111  void newtonSolve();
112  double compute_alpha();
113  void compute_H();
114  void compute_g();
115  void translateReturnInfo(eReturnInfo& orcInfo);
116 
117  // ------------------------ private members ---------------------------------
118  private:
119  bool _completeMethod;
120  bool _adaptativeAlpha;
121  int _maxIter;
122  double _alpha;
123  double _epsilonSqr;
124  //double _r;
125  std::vector<GenericObjective*> _objectives; //< set of objectives
126 
127  eNewtonInfo _info;
128 
129  VectorXd _x0;
130  VectorMap _x;
131  MatrixMap _H;
132  double* _tmpHbuf;
133  VectorMap _g;
134  double* _tmpgbuf;
135  VectorMap _p;
136  Buffer<double> _buffer;
137 
138  Eigen::LDLT<MatrixXd> _ldlt;
139 
140  };
141 
142  void testNewtonSolver01();
143  void testNewtonSolver02();
144 }
145 
146 #endif //_OCRABASE_NEWTON_SOLVER_H_
147 
148 // cmake:sourcegroup=Solvers
const VectorXd & get_x0() const
NewtonSolver class.
Definition: NewtonSolver.h:51
void printValuesAtSolution()
void testNewtonSolver01()
Eigen::Map< MatrixXd > MatrixMap
Definition: NewtonSolver.h:55
void set_x0(const VectorXd &x0)
std::string toString()
void setAdaptativeAlpha(bool adapt)
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Function class.
Definition: Function.h:77
void setEpsilon(double eps)
Eigen::Map< VectorXd > VectorMap
Definition: NewtonSolver.h:56
bool getAdaptativeAlpha() const
Declaration file of the Solver class.
int getMaxIter() const
void addObjective(GenericObjective &obj)
void testNewtonSolver02()
void setMaxIter(int maxIter)
void removeObjective(Function &obj)
double getEpsilon() const
Solver class.
Definition: Solver.h:70