Skip to main content

How to terminate gurobi solver?

Answered

Comments

3 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • 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

Post is closed for comments.