I have a scenario in which an arrival must seize multiple resources simultaneously, with each resource seized for a different timeout. The logical approach seems to be to use clone(); however, the problem I have here is that the number and specific names of the resources are not known a priori - they depend on certain attributes of the arrival.
If I have these resources stored as attributes of the arrival, is there some way for each clone to get a different attribute? For example, the following code sets the attributes to identify which resources are required by the arrival:
... |>
simmer::set_attribute(
keys = \() {
# Get the number of resources required
n_res <- simmer::get_attribute(env, 'res_count') |>
as.integer()
# Dynamically generate the keys sprintf('resource_%d',
seq.int(1, n_res))
},
values = \() {
# step_index identifies the state of the arrival and the appropriate resources are retrieved from a lookup table, res_df
step_index <- simmer::get_attribute(env, keys = 'step_index')
avail_res <- get_valid_resources(step_index)
# Get resource code(s) from lookup table to store in the attribute
res_codes <- res_df |>
dplyr::filter(EquipmentNbr %in% avail_res) |>
dplyr::pull(EquipmentInt)
res_codes
}
) |>
simmer::clone(n = \() simmer::get_attribute('res_count'), ...) |>
simmer::synchronize() |> ...
I'm stuck on how to dynamically define the cloned trajectories. Although one thought I just had, which I will attempt tomorrow, is to define the list of clone trajectories within one of functions used in set_attribute() and super-assign that list via <<- (perhaps with a unique name so it does not get re-used by other arrivals running in other trajectories with similar structure). Could this be feasible, or is there a more straightforward alternative?
Thank you!