ocra-recipes
Doxygen documentation for the ocra-recipes repository
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ocra::Function Class Reference

Function class. More...

#include <Function.h>

Inheritance diagram for ocra::Function:
[legend]
Collaboration diagram for ocra::Function:
[legend]

Public Member Functions

virtual ~Function ()
 
int getDimension () const
 
virtual void updateFdot () const
 
virtual void updateFddot () const
 
virtual void updateJdotXdot () const
 
const VariablegetVariable () const
 
VariablegetVariable ()
 
template<eFunctionAbility Ability>
void invalidate ()
 
void invalidateAll (int timestamp)
 
void invalidateAll ()
 
template<eFunctionAbility Ability>
bool isValid () const
 
template<eFunctionAbility Ability>
bool canCompute () const
 
template<eFunctionAbility Ability>
const IFunction< Ability >::return_type & get () const
 
template<eFunctionAbility Ability>
IFunction< Ability >::return_sub_type get (int index) const
 
const VectorXd & getValue () const
 
double getValue (int index) const
 
const MatrixXd & getJacobian () const
 
MatrixXdRow getJacobian (int index) const
 
- Public Member Functions inherited from ocra::ObserverSubject
 ObserverSubject ()
 
virtual ~ObserverSubject ()
 
- Public Member Functions inherited from ocra::Observer
virtual ~Observer ()
 
