taylor_variable.hpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00034 #ifndef ACADO_TOOLKIT_TAYLOR_VARIABLE_HPP
00035 #define ACADO_TOOLKIT_TAYLOR_VARIABLE_HPP
00036 
00037 #include <acado/utils/acado_utils.hpp>
00038 
00039 
00040 BEGIN_NAMESPACE_ACADO
00041 
00049 template <typename T>
00050 class TaylorVariable
00052 {
00053   // friends of class TaylorVariable
00054   template <typename U> friend void TaylorModel<U>::_size
00055     ( const unsigned int nvar, const unsigned int nord );
00056 
00057   template <typename U> friend class TaylorVariable;
00058 
00059   template <typename U> friend TaylorVariable<U> operator+
00060     ( const TaylorVariable<U>& );
00061   template <typename U, typename V> friend TaylorVariable<U> operator+
00062     ( const TaylorVariable<U>&, const TaylorVariable<V>& );
00063   template <typename U, typename V> friend TaylorVariable<U> operator+
00064     ( const TaylorVariable<U>&, const V& );
00065   template <typename U, typename V> friend TaylorVariable<U> operator+
00066     ( const V&, const TaylorVariable<U>& );
00067   template <typename U> friend TaylorVariable<U> operator+
00068     ( const double, const TaylorVariable<U>& );
00069   template <typename U> friend TaylorVariable<U> operator+
00070     ( const TaylorVariable<U>&, const double );
00071   template <typename U> friend TaylorVariable<U> operator-
00072     ( const TaylorVariable<U>& );
00073   template <typename U, typename V> friend TaylorVariable<U> operator-
00074     ( const TaylorVariable<U>&, const TaylorVariable<V>& );
00075   template <typename U, typename V> friend TaylorVariable<U> operator-
00076     ( const TaylorVariable<U>&, const V& );
00077   template <typename U, typename V> friend TaylorVariable<U> operator-
00078     ( const V&, const TaylorVariable<U>& );
00079   template <typename U> friend TaylorVariable<U> operator-
00080     ( const double, const TaylorVariable<U>& );
00081   template <typename U> friend TaylorVariable<U> operator-
00082     ( const TaylorVariable<U>&, const double );
00083   template <typename U> friend TaylorVariable<U> operator*
00084     ( const TaylorVariable<U>&, const TaylorVariable<U>& );
00085   template <typename U> friend TaylorVariable<U> operator*
00086     ( const double, const TaylorVariable<U>& );
00087   template <typename U> friend TaylorVariable<U> operator*
00088     ( const TaylorVariable<U>&, const double );
00089   template <typename U> friend TaylorVariable<U> operator*
00090     ( const U&, const TaylorVariable<U>& );
00091   template <typename U> friend TaylorVariable<U> operator*
00092     ( const TaylorVariable<U>&, const U& );
00093   template <typename U> friend TaylorVariable<U> operator/
00094     ( const TaylorVariable<U>&, const TaylorVariable<U>& );
00095   template <typename U> friend TaylorVariable<U> operator/
00096     ( const double, const TaylorVariable<U>& );
00097   template <typename U> friend TaylorVariable<U> operator/
00098     ( const TaylorVariable<U>&, const double );
00099   template <typename U> friend std::ostream& operator<<
00100     ( std::ostream&, const TaylorVariable<U>& );
00101 
00102   template <typename U> friend TaylorVariable<U> inv
00103     ( const TaylorVariable<U>& );
00104   template <typename U> friend TaylorVariable<U> sqr
00105     ( const TaylorVariable<U>& );
00106   template <typename U> friend TaylorVariable<U> sqrt
00107     ( const TaylorVariable<U>& );
00108   template <typename U> friend TaylorVariable<U> exp
00109     ( const TaylorVariable<U>& );
00110   template <typename U> friend TaylorVariable<U> log
00111     ( const TaylorVariable<U>& );
00112   template <typename U> friend TaylorVariable<U> xlog
00113     ( const TaylorVariable<U>& );
00114   template <typename U> friend TaylorVariable<U> pow
00115     ( const TaylorVariable<U>&, const int );
00116   template <typename U> friend TaylorVariable<U> pow
00117     ( const TaylorVariable<U>&, const double );
00118   template <typename U> friend TaylorVariable<U> pow
00119     ( const double, const TaylorVariable<U>& );
00120   template <typename U> friend TaylorVariable<U> pow
00121     ( const TaylorVariable<U>&, const TaylorVariable<U>& );
00122   template <typename U> friend TaylorVariable<U> cos
00123     ( const TaylorVariable<U>& );
00124   template <typename U> friend TaylorVariable<U> sin
00125     ( const TaylorVariable<U>& );
00126   template <typename U> friend TaylorVariable<U> tan
00127     ( const TaylorVariable<U>& );
00128   template <typename U> friend TaylorVariable<U> acos
00129     ( const TaylorVariable<U>& );
00130   template <typename U> friend TaylorVariable<U> asin
00131     ( const TaylorVariable<U>& );
00132   template <typename U> friend TaylorVariable<U> atan
00133     ( const TaylorVariable<U>& );
00134   template <typename U> friend TaylorVariable<U> hull
00135     ( const TaylorVariable<U>&, const TaylorVariable<U>& );
00136   template <typename U> friend bool inter
00137     ( TaylorVariable<U>&, const TaylorVariable<U>&, const TaylorVariable<U>& );
00138 
00139 private:
00141   TaylorModel<T> *_TM;
00143   TaylorVariable<T>* _TV() const
00144     { return _TM->_TV; };
00146   unsigned int _nord() const
00147     { return _TM->_nord; };
00149   unsigned int _nvar() const
00150     { return _TM->_nvar; };
00152   unsigned int _nmon() const
00153     { return _TM->_nmon; };
00155   unsigned int _posord
00156     ( const unsigned int i ) const
00157     { return _TM->_posord[i]; };
00159   unsigned int _expmon
00160     ( const unsigned int i ) const
00161     { return _TM->_expmon[i]; };
00163   unsigned int _prodmon
00164     ( const unsigned int i, const unsigned int j ) const
00165     { return _TM->_prodmon[i][j]; };
00167   const T& _bndmon
00168     ( const unsigned int i ) const
00169     { return _TM->_bndmon[i]; };
00171   double _refpoint
00172     ( const unsigned int i ) const
00173     { return _TM->_refpoint[i]; };
00175   double _scaling
00176     ( const unsigned int i ) const
00177     { return _TM->_scaling[i]; };
00178 
00179 public:
00183 
00184   TaylorVariable
00185     ( const double d=0. );
00187   TaylorVariable
00188     ( const T&B );
00190   TaylorVariable
00191     ( TaylorModel<T>*TM, const unsigned int ix, const T&X );
00193   TaylorVariable
00194     ( const TaylorVariable<T>&TV );
00196   template <typename U> TaylorVariable
00197     ( TaylorModel<T>*&TM, const TaylorVariable<U>&TV );
00199   template <typename U> TaylorVariable
00200     ( TaylorModel<T>*&TM, const TaylorVariable<U>&TV, const T& (U::*method)() const );
00202   template <typename U> TaylorVariable
00203     ( TaylorModel<T>*&TM, const TaylorVariable<U>&TV, T (*method)( const U& ) );
00204 
00206   ~TaylorVariable()
00207     { delete [] _coefmon; delete [] _bndord; }
00208 
00210   TaylorVariable<T>& set
00211     ( TaylorModel<T>*TM, const unsigned int ix, const T&X )
00212     { *this = TaylorVariable( TM, ix, X ); return *this; }
00213 
00215   TaylorModel<T>* env() const
00216     { return _TM; }
00217 
00219   T bound() const
00220     { T bndmod; return _bound( bndmod ); }
00221 
00223   T B() const
00224     { T bndmod; return _bound( bndmod ); }
00225 
00227   const T& boundT() const
00228     { return _bndT; }
00229 
00231   T remainder() const
00232     { return( *_bndrem ); }
00233 
00235   T R() const
00236     { return remainder(); }
00237 
00239   //T& R()
00240   //  { return remainder(); }
00241 
00243   TaylorVariable<T>& center()
00244     { _center_TM(); return *this; }
00245 
00247   TaylorVariable<T>& C()
00248     { return center(); }
00249 
00251   TaylorVariable<T> polynomial() const
00252   { TaylorVariable<T> TV = *this; *(TV._bndrem) = 0.; return TV; }
00253 
00255   double polynomial
00256     ( const double*x ) const;
00257 
00259   TaylorVariable<T> P() const
00260     { return polynomial(); }
00261 
00263   double P
00264     ( const double*x ) const
00265     { return polynomial( x ); }
00266 
00268   double* reference() const;
00269 
00271   double constant() const;
00272 
00274   double* linear() const;
00275 
00277   double* quadratic
00278     ( const int opt=0 ) const;
00281 
00282   TaylorVariable<T>& operator =
00283     ( const double );
00284   TaylorVariable<T>& operator =
00285     ( const TaylorVariable<T>& );
00286   TaylorVariable<T>& operator =
00287     ( const T& );
00288   template <typename U> TaylorVariable<T>& operator +=
00289     ( const TaylorVariable<U>& );
00290   template <typename U> TaylorVariable<T>& operator +=
00291     ( const U& );
00292   TaylorVariable<T>& operator +=
00293     ( const double );
00294   template <typename U> TaylorVariable<T>& operator -=
00295     ( const TaylorVariable<U>& );
00296   template <typename U> TaylorVariable<T>& operator -=
00297     ( const U& );
00298   TaylorVariable<T>& operator -=
00299     ( const double );
00300   TaylorVariable<T>& operator *=
00301     ( const TaylorVariable<T>& );
00302   TaylorVariable<T>& operator *=
00303     ( const double );
00304   TaylorVariable<T>& operator *=
00305     ( const T& );
00306   TaylorVariable<T>& operator /=
00307     ( const TaylorVariable<T>& );
00308   TaylorVariable<T>& operator /=
00309     ( const double );
00310 
00311         
00312         
00315         BooleanType isCompact() const;
00316         
00317         
00318 
00320         TaylorVariable
00321         ( TaylorModel<T>*TM, const double d=0. );
00322 
00323 private:
00324 
00325 
00327   TaylorVariable
00328     ( TaylorModel<T>*TM, const T&B );
00329 
00331   double *_coefmon;
00333   T * _bndord; 
00335   T * _bndrem;
00337   T _bndT;
00338 
00340   void _init();
00342   void _reinit();
00344   void _clean();
00345 
00347   void _update_bndord();
00348 
00350   void _center_TM();
00351 
00353   T& _bound
00354     ( T& bndmod ) const;
00356   T& _bound_naive
00357     ( T& bndmod ) const;
00359   T& _bound_LSB
00360     ( T& bndmod ) const;
00362   T& _bound_eigen
00363     ( T& bndmod ) const;
00365   static double* _eigen
00366     ( const unsigned int n, double*a );
00367 
00369   TaylorVariable<T> _intpow
00370     ( const TaylorVariable<T>&TM, const int n );
00371 
00372 };
00373 
00374 
00375 CLOSE_NAMESPACE_ACADO
00376 
00377 //#include <acado/set_arithmetics/interval.ipp>
00378 
00379 #endif  // ACADO_TOOLKIT_TAYLOR_VARIABLE_HPP
00380 


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:39:56