Splitting _ampl_elapsed_time

33 views
Skip to first unread message

Peter Greistorfer

unread,
May 11, 2018, 6:33:20 AM5/11/18
to AMPL Modeling Language
Hello all!

Please consider the following run-file-pseudo-code:

reset;
model LP.mod;
for {run = 1..10} {
  reset data;
  data <instance number run>;
  solve;
  <write instance number run, ..., _ampl_elapsed_time, _solve_elapsed_time to a results-file>
}

Among other instance-specific results, this gives me a line for each instance holding the AMPL- and CPLEX-time. The CPLEX-time is correct, because it's automatically reset at any solve, however AMPL's elapsed time is - logically - cumulative.

How can I get the instance-specific _ampl_elapsed_time into an instance's results line?

I've tried really hard, but ... The problem is that I need to store the cumulative _ampl_elapsed_time of run (i-1) to to get the specific elapsed time at iteration i, but any storage at (i-1) becomes deleted by the next reset data ...

Thanks for your ideas!

AMPL Google Group

unread,
May 11, 2018, 3:14:37 PM5/11/18
to Ampl Modeling Language
You can save the the run time of i-1 and calculate the run time of ith solve time. You should use reset data <comma separated parameter list>; instead of reset data; so that you could selectively reset the parameters. Alternatively, you could do reset; instead of reset data; and redefine your model and data and _ampl_time should give you the time of ith solve.

--
Paras Tiwari
am...@googlegroups.com
{#HS:578872827-7366#}
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.



Peter Greistorfer

unread,
May 12, 2018, 1:48:54 PM5/12/18
to AMPL Modeling Language
Hi, Paras, thanks but ...

(1) reset data <comma separated parameter list> appears to be a good idea in cases when there are not that many parameters to be treated ... nice would have been a feature reset data <exception list>, where exception list would always hold a variable with AMPL-time from run (i-1) ...

(2) Tried your second idea - and it didn't work: if I have a sequence reset/model<>/data<> within the loop, then the reset instantly destroys the loop-index (called run in my example).

Anyway, we'll find a solution - have a nice weekend.

AMPL Google Group

unread,
May 12, 2018, 9:22:27 PM5/12/18
to Ampl Modeling Language
One possibility is to write

update data;
data <instance number run>;

The "update data" statement does not reset any data, but it lets the subsequent data statement read values to replace the current values of params. Using update data rather than reset data can work if the sets stay the same, or if members are added to the sets from one solve to the next, but not if the sets are changing more generally.

Alternatively, to save a single value so that it is not affected by reset data, an option can be used. For example,

option previous_time (_ampl_elapsed_time);
for {run in 1..10} {

reset data;
data <instance number run>;
solve;
print _ampl_elapsed_time - num($previous_time);
option previous_time (_ampl_elapsed_time);
}

--
Paras Tiwari
am...@googlegroups.com
{#HS:578872827-7366#}
On Sat, May 12, 2018 at 5:49 PM UTC, Ampl Modeling Language <am...@googlegroups.com> wrote:
Hi, Paras, thanks but ...

(1) reset data <comma separated parameter list> appears to be a good idea in cases when there are not that many parameters to be treated ... nice would have been a feature reset data <exception list>, where exception list would always hold a variable with AMPL-time from run (i-1) ...

(2) Tried your second idea - and it didn't work: if I have a sequence reset/model<>/data<> within the loop, then the reset instantly destroys the loop-index (called run in my example).

Anyway, we'll find a solution - have a nice weekend.



On Fri, May 11, 2018 at 7:14 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
You can save the the run time of i-1 and calculate the run time of ith solve time. You should use reset data <comma separated parameter list>; instead of reset data; so that you could selectively reset the parameters. Alternatively, you could do reset; instead of reset data; and redefine your model and data and _ampl_time should give you the time of ith solve.

--
Paras Tiwari
am...@googlegroups.com


Peter Greistorfer

unread,
May 13, 2018, 4:57:27 PM5/13/18
to AMPL Modeling Language
Your option made my day - thank you very much!
Reply all
Reply to author
Forward
0 new messages