BIF3203 - Part III Discrete Event Simulation (November 2012)
-
Upload
kevin-kaiguara -
Category
Documents
-
view
214 -
download
0
Transcript of BIF3203 - Part III Discrete Event Simulation (November 2012)
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
1/69
BIF3203Computer SimulationPart III: Discrete Event Simulation
Nicodemus Maingi
[email protected] II First Floor Staffroom, 3B
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
2/69
NMaingi, November 2012
Introduction to Discrete Event
Simulationn A discrete eventis something that occurs at an instant of
time.n Discrete-event simulationis the modeling of a system as
it evolves over time by a representation in which the statevariables change only at a countable number of points intime.
n If the system to be modeled can be represented by series ofdiscrete events, the method known as discrete eventsimulation can be used.n Systems that can be modeled using discrete event approach aregenerally systems where queuing mechanisms operate.
n We have looked at analytical queuing models in the previouschapter, but the systems discussed there were simple, wherevery restrictive assumptions applied.n In practice, queuing system can be quite complex and can contain a
number of sub-systems.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
3/69
NMaingi, November 2012
Introduction to Discrete Event
Simulation (2)n However, the general principles are the same, no matter
how complex the system.n The difficulty is more to do with keeping track of all the different
events and updating the statistics that a simulation willgenerate.
n For this reason, simulation is always carried out bycomputer, but to demonstrate the general principles, amanual method is usually employed.
n The purpose of a discrete event simulationis to study acomplex system by computing the times that would beassociated with real events in a real-life situation.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
4/69
NMaingi, November 2012
Introduction to Discrete Event
Simulation (3)n To analyze this sub-system we need information relating
to:
Arrival process:
n How customers arrive e.g. singly or in groups (batch orbulk arrivals)
n How the arrivals are distributed in time (e.g. what is theprobability distribution of time between successive
arrivals (the inter-arrival time distribution))n Whether there is a finite population of customers or
(effectively) an infinite number
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
5/69
NMaingi, November 2012
Introduction to Discrete Event
Simulation (4)Service mechanism:
n A description of the resources needed for service tobegin
n How long the service will take (the service timedistribution)
n The number of servers availablen Whether the servers are in series (each server has a
separate queue) or in parallel (one queue for all servers)n Whether preemption is allowed (a server can stop
processing a customer to deal with another "emergency"customer)
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
6/69
NMaingi, November 2012
Introduction to Discrete Event
Simulation (5)Queue characteristics:n How, from the set of customers waiting for service, do
we choose the one to be served next (e.g. FIFO (first-in
first-out) also known as FCFS (first-come first served);LIFO (last-in first-out); randomly) (this is often calledthe queue discipline)
n Do we have:n Balking (customers deciding not to join the queue if it is too
long)n Reneging (customers leave the queue if they have waited too
long for service)
n Jockeying (customers switch between queues if they think theywill get served faster by so doing)
n A queue of finite capacity or (effectively) of infinite capacity
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
7/69
NMaingi, November 2012
Important Definitionsn A system is defined to be a collection of entities (e.g., people or
machine), which act or interact together toward theaccomplishment of some logical end.
n The state of a system is the collection of variables necessary todescribe a system at a particular time, relative to the objectives of astudy.
n A discrete system is one in which the state variables change onlyat a countable (or finite) number of points in time.
n A continuous system is one in which the state variables changecontinuously with respect to time.
n Discrete-event simulation is the modeling of a system as itevolves over time by a representation in which the state variableschange only at a countable number of points in time.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
8/69
NMaingi, November 2012
COMPONENTS OF A DISCRETE-
EVENT SIMULATIONn System state: the collection of state variables necessary to
describe the system at a particular time.n Simulation clock: a variable giving the current value of simulated
time Note: There is generally no relationship between the simulated
time and the time needed to run a simulation on the computer.n Event list: a list containing the next time when each type of event
will occur.n Also known as the future event list (FEL).
n Statistical counters: variables used for storing statisticalinformation about system performance
n Activity:A duration of time of specified length (e.g., a service timeor inter-arrival time), which is known when it begins (although itmay be defined in terms of a statistical distribution).
n Delay:A duration of time of unspecified indefinite length, which isnot known until it ends (e.g., a customer's delay in a last-in, first-out waiting line which, when it begins, depends on future arrivals).
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
9/69
NMaingi, November 2012
COMPONENTS OF A DISCRETE-
EVENT SIMULATION (2)n Initialization routine : a subprogram (routine) used to initialize the
simulation model at time 0.n Timing routine: a subprogram (subroutine) that determines the next
event from the event list and then advances the simulation clock to thetime when the event is to occur.
n Event routine: A subprogram (subroutine) that updates the system statewhen a particular type of event occurs (one routine per event).
n Library routine: A set of subprograms used to generate randomobservations from probability distributions that were determined as part ofthe simulation model.
n Report generator: A subprogram that computes estimates (from thestatistical counter) of the desired performance measures when simulationends.
n Main program: a subprogram that invokes (calls) the timing routine todetermine the next event and then transfers control to the correspondingevent routine to update the system state.n May also check for termination and invoke the report generator.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
10/69
NMaingi, November 2012
The Simulation Clock and Eventn Because of their dynamic nature, Discrete Event
Dynamic systems (DEDS) require a time keepingmechanism to advance the simulated time from one
event to another, as the simulation unfolds (progresses)in time.n The variable recording the current simulation time is
called the simulation clock.n To keep track of events, the simulation maintains a list of all
pending events.
n The list is called the event list, and its task is to maintainall pending events in chronological order, that is, eventsare inserted into it ordered by their time of occurrence.n In particular, the most imminent event is always located at the
head of the event list.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
11/69
NMaingi, November 2012
The Simulation Clock and Event
(2)n There are basically two approaches for
advancing the simulation clock:
n Next-event time advance (generally, the preferredmethod)
n Fixed-increment (or continuous) time advanceNext-Event Time Advance Mechanism
n Initially the simulation clock is set to zero, andthe initial events(s) are loaded into the event list(chronologically ordered).
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
12/69
NMaingi, November 2012
The Simulation Clock and Event
(3)n Next, the most imminent event is unloaded from the
event list for execution, and the simulation clockadvanced to its occurrence time.n
In the course of executing the current event, the state of thesystem is updated, and future events are typically generatedand loaded into the event list.
n The process of unloading events from the event list,advancing the simulation clock, and executing the mostimminent event terminates when some specified
stopping condition is met, say as soon as prescribednumber of customers depart from the system.n This approach for advancing the simulation time is called the
next-event time advance approach.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
13/69
NMaingi, November 2012
Summary of the simulation steps1. The simulation clock is initialized to zero, and the times
when future events will occur are determined.2. The clock is then advanced to the time of occurrence of
the most imminent (first) future event.3. The system state is updated to account for the eventthat has occurred.
4. Information about future system events may beupdated.
n Repeat steps 2-4, until the predetermined simulationstopping condition has been reached.
n Perform the necessary calculation and generate areport on the simulation data.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
14/69
NMaingi, November 2012
Performance measuresn Changes in these measures of performance can occur
only when one of the following two events occurs:
n Arrival eventn Departure event
Arrival event
n When a customer arrives, he can either start serviceimmediately or join a waiting line.
n Generate the time at which the immediately succeedingarrival will occur by computing an inter-arrival time Aand adding it to the current simulation time.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
15/69
NMaingi, November 2012
Performance measures (2)n Check the status of the facility (idle or busy).
n If idle, do the following Start the arriving customer in service,generate a service time S and compute the customers
departure time. Change the status of facility to busy and updatethe idle time record of the facility
n If busy, put the arriving customer in the queue and incrementits length by one.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
16/69
NMaingi, November 2012
Performance measures
illustration
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
17/69
NMaingi, November 2012
Performance measures (3)
Departure Eventn When a service is completed, a waiting customer can
start service; or if no one is waiting, the facility becomes
idle.n Check the status of the waiting line (empty or not
empty).n If empty, declare the facility idle.n If not empty, do the following;
nStart the first waiting customer in service, reduce the queue size byone, and update the waiting time record.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
18/69
NMaingi, November 2012
Performance measures (4)
n Generate the customers service time q and compute hisdeparture time (= current time +q).n We can gather the necessary information by observing the
various conditions that arise with occurrence of each of the twoevents.
n For example, we can keep track of the length of thequeue as follows.n When an arrival occurs, the queue length is incremented by one
whenever the facility is found busy.n Similarly, the queue length is decremented by one when
a service is completed and the waiting line is not empty.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
19/69
NMaingi, November 2012
Performance measuresillustration (2)
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
20/69
NMaingi, November 2012
An example simulation
n To illustrate discrete-event simulation let us take thevery simple system below, with just a single queue anda single server.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
21/69
NMaingi, November 2012
Simulation Example
n Suppose that customers arrive with inter-arrival timesthat are uniformly distributed between 1 and 3 minutes,i.e. all arrival times between 1 and 3 minutes are equally
likely.n Suppose too that service times are uniformly distributed
between 0.5 and 2 minutes, i.e. any service timebetween 0.5 and 2 minutes is equally likely.
n We shall illustrate how this system can be analyzedusing simulation.
n Conceptually we have two separate, and independent,statistical distributions.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
22/69
NMaingi, November 2012
Simulation Example (2)
n Hence we can think of constructing two long lists ofnumbers - the first list being inter-arrival times sampledfrom the uniform distribution between 1 and 3 minute,the second list being service times sampled from theuniform distribution between 0.5 and 2 minutes.
n By sampled we mean that we (or a computer) look atthe specified distribution and randomly choose a number(inter-arrival time or service time) from this specifieddistribution.
n For example in Excel using 1+(3-1)*RAND() wouldrandomly generate inter-arrival times and0.5+(2-0.5)*RAND() would randomly generate servicetimes.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
23/69
NMaingi, November 2012
Simulation Example (3)
n Suppose our two lists are:Arrival intervals Service time1.9 1.71.3 1.81.1 1.51.0 0.9etc etc
Where to ease the processing we have chosen to
work one decimal place. Suppose now we consider our system at time zero
(T=0), with no customers in the system.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
24/69
NMaingi, November 2012
Simulation Example (4)
n Take the lists above and ask yourself the question: Whatwill happen next?n The answer is that after 1.9 minutes have elapsed a customer
will appear.n The queue is empty and the server is idle so this customer can
proceed directly to being served.
n What will happen next?n The answer is that after a further 1.3 minutes have elapsed
(i.e. at T=1.9+1.3=3.2) the next customer will appear.n
This customer will join the queue (since the server is busy).n What will happen next?
n The answer is that at time T=1.9+1.7=3.6 the customercurrently being served will finish and leave the system.
n At that time we have a customer in the queue and so they canstart their service (which will take 1.8 minutes and hence end
at T=3.6+1.8=5.4).
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
25/69
NMaingi, November 2012
Simulation Example (5)n What will happen next?
n The answer is that 1.1 minutes after the previous customer arrival(i.e. at T=3.2+1.1=4.3) the next customer will appear.
n This customer will join the queue (since the server is busy).n What will happen next?
n The answer is that after a further 1.0 minutes have elapsed (i.e.at T=4.3+1.0=5.3) the next customer will appear.
n This customer will join the queue (since there is already someonein the queue), so now the queue contains two customers waitingfor service.
n What will happen next?n The answer is that at T=5.4 the customer currently being served
will finish and leave the system.n At that time we have two customers in the queue and assuming a
FIFO queue discipline the first customer in the queue can starttheir service (which will take 1.5 minutes and hence end at
T=5.4+1.5=6.9)
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
26/69
NMaingi, November 2012
Simulation Example (6)
n What will happen next?n The answer is that ...... etc and we could continue in this
fashion if we so wished (had the time and energy!). Plainly the
above process is best done by a computer.n To summarize what we have done we can construct the list
below:
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
27/69
NMaingi, November 2012
Simulation Example (7)
Time T What happened1.9 New Customer appears, starts service scheduled to end
at T=3.63.2 Another customer appears, joins queue3.6 Service ends
Customer at head of queue starts service, scheduled toend at T=5.4
4.3 Customer appears, joins queue5.3 Customer appears, joins queue5.4 Service ends (Customer no. 2)
Another customer at head of queue starts service,scheduled to end at T=6.9
etc
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
28/69
NMaingi, November 2012
Simulation Example (8)
n You can hopefully see from the above how we aresimulating (artificially reproducing) the operationof our queuing system.
n Simulation, as illustrated above, is more accuratelycalled discrete-event simulation since we are lookingat discrete events through time (customers appearing,service ending).
n Here we were only concerned with the discrete pointsT=1.9, 3.2, 3.6, 4.3, 5.3, 7.5 etc
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
29/69
NMaingi, November 2012
Simulation Example (9)
Customer IAT Clocktime
ServiceTime
ServiceStarts
Serviceends
No.Insystem
No. inThequeue
WaitingTime
Time insystem
Idle timeof theserver
1 - 0 0 0 01 1.9 1.9 1.7 1.9 3.62 1.3 3.2 1.8 3.6 5.43 1.1 4.3 1.5 5.4 6.9
4 1.0 5.3 0.9 6.9 7.85 2.2 7.5 0.66 2.1 9.6 1.77 1.8 11.4 1.18 2.8 14.2 1.89 2.7 16.9 0.810 2.4 19.3 0.511 1.6 20.9 0.7
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
30/69
NMaingi, November 2012
Simulation Example (10)
n Once we have done a simulation such as shown abovethen we can easily calculate statistics about the system -for example the average time a customer spendsqueuing and being served (the average time in thesystem).n Here two customers have gone through the entire system the
first appeared at time 1.9 and left the system at time 3.6 and sospent 1.7 minutes in the system.
n The second customer appeared at time 3.2 and left thesystem at time 5.4 and so spent 2.2 minutes in thesystem.n Hence the average time in the system is (1.7+2.2)/2 = 1.95
minutes.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
31/69
NMaingi, November 2012
Simulation Example (11)
n We can also calculate statistics on queue lengths - forexample what is the average queue size (length).
n Here the queue is of size 0 from T=0 to T=3.2, of size 1 fromT=3.2 to 3.6, of size 0 from T=3.6 to T=4.3, of size 1 fromT=4.3 to T=5.3, of size 2 from T=5.3 to T=5.4.
n Hence the time-weighted average queue size is:[0(3.2-0)+1(3.6-3.2)+0(4.3-3.6)+1(5.3-4.3)+2(5.4-5.3)]/5.4 =
0.296
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
32/69
NMaingi, November 2012
Example 1
n Assume that the times between arrivals to a bank weregenerated by rolling a die five times and recording theup face.
n These five inter-arrival times are used to compute thearrival times of six customers at the queuing systems.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
33/69
NMaingi, November 2012
Example 1 (2)
Customer Inter-arrival Time Arrival time on clock1 - 02 2 23 4 64 1 75 2 96 6 15
Inter-arrival times
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
34/69
NMaingi, November 2012
Example 1 (3)
n The first customer is assumed to arrive at clock time 0.n This starts the clock in operation.n
The second customer arrives two time units later, at aclock time of (0+2) = 2.
n The third customer arrives four time units later, at aclock time (2+4) = 6 and so on.
nThe second time of interest is the service time.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
35/69
NMaingi, November 2012
Example 1 (4)
n Assume the service times weregenerated at random from adistribution of service times.
Service Times
Customer Service Time1 22 13 34 25 16 4
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
36/69
NMaingi, November 2012
Example 1 (5)
n Now the inter-arrival times and service times must bemeshed to simulate the single-channel queuing system.
Customer Inter-arrivaltime (IAT)
Arrival time
on clockTime service
begins (clock)Service
timeDuration
Time
serviceends(clock)
1 - 0 0 2 22 2 2 2 1 33
4
6
6
3
9
4 1 7 9 2 115 2 9 11 1 126 6 15 15 4 19
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
37/69
NMaingi, November 2012
Example 1 (6)
n The first customer arrives at clock time 0, andimmediately begins service, which requires 2 minutes.Service is completed at clock time 2.
n The second customer arrives at clock time 2 and isfinished at clock time 3.n Note that the fourth customer arrived at clock time 7, but
service could not begin until clock time 9.
n This occurred because customer 3 did not finish serviceuntil clock time 9.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
38/69
NMaingi, November 2012
Example 1 (7)
n Simulation table for single-server queuing problemCustomer IAT Arrival
time Servicebegins(clock)
Servicetime(duration)
Timeinqueue
Timeserviceends(clock)
TimeInsystem
Idletimeofserver
No inqueue
1 - 0 0 2 0 2 2 0 02 2 2 2 1 0 3 1 0 03 4 6 6 3 0 9 3 3 04 1 7 9 2 2 11 4 0 15 2 9 11 1 2 12 3 0 16 6 15 15 4 0 19 4 3 0Total 13 4 17 6 2
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
39/69
NMaingi, November 2012
Example 1 (8)
Queue statistics
1. Average waiting time for a customer:= 0.6667 or 40 seconds
2. Probability customer has to wait in queue6
4=
customersofnumbertotalwaitwhocustomersofNumberPr(Wait) =
6
2= or 0.3333
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
40/69
NMaingi, November 2012
Example 1 (9)
3. Fraction/proportion of idle time of server
4. Probability of the server being busyPr(server busy) = 1 Pr(idle server)
= 1 - 0.3158
= 0.6842 or 68.42%
simulationoftimerunTotal
timeidleTotalserver)Pr(idle =
19
6= or 0.3158
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
41/69
NMaingi, November 2012
Example 1 (10)
5. Average service time
= 2.167 minutes or 130 seconds
6. Average time between arrivals
7. Average waiting time for those who wait
customersofnumberTotal
timeserviceTotal=
6
13=
1minusarrivalofNumber
arrivalsbetweentimesallofSum=
3
15= = 5 minutes
waitwhocustomersTotal
queueinwaitcustomerstimeTotal=
2
4= = 2 Minutes
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
42/69
NMaingi, November 2012
Example 1 (11)
8. Average time spent in systemcustomersofnumberTotal
systeminspendcustomerstimeTotal=
6
17=
= 2.833 min or 170 seconds
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
43/69
NMaingi, November 2012
Exercise 1
n Assume uniform average arrival rate of customers to abank and that the random arrival times are uniformlydistribute on (1, 8) minutes and random service times
are distributed on (1, 6) minutes.
n The inter-arrival and service times for 20 customers aregenerated from these distributions as follows:
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
44/69
NMaingi, November 2012
Exercise 1 (2)
n Time between arrivalsCustomer Time between arrivals (min)1 -2 83 64 15 86 37 88 79 210 3
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
45/69
NMaingi, November 2012
Exercise 1 (3)
11 112 113 514 615 316 817 118 219 420 5
Table continuation
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
46/69
NMaingi, November 2012
Exercise 1 (4)
Service times
Customer Service time (min)1 42 13 44 35 26 47 58 49 510 3
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
47/69
NMaingi, November 2012
Exercise 1 (5)
Service times continuation
11 312 513 414 115 516 417 318 319 220 3
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
48/69
NMaingi, November 2012
Exercise 1 (6)
n Required: Mesh the inter-arrival times and service timesto simulate the single-channel queuing system for the 20customers. Calculate the queue statistics.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
49/69
NMaingi, November 2012
Generalization
n In General we can show how a typical simulation model isexecuted.
Notation:
n ti = is the clock time of arrival of the ith
customer (byconvention, t0 = 0)
n Ai = ti - ti-1 = is the inter-arrival time between the (i-1)st and itharrivals of the customers
n Si is the time server actually spends serving the ith customer(excluding the customers delay in the queue), during thistime, the server is unavailable to serve other customers.
n qi = qi - ti+1 = delay in the queue of ith customern Di = Si + qi = delay in the system of ith customer
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
50/69
NMaingi, November 2012
Generalization (2)
n di = ti + qi + Si = time ith customer completes serviceand departs
n ei = time of occurrence of the event of any type (At timee0 = 0 the status of the server is idle)
n Vt is the virtual time in the system (time to serve allcustomers).
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
51/69
NMaingi, November 2012
Generalization (3)
n Assume that the inter-arrival times,A1,A2,, and theservice times S1, S2,., are random variables,generated from some given cumulative distributionfunctions (cdfs) F1 and F2respectively.
n Assume further that at time t0= e0= 0 the server is idle,so that at time t1 the first customer arrives for service atan empty system.
n The event list is initialized by an arrival event withoccurrence time t1, and t1 is determined by generating arandom variableA1 from F1 hence
n t1=A1. This event is loaded for execution, and thesimulation clock is advanced from e0= 0 to the time ofthe first event e1= t1.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
52/69
NMaingi, November 2012
Generalization (4)n Since the first customer arrives at an idle system, he
starts service immediately and the service timeS1generated from F2.n The customer did not wait in the queue so q1= 0 and his delay in
the system is D1= S1, and the status of the server at time t1changes from idle to busy.
n Clearly a service completion event will be scheduled attime d1= t1 + D1 and the next arrival event will takeplace at time t2= t1 + A2.n If t2< d1, then it means the second customer finds the first
customer still in service, so this customer joins the queue.n The simulation clock is advanced from time e1to the
next arrival event, that is we set e2= t2.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
53/69
NMaingi, November 2012
Generalization (5)
n Note that the number of customers in the system wouldbe then incremented from 1 to 2 and the number in thequeue incremented from 0 to 1.
n Since the customer arriving at time t2finds the server busy, werecord t2 and compute t3= t2+A3, the time of the third arrival.n Ift3> d1, we advance the simulation clock from e2 to the
next event, e3= d1.
n Executing this event means that the first customercompletes his service and departs from the system,while the second customer begins service at the sametime.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
54/69
NMaingi, November 2012
Generalization (6)
n At this time we generate S2 from F2, then D2= q1+ S2and decrement the number of customers in the systemfrom 2 to 1 and number in the queue from 1 to 0, and
so forth.n The simulation is terminated when the stopping criteria
is reached.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
55/69
NMaingi, November 2012
Generalization (7)
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
56/69
NMaingi, November 2012
Generalization (8)
n Suppose that we wish to simulate a queuing model inwhich arrivals are Poisson with mean 3 customers perminute and the service rate is 5 customers per minutes.
nCustomers are admitted to the service on a first come,first served (FIFO) basis, and there is no limit on thelength of the waiting time or the source from whichcustomers arrive.n We assume that there are no customers in the facility when the
simulation starts.
n For the Poisson arrivals with mean rate = 3customers per minute, the inter-arrival time isexponential and can be generated from the formula
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
57/69
NMaingi, November 2012
Generalization (9)
n The service time is also exponential and generated
Since the system starts empty, the facility status isidle. The first arrival generated occurs after
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
58/69
NMaingi, November 2012
Generalization (10)
n (The successive random numbers we use in thisexample are taken from Table 1 of Random numbers;inter-arrivals-first column and service times-third
column)n Thus the simulation jumps from t0 = 0 to t1 = 0.54.
n At t1 = 0.54 an arrival event is encountered, hence e1= t1=0.54.
n Following the actions summarized above, we computethe time of the next arrival as t2= t1 +A2
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
59/69
NMaingi, November 2012
Generalization (11)
n Now, since the facility is idle, the present customerstarts service and his service time given by
n Thus his departure time is computed as d1 = 0.54 +0.43 = 0.97
n The facility is now declared busy and its idle time isupdated to Idle time = 0 + 0.54 = 0.54 minutes.
n The events thus far generated appear on the time scaleas shown in the figure below;
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
60/69
NMaingi, November 2012
Generalization (12)
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
61/69
NMaingi, November 2012
Generalization (13)
n The next chronological event is an arrival at t = 0.85.Hence e2 = t2= 0.85.
n Since the facility is still busy, the customer is put in thewaiting line and the queue size is updated to q2 = 0 + 1= 1 (at t = 0.85)
n We now generate the next arrival, which occurs at
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
62/69
NMaingi, November 2012
Generalization (14)
n The next event is an arrival occurring at t = 1.00.n The immediately succeeding event occurring at t = 0.97 is a
departure hence e3= d1= 0.97.
n Since the queue is not empty, we remove the firstwaiting customer and start him in service.n Thus the queue size becomes q3 = 1-1 =0n And the cumulative waiting time is W = 0 + (0.97
0.54) = 0.43
n The service time for the second customer is generatedas
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
63/69
NMaingi, November 2012
Generalization (15)
n Thus his departure time is computed as d2 = 0.85 +0.25 = 1.10
n By now you should have developed an appreciation ofhow data are gathered during the course of executingthe simulation model.
n The procedure is repeated successively until a desiredtime period T is simulated.
n We can then compute different measures of performance.
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
64/69
NMaingi, November 2012
Simulation Algorithm
MAIN PROGRAMWhile time < simulation time{
Determine next event;Advance simulation time;Update statistics + system state;Generate future events and add them to event list;}
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
65/69
NMaingi, November 2012
Simulation Algorithm (2)
If the event is an arrival:
n Advance the simulation clockTime = arrival timen Update statistics number in queue and server statusn If server idle, then start new service:n Update statistics time in queuen Schedule new departuren Else add customer to queuen Update the statistics number in queuen Schedule new arrival
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
66/69
NMaingi, November 2012
Simulation Algorithm (3)
If the event is a departure
n Advance the simulation clockTime = departure timen Update statistics number in queue and server statusn If queue is not empty, then start new service:n Update statistics number in queuen Schedule new departuren Else Update the statistics- server status
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
67/69
NMaingi, November 2012
Simulation Algorithm (4)
INITIALIZATIONMAIN PROGRAMwhile time < runlength
{Determine next event;Advance simulation time;Update statistics + system state;Generate future events and add them to event list;}While time < runlength{
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
68/69
NMaingi, November 2012
Simulation Algorithm (5)
Case nextevent of arrival:Time = arrivaltime;Update statistics B and Q;
If server idlethen{Start new service;Update statistics D;Schedule new departure;}Else add customer to queue;Schedule new arrival;
-
7/30/2019 BIF3203 - Part III Discrete Event Simulation (November 2012)
69/69
Simulation Algorithm (6)
Departure:Time = departuretime;}
}Update statistics B and Q;If queue is not emptyThen {Start new service;Update statistics D;Schedule new departure;}}