TypeError: 'bool' object is not iterable
AnsweredI met a problem when I worked on my homework.
The constraint I want to add is below :

And my code look like this :
case.addConstrs(
(quicksum(x[j][k] for k in range(2, K + 1))
for j in range(J) == 1), 'Each job one machine'
)
The result show up :

What is the problem in my code?
p.s I'm not sure whether my question is clear enough.
0
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
When using the addConstrs method, you have to generate a list of constraints. Thus, you have to move your last \(\texttt{for}\)-loop after the \(\texttt{== 1}\) part
case.addConstrs(
(quicksum(x[j][k] for k in range(2, K + 1))
== 1 for j in range(J)), 'Each job one machine'
)Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments