Skip to contents

Activity for selecting a resource for a subsequent seize/release or setting its parameters (capacity or queue size). Resources must be defined in the simulation environment (see add_resource).

Usage

select(.trj, resources, policy = c("shortest-queue",
  "shortest-queue-available", "round-robin", "round-robin-available",
  "first-available", "random", "random-available"), id = 0, ..., tag)

Arguments

.trj

the trajectory object.

resources

one or more resource names, or a callable object (a function) which must return one or more resource names.

policy

if resources is a character vector, this parameter determines the criteria for selecting a resource among the set of policies available (see details).

id

selection identifier for nested usage.

...

unused.

tag

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

Value

Returns the trajectory object.

Details

The 'shortest-queue' policy selects the least busy resource; 'round-robin' selects resources in cyclical order; 'first-available' selects the first resource available, and 'random' selects a resource randomly.

All the 'available'-ending policies ('first-available', but also 'shortest-queue-available', 'round-robin-available' and 'random-available') check for resource availability (i.e., whether the capacity is non-zero), and exclude from the selection procedure those resources with capacity set to zero. This means that, for these policies, an error will be raised if all resources are unavailable.

Examples

## predefined policy
traj <- trajectory() %>%
  select(paste0("doctor", 1:3), "round-robin") %>%
  seize_selected(1) %>%
  timeout(5) %>%
  release_selected(1)

simmer() %>%
  add_resource("doctor1") %>%
  add_resource("doctor2") %>%
  add_resource("doctor3") %>%
  add_generator("patient", traj, at(0, 1, 2)) %>%
  run() %>%
  get_mon_resources()
#>   resource time server queue capacity queue_size system limit replication
#> 1  doctor1    0      1     0        1        Inf      1   Inf           1
#> 2  doctor2    1      1     0        1        Inf      1   Inf           1
#> 3  doctor3    2      1     0        1        Inf      1   Inf           1
#> 4  doctor1    5      0     0        1        Inf      0   Inf           1
#> 5  doctor2    6      0     0        1        Inf      0   Inf           1
#> 6  doctor3    7      0     0        1        Inf      0   Inf           1

## custom policy
env <- simmer()
res <- paste0("doctor", 1:3)

traj <- trajectory() %>%
  select(function() {
    occ <- get_server_count(env, res) + get_queue_count(env, res)
    res[which.min(occ)[1]]
  }) %>%
  seize_selected(1) %>%
  timeout(5) %>%
  release_selected(1)

for (i in res) env %>%
  add_resource(i)
env %>%
  add_generator("patient", traj, at(0, 1, 2)) %>%
  run() %>%
  get_mon_resources()
#>   resource time server queue capacity queue_size system limit replication
#> 1  doctor1    0      1     0        1        Inf      1   Inf           1
#> 2  doctor2    1      1     0        1        Inf      1   Inf           1
#> 3  doctor3    2      1     0        1        Inf      1   Inf           1
#> 4  doctor1    5      0     0        1        Inf      0   Inf           1
#> 5  doctor2    6      0     0        1        Inf      0   Inf           1
#> 6  doctor3    7      0     0        1        Inf      0   Inf           1