非常感谢您调查我的问题!我是 pyomo 的新手,现在正试图用它来解决一个具体的模型。
这是我的部分代码:
———(已编辑)
def objective_rule(model):
ans = sum(model.DAEB[t] * model.DAEP[t] for t in model.t)
ans -= sum(model.DARUP[t] * model.RU[t] + model.DARDP[t] * model.RD[t] for t in model.t)
ans += sum(0.5 * (sum(model.penalty[t, w]) + sum(-model.RTEP[t] * (model.DAEB[t] - ((model.RTRD[t, w] * model.RU[t]) +
sum(model.veh_pwer_dem[t, v, w] for v in model.v))))) for t in model.t for w in model.w)
ans += 0.95 * (model.epslon + 1 / (0.5) * sum(0.01 * model.miu[w] for w in model.w))
return ans
- t 定义为一组 [0:23],一天中的时间小时;
- w被定义为[0,1],它是不同的场景;
- v 是 [0:29],30 个不同的样本。
在定义目标函数之前,我还定义了一系列与上述模型变量相关的约束。
除了最后一步,一切都运行顺利,pyomo 给出:
———(已编辑)
Traceback (most recent call last):
line 61, in <module>
myresult = result.solve(project, pricefile, reg_dispatch, SOC=0, SOC_margin=0.05)
line 56, in solve
opti_model, result = self.Fr_optimal_bidding_optimization(self.vehicles, pricefile, reg_dispatch, SOC)
line 347, in Fr_optimal_bidding_optimization
model.objective = Objective(rule=objective_rule, sense=minimize, doc='minimize the total cost')
line 483, in __setattr__
self.add_component(name, val)
line 849, in add_component
val.construct(data)
line 307, in construct
tmp = _init_rule(_self_parent)
line 337, in objective_rule
sum(model.veh_pwer_dem[t, v, w] for v in model.v))))) for t in model.t for w in model.w)
ERROR: Rule failed when generating expression for objective objective:
line 337, in <genexpr>
TypeError: '_GeneralVarData' object is not iterable
sum(model.veh_pwer_dem[t, v, w] for v in model.v))))) for t in model.t for w in model.w)
ERROR: Constructing component 'objective' from data=None failed:
TypeError: '_GeneralVarData' object is not iterable
TypeError: '_GeneralVarData' object is not iterable
首先,我对这个_GeneralVarData
对象真的很困惑,不知道它指的是什么,其次,我在我的目标函数中看不到问题,所以如果有人能提供任何建议,将不胜感激! !
(我也是“stackoverflow”的新手,如果我的问题没有明确说明,请在前面道歉!)
腾