Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 54

Engineering Analysis & Design

(Modelling & Simulation)


Course Code: CO207

Unit -2:Discrete Event Simulation

1
Contents of Module 2
 Time Advance Mechanism
 Components and Organization of a Discrete Event
Simulation Model
 Selected Illustrative Examples of Simulation Application
Models

2
System , Models, Simulation

Types of Systems

Discrete
State variables change instantaneously at separated points in time.
For eg. Bank model: State changes occur only when a customer arrives
or departs.

Continuous
State variables change continuously as a function of time.
For eg. Airplane flight: State variables like position, velocity change
continuously. Many systems are partly discrete, partly continuous. 3
Simulation Model

 Classification of Simulation Model


 Static vs Dynamic
 Deterministic vs Stochastic
 Continuous vs Discrete

 Most operational models are dynamic, stochastic and


discrete- will be called discrete-event simulation models.

4
Deterministic and Stochastic
● Deterministic Model is one whose behavior is entire
predictable. The system is perfectly understood, then it
is possible to predict precisely what will happen.

● Stochastic Model is one whose behavior cannot be


entirely predicted.

5
Discrete or Continuous Models
● Discrete Model: In this the state variables change only at a
countable number of points in time. These points in time are
the ones at which the event occurs/change in state.

● Continuous Model: In this the state variables change in a


continuous way, and not abruptly from one state to another
(infinite number of states).

6
Simulation Model
7
Time Advances Mechanism
Time advances mechanism is a science of dynamic
system which depicts the time dependence of a point
and it can be studied by two categories:

 Discrete Event Simulation (DES) model (next


event time advance).

 Discrete Time Simulation (DTS) model (Fixed-


increment time advance).

8
Discrete Event Simulation (DES):

Discrete Event Simulation (DES):

Discrete-Event Simulation concerns the modeling of a system as it


evolves over time by a representation in which the state variables
change instantaneously at separate points in time.

Event is defined as an instantaneous occurrence that may change the


state of the system. Although discrete-event simulation could
conceptually be done by hand calculations, the amount of data that
must be stored and manipulated for most real-world systems dictates
that discrete-event simulations be done on a digital computer.
9
Cont..

• In the real world, many systems operate inherently in discrete


time. For example, a digital computer is a typical discrete
time system.
• A digital computer has an internal discrete time clock and
instructions are executed when the clock ‘ticks’. For
example, a CPU clocked at 1 GHz, which represents one
billion cycles per second, theoretically executes one billion
instructions in one second.

10
DES Example 1
• Consider a service facility with a single server
Consider a service facility with a single server---e.g. an information
desk at an airport-for which we would like to estimate the (expected)
average delay in queue (line) of arriving customers, where the delay in
queue of a customer is the length of the time interval from the instant
of his arrival at the facility to the instant he begins being served.
• The status of the server, i.e., either idle or busy, the number of
customers waiting in queue to be served (if any), and the time of
arrival of each person waiting in queue.
• The status of the server is needed to determine, upon a customer's
arrival, whether the customer can be served immediately or must join
the end of the queue.
11
Cont..
• When the server completes serving a customer, the number of customers in the
queue is used to determine whether the server will become idle or begin
serving the first customer in the queue.
• The time of arrival of a customer is needed to compute his delay in queue,
which is the time he begins being served (which will be known) minus his time
of arrival.
• There are two types of events for this system: the arrival of a customer and the
completion of service for a customer, which results in the customer's departure.
• An arrival is an event since it causes the (state variable) server status to change
from idle to busy or the (state variable) number of customers in the queue to
increase by 1. Correspondingly, a departure is an event because it causes the
server status to change from busy to idle or the number of customers in the
queue to decrease by 1.
12
Cont..

Example 2
We assume a sheep farm that currently operates with 100 sheep. The
sheep population growth rate is 5% per year. The objective of the study
is to understand how the sheep population of the farm changes over time.
Given that only the yearly growth rate of the sheep population is known,
what we can study in this case is the change of stock population in each
year, which is actually a discrete time process. First, some variables can
be defined based on the above problem statement:
• A variable representing time t, t ∈ {0, 1, 2, ...}.
• A system state variable (xt), which is the sheep population size in
year t.
13
Cont..

