ellipsoidal_integrator.cpp
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 
27 
35 
36 
38 
39 
40 
41 // IMPLEMENTATION OF PUBLIC MEMBER FUNCTIONS:
42 // ------------------------------------------
43 
45 
47 
48  ASSERT( rhs_.isODE( ) == BT_TRUE );
49  setupOptions();
50  init( rhs_, N_ );
51 }
52 
54 
56 
58 
59  if( this != &arg ){
61  copy(arg);
62  }
63  return *this;
64 }
65 
66 
67 
69 
70  if( rhs_.isODE( ) == BT_FALSE ) return ACADOERROR(RET_CANNOT_TREAT_DAE);
71 
72  nx = rhs_.getDim();
73 
74  Q.resize(nx,nx);
75  for( int i=0; i<nx*nx; i++ ) Q(i) = 0.0;
76  N = N_;
77 
78  IntermediateState derivatives = rhs_.getODEexpansion( N );
79 
80  IntermediateState gg = derivatives.getCol(0);
81  for( int i=0; i<N; i++ ) gg << derivatives.getCol(i+1)/acadoFactorial(i+1);
82 
83  g << gg;
84 
85 // FILE *file = fopen("g.c","w");
86 // file << g;
87 // fclose(file);
88 
89  gr << derivatives.getCol(N+1)/acadoFactorial(N+1);
90  dg << gg.ADforward( VT_DIFFERENTIAL_STATE, rhs_.getComponents(), nx );
91 
92  DifferentialState r("", nx, 1);
93 
95  ddg << 0.5*dgg.ADforward( VT_DIFFERENTIAL_STATE, rhs_.getComponents(), r );
96 
97  return SUCCESSFUL_RETURN;
98 }
99 
100 
101 
103  const Tmatrix<Interval> &x ){
104 
105  Tmatrix<Interval> p(0);
106  Tmatrix<Interval> w(0);
107  return integrate( t0, tf, M, x, p, w );
108 }
109 
111  const Tmatrix<Interval> &x,
112  const Tmatrix<Interval> &p ){
113 
114  Tmatrix<Interval> w(0);
115  return integrate( t0, tf, M, x, p, w );
116 }
117 
119  const Tmatrix<Interval> &x,
120  const Tmatrix<Interval> &p,
121  const Tmatrix<Interval> &w ){
122 
123 
124  typedef TaylorVariable<Interval> T;
125 
127 
128  Tmatrix<T> *pp = 0;
129  Tmatrix<T> *ww = 0;
130 
131  if( p.getDim() > 0 ) pp = new Tmatrix<T>(p.getDim());
132  if( w.getDim() > 0 ) ww = new Tmatrix<T>(w.getDim());
133 
134  int nn = 0;
135  for( int i=0; i<(int) x.getDim(); i++ ) if( diam(x(i)) > EQUALITY_EPS ) nn++;
136  for( int i=0; i<(int) p.getDim(); i++ ) if( diam(p(i)) > EQUALITY_EPS ) nn++;
137  for( int i=0; i<(int) w.getDim(); i++ ) if( diam(w(i)) > EQUALITY_EPS ) nn++;
138 
139  TaylorModel<Interval> Mod( nn, M );
140 
141  nn = 0;
142  for( int i=0; i<(int) x.getDim(); i++ ){
143  if( diam(x(i)) > EQUALITY_EPS ){ xx(i) = T( &Mod, nn, x(i) ); nn++; }
144  else xx(i) = x(i);
145  }
146  for( int i=0; i<(int) p.getDim(); i++ ){
147  if( diam(p(i)) > EQUALITY_EPS ){ pp->operator()(i) = T( &Mod, nn, p(i) ); nn++; }
148  else pp->operator()(i) = p(i);
149  }
150  for( int i=0; i<(int) w.getDim(); i++ ){
151  if( diam(w(i)) > EQUALITY_EPS ){ ww->operator()(i) = T( &Mod, nn, w(i) ); nn++; }
152  else ww->operator()(i) = w(i);
153  }
154 
155  integrate( t0, tf, &xx, pp, ww );
156 
157  return getStateBound( xx );
158 }
159 
160 
161 
162 // IMPLEMENTATION OF PRIVATE MEMBER FUNCTIONS:
163 // ======================================================================================
164 
165 
167 
168  nx = arg.nx ;
169  N = arg.N ;
170  g = arg.g ;
171  gr = arg.gr ;
172  dg = arg.dg ;
173  ddg = arg.ddg;
174  Q = arg.Q ;
175 }
176 
177 
179 
181 
182  for( int i=0; i<nx*nx; i++ ){
183 
184  double r_i;
185  r_i = C(i);
186  for( int j=0; j<N; j++ ) r_i += ::pow(h,j+1)*C(i+(j+1)*nx*nx);
187  r(i) = r_i;
188  }
189  return r;
190 }
191 
192 
194 
195  Tmatrix<double> r(nx,nx);
196 
197  for( int i=0; i<nx*nx; i++ ){
198 
199  double r_i;
200  r_i = C(i);
201  for( int j=0; j<N; j++ ) r_i += ::pow(h,j+1)*C(i+(j+1)*nx*nx);
202  r(i) = r_i;
203  }
204  return r;
205 }
206 
207 double EllipsoidalIntegrator::scale( const Interval &E, const Interval &X ) const{
208 
209  double TOL,ATOL;
210  get( INTEGRATOR_TOLERANCE, TOL );
211  get( ABSOLUTE_TOLERANCE , ATOL );
212 
213  return 0.5*acadoMax( ::fabs(E.l()), ::fabs(E.u()) )/
214  ( TOL*acadoMax( ::fabs(X.l()), ::fabs(X.u()) ) + ATOL );
215 }
216 
217 
219 
220  ASSERT( E.getDim() == X.getDim() );
221 
222  double sum = 0.0;
223 
224  for( int i=0; i < (int) E.getDim(); i++ ) sum += scale(E(i),X(i));
225 
226  return sum/((double) E.getDim());
227 }
228 
229 
231 
232  Tmatrix<double> CT(nx,nx);
233 
234  for( int i=0; i<nx; i++ )
235  for( int j=0;j<nx;j++)
236  CT(i,j) = C(j,i);
237 
238  Q = C*Q*CT;
239 
240  double trQ = 0.0;
241  for( int i=0; i<nx; i++ ) trQ += Q(i,i)/(Q(i,i)+1e-8);
242  trQ = ::sqrt(trQ);
243 
244  DVector sqrR(nx);
245  for( int i=0; i<nx; i++ ) sqrR(i) = acadoMax(::fabs(R(i).l()),::fabs(R(i).u()))/::sqrt(Q(i,i)+1e-8);
246 
247  double kappa = trQ;
248  for( int i=0; i<nx; i++ ) kappa += sqrR(i);
249 
250  Q *= kappa/(trQ+EPS);
251  for( int i=0; i<nx; i++ ){
252  double tmp = acadoMax(::fabs(R(i).l()),::fabs(R(i).u()));
253  tmp *= ::sqrt(kappa/(sqrR(i)+EPS));
254  Q(i,i) += tmp*tmp+EPS;
255  }
256 }
257 
259 
261  for( int i=0; i<nx; i++ ) R(i) = Interval(-1.0,1.0)*::sqrt(Q(i,i)+EPS*EPS);
262  return R;
263 }
264 
266 
267  ASSERT( A.getDim() == B.getDim() );
268 
269  BooleanType result = BT_TRUE;
270 
271  for( int i=0; i < (int) A.getDim(); i++ ){
272  if( A(i).l() < B(i).l() || A(i).u() > B(i).u() ){ result = BT_FALSE; }
273  }
274 
275  return result;
276 }
277 
278 
280 
281 
283 
292 
293  return SUCCESSFUL_RETURN;
294 }
295 
296 
297 
298 
300 
301 // end of file.
virtual returnValue setupOptions()
int * getComponents() const
Implements a templated dense matrix class.
Definition: t_matrix.hpp:53
IntermediateState sqrt(const Expression &arg)
Tmatrix< Interval > getStateBound(const Tmatrix< T > &x) const
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
void copy(const EllipsoidalIntegrator &arg)
C++ template class for definition of and operation on variables in a Taylor model.
Tmatrix< Interval > integrate(double t0, double tf, int M, const Tmatrix< Interval > &x)
const double defaultMaxStepsize
int acadoMax(const int x, const int y)
Definition: acado_utils.cpp:64
Expression getCol(const uint &colIdx) const
Definition: expression.cpp:567
const double & l() const
Returns the lower bounding value.
Definition: interval.hpp:153
BEGIN_NAMESPACE_ACADO const double EPS
Allows to pass back messages to the calling function.
Tmatrix< Interval > boundQ() const
AlgorithmicBase & operator=(const AlgorithmicBase &rhs)
IntermediateState pow(const Expression &arg1, const Expression &arg2)
Base class for all algorithmic modules within the ACADO Toolkit providing some basic functionality...
void updateQ(Tmatrix< double > C, Tmatrix< Interval > R)
double norm(const Tmatrix< Interval > &E, Tmatrix< Interval > &X) const
const double defaultStepsizeTuning
BooleanType isIncluded(const Tmatrix< Interval > &A, const Tmatrix< Interval > &B) const
const double defaultMinStepsize
virtual EllipsoidalIntegrator & operator=(const EllipsoidalIntegrator &arg)
const int defaultMaxNumSteps
const double INFINITY
#define CLOSE_NAMESPACE_ACADO
Implements a rudimentary interval class.
Definition: interval.hpp:67
const double defaultIntegratorTolerance
BooleanType isODE() const
int acadoFactorial(int n)
const int defaultIntegratorPrintlevel
Expression ADforward(const Expression &arg) const
Definition: expression.cpp:971
double scale(const Interval &E, const Interval &X) const
Expression getODEexpansion(const int &order) const
Validated integrator for ODEs based on Taylor models with ellipsoidal remainder term.
int getDim() const
const double & u() const
Returns the upper bounding value.
Definition: interval.hpp:156
#define E
unsigned int getDim() const
Definition: t_matrix.hpp:184
returnValue init(const DifferentialEquation &rhs_, const int &N_=3)
const int defaultprintIntegratorProfile
#define ASSERT(x)
#define BT_TRUE
Definition: acado_types.hpp:47
Tmatrix< Interval > evalC(const Tmatrix< double > &C, double h) const
const double EQUALITY_EPS
#define BEGIN_NAMESPACE_ACADO
#define BT_FALSE
Definition: acado_types.hpp:49
Tmatrix< double > evalC2(const Tmatrix< double > &C, double h) const
returnValue addOption(OptionsName name, int value)
#define R
const double defaultAbsoluteTolerance
#define ACADOERROR(retval)
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.
void resize(const unsigned int nr, const unsigned int nc=1, const bool alloc=true)
Resets the dimension of a Tmatrix objects.
Definition: t_matrix.hpp:149
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:34:33