You are on page 1of 71

1

Ch. 1 Basic Simulation


Modeling
2
Notas

http://delta.cs.cinvestav.mx/~lixo/teaching

3
Basic Simulation Modeling
The nature of simulation
Systems, Models and Simulation
Discrete-Event Simulation
Simulation of a single-server queuing
system
Steps in a sound simulation study
Advantages, disadvantages and pitfalls of
simulation
4
The Nature of Simulation
Conceptions
Application areas
Academic level
Impediments
5
Conceptions
Simulation course is about techniques for using computers to
imitate or simulate the operations of various kinds of real
world facilities or processes
System: the facility or process of interest
Model: a set of assumptions about how the system works,
which usually take the form of mathematical or logical
relationships, constitute a model that is used to try to gain
more understanding of how the corresponding system
behaves.
Analytic soulution: to obtain exact information on questions of
intresets.
Simulation: use a computer to evaluate a model numerically,
and data are gathered in order to estimate the desired true
characteristics of the model.

6
Example
a manufacturing company contemplates
building a large extension onto one of its
plants, but is not sure if the potential gain
in productivity would justify the
construction cost.

7
Application areas
Designing and analyzing manufacturing systems
evaluating military weapons systems or their logistics
requirements
determining hardware requirements or protocols for
communication networks
- Determining hardware and software requirements for a
computer system
- Designing and operating transportation systems such as
airports, freeways, ports and subways
- Evaluating designs for service organizations such as call
centers, fast-food restaurants, hospitals, and post offices
- Reengineering of business processes
- Determining ordering polices for an inventory system
- Analyzing financial or economic systems


8
Academic level
Winter Simulation Conference (600-700 people
every year)
Is one of the three important operations-
research techniques (in serveys related to the
use of operations research techniques: math
programming, statistics, simulation)
The second only to math programming among
13 techniques considered (in 1294 papers from
the journal Interfaces from 1970 through 1992)

9
Impediments
Models used to study large-scale systems tend
to be very complex, and writing computer
programs to execute them can be an arduous
task indeed. (excellent software products)
Large amount of computer time is sometimes
required. (cheaper and faster computer)
An unfortunate impression that simulation is just
an exercise in computer programming, albeit a
complicated one. (attitude, simulation
methodology)
10
Systems, Models and Simulation
System is defined to be a collection of entities, e.g.,
people or machines, which act and interact together
toward the accomplishment of some logical end.
System depends on the objectives of a particular
study.
State of a system: collection of variables necessary
to describe a system at a particular time, relative to
the objectives of a study. (the number of busy tellers,
the number of customers in the bank, the time of
arrival of each customer in the bank)
discrete system: the state variables change instantaneously at
separated points in time. (a bank, e.g., the number of customers in the
bank)
continuous system: the state variables change continuously with
respect to time. (an airplane moving through the air, e.g., position and
velocity )


11
Continue...
Study on a system: try to gain some insight
into the relationships among various
components, or to predict performance under
some new conditions being considered.
Ways to study a system
12
System
Experiment
with the
actual system
Physical
model
Analytical
solution
Simulation
Experiment
with a model
of the system
Mathematical
model
13
Example
- One study on a bank to determine the
number of tellers needed to provide
adequate service for customers who want
just to cash a check or make a savings
deposite, the system can be defined to be
that portion of the bank consisting of the
tellers and the customers waiting in line or
being served.
- If the loan officer and the safety deposite
boxes are to be included, the definition of
the system must be expanded in an
obvious way.

14
Discrete Event Simulation
Definition
Time-Advance Mechanisms
Components and Organization of a
Discrete -Event Simulation Model
Components
Logic Organization
15
Definitions
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. Or the system
can change at only a countable number of
points in time.
Event is defined as an instantaneous
occurrence that may change the state of
the system.

16
Example 1.1
Single-server queuing system: a
barbershop, to estimate the (expected)
average delay in queue (line) of arriving
customers
State variables: the status of the server (busy or
idle), the number of customers waiting in queue
to be served, the time of arrival of each person
waiting in queue.
Events: the arrival of a customer and the
completion of service for a customer, which
results in the customers departure.

17
Time-Advance Mechanism
Simulation clock: the variable in a simulation model
that gives the current value of simulated time.
to keep track of the current value of simulated time as the
simulation proceeds
to advance simulated time from one value to another
Advancing the simulation clock
next-event time advance (mostly used)
fixed-increment time advance (a special case of the first)
Next-event time-advance approach
simulation clock is initialized to zero
the times of occurrence of future events are determined.


