Activities for defining a parallel fork and removing the copies. clone
replicates an arrival n
times (the original one + n-1
copies).
synchronize
removes all but one clone for each set of clones.
Arguments
- .trj
the trajectory object.
- n
number of clones, accepts either a numeric or a callable object (a function) which must return a numeric.
- ...
a number of optional parallel sub-trajectories (or a list of sub-trajectories). Each clone will follow a different sub-trajectory if available.
- tag
activity tag name to perform named rollbacks (see
rollback
) or just to better identify your activities.- wait
if
FALSE
, all clones but the first to arrive are removed. ifTRUE
(default), all clones but the last to arrive are removed.- mon_all
if
TRUE
,get_mon_arrivals
will show one line per clone.
Examples
## clone and wait for the others
traj <- trajectory() %>%
clone(
n = 3,
trajectory() %>%
log_("clone 0 (original)") %>%
timeout(1),
trajectory() %>%
log_("clone 1") %>%
timeout(2),
trajectory() %>%
log_("clone 2") %>%
timeout(3)) %>%
log_("sync reached") %>%
synchronize(wait = TRUE) %>%
log_("leaving")
simmer() %>%
add_generator("arrival", traj, at(0)) %>%
run() %>% invisible
#> 0: arrival0: clone 0 (original)
#> 0: arrival0: clone 1
#> 0: arrival0: clone 2
#> 1: arrival0: sync reached
#> 2: arrival0: sync reached
#> 3: arrival0: sync reached
#> 3: arrival0: leaving
## more clones that trajectories available
traj <- trajectory() %>%
clone(
n = 5,
trajectory() %>%
log_("clone 0 (original)") %>%
timeout(1)) %>%
log_("sync reached") %>%
synchronize(wait = TRUE) %>%
log_("leaving")
simmer() %>%
add_generator("arrival", traj, at(0)) %>%
run() %>% invisible
#> 0: arrival0: clone 0 (original)
#> 0: arrival0: sync reached
#> 0: arrival0: sync reached
#> 0: arrival0: sync reached
#> 0: arrival0: sync reached
#> 1: arrival0: sync reached
#> 1: arrival0: leaving
## clone and continue without waiting
traj <- trajectory() %>%
clone(
n = 3,
trajectory() %>%
log_("clone 0 (original)") %>%
timeout(1),
trajectory() %>%
log_("clone 1") %>%
timeout(2),
trajectory() %>%
log_("clone 2") %>%
timeout(3)) %>%
log_("sync reached") %>%
synchronize(wait = FALSE) %>%
log_("leaving")
simmer() %>%
add_generator("arrival", traj, at(0)) %>%
run() %>% invisible
#> 0: arrival0: clone 0 (original)
#> 0: arrival0: clone 1
#> 0: arrival0: clone 2
#> 1: arrival0: sync reached
#> 1: arrival0: leaving
#> 2: arrival0: sync reached
#> 3: arrival0: sync reached