R Simmer:指定非标准路由算法时出现 "no arrival running" 错误
R Simmer: "no arrival running" errors when specifying a non-standard routing algorithm
考虑下面指定的系统和路由算法:
Image of the system。
让我们首先定义一些在模拟中有用的属性:
library(simmer)
library(parallel)
library(simmer.plot)
#############################
d<- 2
#############################
set.seed(1337)
sim<-simmer()
#let's say the system has 1000 servers/respective queues
queues<- vector(length=1000)
for (i in 1:1000) {
queues[i]<- paste0("q_",i)
}
queueing_system <- trajectory() %>%
set_attribute("X", function() rexp(1,100)) %>%
#"e_i", i in {1,2} will be the number of the queue sampled
set_attribute(paste0("e", 1:d), function() sample(1000,2)) %>%
#d_i will be the size of these respective queues
set_attribute("d1", function() get_server_count(sim,queues[get_attribute(sim,"e1")]))%>%
set_attribute("d2", function() get_server_count(sim,queues[get_attribute(sim,"e2")]))
现在,让我们定义路由算法和之后的轨迹。
我们可以尝试完全在克隆函数中表达路由算法,如下所示:
number_of_clones <- function(a,b)
{
if(function() a+b==0){2}else{1}}
routing_logic <- function(a,b,c,d)
{
if((a>=1 & b=0)|(a=0 & b>=1))
{
trajectory()%>%
select(function() queues[get_attribute(sim,c(c,d)[which(c(a,b)==0)])])%>%
seize_selected()%>%
timeout(function() get_attribute(sim, "X")*(rpois(1, 10)+1))
}
else if (a>=1 & b>=1){
trajectory()%>%
select(function() queues[get_attribute(sim,sample(c(c,d)),1)])%>%
seize_selected()%>%
timeout(function() get_attribute(sim, "X")*(rpois(1, 10)+1))
}
else if (a+b==0){
n <- trajectory()%>%
select(function() queues[get_attribute(sim,c)])%>%
seize_selected()%>%
timeout(function() get_attribute(sim, "X")*(rpois(1, 10)+1))
m <- trajectory()%>%
select(function() queues[get_attribute(sim,d)])%>%
seize_selected()%>%
timeout(function() get_attribute(sim, "X")*(rpois(1, 10)+1))
list(n,m)
}
}
#trajectory is then expressed as
queueing_system %>%
clone(number_of_clones(get_attribute(sim,"d1"),get_attribute(sim,"d2")),routing_logic(get_attribute(sim,"d1"),get_attribute(sim,"d2"),"e1","e2"))%>%
synchronize(FALSE)%>%
release_selected()
我们现在收到以下问题:
> queueing_system %>%
+ clone(number_of_clones(get_attribute(sim,"d1"),get_attribute(sim,"d2")),routing_logic(get_attribute(sim,"d1"),get_attribute(sim,"d2"),"e1","e2"))%>%
+ synchronize(FALSE)%>%
+ release_selected()
Error: there is no arrival running
我认为这与在我的 "if" 和 "else if" 语句的条件下调用函数有关,尽管我不确定我到底做错了什么。
无法直接调用函数get_attribute
。相反,它必须放在模拟期间调用的函数内。
考虑下面指定的系统和路由算法: Image of the system。 让我们首先定义一些在模拟中有用的属性:
library(simmer)
library(parallel)
library(simmer.plot)
#############################
d<- 2
#############################
set.seed(1337)
sim<-simmer()
#let's say the system has 1000 servers/respective queues
queues<- vector(length=1000)
for (i in 1:1000) {
queues[i]<- paste0("q_",i)
}
queueing_system <- trajectory() %>%
set_attribute("X", function() rexp(1,100)) %>%
#"e_i", i in {1,2} will be the number of the queue sampled
set_attribute(paste0("e", 1:d), function() sample(1000,2)) %>%
#d_i will be the size of these respective queues
set_attribute("d1", function() get_server_count(sim,queues[get_attribute(sim,"e1")]))%>%
set_attribute("d2", function() get_server_count(sim,queues[get_attribute(sim,"e2")]))
现在,让我们定义路由算法和之后的轨迹。
我们可以尝试完全在克隆函数中表达路由算法,如下所示:
number_of_clones <- function(a,b)
{
if(function() a+b==0){2}else{1}}
routing_logic <- function(a,b,c,d)
{
if((a>=1 & b=0)|(a=0 & b>=1))
{
trajectory()%>%
select(function() queues[get_attribute(sim,c(c,d)[which(c(a,b)==0)])])%>%
seize_selected()%>%
timeout(function() get_attribute(sim, "X")*(rpois(1, 10)+1))
}
else if (a>=1 & b>=1){
trajectory()%>%
select(function() queues[get_attribute(sim,sample(c(c,d)),1)])%>%
seize_selected()%>%
timeout(function() get_attribute(sim, "X")*(rpois(1, 10)+1))
}
else if (a+b==0){
n <- trajectory()%>%
select(function() queues[get_attribute(sim,c)])%>%
seize_selected()%>%
timeout(function() get_attribute(sim, "X")*(rpois(1, 10)+1))
m <- trajectory()%>%
select(function() queues[get_attribute(sim,d)])%>%
seize_selected()%>%
timeout(function() get_attribute(sim, "X")*(rpois(1, 10)+1))
list(n,m)
}
}
#trajectory is then expressed as
queueing_system %>%
clone(number_of_clones(get_attribute(sim,"d1"),get_attribute(sim,"d2")),routing_logic(get_attribute(sim,"d1"),get_attribute(sim,"d2"),"e1","e2"))%>%
synchronize(FALSE)%>%
release_selected()
我们现在收到以下问题:
> queueing_system %>%
+ clone(number_of_clones(get_attribute(sim,"d1"),get_attribute(sim,"d2")),routing_logic(get_attribute(sim,"d1"),get_attribute(sim,"d2"),"e1","e2"))%>%
+ synchronize(FALSE)%>%
+ release_selected()
Error: there is no arrival running
我认为这与在我的 "if" 和 "else if" 语句的条件下调用函数有关,尽管我不确定我到底做错了什么。
无法直接调用函数get_attribute
。相反,它必须放在模拟期间调用的函数内。