YANE-Framework 1.1.0
Public Member Functions | Protected Member Functions | Protected Attributes

yane::MPC::MPC Class Reference

Class for solving the model predictive control problem. More...

Inheritance diagram for yane::MPC::MPC:
[legend]
Collaboration diagram for yane::MPC::MPC:
[legend]

List of all members.

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::Modelmodel ()
 Function to return the yane::Model::Model object used for optimization and prediction.
yane::Model::Simulatormodelsim ()
 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.
Discretizationproblem ()
 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 $ \infty $.
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

  • STANDARD: without optimization
  • ONESTEP: optimization of the $ m $ new control vectors
  • REPEATED: for $ i \in \{ 0, \ldots, m - 1\} $ a repreated implementation of the in each step new first control vector and a shift of the horizon by $ 1 $ is executed where the last $ N - m + i $ control vectors in each step $ i \in \{ 0, \ldots, m - 2\} $ are reoptimized.

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

  • CURRENT_DATA: data of time grid and control at current time instant is returned
  • PREDICTED_DATA: data of time grid and control at initial time of the underlying optimal control problem is returned, i.e. predicted data.

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.

Detailed Description

The aim of this class is to solve the following optimal control problem with infinite optimization horizon for a given initial value $ x(t_0) = x_0. $

\begin{eqnarray*} \mbox{Minimize} \; J_\infty(x, u) & = & \sum\limits_{i=0}^{\infty} \int\limits_{t_i}^{t_{i + 1}} L \left( \tau, x_{u}(\tau, x_0), u(\tau, x_0) \right) d \tau + \sum\limits_{i=0}^{\infty} l \left( t_k, x_{u}(t_i, x_0), u(t_i, x_0) \right) \\ \dot{x}_{u}(t) & = & f(x_{u}(t, x(t_k)), u(x(t_k), t)) \qquad \forall t \in [t_0, \infty) \\ x_{u}(0, x_0) & = & x_0 \\ x_{u}(t, x_0) & \in & X \qquad \forall t \in [t_0, \infty] \\ u(t, x_0) & \in & U \qquad \forall t \in [t_0, \infty) \end{eqnarray*}

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:

\begin{eqnarray*} \mbox{Find} \; \mu(x(t_k)) & := & u_{[0]} \\ \mbox{ST.} \;\; u_{[0, N-1]} & = & \mbox{{\it argmin}}_{u \in \mathcal{U}_N} J_N (x(t_k), u) \\ J_N (x(t_k), u) & = & \sum\limits_{i=0}^{N - 1} \int\limits_{t_i^k}^{t_{i + 1}^k} L \left( \tau, x_{u}(\tau, x(t_k)), u(\tau, x(t_k)) \right) d \tau \\ && + \sum\limits_{i=0}^{N - 1} l \left( t_i^k, x_{u}(t_i^k, x(t_k)), u(t_i^k, x(t_k)) \right) + F(t_N^k, x_{u}(t_N^k, x(t_k))) \\ \dot{x}_{u}(t) & = & f(t, x_{u}(t, x(t_k)), u(x(t_k), t)) \qquad \forall t \in [t_0^k, t_N^k] \\ x_{u}(0, x(t_k)) & = & x(t_k) \\ x_{u}(t, x(t_k)) & \in & X \qquad \forall t \in [t_0^k, t_N^k] \\ u(x(t_k), t) & \in & U \qquad \forall t \in [t_i^k, t_{i + 1}^k) \end{eqnarray*}

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 $ x(t_{j+1}) $, 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.


Constructor & Destructor Documentation

LIB_EXPORT yane::MPC::MPC::MPC ( double  infty = 1E19,
NetworkedMPCConfig configuration = 0 
)
Parameters:
INFTYDefines the value $ \infty $
configurationDefines the network configuration of the MPC object

Member Function Documentation

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.

Parameters:
tTime grid
uControl vector
Exceptions:
yane::Utils::NotInitializedExceptionIs 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::MemoryExceptionIs 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

Parameters:
xEstimate of the initial value of the state
realtimestepsNumber of time steps on the time grid after which the computation shall be terminated (0 = no limit)
aborttimeoffsetTime offset after which the computation shall be terminated (negative values shorten the time interval available for optimization)
abortSuboptimalityDegreeBound on the degree of suboptimality to stop the optimization
Exceptions:
yane::Utils::NotInitializedExceptionIs 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::SolverWarningIs thrown if the yane::MinProg::NLP object terminates with a warning
yane::OdeSolve::OdeSolExIs thrown if the yane::OdeSolve::OdeSolve object terminates with an error
yane::Utils::ValueExceptionIs thrown if a null pointer is submitted
yane::Utils::ExceptionIs 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

