请考虑以下指定的系统和路由算法: Image of the system。 让我们首先定义一些在仿真中有用的属性:
library(tidyverse)
out <- bind_rows(pit_sch, .id = 'table_name')
现在,让我们定义路由算法及其后的轨迹。
我们可以尝试完全在克隆函数中表示路由算法,如下所示:
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()
我认为这与在“ if”和“ else if”语句的条件下调用函数有关,尽管不确定我到底在做什么错。
答案 0 :(得分:0)
函数get_attribute
不能直接调用。相反,必须将其放置在仿真过程中调用的函数中。