ACADO Toolkit  1.2.0beta
Toolkit for Automatic Control and Dynamic Optimization
Public Member Functions | Protected Attributes

Organizes the evaluation of the function tree. More...

#include <function_evaluation_tree.hpp>

List of all members.

Public Member Functions

 FunctionEvaluationTree ()
 Default constructor.
 FunctionEvaluationTree (const FunctionEvaluationTree &arg)
 Copy constructor (deep copy).
virtual ~FunctionEvaluationTree ()
 Destructor.
FunctionEvaluationTreeoperator= (const FunctionEvaluationTree &arg)
 Assignment operator (deep copy).
virtual returnValue operator<< (const Expression &arg)
 Loading Expressions (deep copy).
virtual int getDim () const
 Returns the dimension of the symbolic expression
.
virtual int getN () const
 Returns the number of intermediate expressions that have
been detected in the symbolic expression.
virtual int getNX () const
 Returns the number of differential states
.
virtual int getNXA () const
 Returns the number of algebraic states
.
virtual int getNDX () const
 Returns the number of differential states derivatives
.
virtual int getNU () const
 Returns the number of controls
.
virtual int getNUI () const
 Returns the number of integer controls
.
virtual int getNP () const
 Returns the number of parameters
.
virtual int getNPI () const
 Returns the number of integer parameters
.
virtual int getNW () const
 Returns the number of disturbances
.
virtual int getNT () const
 Returns the number of time variables
.
virtual int index (VariableType variableType_, int index_) const
 Returns the index of the variable with specified type and
component.
virtual double scale (VariableType variableType_, int index_) const
 Returns the scale of a given variable.
virtual int getNumberOfVariables () const
 Returns the variable counter.
virtual OperatorgetExpression (uint componentIdx) const
 Returns the symbolic expression of the given component of the function.
virtual returnValue evaluate (double *x, double *result)
 Evaluates the expression.
template<typename T >
returnValue evaluate (Tmatrix< T > *x, Tmatrix< T > *result)
 Evaluates the expression.
virtual returnValue evaluate (double *x, double *result, PrintLevel printL)
 Evaluates the expression and also prints
the intermediate results with a specified
print level.
virtual returnValue evaluate (int number, double *x, double *result)
 Evaluates the expression and stores the intermediate
results in a buffer (needed for automatic differentiation
in backward mode)
.
FunctionEvaluationTreedifferentiate (int index)
 Returns the derivative of the expression with respect
to the variable var(index).
virtual FunctionEvaluationTree substitute (VariableType variableType_, int index_, double sub_)
 Substitutes var(index) with the double sub.
virtual NeutralElement isOneOrZero ()
 Checks whether the expression is zero or one
.
virtual BooleanType isDependingOn (const Expression &variable)
 Checks whether the symbolic expression is depending on
a specified variable.
virtual BooleanType isLinearIn (const Expression &variable)
 Checks whether the symbolic expression is linear in
a specified variable.
virtual BooleanType isPolynomialIn (const Expression &variable)
 Checks whether the expression is polynomial in
a variable.
virtual BooleanType isRationalIn (const Expression &variable)
 Checks whether the expression is rational in
the variable var(index)
.
virtual MonotonicityType getMonotonicity ()
 Returns the monotonicity of the expression.
virtual CurvatureType getCurvature ()
 Returns the curvature of the expression
.
virtual returnValue AD_forward (double *x, double *seed, double *f, double *df)
 Automatic Differentiation in forward mode.
virtual returnValue AD_forward (int number, double *seed, double *df)
 Automatic Differentiation in forward mode.
virtual returnValue AD_forward (int number, double *x, double *seed, double *f, double *df)
 Automatic Differentiation in forward mode.
virtual returnValue AD_backward (double *seed, double *df)
 Automatic Differentiation in backward mode.
virtual returnValue AD_backward (int number, double *seed, double *df)
 Automatic Differentiation in backward mode based on
