
120 3 ABMs Using Repast and Java
The @ScheduledMethod annotation is placed prior to each method with the
element priority and a floating-point value for the priority. The higher the
value, the higher the priority. So, if we wish health status to be updated before
movement, and movement to take place before infection, we might use the values
3, 2 and 1, respectively. There are also names such as FIRST_PRIORITY and
LAST_PRIORITY defined in the ScheduleParameters class that can be used
with negative and positive offsets for a more transparency. So we might annotate
updateInfectionStage thus:
@ScheduledMethod(start = 1, interval = 1,
priority = ScheduleParameters.FIRST_PRIORITY)
3.4.10 Visualizing the Model
We are now in a position to think about running the model and visualizing the in-
teractions between the agents. Because we did not specify a model initializer in
the model.score file, it is necessary to define a Data Loader in the Scenario
Tree, to indicate that our MalariaBuilder class fulfills the role of an initializer.
Right-clicking over Data Loader and selecting Set Data Loader brings up a list of
alternative sources for the initialization. For instance, we might have set up agent
details in a delimited file to be loaded, or a specification in an XML file. We select,
A Specific Java Class, and are then offered the MalariaBuilder class.
12
We want to visualize the two types of agents distinctly, and we also want to
distinguish between those agents that are healthy and those that are infected. This
really requires that we define either two separate or a single joint style class, in
the same manner as we did for the Game of Life in Sect. 3.3.6. We will choose
to define a single class for both, called AgentStyle2D, and return four differ-
ent colors depending on agent type and health (Code 3.7). This is added to the
project as a standard Java class—a subclass of DefaultStyle2D.Amoreso-
phisticated approach might vary the color depending on the stage of the infection,
for instance.
A display is set up in the Scenario Tree in the usual way via the Displays option,
selecting a 2D display for the World projection, and the AgentStyle2D class for
the agents’ style. When the model is run, circles of the four chosen colors randomly
distributed about the world should appear on the screen—it is probably a good idea
to reduce the number of agents initially, in order to get a better idea of what is
happening. If the display is changing too quickly, then the update rate can be varied
via the Run Options panel and the Schedule Tick Delay slider. With a low number
of agents, it is quite likely that the infection will die out within the simulation time
range.
12
Remember to save the Scenario Tree after doing this, otherwise this setting will be lost.