Pyomo 中的延时响应

Time-delay response in Pyomo

我正在尝试用多个 ODE 模拟 DAE 系统,其中一个(控制器)与模拟时间尺度相比显示出巨大的时间滞后。我应该如何在 Pyomo 中实现它(不考虑其他包,已经用 Gekko 做了但是因为 apm.exe 源代码没有作为开源发布,不再考虑我的应用程序的包)。

目前我将问题表述为:

odeu = lambda m, t: tau * m.dudt[t] - (m.spu[t] - m.u[t]) == 0
model.odeu = Constraint(model.t, rule=lambda m, t: odeu(m, t))

我想要制作的是这样的东西: 目前我将问题描述为:

odeu = lambda m, t: tau * m.dudt[t] - (m.spu[t-tde] - m.u[t]) == 0
model.odeu = Constraint(model.t, rule=lambda m, t: odeu(m, t))

问题是 Pyomo 会离散化方程并使用奇怪的浮点索引而不是局部评估(优化需要什么,当然,只是对我来说很奇怪的浮点索引),所以索引 t-tde不存在。

我考虑过在每一步搜索最接近该点的索引,但这会成倍地增加我的计算时间。

谢谢!

几点...

首先,这是无效代码。我不确定最后一段是什么,但是您不能在命名的段之后添加位置参数,并且不清楚您要用 t:ode(m, t):

做什么
Constraint(model.t, rule=lambda m, t: odeu(m, t))

Pyomo 评估集合索引的表达式,只要它落在集合中,你就是 GTG。我不确定你所说的 "floating point indexing." 是什么意思 我认为你正在寻找这样的东西,你有一个时间索引和一些你需要在某些约束中使用的偏移量:

# set with lag

from pyomo.environ import * 

mdl = ConcreteModel()    
mdl.t = Set(initialize=range(5))    # a set index for time    
mdl.x = Var(mdl.t)                  # a toy variable

tde = 2                             # some offset

# make constraint
def c1(mdl, t):
    if t - tde < 0:                 # out of bounds
        return Constraint.Skip
    return mdl.x[t - tde] <= 10
mdl.c1 = Constraint(mdl.t, rule=c1)

mdl.pprint()

生成具有适当约束的模型...

1 Set Declarations
    t : Dim=0, Dimen=1, Size=5, Domain=None, Ordered=False, Bounds=(0, 4)
        [0, 1, 2, 3, 4]

1 Var Declarations
    x : Size=5, Index=t
        Key : Lower : Value : Upper : Fixed : Stale : Domain
          0 :  None :  None :  None : False :  True :  Reals
          1 :  None :  None :  None : False :  True :  Reals
          2 :  None :  None :  None : False :  True :  Reals
          3 :  None :  None :  None : False :  True :  Reals
          4 :  None :  None :  None : False :  True :  Reals

1 Constraint Declarations
    c1 : Size=3, Index=t, Active=True
        Key : Lower : Body : Upper : Active
          2 :  -Inf : x[0] :  10.0 :   True
          3 :  -Inf : x[1] :  10.0 :   True
          4 :  -Inf : x[2] :  10.0 :   True

3 Declarations: t x c1