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

yane::MPC::SuboptimalityMPC Class Reference

Implementation of various suboptimality estimates for model predictive control laws. More...

Inheritance diagram for yane::MPC::SuboptimalityMPC:
[legend]
Collaboration diagram for yane::MPC::SuboptimalityMPC:
[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.
double alpha ()
 Function to return the stored degree of suboptimality $ \alpha $.
void aposterioriEstimate (double *x, double &alpha, bool saveprevious=true, bool restart=false)
 Function to evaluate the a posteriori suboptimality estimate.
void aposterioriPracticalEstimate (double *x, double &alpha, bool saveprevious=true, bool restart=false)
 Function to evaluate the a posteriori practical suboptimality estimate.
void aprioriEstimate (double *x, double &alpha, double &gamma, int N0)
 Function to evaluate the a priori suboptimality estimate.
void aprioriPracticalEstimate (double *x, double &alpha, double &gamma, int N0)
 Function to evaluate the a priori practical suboptimality estimate.
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.
void mstepAposterioriEstimate (double *x, double &alpha, int m, bool saveprevious=true, bool restart=false)
 Function to evaluate the m-step a posteriori suboptimality estimate.
void mstepAposterioriPracticalEstimate (double *x, double &alpha, int m, bool saveprevious=true, bool restart=false)
 Function to evaluate the m-step a posteriori practical suboptimality estimate.
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 reset the class yane::MPC::SuboptimalityMPC object with new pointers for underlying classes.
virtual void resizeHorizon (int newhorizon, double h_new)
 Function to modify the length of the optimization horizon.
double samplingLength ()
 Function to return the sampling width.
virtual void setConfigShiftHorizon (T_SHIFTSTATE optimize=STANDARD, T_SHIFTRETURNDATA returndata=PREDICTED_DATA)
 Function to configure the yane::MPC::MPC::shiftHorizon function.
void setConfigSuboptimalityMPC (T_ESTIMATE estimate, int N0=2)
 Function to configure the suboptimality algorithm.
void setEpsilon (double epsilon=1E-6)
 Function to set the radius of the (supposably) practical stability region.
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.
void setNewtonItermax (int newtonItermax)
 Function to set the maximal number of Newton steps to compute $ \gamma(N) $ from a posteriori estimate of $ \alpha(N) $.
void setSamplingLength (double h_new)
 Function to set the sampling width of the new added horizon instances.
virtual void setShowSqpError (bool showSqpError)
 Function to set the decision variable on showing all errors of the used yane::MinProg::NLP object.
void setSingle (bool single=true)
 Function to set the decision variable to distinguish between computing local and closed loop suboptimality estimates.
void setStoreValuefunction (bool storeValuefunction)
 Function to set decision variable to store predicted value function in case an predicted aposteriori estimate is used.
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.
 SuboptimalityMPC (double h_new, double INFTY=1E19)
 Constructor.
 ~SuboptimalityMPC ()
 Destructor.

Protected Member Functions

void aposterioriGamma (int N0)
 Function to compute $ \gamma(N) $ for given $ \alpha(N) $.
void aprioriCalculatedEstimate (double *x, int realtimesteps=0, double aborttimeoffset=0.0)
 Function to compute the suboptimality estimate $ \alpha(N) $ using the methods yane::MPC::SuboptimalityMPC::aposterioriEstimate or yane::MPC::SuboptimalityMPC::aposterioriPracticalEstimate.
void calcAlpha (double *x, int realtimesteps=0, double aborttimeoffset=0.0)
 Function to compute the suboptimality estimate $ \alpha(N) $.
void freeMem ()
 Function to free allocated memory.
void mstepPredictedAposterioriEstimate (double *x, int m=1, int realtimesteps=0, double aborttimeoffset=0.0)
 Function to compute the suboptimality estimate $ \alpha(N) $ using the methods yane::MPC::SuboptimalityMPC::aposterioriEstimate or yane::MPC::SuboptimalityMPC::aposterioriPracticalEstimate.
void predictedAposterioriEstimate (double *x, int realtimesteps, double aborttimeoffset)
 Function to compute the suboptimality estimate $ \alpha(N) $ using the methods yane::MPC::SuboptimalityMPC::aposterioriEstimate or yane::MPC::SuboptimalityMPC::aposterioriPracticalEstimate.
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.
double _alpha
 Suboptimality estimate.
double _alphabound
 Suboptimality bound.
NetworkedMPCConfig_configuration
 Pointer of the NetworkedMPCConfig configuration of the MPC object.
bool _controlAlreadyOptimal
 Decision variable whether optimal control needs to be recalculated for suboptimality estimate.
double _epsilon
 Radius of the (supposably) practical stability region.
T_ESTIMATE _estimate
 Decision variable to define the computing method of the suboptimality degree

  • NONE Standardimplementation without adaptation of the horizon length
  • APOSTERIORI Adaptation of the horizon length using the a posteriori estimate
  • APOSTERIORIPRACTICAL Adaptation of the horizon length using the a posteriori practical estimate
  • APRIORI Adaptation of the horizon length using the a priori estimate
  • APRIORIPRACTICAL Adaptation of the horizon length using the a priori practical estimate.

double _gamma
 Current value of $ \gamma(N) $.
double _h_new
 New added sampling width.
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.
int _N0
 Parameter of the auxilliary length of the additional optimal control problem to compute the a priori suboptimality estimate.
double * _nextcontrols
 Control vector for implementation.
double * _nexttimesteps
 Time grid for implementation.
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_current
 Time grid.
double * _timesteps_preceded
 Time grid for prediction steps.
double * _trajectory_simulated
 Pointer of the open loop solution.
double * _u
 Control vector.
double * _u_current
 Current state vector.
double * _u_preceded
 Control vector for prediction steps.
double * _valuefunction_base
 Pointer of the cost function along the open loop solution for a base initial value using predicted a posteriori estimates.
double * _valuefunction_predicted
 Pointer of the cost function along the open loop solution for a predicted initial value using predicted a posteriori estimates.
double * _valuefunction_simulated
 Pointer of the cost function along the open loop solution.
double * _x_predicted
 Predicted state vector.
double * _x_simulated
 Simulated state vector at the first time instance of optimization.

Detailed Description

Implementation of various suboptimality estimates for model predictive control laws
Using the classes methods one can compute the degree of suboptimality along the closed loop solution as well as the local degree of suboptimality. In the nonpractical case, the results are based on the relaxed Lyapunov inequality

\[ V_N(x(n + 1)) \leq V_N(x(n)) - \alpha l(x(n), \mu_N(x(n))) \]

while in the practical case results are derived from the practical variant of the relaxed Lyapunov inequality

\[ V_N(x(n + 1)) \leq V_N(x(n)) - \min \{ \alpha ( l(x(n), \mu_N(x(n))) - \varepsilon ), l(x(n), \mu_N(x(n))) - \varepsilon \} \]


Constructor & Destructor Documentation

LIB_EXPORT yane::MPC::SuboptimalityMPC::SuboptimalityMPC ( double  h_new,
double  INFTY = 1E19 
)
Parameters:
h_newDiscretization width
INFTYValue for $ \infty $

Member Function Documentation

LIB_EXPORT void yane::MPC::MPC::allocateMemory ( double *&  t,
double *&  u 
) [virtual, inherited]

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 double yane::MPC::SuboptimalityMPC::alpha ( void  )

Function to return the stored degree of suboptimality $ \alpha $

Returns:
degree of suboptimality $ \alpha $

Reimplemented in yane::MPC::AdaptiveMPC.

LIB_EXPORT void yane::MPC::SuboptimalityMPC::aposterioriEstimate ( double *  x,
double &  alpha,
bool  saveprevious = true,
bool  restart = false 
)

This function computes a suboptimality estimate using the relaxed Lyapunov inequality

\[ V_N(x(n + 1)) \leq V_N(x(n)) - \alpha l(x(n), \mu_N(x(n))) \]

for the closed loop solution along the closed loop trajectory. Here, the values of the optimal value function of two consecutive optimal control problems $ V_N(x(n)) $ and $ V_N(x(n + 1)) $ with identical length of the optimization horizon are related to the running cost $ l(x(n), \mu_N(x(n))) $ of the older optimal control problem. The suboptimality estimate is given by the maximal value of the parameter $ \alpha $ which satisfies

\[ \alpha \leq \frac{V_N(x(n)) - V_N(x(n + 1))}{l(x(n), \mu_N(x(n)))} \]

Remark: This function assumes the optimal control for the current optimization horizon is known.

Parameters:
xCurrent state vector
alphaSuboptimality estimate which contains

  • the value of the estimate in the prior MPC step on entrance
  • either the estimate for the current MPC step or the minimum of the current estimate and the previous estimate according to the choice of yane::MPC::SuboptimalityMPC::single on exit
savepreviousDecision variable to store the running cost and cost function value of the current MPC step
restartDecision variable if the estimate shall be restarted
Exceptions:
yane::MPC::SuboptimalityExceptionIs thrown if $ V_N(x(n + 1)) > V_N(x(n)) $ or $ V_N(x(n + 1)) < V_N(x(n)) - l(x(n), \mu_N(x(n))) $ holds
Remark: If this exception occurs due to the second condition then it is likely that a wrong value of $ V_N(x(n + 1)) $ has been computed. In the following MPC step this can be seen from a value $ \alpha > 1 $.
yane::Utils::ExceptionIs thrown if any other error occured
LIB_EXPORT void yane::MPC::SuboptimalityMPC::aposterioriGamma ( int  N0) [protected]

Function to compute $ \gamma(N) $ for given $ \alpha(N) $

See also:
_newtonItermax Maximal number of Newton steps
Parameters:
N0Length of the subproblem
LIB_EXPORT void yane::MPC::SuboptimalityMPC::aposterioriPracticalEstimate ( double *  x,
double &  alpha,
bool  saveprevious = true,
bool  restart = false 
)

This function computes the a posteriori practical suboptimality estimated based upon the relaxed Lyapunov inequality

\[ V_N(x(n + 1)) \leq V_N(x(n)) - \min \{ \alpha ( l(x(n), \mu_N(x(n))) - \varepsilon ), l(x(n), \mu_N(x(n))) - \varepsilon \} \]

along the closed loop trajectory. Here, the values of the optimal value function of two consecutive optimal control problems $ V_N(x(n)) $ and $ V_N(x(n + 1)) $ with identical length of the optimization horizon are related to the running costs of the past optimal control problem $ l(x(n), \mu_N(x(n))) $. Once a set $ \mathcal{L} $ is reached which is forward invariant under the control law $ u_N $, then $ n_0 $ denotes the minimal index such that for all $ 0 \leq n \leq n_0 $ the inequality

\[ V_N(x(n + 1)) \leq V_N(x(n)) \]

holds. Furthermore we define

\[ \sigma := \inf \{ V_N(x(n+ 1)) \, | \; 0 \leq n \leq n_0 \} = V_N(x(n_0 + 1)). \]

Then the suboptimality estimate

\[ \alpha V_\infty(x(n)) \leq \alpha V_\infty^{u_N}(x(n)) \leq V(x(n)) - \sigma, \]

hold with parameter $ \alpha $ which is chosen maximally satisfying the above inequality.
Remark: This function assumes the optimal control for the current optimization horizon is known.

Parameters:
xCurrent state vector
alphaSuboptimality estimate which contains

  • the value of the estimate in the prior MPC step on entrance
  • either the estimate for the current MPC step or the minimum of the current estimate and the previous estimate according to the choice of yane::MPC::SuboptimalityMPC::single on exit
savepreviousDecision variable to store the running cost and cost function value of the current MPC step
restartDecision variable if the estimate shall be restarted
Exceptions:
yane::MPC::SuboptimalityExceptionIs thrown if $ V_N(x(n + 1)) > V_N(x(n)) $ or $ V_N(x(n)) < V_N(x(n + 1)) - l(x(n), \mu_N(x(n))) + \varepsilon $ holds
Remark: If this exception occurs due to the second condition then it is likely that a wrong value of $ V_N(x(n + 1)) $ has been computed. In the following MPC step this can be seen from a value $ \alpha > 1 $.
yane::MPC::PracticalExceptionIs thrown if $ l(x(n), \mu_N(n)) < \varepsilon $
yane::Utils::ExceptionIs thrown if any other error occured
LIB_EXPORT void yane::MPC::SuboptimalityMPC::aprioriCalculatedEstimate ( double *  x,
int  realtimesteps = 0,
double  aborttimeoffset = 0.0 
) [protected]

Function to compute the suboptimality estimate $ \alpha(N) $ using the methods yane::MPC::SuboptimalityMPC::aprioriEstimate or yane::MPC::SuboptimalityMPC::aprioriPracticalEstimate
Remark: This function doesnot assume the optimal control for the current optimization horizon to be known. However, setting _controlAlreadyOptimal to true will override an additional start of the minimizer.

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)
Exceptions:
yane::MPC::MPCExceptionIs thrown if the underlying yane::MPC::MPC object terminates with an error
yane::MinProg::SolverWarningIs thrown if the yane::MinProg::NLP object terminates with a warning
yane::Utils::ExceptionIs thrown if any other error occurs
LIB_EXPORT void yane::MPC::SuboptimalityMPC::aprioriEstimate ( double *  x,
double &  alpha,
double &  gamma,
int  N0 
)

