The method of batch means splits a run into several subruns. It records the means of each subrun. The following code fragment uses this method to obtain the mean of the queue size for the M/M/1 queue.
histogram* h3 = new histogram(".h3","-title meansizes"); tk -> pack(h3); tk -> update(); for (int i=0;i<100;i++) { sim -> run(10000.0); h3 -> sample(h1 -> mean()); // sample the mean h1 -> reset(); // reset for the next subrun } cout << (*h3);
After sampling the mean of each subrun, the histograms are reset, so the results only cover a single subrun.
The method of repeating a single run has the disadvantage that on each run we have an initial transient phase. It can be implemented as follows :
histogram* h3 = new histogram(".h3","-title meansizes"); tk -> pack(h3); tk -> update(); for (int i=0;i<100;i++) { sim -> run(10000.0); h3 -> sample(h1 -> mean()); // sample the mean h1 -> reset(); // reset objects r -> reset(); q -> reset(); sim -> reset(); customer* c = new customer(ARRIVAL); // set up again sim -> schedule(c,0.0); s = new server(); sim -> hold(s); } cout << (*h3);
In this case we also reset the resource, queue and simulation object so we have several independent runs. The simulation is set up at the beginning of each run by scheduling an arrival and making the server conditional.
The reset methods can also be used when running the simulation for an initial transient phase or when designing experiments.