-
Notifications
You must be signed in to change notification settings - Fork 10
Population
This is an R6 class that represents a population. 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 netowrk, and another for social network.
This class inherits the Agent class, i.e., a population is itself an agent, and can thus have its own state and events.
initialize = function(population=0, initializer=NULL)
-
population: 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), and in this case, the initializer is ignored.
addAgent = function(agent)
- agent: either an object of the Agent class, or an external pointer returned from [newAgent](#Create an agent).
the Population object itself for chaining actions.
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.
addContact = function(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.
getAgent = function(i)
- i: the index of the agent (starting from 1)
an external pointer pointing to the agent
setState = function(i, state)
- i: the index of the agent (starting from 1)
- state: a list holding the state to set, an a non-list value (equivalent to
list(state)
)
The population object itself for chaining actions.
The $size
field retrieves the population size, which is an integer
newPopulation = function(n)
- n: an integer specifying the population size.
An external pointer pointing to the created C++ object of the Population class. Note that it is not the [R6 Population class] (#Population-Class) described above. Instead, the Population class' constructor, if called with a population size as the argument, calls this function to create a C++ object, which can be retrieved by the $get active field.
The population will be created with n
individuals in it. These individuals have an empty state upon created. Note that individuals can be added later by the "add" method, the initial population size is for convenience, not required
getSize = function(population)
- population: an external pointer to a population, for example, one returned by newPopulation