Given queuing system for 10 customers with the following inter-arrival time (ITA) and service time (ST):
| ST | 4 | 1 | 4 | 3 | 2 | 4 | 5 | 4 | 5 | 3 |
| ITA | - | 8 | 6 | 1 | 8 | 3 | 8 | 7 | 2 | 3 |
IAT = c(0,8,6,1,8,3,8,7,2,3)
ST = c(4,1,4,3,2,4,5,4,5,3)
AT= cumsum(IAT)
TSB = c()
TCW= c()
TSE=c()
TCSS=c()
idl=c()
for (i in 1:length(IAT)) {
TSB[i]= max(AT[i],TSE[i-1])
TSE[i]= TSB[i]+ST[i]
TCW[i]= abs(TSB[i]-AT[i])
TCSS[i]= abs(TSE[i]-AT[i])
idl[i] = ifelse(i==1,0,ifelse(AT[i]>TSE[i-1],AT[i]-TSE[i-1],0))
}
data.frame(IAT,AT,ST,TSB,TCW,TSE,TCSS)
## IAT AT ST TSB TCW TSE TCSS
## 1 0 0 4 0 0 4 4
## 2 8 8 1 8 0 9 1
## 3 6 14 4 14 0 18 4
## 4 1 15 3 18 3 21 6
## 5 8 23 2 23 0 25 2
## 6 3 26 4 26 0 30 4
## 7 8 34 5 34 0 39 5
## 8 7 41 4 41 0 45 4
## 9 2 43 5 45 2 50 7
## 10 3 46 3 50 4 53 7
Assume the first customer arrives at time t= 0 minute. Write an R code using ITA and ST to construct a matrix or a dataframe including the following columns:
inter-arrival time (ITA)
Arrival time (AT)
Service time (ST)
Time service begins (TSB)
Time a customer waits in the queue (TCW)
Time service ends (TSE)
Time customer spent in the system (TCSS)
Idle time of the server (Idle)
Use the above variables to calculate the following:
mean(TCW>0)
## [1] 0.3
ST
## [1] 4 1 4 3 2 4 5 4 5 3
N.B Submit your answers as a html or pdf file.
set.seed(123)
id= sample(seq(1,100,1),5,replace = F)
id
## [1] 31 79 51 14 67
id= c(60,30,42,9,65)
IAT = function(id){
IAT= ifelse(id<=50,5,ifelse(id<=80,10,15))
}
ITA=IAT(id)
ST=c(7,7,7,7,7)
AT= cumsum(ITA)
TSB = c()
TCW= c()
TSE=c()
TCSS=c()
idl=c()
for (i in 1:length(ITA)) {
TSB[i]= max(AT[i],TSE[i-1])
TSE[i]= TSB[i]+ST[i]
TCW[i]= abs(TSB[i]-AT[i])
TCSS[i]= abs(TSE[i]-AT[i])
idl[i] = ifelse(i==1,0,ifelse(AT[i]>TSE[i-1],AT[i]-TSE[i-1],0))
}
data.frame(id,ITA,AT,ST,TSB,TCW,TSE,TCSS)
## id ITA AT ST TSB TCW TSE TCSS
## 1 60 10 10 7 10 0 17 7
## 2 30 5 15 7 17 2 24 9
## 3 42 5 20 7 24 4 31 11
## 4 9 5 25 7 31 6 38 13
## 5 65 10 35 7 38 3 45 10
tempdir()
## [1] "C:\\Users\\dimaa\\AppData\\Local\\Temp\\RtmpW4hW5t"
# [1] "C:\Users\XYZ~1\AppData\Local\Temp\Rtmp86bEoJ\Rtxt32dcef24de2"
dir.create(tempdir())
## Warning in dir.create(tempdir()):
## 'C:\Users\dimaa\AppData\Local\Temp\RtmpW4hW5t' already exists
id= c(60,30,42,9,65)
IAT = function(id){
IAT= ifelse(id<50,5,ifelse(id<80,10,15))
}
ITA=IAT(id)
ST=c(7,7,7,7,7)
AT= cumsum(ITA)
TSB = c()
TCW= c()
TSE=c()
for (i in 1:length(ITA)) {
TSB[i]= max(AT[i],TSE[i-1])
TSE[i]= TSB[i]+ST[i]
TCW[i]= abs(TSB[i]-AT[i])
}
id2= c(18,74,13,30,52)
AT2 = TSE
ST2 = function(id2){
ifelse(id2<30,4,ifelse(id2<80,8,12))
}
ST2= ST2(id2)
TCB2 = c()
TCW2=c()
TSE2=c()
TSS=c()
for (i in 1:length(id2)) {
TCB2[i]= max(TSE2[i-1],AT2[i])
TCW2[i]= TCB2[i]-AT2[i]
TSE2[i]= TCB2[i]+ST2[i]
TSS[i]= TSE2[i]-AT[i]
}
data.frame(id,ITA,AT,ST,TSB,TCW,TSE,id2,TCB2,TCW2,ST2,TSE2,TSS)
## id ITA AT ST TSB TCW TSE id2 TCB2 TCW2 ST2 TSE2 TSS
## 1 60 10 10 7 10 0 17 18 17 0 4 21 11
## 2 30 5 15 7 17 2 24 74 24 0 8 32 17
## 3 42 5 20 7 24 4 31 13 32 1 4 36 16
## 4 9 5 25 7 31 6 38 30 38 0 8 46 21
## 5 65 10 35 7 38 3 45 52 46 1 8 54 19