A population is a collection of agents. There are two important tasks for a population:
to manage the agents in it
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.
ABM::R6Agent -> R6Population
sizeThe population size, an integer
new()Population$new(population = 0, initializer = NULL)populationcan be either an external pointer pointing to a population object returned from newPopulation, or an integer specifying the population size, or a list.
initializera function or NULL
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
addAgent()Population$addAgent(agent)agenteither an object of the R6 class Agent, or an external pointer returned from newAgent.
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
the population object itself (invisible) for chaining actions
removeAgent()Population$removeAgent(agent)agenteither an object of the R6 class Agent, or an external pointer returned from newAgent.
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
the population object itself (invisible) for chaining actions
addContact()Population$addContact(contact)contactan external pointer pointing to a Contact object, e.g., created from newRandomMixing.
If the contact has already been added, this call does nothing. return a specific agent by index
agent()Population$agent(i)ithe index of the agent (starting from 1)
an external pointer pointing to the agent set the state of a specific agent by index
setState()Population$setState(i, state)ithe index of the agent (starting from 1)
statea list holding the state to set
the population object itself (invisible) for chaining actions Set the states for the agents
setStates()Population$setStates(states)stateseither a list holding the states (one for each agent), or a function
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.
the population object itself for chaining actions
clone()The objects of this class are cloneable with this method.
Population$clone(deep = FALSE)deepWhether to make a deep clone.