Class method.

do_mpc.controller.MPC.set_p_fun(self, p_fun)

Set function which returns parameters. The p_fun is called at each optimization step to get the current values of the (uncertain) parameters.

This is the 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 takes as input a function, which MUST return a structured object, based on the defined parameters and the number of combinations. The defined function has time as a single input.

Obtain this structured object first, by calling get_p_template().

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


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


# 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


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:p_fun (function) – Function which returns a structure with numerical values. Must be the same structure as obtained from get_p_template(). Function must have a single input (time).
Return type:None

This page is auto-generated. Page source is not available on Github.