Queuing system

Queuing system is the management system aim to control the customer flow and streaming the queuing experience. The elements of a queue system includes population of customers, customer arrival process, waiting in line, serve process, number of servers, output (the way customer leave the system), etc. Queuing theory is the collection of mathematical models of queue formation and propagation, which take the inputs and provide quantitative parameters describing the system performance.

The discrete system Markov chain in Chapter 6 is one simple model of queue. But Markov chain not only can be used in queues but in many other applications. A queue process can model by Markov chain when:

  1. the item arriving and leaving in the queue system are independent of each other;

  2. the item arriving and leaving have finite number of outcomes;

  3. a particular outcome can transition to any other state or stay in the current state/node, a probability of arriving or leaving of items from a state/node in Markov chain are between 0 and 1;

4.the sum of probabilities for a node is 1.

Server checkout counter model - Markov chain

Assume that the queue policy is who comes first who serves first. In a Markov chain model, we denote the increasing rate of customer arrival as \(\alpha\) and the service rate as \(\beta\). The total number of customers come in certain period of time is C. \(S_i\) denotes the i th state of Markov chain. The probability of finished checkout denoted as q.

\(q = \frac{\alpha}{\beta}\)

Let pi denote the probability of that i customers exist in the queue. \(p_0 = 1-q\)

The probability of the k th state is \(q^kp_0\) = \(q^k(1-q)\).

The average number of customers in each state is: \(C\displaystyle\sum_{i=1}^{\infty} q^i(1-q) = \frac{q}{1-q}\)

Let’s see what’s the average waiting time under these conditions for a given “rush hour”:

Assume the customer arrival follows uniform distribution and every minute at most 7 people come in the retail store with 4 people as average. Assume item of each customer checks out follows uniform distribution in a range between 1 to 4. Let the service rate is 9 second for one item and 1.5 minute to collect payments, and issuing receipts, refunds and change. The time need for each check out is fomulated as:

\(t = 0.15x\)

alpha <- (((1+7)/2)/10)*((1+4)/2)  # item need to be check out per minute

beta <- 1/(9/60)  # capacity of checking out per minute 

q <- alpha/beta

total_customer <- round((((1+7)/2)/10)*60)  # expected customer in 1 hour

avg_tiem_per_customer <- (1+4)/2
  
total_item <- avg_tiem_per_customer *total_customer  # expected item need to checkout in 1 hour

(avg_waiting_customer <- (total_item * q*(1-q)) /avg_tiem_per_customer )
## [1] 3.06

Server checkout counter model - simulation

We can do simulatation to calculate the average customer waiting in line.

state_list <- c(0)
checkout <- function(){
  for (i in 1:60){
    customer <- round(runif(1, 1, 7))
    item <- c(round(runif(customer, 1, 4)))  # item of each customer
    sevice_time <- 0.15* item  # time need for each customer
    checkout_time <- sum(sevice_time)  # totoal time need at this minute
    not_taken_care <- checkout_time - 1 # checkout(time needed) haven't been taken care at this minute
    state_list <- c(state_list,state_list[i] + not_taken_care) # checkout(time needed) haven't been taken care at each state
  }
  state_list <- state_list[2:61]
  return(state_list)
}

avg_cutomer_simu <- c(0)
for (i in 1:200){
  avg_cutomer_simu <- c(avg_cutomer_simu,mean(checkout()))
}
mean(avg_cutomer_simu/avg_tiem_per_customer)
## [1] 6.021771

The results calculated by Markov chain and simulaton is not the same.