I'd like to code a simulation where all Items (A, B, C, ...) arriving are first disassembled into 2 parts. Item.subpart1 undergoes OPERATION1 directly and Item.subpart2 is collected in a batch (size = 4) before being processed with OPERATION2. After processing, I want all parts of the same item to be reassembled and not mixed with parts from other items (ie, subpart1 from A goes with subpart2 from A only).
I've tried parallel tasks to split the subparts trajectories and also tried to collect all Items.subparts2 in a batch of size 4.
library(simmer)
library(simmer.plot)
library(simmer.bricks)
items <- LETTERS[1:10]
traj <- function(item) {
trajectory() %>%
visit("operator", 10, 1) %>% # disassemble the incoming item
set_global(paste0("subpart1_", item), 1) %>%
set_global(paste0("subpart2_", item), 1) %>%
set_global("CountSubparts2", mod ="+", 1) %>%
do_parallel(
# OPERATION 1
trajectory() %>%
visit("Machine1", 150, 1) %>%
set_global(paste0("subpart1_", item), 0) %>%
set_global(paste0("subpart1_", item, "_processed"), 1)
,
# OPERATION 2
trajectory() %>%
batch(n = 4, timeout = 0, name = "POOL_PARTS") %>%
separate() %>%
visit("Machine2", 200, 1) %>%
set_global(paste0("subpart2_", item, "_processed"), 1) %>%
set_global("CountSubparts2", 0)
, .env = env, wait = TRUE
) %>%
visit("operator", 10, 1) # reassemble the items
}
env <- simmer()
env %>%
add_resource("operator", 1) %>%
add_resource("Machine1", capacity = 1, queue_size = 0, 2) %>%
add_resource("Machine2", capacity = 1, queue_size = 0, 1)
for (i in items) env %>%
add_generator(i, traj(i), at(0), mon = 2)
env %>% run(1000)
ressources <- get_mon_resources(env)
ressources %>% plot(metric = "utilization")
ressources %>% plot(metric = "usage")
attributs <- env %>% get_mon_attributes()
attributs %>% plot(key = "CountSubparts2")
The problem is : First, I expected CountSubparts2 to increase up to 4 and then decrase to 0 after OPERATION 2. Here, CountSubparts2 keeps increasing. Second, I can't find a way to explicitly tell simmer to : "reassemble subpart1_A_processed and subpart2_A_processed. Do the same for B, C,etc."
What am I missing ?
Thank you for your help !