branch: Fork the Trajectory Path

View source: R/trajectory-activities.R

branchR Documentation

Fork the Trajectory Path

Description

Activity for defining a fork with N alternative sub-trajectories.

Usage

branch(.trj, option, continue, ..., tag)

Arguments

.trj

the trajectory object.

option

a callable object (a function) which must return an integer between 0 and N. A return value equal to 0 skips the branch and continues to the next activity. A returning value between 1 to N makes the arrival to follow the corresponding sub-trajectory.

continue

a vector of N booleans that indicate whether the arrival must continue to the main trajectory after each sub-trajectory or not (if only one value is provided, it will be recycled to match the number of sub-trajectories).

...

N trajectory objects (or a list of N trajectory objects) describing each sub-trajectory.

tag

activity tag name to perform named rollbacks (see rollback) or just to better identify your activities.

Value

Returns the trajectory object.

Examples

env <- simmer()

traj <- trajectory() %>%
  set_global("path", 1, mod="+", init=-1) %>%
  log_(function() paste("Path", get_global(env, "path"), "selected")) %>%
  branch(
    function() get_global(env, "path"), continue=c(TRUE, FALSE),
    trajectory() %>%
      log_("following path 1"),
    trajectory() %>%
      log_("following path 2")) %>%
  log_("continuing after the branch (path 0)")

env %>%
  add_generator("dummy", traj, at(0:2)) %>%
  run() %>% invisible


Bart6114/simmer documentation built on Oct. 2, 2024, 4:52 p.m.