gpt4 book ai didi

GEKKO RTO 与 MPC 模式

转载 作者:行者123 更新时间:2023-12-04 04:15:25 28 4
gpt4 key购买 nike

这是从这个 one 派生的问题.发布我的问题后,我找到了一个解决方案(更像是一个强制优化器优化的补丁)。有件事让我很困惑。 John Hedengren正确指出 ODE 中的 b=1.0 导致了 IMODE=6 的不可行解。然而,在我对 IMODE=3 的零碎工作中,我确实找到了解决方案。

我试图通过阅读 GEKKO's 了解这里发生的事情IMODE=36 的文档,但我不清楚

IMODE=3

RTO Real-Time Optimization (RTO) is a steady-state mode that allows decision variables (FV or MV types with STATUS=1) or additional variables in excess of the number of equations. An objective function guides the selection of the additional variables to select the optimal feasible solution. RTO is the default mode for Gekko if m.options.IMODE is not specified.

IMODE=6

MPC Model Predictive Control (MPC) is implemented with IMODE=6 as a simultaneous solution or with IMODE=9 as a sequential shooting method.

为什么 b=1。在一种模式下工作但在另一种模式下不工作?

这是我对 IMODE=3b=1.0 的修补工作:

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

m = GEKKO(remote=False)
m.time = np.linspace(0,23,24)

#initialize variables
T_e = [50.,50.,50.,50.,45.,45.,45.,60.,60.,63.,\
64.,45.,45.,50.,52.,53.,53.,54.,54.,53.,52.,51.,50.,45.]
temp_low = [55.,55.,55.,55.,55.,55.,55.,68.,68.,68.,68.,55.,55.,68.,\
68.,68.,68.,55.,55.,55.,55.,55.,55.,55.]
temp_upper = [75.,75.,75.,75.,75.,75.,75.,70.,70.,70.,70.,75.,75.,\
70.,70.,70.,70.,75.,75.,75.,75.,75.,75.,75.]
TOU = [0.05,0.05,0.05,0.05,0.05,0.05,0.05,200.,200.,\
200.,200.,200.,200.,200.,200.,200.,200.,200.,\
200.,200.,200.,0.05,0.05,0.05]

b = m.Param(value=1.)
k = m.Param(value=0.05)

u = [m.MV(0.,lb=0.,ub=1.) for i in range(24)]

# Controlled Variable
T = [m.SV(60.,lb=temp_low[i],ub=temp_upper[i]) for i in range(24)]

for i in range(24):
u[i].STATUS = 1

for i in range(23):
m.Equation( T[i+1]-T[i]-k*(T_e[i]-T[i])-b*u[i]==0.0 )

m.Obj(np.dot(TOU,u))

m.options.IMODE = 3
m.solve(debug=True)
myu =[u[0:][i][0] for i in range(24)]
print myu
myt =[T[0:][i][0] for i in range(24)]
plt.plot(myt)
plt.plot(temp_low)
plt.plot(temp_upper)
plt.show()
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(myu,color='b')
ax2.plot(TOU,color='k')
plt.show()

结果:

enter image description here

Temperature

Input and Hourly cost

最佳答案

不可行IMODE=6和可行IMODE=3的区别在于IMODE=3情况允许温度初始条件由优化器调整。优化器认识到初始条件可以更改,因此将其修改为 75 以保持可行并最大限度地减少 future 的能源消耗。

Feasible with hard constraints

from gekko import GEKKO
import numpy as np

m = GEKKO(remote=False)
m.time = np.linspace(0,23,24)

#initialize variables
T_external = [50.,50.,50.,50.,45.,45.,45.,60.,60.,63.,\
64.,45.,45.,50.,52.,53.,53.,54.,54.,\
53.,52.,51.,50.,45.]
temp_low = [55.,55.,55.,55.,55.,55.,55.,68.,68.,68.,68.,\
55.,55.,68.,68.,68.,68.,55.,55.,55.,55.,55.,55.,55.]
temp_upper = [75.,75.,75.,75.,75.,75.,75.,70.,70.,70.,70.,75.,\
75.,70.,70.,70.,70.,75.,75.,75.,75.,75.,75.,75.]
TOU_v = [0.05,0.05,0.05,0.05,0.05,0.05,0.05,200.,200.,200.,200.,\
200.,200.,200.,200.,200.,200.,200.,200.,200.,200.,0.05,\
0.05,0.05]

b = m.Param(value=1.)
k = m.Param(value=0.05)
T_e = m.Param(value=T_external)
TL = m.Param(value=temp_low)
TH = m.Param(value=temp_upper)
TOU = m.Param(value=TOU_v)

u = m.MV(lb=0, ub=1)
u.STATUS = 1 # allow optimizer to change

# Controlled Variable
T = m.SV(value=75)

m.Equations([T>=TL,T<=TH])
m.Equation(T.dt() == k*(T_e-T) + b*u)

m.Minimize(TOU*u)

m.options.IMODE = 6
m.solve(disp=True,debug=True)

import matplotlib.pyplot as plt
plt.subplot(2,1,1)
plt.plot(m.time,temp_low,'k--')
plt.plot(m.time,temp_upper,'k--')
plt.plot(m.time,T.value,'r-')
plt.ylabel('Temperature')
plt.subplot(2,1,2)
plt.step(m.time,u.value,'b:')
plt.ylabel('Heater')
plt.xlabel('Time (hr)')
plt.show()

如果再试一天(48 小时),您可能会发现问题最终无法解决,因为较小的加热器 b=1 无法满足较低的温度约束条件。

使用 IMODE=6 的优点之一是您可以编写微分方程而不是自己进行离散化。使用 IMODE=3,您可以对微分方程使用欧拉方法。 IMODE>=4 的默认离散化为 NODES=2,相当于您的 Euler 有限差分法。设置 NODES=3-6 可提高 orthogonal collocation on finite elements 的准确性.

关于GEKKO RTO 与 MPC 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60772432/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com