HQP  1.9.6
Prg_SFunctionOpt Class Reference

Optimal control problem for a model given as MEX S-function treated with multi-stage control vector parameterization. More...

#include <Prg_SFunctionOpt.h>

Inheritance diagram for Prg_SFunctionOpt:
[legend]

Public Member Functions

 Prg_SFunctionOpt ()
 constructor
 
 ~Prg_SFunctionOpt ()
 destructor
 
const 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_u_integer () const
 indicate integers
 
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 IVECP mdl_u_periodic () const
 first and last value are equal (default: false)
 
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_der_u_soft_min () const
 soft lower bounds for rates of change of optimized model inputs
 
const VECP mdl_der_u_soft_max () const
 soft upper bounds for rates of change of optimized model inputs
 
const VECP mdl_der_u_soft_weight1 () const
 weight for linear objective term (default: 0)
 
const VECP mdl_der_u_soft_weight2 () const
 weight for quadratic objective term (default: 0)
 
const IVECP mdl_x_integer () const
 indicate integer valued states
 
const VECP mdl_x_nominal () const
 nominal state values (for scaling)
 
const IVECP mdl_x_periodic () const
 first and last value are equal (default: false)
 
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_u_integer (const IVECP v)
 set integers
 
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_periodic (const IVECP v)
 set periodic congtrols
 
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_der_u_soft_min (const VECP v)
 set soft lower bounds for rates of change of model inputs
 
void set_mdl_der_u_soft_max (const VECP v)
 set soft upper bounds for rates of change of model inputs
 
void set_mdl_der_u_soft_weight1 (const VECP v)
 set linear weight
 
void set_mdl_der_u_soft_weight2 (const VECP v)
 set quadratic weight
 
void set_mdl_x_integer (const IVECP v)
 set integer valued states
 
void set_mdl_x_nominal (const VECP v)
 set nominal states
 
void set_mdl_x_periodic (const IVECP v)
 set periodic 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
 
- Public Member Functions inherited from Prg_SFunction
 Prg_SFunction ()
 constructor
 
 ~Prg_SFunction ()
 destructor
 
const char * mdl_name () const
 S-function name.
 
void set_mdl_name (const char *str)
 set S-function name
 
const char * mdl_path () const
 S-function path, including name, used for dynamic loading. More...
 
void set_mdl_path (const char *str)
 set S-function path
 
const char * mdl_args () const
 String representation of S-function arguments.
 
void set_mdl_args (const char *str)
 set S-function arguments
 
const VECP mdl_p () const
 parameters
 
void set_mdl_p (const VECP value)
 set parameters
 
const VECP mdl_x0 () const
 initial states
 
void set_mdl_x0 (const VECP value)
 set initial states
 
- Public Member Functions inherited from Omu_Program
 Omu_Program ()
 constructor
 
virtual ~Omu_Program ()
 destructor
 
virtual void update (int kk, const adoublev &x, const adoublev &u, adoublev &f, adouble &f0, adoublev &c)
 High-level update for the optimization criterion, constraints, and discrete state equations.
 
virtual void consistic (int kk, double t, const adoublev &x, const adoublev &u, adoublev &xt)
 High-level consistic (consistent initial conditions) routine for the initialization of continuous-time states from optimization variables x and u. More...
 

Protected Member Functions

Implementation of predefined methods.
See Also
Omu_Program
void setup_model ()
 load S-function
 
void setup_stages (IVECP ks, VECP ts)
 Setup stages and time sampling. More...
 
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. More...
 
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. More...
 
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 Member Functions inherited from Prg_SFunction
void read_mx_args (VECP p)
 read _mx_args into vector p
 
void write_mx_args (VECP p)
 write vector p to _mx_args
 
bool setContinuousTask (bool val)
 enable continuous sample time; return true if a continuous sample time exists and has been enabled
 
bool setSampleHit (bool val)
 enable hit for all discrete sample times; return true if a discrete sample time exists and has been enabled
 

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_OptVarVec _mdl_der_u_soft
 relaxed 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 _nsu
 number of slack variables for soft cns on inputs
 
int _nsuc
 number of soft constraints on inputs
 
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). More...
 
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). More...
 
