-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductionline_MonteCarlo_example2.R
31 lines (28 loc) · 1.12 KB
/
productionline_MonteCarlo_example2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#Monte Carlo Simulation in R Example
#from https://www.programmingr.com/monte-carlo-simulation-in-r/
min(runif(1,3000,5000),runif(1,2000,4000),runif(1,150,200)*30)
min(runif(1,3000,5000),runif(1,2000,4000),runif(1,150,200)*30)
min(runif(1,3000,5000),runif(1,2000,4000),runif(1,150,200)*30)
#if we want to run more iterations, e.g. 1000 iterations
#to build a larger vector of results
#full Monte Carlo Simulator in R
results = NULL
for (k in 1:1000) #iterate 1000 times
{
rolls = runif(1,3000,5000)
bags = runif(1,2000,4000)
cases = runif(1,150,200)*30
total = min(rolls, bags, cases)
results = rbind(results, data.frame(rolls, bags, cases, total))
}
head(results)
summary(results) # from the summary, we can see that the bagger is the constraint (least rolls per hour)
#The speed of the overall manufacturing line is limited to the speed of putting the rolls into bags
summary(results$total) #prints horizontally
summary(results['total']) #prints vertically
#the triangular distribution
install.packages("EnvStats")
library(EnvStats)
rtri(50, 0, 1, 1/2) #'50' is the number of samples drawn from the distribution
d <- rnorm(1,2,3)
d