#include <Prg_SFunctionOpt.h>


The optimization time horizon
is split into
stages with time points
. Each stage may be further subdivided into
sample periods per stage. This leads to the overall number of
sample periods with the sample time points
(sample time points within a stage are for instance useful to better treat path constraints). The model time may be parameterized by defining a piecewise constant model input as scaling factor. Sought control trajectories are described piecewise as constant or linear functions of control parameters in each stage.
In the following all vector operations are defined element wise. The treated optimization problem reads
with
subject to the model given with the S-function methods mdlDerivatives
and mdlOutputs
and with parameterized time
with piecewise constant or linear approximation of
either using optimized control parameters
or given inputs
and subject to the constraints at initial and final time
as well as at all time points
Note that path constraints over continuous time intervals can be approximated by specifying
, leading to output constraints at interior sample time points.
The actually optimized rates of changes
for active inputs may be set to fixed values by specifying
and
(defaults: 1), fixing initial values and holding optimized inputs constant over multiple stages, respectively
The initial guess is taken from given initial states and model inputs
The problem is treated as multistage problem with K stages per default. Consequently additional K junction conditions (equality constraints) are introduced for the state variables x and the control trajectories u. Alternatively the problem can be treated without stages applying pure control vector parameterization and hiding model states from the optimizer.
When treated as multistage problem, the additional optimization variables introduced for states are normally initialized with the results of an initial-value simulation for the given initial states and inputs (multistage=1). Alternatively, with multistage=2, the multistage problem may be treated with multiple shooting, i.e. all states are initialized with the initial states
or with an explicitly given initial guess for states
in all stages
The multiple shooting method is advantageous if the expected state trajectories are known (e.g. constant at a set point or following a ramp), but if an initial guess for the control trajectories causing those state trajectories is unknown.
Model inputs, states and outputs can be accessed through
Public Member Functions | |
| Prg_SFunctionOpt () | |
| constructor | |
| ~Prg_SFunctionOpt () | |
| destructor | |
| char * | name () |
| name SFunctionOpt | |
Access methods for program specific members (If prefix: prg_) | |
| int | multistage () const |
| indicate if problem is treated with one stage per time interval | |
| void | set_multistage (int val) |
| set multistage flag | |
Access methods for scaling of time | |
| int | mdl_t_scale_idx () const |
| optional index of a model input used for scaling of time (default: -1) | |
| void | set_mdl_t_scale_idx (int val) |
| set index of model input used for scaling of time | |
| const VECP | taus () const |
| vector of start time points in each sample period | |
| void | set_taus (const VECP n_taus) |
| set vector of start times | |
Read methods for model specific members (no If prefix). | |
Note that the prefix mdl_ is omitted in the detailed mathematical problem description. | |
| const VECP | mdl_x0 () const |
| initial states | |
| const IVECP | mdl_x0_active () const |
| free initial states (default: 0) | |
| const VECP | mdl_x0_min () const |
| lower bounds for initial states | |
| const VECP | mdl_x0_max () const |
| upper bounds for initial states | |
| const VECP | mdl_der_x0_min () const |
| minimum for time derivative of x0 | |
| const VECP | mdl_der_x0_max () const |
| maximum for time derivative of x0 | |
| const VECP | mdl_u0 () const |
| model inputs at initial time | |
| const VECP | mdl_u0_min () const |
| lower bounds for model inputs at initial time | |
| const VECP | mdl_u0_max () const |
| upper bounds for model inputs at initial time | |
| const VECP | mdl_y0 () const |
| model outputs at initial time | |
| const VECP | mdl_y0_min () const |
| lower bounds for model outputs at initial time | |
| const VECP | mdl_y0_max () const |
| upper bounds for model outputs at initial time | |
| const VECP | mdl_y0_weight1 () const |
| weight for linear objective term at initial time (default: 0) | |
| const VECP | mdl_y0_weight2 () const |
| weight for quadratic objective term at initial time (default: 0) | |
| const IVECP | mdl_u_order () const |
| interpolation order (0 (constant) or 1 (linear), default: 1) | |
| const IVECP | mdl_u_active () const |
| indicate optimized inputs | |
| const IVECP | mdl_u0_nfixed () const |
| numbers of fixed control inputs at begin of time horizon (default: 1) | |
| const IVECP | mdl_u_decimation () const |
| decimation for optimized model inputs (default: 1) | |
| const VECP | mdl_u_nominal () const |
| nominal input values (for scaling) | |
| const VECP | mdl_u_min () const |
| lower bounds for optimized model inputs | |
| const VECP | mdl_u_max () const |
| upper bounds for optimized model inputs | |
| const VECP | mdl_u_ref () const |
| reference values for optimized model inputs (default: 0) | |
| const VECP | mdl_u_weight1 () const |
| weight for linear objective term (default: 0) | |
| const VECP | mdl_u_weight2 () const |
| weight for quadratic objective term (default: 0) | |
| const VECP | mdl_der_u_min () const |
| lower bounds for rates of change of optimized model inputs | |
| const VECP | mdl_der_u_max () const |
| upper bounds for rates of change of optimized model inputs | |
| const VECP | mdl_der_u_ref () const |
| reference values for rates of change of optimized inputs (default: 0) | |
| const VECP | mdl_der_u_weight1 () const |
| weight for linear objective term (default: 0) | |
| const VECP | mdl_der_u_weight2 () const |
| weight for quadratic objective term (default: 0) | |
| const VECP | mdl_x_nominal () const |
| nominal state values (for scaling) | |
| const VECP | mdl_x_min () const |
| lower bounds on states at stage boundaries (default: -Inf) | |
| const VECP | mdl_x_max () const |
| upper bounds on states at stage boundaries (default: Inf) | |
| const VECP | mdl_y_bias () const |
| bias for outputs | |
| const VECP | mdl_y_nominal () const |
| nominal output values (for scaling) | |
| const VECP | mdl_y_min () const |
| lower bounds for model outputs | |
| const VECP | mdl_y_max () const |
| upper bounds for model outputs | |
| const VECP | mdl_y_ref () const |
| reference values for model outputs (default: 0) | |
| const VECP | mdl_y_weight1 () const |
| weight for linear objective term (default: 0) | |
| const VECP | mdl_y_weight2 () const |
| weight for quadratic objective term (default: 0) | |
| const VECP | mdl_y_soft_min () const |
| soft lower bounds for model outputs | |
| const VECP | mdl_y_soft_max () const |
| soft upper bounds for model outputs | |
| const VECP | mdl_y_soft_weight1 () const |
| weight for linear objective term (default: 0) | |
| const VECP | mdl_y_soft_weight2 () const |
| weight for quadratic objective term (default: 0) | |
| const VECP | mdl_uf () const |
| model inputs at final time | |
| const VECP | mdl_uf_min () const |
| lower bounds for model inputs at final time | |
| const VECP | mdl_uf_max () const |
| upper bounds for model inputs at final time | |
| const VECP | mdl_yf () const |
| model outputs at final time | |
| const VECP | mdl_yf_min () const |
| lower bounds for model outputs at final time | |
| const VECP | mdl_yf_max () const |
| upper bounds for model outputs at final time | |
| const VECP | mdl_yf_weight1 () const |
| weight for linear objective term (default: 0) | |
| const VECP | mdl_yf_weight2 () const |
| weight for quadratic objective term (default: 0) | |
| const VECP | mdl_yf_soft_min () const |
| soft lower bounds for model outputs at final time | |
| const VECP | mdl_yf_soft_max () const |
| soft upper bounds for model outputs at final time | |
| const VECP | mdl_yf_soft_weight1 () const |
| weight for linear objective term (default: 0) | |
| const VECP | mdl_yf_soft_weight2 () const |
| weight for quadratic objective term (default: 0) | |
| const MATP | mdl_us () const |
| model inputs (size: KK+1 . mdl_nu) | |
| const MATP | mdl_xs () const |
| model states (size: KK+1 . mdl_nx) | |
| const MATP | mdl_ys () const |
| model outputs (read only, size: KK+1 . mdl_ny) | |
Write methods for model specific members (no If prefix). | |
| void | set_mdl_x0 (const VECP v) |
| set initial states and copy them to all mdl_xs | |
| void | set_mdl_x0_active (const IVECP v) |
| set free initial states | |
| void | set_mdl_x0_min (const VECP v) |
| set lower bounds for initial states | |
| void | set_mdl_x0_max (const VECP v) |
| set upper bounds for initial states | |
| void | set_mdl_der_x0_min (const VECP v) |
| set minimum for dx0dt | |
| void | set_mdl_der_x0_max (const VECP v) |
| set maximum for dx0dt | |
| void | set_mdl_u0 (const VECP v) |
| set initial values for model inputs and copy them to all mdl_us | |
| void | set_mdl_u0_min (const VECP v) |
| set lower bounds for initial model inputs | |
| void | set_mdl_u0_max (const VECP v) |
| set upper bounds for initial model inputs | |
| void | set_mdl_y0_min (const VECP v) |
| set lower bounds for initial model outputs | |
| void | set_mdl_y0_max (const VECP v) |
| set upper bounds for initial model outputs | |
| void | set_mdl_y0_weight1 (const VECP v) |
| set linear weight | |
| void | set_mdl_y0_weight2 (const VECP v) |
| set quadratic weight | |
| void | set_mdl_u_order (const IVECP v) |
| set interpolation order | |
| void | set_mdl_u_active (const IVECP v) |
| set optimized inputs | |
| void | set_mdl_u0_nfixed (const IVECP v) |
| set numbers of fixed control inputs | |
| void | set_mdl_u_decimation (const IVECP v) |
| set decimation for optimized model inputs | |
| void | set_mdl_u_nominal (const VECP v) |
| set nominal inputs | |
| void | set_mdl_u_min (const VECP v) |
| set lower bounds for model inputs | |
| void | set_mdl_u_max (const VECP v) |
| set upper bounds for model inputs | |
| void | set_mdl_u_ref (const VECP v) |
| set reference model inputs | |
| void | set_mdl_u_weight1 (const VECP v) |
| set linear weight | |
| void | set_mdl_u_weight2 (const VECP v) |
| set quadratic weight | |
| void | set_mdl_der_u_min (const VECP v) |
| set lower bounds for rates of change of model inputs | |
| void | set_mdl_der_u_max (const VECP v) |
| set upper bounds for rates of change of model inputs | |
| void | set_mdl_der_u_ref (const VECP v) |
| set reference rates of change of model inputs | |
| void | set_mdl_der_u_weight1 (const VECP v) |
| set linear weight | |
| void | set_mdl_der_u_weight2 (const VECP v) |
| set quadratic weight | |
| void | set_mdl_x_nominal (const VECP v) |
| set nominal states | |
| void | set_mdl_x_min (const VECP v) |
| set lower bounds on states | |
| void | set_mdl_x_max (const VECP v) |
| set upper bounds on states | |
| void | set_mdl_y_bias (const VECP v) |
| set output bias | |
| void | set_mdl_y_nominal (const VECP v) |
| set nominal outputs | |
| void | set_mdl_y_min (const VECP v) |
| set lower bounds for model outputs | |
| void | set_mdl_y_max (const VECP v) |
| set upper bounds for model outputs | |
| void | set_mdl_y_ref (const VECP v) |
| set reference model outputs | |
| void | set_mdl_y_weight1 (const VECP v) |
| set linear weight | |
| void | set_mdl_y_weight2 (const VECP v) |
| set quadratic weight | |
| void | set_mdl_y_soft_min (const VECP v) |
| set soft lower bounds for model outputs | |
| void | set_mdl_y_soft_max (const VECP v) |
| set soft upper bounds for model outputs | |
| void | set_mdl_y_soft_weight1 (const VECP v) |
| set linear weight | |
| void | set_mdl_y_soft_weight2 (const VECP v) |
| set quadratic weight | |
| void | set_mdl_uf_min (const VECP v) |
| set lower bounds for final model inputs | |
| void | set_mdl_uf_max (const VECP v) |
| set upper bounds for final model inputs | |
| void | set_mdl_yf_min (const VECP v) |
| set lower bounds for final model outputs | |
| void | set_mdl_yf_max (const VECP v) |
| set upper bounds for final model outputs | |
| void | set_mdl_yf_weight1 (const VECP v) |
| set linear weight | |
| void | set_mdl_yf_weight2 (const VECP v) |
| set quadratic weight | |
| void | set_mdl_yf_soft_min (const VECP v) |
| set soft lower bounds for model outputs at final time | |
| void | set_mdl_yf_soft_max (const VECP v) |
| set soft upper bounds for model outputs at final time | |
| void | set_mdl_yf_soft_weight1 (const VECP v) |
| set linear weight | |
| void | set_mdl_yf_soft_weight2 (const VECP v) |
| set quadratic weight | |
| void | set_mdl_us (const MATP v) |
| set model inputs | |
| void | set_mdl_xs (const MATP v) |
| set model states | |
Protected Member Functions | |
Implementation of predefined methods. | |
| void | setup_model () |
| load S-function | |
| void | setup_stages (IVECP ks, VECP ts) |
| Setup stages and time sampling. | |
| void | setup (int k, Omu_VariableVec &x, Omu_VariableVec &u, Omu_VariableVec &c) |
| Allocate states x, control parameters u, and constraints c for stage k. | |
| void | setup_struct (int k, const Omu_VariableVec &x, const Omu_VariableVec &u, Omu_DependentVec &xt, Omu_DependentVec &F, Omu_DependentVec &f, Omu_Dependent &f0, Omu_DependentVec &c) |
| void | init_simulation (int k, Omu_VariableVec &x, Omu_VariableVec &u) |
| Initialize problem variables using simulation. | |
| void | update (int kk, const Omu_StateVec &x, const Omu_Vec &u, const Omu_StateVec &xf, Omu_DependentVec &f, Omu_Dependent &f0, Omu_DependentVec &c) |
| void | consistic (int kk, double t, const Omu_StateVec &x, const Omu_Vec &u, Omu_DependentVec &xt) |
| void | continuous (int kk, double t, const Omu_StateVec &x, const Omu_Vec &u, const Omu_StateVec &dx, Omu_DependentVec &F) |
Overloaded gradient routines | |
These routines call the S-function method mdlJacobian if available; otherwise they direct calls to the according methods by Omu_Program. | |
| void | update_grds (int kk, const Omu_StateVec &x, const Omu_Vec &u, const Omu_StateVec &xf, Omu_DependentVec &f, Omu_Dependent &f0, Omu_DependentVec &c) |
| Overloaded update routine for obtaining gradients. | |
| void | continuous_grds (int kk, double t, const Omu_StateVec &x, const Omu_Vec &u, const Omu_StateVec &dx, Omu_DependentVec &F) |
| Overloaded continuous routine for obtaining gradients. | |
Protected Attributes | |
| Omu_VariableVec | _mdl_x0 |
| initial states for optimization | |
| IVECP | _mdl_x0_active |
| free initial states (default: 0) | |
| VECP | _mdl_der_x0_min |
| minimum for time derivative of x0 | |
| VECP | _mdl_der_x0_max |
| maximum for time derivative of x0 | |
| Omu_VariableVec | _mdl_u0 |
| initial inputs | |
| Omu_OptVarVec | _mdl_y0 |
| model outputs at initial time | |
| Omu_OptVarVec | _mdl_u |
| model inputs | |
| Omu_OptVarVec | _mdl_der_u |
| rates of change of inputs | |
| Omu_VariableVec | _mdl_x |
| state bounds | |
| Omu_OptVarVec | _mdl_y |
| model outputs | |
| Omu_OptVarVec | _mdl_y_soft |
| attributes for relaxed output constraints | |
| Omu_OptVarVec | _mdl_uf |
| model inputs at final time | |
| Omu_OptVarVec | _mdl_yf |
| model outputs at final time | |
| Omu_OptVarVec | _mdl_yf_soft |
| relaxed output constraints at final time | |
| IVECP | _mdl_u_order |
| interpolation order (default: 1 (linear)) | |
| VECP | _taus |
| scaled time communicated to outside as prg_ts | |
| int | _t_scale_idx |
| index into mdl_u vector for variable used for scaling of time | |
| int | _t_active |
| time is being scaled | |
| int | _t_scale_i |
| index of internal optimization variable for scaling of time | |
| double | _t_scale_nominal |
| nominal value for time scaling (default: 1) | |
| double | _t_nominal |
| nominal time (used internally for scaling) | |
| VECP | _mdl_u_nominal |
| nominal inputs (for scaling) | |
| VECP | _mdl_x_nominal |
| nominal states (for scaling) | |
| VECP | _mdl_y_nominal |
| nominal outputs (for scaling) | |
| VECP | _mdl_y_bias |
| bias correction (offset) for outputs | |
| int | _nx |
| number of states for optimizer | |
| int | _nu |
| number of optimized control inputs | |
| int | _nc |
| number of constrained outputs | |
| int | _nc0 |
| number of constrained/used outputs at initial time | |
| int | _ncf |
| number of constrained/used outputs at final time | |
| int | _ns |
| number of slack variables for soft constraints | |
| int | _nsc |
| number of soft constraints | |
| int | _nsf |
| number of slacks for soft constraints at final time | |
| int | _nscf |
| number of soft constraints at final time | |
| int | _multistage |
| treat as multistage problem | |
| int | _sps |
| Number of sample periods per stage (default: 1). | |
| MATP | _mdl_us |
| given model inputs (controls and disturbances) | |
| MATP | _mdl_xs |
| given and calculated model states | |
| MATP | _mdl_ys |
| calculated model outputs | |
| IVECP | _mdl_u0_nfixed |
| Numbers of fixed control inputs at begin of time horizon (default: 0). | |
| IVECP | _mdl_u_decimation |
| Decimation factor, i.e. | |
Setup stages and time sampling.
The default implementation sets up an optimization problem without stages.
Reimplemented from Omu_Program.
| void Prg_SFunctionOpt::setup | ( | int | k, | |
| Omu_VariableVec & | x, | |||
| Omu_VariableVec & | u, | |||
| Omu_VariableVec & | c | |||
| ) | [protected, virtual] |
Allocate states x, control parameters u, and constraints c for stage k.
Additionally setup bounds and initial values.
Implements Omu_Program.
| void Prg_SFunctionOpt::init_simulation | ( | int | k, | |
| Omu_VariableVec & | x, | |||
| Omu_VariableVec & | u | |||
| ) | [protected, virtual] |
Initialize problem variables using simulation.
A problem specification may set state variables x and/or control parameters u prior to the evaluation of stage k. The default version causes an initial value simulation based on initial values given in setup.
Reimplemented from Omu_Program.
int Prg_SFunctionOpt::_sps [protected] |
Number of sample periods per stage (default: 1).
The value can be increased to devide each control interval into multiple sample periods, e.g. for evaluating constraints and the objective within control intervals. Currently _sps>1 is only supported for multistage problems.
IVECP Prg_SFunctionOpt::_mdl_u0_nfixed [protected] |
Numbers of fixed control inputs at begin of time horizon (default: 0).
An active input is free for _mdl_u0_fixed=0, fixed at the initial time point for _mdl_u0_nfixed=1, fixed up to the last time point of the first stage for _mdl_u0_nfixed=2, and so on.
Referenced by mdl_u0_nfixed(), and set_mdl_u0_nfixed().
IVECP Prg_SFunctionOpt::_mdl_u_decimation [protected] |
Decimation factor, i.e.
~numbers of subsequent optimized inputs with equal values (default: 1). The controls of two subsequent stages are equal for decimation=2, three for decimation=3, and so on.
Referenced by mdl_u_decimation(), and set_mdl_u_decimation().
.