Introduction to Discrete-Event Simulation Using SimPy ( PDFDrive )
Introduction to Discrete-Event Simulation Using SimPy ( PDFDrive )
to Discrete-
Event
Simulation
Using SimPy
Chun-Chieh
Huang
Introduction to Discrete-Event Simulation
What is
Using SimPy
Simulation
and Why do
we need it?
SimPy
Example
References
Outline
Introduction
to Discrete-
Event
Simulation
Using SimPy
1 What is Simulation and Why do we need it?
Chun-Chieh
Huang
What is
2 What is Discrete-Event Simulation?
Simulation
and Why do
we need it?
3 Example to Illustrate World Views
What is
Discrete-
Event
Simulation?
4 Introduction to SimPy
Example to
Illustrate
World Views
SimPy
Example
References
What is Simulation and Why do we need it?
Introduction
to Discrete-
Event
Simulation
Simulation
Using SimPy a computer program that creates a virtual environment
Chun-Chieh in order to study physical problems
Huang
What is
Simulation
and Why do
we need it?
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
What is Simulation and Why do we need it?
Introduction
to Discrete-
Event
Simulation
Simulation
Using SimPy a computer program that creates a virtual environment
Chun-Chieh in order to study physical problems
Huang
When to use simulation
What is
Simulation
hard to do real experiment,
and Why do e.g. battle field, or banking system
we need it?
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
What is Simulation and Why do we need it?
Introduction
to Discrete-
Event
Simulation
Simulation
Using SimPy a computer program that creates a virtual environment
Chun-Chieh in order to study physical problems
Huang
When to use simulation
What is
Simulation
hard to do real experiment,
and Why do e.g. battle field, or banking system
we need it?
cheaper to do simulation,
What is
Discrete- e.g. RTL simulation for IC design,
Event
Simulation?
or highway/freeway route planning
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
What is Simulation and Why do we need it?
Introduction
to Discrete-
Event
Simulation
Simulation
Using SimPy a computer program that creates a virtual environment
Chun-Chieh in order to study physical problems
Huang
When to use simulation
What is
Simulation
hard to do real experiment,
and Why do e.g. battle field, or banking system
we need it?
cheaper to do simulation,
What is
Discrete- e.g. RTL simulation for IC design,
Event
Simulation?
or highway/freeway route planning
Example to
analyzing bottleneck for current workflow
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
What is Simulation and Why do we need it?
Introduction
to Discrete-
Event
Simulation
Simulation
Using SimPy a computer program that creates a virtual environment
Chun-Chieh in order to study physical problems
Huang
When to use simulation
What is
Simulation
hard to do real experiment,
and Why do e.g. battle field, or banking system
we need it?
cheaper to do simulation,
What is
Discrete- e.g. RTL simulation for IC design,
Event
Simulation?
or highway/freeway route planning
Example to
analyzing bottleneck for current workflow
Illustrate
World Views
When not to use simulation
Introduction more expensive to do simulation,
to SimPy e.g. simple harmonic motion
SimPy
Example
References
What is Simulation and Why do we need it?
Introduction
to Discrete-
Event
Simulation
Simulation
Using SimPy a computer program that creates a virtual environment
Chun-Chieh in order to study physical problems
Huang
When to use simulation
What is
Simulation
hard to do real experiment,
and Why do e.g. battle field, or banking system
we need it?
cheaper to do simulation,
What is
Discrete- e.g. RTL simulation for IC design,
Event
Simulation?
or highway/freeway route planning
Example to
analyzing bottleneck for current workflow
Illustrate
World Views
When not to use simulation
Introduction more expensive to do simulation,
to SimPy e.g. simple harmonic motion
SimPy
Example
problems that can be analyzed by pencil and paper
References
Categories of Simulation
Introduction
to Discrete-
Event
Simulation
Using SimPy
Continuous or discrete
Chun-Chieh
Huang
State variable is continuous, e.g. weather systems
State variable is discrete, e.g. number of customers
What is
Simulation
and Why do
we need it?
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
Categories of Simulation
Introduction
to Discrete-
Event
Simulation
Using SimPy
Continuous or discrete
Chun-Chieh
Huang
State variable is continuous, e.g. weather systems
State variable is discrete, e.g. number of customers
What is
Simulation
Static or dynamic
and Why do
we need it?
Static: represents a system at a particular point of time
What is
called Monte-Carlo Simulation [2]
Discrete- Dynamic: represents systems as they change over time
Event
Simulation? e.g. banking system from 9:00 AM to 5:00 PM
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
Categories of Simulation
Introduction
to Discrete-
Event
Simulation
Using SimPy
Continuous or discrete
Chun-Chieh
Huang
State variable is continuous, e.g. weather systems
State variable is discrete, e.g. number of customers
What is
Simulation
Static or dynamic
and Why do
we need it?
Static: represents a system at a particular point of time
What is
called Monte-Carlo Simulation [2]
Discrete- Dynamic: represents systems as they change over time
Event
Simulation? e.g. banking system from 9:00 AM to 5:00 PM
Example to
Illustrate
Deterministic or stochastic
World Views Deterministic: contains no random variable
Introduction
to SimPy
Stochastic: has one or more random variables
SimPy
Example
References
What is Discrete-Event Simulation?
Introduction
to Discrete-
Event
Simulation
Using SimPy
SimPy
Example
References
Discrete-Event Simulation World Views
Introduction
to Discrete-
Event
Simulation
Using SimPy
Activity-oriented
Chun-Chieh
Huang
fixed increment of time
time-consuming
What is
Simulation
and Why do
we need it?
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
Discrete-Event Simulation World Views
Introduction
to Discrete-
Event
Simulation
Using SimPy
Activity-oriented
Chun-Chieh
Huang
fixed increment of time
time-consuming
What is
Simulation
Event-oriented
and Why do
we need it? on each event, generate next event and
What is
put into event queue
Discrete- simulation time advances to next event
Event
Simulation? faster than activity-oriented
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
Discrete-Event Simulation World Views
Introduction
to Discrete-
Event
Simulation
Using SimPy
Activity-oriented
Chun-Chieh
Huang
fixed increment of time
time-consuming
What is
Simulation
Event-oriented
and Why do
we need it? on each event, generate next event and
What is
put into event queue
Discrete- simulation time advances to next event
Event
Simulation? faster than activity-oriented
Example to
Illustrate
Process-oriented
World Views abstract one object into a process
Introduction easier to maintain in the end
to SimPy
SimPy
Example
References
Example to Illustrate World Views
Introduction
to Discrete-
Event
Simulation
Using SimPy
Chun-Chieh
Huang
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
Discrete-Event Simulation World Views
Introduction
to Discrete-
Event
Simulation
Using SimPy
Activity-oriented
Chun-Chieh
Huang
fixed increment of time
time-consuming
What is
Simulation
Event-oriented
and Why do
we need it? on each event, generate next event and
What is
put into event queue
Discrete- simulation time advances to next event
Event
Simulation? faster than activity-oriented
Example to
Illustrate
Process-oriented
World Views abstract one object into a process
Introduction easier to maintain in the end
to SimPy
SimPy
Example
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
4
What is
Simulation
Simulation starts!
and Why do
we need it?
3
What is Gen 1st arr at 2.6
Discrete-
Event
Simulation? 2
Check events: 1st arr at 2.6
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 1st arr at 2.6
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 1st arr at 2.6
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 1st arr at 2.6
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 1st arr at 2.6
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 1st arr at 2.6
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 1st arr at 2.6...
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
4
What is
Simulation
First arrival!
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh Calculate service time, end at 4.0
Huang
4
What is
Simulation
Calculate next arrival at 3.5
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 2nd arrival at 3.5
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 2nd arrival at 3.5
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 2nd arrival at 3.5
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 2nd arrival at 3.5
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 2nd arrival at 3.5
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 2nd arrival at 3.5
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 2nd arrival at 3.5
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 2nd arrival at 3.5
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: 2nd arrival at 3.5...
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
4
What is
Simulation
Second arrival!
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
4
What is
Simulation
Calculate next arrival at ...
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: service end at 4.0
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: service end at 4.0
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Activity-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Check events: service end at 4.0...
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Discrete-Event Simulation World Views
Introduction
to Discrete-
Event
Simulation
Using SimPy
Activity-oriented
Chun-Chieh
Huang
fixed increment of time
time-consuming
What is
Simulation Event-oriented
and Why do
we need it? on each event, generate next event and
What is put into event queue
Discrete-
Event
simulation time advances to next event
Simulation? faster than activity-oriented
Example to
Illustrate
Process-oriented
World Views abstract one object into a process
Introduction
to SimPy
easier to maintain in the end
SimPy
Example
References
Event-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event 2.6: 1st arr
Simulation
Using SimPy
5
Chun-Chieh
Huang
4
What is
Simulation
Simulation starts!
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Event-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event 2.6: 1st arr
Simulation
Using SimPy
5
Chun-Chieh
Huang
4
What is
Simulation
First arrival!
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Event-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event 3.5: 2nd arr 4.0: 1st arr end
Simulation
Using SimPy
5
Chun-Chieh Calculate service time, end at 4.0
Huang
4
What is
Simulation
Calculate next arrival at 3.5
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Event-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event 3.5: 2nd arr 4.0: 1st arr end
Simulation
Using SimPy
5
Chun-Chieh
Huang
4
What is
Simulation
Second arrival!
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Event-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event 4.0: 1st arr end 5.0: 3rd arr
Simulation
Using SimPy
5
Chun-Chieh
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Event-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event 4.0: 1st arr end 5.0: 3rd arr
Simulation
Using SimPy
5
Chun-Chieh End service of 1st arrival.
Huang
What is
4
Simulation
and Why do
we need it?
3
What is
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Discrete-Event Simulation World Views
Introduction
to Discrete-
Event
Simulation
Activity-oriented
Using SimPy fixed increment of time
Chun-Chieh time-consuming
Huang
Event-oriented
What is
Simulation
on each event, generate next event and
and Why do put into event queue
we need it?
simulation time advances to next event
What is
Discrete- faster than activity-oriented
Event
Simulation? Process-oriented
Example to abstract one object into a process
Illustrate
World Views Arrival process for customers, or A
Introduction Clerk process, or S
to SimPy Event manager, or E
SimPy
Example easier to maintain in the end
References
Process-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh A: Gen 1st arr at 2.6
Huang
4
What is
Simulation
Simulation starts!
and Why do
we need it?
3
What is S:
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
E: Add one event of 2.6
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Process-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh A: Add customer to queue
Huang
4
What is
Simulation
First arrival!
and Why do
we need it?
3
What is S:
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
E: Process event, wake A up
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Process-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh A: Calc next arr at 3.5
Huang
What is
4
Simulation
and Why do
we need it?
3
What is S:
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
E: Add event of 2.6&3.5
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Process-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh A:
Huang
What is
4
Simulation
and Why do
we need it?
3
What is S: Serv, calc serv T at 4.0
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
E: Proc event of 2.6, add Ev 4.0
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Process-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh A: Add customer to queue
Huang
4
What is
Simulation
Second arrival!
and Why do
we need it?
3
What is S:
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
E: Proc event of 3.5, wake A up
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Process-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh A: Calc next arr at 5.0
Huang
4
What is
Simulation
Calc next arrival at 5.0
and Why do
we need it?
3
What is S:
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
E:
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Process-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh A:
Huang
What is
4
Simulation
and Why do
we need it?
3
What is S: 1st arr end serv.
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
E: Proc event of 4.0, wake S up
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Process-Oriented Discrete-Event Simulation
Introduction
to Discrete- 6
Event
Simulation
Using SimPy
5
Chun-Chieh A:
Huang
What is
4
Simulation
and Why do
we need it?
3
What is S: Serv 2nd arr.
Discrete-
Event
Simulation? 2
Example to
Illustrate
World Views 1
E: Add end serv event for 2nd arr.
Introduction
to SimPy
SimPy
0
Example 0 1 2 3 4 5 6 7 8 9
References
Implementing Discrete-Event Simulation
Introduction
to Discrete-
Event
Simulation
Using SimPy
Use your own C/C++ implementation
Chun-Chieh
Huang
takes time to write simulation engine and algorithm code
hard to debug, especially for event manager
What is not very convincing
Simulation
and Why do
we need it?
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
Implementing Discrete-Event Simulation
Introduction
to Discrete-
Event
Simulation
Using SimPy
Use your own C/C++ implementation
Chun-Chieh
Huang
takes time to write simulation engine and algorithm code
hard to debug, especially for event manager
What is not very convincing
Simulation
and Why do Use generalized simulation library, or language
we need it?
What is
SIMULA programming language
Discrete- C++SIM or JavaSIM [1]
Event
Simulation? SimEvents in Simulink/MATLAB
Example to SimPy [5]
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
Implementing Discrete-Event Simulation
Introduction
to Discrete-
Event
Simulation
Using SimPy
Use your own C/C++ implementation
Chun-Chieh
Huang
takes time to write simulation engine and algorithm code
hard to debug, especially for event manager
What is not very convincing
Simulation
and Why do Use generalized simulation library, or language
we need it?
What is
SIMULA programming language
Discrete- C++SIM or JavaSIM [1]
Event
Simulation? SimEvents in Simulink/MATLAB
Example to SimPy [5]
Illustrate
World Views Use special purpose simulation packages
Introduction ns-3 for network simulation [4]
to SimPy
SimPy
Example
References
Introduction to SimPy
Introduction
to Discrete-
Event
Simulation
Using SimPy
Uses Python for modeling
Chun-Chieh
Huang Python is a scripting language like MATLAB, but faster!
Python is very easy to write and very beautiful!
What is
Simulation
and Why do
we need it?
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
Introduction to SimPy
Introduction
to Discrete-
Event
Simulation
Using SimPy
Uses Python for modeling
Chun-Chieh
Huang Python is a scripting language like MATLAB, but faster!
Python is very easy to write and very beautiful!
What is
Simulation Process-oriented Discrete Event Simulation Language
and Why do
we need it? easier to write model
What is provides event manager implementation
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
Introduction to SimPy
Introduction
to Discrete-
Event
Simulation
Using SimPy
Uses Python for modeling
Chun-Chieh
Huang Python is a scripting language like MATLAB, but faster!
Python is very easy to write and very beautiful!
What is
Simulation Process-oriented Discrete Event Simulation Language
and Why do
we need it? easier to write model
What is provides event manager implementation
Discrete-
Event Uses coroutine to suspend/resume process
Simulation?
Example to
will be refered to as thread in this presentation
Illustrate guarantees order of execution
World Views
cannot run on parallel machine
Introduction
to SimPy
SimPy
Example
References
SimPy Terminology: Classes
Introduction
to Discrete-
Event
Simulation
Using SimPy
Chun-Chieh
Huang
Process
What is
Simulation
simulates an entity which evolves in time, e.g.
and Why do a customer who needs to be served by a clerk
we need it?
refered to as thread in [3]
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
SimPy Terminology: Classes
Introduction
to Discrete-
Event
Simulation
Using SimPy
Chun-Chieh
Huang
Process
What is
Simulation
simulates an entity which evolves in time, e.g.
and Why do a customer who needs to be served by a clerk
we need it?
refered to as thread in [3]
What is
Discrete- Resource
Event
Simulation? simulates something to be queued, e.g. the waiting list
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
SimPy Terimnology: Functions
Introduction
to Discrete-
Event activate() used to mark a thread as runnable when it is first
Simulation
Using SimPy
created
Chun-Chieh
Huang
What is
Simulation
and Why do
we need it?
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
SimPy Terimnology: Functions
Introduction
to Discrete-
Event activate() used to mark a thread as runnable when it is first
Simulation
Using SimPy
created
Chun-Chieh simulate() starts the simulation
Huang
What is
Simulation
and Why do
we need it?
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
SimPy Terimnology: Functions
Introduction
to Discrete-
Event activate() used to mark a thread as runnable when it is first
Simulation
Using SimPy
created
Chun-Chieh simulate() starts the simulation
Huang
yield hold put current thread into suspension for a certain
What is
Simulation
amount of time
and Why do
we need it?
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
SimPy Terimnology: Functions
Introduction
to Discrete-
Event activate() used to mark a thread as runnable when it is first
Simulation
Using SimPy
created
Chun-Chieh simulate() starts the simulation
Huang
yield hold put current thread into suspension for a certain
What is
Simulation
amount of time
and Why do
we need it? yield request requests for a given resource
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
SimPy Terimnology: Functions
Introduction
to Discrete-
Event activate() used to mark a thread as runnable when it is first
Simulation
Using SimPy
created
Chun-Chieh simulate() starts the simulation
Huang
yield hold put current thread into suspension for a certain
What is
Simulation
amount of time
and Why do
we need it? yield request requests for a given resource
What is
Discrete-
yield release used to indicate that current thread no longer
Event
Simulation?
need the given resource
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
SimPy Terimnology: Functions
Introduction
to Discrete-
Event activate() used to mark a thread as runnable when it is first
Simulation
Using SimPy
created
Chun-Chieh simulate() starts the simulation
Huang
yield hold put current thread into suspension for a certain
What is
Simulation
amount of time
and Why do
we need it? yield request requests for a given resource
What is
Discrete-
yield release used to indicate that current thread no longer
Event
Simulation?
need the given resource
Example to yield passivate put current thread into suspension and
Illustrate
World Views wait until awakened by some other thread
Introduction
to SimPy
SimPy
Example
References
SimPy Terimnology: Functions
Introduction
to Discrete-
Event activate() used to mark a thread as runnable when it is first
Simulation
Using SimPy
created
Chun-Chieh simulate() starts the simulation
Huang
yield hold put current thread into suspension for a certain
What is
Simulation
amount of time
and Why do
we need it? yield request requests for a given resource
What is
Discrete-
yield release used to indicate that current thread no longer
Event
Simulation?
need the given resource
Example to yield passivate put current thread into suspension and
Illustrate
World Views wait until awakened by some other thread
Introduction
to SimPy
reactivate() awakes a previously-passivated thread
SimPy
Example
References
SimPy Terimnology: Functions
Introduction
to Discrete-
Event activate() used to mark a thread as runnable when it is first
Simulation
Using SimPy
created
Chun-Chieh simulate() starts the simulation
Huang
yield hold put current thread into suspension for a certain
What is
Simulation
amount of time
and Why do
we need it? yield request requests for a given resource
What is
Discrete-
yield release used to indicate that current thread no longer
Event
Simulation?
need the given resource
Example to yield passivate put current thread into suspension and
Illustrate
World Views wait until awakened by some other thread
Introduction
to SimPy
reactivate() awakes a previously-passivated thread
SimPy cancel() cancels all the events associated with a
Example
previously-passivated thread
References
SimPy Example
Introduction
to Discrete-
Event
Simulation
Using SimPy
Chun-Chieh Scenario
Huang
A post office with only one clerk.
What is Customers arrival is poisson process,
Simulation
and Why do
i.e. inter-arrival time is exponential distribution.
we need it? Service time is also poisson process.
What is
Discrete-
Process
Event
Simulation?
Arrival
Example to
Clerk
Illustrate
World Views Queue is managed by ourselves.
Introduction
to SimPy
SimPy
Example
References
Arrival Process
Introduction
to Discrete-
Event
Simulation
Using SimPy
Chun-Chieh c l a s s A r r i v a l C l a s s ( Process ) :
Huang A r r i v a l R a t e = 1/1.0 # reciprocal o f mean a r r i v a l time
d e f __init__ ( s e l f ) :
What is P r o c e s s . __init__ ( s e l f )
Simulation
and Why do d e f Run ( s e l f ) :
we need it? while 1:
I n t e r A r r i v a l T i m e = G . Rnd . e x p o v a r i a t e ( A r r i v a l C l a s s . A r r i v a l R a t e
What is y i e l d hold , s e l f , I n t e r A r r i v a l T i m e
Discrete- C = Customer ( )
Event C l e r k C l a s s . Queue . append ( C) # a c u s t o m e r a r r i v e s
Simulation? G . NumCustomers += 1
Example to
if C l e r k C l a s s . I d l e != [ ] : # I s t h e r e any c l e r k i d l e ?
Illustrate
r e a c t i v a t e ( C l e r k C l a s s . I d l e [ 0 ] ) # Yes , wake him / h e r up
World Views
Introduction
to SimPy
SimPy
Example
References
Clerk Process
Introduction
to Discrete- c l a s s Cler kClass ( Process ) :
Event Serv iceRa te = 1/1.2 # r e c i p r o c a l o f mean s e r v i c e t i m e
Simulation MaxQueueLength = 0
Using SimPy Queue = [ ]
Idle = []
Chun-Chieh Busy = [ ]
Huang NumDone = 0
d e f __init__ ( s e l f ) :
P r o c e s s . __init__ ( s e l f )
What is C l e r k C l a s s . I d l e . append ( s e l f ) # I nitially idle
Simulation d e f Run ( s e l f ) :
and Why do while 1:
we need it? yi e ld passivate , s e l f # w a i t u n t i l awaken by c u s t o m e r s
C l e r k C l a s s . I d l e . r emov e ( s e l f )
What is C l e r k C l a s s . Busy . append ( s e l f ) # g o i n g t o be b u s y
Discrete- w h i l e C l e r k C l a s s . Queue != [ ] :
Event C = C l e r k C l a s s . Queue . pop ( ) # c a l l n e x t c u s t o m e r i n l i n e
Simulation? i f l e n ( C l e r k C l a s s . Queue ) > C l e r k C l a s s . MaxQueueLength :
C l e r k C l a s s . MaxQueueLength = l e n ( C l e r k C l a s s . Queue )
Example to # St a r t s e r v i c e the customer
Illustrate S e r v i c e T i m e = G . Rnd . e x p o v a r i a t e ( C l e r k C l a s s . S e r v i c e R a t e )
World Views y i e l d hold , s e l f , ServiceT ime
C. endService ()
Introduction G . T o t a l W a i t i n g T i m e += C . W a i t i n g T i m e
to SimPy C l e r k C l a s s . NumDone += 1
SimPy del C
Example
C l e r k C l a s s . Busy . r emov e ( s e l f )
References C l e r k C l a s s . I d l e . append ( s e l f )
Live Demo
Introduction
to Discrete-
Event
Simulation
Using SimPy
Chun-Chieh
Huang
What is
Simulation
and Why do
we need it?
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
Important Simulation Parameters
Introduction
to Discrete-
Event
Simulation
Using SimPy
Purpose List below parameters to prove that your work is
Chun-Chieh
Huang repeatable.
What is
RNG Random number generator method
Simulation
and Why do
Linear Congruential Method
we need it? oldest and best well known
What is
Discrete-
Mersenne Twister
Event
Simulation?
designed with simulation purpose in mind
Example to
used to implement random library in python
Illustrate after version 2.5
World Views
SimPy
Example
References
Concluding Remarks
Introduction
to Discrete-
Event
Simulation
Using SimPy
Chun-Chieh
Huang
What is
SimPy provides process-oriendted DES framework
Discrete- to write simlation easily and reasonably fast.
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References
References
Introduction
to Discrete-
Event
Simulation
Using SimPy
Chun-Chieh
Huang
[1] JavaSIM and C++SIM. http://javasim.codehaus.org/.
[2] Jerry Banks, John S. Carson, Barry L. Nelson, and
What is
Simulation David M. Nicol. Discrete-Event System Simulation (5th
and Why do
we need it? Edition). Prentice Hall, 2009.
What is
Discrete-
[3] N Matloff. A discrete-event simulation course based on the
Event simpy language. Davis, 2006.
Simulation?
SimPy
Example
References
Introduction
to Discrete-
Event
Simulation
Using SimPy
Chun-Chieh
Huang
What is
Simulation
and Why do
we need it? Q&A
What is
Discrete-
Event
Simulation?
Example to
Illustrate
World Views
Introduction
to SimPy
SimPy
Example
References