GEKKO为什么不进行初始测量?

问题描述 投票:5回答:1

[使用GEKKO对具有初始测量值的动态系统进行建模时,即使打开FSTATUS,GEKKO似乎也完全忽略了该测量值。是什么原因造成的?如何让GEKKO识别初始测量值?

我希望求解器将初始测量值考虑在内,并相应地调整解决方案。

adjust

from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt 

# measurement
tm = 0
xm = 25

m = GEKKO()
m.time = np.linspace(0,20,41)
tau = 10
b = m.Param(value=50)
K = m.Param(value=0.8)

# Manipulated Variable
u = m.MV(value=0, lb=0, ub=100)
u.STATUS = 1  # allow optimizer to change
u.DCOST = 0.1
u.DMAX = 30

# Controlled Variable
x = m.CV(value=0,name='x')
x.STATUS = 1  # add the SP to the objective
m.options.CV_TYPE = 2 # squared error
x.SP = 40     # set point
x.TR_INIT = 1 # set point trajectory
x.TAU = 5     # time constant of trajectory
x.FSTATUS = 1
x.MEAS = xm

# Process model
m.Equation(tau*x.dt() == -x + K*u)
m.options.IMODE = 6 # control
m.solve()

# 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,u.value,'b-',label='MV Optimized')
plt.legend()
plt.ylabel('Input')
plt.subplot(2,1,2)
plt.plot(tm,xm,'ro', label='Measurement')
plt.plot(m.time,results['x.tr'],'k-',label='Reference Trajectory')
plt.plot(m.time,results['x.bcv'],'r--',label='CV Response')
plt.ylabel('Output')
plt.xlabel('Time')
plt.legend()
plt.show()
python optimization gekko
1个回答
3
投票

Gekko忽略了MPC初始化的第一个周期的测量。如果您进行其他求解,则它将使用度量。

m.solve() # for MPC initialization

x.MEAS = xm
m.solve() # update initial condition with measurement

反馈状态(FSTATUS)是用于测量的一阶滤波器,范围介于0(无更新)和1(完全测量更新)之间。

MEAS = LSTVAL * (1-FSTATUS) + MEAS * FSTATUS

然后新的测量值(MEAS)用于偏差计算。存在无偏(原始预测不受测量影响)模型预测和有偏模型预测。偏差计算为无偏差模型预测与测量值之间的差。

BIAS = MEAS - UNBIASED_MODEL

Biased and Unbiased Model

from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt 

# measurement
tm = 0
xm = 25

m = GEKKO()
m.time = np.linspace(0,20,41)
tau = 10
b = m.Param(value=50)
K = m.Param(value=0.8)

# Manipulated Variable
u = m.MV(value=0, lb=0, ub=100)
u.STATUS = 1  # allow optimizer to change
u.DCOST = 0.1
u.DMAX = 30

# Controlled Variable
x = m.CV(value=0,name='x')
x.STATUS = 1  # add the SP to the objective
m.options.CV_TYPE = 2 # squared error
x.SP = 40     # set point
x.TR_INIT = 1 # set point trajectory
x.TAU = 5     # time constant of trajectory
x.FSTATUS = 1

# Process model
m.Equation(tau*x.dt() == -x + K*u)
m.options.IMODE = 6 # control
m.solve(disp=False)

m.options.TIME_SHIFT = 0
x.MEAS = xm
m.solve(disp=False)
# turn off time shift, only for initialization
m.options.TIME_SHIFT = 1

# 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,u.value,'b-',label='MV Optimized')
plt.legend()
plt.ylabel('Input')
plt.ylim([-5,105])
plt.subplot(2,1,2)
plt.plot(tm,xm,'ro', label='Measurement')
plt.plot(m.time,results['x.tr'],'k-',label='Reference Trajectory')
plt.plot(m.time,results['x.bcv'],'r--',label='CV Response Biased')
plt.plot(m.time,x.value,'g:',label='CV Response Unbiased')
plt.ylim([-1,41])
plt.ylabel('Output')
plt.xlabel('Time')
plt.legend()
plt.show()

这是当前的工作方式,因为对于上述计算,没有LSTVAL或无偏模型预测。第一个周期计算这些值,并允许后续周期进行更新。如果确实在第一个循环中需要更新的值,则可以在第二个求解中使用选项m.option.TIME_SHIFT=0进行求解,以不更新模型的初始条件。您将需要为后续循环更改TIME_SHIFT=1,以使动态模型具有预期的时间进度。

© www.soinside.com 2019 - 2024. All rights reserved.