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

classify decision variables according their value in the user callback

回答済み

コメント

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?.
  • Jaromił Najman
    • Gurobi Staff

    Hi Amir,

    You can access only the \(y\) variables via the cbGetSolution function. To achieve this, you will have to define them as a private model variable

    import gurobipy as gp
    from gurobipy import GRB

    def myCallback(model, where):
    if where == GRB.Callback.MIPSOL:
    # get values of the y variables only
    yvals = model.cbGetSolution(model._yvars)
    print(yvals)
    # do something with the values of y variables

    m = gp.Model("myModel")
    x = m.addVars(3, 3, vtype = GRB.BINARY, name="x")
    y = m.addVars(3, 3, 3, vtype = GRB.BINARY, name="y")

    # construct model
    # [...]

    # define the y variables as a private model variable
    # to get access to them in the callback
    m._yvars = y

    m.optimize(myCallback)

    Best regards,
    Jaromił

    0

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