我正在尝试在PULP中设置一些特定的约束,并且觉得自己缺少一些简单的东西。所有问题都是相同的TypeError,显示“生成器”与int或Continuous之间的UNSUPPORTED OPERAND。
我尝试了各种解决方案,但提供了我提供的代码,尽管不起作用。
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”不支持的操作数类型
答案 0 :(得分:1)
您在此处使用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])