I have reviewed the bibliography and the Gekko programming structure for model predictive control. Although I understood the way it is programmed and their purpose. I would like to understand how Gekko manages the differences between the control horizon and prediction horizon according to related in Seborg, for example. I can´t see a differentiation on the code. Below is an example MPC application for illustration.
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
m = GEKKO()
# Time Horizon [0,1,2,...,39,40]
m.time = np.linspace(0,40,41)
# MV = Manipulated Variable
u = m.MV(value=0, lb=0, ub=100)
u.STATUS=1; u.DCOST=0.1; u.DMAX=20
# CV = Controlled Variable
x = m.CV(value=0,name='x')
x.STATUS=1; x.SP=45
# Define model
K = m.Param(value=0.8); tau = 15.0
m.Equation(tau*x.dt() == -x + K*u)
# Options and solve
m.options.CV_TYPE = 2
m.options.MV_TYPE = 0
m.options.NODES = 3
m.options.IMODE = 6
# Define Control and Prediction Horizon
m.options.CTRL_HOR = 10
m.options.CTRL_TIME = 1
m.options.PRED_HOR = 40
m.options.PRED_TIME = 2
m.solve(disp=False)
# Plot results
plt.figure()
plt.subplot(2,1,1)
plt.step(m.time,u.value,'b-',label='MV Move Plan')
plt.legend()
plt.ylabel('MV')
plt.subplot(2,1,2)
plt.plot([0,40],[45,45],'k-',label='Target Setpoint')
plt.plot(m.time,x.value,'r--',label='CV Response')
plt.ylabel('CV')
plt.xlabel('Time')
plt.legend(loc='best')
plt.show()
I would appreciate your feedback about how I should consider the np.linspace()
instruction used in the code.
Thank you.
Sandra Rodríguez