renege: Renege on some Condition

renegeR Documentation

Renege on some Condition

Description

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.

Value

Returns the trajectory object.

See Also

handle_unfinished

send

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

## 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


simmer documentation built on Sept. 28, 2024, 1:07 a.m.