batch {simmer} | R Documentation |
Batch/Separate Arrivals
Description
Activities for collecting a number of arrivals before they can continue processing and splitting a previously established batch.
Usage
batch(.trj, n, timeout = 0, permanent = FALSE, name = "", rule = NULL,
..., tag)
separate(.trj, ..., tag)
Arguments
.trj |
the trajectory object. |
n |
batch size, accepts a numeric or a callable object (a function) which must return a numeric. |
timeout |
set an optional timer which triggers batches every
|
permanent |
if |
name |
optional string. Unnamed batches from different |
rule |
an optional callable object (a function) which will be applied to every arrival to determine whether it should be included into the batch, thus it must return a boolean. |
... |
unused. |
tag |
activity tag name to perform named rollbacks (see
|
Value
Returns the trajectory object.
Examples
## unnamed batch with a timeout
traj <- trajectory() %>%
log_("arrived") %>%
batch(2, timeout=5) %>%
log_("in a batch") %>%
timeout(5) %>%
separate() %>%
log_("leaving")
simmer() %>%
add_generator("dummy", traj, at(0:2)) %>%
run() %>% invisible
## batching based on some dynamic rule
traj <- trajectory() %>%
log_("arrived") %>%
# always FALSE -> no batches
batch(2, rule=function() FALSE) %>%
log_("not in a batch") %>%
timeout(5) %>%
separate() %>%
log_("leaving")
simmer() %>%
add_generator("dummy", traj, at(0:2)) %>%
run() %>% invisible
## named batch, shared across trajectories
traj0 <- trajectory() %>%
log_("arrived traj0") %>%
batch(2, name = "mybatch")
traj1 <- trajectory() %>%
log_("arrived traj1") %>%
timeout(1) %>%
batch(2, name = "mybatch") %>%
log_("in a batch") %>%
timeout(2) %>%
separate() %>%
log_("leaving traj1")
simmer() %>%
add_generator("dummy0", traj0, at(0)) %>%
add_generator("dummy1", traj1, at(0)) %>%
run() %>% invisible