ocra-recipes
Doxygen documentation for the ocra-recipes repository
QuadraticFunction.h
Go to the documentation of this file.
1 
10 #ifndef _OCRA_QUADRATIC_FUNCTION_H_
11 #define _OCRA_QUADRATIC_FUNCTION_H_
12 
13 // includes
14 #include "ocra/optim/Function.h"
15 #include "ocra/optim/ocra_assert.h"
16 #include <ocra/util/Macros.h>
17 
23 namespace ocra
24 {
32  class QuadraticFunction : public Function
33  {
35  // ------------------------ structures --------------------------------------
36  public:
37  typedef Function functionType_t; //< alias on the type of the mother class. Needed to duplicate the function tree.
38 
39  // ------------------------ constructors ------------------------------------
40  private:
46 
47  protected:
49  QuadraticFunction(Variable& x, int dimension = 1);
50 
51  public:
53  template<class Derived, class VectorBase>
54  QuadraticFunction(Variable& x, const MatrixBase<Derived>& P, const VectorBase& q, double r) //unidimensional constant form
55  : NamedInstance("QuadraticFunction")
59  , false //not time dependant
60  , true) //thus time separable
61  ,_qIsUpToDate(true)
62  ,_rIsUpToDate(true)
63  ,_inhibitPropagationFrom_q_or_r(false)
64  {
65  _q.push_back(new VectorXd);
66  _r.resize(1);
67  changePi(P);
68  changeqi(q);
69  changeri(r);
70  }
71 
72  virtual ~QuadraticFunction();
73 
74  // ------------------------ public interface --------------------------------
75  public:
76  const MatrixXd& getPi(int index = 0) const;
77  const VectorXd& getqi(int index = 0) const;
78  double getri(int index = 0) const;
79  const VectorXd& getr() const;
80 
81  void changePi(const MatrixXd& Pi, int index = 0);
82  void changeqi(const VectorXd& qi, int index = 0);
83  void changeri(double ri, int index = 0);
84 
85  // ------------------------ protected methods -------------------------------
86  protected:
87  virtual void updateValue() const;
88  virtual void updateJacobian() const;
89  virtual void updateHessian() const;
90 
91  virtual void updateq() const;
92  virtual void updater() const;
93 
94  virtual void doUpdateInputSizeEnd();
95 
96  virtual void doUpdateDimensionEnd(int oldDimension);
97 
98  virtual void doChangePi(const MatrixXd& Pi, int index);
99  virtual void doChangeqi(const VectorXd& qi, int index);
100  virtual void doChangeri(double ri, int index);
101 
102  void invalidateq(int timestamp);
103  void invalidater(int timestamp);
104 
110  void inhibitPropagationFrom_q_or_r() const;
113 
114  // ------------------------ protected members -------------------------------
115  protected:
116  mutable std::vector<VectorXd*> _q;
117  mutable VectorXd _r;
118  mutable bool _qIsUpToDate;
119  mutable bool _rIsUpToDate;
120 
121  private:
122  mutable bool _inhibitPropagationFrom_q_or_r;
123  };
124 
125 
126  inline const MatrixXd& QuadraticFunction::getPi(int index) const
127  {
128  ocra_assert(index <_dim);
129  return get<PARTIAL_XX>(index);
130  }
131 
132  inline const VectorXd& QuadraticFunction::getqi(int index) const
133  {
134  ocra_assert(index <_dim);
135  if (!_qIsUpToDate)
136  {
137  updateq();
138  _qIsUpToDate = true;
139  }
140  return *_q[index];
141  }
142 
143  inline double QuadraticFunction::getri(int index) const
144  {
145  return getr()[index];
146  }
147 
148  inline const VectorXd& QuadraticFunction::getr() const
149  {
150  if (!_rIsUpToDate)
151  {
152  updater();
153  _rIsUpToDate = true;
154  }
155  return _r;
156  }
157 
158 
159  void testQuadraticFunction();
160 }
161 
162 #endif //_OCRA_QUADRATIC_FUNCTION_H_
163 
164 // cmake:sourcegroup=Function
virtual void updater() const
void invalidateq(int timestamp)
virtual void doChangeqi(const VectorXd &qi, int index)
void inhibitPropagationFrom_q_or_r() const
void changePi(const MatrixXd &Pi, int index=0)
Variable & x
Definition: Function.h:309
virtual void doChangePi(const MatrixXd &Pi, int index)
void testQuadraticFunction()
virtual void updateq() const
virtual void updateValue() const
virtual void doChangeri(double ri, int index)
#define DEFINE_CLASS_POINTER_TYPEDEFS(Class)
Definition: Macros.h:8
virtual void updateJacobian() const
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
Function class.
Definition: Function.h:77
virtual void doUpdateInputSizeEnd()
const VectorXd & getqi(int index=0) const
void changeqi(const VectorXd &qi, int index=0)
std::vector< VectorXd * > _q
This class represents a variable in a mathematical sense.
Definition: Variable.h:105
void desinhibitPropagationFrom_q_or_r() const
const MatrixXd & getPi(int index=0) const
virtual void updateHessian() const
void changeri(double ri, int index=0)
QuadraticFunction(Variable &x, const MatrixBase< Derived > &P, const VectorBase &q, double r)
double getri(int index=0) const
Declaration file of the Function class.
void invalidater(int timestamp)
const VectorXd & getr() const
#define ocra_assert(ocra_expression)
Definition: ocra_assert.h:45
QuadraticFunction class.
virtual void doUpdateDimensionEnd(int oldDimension)
const int & _dim
Definition: Function.h:320