I’ll assume Walther restocks every morning; and calculate daily profit according to what he had to add to the mornings inventory to meet max demand
Data first
oats = c(1.05,1.29,10)
peas = c(3.17,3.76,8)
beans = c(1.99,2.23,14)
barley = c(.95,1.65,11)
Took a formula from the textbook
#Uniform distribution discrete random variable
uddrv = function(a,b){
return(floor(a+(b+1-a)*runif(1,min=0,max=1)))
}
#Lets create a spreadsheet for each product, then combine them
profits = function(item,days){
spreadsheet = data.frame(matrix(vector(), days, 5,
dimnames=list(c(), c("New day inventory","cost", "h", 'revenue', "profit"))),
stringsAsFactors=F)
spreadsheet[1,] = c(0,item[1]*item[3],0,0,-item[1]*item[3])
for(i in 2:nrow(spreadsheet)) {
previousRow = spreadsheet[i-1,]
row = spreadsheet[i,]
newDayInventory = item[3]-previousRow[3]
costToStock = (item[3]-newDayInventory)*item[1]
itemsSold = uddrv(0,item[3])
sales = itemsSold*item[2]
profit = sales-costToStock
newRow = c(newDayInventory,costToStock,itemsSold,sales,profit)
spreadsheet[i,] =newRow
}
return(spreadsheet)
}
# Create some spreadsheets per item; along with their totals
oats_summer = profits(oats,90)
oats_summer_totals = colSums(oats_summer)
peas_summer = profits(peas,90)
peas_summer_totals = colSums(peas_summer)
beans_summer = profits(beans,90)
beans_summer_totals = colSums(beans_summer)
barley_summer = profits(barley,90)
barley_summer_totals = colSums(barley_summer)
walthers_food_emporium = barley_summer+oats_summer+peas_summer+beans_summer
walthers_totals = colSums(walthers_food_emporium)
#combine em
Walthers_chart = rbind(walthers_totals,oats_summer_totals,peas_summer_totals,beans_summer_totals,barley_summer_totals)
So here is a chart you’ve approximately seen, in every other discussion.
kable(Walthers_chart)
New.day.inventory | cost | h | revenue | profit | |
---|---|---|---|---|---|
walthers_totals | 1984 | 3221.68 | 1868 | 3999.92 | 778.24 |
oats_summer_totals | 446 | 476.70 | 446 | 575.34 | 98.64 |
peas_summer_totals | 361 | 1138.03 | 356 | 1338.56 | 200.53 |
beans_summer_totals | 695 | 1124.35 | 564 | 1257.72 | 133.37 |
barley_summer_totals | 482 | 482.60 | 502 | 828.30 | 345.70 |
Here is the day by day for peas
peas_summer[nrow(peas_summer)+1,] = peas_summer_totals
kable(peas_summer)
New.day.inventory | cost | h | revenue | profit |
---|---|---|---|---|
0 | 25.36 | 0 | 0.00 | -25.36 |
8 | 0.00 | 6 | 22.56 | 22.56 |
2 | 19.02 | 5 | 18.80 | -0.22 |
3 | 15.85 | 0 | 0.00 | -15.85 |
8 | 0.00 | 0 | 0.00 | 0.00 |
8 | 0.00 | 7 | 26.32 | 26.32 |
1 | 22.19 | 1 | 3.76 | -18.43 |
7 | 3.17 | 8 | 30.08 | 26.91 |
0 | 25.36 | 1 | 3.76 | -21.60 |
7 | 3.17 | 0 | 0.00 | -3.17 |
8 | 0.00 | 6 | 22.56 | 22.56 |
2 | 19.02 | 0 | 0.00 | -19.02 |
8 | 0.00 | 2 | 7.52 | 7.52 |
6 | 6.34 | 4 | 15.04 | 8.70 |
4 | 12.68 | 0 | 0.00 | -12.68 |
8 | 0.00 | 5 | 18.80 | 18.80 |
3 | 15.85 | 4 | 15.04 | -0.81 |
4 | 12.68 | 7 | 26.32 | 13.64 |
1 | 22.19 | 2 | 7.52 | -14.67 |
6 | 6.34 | 6 | 22.56 | 16.22 |
2 | 19.02 | 6 | 22.56 | 3.54 |
2 | 19.02 | 3 | 11.28 | -7.74 |
5 | 9.51 | 6 | 22.56 | 13.05 |
2 | 19.02 | 8 | 30.08 | 11.06 |
0 | 25.36 | 2 | 7.52 | -17.84 |
6 | 6.34 | 6 | 22.56 | 16.22 |
2 | 19.02 | 4 | 15.04 | -3.98 |
4 | 12.68 | 7 | 26.32 | 13.64 |
1 | 22.19 | 7 | 26.32 | 4.13 |
1 | 22.19 | 8 | 30.08 | 7.89 |
0 | 25.36 | 1 | 3.76 | -21.60 |
7 | 3.17 | 8 | 30.08 | 26.91 |
0 | 25.36 | 4 | 15.04 | -10.32 |
4 | 12.68 | 8 | 30.08 | 17.40 |
0 | 25.36 | 8 | 30.08 | 4.72 |
0 | 25.36 | 1 | 3.76 | -21.60 |
7 | 3.17 | 4 | 15.04 | 11.87 |
4 | 12.68 | 3 | 11.28 | -1.40 |
5 | 9.51 | 1 | 3.76 | -5.75 |
7 | 3.17 | 2 | 7.52 | 4.35 |
6 | 6.34 | 3 | 11.28 | 4.94 |
5 | 9.51 | 6 | 22.56 | 13.05 |
2 | 19.02 | 2 | 7.52 | -11.50 |
6 | 6.34 | 1 | 3.76 | -2.58 |
7 | 3.17 | 6 | 22.56 | 19.39 |
2 | 19.02 | 1 | 3.76 | -15.26 |
7 | 3.17 | 2 | 7.52 | 4.35 |
6 | 6.34 | 2 | 7.52 | 1.18 |
6 | 6.34 | 2 | 7.52 | 1.18 |
6 | 6.34 | 7 | 26.32 | 19.98 |
1 | 22.19 | 2 | 7.52 | -14.67 |
6 | 6.34 | 8 | 30.08 | 23.74 |
0 | 25.36 | 0 | 0.00 | -25.36 |
8 | 0.00 | 4 | 15.04 | 15.04 |
4 | 12.68 | 7 | 26.32 | 13.64 |
1 | 22.19 | 8 | 30.08 | 7.89 |
0 | 25.36 | 1 | 3.76 | -21.60 |
7 | 3.17 | 2 | 7.52 | 4.35 |
6 | 6.34 | 0 | 0.00 | -6.34 |
8 | 0.00 | 3 | 11.28 | 11.28 |
5 | 9.51 | 4 | 15.04 | 5.53 |
4 | 12.68 | 6 | 22.56 | 9.88 |
2 | 19.02 | 3 | 11.28 | -7.74 |
5 | 9.51 | 4 | 15.04 | 5.53 |
4 | 12.68 | 6 | 22.56 | 9.88 |
2 | 19.02 | 1 | 3.76 | -15.26 |
7 | 3.17 | 6 | 22.56 | 19.39 |
2 | 19.02 | 6 | 22.56 | 3.54 |
2 | 19.02 | 6 | 22.56 | 3.54 |
2 | 19.02 | 2 | 7.52 | -11.50 |
6 | 6.34 | 2 | 7.52 | 1.18 |
6 | 6.34 | 8 | 30.08 | 23.74 |
0 | 25.36 | 1 | 3.76 | -21.60 |
7 | 3.17 | 5 | 18.80 | 15.63 |
3 | 15.85 | 7 | 26.32 | 10.47 |
1 | 22.19 | 4 | 15.04 | -7.15 |
4 | 12.68 | 4 | 15.04 | 2.36 |
4 | 12.68 | 1 | 3.76 | -8.92 |
7 | 3.17 | 4 | 15.04 | 11.87 |
4 | 12.68 | 3 | 11.28 | -1.40 |
5 | 9.51 | 6 | 22.56 | 13.05 |
2 | 19.02 | 8 | 30.08 | 11.06 |
0 | 25.36 | 7 | 26.32 | 0.96 |
1 | 22.19 | 1 | 3.76 | -18.43 |
7 | 3.17 | 2 | 7.52 | 4.35 |
6 | 6.34 | 0 | 0.00 | -6.34 |
8 | 0.00 | 5 | 18.80 | 18.80 |
3 | 15.85 | 3 | 11.28 | -4.57 |
5 | 9.51 | 8 | 30.08 | 20.57 |
0 | 25.36 | 5 | 18.80 | -6.56 |
361 | 1138.03 | 356 | 1338.56 | 200.53 |