template<int EVT>
void bind (SubjectBase< EVT > &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 
template<int EVT>
void stopPropagation ()
 
- Public Member Functions inherited from ocra::ObserverBase< EVT_RESIZE >
void bind (subject_type &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 
- Public Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_DEPENDENCIES >
void bind (subject_type &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 
- Public Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_VALUE >
void bind (subject_type &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 
- Public Member Functions inherited from ocra::Subject
virtual ~Subject ()
 
template<int EVT, class Derived , class Base >
void connect (Derived &object, void(Base::*newCallback)(int)) const
 Call this method to register a non-static method as a callback. More...
 
template<int EVT>
void connect (void(*newCallback)(int)) const
 Call this method to register a free function as a callback. More...
 
template<int EVT, class Derived , class Base >
void disconnect (Derived &object, void(Base::*callbackToErase)(int)) const
 Disconnect non-static method. More...
 
template<int EVT>
void disconnect (void(*callbackToErase)(int)) const
 Disconnect free function. More...
 
template<int EVT>
void propagate () const
 
template<int EVT>
void propagate (int timestamp) const
 
- Public Member Functions inherited from ocra::SubjectBase< EVT_RESIZE >
void connect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const
 Call this method to register a non-static method as a callback. More...
 
void connect (typename SubjectBaseTraits< EVT, void >::callback_type newCallback) const
 Call this method to register a free function as a callback. More...
 
void disconnect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const
 Disconnect non-static method. More...
 
void disconnect (typename SubjectBaseTraits< EVT, void >::callback_type callbackToErase) const
 Disconnect free function. More...
 
void propagate (int timestamp) const
 
void propagate () const
 
- Public Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_DEPENDENCIES >
void connect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const
 Call this method to register a non-static method as a callback. More...
 
void connect (typename SubjectBaseTraits< EVT, void >::callback_type newCallback) const
 Call this method to register a free function as a callback. More...
 
void disconnect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const
 Disconnect non-static method. More...
 
void disconnect (typename SubjectBaseTraits< EVT, void >::callback_type callbackToErase) const
 Disconnect free function. More...
 
void propagate (int timestamp) const
 
void propagate () const
 
- Public Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_VALUE >
void connect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const
 Call this method to register a non-static method as a callback. More...
 
void connect (typename SubjectBaseTraits< EVT, void >::callback_type newCallback) const
 Call this method to register a free function as a callback. More...
 
void disconnect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const
 Disconnect non-static method. More...
 
void disconnect (typename SubjectBaseTraits< EVT, void >::callback_type callbackToErase) const
 Disconnect free function. More...
 
void propagate (int timestamp) const
 
void propagate () const
 
- Public Member Functions inherited from ocra::IFunctionProperties
bool hasSeparableTimeDependancy (void) const
 
eFunctionLinearity getType (void) const
 
eFunctionConvexity getConvexityProperty (void) const
 
int getContinuityProperty (void) const
 
const std::string & getProperty (int i) const
 
int getNumberOfProperties (void) const
 
bool hasProperty (const std::string &functionProperty) const
 
bool isExplicitlyTimeDependant (void) const
 
- Public Member Functions inherited from ocra::NamedInstance
 NamedInstance (const std::string &name)
 
const std::string & getName () const
 
virtual ~NamedInstance ()
 
- Public Member Functions inherited from ocra::AbilitySet
AbilitySetadd (eFunctionAbility prop)
 
AbilitySetremove (eFunctionAbility prop)
 

Protected Member Functions

 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. More...
 
void disconnectVariable ()
 
void changeFunctionDimension (int newDimension)
 
void updateInputSize (int timestamp)
 
void resize ()
 
virtual int computeDimensionFromInputSize () const
 
virtual void doUpdateInputSizeBegin ()
 
virtual void doUpdateInputSizeEnd ()
 
virtual void doUpdateDimensionBegin (int newDimension)
 
virtual void doUpdateDimensionEnd (int oldDimension)
 
- Protected Member Functions inherited from ocra::ObserverBase< EVT_RESIZE >
void stopPropagation ()
 Call this method from your callbacks to avoid propagation to the bound subject (if any). More...
 
 ObserverBase ()
 
 ~ObserverBase ()
 
- Protected Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_DEPENDENCIES >
void stopPropagation ()
 Call this method from your callbacks to avoid propagation to the bound subject (if any). More...
 
 ObserverBase ()
 
 ~ObserverBase ()
 
- Protected Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_VALUE >
void stopPropagation ()
 Call this method from your callbacks to avoid propagation to the bound subject (if any). More...
 
 ObserverBase ()
 
 ~ObserverBase ()
 
- Protected Member Functions inherited from ocra::SubjectBase< EVT_RESIZE >
 SubjectBase ()
 
 ~SubjectBase ()
 
- Protected Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_DEPENDENCIES >
 SubjectBase ()
 
 ~SubjectBase ()
 
- Protected Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_VALUE >
 SubjectBase ()
 
 ~SubjectBase ()
 
- Protected Member Functions inherited from ocra::IFunctionProperties
 IFunctionProperties (eFunctionLinearity linearity=LINEARITY_UNDEFINED, eFunctionConvexity convexity=CONVEXITY_UNDEFINED, int continuity=CONTINUITY_UNKNOWN, bool explicitlyTimeDependant=false, bool separableTimeDependancy=true)
 IFunctionProperties Constructor. More...
 
void changeType (eFunctionLinearity newType)
 
void changeConvexityProperty (eFunctionConvexity newProperty)
 
void changeContinuityProperty (int newProperty)
 
void addProperty (const std::string &functionProperty)
 
void removeProperty (const std::string &functionProperty)
 
void changeExplicitTimeDependancy (bool b)
 
void changeSeparableTimeDependancy (bool b)
 
- Protected Member Functions inherited from ocra::AbilitySet
 AbilitySet (const std::vector< bool > &usageSet)
 
const std::vector< bool > & getUsageSet () const
 
 AbilitySet (eFunctionAbility prop0=FUN_VALUE, eFunctionAbility prop1=FUN_VALUE)
 
 AbilitySet (eFunctionAbility prop0, eFunctionAbility prop1, eFunctionAbility prop2, eFunctionAbility prop3=FUN_VALUE, eFunctionAbility prop4=FUN_VALUE)
 
 AbilitySet (eFunctionAbility prop0, eFunctionAbility prop1, eFunctionAbility prop2, eFunctionAbility prop3, eFunctionAbility prop4, eFunctionAbility prop5, eFunctionAbility prop6=FUN_VALUE, eFunctionAbility prop7=FUN_VALUE, eFunctionAbility prop8=FUN_VALUE, eFunctionAbility prop9=FUN_VALUE)
 
- Protected Member Functions inherited from ocra::CoupledInputOutputSize
 CoupledInputOutputSize (bool coupledInputOutputSize)
 
bool inputAndOutputSizesAreCoupled () const
 

Protected Attributes

Variablex
 
VectorXd & _value
 
MatrixXd & _jacobian
 
const int & _dim
 

Additional Inherited Members

- Protected Types inherited from ocra::ObserverBase< EVT_RESIZE >
typedef SubjectBase< EVT > subject_type
 
typedef InvokerBase< EVT > invoker_type
 
- Protected Types inherited from ocra::ObserverBase< EVT_CHANGE_DEPENDENCIES >
typedef SubjectBase< EVT > subject_type
 
typedef InvokerBase< EVT > invoker_type
 
- Protected Types inherited from ocra::ObserverBase< EVT_CHANGE_VALUE >
typedef SubjectBase< EVT > subject_type
 
typedef InvokerBase< EVT > invoker_type
 

Detailed Description

Function class.

Author
Escande Adrien
Warning
None

Base class for a function $ f_A $ defined as follows: $x$ is time-dependant n-dimensional variable living in $R^n$, A is a set of (possibly changing) parameters. $ f_A $ is a function of $x$ with a possible explicit time dependency. Thus we have $ f_A : R^n \times R \rightarrow R^m $, with $ f_A(x,t) = (f_{1_A}(x,t), \cdots, f_{m_A}(x,t))^T $ The set of parameters is considered to be constant with respect to the time on a mathematical point of view, yet the user can change it anytime. Although $ f $ might be explicitly time-dependant, no interfaces are given at this level to specify the value of variable $ t $. This responsibility is transfered to the derived classes.

Function inherits from several IFunction, each of which comes with a virtual method that need to be overloaded if the corresponding ability is used. Below is the list of abilities with the corresponding methods and return types. In case of doubt or out-of-date documentation, please see the use of the macro DECLARE_FUNCTION_TRAITS in IFunction.h. For the most usual abilities, some shortcuts are implemented to ease both programming and reading.

Ability return type virtual update method buffer alias getter alias FUN_VALUE VectorXd updateValue _value getValue PARTIAL_X MatrixXd updateJacobian _jacobian getJacobian PARTIAL_T VectorXd updatePartialT FUN_DOT VectorXd updateFdot PARTIAL_X_DOT MatrixXd updateJdot PARTIAL_XX std::vector<MatrixXd*> updateHessian FUN_DDOT VectorXd updateFddot PARTIAL_TT VectorXd updatePartialTT PARTIAL_TX MatrixXd updatePartialTX PARTIAL_XT MatrixXd updatePartialXT PARTIAL_T_DOT VectorXd updatePartialTdot PARTIAL_X_DOT_X_DOT VectorXd updateJdotXdot

[Please UPDATE if you add abilities]

Function also inherits from IFunctionProperties and as such is given an interface of trivial getters and setters which don't appear here.

See also
IFunctionProperty

Definition at line 77 of file Function.h.

Constructor & Destructor Documentation

ocra::Function::Function ( Variable x,
int  dimension,
eFunctionLinearity  linearity = LINEARITY_UNDEFINED,
eFunctionConvexity  convexity = CONVEXITY_UNDEFINED,
int  continuity = CONTINUITY_UNKNOWN,
bool  explicitlyTimeDependant = false,
bool  separableTimeDependancy = true 
)
protected

Function Constructor.

Parameters
[in]xThe time-dependant variable on which f is defined.
[in]dimensionThe dimension of the output space, m in the description of the class.
[in]linearityLinearity property of the function.
[in]convexityConvexity property of the function.
[in]continuityContinuity property of the function.
[in]explicitlyTimeDependant
[in]separableTimeDependancy
[in]use[SomeAbility]Indicates wether the function must perform memory allocation and computation for the corresponding ability.
Precondition
(continuity==CONTINUITY_UNKNOWN) || (continuity>0 && continuity<=CONTINUITY_CINF)

Definition at line 6 of file Function.cpp.

ocra::Function::~Function ( )
virtual

Definition at line 27 of file Function.cpp.

Member Function Documentation

template<eFunctionAbility Ability>
bool ocra::Function::canCompute ( ) const
inline

return true if the corresponding ability is enabled

Definition at line 347 of file Function.h.

void ocra::Function::changeFunctionDimension ( int  newDimension)
protected

Changes the dimension of the function to newDimension. This changes the value of _dimension by performing the following actions:

This method calls doUpdateDimensionBegin before executing its core and doUpdateDimensionEnd after. These virtual methods might throw exceptions depending on their overloaded implementation. By default, doUpdateSizeBegin throws a runtime_error: the programmer of a new function needs to overloaded it if his/her function supports function resizing.

Postcondition
Each IFunction<Ability>::_validated must be false.

Definition at line 56 of file Function.cpp.

int ocra::Function::computeDimensionFromInputSize ( ) const
protectedvirtual

Does what it tells...

Reimplemented in ocra::DiagonalLinearFunction, and ocra::DoubleDiagonalLinearFunction.

Definition at line 103 of file Function.cpp.

void ocra::Function::disconnectVariable ( )
protected

Call this method before deleting, if needed, the variable &x in any child classes. Else it's automatically called in ~Function. Error prone design inside(tm)

Definition at line 31 of file Function.cpp.

void ocra::Function::doUpdateDimensionBegin ( int  newDimension)
protectedvirtual

Methods for pre and post update in case the dimension of the function has changed. Default implementation of doUpdateDimensionEnd does nothing, doUpdateDimensionBegin throws an exception. These methods might throw exceptions when overloaded. Furthermore, doUpdateDimensionEnd() must comply with the post condition of updateDimension(), i.e. let the values of each ability invalidated.

Reimplemented in ocra::DiagonalLinearFunction, ocra::ContactAvoidanceFunction, ocra::DoubleDiagonalLinearFunction, and ocra::LinearTask.

Definition at line 109 of file Function.cpp.

void ocra::Function::doUpdateDimensionEnd ( int  oldDimension)
protectedvirtual

Reimplemented in ocra::ContactAvoidanceFunction, ocra::QuadraticFunction, and ocra::LinearTask.

Definition at line 114 of file Function.cpp.

void ocra::Function::doUpdateInputSizeBegin ( )
protectedvirtual

Methods for pre and post update in case the variable size has changed. Default implementation of doUpdateInputSizeEnd does nothing, doUpdateInputSizeBegin throws an exception. These methods might throw exceptions when overloaded. Furthermore, doUpdateInputSizeEnd() must comply with the post condition of updateInputSize(), i.e. let the values of each ability invalidated.

Reimplemented in Function3, Function2, ocra::DiagonalLinearFunction, ocra::DoubleDiagonalLinearFunction, ocra::LinearTask, ocra::WeightedSquareDistanceFunction, ocra::SquaredLinearFunction, Function1, ocra::FullDynamicEquationFunction, ocra::DynamicEquationFunction, ocra::IdentityFunction, ocra::SumOfLinearFunctions, ocra::FcQuadraticFunction, and ocra::VariableChiFunction.

Definition at line 93 of file Function.cpp.

void ocra::Function::doUpdateInputSizeEnd ( void  )
protectedvirtual
template<eFunctionAbility Ability>
const IFunction< Ability >::return_type & ocra::Function::get ( ) const
inline

Get the value of the quantity corresponding to the function ability specified by Ability. This value is recomputed if needed in a transparent way for the user.

Template Parameters
AbilityThe label of the ability
Precondition
IFunction<Ability>::canBeComputed()==true. If this is not the case, no physical memory is allocated for the corresponding memory buffer and computation will fail or worse result in a buffer overflow.

Throws std::runtime_error if the virtual update method has not been overloaded for this ability.

For performance reasons, no exceptions are thrown when this method is called for an ability which is not used. A high-level usage should make its own check by calling first IFunction<Ability>::canBeComputed.

For example, get<PARTIAL_TX>() returns $ \frac{\partial^2 f}{\partial t \partial x}$ computed at the current (x,t).

For some abilities, there exist aliases.

See also
getValue(), getJacobian()

Definition at line 353 of file Function.h.

template<eFunctionAbility Ability>
IFunction< Ability >::return_sub_type ocra::Function::get ( int  index) const
inline

Get a subpart of the value of the quantity corresponding to the function ability specified by Ability. This value is recomputed if needed in a transparent way for the user.

Template Parameters
AbilityThe label of the ability.
Parameters
[in]indexThe index of the subpart of the value (corresponding to f_index).

For example, get<PARTIAL_X>(i) returns $ \frac{\partial f_i}{\partial x}$ computed at the current (x,t).

See also
get()

Definition at line 359 of file Function.h.

int ocra::Function::getDimension ( ) const

get the dimension m of the output space

Definition at line 41 of file Function.cpp.

const MatrixXd & ocra::Function::getJacobian ( ) const
inline

return the jacobian of the function at the current (x,t). Synonym for get<PARTIAL_X>()

Definition at line 375 of file Function.h.

MatrixXdRow ocra::Function::getJacobian ( int  index) const
inline

return the ith component of the jacobian of the function at the current (x,t). Synonym for get<PARTIAL_X>(index)

Definition at line 380 of file Function.h.

const VectorXd & ocra::Function::getValue ( ) const
inline

aliases return the value of the function at the current (x,t). Synonym for get<FUN_VALUE>()

Definition at line 365 of file Function.h.

double ocra::Function::getValue ( int  index) const
inline

return the ith component of the value of the function at the current (x,t). Synonym for get<FUN_VALUE>(index)

Definition at line 370 of file Function.h.

const Variable & ocra::Function::getVariable ( ) const

get the variable x on which the function is defined

Definition at line 46 of file Function.cpp.

Variable & ocra::Function::getVariable ( )

Definition at line 51 of file Function.cpp.

template<eFunctionAbility Ability>
void ocra::Function::invalidate ( )
inline

invalidate the value of the corresponding ability

Definition at line 325 of file Function.h.

void ocra::Function::invalidateAll ( int  timestamp)
inline

invalidate the value of each ability

Definition at line 335 of file Function.h.

void ocra::Function::invalidateAll ( )
inline

Definition at line 330 of file Function.h.

template<eFunctionAbility Ability>
bool ocra::Function::isValid ( ) const
inline

check the validity of the value of the corresponding ability

Definition at line 341 of file Function.h.

void ocra::Function::resize ( )
protected

Core of updateInputSize() and Update the size of the memory buffers according to the size of the input variable and the dimension m of the function. Only the buffers corresponding to used ability are resized. This implies that their values are invalidated.

Definition at line 86 of file Function.cpp.

void ocra::Function::updateFddot ( ) const
virtual

Generic implentation of updateFddot.

Precondition
The first and second time-derivative of the variable exist.
Values partial_X and partial_X_DOT needs to be computable.
Values partial_XT and partialTT needs to be computable if the function depends explicitly on time.

This is not an optimal implementation in case it is known wether the function depends explicitly on time or not. A test is indeed performed at runtime to decide which computations need to be done.

Definition at line 130 of file Function.cpp.

void ocra::Function::updateFdot ( ) const
virtual

Generic implementation of updateFdot.

Precondition
The first time derivative of the variable exists.
Value partial_X needs to be computable.
Value partial_T needs to be computable if the function depends explicitly on time.

This is not an optimal implementation in case it is known wether the function depends explicitly on the time or not. A test is indeed performed at runtime to decide which computations need to be done.

Reimplemented in MyFunction.

Definition at line 119 of file Function.cpp.

void ocra::Function::updateInputSize ( int  timestamp)
protected

Update the size of the memory buffers according to the size of the input variable and the current dimension m of the function. Only the buffers corresponding to used abilities are resized. This implies that their values are invalidated. This method is automaticaly invoked when the function variable x is resized.

This method calls doUpdateSizeBegin before executing its core and doUpdateSizeEnd after. These virtual methods might throw exceptions depending on their overloaded implementation. By default, doUpdateSizeBegin throws a runtime_error: the programmer of a new function needs to overloaded it if his/her function supports variable resizing.

Postcondition
Each IFunction<Ability>::_validated must be false.

Definition at line 71 of file Function.cpp.

void ocra::Function::updateJdotXdot ( ) const
virtual

Generic implementation of updateJdotXdot.

Precondition
The first time derivative of the variable exists.
Value partial_X_DOT needs to be computable.

Definition at line 145 of file Function.cpp.

Member Data Documentation

const int& ocra::Function::_dim
protected

Definition at line 320 of file Function.h.

MatrixXd& ocra::Function::_jacobian
protected

Definition at line 313 of file Function.h.

VectorXd& ocra::Function::_value
protected

Definition at line 312 of file Function.h.

Variable& ocra::Function::x
protected

Definition at line 309 of file Function.h.


The documentation for this class was generated from the following files: