Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset() does not restore initial sources and trajectories #324

Closed
jr1234567 opened this issue Sep 26, 2024 · 2 comments
Closed

reset() does not restore initial sources and trajectories #324

jr1234567 opened this issue Sep 26, 2024 · 2 comments
Labels

Comments

@jr1234567
Copy link

In the following simulation, when the generator "Gen" is stopped using set_source, it remains permanently stopped in subsequent runs despite the simulation being resetted using reset() function.

Whereas it is re-started when using the function deactivate to stop the generator.

WITH set_source()

library(simmer)

set.seed(123)
sim <- simmer(" Simulation")

traj1 <- trajectory("traj1") %>%
  timeout(function() 100)

traj2 <- trajectory("traj2") %>%
set_source("Gen", function() -10)

env <- sim %>%
  add_generator("Gen", traj1, from(0, function() 1)) %>%
  add_generator("Stopper", traj2, at(1.5), mon=2)  %>%
  run(600) 

arrivals <- get_mon_arrivals(env) 
arrivals[order(arrivals$start_time), ]

  name start_time end_time activity_time finished replication

2 Gen0 0.0 100.0 100 TRUE 1
3 Gen1 1.0 101.0 100 TRUE 1
1 Stopper0 1.5 1.5 0 TRUE 1
4 Gen2 2.0 102.0 100 TRUE 1

#################################################################
#### second run
#################################################################
reset(sim)

sim %>%  run(300) 
arrivals <- get_mon_arrivals(env) 
arrivals[order(arrivals$start_time), ]`

  name start_time end_time activity_time finished replication

1 Stopper0 1.5 1.5 0 TRUE 1

WITH deactivate()

library(simmer)

set.seed(123)
sim <- simmer(" Simulation")

traj1 <- trajectory("traj1") %>%
  timeout(function() 100)

traj2 <- trajectory("traj2") %>%
# set_source("Gen", function() -10)
deactivate("Gen")

env <- sim %>%
  add_generator("Gen", traj1, from(0, function() 1)) %>%
  add_generator("Stopper", traj2, at(1.5), mon=2)  %>%
  run(600) 

arrivals <- get_mon_arrivals(env) 
arrivals[order(arrivals$start_time), ]

  name start_time end_time activity_time finished replication

2 Gen0 0.0 100.0 100 TRUE 1
3 Gen1 1.0 101.0 100 TRUE 1
1 Stopper0 1.5 1.5 0 TRUE 1

#################################################################
#### second run
#################################################################

reset(sim)

sim %>%  run(3000) 
arrivals <- get_mon_arrivals(env) 
arrivals[order(arrivals$start_time), ]

  name start_time end_time activity_time finished replication

2 Gen0 0.0 100.0 100 TRUE 1
3 Gen1 1.0 101.0 100 TRUE 1
1 Stopper0 1.5 1.5 0 TRUE 1

@Enchufa2 Enchufa2 changed the title a generator stopped using set_source() does not get re-started in subsequent runs despite a reset() reset() does not restore initial sources and trajectories Sep 26, 2024
@Enchufa2 Enchufa2 added the bug label Sep 26, 2024
@Enchufa2
Copy link
Member

Enchufa2 commented Sep 27, 2024

Here's a test case:

library(simmer)

t0 <- trajectory() %>%
  timeout(1)

t1 <- trajectory() %>%
  set_source("gen", at(10)) %>%
  set_trajectory("gen", t0)

env <- simmer() %>%
  add_generator("gen", t1, at(0)) %>%
  run()

df1 <- get_mon_arrivals(env)

env %>%
  reset() %>%
  run()

df2 <- get_mon_arrivals(env)

testthat::expect_equal(df1, df2)

@jr1234567
Copy link
Author

jr1234567 commented Sep 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants