Skip to main content

Force Gurobi to ignore timelimit until one feasible solution is found

Answered

Comments

2 comments

  • Silke Horn
    Gurobi Staff Gurobi Staff

    This can already be done by using callbacks. The callback examples on our website demonstrate how to implement a custom termination strategy: https://www.gurobi.com/resource/functional-code-examples/

     

    1
  • Gwyneth Butera
    Gurobi Staff Gurobi Staff

    As an alternative solution to Silke's suggestion of callbacks, you can also try something like the following Python sample:

    timeLimit = 20
    try:
    m = read('b1c1s1.mps.gz')
    oldSolutionLimit = m.Params.SolutionLimit
    m.Params.SolutionLimit = 1
    m.optimize()
    m.Params.TimeLimit = timeLimit - m.getAttr(GRB.Attr.Runtime)
    m.Params.SolutionLimit = oldSolutionLimit - m.Params.SolutionLimit
    m.optimize()
    except (GurobiError, AttributeError, Exception) as e:
    print('Caught: ' + e.message)

     

    2

Please sign in to leave a comment.