Estimate by simulation the average number of lost sales per week for an inventor
ID: 3707276 • Letter: E
Question
Estimate by simulation the average number of lost sales per week for an inventory system that functions as follows:
(a) When ever the inventory level falls to or below 10 units, an order is placed. Only one order can be outstanding at a time
(b) The size of each order is 20-I where I is the inventory level when the order is placed.
(c) If a demand occurs during a period when the inventory level is zero, the sale is lost.
(d) Daily demand is normally distributed with a mean of 5 and a standard deviation of 1.5 units. (Round off demand to the closest integer during the simulation and if a negative value results, give it a demand of zero).
(e) Lead time is distributed uniformly between zero and 5 days, integers only
(f) The simulation starts with 18 units in inventory
(g) For simplicity, assume that all demands occur at 12 noon and that all orders are placed at the same time. Assume further that orders are received at 5:00 pm, or after demand has occurred for that day.
(h) Let the simulation run for 5 weeks.
Explanation / Answer
inventorySim <- function(daysToSimulate, daysPerWeek)
{
simTable <- data.frame(day=seq(0, daysToSimulate),
#dayInCycle=c(daysPerWeek, rep(seq(1, daysPerWeek), daysToSimulate / daysPerWeek)),
beginInv=c(NA, rep(NA, daysToSimulate)),
demand=c(NA, round(rnorm(daysToSimulate, mean=5, sd=1.5))),
endInv=c(18, rep(NA, daysToSimulate)),
lostSales=rep(NA, daysToSimulate + 1),
#shortage=c(0, rep(NA, daysToSimulate)),
pendingOrder=c(0, rep(0, daysToSimulate)),
leadTime=c(NA, rep(NA, daysToSimulate)),
orderArriveDays=c(0, rep(0, daysToSimulate)))
# Loop over the rows the compute the various activity and clock times
for(i in seq(1, nrow(simTable)))
{
if(i == 1)
{
# Do nothing on first row (zeroth)
}
else
{
# Are any orders arriving today?
pendingO <- 0
if(simTable[i-1,]$orderArriveDays <= 1)
{
pendingO <- simTable[i-1,]$pendingOrder
simTable[i,]$pendingOrder <- 0
}
# Adjust begining inventory based on prior ending plus arriving orders
simTable[i,]$beginInv <- simTable[i-1,]$endInv + pendingO
if(simTable[i,]$demand > 0 && simTable[i,]$beginInv == 0)
{
simTable[i,]$lostSales <- simTable[i,]$demand
}
# Adjust ending inventory
endI <- simTable[i,]$beginInv - simTable[i,]$demand #- simTable[i-1,]$shortage
simTable[i,]$endInv <- max(endI, 0)
# Ordering
if(simTable[i,]$endInv <= 10 && simTable[i-1,]$orderArriveDays <= 1)
{
# New Order
simTable[i,]$pendingOrder <- 20 - simTable[i,]$endInv
simTable[i,]$leadTime <- round(runif(1, 0, 5))
simTable[i,]$orderArriveDays <- simTable[i,]$leadTime
}
else
{
# Adjust arrival days for pending orders
simTable[i,]$orderArriveDays <- if(simTable[i-1,]$orderArriveDays > 0) simTable[i-1,]$orderArriveDays - 1 else 0
if(simTable[i,]$orderArriveDays > 0)
{
simTable[i,]$pendingOrder <- simTable[i-1,]$pendingOrder
}
}
}
}
return(simTable)
}
# Days based on 5 biz days/wk for n weeks
weeksToSim <- 5
daysToSim <- 5 * weeksToSim
inventorySimTable <- inventorySim(daysToSim)
kable(inventorySimTable)
Based on the previously shown simulation data, the average lost sales per week are r sum(inventorySimTable$lostSales, na.rm=TRUE) / weeksToSim. The following chart shows lost sales as red points and the blue line represents the inventory levels during the simulation.
g1 <- ggplot(inventorySimTable) +
geom_point(aes(x=day, y=lostSales), colour="red") +
geom_line(aes(x=day, y=beginInv), colour="lightblue") +
labs(title="Lost Sales Simulation", y="Inventory Level") +
myTheme
g1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.