Skip to main content

model.addVars

Answered

Comments

2 comments

  • Jonasz Staszek
    Community Moderator 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 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

Please sign in to leave a comment.