Activities for leaving with some probability, or for setting or unsetting a timer or a signal after which the arrival will abandon.
Usage
leave(.trj, prob, out = NULL, keep_seized = TRUE, ..., tag)
renege_in(.trj, t, out = NULL, keep_seized = FALSE, ..., tag)
renege_if(.trj, signal, out = NULL, keep_seized = FALSE, ..., tag)
renege_abort(.trj, ..., tag)
Arguments
- .trj
the trajectory object.
- prob
a probability or a function returning a probability.
- out
optional sub-trajectory in case of reneging.
- keep_seized
whether to keep already seized resources. By default, all resources are released.
- ...
unused.
- tag
activity tag name to perform named rollbacks (see
rollback
) or just to better identify your activities.- t
timeout to trigger reneging, accepts either a numeric or a callable object (a function) which must return a numeric.
- signal
signal to trigger reneging, accepts either a string or a callable object (a function) which must return a string.
Details
Arrivals that leave the trajectory will set the finished
flag
to FALSE
in the output of get_mon_arrivals
. Unfinished
arrivals can be handled with a drop-out trajectory that can be set using the
optional argument out
or the handle_unfinished
activity.
Note that, for historical reasons, leave
has keep_seized=TRUE
by default, while renege_*
does not.
Note that renege_if
works similarly to trap
,
but in contrast to that, reneging is triggered even if the arrival is waiting
in a queue or is part of a non-permanent batch
.
Examples
## leave with some probability
set.seed(1234)
traj <- trajectory() %>%
log_("leave with some probability") %>%
leave(function() runif(1) < 0.5) %>%
log_("didn't leave")
simmer() %>%
add_generator("dummy", traj, at(0, 1)) %>%
run() %>% invisible
#> 0: dummy0: leave with some probability
#> 1: dummy1: leave with some probability
#> 1: dummy1: didn't leave
## reneging after some time
bank <- trajectory() %>%
log_("here I am") %>%
# renege in 5 minutes
renege_in(
5,
out = trajectory() %>%
log_("lost my patience. Reneging...")) %>%
seize("clerk") %>%
# stay if I'm being attended within 5 minutes
renege_abort() %>%
log_("I'm being attended") %>%
timeout(10) %>%
release("clerk") %>%
log_("finished")
simmer() %>%
add_resource("clerk", 1) %>%
add_generator("customer", bank, at(0, 1)) %>%
run() %>% invisible
#> 0: customer0: here I am
#> 0: customer0: I'm being attended
#> 1: customer1: here I am
#> 6: customer1: lost my patience. Reneging...
#> 10: customer0: finished