This function computes the a priori suboptimality estimate implicitely based on the relaxed Lyapunov inequality

\[ V_N(x(n + 1)) \leq V_N(x(n)) - \alpha l(x(n), \mu_N(x(n))) \]

along the closed loop trajectory. Since the value of $ V_N(x(n + 1)) $ is not readily available at runtime of the algorithm this is replaced by a sufficient condition:
Suppose that for a given $ N \geq N_0 \geq 2 $ there exists a $ \gamma > 0 $ such that inequalities

\[ \frac{V_{N_0}(x_{u}(N - N_0, x(n)))}{\gamma + 1} \leq \max_{j = 2, \ldots, N_0} l(x_{u}(N - j, x(n)), \mu_{j - 1}(x_{u}(N - j, x(n)))) \]

\[ \frac{V_k(x_{u}(N - k, x(n)))}{\gamma + 1} \leq l(x_{u}(N - k, x(n)), \mu_k(x_{u_N}(N - k, x(n)))) \]

hold for all $ k \in \{N_0 + 1, \ldots, N \} $ and all $ n \geq 0 $. Here, $ x_{u}(j, x(n)) $ denotes the $ j $th open loop state vector of the optimal control problem with initial value $ x(n) $ and horizon length $ N $.
Then, we can compute the suboptimality degree $ \alpha $ according to the following formula

