ocra-recipes
Doxygen documentation for the ocra-recipes repository
LinearFunction.h
Go to the documentation of this file.
1 
13 #ifndef _OCRABASE_LINEAR_FUNCTION_H_
14 #define _OCRABASE_LINEAR_FUNCTION_H_
15 
16 // ocra includes
17 #include "ocra/optim/Function.h"
18 #include <ocra/util/Macros.h>
19 //#define LINEAR_FUNCTION_PROVIDES_HESSIANS
20 
26 namespace ocra
27 {
37  class LinearFunction : public Function
38  {
40  // ------------------------ structures --------------------------------------
41  public:
42  typedef Function functionType_t; //< alias on the type of the mother class. Needed to duplicate the function tree.
43 
44  // ------------------------ constructors ------------------------------------
45  private:
49  LinearFunction& operator=(const LinearFunction&);
51 
52  protected:
54  LinearFunction(Variable& x, int dimension);
55  public:
57  template<class Derived, class VectorBase>
58  LinearFunction(Variable& x, const MatrixBase<Derived>& A, const VectorBase& b);
60 
61  // ------------------------ public interface---------------------------------
62  public:
67  const MatrixXd& getA() const;
68  const VectorXd& getb() const;
69  void changeA(const MatrixXd& A);
70  void changeb(const VectorXd& b);
72 
74  void invalidateb(int timestamp);
75 
76  // ------------------------ protected methods -------------------------------
77  protected:
80  virtual void updateValue() const;
81  virtual void updateJacobian() const;
83 
85  virtual void updateb() const;
86 
89  virtual void doChangeA(const MatrixXd& A);
90  virtual void doChangeb(const VectorXd& b);
92 
96  virtual void doUpdateInputSizeEnd();
97 
103  void inhibitPropagationFromb() const;
104  void desinhibitPropagationFromb() const;
106 
107  // ------------------------ protected members -------------------------------
108  protected:
109  mutable VectorXd _b; //< the vecor b in Ax+b
110  mutable bool _bIsUpToDate; //< a boolean indicating the validity of _b
111 
112  private:
113  mutable bool _inhibitPropagationFromb; //< if true, invalidateb will not trigger an EVT_CHANGE_VALUE event
114  };
115 
116 
117  template<class Derived, class VectorBase>
118  inline LinearFunction::LinearFunction(Variable& x, const MatrixBase<Derived>& A, const VectorBase& b)
119  :NamedInstance("linear function")
121  ,CoupledInputOutputSize(false)
123  ,_bIsUpToDate(true)
124  ,_inhibitPropagationFromb(false)
125  {
127  ocra_assert(b.cols()==1);
128 
129  _b.resize(_dim);
130 
131  changeA(A); //non-forwarded virtual call ok here
132  changeb(b); //non-forwarded virtual call ok here
133  }
134 
135 
136  void testLinearFunction();
137 }
138 
139 #endif //_OCRABASE_LINEAR_FUNCTION_H_
140 
141 // cmake:sourcegroup=Function
virtual void doUpdateInputSizeEnd()
virtual void updateJacobian() const
void desinhibitPropagationFromb() const
virtual void doChangeb(const VectorXd &b)
virtual void doChangeA(const MatrixXd &A)
void changeA(const MatrixXd &A)
virtual void updateb() const
virtual void updateValue() const
Variable & x
Definition: Function.h:309
void changeb(const VectorXd &b)
LinearFunction class.
#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
const VectorXd & getb() const
void invalidateb(int timestamp)
This class represents a variable in a mathematical sense.
Definition: Variable.h:105
void inhibitPropagationFromb() const
const MatrixXd & getA() const
Declaration file of the Function class.
void testLinearFunction()
#define ocra_assert(ocra_expression)
Definition: ocra_assert.h:45
#define OCRA_STATIC_ASSERT_VECTOR_OR_DYNAMIC_MATRIX(TYPE)
Definition: MathTypes.h:31
const int & _dim
Definition: Function.h:320