opt_x¶

Class attribute.

MPC.opt_x

Full structure of (symbolic) MPC optimization variables.

The attribute is a CasADi symbolic structure with nested power indices. It can be indexed as follows:

# dynamic states:
opt_x['_x', time_step, scenario, collocation_point, _x_name]
# algebraic states:
opt_x['_z', time_step, scenario, collocation_point, _z_name]
# inputs:
opt_x['_u', time_step, scenario, _u_name]
# slack variables for soft constraints:
opt_x['_eps', time_step, scenario, _nl_cons_name]


The names refer to those given in the do_mpc.model.Model configuration. Further indices are possible, if the variables are itself vectors or matrices.

The attribute can be used to alter the objective function or constraints of the NLP.

How to query?

Querying the structure is more complicated than it seems at first look because of the scenario-tree used for robust MPC. To obtain all collocation points for the finite element at time-step $$k$$ and scenario $$b$$ use:

horzcat(*[mpc.opt_x['_x',k,b,-1]]+mpc.opt_x['_x',k+1,b,:-1])


Due to the multi-stage formulation at any given time $$k$$ we can have multiple future scenarios. However, there is only exactly one scenario that lead to the current node in the tree. Thus the collocation points associated to the finite element $$k$$ lie in the past.

The concept is illustrated in the figure below:

Note

The attribute opt_x carries the scaled values of all variables.

Note

The attribute is populated when calling setup() or prepare_nlp()