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

Increase the number of variable number by updating the gurobi model

回答済み

コメント

2件のコメント

  • 正式なコメント
    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 why not try our AI Gurobot?.
  • Matthias Miltenberger
    • Gurobi Staff

    Hi Taejoon!

    You can do the following to extend the existing tupledict x:

    x = m.addVars(3, vtype="B", name="x")
    m.setObjective(gp.quicksum(x), GRB.MAXIMIZE)
    [...]
    x.update({3: m.addVar(vtype="B", name="x[3]")})
    m.setObjective(gp.quicksum(x), GRB.MAXIMIZE)

    The Gurobi tupledict is just an extension of the standard Python dictionary and also supports the update() function. You just need to make sure to name the variables accordingly.

    There is no dedicated function to extend variables in the way you are describing. You also need to update the objective after extending the x tupledict. Alternatively, you could also add a 1 as objective coefficient when adding the variable in the update() call:

    x.update({3: m.addVar(vtype="B", name="x[3]", obj=1)})

     I hope that helps.

    Cheers,
    Matthias

    0

投稿コメントは受け付けていません。