\[ \alpha = \frac{(\gamma + 1)^{N - N_0} - \gamma^{N - N_0 + 2}}{(\gamma + 1)^{N - N_0}} \]

Remark: This function assumes the optimal control for the current optimization horizon is known.

Parameters:
xCurrent state vector
alphaSuboptimality estimate which contains

  • the value of the estimate in the prior MPC step on entrance
  • either the estimate for the current MPC step or the minimum of the current estimate and the previous estimate according to the choice of yane::MPC::SuboptimalityMPC::single on exit
gammaVariable $ \gamma $ which contains

  • the value of the characteristic of the prior MPC step on entrance
  • either the characteristic or the minimum of the current and the previous characteristic according to the choice of yane::MPC::SuboptimalityMPC::single on exit
N0Horizon length of the auxilliary optimal control problem
Exceptions:
yane::MPC::SuboptimalityExceptionIs thrown if one of the optimal control problems is not correctly solved
Remark: If this exception is thrown then either a wrong value of $ l(x_{u}(N - j, x(n)), \mu_{j - 1}(x_{u}(N - j, x(n)))) $ or $ V_{N}(x(n)) $ has been computed within the optimization. This becomes obvious if a value $ \alpha > 1 $ could be obtained.
yane::MPC::MPCExceptionIs thrown if an MPC internal error occured
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 or $ N_0 $ is larger than the optimization horizon
yane::Utils::ExceptionIs thrown if any other error occured
LIB_EXPORT void yane::MPC::SuboptimalityMPC::aprioriPracticalEstimate ( double *  x,
double &  alpha,
double &  gamma,
int  N0 
)

