Skip to main content

How to terminate gurobi solver?

Answered

Comments

2 comments

  • Jaromił Najman
    • Gurobi Staff

    Hi Hussein,

    It is not possible to retrieve the number of (discrete) variables removed by presolve during the optimization.

    However, you could implement a MESSAGE callback, where you scan for the string "Variable types" and check whether the number of integers/binaries is 0. You can then call the terminate() method from within the callback to terminate the optimization run.

    Best regards, 
    Jaromił

    1
  • Hussein Sharadga
    • Gurobi-versary
    • Investigator
    • Conversationalist

    This one now works! Thank you Jaromił Najman

            def mycallback(model, where):
              if where == GRB.Callback.MESSAGE:
                  if 'Variable types' in m.cbGet(GRB.Callback.MSG_STRING):
                      if '0 binary' in m.cbGet(GRB.Callback.MSG_STRING):
                          m.terminate()
                      
            m.optimize(mycallback)
    0

Please sign in to leave a comment.