-
-
Notifications
You must be signed in to change notification settings - Fork 42
Closed
Labels
Description
I am learning and experimenting with Simmer.
In the following code, an entity in traj2 will deactivate at t= 75 a generator for traj1 (Gen1).
This deactivation can be made using deactivate("Gen1") or set_source("Gen1", function() -1).
I run the simulation two times until t = 300.
With deactivate("Gen1") it works fine : Gen1 stops producing entities at t = 75 and both runs show similar behaviours.
There are two issues when using set_source("Gen1", function() -1) :
- an additional single entity is generated by Gen1 after t = 75, at a time where it should be stopped
- in the second run Gen1 remains stopped and does not generate entities despite the reset() should have restarted it
Are these issues bugs or am I missing something ?
Thanks
rm(list=ls())
library(simmer)
sim <- simmer("Simulation")
traj1 <- trajectory("Traj1") %>%
set_attribute("TIME", now(sim))
traj2 <- trajectory("Traj2")%>%
# set_source("Gen1", function() -1)
deactivate("Gen1")
################################################################################
sim %>%
add_generator("Gen2", traj1, from(0, function() rexp(1, 0.2)), mon=2) %>%
add_generator("Gen1", traj1, from(0, function() rexp(1, 2.1)), mon=2) %>%
add_generator("STOPPER", traj2, at(75), mon=2)
sim %>% run(300)
arrivals <- get_mon_arrivals(sim)
mon <- get_mon_attributes(sim)
time <- mon[mon$key == "TIME", ]
time <- time[order(time$value),]
time$N <- 1
time$cumul <- cumsum(time$N)
plot(time$time, time$cumul, lwd=4, type="l", col=rgb(0.9, 0.3, 0.9, .8), ylim=c(0, 300), xlim=c(0, 300))
#################################################################
#### second run
#################################################################
reset(sim)
sim %>% run(300)
arrivals <- get_mon_arrivals(sim)
mon <- get_mon_attributes(sim)
time <- mon[mon$key == "TIME", ]
time <- time[order(time$value),]
time$N <- 1
time$cumul <- cumsum(time$N)
lines(time$time, time$cumul, lwd=3, col=rgb(0.2, 0.3, 0.9, .9))