简体   繁体   English

GEKKO MPC 示例中的默认目标 function

[英]Default objective function in GEKKO MPC example

This Model Predictive Control (MPC) example using GEKKO (relating gas pedal movement to car velocity), doesn't explicitly state a cost function to minimize:此 Model 预测控制 (MPC) 示例使用 GEKKO(将油门踏板运动与汽车速度相关联),并未明确 state 成本 function 以最小化:

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()

Can anyone give me an algebraic expression for what cost function GEKKO is minimizing by default for this problem?谁能给我一个代数表达式,说明 function GEKKO 在默认情况下最小化这个问题的成本是多少?

With 'CV_TYPE = 2', your cost function is going to be the sum of squared error between setpoint and predicted CV value throughout the horizon length that you defined (m.time).使用“CV_TYPE = 2”,您的成本 function 将是您定义的整个地平线长度(m.time)中设定点和预测 CV 值之间的平方误差之和。

Please see the below link for detailed equations for squared error form and L1 (CV_TYPE = 1) form of the MPC objective function.有关 MPC 物镜 function 的平方误差形式和 L1 (CV_TYPE = 1) 形式的详细方程式,请参见以下链接。

http://apmonitor.com/do/index.php/Main/ControllerObjective http://apmonitor.com/do/index.php/Main/ControllerObjective

Junho俊昊

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM