我正在尝试将get_mon_resources
存储到数据变量中。
library(simmer)
SystemTime <- 200
delay= c(20,40,60,80,100,120,140,160,180,200)/60
set.seed(1234)
elevators <-lapply(1:100, function(i) {
elevator <- simmer("elevator")
worker <-
trajectory("elevator service") %>% #trajectory name
log_("new worker arrived") %>% #
set_attribute("start_time", function() {now(elevator)}) %>%
seize("elevator",amount = 1) %>% #elevator queue and service
timeout(function() sample(delay,1)) %>%
log_(function() {paste("Waited: ", now(elevator) - get_attribute(elevator, "start_time"))}) %>%
release("elevator")
elevator %>%
add_generator("worker", worker, function() rexp(1, 2)) %>%
add_resource("elevator", capacity = 2) %>%
run(until = SystemTime)
mydata <- get_mon_resources(elevator)
})
但mydata <- get_mon_resources(elevator)
命令行不起作用
答案 0 :(得分:0)
您尚未将mydata变量声明为全局变量,因为您无法访问外部变量。使用以下代码访问mydata <- get_mon_resources(elevator)
mydata <<- get_mon_resources(elevator)
答案 1 :(得分:0)
library(simmer)
SystemTime <- 200
delay= c(20,40,60,80,100,120,140,160,180,200)/60
Start_times <<-data.frame(row.names=TRUE)
set.seed(1234)
elevators <-lapply(1:10, function(i) {
elevator <- simmer("elevator")
worker <-
trajectory("elevator service") %>% #trajectory name
log_("new worker arrived") %>% #
set_attribute("start_time", function() {now(elevator)}) %>%
seize("elevator",amount = 1) %>% #elevator queue and service
timeout(function() sample(delay,1)) %>%
Start_times<<-rbind(get_attribute(elevator, "start_time"),Start_times)%>%
log_(function() {paste("Waited: ", now(elevator) - get_attribute(elevator, "start_time"))}) %>%
release("elevator")
elevator %>%
add_generator("worker", worker, function() rexp(1, 2)) %>%
add_resource("elevator", capacity = 2) %>%
run(until = SystemTime)
})
答案 2 :(得分:0)
get_mon_*()
方法也适用于模拟列表:
library(simmer)
SystemTime <- 200
delay= c(20,40,60,80,100,120,140,160,180,200)/60
set.seed(1234)
elevators <-lapply(1:100, function(i) {
elevator <- simmer("elevator")
worker <-
trajectory("elevator service") %>% #trajectory name
#log_("new worker arrived") %>% #
set_attribute("start_time", function() {now(elevator)}) %>%
seize("elevator",amount = 1) %>% #elevator queue and service
timeout(function() sample(delay,1)) %>%
#log_(function() {paste("Waited: ", now(elevator) - get_attribute(elevator, "start_time"))}) %>%
release("elevator")
elevator %>%
add_generator("worker", worker, function() rexp(1, 2)) %>%
add_resource("elevator", capacity = 2) %>%
run(until = SystemTime)
})
mydata <- get_mon_resources(elevators)
head(mydata)
#> resource time server queue capacity queue_size system limit replication
#> 1 elevator 1.250879 1 0 2 Inf 1 Inf 1
#> 2 elevator 1.254170 2 0 2 Inf 2 Inf 1
#> 3 elevator 1.420254 2 1 2 Inf 3 Inf 1
#> 4 elevator 1.434505 2 2 2 Inf 4 Inf 1
#> 5 elevator 1.628096 2 3 2 Inf 5 Inf 1
#> 6 elevator 1.673071 2 4 2 Inf 6 Inf 1
答案 3 :(得分:0)