Assignment #6-simulation

Performance Lawn Equipment produces lawnmowers and a medium size diesel power lawn tractor. Because customer demand fluctuates, PLE is considering running a second manufacturing shift if inventory drops below a specified level. For varying demand levels, perform a Monte Carlo simulation in order to determine inventory levels and number of shifts required. Find the distribution of number of shifts required and write a formal report summarizing your results

Data

Run simulation for 1000 times. In each time, go through 260 business days, and on each day create a random number between 80 and 130 representing the demand (assuming uniform probablity destribution). Calculate the annual total number of shifts required according to the proposed policy, i.e., to add a second shift if yesterday’s end-of-day inventory is 50 units or less.

Planned production capacity for one component 100 units per shift demand fluctuates 80 -130 units per day If inventory drops below 50 % 260 of working days

set.seed(51669841)             
thld = 50                       
                              
for(i_sim in 1:1000) {          
  for(day in 1:260) {           
    if(day == 1) {             
      beg_inventory <- 100          
      num_shifts <- 1          
      production <- num_shifts * 100
                                
      demand <- floor(runif(1, min = 80, max = 131))
                           
      if (demand == 131) {demand <- 130}
      end_inventory <- beg_inventory + production - demand
                               
      insuff_inventory_ind = FALSE  
      if (end_inventory < 0) {      
        end_inventory <- 0          
        insuff_inventory_ind = TRUE 
      }
      current_day_entry <- data.frame(day,
                                   beg_inventory,
                                   num_shifts,
                                   production,
                                   demand,
                                   end_inventory,
                                   insuff_inventory_ind)
                               
      inventory_log <- current_day_entry
                                
      
    } else {                    
      beg_inventory <- end_inventory    
      num_shifts <- ifelse(beg_inventory <= thld, 2, 1)
                                
      production <- num_shifts * 100
                               
      demand <- floor(runif(1, min = 80, max = 131))
                                
      if (demand == 131) {demand <- 130}
                               
      end_inventory <- beg_inventory + production - demand
                                
      insuff_inventory_ind = FALSE  
      if (end_inventory < 0) {      
        end_inventory <- 0          
        insuff_inventory_ind = TRUE 
      }
      current_day_entry <- data.frame(day,
                                   beg_inventory,
                                   num_shifts,
                                   production,
                                   demand,
                                   end_inventory,
                                   insuff_inventory_ind)
                               
      inventory_log <- rbind(inventory_log, current_day_entry)
                                
    }
  }
  
  annu_shifts <- sum(inventory_log$num_shifts)
                                
  annu_insuff_inventory <- sum(inventory_log$insuff_inventory_ind)
                                
  if(i_sim == 1) {
    sim_log <- data.frame(i_sim, annu_shifts, annu_insuff_inventory)
  } else {
    sim_log <- rbind(sim_log,
                     data.frame(i_sim, annu_shifts, annu_insuff_inventory))
  }
}

On average, the simulation generates an annual total number of shifts of 273.207:

avg_annual_shifts <- mean(sim_log$annu_shifts)  

Step 2. Distribution of number of shifts

library(ggplot2)
plot <- ggplot(sim_log)                     
plot +
  geom_histogram(aes(annu_shifts,       
                     ..density..),          
                 binwidth = 1,              
                 fill = "yellow",       
                 color = "white") +        
  labs(x = "Annual Total Number of Shifts", 
       y = "Probability Density") +         
  stat_function(fun = dnorm,                
                color = "blue",       
                size = 2,                 
                args = list(mean = avg_annual_shifts, 
                            sd = sd(sim_log$annu_shifts))
                )

The peak is at 273 shifts which will be the ideal number of shifts to be calculated for the budget plan.