14
Cont..
 For year 0, the initial sheep population size is 100, which can be denoted by x 0 = 100.
 xt is the population size of year t, then the population size of the next year is x t+1
 The yearly population growth rate (r), which equals 5%.

The relationship between the population size in the current year and the next year can be easily constructed using
the growth rate, r, as below:
xt+1 = xt + r × xt
This equation describes how the system state x changes occur at discrete time steps. Considering the initial
population (x0= 100) and the growth rate (r = 5%) and we can obtain the yearly sheep population size, as
illustrated in Table 8.1.
We can clearly see in this example how variables – the sheep population (x t), the input (yearly growth rate r) and
the output (yearly increment of sheep population (xt × r) – are defined only for discrete time points, t. Therefore,
the sheep population of the farm in this example can be viewed as a discrete time system. Based on this example,
the definition of a discrete time system can be given as follows:
A discrete time system is a system for which the state, input, and output variables are defined only for discrete
moments in time.
15
Discrete Time System and Modelling
By the definition, the time domain of a discrete time system is discrete. This means
that the spacing between successive time points may be arbitrary or uniform. In the
sheep farm example, the time space, t, was divided uniformly into years: t ∈ {0, 1,
2, ...}. However, time can also be partitioned using arbitrary intervals, as in the case of
discrete event systems, where the system clock ticks at the time point when a particular
event happens. Hence, from this point of view, a discrete event system is a special case
of a discrete time system.

To model and simulate a discrete time system, a particular type of simulation – called
discrete time simulation (DTS) – is typically employed. The resultant DTS will use a
time-advancing mechanism that can be either a fixed-increment time-advancing
mechanism (uniform spacing) or a next-event time-advancing mechanism
(arbitrary) due to the discrete nature of the real-world system to be simulated.

16
Cont..
At each simulation clock tick, the state of a discrete time system may be changed by its input and may produce
some output, with a subsequent effect. The system state, input, and output are measurable variables of the
system; thus, we can collect the data by taking measurements at specific time points over a period, such as the
share prices in a stock market each day, the sheep population of a farm at the beginning of a year and the
voltage and currents of an electric circuit.
Let us consider that the input variable, u, is a function of time:
u(tk)= {u1(tk), u2(tk), ..., up(tk)}, k ∈ {0, 1, 2, ..., n}.
The initial state can be represented as in the following equation:
x(t0) = x0.
We note that the initial state does not depend on the input variable, while all other states do. The state of the
system at time (tk+1) is a time function of the input variables and the system state at the previous time point (tk):
x(tk+1) = f(x(tk), u(tk), tk) , k ∈ {0, 1, 2, ..., n}
where f(⋅) is a time function that can change the system state based on the system state and input at the time
instant (tk). Similarly, the system output variable y can be defined as a time function as well:
y (tk)= { y1(tk), y2(tk), ..., yq(tk) }
17
Cont..
The output at arbitrary time points y(tk), is determined by the input
and system state variables and can be expressed as:
y(tk) = g (x(tk), u(tk), tk), k ∈ {0, 1, 2, ..., n}

18
Fig. Discrete time system – input, output, state.
Cont..
where g(⋅) is the function that produces the output from a system, using the system state and
input to the system at time point tk.

Through the above examples, we introduced the basic methods to construct a DTS for a
discrete time system, considering the very simple objectives assumed in these examples.
However, DTS may be employed for a variety of purposes; hence, various objectives need to
be taken into account. Sometimes, we are interested in the behaviors of a discrete time
system. On some other occasions, we would like to evaluate the effects on the environment
of a discrete time system over a period, or solve some problems. To achieve these objectives,
it is important to collect data about input, system state and output variables, and then conduct
relevant analysis of these data.

19
Discrete Time Simulation and Discrete Event
Simulation
• DES is a special case of DTS, as mentioned earlier in this chapter.
The dynamics of DES are driven by a set of discrete events that
occur at specific time instants. Therefore, DES can be seen as a
special case of DTS, in which the intervals between time points
are defined by the event occurrence times.
• In the following, we use another example – the simulation of a
vending machine – to describe the differences between a DES
approach and a DTS approach.

20
Cont..

For eg. A vending machine is used for selling various soft drinks to
customers. To keep this example intuitive, we include the following
simplifying assumptions: all drinks are priced at one dollar, the vending
machine accepts only one-dollar coins, and the machine provides a soft
drink once a customer inserts a coin and makes selection.
DES approach is perfectly fine for this vending machine because its states
are driven by a set of discrete events {COIN INSERTED, SELECTION
MADE, DRINK TAKEN}. Further, a FSM can be used for modelling the
operation of this DES.

21
Cont..

• There are three system states of the vending machine: ‘waiting coins’,
‘waiting selection’, and ‘vending drink’. The events of ‘coin inserted’,
‘selection made’, and ‘drink taken’ trigger the vending machine state to
change from one to another.
• For example, the state of the machine changes from ‘waiting coin’ to
‘waiting selection’ when the event ‘coin inserted’ occurs, and changes to
‘vending drink’ once a selection is made by the customer. The machine
then moves again to ‘waiting coin’ state after the chosen drink is taken by
the customer.

22
Cont..

A DES approach for the vending machine by FSM.


23
Cont..
• In the given FSM model, the time points when the machine changes its
state depend on the times when events are happening. Hence, the time
points of the state changes are not uniformly distributed in the time
domain.
• Let us assume that there is an internal digital clock ticking every
second in the machine. At each clock tick, the machine checks whether
any event has occurred. If there is no event occurring, the vending
machine maintains the current state. Otherwise, it changes to a specific
state triggered by the respective event. In such a case, the vending
machine is driven by time, so we can try to re-model it using DTS.

24
Cont..
• To apply a DTS approach, we could use a flowchart to model the system
behavior with consideration of an internal clock ticking. Unlike the FSM
(DES) approach, the time concept is explicitly introduced in the DTS
approach.
• A ‘null’ event is also introduced to represent the situation in which there is
no event happening when the clock ticks. The clock in the vending
machine keeps ticking. If any event except the ‘null’ event occurs before
each clock tick, the vending machine’s state changes.

25
Flowchart Representation of a DTS Approach for the
Vending Machine

A DTS approach for the vending machine represented by flowchart 26


Cont..

• In DES, system state transitions are caused by


asynchronous events and the system state is expected to
change at every occurrence of an event.
• In contrast, in DTS, system state transitions are
synchronous, guided by the system clock. At each clock
tick, an event is selected and, if it is not a ‘null’ event, the
system state changes. We say that the time information is
explicit in DTS, yet implicit in DES.

27
Cont..
• In the vending machine example, DES has certain advantages
over DTS. This is mainly due to the nature of the vending
machine system, which is driven by events.
• DTS has advantages over DES in some cases where the system
time space is discrete and the time intervals between state
changes are uniform.
• The sheep farm example presented earlier in this chapter is a
good case in which DTS should be us

28
Cont..

• DES is used for systems where the state of a system changes in discrete
points in time.
• A system can change in only countable number of points in time.
• Makes use of a Time-Advance Algorithm.

Time-Advance Algorithm (Event Scheduling):


• This method requires an event list.
• The Simulation Clock Time will progress only up to the time when the
event is expected to occur.

29
Differences

Overview of DTS (a) and DES (b)


30
31
Components and Organization of a Discrete Event
Simulation Model
System State: The collection of state variables necessary to describe
the system at a particular time.
Simulation Clock: A variable giving the current value of simulated
time.
Event List: A list containing all information about all scheduled
events like time when each type of event will occur.
Initialization Routine: A subprogram to initialize the simulation
model at time zero.
Statistical Counters: Variables used for storing statistical
information about system performance.
32
Examples of Statistical Counters
• The number of parts produced so far
• The total of the waiting times in queue so far
• The number of parts that have passed through the queue so far
• The longest time spent in queue we’ve seen so far
• The total of the time spent in the system by all parts that have
departed so far
• The longest time in system we’ve seen so far
• The area so far under the queue-length curve Q(t)The highest level
that Q(t) has so far attained
• The area so far under the server-busy function B(t)
33
Cont..
• Timing Routine: A subprogram that determines the next event from
the event list and then advances the simulation clock to the time when
that event is to occur.
• Event Routine: A subprogram that updates the system state when a
particular type of event occurs (there is one event routine for each
event type).
• Library Routine: A set of subprograms used to generate random
observations from probability distributions that were determined as
part of the simulation model.

34
Cont..

• Report Generator: A subprogram that computes estimates (from the


statistical counters) of the desired measures of performance produces a
report when the simulation ends.

• Main Program: A subprogram that invokes the timing routine to


determine the next event transfers control to the corresponding event
routine to update the system state appropriately. check for termination
and invoke the report generator when the simulation is over.

35
Simulation of a Single-Server Queueing System

 What is Queuing Theory


• Mathematical analysis of queues and waiting times in stochastic systems.
• Used extensively to analyze production and service processes exhibiting random
variability in market demand (arrival times) and service times.

• Queues arise when the short term demand for service exceeds the capacity
• Most often caused by random variation in service times and the times between
customer arrivals.
• If long term demand for service > capacity the queue will explode!

36
Why is Queuing Analysis Important?

• Capacity problems are very common in industry and one of the main drivers of process
redesign
• Need to balance the cost of increased capacity against the gains of increased productivity and
service
• Queuing and waiting time analysis is particularly important in service systems
• Large costs of waiting and of lost sales due to waiting

Prototype Example – ER at County Hospital


• Patients arrive by ambulance or by their own accord
• One doctor is always on duty
• More and more patients seeks help  longer waiting times
Question: Should another MD position be instated?

37
Examples of Real World Queuing Systems
• Commercial Queuing Systems
• Commercial organizations serving external customers
• Ex. Dentist, bank, ATM, gas stations, plumber, garage …
• Transportation service systems
• Vehicles are customers or servers
• Ex. Vehicles waiting at toll stations and traffic lights, trucks or ships waiting to be loaded, taxi cabs,
fire engines, elevators, buses …
• Business-internal service systems
• Customers receiving service are internal to the organization providing the service
• Ex. Inspection stations, conveyor belts, computer support …
• Social service systems
• Ex. Judicial process, the ER at a hospital, waiting lists for organ transplants or student dorm rooms

38
Components of a Basic Queuing Process

39
Components of a Basic Queuing Process

The Calling Population


• The population from which customers/jobs originate
• The size can be finite or infinite (the latter is most
common)
• Can be homogeneous (only one type of customers/ jobs)
or heterogeneous (several different kinds of
customers/jobs)
The Arrival Process
• Determines how, when and where customer/jobs arrive
to the system
• Important characteristic is the customers’/jobs’ inter-
arrival times
• To correctly specify the arrival process requires data
collection of interarrival times and statistical analysis.
40
Cont..
The Queue Configuration
• Specifies the number of queues
• Single or multiple lines to a number of service stations
• Their location
• Their effect on customer behavior
• Balking and reneging
• Their maximum size (# of jobs the queue can hold)
• Distinction between infinite and finite capacity

41
Single channel queuing systems Problems

Problem 1: A small grocery store has only one checkout counter. Customers arrive at this checkout counter at random from
1 to 8 minutes apart. Each possible value of inter-arrival time has the same probability of occurrence. The service times
vary from 1 to 6 minutes with the probabilities shown in table 5. The problem is to analyze the system by simulating
the arrival and service of 6 customers.

Service time Probability


(min)

1 0.10
2 0.20
3 0.30
4 0.25
5 0.10
6 0.05

42
Calculate
1) The average waiting time for a customer
2) The probability that a customer has to wait in the queue
3) The fraction of the idle time of the server
4) The average service time
5) The average time between arrivals
6) The average waiting time of those who wait
7) The average time a customer spends in the system

