model = ConcreteModel()
model.time = Set(initialize = range(24*3))
model.option = Set(initialize = range(4))
model.time_soc = Var(model.time, bounds = (0.1,0.9), domain=PositiveReals)
model.time_option = Var(model.time, model.option, domain = Binary)
model.soc_param = Param(model.option, initialize={0:0, 1:-0.025, 2:-0.05, 3:0.125})
model.soc_ini = Param(initialize = 0.5)
def cons_time_opt(model, i):
total_choice = sum(model.time_option[i,j] for j in model.option)
return total_choice == 1
model.opt = Constraint(model.time, rule = cons_time_opt)
model.soc_con0 = Constraint(0.5 + model.time_option[0,j]*model.soc_param[j] == model.time_soc[0] for j in model.option)
我遇到以下错误:
错误:从data = None构造组件'soc_con0_index'失败: TypeError:将time_soc [0] == 0.5插入设置soc_con0_index时出现问题
答案 0 :(得分:0)
我猜想soc_con0
约束是要成为索引约束,在这种情况下您会丢失约束规则。应该是:
def soc_con0_rule(model, j):
return 0.5 + model.time_option[0,j]*model.soc_param[j] == model.time_soc[0]
model.soc_con0 = Constraint(model.option, rule=soc_con0_rule)