Simulation: Based On Law & Kelton, Simulation Modeling & Analysis, Mcgraw-Hill
Simulation: Based On Law & Kelton, Simulation Modeling & Analysis, Mcgraw-Hill
?Why Simulation
Test design when cannot analyze
System too complex Can analyze only for certain cases (Poisson arrivals, very large N, etc.)
Simulation types
Static vs. dynamic Deterministic vs. stochastic Continuous vs. discrete
Simulation model system model
Continuous Simulation
Simulating the flight of a rocket in the air
System state: rocket position and weight State changes continuously in time (according to a partial differential equation)
Flow control
Init Determine next event Event 1 Event n no
?Done report
Example
Initial state
Empty and idle First arrival after Ai time units from time 0
Performance measures
d(n) = expected average delay in queue.
Customer point of view
)Performance measures (2
Averages are not always enough. Register max/min values. Register the entire pdf
histograms
Initialization
Set simulation time to 0. Set initial state:
Server idle Queue empty Last event time
Add 0 to the area under Q(t). Add 0 to the area under B(t).
Remarks
While handling an event time is standing But, order of operation is still important:
First update area under Q(t) then update No. in queue
Determining Events
In complex systems events sequence may not be trivial. Use of event graph to aim us is designing the events
Event Graph
States are bulbs, connected with arrows Bold arrow: event may occur after nonzero time. Thin arrow: event may occur immediately.
arrival
-depar ture
This design is correct as well! One more event => more complexity Simplification rule:
If an event node has incoming arcs that are all thin and smooth, it can be eliminated.
A strongly connected component that has no incoming arcs from other nodes must be initialized.
Take care
GIGO = garbage in garbage out
Realistic scenarios (arrival process, service time) Full cover of system behavior
Random Generator
Make sure you can regenerate your random sequence, or debugging is hell. For long simulations, use 32 bit pseudo random generator. 16 bit is too short!
Statistical Confidence
Better a few short runs than one long one. However, make sure run time is long enough to make end conditions negligible. Given a set of IID random variables we can calculate the confidence interval.
Confidence Interval
X1, X2, Xn are IID random variables with finite mean and finite variance 2>0.
Z n = ( X (n ) )
/n
2
By central limit theorem Fn(z)(z) (the std. Normal r.v.) For sufficiently large n, approx. 100(1-) percent confidence interval for is given by
X ( n ) z1 / 2 S 2 ( n ) / n
:Area -1
3-
z1 / 2
z1 / 2
X ( n ) tn 1,1 / 2 S ( n ) / n
2
The smaller n the larger tn-1,1-/2 is. tn-1,1-/2 is taken from a table.
Confidence Interval
In general all plots has to have a confidence interval on every mark Exception: high confidence (mark size)
F 1 (u ) = ln(1 u )
Note we can use - ln(u).
20
40
60
80
100
120
140
160
180
200
Hand-ins:
Code transcript Histogram of the one-way inter packet delay for the packet pairs. Plot a graph of the capacity estimation as a function of the load and measurement packet size (use 3-5 sizes).
Remarks
Code has to work anywhere (not just at home), especially in TAU. Make it portable. Oral exams through the semester. Send code to shavitt@eng.tau.ac.il
Specify development env. (Unix/Visual C/..) One tar/zip file with makefile etc. Header: EX1 PCN: stu-name