Simulation: R6Class Simulation

Description Public fields Methods Examples

Description

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

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

 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
}

OpenABMCovid19 documentation built on July 20, 2021, 5:08 p.m.