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

KeyError when running TSP example (tsp.ipynb) during m.optimize(subtourelim)

回答済み

コメント

1件のコメント

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Huang,

    I suspect the error is related to the usage of model._vars.  This particular attribute name will be a problem in v12 of Gurobi.  You can avoid this by using another attribute name instead, e.g. model._myvars, but best practice would be to actually use a callback class:

    class Callback:

    def __init__(self, vars):
    self.vars = vars

    def __call__(self, model, where):
    if where == gp.GRB.Callback.MIPSOL:
    print("variables", self.vars)

    m = gp.Model()
    x = m.addVars(2, vtype="B", name="x")

    cb = Callback({"x":x})

    m.optimize(cb)

    A more full example is shown in the tsp.py example from our Example Source Code in the documentation.

    - Riley

     

     

     

     

    0

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