Transcript Lecture 19
Discrete Event Simulation
•How to generate RV according to a specified
distribution?
• geometric
• Poisson etc.
• Example of a DEVS:
• repair problem
Outline
What is discrete event simulation?
Events
Probability
Probability distributions
Sample application
What is discrete event simulation?
“Simulation
is the process of designing a model of a real
system and conducting experiments with this model for
the purpose either of understanding the behavior of the
system or of evaluating various strategies (within the limits
imposed by a criterion or set of criteria) for the operation
of a system.”
-Robert E Shannon 1975
“Simulation is the process of designing a dynamic model of an
actual dynamic system for the purpose either of understanding the
behavior of the system or of evaluating various strategies (within the
limits imposed by a criterion or set of criteria) for the operation of a
system.”
-Ricki G Ingalls 2002
Definitions from http://staff.unak.is/not/andy/Year%203%2Simulation/Lectures/SIMLec2.pdf
What is discrete event simulation?
A simulation is a dynamic model that
replicates the behavior a real system.
Simulations may be deterministic or stochastic,
static or dynamic, continuous or discrete.
Discrete event simulation (DEVS) is stochastic,
dynamic, and discrete.
DEVS is not necessarily spatial – it usually isn’t,
but the ideas are applicable to many spatial
simulations
What is discrete event simulation?
• DEVS has been around for decades, and is supported
by a large set of supporting tools, programming
languages, conventional practices, etc.
• Like other kinds of simulation, offers an alternative,
often simple way of solving a problem – simulate
system and observe results, instead of coming up with
analytical model.
• Many other benefits like repeatability, ability to use
multiple parameter sets, experimental treatment of
what may be unique system, cheap compared to
physical experiment, etc.
• Usually involves posing a question. The simulation
estimates an answer.
What is discrete event simulation?
• Stochastic = probabilistic
• Dynamic = changes over time
• Discrete = instantaneous events are
separated by intervals of time
Time may be modeled in a variety of ways
within the simulation.
Alternate treatments of time
Time divided into equal increments:
Unequal increments:
Cyclical:
Termination
• Simulation may terminate when a
terminating condition is met.
• May also be periodic.
• Can also be conceptually endless, like
weather, terminated at some arbitrary time.
• Usually converges or stabilizes on particular
result.
Events
• May change the state of the system.
• Have no duration.
• If time is event-based, events happen when
time advances.
• Canonical example: flipping a coin.
• Events usually have a value associated with
them (e.g. coin: true/false).
• The definition of an event depends on the
subject of the model.
Random Variables
• A random variable (“X”) is numerical value
associated with a random event.
• X can have different values:
• X1, X2, X3…Xn
• In a stochastic DEVS, the value associated
with event is probablistic, that is it occurs with
a given probability.
• That probability is what allows us to use DEVS
to estimate results when we don’t know the
precise value of input parameters to our
model.
Pseudorandom Number Generators
• A stochastic simulation depends on a
pseudorandom number generator to
generate usable random numbers.
• These generators can vary significantly in
quality.
• For practical purposes, it may be important to
check the random number generator you are
using to make sure it behaves as expected.
Example: Using matlab’s rand(), let us simulate
a coin toss and test how good the random
number generator is.
Probability distributions
• In a DEVS, you need to decide what
probability distribution functions best model
the events.
• Pseudorandom number generators generate
numbers in a uniform distribution
• One basic trick is to transform that uniform
distribution into other distributions.
• There are many basic probability distributions
are convenient to represent mathematically.
• They may or may not represent reality, but can
be useful simplifications.
Normal or Gaussian distribution
o Ubiquitous in statistics
o Many phenomena
follow this distribution
o When an experiment is
repeated, the results
tend to be normally
distributed.
Simulating a Probability distribution
Sampling values from an observational
distribution with a given set of probabilities
(“discrete inverse transform method”).
Generate a random number U
If U < p0 return X1
If U < p0 + p1 return X2
If U < p0 + p1 + p2 return X3
etc.
This can be speeded up by sorting p so that the
larger intervals are processed first, reducing
the number of steps.
Poisson distribution
• Example of algorithm to sample from a distribution.
• X follows a Poisson distribution if:
P{ X i} e
i
i!
An algorithm for sampling from a Poisson distribution:
1.
2.
3.
4.
Generate a random number U
If i=0, p=e-l, F=p
If U < F, return I
P = l * p / (i + 1),
F = F + p, i = i + 1
5. Go to 3
There are similar tricks to sampling from other
probability distributions. Some tools like Matlab
have these built in.
A repair problem
n machines are needed to keep an operation.
There are s spare machines. The machines in
operation fail according to some known
distribution (e.g. exponential, Poisson, uniform
etc. with a known mean). When a machine fails,
it is sent to repair shop and the time to fix is a
random variable that follows a known
distribution.
Question: What is the expected time for the
system to crash? System crashes when fewer
than n machines are available.
Plotting outcome of experiments
The expected value (mean) will converge after a
number of repetitions.
We can demonstrate the process of flipping
coins…with a simulation. Here are two runs of a
simulated sequences of 1000 coin flips (see code),
displaying the average result (sum of Xi / n):
Note that the variance is high initially and diminishes
with time.