18
Example 1.2
Notations:
: time of arrival of the ith customer ()
: interarrival time between (i-1)st and ith arrivals
of customers
: time that server actually spends serving ith
customer (exclusive of customers delay in
queue)
: delay in queue of ith customer
: time that ith customer completes service and
departs
: time of occurrence of ith event of any type (ith
value the simulation clock takes on, excluding
the value )
19
e0
e1
e2 e3 e4 e5
0
t1 t2 c1 t3 c2
A1 A2 A3
S1 S2
Time
20
Components and Organization of a
Discrete -Event Simulation Model
Components (10)
Systems 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 the next time when
each type of event will occur
Statistical counters: Variables used for storing
statistical information about system performance
21
Continue...
Initialization routine: A subprogram to initialize the
simulation model at time 0
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 routines: A set of subprograms used to
generate random observations from probability
distributions that were determined as part of the
simulation model

22
Continue...
Report generator: A subprogram that computes
estimates (from the statistical counters) of the
desired measures of performance and produces a
report when the simulation ends
Main program: A subprogram that invokes the
timing routine to determine the next event and then
transfers control to the corresponding event routine
to update the system state appropriately. The main
program may also check for termination and invoke
the report generator when the simulation is over.


23
Start
1. Set simulation
clock=0
2. Initialize system state
and statistical counters
3. Initialize event list
0. Invoke the initialization routine


1. Invoke the timing routine
2. Invoke event routine
1. Determine the next
event type, say, i
2. Advance the
simulation clock
1.Update system state
2.Update statistical counters
3.Generate future events and add to
event list
Repeatedly
Initialization routine Main program Time routine
Event routine i
Generate random
variates
Library routines
Is
simulation
over?
1. Compute estimates of interest
2. Write report
Stop
Report generator
1 0
2
i
No
Yes
24
Simulation of A Single-Server
Queueing System
25
Components of a queueing system
1. Arrival process:
Interarrivals: Ai
Mean interarrival time: E(A)
Arrival rate:
2. Service mechanism
Service time: Si
Number of servers: s
Mean service time: E(S)
Service rate:
3. Queue discipline
FIFO
LIFO
Priority

* D. Gross, and C.M. Harris, Fundamentals of Queueing Theory, 3d ed., John Wiley, New York,
1998

) ( / 1 A E =
) ( / 1 S E = e
26
Notation for queueing systems
1. s servers in parallel and one FIFO queue feeding all servers
2. A1, A2, are IID random variables
3. S1, S2,are IID random variables
4. The Ais and Sis are independent

1 2 s
. . .
FIGURE 1.71
A GI/G/s queue
27
GI/G/s queue
GI (general independent): the distribution of the Ais
G (general): the distribution of the Sis
Symbols: M (exponential), Ek (k-Erlang), D
(deterministic times)
M/M/1: a single-server queueing system with
exponential interarrival and service times and a FIFO
discipline
: the utilization factor of the queueing
system
) /( e s =
28
A departure customer
Server
Customer in service
Customers in queue
An arrival customer
FIGURE 1.4
A single-server queueing system.
29
Measures of Performance for Queueing Systems
i
D
1 w.p. lim
1
n
D
d
n
i
i
n

=

=
w L d Q = = and
: delay in queue of ith customer
i i i
S D W + = : waiting time in system of ith customer
) (t Q : number of customers in queue at time t
) (t L : number of customers in system at time t [Q(t) plus number of customers being served at time t]
1 w.p. lim
1
n
W
w
n
i
i
n

=

=
: steady-state average delay
: steady-state average waiting time
1 w.p.
) (
lim
0
T
dt t Q
Q
T
T
}

=
1 w.p.
) (
lim
0
T
dt t L
L
T
T
}

=

: steady-state time-average number in queue
: steady-state time-average number in system
) (S E d w + =
30
e1, e2, , e13 : 13 successive events

n=6 : delays in queue
Interarrival times:

A1=0.4, A2=1.2, A3=0.5, A4=1.7, A5=0.2,

A6=1.6, A7=0.2, A8=1.4, A9=1.9,
Service times:

S1=2.0, S2=0.7, S3=0.2, S4=1.1, S5=3.7, S6=0.6,
31
Measures of Performance for the example
i
D
) (
1
n
D
n d
n
i
i
=
=
: delay in queue of ith customer
: the expected proportion of the time that Q(t) is equal to i
) (t Q : number of customers in queue at time t

) (
Q(t)

) (
) (
T(n)
0 0
n T
dt
n T
iT
n q
i
i
}

= =

