Pyomo中的时延响应

2024-09-28 21:52:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用几个ODE模拟一个DAE系统,其中一个(控制器)显示出与模拟时间尺度相比的巨大时滞。我应该如何在Pyomo中实现这一点(不考虑其他软件包,Gekko已经考虑过了,但由于apm.exe source不是作为开源发布的,因此不再考虑我的应用程序的软件包)

目前,我已将问题表述为:

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不存在

我考虑过在每一步中搜索最接近该点的索引,但这将以指数方式增加我的计算时间

谢谢


Tags: lambdamodel系统rulepyomo浮点odetau
1条回答
网友
1楼 · 发布于 2024-09-28 21:52:00

几点

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

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

Pyomo对集合索引的表达式进行求值,只要它在集合内,您就是GTG。我不确定你所说的“浮点索引”是什么意思。我认为你正在寻找类似这样的东西,其中有一个时间索引和一些偏移量,需要在某些约束中使用:

# 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

相关问题 更多 >