library(simmer)library(simmer.plot)
tmax <- 100
#set TimeoutsTIME_OUT <- 5 TIME_OUT_2 <- 20INTAKE_TIMES <- at(seq(from = 0, to = tmax, by = 0.1))
#Basic seize/release trajectory with constant timeouttrj_1 <- trajectory() %>% seize("resrc")%>% timeout(TIME_OUT)%>% release("resrc")%>% seize("resrc2")%>% timeout(TIME_OUT_2)%>% release("resrc2")
#Basic Trajectory with signalling and "do nothing" handlerhandlr <- trajectory()%>% set_attribute(c("start", "delay"), function() { left <- sum(get_attribute(envs, c("start", "delay"))) - now(envs) delay <- left c(now(envs), delay) })%>% timeout_from_attribute("delay")
trj_2 <- trajectory()%>% seize("resrc")%>% set_attribute(c("start","delay"), function() c(now(envs), TIME_OUT))%>% trap("sgnl", handlr)%>% send("sgnl")%>% untrap("sgnl") %>% release("resrc")%>% send("sgnl")%>% seize("resrc2")%>% #seize resource 2 send("sgnl")%>% #update the delay of entities seizing resource 1 timeout(TIME_OUT_2)%>% release("resrc2")%>% send("sgnl")
envs <- simmer()
envs%>% add_resource("resrc", Inf, Inf)%>% add_resource("resrc2", Inf, Inf)%>% add_generator("entity", trj_2, distribution = INTAKE_TIMES)%>% run(until = tmax)%>% get_mon_resources()%>% plot(metric = "usage")
and for trajectory 2.

We can see that trajectory 1 hits the desired steady state of 50 for resource 1 while trajectory 2 does not.
What I have done so far:
1. I tried replicating the problem with only using resource 1.
Here I was not able to recreate the same problem. I tried sending the signal multiple times after untrapping and releasing resource 1. However the trj_1 and trj_2 plots remained identical with only 1 resource.
2. Removing lines of code to isolate the problem.
In trajectory 2, if I remove any one of the send("sgnl") commands after releasing resource 1 or the timeout(TIME_OUT_2) command. It results in a plot identical to trajectory 1. I also discovered here that the duration of TIME_OUT_2 affects the resource 1 usage curve.
3. I tried changing the INTAKE_TIMES data. Here I discovered that if the increment of the arrival sequence is less than or equal to 0.1 then the two plots will differ. But if the increment is greater than 0.1 then the plots for trajectory 1 and trajectory 2 will be identical.
4. I tried logging each entity as they went through the handler. Here I discovered an interesting pattern. The first 10 entities sent each time send("sgnl") is called appear to be entities from earlier in the simulation which should have been untrapped and unsubscribed from the signal. Every 5th entity from 274 to 319 seems to have not unsubscribed.
99.9: entity274: in the handler
99.9: entity279: in the handler
99.9: entity284: in the handler
99.9: entity289: in the handler
99.9: entity294: in the handler
99.9: entity299: in the handler
99.9: entity304: in the handler
99.9: entity309: in the handler
99.9: entity314: in the handler
99.9: entity319: in the handler
99.9: entity949: in the handler
99.9: entity950: in the handler
99.9: entity951: in the handler
99.9: entity952: in the handler
...
99.9: entity996: in the handler
99.9: entity997: in the handler
library(simmer)library(simmer.plot)
x0 <- c(25, 100)xtarget <- c(50, 200) c <- 0.05 a <- c * xtarget[2]b <- a / xtarget[1] tmax <- 100
TIME_OUT <- rexp(1, b)TIME_OUT_2 <- function() rexp(1, c)INTAKE_TIMES <- function() rexp(1, a)
#List of test trajectories#Basic seize/release trajectory with contant timeouttrj_1.2 <- trajectory()%>% seize("resrc2")%>% timeout(TIME_OUT_2)%>% release("resrc2")
trj_1 <- trajectory() %>% seize("resrc")%>% timeout(function() rexp(1, b))%>% release("resrc")%>% join(trj_1.2)
#Basic Trajectory with signalling and "do nothing" handlerhandlr <- trajectory()%>% set_attribute(c("start", "delay"), function() { left <- sum(get_attribute(envs, c("start", "delay"))) - now(envs) delay <- left c(now(envs), delay) })%>% timeout_from_attribute("delay")
trj_2.2 <- trajectory()%>% seize("resrc2")%>% send("sgnl")%>% timeout(TIME_OUT_2)%>% release("resrc2")%>% send("sgnl")
trj_2 <- trajectory()%>% seize("resrc")%>% set_attribute(c("start","delay","multiplier"), function() c(now(envs), rexp(1, b), 1))%>% trap("sgnl", handlr)%>% send("sgnl")%>% untrap("sgnl") %>% release("resrc")%>% send("sgnl")%>% #comment out this line for picture 3 #timeout(0)%>% #uncomment this line for picture 4 join(trj_2.2)
envs <- simmer()
envs%>% add_resource("resrc", Inf, Inf)%>% add_resource("resrc2", Inf, Inf)%>% add_generator("initial resrc", trj_1.2, at(numeric(x0[2]))) %>% add_generator("initial resrc2", trj_1, at(numeric(x0[1]))) %>% add_generator("entity", trj_1, distribution = INTAKE_TIMES)%>% run(until = tmax)
resrcs <- get_mon_resources(envs)plot(resrcs, metric = "usage")



