Reputation: 91
I am trying to set up some specific constraint in PULP and feel like I am missing something simple. All of the issues are all the same TypeError, showing UNSUPPORTED OPERAND between 'generator' and int or continuous.
I have tried various solutions, the code that I have is provided, although does not work.
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: unsupported operand type(s) for /: 'generator' and 'int'
and
TypeError: unsupported operand type(s) for *: 'int' and 'generator'
Upvotes: 2
Views: 3053
Reputation: 11929
You are using a generator expression here:
(YAHL[i][j] for i in range(YPER) for j in range(HE) if j >= 7 and j <= 22)
I guess it's not what you really want.
You should change according to your goal
e.g.,
== pulp.lpsum([YAHL[i][j] for i in range(YPER) for j in range(HE) if j >= 7 and j <= 22])
Upvotes: 2