Incomplete Trajectories in R Simmer when using Branches within Do_Parallel

I am building a simulation in R using the simmer package.

The simulation models a restaurant where customers wait for their food after an order is placed.

Each order resource takes a different amount of time to use. Branch assigns a trajectory with a related timeout value depending on which resource was selected and records whether the resource used was digital or live for later reference. Note that this trajectory is incomplete on its own (explained later).

An order may have up to three types of products, each type having a different probability and taking a different amount of time to assemble. The limiting resource here is space to assemble orders. An assembly does not start until there is space for its tray. The trajectory is returned by the following function.

# Packages and model variables used
library(simmer)
library(simmer.plot)
library(simmer.bricks)
library(tidyr)

# (p) probability
p_rts <- 0.125 # ready to serve menu item
p_hot <- 0.25 # hot food item
p_bev <- 0.7 # Beverage

# (t) time in seconds - average from 
t_rts <- 10
t_hot <- 175
t_bev <- 25

# arrival distribution
r_arrive <- function(){
    runif(20, min = 0, max = 600) %>% # all arrivals occur within first 600 seconds
    sort
}

# The trajectory where the issue likely exists
f_order_prepare <- function(e, p_rts, p_hot, p_bev, t_rts, t_hot, t_bev){
  trajectory() %>%
    set_attribute("start_assembly", function() now(e)) %>%
    do_parallel(
      traj = list(
        trajectory() %>% branch(
          function() ifelse(runif(1) <= p_rts, 1, 2),
          continue = c(TRUE, TRUE), 
          trajectory() %>% set_attribute("has_rts", 1) %>% timeout(t_rts), 
          trajectory() %>% set_attribute("has_rts", 0)),
        trajectory() %>% branch(
          function() ifelse(runif(1) <= p_hot, 1, 2),
          continue = c(TRUE, TRUE), 
          trajectory() %>% set_attribute("has_hot", 1) %>% timeout(t_hot),
          trajectory() %>% set_attribute("has_hot", 0)),
        trajectory() %>% branch(
          function() ifelse(runif(1) <= p_bev, 1, 2),
          continue = c(TRUE, TRUE), 
          trajectory() %>% set_attribute("has_bev", 1) %>% timeout(t_bev), 
          trajectory() %>% set_attribute("has_bev", 0))
      ),
      .env = e, 
      wait = TRUE
    ) %>%
    log_("order ready") %>%
    set_attribute("order_ready", function() now(e))
}

We record when the assembly starts and then run three branches in parallel. If a product is chosen, it sets its timeout and records that it was chosen; otherwise, it records that the product was not selected. do_parallel waits for the longest of the three trajectories to complete, then continues.

trj_QSR <- trajectory() %>%
  seize("pickup_capacity", 1) %>%
  log_("seized the pick_up capacity") %>%
  simmer::join(
    f_order_prepare(env, p_rts, p_hot, p_bev, 
                  t_rts, t_hot, t_bev)
    )%>%
  timeout(20) %>% #delay for customer to collect tray
  release("pickup_capacity", 1) %>%
  set_attribute("transaction_done", function() now(env))

## Initiate
reset(env)
set.seed(12345)
env <- simmer() 
env <- env %>%
  add_resource("pickup_capacity", 12) %>%
  add_generator("transaction", trj_QSR, 
                distribution = at(r_arrive()), mon = 2)

env %>% run(until=50000000) #~578 days to ensure issues are not related to run time

The script executes without error; however, only the first 13 arrivals make it far enough to record which products were selected in do_parallel and only two finish their trajectory. The other 11 record the selections but then stop. The following code summarizes the attributes I tracked for troubleshooting.

get_mon_attributes(env) %>%
  dplyr::select(-c("time", "replication")) %>%
  pivot_wider(
    names_from = key,
    values_from = value
  ) %>%
  View(title = "atts")

Summary:
For some reason, most arrivals do not complete the do_parallel trajectories and, therefore, never release the “pickup_capacity” resource, leaving remaining arrivals in the queue.

I am looking for help isolating why this is occurring. Thanks.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật