使用PYOMO计算两个参数的比率

发布于 2025-02-08 11:49:12 字数 437 浏览 1 评论 0原文

我有2个参数,例如需求和能力: 我对这些建模如下:

model.Dmem=Param(model.nf,within=NonNegativeIntegers, initialize=1)
model.Cmem=Param(model.ns, within=NonNegativeIntegers, initialize=5)

我想计算这两个参数的比率。 我通过将上述参数划分为:

model.ame = expr(model.cmem/model.dmem)

但是我收到的错误是:

typeerror:无支持的操作数类型(s) for /:“ indexedParam”和“ indexedParam” < /strong>

请提供帮助。

问候

I have 2 parameters such as Demand and Capacity:
I have modeled these as follows:

model.Dmem=Param(model.nf,within=NonNegativeIntegers, initialize=1)
model.Cmem=Param(model.ns, within=NonNegativeIntegers, initialize=5)

I want to calculate the ratio of these two parameters.
I did this by dividing the parameters above as:

model.ame=expr(model.Cmem/model.Dmem)

But the error I am receiving is:

TypeError: unsupported operand type(s) for /: 'IndexedParam' and 'IndexedParam'

Please help.

Regards

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

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

发布评论

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

评论(1

感性不性感 2025-02-15 11:49:12

如果我正确理解您的问题,并且确实是model.ame是一个PYOMO参数,则可以将其初始化为以下内容:

def ame_rule(model, ns, nf):
    return model.Cmem[ns]/model.Dmem[nf]

model.ame=Param(model.ns, model.nf, initialize=ame_rule)

这样,Pyomo将通过调用来构建您的ame参数每对nsnfame_rule函数。

If I understood your question correct and, indeed, model.ame is a Pyomo parameter, you can initialize it doing the following:

def ame_rule(model, ns, nf):
    return model.Cmem[ns]/model.Dmem[nf]

model.ame=Param(model.ns, model.nf, initialize=ame_rule)

That way Pyomo will construct your ame parameter by calling the ame_rule function for every pair of ns and nf.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文