This function computes the a priori suboptimality estimate implicitely based on the relaxed Lyapunov inequality

\[ V_N(x(n + 1)) \leq V_N(x(n)) - \min \{ \alpha ( l(x(n), \mu_N(x(n))) - \varepsilon ), l(x(n), \mu_N(x(n))) - \varepsilon \} \]

along the closed loop trajectory. Since the value of $ V_N(x(n + 1)) $ is not readily available at runtime of the algorithm this is replaced by a sufficient condition:
Suppose that for a given $ N \geq N_0 \geq 2 $ there exists a $ \gamma > 0 $ such that inequalities

\[ V_{N_0}(x_{u}(N - N_0, x(n))) \leq \max_{j = 2, \ldots, N_0} \{ (\gamma + 1) l(x_{u}(N - j, x(n)), \mu_{j - 1}(x_{u}(N - j, x(n)))) + (1 - (N_0 - 1) \gamma) \varepsilon, l(x_{u}(N - j, x(n)), \mu_{j - 1}(x_{u}(N - j, x(n)))) + \varepsilon \} \]

\[ V_k(x_{u}(N - k, x(n))) \leq \max \{ (\gamma + 1) l(x_{u}(N - k, x(n)), \mu_k(x_{u}(N - k, x(n)))) + (k - \gamma - 1) \varepsilon, l(x_{u}(N - k, x(n)), \mu_k(x_{u}(N - k, x(n)))) + (k - 1) \varepsilon \} \]

