Hello ,
I am working with the simmer package.
There are arrivals, at absolute points in time and two trajectories, for two resources, which use one resource.
I always want one trajectory to be executed, until its queue is empty and the switch to the other one.
My code works without the switching, but with it it does not run.
library(simmer)
set.seed(2020)
max<-25
data1 <- c(3,3,4)
data2 <- c(2,3,4)
i<-0
readytraj1<-0
readytraj2<-0
env <- simmer("env")
loop1 <- function(){
a <- env %>% get_mon_arrivals("traj1")
b <- a["finished"]
ready <- nrow(b)
e<-env %>% get_n_generated("traj1")
queue <- e - ready
return(queue)
}
loop2 <- function(){
a <- env %>% get_mon_arrivals("traj2")
b <- a["finished"]
ready <- nrow(b)
e<-env %>% get_n_generated("traj2")
queue <- e - ready
return(queue)
}
traj1 <- trajectory("traj1") %>%
seize("res", 1) %>%
timeout(task = 1) %>%
release("res", 1) %>%
branch(option = function() {round(ifelse(runif(loop1()>0)))},
continue=c(FALSE, TRUE),
join(traj1),
join(traj2)%>%rollback(amount=7, times = 1,check = NULL)
)
traj2 <- trajectory("traj2") %>%
seize("res", 1) %>%
timeout(task = 1) %>%
release("res", 1) %>%
branch(option = function() {round(ifelse(runif(loop2()>0)))},
continue=c(FALSE, TRUE),
join(traj2),
join(traj1)%>%rollback(amount=7, times = 1,check = NULL)
)
env %>%
add_resource("res", 1) %>%
add_generator("one", traj1, at(c(data1)), mon=2) %>%
add_generator("two", traj2, at(c(data2)), mon=2)
env %>%
run()
env %>% get_mon_arrivals()
Thank you in advance!