0

我有一个慢炖 DES 的工作示例,用于简单的门诊服务。有高优先级和低优先级的患者,每个患者都有一个专门的诊所。高优先级诊所每天有 5 个时段,低优先级诊所每天有 1 个时段。这是测试代码:

testmixcap <- simmer()

highpriority <- trajectory("high") %>%
  log_("High priority arrival - add to wl") %>%
  select("highpclinic") %>%
  seize_selected() %>%
  log_("Attend appointment") %>%
  timeout(1) %>%
  release_selected() %>%
  log_("Discharge")

lowpriority <- trajectory("low") %>%
  log_("Low priority arrival - add to wl") %>%
  select("lowpclinic") %>%
  seize_selected() %>%
  log_("Attend appointment") %>%
  timeout(1) %>%
  release_selected() %>%
  log_("Discharge")

testmixcap %>%
  add_generator("high",highpriority,at(1,1,1,2,2,3,3,3,4)) %>%
  add_generator("low",lowpriority,at(1,1,1,1,2,2,2,3,3,3,4,4,4,5,5,6)) %>%
  add_resource("highpclinic",5) %>%
  add_resource("lowpclinic",1) 

testmixcap %>%
  run(until = 100)

testmixcap %>%
  get_mon_resources()

我的问题是,在没有高优先级诊所插槽需求的日子里(或者不是所有 5 个都需要),有没有办法告诉 simmer 将其余插槽释放给低优先级资源?例如,高优先级诊所看到 2 名患者,但剩余的 3 个插槽被添加到低优先级诊所并通过 4 名患者?

然后,诊所需要在第二天恢复正常容量,但我认为我可以使用时间表而不是固定优先级来做到这一点。

我认为答案在于使用信号,但我无法理解它们。我还考虑过将两个诊所合并为一个锅,并使用优先级分配给更高优先级的患者。但这意味着我们可能会有几天看到零低优先级患者,这是不太可能的。

任何帮助都感激不尽!

4

1 回答 1

0

我设法找到了一个使用全局变量的解决方案,以及一个虚假的到达生成器,它可以作为日常监控器,以监测何时将过剩产能分配给高优先级诊所。

library(simmer)
library(dplyr)

testmixcap <- simmer()

highpriority <- trajectory("high") %>%
  log_("High priority arrival - add to wl") %>%
  select("highpclinic") %>%
  seize_selected() %>%
  set_global("highpseentoday",1,"+") %>%
  log_("Attend appointment") %>%
  timeout(1) %>%
  release_selected() %>%
  log_("Discharge")

lowpriority <- trajectory("low") %>%
  log_("Low priority arrival - add to wl") %>%
  select("lowpclinic") %>%
  seize_selected() %>%
  log_("Attend appointment") %>%
  timeout(1) %>%
  release_selected() %>%
  log_("Discharge")

cap_monitor <- trajectory() %>%
  set_global("highpseentoday",0) %>% 
  timeout(0.1) %>%
  log_("Check if all today's slots used in high priority clinic") %>%
  branch(
    function(){
      seentoday <- get_global(testmixcap,"highpseentoday")
      highpcap <- get_capacity(testmixcap,"highpclinic")
      if(seentoday < highpcap) {1} else {0}
    }
    ,continue = TRUE
    ,trajectory() %>% set_capacity("lowpclinic",value = function(){
      seentoday <- get_global(testmixcap,"highpseentoday")
      highpcap <- get_capacity(testmixcap,"highpclinic")
      highpcap - seentoday
    },mod = "+")
  ) %>%
  timeout(0.9) %>%
  rollback(Inf)


testmixcap %>%
  add_generator("high",highpriority,at(1,1,1,2,2,3,3,3,4),mon = 2) %>%
  add_generator("low",lowpriority,at(1,1,1,1,2,2,2,3,3,3,4,4,4,5,5,6)) %>%
  add_resource("highpclinic",5) %>%
  add_resource("lowpclinic",schedule(c(1,2),c(1,1),2)) %>% 
  add_generator("monitor",cap_monitor,at(1))

testmixcap %>%
  run(until = 100)

testmixcap %>%
  get_mon_resources()

testmixcap %>%
  get_mon_arrivals()

于 2021-04-20T13:12:31.903 回答