# get_p_template¶

Class method.

do_mpc.controller.MPC.get_p_template(self, n_combinations)

Obtain output template for set_p_fun().

Low level API method to set user defined scenarios for robust multi-stage MPC by defining an arbitrary number of combinations for the parameters defined in the model. For more details on robust multi-stage MPC please read our background article.

The method returns a structured object which is initialized with all zeros. Use this object to define values of the parameters for an arbitrary number of scenarios (defined by n_combinations).

This structure (with numerical values) should be used as the output of the p_fun function which is set to the class with set_p_fun().

Use the combination of get_p_template() and set_p_template() as a more adaptable alternative to set_uncertainty_values().

Note

We advice less experienced users to use set_uncertainty_values() as an alterntive way to configure the scenario-tree for robust multi-stage MPC.

Example:

# in model definition:
alpha = model.set_variable(var_type='_p', var_name='alpha')
beta = model.set_variable(var_type='_p', var_name='beta')

...
# in MPC configuration:
n_combinations = 3
p_template = MPC.get_p_template(n_combinations)
p_template['_p',0] = np.array([1,1])
p_template['_p',1] = np.array([0.9, 1.1])
p_template['_p',2] = np.array([1.1, 0.9])

def p_fun(t_now):
return p_template

MPC.set_p_fun(p_fun)


Note the nominal case is now: alpha = 1 beta = 1 which is determined by the order in the arrays above (first element is nominal).

Parameters: n_combinations (int) – Define the number of combinations for the uncertain parameters for robust MPC. None None