![]() |
YANE-Framework 1.1.0
|
Class for solving the model predictive control problem. More...
Public Member Functions | |
virtual void | allocateMemory (double *&t, double *&u) |
Function to allocate the memory for the time and the control values. | |
virtual void | calc (double *x, int realtimesteps=0, double aborttimeoffset=0.0, double abortSuboptimalityDegree=INFINITY) |
Function to start the computation of the MPC solution. | |
virtual void | generateTimeGrid (double *t, double t_start, double h_new) |
Function to assign equidistant values to the time grid variable. | |
int | horizon () |
Function to return the current optimization horizon. | |
virtual void | initCalc (double *t, double *u0) |
Function to initialize the MPC problem. | |
int | maxHorizon () |
Function to return the maximal allowable optimization horizon. | |
yane::Model::Model * | model () |
Function to return the yane::Model::Model object used for optimization and prediction. | |
yane::Model::Simulator * | modelsim () |
Function to return the pointer of the simulator used within the MPC routine. | |
MPC (double infty=1E19, NetworkedMPCConfig *configuration=0) | |
Constructor. | |
T_OPTIMALITYSTATE | optimalitystate () |
Function to return the current state of the internal optimization error variable. | |
int | precedesteps () |
Function to return the current number of precedesteps. | |
Discretization * | problem () |
Function to return the pointer of the discretized optimal control problem. | |
virtual void | reset (OdeManager *odemanager, yane::MinProg::NLP *minimizer, yane::Model::Model *model, int horizon, int precedesteps=0, ModelShootingData *shootingdata=0) |
Function to initialize the MPC object and set all relevant internal data. | |
virtual void | resizeHorizon (int newhorizon, double h_new) |
Function to modify the length of the optimization horizon. | |
virtual void | setConfigShiftHorizon (T_SHIFTSTATE optimize=STANDARD, T_SHIFTRETURNDATA returndata=PREDICTED_DATA) |
Function to configure the yane::MPC::MPC::shiftHorizon function. | |
virtual void | setInternalSimulatorPrecision (double *rtol, double *atol) |
Function to modify the absolute and relative error tolerance vectors of the internally used yane::Model::Simulator object. | |
virtual void | setInternalSimulatorPrecision (double rtol, double atol) |
Function to modify the absolute and relative error tolerances of the internally used yane::Model::Simulator object. | |
virtual void | setShowSqpError (bool showSqpError) |
Function to set the decision variable on showing all errors of the used yane::MinProg::NLP object. | |
virtual void | shiftHorizon (double *nextControls, double *nextTimesteps, int m=1, double *x=0, double h_new=0.0) |
Function to shift the time horizon of the optimal control problem. | |
virtual | ~MPC () |
Destructor. | |
Protected Member Functions | |
void | freeMem () |
Function to free allocated memory. | |
void | setAbortSuboptimalityValues (double *x) |
Function to set he configuration of the suboptimality based stopping criterion. | |
Protected Attributes | |
double | _abortsuboptimalitydegree |
Bound on the degree of suboptimality to stop the optimization. | |
NetworkedMPCConfig * | _configuration |
Pointer of the NetworkedMPCConfig configuration of the MPC object. | |
int | _horizon |
Length of the optimization horizon. | |
double | _infty |
Value for ![]() | |
int | _maxhorizon |
Maximal length of the optimization horizon. | |
yane::MinProg::NLP * | _minimizer |
Pointer to used class yane::MinProg::NLP object. | |
yane::Model::Model * | _model |
Pointer to used class yane::Model::Model object. | |
yane::Model::Simulator * | _modelsim |
Pointer to used class yane::Model::Simulator object. | |
OdeManager * | _odemanager |
Pointer to used class yane::MPC::OdeManager object. | |
T_OPTIMALITYSTATE | _optimalitystate |
Value of the internal optimization error variable. | |
T_SHIFTSTATE | _optimize |
Decision variable on the type of shift
| |
int | _precedesteps |
Number of prediction steps to obtain initial value for optimization. | |
Discretization * | _problem |
Pointer to used class yane::MPC::Discretization object. | |
Discretization * | _problem_shift |
Pointer to used class yane::MPC::Discretization object used within the yane::MPC::MPC::shiftHorizon method. | |
T_SHIFTRETURNDATA | _returndata |
Decision variable on the return data of shifted
| |
ModelShootingData * | _shootingdata |
Pointer to used class yane::MPC::ModelShootingData object. | |
bool | _showsqperror |
Decision variable on showing all errors of the used yane::MinProg::NLP object. | |
double * | _timesteps |
Time grid. | |
double * | _timesteps_preceded |
Time grid for prediction steps. | |
double * | _u |
Control vector. | |
double * | _u_preceded |
Control vector for prediction steps. | |
double * | _x_simulated |
Simulated state vector at the first time instance of optimization. |
The aim of this class is to solve the following optimal control problem with infinite optimization horizon for a given initial value
Since solving this problem usually requires the solution of a Hamilton-Jacobi-Bellman (partial) differential equation, we use a receding horizon control approach an approximate the infinite horizon solution by the solution of a sequence of finite horizon optimal control problems:
To solve each of these optimal control problems the function yane::MPC::MPC::initCalc discretizes the control problem with a not necessarily equidistant time grid. The resulting optimization problem is then solved by a (predefined) minimization routine.
Then the first value of the computed control is implemented and the optimization horizon is shifted forward in time. This allows the procedure to be applied iteratively and computes a (suboptimal) infinite horizon control.
Note that the function yane::MPC::MPC::shiftHorizon can be used to shift the optimization horizon forward in time by one or more sampling intervals. The required initial value , however, has to be supplied by an external routine. This corresponds to the usage of this method in real life since the internal model and the external plant not necessarily coincide.
LIB_EXPORT yane::MPC::MPC::MPC | ( | double | infty = 1E19 , |
NetworkedMPCConfig * | configuration = 0 |
||
) |
INFTY | Defines the value ![]() |
configuration | Defines the network configuration of the MPC object |
LIB_EXPORT void yane::MPC::MPC::allocateMemory | ( | double *& | t, |
double *& | u | ||
) | [virtual] |
This function allocates the memory for the time and the control values. Additionally default values for the control as defined in the yane::Model::Model object are set.
t | Time grid |
u | Control vector |
yane::Utils::NotInitializedException | Is thrown if the yane::MPC::MPC object is not yet defined, i.e. if the yane::MPC::MPC::reset function has not been called |
yane::Utils::MemoryException | Is thrown if memory allocation failed |
LIB_EXPORT void yane::MPC::MPC::calc | ( | double * | x, |
int | realtimesteps = 0 , |
||
double | aborttimeoffset = 0.0 , |
||
double | abortSuboptimalityDegree = INFINITY |
||
) | [virtual] |
This function triggers the computation of the MPC solution
x | Estimate of the initial value of the state |
realtimesteps | Number of time steps on the time grid after which the computation shall be terminated (0 = no limit) |
aborttimeoffset | Time offset after which the computation shall be terminated (negative values shorten the time interval available for optimization) |
abortSuboptimalityDegree | Bound on the degree of suboptimality to stop the optimization |
yane::Utils::NotInitializedException | Is thrown if the yane::MPC::MPC object is not yet defined, i.e. if the yane::MPC::MPC::reset function has not been called |
yane::MinProg::SolverWarning | Is thrown if the yane::MinProg::NLP object terminates with a warning |
yane::OdeSolve::OdeSolEx | Is thrown if the yane::OdeSolve::OdeSolve object terminates with an error |
yane::Utils::ValueException | Is thrown if a null pointer is submitted |
yane::Utils::Exception | Is thrown if any other error occurs |
Reimplemented in yane::MPC::AdaptiveMPC.
LIB_EXPORT void yane::MPC::MPC::generateTimeGrid | ( | double * | t, |
double | t_start, | ||
double | h_new | ||
) | [virtual] |
This function assignes equidistant values to the time grid variable
t | Time grid |
t_start | Initial time |
h_new | Sampling width |
yane::Utils::NotInitializedException | Is thrown if the yane::MPC::MPC object is not yet defined, i.e. if the yane::MPC::MPC::reset function has not been called |
LIB_EXPORT int yane::MPC::MPC::horizon | ( | ) |
This function returns the current optimization horizon
yane::Utils::NotInitializedException | Is thrown if the yane::MPC::MPC object is not yet defined, i.e. if the yane::MPC::MPC::reset function has not been called |
LIB_EXPORT void yane::MPC::MPC::initCalc | ( | double * | t, |
double * | u0 | ||
) | [virtual] |
This function initializes the MPC problem
t | Time grid |
u0 | Initial guess of the control on the optimization horizon |
yane::Utils::NotInitializedException | Is thrown if the yane::MPC::MPC object is not yet defined, i.e. if the yane::MPC::MPC::reset function has not been called |
yane::Utils::ValueException | Is thrown if a null pointer submitted |
LIB_EXPORT int yane::MPC::MPC::maxHorizon | ( | ) |
This function returns the maximal allowable optimization horizon
yane::Utils::NotInitializedException | Is thrown if the yane::MPC::MPC object is not yet defined, i.e. if the yane::MPC::MPC::reset function has not been called |
LIB_EXPORT yane::Model::Model * yane::MPC::MPC::model | ( | ) |
This function returns the yane::Model::Model object used for optimization and prediction
yane::Utils::NotInitializedException | Is thrown if the yane::MPC::MPC object is not yet defined, i.e. if the yane::MPC::MPC::reset function has not been called |
LIB_EXPORT yane::Model::Simulator * yane::MPC::MPC::modelsim | ( | ) |
LIB_EXPORT yane::MPC::T_OPTIMALITYSTATE yane::MPC::MPC::optimalitystate | ( | ) |
This function returns the current state of the internal optimization error variable
LIB_EXPORT int yane::MPC::MPC::precedesteps | ( | ) |
This function returns the current number of precedesteps
yane::Utils::NotInitializedException | Is thrown if the yane::MPC::MPC object is not yet defined, i.e. if the yane::MPC::MPC::reset function has not been called |
LIB_EXPORT yane::MPC::Discretization * yane::MPC::MPC::problem | ( | ) |
This function returns the pointer of the discretized optimal control problem
LIB_EXPORT void yane::MPC::MPC::reset | ( | OdeManager * | odemanager, |
yane::MinProg::NLP * | minimizer, | ||
yane::Model::Model * | model, | ||
int | horizon, | ||
int | precedesteps = 0 , |
||
ModelShootingData * | shootingdata = 0 |
||
) | [virtual] |
This function initializes the MPC object and sets all relevant internal data. If this method is called repeatedly, then all all variables are set back to their original values.
Note that before one can use an MPC object this method must be called once.
odemanager | Pointer to used class yane::MPC::OdeManager object |
minimizer | Pointer to used class yane::MinProg::NLP object |
model | Pointer to used class yane::Model::Model object |
horizon | Maximal length of the optimization horizon |
precedesteps | Number of prediction steps to obtain initial value for optimization |
shootingdata | Pointer to used class yane::MPC::ModelShootingData object |
yane::MinProg::MinProgException | Is thrown if problem cannot be initialized |
yane::Utils::ValueException | Is thrown if input values are incorrect |
yane::Utils::Exception | Is thrown if called objects reveal error messages |
yane::Utils::MemoryException | Is thrown if memory allocation failed |
Reimplemented in yane::MPC::m21MPC, and yane::MPC::SuboptimalityMPC.
LIB_EXPORT void yane::MPC::MPC::resizeHorizon | ( | int | newhorizon, |
double | h_new | ||
) | [virtual] |
This function modifies the length of the optimization horizon of the yane::MPC::MPC object. Note that the length must not be larger than the maximal length of the optimization horizon.
newhorizon | New length of the optimization horizon |
h_new | Length of the sampling width for added time instances |
yane::Utils::ValueException | Is thrown if the new horizon length is larger than the maximal horizon length or if the new horizon length is negative |
yane::Utils::NotInitializedException | Is thrown if the yane::MPC::MPC object is not yet defined, i.e. if the yane::MPC::MPC::reset function has not been called |
yane::MinProg::MinProgException | Is thrown if the discretized optimization problem or the prediction cannot be initialized |
yane::Utils::MemoryException | Is thrown if memory allocation fails |
yane::Utils::ValueException | Is thrown if a null pointer is submitted |
yane::Utils::Exception | Is thrown if an other error occurs |
Reimplemented in yane::MPC::m21MPC, and yane::MPC::SuboptimalityMPC.
LIB_EXPORT void yane::MPC::MPC::setAbortSuboptimalityValues | ( | double * | x | ) | [protected] |
This function sets the configuration of the suboptimality based stopping criterion
x | Current state vector |
yane::Utils::NotInitializedException | Is thrown if the yane::MPC::MPC object is not yet defined, i.e. if the yane::MPC::MPC::reset function has not been called |
LIB_EXPORT void yane::MPC::MPC::setConfigShiftHorizon | ( | T_SHIFTSTATE | optimize = STANDARD , |
T_SHIFTRETURNDATA | returndata = PREDICTED_DATA |
||
) | [virtual] |
This function configures the yane::MPC::MPC::shiftHorizon function
optimize | Decision variable on the type of shift
|
yane::Utils::NotInitializedException | Is thrown if the yane::MPC::MPC object is not yet defined, i.e. if the yane::MPC::MPC::reset function has not been called |
yane::Utils::ValueException | Is thrown if input is errorneous |
LIB_EXPORT void yane::MPC::MPC::setInternalSimulatorPrecision | ( | double | rtol, |
double | atol | ||
) | [virtual] |
This function modifies the absolute and relative error tolerances of the internally used yane::Model::Simulator object
rtol | Relative tolerance |
atol | Absolute tolerance |
yane::Utils::MemoryException | Is thrown if memory allocation fails |
yane::Utils::Exception | Is thrown if an other error occurs |
LIB_EXPORT void yane::MPC::MPC::setInternalSimulatorPrecision | ( | double * | rtol, |
double * | atol | ||
) | [virtual] |
This function modifies the absolute and relative error tolerance vectors of the internally used yane::Model::Simulator object
rtol | Vector of relative tolerances |
atol | Vector of absolute tolerances |
yane::Utils::MemoryException | Is thrown if memory allocation fails |
yane::Utils::Exception | Is thrown if an other error occurs |
LIB_EXPORT void yane::MPC::MPC::setShowSqpError | ( | bool | showSqpError | ) | [virtual] |
This function set the decision variable on showing all errors of the used yane::MinProg::NLP object
showSqpError | Decision variable on showing all errors of the used yane::MinProg::NLP object |
LIB_EXPORT void yane::MPC::MPC::shiftHorizon | ( | double * | nextControls, |
double * | nextTimesteps, | ||
int | m = 1 , |
||
double * | x = 0 , |
||
double | h_new = 0.0 |
||
) | [virtual] |
This function shifts the time horizon of the optimal control problem
The function expects pointers for the control values and the time instances at which these are valid. Moreover, the number of shifts is required. Optionally, the user can supply an estimate of the current state vector as well as a length for the new added sampling interval at the end of the optimization horizon.
nextControls | Pointer to the control values which are to be implemented next |
nextTimesteps | Pointer to the time instances for which the next control values are computed |
m | Number of sampling instances to be shifted (default 1) |
x | Estimate of the current state vector |
h_new | Length of the added sampling interval at the end of the shifted optimization horizon |
yane::Utils::NotInitializedException | Is thrown if the yane::MPC::MPC object is not yet defined, i.e. if the yane::MPC::MPC::reset function has not been called |
yane::MinProg::MinProgException | Is thrown if the discretized optimization problem or the prediction cannot be initialized |
yane::OdeSolve::OdeSolEx | Is thrown if the yane::OdeSolve::OdeSolve object terminates with an error |
yane::Utils::MemoryException | Is thrown if memory allocation fails |
yane::Utils::ValueException | Is thrown if input is errorneous |
yane::Utils::Exception | Is thrown if an other error occurs |
Reimplemented in yane::MPC::m21MPC.