Description Public fields Methods Examples
Simulation object to run the model and store data across multiple simulations.
env
Current environment
(Environment
R6 class object)
agent
Current agent
(Agent
R6 class object)
current_state
Current environment state.
current_action
Current action from agent.
simulation_number
Simulation Number.
end_time
Time when the simulation should end.
results
Results of current simulation (list of vectors).
results_all_simulations
Results of all simulations (list of list of vectors).
verbose
Log verbosity.
timestep
Current time step.
sim_started
TRUE
is the simulation has started,
FALSE
otherwise.
new()
Environment subclass representing a COVID19 outbreak as defined in the COVID19-IBM model
Simulation$new(env, agent = Agent$new(), end_time = NULL, verbose = FALSE)
env
Instance of Environment
R6Class
agent
Instance of Agent
R6Class
end_time
End time for the simulation
verbose
Log verbosity.
start_simulation()
Initialisation of the simulation; reset the model
Simulation$start_simulation()
end_simulation()
End the simulation
Simulation$end_simulation()
steps()
Run the model for a specific number of steps, starting from the current state, save data as model progresses.
Simulation$steps(n_steps)
n_steps
Number of steps for which to call
self$model.one_time_step()
collect_results()
Collect model results at each step; fixme action is not currently stored
Simulation$collect_results(state, action)
state
The state to collect results from.
action
Currently unused.
is_terminal_state()
Get terminal state.
Simulation$is_terminal_state()
Is the current state the terminal state
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # Create a model using the baseline parameters included in the package.
# Note: This initialisation can take a few seconds.
model <- Model.new( params = list( n_total = 10000 ) )
if (!is.null(model)) {
# Begin simulation:
env <- COVID19IBM$new( model )
sim <- Simulation$new( env )
sim$start_simulation()
sim$steps(1) # Note: slow operation (takes a few seconds).
# Make changes to the model (environment)
model$seed_infect_by_idx(0)
# Resume simulation
sim$steps(1) # Note: slow operation (takes a few seconds).
# Get results
sim$results
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.