53 userInit.allocateAll( );
62 userInit.allocateAll( );
68 if( arg.
ocp != 0 ) ocp =
new OCP(*arg.
ocp) ;
92 if( arg.
ocp != 0 ) ocp =
new OCP(*arg.
ocp) ;
109 tmp.
read( fileName );
114 return initializeDifferentialStates(tmp,autoinit);
121 tmp.
read( fileName );
126 return initializeAlgebraicStates(tmp,autoinit);
133 tmp.
read( fileName );
138 return initializeParameters(tmp);
145 tmp.
read( fileName );
150 return initializeControls(tmp);
157 tmp.
read( fileName );
162 return initializeDisturbances(tmp);
169 if ( userInit.x != 0 )
delete userInit.x;
172 userInit.x->enableAutoInit();
174 userInit.x->disableAutoInit();
181 if( userInit.x != 0 ) userInit.x ->enableAutoInit();
182 if( userInit.xa != 0 ) userInit.xa->enableAutoInit();
189 if ( userInit.xa != 0 )
delete userInit.xa;
192 userInit.xa->enableAutoInit();
195 userInit.xa->disableAutoInit();
203 if ( userInit.p != 0 )
delete userInit.p;
211 if ( userInit.u != 0 )
delete userInit.u;
219 if ( userInit.w != 0 )
delete userInit.w;
228 return nlpSolver->getDifferentialStates( xd_ );
235 return nlpSolver->getAlgebraicStates( xa_ );
242 return nlpSolver->getParameters( p_ );
252 returnValue returnvalue = nlpSolver->getParameters( tmp );
265 return nlpSolver->getControls( u_ );
272 return nlpSolver->getDisturbances( w_ );
282 returnvalue = nlpSolver->getDifferentialStates( xx );
285 xx.
print( fileName );
297 returnvalue = nlpSolver->getAlgebraicStates( xx );
300 xx.
print( fileName );
312 returnvalue = nlpSolver->getParameters( xx );
315 xx.
print( fileName );
327 returnvalue = nlpSolver->getControls( xx );
330 xx.
print( fileName );
342 returnvalue = nlpSolver->getDisturbances( xx );
345 xx.
print( fileName );
353 ofstream stream( fileName );
354 stream << scientific << getObjectiveValue();
364 return nlpSolver->getObjectiveValue();
372 return nlpSolver->getSensitivitiesX( _sens );
379 return nlpSolver->getSensitivitiesXA( _sens );
385 return nlpSolver->getSensitivitiesP( _sens );
392 return nlpSolver->getSensitivitiesU( _sens );
399 return nlpSolver->getSensitivitiesW( _sens );
406 return iter.getNX( );
412 return iter.getNXA( );
418 return iter.getNP( );
424 return iter.getNU( );
430 return iter.getNW( );
437 return ocp->getStartTime( );
446 return ocp->getEndTime( );
465 if ( nlpSolver != 0 )
474 userInit.allocateAll( );
491 if ( extractOCPdata( &objective,&differentialEquation,&constraint,
499 if ( setupObjective( objective,differentialEquation,constraint,
507 if ( setupDifferentialEquation( objective,differentialEquation,constraint,
517 if ( setupDynamicDiscretization( _userIteraction,
518 objective,differentialEquation,constraint,
520 &dynamicDiscretization
526 if ( allocateNlpSolver( objective,dynamicDiscretization,constraint ) !=
SUCCESSFUL_RETURN )
538 if ( determineDimensions( objective,differentialEquation,constraint, nx,nxa,np,nu,nw ) !=
SUCCESSFUL_RETURN )
540 if( differentialEquation != 0 )
delete differentialEquation[0];
542 if( objective != 0 )
delete objective ;
543 if( differentialEquation != 0 )
delete[] differentialEquation ;
544 if( constraint != 0 )
delete constraint ;
545 if( dynamicDiscretization != 0 )
delete dynamicDiscretization;
550 if ( initializeOCPiterate( constraint,unionGrid,nx,nxa,np,nu,nw ) !=
SUCCESSFUL_RETURN )
552 if( differentialEquation != 0 )
delete differentialEquation[0];
554 if( objective != 0 )
delete objective ;
555 if( differentialEquation != 0 )
delete[] differentialEquation ;
556 if( constraint != 0 )
delete constraint ;
557 if( dynamicDiscretization != 0 )
delete dynamicDiscretization;
574 if( iter.p != 0 ) iter.p ->disableAutoInit();
575 if( iter.u != 0 ) iter.u ->disableAutoInit();
576 if( iter.w != 0 ) iter.w ->disableAutoInit();
594 if( differentialEquation != 0 )
delete differentialEquation[0];
596 if( objective != 0 )
delete objective ;
597 if( differentialEquation != 0 )
delete[] differentialEquation ;
598 if( constraint != 0 )
delete constraint ;
599 if( dynamicDiscretization != 0 )
delete dynamicDiscretization;
641 if( ocp->hasDifferentialEquation() ==
BT_TRUE ){
644 else *differentialEquation = 0;
646 if( ocp->hasConstraint() ==
BT_TRUE )
649 ocp->getConstraint( **constraint );
658 ocp->getObjective( **objective );
659 returnvalue = initializeObjective( *objective );
663 if( ocp->hasDifferentialEquation() ==
BT_TRUE ){
666 ocp->getModel( *differentialEquation[0][0] );
672 ocp->getGrid( unionGrid );
688 return objective->
init( 1,0,differentialEquation,0,constraint );
698 if( differentialEquation != 0 ){
699 if( differentialEquation[0]->getNumAlgebraicEquations() != 0 ){
717 if( differentialEquation != 0 ){
724 if( differentialEquation[0]->getNumAlgebraicEquations() != 0 ) intType = (int)
INT_BDF ;
725 if( differentialEquation[0]->isImplicit() ==
BT_TRUE ) intType = (
int)
INT_BDF ;
735 (*dynamicDiscretization)->addStage( *differentialEquation[0],
754 if( _objective != 0 )
762 if( _differentialEquation != 0 )
764 _nx =
acadoMax( _differentialEquation[0]->getNX() , _nx );
765 _nxa =
acadoMax( _differentialEquation[0]->getNXA(), _nxa );
766 _np =
acadoMax( _differentialEquation[0]->getNP (), _np );
767 _nu =
acadoMax( _differentialEquation[0]->getNU (), _nu );
768 _nw =
acadoMax( _differentialEquation[0]->getNW (), _nw );
770 if( _constraint != 0 )
779 if( _differentialEquation == 0 )
809 const Grid& _unionGrid,
834 if( _constraint != 0 ){
855 if( iter.x != 0 ) iter.x ->initializeFromBounds();
856 if( iter.xa != 0 ) iter.xa->initializeFromBounds();
857 if( iter.p != 0 ) iter.p ->initializeFromBounds();
858 if( iter.u != 0 ) iter.u ->initializeFromBounds();
859 if( iter.w != 0 ) iter.w ->initializeFromBounds();
880 if( nx > 0 && userInit.x->getNumPoints() > 0 ){
881 ai=userInit.x->getAutoInit(0);
882 for( run1 = 0; run1 < _unionGrid.
getNumPoints(); run1++ ){
883 DVector tmp = userInit.x->linearInterpolation( _unionGrid.
getTime(run1) );
885 if( nxx > nx ) nxx = nx;
886 for( run2 = 0; run2 < nxx; run2++ )
887 iter.x->operator()( run1, run2 ) = tmp(run2);
888 iter.x->setAutoInit(run1,ai);
892 if( nxa > 0 && userInit.xa->getNumPoints() > 0 ){
893 ai=userInit.xa->getAutoInit(0);
894 for( run1 = 0; run1 < _unionGrid.
getNumPoints(); run1++ ){
895 DVector tmp = userInit.xa->linearInterpolation( _unionGrid.
getTime(run1) );
897 if( nxx > nxa ) nxx = nxa;
898 for( run2 = 0; run2 < nxx; run2++ )
899 iter.xa->operator()( run1, run2 ) = tmp(run2);
900 iter.xa->setAutoInit(run1,ai);
904 if( nu > 0 && userInit.u->getNumPoints() > 0 ){
905 for( run1 = 0; run1 < _unionGrid.
getNumPoints(); run1++ ){
906 DVector tmp = userInit.u->linearInterpolation( _unionGrid.
getTime(run1) );
908 if( nxx > nu ) nxx =
nu;
909 for( run2 = 0; run2 < nxx; run2++ )
910 iter.u->operator()( run1, run2 ) = tmp(run2);
918 if( np > 0 && userInit.p->getNumPoints() > 0 ){
919 iter.p->setAllVectors( userInit.p->getVector(0) );
932 if( nw > 0 && userInit.w->getNumPoints() > 0 ){
933 for( run1 = 0; run1 < _unionGrid.
getNumPoints(); run1++ ){
934 DVector tmp = userInit.w->linearInterpolation( _unionGrid.
getTime(run1) );
936 if( nxx > nw ) nxx = nw;
937 for( run2 = 0; run2 < nxx; run2++ )
938 iter.w->operator()( run1, run2 ) = tmp(run2);
returnValue simulateStatesForInitialization()
returnValue print(std::ostream &stream=std::cout, const char *const name=DEFAULT_LABEL, const char *const startString=DEFAULT_START_STRING, const char *const endString=DEFAULT_END_STRING, uint width=DEFAULT_WIDTH, uint precision=DEFAULT_PRECISION, const char *const colSeparator=DEFAULT_COL_SEPARATOR, const char *const rowSeparator=DEFAULT_ROW_SEPARATOR) const
Implements a very rudimentary block sparse matrix class.
OptimizationAlgorithmBase & operator=(const OptimizationAlgorithmBase &arg)
virtual uint getNP() const
double getEndTime() const
returnValue getSensitivitiesXA(BlockMatrix &_sens) const
virtual uint getNX() const
double getTime(uint pointIdx) const
int acadoMax(const int x, const int y)
int getNumDynamicEquations() const
virtual uint getNXA() const
returnValue initializeControls(const char *fileName)
OptimizationAlgorithmBase()
virtual returnValue initializeOCPiterate(Constraint *const _constraint, const Grid &_unionGrid, uint nx, uint nxa, uint np, uint nu, uint nw)
virtual ~OptimizationAlgorithmBase()
returnValue get(OptionsName name, int &value) const
returnValue initializeDisturbances(const char *fileName)
Discretizes a DifferentialEquation by means of single or multiple shooting.
Stores and evaluates the constraints of optimal control problems.
Provides a time grid consisting of vector-valued optimization variables at each grid point...
Allows to pass back messages to the calling function.
returnValue getSensitivitiesW(BlockMatrix &_sens) const
double getStartTime() const
BooleanType isAffine() const
double getObjectiveValue() const
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Allows to conveniently handle (one-dimensional) grids consisting of time points.
BooleanType isEmpty() const
returnValue getParameters(VariablesGrid &u_) const
virtual returnValue setupDynamicDiscretization(UserInteraction *_userIteraction, Objective *objective, DifferentialEquation **differentialEquation, Constraint *constraint, Grid unionGrid, DynamicDiscretization **dynamicDiscretization)
returnValue initializeParameters(const char *fileName)
#define CLOSE_NAMESPACE_ACADO
returnValue getSensitivitiesP(BlockMatrix &_sens) const
Base class for user-interfaces to formulate and solve optimal control problems and static NLPs...
Base class for discretizing a DifferentialEquation for use in optimal control algorithms.
returnValue getAlgebraicStates(VariablesGrid &xa_) const
virtual returnValue getBounds(const OCPiterate &iter)
returnValue add(const double lb_, const Expression &arg, const double ub_)
virtual NLPsolver * clone() const =0
returnValue getSensitivitiesX(BlockMatrix &_sens) const
BooleanType isLinearQuadratic(Objective *F, DynamicDiscretization *G, Constraint *H) const
returnValue getSensitivitiesU(BlockMatrix &_sens) const
BooleanType isQuadratic()
returnValue initializeDifferentialStates(const char *fileName, BooleanType autoinit=BT_FALSE)
returnValue getDisturbances(VariablesGrid &w_) const
Encapsulates all user interaction for setting options, logging data and plotting results.
virtual returnValue setupObjective(Objective *objective, DifferentialEquation **differentialEquation, Constraint *constraint, Grid unionGrid)
Data class for defining optimal control problems.
virtual returnValue extractOCPdata(Objective **objective, DifferentialEquation ***differentialEquation, Constraint **constraint, Grid &unionGrid)
virtual uint getNU() const
virtual BooleanType isAffine() const =0
returnValue read(std::istream &stream)
returnValue getControls(VariablesGrid &p_) const
returnValue initializeAlgebraicStates(const char *fileName, BooleanType autoinit=BT_FALSE)
virtual uint getNW() const
returnValue init(const Grid &grid_)
uint getNumPoints() const
DVector getVector(uint pointIdx) const
virtual returnValue setupDifferentialEquation(Objective *objective, DifferentialEquation **differentialEquation, Constraint *constraint, Grid unionGrid)
#define ACADOWARNING(retval)
#define BEGIN_NAMESPACE_ACADO
virtual returnValue determineDimensions(Objective *const _objective, DifferentialEquation **const _differentialEquation, Constraint *const _constraint, uint &_nx, uint &_nxa, uint &_np, uint &_nu, uint &_nw) const
returnValue init(UserInteraction *_userIteraction)
Stores and evaluates the objective function of optimal control problems.
returnValue getDifferentialStates(VariablesGrid &xd_) const
#define ACADOERROR(retval)
returnValue init(const Grid &grid_, const int &numberOfStages_=1)
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.