94 3 ABMs Using Repast and Java
3.3.2.2 The Issue of Update Ordering
In many models there is an underlying assumption that agents update their state
simultaneously at each time step, ready for the next time step. In a program it is
not practically possible for all agents to act concurrently. Instead, they are given
the chance to update sequentially—one after the other—at notionally the same time
step. Where agent behavior is independent of each other this is not a problem, but
this is often not the case. We pointed out in Sect. 2.3, for instance, that there will
be a different outcome if one Game of Life agent changes its state for the next time
step before its neighbors have determined their own next state.
What this means in practice for the model programmer is that agents often need
to be written to maintain some additional properties (that are not strictly part of
their state) in order to overcome the limitations of necessarily sequential execution
of what should properly be simultaneous update. The approach we will take with our
Game of Life agents is to add an additional property to Agent called nextState.
When an agent determines its new state from the state of its neighbors, it actually
stores the calculated value in nextState rather than currentState. That way,
when an agent is asked for its current state by its neighbors it will still be able to
return the “old” value. Once every agent has calculated its next state, each can then
be told to update the currentState property with the value of nextState,
ready for a repeat of this process at the next time step. We add a Next State property
along these lines to our agent. This time, we can use Only Me for step 4 because
we anticipate that no other part of the model needs to be aware of this internal
contrivance—it is not a genuine part of an agent’s externally-presented state, but an
artifact of implementational limitations.
3.3.2.3 Behavior and Interaction
The behavior of agents defining their interactions is programmed in Repast by link-
ing together a sequence of flowchart symbols. The flowchart language provided
allows all the standard programming elements to be used: variable assignments,
arithmetic calculations, choices between alternative actions, repeated actions, and
so on. An agent may have as many behaviors as desired. As we shall see, however,
an agent with even just a few, moderately complex behaviors can quickly become
quite difficult to manage via the flowchart editor. A particular advantage of Repast
in this respect is that it is relatively simple to switch from using flowcharts to Java or
Groovy (or even use a mixture of all three), without having to abandon the Repast
environment, with its rich set of features.
We will start programming the agent’s behaviors with the simplest operation—
that of copying the calculated next state into the currentState variable. This
will serve to illustrate the basics of behavior programming.
Behaviors are started by selecting the Behavior icon—a triangle—from the
flowchart palette. By default this will appear with the label Step in the program-
ming area. There are nine steps that can be filled out, six of which are indicated as