00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00034 #ifndef ACADO_TOOLKIT_FUNCTION_EVALUATION_TREE_HPP
00035 #define ACADO_TOOLKIT_FUNCTION_EVALUATION_TREE_HPP
00036
00037 #include <acado/symbolic_expression/expression.hpp>
00038 #include <acado/symbolic_operator/evaluation_template.hpp>
00039 #include <acado/symbolic_operator/symbolic_index_list.hpp>
00040
00041 BEGIN_NAMESPACE_ACADO
00042
00053 class FunctionEvaluationTree
00054 {
00055
00056
00057
00058
00059 public:
00060
00062 FunctionEvaluationTree( );
00063
00065 FunctionEvaluationTree( const FunctionEvaluationTree& arg );
00066
00068 virtual ~FunctionEvaluationTree( );
00069
00071 FunctionEvaluationTree& operator=( const FunctionEvaluationTree& arg );
00072
00074 virtual returnValue operator<<( const Expression& arg );
00075
00076
00080 virtual int getDim () const;
00081
00082
00087 virtual int getN () const;
00088
00089
00093 virtual int getNX () const;
00094
00098 virtual int getNXA () const;
00099
00104 virtual int getNDX () const;
00105
00106
00110 virtual int getNU () const;
00111
00115 virtual int getNUI () const;
00116
00120 virtual int getNP () const;
00121
00125 virtual int getNPI () const;
00126
00130 virtual int getNW () const;
00131
00135 virtual int getNT () const;
00136
00138 virtual int getNOD () const;
00139
00140
00145 virtual int index( VariableType variableType_, int index_ ) const;
00146
00147
00152 virtual double scale( VariableType variableType_, int index_ ) const;
00153
00154
00158 virtual int getNumberOfVariables() const;
00159
00160
00164 virtual Operator* getExpression( uint componentIdx
00165 ) const;
00166
00167
00172 virtual returnValue evaluate( double *x ,
00173 double *result );
00174
00175
00176
00178 template <typename T> returnValue evaluate( Tmatrix<T> *x, Tmatrix<T> *result );
00179
00180
00181
00188 virtual returnValue evaluate( double *x ,
00189 double *result ,
00190 PrintLevel printL );
00191
00192
00193
00194
00201 virtual returnValue evaluate( int number ,
00202 double *x ,
00203 double *result );
00204
00205
00206
00212 FunctionEvaluationTree* differentiate( int index );
00213
00214
00215
00220 virtual FunctionEvaluationTree substitute( VariableType variableType_,
00221 int index_ ,
00222 double sub_ );
00223
00224
00231 virtual NeutralElement isOneOrZero();
00232
00233
00234
00241 virtual BooleanType isDependingOn( const Expression &variable );
00242
00243
00251 virtual BooleanType isLinearIn( const Expression &variable );
00252
00253
00260 virtual BooleanType isPolynomialIn( const Expression &variable );
00261
00262
00269 virtual BooleanType isRationalIn( const Expression &variable );
00270
00271
00278 virtual MonotonicityType getMonotonicity( );
00279
00280
00281
00289 virtual CurvatureType getCurvature( );
00290
00291
00292
00297 virtual returnValue AD_forward( double *x ,
00299 double *seed ,
00300 double *f ,
00302 double *df );
00304
00305
00306
00313 virtual returnValue AD_forward( int number ,
00314 double *seed ,
00315 double *df );
00317
00318
00319
00327 virtual returnValue AD_forward( int number ,
00328 double *x ,
00330 double *seed ,
00331 double *f ,
00333 double *df );
00335
00336
00337
00338
00339
00344 virtual returnValue AD_backward( double *seed ,
00345 double *df );
00347
00348
00349
00350
00351
00352
00358 virtual returnValue AD_backward( int number ,
00360 double *seed ,
00361 double *df );
00363
00364
00365
00366
00374 virtual returnValue AD_forward2( int number ,
00376 double *seed1 ,
00377 double *seed2 ,
00379 double *df ,
00381 double *ddf );
00383
00384
00385
00386
00387
00388
00394 virtual returnValue AD_backward2( int number ,
00396 double *seed1 ,
00397 double *seed2 ,
00398 double *df ,
00400 double *ddf );
00402
00403
00412 returnValue C_print( std::ostream& stream = std::cout,
00413 const char *fcnName = "ACADOfcn",
00414 const char *realString = "double"
00415 ) const;
00416
00417 returnValue exportForwardDeclarations( std::ostream& stream = std::cout,
00418 const char *fcnName = "ACADOfcn",
00419 const char *realString = "double"
00420 ) const;
00421
00422 returnValue exportCode( std::ostream& stream = std::cout,
00423 const char *fcnName = "ACADOfcn",
00424 const char *realString = "double",
00425 uint _numX = 0,
00426 uint _numXA = 0,
00427 uint _numU = 0,
00428 uint _numP = 0,
00429 uint _numDX = 0,
00430 uint _numOD = 0,
00431 bool allocateMemory = true,
00432 bool staticMemory = false
00433 ) const;
00434
00439 virtual returnValue clearBuffer();
00440
00441
00447 virtual returnValue makeImplicit();
00448 virtual returnValue makeImplicit( int dim_ );
00449
00450
00455 virtual BooleanType isSymbolic() const;
00456
00457
00459 virtual returnValue setScale( double *scale_ );
00460
00461 virtual returnValue getExpression( Expression& expression ) const;
00462
00463 returnValue setGlobalExportVariableName(const std::string& _name);
00464
00465 std::string getGlobalExportVariableName() const;
00466
00467 unsigned getGlobalExportVariableSize() const;
00468
00469
00470
00471
00472 protected:
00473
00474 Operator **f ;
00475 Operator **sub ;
00476 int *lhs_comp ;
00477 SymbolicIndexList *indexList;
00478 int dim ;
00479 int n ;
00481 Expression safeCopy ;
00482
00484 std::string globalExportVariableName;
00485 };
00486
00487
00488 template <typename T> returnValue FunctionEvaluationTree::evaluate( Tmatrix<T> *x,
00489 Tmatrix<T> *result ){
00490
00491 int run1;
00492
00493 EvaluationTemplate<T> y(x);
00494
00495 for( run1 = 0; run1 < n; run1++ ){
00496 sub[run1]->evaluate(&y);
00497 x->operator()(indexList->index(VT_INTERMEDIATE_STATE,lhs_comp[run1])) = y.res;
00498 }
00499
00500 for( run1 = 0; run1 < dim; run1++ ){
00501 f[run1]->evaluate(&y);
00502 result->operator()(run1) = y.res;
00503 }
00504
00505 return SUCCESSFUL_RETURN;
00506 }
00507
00508
00509
00510 CLOSE_NAMESPACE_ACADO
00511
00512
00513
00514 #include <acado/function/function_evaluation_tree.ipp>
00515
00516
00517 #endif // ACADO_TOOLKIT_FUNCTION_HPP
00518
00519