Use the following sequence of random number. Assume that the first customer arrives at
time 0.
Random 913 727 15 948 309 922
digits for
arrival
Random 84 10 74 53 17 79
digits for
service time

43
Solution:
Step 1: Calculate the arrival and service time table and get the random
number Assignment
Time between Probability Cumulative probability Random digit
arrival (In Assignment
minutes)
1 0.125 0.125 0-125
2 0.125 0.250 126-250
3 0.125 0.375 251-375
4 0.125 0.500 376-500
5 0.125 0.625 501-625
6 0.125 0.750 626-750
7 0.125 0.825 751-815
8 0.125 1.000 816- 1000

Table 1Distribution of the arrival time

Probability of each arrival time = 1/8

44
Note: Cumulative probability = Current probability + addition of the value above it

Service Time Probability Cumulative Probability Random digit Assignment

1 0.1 0.1 1-10


2 0.2 0.3 11-30
3 0.3 0.6 31-60
4 0.25 0.85 61-85

5 0.1 0.95 86-95


6 0.05 1.00 96-100

Table 2 Distribution of service time

45
Step 2: Detemining time between arrival

Customer Random Digit Time between


Arrival
Customer Random Digit Service Time
1 ----- -----
1 84 4
2 913 8
2 10 1
3 727 6
3 74 4
4 15 1
4 53 3
5 948 8 5 17 2
6 309 3 6 79 4

