Not sure how to fix the problem in simmer simulation

Hello. I am tying to create a code in order to simulate the arrivals, service time and waiting time of vessels (deep-sea and inland barges). I use the following code but the activity times turn out to be wrong therefore affecting the waiting times. For the rgamma inputs I used (number of arrivals, shape, scale) for the add_generator function whereas for the timeout function it only lets me put 1 as the first input in rgamma or else I get the message "Expecting a single value". Perhaps this is my issue?

My code:
set.seed(1269)

terminal <- simmer("terminal")

deepsea <-
trajectory("Deep sea path") %>%
log_("Here I am") %>%
set_attribute("start_time", function() {now(terminal)}) %>%
seize("berth") %>%
timeout(function() {rgamma(1,2.53,0.4)}) %>%

log_(function() {paste("Waited: ", now(terminal) - get_attribute(terminal, "start_time"))}) %>%

release("berth") %>%
log_(function() {paste("Finished: ", now(terminal))})

barge <-
trajectory("Barge path") %>%
log_("Here I am") %>%
set_attribute("start_time", function() {now(terminal)}) %>%
seize("berth") %>%

log_(function() {paste("Waited: ", now(terminal) - get_attribute(terminal, "start_time"))}) %>%

timeout(function() {rgamma(1, 1.24,0.09)}) %>%
release("berth") %>%
log_(function() {paste("Finished: ", now(terminal))})

terminal <-
simmer("terminal") %>%
add_resource("berth",8) %>%
add_generator("Deep sea vessel", deepsea, function() {c(0, rgamma(79, 1.47,0.23))}) %>%
add_generator("Barge", barge, function() {c(0, rgamma(609,1.14,0.04))}) %>%
run(until = 500)

terminal %>%
get_mon_arrivals() %>%
transform(waiting_time = end_time - start_time - activity_time)

I can run your code without encountering any (error) messages other than (the expected?) :

... (previous log messages removed)
459.001: Deep sea vessel81: Here I am
465.171: Deep sea vessel81: Finished:  0
467.804: Deep sea vessel82: Here I am
469.125: Deep sea vessel83: Here I am
472.329: Deep sea vessel83: Finished:  0
477.765: Deep sea vessel82: Finished:  0
477.99: Deep sea vessel84: Here I am
481.493: Deep sea vessel85: Here I am
481.517: Barge22: Here I am
486.295: Deep sea vessel84: Finished:  0
488.819: Deep sea vessel85: Finished:  0
489.986: Barge22: Finished:  0
495.945: Deep sea vessel86: Here I am

Maybe it also works for you in a clean R environment?

Update: why would you expect timeout to have more than one value?
Or would you like to use timeout(function() {sum(rgamma(n,2.53,0.4))}) for some n ?

Thank you for your responce! No, I do not need the sum in the timeout function but my issue is that the activity time turns out to be really close to: (end time-start time) which is not correct so there is a problem with the calculation for the activity time. I thought that since the problem is there it is affected by the timeout function which is used for the service time (right now activity time calculates the whole time in the system and not just the service time)

If I understand you correctly you think that you should see some waiting time from time to time (?) . With the current parameters and random seed there are none.
But if you set the capacity of berths to 5 some waiting time will occur.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.