ACADO Toolkit
1.2.0beta
Toolkit for Automatic Control and Dynamic Optimization
|
Organizes the evaluation of the function tree. More...
#include <function_evaluation_tree.hpp>
Public Member Functions | |
FunctionEvaluationTree () | |
Default constructor. | |
FunctionEvaluationTree (const FunctionEvaluationTree &arg) | |
Copy constructor (deep copy). | |
virtual | ~FunctionEvaluationTree () |
Destructor. | |
FunctionEvaluationTree & | operator= (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 Operator * | getExpression (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) . | |
FunctionEvaluationTree * | differentiate (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. | |
SymbolicIndexList * | indexList |
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. |
The class FunctionEvaluationTree is designed to organize the evaluation of tree structured expressions.
References Operator::clone(), dim, f, globalExportVariableName, indexList, lhs_comp, n, safeCopy, and sub.
FunctionEvaluationTree::~FunctionEvaluationTree | ( | ) | [virtual] |
returnValue FunctionEvaluationTree::AD_backward | ( | double * | seed, |
double * | df | ||
) | [virtual] |
seed | the seed |
df | the 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] |
number | the buffer position |
seed | the seed |
df | the 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] |
number | the buffer position |
seed1 | the seed1 |
seed2 | the seed2 |
df | the 1st derivative of the expression |
ddf | the 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] |
x | The evaluation point x |
seed | the seed |
f | the value of the expression at x |
df | the 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
number | storage position |
seed | the seed |
df | the 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)
number | storage position |
x | The evaluation point x |
seed | the seed |
f | the value of the expression at x |
df | the 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.
number | the buffer position |
seed1 | the seed |
seed2 | the seed for the first derivative |
df | the derivative of the expression |
ddf | the 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].
file | The file to which the expression should be printed. |
fcnName | The name of the generated function (default: "ACADOfcn"). |
realString | |
precision | The number of internal dec. places to be printed (default: 16). |
References acadoFPrintf(), exportCode(), exportForwardDeclarations(), exportHeader(), and SUCCESSFUL_RETURN.
Referenced by Function::print().
returnValue FunctionEvaluationTree::clearBuffer | ( | ) | [virtual] |
References Operator::clearBuffer(), dim, f, n, sub, and SUCCESSFUL_RETURN.
Referenced by Function::clearBuffer().
FunctionEvaluationTree * FunctionEvaluationTree::differentiate | ( | int | index | ) |
index | diff. index |
References ACADOERROR, and RET_NOT_IMPLEMENTED_YET.
returnValue FunctionEvaluationTree::evaluate | ( | double * | x, |
double * | result | ||
) | [virtual] |
x | the input variable x |
result | the result |
References dim, Operator::evaluate(), f, SymbolicIndexList::index(), indexList, lhs_comp, n, sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.
Referenced by Function::evaluate().
returnValue FunctionEvaluationTree::evaluate | ( | Tmatrix< T > * | x, |
Tmatrix< T > * | result | ||
) |
References dim, Operator::evaluate(), f, SymbolicIndexList::index(), indexList, lhs_comp, n, EvaluationTemplate< T >::res, sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.
returnValue FunctionEvaluationTree::evaluate | ( | double * | x, |
double * | result, | ||
PrintLevel | printL | ||
) | [virtual] |
x | the input variable x |
result | the result |
printL | the 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] |
number | storage position |
x | the input variable x |
result | the 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 |
References acadoFPrintf(), dim, f, String::getName(), getNDX(), getNP(), getNPI(), getNT(), getNU(), getNUI(), getNW(), getNX(), getNXA(), globalExportVariableName, lhs_comp, n, Operator::setVariableExportName(), sub, SUCCESSFUL_RETURN, and VT_INTERMEDIATE_STATE.
Referenced by C_print(), and Function::exportCode().
returnValue FunctionEvaluationTree::exportForwardDeclarations | ( | FILE * | file, |
const char * | fcnName = "ACADOfcn" , |
||
const char * | realString = "double" |
||
) | const |
References acadoFPrintf(), and SUCCESSFUL_RETURN.
Referenced by C_print(), and Function::exportForwardDeclarations().
returnValue FunctionEvaluationTree::exportHeader | ( | FILE * | file, |
const char * | fcnName = "ACADOfcn" , |
||
const char * | realString = "double" |
||
) | const |
References acadoFPrintf(), String::getName(), globalExportVariableName, n, and SUCCESSFUL_RETURN.
Referenced by C_print(), and Function::exportHeader().
CurvatureType FunctionEvaluationTree::getCurvature | ( | ) | [virtual] |
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] |
References dim.
Referenced by Function::getDim(), getExpression(), and OutputFcn::isDefined().
Operator * FunctionEvaluationTree::getExpression | ( | uint | componentIdx | ) | const [virtual] |
References Operator::clone(), f, getDim(), and NE_ZERO.
Referenced by Function::getExpression().
returnValue FunctionEvaluationTree::getExpression | ( | Expression & | expression | ) | const [virtual] |
References safeCopy, and SUCCESSFUL_RETURN.
References globalExportVariableName.
Referenced by Function::getGlobalExportVariableName().
unsigned FunctionEvaluationTree::getGlobalExportVariableSize | ( | ) | const |
References n.
Referenced by Function::getGlobalExportVariableSize().
MonotonicityType FunctionEvaluationTree::getMonotonicity | ( | ) | [virtual] |
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] |
int FunctionEvaluationTree::getNDX | ( | ) | const [virtual] |
References SymbolicIndexList::getNDX(), and indexList.
Referenced by exportCode(), and Function::getNDX().
int FunctionEvaluationTree::getNP | ( | ) | const [virtual] |
References SymbolicIndexList::getNP(), and indexList.
Referenced by exportCode(), and Function::getNP().
int FunctionEvaluationTree::getNPI | ( | ) | const [virtual] |
References SymbolicIndexList::getNPI(), and indexList.
Referenced by exportCode(), and Function::getNPI().
int FunctionEvaluationTree::getNT | ( | ) | const [virtual] |
References SymbolicIndexList::getNT(), and indexList.
Referenced by exportCode(), and Function::getNT().
int FunctionEvaluationTree::getNU | ( | ) | const [virtual] |
References SymbolicIndexList::getNU(), and indexList.
Referenced by exportCode(), and Function::getNU().
int FunctionEvaluationTree::getNUI | ( | ) | const [virtual] |
References SymbolicIndexList::getNUI(), and indexList.
Referenced by exportCode(), and Function::getNUI().
int FunctionEvaluationTree::getNumberOfVariables | ( | ) | const [virtual] |
References SymbolicIndexList::getNumberOfVariables(), and indexList.
Referenced by Function::getNumberOfVariables().
int FunctionEvaluationTree::getNW | ( | ) | const [virtual] |
References SymbolicIndexList::getNW(), and indexList.
Referenced by exportCode(), and Function::getNW().
int FunctionEvaluationTree::getNX | ( | ) | const [virtual] |
References SymbolicIndexList::getNX(), and indexList.
Referenced by exportCode(), Function::getN(), and Function::getNX().
int FunctionEvaluationTree::getNXA | ( | ) | const [virtual] |
References SymbolicIndexList::getNXA(), and indexList.
Referenced by exportCode(), and Function::getNXA().
int FunctionEvaluationTree::index | ( | VariableType | variableType_, |
int | index_ | ||
) | const [virtual] |
References SymbolicIndexList::index(), and indexList.
Referenced by Function::index(), and substitute().
BooleanType FunctionEvaluationTree::isDependingOn | ( | const Expression & | variable | ) | [virtual] |
References ACADOERROR, BT_FALSE, BT_TRUE, dim, Expression::element, f, Expression::getDim(), Operator::isDependingOn(), Operator::isVariable(), n, RET_INVALID_ARGUMENTS, sub, and VT_INTERMEDIATE_STATE.
Referenced by Function::isDependingOn().
BooleanType FunctionEvaluationTree::isLinearIn | ( | const Expression & | variable | ) | [virtual] |
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().
NeutralElement FunctionEvaluationTree::isOneOrZero | ( | ) | [virtual] |
References dim, f, NE_NEITHER_ONE_NOR_ZERO, NE_ONE, and NE_ZERO.
Referenced by Function::isOneOrZero().
BooleanType FunctionEvaluationTree::isPolynomialIn | ( | const Expression & | variable | ) | [virtual] |
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().
BooleanType FunctionEvaluationTree::isRationalIn | ( | const Expression & | variable | ) | [virtual] |
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().
BooleanType FunctionEvaluationTree::isSymbolic | ( | ) | const [virtual] |
returnValue FunctionEvaluationTree::makeImplicit | ( | ) | [virtual] |
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::makeImplicit | ( | int | dim_ | ) | [virtual] |
returnValue FunctionEvaluationTree::operator<< | ( | const Expression & | arg | ) | [virtual] |
References Operator::clone(), dim, f, SymbolicIndexList::getNumberOfOperators(), SymbolicIndexList::getOperators(), indexList, lhs_comp, n, safeCopy, sub, SUCCESSFUL_RETURN, and uint.
FunctionEvaluationTree & FunctionEvaluationTree::operator= | ( | const FunctionEvaluationTree & | arg | ) |
References Operator::clone(), dim, f, globalExportVariableName, indexList, lhs_comp, n, safeCopy, and sub.
double FunctionEvaluationTree::scale | ( | VariableType | variableType_, |
int | index_ | ||
) | const [virtual] |
References indexList, and SymbolicIndexList::scale().
Referenced by Function::scale().
returnValue FunctionEvaluationTree::setGlobalExportVariableName | ( | const String & | _name | ) |
References ACADOERROR, String::getLength(), globalExportVariableName, RET_INVALID_ARGUMENTS, and SUCCESSFUL_RETURN.
Referenced by Function::setGlobalExportVariableName().
returnValue FunctionEvaluationTree::setScale | ( | double * | scale_ | ) | [virtual] |
References ACADOERROR, and RET_INVALID_USE_OF_FUNCTION.
Referenced by Function::setScale().
FunctionEvaluationTree FunctionEvaluationTree::substitute | ( | VariableType | variableType_, |
int | index_, | ||
double | sub_ | ||
) | [virtual] |
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().
int FunctionEvaluationTree::dim [protected] |
Referenced by AD_backward(), AD_backward2(), AD_forward(), AD_forward2(), clearBuffer(), evaluate(), exportCode(), FunctionEvaluationTree(), getCurvature(), getDim(), QPsolver_qpOASES::getDualSolution(), getMonotonicity(), QPsolver_qpOASES::getPrimalSolution(), isDependingOn(), isLinearIn(), isOneOrZero(), isPolynomialIn(), isRationalIn(), isSymbolic(), makeImplicit(), operator<<(), operator=(), substitute(), and ~FunctionEvaluationTree().
Operator** FunctionEvaluationTree::f [protected] |
Referenced by AD_backward(), AD_backward2(), AD_forward(), AD_forward2(), clearBuffer(), evaluate(), exportCode(), FunctionEvaluationTree(), getCurvature(), getExpression(), getMonotonicity(), isDependingOn(), isLinearIn(), isOneOrZero(), isPolynomialIn(), isRationalIn(), isSymbolic(), makeImplicit(), operator<<(), operator=(), substitute(), and ~FunctionEvaluationTree().
SymbolicIndexList* FunctionEvaluationTree::indexList [protected] |
Referenced by AD_backward(), AD_backward2(), AD_forward(), AD_forward2(), evaluate(), FunctionEvaluationTree(), getNDX(), getNP(), getNPI(), getNT(), getNU(), getNUI(), getNumberOfVariables(), getNW(), getNX(), getNXA(), index(), makeImplicit(), operator<<(), operator=(), scale(), substitute(), and ~FunctionEvaluationTree().
int* FunctionEvaluationTree::lhs_comp [protected] |
int FunctionEvaluationTree::n [protected] |
Referenced by AD_backward(), AD_backward2(), AD_forward(), AD_forward2(), clearBuffer(), evaluate(), exportCode(), exportHeader(), FunctionEvaluationTree(), getGlobalExportVariableSize(), getN(), isDependingOn(), isLinearIn(), isPolynomialIn(), isRationalIn(), isSymbolic(), operator<<(), operator=(), substitute(), and ~FunctionEvaluationTree().
Expression FunctionEvaluationTree::safeCopy [protected] |
Referenced by FunctionEvaluationTree(), getExpression(), operator<<(), and operator=().
Operator** FunctionEvaluationTree::sub [protected] |