如何总和二维纸浆溶液

发布于 2025-02-06 05:30:42 字数 572 浏览 3 评论 0原文

我有以下代码切口:

        a = range(0, 30)
        b = range (0, 88)
         Power_consumption =  LpVariable.dicts('Power_consumption', (a,b), lowBound=0, upBound=5, cat='Continuous')
    ...

result= [[]]
    for i in a:
        for j in b:
            print("i:",3, "j:",3, " = ", Power_consumption[i][j].varValue)
            result[i][j] = Power_consumption[i][j].varValue

在获得线性编程模型的选择性解决方案后,我想在索引i(i = timeStep,j = device)上总结“ power_ccumpumption”,以便我为每个timeStep“ i”所有设备的功耗。但是,当尝试时,我一直都会获得“ IndexError:列表分配索引范围之外”。所以我想知道我做错了什么,最好的做法是什么?

I have following code cutouts:

        a = range(0, 30)
        b = range (0, 88)
         Power_consumption =  LpVariable.dicts('Power_consumption', (a,b), lowBound=0, upBound=5, cat='Continuous')
    ...

result= [[]]
    for i in a:
        for j in b:
            print("i:",3, "j:",3, " = ", Power_consumption[i][j].varValue)
            result[i][j] = Power_consumption[i][j].varValue

After getting the optmimal solution of the Linear Programming Model, I would like to sum up the "Power_consumption" on the index i ( i = timestep, j = device) so that I have for every timestep "i" the power consumption of all devices. But when trying I get all the time "IndexError: list assignment index out of range". So I am wondering what I did wrong and whats the best way of doing so ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽梦忆笙歌 2025-02-13 05:30:42

我认为您对ab的变量并不正确。在那里更加明确…

a = list(range(30))
b = list(range(88))
ab = [(i, j) for i in a for j in b]
Power = LpVariable.dicts(‘power’, ab, . . . )

I don’t think you are constructing your variable correctly with respect to a and b. Be more explicit there…

a = list(range(30))
b = list(range(88))
ab = [(i, j) for i in a for j in b]
Power = LpVariable.dicts(‘power’, ab, . . . )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文