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

cbCut - Variable not in model

回答済み

コメント

2件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff 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?.
  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    It is not possible to access variables \(\texttt{gamma}\) from inside your callback, because the model at this point doesn't know them. You have to save these variables as a private model object as is done in, e.g., the tsp.py example.

    So your code should read something like

    def add_valid_cut(model, where):
    if where == GRB.Callback.MIPNODE:
    status = model.cbGet(GRB.Callback.MIPNODE_STATUS)
    if status == GRB.OPTIMAL:
    print('valid ineqaulities added')
    rel = model.cbGetNodeRel(model._gamma)
    for base in train_drone_bases:
    if rel[base, 1] > 1 - rel[base, 2]:
    print(base, 'valid cut added')
    print(model._gamma[1,1], 'gamma', model._gamma[1,2])
    model.cbCut((model._gamma[1,1] <= 1 - model._gamma[1,2]))


    model = Model("myModel")
    gamma = model.addVars(...)
    model._gamma = gamma
    [...]
    model.optimize(add_valid_cut)

    Best regards,
    Jaromił

    0

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