I'm studying the vignette "The Bank Tutorial: Part II" and saw the following code (reprex included) when balking is introduced. I would have expected Customer 3, 4, 5, and 7 to not be finished. Given the output, other than seeing an activity time of 0, how would we know someone had balked?
library(simmer)
timeInBank <- 12 # mean, minutes
ARRint <- 10 # mean, minutes
numServers <- 1 # servers
maxInSystem <- 2 # customers
maxInQueue <- maxInSystem - numServers
maxNumber <- 8
maxTime <- 400 # minutes
set.seed(59098)
bank <- simmer()
customer <-
trajectory("Customer's path") %>%
log_("Here I am") %>%
set_attribute("start_time", function() {now(bank)}) %>%
seize("counter",
continue = FALSE,
reject =
trajectory("Balked customer") %>%
log_("BALKING")) %>%
log_(function() {paste("Waited", now(bank) - get_attribute(bank, "start_time"))}) %>%
timeout(function() {rexp(1, 1/timeInBank)}) %>%
release("counter") %>%
log_("Finished")
bank <-
simmer("bank") %>%
add_resource("counter",
capacity = numServers,
queue_size = maxInQueue) %>%
add_generator("Customer",
customer,
at(c(0, cumsum(rexp(maxNumber - 1, 1 / ARRint)))))
bank %>% run(until = maxTime)
#> 0: Customer0: Here I am
#> 0: Customer0: Waited 0
#> 0.822239: Customer1: Here I am
#> 1.01227: Customer2: Here I am
#> 1.01227: Customer2: BALKING
#> 4.7448: Customer3: Here I am
#> 4.7448: Customer3: BALKING
#> 20.5472: Customer4: Here I am
#> 20.5472: Customer4: BALKING
#> 21.6132: Customer5: Here I am
#> 21.6132: Customer5: BALKING
#> 22.7358: Customer0: Finished
#> 22.7358: Customer1: Waited 21.9136007670654
#> 23.5339: Customer6: Here I am
#> 32.1107: Customer7: Here I am
#> 32.1107: Customer7: BALKING
#> 52.5108: Customer1: Finished
#> 52.5108: Customer6: Waited 28.9769820388615
#> 55.8923: Customer6: Finished
#> simmer environment: bank | now: 55.8923309646971 | next:
#> { Monitor: in memory }
#> { Resource: counter | monitored: TRUE | server status: 0(1) | queue status: 0(1) }
#> { Source: Customer | monitored: 1 | n_generated: 8 }
get_mon_arrivals(bank) %>%
dplyr::arrange(start_time)
#> name start_time end_time activity_time finished replication
#> 1 Customer0 0.0000000 22.735840 22.735840 TRUE 1
#> 2 Customer1 0.8222395 52.510839 29.774999 TRUE 1
#> 3 Customer2 1.0122676 1.012268 0.000000 TRUE 1
#> 4 Customer3 4.7447981 4.744798 0.000000 TRUE 1
#> 5 Customer4 20.5472028 20.547203 0.000000 TRUE 1
#> 6 Customer5 21.6132293 21.613229 0.000000 TRUE 1
#> 7 Customer6 23.5338568 55.892331 3.381492 TRUE 1
#> 8 Customer7 32.1107494 32.110749 0.000000 TRUE 1
number_balked <- sum(!get_mon_arrivals(bank)$finished)
paste("Balking rate is", number_balked / now(bank), "customers per minute.")
#> [1] "Balking rate is 0 customers per minute."
I'm studying the vignette "The Bank Tutorial: Part II" and saw the following code (reprex included) when balking is introduced. I would have expected Customer 3, 4, 5, and 7 to not be finished. Given the output, other than seeing an activity time of 0, how would we know someone had balked?
Created on 2022-06-24 by the reprex package (v2.0.1)