The Collector collects statistics and manages the persistence of the simulation outputs on the database. It extends the AbstractSimulationCollectorManager interface and requires, similarly to the Model, the implementation of a buildObjects() method and a buildSchedule() method. The buildObjects() method creates several CrossSection objects, which collect specific values from each individual in the population (Box 13).
The Collector’s schedule is made up of two processes only, which take place at every simulation period: the CrossSections are updated (Processes.Update), and the persons and households are persisted in the database (Processes.DumpInfo) (see Box 14).
The Collector also implements the EventListener interface, featuring the Enum Processes and onEvent() method (see Box 15).
As we have seen in Section 3.3, implementing the EventListener interface is not necessary, as the class can be activated by the scheduler using the Java reflection. However, grouping all the updating in one single Update process improves on clarity. (Because updating is a common activity, it is also defined as a CommonEventType Enum in the JAS-mine event library (together with saving). Passing the scheduler this Enum does not require implementing the EventListener interface. An example of this approach is implemented in the Observer.) Updating the CrossSection objects only involves simple instructions such as
Similarly, dumping the simulation outputs is done by the DumpInfo process and only requires
Previous: 5. The Household class Next: 7. The PersonsObserver class |
Demo models > Demo07 >