Pyomo 变量下界
大家好,我有以下问题。我有两个优化问题,第一个的输出值是第二个变量的下限。
我尝试按以下方式编写:
model_low=ConcreteModel()
#Decision Variables
model_low.p=Var((tech for tech in fuels+['hydro_big']+renew),hours,within=NonNegativeReals,initialize=2000)
model_low.C=Var(techs,within=NonNegativeReals,initialize=0)
我为下一个优化问题设置以下决策变量:
model_high=ConcreteModel()
#Decision Variables
model_high.p=Var((tech for tech in fuels+['hydro_big']+renew),hours,within=NonNegativeReals,lb=value(model_low.p),initialize=2000)
model_high.C=Var(techs,within=NonNegativeReals,lb=value(model_low.C),initialize=0)
但我收到以下错误:
ERROR: evaluating object as numeric value: p
(object: \<class 'pyomo.core.base.var.IndexedVar'\>)
'IndexedVar' object is not callable
Traceback (most recent call last):
File "C:/Final_python.py", line 144, in \<module\>
model_high.p=Var((tech for tech in fuels+\['hydro_big'\]+renew),hours,within=NonNegativeReals,lb=value(model_low.p),initialize=2000)
File "pyomo\\core\\expr\\numvalue.pyx", line 156, in pyomo.core.expr.numvalue.value
File "pyomo\\core\\expr\\numvalue.pyx", line 141, in pyomo.core.expr.numvalue.value
TypeError: 'IndexedVar' object is not callable
如何解决此问题?
Hi guys I have the following problem. I have two optimization problems and the output values of the first are the lower bounds in second's variables.
I try to write it the following way :
model_low=ConcreteModel()
#Decision Variables
model_low.p=Var((tech for tech in fuels+['hydro_big']+renew),hours,within=NonNegativeReals,initialize=2000)
model_low.C=Var(techs,within=NonNegativeReals,initialize=0)
I set for the next optimization problem the following decision variables :
model_high=ConcreteModel()
#Decision Variables
model_high.p=Var((tech for tech in fuels+['hydro_big']+renew),hours,within=NonNegativeReals,lb=value(model_low.p),initialize=2000)
model_high.C=Var(techs,within=NonNegativeReals,lb=value(model_low.C),initialize=0)
But I got the following Error:
ERROR: evaluating object as numeric value: p
(object: \<class 'pyomo.core.base.var.IndexedVar'\>)
'IndexedVar' object is not callable
Traceback (most recent call last):
File "C:/Final_python.py", line 144, in \<module\>
model_high.p=Var((tech for tech in fuels+\['hydro_big'\]+renew),hours,within=NonNegativeReals,lb=value(model_low.p),initialize=2000)
File "pyomo\\core\\expr\\numvalue.pyx", line 156, in pyomo.core.expr.numvalue.value
File "pyomo\\core\\expr\\numvalue.pyx", line 141, in pyomo.core.expr.numvalue.value
TypeError: 'IndexedVar' object is not callable
How could I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模型中的变量似乎是索引的,因此您必须提供一些索引的下界索引工具。您可以通过(如显示)传递一个可以执行此操作的函数,就像使用规则来制定约束一样。或者,您可以将其作为模型中的约束构建,而不是在模型空间中使用下限。
我会强烈地鼓励您为您所索引的每件事制作
pyomo.set
,它将为您节省大量的时间故障排除等。代码:
输出(第二阶段模型打印):
Your variables in the model appear to be indexed, so you have to provide some lower bound indexing tool that is indexed. You can pass a function (as show) that will do this, same as if you were using a rule to make constraints. Or you could just build this in as a constraint in the model and not use lower bound...same thing in model space.
I would strongly encourage you to make a
pyomo.Set
for each of the things you are indexing with, it will save you a ton of time troubleshooting and such.Code:
Output (the 2nd stage model print):