ocra-recipes
Doxygen documentation for the ocra-recipes repository
Function.h
Go to the documentation of this file.
1 
15 #ifndef _OCRABASE_FUNCTION_H_
16 #define _OCRABASE_FUNCTION_H_
17 
18 
19 
20 //ocra includes
21 
22 #include "ocra/optim/IFunction.h"
24 #include "ocra/optim/AbilitySet.h"
26 #include "ocra/optim/Variable.h"
29 
30 
31 
37 namespace ocra
38 {
77  class Function
78  : public ObserverSubject
79  , public IFunctionProperties
81  , virtual public NamedInstance
82  , virtual public AbilitySet
83  , virtual public CoupledInputOutputSize
84  {
85  // ------------------------ constructors --------------------------------------
86  protected:
102  Function(Variable& x, int dimension, eFunctionLinearity linearity = LINEARITY_UNDEFINED,
103  eFunctionConvexity convexity = CONVEXITY_UNDEFINED, int continuity = CONTINUITY_UNKNOWN,
104  bool explicitlyTimeDependant=false, bool separableTimeDependancy = true);
105 
106  public:
107  virtual ~Function();
108 
109  protected:
114  void disconnectVariable();
115 
116  private:
119  Function(const Function&);
120  Function& operator= (const Function&);
122 
123 
124  // ------------------------ public interface ----------------------------------
125  public:
127  int getDimension() const;
128 
131  const Variable& getVariable() const;
133 
135  template<eFunctionAbility Ability>
136  void invalidate();
137 
139  void invalidateAll(int timestamp);
140  void invalidateAll();
141 
143  template<eFunctionAbility Ability>
144  bool isValid() const;
145 
147  template<eFunctionAbility Ability>
148  bool canCompute() const;
149 
169  template<eFunctionAbility Ability>
170  const typename IFunction<Ability>::return_type& get() const;
171 
172 
183  template<eFunctionAbility Ability>
184  typename IFunction<Ability>::return_sub_type get(int index) const;
185 
189  const VectorXd& getValue() const;
190 
194  double getValue(int index) const;
195 
197  const MatrixXd& getJacobian() const;
198 
202  MatrixXdRow getJacobian(int index) const;
204 
205 
206  // ------------------------ public methods ------------------------------------
207  public:
217  virtual void updateFdot() const;
218 
228  virtual void updateFddot() const;
229 
235  virtual void updateJdotXdot() const;
236 
237  // ------------------------ protected methods ---------------------------------
238  protected:
256  void changeFunctionDimension(int newDimension);
257 
269  void updateInputSize(int timestamp);
270 
276  void resize();
277 
285  virtual void doUpdateInputSizeBegin();
286  virtual void doUpdateInputSizeEnd();
288 
296  virtual void doUpdateDimensionBegin(int newDimension);
297  virtual void doUpdateDimensionEnd(int oldDimension);
299 
301  virtual int computeDimensionFromInputSize() const;
302 
303  // ------------------------ private methods -----------------------------------
304  private:
305  void changeFunctionDimensionImpl(int newDimension);
306 
307  // ------------------------ protected members ---------------------------------
308  protected:
309  Variable& x; //< the variable x
310 
311  //Shortcuts
312  VectorXd& _value; //< alias on IFunction<FUN_VALUE>::_val
313  MatrixXd& _jacobian; //< alias on IFunction<PARTIAL_X>::_val
314 
315  private:
316  int _dimension; //< the dimension of the image space (m in the class description)
317  bool _hasDisconnected; //< see error prone design(tm) method disconnectVariable
318 
319  protected:
320  const int& _dim; //< alias on the dimension for easy (read-only) acces by derived class
321 
322  };
323 
324  template<eFunctionAbility Ability>
325  inline void Function::invalidate()
326  {
328  }
329 
331  {
333  }
334 
335  inline void Function::invalidateAll(int)
336  {
337  invalidateAll();
338  }
339 
340  template<eFunctionAbility Ability>
341  inline bool Function::isValid() const
342  {
344  }
345 
346  template<eFunctionAbility Ability>
347  inline bool Function::canCompute() const
348  {
350  }
351 
352  template< eFunctionAbility Ability>
353  inline const typename IFunction<Ability>::return_type& Function::get() const
354  {
355  return IFunction<Ability>::get(*this);
356  }
357 
358  template< eFunctionAbility Ability>
359  inline typename IFunction<Ability>::return_sub_type Function::get(int index) const
360  {
361  return IFunction<Ability>::get(*this, index);
362  }
363 
364 
365  inline const VectorXd& Function::getValue() const
366  {
367  return IFunction<FUN_VALUE>::get(*this);
368  }
369 
370  inline double Function::getValue(int index) const
371  {
372  return IFunction<FUN_VALUE>::get(*this, index);
373  }
374 
375  inline const MatrixXd& Function::getJacobian() const
376  {
377  return IFunction<PARTIAL_X>::get(*this);
378  }
379 
380  inline MatrixXdRow Function::getJacobian(int index) const
381  {
382  return IFunction<PARTIAL_X>::get(*this, index);
383  }
384 }
385 
386 void testFunction();
387 
388 #endif //_OCRABASE_FUNCTION_H_
389 
390 // cmake:sourcegroup=Function
const Variable & getVariable() const
Definition: Function.cpp:46
void invalidate()
Definition: Function.h:325
virtual int computeDimensionFromInputSize() const
Definition: Function.cpp:103
int getDimension() const
Definition: Function.cpp:41
VectorXd & _value
Definition: Function.h:312
virtual void updateFdot() const
Definition: Function.cpp:119
Variable & x
Definition: Function.h:309
ocra_function_traits< Property >::sub_type_t return_sub_type
Definition: IFunction.h:282
virtual void doUpdateDimensionBegin(int newDimension)
Definition: Function.cpp:109
const return_type & get(FunctionType &data) const
Definition: IFunction.h:322
bool isValid() const
Definition: IFunction.h:290
virtual ~Function()
Definition: Function.cpp:27
void disconnectVariable()
Definition: Function.cpp:31
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
ocra_function_traits< Property >::type_t return_type
Definition: IFunction.h:281
virtual void updateFddot() const
Definition: Function.cpp:130
virtual void doUpdateDimensionEnd(int oldDimension)
Definition: Function.cpp:114
Function class.
Definition: Function.h:77
MatrixXd & _jacobian
Definition: Function.h:313
bool isValid() const
Definition: Function.h:341
const IFunction< Ability >::return_type & get() const
Definition: Function.h:353
virtual void doUpdateInputSizeEnd()
Definition: Function.cpp:98
const MatrixXd & getJacobian() const
Definition: Function.h:375
bool canCompute() const
Definition: Function.h:347
void resize()
Definition: Function.cpp:86
Function(Variable &x, int dimension, eFunctionLinearity linearity=LINEARITY_UNDEFINED, eFunctionConvexity convexity=CONVEXITY_UNDEFINED, int continuity=CONTINUITY_UNKNOWN, bool explicitlyTimeDependant=false, bool separableTimeDependancy=true)
Function Constructor.
Definition: Function.cpp:6
This class represents a variable in a mathematical sense.
Definition: Variable.h:105
const VectorXd & getValue() const
Definition: Function.h:365
#define OCRA_APPLY_FUNCTION_ON_ALL_INTERFACE(methodAndArgs)
Definition: IFunction.h:412
#define OCRA_FUNCTION_INTERFACE_INHERITANCE(inheritanceAccessRight)
Definition: IFunction.h:403
bool canBeComputed() const
Definition: IFunction.h:293
Eigen::DenseBase< MatrixXd >::ConstRowXpr MatrixXdRow
Definition: MathTypes.h:29
void changeFunctionDimension(int newDimension)
Definition: Function.cpp:56
void invalidateAll()
Definition: Function.h:330
void invalidate()
Definition: IFunction.h:287
void testFunction()
Definition: Function.cpp:184
virtual void doUpdateInputSizeBegin()
Definition: Function.cpp:93
virtual void updateJdotXdot() const
Definition: Function.cpp:145
Declaration file of the Variable class.
Declaration file of the Observer, Subject and ObserverSubject classes.
const int & _dim
Definition: Function.h:320
Declaration file of the IFunction interface.
void updateInputSize(int timestamp)
Definition: Function.cpp:71