Use AMPL’s reset data
command to resample from all of the random-valued functions in the model. For example, in model steel4.mod from the AMPL book, suppose that parameter avail
is changed so that its value is given by a random function:
param avail_mean {STAGE} >= 0; param avail_variance {STAGE} >= 0; param avail {s in STAGE} := Normal (avail_mean[s], avail_variance[s]);
with corresponding data
param: avail_mean avail_variance := reheat 35 5 roll 40 2 ;
Then AMPL will take new samples from the Normal distribution after each reset data
:
ampl: model steel4.mod; ampl: data steel4.dat; ampl: solve; MINOS 5.4: optimal solution found. 3 iterations, objective 187632.2489 avail [*] := reheat 32.3504 roll 43.038 ; ampl: reset data avail; ampl: solve; MINOS 5.4: optimal solution found. 4 iterations, objective 158882.901 ampl: display avail; avail [*] := reheat 32.0306 roll 32.6855 ;
Using this feature together with one of AMPL’s looping commands, you can automatically solve a series of random realizations from the model, and summarize the results:
model steel4.mod; data steel4.dat; param nruns := 5; param optvalue {1..nruns}; for {k in 1..nruns} { reset data avail; solve; let optvalue[k] := Total_Profit; } display (sum {k in 1..nruns} optvalue[k]) / nruns;
If you use reset
rather than reset data
, then AMPL’s random number generator is reset, and the values of avail repeat from the beginning. To get a different sequence of random numbers from the generator, you must change the random number seed; give the command option randseed n
— where n
is a positive integer — or option randseed 0
to have AMPL choose a seed based on the system clock.
Posted in: Files and Preprocessing