simmer模拟异常终止咨询:周转箱批量运输场景
问题分析与解决方案
1. 轨迹结构的核心错误
当前轨迹中**seize("transportation", 6) 和 batch(n=6) 的顺序完全颠倒**,是模拟终止的根本原因:
- 每个周转箱单独执行轨迹,都会尝试抢占6个运输资源单位,但运输资源总容量仅为6。第一个周转箱会直接占满所有运输资源,剩下5个周转箱永远卡在
seize步骤,无法到达batch节点,永远凑不齐6个触发后续流程,最终模拟因无法推进而终止。 - 移除
batch后,每个周转箱能单独完成运输步骤(虽不符合“集齐6个才运输”的需求),所以模拟能正常运行。
2. 正确的轨迹逻辑
必须先通过batch集齐6个周转箱,再统一抢占运输资源,完成运输后拆分(separate),让每个周转箱继续后续流程。调整后的关键运输段顺序:
# 正确的运输段逻辑 batch(n = 6) %>% # 先集齐6个周转箱 seize("transportation", 6) %>% # 统一抢占运输资源 timeout(4) %>% # 运输时间 release("transportation", 6) %>% # 释放运输资源 separate() %>% # 拆分周转箱,各自继续后续流程
3. 修正后的完整代码
library(simmer) library(parallel) library(simmer.bricks) library(simmer.plot) library(magrittr) set.seed(333) num_tote_bins <- 6 # 周转箱数量 totebin_movement <- trajectory("totebin_movement") %>% timeout(1, tag = "Inspection") %>% # 检测时间 # 维护环节 seize("Maintenance_Dept", 1) %>% timeout(1) %>% # 维护时间1天 release("Maintenance_Dept", 1) %>% # 生产线1生产 seize("Production_Line_1", 1) %>% timeout(1) %>% # 生产时间1天 release("Production_Line_1", 1) %>% # 成品库存暂存 seize("FG Inv", 1) %>% timeout(1) %>% # 暂存延迟 release("FG Inv", 1) %>% # 运输环节(修正顺序) batch(n = 6) %>% # 先集齐6个周转箱 seize("transportation", 6) %>% timeout(4) %>% # 运输时间 release("transportation", 6) %>% separate() %>% # 拆分后各自继续 # 生产线2生产 seize("Production_Line_2", 1) %>% timeout(2) %>% release("Production_Line_2", 1) %>% # 返回运输 seize("return_transport", 1) %>% timeout(4) %>% # 返回运输时间 release("return_transport", 1) %>% rollback(times = Inf, target = "Inspection") # 循环执行 # 绘图(可选) get_palette <- scales::brewer_pal(type = "qual", palette = 1) plot(totebin_movement, fill = get_palette, verbose = TRUE) # 模拟环境搭建 totebin_simulation <- simmer("totebin_simulation") %>% add_resource("Maintenance_Dept", capacity = 2 ) %>% add_resource("Production_Line_1", capacity = 6) %>% add_resource("FG Inv", capacity = 20) %>% add_resource("transportation", capacity = 6 ) %>% add_resource("Production_Line_2", capacity = 6) %>% add_resource("return_transport", capacity = 6) # 添加6个周转箱,初始时刻全部启动 for (i in 1:num_tote_bins) { totebin_simulation <- totebin_simulation %>% add_generator(paste0("ToteBin_", i), trajectory = totebin_movement, distribution = at(0)) } # 运行模拟 totebin_simulation <- run(totebin_simulation, until = 365) # 提取结果 rotation <- get_mon_arrivals(totebin_simulation, per_resource = TRUE ) resource_usage <- get_mon_resources(totebin_simulation)
4. Generator的选择
不需要更换generator,使用at(0)一次性生成6个周转箱完全符合需求,能保证初始时刻所有周转箱都进入循环流程,满足“集齐6个才运输”的规则前提。
内容的提问来源于stack exchange,提问作者RohitSSS
相关产品推荐
相关产品推荐

