python - GEKKO MPC 示例中的默认目标函数
问题描述
这个使用 GEKKO(将油门踏板运动与汽车速度相关联)的模型预测控制 (MPC) 示例没有明确说明要最小化的成本函数:
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)
# 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()
任何人都可以给我一个代数表达式,说明 GEKKO 在默认情况下最小化这个问题的成本函数吗?
解决方案
使用“CV_TYPE = 2”,您的成本函数将是您定义的整个地平线长度(m.time)内设定点和预测 CV 值之间的平方误差之和。
有关 MPC 目标函数的平方误差形式和 L1 (CV_TYPE = 1) 形式的详细方程,请参阅下面的链接。
http://apmonitor.com/do/index.php/Main/ControllerObjective
俊昊
推荐阅读
- flutter - 圆形进度指示器未在颤动中显示
- scala - java.lang.NoClassDefFoundError: org/apache/htrace/core/Tracer$Builder - Scala Spark
- c# - 无法在 OneWay 模式下绑定 Picker SelectedItem
- docker - semitech:部署 docker 容器时,weaviate 扩展存储连接被拒绝
- ldap - 带有通配符和多个搜索条件的 Ldap 过滤器
- javascript - CSS表格数据超出表格数据宽度
- u-boot - CodeViser JTag 调试器:它如何知道 u-boot 在 RAM 中的重定位偏移量?
- javascript - 隐藏一个 div,直到该 div 内的图像从 YouTube 加载
- android - 使用 EXO 播放器播放音频文件并同时使用双簧管录制时,录制的音频文件被拉伸
- android - 使用底部导航视图保存状态