+ All Categories
Home > Documents > 2 2005 Simulation

2 2005 Simulation

Date post: 04-Jun-2018
Category:
Upload: gerome-t-manantan
View: 219 times
Download: 0 times
Share this document with a friend
36
Simulation Based on Law & Kelton, Simulation Modeling & Analysis, McGraw-Hill
Transcript

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 1/36

Simulation

Based on

Law & Kelton, Simulation Modeling &Analysis, McGraw-Hill

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 2/36

Why Simulation?

• Test design when cannot analyze – System too complex – Can analyze only for certain cases (Poisson

arrivals, very large N, etc.)

• Verify analysis

• Fast production of results

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 3/36

Simulation types

• Static vs. dynamic• Deterministic vs. stochastic• Continuous vs. discrete

– Simulation model system model

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 4/36

Discrete Event System

• Discrete system – The system state can change only in a countable

number of points in time! – Event = an instantaneous change in state.

• Example: a queueing system

– System state: Number of customer – At each time number of customer can only

change by an integer

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 5/36

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)

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 6/36

Components of a discrete-event

simulation model• System state : the collection of state variables

necessary to describe the system at a particulartime.

• Simulation clock : a variable giving the currentvalue of simulated time

• Event list : a list containing the next time when

each type of event will occur.• Statistical counters : variables used for storingstatistical information about system performance – How many moments?

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 7/36

Components of a discrete-event

simulation model (2)• Initialization routine : a subprogram to initialize

the simulation model at time 0.

• Timing routine : a subprogram that determines thenext event from the event list and then advancesthe simulation clock to the time when the event isto occur.

• Event routine : A subprogram that updates thesystem state when a particular type of event occurs(one routine per event).

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 8/36

Components of a discrete-event

simulation model (3)• Library routine : A set of subprograms used

to generate random observations from

probability distributions that weredetermined as part of the simulation model.

• Report generator : A subprogram that

computes estimates (from the statisticalcounter) of the desired performancemeasures when simulation ends.

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 9/36

Components of a discrete-event

simulation model (4)• Main program : a subprogram that invokes

the timing routine to determine the next

event and then transfers control to thecorresponding event routine to update thesystem state. May also check for

termination and invoke the report generator.

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 10/36

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 11/36

Example

a single server queuing system• System to be simulated

– A i Interarrival times are I.I.D. – S

i Service time are I.I.D.

– FIFO service – Work preserving

• Initial state

– Empty and idle – First arrival after A i time units from time 0

• Termination after n customers left queue.

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 12/36

Performance measures

• d(n) = expected average delay in queue. – Customer point of view

• q(n) = expected time-average number ofcustomers in queue. – System point of view

– Note: average over time which is continuous !!• u(n) = proportion of time server is busy

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 13/36

No. of customers in queue.

0

1

2

3

4

t

Q(t)

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 14/36

No. of customers in queue.

0

1

2

3

4

t

Q(t)

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 15/36

Performance measures (2)

• Averages are not always enough.• Register max/min values.• Register the entire “pdf”

– histograms

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 16/36

Initialization

• Set simulation time to 0.• Set initial state:

– Server idle – Queue empty – Last event time

• Init event list

– Generate 1st arrival• Zero stat counters

– Total delay and number delayed – Area under Q(t) and B(t) .

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 17/36

1st Event: customer arrival

• After init finished the arrival event is selected andtime is advanced to this event

• Change server from idle to busy• Add 0 to total delay, increment No of delayed.• Generate two events:

– This customer departure

– Next arrival ( generate as you go )• Add 0 to the area under Q(t) .• Add 0 to the area under B(t) .

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 18/36

2nd Event: customer arrival

• Arrival event is selected and time is advanced tothis event

• Server busy => put customer in queue with arrivaltime

• Set “No. in queue” to 1.• Generate next- arrival events (don’t mess with dep.) • Add 0 to the area under Q(t) .• Add ( t 2-t 1) to the area under B(t) .

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 19/36

Remarks

• While handling an event time is standing• But, order of operation is still important:

