Plotting simmer trajectories

Iñaki Ucar, Bart Smeets

2016-12-30

This package provides an S3 method for the plot generic to visualise diagrams of trajectory objects (see ?plot.trajectory for more details) using the DiagrammeR package as backend.

library(simmer.plot)

t0 <- trajectory() %>%
  seize("resource", 1) %>%
  timeout(function() rnorm(1, 15)) %>%
  release("resource", 1) %>%
  branch(function() 1, c(TRUE, FALSE),
         trajectory() %>%
           clone(2,
                 trajectory() %>%
                   seize("resource", 1) %>%
                   timeout(1) %>%
                   release("resource", 1),
                 trajectory() %>%
                   trap("signal",
                        handler=trajectory() %>%
                          timeout(1)) %>%
                   timeout(1)),
         trajectory() %>%
           set_attribute("dummy", 1) %>%
           set_attribute("dummy", function() 1) %>%
           seize("resource", function() 1) %>%
           timeout(function() rnorm(1, 20)) %>%
           release("resource", function() 1) %>%
           rollback(9)) %>%
  timeout(1) %>%
  rollback(2)
plot(t0)
cat(plot(t0, output="DOT"))
#> digraph {
#> 
#>   '1' [label = 'Seize', shape = 'box', tooltip = 'amount: 1'] 
#>   '2' [label = 'Timeout', shape = 'box', tooltip = 'delay: 0x55a65c34a0c0'] 
#>   '3' [label = 'Release', shape = 'box', tooltip = 'amount: 1'] 
#>   '4' [label = 'Branch', shape = 'diamond', tooltip = 'option: 0x55a65b84b1b8'] 
#>   '5' [label = 'Clone', shape = 'diamond', tooltip = 'n: 2'] 
#>   '6' [label = 'Seize', shape = 'box', tooltip = 'amount: 1'] 
#>   '7' [label = 'Timeout', shape = 'box', tooltip = 'delay: 1'] 
#>   '8' [label = 'Release', shape = 'box', tooltip = 'amount: 1'] 
#>   '9' [label = 'Trap', shape = 'diamond', tooltip = 'signals: [signal, ]'] 
#>   '10' [label = 'Timeout', shape = 'box', tooltip = 'delay: 1'] 
#>   '11' [label = 'Timeout', shape = 'box', tooltip = 'delay: 1'] 
#>   '12' [label = 'SetAttribute', shape = 'box', tooltip = 'key: dummy, value: 1, global: 0'] 
#>   '13' [label = 'SetAttribute', shape = 'box', tooltip = 'key: dummy, value: 0x55a65b9f3d78, global: 0'] 
#>   '14' [label = 'Seize', shape = 'box', tooltip = 'amount: 0x55a65bad0c70'] 
#>   '15' [label = 'Timeout', shape = 'box', tooltip = 'delay: 0x55a65baba3f8'] 
#>   '16' [label = 'Release', shape = 'box', tooltip = 'amount: 0x55a65baa5f30'] 
#>   '17' [label = 'Rollback', shape = 'diamond', tooltip = 'times: 1'] 
#>   '18' [label = 'Timeout', shape = 'box', tooltip = 'delay: 1'] 
#>   '19' [label = 'Rollback', shape = 'diamond', tooltip = 'times: 1'] 
#> '1'->'2' [color = 'black', style = 'solid'] 
#> '2'->'3' [color = 'black', style = 'solid'] 
#> '3'->'4' [color = 'black', style = 'solid'] 
#> '4'->'18' [color = 'gray', style = 'dashed'] 
#> '5'->'18' [color = 'gray', style = 'dashed'] 
#> '6'->'7' [color = 'black', style = 'solid'] 
#> '7'->'8' [color = 'black', style = 'solid'] 
#> '8'->'18' [color = 'black', style = 'solid'] 
#> '9'->'11' [color = 'gray', style = 'dashed'] 
#> '11'->'18' [color = 'black', style = 'solid'] 
#> '12'->'13' [color = 'black', style = 'solid'] 
#> '13'->'14' [color = 'black', style = 'solid'] 
#> '14'->'15' [color = 'black', style = 'solid'] 
#> '15'->'16' [color = 'black', style = 'solid'] 
#> '16'->'17' [color = 'black', style = 'solid'] 
#> '18'->'19' [color = 'black', style = 'solid'] 
#> '4'->'5' [color = 'black', style = 'solid'] 
#> '5'->'6' [color = 'black', style = 'solid'] 
#> '5'->'9' [color = 'black', style = 'solid'] 
#> '9'->'10' [color = 'black', style = 'solid'] 
#> '4'->'12' [color = 'black', style = 'solid'] 
#> '17'->'1' [color = 'black', style = 'solid'] 
#> '19'->'4' [color = 'black', style = 'solid'] 
#> }