Skip to main content

Force Gurobi to ignore timelimit until one feasible solution is found

Answered

Comments

3 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?.
  • 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

Post is closed for comments.