Statistical Data CollectorsUsing a Counter
Necessary Changes to Model and Train Classes |
||
In the description of the implementation, we will focus on the Count objects and their use. To the model class we have to add (i) an import statement for the desmoj.core.statistic package, (ii) an attribute each for the two counter objects, and (iii) their initialisation in the init() method. import desmoj.core.simulator.*; import desmoj.core.dist.*; import desmoj.core.advancedModellingFeatures.*; import desmoj.core.statistic.*; // NEW /** * 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 different storage areas. * Two counters are added to record the number of trains leaving the * terminal and the overall number of containers exchanged. */ public class CountExample extends Model { // define model attributes: // distributions ... // bins ... /** NEW: a counter to record the number of trains leaving the terminal */ protected Count numberOfTrains; /** NEW: a counter to record the total number of containers exchanged */ protected Count numberOfContainers; // constructor ... /** * initialises static model components like distributions and queues. */ public void init() { // initialise distributions ... // initialise the bins (storage areas) ... // NEW: initialise the data collectors (counters) numberOfTrains = new Count(this, "number of trains", true, false); numberOfContainers = new Count(this, "number of containers", true, false); } // additional required methods ... } In the life cycle of the train process, the actual update of the counters has to be done. After finishing loading containers and before leaving the terminal, a train now (i) updates the numberOfTrains counter by 1, using the parameter-less update() method, and (ii) updates the numberOfContainers counter with the number of containers it carries, i.e. its length, using the standard update() method. public void lifeCycle() { // arrive at the terminal and load containers ... // train is loaded and can leave the system // NEW: update statistics (counters) myModel.numberOfTrains.update(); myModel.numberOfContainers.update(length); ... } |
||
http://desmoj.sourceforge.net/tutorial/statistics/counter1.html |