hold for all $ k \in \{N_0 + 1, \ldots, N \} $ and all $ n \geq 0 $. Here, $ x_{u}(j, x(n)) $ denotes the $ j $th open loop state vector of the optimal control problem with initial value $ x(n) $ and horizon length $ N $.
Then, we can compute the suboptimality degree $ \alpha $ according to the following formula

\[ \alpha = \frac{(\gamma + 1)^{N - N_0} - \gamma^{N - N_0 + 2}}{(\gamma + 1)^{N - N_0}} \]

Remark: This function assumes the optimal control for the current optimization horizon is known.

Parameters:
xCurrent state vector
alphaSuboptimality estimate which contains

  • the value of the estimate in the prior MPC step on entrance
  • either the estimate for the current MPC step or the minimum of the current estimate and the previous estimate according to the choice of yane::MPC::SuboptimalityMPC::single on exit
gammaVariable $ \gamma $ which contains

  • the value of the characteristic of the prior MPC step on entrance
  • either the characteristic or the minimum of the current and the previous characteristic according to the choice of yane::MPC::SuboptimalityMPC::single on exit
N0Horizon length of the auxilliary optimal control problem
Exceptions:
yane::MPC::SuboptimalityExceptionIs thrown if
(1) $ \max\limits_{j=2, \ldots, N_0} l(x_{u}(N - j, x(n)), \mu_{j-1}(x_{u}(N - j, x(n))) \leq ( N_0 - 1 ) \varepsilon $
(2) $ V_{N_0}(x_{u}(N - N_0, x(n))) \leq \max\limits_{j=2, \ldots, N_0} l(x_{u}(N - j, x(n)), \mu_{j - 1}(x_u(N - j, x(n)))) + \varepsilon $
(3) $ V_k(x_{u}(N - k, x(n))) \leq k \varepsilon $ for all $ k \in \{ N_0 + 1, \ldots, N \} $
(4) $ l(x_{u}(N - k, x(n)), \mu_N(x_{u}(N - k, x(n))) \leq \varepsilon $
yane::MPC::PracticalExceptionIs thrown if $ l(x(n), \mu_N(x(n))) < \varepsilon $
yane::MPC::MPCExceptionIs thrown if an MPC internal error occured
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 or $ N_0 $ is larger than the optimization horizon
yane::Utils::ExceptionIs thrown if any other error occured
LIB_EXPORT void yane::MPC::MPC::calc ( double *  x,
int  realtimesteps = 0,
double  aborttimeoffset = 0.0,
double  abortSuboptimalityDegree = INFINITY 
) [virtual, inherited]

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::SuboptimalityMPC::calcAlpha ( double *  x,
int  realtimesteps = 0,
double  aborttimeoffset = 0.0 
) [protected]

Function to compute the suboptimality estimate $ \alpha(N) $
To this end, the suboptimality estimate of class SuboptimalityMPC chosen by setting estimate in method setConfigSuboptimalityMPC is used.
Remark: This function doesnot assume the optimal control for the current optimization horizon to be known. However, setting _controlAlreadyOptimal to true will override an additional start of the minimizer.

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)
Exceptions:
yane::MPC::MPCExceptionIs thrown if the underlying yane::MPC::MPC object terminates with an error
yane::MinProg::SolverWarningIs thrown if the yane::MinProg::NLP object terminates with a warning
yane::Utils::ExceptionIs thrown if any other error occurs
See also:
yane::MPC::AdaptiveMPC::setConfigAdaptiveMPC Function to configure the adaptation algorithm
yane::MPC::AdaptiveMPC::_estimate Decision variable to define the computing method of the suboptimality degree
  • (0) Standardimplementation without adaptation of the horizon length
  • (1) Adaptation of the horizon length using the a posteriori estimate
  • (2) Adaptation of the horizon length using the a posteriori practical estimate
  • (3) Adaptation of the horizon length using the a priori estimate
  • (4) Adaptation of the horizon length using the a priori practical estimate
LIB_EXPORT void yane::MPC::MPC::generateTimeGrid ( double *  t,
double  t_start,
double  h_new 
) [virtual, inherited]

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 ( ) [inherited]

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, inherited]

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 ( ) [inherited]

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 ( ) [inherited]

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 ( ) [inherited]

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 void yane::MPC::SuboptimalityMPC::mstepAposterioriEstimate ( double *  x,
double &  alpha,
int  m,
bool  saveprevious = true,
bool  restart = false 
)

