我只是想模拟一个机器维修系统。输入: 5 台触发停机事件的机器,2 名维修人员处理停机事件
注意:一旦机器停机(由于故障而无法工作),add_generator 函数将不再生成“停机事件”,因为机器已经停机/损坏(因此不能产生任何停机事件!)。
到目前为止,这是我的简单方法(它有效,但没有上述限制):
```
library(simmer)
set.seed(42)
env <- simmer("andi_simu") %>% add_global("cnt",0)
env
cnt<-0
NUM_MACHINES<-6 # equals: max. number of down machines! (obviously)
BREAK_MEAN<-1/20 # 20 = MTTF
NUM_ENGINEERS<-3
REPAIR_TIME<-1.3 # in hours
engineers <- paste0("engineer", 1:NUM_ENGINEERS-1)
downevent <- trajectory("downevents' path") %>%
## add an intake activity
select(engineers, policy = "random") %>%
set_attribute("start_time", function() {now(env)}) %>%
seize_selected(1) %>%
log_(function() {paste("Waited: ", now(env) - get_attribute(env, "start_time"))}) %>%
timeout(function() rexp(1,REPAIR_TIME)) %>%
release_selected(1)
for (i in engineers) env %>%
add_resource(i, 1, 0) #, preemptive = TRUE) %>%
env %>%
add_generator("downevent",downevent,function() rexp(1,BREAK_MEAN*NUM_MACHINES))
env %>%
run(80) %>%
now()
result <-
env %>%
get_mon_arrivals() %>%
transform(waiting_time = end_time - start_time - activity_time)
print(paste("Mean waiting time: ", mean(result$waiting_time)))
```
将不胜感激每一个提示如何做到这一点!谢谢, 安德烈亚斯