Skip to contents

These convenience functions facilitate the definition of generators of arrivals for some common cases.

Usage

at(...)

from(start_time, dist, arrive = TRUE)

to(stop_time, dist)

from_to(start_time, stop_time, dist, arrive = TRUE, every = NULL)

when_activated(n = 1)

Arguments

...

a vector or multiple parameters of times at which to initiate an arrival.

start_time

the time at which to launch the initial arrival (numeric or function).

dist

a function modelling the interarrival times. It is supposed to be an infinite source of values >= 0 (e.g., rexp and the like). If the function provided returns any negative value, the behaviour is undefined.

arrive

if set to TRUE (default) the first arrival will be generated at start_time and will follow dist from then on. If set to FALSE, will initiate dist at start_time (and the first arrival will most likely start at a time later than start_time).

stop_time

the time at which to stop the generator (numeric or function).

every

repeat with this time cycle (numeric or function).

n

an integer or a callable object (a function) which must return a number of arrivals to generate when activated.

Value

Returns a generator function (a closure).

Details

at generates arrivals at specific absolute times.

from generates inter-arrivals following a given distribution with a specified start time. union of the last two.

to generates inter-arrivals following a given distribution with a specified stop time.

from_to is the union of from and to.

when_activated sets up an initially inactive generator which generates n arrivals each time it is activated from any trajectory using the activity activate.

See also

Examples

## common to all examples below
# some trajectory
t0 <- trajectory() %>%
  timeout(0)
# some distribution
distr <- function() runif(1, 1, 2)

# arrivals at 0, 1, 10, 30, 40 and 43
simmer() %>%
  add_generator("dummy", t0, at(0, c(1,10,30), 40, 43)) %>%
  run(100) %>%
  get_mon_arrivals()
#>     name start_time end_time activity_time finished replication
#> 1 dummy0          0        0             0     TRUE           1
#> 2 dummy1          1        1             0     TRUE           1
#> 3 dummy2         10       10             0     TRUE           1
#> 4 dummy3         30       30             0     TRUE           1
#> 5 dummy4         40       40             0     TRUE           1
#> 6 dummy5         43       43             0     TRUE           1

# apply distribution starting at 5 (and no end)
simmer() %>%
  add_generator("dummy", t0, from(5, distr)) %>%
  run(10) %>%
  get_mon_arrivals()
#>     name start_time end_time activity_time finished replication
#> 1 dummy0   5.000000 5.000000             0     TRUE           1
#> 2 dummy1   6.298666 6.298666             0     TRUE           1
#> 3 dummy2   8.009420 8.009420             0     TRUE           1
#> 4 dummy3   9.015043 9.015043             0     TRUE           1

# apply distribution until 5 (starting at 0)
simmer() %>%
  add_generator("dummy", t0, to(5, distr)) %>%
  run(10) %>%
  get_mon_arrivals()
#>     name start_time end_time activity_time finished replication
#> 1 dummy0   1.046252 1.046252             0     TRUE           1
#> 2 dummy1   2.375289 2.375289             0     TRUE           1
#> 3 dummy2   3.798414 3.798414             0     TRUE           1
#> 4 dummy3   4.808439 4.808439             0     TRUE           1

# apply distribution from 8 to 16 h every 24 h:
simmer() %>%
  add_generator("dummy", t0, from_to(8, 16, distr, every=24)) %>%
  run(48) %>%
  get_mon_arrivals()
#>       name start_time  end_time activity_time finished replication
#> 1   dummy0   8.000000  8.000000             0     TRUE           1
#> 2   dummy1   9.491416  9.491416             0     TRUE           1
#> 3   dummy2  11.178817 11.178817             0     TRUE           1
#> 4   dummy3  12.432569 12.432569             0     TRUE           1
#> 5   dummy4  13.483285 13.483285             0     TRUE           1
#> 6   dummy5  14.792819 14.792819             0     TRUE           1
#> 7   dummy6  15.815064 15.815064             0     TRUE           1
#> 8   dummy7  32.000000 32.000000             0     TRUE           1
#> 9   dummy8  33.222330 33.222330             0     TRUE           1
#> 10  dummy9  34.947200 34.947200             0     TRUE           1
#> 11 dummy10  36.310598 36.310598             0     TRUE           1
#> 12 dummy11  38.004075 38.004075             0     TRUE           1
#> 13 dummy12  39.737375 39.737375             0     TRUE           1

# triggering arrivals on demand from a trajectory
t1 <- trajectory() %>%
  activate("dummy")

simmer() %>%
  add_generator("dummy", t0, when_activated()) %>%
  add_generator("trigger", t1, at(2)) %>%
  run() %>%
  get_mon_arrivals()
#>       name start_time end_time activity_time finished replication
#> 1 trigger0          2        2             0     TRUE           1
#> 2   dummy0          2        2             0     TRUE           1