-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathREADME.Rmd
More file actions
143 lines (93 loc) · 4.67 KB
/
README.Rmd
File metadata and controls
143 lines (93 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
output: github_document
---
<!-- badges: start -->
[](https://CRAN.R-project.org/package=queuecomputer)
[](https://CRAN.R-project.org/package=queuecomputer)
[](https://github.com/AnthonyEbert/queuecomputer/actions)
[](https://app.codecov.io/gh/AnthonyEbert/queuecomputer)
[](https://doi.org/10.18637/jss.v095.i05)
<!-- badges: end -->
<!-- --- -->
<!-- output: html -->
<!-- bibliography: references.bib -->
<!-- --- -->
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
echo = TRUE,
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# queuecomputer
## Overview
queuecomputer implements a new and computationally efficient method for simulating from a general set of queues. The current most popular method for simulating queues is Discete Event Simulation (DES). The top R package for DES is called simmer and the top Python package is called SimPy. We have validated and benchmarked queuecomputer against both these packages and found that queuecomputer is two orders of magnitude faster than either package.
Simulating arbitrary queues is difficult, however once:
1. The arrival times A and service times S are known for all customers and,
2. the server resource schedule is specified
then the departure times D for all customers can be computed deterministically.
The focus on this package is:
* fast computation of departure times given arrival and service times, and
* a flexible framework to allow for extensions such as server effects.
It is up to the user to provide arrival and service times, and therefore very complicated distributions can be simulated (by the user) and tested with this package.
For detailed information regarding the algorithm used in this package see our paper:
Ebert A, Wu P, Mengersen K, Ruggeri F (2020). “Computationally
Efficient Simulation of Queues: The R Package queuecomputer.”
_Journal of Statistical Software_, *95*(5), 1-29. doi:
10.18637/jss.v095.i05 (URL: https://doi.org/10.18637/jss.v095.i05).
## Installation
```{r, eval = FALSE}
install.packages('queuecomputer')
```
## Usage
```{r seed, echo=FALSE}
set.seed(1)
```
### Simple example
We demonstrate simulating the first 50 customers from a M/M/2 queue. In queueing theory, M/M/2 refers to a queue with exponential inter-arrival times, exponential service times and two servers.
```{r}
library(queuecomputer)
n <- 50
arrivals <- cumsum(rexp(n, 1.9))
service <- rexp(n)
queue_mm2 <- queue_step(arrivals = arrivals, service = service, servers = 2)
```
You can see the table of customer arrival, service and departure times by accessing the `departures_df` object from queue_mm2.
```{r}
queue_mm2$departures_df
```
You can see visualisations of the queueing system.
```{r}
plot(queue_mm2)
```
A summary of the performance of the queueing system can be computed.
```{r}
summary(queue_mm2)
```
### Queueing network
In this example of a queueing network, customers must pass through two queues. The arrival times to the first queue come in two waves starting at time 100 and time 500. The arrival times to the second queue are the departure times of the first queue plus the time they spent walking to the second queue.
```{r}
library(queuecomputer)
library(ggplot2)
library(dplyr)
set.seed(1)
n <- 100
arrivals_1 <- c(100 + cumsum(rexp(n)), 500 + cumsum(rexp(n)))
service_1 <- rexp(2*n, 1/2.5)
queue_1 <- queue_step(arrivals = arrivals_1, service = service_1, servers = 2)
walktimes <- rexp(2*n, 1/100)
arrivals_2 <- lag_step(arrivals = queue_1, service = walktimes)
service_2 <- rexp(2*n, 1/3)
queue_2 <- queue_step(arrivals = arrivals_2, service = service_2, servers = 1)
head(arrivals_1)
head(queue_1$departures_df)
head(arrivals_2)
head(queue_2$departures_df)
summary(queue_1)
summary(queue_2)
```
## Acknowledgements
I'd like to thank my supervisors [Professor Kerrie Mengersen](https://bragqut.wordpress.com/mengersen/), [Dr Paul Wu](https://bragqut.wordpress.com/people/research-staff/wu/) and [Professor Fabrizio Ruggeri](http://www.mi.imati.cnr.it/fabrizio/).
This work was supported by the [ARC Centre of Excellence for Mathematical and Statistical Frontiers (ACEMS)](http://acems.org.au/). This work was funded through the ARC Linkage Grant “Improving the Productivity and Efficiency of Australian Airports” (LP140100282).