I am solving a large MIP in Gurobi 6.0. My advisor wants to set a time limit of 12 hours on the problem. I have found that I can set the TimeLimit parameter and that will kill the solver after the alloted time, but I don't know how to retrieve the best feasible solution at that time, just the objective value and optimality gap. Is there a way to get the best feasible solution?
Asked
Active
Viewed 1,987 times
2 Answers
1
To obtain the best feasible answer so far, you should first verify that there is a feasible solution by checking the Status attribute on your model object, then querying the X
attribute on your variable objects. If you have named your variables (with the name parameter on e neat way to do it with the python api is to create a dictionary with the nonzero values.
import math
epsilon = 1e-6
m = grb.Model()
# .....
if m.SolCount > 0:
solution = {v.varName: v.X for v in m.getVars() if math.abs(v.X) > epsilon}

David Nehme
- 21,379
- 8
- 78
- 117
-2
Have you tried using the Xn
attribute, possibly in the combination with the SolutionNumber
parameter? Although for your case you should keep the default 0 value of SolutionNumber
.
You can start from here: http://www.gurobi.com/documentation/6.0/reference-manual/xn.

MMSt
- 129
- 3