检查加入队列时的最大等待时间。

huangapple go评论91阅读模式
英文:

R Simmer check the max wait time when joining queue

问题

我希望这个问题很简单!
我可以看到有一个名为get_queue_count的函数,几乎是我所需要的,但我不需要队列中的数字,我需要知道队列中任何个体的最大等待时间。如果最大队列时间超过某个变量,我可以将客户引导到另一个轨迹。

如常,非常感谢任何帮助!

英文:

I'm hoping this is an easy question!
I can see that there is a function get_queue_count which is almost what I need, but I don't need the number in the queue, I need to know the max time spent in the queue by any individual. I can then send the customers down another trajectory if the max queue time is over a variable.

Any help, as always, greatly appreciated!

答案1

得分: 1

创建一个自定义函数解决了这个问题。毫不否认,我需要清理这个代码,我确信有人可以使它运行得更快,但是就这样吧。

英文:

Creating a custom function solved this. Admittedly I need to clean this and I'm sure someone could make it a lot faster but there we go.

fn_queue_time <- function() {
qt <- sim %>%
get_mon_attributes() %>%
filter(key == "q_start" | key == "q_end") %>%
group_by(name) %>%
mutate(count = n()) %>%
filter(count == 1) %>%
pivot_wider(id_cols = name, names_from= key, values_from = time) %>%
mutate(q = simmer::now(sim) - q_start) %>%
ungroup() %>%
summarise(m = max(q)) %>%
pull()
}

arrive <- c(1:5)

traj <- trajectory("traj") %>%
log_("arrive") %>%
set_attribute(keys = "q_start", values = function() {now(sim)}) %>%
log_(function() {paste("Q time: ", fn_queue_time())}) %>%
branch(function() ifelse(fn_queue_time() >= 5, 1, 2),
continue = F,
trajectory() %>%
log_("q too long, offered alternative") %>%

renege_in(5,
out = trajectory() %>%
log_("alternative accepted") %>% set_attribute(keys = "q_end", values = function() {now(sim)}) %>%
set_attribute(keys = "alternative accepted", values = function() {now(sim)})
) %>%
seize("resource") %>%
log_("service") %>%
renege_abort() %>%
set_attribute(keys = "q_end", values = function() {now(sim)}) %>%
timeout(10) %>%
release("resource"),
trajectory() %>%
log_("norm") %>%
renege_in(5, out = trajectory() %>%
log_("reneg") %>% set_attribute(keys = "q_end", values = function() {now(sim)}) %>%
set_attribute(keys = "reneg", values =function({now(sim)})) %>%
seize("resource") %>%
log_("service") %>%
renege_abort() %>%
set_attribute(keys = "q_end", values = function() {now(sim)}) %>%
timeout(10) %>%
log_("service end") %>%
release("resource"))

sim <- simmer("sim") %>%
add_generator("cust",traj, at(arrive), mon = 2) %>%
add_resource("resource", 1)


sim %>%
run(until = 800)

huangapple
  • 本文由 发表于 2023年2月14日 22:25:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75449224.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定