Skip to content

Commit

Permalink
fix start time of arrivals in cloned batches, closes #285
Browse files Browse the repository at this point in the history
  • Loading branch information
Enchufa2 committed Sep 27, 2024
1 parent d3c3fcf commit 550e59f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion inst/include/simmer/process/arrival.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
25 changes: 24 additions & 1 deletion tests/testthat/test-trajectory-clone-synchronize.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2016-2023 Iñaki Ucar
# Copyright (C) 2016-2024 Iñaki Ucar
#
# This file is part of simmer.
#
Expand Down Expand Up @@ -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) %>%
Expand Down

0 comments on commit 550e59f

Please # to comment.