Build function to solve probelms for this assignments
# get Utilization
utilization <- function(lamda,c,u){
result<-lamda/(c*u)
return(result)
}
# get P(0)
pzero<-function(c,p){
result1<-((c*p)^c)/(factorial(c)*(1-p))
result2<-0
for(i in 0:(c-1)){
result2<-result2+((c*p)^(i))/factorial(i)
}
result<-(result1+result2)^-1
return(result)
}
lamdaEffective<-function(outputRate,lamdaInput){
return(lamdaInput/outputRate)
}
# get number of customer at Queue Lq
Lq<-function(c,p){
result1<-((c*p)^c)/(factorial(c)*(1-p))
result2<-0
for(i in 0:(c-1)){
result2<-result2+((c*p)^(i))/factorial(i)
}
pZero<-(result1+result2)^-1
result<-(p*((c*p)^c)*pZero)/(factorial(c)*(1-p)^2)
return(result)
}
# get number of customer in the system L
L<-function(c,p,lamda,u){
result1<-((c*p)^c)/(factorial(c)*(1-p))
result2<-0
for(i in 0:(c-1)){
result2<-result2+((c*p)^(i))/factorial(i)
}
pZero<-(result1+result2)^-1
lq<-(p*((c*p)^c)*pZero)/(factorial(c)*(1-p)^2)
result<-lq+(lamda/u)
return(result)
}
# get time in the queue Wq
Wq<-function(c,p,u){
result1<-((c*p)^c)/(factorial(c)*(1-p))
result2<-0
for(i in 0:(c-1)){
result2<-result2+((c*p)^(i))/factorial(i)
}
pZero<-(result1+result2)^-1
result<-(((c*p)^c)*pZero)/(factorial(c)*c*u*(1-p)^2)
return(result)
}
# get time in the system W
W<-function(c,p,u){
result1<-((c*p)^c)/(factorial(c)*(1-p))
result2<-0
for(i in 0:(c-1)){
result2<-result2+((c*p)^(i))/factorial(i)
}
pZero<-(result1+result2)^-1
wq<-(((c*p)^c)*pZero)/(factorial(c)*c*u*(1-p)^2)
r<-wq+(1/u)
return(r)
}
Wqc<-function(lamda,SD,u){
result<-(lamda*(SD^2+(1/u^2)))/(2*(1-(lamda/u)))
return(result)
}
# M/M/1
interarrival<-1.25
serviceTime<-1
lamda<-1/interarrival
u<-1/serviceTime
c<-1
p<-utilization(lamda,c,u)
lq<-Lq(c,p)
l<-L(c,p,lamda,u)
wq<-Wq(c,p,u)
w<-W(c,p,u)
myDfTemp<-data.frame( "Method" = "Exponential", "lamda"= lamda,"U"= u,"C" = c,"P"= p,"Lq"= lq,"L"= l,"Wq"=wq,"W"= w,"SD"= 0)
myDf<-myDfTemp
myDf
## Method lamda U C P Lq L Wq W SD
## 1 Exponential 0.8 1 1 0.8 3.2 4 4 5 0
# M/G/1
a<-0.1
b<-1.9
es<-(a+b)/2
sd<-sqrt(((b-a)^2)/12)
u<-1/es
p<-lamda/u
wq_c<-Wqc(lamda,sd,u)
Lq_c<-wq_c*lamda
w_c<-wq_c+es
L_c<-w_c*lamda
myDfTemp<-data.frame("Method" = "Uniform Distripution","lamda" = lamda, "U" = u,"C" = c, "P" = p, "Lq" = Lq_c,"L" = L_c,"Wq" = wq_c, "W" = w_c, "SD" = sd)
myDfTemp
## Method lamda U C P Lq L Wq W SD
## 1 Uniform Distripution 0.8 1 1 0.8 2.032 2.832 2.54 3.54 0.5196152
myDf<-rbind(myDf,myDfTemp)
m<-1
es<-(a+b+m)/3
sd<-sqrt((a^2+m^2+b^2-a*m-a*b-b*m)/18)
u<-1/es
p<-lamda/u
wq_c<-Wqc(lamda,sd,u)
Lq_c<-wq_c*lamda
w_c<-wq_c+es
L_c<-w_c*lamda
myDfTemp<-data.frame("Method" = "Triangular Distribution","lamda" = lamda, "U" = u,"C" = c, "P" = p, "Lq" = Lq_c,"L" = L_c,"Wq" = wq_c, "W" = w_c, "SD" = sd)
myDf<-rbind(myDf,myDfTemp)
myDf
## Method lamda U C P Lq L Wq W SD
## 1 Exponential 0.8 1 1 0.8 3.200 4.000 4.00 5.00 0.0000000
## 2 Uniform Distripution 0.8 1 1 0.8 2.032 2.832 2.54 3.54 0.5196152
## 3 Triangular Distribution 0.8 1 1 0.8 1.816 2.616 2.27 3.27 0.3674235
The result of the three distributions analysis methods with the same arrival rate produces different outcome. The M/M/1, the exponential distribution has the highest queueing rate and system process time of all distributions tested. While the M/G/1, the continuous uniform distribution illustrates a much lower queueing rate and system process time than the exponential distribution. The triangle distribution produces the lowest expectation queueing rate and system processing of all the distribution.
in conclusion, the exponential distribution produces higher expectations than the general distributions. It seems the exponential distribution process services time has impacted by the exponential behavior and produces higher expected values, while; the uniform distribution produces average system processing service time that is more realistic in term changes between system processes.
# M/M/1
interarrival<-1.25
serviceTime<-3
lamda<-1/interarrival
u<-1/serviceTime
c<-3
p<-utilization(lamda,c,u)
lq<-Lq(c,p)
l<-L(c,p,lamda,u)
wq<-Wq(c,p,u)
w<-W(c,p,u)
myDf<-data.frame( "lamda"= lamda,"U"= u,"c" =c,"P"= p,"Lq"= lq,"L"= l,"Wq"=wq,"W"= w)
myDf
## lamda U c P Lq L Wq W
## 1 0.8 0.3333333 3 0.8 2.588764 4.988764 3.235955 6.235955
options(width = 75)
# M/M/1
# Sign In
interarrival<-6
serviceTime<-3
c<-2
lamda<-(1/interarrival)*1
u<-1/serviceTime
p<-utilization(lamda,c,u)
lq<-Lq(c,p)
l<-L(c,p,lamda,u)
wq<-Wq(c,p,u)
w<-W(c,p,u)
mydfTemp<-data.frame("Station" = "Sign In" ,"lamda"= round(lamda,3),"U"= round(u,3),"c" = round(c,3),"P"= round(p,3),"Lq"= round(lq,3),"L"= round(l,3),"Wq"= round(wq,3),"W"= round(w,3))
myDf<-mydfTemp
# Registration
serviceTime<-5
c<-1
lamda<-(1/interarrival)*0.9
u<-1/serviceTime
p<-utilization(lamda,c,u)
lq<-Lq(c,p)
l<-L(c,p,lamda,u)
wq<-Wq(c,p,u)
w<-W(c,p,u)
mydfTemp<-data.frame("Station" = "Registration" ,"lamda"= round(lamda,3),"U"= round(u,3),"c" = round(c,3),"P"= round(p,3),"Lq"= round(lq,3),"L"= round(l,3),"Wq"= round(wq,3),"W"= round(w,3))
myDf<-rbind(myDf,mydfTemp)
# Exam Room
serviceTime<-16
c<-3
lamda<-(1/interarrival)*0.9
u<-1/serviceTime
p<-utilization(lamda,c,u)
lq<-Lq(c,p)
l<-L(c,p,lamda,u)
wq<-Wq(c,p,u)
w<-W(c,p,u)
mydfTemp<-data.frame("Station" = "Exam Room" ,"lamda"= round(lamda,3),"U"= round(u,3),"c" = round(c,3),"P"= round(p,3),"Lq"= round(lq,3),"L"= round(l,3),"Wq"= round(wq,3),"W"= round(w,3))
myDf<-rbind(myDf,mydfTemp)
# Trauma Room
serviceTime<-90
c<-2
lamda<-(1/interarrival)*0.1
u<-1/serviceTime
p<-utilization(lamda,c,u)
lq<-Lq(c,p)
l<-L(c,p,lamda,u)
wq<-Wq(c,p,u)
w<-W(c,p,u)
mydfTemp<-data.frame("Station" = "Trauma Room" ,"lamda"= round(lamda,3),"U"= round(u,3),"c" = round(c,3),"P"= round(p,3),"Lq"= round(lq,3),"L"= round(l,3),"Wq"= round(wq,3),"W"= round(w,3))
myDf<-rbind(myDf,mydfTemp)
#Treatment Room
serviceTime<-15
c<-2
lamda<-(1/interarrival)*0.1+(1/interarrival)*(0.9*0.6)
u<-1/serviceTime
p<-utilization(lamda,c,u)
lq<-Lq(c,p)
l<-L(c,p,lamda,u)
wq<-Wq(c,p,u)
w<-W(c,p,u)
mydfTemp<-data.frame("Station" = "Treatment Room" ,"lamda"= round(lamda,3),"U"= round(u,3),"c" = round(c,3),"P"= round(p,3),"Lq"= round(lq,3),"L"= round(l,3),"Wq"= round(wq,3),"W"= round(w,3))
myDf<-rbind(myDf,mydfTemp)
myDf
## Station lamda U c P Lq L Wq W
## 1 Sign In 0.167 0.333 2 0.25 0.033 0.533 0.200 3.200
## 2 Registration 0.150 0.200 1 0.75 2.250 3.000 15.000 20.000
## 3 Exam Room 0.150 0.062 3 0.80 2.589 4.989 17.258 33.258
## 4 Trauma Room 0.017 0.011 2 0.75 1.929 3.429 115.714 205.714
## 5 Treatment Room 0.107 0.067 2 0.80 2.844 4.444 26.667 41.667
Since all the values for utilizations are less than 1 thus the system will work and experience stability. The Exam Room and Treatment Room are congested and need more servers to reduce process time.