Using the software or spreadsheet of your choice, build one of the random number generators discussed in Banks Discrete-Event System Simulation. Post your code to the discussion board. What challenges did you have?
C++
is a powerful, efficient and fast language. It finds a wide range of applications - from GUI applications to 3D graphics for games to real-time mathematical simulations. C++
is a highly portable language with a rich function library that is often the language of choice for multi-device, multi-platform app development. C++
is an object-oriented programming language and includes classes, inheritance, polymorphism, data abstraction and encapsulation. C++
allows exception handling, and function overloading which are not possible in C.
The Rcpp
package provides R
functions as well as C++
classes which offer a seamless integration of R
and C++
. Many R
data types and objects can be mapped back and forth to C++
equivalents which facilitates both writing of new code as well as easier integration of third-party libraries. Code chunks that define functions in C++
using Rcpp
attributes are accomplished using the {r engine = 'Rcpp'}
chunk option.
\[h\left( n \right) \equiv \left( an+c \right) \left( \textrm{mod } { m } \right) \quad\quad\quad { U }_{ i }=\frac { { n }_{ i }+0.5 }{ m } ,\quad i\in \mathbb{N}\]
If \(a-1\) is a multiple of \(4\), the period \(m\) is maximal. Commonly used 32-bit parameters are \(m=2^{32}, c=1\), and \(a=22,695,477\).
#include <Rcpp.h>
// [[Rcpp::export]]
double LCG(unsigned int seed) {
static unsigned int n;
if (seed) {
return n = seed;
}
int a = 22695477.0;
double m = 4294967296.0;
n = a * n + 1;
return ((n + 0.5) / m);
}
To execute, first seed the random number generator with a natural number LCG(seed)
, then call the random number generator with zero LCG(0)
.
LCG(2017) # Seed the random number generator
LCG(0) # Generate the random number.
Getting Rcpp
to work with R Markdown was a challenge. The function returns \(0.6582365\) in R
, but does not output to markdown.
Complete problems 2, 3, 9, and 12 from Chapter 4 of Kelton. All assignment problems are based on Problem 1.
Problem 4.10.1: Create a model similar to Model 4-1 [Model_04_01.spfx, M/M/1, pp. 80-7] except use arrival rate, \(\lambda\), of 120 entities per hour and service rate, \(\mu\), of 190 entities per hour. Run your model for 100 hours and report the number of entities that were created, the number that completed service, and the average time entities spent in the system.
Develop a queuing model for the Simio model from Problem 1 and compute the exact values for the steady-state time entities spend in the system and the expected number of entities processed in 100 hours.
\[\lambda = \frac{N}{T_a} = \frac{1}{1/120} = 120, \quad \mu = \frac{N}{T_s} = \frac{1}{1/190} = 190, \quad E[100\mu]=100\cdot190=19000, \quad \rho = \frac{\lambda}{c\mu} = \frac{120}{1\cdot190} = \frac{12}{19}\] \[L = \frac{\lambda}{\mu - \lambda} = \frac{12}{7}, \quad W = \frac{1}{\mu\left(1 - \rho\right)} = \frac{1}{70}, \quad L_q = \frac{\rho^2}{1 - \rho}= \frac{144}{133}, \quad W_q = \frac{\rho}{\mu\left(1 - \rho\right)} = \frac{6}{665}\]
T_a <- 1 / 120
T_s <- 1 / 190
lambda <- 1 / T_a
mu <- 1 / T_s
c <- 1
rho = lambda / (c * mu)
L_q <- rho^2 / (1 - rho)
L <- lambda / (mu - lambda)
W <- 1 / (mu * (1 - rho))
W_q <- rho / (mu * (1 - rho))
exp_val <- mu * 100
data.frame(exp_val, rho, L, W, L_q, W_q)
## exp_val rho L W L_q W_q
## 1 19000 0.6315789 1.714286 0.01428571 1.082707 0.009022556
Using the model from Problem 1, create an experiment that includes 100 replications. Run the experiment and observe the SMORE plot for the time entities spend in the system. Experiment with the various SMORE plot settings - viewing the histogram, rotating the plot, changing the upper and lower percentile values.
Simulation Model | Experiment |
---|---|
One Source with Interarrival Time of Random.Exponential( 1/120 ) in Hours. One Server with Processing Time of Random.Exponential( 1/190 ) in Hours. One unmodified Sink. Experiment conducted with 100 Replications of 10 hour runs. Add Response of “W” with expression DefaultEntity.Population.TimeInSystem.Average. For changes in percentile values, 200 Replications were used.
SMORE Plot | Histogram | Rotate | Percentile Change |
---|---|---|---|
Replicate the model from Problem 1 using Simio processes (i.e., not using objects from the Standard Library). Compare the run times for this model and the model from Problem 1 for 50 replications of length 100 hours.
Facility Tab | Definitions Tab |
---|---|
Proecesses Tab |
---|
For a 100 hour 50 replication experiment on Problem 1, following the steps from Kelton pp. 99-102 (with the exception of using Random.Exponential( 1/120 ) in step 5 and Random.Exponential( 1/190 ) in step 12) to build and run a Simio process yielded results 28 times faster than the building and running a model using objects from the Simio standard library.
Animate your model from Problem 1 assuming that you are modeling a cashier at a fast food restaurant - the entities represent customers and the server represents the cashier at the cash register. Use Simio’s standard symbols for your animation.
Animation |
---|
https://www.youtube.com/watch?v=GtOt7EBNEwQ
http://dirk.eddelbuettel.com/code/rcpp/Rcpp-FAQ.pdf
https://www.youtube.com/watch?v=ZUBUjemyqpE&index=8
https://www.youtube.com/watch?v=6DN1NYfG1kQ&index=14
http://rmarkdown.rstudio.com/authoring_rcodechunks.html
https://en.wikipedia.org/wiki/Linear_congruential_generator
http://s1.daumcdn.net/editor/fp/service_nc/pencil/Pencil_chromestore.html
https://www.invensis.net/blog/it/benefits-of-c-c-plus-plus-over-other-programming-languages/
Simio and Simulation: Modeling, Analysis, Applications 3d Ed. by W. David Kelton, Jeffrey S. Smith and David T. Sturrock with Simio software.
Discrete-Event Systems Simulation, 5th Edition (2010), by Jerry Banks, John S. Carlson, Barry L. Nelson,and David M. Nicol.
Methods of Monte Carlo Simulation, Baruch College MTH 4135, C. Douglas Howard, 2011