-
Notifications
You must be signed in to change notification settings - Fork 10
Contact
This is an R6 class that implements a contact pattern in R
The main task of the class is to return the contacts of a given agent. Each object of this class is associated to a population. A population may have multiple contacts attached, e.g., a random mixing contact pattern and a network contact pattern.
This class must be subclassed in order to implement specific functionality. To subclass, we must implement three methods, namely contact, addAgent, and build. See more details in the documentation of each method.
initialize = function()
contact = function(time, agent)
- time: the current time in the simulation, a number
- agent: the agent whose contacts are requested. An external pointer
a list of external pointers pointing to the contacting agents
This method must
addAgent = function(agent)
- agent: the agent whose contacts are requested. An external pointer
When an agent is added to a population, it is added to each of the contact patterns. When a contact pattern is added to a population, all agents in a population is added to the contact pattern, one by one.
Note that, immediately before the simulation is run, while reporting the states to the simulation object, the population will call the build method for each Contact object. Thus a contact object may choose to ignore addin agents before build is called, and handle all agents within the finalize method. However, the contact object must handle adding an agent after build is called.
build = function()
This method is called immediately before the simulation is run, when the attached population reports the states to the simulation object. Thus this method can be considered as a callback function to notify the contact object the population state, such as its agents, states, events, and contact patterns are all initialized, so the contact pattern should finish initialization, for example, building the contact network.
This is needed because some contact patterns, such as a configuration-model contact network, cannot be built while adding agents one by one. It must be generated when all agents are present. This is unlike the Albert-Barabasi networkm which can be built while adding the agents.
When the function is called, the active field private$population
field is available, which is the population that it is attached to.
$get
is the external pointer pointing to the C++ RContact object.
$attached
is a logical value indicating whether the object has been attached
to a population
newRandomMixing = function()
an external pointer.
The returned external pointer can then be passed to the addContact method of a population (or simulation).
# creates a simulation with 100 agents
sim = Simulation$new(100)
# add a random mixing contact pattern for these agents.
sim$addContact(newRandomMixing())
newConfigurationModel = function(rng)
- rng: a function that generates random degrees. Please see the Details sub-sub-section below.
an external pointer.
The function rng
should take exactly one argument n
for the number of degrees
to generate, and should return an integer vector of length n.
The following example generates the degrees for a Poisson random network with a mean degree 5.
# creates a simulation with 100 agents
sim = Simulation$new(100)
# add a Poisson network with a mean degree 5
sim$addContact(newConfigurationModel(function(n) rpois(n, 5)))