interval.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_INTERVAL_HPP
00035 #define ACADO_TOOLKIT_INTERVAL_HPP
00036 
00037 #include <acado/utils/acado_utils.hpp>
00038 
00039 
00040 BEGIN_NAMESPACE_ACADO
00041 
00067 class Interval{
00068  
00069   // friends of class Interval for operator overloading
00070   friend Interval operator+( const Interval& );
00071   friend Interval operator+( const Interval&, const Interval& );
00072   friend Interval operator+( const double, const Interval& );
00073   friend Interval operator+( const Interval&, const double );
00074   friend Interval operator-( const Interval& );
00075   friend Interval operator-( const Interval&, const Interval& );
00076   friend Interval operator-( const double, const Interval& );
00077   friend Interval operator-( const Interval&, const double );
00078   friend Interval operator*( const Interval&, const Interval& );
00079   friend Interval operator*( const Interval&, const double );
00080   friend Interval operator*( const double, const Interval& );
00081   friend Interval operator/( const Interval&, const Interval& );
00082   friend Interval operator/( const Interval&, const double );
00083   friend Interval operator/( const double, const Interval& );
00084   friend std::ostream& operator<<( std::ostream&, const Interval& );
00085   friend bool operator==( const Interval&, const Interval& );
00086   friend bool operator!=( const Interval&, const Interval& );
00087   friend bool operator<=( const Interval&, const Interval& );
00088   friend bool operator>=( const Interval&, const Interval& );
00089   friend bool operator<( const Interval&, const Interval& );
00090   friend bool operator>( const Interval&, const Interval& );
00091 
00092   // friends of class Interval for function overloading
00093   friend double diam( const Interval& );
00094   friend double abs ( const Interval& );
00095   friend double mid ( const Interval& );
00096   friend double mid ( const double, const double, const double, int& );
00097 
00098   friend Interval inv ( const Interval& );
00099   friend Interval sqr ( const Interval& );
00100   friend Interval exp ( const Interval& );
00101   friend Interval log ( const Interval& );
00102   friend Interval cos ( const Interval& );
00103   friend Interval sin ( const Interval& );
00104   friend Interval tan ( const Interval& );
00105   friend Interval acos( const Interval& );
00106   friend Interval asin( const Interval& );
00107   friend Interval atan( const Interval& );
00108   friend Interval fabs( const Interval& );
00109   friend Interval sqrt( const Interval& );
00110   friend Interval xlog( const Interval& );
00111   friend Interval pow ( const Interval&, const int );
00112   friend Interval arh ( const Interval&, const double );
00113   friend Interval pow ( const Interval&, const double );
00114   friend Interval pow ( const Interval&, const Interval& );
00115   friend Interval hull( const Interval&, const Interval& );
00116   friend Interval min ( const Interval&, const Interval& );
00117   friend Interval max ( const Interval&, const Interval& );
00118   friend Interval min ( const unsigned int, const Interval* );
00119   friend Interval max ( const unsigned int, const Interval* );
00120 
00121   friend bool inter( Interval&, const Interval&, const Interval& );
00122 
00123 public:
00124 
00125   Interval& operator= ( const double   c ){ _l  = c   ; _u  = c   ; return *this; }
00126   Interval& operator= ( const Interval&I ){ _l  = I._l; _u  = I._u; return *this; }
00127   Interval& operator+=( const double   c ){ _l += c   ; _u += c   ; return *this; }
00128   Interval& operator+=( const Interval&I ){ _l += I._l; _u += I._u; return *this; }
00129   Interval& operator-=( const double   c ){ _l -= c   ; _u -= c   ; return *this; }
00130   Interval& operator-=( const Interval&I ){ _l -= I._u; _u -= I._l; return *this; }
00131   Interval& operator*=( const double   c ){ _l *= c   ; _u *= c   ; return *this; }
00132 
00133   Interval& operator*=( const Interval&I ){ *this = operator*(*this,I); return *this; }
00134   Interval& operator/=( const double   c ){ *this = operator/(*this,c); return *this; }
00135   Interval& operator/=( const Interval&I ){ *this = operator/(*this,I); return *this; }
00136 
00138   Interval(){}
00139 
00141   Interval( const double c ):_l(c), _u(c) {}
00142 
00144   Interval( const double l_, const double u_ ): _l(l_<u_?l_:u_), _u(l_<u_?u_:l_) {}
00145 
00147   Interval( const Interval&I ): _l(I._l), _u(I._u) {}
00148 
00150   ~Interval(){}
00151 
00153   const double& l() const{ return _l; }
00154   
00156   const double& u() const{ return _u; }
00157 
00159   void l ( const double lb ){ _l = lb; }
00160   
00162   void u ( const double ub ){ _u = ub; }
00165   void print() const{ std::cout << *this << "\n"; }
00166 
00169         BooleanType isCompact() const;
00170         
00171         
00172 private:
00173 
00174   double mid( const double convRel, const double concRel, const double valCut, int &indexMid ) const;
00175   double xlog( const double x ) const{ return x*(::log(x)); }
00176  
00178   double _l;
00180   double _u;
00181 };
00182 
00183 CLOSE_NAMESPACE_ACADO
00184 
00185 #include <acado/set_arithmetics/interval.ipp>
00186 
00187 #endif  // ACADO_TOOLKIT_INTERVAL_HPP
00188 


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:58:37