expression.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 
34 #ifndef ACADO_TOOLKIT_EXPRESSION_HPP
35 #define ACADO_TOOLKIT_EXPRESSION_HPP
36 
39 
41 
42 class Operator;
43 
57 {
58  friend class COperator;
59  friend class CFunction;
60  friend class FunctionEvaluationTree;
61 
62 public:
64  Expression( );
65 
67  Expression( const Operator &tree_ );
68 
70  explicit Expression( const std::string& name_
71  );
72 
74  explicit Expression( const std::string& name_,
75  uint nRows_,
76  uint nCols_,
77  VariableType variableType_ = VT_UNKNOWN,
78  uint globalTypeID = 0
79  );
80 
82  explicit Expression( int nRows_ ,
83  int nCols_ = 1 ,
84  VariableType variableType_ = VT_UNKNOWN,
85  int globalTypeID = 0
86  );
87 
89  explicit Expression( uint nRows_ ,
90  uint nCols_ = 1 ,
91  VariableType variableType_ = VT_UNKNOWN,
92  uint globalTypeID = 0
93  );
94 
96  Expression( const double& rhs );
97  Expression( const DVector & rhs );
98  Expression( const DMatrix & rhs );
99  Expression( const Expression & rhs );
100 
102  virtual ~Expression( );
103 
105  virtual Expression* clone() const
106  { return new Expression( *this ); }
107 
109  Expression& operator=( const Expression& arg );
110 
112  Expression& operator<<( const Expression & arg );
113 
120  Expression& appendRows(const Expression& arg);
121 
128  Expression& appendCols(const Expression& arg);
129 
130  Expression operator()( uint idx ) const;
131  Expression operator()( uint rowIdx, uint colIdx ) const;
132 
133  Operator& operator()( uint idx );
134  Operator& operator()( uint rowIdx, uint colIdx );
135 
136  friend Expression operator+( const Expression & arg1, const Expression & arg2 );
137  friend Expression operator-( const Expression & arg1, const Expression & arg2 );
138  Expression operator-( ) const;
139  friend Expression operator*( const Expression & arg1, const Expression & arg2 );
140  friend Expression operator/( const Expression & arg1, const Expression & arg2 );
141 
142  Expression& operator+=(const Expression &arg);
143  Expression& operator-=(const Expression &arg);
144  Expression& operator*=(const Expression &arg);
145  Expression& operator/=(const Expression &arg);
146 
147  std::ostream& print( std::ostream &stream ) const;
148  friend std::ostream& operator<<( std::ostream& stream, const Expression &arg );
149 
151  Expression getInverse( ) const;
152 
153  Expression getRow( const uint& rowIdx ) const;
154  Expression getRows( const uint& rowIdx1, const uint& rowIdx2 ) const;
155  Expression getCol( const uint& colIdx ) const;
156  Expression getCols( const uint& colIdx1, const uint& colIdx2 ) const;
157  Expression getSubMatrix( const uint& rowIdx1, const uint& rowIdx2, const uint& colIdx1, const uint& colIdx2 ) const;
158 
163  DMatrix getDependencyPattern( const Expression& arg ) const;
164 
165  DMatrix getSparsityPattern() const;
166 
167  Expression getSin ( ) const;
168  Expression getCos ( ) const;
169  Expression getTan ( ) const;
170  Expression getAsin ( ) const;
171  Expression getAcos ( ) const;
172  Expression getAtan ( ) const;
173  Expression getExp ( ) const;
174  Expression getSqrt ( ) const;
175  Expression getLn ( ) const;
176 
177  Expression getPow ( const Expression &arg ) const;
178  Expression getPowInt( const int &arg ) const;
179 
180  Expression getSumSquare ( ) const;
181  Expression getLogSumExp ( ) const;
182  Expression getEuclideanNorm( ) const;
183  Expression getEntropy ( ) const;
184 
185  Expression getDot ( ) const;
186  Expression getNext ( ) const;
187 
188  Expression ADforward ( const Expression &arg ) const;
189  Expression ADforward ( const VariableType &varType_, const int *arg, int nV ) const;
190  Expression ADbackward ( const Expression &arg ) const;
191 
209  Expression ADsymmetric( const Expression &arg,
210  const Expression &S ,
211  const Expression &l ,
212  Expression *dfS = 0,
213  Expression *ldf = 0
214  ) const;
215 
233  Expression ADsymmetric( const Expression &arg,
234  const Expression &l ,
235  Expression *dfS = 0,
236  Expression *ldf = 0
237  ) const;
238 
239  Expression getODEexpansion( const int &order, const int *arg ) const;
240 
241  Expression ADforward ( const Expression &arg, const Expression &seed ) const;
242  Expression ADforward ( const VariableType &varType_, const int *arg, const Expression &seed ) const;
243  Expression ADforward ( const VariableType *varType_, const int *arg, const Expression &seed ) const;
244  Expression ADbackward( const Expression &arg, const Expression &seed ) const;
245 
248  Expression transpose( ) const;
249 
252  inline uint getDim( ) const;
253 
256  inline uint getNumRows( ) const;
257 
260  inline uint getNumCols( ) const;
261 
264  inline uint getComponent( const unsigned int idx ) const;
265 
268  inline BooleanType isVariable( ) const;
269 
272  Operator* getOperatorClone( uint idx ) const;
273 
276  inline VariableType getVariableType( ) const;
277 
278  BooleanType isDependingOn( VariableType type ) const;
279  BooleanType isDependingOn(const Expression &e ) const;
280 
282  returnValue substitute( int idx, const Expression &arg ) const;
283 
284 protected:
285 
286  Expression add(const Expression& arg) const;
287  Expression sub(const Expression& arg) const;
288  Expression mul(const Expression& arg) const;
289  Expression div(const Expression& arg) const;
290 
292  void construct( VariableType variableType_,
293  uint globalTypeID_,
294  uint nRows_,
295  uint nCols_,
296  const std::string& name_ );
297 
299  void copy( const Expression &rhs );
300 
302  void deleteAll( );
303 
306  Expression& assignmentSetup( const Expression &arg );
307 
309  Operator* product( const Operator *a, const Operator *b ) const;
310 
316  std::string name ;
317 };
318 
320 
321 #include <acado/symbolic_expression/expression.ipp>
322 
324 
339 template<class Derived, VariableType Type, bool AllowCounter = true>
341 {
342 public:
343 
346  : Expression("", 1, 1, Type, AllowCounter ? count : 0)
347  {
348  if (AllowCounter == true)
349  count++;
350  }
351 
353  ExpressionType(const std::string& _name, unsigned _nRows, unsigned _nCols)
354  : Expression(_name, _nRows, _nCols, Type, AllowCounter ? count : 0)
355  {
356  if (AllowCounter == true)
357  count += _nRows * _nCols;
358  }
359 
361  ExpressionType(const Expression& _expression, unsigned _componentIdx = 0)
362  : Expression( _expression )
363  {
364  variableType = Type;
365  component += _componentIdx;
366  if (AllowCounter == true)
367  count++;
368  }
369 
371  ExpressionType( const double& _arg )
372  : Expression( _arg )
373  {}
374 
376  ExpressionType( const DVector& _arg )
377  : Expression( _arg )
378  {}
379 
381  ExpressionType( const DMatrix& _arg )
382  : Expression( _arg )
383  {}
384 
386  ExpressionType( const Operator& _arg )
387  : Expression( _arg )
388  {}
389 
391  virtual ~ExpressionType() {}
392 
394  virtual Expression* clone() const
395  { return new Derived( static_cast< Derived const& >( *this ) ); }
396 
399  { count = 0; return SUCCESSFUL_RETURN; }
400 
401 private:
402  static unsigned count;
403 };
404 
405 template<class Derived, VariableType Type, bool AllowCounter>
407 
409 
410 #endif // ACADO_TOOLKIT_EXPRESSION_HPP
VariableType variableType
Definition: expression.hpp:314
Operator * getOperatorClone(uint idx) const
virtual ~Expression()
Definition: expression.cpp:126
Expression getAtan() const
Definition: expression.cpp:733
BooleanType isVariable() const
Expression & operator-=(const Expression &arg)
Definition: expression.cpp:310
Expression getEntropy() const
Definition: expression.cpp:945
Expression getPow(const Expression &arg) const
Definition: expression.cpp:782
friend Expression operator+(const Expression &arg1, const Expression &arg2)
Definition: expression.cpp:298
returnValue substitute(int idx, const Expression &arg) const
Abstract base class for all scalar-valued symbolic operators.
Definition: operator.hpp:60
Expression ADsymmetric(const Expression &arg, const Expression &S, const Expression &l, Expression *dfS=0, Expression *ldf=0) const
Expression getCol(const uint &colIdx) const
Definition: expression.cpp:567
Expression operator-() const
Expression getRow(const uint &rowIdx) const
Definition: expression.cpp:533
Expression div(const Expression &arg) const
Definition: expression.cpp:474
Allows to pass back messages to the calling function.
uint getNumCols() const
uint getNumRows() const
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
Expression getCols(const uint &colIdx1, const uint &colIdx2) const
Definition: expression.cpp:582
void copy(const Expression &rhs)
Expression operator()(uint idx) const
Definition: expression.cpp:218
Expression getLogSumExp() const
Definition: expression.cpp:860
Expression getDot() const
Definition: expression.cpp:952
#define CLOSE_NAMESPACE_ACADO
std::ostream & print(std::ostream &stream) const
Definition: expression.cpp:198
Expression mul(const Expression &arg) const
Definition: expression.cpp:412
Expression sub(const Expression &arg) const
Definition: expression.cpp:350
VariableType
Definition: acado_types.hpp:95
Operator * product(const Operator *a, const Operator *b) const
Definition: expression.cpp:382
Expression getSqrt() const
Definition: expression.cpp:757
std::string name
Definition: expression.hpp:316
BooleanType isDependingOn(VariableType type) const
Expression & operator*=(const Expression &arg)
Definition: expression.cpp:313
Base class for all variables within the symbolic expressions family.
Definition: expression.hpp:56
Expression getPowInt(const int &arg) const
Definition: expression.cpp:797
Expression getInverse() const
Definition: expression.cpp:490
Expression getExp() const
Definition: expression.cpp:745
virtual Expression * clone() const
Definition: expression.hpp:105
Expression getTan() const
Definition: expression.cpp:697
Expression getSumSquare() const
Definition: expression.cpp:828
Operator ** element
Definition: expression.hpp:311
Expression ADforward(const Expression &arg) const
Definition: expression.cpp:971
void construct(VariableType variableType_, uint globalTypeID_, uint nRows_, uint nCols_, const std::string &name_)
Expression getAsin() const
Definition: expression.cpp:709
Expression add(const Expression &arg) const
Definition: expression.cpp:319
Expression & operator<<(const Expression &arg)
Definition: expression.cpp:175
Expression & operator=(const Expression &arg)
Definition: expression.cpp:131
DMatrix getDependencyPattern(const Expression &arg) const
Definition: expression.cpp:623
Expression & appendRows(const Expression &arg)
Definition: expression.cpp:141
virtual ~ExpressionType()
Definition: expression.hpp:391
DMatrix getSparsityPattern() const
Definition: expression.cpp:656
The class COperator is an auxiliary class to use C-Functions within a function evaluation tree...
Definition: c_operator.hpp:58
friend Expression operator*(const Expression &arg1, const Expression &arg2)
Definition: expression.cpp:302
void rhs(const real_t *x, real_t *f)
ExpressionType(const std::string &_name, unsigned _nRows, unsigned _nCols)
Definition: expression.hpp:353
ExpressionType(const DVector &_arg)
Definition: expression.hpp:376
uint component
Definition: expression.hpp:315
Expression transpose() const
Definition: expression.cpp:811
ExpressionType(const DMatrix &_arg)
Definition: expression.hpp:381
Expression getNext() const
Definition: expression.cpp:965
friend Expression operator/(const Expression &arg1, const Expression &arg2)
Definition: expression.cpp:304
VariableType getVariableType() const
Organizes the evaluation of the function tree.
Expression & assignmentSetup(const Expression &arg)
void deleteAll()
Expression getODEexpansion(const int &order, const int *arg) const
Expression getAcos() const
Definition: expression.cpp:721
(no description yet)
Definition: c_function.hpp:54
uint getComponent(const unsigned int idx) const
Expression getSin() const
Definition: expression.cpp:673
virtual Expression * clone() const
Definition: expression.hpp:394
Expression getLn() const
Definition: expression.cpp:769
Expression getSubMatrix(const uint &rowIdx1, const uint &rowIdx2, const uint &colIdx1, const uint &colIdx2) const
Definition: expression.cpp:601
#define BEGIN_NAMESPACE_ACADO
returnValue clearStaticCounters()
Definition: expression.hpp:398
Expression getEuclideanNorm() const
Definition: expression.cpp:912
static unsigned count
Definition: expression.hpp:402
Expression ADbackward(const Expression &arg) const
Expression & operator+=(const Expression &arg)
Definition: expression.cpp:307
Expression & appendCols(const Expression &arg)
Definition: expression.cpp:162
Expression getCos() const
Definition: expression.cpp:685
ExpressionType(const Operator &_arg)
Definition: expression.hpp:386
Expression getRows(const uint &rowIdx1, const uint &rowIdx2) const
Definition: expression.cpp:548
ExpressionType(const double &_arg)
Definition: expression.hpp:371
Expression & operator/=(const Expression &arg)
Definition: expression.cpp:316
uint getDim() const
ExpressionType(const Expression &_expression, unsigned _componentIdx=0)
Definition: expression.hpp:361


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