煨以记录使用的资源

时间:2018-02-14 21:04:03

标签: r event-simulation

在下面的Simmer代码中,有没有办法记录患者看到的医生:

  patient_traj <- trajectory(name = "patient_trajectory") %>%
  select(resources = c("doctor1", "doctor2", "doctor3"), policy = "round-robin") %>%
  set_capacity_selected(1) %>%
  seize_selected(amount = 1) %>%
  timeout(5) %>%
  release_selected(amount = 1)

即如果patient01看到医生1,它就会被记录在数据表中。

1 个答案:

答案 0 :(得分:1)

默认情况下。要获取此信息,只需使用参数get_mon_arrivals调用per_resource=TRUE即可。快速举例:

library(simmer)

patient_traj <- trajectory(name = "patient_trajectory") %>%
  select(resources = c("doctor1", "doctor2", "doctor3"), policy = "round-robin") %>%
  set_capacity_selected(1) %>%
  seize_selected(amount = 1) %>%
  timeout(5) %>%
  release_selected(amount = 1)

simmer() %>%
  add_resource("doctor1") %>%
  add_resource("doctor2") %>%
  add_resource("doctor3") %>%
  add_generator("patient", patient_traj, at(0, 1, 2, 3)) %>%
  run() %>%
  get_mon_arrivals(per_resource = TRUE)
#>       name start_time end_time activity_time resource replication
#> 1 patient0          0        5             5  doctor1           1
#> 2 patient1          1        6             5  doctor2           1
#> 3 patient2          2        7             5  doctor3           1
#> 4 patient3          3       10             5  doctor1           1