Skip to content
Junling Ma edited this page Sep 1, 2023 · 23 revisions

ABM R Package: Agent Based Model Simulation Framework

The ABM package provides a high-performance, flexible framework for agent-based modeling. It has an easy-to-use state transition mechanism, that makes it especially suitable for modeling agent based models. For example, an SEIR model can be implemented in 18 lines.

In addition, this framework is a general event-based framework. Yet this framework allows the state of an agent to be quite general, described by a R list taking arbitrary R values. The states are modified by events, which can be easily defined. Thus, it is suitable for a wide range of applications, such as implementing the Gillespie algorithm.

Agent

The concept of this framework is agent, which is an object of the Agent class. An agent maintains its own state, which is a named R list storing any R values in it. (see State of an agent. The main task of an agent is to manage events (see Event), and handle them in chronological order.

Population

An object of the Population class manages agents and their contacts. The contacts of agents are managed by Contact objects. The main functionality for a contact object is to provide contacts of a given individuals at a given time. For example, the [[newRandomMixing function|Contact#Create-a-random-mixing-pattern) returns such an object that finds a random agent in the population as a contact. the effect of contacts on the states of agents are defined using a state transition rule. Please see the Simulation class' addTransition method of the for more details.

Simulation

The Simulation class inherits the Population class. So a simulation manages agents and their contacts. Thus, the class also inherits the Agent class. So a simulation can have its own state, and events attached (scheduled) to it. In addition, it also manages all the transitions, using its addTransition method. At last, it maintains loggers, which record (or count) the state changes, and report their values at specified times.

During a simulation the earliest event in the simulation is picked out, unscheduled (detached), and handled, which potentially causes the state change of the agent (or another agent in the simulation). The state change is then logged by loggers (see newCounter and newStateLogger for more details) that recognize the state change.

Usage

To use this framework, we start by creating a simulation object, populate the simulation with agents (either using the argument in the constructor, or use its addAgent method, and initialize the agents with their initial states using its setState method.

We then attach (schedule) events to agents (possibly to the populations or the simulation object too), so that these events change the agents' state. For models which agents' states are defined by discrete states, such as the SIR epidemic model, the events are managed by the framework through state transitions, using rules defined by the addTransition method of the Simulation class.

At last, we add loggers to the simulation using the Simulation class' addLogger method and either the newCounter function or newStateLogger function. At last, run the simulation using its run method, which returns the observations of the loggers at the requested time points as a data.frame object.

Examples

  1. An SIR model using the Gillespie method
  2. An agent based SEIR model
  3. A multi-group SEIR model
  4. A contact network SIR model
  5. Contact tracing on an SIR model
  6. A household SEIR model
  7. An SIR model with births and deaths

Roadmap

Clone this wiki locally