=
=
0
) (
i
i
ip n q

=
=
0
) (
i
i
p i n q
i
p
The expected average delay in queue
The expected average number of customers in queue
32
t
Q(t)
0
1 2 3 4 5 6 7 8 9
e1=0.4 e2=1.6
e3=2.1
e4=2.4 e5=3.1
e6=3.3
e7=3.8
e8=4.0
e9=4.9
e10=5.6
e11=5.8
e12=7.2
e13=8.6=T(6)
FIGURE 1.5
Q(t), arrival times, and departure times for a realization of a single-server queueing system.
Arrivals
Departures
1
2
3
33
Measures of Performance for the example

=
t
t
t B
at time idle is server the if 0
at time busy is server the if 1
) (
) (
) (
) (
) (
0
n T
dt t B
n u
n T
}
=
The expected utilization of the server
34
t
B(t)
0
1 2 3 4 5 6 7 8 9
e1=0.4 e2=1.6
e3=2.1
e4=2.4 e5=3.1
e6=3.3
e7=3.8
e8=4.0
e9=4.9
e10=5.6
e11=5.8
e12=7.2
e13=8.6=T(6)
FIGURE 1.6
B(t), arrival times, and departure times for a realization of a single-server queueing system.
Arrivals
Departures
1
35
Intuitive Explanation
36
0 0 0
0
0 0 0 0
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Initialization
time = 0
System
(a)
Number
in
queue
Times
of
arrival
Time
of last
event
0.4

A
D
Number
delayed
37
1 0 0.4
0.4
1 0 0 0
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Arrival
time = 0.4
System
(b)
Number
in
queue
Times
of
arrival
Time
of last
event
1.6 A
D
0.4
2.4
Number
delayed
38
1 1 1.6
1.6
1 0 0 1.2
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Arrival
time = 1.6
System
(c)
Number
in
queue
Times
of
arrival
Time
of last
event
2.1 A
D
0.4
2.4
1.6
1.6
Number
delayed
39
1 2 2.1
2.1
1 0 0.5 1.7
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Arrival
time = 2.1
System
(d)
Number
in
queue
Times
of
arrival
Time
of last
event
3.8 A
D
0.4
2.4
1.6
1.6
2.1
2.1
Number
delayed
40
1 1 2.4
2.4
2 0.8 1.1 2.0
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Departure
time = 2.4
System
(e)
Number
in
queue
Times
of
arrival
Time
of last
event
3.8 A
D
1.6
3.1
2.1
2.1
Number
delayed
41
1 0 3.1
3.1
3 1.8 1.8 2.7
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Departure
time = 3.1
System
(f)
Number
in
queue
Times
of
arrival
Time
of last
event
3.8 A
D
2.1
3.3
Number
delayed
42
0 0 3.3
3.3
3 1.8 1.8 2.9
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Departure
time = 3.3
System
(g)
Number
in
queue
Times
of
arrival
Time
of last
event
3.8 A
D

Number
delayed
43
1 0 3.8
3.8
4 1.8 1.8 2.9
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Arrival
time = 3.8
System
(h)
Number
in
queue
Times
of
arrival
Time
of last
event
4.0 A
D
3.8
4.9
Number
delayed
44
1 1 4.0
4.0
4 1.8 1.8 3.1
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Departure
time = 4.0
System
(i)
Number
in
queue
Times
of
arrival
Time
of last
event
5.6 A
D
3.8
4.9
4.0
4.0
Number
delayed
45
1 0 4.9
4.9
5 2.7 2.7 4.0
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Departure
time = 4.9
System
(j)
Number
in
queue
Times
of
arrival
Time
of last
event
5.6 A
D 8.6
4.0
Number
delayed
46
1 1 5.6
5.6
5 2.7 2.7 4.7
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Arrival
time = 5.6
System
(k)
Number
in
queue
Times
of
arrival
Time
of last
event
5.8 A
D
4.0
8.6
5.6
5.6
Number
delayed
47
1 2 5.8
5.8
5 2.7 2.9 4.9
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Arrival
time = 5.8
System
(l)
Number
in
queue
Times
of
arrival
Time
of last
event
7.2 A
D
4.0
8.6
5.6
5.6
5.8
5.8
Number
delayed
48
1 3 7.2
7.2
5 2.7 5.7 6.3
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Arrival
time = 7.2
System
(m)
Number
in
queue
Times
of
arrival
Time
of last
event
9.1 A
D
4.0
8.6
5.6
5.6
5.8
5.8
7.2
7.2
Number
delayed
49
1 2 8.6
8.6
6 5.7 9.9 7.7
Computer Representation
System state
Statistical counters
Sever
status
Total
delay
Area
under Q(t)
Area
under B(t)
Clock
Event list
Departure
time = 8.6
System
(n)
Number
in
queue
Times
of
arrival
Time
of last
event
9.1 A
D
5.6
9.2
5.8
5.8
7.2
7.2
Number
delayed
50
Comments
Interaction between the simulation clock and
the event list
Process updates of the state variables and
statistical counters
Contingencies
A departing customer could leave behind an empty
queue
Termination conditions
Time ties
51
1.4.3 Program Organization and Logic
Why general-purpose language
Model being simulated: M/M/1 queue
n=1000
Interarrival and service times
Interarrival: exponential distribution (mean=1 min)
Service: exponential distribution (mean=0.5 min)


