我是 R 新手,对离散事件模拟非常陌生。r.simmer 似乎是一个非常好的包,因此尝试使用它来模拟医院床位入院策略,对我来说,轨迹分支选项能够检查资源状态和到达的任意属性似乎很自然,例如
library(simmer)
daypatient<-trajectory() %>%
log_("sent home") %>%
timeout(300) %>%
seize("admin",1) %>%
release("admin",1) %>%
seize("bed",1)
patient <-trajectory() %>%
log_("start pat") %>%
branch(
function() rnorm(1)>0.5 ,
# actually want to inspect arrival priority and queues to decide which trajectory path to follow
continue= TRUE,
daypatient
) %>%
seize("bed",1) %>%
seize("theatre",1) %>%
timeout(rnorm(1,5)) %>%
release("theatre",1) %>%
timeout(50) %>%
release("bed",1)
# some patients need treatment pdq...
serious<-data.frame(time=rexp(10,1),priority=2)
# ... other less so
wounded<-data.frame(time=rexp(10,1),priority=1)
hos <- simmer() %>%
add_resource("bed",2) %>%
add_resource("admin",3) %>%
add_resource("theatre",1) %>%
add_dataframe("serious",
patient,
serious) %>%
add_dataframe("wounded",
patient,
wounded)
hos %>% run(until = 500)
有什么办法可以做到这一点,还是我从根本上误解了 r.simmer/DES 框架?