Skip to main content

timelimit option

Answered

Comments

7 comments

  • Gurobot (AI-generated response)
    Gurobi Staff Gurobi Staff

    The code snippet you've provided seems correct for setting a time limit when using Gurobi with AMPL. The option timelimit=7200 should indeed set a limit of 7200 seconds (2 hours) for each optimization instance. If it's not functioning as expected, there are a few potential issues to consider:

    1. Instance Reset: Ensure that the time limit is being correctly applied to each individual instance. If you're running multiple instances in a loop or batch, the time limit needs to be reset or reaffirmed for each instance.

    2. AMPL Environment: Double-check the environment in which you are running AMPL. Make sure that the version of AMPL and Gurobi you're using are compatible and correctly configured.

    3. Gurobi License and Configuration: Verify that your Gurobi license is valid and that there are no other configuration issues that might be overriding or affecting the timelimit setting.

    4. Problem Complexity: Consider the complexity of the instances. If the problems are very simple, Gurobi might solve them so quickly that the time limit does not come into play. Conversely, if the problems are extremely complex, Gurobi might reach a stopping criterion other than the time limit (like reaching the specified mipgap or due to other limits).

    5. Gurobi Log: Check the Gurobi log for each instance to see if there are any messages related to the time limit. The log might provide clues about whether the time limit is being recognized and what's happening when it's reached.

    0
  • Robert Fourer
    Collaborator
    Gurobi-versary

    That is a correct way to set the Gurobi time limit, and it's verified to be working with Gurobi 11.0 for AMPL. To be sure you are using it correctly, look for timelimit=7200 or lim:time=7200 in AMPL's Gurobi log output. If you don't see one of these, you can display the actual value of gurobi_options by running again with the AMPL command "option gurobi_options;" right before "solve;".

    If the setting of the time limit checks out, then can you explain in more detail how the Gurobi time limit is functioning, and why that's not as expected? 

    0
  • Saravanan Kuppusamy
    First Comment
    First Question

    Thank you so much for the quick response. 

    I used the following code: 

    option gurobi_options 'timelimit=100 outlev=1 mipgap=0 mipfocus=3';
    option gurobi_options 'logfile=C:\AMPL\2023_01_29\Replication01\logfile.temp'; 
    option log_file 'C:\AMPL\2023_01_29\Replication01\logfile.temp';
    solve;

    I set the time limit to 100 seconds for testing purposes, but the solver continued running beyond that limit, forcing me to interrupt it. Therefore, it is still not functioning as expected. Please let me know if there are any corrections needed in the code.

    The following is the information from the log file:

    ampl: model C:\AMPL\2023_01_29\Replication01\2024_03_03_ModelFile_No_Loop.mod;

    Gurobi 11.0.0 (win64) logging started Wed Mar  6 17:59:19 2024

    Set parameter LogFile to value "C:\AMPL\2023_01_29\Replication01\logfile.temp"
    Set parameter InfUnbdInfo to value 1
    Gurobi Optimizer version 11.0.0 build v11.0.0rc2 (win64 - Windows 10.0 (19045.2))

    CPU model: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz, instruction set [SSE2|AVX|AVX2]
    Thread count: 4 physical cores, 8 logical processors, using up to 8 threads

    Optimize a model with 5620 rows, 3051 columns and 136173 nonzeros
    Model fingerprint: 0xbac440c9
    Variable types: 201 continuous, 2850 integer (0 binary)
    Coefficient statistics:
      Matrix range     [1e+00, 6e+00]
      Objective range  [1e+00, 3e+03]
      Bounds range     [1e+00, 2e+05]
      RHS range        [1e+00, 1e+00]
    Using branch priorities (all 0).
    Found heuristic solution: objective 150000.00000
    Presolve removed 4365 rows and 276 columns
    Presolve time: 0.19s
    Presolved: 1255 rows, 2775 columns, 20571 nonzeros
    Variable types: 0 continuous, 2775 integer (2719 binary)

    Root relaxation: objective 2.500000e+01, 1416 iterations, 0.03 seconds (0.04 work units)

        Nodes    |    Current Node    |     Objective Bounds      |     Work
     Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

         0     0   25.00000    0   67 150000.000   25.00000   100%     -    0s
    H    0     0                    3036.0000000   25.00000  99.2%     -    0s
    H    0     0                      42.0000000   25.00000  40.5%     -    0s
    H    0     0                      40.0000000   25.00000  37.5%     -    0s
    H    0     0                      33.0000000   25.00000  24.2%     -    0s
         0     0   25.00000    0  179   33.00000   25.00000  24.2%     -    0s
    H    0     0                      32.0000000   25.00000  21.9%     -    0s
    H    0     0                      31.0000000   25.00000  19.4%     -    0s
         0     0   25.00000    0   51   31.00000   25.00000  19.4%     -    0s
         0     0   25.00000    0  100   31.00000   25.00000  19.4%     -    0s
    H    0     0                      30.0000000   25.00000  16.7%     -    0s
         0     0   25.00000    0   66   30.00000   25.00000  16.7%     -    1s
         0     0   25.00000    0  135   30.00000   25.00000  16.7%     -    1s
    H    0     0                      28.0000000   25.00000  10.7%     -    1s
         0     0   25.00000    0   63   28.00000   25.00000  10.7%     -    1s
         0     0   25.00000    0   63   28.00000   25.00000  10.7%     -    1s
         0     2   25.00000    0   63   28.00000   25.00000  10.7%     -    1s
       490   307   25.00000   27  119   28.00000   25.00000  10.7%   148    5s
      2060  1090   26.00000   46   70   28.00000   25.00000  10.7%  96.6   10s
      3840  1312   25.87500   42   86   28.00000   25.00000  10.7%  97.2   17s
      3862  1382   25.87500   43   90   28.00000   25.00000  10.7%  97.6   20s
      8784  3562   26.00000   56   85   28.00000   25.00000  10.7%  75.1   27s
     11848  5067   26.00000   76   88   28.00000   25.00000  10.7%  75.1   30s
     13108  5129   26.00000   42   72   28.00000   25.00000  10.7%  73.4   35s
     17547  7511     cutoff   44        28.00000   25.00000  10.7%  73.3   44s
     17851  8025     cutoff   38        28.00000   25.00000  10.7%  73.6   45s
     19255  8563   26.28376   78  128   28.00000   25.00000  10.7%  74.8   50s
     24019 11146   26.66667   61   32   28.00000   25.00000  10.7%  76.1   55s
     30054 14593   25.00000   70  103   28.00000   25.00000  10.7%  73.8   68s
     32413 14594   26.00000   62  103   28.00000   25.00000  10.7%  73.0   76s
     35783 16897   26.00000   50   46   28.00000   25.00000  10.7%  71.7   80s
     40976 19210   27.00000   32   27   28.00000   25.00000  10.7%  72.5   88s
     42314 20340   26.00000   72   18   28.00000   25.00000  10.7%  72.9   90s
     47435 22558   25.22222   93   66   28.00000   25.00000  10.7%  73.4   95s
     52079 24566   27.00000   72   67   28.00000   25.00000  10.7%  74.6  100s
     57191 27072   27.00000   36   82   28.00000   25.00000  10.7%  75.3  105s
     60873 29117   25.00000   33   76   28.00000   25.00000  10.7%  75.8  110s
     65007 31139   27.00000   44   65   28.00000   25.00000  10.7%  77.6  115s
     69001 32582   25.33333   41  165   28.00000   25.00000  10.7%  78.2  124s
     69296 33163   26.00000   42  113   28.00000   25.00000  10.7%  78.3  125s
     70625 33387   26.12000   83   73   28.00000   25.00000  10.7%  78.5  131s
     73322 35272     cutoff   40        28.00000   25.00000  10.7%  78.9  136s
     76051 36623   26.00000   54   79   28.00000   25.00000  10.7%  79.5  140s
     79738 38560   25.07242   35  112   28.00000   25.00000  10.7%  80.0  145s
     80955 38641     cutoff   42        28.00000   25.00000  10.7%  80.3  153s
     81151 39297     cutoff   55        28.00000   25.00000  10.7%  80.3  155s
     85169 41709   27.00000  101   35   28.00000   25.00000  10.7%  80.8  160s
     89310 43775   26.00000   61  120   28.00000   25.00000  10.7%  80.4  165s
     93365 45836     cutoff   75        28.00000   25.00000  10.7%  80.6  170s
     96880 47940   26.00000   60   35   28.00000   25.00000  10.7%  80.7  175s
     98768 49046   26.00000   45   55   28.00000   25.00000  10.7%  80.4  180s
     103461 51606   25.17647   72   75   28.00000   25.00000  10.7%  79.9  185s
     104830 51949     cutoff   49        28.00000   25.00000  10.7%  79.8  191s
     105452 55120     cutoff   50        28.00000   25.00000  10.7%  79.8  197s
     112547 56136   25.02427   56   78   28.00000   25.00000  10.7%  78.7  200s
     117465 58233   27.00000   72  102   28.00000   25.00000  10.7%  78.6  206s
     118735 58341   26.00000   75   68   28.00000   25.00000  10.7%  78.5  217s
     118920 58420   26.50000   98   67   28.00000   25.00000  10.7%  78.6  222s
     120481 60031   25.00000   67  117   28.00000   25.00000  10.7%  78.5  225s
     125731 61921     cutoff   47        28.00000   25.00000  10.7%  78.5  230s
     130745 64169   25.40625   70  117   28.00000   25.00000  10.7%  78.5  236s
     135598 66321   26.45455   98   57   28.00000   25.00000  10.7%  78.5  242s
     139813 67880   26.75000   71   67   28.00000   25.00000  10.7%  78.3  245s
     144289 70071     cutoff   63        28.00000   25.00000  10.7%  78.5  250s
     148923 72174   25.50000   64  115   28.00000   25.00000  10.7%  78.5  256s
     152857 74075   27.00000   47  109   28.00000   25.00000  10.7%  78.6  260s
     157594 75672   26.00000   60   53   28.00000   25.00000  10.7%  78.9  275s
     160315 77259     cutoff   62        28.00000   25.00000  10.7%  79.1  280s
     165403 79406   27.00000   73   80   28.00000   25.00000  10.7%  79.4  286s
     169432 80463   26.00000   43   68   28.00000   25.00000  10.7%  79.5  301s
     172144 82236     cutoff   55        28.00000   25.00000  10.7%  79.5  306s
     176257 84172   27.00000   92   50   28.00000   25.00000  10.7%  79.5  310s
     180049 85912     cutoff   89        28.00000   25.00000  10.7%  79.5  315s
     184022 87167   26.50769   79   81   28.00000   25.00000  10.7%  79.5  323s
     184284 88016   26.60000   80   78   28.00000   25.00000  10.7%  79.5  325s
     188426 89743   26.00000   60   62   28.00000   25.00000  10.7%  79.4  331s
     191959 91392     cutoff   52        28.00000   25.00000  10.7%  79.5  336s
     194366 92562     cutoff   86        28.00000   25.00000  10.7%  79.6  340s
     198255 94642   25.00000   62  101   28.00000   25.00000  10.7%  79.8  345s
     203564 97183   26.04688   61   62   28.00000   25.00000  10.7%  79.8  351s
     206165 97944   26.00000   55   67   28.00000   25.00000  10.7%  79.7  359s
     206415 98385   26.00000   56   82   28.00000   25.00000  10.7%  79.7  360s
     209818 99878     cutoff   57        28.00000   25.00000  10.7%  80.0  365s
     212351 100745   25.55556   72   63   28.00000   25.00000  10.7%  80.1  373s
     213648 102229   27.00000  100   34   28.00000   25.00000  10.7%  80.1  376s
     217712 104069   27.00000   69   44   28.00000   25.00000  10.7%  80.0  381s
     220860 105299     cutoff   63        28.00000   25.00000  10.7%  80.2  390s
     223788 107535   26.00000   55   54   28.00000   25.00000  10.7%  80.1  395s
     228404 109842   27.00000  107   75   28.00000   25.00000  10.7%  80.0  400s
     232557 111962   27.00000   68   23   28.00000   25.00000  10.7%  80.0  406s
     233664 112349   26.00000   80   65   28.00000   25.00000  10.7%  80.0  415s
     236927 114156     cutoff  120        28.00000   25.00000  10.7%  80.0  420s
     240605 116308   25.53643   50  117   28.00000   25.00000  10.7%  80.2  425s
     244884 118263     cutoff   89        28.00000   25.00000  10.7%  80.1  431s
     248630 120150   26.83333   49   81   28.00000   25.00000  10.7%  80.0  435s
     253612 122524     cutoff   90        28.00000   25.00000  10.7%  79.8  441s
     256816 124450   27.00000   82   66   28.00000   25.00000  10.7%  79.9  445s
     260735 126476   27.00000   85   48   28.00000   25.00000  10.7%  79.8  450s
     262118 126484   26.00000   58   69   28.00000   25.00000  10.7%  79.8  462s
     262126 126543   26.00000   59   41   28.00000   25.00000  10.7%  79.8  467s
     263772 127967   25.00000   52   60   28.00000   25.00000  10.7%  79.8  471s
     267565 129558   25.08387   59  114   28.00000   25.00000  10.7%  79.7  475s
     271368 131690     cutoff   86        28.00000   25.00000  10.7%  79.7  480s

    Cutting planes:
      Gomory: 11
      Projected implied bound: 25
      MIR: 76
      StrongCG: 24
      Flow cover: 287
      Zero half: 205
      Relax-and-lift: 192

    Explored 273599 nodes (21843918 simplex iterations) in 482.24 seconds (408.41 work units)
    Thread count was 8 (of 8 available processors)

    Solution count 9: 28 30 31 ... 150000

    Solve interrupted
    Best objective 2.800000000000e+01, best bound 2.500000000000e+01, gap 10.7143%



    0
  • Robert Fourer
    Collaborator
    Gurobi-versary

    You are setting gurobi_options twice:

    option gurobi_options 'timelimit=100 outlev=1 mipgap=0 mipfocus=3';
    option gurobi_options 'logfile=C:\AMPL\2023_01_29\Replication01\logfile.temp'; 

    The second statement resets gurobi_options to 'logfile=C:\AMPL\2023_01_29\Replication01\logfile.temp', so all of the options set by the first statement are lost. Instead, use one AMPL option statement to specify all of the options for Gurobi. To avoid having a very long line, you can specify more than one option string, and they will be concatenated:

    option gurobi_options 
    'timelimit=100 outlev=1 mipgap=0 mipfocus=3 '
    'logfile=C:\AMPL\2023_01_29\Replication01\logfile.temp';

    Be sure to put a space at the end of the first string (as shown) or at the beginning of the second string.

    1
  • Saravanan Kuppusamy
    First Comment
    First Question

    You are correct. It is working now. Thank you so much, and I appreciate the quick responses. 

    0
  • ALESSANDRO BOSCHETTI
    First Comment

    Hello, I am using this code and I need the _ampl_elapsed_time + _total_solve_elapsed_time to be between 300 and 600 seconds. How can I do that?

     

    # ----------------------------------------

    # GILMORE-GOMORY METHOD FOR

    # CUTTING STOCK PROBLEM

    # ----------------------------------------

    reset;

    option solver gurobi;

    model cut_1_A.mod;

    data cut_1_A.dat;

     

     

    #definizione del problema Cutting_Opt

    #NB: rilassamento del vincolo di interezza delle variabili

    problem Cutting_Opt: Cut, Number_Cut, Fill_Orders;

    option relax_integrality 1;

    #definizione del problema Pattern_Gen

    problem Pattern_Gen: Use, Reduced_Cost, Width_Limit;

    option relax_integrality 0;

     

    # Variabili e parametri per il metodo Gilmore-Gomory

    let nPAT := 0;

    for {i in FINALTYPES} {

    let nPAT := nPAT + 1;

    let nbr[i,nPAT] := floor(roll_width/width[i]);

    let {i2 in FINALTYPES: i2 <> i} nbr[i2,nPAT] := 0;

    };

    param tt;

    let tt := 0;

    repeat {

    solve Cutting_Opt;

    print Number_Cut;

    let tt := tt + _total_solve_elapsed_time;

    let {i in FINALTYPES} price[i] := Fill_Orders[i].dual;

    solve Pattern_Gen;

    let tt := tt + _total_solve_elapsed_time;

    if Reduced_Cost > 0.00001 then {

    let nPAT := nPAT + 1;

    let {i in FINALTYPES} nbr[i,nPAT] := Use[i];

    }

    else break;

    };

    # Opzioni per la visualizzazione dei risultati

    option display_width 1000;

    display nbr;

    option display_width 132;

    display Cut;

    display nPAT;

    print Number_Cut;

    print "Tempo di esecuzione:";

    display _ampl_elapsed_time + _total_solve_elapsed_time;

     

    0
  • Robert Fourer
    Collaborator
    Gurobi-versary

    You seem to be asking a new question about time limits, which is only indirectly related to the previous posts in this thread. Also, your question is more about how to use AMPL than how to use Gurobi. Thus I recommend submitting your question instead to the AMPL forum at https://discuss.ampl.com.

    0

Please sign in to leave a comment.