1

I am not understanding the rollback function in simmer correctly, According to https://r-simmer.org/reference/rollback.html the amount parameter represents the amount of activities to roll back. But my code is not doing what is supposed to. Here I did an example

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)

When the simulation gets to a "Restart" activity, it should roll 3 activities back and perform Repair Simple or Repair Complex again. But with the code provided the Restart activity just repeats it self. How is this possible if the amount parameter is set to 3?

Here the output of my simulation:

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
ncnc_2020
  • 67
  • 9

1 Answers1

1

From what I experienced, rollback seems to go back a number of lines (including logs) or activities within a trajectory. You can use get_n_activities() to know how many activities are within a trajectory. So when you put 3 as the number of activities to rollback it goes back to the start of the same trajectory the rollback sits in and just triggers "restarts" log and moves on. If you change the amount to 6, it should work.


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=6, 1)
            ),
          
          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=6, 1) 
            )
  ) %>%
  
  timeout(0) %>%
  log_("User Informed")  %>%
  
  timeout(0) %>%
  log_("Repair Archived")

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

outcome:

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 Complex
6: Case_2: Registered
7: Case_1: Repair Tested (Complex)
7: Case_2: Analyzed
8: Case_2: Repair Complex
8: Case_3: Registered
9: Case_1: Restart
9: Case_2: Repair Tested (Complex)
9: Case_3: Analyzed
9: Case_1: Repair Complex
9: Case_2: User Informed
9: Case_2: Repair Archived
10: Case_0: Repair Tested (Simple)
10: Case_3: Repair Complex
10: Case_1: Repair Tested (Complex)
10: Case_4: Registered
11: Case_3: Repair Tested (Complex)
11: Case_4: Analyzed
11: Case_3: User Informed
11: Case_3: Repair Archived
12: Case_0: Restart
12: Case_1: Restart
12: Case_4: Repair Simple
12: Case_0: Repair Simple
12: Case_5: Registered
12: Case_1: User Informed
12: Case_1: Repair Archived
13: Case_5: Analyzed
14: Case_5: Repair Complex
14: Case_6: Registered
15: Case_5: Repair Tested (Complex)
15: Case_6: Analyzed
16: Case_6: Repair Simple
16: Case_7: Registered
17: Case_5: Restart
17: Case_7: Analyzed
17: Case_5: Repair Complex
18: Case_7: Repair Simple
18: Case_5: Repair Tested (Complex)
18: Case_8: Registered
18: Case_5: User Informed
18: Case_5: Repair Archived
19: Case_8: Analyzed