cold_away
cold_away

Reputation: 33

How Can I fix "Can only add LpConstraintVar, LpConstraint, LpAffineExpression or True objects" error

Currently I have an LP model and while I'm trying to run it, the constraint

for i in DEMANDPOINT:
    prob += (lpSum(z[i][j]) == 1 for j in FACILITY5) 

causes this error to pop up.

TypeError: Can only add LpConstraintVar, LpConstraint, LpAffineExpression or True objects

How can I fix this? Thanks in advance

Upvotes: 0

Views: 700

Answers (1)

abc
abc

Reputation: 11929

You get an error because are adding to your problem a generator of constraints, where each constraint is of the form z[i][j] == 1, which is probably not what you want.

In case you are trying to add a constraint on the z variables with the sum over all the values of j for a given i must be one, then you can write it as follows.

for i in DEMANDPOINT:
    prob += lpSum(z[i][j] for j in FACILITY5) == 1

Upvotes: 2

Related Questions