TypeError: 'TempConstr' object is not iterable (on line 3)
回答済みfor k in range(1, 2*n):
for y,z in zip(range(max(0, k-n), min(n, k)),range(min(n, k)-1, max(0, k-n)-1, -1)):
name4 = model.addConstr(quicksum(x[y,z] == 1))
0
-
正式なコメント
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. -
The expression
x[y,z] == 1
is a constraint, in particular it's a TempConstr object. So what you are trying to do in the code snippet is to add a constraint which is a sum of constraints, which is not possible.
Maybe you mean something like
for k in range(1, 2*n):
name4 = model.addConstr(quicksum(x[y,z] for y,z in zip(range(max(0, k-n), min(n, k)),range(min(n, k)-1, max(0, k-n)-1, -1))) == 1)Note that I am only guessing here, because your code snippet is not reproducible code.
Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
2件のコメント