1 The SimulationManager interface
Collectors and Observers follow a similar logic, the only difference being that Collectors must implement the CollectorManager interface, and Observers must implement the ObserverManager interface. The Demo07 model describes those classes in details. In the following example the first instruction loads a list of agents, instances of the Agent class, from an input database table using the JAS-mine integrated ORM system: public void buildObjects() {
Events are planned based on a discrete event simulation paradigm. This means that events can be scheduled dynamically at specific points in time. The frequency of repetition of an event can be specified in case of recurring events characterized by a specific frequency. An event can be created for a specific recipient. In particular, an event can be created and managed by the simulation engine (a system event, e.g. simulation stops), it can be sent to all the components of a collection or list of agents or it can be sent to a specific object/instance. Events can be grouped together if they share the same schedule.
public void buildSchedule() { In the example above a group of events (labeled s) is created to be run for the first time at time 0.0 and then repeated at each interval of 1.0 time units. Within an event group, events are run sequentially, as specified in the code. The first event in the event group s (Age) is sent to all the individuals in the simulated population and entails aging. The second event is targeted to the model itself and entails running the MarriageMatch() method, which forms couples based on a some matching algorithm. The event group s is added to the model's schedule in repeat mode using the scheduleRepeat() method. Finally, the end of the simulation is scheduled once using the scheduleOnce() method at time t=2.0 and is notified to the model itself. 2 The Ordering of EventsThe signature of the scheduleOnce() method is: whilst the signature of the scheduleRepeat() method is: Note the use of the 'withOrdering' integer field. This is used to specify the order in which events scheduled at the same time are fired; events with lower values of the withOrdering field will fire first. For example, if two events are scheduled to occur at time 10.52, then if event A was scheduled with the withOrdering field set to 0 whereas event B was scheduled with withOrdering set to -1, event B will fire before event A. If two events are scheduled with both the same atTime and withOrdering, the event that was added to the schedule earlier in the simulation will be fired first. It is therefore important that the ordering of events scheduled for the same time only share the same value of the withOrdering field if it doesn't matter what order the events need to be fired in. There are two standard ordering values:
Note that the schedule(Event event, long atTime) and schedule(Event event, long atTime, int withLoop) methods that were part of the JAS2.0 libraries are now deprecated, because they were built on a platform that only allows events to be scheduled at integer time steps, and does not allow control of the ordering of events scheduled at the same time. If you still use these methods in the JAS-mine release, be aware that the withOrdering field defaults to 0, so all events scheduled at the same time will be fired in the order in which they were added to the schedule. 3 The EventListener interfaceIn the example, the model defines an enum called Processes as follows: public enum Processes {
The onEvent() method decodes this object and performs the required action: public void onEvent(Enum<?> type) { […] Analogously, the Agent class also defines an enum called Processes, which in this example contains the Age case. 4 Dynamic SchedulingNote that events can be scheduled dynamically and need not be planned in advance when constructing the model. For instance, events can be added by the agents themselves, based on their behavioural rules. This simply requires accessing the event list through a singleton instance of the simulation engine, with the following instruction: SimulationEngine.instance.getEventList(); |