メインコンテンツへスキップ

TypeError: 'TempConstr' object is not iterable (on line 3)

回答済み

コメント

1件のコメント

  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    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

サインインしてコメントを残してください。