Learn R Programming

OpenABMCovid19 (version 1.0.1)

Simulation: R6Class Simulation

Description

Simulation object to run the model and store data across multiple simulations.

Arguments

Public fields

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.

Methods

Public methods

Method new()

Environment subclass representing a COVID19 outbreak as defined in the COVID19-IBM model

Usage

Simulation$new(env, agent = Agent$new(), end_time = NULL, verbose = FALSE)

Arguments

env

Instance of Environment R6Class

agent

Instance of Agent R6Class

end_time

End time for the simulation

verbose

Log verbosity.

Method start_simulation()

Initialisation of the simulation; reset the model

Usage

Simulation$start_simulation()

Method end_simulation()

End the simulation

Usage

Simulation$end_simulation()

Method steps()

Run the model for a specific number of steps, starting from the current state, save data as model progresses.

Usage

Simulation$steps(n_steps)

Arguments

n_steps

Number of steps for which to call self$model.one_time_step()

Method collect_results()

Collect model results at each step; fixme action is not currently stored

Usage

Simulation$collect_results(state, action)

Arguments

state

The state to collect results from.

action

Currently unused.

Method is_terminal_state()

Get terminal state.

Usage

Simulation$is_terminal_state()

Returns

Is the current state the terminal state

Examples

Run this code
# NOT RUN {
# 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
}
# }

Run the code above in your browser using DataLab