Complete problems 17 from Section 3.5 in Kelton.
#create reproducability
set.seed(123)
Walther had a roadside produce stand where he sells oats, peas, beans, and barley. He buys these products at per-pound wholesale prices of, respectively, $1.05, $3.17, $1.99, and $0.95; he sells them at per-pound retail prices of, respectively, $1.29, $3.76, $2.23, $1.65. Each day the amount demanded (in pounds) could be as little as zero for each product, respectively, and as much as 10, 8, 14, and 11 for oats, peas, beans, and barely, respectively; he sells only whole-pound amounts, no partial pounds. Assume a discrete uniform distribution for daily demand for each product over its range; assume as well that Walther always has enough inventory to satisfy all demand. The summer selling season is 90 days, and demand each day is independent of demand on other days. Create a spreadsheet simulation that will, for each day as well as for the whole season, simulate Walther’s total cost, total revenue, and total profit.
oats <- data.frame('cost'=c(1.05), 'sale'=c(1.29), 'profit'=c(1.29-1.05), 'maxdemand'=c(10))
peas <- data.frame('cost'=c(3.17), 'sale'=c(3.76), 'profit'=c(3.76-3.17), 'maxdemand'=c(8))
beans <- data.frame('cost'=c(1.99), 'sale'=c(2.23), 'profit'=c(2.23-1.99), 'maxdemand'=c(14))
barley <- data.frame('cost'=c(0.95), 'sale'=c(1.65), 'profit'=c(1.65-0.95), 'maxdemand'=c(11))
A function will easily solve this:
#function to run through simulations
demandrun <- function(df, days){
#create new data frame with needed columns
df2 <- data.frame('day'=c(1:days), 'demand'=c(rep('', days)), 'dailycost'=c(rep('', days)), 'dailysale'=c(rep('', days)), 'dailyprofit'=c(rep('', days)))
#fill columns with data
df2$demand <- round(runif(days, min=0, max=oats['maxdemand'][[1]]))
df2$dailycost <- df2$demand * df$cost[[1]]
df2$dailysale <- df2$demand * df$sale[[1]]
df2$dailyprofit <- df2$demand * df$profit[[1]]
#output data frame
df2
}
and output our simulations:
oats2 <- demandrun(oats, 90)
head(oats2)
## day demand dailycost dailysale dailyprofit
## 1 1 3 3.15 3.87 0.72
## 2 2 8 8.40 10.32 1.92
## 3 3 4 4.20 5.16 0.96
## 4 4 9 9.45 11.61 2.16
## 5 5 9 9.45 11.61 2.16
## 6 6 0 0.00 0.00 0.00
peas2 <- demandrun(peas, 90)
head(peas2)
## day demand dailycost dailysale dailyprofit
## 1 1 1 3.17 3.76 0.59
## 2 2 7 22.19 26.32 4.13
## 3 3 3 9.51 11.28 1.77
## 4 4 7 22.19 26.32 4.13
## 5 5 3 9.51 11.28 1.77
## 6 6 2 6.34 7.52 1.18
beans2 <- demandrun(beans,90)
head(beans2)
## day demand dailycost dailysale dailyprofit
## 1 1 8 15.92 17.84 1.92
## 2 2 3 5.97 6.69 0.72
## 3 3 7 13.93 15.61 1.68
## 4 4 3 5.97 6.69 0.72
## 5 5 6 11.94 13.38 1.44
## 6 6 5 9.95 11.15 1.20
barley2 <- demandrun(barley, 90)
head(barley2)
## day demand dailycost dailysale dailyprofit
## 1 1 9 8.55 14.85 6.3
## 2 2 0 0.00 0.00 0.0
## 3 3 1 0.95 1.65 0.7
## 4 4 2 1.90 3.30 1.4
## 5 5 8 7.60 13.20 5.6
## 6 6 7 6.65 11.55 4.9
To see a total view:
totaldf <- oats2 + peas2 + beans2 + barley2
totaldf$day <- totaldf$day / 4
head(totaldf)
## day demand dailycost dailysale dailyprofit
## 1 1 21 30.79 40.32 9.53
## 2 2 18 36.56 43.33 6.77
## 3 3 15 28.59 33.70 5.11
## 4 4 21 39.51 47.92 8.41
## 5 5 26 38.50 49.47 10.97
## 6 6 14 22.94 30.22 7.28
In which we can see total profits:
sum(totaldf$dailyprofit)
## [1] 785.11
My thoughts with re-creating this simulation in Simio would be to create an input (Source) without a frequency limit (e.g. unlimited customers can enter), four parallel servers (e.g. a fruit stand for each food type), and one exit/sink (e.g. leaving the market). At each stand have a maximum capacity of your max demand, and minimum capacity of 0 (e.g. no demand for that food). When running the simulation, each simulation ‘run’ would be a day, and using the financials section in Simio a cost/profit would be calculated.
When trying to do this, I was unable to figure out how to work profit per server (as I only see cost in the financials) and could not solve for a daily run period.