buffered values
.
virtual returnValue AD_forward2 (int number, double *seed1, double *seed2, double *df, double *ddf)
 Automatic Differentiation in forward mode for
2nd derivatives.
virtual returnValue AD_backward2 (int number, double *seed1, double *seed2, double *df, double *ddf)
 Automatic Differentiation in backward mode for 2nd order
derivatives based on buffered values.
returnValue C_print (FILE *file, const char *fcnName="ACADOfcn", const char *realString="double", int precision=16) const
 Prints the expression as C-code into a file.
returnValue exportHeader (FILE *file, const char *fcnName="ACADOfcn", const char *realString="double") const
returnValue exportForwardDeclarations (FILE *file, const char *fcnName="ACADOfcn", const char *realString="double") const
returnValue exportCode (FILE *file, const char *fcnName="ACADOfcn", const char *realString="double", int precision=16, uint _numX=0, uint _numXA=0, uint _numU=0, uint _numP=0, uint _numDX=0) const
ExportVariable getGlobalExportVariable () const
virtual returnValue clearBuffer ()
 Clears the buffer and resets the buffer size
to 1.
virtual returnValue makeImplicit ()
 Make the symbolic expression implicit.
virtual returnValue makeImplicit (int dim_)
virtual BooleanType isSymbolic () const
 Returns whether the function is symbolic or not.
virtual returnValue setScale (double *scale_)
 Defines scalings for the variables.
virtual returnValue getExpression (Expression &expression) const
returnValue setGlobalExportVariableName (const String &_name)
String getGlobalExportVariableName () const
unsigned getGlobalExportVariableSize () const

Protected Attributes

Operator ** f
 The right-hand side expressions.
Operator ** sub
 The intermediate expressions.
int * lhs_comp
 The components of the intermediate states.
SymbolicIndexListindexList
 an SymbolicIndexList
int dim
 The dimension of the function.
int n
 The number of Intermediate expressions.
Expression safeCopy
String globalExportVariableName
 Name of the variable that holds intermediate expressions.

Detailed Description

The class FunctionEvaluationTree is designed to organize the evaluation of tree structured expressions.

Author:
Boris Houska, Hans Joachim Ferreau, Milan Vukov

Constructor & Destructor Documentation

References dim, f, indexList, lhs_comp, n, and sub.


Member Function Documentation

returnValue FunctionEvaluationTree::AD_backward ( double *  seed,
double *  df 
) [virtual]


Returns:
SUCCESFUL_RETURN
RET_NAN
Parameters:
seedthe seed
dfthe derivative of the expression

References Operator::AD_backward(), dim, f, SymbolicIndexList::index(), indexList, lhs_comp, n, sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.

Referenced by Function::AD_backward().

returnValue FunctionEvaluationTree::AD_backward ( int  number,
double *  seed,
double *  df 
) [virtual]
Returns:
SUCCESFUL_RETURN
RET_NAN
Parameters:
numberthe buffer position
seedthe seed
dfthe derivative of the expression

References Operator::AD_backward(), dim, f, SymbolicIndexList::index(), indexList, lhs_comp, n, sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.

returnValue FunctionEvaluationTree::AD_backward2 ( int  number,
double *  seed1,
double *  seed2,
double *  df,
double *  ddf 
) [virtual]


Returns:
SUCCESFUL_RETURN
RET_NAN
Parameters:
numberthe buffer position
seed1the seed1
seed2the seed2
dfthe 1st derivative of the expression
ddfthe 2nd derivative of the expression

References Operator::AD_backward2(), dim, f, SymbolicIndexList::index(), indexList, lhs_comp, n, sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.

Referenced by Function::AD_backward2().

returnValue FunctionEvaluationTree::AD_forward ( double *  x,
double *  seed,
double *  f,
double *  df 
) [virtual]


