[英]R Simmer - “Number of keys and values don't match”
I am trying to simulate a JSQ(d) (join-shortest-queue of d sampled queues) system but am having trouble executing my code. 我试图模拟JSQ(d)(d采样队列的连接最短队列)系统,但是我在执行代码时遇到了问题。 In this case, let us assume d=2.
在这种情况下,我们假设d = 2。 I wish to have job size determined upon arrival (the value of "X") as well as the selection of which 2 queues will be sampled and "JSQ-ed" (this could be done perhaps differently, though for my purposes beyond this minimal working example, these must be determined upon arrival).
我希望在到达时确定工作规模(“X”的值),以及选择哪两个队列进行抽样和“JSQ-ed”(这可能会有所不同,尽管我的目的超出了这个工作实例,这些必须在抵达时确定)。
library(simmer)
set.seed(1337)
sim <- simmer("sim")
queues <- vector(length=1000)
for (i in 1:1000) {
queues[i] <- paste0("q_",i)
}
queueing_system <- trajectory() %>%
set_attribute("X", function() rexp(1)) %>%
set_attribute("d", function() sample(1000,2)) %>%
select(function() queues[get_attribute(sim, "d")], policy="shortest-queue") %>%
seize_selected()%>%
timeout(function() get_attribute(sim, "X")*(rpois(1, 1)+1)) %>%
release_selected()
for (i in 1:1000) {
sim %>%
add_resource(queues[i], 1)
}
sim %>%
add_generator("path", queueing_system, function() rexp(1,1)) %>%
run(400) %>%
now()
I receive 我收到
Error: 'path0' at 0.15 in [SetAttribute]->SetAttribute->[Select]:
number of keys and values don't match
What seems to be the issue and how might I go about fixing this? 什么似乎是问题,我怎么可能解决这个问题?
Attributes store a single value. 属性存储单个值。 Why don't you sample directly in the
select
activity? 为什么不直接在
select
活动中进行采样? Ie, 也就是说,
queueing_system <- trajectory() %>%
set_attribute("X", function() rexp(1)) %>%
select(function() queues[sample(1000, 2)], policy="shortest-queue") %>%
seize_selected()%>%
timeout(function() get_attribute(sim, "X")*(rpois(1, 1)+1)) %>%
release_selected()
I would call rexp(1)
in place too, instead of defining X
. 我也会调用
rexp(1)
,而不是定义X
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.