46
Customer Inter A.T A.T S.T Time Waiting Time Total time Idle time of
Service Time Service Ends spent in the server
Begin system

1 ----- 0 4 0 0 4 4 0
2 8 8 1 8 0 9 1 4
3 6 14 4 14 0 18 4 5
4 1 15 3 18 3 21 6 0
5 8 23 2 23 0 25 2 2
6 3 26 4 26 0 30 4 1
Total 18 3 21 12

Table 3 Simulation Table

47
• Average waiting time = total time customer waits in queue
total no of customers
= 3/6
= 0.5 minutes

• Probability customer has to wait in a queue = total no of customers waited in queue


Total # of customers
= 1/6
= 0.166
= 16.66%
• Probability of idle time= total idle time of the server
Total runtime of the entire simulation
= 12/30
= 0.4
=40%

48
• Average Service Time = Total service time
# of customers
= 18/6
= 3 minutes

• Average time between arrivals = Sum of all time between the arrival
# of arrival - 1
= 26/5
= 5.2 minutes

• Average waiting time of those who wait = total time customers waited in queue
Total # customer who actually wait
= 3/1
=3

49
• Average time customer spends in the system = # time customer spends in the system
# of customers
= 21/6
= 3.5 minutes

50
Problem 2: For the following data find the queue statistics (time in minutes): IAT denotes the inter-arrival time
and ST denotes the service time. Assume the first customer arrives at Time t=0.

IAT --- 8 6 1 8 3 8 7 2 3

ST 4 1 4 3 2 4 5 4 5 3

51
Solution:

Customer IAT Arrival Service Time Time Time Time System


Time time Service service customer customer idle time
Begin ends waits in spends in
queue system

1 --- 0 4 0 0 4 4 0
2 8 8 1 8 0 9 1 4
3 6 14 4 14 0 18 4 5
4 1 15 3 18 3 21 6 0
5 8 23 2 23 0 25 2 2
6 3 26 4 26 0 30 4 1
7 8 34 5 34 0 39 5 4
8 7 41 4 41 0 45 4 2
9 2 43 5 45 2 50 7 0
10 3 46 3 50 4 53 7 0
Total 46 35 9 44 18

Simulation table 52
• Average waiting time for customer = 9/10 = 0.9
• Probability cutomer has to wait = 3/10 = 0.3
• Probability of idle server = 18/53 = 0.34
• Average service time = 35/10 = 3.5
• Average time between arrival = 46/9 = 5.11
• Waiting time for customer = 9/3 = 3
• Time spend on system = 44/10 = 4.4
• Max queue length = 1

53
Thank You

54

You might also like