Python PULP 不支持的操作类型 (s) TypeE

2024-09-25 06:23:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在PULP中设置一些特定的约束,感觉好像我错过了一些简单的东西。所有问题都是相同的TypeError,显示“generator”和int或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”的操作数类型


Tags: andinforifrangepulpcathe