interval.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_INTERVAL_HPP
35 #define ACADO_TOOLKIT_INTERVAL_HPP
36 
38 
39 
41 
67 class Interval{
68 
69  // friends of class Interval for operator overloading
70  friend Interval operator+( const Interval& );
71  friend Interval operator+( const Interval&, const Interval& );
72  friend Interval operator+( const double, const Interval& );
73  friend Interval operator+( const Interval&, const double );
74  friend Interval operator-( const Interval& );
75  friend Interval operator-( const Interval&, const Interval& );
76  friend Interval operator-( const double, const Interval& );
77  friend Interval operator-( const Interval&, const double );
78  friend Interval operator*( const Interval&, const Interval& );
79  friend Interval operator*( const Interval&, const double );
80  friend Interval operator*( const double, const Interval& );
81  friend Interval operator/( const Interval&, const Interval& );
82  friend Interval operator/( const Interval&, const double );
83  friend Interval operator/( const double, const Interval& );
84  friend std::ostream& operator<<( std::ostream&, const Interval& );
85  friend bool operator==( const Interval&, const Interval& );
86  friend bool operator!=( const Interval&, const Interval& );
87  friend bool operator<=( const Interval&, const Interval& );
88  friend bool operator>=( const Interval&, const Interval& );
89  friend bool operator<( const Interval&, const Interval& );
90  friend bool operator>( const Interval&, const Interval& );
91 
92  // friends of class Interval for function overloading
93  friend double diam( const Interval& );
94  friend double abs ( const Interval& );
95  friend double mid ( const Interval& );
96  friend double mid ( const double, const double, const double, int& );
97 
98  friend Interval inv ( const Interval& );
99  friend Interval sqr ( const Interval& );
100  friend Interval exp ( const Interval& );
101  friend Interval log ( const Interval& );
102  friend Interval cos ( const Interval& );
103  friend Interval sin ( const Interval& );
104  friend Interval tan ( const Interval& );
105  friend Interval acos( const Interval& );
106  friend Interval asin( const Interval& );
107  friend Interval atan( const Interval& );
108  friend Interval fabs( const Interval& );
109  friend Interval sqrt( const Interval& );
110  friend Interval xlog( const Interval& );
111  friend Interval pow ( const Interval&, const int );
112  friend Interval arh ( const Interval&, const double );
113  friend Interval pow ( const Interval&, const double );
114  friend Interval pow ( const Interval&, const Interval& );
115  friend Interval hull( const Interval&, const Interval& );
116  friend Interval min ( const Interval&, const Interval& );
117  friend Interval max ( const Interval&, const Interval& );
118  friend Interval min ( const unsigned int, const Interval* );
119  friend Interval max ( const unsigned int, const Interval* );
120 
121  friend bool inter( Interval&, const Interval&, const Interval& );
122 
123 public:
124 
125  Interval& operator= ( const double c ){ _l = c ; _u = c ; return *this; }
126  Interval& operator= ( const Interval&I ){ _l = I._l; _u = I._u; return *this; }
127  Interval& operator+=( const double c ){ _l += c ; _u += c ; return *this; }
128  Interval& operator+=( const Interval&I ){ _l += I._l; _u += I._u; return *this; }
129  Interval& operator-=( const double c ){ _l -= c ; _u -= c ; return *this; }
130  Interval& operator-=( const Interval&I ){ _l -= I._u; _u -= I._l; return *this; }
131  Interval& operator*=( const double c ){ _l *= c ; _u *= c ; return *this; }
132 
133  Interval& operator*=( const Interval&I ){ *this = operator*(*this,I); return *this; }
134  Interval& operator/=( const double c ){ *this = operator/(*this,c); return *this; }
135  Interval& operator/=( const Interval&I ){ *this = operator/(*this,I); return *this; }
136 
139 
141  Interval( const double c ):_l(c), _u(c) {}
142 
144  Interval( const double l_, const double u_ ): _l(l_<u_?l_:u_), _u(l_<u_?u_:l_) {}
145 
147  Interval( const Interval&I ): _l(I._l), _u(I._u) {}
148 
151 
153  const double& l() const{ return _l; }
154 
156  const double& u() const{ return _u; }
157 
159  void l ( const double lb ){ _l = lb; }
160 
162  void u ( const double ub ){ _u = ub; }
165  void print() const{ std::cout << *this << "\n"; }
166 
169  BooleanType isCompact() const;
170 
171 
172 private:
173 
174  double mid( const double convRel, const double concRel, const double valCut, int &indexMid ) const;
175  double xlog( const double x ) const{ return x*(::log(x)); }
176 
178  double _l;
180  double _u;
181 };
182 
184 
185 #include <acado/set_arithmetics/interval.ipp>
186 
187 #endif // ACADO_TOOLKIT_INTERVAL_HPP
188 
friend Interval inv(const Interval &)
double _u
Upper bound.
Definition: interval.hpp:180
void print() const
Definition: interval.hpp:165
friend double abs(const Interval &)
friend Interval sqr(const Interval &)
friend Interval operator+(const Interval &)
friend Interval pow(const Interval &, const int)
Interval & operator+=(const Interval &I)
Definition: interval.hpp:128
friend bool operator==(const Interval &, const Interval &)
friend Interval operator/(const Interval &, const Interval &)
const double & l() const
Returns the lower bounding value.
Definition: interval.hpp:153
friend Interval operator*(const Interval &, const Interval &)
friend Interval xlog(const Interval &)
~Interval()
Destructor.
Definition: interval.hpp:150
friend Interval operator-(const Interval &)
Interval(const double l_, const double u_)
Constructor for a variable that belongs to the interval [l,u].
Definition: interval.hpp:144
BooleanType isCompact() const
Definition: interval.cpp:41
friend bool operator>=(const Interval &, const Interval &)
friend Interval tan(const Interval &)
#define CLOSE_NAMESPACE_ACADO
Interval()
Default constructor.
Definition: interval.hpp:138
Implements a rudimentary interval class.
Definition: interval.hpp:67
friend Interval fabs(const Interval &)
friend Interval cos(const Interval &)
Interval(const double c)
Constructor for a constant value c
Definition: interval.hpp:141
Interval & operator/=(const Interval &I)
Definition: interval.hpp:135
Interval & operator-=(const Interval &I)
Definition: interval.hpp:130
friend Interval asin(const Interval &)
Interval & operator*=(const Interval &I)
Definition: interval.hpp:133
Interval(const Interval &I)
Copy constructor.
Definition: interval.hpp:147
friend Interval max(const Interval &, const Interval &)
friend bool operator!=(const Interval &, const Interval &)
Interval & operator+=(const double c)
Definition: interval.hpp:127
Interval & operator=(const double c)
Definition: interval.hpp:125
friend Interval sin(const Interval &)
friend Interval hull(const Interval &, const Interval &)
const double & u() const
Returns the upper bounding value.
Definition: interval.hpp:156
friend Interval min(const Interval &, const Interval &)
friend Interval exp(const Interval &)
friend bool operator<=(const Interval &, const Interval &)
friend bool inter(Interval &, const Interval &, const Interval &)
void l(const double lb)
Sets the lower bound.
Definition: interval.hpp:159
friend Interval sqrt(const Interval &)
friend Interval arh(const Interval &, const double)
friend Interval atan(const Interval &)
friend bool operator>(const Interval &, const Interval &)
friend Interval acos(const Interval &)
friend std::ostream & operator<<(std::ostream &, const Interval &)
#define BEGIN_NAMESPACE_ACADO
double xlog(const double x) const
Definition: interval.hpp:175
Interval & operator-=(const double c)
Definition: interval.hpp:129
friend double diam(const Interval &)
Interval & operator/=(const double c)
Definition: interval.hpp:134
double _l
Lower bound.
Definition: interval.hpp:178
void u(const double ub)
Sets the upper bound.
Definition: interval.hpp:162
friend double mid(const Interval &)
friend Interval log(const Interval &)
Interval & operator*=(const double c)
Definition: interval.hpp:131
friend bool operator<(const Interval &, const Interval &)


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