Skip to main content

Limit solutions for an LP

Answered

Comments

8 comments

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    It is currently not possible to get an intermediate point of the Simplex (or Barrier) solution process.

    If the objective value only is enough in your case, then you can tell Gurobi to stop as soon as an iterate gets primal feasible and retrieve the last objective value in a callback. This would look similar to this:

    import gurobipy as gp
    from gurobipy import GRB

    def simplexcallback(model,where):
      if where == GRB.Callback.SIMPLEX:
          vio = model.cbGet(GRB.Callback.SPX_PRIMINF)
          if vio < 1e-6:
            print(model.cbGet(GRB.Callback.SPX_OBJVAL))
          print("Reached primal feasibility")
            model.terminate()

    m = gp.read("myLP.lp")

    m.setParam("Method",0)

    m.optimize(simplexcallback)

    Best regards, 
    Jaromił

    0
  • Zohar Levi

    I see, thanks, but I need a solution to terminate prematurely.

    I'll just note that the simplex algo. has a theoretical exponential complexity, and maybe my request isn't so far fetched.

    For future reference, soplex is an established open source, and it has a parameter to control the iteration limit.

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    For future reference, soplex is an established open source, and it has a parameter to control the iteration limit.

    Please note that there is the IterationLimit parameter, which controls the maximum number of iterations for Simplex algorithms.

    0
  • Zohar Levi

    And what happens if I stop it prematurely?

    Let's try again. This is my objective:

    https://math.stackexchange.com/questions/4510587/find-a-feasible-but-not-optimal-solution-to-a-large-lp

    Can I specify a warm-start, use the primal simplex, terminate it early and get a better feasible solution?

    Your python callback, how do I specify it in matlab?

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Can I specify a warm-start, use the primal simplex, terminate it early and get a better feasible solution?

    If you terminate the Simplex algorithm early, due to,e.g., the IterationLimit or TimeLimit parameter, you will not be able to retrieve the current Simplex candidate (let it be feasible or not) from Gurobi. Thus, I don't think that there is any other option for you here except to let Simplex run till optimality.

    Your python callback, how do I specify it in matlab?

    Unfortunately, Gurobi's MATLAB interface does not support callbacks.

    0
  • Zohar Levi

    Okay, thanks.

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Here is an update and a correction to my last statement.

    If you terminate the Simplex algorithm early, due to,e.g., the IterationLimit or TimeLimit parameter, you will not be able to retrieve the current Simplex candidate (let it be feasible or not) from Gurobi. Thus, I don't think that there is any other option for you here except to let Simplex run till optimality.

    You can access the current Simplex candidate but you have to run the Simplex algorithm with presolve turned off, i.e., set Presolve=0.

    Note that solving models without presolve can impact performance drastically.

    0
  • Zohar Levi

    It works, thanks.

    0

Please sign in to leave a comment.