【问题标题】:Why is GEKKO not picking up the initial measurement?为什么 GEKKO 不进行初始测量?
【发布时间】:2020-03-17 19:12:58
【问题描述】:

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

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

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】:

    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
    

    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 以在后续循环中获得动态模型的预期时间进度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-16
      • 1970-01-01
      • 2019-05-25
      • 2013-10-14
      • 2011-05-26
      相关资源
      最近更新 更多