IVECP _mdl_u_decimation
 Decimation factor, i.e. More...
 
IVECP _mdl_u_periodic
 Periodic controls, i.e. More...
 
IVECP _mdl_x_periodic
 Periodic states, i.e. More...
 
- Protected Attributes inherited from Prg_SFunction
char * _mdl_name
 S-function name.
 
char * _mdl_path
 full S-function path
 
char * _mdl_args
 S-function parameters.
 
SimStruct * _SS
 pointer to SimStruct
 
mxArray ** _mx_args
 S-function parameters after parsing.
 
int _mdl_nargs
 number of S-function arguments
 
double _t0_setup_model
 time used for initialization of model
 
int _mdl_np
 number of model parameters
 
int _mdl_nd
 number of discrete-time states
 
int _mdl_nx
 number of model states (incl. discrete)
 
int _mdl_nu
 number of model inputs
 
int _mdl_ny
 number of model outputs
 
VECP _mdl_p
 parameters
 
VECP _mdl_x0
 initial states
 
bool _mdl_needs_setup
 indicate that setup_model needs to be called as _mdl_name, _mdl_path, or _mdl_args changed
 

Detailed Description

Optimal control problem for a model given as MEX S-function treated with multi-stage control vector parameterization.

The optimization time horizon \([t_0,t_f]\) is split into \(k=0,...,K\) stages with time points \(t_0=t^0<t^1<\ldots<t^K=t_f\). Each stage may be further subdivided into \(sps\) sample periods per stage. This leads to the overall number of \(KK=sps\,K\) sample periods with the sample time points \(t^{kk}, kk=0,...,KK\) (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

\[ \begin{array}{l} \displaystyle J\ =\ \sum_{i=1}^{n_y} \left\{ y_{0\_weight1}\left[y(t_0)-\frac{y_{ref}}{y_{nominal}}\right] \ +\ y_{0\_weight2}\left[y(t_0)-\frac{y_{ref}}{y_{nominal}}\right]^2 \right\}_i \\[4ex] \displaystyle \qquad \ + \ \sum_{kk=0}^{KK} \sum_{i=1}^{n_u} \Delta t_{u,i}^{kk} \left\{ u_{weight1}\left[u(t^{kk})-\frac{u_{ref}}{u_{nominal}}\right] \ +\ u_{weight2}\left[u(t^{kk})-\frac{u_{ref}}{u_{nominal}}\right]^2 \right\}_i \\[4ex] \displaystyle \qquad \ + \ \sum_{k=0}^{K-1} (t^{k+1}-t^{k}) \sum_{i=1}^{n_u} \left\{ {der\_u}_{weight1}\left[du^k -\frac{{der\_u}_{ref}}{u_{nominal}}\right] \ +\ {der\_u}_{weight2}\left[du^k -\frac{{der\_u}_{ref}}{u_{nominal}}\right]^2 \right\}_i \\[4ex] \displaystyle \qquad \ + \ \sum_{kk=0}^{KK} \Delta t^{kk} \sum_{i=1}^{n_y} \left\{ y_{weight1}\left[y(t^{kk})-\frac{y_{ref}}{y_{nominal}}\right] \ +\ y_{weight2}\left[y(t^{kk})-\frac{y_{ref}}{y_{nominal}}\right]^2 \right\}_i \\[4ex] \displaystyle \qquad \ + \ \sum_{i=1}^{n_y} \left\{ y_{f\_weight1}\left[y(t_f)-\frac{y_{ref}}{y_{nominal}}\right] \ +\ y_{f\_weight2}\left[y(t_f)-\frac{y_{ref}}{y_{nominal}}\right]^2 \right\}_i \\[4ex] \displaystyle \qquad \ + \ \sum_{kk=0}^{KK} \Delta t^{kk} \sum_{i=1}^{n_y} \left\{ y_{soft\_weight1}\,s^{kk} + y_{soft\_weight2}\,s^{kk}s^{kk} \right\}_i \\[4ex] \displaystyle \qquad \ + \ \sum_{i=1}^{n_y} \left\{ y_{f\_soft\_weight1}\,s_f + y_{f\_soft\_weight2}\,s_fs_f \right\}_i \\[4ex] \displaystyle \qquad \ \to\quad \min \end{array} \]

with

\[ \begin{array}{l} \displaystyle \Delta t_{u,i}^{kk} = \left\{\begin{array}{ll} t_{scale}^{kk+1}(t^{kk+1} - t^{kk}), & u_{order,i} = 0 \ \ \mbox{and}\ \ kk < KK, \\[1ex] 0, & u_{order,i} = 0 \ \ \mbox{and}\ \ kk = KK, \\[1ex] \Delta t^{kk}, & u_{order,i} = 1, \end{array}\right. \\[5ex] \displaystyle \Delta t^{kk} = \frac{1}{2} \left\{\begin{array}{ll} t_{scale}^{kk+1}(t^{kk+1} - t^{kk}), & kk=0, \\[1ex] t_{scale}^{kk}(t^{kk} - t^{kk-1}), & kk=KK, \\[1ex] t_{scale}^{kk+1}(t^{kk+1} - t^{kk}) + t_{scale}^{kk}(t^{kk} - t^{kk-1}), & \mbox{else}, \end{array}\right. \\[5ex] \displaystyle t_{scale} = \left\{\begin{array}{ll} u_{t\_scale\_idx}, & t\_scale\_idx \ge 0, \\ 1, & \mbox{else}, \end{array}\right. \end{array} \]

subject to the model given with the S-function methods mdlDerivatives \(f\), mdlOutputs \(g\) and mdlUpdate \(h,\ t\in[t_0,t_f]\), as well as with parameterized time \(\tau\)

\[ \begin{array}{l} \displaystyle \quad\ \frac{d\tau(t)}{dt} = t_{scale}(t), \\[3ex] \displaystyle x(\tau(t)) = \left[\begin{array}{ll} x_d^{kk}, & t\in[t^{kk},t^{kk+1}),\ kk=0,\ldots,KK \\ x_c(\tau(t)) \end{array}\right], \\[3ex] \displaystyle x_d^{kk} = \frac{h[x_{nominal}\,x(\tau(t^-)),\ u_{nominal}\,u(\tau(t^-))]} {x_{nominal_d}},\quad t=t^{kk},\ kk=1,\ldots,KK,\\[3ex] \displaystyle \frac{dx_c(\tau(t))}{d\tau(t)} = \frac{f[x_{nominal}\,x(\tau(t)),\ u_{nominal}\,u(\tau(t))]} {x_{nominal_c}}, \\[3ex] \displaystyle y(\tau(t)) = \frac{g[x_{nominal}\,x(\tau(t)),\ u_{nominal}\,u(\tau(t))]}{y_{nominal}} \ +\ \frac{y_{bias}}{y_{nominal}}, \end{array} \]

with piecewise constant or linear approximation of \(u(t)\) either using optimized control parameters \(du^k\) or given inputs \(us\)

\[ \begin{array}{ll} \left\{ u(t) = u(t^{k-1}) + \Delta u(t^{k-1}) \right\}_i, & i \in \mbox{find}(u_{active}\ \mbox{and}\ u_{order}=0), \\[1ex] & t\in[t^{k},t^{k+1}),\ k=1,\ldots,K-1, \\[1ex] \ \ \Delta u(t^{k-1}) = \left\{\begin{array}{ll} (t^{k}-t^{k-1})du^{k-1}, & i = t\_scale\_idx \\[1ex] (t^{k}-t^{k-1})du^{k-1}t_{scale}^k, & \mbox{else} \end{array}\right. & k=1,\ldots,K-1, \\[3ex] \left\{ \frac{du(\tau(t))}{d\tau(t)} = du^{k} \right\}_i, & i \in \mbox{find}(u_{active}\ \mbox{and}\ u_{order}=1), \\[1ex] & t\in[t^{k},t^{k+1}),\ k=0,\ldots,K-1, \\[3ex] \left\{ u(t) = \displaystyle \frac{us^{kk}}{u_{nominal}} \right\}_i, & i \in \mbox{find}(\mbox{not}\ u_{active}\ \mbox{and}\ u_{order}=0),\\[3ex] \left\{ u(t) = \displaystyle \frac{t^{kk+1}-t}{t^{kk+1}-t^{kk}}\ \frac{us^{kk}}{u_{nominal}} + \frac{t-t^{kk}}{t^{kk+1}-t^{kk}} \ \frac{us^{kk+1}}{u_{nominal}} \right\}_i, & i \in \mbox{find}(\mbox{not}\ u_{active}\ \mbox{and}\ u_{order}=1), \\[3ex] & t\in[t^{kk},t^{kk+1}),\ kk=0,\ldots,KK-1, \end{array} \]

and subject to the constraints at initial and final time

\[ \begin{array}{rcccll} \displaystyle && \{ x(t^0) &=& \displaystyle \frac{x^0}{x_{nominal}}\}_i, \quad & i\notin\mbox{find}(x_{0\_active}), \\[3ex] \displaystyle \left\{ \frac{x^0_{min}}{x_{nominal}} \right. &\le& x(t^{0}) &\le& \displaystyle \left. \frac{x^0_{max}}{x_{nominal}} \right\}_i, \quad & i\in\mbox{find}(x_{0\_active}), \\[3ex] \displaystyle \left\{ \frac{der\_x^0_{min}}{x_{nominal}} \right. &\le& \dot{x}(t^{0}) &\le& \displaystyle \left. \frac{der\_x^0_{max}}{x_{nominal}} \right\}_i, \quad & i\in\mbox{find}(x_{0\_active}), \\[3ex] \displaystyle \left\{ \frac{u^0_{min}}{u_{nominal}} \right. &\le& u(t^{0}) &\le& \displaystyle \left. \frac{u^0_{max}}{u_{nominal}} \right\}_i, \quad & i\in\mbox{find}(u_{active}\ \mbox{and}\ u_{0,nfixed}=0), \\[3ex] \displaystyle && \{ u(t^0) &=& \displaystyle \frac{us^0}{u_{nominal}} \}_i, \quad & i \in \mbox{find}(u_{0,nfixed}>1-u_{order}), \\[3ex] \displaystyle\left\{\frac{us^0+der\_u_{min}}{u_{nominal}}\right. &\le& u(t^0) &\le& \displaystyle\left.\frac{us^0+der\_u_{max}}{u_{nominal}}\right\}_i, \ & i \in \mbox{find}(u_{0,nfixed}=1\ \mbox{and}\ u_{order}=0), \\[3ex] \displaystyle \frac{y_{0,min}}{y_{nominal}} &\le& y(t^{0}) &\le& \displaystyle \frac{y_{0,max}}{y_{nominal}}, \\[3ex] \displaystyle \frac{u_{f\_min}}{u_{nominal}} &\le& u(t_f) &\le& \displaystyle \frac{u_{f\_max}}{u_{nominal}}, \\[3ex] \displaystyle \frac{y_{f\_min}}{y_{nominal}} &\le& y(t_f) &\le& \displaystyle \frac{y_{f\_max}}{y_{nominal}}, \\[3ex] \displaystyle \frac{y_{f\_soft\_min}}{y_{nominal}} - s_f &\le& y(t_f) &\le& \displaystyle \frac{y_{f\_soft\_max}}{y_{nominal}} + s_f, \\[3ex] \displaystyle && s_f &\ge& 0, \end{array} \]

as well as at all time points

\[ \begin{array}{rcccll} \displaystyle\left\{ \frac{u_{min}}{u_{nominal}} \right. &\le& u(t^{k}) &\le& \displaystyle\left. \frac{u_{max}}{u_{nominal}} \right\}_i, \quad & i \in \mbox{find}(k \ge u_{0,nfixed} + u_{order} - 1), \\[1ex] && && & k=0,\ldots,K, \\[2ex] \displaystyle \frac{{der\_u}_{min}}{u_{nominal}} &\le& du^{k} &\le& \displaystyle \frac{{der\_u}_{max}}{u_{nominal}}, \quad & k=0,\ldots,K-1, \\[3ex] \displaystyle \frac{x_{min}}{x_{nominal}} &\le& x(t^{k}) &\le& \displaystyle \frac{x_{max}}{x_{nominal}}, \quad & k=0,\ldots,K, \\[3ex] \displaystyle \frac{y_{min}}{y_{nominal}} &\le& y(t^{kk}) &\le& \displaystyle \displaystyle \frac{y_{max}}{y_{nominal}}, \quad & kk=0,\ldots,KK, \\[3ex] \displaystyle \frac{y_{soft\_min}}{y_{nominal}} - s^{kk} &\le& y(t^{kk}) &\le& \displaystyle \frac{y_{soft\_max}}{y_{nominal}} + s^{kk}, \\[3ex] \displaystyle && s^{kk} &\ge& 0, \quad & kk=0,\ldots,KK. \end{array} \]

Note that path constraints over continuous time intervals can be approximated by specifying \(sps>1\), leading to output constraints at interior sample time points.

The actually optimized rates of changes \(du^k, k=0,\ldots,K-1\) for active inputs may be set to fixed values by specifying \(u_{0,nfixed}\) and \(u_{decimation}\) (defaults: 1), fixing initial values and holding optimized inputs constant over multiple stages, respectively

\[ du^k_i = \left\{\begin{array}{ll} \displaystyle 0 , \quad & i \in \mbox{find}(\mbox{mod}(k+1, u_{decimation}) \ne 0), \\[2ex] \displaystyle du^k_{initial,i}, \quad & i \in \mbox{find}(\mbox{mod}(k+1, u_{decimation}) = 0\ \mbox{and}\ k < u_{0,nfixed}+u_{order}-2), \\[2ex] \displaystyle \mbox{free} , \quad & \mbox{else}. \end{array}\right. \]

The initial guess is taken from given initial states and model inputs

\[ \begin{array}{rcll} x_{initial}(t^0) &=& \displaystyle \frac{x^0}{x_{nominal}}, \\[3ex] u_{initial}(t^0) &=& \displaystyle \frac{us^0}{u_{nominal}}, \\[3ex] du^k_{initial} &=& \displaystyle \left\{\frac{us^{sps\,(k+1)} - us^{sps\,k}} {(t^{sps\,(k+1)}-t^{sps\,k})\,u_{nominal}} \right\}_i, & i \in \mbox{find}(u_{active}), \\[1ex] &&& k=0,\ldots,K-1. \end{array} \]

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 \(x^0\)

\[ \begin{array}{rcll} x_{initial}(t^k) &=& \displaystyle \frac{x^0}{x_{nominal}}, & k=1,\ldots,K \end{array} \]

or with an explicitly given initial guess for states \(xs\) in all stages

\[ \begin{array}{rcll} x_{initial}(t^k) &=& \displaystyle \frac{xs^{sps\,k}}{x_{nominal}}, & k=1,\ldots,K. \end{array} \]

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

\[ \begin{array}{l} us^{kk} = u_{nominal}\,u(t^{kk}), \\[1ex] xs^{kk} = x_{nominal}\,x(t^{kk}), \\[1ex] ys^{kk} = y_{nominal}\,y(t^{kk}), \quad kk=0,\ldots,KK. \end{array} \]

Member Function Documentation

void Prg_SFunctionOpt::init_simulation ( int  k,
Omu_VariableVec x,
Omu_VariableVec u 
)
protectedvirtual

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.

void Prg_SFunctionOpt::setup ( int  k,
Omu_VariableVec x,
Omu_VariableVec u,
Omu_VariableVec c 
)
protectedvirtual

Allocate states x, control parameters u, and constraints c for stage k.

Additionally setup bounds and initial values.

Implements Omu_Program.

void Prg_SFunctionOpt::setup_stages ( IVECP  ks,
VECP  ts 
)
protectedvirtual

Setup stages and time sampling.

The default implementation sets up an optimization problem without stages.

Reimplemented from Omu_Program.

Member Data Documentation

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().

IVECP Prg_SFunctionOpt::_mdl_u_periodic
protected

Periodic controls, i.e.

~first and last value are equal

Referenced by mdl_u_periodic(), and set_mdl_u_periodic().

IVECP Prg_SFunctionOpt::_mdl_x_periodic
protected

Periodic states, i.e.

~first and last value are equal

Referenced by mdl_x_periodic(), and set_mdl_x_periodic().

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.


The documentation for this class was generated from the following file: