These are the answers to the problems in Chapter 2. For the answers to the problem in Chapter 1, please refer to the other attached PDF.
2.1
set.seed(10)
processtime <- c(50, round(rnorm(9, 50, 8)))
mean(processtime)
## [1] 46.2
The mean processing time is 46 minutes.
set.seed(10)
interarrival <- c(0,sample(c(0,60,120,180), 9, replace = TRUE, prob = c(0.23, 0.37, 0.28, 0.12)))
wait = rep(1,10)
wait[1] = 25
for (i in 2:10){
wait[i] = wait[i-1] + processtime[i-1] - interarrival[i]
if (wait[i] <= 0){
wait[i] = 0
} else {
wait[i] = wait[i-1] + processtime[i-1] - interarrival[i]
}
}
mean(wait)
## [1] 11.3
The mean queue time is 11.3 minutes.
total <- processtime + wait
max(total)
## [1] 84
The maximum time in the system for the ten new jobs was 84 minutes.
2.2
set.seed(10)
numberofcustomers <- sample(c(8,10,12,14), 5, replace = TRUE, prob = c(0.35,0.3,0.25,0.1))
set.seed(10)
numberordered <- sample(c(1,2,3,4), 5, replace = TRUE, prob = c(0.4,0.3,0.2,0.1))
net <- numberofcustomers*numberordered
net
## [1] 20 8 20 24 8
required <- max(net)
required
## [1] 24
Within these 5 days, the maximum number of bagels baked is 24. When we round it up to the nearest 5 we get 25. Therefore 25 dozen bagels should be baked each day.
2.4
Given that the company operates 8 hours a day, there is a high possibility that the number of customers that the company will get in a typical day is 20 because the probability a customer would use the service for 25 minutes is greater than those of the other service time lengths. Dividing 8 hours by 25 minutes we get a number that we can round to up 20.
set.seed(10)
intercalltime1 <- c(0,sample(c(15,20,25,30,35), 19, replace = TRUE, prob = c(0.14,0.22,0.43,0.17,0.04)))
intercalltime2 <- c(0,sample(c(15,20,25,30,35), 19, replace = TRUE, prob = c(0.14,0.22,0.43,0.17,0.04)))
intercalltime3 <- c(0,sample(c(15,20,25,30,35), 19, replace = TRUE, prob = c(0.14,0.22,0.43,0.17,0.04)))
intercalltime4 <- c(0,sample(c(15,20,25,30,35), 19, replace = TRUE, prob = c(0.14,0.22,0.43,0.17,0.04)))
intercalltime5 <- c(0,sample(c(15,20,25,30,35), 19, replace = TRUE, prob = c(0.14,0.22,0.43,0.17,0.04)))
set.seed(10)
servicetime1 <- sample(c(5,15,25,35,45), 20, replace = TRUE, prob = c(0.12, 0.35, 0.43, 0.06, 0.04))
servicetime2 <- sample(c(5,15,25,35,45), 20, replace = TRUE, prob = c(0.12, 0.35, 0.43, 0.06, 0.04))
servicetime3 <- sample(c(5,15,25,35,45), 20, replace = TRUE, prob = c(0.12, 0.35, 0.43, 0.06, 0.04))
servicetime4 <- sample(c(5,15,25,35,45), 20, replace = TRUE, prob = c(0.12, 0.35, 0.43, 0.06, 0.04))
servicetime5 <- sample(c(5,15,25,35,45), 20, replace = TRUE, prob = c(0.12, 0.35, 0.43, 0.06, 0.04))
wait1 = rep(1,20)
wait1[1] = 0
for (i in 2:20) {
wait1[i] = wait1[i-1] + servicetime1[i-1] - intercalltime1[i]
if (wait1[i] <= 0) {
wait1[i] = 0
} else {
wait1[i] = wait1[i-1] + servicetime1[i-1] - intercalltime1[i]
}
}
wait2 = rep(1,20)
wait2[1] = 0
for (i in 2:20) {
wait2[i] = wait2[i-1] + servicetime2[i-1] - intercalltime2[i]
if (wait2[i] <= 0) {
wait2[i] = 0
} else {
wait2[i] = wait2[i-1] + servicetime2[i-1] - intercalltime2[i]
}
}
wait3 = rep(1,20)
wait3[1] = 0
for (i in 2:20) {
wait3[i] = wait3[i-1] + servicetime3[i-1] - intercalltime3[i]
if (wait3[i] <= 0) {
wait3[i] = 0
} else {
wait3[i] = wait3[i-1] + servicetime3[i-1] - intercalltime3[i]
}
}
wait4 = rep(1,20)
wait4[1] = 0
for (i in 2:20) {
wait4[i] = wait4[i-1] + servicetime4[i-1] - intercalltime4[i]
if (wait4[i] <= 0) {
wait4[i] = 0
} else {
wait4[i] = wait4[i-1] + servicetime4[i-1] - intercalltime4[i]
}
}
wait5 = rep(1,20)
wait5[1] = 0
for (i in 2:20) {
wait5[i] = wait5[i-1] + servicetime5[i-1] - intercalltime5[i]
if (wait5[i] <= 0) {
wait5[i] = 0
} else {
wait4[i] = wait5[i-1] + servicetime5[i-1] - intercalltime5[i]
}
}
mean(wait1)
## [1] 0
mean(wait2)
## [1] 3.5
mean(wait3)
## [1] 1.75
mean(wait4)
## [1] 6.25
mean(wait5)
## [1] 2.5
set.seed(1234)
servicetime11 <- sample(c(5,15,25,35,45), 20, replace = TRUE, prob = c(0.12, 0.35, 0.43, 0.06, 0.04))
servicetime22 <- sample(c(5,15,25,35,45), 20, replace = TRUE, prob = c(0.12, 0.35, 0.43, 0.06, 0.04))
servicetime33 <- sample(c(5,15,25,35,45), 20, replace = TRUE, prob = c(0.12, 0.35, 0.43, 0.06, 0.04))
servicetime44 <- sample(c(5,15,25,35,45), 20, replace = TRUE, prob = c(0.12, 0.35, 0.43, 0.06, 0.04))
servicetime55 <- sample(c(5,15,25,35,45), 20, replace = TRUE, prob = c(0.12, 0.35, 0.43, 0.06, 0.04))
set.seed(1234)
intercalltime11 <- c(0,sample(0:(servicetime11[1] + 1), 1),sample(c(15,20,25,30,35), 18, replace = TRUE, prob = c(0.14,0.22,0.43,0.17,0.04)))
intercalltime22 <- c(0,sample(0:(servicetime22[1] + 1), 1),sample(c(15,20,25,30,35), 18, replace = TRUE, prob = c(0.14,0.22,0.43,0.17,0.04)))
intercalltime33 <- c(0,sample(0:(servicetime33[1] + 1), 1),sample(c(15,20,25,30,35), 18, replace = TRUE, prob = c(0.14,0.22,0.43,0.17,0.04)))
intercalltime44 <- c(0,sample(0:(servicetime44[1] + 1), 1),sample(c(15,20,25,30,35), 18, replace = TRUE, prob = c(0.14,0.22,0.43,0.17,0.04)))
intercalltime55 <- c(0,sample(0:(servicetime55[1] + 1), 1),sample(c(15,20,25,30,35), 18, replace = TRUE, prob = c(0.14,0.22,0.43,0.17,0.04)))
In this case, in order to calculate the waiting time for each customer, we have to take into account, which driver finishes the job first. Whichever driver finishes first can pick up the next customer. Thus, waiting times for each customer can be minimized.
Due to the fact that for some of the data in each set, there is no continuous trend of which vehicle is used for each job. All of the waiting times are calculated in Microsoft Excel. When computing these waiting times we compute the amount of time the customer has to wait for the first cab to arrive and compare it to that of the second cab. Whichever quantity is the smallest is the actual waiting time of the customer. If we get a negative value for the waiting time, we can take the actual waiting time to be 0 minutes.
wait11 <- data.frame(servicetime11, intercalltime11)
wait22 <- data.frame(servicetime22, intercalltime22)
wait33 <- data.frame(servicetime33, intercalltime33)
wait44 <- data.frame(servicetime44, intercalltime44)
wait55 <- data.frame(servicetime55, intercalltime55)
write.table(wait11, file = "wait11.csv", sep = ",", row.names = FALSE)
write.table(wait22, file = "wait22.csv", sep = ",", row.names = FALSE)
write.table(wait33, file = "wait33.csv", sep = ",", row.names = FALSE)
write.table(wait44, file = "wait44.csv", sep = ",", row.names = FALSE)
write.table(wait55, file = "wait55.csv", sep = ",", row.names = FALSE)
wait11 <- read.csv(file = "/Users/chittampalliyashaswini/Desktop/Yadu/waiting11.csv", sep = ",", header = TRUE)
wait11$waiting.time
## [1] 0 0 -5 -18 -25 -20 -30 -30 -25 -30 -35 -35 -35 -30 -15 -5 -15
## [18] -35 -25 -25
wait11$actual.waiting.time
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
wait22 <- read.csv(file = "/Users/chittampalliyashaswini/Desktop/Yadu/waiting22.csv", sep = ",", header = TRUE)
wait22$waiting.time
## [1] 0 0 -6 -25 -25 -25 -25 -50 -35 -10 -15 -15 -30 -20 -25 -30 -20
## [18] -40 -30 -25
wait22$actual.waiting.time
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
wait33 <- read.csv(file = "/Users/chittampalliyashaswini/Desktop/Yadu/waiting33.csv", sep = ",", header = TRUE)
wait33$waiting.time
## [1] 0 -1 -15 0 -15 -30 -20 -30 -30 -35 -25 -30 -30 -30 -35 -40 -25
## [18] -30 -30 -25
wait33$actual.waiting.time
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
wait44 <- read.csv(file = "/Users/chittampalliyashaswini/Desktop/Yadu/waiting44.csv", sep = ",", header = TRUE)
wait44$waiting.time
## [1] 0 0 -25 -15 -5 -15 -25 -35 -25 -40 -30 -30 -20 0 -20 0 -15
## [18] -40 -30 -20
wait44$actual.waiting.time
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
wait55 <- read.csv(file = "/Users/chittampalliyashaswini/Desktop/Yadu/waiting55.csv", sep = ",", header = TRUE)
wait55$waiting.time
## [1] 0 0 -10 -29 -30 -30 -15 -35 -20 -20 -15 -35 -25 -15 -15 -15 -15
## [18] -25 -25 -25
wait55$actual.waiting.time
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
operatingtimes1 <- c((round(sum(servicetime1)/60)), round(sum(servicetime2)/60), round(sum(servicetime3)/60), round(sum(servicetime4)/60), round(sum(servicetime5)/60))
operatingtimes111 <- subset(wait11, wait11$vehicle.number == 1)
total111 <- round(sum(operatingtimes111$servicetime11)/60)
operatingtimes112 <- subset(wait11, wait11$vehicle.number == 2)
total112 <- round(sum(operatingtimes112$servicetime11)/60)
operatingtimes221 <- subset(wait22, wait22$vehicle.number == 1)
total221 <- round(sum(operatingtimes221$servicetime22)/60)
operatingtimes222 <- subset(wait22, wait22$vehicle.number == 2)
total222 <- round(sum(operatingtimes222$servicetime22)/60)
operatingtimes331 <- subset(wait33, wait33$vehicle.number == 1)
total331 <- round(sum(operatingtimes331$servicetime33)/60)
operatingtimes332 <- subset(wait33, wait33$vehicle.number == 2)
total332 <- round(sum(operatingtimes332$servicetime33)/60)
operatingtimes441 <- subset(wait44, wait44$vehicle.number == 1)
total441 <- round(sum(operatingtimes441$servicetime44)/60)
operatingtimes442 <- subset(wait44, wait44$vehicle.number == 2)
total442 <- round(sum(operatingtimes442$servicetime44)/60)
operatingtimes551 <- subset(wait55, wait55$vehicle.number == 1)
total551 <- round(sum(operatingtimes551$servicetime55)/60)
operatingtimes552 <- subset(wait55, wait55$vehicle.number == 2)
total552 <- round(sum(operatingtimes552$servicetime55)/60)
sum(total111, total112) <= operatingtimes1[1]
## [1] TRUE
sum(total221, total222) <= operatingtimes1[2]
## [1] TRUE
sum(total331, total332) <= operatingtimes1[3]
## [1] TRUE
sum(total441, total442) <= operatingtimes1[4]
## [1] TRUE
sum(total551, total552) <= operatingtimes1[5]
## [1] TRUE
When a second taxi is added to the fleet, the waiting time is reduced to 0 minutes for all of the customers.
During all five days the drivers end up working undertime when a second taxi is added to the fleet. When there is only one cab in the fleet, the driver works overtime only during one day. The number of hours worked that day is 9 hours. During other days, the number of hours worked is less than 8 hours.
Also, the number of hours worked by each driver is less than that of the driver who works alone. When we sum up those two operating times, we get a value that greater than that of the driver who works alone. There is a possibility that there is a lot of idle time during the operating hours of the company because both of the cabs can run simultaneously.
2.5
set.seed(10)
X <- c(round(rnorm(50, 100, 10)))
set.seed(10)
Y <- c(round(rnorm(50, 300, 15)))
set.seed(10)
Z <- c(round(rnorm(50, 40, 8)))
W <- (X + Y)/Z
min(W)
## [1] 8.714286
max(W)
## [1] 15.08696
hist(W, breaks = seq(from = 8, to = 17, by = 3))
2.7
Let us assume that when the simulation starts with 18 units in inventory, the demand is 0 and there are no orders placed or outstanding. The lead time is there just in case an order is placed on a particular day.
set.seed(10)
leadtime <- c(0,ceiling(runif(25, min = 0, max = 5)))
set.seed(10)
dailydemand <- c(0, round(rnorm(25, 5, 1.5)))
Let us assume that on day 0, there are no orders made and that there are no demands. This implies that the beginning and ending inventory are both the same.
inventory <- data.frame(dailydemand,leadtime)
write.table(inventory, file = "inventory.csv", sep = ",", row.names = FALSE)
inventory <- read.csv(file = "/Users/chittampalliyashaswini/Desktop/Yadu/inventory2.csv", sep = ",", header = TRUE)
sum(inventory$shortage)/25
## [1] 1.36
The average loss of sales is the average of all of the shortages. Over 25 days we get an average loss of sales as 1.36. To be discrete we can round it up to 2 sales lost.
2.8
Let us assume that there the elevator carries only one type of material at a time. For the first hour of operation let us assume that the elevator completes a total of 15 jobs. This means that it would have ideally carried either a total of 30 boxes of Material A or a total of 60 boxes of Material B or a total of 120 boxes of Material C.
set.seed(10)
interarrivalA <- c(0, sample((3:7), 29, replace = TRUE))
The reason why the job time or the elevator time for every odd-numbered package is 0 minutes is because it will not go up to the next floor unless another package of the same size is with it. Also, the reason why the elevator time for every even-numbered package is 4 minutes is to just facilitate the calculation of the wait times.
jobtimeA = rep(1,30)
for (i in 1:30){
if (i %% 2 == 1){
jobtimeA[i] = 0
} else {
jobtimeA[i] = 4
}
}
waittimeA = rep(1,30)
waittimeA[1] = interarrivalA[2]
waittimeA[2] = 0
for (i in 3:30) {
if (i %% 2 == 1) {
waittimeA[i] = interarrivalA[i+1] + jobtimeA[i-1] + waittimeA[i-1] - interarrivalA[i]
} else {
waittimeA[i] = waittimeA[i-1] - interarrivalA[i]
}
if (waittimeA[i] <= 0)
waittimeA[i] = 0
}
However, due to the interarrival times the elevator ends up operating overtime in this case because there are several minutes where the elevator is idle due to the fact that it cannot leave unless it has a full load. The one hour of operation would have to include the idle time for the elevator.
operateA = rep(1,15)
operateA[1] = 9
for (i in 2:15){
operateA[i] = interarrivalA[2*(i)-1] + interarrivalA[2*i]
if (interarrivalA[2*(i)-1] < 4) {
operateA[i] = interarrivalA[2*i] + 4
}
}
nhoursA = rep(1,15)
for (i in 1:15) {
nhoursA[i] = sum(operateA[1:i])
}
which(grepl(56, nhoursA))
## [1] 6
A total of 12 boxes will have been delivered by the time that approximately 1 hour would have elapsed. Therefore, It would operate 6 times in this hour.
transittimeA = waittimeA[1:12] + 3
mean(transittimeA)
## [1] 5.166667
The average transit time for a box of material A is calculated as 5.16 minutes in this hour of operation.
waittimeB = rep(5,60)
waittimeB[1] = 18
waittimeB[2] = 12
waittimeB[3] = 6
waittimeB[4] = 0
waittimeB[5:60] = rev(seq(-2,16,6))
for (i in 5:60){
if (waittimeB[i] < 0){
waittimeB[i] = 0
} else {
waittimeB[i] = waittimeB[i]
}
}
Due to the fact that the interarrival time for each box is the same. We do not have to run any loops to calculate the number of jobs completed by the elevator in 1 hour.
We can assume that there is one box of material B that is already waiting to be transported. That box has to wait 18 minutes for 3 more boxes to arrive. Therefore, the elevator is idle for 18 minutes. After those other 3 boxes arrive, the elevator takes 4 minutes to transport those boxes and to return to the ground floor. Then, the elevator has to just wait for 2 minutes for a box to arrive because 6 minutes after the 4th box arrives, the 5th box arrives. This cycle repeats for a whole number of times. We divide 60 by 24 and we get 2.5. This can be rounded up to a discrete value of 3. The number of jobs that has to be completed is 3. So, the elevator has to operate an extra 12 minutes yielding a total of 72 minutes. The total number of boxes that have to be transported is therefore 12.
mean(waittimeB[1:12])
## [1] 8
The average waiting time for a box of material B is 8 minutes.
set.seed(1234)
interarrivalC <- c(0, sample(c(2,3), 39, replace = TRUE, prob = c(0.33,0.67)))
Given the interarrival time probabilities for a box of material C, it would take more than 1 hour to transport a total of 120 boxes. Thus we should run a simulation for 40 boxes.
We then calculate for how long the elevator would have to operate in order to complete 5 jobs with each job containing 8 boxes. And yes, the operating time includes the idle time for the elevator as well.
operateC = rep(1,5)
for (i in 1:5) {
operateC[i] = sum(interarrivalC[((8*i)-7):((8*i))]) + 4
}
nhoursC = rep(1,5)
for (i in 1:5) {
nhoursC[i] = sum(operateC[1:i])
}
which(grepl(50, nhoursC))
## [1] 2
After 2 jobs are completed, a total of 50 minutes are elapsed. If a third job has to be completed then the elevator would have to operate overtime for 27 extra minutes. Therefore a total of 16 boxes of material C can make the trip in 1 hour.