Skip to main content

Is there any method to reduce cpu time in callback function ?

Answered

Comments

4 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff 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 Gurobi Staff

    Hi Canqi Yao,

    Your callback has been called 1894330 times for a total of 362.67 seconds. This makes it roughly to 0.19 milliseconds per callback, which is not too much. What you could try is to reduce the number of values which you have to re-calculate and pre-calculate them outside of the callback.
    If the values of

    N = model._coeff[0]
    K = model._coeff[1]

    are fixed, then you could pre-calculate most of the objects and values you use in the callback and then acces them, e.g., via

    model._someValue

    Best regards,
    Jaromił

    0
  • Canqi Yao
    Gurobi-versary
    Conversationalist
    Curious

    Hi Jaromił

    Apart from reducing time in callback function, can we decrease the number of calling callback function by choosing some nodes with callback function added? 

    Best

    Canqi

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi Canqi,

    You cannot directly choose the nodes where the callback is being called or not being called, as the callback \(\texttt{MIPNODE}\) is always called whenever a mip node is explored within the B&B algorithm.

    You could implement a counter, and only compute a cut at every n-th call. You could also check the MIPNODE_NODCNT and only compute a cut whenever this value has some specific properties, e.g., is a multiple of 2 or similar.

    Best regards,
    Jaromił

    0

Post is closed for comments.