Skip to contents

Executes a discrete-event simulation of a scenario with simmer, routing each casualty through board-area resources according to its sighting category and therapy concept, and returns per-area event records, per-casualty flow records and resource utilisation.

Usage

sdt_simulate(
  scenario,
  replications = 1L,
  service_times = list(),
  horizon = 270,
  parallel = FALSE,
  workers = NULL,
  seed = NULL,
  verbose = TRUE
)

Arguments

scenario

A scenario object from sdt_scenario().

replications

Number of independent replications (positive whole number). The replication index is carried in every returned table.

service_times

Named list of mean service times in minutes per board area, used as exponential rates. Missing areas fall back to the reference defaults.

horizon

Length of the game in minutes. Casualties still in the system when the clock stops are recorded where they stood, which is what makes the end-of-game distribution meaningful. Inf runs every casualty to completion.

parallel

If TRUE, run replications concurrently. Defaults to FALSE. The backend is set up for the duration of the call and the caller's plan is restored on exit.

workers

Number of parallel workers, or NULL to choose one: a core short of the machine, capped at 8.

seed

Optional integer seed, applied with withr::local_seed().

verbose

If TRUE, report progress via cli.

Value

An S3 object of class game_run with elements:

events

One row per casualty per board area entered: replication, id, step, area, start, end, duration, service_time. A state runs from entering an area to entering the next, and the last runs to the horizon, so duration is time spent standing in that area. service_time is the treatment time simmer actually recorded, and is NA where the casualty was still being treated at the horizon or was only being held. The two differ whenever a casualty is finished but waiting for a bed downstream.

arrivals

One row per casualty per replication, carrying the card fields and total time in system.

resources

Resource utilisation over time.

Details

Theatre time scales with the therapy concept: abbreviated surgical care is quickest, damage-control surgery the reference, early total care the longest. The multipliers live in sdt_reference("defaults")$or_multiplier.

See also

summary.game_run() for the end-of-game distribution, and sdt_decision_paths() to turn the event log into state sequences.

Examples

co <- sdt_synthetic_cohort(n = 20, seed = 1)
sc <- sdt_scenario(co, resources = list(or = 2, icu_imc = 6))
run <- sdt_simulate(sc, replications = 2, seed = 1, verbose = FALSE)
run
#> <game_run> 2 replications over 270 minutes
#> 14 casualty records, 118 area events
head(run$events)
#> # A tibble: 6 × 8
#>   replication id     step area         start    end duration service_time
#>         <int> <chr> <int> <chr>        <dbl>  <dbl>    <dbl>        <dbl>
#> 1           1 P001      1 triage        6.07   7.94     1.86         1.86
#> 2           1 P001      2 ed_red        7.94  35.8     27.8         27.8 
#> 3           1 P001      3 diagnostics  35.8   60.1     24.4         24.4 
#> 4           1 P001      4 or           60.1  133.      72.9         72.9 
#> 5           1 P001      5 icu_imc     133.   200.      66.6         66.6 
#> 6           1 P002      1 triage        7.99  35.8     27.8          9.66