我试图用几个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
不存在。
我考虑在每一步搜索最接近该点的索引,但这将极大地增加我的计算时间。
谢谢!
发布于 2020-06-19 23:56:48
几分..。
首先,这是无效的代码。我不确定最后的段是什么,但是不能在命名段后面添加位置参数,也不清楚您要用t:ode(m, t)
做什么
Constraint(model.t, rule=lambda m, t: odeu(m, t))
Pyomo确实计算了set索引的表达式,只要它在集合内,您就是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
https://stackoverflow.com/questions/62476001
复制相似问题