The Gekko
显示版本是GUI=True
正如你问题中的情节所示。仅有的FV
, MV
, SV
, and CV
值显示在 Web 界面中。
Edit:正如您的评论中所述,您通过升级解决了趋势显示不足的问题flask
.
pip install flask --upgrade
选项WEB
是 Web 界面的 APMonitor 版本,它使用 AJAX 和 Flash 绘图(已弃用,将在未来版本中替换)来显示 Web 界面。这可以保留为m.options.WEB=0
使用 Gekko GUI。
下面是生成 Web 界面的示例。这flask
package 是 Web 界面的依赖项,第一次启动时需要刷新网页。选择绘图上的变量以显示或添加新绘图。
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
m = GEKKO()
m.time = np.linspace(0,20,41)
# Parameters
mass = 500
b = m.Param(value=50)
K = m.Param(value=0.8)
# Manipulated variable
p = m.MV(value=0, lb=0, ub=100)
p.STATUS = 1 # allow optimizer to change
p.DCOST = 0.1 # smooth out gas pedal movement
p.DMAX = 20 # slow down change of gas pedal
# Controlled Variable
v = m.CV(value=0)
v.STATUS = 1 # add the SP to the objective
m.options.CV_TYPE = 2 # squared error
v.SP = 40 # set point
v.TR_INIT = 1 # set point trajectory
v.TAU = 5 # time constant of trajectory
# Process model
m.Equation(mass*v.dt() == -v*b + K*b*p)
m.options.IMODE = 6 # control
m.solve(disp=False,GUI=True)
Calling m.solve(GUI=True)
每次调用时生成(或更新)Web 界面。还可以使用 Matplotlib 显示 MPC 解决方案。
# get additional solution information
import json
with open(m.path+'//results.json') as f:
results = json.load(f)
plt.figure()
plt.subplot(2,1,1)
plt.plot(m.time,p.value,'b-',label='MV Optimized')
plt.legend()
plt.ylabel('Input')
plt.subplot(2,1,2)
plt.plot(m.time,results['v1.tr'],'k-',label='Reference Trajectory')
plt.plot(m.time,v.value,'r--',label='CV Response')
plt.ylabel('Output')
plt.xlabel('Time')
plt.legend(loc='best')
plt.show()
More 复杂的 Matplotlib 绘图 https://apmonitor.com/do/uploads/Main/tclab_mhe_mpc.mp4还可以生成以显示未来预测范围、移动范围估计或 MPC 解决方案的其他定制功能。