From 550e59fbca32304abcdfd1fa3560f13be4a2f93d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20=C3=9Acar?= Date: Fri, 27 Sep 2024 16:33:00 +0200 Subject: [PATCH] fix start time of arrivals in cloned batches, closes #285 --- DESCRIPTION | 2 +- NEWS.md | 1 + inst/include/simmer/process/arrival.h | 3 ++- .../test-trajectory-clone-synchronize.R | 25 ++++++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1b2182a..51e810e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: simmer Type: Package Title: Discrete-Event Simulation for R -Version: 4.4.6.7 +Version: 4.4.6.8 Authors@R: c( person("Iñaki", "Ucar", email="iucar@fedoraproject.org", role=c("aut", "cph", "cre"), comment=c(ORCID="0000-0001-6403-5550")), diff --git a/NEWS.md b/NEWS.md index 97d04e2..f8dfc95 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ - Fix `set_source()` to avoid leaking arrivals from the old source (#322). - Fix sources to properly reset distributions and trajectories (#324). - Fix resources to properly reset initial parameters (#325). +- Fix start time of arrivals in cloned batches (#285). # simmer 4.4.6.4 diff --git a/inst/include/simmer/process/arrival.h b/inst/include/simmer/process/arrival.h index e251395..ffa5a11 100644 --- a/inst/include/simmer/process/arrival.h +++ b/inst/include/simmer/process/arrival.h @@ -73,7 +73,8 @@ namespace simmer { Arrival(const Arrival& o) : Process(o), order(o.order), src(o.src), paused(o.paused), sync(o.sync), - clones(o.clones), activity(NULL), attributes(o.attributes), timer(NULL), + clones(o.clones), lifetime(o.lifetime), activity(NULL), + attributes(o.attributes), timer(NULL), dropout(NULL), batch(NULL), act_shd(o.act_shd) { init(); *sync = NULL; } diff --git a/tests/testthat/test-trajectory-clone-synchronize.R b/tests/testthat/test-trajectory-clone-synchronize.R index 0d00761..bf3393a 100644 --- a/tests/testthat/test-trajectory-clone-synchronize.R +++ b/tests/testthat/test-trajectory-clone-synchronize.R @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2023 Iñaki Ucar +# Copyright (C) 2016-2024 Iñaki Ucar # # This file is part of simmer. # @@ -130,6 +130,29 @@ test_that("clones synchronize with the last (2)", { expect_equal(arrivals$finished, rep(TRUE, 3)) }) +test_that("clones synchronize with the last (3)", { + t <- function(x, y) trajectory() %>% + batch(3) %>% + clone(n = 2, + trajectory("original") %>% + timeout(x), + trajectory("clone 1") %>% + timeout(y)) %>% + synchronize(wait = TRUE) %>% + separate() + + arrivals1 <- simmer(verbose = env_verbose) %>% + add_generator("dummy" , t(4, 5), at(c(5, 10, 20))) %>% + run() %>% + get_mon_arrivals() + arrivals2 <- simmer(verbose = env_verbose) %>% + add_generator("dummy" , t(5, 4), at(c(5, 10, 20))) %>% + run() %>% + get_mon_arrivals() + + expect_equal(arrivals1, arrivals2) +}) + test_that("clones synchronize with the first (1)", { t <- trajectory() %>% batch(1) %>%