Skip to main content

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

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    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.
  • Jaromił Najman
    • 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

Post is closed for comments.