Skip to content

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

@jr1234567

Description

@jr1234567

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions