Docsity

Lecture Notes on Simulation Modeling | CS 6910, Study notes of Computer Science

Partial preview of the text

Download Lecture Notes on Simulation Modeling | CS 6910 and more Study notes Computer Science in PDF only on Docsity!

Simulation Modeling

• Imitation of the operation of a real-world

process or system over timep

y

• Objective: to collect data as if a real system

were being observedwere being observed

• Data collected from the simulation are used

to estimate the performance/dependabilityto estimate the performance/dependabilitymeasures of the system

Discrete Event Simulation

• modeling of the system as it evolves over

modeling of the system as it evolves overtime by a representation in which the statevariables change only at a countableva

ab es c a ge o

y at a cou tab e

number of points in time

• terminology:• terminology:

  • simulation clock: a variable that gives the

current value of the simulated timecurrent value of the simulated time

  • event: an instantaneous occurrence which may

change the state of the system

change the state of the system

Event Scheduling

• Determine the number of event types in the

system, e.g., 1: arrival, 2: request for service, 3:

y

g ,

q

service completion, 4: timer, etc.

• Place one or more initial event records in the

Place one or more initial event records in theevent list, each containing

  • event time event type customer class etc– event time, event type, customer class, etc.

Determine the most imminent event in the event (by thetiming routine) in a loop until a specified stopping ruletiming routine) in a loop until a specified stopping ruleis satisfied

  • update the simulation clock when an event record is

update the simulation clock when an event record isremoved from the event list

Event Scheduling (cont.)

  • Pass the control to the event routine corresponding

to the event type

  • Update the state of the system– Gather the statistics if necessary

• Report the simulation results when the

simulation is completed

p

  • For example

the average response time per client

g

p

p

the loss probability of cells

the system throughput

the average number of clients served over a timeperiod

Structure of An smpl Program

p

g

Initialization routine;timing control routine to select the most imminent eventfrom the event list (event clock is updated implicitly){{

event type 1: event routine for event type 1;event type 2: event routine for event type 2;

event type n: event routine for event type n;event type n: event routine for event type n; }

t ti ti

ti

ti

statistics reporting routine;

Initialization Routine

smpl(m, s)int m=0; /* always 0 */int m 0; /

always 0

char *s;

l

id

d

f

t

f

ti

d

smpl provides seeds for 15 streams for generating randomnumbers. To collect a set of 15 sample values of a particularperformance measure, one can invoke smpl() 15 times:

loop: repeat 15 times

smpl(0, “hw1”); }

O

l

t

t

t

t

if

th

One can also use stream(1), stream(2), etc. to specify thestream number to be used in a simulation run

r = preempt(fd id, tkn id, pri)

Facility Definition and Control

p

p (

_

_

, p

int fd_id, tkn_id, pri;=> same as request() except that it will preempt the server if it is busyserving a task with priority < “pri”serving a task with priority <

pri

=> the event record corresponding to the preempted token is removedfrom the event list and a queue entry with the residual time is createdr=0: facility is reservedr=1: facility is busy and the request is blocked in the queue

y

y

q

q

ordered on priorityrelease(fd id tkn id)

create an event with the same

t t

d

t it i

th

t li t

release(fd_id, tkn_id)int fd_id; int tkn_id;=> release the facility and if the queue is not empty, reschedule

bl

k d

i h h

i

NOW

event type and put it in the event list

a blocked request to occur with the event occurrence time at NOW+te (te=event time for a blocked task and te=the residualtime for a preempted task)

h d l (

id

k

id)

Scheduling Events

schedule(event_id, te, tkn_id)int event_id;real te; /* time interval relative to the current time */

int tkn_id;=> schedule the event with id “event_id” to occur at NOW+te=> this essentially inserts an event record with the event occurrence

this essentially inserts an event record with the event occurrence time NOW+te into the event list=> part of the information in the event record is event_id, tkn_id

d h

i

NOW

and the event occurrence time NOW+teExample: schedule(2, 0.0, token_id)

p

_

=> schedule event type #2 associated with token id “token_id” tooccur NOW

Canceling Events

cancel(event_id)int event_id;=> search the event list and remove the first event with the event=> search the event list and remove the first event with the eventnumber = event_id

Get Current Simulation Time

t = real time()t = real time()=> return the current simulation clock value=> real is a predefined type; it is the same as double in C

Status Functions

n= int inq(fd);=> returning # of tokens currently in queue (not including the onesin service)in service)r = int status(fd)

f

ili

i

f

f

ili

i

b

=> r=0: facility is free; r=1: facility is busyu = real U(fd)

=> mean # of tokens in servicen = real Lq(fd)n = real Lq(fd)=> mean # of tokens in queue excluding the ones in serviceb

l B(fd)

b = real B(fd)=> mean busy period = accumulated busy time/release counts

Traces and Debugging

trace(n)int n;

gg

g

=> generate trace messages when a facility is defined, requested, orreleased, or whenever an event is scheduled or causedn=0: trace is offn=1; free-running, i.e., trace messages are generated continuouslyn=2: screen by screen running (press any key to resume tracing)n=2: screen by screen running (press any key to resume tracing)n=3: message by message running (press any key to resume)

M/M/1 smpl program

#i

l d

“

l h”

#include “smpl.h”main(){ real Ta=200 Ts=

te=200000;

case 2: /* request server */

if (request(server, customer,0)==0)

h d l (

l(T )

)

real Ta=200, Ts=100, te=200000;int customer=1, event, server;smpl(0, “M/M/1 Queue”);server = facility(“server”,1);

schedule(3, expntl(Ts), customer);break;

case 3: /* completion */

release(server customer);

server

facility( server ,1);

schedule(1, 0.0, customer);while (time()< te){

release(server, customer);break;

}

{

cause(&event, &customer);switch(event){

} } report();}

case 1: /* arrival */

schedule(2,0.0, customer);schedule(1, expntl(Ta), customer);b

k

}

17

break;

Confidence Interval and Level

(cont.)

• When Y

1

, Y

2

, …, Y

N

are independent random

variables from a normal distribution with themean

, H is defined by H = t

α

/2;N-

/sqrt(N)

where t is the standard t distribution and

2

is

the sample variance given by

2

i (

Y

i^

- Y

) 2

/(N-1) (and thus

is the standard deviation).

Batch Mean Analysis by smpl

m

m

samples to

samples to

Use a batch size m around 2000 observations to

generate Y

1

p

generate Y

2

collect a sample value

Y

i^

to justify the normal

distribution assumption.

Delete d = 0.1 m initial observations

Collect k = 10 batches and compute the confidence

p

interval half-width H

If the desired accuracy has not been reached, collect

another batch and compute H again. Repeat asnecessary.