我正尝试写出如图所示的约束。但是出现以下错误:
> --------------------------------------------------------------------------- GurobiError Traceback (most recent call
> last) <ipython-input-112-d0e0b7b1cb5e> in <module>()
> ----> 1 Boiler_capacity = m.addConstrs((boiler_produced_thermal[t] <= boiler_thermal_max for t in time_slots), name = "Boiler_capacity")
>
> model.pxi in gurobipy.Model.addConstrs
> (../../src/python/gurobipy.c:89458)()
>
> model.pxi in gurobipy.Model.addConstr
> (../../src/python/gurobipy.c:87963)()
>
> linexpr.pxi in gurobipy.LinExpr.__sub__
> (../../src/python/gurobipy.c:34728)()
>
> linexpr.pxi in gurobipy.LinExpr.__add__
> (../../src/python/gurobipy.c:34333)()
>
> linexpr.pxi in gurobipy.LinExpr.add
> (../../src/python/gurobipy.c:31162)()
>
> GurobiError: Unsupported type (<class 'tuple'>) for LinExpr addition
> argument
到目前为止我尝试过的事情:
Boiler_capacity = m.addConstrs((boiler_produced_thermal[t] <= boiler_thermal_max for t in time_slots), name = "Boiler_capacity")
位置:
boiler_produced_thermal 随索引时隙而变化
boiler_thermal_max = 21000被分配给整数值。
时间段 = ['k1','k2','k3','k4','k5']
此代码有效:
如果使用分配给变量的值,则不要使用变量名。有用。但是我没有得到背后的真正原因是什么。
Boiler_capacity = m.addConstrs((boiler_produced_thermal[t] <= 21000 for t in time_slots), name = "Boiler_capacity")
有人可以帮助我理解问题吗?。