handlr2 <- trajectory() %>% set_attribute(c("start", "delay", "multiplier"), function() { cap <- 1/3*get_server_count(envs, "resrc2") multiplier <- get_attribute(envs, "multiplier") num_mentees <- get_server_count(envs, "resrc") left <- sum(get_attribute(envs, c("start", "delay"))) - now(envs) new_multiplier <- cap/num_mentees #return new values if (num_mentees <= cap) delay <- left else delay <- left*multiplier / new_multiplier c(now(envs), delay, new_multiplier) })%>% timeout_from_attribute("delay")
trj_2 <- trajectory()%>% seize("resrc")%>% set_attribute(c("start","delay","multiplier"), function() c(now(envs), rexp(1, b), 1))%>% trap("sgnl", handlr)%>% send("sgnl")%>% untrap("sgnl") %>% release("resrc")%>% send("sgnl")%>% timeout(0)%>% timeout(0)%>% join(trj_2.2)
trj_2 <- trajectory()%>% seize("resrc")%>% set_attribute(c("start","delay","multiplier"), function() c(now(envs), rexp(1, b), 1))%>% trap("sgnl", handlr)%>% send("sgnl")%>% untrap("sgnl") %>% release("resrc")%>% # send("sgnl")%>% # timeout(0)%>% # timeout(0)%>% join(trj_2.2)
trj_2 <- trajectory()%>% seize("resrc")%>% set_attribute(c("start","delay","multiplier"), function() c(now(envs), rexp(1, b), 1))%>% trap("sgnl", handlr)%>% send("sgnl")%>% untrap("sgnl") %>% release("resrc")%>% send("sgnl")%>% # timeout(0)%>% # timeout(0)%>% join(trj_2.2)
Maybe a single consecutive run. But run many replications and you'll
see that on average it's completely equivalent to trajectory 1.

You mean compared to the MC method? Are you taking a single simmer
simulation or the average of many replications?
add_generator("initial resrc", trj_2.2, at(numeric(x0[2]))) %>% add_generator("initial resrc2", trj_2, at(numeric(x0[1]))) %>% add_generator("entity", trj_2, distribution = INTAKE_TIMES)%>% add_generator("initial resrc", trj_1.2, at(numeric(x0[2]))) %>% add_generator("initial resrc2", trj_1, at(numeric(x0[1]))) %>% add_generator("entity", trj_2, distribution = INTAKE_TIMES)%>%> To unsubscribe from this group and stop receiving emails from it, send an email to simmer...@googlegroups.com.
library(simmer)library(simmer.plot)
tmax <- 100
handlr <- trajectory()%>% set_attribute(c("start", "delay"), function() { left <- sum(get_attribute(envs, c("start", "delay"))) - now(envs) delay <- left #delay <- max(0,delay) c(now(envs), delay) })%>% timeout_from_attribute("delay")
trj <- trajectory()%>% #send("sgnl") %>% seize("resrc")%>% set_attribute(c("start","delay") , function() c(now(envs), 5))%>% trap("sgnl", handlr)%>% send("sgnl")%>% untrap("sgnl") %>% release("resrc")
envs <- simmer()
data <- data.frame(time = replicate(1000, rexp(1, 10)))init <- replicate(25, 0)
envs%>% add_resource("resrc", Inf, Inf)%>% add_generator("initial entities", trj, at(init), mon = 2) %>% #add_dataframe("signallers", trj, data)%>% run(until = tmax)
resrcs <- get_mon_resources(envs)plot(resrcs, metric = "usage")
attrbs <- get_mon_attributes(envs)plot(attrbs)