mm1 <- function (mean_inter, mean_service, mult=1) {
lam <- (1/mean_inter)*mult
mu <- 1/ mean_service
# If p is less than 1, we have a stable queue
p <- lam/mu
# Lq is the steady state average number of entities in the queue
Lq <- p^2 / (1-p)
#L is the steady state average number of entities in the system (rather than the number in queue)
L <- p / (1-p)
#W is the steady state average time in the system
W <- 1 / (mu*(1-p))
#Wq is the steady state average time in the queue
Wq <- p / (mu*(1-p))
df <- data.frame(p=p, Lq=Lq, L=L, W=W, Wq=Wq)
return(df)
}
df <- mm1(1.25,1)
Note to self: See section 2.33 for the Wq equation and 2.2 for Littleās Law and other equations
mg1 <- function (mean_inter, a, b) {
lam <- 1/mean_inter
Es <- (a + b)/2
mu <- 1/Es
sdev <- sqrt((b-a)^2/12)
# If p is less than 1, we have a stable queue
p <- lam/mu
#Wq is the steady state average time in the queue
Wq <- (lam*(sdev^2 + 1/(mu^2))) / (2*(1-p))
#W is the steady state average time in the system
W <- Wq + Es
#L is the steady state average number of entities in the system (rather than the number in queue)
L <- lam * W
# Lq is the steady state average number of entities in the queue
Lq <- lam * Wq
df <- data.frame(p=p, Lq=Lq, L=L, W=W, Wq=Wq)
return(df)
}
df2 <- rbind(df, mg1(1.25, 0.1, 1.9))
df2
## p Lq L W Wq
## 1 0.8 3.200 4.000 5.00 4.00
## 2 0.8 2.032 2.832 3.54 2.54
The number of entities in system/queue and the wait time/time in queues decreased while p remained the same as in problem 1 (The discussion problem). This intuitively makes sense as the service time takes on a specific range of values and we avoid the chance of a particularly long service time for a given entity, which could have occured within an exponential distibution like in problem 1. A long service time in a single server system would predictably slow things down.
tri <- function (mean_inter, a, b, m) {
lam <- 1/mean_inter
Es <- (a + m + b)/3
mu <- 1/Es
sdev <- sqrt((a^2 + m^2 + b^2 - a*m - a*b - b*m)/18)
# If p is less than 1, we have a stable queue
p <- lam/mu
#Wq is the steady state average time in the queue
Wq <- (lam*(sdev^2 + 1/(mu^2))) / (2*(1-p))
#W is the steady state average time in the system
W <- Wq + Es
#L is the steady state average number of entities in the system (rather than the number in queue)
L <- lam * W
# Lq is the steady state average number of entities in the queue
Lq <- lam * Wq
df <- data.frame(p=p, Lq=Lq, L=L, W=W, Wq=Wq)
return(df)
}
df3 <- rbind(df2, tri(1.25, 0.1, 1.9, 1))
df3
## p Lq L W Wq
## 1 0.8 3.200 4.000 5.00 4.00
## 2 0.8 2.032 2.832 3.54 2.54
## 3 0.8 1.816 2.616 3.27 2.27
The p values remained the same again, while the number of entities in system/queue and the wait time/time in queues decreased even further as compared to Question #2.
Ran into some issues here, with the numbers only approximating the mmc output
mmc <- function (mean_inter, mean_service, c, mult=1) {
lam <- (1/mean_inter)*mult
mu <- 1/(mean_service)
# If p is less than 1, we have a stable queue
p <- lam/(mu*3)
#empty vector to stre values
summ <- 0
for (i in 1:3) {
summ <- summ + (c*p)^(i-1)/(factorial(i-1))
}
p0 <- (((c*p)^c)/(factorial(c)*(1-p)) + summ)^-1
#Wq is the steady state average time in the queue
Wq <- ((c*p)^c*p0) / (factorial(c)*c*mu*(1-p)^2)
#W is the steady state average time in the system
W <- Wq + 1/mu
# Lq is the steady state average number of entities in the queue
Lq <- (p * ((c*p)^c) * p0)/ (factorial(c)*((1-p)^2))
#L is the steady state average number of entities in the system (rather than the number in queue)
L <- Lq + (lam/mu)
df <- data.frame(p=p, Lq=Lq, L=L, W=W, Wq=Wq)
return(df)
}
mmc(1.25,3,3)
## p Lq L W Wq
## 1 0.8 2.588764 4.988764 6.235955 3.235955
df4 <- rbind(df3, mmc(1.25, 3, 3))
df4
## p Lq L W Wq
## 1 0.8 3.200000 4.000000 5.000000 4.000000
## 2 0.8 2.032000 2.832000 3.540000 2.540000
## 3 0.8 1.816000 2.616000 3.270000 2.270000
## 4 0.8 2.588764 4.988764 6.235955 3.235955
alt text
My formula is not perfect, but I decided to use it for the next problem anyway. Hopefully, I can figure out what needs to be tweaked when we go over the homework.
Service Time in minutes is 3 for sign in, 5 for registration, 90 for trauma, 16 for exam rooms and 15 for treatment.
#Sign in
mmc(6,3,2)
## p Lq L W Wq
## 1 0.1666667 0.009160305 0.5091603 3.082443 0.08244275
#registration
mm1(6,5,0.9)
## p Lq L W Wq
## 1 0.75 2.25 3 20 15
# trauma
mmc(6, 90, 2, 0.1)
## p Lq L W Wq
## 1 0.5 0.2857143 1.785714 115.7143 25.71429
#exam
mmc(6, 16, 3, 0.9)
## p Lq L W Wq
## 1 0.8 2.588764 4.988764 33.25843 17.25843
#treatment
mmc(6,15,2,(0.9*0.6)+0.1)
## p Lq L W Wq
## 1 0.5333333 0.3614373 1.961437 20.08271 5.082712
I would add a server to the trauma room. The trauma room has the highest queue time (25 minutes) and these are the patients who need help quickly.