integration_algorithm.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 
36 
37 
38 
40 
41 
42 
43 //
44 // PUBLIC MEMBER FUNCTIONS:
45 //
46 
47 
49 {
50  setupOptions( );
51  setupLogging( );
52 
53  integrationMethod = new ShootingMethod( this );
54 
56 }
57 
58 
60 {
61  // take care of userInteraction pointer!!!
62  if ( arg.integrationMethod != 0 )
64  else
66 
67  iter = arg.iter;
68 }
69 
70 
72 {
73  if ( integrationMethod != 0 )
74  delete integrationMethod;
75 }
76 
77 
79 {
80  if ( this != &arg )
81  {
82  if ( integrationMethod != 0 )
83  delete integrationMethod;
84 
85  // take care of userInteraction pointer!!!
86  if ( arg.integrationMethod != 0 )
88  else
90 
91  iter = arg.iter;
92  }
93 
94  return *this;
95 }
96 
97 
99  const Grid &stageIntervals,
100  const IntegratorType &integratorType_ ){
101 
102  return integrationMethod->addStage( dynamicSystem_, stageIntervals, integratorType_ );
103 }
104 
105 
107 
108  return integrationMethod->addTransition( transition_ );
109 }
110 
111 
113 
114  return integrationMethod->clear( );
115 }
116 
117 
118 
120  VariablesGrid *xa,
121  VariablesGrid *p ,
122  VariablesGrid *u ,
123  VariablesGrid *w ){
124 
125  iter.init( x,xa,p,u,w );
126  return evaluate( iter );
127 }
128 
129 
131 
132  if ( integrationMethod->evaluate( _iter ) != SUCCESSFUL_RETURN )
134 
135  return plot( );
136 }
137 
138 
139 
141  VariablesGrid *xa,
142  VariablesGrid *p ,
143  VariablesGrid *u ,
144  VariablesGrid *w
145  ){
146 
147  return evaluate( x,xa,p,u,w );
148 }
149 
150 
152  double tend,
153  const DVector &x0,
154  const DVector &xa,
155  const DVector &p,
156  const DVector &u,
157  const DVector &w
158  )
159 {
160  Grid grid( t0,tend,2 );
161 
162  VariablesGrid xGrid( x0,grid );
163  VariablesGrid xaGrid( xa,grid );
164  VariablesGrid pGrid( p,grid );
165  VariablesGrid uGrid( u,grid );
166  VariablesGrid wGrid( w,grid );
167 
168  return integrate( &xGrid,&xaGrid,&pGrid,&uGrid,&wGrid );
169 }
170 
171 
173  const DVector &x0,
174  const DVector &xa,
175  const DVector &p,
176  const DVector &u,
177  const DVector &w
178  )
179 {
180  //Grid grid( t.getFirstTime(),t.getLastTime(),2 );
181 
182  VariablesGrid xGrid( x0,t );
183  VariablesGrid xaGrid( xa,t );
184  VariablesGrid pGrid( p,t );
185  VariablesGrid uGrid( u,t );
186  VariablesGrid wGrid( w,t );
187 
188  return integrate( &xGrid,&xaGrid,&pGrid,&uGrid,&wGrid );
189 }
190 
191 
192 
194  const BlockMatrix &pSeed_,
195  const BlockMatrix &uSeed_,
196  const BlockMatrix &wSeed_
197  )
198 {
199  return integrationMethod->setForwardSeed( xSeed_,pSeed_,uSeed_,wSeed_ );
200 }
201 
202 
204  const DVector &pSeed,
205  const DVector &uSeed,
206  const DVector &wSeed
207  )
208 {
209  BlockMatrix xSeedTmp( (DMatrix)xSeed );
210  BlockMatrix pSeedTmp( (DMatrix)pSeed );
211  BlockMatrix uSeedTmp( (DMatrix)uSeed );
212  BlockMatrix wSeedTmp( (DMatrix)wSeed );
213 
214  return integrationMethod->setForwardSeed( xSeedTmp,pSeedTmp,uSeedTmp,wSeedTmp );
215 }
216 
217 
219 {
221 }
222 
223 
225  )
226 {
227  return integrationMethod->setBackwardSeed( seed );
228 }
229 
230 
232  )
233 {
234  DMatrix seedTmpMatrix( seed );
235  seedTmpMatrix.transposeInPlace();
236  BlockMatrix seedTmp( seedTmpMatrix );
237 
238  return integrationMethod->setBackwardSeed( seedTmp );
239 }
240 
241 
243 {
245 }
246 
247 
248 
250 {
252 }
253 
254 
255 
257 {
259 }
260 
261 
263 {
264  return evaluateSensitivities( );
265 }
266 
267 
269 {
270  return integrationMethod->evaluateSensitivities( seed,hessian );
271 }
272 
273 
275 {
276  return evaluateSensitivities( seed,hessian );
277 }
278 
279 
280 
282 {
283  return integrationMethod->unfreeze( );
284 }
285 
286 
288 {
289  return integrationMethod->isAffine( );
290 }
291 
292 
294  ) const
295 {
296  if ( iter.x != 0 )
297  xEnd = iter.x->getLastVector( );
298 
299  return SUCCESSFUL_RETURN;
300 }
301 
302 
304  ) const
305 {
306  if ( iter.xa != 0 )
307  xaEnd = iter.xa->getLastVector( );
308 
309  return SUCCESSFUL_RETURN;
310 }
311 
312 
314  ) const
315 {
316  if ( iter.x != 0 )
317  X = *(iter.x);
318 
319  return SUCCESSFUL_RETURN;
320 }
321 
322 
324  ) const
325 
326 {
327  if ( iter.xa != 0 )
328  XA = *(iter.xa);
329 
330  return SUCCESSFUL_RETURN;
331 }
332 
333 
334 
336  ) const
337 {
339 }
340 
341 
343  ) const
344 {
345  BlockMatrix DxTmp;
346 
347  returnValue returnvalue = integrationMethod->getForwardSensitivities( DxTmp );
348  if ( returnvalue != SUCCESSFUL_RETURN )
349  return returnvalue;
350 
351  if ( DxTmp.isEmpty( ) == BT_FALSE )
352  {
353  DMatrix DxTmpMatrix;
354  DxTmp.getSubBlock( 0,0,DxTmpMatrix );
355 
356  if ( DxTmpMatrix.getNumCols( ) > 0 )
357  Dx = DxTmpMatrix.getCol( 0 );
358  }
359 
360  return SUCCESSFUL_RETURN;
361 }
362 
363 
364 
366  ) const
367 {
369 }
370 
371 
373  DVector &Dx_p ,
374  DVector &Dx_u ,
375  DVector &Dx_w
376  ) const
377 {
378  BlockMatrix DxTmp;
379 
381  if ( returnvalue != SUCCESSFUL_RETURN )
382  return returnvalue;
383 
384  if ( DxTmp.isEmpty( ) == BT_FALSE )
385  {
386  DMatrix DxTmpMatrix;
387 
388  DxTmp.getSubBlock( 0,0,DxTmpMatrix );
389  if ( DxTmpMatrix.getNumRows( ) > 0 )
390  Dx_x0 = DxTmpMatrix.getRow( 0 );
391  else
392  Dx_x0.init( );
393 
394  DxTmp.getSubBlock( 0,2,DxTmpMatrix );
395  if ( DxTmpMatrix.getNumRows( ) > 0 )
396  Dx_p = DxTmpMatrix.getRow( 0 );
397  else
398  Dx_p.init( );
399 
400  DxTmp.getSubBlock( 0,3,DxTmpMatrix );
401  if ( DxTmpMatrix.getNumRows( ) > 0 )
402  Dx_u = DxTmpMatrix.getRow( 0 );
403  else
404  Dx_u.init( );
405 
406  DxTmp.getSubBlock( 0,4,DxTmpMatrix );
407  if ( DxTmpMatrix.getNumRows( ) > 0 )
408  Dx_w = DxTmpMatrix.getRow( 0 );
409  else
410  Dx_w.init( );
411  }
412 
413  return SUCCESSFUL_RETURN;
414 }
415 
416 
417 
418 //
419 // PROTECTED MEMBER FUNCTIONS:
420 //
421 
423 {
424  //printf( "IntegrationAlgorithm::setupOptions( ) called.\n" );
425 
426  // add integration options
431 
432  // add integrator options
446 
447  return SUCCESSFUL_RETURN;
448 }
449 
450 
452 {
453  LogRecord tmp( LOG_AT_END );
454 
457  tmp.addItem( LOG_PARAMETERS );
458  tmp.addItem( LOG_CONTROLS );
459  tmp.addItem( LOG_DISTURBANCES );
461 
464 
465  logIdx = addLogRecord( tmp );
466 
467  return SUCCESSFUL_RETURN;
468 }
469 
470 
472 
473 // end of file.
virtual returnValue plot(PlotFrequency _frequency=PLOT_IN_ANY_CASE)
GenericVector< T > getCol(unsigned _idx) const
Definition: matrix.hpp:205
virtual returnValue getForwardSensitivities(BlockMatrix &D) const
Data class for storing generic optimization variables.
Definition: ocp_iterate.hpp:57
Implements a very rudimentary block sparse matrix class.
virtual returnValue clear()
const int defaultFeasibilityCheck
virtual returnValue evaluate(OCPiterate &iter)
returnValue addItem(LogName _name, const char *const _label=DEFAULT_LABEL)
Definition: log_record.cpp:70
VariablesGrid * x
const double defaultRelaxationParameter
const double defaultMaxStepsize
returnValue getBackwardSensitivities(BlockMatrix &D) const
ShootingMethod * integrationMethod
Stores a DifferentialEquation together with an OutputFcn.
returnValue setStatus(BlockStatus _status)
virtual returnValue deleteAllSeeds()
void init(unsigned _dim=0)
Definition: vector.hpp:155
Discretizes a DifferentialEquation by means of single or multiple shooting.
Provides a time grid consisting of vector-valued optimization variables at each grid point...
int addLogRecord(LogRecord &record)
Definition: logging.cpp:58
Allows to pass back messages to the calling function.
virtual returnValue evaluateSensitivities()
returnValue getXA(DVector &xaEnd) const
virtual returnValue setBackwardSeed(const BlockMatrix &seed)
const double defaultStepsizeTuning
returnValue init(const VariablesGrid *const _x, const VariablesGrid *const _xa, const VariablesGrid *const _p, const VariablesGrid *const _u, const VariablesGrid *const _w)
const double defaultMinStepsize
Allows to conveniently handle (one-dimensional) grids consisting of time points.
Definition: grid.hpp:58
returnValue getX(DVector &xEnd) const
virtual returnValue setupLogging()
const int defaultMaxNumSteps
returnValue integrate(VariablesGrid *x, VariablesGrid *xa, VariablesGrid *p, VariablesGrid *u, VariablesGrid *w)
#define CLOSE_NAMESPACE_ACADO
const double defaultIntegratorTolerance
int logIdx
Definition: logging.hpp:277
VariablesGrid * xa
const int defaultIntegratorPrintlevel
virtual returnValue setUnitForwardSeed()
returnValue getSubBlock(uint rowIdx, uint colIdx, DMatrix &value) const
IntegratorType
const double defaultCorrectorTolerance
DVector getLastVector() const
User-interface to integrate a DynamicSystem, possibly over multiple stages.
virtual returnValue addTransition(const Transition &transition_)
returnValue setForwardSeed(const BlockMatrix &xSeed_, const BlockMatrix &pSeed_=emptyBlockMatrix, const BlockMatrix &uSeed_=emptyBlockMatrix, const BlockMatrix &wSeed_=emptyBlockMatrix)
virtual returnValue clear()
Encapsulates all user interaction for setting options, logging data and plotting results.
virtual BooleanType isAffine() const
const double defaultInitialStepsize
unsigned getNumRows() const
Definition: matrix.hpp:185
const int defaultprintIntegratorProfile
virtual returnValue setupOptions()
const int defaultAlgebraicRelaxation
virtual returnValue unfreeze()
unsigned getNumCols() const
Definition: matrix.hpp:189
Allows to setup and evaluate transition functions based on SymbolicExpressions.
Definition: transition.hpp:53
IntegrationAlgorithm & operator=(const IntegrationAlgorithm &rhs)
returnValue setBackwardSeed(const BlockMatrix &seed)
returnValue evaluate(VariablesGrid *x, VariablesGrid *xa, VariablesGrid *p, VariablesGrid *u, VariablesGrid *w)
virtual returnValue setForwardSeed(const BlockMatrix &xSeed_, const BlockMatrix &pSeed_, const BlockMatrix &uSeed_, const BlockMatrix &wSeed_)
returnValue getForwardSensitivities(BlockMatrix &D) const
bool isEmpty() const
virtual returnValue addStage(const DynamicSystem &dynamicSystem_, const Grid &stageIntervals, const IntegratorType &integratorType_=INT_UNKNOWN)
Allows to setup and store user-specified log records of algorithmic information.
Definition: log_record.hpp:72
#define BEGIN_NAMESPACE_ACADO
#define BT_FALSE
Definition: acado_types.hpp:49
const int defaultPlotResoltion
const int defaultLinearAlgebraSolver
virtual returnValue getBackwardSensitivities(BlockMatrix &D) const
virtual returnValue setUnitBackwardSeed()
returnValue addOption(OptionsName name, int value)
Definition: options.cpp:301
BooleanType isAffine() const
virtual returnValue addStage(const DynamicSystem &dynamicSystem_, const Grid &stageIntervals, const IntegratorType &integratorType_=INT_UNKNOWN)
virtual returnValue addTransition(const Transition &transition_)
const double defaultAbsoluteTolerance
GenericVector< T > getRow(unsigned _idx) const
Definition: matrix.hpp:197
#define ACADOERROR(retval)


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