Population | R Documentation |
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
size
The population size, an integer
new()
Population$new(population = 0, initializer = NULL)
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
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)
agent
either 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)
agent
either 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)
contact
an 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)
i
the 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)
i
the index of the agent (starting from 1)
state
a list holding the state to set
the population object itself (invisible) for chaining actions Set the states for the agents
setStates()
Population$setStates(states)
states
either 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)
deep
Whether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.