r-simmer / simmer

Discrete-Event Simulation for R
https://r-simmer.org
GNU General Public License v2.0
223 stars 42 forks source link

get_mon_arrivals() shows incorrect results if called multiple times #247

Closed tomjemmett closed 3 years ago

tomjemmett commented 3 years ago

if you run get_mon_arrivals() with ongoing = TRUE multiple times the unfinished entities are repeated. If you run the function again with ongoing = FALSE (default argument value) the unfinished entities appear

library(simmer)
trj <- trajectory() %>%
  log_("I'm here")

env <- simmer() %>%
  add_generator("x", trj, function() 1) %>%
  run(5)
#> 1: x0: I'm here
#> 2: x1: I'm here
#> 3: x2: I'm here
#> 4: x3: I'm here

# running with ongoing = FALSE shows same results each time
get_mon_arrivals(env)
#>   name start_time end_time activity_time finished replication
#> 1   x0          1        1             0     TRUE           1
#> 2   x1          2        2             0     TRUE           1
#> 3   x2          3        3             0     TRUE           1
#> 4   x3          4        4             0     TRUE           1
get_mon_arrivals(env)
#>   name start_time end_time activity_time finished replication
#> 1   x0          1        1             0     TRUE           1
#> 2   x1          2        2             0     TRUE           1
#> 3   x2          3        3             0     TRUE           1
#> 4   x3          4        4             0     TRUE           1
# running with ongoing = TRUE multiple times causes the finished = FALSE to appear multiple times
get_mon_arrivals(env, ongoing = TRUE)
#>   name start_time end_time activity_time finished replication
#> 1   x0          1        1             0     TRUE           1
#> 2   x1          2        2             0     TRUE           1
#> 3   x2          3        3             0     TRUE           1
#> 4   x3          4        4             0     TRUE           1
#> 5   x4         -1       NA            NA    FALSE           1
get_mon_arrivals(env, ongoing = TRUE)
#>   name start_time end_time activity_time finished replication
#> 1   x0          1        1             0     TRUE           1
#> 2   x1          2        2             0     TRUE           1
#> 3   x2          3        3             0     TRUE           1
#> 4   x3          4        4             0     TRUE           1
#> 5   x4         -1       NA            NA    FALSE           1
#> 6   x4         -1       NA            NA    FALSE           1
# now runnning with ongoing = FALSE shows the finished = FALSE entities too
get_mon_arrivals(env)
#>   name start_time end_time activity_time finished replication
#> 1   x0          1        1             0     TRUE           1
#> 2   x1          2        2             0     TRUE           1
#> 3   x2          3        3             0     TRUE           1
#> 4   x3          4        4             0     TRUE           1
#> 5   x4         -1       NA            NA    FALSE           1
#> 6   x4         -1       NA            NA    FALSE           1
Enchufa2 commented 3 years ago

Already fixed, see #240, but it's not released yet. I'll submit an update to CRAN this summer.

tomjemmett commented 3 years ago

ahh, sorry, only checked open issues! Thanks! :-)