operator.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
27 
34 #ifndef ACADO_TOOLKIT_OPERATOR_HPP
35 #define ACADO_TOOLKIT_OPERATOR_HPP
36 
37 
39 
40 
42 
43 
44 class Expression;
46 class EvaluationBase;
47 
48 
60 class Operator{
61 
62 public:
63 
64 
66  Operator();
67 
68  virtual ~Operator();
69 
70 
73  virtual Operator& operator=( const double & arg );
74  virtual Operator& operator=( const DVector & arg );
75  virtual Operator& operator=( const DMatrix & arg );
76  virtual Operator& operator=( const Expression & arg );
77  virtual Operator& operator=( const Operator & arg );
78 
79 
80  Operator& operator+=( const double & arg );
81  Operator& operator+=( const DVector & arg );
82  Operator& operator+=( const DMatrix & arg );
83  Operator& operator+=( const Expression & arg );
84 
85  Operator& operator-=( const double & arg );
86  Operator& operator-=( const DVector & arg );
87  Operator& operator-=( const DMatrix & arg );
88  Operator& operator-=( const Expression & arg );
89 
90  Operator& operator*=( const double & arg );
91  Operator& operator*=( const DVector & arg );
92  Operator& operator*=( const DMatrix & arg );
93  Operator& operator*=( const Expression & arg );
94 
95  Operator& operator/=( const double & arg );
96  Operator& operator/=( const Expression & arg );
97 
98 
99  Expression operator+( const double & arg ) const;
100  Expression operator+( const DVector & arg ) const;
101  Expression operator+( const DMatrix & arg ) const;
102  Expression operator+( const Operator& arg ) const;
103  Expression operator+( const Expression & arg ) const;
104 
105  friend Expression operator+( const double & arg1, const Operator& arg2 );
106  friend Expression operator+( const DVector & arg1, const Operator& arg2 );
107  friend Expression operator+( const DMatrix & arg1, const Operator& arg2 );
108 
109  Expression operator-( const double & arg ) const;
110  Expression operator-( const DVector & arg ) const;
111  Expression operator-( const DMatrix & arg ) const;
112  Expression operator-( const Operator & arg ) const;
113  Expression operator-( const Expression & arg ) const;
114 
115  Expression operator-( ) const;
116 
117  friend Expression operator-( const double & arg1, const Operator& arg2 );
118  friend Expression operator-( const DVector & arg1, const Operator& arg2 );
119  friend Expression operator-( const DMatrix & arg1, const Operator& arg2 );
120 
121  Expression operator*( const double & arg ) const;
122  Expression operator*( const DVector & arg ) const;
123  Expression operator*( const DMatrix & arg ) const;
124  Expression operator*( const Operator & arg ) const;
125  Expression operator*( const Expression & arg ) const;
126 
127  friend Expression operator*( const double& arg1, const Operator& arg2 );
128  friend Expression operator*( const DVector& arg1, const Operator& arg2 );
129  friend Expression operator*( const DMatrix& arg1, const Operator& arg2 );
130 
131  Expression operator/( const double & arg ) const;
132  Expression operator/( const Operator & arg ) const;
133  Expression operator/( const Expression & arg ) const;
134 
135 
136  friend Expression operator/( const double& arg1, const Operator& arg2 );
137  friend Expression operator/( const DVector& arg1, const Operator& arg2 );
138  friend Expression operator/( const DMatrix& arg1, const Operator& arg2 );
139 
140  ConstraintComponent operator<=( const double& ub ) const;
141  ConstraintComponent operator>=( const double& lb ) const;
142  ConstraintComponent operator==( const double& b ) const;
143 
144  ConstraintComponent operator<=( const DVector& ub ) const;
145  ConstraintComponent operator>=( const DVector& lb ) const;
146  ConstraintComponent operator==( const DVector& b ) const;
147 
148  ConstraintComponent operator<=( const VariablesGrid& ub ) const;
149  ConstraintComponent operator>=( const VariablesGrid& lb ) const;
150  ConstraintComponent operator==( const VariablesGrid& b ) const;
151 
152  friend ConstraintComponent operator<=( double lb, const Operator &arg );
153  friend ConstraintComponent operator==( double b, const Operator &arg );
154  friend ConstraintComponent operator>=( double ub, const Operator &arg );
155 
156  friend ConstraintComponent operator<=( DVector lb, const Operator &arg );
157  friend ConstraintComponent operator==( DVector b, const Operator &arg );
158  friend ConstraintComponent operator>=( DVector ub, const Operator &arg );
159 
160  friend ConstraintComponent operator<=( VariablesGrid lb, const Operator &arg );
161  friend ConstraintComponent operator==( VariablesGrid b, const Operator &arg );
162  friend ConstraintComponent operator>=( VariablesGrid ub, const Operator &arg );
163 
164 
171  virtual returnValue evaluate( int number ,
172  double *x ,
173  double *result ) = 0;
174 
175 
177  virtual returnValue evaluate( EvaluationBase *x ) = 0;
178 
179 
185  virtual Operator* differentiate( int index ) = 0;
186 
187 
188 
194  virtual Operator* AD_forward( int dim ,
195  VariableType *varType ,
196  int *component,
197  Operator **seed ,
198  int &nNewIS ,
199  TreeProjection ***newIS ) = 0;
200 
201 
202 
208  virtual returnValue AD_backward( int dim ,
209  VariableType *varType ,
210  int *component,
211  Operator *seed ,
212  Operator **df ,
213  int &nNewIS ,
214  TreeProjection ***newIS ) = 0;
215 
216 
217 
223  virtual returnValue AD_symmetric( int dim ,
224  VariableType *varType ,
225  int *component ,
226  Operator *l ,
227  Operator **S ,
228  int dimS ,
229  Operator **dfS ,
230  Operator **ldf ,
231  Operator **H ,
232  int &nNewLIS ,
233  TreeProjection ***newLIS ,
234  int &nNewSIS ,
235  TreeProjection ***newSIS ,
236  int &nNewHIS ,
237  TreeProjection ***newHIS ) = 0;
238 
239 
240 
245  virtual Operator* substitute( int index ,
246  const Operator *sub ) = 0;
247 
248 
249 
256  virtual NeutralElement isOneOrZero() const = 0;
257 
258 
259 
265  virtual BooleanType isDependingOn( VariableType var ) const = 0;
266 
267 
268 
274  virtual BooleanType isDependingOn( int dim ,
275  VariableType *varType ,
276  int *component,
277  BooleanType *implicit_dep ) = 0;
278 
279 
280 
281 
289  virtual BooleanType isLinearIn( int dim ,
290  VariableType *varType ,
291  int *component,
292  BooleanType *implicit_dep ) = 0;
293 
294 
295 
302  virtual BooleanType isPolynomialIn( int dim ,
303  VariableType *varType ,
304  int *component,
305  BooleanType *implicit_dep ) = 0;
306 
307 
308 
315  virtual BooleanType isRationalIn( int dim ,
316  VariableType *varType ,
317  int *component,
318  BooleanType *implicit_dep ) = 0;
319 
325  virtual BooleanType isSmooth( ) const = 0;
326 
327 
334  virtual MonotonicityType getMonotonicity( ) = 0;
335 
336 
337 
345  virtual CurvatureType getCurvature( ) = 0;
346 
347 
348 
354  virtual returnValue setMonotonicity( MonotonicityType monotonicity_ ) = 0;
355 
356 
357 
358 
364  virtual returnValue setCurvature( CurvatureType curvature_ ) = 0;
365 
366 
367 
375  virtual returnValue AD_forward( int number ,
376  double *x ,
378  double *seed ,
379  double *f ,
381  double *df ) = 0;
383 
384 
385 
392  virtual returnValue AD_forward( int number ,
393  double *seed ,
394  double *df ) = 0;
396 
397 
398 
399  // IMPORTANT REMARK FOR AD_BACKWARD: run evaluate first to define
400  // the point x and to compute f.
401 
407  virtual returnValue AD_backward( int number ,
409  double seed ,
410  double *df ) = 0;
412 
413 
414 
422  virtual returnValue AD_forward2( int number ,
424  double *seed1 ,
425  double *seed2 ,
427  double *df ,
429  double *ddf ) = 0;
431 
432 
433 
434  // IMPORTANT REMARK FOR AD_BACKWARD2: run AD_forward first to define
435  // the point x and to compute f and df.
436 
442  virtual returnValue AD_backward2( int number ,
444  double seed1 ,
445  double seed2 ,
446  double *df ,
448  double *ddf ) = 0;
450 
454  virtual std::ostream& print(std::ostream& stream) const = 0;
455 
456 
460  friend std::ostream& operator<<(std::ostream& stream, const Operator& arg);
461 
465  virtual Operator* clone() const = 0;
466 
467 
473  virtual TreeProjection* cloneTreeProjection() const;
474 
475 
476 
481  virtual returnValue clearBuffer() = 0;
482 
483 
484 
489  virtual returnValue enumerateVariables( SymbolicIndexList *indexList ) = 0;
490 
491 
492 
496  virtual OperatorName getName() = 0;
497 
498 
501  //virtual int getVariableIndex( ) const;
502 
503 
506  virtual int getGlobalIndex( ) const;
507 
508 
512  virtual BooleanType isVariable( VariableType &varType,
513  int &component ) const = 0;
514 
515 
534  virtual returnValue loadIndices( SymbolicIndexList *indexList ) = 0;
536 
537 
538 
540  virtual double getValue() const;
541 
542 
543 
545  virtual Operator* passArgument() const;
546 
547 
553  virtual BooleanType isSymbolic() const = 0;
554 
555 
556  int nCount;
557 
558 
559 
563  virtual returnValue setVariableExportName( const VariableType &_type,
564  const std::vector< std::string >& _name
565  );
566 
567 
568 
569 
570  virtual Operator* myProd(Operator* a,Operator* b);
571  virtual Operator* myAdd (Operator* a,Operator* b);
572  virtual Operator* mySubtract (Operator* a,Operator* b);
573  virtual Operator* myPower (Operator* a,Operator* b);
574  virtual Operator* myPowerInt (Operator* a,int b);
575  virtual Operator* myLogarithm (Operator* a);
576 
577 
578  virtual BooleanType isTrivial() const;
579 
580 
581  virtual returnValue initDerivative();
582 
583 
584 //
585 // PROTECTED FUNCTIONS:
586 //
587 
588 protected:
589 
590 
591  virtual TreeProjection* convert2TreeProjection( Operator* a ) const; // Caution: a is deleted inside...
592 
594  TreeProjection &da ,
595  TreeProjection &dda,
596  int dim ,
597  VariableType *varType ,
598  int *component ,
599  Operator *l ,
600  Operator **S ,
601  int dimS ,
602  Operator **dfS ,
603  Operator **ldf ,
604  Operator **H ,
605  int &nNewLIS ,
606  TreeProjection ***newLIS ,
607  int &nNewSIS ,
608  TreeProjection ***newSIS ,
609  int &nNewHIS ,
610  TreeProjection ***newHIS );
611 
612 
614  Operator *b ,
615  TreeProjection &dx ,
616  TreeProjection &dy ,
617  TreeProjection &dxx,
618  TreeProjection &dxy,
619  TreeProjection &dyy,
620  int dim ,
621  VariableType *varType ,
622  int *component ,
623  Operator *l ,
624  Operator **S ,
625  int dimS ,
626  Operator **dfS ,
627  Operator **ldf ,
628  Operator **H ,
629  int &nNewLIS ,
630  TreeProjection ***newLIS ,
631  int &nNewSIS ,
632  TreeProjection ***newSIS ,
633  int &nNewHIS ,
634  TreeProjection ***newHIS );
635 
636  //
637  // PROTECTED MEMBERS:
638  //
639 
640  protected:
641 
643 
644 
645 };
646 
647 
649 
650 
651 
652 #endif
653 
654 
655 
OperatorName
Definition: acado_types.hpp:72
virtual returnValue clearBuffer()=0
virtual int getGlobalIndex() const
Definition: operator.cpp:103
virtual returnValue AD_forward2(int number, double *seed1, double *seed2, double *df, double *ddf)=0
ConstraintComponent operator==(const double &b) const
Definition: operator.cpp:187
virtual MonotonicityType getMonotonicity()=0
Abstract base class for all scalar-valued symbolic operators.
Definition: operator.hpp:60
ConstraintComponent operator>=(const double &lb) const
Definition: operator.cpp:186
virtual BooleanType isDependingOn(VariableType var) const =0
virtual NeutralElement isOneOrZero() const =0
Operator()
Definition: operator.cpp:47
Expression operator*(const double &arg) const
Definition: operator.cpp:154
virtual Operator * myPowerInt(Operator *a, int b)
Definition: operator.cpp:293
virtual Operator * differentiate(int index)=0
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Allows to pass back messages to the calling function.
virtual returnValue loadIndices(SymbolicIndexList *indexList)=0
Expression operator+(const double &arg) const
Definition: operator.cpp:132
virtual Operator * clone() const =0
virtual Operator * substitute(int index, const Operator *sub)=0
virtual returnValue setVariableExportName(const VariableType &_type, const std::vector< std::string > &_name)
Definition: operator.cpp:223
virtual double getValue() const
Definition: operator.cpp:211
#define CLOSE_NAMESPACE_ACADO
virtual BooleanType isSymbolic() const =0
Manages the indices of SymbolicVariables.
Data class for symbolically formulating constraints within optimal control problems.
VariableType
Definition: acado_types.hpp:95
virtual OperatorName getName()=0
BooleanType initialized
Definition: operator.hpp:642
virtual Operator * mySubtract(Operator *a, Operator *b)
Definition: operator.cpp:263
Expression operator/(const double &arg) const
Definition: operator.cpp:177
int nCount
Definition: operator.hpp:556
Operator & operator+=(const double &arg)
Definition: operator.cpp:111
Base class for all variables within the symbolic expressions family.
Definition: expression.hpp:56
virtual Operator * AD_forward(int dim, VariableType *varType, int *component, Operator **seed, int &nNewIS, TreeProjection ***newIS)=0
virtual returnValue enumerateVariables(SymbolicIndexList *indexList)=0
returnValue ADsymCommon2(Operator *a, Operator *b, TreeProjection &dx, TreeProjection &dy, TreeProjection &dxx, TreeProjection &dxy, TreeProjection &dyy, int dim, VariableType *varType, int *component, Operator *l, Operator **S, int dimS, Operator **dfS, Operator **ldf, Operator **H, int &nNewLIS, TreeProjection ***newLIS, int &nNewSIS, TreeProjection ***newSIS, int &nNewHIS, TreeProjection ***newHIS)
Definition: operator.cpp:387
Operator & operator*=(const double &arg)
Definition: operator.cpp:121
virtual returnValue AD_backward2(int number, double seed1, double seed2, double *df, double *ddf)=0
virtual Operator & operator=(const double &arg)
Definition: operator.cpp:56
virtual Operator * myProd(Operator *a, Operator *b)
Definition: operator.cpp:232
virtual TreeProjection * cloneTreeProjection() const
Definition: operator.cpp:92
virtual returnValue AD_backward(int dim, VariableType *varType, int *component, Operator *seed, Operator **df, int &nNewIS, TreeProjection ***newIS)=0
virtual returnValue initDerivative()
Definition: operator.cpp:519
virtual Operator * myAdd(Operator *a, Operator *b)
Definition: operator.cpp:246
returnValue ADsymCommon(Operator *a, TreeProjection &da, TreeProjection &dda, int dim, VariableType *varType, int *component, Operator *l, Operator **S, int dimS, Operator **dfS, Operator **ldf, Operator **H, int &nNewLIS, TreeProjection ***newLIS, int &nNewSIS, TreeProjection ***newSIS, int &nNewHIS, TreeProjection ***newHIS)
Definition: operator.cpp:321
virtual std::ostream & print(std::ostream &stream) const =0
ConstraintComponent operator<=(const double &ub) const
Definition: operator.cpp:185
virtual BooleanType isLinearIn(int dim, VariableType *varType, int *component, BooleanType *implicit_dep)=0
virtual returnValue evaluate(int number, double *x, double *result)=0
NeutralElement
Definition: acado_types.hpp:64
virtual BooleanType isVariable(VariableType &varType, int &component) const =0
friend std::ostream & operator<<(std::ostream &stream, const Operator &arg)
Definition: operator.cpp:213
virtual BooleanType isPolynomialIn(int dim, VariableType *varType, int *component, BooleanType *implicit_dep)=0
virtual BooleanType isSmooth() const =0
MonotonicityType
Expression operator-() const
Definition: operator.cpp:148
virtual Operator * myLogarithm(Operator *a)
Definition: operator.cpp:304
virtual Operator * passArgument() const
Definition: operator.cpp:218
virtual returnValue setCurvature(CurvatureType curvature_)=0
Implements the tree-projection operator within the family of SymbolicOperators.
CurvatureType
virtual TreeProjection * convert2TreeProjection(Operator *a) const
Definition: operator.cpp:312
#define BEGIN_NAMESPACE_ACADO
Abstract base class for templated evaluation of operators.
virtual CurvatureType getCurvature()=0
virtual BooleanType isRationalIn(int dim, VariableType *varType, int *component, BooleanType *implicit_dep)=0
virtual BooleanType isTrivial() const
Definition: operator.cpp:514
virtual ~Operator()
Definition: operator.cpp:53
virtual returnValue setMonotonicity(MonotonicityType monotonicity_)=0
Operator & operator-=(const double &arg)
Definition: operator.cpp:116
virtual Operator * myPower(Operator *a, Operator *b)
Definition: operator.cpp:280
Operator & operator/=(const double &arg)
Definition: operator.cpp:126
virtual returnValue AD_symmetric(int dim, VariableType *varType, int *component, Operator *l, Operator **S, int dimS, Operator **dfS, Operator **ldf, Operator **H, int &nNewLIS, TreeProjection ***newLIS, int &nNewSIS, TreeProjection ***newSIS, int &nNewHIS, TreeProjection ***newHIS)=0


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:54