discrete event simulation - lthomikron.eit.lth.se/etsn01/etsn012016/lectures/1.2_simulation.pdf•...
TRANSCRIPT
Lund University / Presentation 2012
Discrete Event Simulation
ETSN01 Advanced Telecommunication
Lund University / Presentation 2012
Why simulation?
• We need to study and understand complicated systems to be able to design better ones
• Predict system behaviour under different conditions and parameters• Approaches:
– Analysis– Experiment– Simulation
Lund University / Presentation 2012
Why simulation? (cont’d)
Analysis Simulation ExperimentMathematical model (solving equations etc.)
Software implementation of system model
Tinker with actual system
Requires detailed understanding of system properties
For complex systems, usually requires approximations and simplifying assumptions
Usually straightforward
Possible to implement complex details of system without approximation
Still requires modelling of environment
In principle, does not require understanding how the system works
Captures behaviour of environment
If model is good, allows deep insight for broad range of scenarios, including rare events
Allows insight to broad range of scenarios
Study of rare events tricky but possible
Requires deployment of every scenario tested
May be difficult to reproduce
Rare events can be impossible to stimulate
Lund University / Presentation 2012
Types of Simulation
• Time-driven simulation– Evaluate changes in system every time step– Can we wasteful if system frequently idle
• Discrete event-driven simulation– Maintain a list of pending “events” at all times– Process each event in turn to update system state and list of future events– Works well for time-independent systems with not too frequent events
• Markovian simulation (aka Roulette simulation)– Only possible for Markovian systems (memoryless and time-independent, transitions among
states only depend on current state)– Only maintain current state, simulate state transitions (no timing information needed)
• Monte-Carlo simulation– Use independent samples from some analytic solution
• Rare event simulation– Artificially boost occurrence of rare events
Lund University / Presentation 2012
Simulation approaches
• Code in some HLL: C, C++, Java,….
• Use a simulation package: ns, ssf, Opnet, …– Ns (http://www.nsnam.org): “Ns is a discrete event simulator targeted at networking
research. Ns provides substantial support for simulation of TCP, routing, and multicast protocols over wired and wireless (local and satellite) networks”
– Ssfnet (http://www.ssfnet.org): “A public-domain standard for discrete-event simulation of large, complex systems in Java and C++”
– Opnet (http://www.opnet.com): Commercial network simulation product
– Omnet++ (http://www.omnetpp.org/): Network simulation tool, open source, gaining traction.
Lund University / Presentation 2012
Discrete Event Simulation: Event List
• Key is the event list– Contains times of scheduled events
– All events must be scheduled
– Assuming t1<t2<t3<t4<t5<t6<t7
t1,t1info
t2,t2info
t3,t3info
t4,t4info
t5,t5info
t6,t6info
t7,t7info
Next event
Lund University / Presentation 2012
Discrete Event Simulation: Event List
t1,t1info
t2,t2info
t3,t3info
– Now schedule new event at time tn where t3<tn<t4
t4,t4info
t5,t5info
t6,t6info
t7,t7info
t4t4info
t5,t5info
t6,t6info
t7,t7info
tn,tninfo
Lund University / Presentation 2012
Example: Single Server Queue
Events:– Packet arrives and joins queue– Packet begins service– Packet completes service
Lund University / Presentation 2012
–Packet arrives and joins queue–Increment queue; if queue was empty, begin service of packet
–Packet begins service–Schedule completion of packet service
–Packet completes service–Decrement queue
Example: Single Server Queue
Lund University / Presentation 2012
Implementation Details
• Must implement the event list processing– need to maintain event list, system state, simulation clock
– execute events from list
• Must consider inputs– schedule all arrivals at start
– or use “bootstrapping”: schedule next arrival when prior arrival happens
• Must consider outputs– decide which statistics to collect (e.g. count arrivals, departures)
• Consider length of simulation / termination condition
Lund University / Presentation 2012
Single-Server Queue Simulation
Start
Init
MoreEvents?
Arrvl? Dept?
Update varsSchedule next arrival
Update varsSchedule next departure
Yes
Yes Yes
No
End
No
Compute performanceDisplay stats
Lund University / Presentation 2012
Statistical Analysis
• Simulation is an experiment of a software model• Results are samples of underlying random variables• We want to obtain insight into the system behaviour
– and predict how it will work in other scenarios• This means that we MUST analyse the simulation results
statistically
Estimated MeanConfidence Interval,with probability x%,true mean lies withinthis range
Lund University / Presentation 2012
Understanding statistical analysis
OR??
Lund University / Presentation 2012
Independent Samples
• Assume a random variable Z with unknown probability distribution• How to estimate key distribution metrics?
– mean μ– variance σ2
• Obtain n independent samples (data points) {z1,z2,...,zn}
Lund University / Presentation 2012
Estimation of mean
• Estimate mean by calculating sample average:
• Sample average is itself a random variable!
• Is a good estimator of the mean μ?
• Since each zi is distributed according to Z,
• therefore
Lund University / Presentation 2012
Estimation of mean (cont’d)
• How many samples should we take?• Let’s estimate the variance
• So: the more samples, the smaller the variance of around the mean
Lund University / Presentation 2012
Estimation of variance
• Calculate sample variance:
• Expected value of the sample variance:
Lund University / Presentation 2012
Estimation of variance (cont'd)
• This gives a biased estimate of the population variance, σ2
• So we instead use unbiased sample variance, denoted s2. Note division by n – 1 instead of n: this is called Bessel's correction.
Lund University / Presentation 2012
Confidence Intervals
• Assume is distributed normally (Gaussian)– reasonable approximation if sample size is large
• Then, depends only on α!
– is 0.9 for α≈1.645
– is 0.95 for α≈1.96
– is 0.99 for α≈2.576
• For example: is confidence interval for μ with confidence level of 95%
• In practice, σ is not known – use instead
Lund University / Presentation 2012
Transients in the Simulation
• Everything above assumes that the samples are:– independent
– and identically distributed
• Distribution is different during transient phase– must ensure samples are obtained after system has reached steady state
• To avoid transient data:– run long enough so that transients have negligible impact on the estimates of confidence
interval
– or, if only short runs available, manually discard samples from transient phase
Lund University / Presentation 2012
Effect of Correlation
• Simulation data is never perfectly independent
• Can estimate correlation between successive samples
– autocovariance of lag k is defined as:
• Autocovariance should be low (close to zero) for any k
• Otherwise, need to do better
Lund University / Presentation 2012
Method of Batch Means
• Group raw sample data into batches–so that successive batches are approximately
independent• For example, if you have n data points, group them into m
batches of size p=n/m• Calculate the m batch means• Now treat the batches as if they were independent
Lund University / Presentation 2012
Batch Means
• Probably most widely-used method for estimating confidence intervals
• Gives less bias at the expense of more variability in the estimator• The difficult part is choosing the batch size
– batch too large: confidence intervals larger than is justified by the actual data
– batch too small: excessive correlation and misleadingly small confidence intervals
Lund University / Presentation 2012
For Further Reading
• B.D. Ripley, Stochastic Simulation, John Wiley and Sons, 1987 • B.D. Ripley, Uses and abuses of statistical simulation, Mathematical Programming Vol 42, pp
53-68, 1988 • K. Pawlikowski, “Steady-state simulation of queueing processes: A survey of problems and solutions”, ACM
Computing Surveys, Vol 22, No 2, pp123-170, June 1990• A.M. Law and W.D. Kelton, Simulation Modelling and Analysis, McGraw-Hill, 1991• R.F. Garzia and M.R. Garzia (eds), Network Modelling, Simulation and Analysis, Marcel Dekke
1990 • E.D. Lazowska, Quantitative System Performance: Computer System Analysis using Queueing
Network Models, Prentice-Hall, 1984 • Telecom Australia, A Course in Teletraffic Engineering, Telecom Australia, 1978 • The Network Simulator - ns-3, http://www.nsnam.org