Data Science Austria

simmer 4.2.1

The 4.2.1 release of simmer, the Discrete-Event Simulator for R, is on CRAN with quite interesting new features and fixes. As discussed in the mailing list, there is a way to handle the specific case in which an arrival is rejected because a queue is full:

library(simmer) reject <- trajectory() %>% log_("kicked off...") patient <- trajectory() %>% seize("nurse", continue=FALSE, reject=reject) %>% log_("nurse seized") %>% timeout(5) %>% release("nurse") %>% log_("nurse released") env <- simmer() %>% add_resource("nurse", 1, 0) %>% add_generator("patient", patient, at(0, 1)) %>% run()
## 0: patient0: nurse seized
## 1: patient1: kicked off...
## 5: patient0: nurse released

But as Tom Lawton pointed out, until now, there was no way of handling any alternative path for an arrival that was preempted and “kicked off” from a resource. This mechanism has been implemented into the new handle_unfinished() activity:

patient <- trajectory() %>% handle_unfinished(reject) %>% seize("nurse") %>% log_("nurse seized") %>% timeout(5) %>% release("nurse") %>% log_("nurse released") env <- simmer() %>% add_resource("nurse", 1, 0, preemptive=TRUE, queue_size_strict=TRUE) %>% add_generator("LowPrio_patient", patient, at(0), priority=0) %>% add_generator("HighPrio_patient", patient, at(1), priority=10) %>% run()
## 0: LowPrio_patient0: nurse seized
## 1: HighPrio_patient0: nurse seized
## 1: LowPrio_patient0: kicked off...
## 6: HighPrio_patient0: nurse released

Note that such a mechanism is more general, because it also covers the first scenario:

env <- simmer() %>% add_resource("nurse", 1, 0) %>% add_generator("patient", patient, at(0, 1)) %>% run()
## 0: patient0: nurse seized
## 1: patient1: kicked off...
## 5: patient0: nurse released

Whenever rejection (or preemption) happens and it is catched by the appropriate handler, the new getter get_seized() may be useful to know which resource was abandoned.

Finally, the readership may find interesting the new section about the implementation of state-dependent service rates in the Queueing Systems vignette. See below for a complete list of changes.

New features:

  • New handle_unfinished() activity sets a drop-out trajectory for unfinished arrivals, i.e., those dropped from a resource (due to preemption, resource shrinkage or a rejected seize) or those that leave a trajectory (#178 addressing #177).
  • New release_all() and release_selected_all() activities automatically retrieve the amount of resources seized and release it (#180 addressing #25).
  • New get_seized() and get_seized_selected() getters allow an arrival to retrieve the amount of resources seized (#180 addressing #179).
  • New stop_if() activity sets a conditional breakpoint (#181 addressing #100).

Minor changes and fixes:

  • Fix performance issues in data sources (#176).
  • Update CITATION.
  • Fix monitored activity for preempted arrivals (as part of #178).
  • Fix seizes/releases with a null amount (as part of #180).
  • Rename internal status codes (as part of #181).
  • Provide more context on error or warning (as part of #181).
  • Extend the Queueing Systems vignette with a section about state-dependent service rates.
  • Fix performance issues in getters (#183).

Article originally published in Enchufa2.es: simmer 4.2.1.

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

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more…


If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook

Leave a Comment