Retrieve MIP gap of final solution

1,572 views
Skip to first unread message

Vincent Brunelle

unread,
Mar 6, 2018, 5:39:48 PM3/6/18
to pyomo...@googlegroups.com
Hi everyone,

I want to log the MIP gap of solutions obtained via Pyomo. I know it can be found in the solver's log after the optimization, but I need to retrieve the MIP gap automatically. We are working on a project where we assume that the solver will be changed frequently. Since not every solver log their steps the same way, I am looking for a way that is independant of the solver used.

Does Pyomo has already a built-in way to retrieve the MIP gap value, or should I make one script per solver to do it?

Vincent

Gabriel Hackebeil

unread,
Mar 11, 2018, 3:18:52 PM3/11/18
to Pyomo Forum
If you are using the Python or LP- or MPS-file interface to Cplex or Gurobi (e.g., solver_io=‘python’, solver_io=‘lp’) you should find the absolute gap stored as results.solution.gap. However, the solution gets taken off of the results object and loaded into the model by default, so you will need to disable this by calling solve with load_solutions=False. E.g.,

results = opt.solve(model, load_solutions=False)
if len(results.solution) > 0:
    # you may need to relax these checks in certain cases
    assert str(results.solver.status) == ‘ok’
    assert str(results.solver.termination_condition) == ‘optimal'
    absgap = results.solution(0).gap
   # now load the solution
   model.solutions.load_from(results)

If you are using the AMPL interface to a solver (e.g., gurobi_ampl), the gap is often not reported by default in the standardized solution format returned by the ASL library. Sometimes you can tell solvers to return it as a suffix, which you load into the Pyomo model with the solution by adding a Suffix component to the model before the solve. See the ‘return_mipgap’ command-line option for gurobi_ampl as an example.

Gabe

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages