rollback {simmer} | R Documentation |
Activity for going backwards to a previous point in the trajectory. Useful to implement loops.
rollback(.trj, amount, times = Inf, check = NULL)
.trj |
the trajectory object. |
amount |
the amount of activities (of the same or parent trajectories) to roll back. |
times |
the number of repetitions until an arrival may continue. |
check |
a callable object (a function) which must return a boolean. If
present, the |
Returns the trajectory object.
## rollback a specific number of times
traj <- trajectory() %>%
log_("hello!") %>%
timeout(1) %>%
rollback(2, 3)
simmer() %>%
add_generator("hello_sayer", traj, at(0)) %>%
run() %>% invisible
## custom check
env <- simmer()
traj <- trajectory() %>%
set_attribute("var", 0) %>%
log_(function()
paste("attribute level is at:", get_attribute(env, "var"))) %>%
set_attribute("var", 25, mod="+") %>%
rollback(2, check=function() get_attribute(env, "var") < 100) %>%
log_("done")
env %>%
add_generator("dummy", traj, at(0)) %>%
run() %>% invisible