Skip to main content

model.addVars

Answered

Comments

3 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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.
  • Jonasz Staszek
    • Community Moderator
    • Gurobi-versary
    • Thought Leader
    • First Question

    You can do that by looping over both your lists:

    x = gp.tupledict()
    for l in L:
    for r in R:
    x[l,r] = m.addVar(vtype="B", name=f"x_{l}{r}")

    The reasons why your code doesn't work can be found here.

    Hope this helps.

    Best regards
    Jonasz

    0
  • Riley Clement
    • Gurobi Staff

    You can also appeal to itertools.product to create a single index set, but this will run a bit slower than the solution from Jonasz

    import itertools
    x = m.addVars(itertools.product(R,L), vtype="B", name="x_")

     - Riley

    0

Post is closed for comments.