Python PULP 不支持的操作数类型类型错误

Python PULP Unsupported Operand Type(s) TypeError

我正在尝试在 PULP 中设置一些特定的约束,但感觉好像遗漏了一些简单的东西。所有的问题都是一样的TypeError,showing UNSUPPORTED OPERAND between 'generator' and int or continuous.

我尝试了各种解决方案,提供了我的代码,但不起作用。

YPER = 365
HE = 24

yearlyhours = [(i,j) for i in range(YPER) for j in range(HE)]

YAHL = pulp.LpVariable.dicts('YAHL', yearlyhours, lowBound=0, cat='Continuous')
YALL = pulp.LpVariable.dicts('YALL', yearlyhours, lowBound=0, cat='Continuous')
YAHLINT = pulp.LpVariable.dicts('YAHLINT', yearlyhours, lowBound=0, cat='Integer')
YAHLBIN = pulp.LpVariable.dicts('YAHLBIN', yearlyhours, lowBound=0, cat='Binary')

model += pulp.lpSum([YAHLINT[(i,j)] for i in range(YPER) for j in range(HE) if j >= 7 and j <= 22]) == (YAHL[i][j] for i in range(YPER) for j in range(HE) if j >= 7 and j <= 22) / 25

model += pulp.lpSum([YAHL[(i,j)] for i in range(YPER) for j in range(HE) if j >= 7 and j <= 22]) >= 0 * (YAHLBIN[i][j] for i in range(YPER) for j in range(HE) if j >= 7 and j <= 22)

TypeError:/ 的操作数类型不受支持:'generator' 和 'int'

TypeError:* 不支持的操作数类型:'int' 和 'generator'

您在这里使用 generator expression:

(YAHL[i][j] for i in range(YPER) for j in range(HE) if j >= 7 and j <= 22)

我想这不是你真正想要的。

你应该根据你的目标改变

例如,

== pulp.lpsum([YAHL[i][j] for i in range(YPER) for j in range(HE) if j >= 7 and j <= 22])