Runs the specified simulation until a stopping condition occurs
and returns a table listing all events that occurred. simulation_run
can be
called repeatedly and will continue from the point where the last run stopped.
Note that for an epidemic to start, initially infected nodes must be defined
with simulation_addinfections
.
Usage
simulation_run(sim, stop, opts = list())
Value
a data.frame
containing the columns
time: time since the start of the simulation
epidemic_step: total number of epidemic events so far
network_step: total number of network events so far
kind: kind of event (outside_infection, infection, reset, neighbour_added, neibhour_removed, instantenous_contact)
node: node affected by the event
neighbour: neighbour (for infection, neighbour_added, neibhour_removed)
total_infected: total number of infected nodes since simulations start
total_reset: total number of recovered/reset nodes since simulation start
infected: current number of infected nodes
Details
Stopping conditions are specified as a named list of threshold values for any combination of the following variables:
epidemic_steps: Number of epidemic events (infection, outside_infection, reset) since the simulation was started.
network_steps: Number of network events (edge added, edge removed, instantaneous contact) since the simulation was started. Only relevant for simulations on dynamic networks.
time: time since the simulation was started
infected: Number of currently infected nodes
total_infected: Total number of infections since the start of the simulation
total_reset: Total number of recoveries/resets since the start of the simulation
Possible return value options are:
network_events: Include network events in the returned
data.frame
. Default falseepidemic_events: Include epidemic events in the returned
data.frame
. Default true
Examples
# Create contact network network
nw <- erdos_renyi_network(1e5, 5)
# Create transmission and reset time distributions
psi <- lognormal_time(6, 30, 0.1)
rho <- weibull_time(shape=5, scale=50)
# Create simulation and specifiy initial set of infections
sim <- simulation(nw, psi, rho)
simulation_addinfections(sim, nodes=c(1), times=c(0.0))
# Run simulation until time t=100 or 200,000 infections have occured
r <- simulation_run(sim, stop=list(time=300, total_infected=300e3))
# Plot the number of infected nodes against time
plot(r$time, r$infected, type='l')