m.Runtime
AnsweredHi, I have a question and I appreciate your help.
When I ask gurobi to print the Runtime after solving the model, the run time it shows is much less than the actual time it takes. Then, I put a time.time() before and after my gurobi model, and then calculate their difference. The m.Runtime is about 1.5 minutes, but the time I get by the second method is around 50 minutes.
I want to know what is m.Runtime exactly? and which time should I report to my paper as model solving time? The m.Runtime or the second approach time?
Thank you.
-
Hi Monir,
The Runtime is the time used by Gurobi to solve the problem. It does not include model-building time (adding the variables, constraints, etc.).
Where exactly do you start and end your manual timing? If you do this immediately before and after Model.optimize(), the number should be virtually the same as the Runtime.
It sounds like you start the timing much earlier than this, so that the model-building time is included in the total. If this is the case, the model-building code takes nearly 50 minutes. This is much longer than is reasonable and suggests that the model-building code is very inefficient.
Thanks,
Eli
0 -
Hi Eli,
Can I print runtime interactively "as" the code running? Assume I set a time limit of 5*60 and want to see how much time left or passed interactively.
Regards,
Serhan
0 -
By default, Gurobi displays output showing how long it has been solving the model. You can control Gurobi's output with the LogFile, LogToConsole, and OutputFlag parameters.
Alternatively, you could write a callback function to track elapsed time. For example, the following Python code uses a callback function to periodically print how much solve time has elapsed:
import time
import math
import gurobipy as gp
from gurobipy import GRB
m = gp.read("/Users/towle/examples/glass4.mps")
# Periodically print elapsed time
def callback(model, where):
if where == GRB.Callback.POLLING and time.time() > m._nextupdate:
elapsed = time.time() - model._starttime
print(f"{elapsed:.2f} seconds have elapsed")
model._nextupdate += math.ceil(time.time() - m._nextupdate)
m._starttime = time.time()
m._nextupdate = m._starttime + 1
m.optimize(callback=callback)The output:
Gurobi Optimizer version 10.0.2 build v10.0.2rc0 (mac64[arm])
CPU model: Apple M1 Pro
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads
Optimize a model with 396 rows, 322 columns and 1815 nonzeros
Model fingerprint: 0x18b19fdf
Variable types: 20 continuous, 302 integer (0 binary)
...
H 3154 1626 1.658348e+09 8.0000e+08 51.8% 5.4 0s
H 4313 1951 1.650014e+09 8.0000e+08 51.5% 4.7 0s
H 4328 1889 1.633347e+09 8.0000e+08 51.0% 4.7 0s
H 4369 1856 1.633347e+09 8.0000e+08 51.0% 4.8 0s
1.01 seconds have elapsed
*17525 10038 49 1.600015e+09 8.0000e+08 50.0% 4.1 1s
*17528 10036 51 1.600015e+09 8.0000e+08 50.0% 4.1 1s
2.00 seconds have elapsed
H29208 16070 1.600014e+09 8.0000e+08 50.0% 4.2 2s
H29226 15277 1.600014e+09 8.0950e+08 49.4% 4.2 2s
H29227 14514 1.600014e+09 8.0950e+08 49.4% 4.2 2s
H29227 13788 1.525014e+09 8.0950e+08 46.9% 4.2 2s
H29229 13099 1.525013e+09 8.0950e+08 46.9% 4.2 2s
3.00 seconds have elapsed
4.00 seconds have elapsed
5.00 seconds have elapsed
29375 13200 1.4000e+09 57 110 1.5250e+09 9.0001e+08 41.0% 4.3 5s
*29809 12707 75 1.500017e+09 9.0001e+08 40.0% 4.5 5s
*29814 12077 77 1.500017e+09 9.0001e+08 40.0% 4.5 5s
*29988 11597 77 1.500016e+09 9.0001e+08 40.0% 4.6 5s
*30148 11043 102 1.500015e+09 9.0001e+08 40.0% 4.6 5s
*30149 10505 102 1.500015e+09 9.0001e+08 40.0% 4.6 5s
H30221 9902 1.483349e+09 9.0001e+08 39.3% 4.7 5s
*31231 9640 94 1.450015e+09 9.0001e+08 37.9% 5.1 5s
6.00 seconds have elapsed
H31341 9115 1.400014e+09 9.0001e+08 35.7% 5.1 6s
...0 -
Thank you for your response. I haven't implemented it yet but hope I can use the this func in LogToConsole = 0 mode which is what I normally do (I just print stuff like status, objval, runtime, etc. once the model has been solved). Thanks again.
0
Please sign in to leave a comment.
Comments
4 comments