[英]Pyomo ValueError: Error retrieving component
My code is the following:我的代码如下:
from coopr.pyomo import *
import numpy as np
from scipy.optimize import minimize
import math
model = ConcreteModel()
model.days = RangeSet(1, 31) #model.time)
T = model.days
M_b1_O_stored_T = Var(T,bounds=(0, None))
def obj_rule(model):
return sum( M_b1_O_stored_T[i] for i in model.days )
model.funcobj = Objective( rule =obj_rule , sense=maximize)
It shows the following error: ValueError: Error retrieving component IndexedVar[1]: The component has not been constructed.它显示以下错误: ValueError:检索组件 IndexedVar[1] 时出错:组件尚未构建。 Do anyone can please help me on this please?
有人可以帮我吗? The constraints do not show problem, but the objective function is showing...
约束没有显示问题,但目标函数显示...
Welcome to the site...欢迎来到本站...
You neglected to put your variable "into the model" with the model.
您忽略了将变量与模型一起“放入模型中”
model.
prefix.字首。 Note my fix below in both the declaration and in your objective function.
请注意我在声明和目标函数中的修复。
from pyomo.environ import *
# from coopr.pyomo import *
# import numpy as np
# from scipy.optimize import minimize
# import math
model = ConcreteModel()
model.days = RangeSet(1, 31) #model.time)
# T = model.days
model.M_b1_O_stored_T = Var(model.days,bounds=(0, None))
def obj_rule(model):
return sum( model.M_b1_O_stored_T[i] for i in model.days )
model.funcobj = Objective( rule =obj_rule , sense=maximize)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.