View source: R/trajectory-activities.R
| clone | R Documentation | 
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.
clone(.trj, n, ..., tag)
synchronize(.trj, wait = TRUE, mon_all = FALSE, ..., tag)
| .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
 | 
| wait | if  | 
| mon_all | if  | 
Returns the trajectory object.
## 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
## 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
## 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.