Running consecutive optimizations on the same model
AnsweredWhat exactly happens when I construct a model, run an optimization, then change the parameters, and run the optimization again?
Does the second run learn from the first run and start where it left off? or does it start from scratch and would try the same combinations that were found unsuccessful or infeasible by run 1?
-
Hi,
Gurobi will continue optimization from where it left off in the first run with the change in the parameters. For example, the following script reading the "glass4.mps" model, which we distribute with the Gurobi installation,
import gurobipy as gp
m = gp.read("glass4.mps")
m.params.TimeLimit=1
m.optimize()
m.params.heuristics=0.8
m.params.TimeLimit=2
m.optimize()produces the following log that shows the second run continues optimization from the last node of the previous run.glass4: 396 rows, 322 columns, 1815 nonzeros
Set parameter TimeLimit to value 1
Gurobi Optimizer version 10.0.3 build v10.0.3rc0 (win64)
[...]
Explored 8190 nodes (35843 simplex iterations) in 1.01 seconds (0.52 work units)
Thread count was 16 (of 16 available processors)
Solution count 10: 1.80001e+09 1.80001e+09 1.80002e+09 ... 1.90002e+09
Time limit reached
Best objective 1.800014350000e+09, best bound 8.000040048387e+08, gap 55.5557%
Set parameter Heuristics to value 0.8
Set parameter TimeLimit to value 2
Gurobi Optimizer version 10.0.3 build v10.0.3rc0 (win64)
[ ...]
Continuing optimization...
H 8190 4981 1.800014e+09 8.0000e+08 55.6% 4.3 1s
8190 4981 1.0000e+09 34 53 1.8000e+09 8.0000e+08 55.6% 4.3 1s
[...]Best regards,Simran1 -
What does parameter Heuristics do?
Also, can I write any model as .mps too?
And thanks for answering my original question.
0 -
Hi,
Gurobi runs a range of heuristics to find feasible solutions while solving a model. The Heuristics parameter defines the fraction of total runtime that can be used for running heuristics during a solve.
Yes, once a model is constructed, it can be exported to an MPS file, for example, by using model.write('mymodel.mps') in Python.
Best regards,
Simran0
Please sign in to leave a comment.
Comments
3 comments