我是Pyomo的新手。我试图运行两个单独的方程来迭代一个集合及其子集,它没有按预期给出结果:
model.E = Set(initialize = [0, 1, 2, 3])
model.E_n = Set(model.E, initialize = {0:[1,2,3,4,5], 1:[6,7,8,9,10], 2:[11,12,13,14,15], 3:[16,17,18,19,20]})
model.int_rate = 0.05
def R_discount_inv_init(model, i):
return sum(1 / (1 + model.int_rate)**(i - 1) for i in model.E)
model.cum_disc_inv_cost = Param(model.E, initialize = R_discount_inv_init)
def R_discount_op_init(model, i):
for index in model.E_n:
return sum(1 / (1 + model.int_rate)**(i - 1) for i in model.E_n[index])
model.cum_disc_op_cost = Param(model.E, initialize = R_discount_op_init)
我希望第一个表达式遍历model.E(Epochs的数量)中的集合,第二个表达式将遍历其子集model.E_n(Epoch中的时间段= 5年)。
请问有更好的方法对此进行编码以产生预期结果吗?
谢谢