The key task of an agent is to maintain events, and handle them in the chronological order. Agents also maintain their states, which is a list of values. The events, when handled, operate on the state of the agent (or other agents).
state
Get/set the state of the agent
id
Get the agent ID
get
Get the external pointer for the agent
new()
Agent$new(agent = NULL, death.time = NA)
agent
can be either an external pointer to an agent such as one returned by newAgent, or a list representing the initial state for creating a new agent, or NULL (an empty state)
death.time
the time of death for the agent, a numeric value
match()
Agent$match(rule)
rule
the state to match, a list
a logical value Schedule an event
schedule()
Agent$schedule(event)
event
an object of the R6 class Event, or an external pointer returned by newEvent
the agent itself (invisible) Unschedule an event
unschedule()
Agent$unschedule(event)
event
an object of the R6 class Event, or an external pointer returned by newEvent
the agent itself (invisible) leave the population that the agent is in
leave()
Agent$leave()
the agent itself set the time of death for the agent
setDeathTime()
Agent$setDeathTime(time)
time
the time of death, a numeric value
the agent itself (invisible)
clone()
The objects of this class are cloneable with this method.
Agent$clone(deep = FALSE)
deep
Whether to make a deep clone.
During the simulation the agent with the earliest event in the simulation is picked out, unscheduled, then its earliest event is handled, which potentially causes the state change of the agent (or another agent in the simulation). The state change is then logged by loggers that recognize the state change.
An agent itself cannot handle the event. Instead, it has to be added to a simulation (or a population that itself is added to a simulation).
Note that specifying death.time is equivalent to call the
$setDeathTime
method.
Check if the state of the agent matches a given state
At the time of death, the agent is removed from the simulation. Calling it multiple times causes the agent to die at the earliest time.