Statistical Data Collectors

An Extended Example

Necessary Changes to the Train and Ship Classes

   
 

In the life cycles of the dynamic model components, the actual update of the data collectors has to be done. The ship process delivers containers to the storage area, thus changing its current load level. After finishing unloading containers and before leaving the terminal, a ship now updates the storageLoadLevel accumulate, using the new getCurrentStorageLoad() method of the model class, and the loadLevelNorth time series. It also updates the shipSize histogram with its size, i.e. the number of containers it delivered to all four bins.


public void lifeCycle() throws SuspendExecution {

   // arrive at the terminal and deliver containers
   ...

   // ship is unloaded and can leave the system

   // NEW: update statistics
   // (1) update the accumulate with the new storage load level
   myModel.storageLoadLevel.update(myModel.getCurrentStorageLoad());
   // (2) update the time series with the new load level of the Northern Europe bin
   myModel.loadLevelNorth.update(myModel.north.getAvail());
   // (3) update the histogram with this ship's size
   myModel.shipSize.update(numEast+numNorth+numCentral+numGermany);

   ...

}

The train process retrieves containers from one of the storage areas, thus also changing its current load level. After finishing loading containers and before leaving the terminal, a train now updates the storageLoadLevel accumulate, using the new getCurrentStorageLoad() method of the model class, and -- if it is heading to Northern Europe -- the loadLevelNorth time series. It also updates the trainWaitTime tally with the time span it had to wait before loading containers. To be able to do this, we add a variable arrivalTime at the beginning of the life cycle to record the arrival time of this train. When updating the tally, we only have to subtract this arrival time from the current simulation time value to calculate the train's waiting time.


public void lifeCycle() throws SuspendExecution {

   // arrive at the terminal

   // NEW: record arrival time to be able to calculate wait time later
   double arrivalTime = presentTime().getTimeAsDouble();

   // load containers
   ...

   // train is loaded and can leave the system

   // update statistics
   ...
   // NEW: update the tally with the time this train spent waiting for containers
   myModel.trainWaitTime.update(presentTime().getTimeAsDouble() - arrivalTime);
   // NEW: update the accumulate with the new storage load level
   myModel.storageLoadLevel.update(myModel.getCurrentStorageLoad());
   // NEW: update the time series
   if (this.storage == myModel.north)
	myModel.loadLevelNorth.update(this.storage.getAvail());

   ...

}



   
  http://desmoj.sourceforge.net/tutorial/statistics/extended2.html