Site icon R-bloggers

simmer 2.0: a performance boost & revised syntax

[This article was first published on FishyOperations » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

It was very clear that the performance of the first simmer version was lagging behind. The 2.0 release introduces a C++ based engine and comes with a significant performance boost versus the previous version. While the performance can always be further improved I’m currently quite satisfied with it. Future refinement of the code base will however focus on further improving efficiency.

The syntax also had a massive overhaul. Most notably, a trajectory is no longer based on a data frame but build up using the magrittr-style piping philosophy. The code, installation instructions and documentation can be found at the simmer GitHub repo.

As an example a simple bank clerk – customer interaction process is simulated.

library(simmer)

    bank_customer_trajectory<-
      create_trajectory("bank customer") %>%
      ## see the bank clerk
      add_seize_event("clerk",1) %>%
      add_timeout_event("rpois(1, 20)") %>%
      add_release_event("clerk",1) %>%
      ## with a 50% chance skip the next three steps
      add_skip_event("sample(c(0,3), 1)") %>%
      ## with a 50% chance see the bank director
      add_seize_event("director",1) %>%
      add_timeout_event("rpois(1, 15)") %>%
      add_release_event("director",1)

    bank_process<-
      # create simulation with 50 replications & a max time of 360
      create_simulator("bank process", n = 50, until = 360) %>%  
      add_resource("clerk", 1) %>%
      add_resource("director", 1) %>%
      # add 30 customers with a given inter-arrival time
      add_entities_with_interval(trajectory = bank_customer_trajectory, n = 30, name_prefix = "customer", interval = "rpois(1, 20)") %>%
      # run the simulation
      simmer()

Once the simulation has finished, we can have a look at the results.

# have a look at the flow time
    plot_evolution_entity_times(bank_process, type = "flow_time")

# have a look at the overall resource utilization
    plot_resource_utilization(bank_process, c("clerk","director"))

# have a look at the in use moments of the director for replication 5
    plot_resource_usage(bank_process, "director", replication_n = 5)

As always, comments, questions, tips & suggestions are very welcome. Either post a GitHub issue or contact me by mail at bartsmeets86@gmail.com

The post simmer 2.0: a performance boost & revised syntax appeared first on FishyOperations.

To leave a comment for the author, please follow the link and comment on their blog: FishyOperations » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.