MPCEmulation

class mshoot.MPCEmulation(emumod, cfun)

Bases: object

MPC emulation is used to test an MPC strategy in a simulated environment. Two models are required: (1) control model, (2) emulation model.

The control model is used in the optimization. The emulation model is the virtual mock-up of the real system.

The cost function should return a scalar and have the following signature:

def cost(xdf, ydf):
    # user code here
    return cost

where xdf is the state data frame and ydf is the output data frame.

Parameters:
  • emumod – SimModel, emulation model
  • cfun – user cost function
optimize(model, inp_ctr, inp_emu, free, ubounds, xbounds, x0, ynominal=None, maxiter=50, step=1, horizon=10, inp_clb=None)

Optimize problem using progressive multiple shooting optimizations.

inp_ctr and inp_emu have to have the same index (control and emulation inputs need to be aligned).

If inp_clb is provided with a callback function, then it overrides inp_ctr. The function can be used to provide new inputs for each receding horizon, emulating in example new weather/occupancy forecasts. The callback function takes only one argument index, which is a numpy 1D array with time steps for which the inputs have to be provided, e.g. if index = [300, 600, 900, 1200] is passed to the function, it should return a data frame with index [300, 600, 900, 1200] and columns for all input variables. Since inp_ctr is a required argument, for clarity it is advised to set it to None in cases when inp_clb is provided. See the example examples/mpc_fmi_6.py for how to use inp_clb.

Return:

  • u - DataFrame, optimal free inputs
  • xctr - DataFrame, control states
  • xemu - DataFrame, emulation states
  • yemu - DataFrame, emulation outputs
  • uhist - list of DataFrames, optimal free inputs per MPC interval
Parameters:
  • model – SimModel, control model
  • inp_ctr – DataFrame, fixed inputs for control model, index with time
  • inp_emu – DataFrame, fixed inputs for emulation model, index with time
  • free – list, names of free inputs
  • ubounds – list of tuples of floats, free input bounds
  • xbounds – list of tuples of vectors, state bounds
  • x0 – list, initial state
  • ynominal – list, nominal values of outputs (for regularization)
  • maxiter – int, maximum number of iterations (default 50)
  • step – int, MPC re-run step - number of inp rows (default 1)
  • horizon – int, opt. horizon - number of inp rows (default 10)
  • inp_clb – callback function, see description
Returns:

u, xctr, xemu, yemu, uhist