This function computes a m-step suboptimality estimate using the relaxed Lyapunov inequality

\[ V_N(x(n + m)) \leq V_N(x(n)) - \alpha \sum\limits_{j = n}^{n + m} l(x_u(j, x(n)), u(j, x(n))) \]

for the closed loop solution along the closed loop trajectory. Here, we relate two optimal control problems to each other which arise from a shift of $ m $ time instances, i.e. we not only implement one control vector but a sequence of $ m $ control vectors before reoptimizing. The values of the optimal value function of two consecutive optimal control problems $ V_N(x(n)) $ and $ V_N(x(n + m)) $ with identical length of the optimization horizon are related to the sum of running cost $ \sum\limits_{j = n}^{n + m} l(x(n), \mu_N(x(n))) $ of the older optimal control problem. The suboptimality estimate is given by the maximal value of the parameter $ \alpha $ which satisfies

\[ \alpha \leq \frac{V_N(x(n)) - V_N(x(n + m))}{\sum\limits_{j = n}^{n + m} l(x_u(j, n), u(j, x(n)))} \]

Remark: This function assumes the optimal control for the current optimization horizon is known.

Parameters:
xCurrent state vector
alphaSuboptimality estimate which contains

  • the value of the estimate in the prior MPC step on entrance
  • either the estimate for the current MPC step or the minimum of the current estimate and the previous estimate according to the choice of yane::MPC::SuboptimalityMPC::single on exit
mNumber of control vectors which shall be implemented
savepreviousDecision variable to store the running cost and cost function value of the current MPC step
restartDecision variable if the estimate shall be restarted
Exceptions:
yane::MPC::SuboptimalityExceptionIs thrown if $ V_N(x_{u}(n + m, x)) > V_N(x_{u}(n, x)) $ or $ V_N(x(n + m)) < V_N(x(n)) - \sum\limits_{j = n}^{n + m} l(x_u(j, x(n)), u(j, x(n))) $ holds
Remark: If this exception occurs due to the second condition then it is likely that a wrong value of $ V_N(x(n + m)) $ has been computed. In the following MPC step this can be seen from a value $ \alpha > 1 $.
yane::OdeSolve::OdeSolExIs thrown if the yane::OdeSolve::OdeSolve object terminates with an error
yane::Utils::ValueExceptionIs thrown if a null pointer is submitted or $ m $ is larger than the optimization horizon
yane::Utils::ExceptionIs thrown if any other error occured
LIB_EXPORT void yane::MPC::SuboptimalityMPC::mstepAposterioriPracticalEstimate ( double *  x,
double &  alpha,
int  m,
bool  saveprevious = true,
bool  restart = false 
)

This function computes the a posteriori practical suboptimality estimated based upon the relaxed Lyapunov inequality

\[ V_N(x(n + 1)) \leq V_N(x(n)) - \min \{ \alpha ( \sum\limits_{j = n}^{n + m} l(x_u(j, x(n)), u(j, x(n))) - \varepsilon ), \sum\limits_{j = n}^{n + m} l(x_u(j, x(n)), u(j, x(n))) - \varepsilon \} \]

along the closed loop trajectory. Here, we relate two optimal control problems to each other which arise from a shift of $ m $ time instances, i.e. we not only implement one control vector but a sequence of $ m $ control vectors before reoptimizing. The values of the optimal value function of two consecutive optimal control problems $ V_N(x(n)) $ and $ V_N(x(n + m)) $ with identical length of the optimization horizon are related to the sum of running cost $ \sum\limits_{j = n}^{n + m} l(x(n), \mu_N(x(n))) $ of the older optimal control problem. Once a set $ \mathcal{L} $ is reached which is forward invariant under the control law $ u_N $, then $ n_0 $ denotes the minimal index such that for all $ 0 \leq n \leq n_0 $ the inequality

\[ V_N(x(n + 1)) \leq V_N(x(n)) \]