Returns:
SUCCESFUL_RETURN
RET_NAN
Parameters:
xThe evaluation point x
seedthe seed
fthe value of the expression at x
dfthe derivative of the expression

References Operator::AD_forward(), dim, f, SymbolicIndexList::index(), indexList, lhs_comp, n, sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.

Referenced by Function::AD_forward().

returnValue FunctionEvaluationTree::AD_forward ( int  number,
double *  seed,
double *  df 
) [virtual]


This function uses the intermediate
results from a buffer

Returns:
SUCCESFUL_RETURN
RET_NAN
Parameters:
numberstorage position
seedthe seed
dfthe derivative of the expression

References Operator::AD_forward(), dim, f, SymbolicIndexList::index(), indexList, lhs_comp, n, sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.

returnValue FunctionEvaluationTree::AD_forward ( int  number,
double *  x,
double *  seed,
double *  f,
double *  df 
) [virtual]


This function stores the intermediate
results in a buffer (needed for 2nd order automatic
differentiation in backward mode)

Returns:
SUCCESFUL_RETURN
RET_NAN
Parameters:
numberstorage position
xThe evaluation point x
seedthe seed
fthe value of the expression at x
dfthe derivative of the expression

References Operator::AD_forward(), dim, f, SymbolicIndexList::index(), indexList, lhs_comp, n, sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.

returnValue FunctionEvaluationTree::AD_forward2 ( int  number,
double *  seed1,
double *  seed2,
double *  df,
double *  ddf 
) [virtual]


This function uses intermediate
results from a buffer.

Returns:
SUCCESFUL_RETURN
RET_NAN
Parameters:
numberthe buffer position
seed1the seed
seed2the seed for the first derivative
dfthe derivative of the expression
ddfthe 2nd derivative of the expression

References Operator::AD_forward2(), dim, f, SymbolicIndexList::index(), indexList, lhs_comp, n, sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.

Referenced by Function::AD_forward2().

returnValue FunctionEvaluationTree::C_print ( FILE *  file,
const char *  fcnName = "ACADOfcn",
const char *  realString = "double",
int  precision = 16 
) const

The integer
"precision" must be in [1,16].

Parameters:
fileThe file to which the expression should be printed.
fcnNameThe name of the generated function (default: "ACADOfcn").
realString
precisionThe number of internal dec. places to be printed (default: 16).

Returns:
SUCCESFUL_RETURN

References acadoFPrintf(), exportCode(), exportForwardDeclarations(), exportHeader(), and SUCCESSFUL_RETURN.

Referenced by Function::print().


Returns:
SUCCESFUL_RETURN

References Operator::clearBuffer(), dim, f, n, sub, and SUCCESSFUL_RETURN.

Referenced by Function::clearBuffer().


Returns:
The symbolic expression for the derivative.
Parameters:
indexdiff. index

References ACADOERROR, and RET_NOT_IMPLEMENTED_YET.

returnValue FunctionEvaluationTree::evaluate ( double *  x,
double *  result 
) [virtual]
Returns:
SUCCESSFUL_RETURN
RET_NAN
Parameters:
xthe input variable x
resultthe result

References dim, Operator::evaluate(), f, SymbolicIndexList::index(), indexList, lhs_comp, n, sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.

Referenced by Function::evaluate().

template<typename T >
returnValue FunctionEvaluationTree::evaluate ( Tmatrix< T > *  x,
Tmatrix< T > *  result 
)
returnValue FunctionEvaluationTree::evaluate ( double *  x,
double *  result,
PrintLevel  printL 
) [virtual]


Returns:
SUCCESFUL_RETURN
RET_NAN
Parameters:
xthe input variable x
resultthe result
printLthe print level

References acadoPrintf(), dim, Operator::evaluate(), f, HIGH, SymbolicIndexList::index(), indexList, lhs_comp, MEDIUM, n, sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.

