GithubHelp home page GithubHelp logo

simmer's Introduction

simmer

Build Status

by Bart Smeets -- [email protected]

simmer is under heavy development and its internals and syntax can still change extensively over the coming time

simmer is a discrete event package for the R language. It is developed with my own specific requirements for simulating day-to-day hospital proceses and thus might not be suited for everyone. It is designed to be as simple to use as possible and tries to be compatible with the chaining/piping workflow introduced by the magrittr package.

Installation

The installation requires the devtools package to be installed.

devtools::install_github("Bart6114/simmer")

Using simmer

First load the package.

library(simmer)

Set-up a simple trajectory (the column names are important!).

t0<-
  read.table(header=T, text=
               "event_id  description   resource        amount  duration      successor
                1         intake        nurse           1       15            2
                2         consultation  doctor          1       20            3
                3         planning      administration  1       5             NA"  )

The successor describes which event is started next. An successor value of NA means that the end of the trajectory has been reached. The duration and successor value are parsed as R commands and re-evaluated for every individual entity and event. This means that this does not have to be a static value and the concept of probability can be introduced. The following trajectory shows this.

t1<-
  read.table(header=T, text=
               "event_id  description   resource        amount  duration      successor
                1         intake        nurse           1       rnorm(1,15)   2
                2         consultation  doctor          1       rnorm(1,20)   sample(c(NA,3),1)
                3         planning      administration  1       rnorm(1,5)    NA"  )

In the above trajectory the duration is drawn from a normal distribution with a given mean. The successor of event 2 is either NA (end of trajectory) or event 3.

When the trajectory is know, a simulator object can be build. In the below example, a simulator is instantiated and three types of resources are added. The nurse and administration resource each with a capacity of 1 and the doctor resource with a capacity of 2.

library(magrittr)

sim<-
  create_simulator(name = "SuperDuperSim") %>%
  add_resource("nurse", 1) %>%
  add_resource("doctor", 2) %>%
  add_resource("administration", 1)

The simulator object is extended by adding a trajectory and adding 10 entities wich are activated with an interval of 10 minutes.

sim<-
  sim %>%
  add_trajectory("Trajectory1",t1) %>%
  add_entities_with_interval(n = 10, name_prefix = "patient", trajectory_name = "Trajectory1", interval =  10)

Entities can also be added on an individual basis. In the below example 1 extra individual entity is added which will be activated at time 100.

sim<-
  sim %>%
  add_entity(name = "individual_entity", trajectory_name = "Trajectory1", early_start = 100)

If we only simulate the entities going through the trajectory 1 time we won't get a good look on the stability of the system, so we add a replicator and simulate it 10 times.

sim<-
  sim %>%
  replicator(10)

The simulation is now ready for a test run; just let it simmer for a bit (or for 120 time units to be precise).

sim <-
  sim %>%
  simmer(until = 120)

Resource utilization

After you've left it simmering for a bit (pun intended), we can have a look at the overall resource utilization. The top and bottom of the error bars show respectively the 25th and 75th percentile of the utilization across all the replications. The top of the bar shows the median utilization.

plot_resource_utilization(sim)

plot of chunk unnamed-chunk-10

It is also possible to have a look at a specific resource and its activity during the simulation.

plot_resource_usage(sim, "doctor")

plot of chunk unnamed-chunk-11

In the above graph, the individual lines are all seperate replications. A smooth line is drawn over them to get a sense of the 'average' utilization. You can also see here that the until time of 120 was most likely lower than the unrestricted run time of the simulation. It is also possible to get a graph about a specific replication by simply specifying the replication number. In the example below the 6th replication is shown.

plot_resource_usage(sim, "doctor", 6)

plot of chunk unnamed-chunk-12

Flowtime

Next we can have a look at the evolution of the entities' flow time during the simulation. In the below plot, each individual line represents a replication. A smoothline is drawn over them.

plot_evolution_entity_times(sim, "flow_time")

plot of chunk unnamed-chunk-13

Similarly one can have a look at the evolution of the activity times with type = "activity_time" and waiting times with type = "waiting_time".

DOCUMENTATION TO BE CONTINUED

Contact

For bugs and/or issues: create a new issue on GitHub.

Other questions or comments: [email protected]

simmer's People

Contributors

bart6114 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.