Replies: 1 comment 2 replies
-
library(simmer)
bank <- simmer("bank")
customerA <- function(s) {
path = trajectory("Customer's path") %>%
log_(function() paste0("Tnow_A = ", now(s))) %>%
log_("Here I am") %>%
timeout(4) %>%
log_("I must leave")
return(path)
}
customerB <- function(s) {
join(trajectory() %>%
log_(function() paste0("Tnow_0 = ", now(s))), customerA(s))
}
add_generator(bank, "Customer", customerB(bank), at(5, 8))
#> simmer environment: bank | now: 0 | next: 0
#> { Monitor: in memory }
#> { Source: Customer | monitored: 1 | n_generated: 0 }
bank %>% run(until = 50)
#> 5: Customer0: Tnow_0 = 5
#> 5: Customer0: Tnow_A = 5
#> 5: Customer0: Here I am
#> 8: Customer1: Tnow_0 = 8
#> 8: Customer1: Tnow_A = 8
#> 8: Customer1: Here I am
#> 9: Customer0: I must leave
#> 12: Customer1: I must leave
#> simmer environment: bank | now: 12 | next:
#> { Monitor: in memory }
#> { Source: Customer | monitored: 1 | n_generated: 2 } |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Good afternoon,
I am working on a simulation model using simmer. I am really happy with this great package!
So far, everything I want to model is possible. But every now and then I run into some issues that puzzle me.
These issues are the following:
During the testing of my model, I ran into the situation where the information obtained from get_mon_arrivals includes the same arrival twice (not clones). One record where the start_time and end_time are available, and another identical record with the only difference that the end_time is missing (NA). I have solved this by simply removing the duplicate record with the missing end_time before processing the results.
The strange thing is that this issue disappeared when I made some (seemingly unrelated) changes to the model. So unfortunately I cannot reproduce this issue and provide code that caused it. But before I remove the code lines that remove the duplicate records from get_mon_arrivals, I was wondering if anyone has encountered this before.
The second issue is actually a question. In my model there are processes that clone the arrival. These cloned arrivals then continue in the process as separate arrivals and will not be merged again with the original arrival. I have marked the clones by keeping track of an attribute "clonenr" (0 = original, 1 = clone 1, 2 = clone 2 etc.) hoping that I could use this attribute to assign the records obtained from get_mon_arrivals to the correct clone (combined with info from get_mon_attributes). I was not able to get this done and I think it is not possible to do this.
So instead, I created my own output data with information per arrival/clone which is filled during the simulation. This works fine, but of course adds to the time needed to run the model.
So I wanted to check whether my assumption is indeed correct, that records from get_mon_arrivals cannot be assigned to the right clone/ original arrival.
Somehow, the now() function sometimes returns an incorrect simulation time. This does not always happen, but I was able to create a small example (derived from the banking example) where this happens.
The output of the code is as follows:
In the output, the now() function returns 0 for the simulation time, which is incorrect.
Does anyone know what is going on here?
Thanks for your help!
Beta Was this translation helpful? Give feedback.
All reactions