Skip to main content

m.Runtime

Answered

Comments

4 comments

  • Eli Towle
    Gurobi Staff Gurobi Staff

    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
  • Nadi Serhan Aydin
    Gurobi-versary
    Conversationalist
    First Question

    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
  • Eli Towle
    Gurobi Staff Gurobi Staff

    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
  • Nadi Serhan Aydin
    Gurobi-versary
    Conversationalist
    First Question

    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.