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

How to distinguish between branching-solutions and heuristic-solutions inside a MIP callback?

回答済み

コメント

4件のコメント

  • 正式なコメント
    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

    Dear Jonathan,

    It is not possible to get the information whether a solution has been found via a heuristic or branching. Currently, the best way is to use the MESSAGE callback to scan the printed LOG message for 'H' and '*' as you already suggested.

    Best regards,
    Jaromił

    1
  • Jonathan Helgert
    • Gurobi-versary
    • First Question
    • First Comment

    Hi Jaromił,

    thanks a lot for the hint with the MESSAGE callback! For anyone who stumbles across this post, here's how it works (Python >= 3.8 required):

    def logIncumbents(model, where):
    # MIP solution callback
    if where == GRB.Callback.MIPSOL:
    if hasattr(model, '_IncObjVal'):
    model._IncObjVal += [model.cbGet(GRB.Callback.MIPSOL_OBJ)]
    model._IncRuntime += [model.cbGet(GRB.Callback.RUNTIME)]
    else:
    model._IncObjVal = [model.cbGet(GRB.Callback.MIPSOL_OBJ)]
    model._IncRuntime = [model.cbGet(GRB.Callback.RUNTIME)]
    if where == GRB.Callback.MESSAGE:
    if (c := model.cbGet(GRB.Callback.MSG_STRING)[0]) in ['H', '*']:
    if hasattr(model, '_IncFoundBy'):
    model._IncFoundBy += c
    else:
    model._IncFoundBy = c

     

    Best, Jonathan

    1
  • Jose Vindel
    • Gurobi-versary
    • Thought Leader
    • Investigator

    Hello Jonathan,

    I came across your solution, I find it quite useful. I would like to ask you, in your script. the variable:

    model._IncObjVal

    is where you update the value of the incumbent. Is that correct? I would like to update my incumbent value as well with the best current obj value but I am still struggling with how to set up the initial value. Can you query the value from the model attributes?

    0

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