pyomo创建一个可变的时间索引 [英] Pyomo creating a variable time index

查看:208
本文介绍了pyomo创建一个可变的时间索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将此约束引入我的pyomo模型中 [

I'm trying to bring this constraint in my pyomo model [1

我定义了一个随时间变化的索引集,我想在下面优化相应的能量变量

I define a set for indexing over time and I want to optimize the corresponding energy variable below

model.grid_time = Set(initialize=range(0, 23)))
model.charging_energy = Var(model.grid_time, initialize=0)

我的约束定义如下:

model.limits = ConstraintList()
for t in model.grid_time:
    model.limits.add(sum(model.charging_energy[t] for t in model.grid >= energy_demand.at[t,"total_energy_demand"])

这些代码行的问题在于,我正在对整个索引集model.grid_time求和,而不只是对t求和.我想我需要第二个变量索引集(替换for t in model.grid),但是在创建变量索引集之后,搜索失败.

The problem with these codelines is that I'm summing over the whole indexing set model.grid_time and not just up to t. I think I need a second variable indexing set (replacing for t in model.grid), but I'm searching unsuccessfully after how creating a variable index set..

我将不胜感激!

推荐答案

这样的作品行吗?

def Sum_rule(model, v, t):
    return sum(model.Ech[t2] for t2 in model.grid_time if t2 <= t) <= model.Edem[v,t]

model.Sum_constraint = Constraint(model.grid_time, model.V, rule=Sum_rule)

本质上,发生的是Sum_rule(model, v, t)中的t确保对model.grid_times中的每个t调用约束.总和中的t2也是model.grid_times的一部分,但只会采用小于调用约束的t的值.

Essentially, what happens is that the t in the Sum_rule(model, v, t) makes sure that the constraint is called for each t in model.grid_times. The t2 in the sum is also part of model.grid_times, but it will only take values that are smaller than the t at which the constraint is called.

我不确定我的约束条件是否完全符合您的表示法,因为您没有提供所有必需的信息(例如,关于E^dem变量的下标v的信息,但基本上可以用总和来完成

I am not sure if my constraint matches exactly your notation, as you have not provided all the information required (e.g. regarding the subscript v of the E^dem variable, but it will basically do what you want with the sum.

这篇关于pyomo创建一个可变的时间索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