Skip to main content

Extracting Runtime for Root Node

Answered

Comments

3 comments

  • David Torres Sanchez
    Gurobi Staff Gurobi Staff

    Hi Elina,

    The correct syntax to obtain the runtime in a callback is:

    runtime = model.cbGet(GRB.Callback.RUNTIME)

    As shown in the Callback Codes page, this attribute is available everywhere except when \(\texttt{where}=\texttt{GRB.Callback.POLLING}\).

    Cheers, 
    David

    0
  • Elina Joksch
    Conversationalist
    Curious

    Hey David,

    thank you very much! This worked perfectly. Is it now possible to print those numbers also "in the end" to extract those numbers and compare it with different optimizations?

    Best,

    Elina

    0
  • David Torres Sanchez
    Gurobi Staff Gurobi Staff

    Hi Elina,

    Glad it worked.
    Of course, from the Python Callbacks section:

    If you would like to pass data to your callback function, you can do so through the Model object. For example, if your program includes the statement model._value = 1 before the optimization begins, then your callback function can query the value of model._value. Note that the name of the user data field must begin with an underscore.

    So, in your case, you can set \(\texttt{model._runtime}=0\) at the beginning, update that attribute in the callback, then finally query it at the end of the optimisation.

    Cheers, 
    David

    0

Please sign in to leave a comment.