Parameters:
tTime grid
t_startInitial time
h_newSampling width
Exceptions:
yane::Utils::NotInitializedExceptionIs 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

Returns:
Current optimization horizon
Exceptions:
yane::Utils::NotInitializedExceptionIs 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

Parameters:
tTime grid
u0Initial guess of the control on the optimization horizon
Exceptions:
yane::Utils::NotInitializedExceptionIs 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::ValueExceptionIs thrown if a null pointer submitted
LIB_EXPORT int yane::MPC::MPC::maxHorizon ( )

This function returns the maximal allowable optimization horizon

Returns:
Maximal allowable optimization horizon
Exceptions:
yane::Utils::NotInitializedExceptionIs 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

Returns:
Pointer the used yane::Model::Model object
Exceptions:
yane::Utils::NotInitializedExceptionIs 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 ( )

This function returns the pointer of the simulator used within the MPC routine

Returns:
Pointer of the simulator used within the MPC routine
LIB_EXPORT yane::MPC::T_OPTIMALITYSTATE yane::MPC::MPC::optimalitystate ( )

This function returns the current state of the internal optimization error variable

Returns:
Value of the internal optimization error variable
LIB_EXPORT int yane::MPC::MPC::precedesteps ( )

This function returns the current number of precedesteps

Returns:
Current number of precedesteps
Exceptions:
yane::Utils::NotInitializedExceptionIs 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

Returns:
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.

Parameters:
odemanagerPointer to used class yane::MPC::OdeManager object
minimizerPointer to used class yane::MinProg::NLP object
modelPointer to used class yane::Model::Model object
horizonMaximal length of the optimization horizon
precedestepsNumber of prediction steps to obtain initial value for optimization
shootingdataPointer to used class yane::MPC::ModelShootingData object
Exceptions:
yane::MinProg::MinProgExceptionIs thrown if problem cannot be initialized
yane::Utils::ValueExceptionIs thrown if input values are incorrect
yane::Utils::ExceptionIs thrown if called objects reveal error messages
yane::Utils::MemoryExceptionIs 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.

Parameters:
newhorizonNew length of the optimization horizon
h_newLength of the sampling width for added time instances
Exceptions:
yane::Utils::ValueExceptionIs thrown if the new horizon length is larger than the maximal horizon length or if the new horizon length is negative
yane::Utils::NotInitializedExceptionIs 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::MinProgExceptionIs thrown if the discretized optimization problem or the prediction cannot be initialized
yane::Utils::MemoryExceptionIs thrown if memory allocation fails
yane::Utils::ValueExceptionIs thrown if a null pointer is submitted
yane::Utils::ExceptionIs 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

Parameters:
xCurrent state vector
Exceptions:
yane::Utils::NotInitializedExceptionIs 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

Parameters:
optimizeDecision variable on the type of shift

  • (0): without optimization
  • (1): optimization of the $ m $ new control vectors
  • (2): for $ i \in \{ 0, \ldots, m - 1\} $ a repreated implementation of the in each step new first control vector and a shift of the horizon by $ 1 $ is executed where the last $ N - m + i $ control vectors in each step $ i \in \{ 0, \ldots, m - 2\} $ are reoptimized
Exceptions:
yane::Utils::NotInitializedExceptionIs 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::ValueExceptionIs 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

Parameters:
rtolRelative tolerance
atolAbsolute tolerance
Exceptions:
yane::Utils::MemoryExceptionIs thrown if memory allocation fails
yane::Utils::ExceptionIs 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

Parameters:
rtolVector of relative tolerances
atolVector of absolute tolerances
Exceptions:
yane::Utils::MemoryExceptionIs thrown if memory allocation fails
yane::Utils::ExceptionIs 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

Parameters:
showSqpErrorDecision 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.

Parameters:
nextControlsPointer to the control values which are to be implemented next
nextTimestepsPointer to the time instances for which the next control values are computed
mNumber of sampling instances to be shifted (default 1)
xEstimate of the current state vector
h_newLength of the added sampling interval at the end of the shifted optimization horizon
Exceptions:
yane::Utils::NotInitializedExceptionIs 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::MinProgExceptionIs thrown if the discretized optimization problem or the prediction cannot be initialized
yane::OdeSolve::OdeSolExIs thrown if the yane::OdeSolve::OdeSolve object terminates with an error
yane::Utils::MemoryExceptionIs thrown if memory allocation fails
yane::Utils::ValueExceptionIs thrown if input is errorneous
yane::Utils::ExceptionIs thrown if an other error occurs

Reimplemented in yane::MPC::m21MPC.