returnValue FunctionEvaluationTree::evaluate ( int  number,
double *  x,
double *  result 
) [virtual]
Returns:
SUCCESFUL_RETURN
RET_NAN
Parameters:
numberstorage position
xthe input variable x
resultthe result

References dim, Operator::evaluate(), f, SymbolicIndexList::index(), indexList, lhs_comp, n, sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.

returnValue FunctionEvaluationTree::exportCode ( FILE *  file,
const char *  fcnName = "ACADOfcn",
const char *  realString = "double",
int  precision = 16,
uint  _numX = 0,
uint  _numXA = 0,
uint  _numU = 0,
uint  _numP = 0,
uint  _numDX = 0 
) const
returnValue FunctionEvaluationTree::exportForwardDeclarations ( FILE *  file,
const char *  fcnName = "ACADOfcn",
const char *  realString = "double" 
) const
returnValue FunctionEvaluationTree::exportHeader ( FILE *  file,
const char *  fcnName = "ACADOfcn",
const char *  realString = "double" 
) const
Returns:
CT_CONSTANT
CT_AFFINE
CT_CONVEX
CT_CONCAVE

References CT_AFFINE, CT_CONCAVE, CT_CONSTANT, CT_CONVEX, CT_NEITHER_CONVEX_NOR_CONCAVE, dim, f, and Operator::getCurvature().

Referenced by Function::isConcave(), and Function::isConvex().

BEGIN_NAMESPACE_ACADO int FunctionEvaluationTree::getDim ( ) const [inline, virtual]
Returns:
The requested dimension.

References dim.

Referenced by Function::getDim(), getExpression(), and OutputFcn::isDefined().

Operator * FunctionEvaluationTree::getExpression ( uint  componentIdx) const [virtual]


Returns:
The symbolic expression

References Operator::clone(), f, getDim(), and NE_ZERO.

Referenced by Function::getExpression().

References safeCopy, and SUCCESSFUL_RETURN.

References n.

Referenced by Function::getGlobalExportVariableSize().


Returns:
MT_NONDECREASING
MT_NONINCREASING
MT_NONMONOTONIC

References dim, f, Operator::getMonotonicity(), MT_CONSTANT, MT_NONDECREASING, MT_NONINCREASING, and MT_NONMONOTONIC.

Referenced by Function::isNondecreasing(), and Function::isNonincreasing().

int FunctionEvaluationTree::getN ( ) const [inline, virtual]


Returns:
The requested number of intermediate states.

References n.

Referenced by Function::getN().

int FunctionEvaluationTree::getNDX ( ) const [virtual]
Returns:
The requested number of differential state
derivatives.

References SymbolicIndexList::getNDX(), and indexList.

Referenced by exportCode(), and Function::getNDX().

int FunctionEvaluationTree::getNP ( ) const [virtual]
Returns:
The requested number of parameters.

References SymbolicIndexList::getNP(), and indexList.

Referenced by exportCode(), and Function::getNP().

int FunctionEvaluationTree::getNPI ( ) const [virtual]
Returns:
The requested number of integer parameters.

References SymbolicIndexList::getNPI(), and indexList.

Referenced by exportCode(), and Function::getNPI().

int FunctionEvaluationTree::getNT ( ) const [virtual]
Returns:
The requested number of time variables.

References SymbolicIndexList::getNT(), and indexList.

Referenced by exportCode(), and Function::getNT().

int FunctionEvaluationTree::getNU ( ) const [virtual]
Returns:
The requested number of controls.

References SymbolicIndexList::getNU(), and indexList.

Referenced by exportCode(), and Function::getNU().

int FunctionEvaluationTree::getNUI ( ) const [virtual]
Returns:
The requested number of integer controls.

References SymbolicIndexList::getNUI(), and indexList.

Referenced by exportCode(), and Function::getNUI().


Returns:
The number of variables

References SymbolicIndexList::getNumberOfVariables(), and indexList.

Referenced by Function::getNumberOfVariables().

