Population {ABM}R Documentation

R6 class that represents a population

Description

A population is a collection of agents. There are two important tasks for a population:

  1. to manage the agents in it

  2. to define the contact patterns of the agents

The contact patterns are defined by objects of the Contact class that are associated with the population. A population may have multiple Contact objects, for example, one for random mixing, one for close contacts represented by a contact network, and another for social network.

Super class

ABM::R6Agent -> R6Population

Active bindings

size

The population size, an integer

Methods

Public methods

Inherited methods

Method new()

Usage
Population$new(population = 0, initializer = NULL)
Arguments
population

can be either an external pointer pointing to a population object returned from newPopulation, or an integer specifying the population size, or a list.

initializer

a function or NULL

Details

If population is a number (the population size), then initializer can be a function that take the index of an agent and return its initial state. If it is a list, the length is the population size, and each element corresponds to the initial state of an agent (with the same index). Add an agent


Method addAgent()

Usage
Population$addAgent(agent)
Arguments
agent

either an object of the R6 class Agent, or an external pointer returned from newAgent.

Details

The agent is scheduled in the population. If the population is already added to a simulation, the agent will report its state to the simulation. remove an agent

Returns

the population object itself (invisible) for chaining actions


Method removeAgent()

Usage
Population$removeAgent(agent)
Arguments
agent

either an object of the R6 class Agent, or an external pointer returned from newAgent.

Details

The agent is scheduled in the population. If the population is already added to a simulation, the agent will report its state to the simulation. Add a contact pattern

Returns

the population object itself (invisible) for chaining actions


Method addContact()

Usage
Population$addContact(contact)
Arguments
contact

an external pointer pointing to a Contact object, e.g., created from newRandomMixing.

Details

If the contact has already been added, this call does nothing. return a specific agent by index


Method agent()

Usage
Population$agent(i)
Arguments
i

the index of the agent (starting from 1)

Returns

an external pointer pointing to the agent set the state of a specific agent by index


Method setState()

Usage
Population$setState(i, state)
Arguments
i

the index of the agent (starting from 1)

state

a list holding the state to set

Returns

the population object itself (invisible) for chaining actions Set the states for the agents


Method setStates()

Usage
Population$setStates(states)
Arguments
states

either a list holding the states (one for each agent), or a function

Details

If states is a function then it takes a single argument i, specifying the index of the agent (starting from 1), and returns a state.

Returns

the population object itself for chaining actions


Method clone()

The objects of this class are cloneable with this method.

Usage
Population$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


[Package ABM version 0.4.1 Index]