|
|
x
e x f

=
1
) (
52
Arrival
Event
Schedule the next
arrival event
Is
the server
busy?
Set delay=0
for this customer
and gather statistics
Add 1 to the
number in queue
Add 1 to the
number of
customers delayed
Make the
server busy
Schedule a
departure event
for this customer
Is
the queue
full?
Write error
message and stop
simulation
Store time of
arrival of this
customer
Return
Yes
Yes
No
No
FIGURE 1.8
Flowchart for arrival routine, queueing model
53
Departure
Event
Is
the queue
empty?
Subtract 1 from
the number
in queue
Compute delay of
customer entering service
and gather statistics
Add 1 to the
number of customers
delayed
Schedule a
departure event
for this customer
Return
Yes No
FIGURE 1.9
Flowchart for arrival routine, queueing model
Move each customer
in queue (if any) up
one place
Make the server idle
Eliminate departure
event from
consideration
54
C Program for Queueing Model
(Fig 1.19 Fig. 1.27)
External definitions
Main functions
Function initialize
Function timing
Function arrive
Function departure
Function report
Function update_avg_stats
Function expon
55
Simulation Output and Discussion
(Fig. 1.28 Output report, queueing model)
Single-server queueing system

Mean interarrival time 1.000 mins
Mean service time 0.500 mins
Number of customers 1000

Average delay in queue 0.430 mins
Average number in queue 0.418
Server utilization 0.460
Time simulation ended 1027.915 mins
56
Alternative Stopping Rules
(Fig. 1.33 Fig. 1.37)

Stop: fixed run time 480 mins

External definitions
Main functions
Function initialize
Function report
Output report
57
Determining the Events and Variables
Event-graph


Arrival Departure
FIGURE 1.38
Event graph, queueing model
58
Determining the Events and Variables
Event-graph
Arrival
Enter
service
FIGURE 1.39
Event graph, queueing model with separate enter-service event
Departure
59
Determining the Events and Variables
Event-graph
FIGURE 1.40
Event graph, queueing model with fixed run length
Arrival Departure
End
simulation
60
STEPS IN A SOUND SIMULATION STUDY
1. Formulate the problem and plan the study

a. Problem of interest is stated by manager.
b. One or more kickoff meeting for the study are conducted,
with the project manager, the simulation analysts, and
subject-matter experts (SMEs) in attendance. The
following issues are discussed:
Overall objectives of the study
Specific questions to be answered by the study
Performance measures that will be used to evaluate the effeciency
of different system configurations
Scope of the model
System configurations to be modeled
Software to be used
Time frame for the study and the required resources
61
STEPS
2. Collect data and define a model.

a. Collect information on the system layout and operating procedures.
No single person or document is sufficient.
Some people may have inaccurate information---make sure that ture SMEs are identified.
Operating procedures may not be formalized.
b. Collect data (if possible) to specify model parameters and input probability distributions
c. Delineate the above information and data in an assumptions document, which is the
conceptual model
d. Collect data (if possible) on the performance of the existing systsem (for validation purpose
in Step 6)
e. The level of model detail should depend on the following:
Project objectives
Performance measures
Data availability
Credibility concerns
Computer constraints
Opinions of SMEs
Time and money constraints
f. There need not be a one-to-one correspondence between each element of the model and
the corresponding element of the system.
g. Interact with the manager (and other key project personnel) on a regular basis
62
STEPS
3. Is the conceptual model valid?

a. Perform a structured walk-through of the conceptual model using the
assumptions document before an audience of managers, analysts, and
SMEs
Helps ensure that the models assumptions are correct and complete
Promotes ownership of the model
Take place before programming begins to avoid significant
reprogramming later
4. Construct a computer program and verify.
a. Program the model in a programming language or in simulation
software. Benefits of using a programming language are that one is
often known, they have a low purchase cost, and they may result in a
smaller model execution time. The use of simulation software, on the
other hand, reduces programming time and results in a lower project
cost.
b. Verify (debug) the simulation computer program.
63
STEPS
5. Make pilot runs.
a. Make pilot runs for validation purposes in Step 6.
6. Is the programed model valid?
a. If ther is an existing system, then compare model and system (from
Step 2) performance measures for existing system
b. Regardless of whether there is an existing system, the simulation
analysts and SMEs should review the model results for correctness.
c. Use sensitivity analyses to determine what model factors have a
significant impact on performance measures and, thus, have to be
modeled carefully.
7. Design experiments.
a. Specify the following for each system configuration of interest:
Length of each run
Length of the warmup period, if one is appropriate
Number of independent simulation runs using different random numbers--
-facilitates construction of confidence intervals
64
STEPS
8. Make production runs.
a. Production runs are made for use in Step 9.
9. Analyze output data.
a. Two major objectives in analyzing output data are:
Determining the absolute performance of certain system configurations
Comparing alternative system configurations in a relative sense
10. Document, present, and use results.
a. Document assumptions (see Step 2), computer program, and studys
results for use in the current and future projects.
b. Present studys results.
Use animation to communicate model to managers and other people who
are not familiar with all of the model details.
Discuss model building and validation process to promote credibility.
c. Results are used in decision-making process if they are both valid and
credible.
65
Formulate problem
and plan the study
Collect data and
define a model
Conceptual
model valid?
Construct a computer
program and verify
Make pilot runs
Programmed
Model valid?
Design experiments
Make production runs
Analyze output data
Document, present,
and use results
No
Yes
No
Yes
FIGURE 1.68
Steps in a simulation study.
66
ADVANTAGES OF SIMULATION
Most complex, real-world systems with stochastic elements cannot be
accurately described by a mathematical model that can be evaluated
analytically. Thus, a simulation is often the only type of investigation
possible.
Simulation allows one to estimate the performance of an existing system
under some projected set of operating conditions.
Alternative proposed system designs (or alternative operating policies for a
single system) can be compared via simulation to see which best meets a
specified requirement.
In a simulation we can maintain much better control over experimental
conditions than would generally be possible when experimenting with the
system itself.
Simulation allows us to study a system with a long time frame---e.g., an
economic system---in compressed time, or alternatively to study the
detailed workings of a system in expanded time.
67
DISADVANTAGES OF SIMULATION
Each run of a stochastic simulation model produces only
estimates of a models true characteristics for a particular set
of input parameters. If a valid analytic model is available or
can be easily de developed, it will generally be preferable to a
simulation model.
Simulation models are often expensive and time-consuming to
develop.
If a model is not a valid representation of a system under
study, the simulation results, no matter how impressive they
appear, will provide little useful information about the actual
system.
In some studies both simulation and analytic models might
be useful. In particular, simulation can be used to check the
validity of assumptions needed in an analytic mode. On the
other hand, an analytic model can suggest reasonable
alternatives to investigate in a simulation study.

68
Pitfalls to the successful completion of
a simulation study
Failure to have a well-defined set of objectives at the beginning of
the simulation study
Inappropriate level of model detail
Failure to communicate with management throughout the course of
the simulation study
Misunderstanding of simulation by management
Treating a simulation study as if it were primarily an exercise in
computer programming
Failure to have people with a knowledge of simulation methodology
and statistics on the modeling team
Failure to collect good system data
Inappropriate simulation software
Obliviously using simulation software products whose complex
marco statement may not be well documented and may not
implement the desired modeling logic


69
Pitfalls to the successful completion of a
simulation study
Belief that easy-to-use simulation packages, which require little or
no programming, require a significantly lower level of technical
competence
Misuse of animation
Failure to account correctly for sources of randomness in the actual
system
Using arbitrary distributions (e.g., normal, uniform, or trianglar) as
input to the simualation
Analyzing the output data from one simulation run (replication) using
formulas that assume independence
Making a single replication of a particular system design and treating
the output statistics as the true answers
Comparing alternative system design on the basis of one replication
for each design
Using the wrong performance measures

70
Notes
In some studies both simulation and
analytic models might be useful. In
particular, simulation can be used to
check the validity of assumptions needed
in an analytic model. On the other hand,
an analytic model can suggest reasonable
alternatives to investigate in a simulation
study.


71
Tarea 1: Simulation of a Single server queueing system
Modify the code for the single-server queue in Chapter 1 to
compute and write in addition the following measures of
performance:
1. The time-average number in the system
2. The average total time in the system
3. The maximum queue length
4. The maximum delay in quque
5. The maximum time in the system
6. The proportion of customers having a delay in queue in excess of 1 minute
Entegar: report on the simulation including simulation model description, design of
the experiments, results of above measures after the simulation, conclusion on
the simulation, and program code.
Fecha limite: 18 de Febrero de 2005

You might also like