taylor_variable.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_TAYLOR_VARIABLE_HPP
35 #define ACADO_TOOLKIT_TAYLOR_VARIABLE_HPP
36 
38 
39 
41 
49 template <typename T>
50 class TaylorVariable
52 {
53  // friends of class TaylorVariable
54  template <typename U> friend void TaylorModel<U>::_size
55  ( const unsigned int nvar, const unsigned int nord );
56 
57  template <typename U> friend class TaylorVariable;
58 
59  template <typename U> friend TaylorVariable<U> operator+
60  ( const TaylorVariable<U>& );
61  template <typename U, typename V> friend TaylorVariable<U> operator+
62  ( const TaylorVariable<U>&, const TaylorVariable<V>& );
63  template <typename U, typename V> friend TaylorVariable<U> operator+
64  ( const TaylorVariable<U>&, const V& );
65  template <typename U, typename V> friend TaylorVariable<U> operator+
66  ( const V&, const TaylorVariable<U>& );
67  template <typename U> friend TaylorVariable<U> operator+
68  ( const double, const TaylorVariable<U>& );
69  template <typename U> friend TaylorVariable<U> operator+
70  ( const TaylorVariable<U>&, const double );
71  template <typename U> friend TaylorVariable<U> operator-
72  ( const TaylorVariable<U>& );
73  template <typename U, typename V> friend TaylorVariable<U> operator-
74  ( const TaylorVariable<U>&, const TaylorVariable<V>& );
75  template <typename U, typename V> friend TaylorVariable<U> operator-
76  ( const TaylorVariable<U>&, const V& );
77  template <typename U, typename V> friend TaylorVariable<U> operator-
78  ( const V&, const TaylorVariable<U>& );
79  template <typename U> friend TaylorVariable<U> operator-
80  ( const double, const TaylorVariable<U>& );
81  template <typename U> friend TaylorVariable<U> operator-
82  ( const TaylorVariable<U>&, const double );
83  template <typename U> friend TaylorVariable<U> operator*
84  ( const TaylorVariable<U>&, const TaylorVariable<U>& );
85  template <typename U> friend TaylorVariable<U> operator*
86  ( const double, const TaylorVariable<U>& );
87  template <typename U> friend TaylorVariable<U> operator*
88  ( const TaylorVariable<U>&, const double );
89  template <typename U> friend TaylorVariable<U> operator*
90  ( const U&, const TaylorVariable<U>& );
91  template <typename U> friend TaylorVariable<U> operator*
92  ( const TaylorVariable<U>&, const U& );
93  template <typename U> friend TaylorVariable<U> operator/
94  ( const TaylorVariable<U>&, const TaylorVariable<U>& );
95  template <typename U> friend TaylorVariable<U> operator/
96  ( const double, const TaylorVariable<U>& );
97  template <typename U> friend TaylorVariable<U> operator/
98  ( const TaylorVariable<U>&, const double );
99  template <typename U> friend std::ostream& operator<<
100  ( std::ostream&, const TaylorVariable<U>& );
101 
102  template <typename U> friend TaylorVariable<U> inv
103  ( const TaylorVariable<U>& );
104  template <typename U> friend TaylorVariable<U> sqr
105  ( const TaylorVariable<U>& );
106  template <typename U> friend TaylorVariable<U> sqrt
107  ( const TaylorVariable<U>& );
108  template <typename U> friend TaylorVariable<U> exp
109  ( const TaylorVariable<U>& );
110  template <typename U> friend TaylorVariable<U> log
111  ( const TaylorVariable<U>& );
112  template <typename U> friend TaylorVariable<U> xlog
113  ( const TaylorVariable<U>& );
114  template <typename U> friend TaylorVariable<U> pow
115  ( const TaylorVariable<U>&, const int );
116  template <typename U> friend TaylorVariable<U> pow
117  ( const TaylorVariable<U>&, const double );
118  template <typename U> friend TaylorVariable<U> pow
119  ( const double, const TaylorVariable<U>& );
120  template <typename U> friend TaylorVariable<U> pow
121  ( const TaylorVariable<U>&, const TaylorVariable<U>& );
122  template <typename U> friend TaylorVariable<U> cos
123  ( const TaylorVariable<U>& );
124  template <typename U> friend TaylorVariable<U> sin
125  ( const TaylorVariable<U>& );
126  template <typename U> friend TaylorVariable<U> tan
127  ( const TaylorVariable<U>& );
128  template <typename U> friend TaylorVariable<U> acos
129  ( const TaylorVariable<U>& );
130  template <typename U> friend TaylorVariable<U> asin
131  ( const TaylorVariable<U>& );
132  template <typename U> friend TaylorVariable<U> atan
133  ( const TaylorVariable<U>& );
134  template <typename U> friend TaylorVariable<U> hull
135  ( const TaylorVariable<U>&, const TaylorVariable<U>& );
136  template <typename U> friend bool inter
137  ( TaylorVariable<U>&, const TaylorVariable<U>&, const TaylorVariable<U>& );
138 
139 private:
144  { return _TM->_TV; };
146  unsigned int _nord() const
147  { return _TM->_nord; };
149  unsigned int _nvar() const
150  { return _TM->_nvar; };
152  unsigned int _nmon() const
153  { return _TM->_nmon; };
155  unsigned int _posord
156  ( const unsigned int i ) const
157  { return _TM->_posord[i]; };
159  unsigned int _expmon
160  ( const unsigned int i ) const
161  { return _TM->_expmon[i]; };
163  unsigned int _prodmon
164  ( const unsigned int i, const unsigned int j ) const
165  { return _TM->_prodmon[i][j]; };
167  const T& _bndmon
168  ( const unsigned int i ) const
169  { return _TM->_bndmon[i]; };
171  double _refpoint
172  ( const unsigned int i ) const
173  { return _TM->_refpoint[i]; };
175  double _scaling
176  ( const unsigned int i ) const
177  { return _TM->_scaling[i]; };
178 
179 public:
185  ( const double d=0. );
188  ( const T&B );
191  ( TaylorModel<T>*TM, const unsigned int ix, const T&X );
194  ( const TaylorVariable<T>&TV );
196  template <typename U> TaylorVariable
197  ( TaylorModel<T>*&TM, const TaylorVariable<U>&TV );
199  template <typename U> TaylorVariable
200  ( TaylorModel<T>*&TM, const TaylorVariable<U>&TV, const T& (U::*method)() const );
202  template <typename U> TaylorVariable
203  ( TaylorModel<T>*&TM, const TaylorVariable<U>&TV, T (*method)( const U& ) );
204 
207  { delete [] _coefmon; delete [] _bndord; }
208 
210  TaylorVariable<T>& set
211  ( TaylorModel<T>*TM, const unsigned int ix, const T&X )
212  { *this = TaylorVariable( TM, ix, X ); return *this; }
213 
216  { return _TM; }
217 
219  T bound() const
220  { T bndmod; return _bound( bndmod ); }
221 
223  T B() const
224  { T bndmod; return _bound( bndmod ); }
225 
227  const T& boundT() const
228  { return _bndT; }
229 
231  T remainder() const
232  { return( *_bndrem ); }
233 
235  T R() const
236  { return remainder(); }
237 
239  //T& R()
240  // { return remainder(); }
241 
244  { _center_TM(); return *this; }
245 
248  { return center(); }
249 
252  { TaylorVariable<T> TV = *this; *(TV._bndrem) = 0.; return TV; }
253 
255  double polynomial
256  ( const double*x ) const;
257 
260  { return polynomial(); }
261 
263  double P
264  ( const double*x ) const
265  { return polynomial( x ); }
266 
268  double* reference() const;
269 
271  double constant() const;
272 
274  double* linear() const;
275 
277  double* quadratic
278  ( const int opt=0 ) const;
281  TaylorVariable<T>& operator =
283  ( const double );
284  TaylorVariable<T>& operator =
285  ( const TaylorVariable<T>& );
286  TaylorVariable<T>& operator =
287  ( const T& );
288  template <typename U> TaylorVariable<T>& operator +=
289  ( const TaylorVariable<U>& );
290  template <typename U> TaylorVariable<T>& operator +=
291  ( const U& );
292  TaylorVariable<T>& operator +=
293  ( const double );
294  template <typename U> TaylorVariable<T>& operator -=
295  ( const TaylorVariable<U>& );
296  template <typename U> TaylorVariable<T>& operator -=
297  ( const U& );
298  TaylorVariable<T>& operator -=
299  ( const double );
300  TaylorVariable<T>& operator *=
301  ( const TaylorVariable<T>& );
302  TaylorVariable<T>& operator *=
303  ( const double );
304  TaylorVariable<T>& operator *=
305  ( const T& );
306  TaylorVariable<T>& operator /=
307  ( const TaylorVariable<T>& );
308  TaylorVariable<T>& operator /=
309  ( const double );
310 
311 
312 
315  BooleanType isCompact() const;
316 
317 
318 
321  ( TaylorModel<T>*TM, const double d=0. );
322 
323 private:
324 
325 
328  ( TaylorModel<T>*TM, const T&B );
329 
331  double *_coefmon;
333  T * _bndord;
338 
340  void _init();
342  void _reinit();
344  void _clean();
345 
347  void _update_bndord();
348 
350  void _center_TM();
351 
353  T& _bound
354  ( T& bndmod ) const;
356  T& _bound_naive
357  ( T& bndmod ) const;
359  T& _bound_LSB
360  ( T& bndmod ) const;
362  T& _bound_eigen
363  ( T& bndmod ) const;
365  static double* _eigen
366  ( const unsigned int n, double*a );
367 
370  ( const TaylorVariable<T>&TM, const int n );
371 
372 };
373 
374 
376 
377 //#include <acado/set_arithmetics/interval.ipp>
378 
379 #endif // ACADO_TOOLKIT_TAYLOR_VARIABLE_HPP
380 
void _init()
Initialize private members.
friend TaylorVariable< U > sqr(const TaylorVariable< U > &)
unsigned int _prodmon(const unsigned int i, const unsigned int j) const
Get exponents of monomial term products in TaylorModel.
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
double * quadratic(const int opt=0) const
Return pointer to array of size nvar comprising coefficients in quadratic term (diagonal coefs if opt...
C++ template class for definition of and operation on variables in a Taylor model.
TaylorVariable< T > & center()
Return reference to current remainder.
friend TaylorVariable< U > sqrt(const TaylorVariable< U > &)
T & _bound_LSB(T &bndmod) const
Range bounder - Lin & Stadtherr approach.
friend TaylorVariable< U > cos(const TaylorVariable< U > &)
friend TaylorVariable< U > sin(const TaylorVariable< U > &)
const T & _bndmon(const unsigned int i) const
Get bounds on all monomial terms in TaylorModel.
double * _refpoint
Reference point.
double * _coefmon
Coefficients for monomial terms 1,...,nmon.
unsigned int * _posord
Positions of terms of degrees 1,...,_nord.
friend TaylorVariable< U > exp(const TaylorVariable< U > &)
TaylorModel< T > * env() const
Return pointer to TaylorModel environment.
T _bndT
Interval bound evaluated in T arithmetic.
double constant() const
Return coefficient value in constant term.
double * _scaling
Variable scaling.
unsigned int _expmon(const unsigned int i) const
Get monomial term exponents in TaylorModel.
void _center_TM()
Center remainder error term _bndrem.
T & _bound_naive(T &bndmod) const
Range bounder - naive approach.
TaylorVariable< T > P() const
Cancel remainder error term and return polynomial part.
T * _bndmon
Bounds on all the monomial terms 1,...,_nmon for given interval vector .
#define CLOSE_NAMESPACE_ACADO
void _update_bndord()
Update _bndord w/ (naive) bounds for individual terms of degrees 0,...,_nord()
unsigned int _nord
Model order of the model.
BooleanType isCompact() const
void _reinit()
Reinitialize private members.
friend TaylorVariable< U > acos(const TaylorVariable< U > &)
friend TaylorVariable< U > asin(const TaylorVariable< U > &)
~TaylorVariable()
Class destructor.
unsigned int _nord() const
Get model order in TaylorModel.
unsigned int _nmon
Number of monomial terms.
void _clean()
Clean private members.
TaylorVariable< T > polynomial() const
Cancel remainder term and return polynomial part.
unsigned int * _expmon
Variable exponents for monomial terms 1,...,_nmon.
T B() const
Return range bounder.
friend TaylorVariable< U > atan(const TaylorVariable< U > &)
friend bool inter(TaylorVariable< U > &, const TaylorVariable< U > &, const TaylorVariable< U > &)
double * reference() const
Return pointer to array of size nvar comprising reference point.
friend TaylorVariable< U > inv(const TaylorVariable< U > &)
friend TaylorVariable< U > log(const TaylorVariable< U > &)
T & _bound_eigen(T &bndmod) const
Range bounder - eignevalue decomposition-based approach.
double * linear() const
Return pointer to array of size nvar comprising coefficients in linear term.
friend TaylorVariable< U > xlog(const TaylorVariable< U > &)
unsigned int _nvar
Number of independent variables.
T * _bndrem
Pointer to the remainder error bound.
TaylorVariable< T > * _TV
Taylor variable to speed-up computations and reduce dynamic allocation.
double _refpoint(const unsigned int i) const
Get reference point in TaylorModel.
T & _bound(T &bndmod) const
Range bounder.
const T & boundT() const
Return reference to range bounder in T arithmetic.
friend TaylorVariable< U > pow(const TaylorVariable< U > &, const int)
TaylorVariable< T > * _TV() const
Get pointer to internal TaylorVariable in TaylorModel.
T * _bndord
Bounds for individual terms of degrees 0,...,_nord+1.
unsigned int _nvar() const
Get number of variables in TaylorModel.
#define BEGIN_NAMESPACE_ACADO
unsigned int _nmon() const
Get number of monomial terms in TaylorModel.
TaylorVariable< T > & C()
Recenter remainder term.
double _scaling(const unsigned int i) const
Get scaling in TaylorModel.
friend TaylorVariable< U > hull(const TaylorVariable< U > &, const TaylorVariable< U > &)
T R() const
Return const reference to current remainder.
friend TaylorVariable< U > tan(const TaylorVariable< U > &)
static double * _eigen(const unsigned int n, double *a)
Wrapper to LAPACK function _dsyev doing eigenvalue decomposition of a symmetric matrix.
friend class TaylorVariable
T bound() const
Return range bounder.
TaylorModel< T > * _TM
Pointer to underlying TaylorModel object.
unsigned int _posord(const unsigned int i) const
Get term positions in TaylorModel.
T remainder() const
Return const reference to current remainder.
unsigned int ** _prodmon
Variable exponents resulting from the product of two monomial terms 1,...,_nmon.
void _size(const unsigned int nvar, const unsigned int nord)
Set the order (nord) and number of variables (nvar)
TaylorVariable< T > _intpow(const TaylorVariable< T > &TM, const int n)
Recursive calculation of nonnegative integer powers.
C++ class supporting the definition and computation of Taylor models for factorable functions...


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