I realize there are not a lot of questions here about using the Simmer package for discrete events simulation in R, but I have gone through all the vignettes and cannot find an answer to perform this seemingly simple task.
I would like to model 2 customers arriving at a random, triangularly distributed check in, with a constant inter-arrival time of 10 minutes. Here is the trajectory I have created using simmer:
library(simmer)
traj <- trajectory("admin") %>%
seize("check_in") %>%
timeout(function() rtriangle(a=1, b=3, c=2)) %>%
release("check_in")
outpat_clinic <- simmer() %>%
add_generator("customer", traj, function(){c(0,rep(20,5),-1)}) %>%
add_resource("check_in", 1)
The 'Many customers' subheading here: https://cran.r-project.org/web/packages/simmer/vignettes/D-bank-1.html#more-customers Is what I have used to get the code above.
Running the above code and checking arrival times shows that the above code simulates a constant inter-arrival time of 20 minutes, but does not have the feature of 2 patients arriving at those times. I am unsure how to create a function to reflect this.
Running the model gives me the following output:
run(clinic, 100)
get_mon_arrivals(clinic)
name start_time end_time activity_time finished replication
1 customer0 0 1.623746 1.623746 TRUE 1
2 customer1 20 22.336749 2.336749 TRUE 1
3 customer2 40 42.216531 2.216531 TRUE 1
4 customer3 60 62.019354 2.019354 TRUE 1
5 customer4 80 81.995766 1.995766 TRUE 1
Any insights on this would be much appreciated.
Just started playing with this nifty package myself. Could you not just include another add_generator
for the same trajectory?
# with inter-arrival time = 10 mins
clinic <- simmer() %>%
add_generator("customer_1", traj, function(){c(0,rep(10,5),-1)}) %>%
add_generator("customer_2", traj, function(){c(0,rep(10,5),-1)}) %>%
add_resource("check_in", 1)
Output:
name start_time end_time activity_time finished replication
1 customer_10 0 2.391233 2.391233 TRUE 1
2 customer_20 0 4.699580 2.308347 TRUE 1
3 customer_11 10 11.700081 1.700081 TRUE 1
4 customer_21 10 13.459180 1.759099 TRUE 1
5 customer_12 20 21.723494 1.723494 TRUE 1
6 customer_22 20 23.515589 1.792095 TRUE 1
7 customer_13 30 31.279699 1.279699 TRUE 1
8 customer_23 30 32.797642 1.517943 TRUE 1
9 customer_14 40 41.730055 1.730055 TRUE 1
10 customer_24 40 43.690247 1.960192 TRUE 1
11 customer_15 50 52.748773 2.748773 TRUE 1
12 customer_25 50 53.986411 1.237638 TRUE 1
Also i think your trajectory
has the timeout
following a random triangualar dist, not the arrival. There's also some info here on combining separate trajectories.