holds. Furthermore we define

\[ \sigma := \inf \{ V_N(x(n + m)) \, | \; 0 \leq n \leq n_0 \} = V_N(x(n_0 + 1)). \]

Then the suboptimality estimate

\[ \alpha V_\infty(x(n)) \leq \alpha V_\infty^{u_N}(x(n)) \leq V(x(n)) - \sigma, \]

hold with parameter $ \alpha $ which is chosen maximally satisfying the above inequality.
Remark: This function assumes the optimal control for the current optimization horizon is known.

Parameters:
xCurrent state vector
alphaSuboptimality estimate which contains

  • the value of the estimate in the prior MPC step on entrance
  • either the estimate for the current MPC step or the minimum of the current estimate and the previous estimate according to the choice of yane::MPC::SuboptimalityMPC::single on exit
  • or 1 if the restart option is used
mNumber of control vectors which shall be implemented
savepreviousDecision variable to store the running cost and cost function value of the current MPC step (default true)
restartDecision variable if the estimate shall be restarted (default false)
Exceptions:
yane::MPC::SuboptimalityExceptionIs thrown if $ V_N(x(n + m)) > V_N(x(n)) $ or $ V_N(x(n)) < V_N(x(n + m)) - \sum\limits_{j = i}^{i + m} l(x_u(j, x(n)), u(j, x(n))) + \varepsilon $ holds
Remark: If this exception occurs due to the second condition then it is likely that a wrong value of $ V_N(x(n + m)) $ has been computed. In the following MPC step this can be seen from a value $ \alpha > 1 $.
yane::MPC::PracticalExceptionIs thrown if $ \sum\limits_{j = i}^{i + m} l(x_u(j, x(n)), u(j, x(n))) < \varepsilon $
yane::MPC::MPCExceptionIs thrown if an MPC internal error occured
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 or $ N_0 $ is larger than the optimization horizon
yane::Utils::ExceptionIs thrown if any other error occured
LIB_EXPORT void yane::MPC::SuboptimalityMPC::mstepPredictedAposterioriEstimate ( double *  x,
int  m = 1,
int  realtimesteps = 0,
double  aborttimeoffset = 0.0 
) [protected]

Function to compute the suboptimality estimate $ \alpha(N) $ using the methods yane::MPC::SuboptimalityMPC::aposterioriEstimate or yane::MPC::SuboptimalityMPC::aposterioriPracticalEstimate for $ m $ open loop steps
To this end the open-loop problem is artificially shifted forward in time and the resulting value of $ V_N(\cdot) $ is used within the estimate $ \alpha(N) $.
Remark: If the adaptation algorithm is used with the methods yane::MPC::AdaptiveMPC::fixpointProlongation or yane::MPC::AdaptiveMPC::monotoneProlongation then the method yane::MPC::AdaptiveMPC::aposterioriGamma is called to compute $ \gamma(N) $.
Remark: This function doesnot assume the optimal control for the current optimization horizon to be known. However, setting _controlAlreadyOptimal to true will override an additional start of the minimizer.

Parameters:
xEstimate of the initial value of the state
mNumber of open loop steps
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)
Exceptions:
yane::MPC::MPCExceptionIs thrown if the underlying yane::MPC::MPC object terminates with an error
yane::MinProg::SolverWarningIs thrown if the yane::MinProg::NLP object terminates with a warning
yane::Utils::ExceptionIs thrown if any other error occurs
yane::Utils::MemoryExceptionIs thrown if memory allocation failed
LIB_EXPORT yane::MPC::T_OPTIMALITYSTATE yane::MPC::MPC::optimalitystate ( ) [inherited]

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 ( ) [inherited]

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 void yane::MPC::SuboptimalityMPC::predictedAposterioriEstimate ( double *  x,
int  realtimesteps,
double  aborttimeoffset 
) [protected]

