Statistical Data CollectorsAn Extended Example
Necessary Changes to the Model Class |
||
In the description of the implementation, we will focus on the different data collector objects and their use. To the model class we have to add (i) an import statement for the desmoj.core.statistic package (if it's not already there), (ii) an attribute each for the Tally, Accumulate, Histogram and TimeSeries objects, and (iii) their initialisation in the init() method. To make updating the accumulate easier for the dynamic model components (the ships and trains), we will also add a new method to our model class. This method returns the total number of containers currently stored in all four storage areas. import desmoj.core.simulator.*; import desmoj.core.dist.*; import desmoj.core.statistic.*; import desmoj.core.advancedModellingFeatures.*; /** * This is the model class. It is the main class of a simple process-oriented * model of the railway station inside a container terminal using bins to represent * In addition to the two counters from the CountExample model, several other * data collectors are added: a tally to record the average time a trains needs to * wait for containers, an accumulate to calculate the mean storage load level of the * four storage areas, a time series to log the storage load level of the Northern * Europe dedicated storage area, and a histogram to record a distribution * of ship sizes. */ public class CountExample extends Model { // define model attributes: // distributions ... // bins ... // data collectors ... /** NEW: a tally to record the average time a train has to wait */ protected Tally trainWaitTime; /** NEW: an accumulate to calculate the mean storage load level of all * four storage areas */ protected Accumulate storageLoadLevel; /** NEW: a time series to log the storage load level of the Northern * Europe dedicated storage area */ protected TimeSeries loadLevelNorth; /** NEW: a histogram to record the distribution of ship sizes */ protected Histogram shipSize; // constructor ... /** * initialises static model components like distributions and queues. */ public void init() { // initialise distributions ... // initialise the bins (storage areas) ... // initialise the data collectors ... // NEW: the tally trainWaitTime = new Tally(this, "train wait time", true, false); // NEW: the accumulate storageLoadLevel = new Accumulate(this, "storage load level", true, false); // NEW: the histogram shipSize = new Histogram(this, "ship size", 200, 1400, 10, true, false); // NEW: the time series loadLevelNorth = new TimeSeries(this, "load level for Northern Europe", "StatisticsExample_LoadLevelNorth.txt", new TimeInstant(0.0), new TimeInstant(500.0), true, false); } // additional required methods ... /** This method is used by the model components to receive the current * load level of all four storage areas combined, in order to be able * to update the accumulate. * @return long */ protected long getCurrentStorageLoad() { return (east.getAvail() + north.getAvail() + central.getAvail() + germany.getAvail()); } } |
||
http://desmoj.sourceforge.net/tutorial/statistics/extended1.html |