Skip to main content

How do I set multiple termination criteria for a model?



  • Preethi Ramanujam

    This code raises an exception if the first solution is obtained after the timeLimit. This is because once the first solution is found, the m.Params.TimeLimit is adjusted.  

    m.Params.TimeLimit = timeLimit - m.getAttr(GRB.Attr.Runtime)

    If the Runtime is already over the timeLimit, then it raises the exception:

    Caught: Unable to set parameter TimeLimit to value -28.9511 (minimum is 0)

    For it to work, the code needs to be adjusted to say

    m.Params.TimeLimit = max(0, timeLimit - m.getAttr(GRB.Attr.Runtime))
  • Yuriy Zinchenko
    Gurobi Staff

    Note it is highly unlikely that the runtime will exceed the TimeLimit, as the said TimeLimit value has already been used as one of the termination criterion.  However, indeed, in some corner cases this may happen. A simple way to address this is to add 'max' clause as suggested, but you may also want to build out some more logic here to understand what exactly happened.  Thank you for pointing this out.


Article is closed for comments.