Function to compute the suboptimality estimate $ \alpha(N) $ using the methods yane::MPC::SuboptimalityMPC::aposterioriEstimate or yane::MPC::SuboptimalityMPC::aposterioriPracticalEstimate
To this end the open-loop problem is artificially shifted forward in time and the resulting value of $ V_N(\cdot) $ is used within the estimate $ \alpha(N) $.
Remark: If the adaptation algorithm is used with the methods yane::MPC::AdaptiveMPC::fixpointProlongation or yane::MPC::AdaptiveMPC::monotoneProlongation then the method yane::MPC::AdaptiveMPC::aposterioriGamma is called to compute $ \gamma(N) $.
Remark: This function doesnot assume the optimal control for the current optimization horizon to be known. However, setting _controlAlreadyOptimal to true will override an additional start of the minimizer.

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)
Exceptions:
yane::MPC::MPCExceptionIs thrown if the underlying yane::MPC::MPC object terminates with an error
yane::MinProg::SolverWarningIs thrown if the yane::MinProg::NLP object terminates with a warning
yane::Utils::ExceptionIs thrown if any other error occurs
yane::Utils::MemoryExceptionIs thrown if memory allocation failed
LIB_EXPORT yane::MPC::Discretization * yane::MPC::MPC::problem ( ) [inherited]

This function returns the pointer of the discretized optimal control problem

Returns:
Pointer of the discretized optimal control problem
LIB_EXPORT void yane::MPC::SuboptimalityMPC::reset ( OdeManager odemanager,
yane::MinProg::NLP minimizer,
yane::Model::Model model,
int  horizon,
int  precedesteps = 0,
ModelShootingData shootingdata = 0 
) [virtual]

This functions resets the class yane::MPC::SuboptimalityMPC object with new pointers for underlying classes.

Parameters:
odemanagerPointer to used class yane::MPC::OdeManager object
minimizerPointer to used class yane::Minprog2::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::MPC::MPCExceptionIs thrown if an MPC internal error occured

Reimplemented from yane::MPC::MPC.

Reimplemented in yane::MPC::m21MPC.

LIB_EXPORT void yane::MPC::SuboptimalityMPC::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 from yane::MPC::MPC.

Reimplemented in yane::MPC::m21MPC.

LIB_EXPORT double yane::MPC::SuboptimalityMPC::samplingLength ( )
Returns:
Sampling width
LIB_EXPORT void yane::MPC::MPC::setAbortSuboptimalityValues ( double *  x) [protected, inherited]

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, inherited]

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::SuboptimalityMPC::setConfigSuboptimalityMPC ( T_ESTIMATE  estimate,
int  N0 = 2 
)

Function to configure the suboptimality algorithm

Parameters:
estimateDecision variable to define the computing method of the suboptimality degree

  • (0) Standardimplementation without adaptation of the horizon length
  • (1) Adaptation of the horizon length using the a posteriori estimate
  • (2) Adaptation of the horizon length using the a posteriori practical estimate
  • (3) Adaptation of the horizon length using the a priori estimate
  • (4) Adaptation of the horizon length using the a priori practical estimate
N0Parameter for the a priori suboptimality estimate, requires $ N_0 \geq 2 $, default is $ N_0 = 2 $
LIB_EXPORT void yane::MPC::SuboptimalityMPC::setEpsilon ( double  epsilon = 1E-6)

This function sets the radius of the (supposably) practical stability region.

Parameters:
epsilonRadius of the (supposably) practical stability region
LIB_EXPORT void yane::MPC::MPC::setInternalSimulatorPrecision ( double *  rtol,
double *  atol 
) [virtual, inherited]

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::setInternalSimulatorPrecision ( double  rtol,
double  atol 
) [virtual, inherited]

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::SuboptimalityMPC::setNewtonItermax ( int  newtonItermax)
Parameters:
newtonItermaxMaximal number of Newton steps
LIB_EXPORT void yane::MPC::SuboptimalityMPC::setSamplingLength ( double  h_new)

Function to set the sampling width of the new added horizon instances

Parameters:
h_newSampling width
LIB_EXPORT void yane::MPC::MPC::setShowSqpError ( bool  showSqpError) [virtual, inherited]

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::SuboptimalityMPC::setSingle ( bool  single = true)

This function set the decision variable to distinguish between computing local and closed loop suboptimality estimates.

Parameters:
singleDecision variable to distinguish between computing local and closed loop suboptimality estimates
LIB_EXPORT void yane::MPC::SuboptimalityMPC::setStoreValuefunction ( bool  storeValuefunction)

Function to set decision variable to store predicted value function in case an predicted aposteriori estimate is used

Parameters:
storeValuefunctionDecision variable
LIB_EXPORT void yane::MPC::MPC::shiftHorizon ( double *  nextControls,
double *  nextTimesteps,
int  m = 1,
double *  x = 0,
double  h_new = 0.0 
) [virtual, inherited]

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.