– First update area under Q(t) then update “No. inqueue”

• Two events at the same time – Order may change simulation result!

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 20/36

Determining Events

• In complex systems events sequence maynot be trivial.

• Use of event graph to aim us is designingthe events

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 21/36

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

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 22/36

Alternative Event Graph

• This design is correct as well!• One more event => more complexity• Simplification rule:

– If an event node has incoming arcs that are all thin andsmooth, it can be eliminated.

• A strongly connected component that has noincoming arcs from other nodes must be

initialized.

arrivalEnter

servicedepar-

ture

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 23/36

Take care

• GIGO = garbage in garbage out – Realistic scenarios (arrival process, service time) – Full cover of system behavior

• Statistical confidence• What to model

– Not enough details => hurts accuracy

– Too many details => slows simulation• Attempt to verify correctness

– Simulate cases you can analyze

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 24/36

Random Generator

• Make sure you can regenerate your randomsequence, or debugging is hell .

• For long simulations, use 32 bit pseudorandom generator. 16 bit is too short!

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 25/36

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.

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 26/36

Confidence Interval

• X1, X 2, …X n are IID random variables withfinite mean and finite variance 2>0.

n

n X Z n

/))((

2

• By central limit theorem F n(z) (z) (the

std. Normal r.v.)• For sufficiently large n, approx. 100(1- )

percent confidence interval for is given by

F n(z)=P(Z n z) is Dist. Func. of Z n

nnS z n X /)()( 22/1

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 27/36

-5 -3 0 3 50

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

2/1 z

2/1 z

Area:

1-

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 28/36

Confidence Interval for Small n

• For small number of observations, we needto correct the coefficient of the interval

width

• The smaller n the larger t n-1,1- /2 is.• t n-1,1- /2 is taken from a table.

nnS t n X n /)()( 2

2/1,1

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 29/36

Confidence Interval

• In general all plots has to have a confidenceinterval on every mark

• Exception: high confidence (mark size)

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 30/36

A good pseudo random generator

float myrand(){

b32 = (314159269*b32 + 453860245);if (b32<0)

b32 = -b32;return(0.00000000046566128730 * b32);

}

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 31/36

Generating Non-Uniform

Distributions• F(x), the PDF, of any distribution is a

function to [0,1], => use the inverse

transform – Generate U~U(0,1) – Return X=F -1(U )

• P ( X x) = P ( F -1(U ) x)=P (U F ( x))=F( x)

Since U is U(0,1) and 0 F ( x) 1,

P (U y) = y

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 32/36

Generating the Exponential

distribution

)1ln()(

otherwise

0if

0

1)(

1

/

uu F

xe x F

x

Note we can use - ln(u).

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 33/36

0 20 40 60 80 100 120 140 160 180 2000

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 34/36

Simulating complex systems

• Systems often have many identical components – A queueing system with multiple queues

– A switch with multiple ports running a distributedalgorithm

• Must keep state for each component – Array of structures in C,

– multiple instances of the basic object (C++)• Keep the connectivity (when applicable)

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 35/36

Wet Exercise No. 1Assume a 100MHz output port. The port is fed from four input ports each

with its own queue. For this exercise we neglect all other traffic.Packets arrive at the input ports with inter packet space that is Exponentially

distributed with parameter (such that the total load is 20:20:120

percent). Packet length is distributed according to Internet mix.Scheduling between Qs: smooth deficit round robin, quota=3000.Every 250mS we send two back-to-back packets to measure the link capacity

e.g., according to the method inhttp://www.cc.gatech.edu/fac/Constantinos.Dovrolis/Papers/ton_dispersion.pdf

Run each simulation for 25 Sec.

• 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).

8/13/2019 2 2005 Simulation

http://slidepdf.com/reader/full/2-2005-simulation 36/36

Remarks

• Code has to work anywhere (not just athome), especially in TAU.

• Make it portable.• Oral exams through the semester.• Send code to [email protected]

– Specify development env. (Unix/Visual C/..) – One tar/zip file with makefile etc. – Header: “EX 1 PCN: stu- name”


Recommended