@@ -14,11 +14,6 @@ vignette: >
14
14
``` {r, cache = FALSE, include=FALSE}
15
15
knitr::opts_chunk$set(collapse = T, comment = "#>",
16
16
fig.width = 6, fig.height = 4, fig.align = "center")
17
-
18
- required <- c("dplyr")
19
-
20
- if (!all(sapply(required, requireNamespace, quietly = TRUE)))
21
- knitr::opts_chunk$set(eval = FALSE)
22
17
```
23
18
24
19
## Introduction
@@ -64,7 +59,7 @@ bank <-
64
59
add_generator("Customer", customer, at(5))
65
60
66
61
bank %>% run(until = 100)
67
- bank %>% get_mon_arrivals
62
+ bank %>% get_mon_arrivals()
68
63
```
69
64
70
65
The short trace printed out by the ` get_mon_arrivals ` function shows the result.
@@ -99,7 +94,7 @@ bank <-
99
94
add_generator("Customer", customer, at(rexp(1, 1/5)))
100
95
101
96
bank %>% run(until = 100)
102
- bank %>% get_mon_arrivals
97
+ bank %>% get_mon_arrivals()
103
98
```
104
99
105
100
The trace shows that the customer now arrives at time 7.839305. Changing the
@@ -191,7 +186,7 @@ bank <-
191
186
add_generator("Customer", customer, at(2, 5, 12))
192
187
193
188
bank %>% run(until = 400)
194
- bank %>% get_mon_arrivals
189
+ bank %>% get_mon_arrivals()
195
190
```
196
191
197
192
Alternatively, we can create three different customer trajectories for the three
@@ -233,7 +228,7 @@ bank <-
233
228
add_generator("Evelyn", Evelyn, at(12))
234
229
235
230
bank %>% run(until = 400)
236
- bank %>% get_mon_arrivals
231
+ bank %>% get_mon_arrivals()
237
232
```
238
233
239
234
Again, the simulations finish before the 400 specified in the ` run ` function.
@@ -265,7 +260,7 @@ bank <-
265
260
add_generator("Customer", customer, from_to(0, 41, function() {10}))
266
261
267
262
bank %>% run(until = 400)
268
- bank %>% get_mon_arrivals
263
+ bank %>% get_mon_arrivals()
269
264
```
270
265
271
266
### Many random customers
@@ -305,7 +300,7 @@ bank <-
305
300
add_generator("Customer", customer, function() {c(0, rexp(4, 1/10), -1)})
306
301
307
302
bank %>% run(until = 400)
308
- bank %>% get_mon_arrivals
303
+ bank %>% get_mon_arrivals()
309
304
```
310
305
311
306
## A Service counter
@@ -336,7 +331,7 @@ step is complete, the `release` function causes the customer to make the counter
336
331
available to other customers in the queue.
337
332
338
333
Since the activity trace does not produce the waiting time by default, this is
339
- calculated and appended using the ` mutate ` function in the dplyr package .
334
+ calculated and appended using the ` transform ` function.
340
335
341
336
``` {r, message = FALSE}
342
337
library(simmer)
@@ -362,8 +357,8 @@ bank <-
362
357
363
358
bank %>% run(until = 400)
364
359
bank %>%
365
- get_mon_arrivals %>%
366
- dplyr::mutate (waiting_time = end_time - start_time - activity_time)
360
+ get_mon_arrivals() %>%
361
+ transform (waiting_time = end_time - start_time - activity_time)
367
362
```
368
363
369
364
Examining the trace we see that the first two customers get instant service but
@@ -404,8 +399,8 @@ bank <-
404
399
405
400
bank %>% run(until = 400)
406
401
bank %>%
407
- get_mon_arrivals %>%
408
- dplyr::mutate (waiting_time = end_time - start_time - activity_time)
402
+ get_mon_arrivals() %>%
403
+ transform (waiting_time = end_time - start_time - activity_time)
409
404
```
410
405
411
406
This model with random arrivals and exponential service times is an example of
@@ -453,8 +448,8 @@ bank <-
453
448
454
449
bank %>% run(until = 400)
455
450
bank %>%
456
- get_mon_arrivals %>%
457
- dplyr::mutate (waiting_time = end_time - start_time - activity_time)
451
+ get_mon_arrivals() %>%
452
+ transform (waiting_time = end_time - start_time - activity_time)
458
453
```
459
454
460
455
The waiting times in this model are much shorter than those for the single
@@ -499,12 +494,12 @@ bank <-
499
494
500
495
bank %>% run(until = 400)
501
496
bank %>%
502
- get_mon_arrivals %>%
503
- dplyr::mutate (service_start_time = end_time - activity_time) %>%
504
- dplyr::arrange( start_time)
497
+ get_mon_arrivals() %>%
498
+ transform (service_start_time = end_time - activity_time) %>%
499
+ .[order(.$ start_time),]
505
500
bank %>%
506
- get_mon_resources %>%
507
- dplyr::arrange( time)
501
+ get_mon_resources() %>%
502
+ .[order(.$ time),]
508
503
```
509
504
510
505
The results show that the customers chose the counter with the smallest number.
@@ -519,7 +514,7 @@ We now demonstrate how to calculate average waiting times for our customers. In
519
514
the original SimPy version of this tutorial, this involved using 'Monitors'. In
520
515
simmer, data is returned by the ` get_mon_* ` family of functions, as has already
521
516
been demonstrated. Here, we simply summarise the data frame returned by the
522
- ` get_mon_arrivals ` function, using functions from the ` dplyr ` package .
517
+ ` get_mon_arrivals ` function, using standard R functions .
523
518
524
519
We also increase the number of customers to 50 (find the number '49' in the
525
520
code.code).
@@ -544,8 +539,8 @@ bank %>% run(until = 1000)
544
539
545
540
result <-
546
541
bank %>%
547
- get_mon_arrivals %>%
548
- dplyr::mutate (waiting_time = end_time - start_time - activity_time)
542
+ get_mon_arrivals() %>%
543
+ transform (waiting_time = end_time - start_time - activity_time)
549
544
```
550
545
551
546
The average waiting time for 50 customers in this 2-counter system is more
@@ -594,8 +589,8 @@ mclapply(c(393943, 100005, 777999555, 319999772), function(the_seed) {
594
589
bank %>% run(until = 400)
595
590
result <-
596
591
bank %>%
597
- get_mon_arrivals %>%
598
- dplyr::mutate (waiting_time = end_time - start_time - activity_time)
592
+ get_mon_arrivals() %>%
593
+ transform (waiting_time = end_time - start_time - activity_time)
599
594
paste("Average wait for ", sum(result$finished), " completions was ",
600
595
mean(result$waiting_time), "minutes.")
601
596
}) %>% unlist()
0 commit comments