4

I am working on an MPC problem with individual linear models predicting the control variable at each time step in the prediction horizon (see below where u is the manipulated variable and y is the control variable). The coefficients of each linear model in the prediction horizon change based on the current state variables each time the window moves.

y[i+1] = A[i]@u[i]+B[i]
y[i+2] = A[i+1]@u[i:i+2]+B[i+1]
...
y[i+n] = A[i+n-1]@u[i:i+n]+B[i+n-1]

A and B are a list of matrices which are determined from a function of the current state. I basically want to pause the controller at the beginning of each time step (prior to optimization) and recalculate these coefficient matrices based on the feedback from the system. Is it possible to do this in Gekko using MPC mode (IMODE=6) or do I need to manage the time outside of Gekko?

cdgood
  • 61
  • 3

2 Answers2

4

You can do it by running both MHE and MPC in a row. You want to run MHE(imode=5) at every time step to estimate the model parameters A and B. Then, update the MPC model with the new A and B before executing the MPC(mode=6) calculation.

Here is an example of TCLab temperature control using combined MHE and MPC. https://apmonitor.com/do/index.php/Main/TCLabH

You might need to change the model in this example with an ARX type of model that you can find on this page. https://apmonitor.com/do/index.php/Main/NonlinearControl

Junho Park
  • 997
  • 4
  • 12
  • 1
    Thank you. That example is helpful. I have a follow-up question. How can I define different models for each time step in the prediction horizon? From my original post, the prediction horizon is length n. At each time step within the prediction horizon the control variable is defined by a different equation. The first time step is only a function of the manipulated variable at that time step, but for predicting the CV four time steps in the future, the CV is dependent on the previous MVs as well. Maybe that's answered in the ARX type model example but I don't see it. – cdgood Dec 23 '20 at 15:20
2

This is for your follow-up question in the comment.

Just for clarification, does the ARX model structure for MPC prediction change throughout all simulation time steps? Or, does it only happen at the beginning of the simulation when you don't have enough past data?

If the latter is your case, GEKKO will automatically handle it for you.

This is the structure of the ARX model.

enter image description here

na: # of the coefficient for CV
nb: # of the coefficient for MV
nk: Length of a time-delay between CV and MV

Gekko automatically adjusts the na and nb for the beginning of the simulation when t < na or t < nb, which turns out the same formula in your original question above.

Junho Park
  • 997
  • 4
  • 12
  • 1
    The ARX model structure will always look like what I outlined in the original post. Looking at the equation you included, b1, b2,..., bnb appear to be the same for all discrete steps within the same horizon. In my application, predicting the first time step in the prediction horizon will have different b values than the 4th time step prediction b values in the same prediction horizon. I'm thinking what I need to do is create 10 individual CVs (for a pred. horizon = 10) and 10 MVs so I can create my own equations linking the MVs and CVs. – cdgood Dec 23 '20 at 19:54