首页 > 解决方案 > 煨回滚功能

问题描述

我没有正确理解 simmer 中的回滚功能,根据https://r-simmer.org/reference/rollback.html,数量参数表示要回滚的活动量。但是我的代码没有做应该做的事情。这里我做了一个例子

MyEnv <- simmer("MyEnv")
Traj <- trajectory() %>%
    timeout(0) %>%
    log_("Registered")  %>%
                                                                   
    timeout(1) %>%
    log_("Analyzed") %>%
    
    branch (option = function() {round(ifelse(runif(1,0,100)<50,1,2))},
            continue=TRUE, 
            
            trajectory() %>%
              timeout(1) %>%
              log_("Repair Simple")  %>%
              
              timeout(function() {round(runif(1,5,10))}) %>%
              log_("Repair Tested (Simple)") %>% 
              
              branch (option = function() {round(ifelse(runif(1,0,100)<50,0,1))},
                      continue=TRUE,
                      # Restart Repair
                      trajectory() %>%
                        timeout(2) %>%
                        log_("Restart") %>%
                        rollback(amount=3)
              ),
            
            trajectory() %>%
              timeout(1) %>%
              log_("Repair Complex")%>%
              
              timeout(1) %>%
              log_("Repair Tested (Complex)") %>%   
              
              branch (option = function() {round(ifelse(runif(1,0,100)<50,0,1))},
                      continue=TRUE,
                      
                      trajectory() %>%
                        timeout(2) %>%
                        log_("Restart")   %>%
                        rollback(amount=3) 
              )
    ) %>%
    
    timeout(0) %>%
    log_("User Informed")  %>%
    
    timeout(0) %>%
    log_("Repair Archived")

MyEnv%>%
    add_generator("Case_", Traj, distribution = function() 2) %>%
    run(until=20)

当模拟进入“重新启动”活动时,它应该回滚 3 个活动并再次执行修复简单或修复复杂。但是使用提供的代码重新启动活动只是重复它自己。如果将数量参数设置为 3,这怎么可能?

这是我的模拟输出:

2: Case_0: Registered
3: Case_0: Analyzed
4: Case_0: Repair Simple
4: Case_1: Registered
5: Case_1: Analyzed
6: Case_1: Repair Simple
6: Case_2: Registered
7: Case_2: Analyzed
8: Case_2: Repair Complex
8: Case_3: Registered
9: Case_2: Repair Tested (Complex)
9: Case_3: Analyzed
9: Case_2: User Informed
9: Case_2: Repair Archived
10: Case_0: Repair Tested (Simple)
10: Case_3: Repair Simple
10: Case_4: Registered
11: Case_4: Analyzed
12: Case_1: Repair Tested (Simple)
12: Case_0: Restart
12: Case_4: Repair Complex
12: Case_5: Registered
13: Case_4: Repair Tested (Complex)
13: Case_5: Analyzed
13: Case_4: User Informed
13: Case_4: Repair Archived
14: Case_1: Restart
14: Case_0: Restart
14: Case_5: Repair Complex
14: Case_6: Registered
14: Case_0: User Informed
14: Case_0: Repair Archived
15: Case_5: Repair Tested (Complex)
15: Case_6: Analyzed
15: Case_5: User Informed
15: Case_5: Repair Archived
16: Case_1: Restart
16: Case_6: Repair Simple
16: Case_7: Registered
16: Case_1: User Informed
16: Case_1: Repair Archived
17: Case_3: Repair Tested (Simple)
17: Case_7: Analyzed
18: Case_7: Repair Simple
18: Case_8: Registered
19: Case_3: Restart
19: Case_8: Analyzed

标签: rsimulationrollback

解决方案


推荐阅读