int FunctionEvaluationTree::getNW ( ) const [virtual]
Returns:
The requested number of disturbances.

References SymbolicIndexList::getNW(), and indexList.

Referenced by exportCode(), and Function::getNW().

int FunctionEvaluationTree::getNX ( ) const [virtual]
Returns:
The requested number of differential states.

References SymbolicIndexList::getNX(), and indexList.

Referenced by exportCode(), Function::getN(), and Function::getNX().

int FunctionEvaluationTree::getNXA ( ) const [virtual]
Returns:
The requested number of algebraic states.

References SymbolicIndexList::getNXA(), and indexList.

Referenced by exportCode(), and Function::getNXA().

int FunctionEvaluationTree::index ( VariableType  variableType_,
int  index_ 
) const [virtual]


Returns:
The index of the requested variable.

References SymbolicIndexList::index(), and indexList.

Referenced by Function::index(), and substitute().


Returns:
BT_FALSE if no linearity is
detected
BT_TRUE otherwise

References ACADOERROR, BT_FALSE, BT_TRUE, dim, Expression::element, f, Expression::getDim(), Operator::isLinearIn(), Operator::isVariable(), n, RET_INVALID_ARGUMENTS, sub, and VT_INTERMEDIATE_STATE.

Referenced by Function::isLinearIn().

Returns:
NE_ZERO
NE_ONE
NE_NEITHER_ONE_NOR_ZERO

References dim, f, NE_NEITHER_ONE_NOR_ZERO, NE_ONE, and NE_ZERO.

Referenced by Function::isOneOrZero().


Returns:
BT_FALSE if the expression is not polynomial
BT_TRUE otherwise

References ACADOERROR, BT_FALSE, BT_TRUE, dim, Expression::element, f, Expression::getDim(), Operator::isPolynomialIn(), Operator::isVariable(), n, RET_INVALID_ARGUMENTS, sub, and VT_INTERMEDIATE_STATE.

Referenced by Function::isPolynomialIn().

Returns:
BT_FALSE if the expression is not rational
BT_TRUE otherwise

References ACADOERROR, BT_FALSE, BT_TRUE, dim, Expression::element, f, Expression::getDim(), Operator::isRationalIn(), Operator::isVariable(), n, RET_INVALID_ARGUMENTS, sub, and VT_INTERMEDIATE_STATE.

Referenced by Function::isRationalIn().

If BT_TRUE
is returned, automatic differentiation will be used by
default.

References BT_FALSE, BT_TRUE, dim, f, n, and sub.

Referenced by Function::isSymbolic().

This functionality
makes only sense for Differential Equation and should in
general not be used for anything else. (Although it is
public here.)

References dim.

Referenced by DifferentialEquation::makeImplicit().

returnValue FunctionEvaluationTree::operator<< ( const Expression arg) [virtual]
FunctionEvaluationTree & FunctionEvaluationTree::operator= ( const FunctionEvaluationTree arg)
double FunctionEvaluationTree::scale ( VariableType  variableType_,
int  index_ 
) const [virtual]


Returns:
The requested scale or
1.0 if index is out of range

References indexList, and SymbolicIndexList::scale().

Referenced by Function::scale().

returnValue FunctionEvaluationTree::setScale ( double *  scale_) [virtual]
FunctionEvaluationTree FunctionEvaluationTree::substitute ( VariableType  variableType_,
int  index_,
double  sub_ 
) [virtual]


Returns:
The substituted expression.
Parameters:
index_subst. index
sub_the substitution

References dim, EPS, f, fabs(), index(), indexList, lhs_comp, n, NE_NEITHER_ONE_NOR_ZERO, NE_ONE, NE_ZERO, sub, Operator::substitute(), and SymbolicIndexList::substitute().

Referenced by Function::substitute().


Member Data Documentation

int FunctionEvaluationTree::dim [protected]
int FunctionEvaluationTree::n [protected]

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines