在使用 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()