Closed DannyO-dev closed 3 years ago
Short answer: just don't reference trajectories recursively. Trajectories are built sequentially. If you do that, wherever you insert the join
, you are referencing an object that is being built, and copying that intermediate state, so that's not a good idea.
OK all right. I am looking for a way to call up a trajectory more than once. What would be the right way to do this? I could for example do it like this:
library(simmer)
set.seed(123)
drive <- trajectory("Test Path")
controller <- trajectory("Controller")
elevator <- simmer()
drive <- drive %>%
log_("Enter trajectory") %>%
timeout(1) %>%
branch(
function() 1 > 0, continue = TRUE,
trajectory() %>%
log_(function() {
paste("Enter branch")
}),
trajectory() %>%
log_("DUMMY for branch")) %>%
log_("Leave trajectory")
controller <- controller %>%
branch(
function() 1 > 0, continue = TRUE,
trajectory() %>%
log_(function() {
paste("Restart branch")
}) %>%
join(drive),
trajectory() %>%
log_("DUMMY for branch")) %>%
rollback(1)
elevator <-
simmer("elevator") %>%
add_generator("Controller", controller, at(0))
elevator %>% run(until = 10)
Than I would need the branch a second time. Thank you in advance and best regrads
If you want to repeat something, that's a loop, and there's a mechanism for that which doesn't involve recursion: rollback()
.
Hello again, I have another question: Why is my branch in this case is not repeated?
Thank you in advance and best regards.