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_OPERATOR_HPP
00035 #define ACADO_TOOLKIT_OPERATOR_HPP
00036
00037
00038 #include <acado/symbolic_operator/symbolic_operator_fwd.hpp>
00039
00040
00041 BEGIN_NAMESPACE_ACADO
00042
00043
00044 class Expression;
00045 class ConstraintComponent;
00046 class EvaluationBase;
00047
00048
00060 class Operator{
00061
00062 public:
00063
00064
00066 Operator();
00067
00068 virtual ~Operator();
00069
00070
00073 virtual Operator& operator=( const double & arg );
00074 virtual Operator& operator=( const DVector & arg );
00075 virtual Operator& operator=( const DMatrix & arg );
00076 virtual Operator& operator=( const Expression & arg );
00077 virtual Operator& operator=( const Operator & arg );
00078
00079
00080 Operator& operator+=( const double & arg );
00081 Operator& operator+=( const DVector & arg );
00082 Operator& operator+=( const DMatrix & arg );
00083 Operator& operator+=( const Expression & arg );
00084
00085 Operator& operator-=( const double & arg );
00086 Operator& operator-=( const DVector & arg );
00087 Operator& operator-=( const DMatrix & arg );
00088 Operator& operator-=( const Expression & arg );
00089
00090 Operator& operator*=( const double & arg );
00091 Operator& operator*=( const DVector & arg );
00092 Operator& operator*=( const DMatrix & arg );
00093 Operator& operator*=( const Expression & arg );
00094
00095 Operator& operator/=( const double & arg );
00096 Operator& operator/=( const Expression & arg );
00097
00098
00099 Expression operator+( const double & arg ) const;
00100 Expression operator+( const DVector & arg ) const;
00101 Expression operator+( const DMatrix & arg ) const;
00102 Expression operator+( const Operator& arg ) const;
00103 Expression operator+( const Expression & arg ) const;
00104
00105 friend Expression operator+( const double & arg1, const Operator& arg2 );
00106 friend Expression operator+( const DVector & arg1, const Operator& arg2 );
00107 friend Expression operator+( const DMatrix & arg1, const Operator& arg2 );
00108
00109 Expression operator-( const double & arg ) const;
00110 Expression operator-( const DVector & arg ) const;
00111 Expression operator-( const DMatrix & arg ) const;
00112 Expression operator-( const Operator & arg ) const;
00113 Expression operator-( const Expression & arg ) const;
00114
00115 Expression operator-( ) const;
00116
00117 friend Expression operator-( const double & arg1, const Operator& arg2 );
00118 friend Expression operator-( const DVector & arg1, const Operator& arg2 );
00119 friend Expression operator-( const DMatrix & arg1, const Operator& arg2 );
00120
00121 Expression operator*( const double & arg ) const;
00122 Expression operator*( const DVector & arg ) const;
00123 Expression operator*( const DMatrix & arg ) const;
00124 Expression operator*( const Operator & arg ) const;
00125 Expression operator*( const Expression & arg ) const;
00126
00127 friend Expression operator*( const double& arg1, const Operator& arg2 );
00128 friend Expression operator*( const DVector& arg1, const Operator& arg2 );
00129 friend Expression operator*( const DMatrix& arg1, const Operator& arg2 );
00130
00131 Expression operator/( const double & arg ) const;
00132 Expression operator/( const Operator & arg ) const;
00133 Expression operator/( const Expression & arg ) const;
00134
00135
00136 friend Expression operator/( const double& arg1, const Operator& arg2 );
00137 friend Expression operator/( const DVector& arg1, const Operator& arg2 );
00138 friend Expression operator/( const DMatrix& arg1, const Operator& arg2 );
00139
00140 ConstraintComponent operator<=( const double& ub ) const;
00141 ConstraintComponent operator>=( const double& lb ) const;
00142 ConstraintComponent operator==( const double& b ) const;
00143
00144 ConstraintComponent operator<=( const DVector& ub ) const;
00145 ConstraintComponent operator>=( const DVector& lb ) const;
00146 ConstraintComponent operator==( const DVector& b ) const;
00147
00148 ConstraintComponent operator<=( const VariablesGrid& ub ) const;
00149 ConstraintComponent operator>=( const VariablesGrid& lb ) const;
00150 ConstraintComponent operator==( const VariablesGrid& b ) const;
00151
00152 friend ConstraintComponent operator<=( double lb, const Operator &arg );
00153 friend ConstraintComponent operator==( double b, const Operator &arg );
00154 friend ConstraintComponent operator>=( double ub, const Operator &arg );
00155
00156 friend ConstraintComponent operator<=( DVector lb, const Operator &arg );
00157 friend ConstraintComponent operator==( DVector b, const Operator &arg );
00158 friend ConstraintComponent operator>=( DVector ub, const Operator &arg );
00159
00160 friend ConstraintComponent operator<=( VariablesGrid lb, const Operator &arg );
00161 friend ConstraintComponent operator==( VariablesGrid b, const Operator &arg );
00162 friend ConstraintComponent operator>=( VariablesGrid ub, const Operator &arg );
00163
00164
00171 virtual returnValue evaluate( int number ,
00172 double *x ,
00173 double *result ) = 0;
00174
00175
00177 virtual returnValue evaluate( EvaluationBase *x ) = 0;
00178
00179
00185 virtual Operator* differentiate( int index ) = 0;
00186
00187
00188
00194 virtual Operator* AD_forward( int dim ,
00195 VariableType *varType ,
00196 int *component,
00197 Operator **seed ,
00198 int &nNewIS ,
00199 TreeProjection ***newIS ) = 0;
00200
00201
00202
00208 virtual returnValue AD_backward( int dim ,
00209 VariableType *varType ,
00210 int *component,
00211 Operator *seed ,
00212 Operator **df ,
00213 int &nNewIS ,
00214 TreeProjection ***newIS ) = 0;
00215
00216
00217
00223 virtual returnValue AD_symmetric( int dim ,
00224 VariableType *varType ,
00225 int *component ,
00226 Operator *l ,
00227 Operator **S ,
00228 int dimS ,
00229 Operator **dfS ,
00230 Operator **ldf ,
00231 Operator **H ,
00232 int &nNewLIS ,
00233 TreeProjection ***newLIS ,
00234 int &nNewSIS ,
00235 TreeProjection ***newSIS ,
00236 int &nNewHIS ,
00237 TreeProjection ***newHIS ) = 0;
00238
00239
00240
00245 virtual Operator* substitute( int index ,
00246 const Operator *sub ) = 0;
00247
00248
00249
00256 virtual NeutralElement isOneOrZero() const = 0;
00257
00258
00259
00265 virtual BooleanType isDependingOn( VariableType var ) const = 0;
00266
00267
00268
00274 virtual BooleanType isDependingOn( int dim ,
00275 VariableType *varType ,
00276 int *component,
00277 BooleanType *implicit_dep ) = 0;
00278
00279
00280
00281
00289 virtual BooleanType isLinearIn( int dim ,
00290 VariableType *varType ,
00291 int *component,
00292 BooleanType *implicit_dep ) = 0;
00293
00294
00295
00302 virtual BooleanType isPolynomialIn( int dim ,
00303 VariableType *varType ,
00304 int *component,
00305 BooleanType *implicit_dep ) = 0;
00306
00307
00308
00315 virtual BooleanType isRationalIn( int dim ,
00316 VariableType *varType ,
00317 int *component,
00318 BooleanType *implicit_dep ) = 0;
00319
00325 virtual BooleanType isSmooth( ) const = 0;
00326
00327
00334 virtual MonotonicityType getMonotonicity( ) = 0;
00335
00336
00337
00345 virtual CurvatureType getCurvature( ) = 0;
00346
00347
00348
00354 virtual returnValue setMonotonicity( MonotonicityType monotonicity_ ) = 0;
00355
00356
00357
00358
00364 virtual returnValue setCurvature( CurvatureType curvature_ ) = 0;
00365
00366
00367
00375 virtual returnValue AD_forward( int number ,
00376 double *x ,
00378 double *seed ,
00379 double *f ,
00381 double *df ) = 0;
00383
00384
00385
00392 virtual returnValue AD_forward( int number ,
00393 double *seed ,
00394 double *df ) = 0;
00396
00397
00398
00399
00400
00401
00407 virtual returnValue AD_backward( int number ,
00409 double seed ,
00410 double *df ) = 0;
00412
00413
00414
00422 virtual returnValue AD_forward2( int number ,
00424 double *seed1 ,
00425 double *seed2 ,
00427 double *df ,
00429 double *ddf ) = 0;
00431
00432
00433
00434
00435
00436
00442 virtual returnValue AD_backward2( int number ,
00444 double seed1 ,
00445 double seed2 ,
00446 double *df ,
00448 double *ddf ) = 0;
00450
00454 virtual std::ostream& print(std::ostream& stream) const = 0;
00455
00456
00460 friend std::ostream& operator<<(std::ostream& stream, const Operator& arg);
00461
00465 virtual Operator* clone() const = 0;
00466
00467
00473 virtual TreeProjection* cloneTreeProjection() const;
00474
00475
00476
00481 virtual returnValue clearBuffer() = 0;
00482
00483
00484
00489 virtual returnValue enumerateVariables( SymbolicIndexList *indexList ) = 0;
00490
00491
00492
00496 virtual OperatorName getName() = 0;
00497
00498
00501
00502
00503
00506 virtual int getGlobalIndex( ) const;
00507
00508
00512 virtual BooleanType isVariable( VariableType &varType,
00513 int &component ) const = 0;
00514
00515
00534 virtual returnValue loadIndices( SymbolicIndexList *indexList ) = 0;
00536
00537
00538
00540 virtual double getValue() const;
00541
00542
00543
00545 virtual Operator* passArgument() const;
00546
00547
00553 virtual BooleanType isSymbolic() const = 0;
00554
00555
00556 int nCount;
00557
00558
00559
00563 virtual returnValue setVariableExportName( const VariableType &_type,
00564 const std::vector< std::string >& _name
00565 );
00566
00567
00568
00569
00570 virtual Operator* myProd(Operator* a,Operator* b);
00571 virtual Operator* myAdd (Operator* a,Operator* b);
00572 virtual Operator* mySubtract (Operator* a,Operator* b);
00573 virtual Operator* myPower (Operator* a,Operator* b);
00574 virtual Operator* myPowerInt (Operator* a,int b);
00575 virtual Operator* myLogarithm (Operator* a);
00576
00577
00578 virtual BooleanType isTrivial() const;
00579
00580
00581 virtual returnValue initDerivative();
00582
00583
00584
00585
00586
00587
00588 protected:
00589
00590
00591 virtual TreeProjection* convert2TreeProjection( Operator* a ) const;
00592
00593 returnValue ADsymCommon( Operator *a ,
00594 TreeProjection &da ,
00595 TreeProjection &dda,
00596 int dim ,
00597 VariableType *varType ,
00598 int *component ,
00599 Operator *l ,
00600 Operator **S ,
00601 int dimS ,
00602 Operator **dfS ,
00603 Operator **ldf ,
00604 Operator **H ,
00605 int &nNewLIS ,
00606 TreeProjection ***newLIS ,
00607 int &nNewSIS ,
00608 TreeProjection ***newSIS ,
00609 int &nNewHIS ,
00610 TreeProjection ***newHIS );
00611
00612
00613 returnValue ADsymCommon2( Operator *a ,
00614 Operator *b ,
00615 TreeProjection &dx ,
00616 TreeProjection &dy ,
00617 TreeProjection &dxx,
00618 TreeProjection &dxy,
00619 TreeProjection &dyy,
00620 int dim ,
00621 VariableType *varType ,
00622 int *component ,
00623 Operator *l ,
00624 Operator **S ,
00625 int dimS ,
00626 Operator **dfS ,
00627 Operator **ldf ,
00628 Operator **H ,
00629 int &nNewLIS ,
00630 TreeProjection ***newLIS ,
00631 int &nNewSIS ,
00632 TreeProjection ***newSIS ,
00633 int &nNewHIS ,
00634 TreeProjection ***newHIS );
00635
00636
00637
00638
00639
00640 protected:
00641
00642 BooleanType initialized;
00643
00644
00645 };
00646
00647
00648 CLOSE_NAMESPACE_ACADO
00649
00650
00651
00652 #endif
00653
00654
00655