08448380779 Call Girls In Friends Colony Women Seeking Men
Introduction Discrete-Event Simulation Using SimPy
1. Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang Introduction to Discrete-Event Simulation
jjhuang
Using SimPy
What is
Simulation and
When to Use it?
What is
Discrete-Event
Chun-Chieh Huang
Simulation?
jjhuang
Example to
Illustrate World
Views DSP and Algorithm Design Department
Introduction to Metanoia Communications Inc.
SimPy <jiunjie.huang@gmail.com>
SimPy Example
References June 9, 2012
2. Outline
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang
1 What is Simulation and When to Use it?
jjhuang
What is
Simulation and
2 What is Discrete-Event Simulation?
When to Use it?
What is
Discrete-Event 3 Example to Illustrate World Views
Simulation?
Example to
Illustrate World
Views 4 Introduction to SimPy
Introduction to
SimPy
SimPy Example 5 SimPy Example
References
3. What is Simulation and When to Use it?
Introduction to
Discrete-Event
Simulation
Using SimPy Simulation
Chun-Chieh a computer program that creates a virtual environment
Huang
jjhuang in order to study physical problems
What is
Simulation and
When to Use it?
What is
Discrete-Event
Simulation?
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
4. What is Simulation and When to Use it?
Introduction to
Discrete-Event
Simulation
Using SimPy Simulation
Chun-Chieh a computer program that creates a virtual environment
Huang
jjhuang in order to study physical problems
What is
When to use simulation
Simulation and
When to Use it?
hard to do real experiment,
e.g. battle field, or banking system
What is
Discrete-Event
Simulation?
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
5. What is Simulation and When to Use it?
Introduction to
Discrete-Event
Simulation
Using SimPy Simulation
Chun-Chieh a computer program that creates a virtual environment
Huang
jjhuang in order to study physical problems
What is
When to use simulation
Simulation and
When to Use it?
hard to do real experiment,
e.g. battle field, or banking system
What is
Discrete-Event cheaper to do simulation,
Simulation?
e.g. RTL simulation for IC design,
Example to
Illustrate World or highway/freeway route planning
Views
Introduction to
SimPy
SimPy Example
References
6. What is Simulation and When to Use it?
Introduction to
Discrete-Event
Simulation
Using SimPy Simulation
Chun-Chieh a computer program that creates a virtual environment
Huang
jjhuang in order to study physical problems
What is
When to use simulation
Simulation and
When to Use it?
hard to do real experiment,
e.g. battle field, or banking system
What is
Discrete-Event cheaper to do simulation,
Simulation?
e.g. RTL simulation for IC design,
Example to
Illustrate World or highway/freeway route planning
Views
analyzing bottleneck of current workflow
Introduction to
SimPy
SimPy Example
References
7. What is Simulation and When to Use it?
Introduction to
Discrete-Event
Simulation
Using SimPy Simulation
Chun-Chieh a computer program that creates a virtual environment
Huang
jjhuang in order to study physical problems
What is
When to use simulation
Simulation and
When to Use it?
hard to do real experiment,
e.g. battle field, or banking system
What is
Discrete-Event cheaper to do simulation,
Simulation?
e.g. RTL simulation for IC design,
Example to
Illustrate World or highway/freeway route planning
Views
analyzing bottleneck of current workflow
Introduction to
SimPy When not to use simulation
SimPy Example more expensive to do simulation,
References e.g. simple harmonic motion
8. What is Simulation and When to Use it?
Introduction to
Discrete-Event
Simulation
Using SimPy Simulation
Chun-Chieh a computer program that creates a virtual environment
Huang
jjhuang in order to study physical problems
What is
When to use simulation
Simulation and
When to Use it?
hard to do real experiment,
e.g. battle field, or banking system
What is
Discrete-Event cheaper to do simulation,
Simulation?
e.g. RTL simulation for IC design,
Example to
Illustrate World or highway/freeway route planning
Views
analyzing bottleneck of current workflow
Introduction to
SimPy When not to use simulation
SimPy Example more expensive to do simulation,
References e.g. simple harmonic motion
problems that can be analyzed by pencil and paper
9. Categories of Simulation
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Continuous or discrete
Huang
jjhuang
state variable is continuous, e.g. weather systems
state variable is discrete, e.g. number of customers
What is
Simulation and
When to Use it?
What is
Discrete-Event
Simulation?
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
10. Categories of Simulation
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Continuous or discrete
Huang
jjhuang
state variable is continuous, e.g. weather systems
state variable is discrete, e.g. number of customers
What is
Simulation and Static or dynamic
When to Use it?
Static: represents a system at a particular point of time
What is
Discrete-Event representation of time is unnecessary [1]
Simulation? sometimes called Monte-Carlo simulation [2]
Example to Dynamic: represents systems as they change over time
Illustrate World
Views e.g. banking system from 9:00 AM to 5:00 PM
Introduction to
SimPy
SimPy Example
References
11. Categories of Simulation
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Continuous or discrete
Huang
jjhuang
state variable is continuous, e.g. weather systems
state variable is discrete, e.g. number of customers
What is
Simulation and Static or dynamic
When to Use it?
Static: represents a system at a particular point of time
What is
Discrete-Event representation of time is unnecessary [1]
Simulation? sometimes called Monte-Carlo simulation [2]
Example to Dynamic: represents systems as they change over time
Illustrate World
Views e.g. banking system from 9:00 AM to 5:00 PM
Introduction to
SimPy
Deterministic or stochastic
SimPy Example Deterministic: contains no random variable
References Stochastic: has one or more random variables
12. What is Discrete-Event Simulation?
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang
jjhuang Discrete-Event Simulation is
Discrete
What is
Simulation and Dynamic
When to Use it?
Stochastic
What is
Discrete-Event Simulation for queueing in a post office is DES
Simulation?
Example to
Mostly, but not limited to, queueing systems
Illustrate World
Views
factory work flow
Introduction to
freeway traffic simulation
SimPy network traffic simulation
SimPy Example
References
13. Discrete-Event Simulation World Views
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Activity-oriented
Huang
jjhuang
fixed increment of time
time-consuming
What is
Simulation and
When to Use it?
What is
Discrete-Event
Simulation?
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
14. Discrete-Event Simulation World Views
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Activity-oriented
Huang
jjhuang
fixed increment of time
time-consuming
What is
Simulation and Event-oriented
When to Use it?
on each event, generate next event and
What is
Discrete-Event put into event queue and sort
Simulation?
simulation time advances to next closest event
Example to faster than activity-oriented
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
15. Discrete-Event Simulation World Views
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Activity-oriented
Huang
jjhuang
fixed increment of time
time-consuming
What is
Simulation and Event-oriented
When to Use it?
on each event, generate next event and
What is
Discrete-Event put into event queue and sort
Simulation?
simulation time advances to next closest event
Example to faster than activity-oriented
Illustrate World
Views
Process-oriented
Introduction to
SimPy abstract one object into a process
SimPy Example
easier to maintain in the end
References
16. Discrete-Event Simulation World Views
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Activity-oriented
Huang
jjhuang
fixed increment of time
time-consuming
What is
Simulation and Event-oriented
When to Use it?
on each event, generate next event and
What is
Discrete-Event put into event queue and sort
Simulation?
simulation time advances to next closest event
Example to faster than activity-oriented
Illustrate World
Views
Process-oriented
Introduction to
SimPy abstract one object into a process
SimPy Example
easier to maintain in the end
References
SimPy belongs here!
17. Example to Illustrate World Views
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang
jjhuang
What is
Simulation and Simulating a post office with only one clerk
When to Use it?
Customers come in at random time
What is
Discrete-Event and wait if the clerk is already serving
Simulation?
Example to Clerk serves each customer for a random period of time
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
18. Discrete-Event Simulation World Views
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh Activity-oriented
Huang
jjhuang fixed increment of time
What is
time-consuming
Simulation and
When to Use it?
Event-oriented
What is on each event, generate next event and
Discrete-Event
Simulation?
put into event queue and sort
Example to
simulation time advances to next closest event
Illustrate World faster than activity-oriented
Views
Introduction to
Process-oriented
SimPy
abstract one object into a process
SimPy Example easier to maintain in the end
References
19. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
4
Simulation and
When to Use it?
Simulation starts at 2.0!
What is
Discrete-Event 3
Simulation? Gen 1st arr at 2.6
Example to
Illustrate World 2
Views Check events: 1st arr at 2.6, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
20. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 1st arr at 2.6, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
21. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 1st arr at 2.6, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
22. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 1st arr at 2.6, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
23. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 1st arr at 2.6, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
24. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 1st arr at 2.6, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
25. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 1st arr at 2.6, process now
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
26. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
4
Simulation and
When to Use it?
First arrival!
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
27. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang Calculate service time, end at 4.0
What is
4
Simulation and
When to Use it?
Calculate next arrival at 3.5
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
28. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 2nd arrival at 3.5, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
29. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 2nd arrival at 3.5, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
30. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 2nd arrival at 3.5, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
31. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 2nd arrival at 3.5, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
32. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 2nd arrival at 3.5, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
33. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 2nd arrival at 3.5, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
34. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 2nd arrival at 3.5, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
35. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 2nd arrival at 3.5, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
36. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: 2nd arrival at 3.5, process now
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
37. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
4
Simulation and
When to Use it?
Second arrival!
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
38. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
4
Simulation and
When to Use it?
Calculate next arrival at ...
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
39. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: service end at 4.0, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
40. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: service end at 4.0, no action
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
41. Activity-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views Check events: service end at 4.0, no action...
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
42. Discrete-Event Simulation World Views
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh Activity-oriented
Huang
jjhuang fixed increment of time
time-consuming
What is
Simulation and
When to Use it? Event-oriented
What is on each event, generate next event and
Discrete-Event
Simulation? put into event queue and sort
Example to
simulation time advances to next closest event
Illustrate World faster than activity-oriented
Views
Introduction to Process-oriented
SimPy
abstract one object into a process
SimPy Example
easier to maintain in the end
References
43. Event-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
2.6: 1st arr
Chun-Chieh
Huang 5
jjhuang
What is
4
Simulation and
When to Use it?
Simulation starts!
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
44. Event-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
2.6: 1st arr
Chun-Chieh
Huang 5
jjhuang
What is
4
Simulation and
When to Use it?
First arrival!
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
45. Event-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
3.5: 2nd arr 4.0: 1st arr end
Chun-Chieh
Huang 5
jjhuang Calculate service time, end at 4.0
What is
4
Simulation and
When to Use it?
Calculate next arrival at 3.5
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
46. Event-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
3.5: 2nd arr 4.0: 1st arr end
Chun-Chieh
Huang 5
jjhuang
What is
4
Simulation and
When to Use it?
Second arrival!
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
47. Event-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
4.0: 1st arr end
Chun-Chieh
Huang 5
jjhuang
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
48. Event-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
4.0: 1st arr end
Chun-Chieh
Huang 5
jjhuang End service of 1st arrival.
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
49. Discrete-Event Simulation World Views
Introduction to
Discrete-Event
Simulation
Using SimPy
Activity-oriented
Chun-Chieh
Huang fixed increment of time
jjhuang
time-consuming
What is Event-oriented
Simulation and
When to Use it? on each event, generate next event and
What is put into event queue and sort
Discrete-Event
Simulation? simulation time advances to next closest event
Example to
faster than activity-oriented
Illustrate World
Views Process-oriented
Introduction to abstract one object into a process
SimPy
Arrival process for customers, or A
SimPy Example
Clerk process, or S
References
easier to maintain in the end
50. Process-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang
jjhuang
Arrival is an infinite loop of the following
What is Calculate next arrival time
Simulation and
When to Use it? Sleep until next arrival
What is Add customer into queue
Discrete-Event
Simulation? Clerk is an infinite loop of the following
Example to Sleep until waken up by customers
Illustrate World
Views Serve the customer on waken up
Introduction to until there is no customer in line
SimPy
SimPy Example
References
51. Process-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang A: Gen 1st arr at 2.6
What is
4
Simulation and
When to Use it?
Simulation starts!
What is
Discrete-Event 3
Simulation? S:
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
52. Process-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang A: Add customer to queue
What is
4
Simulation and
When to Use it?
First arrival!
What is
Discrete-Event 3
Simulation? S:
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
53. Process-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang A: Calc next arr at 3.5
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation? S:
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
54. Process-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang A:
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation?
S: Serv, calc serv T at 4.0
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
55. Process-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang A: Add customer to queue
What is
4
Simulation and
When to Use it?
Second arrival!
What is
Discrete-Event 3
Simulation? S:
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
56. Process-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang A: Calc next arr at ...
What is
4
Simulation and
When to Use it?
Calc next arrival at ...
What is
Discrete-Event 3
Simulation? S:
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
57. Process-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang A:
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation? S: 1st arr end serv. Call next.
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
58. Process-Oriented Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation 6
Using SimPy
Chun-Chieh
Huang 5
jjhuang A:
What is
Simulation and
4
When to Use it?
What is
Discrete-Event 3
Simulation? S: Serv 2nd arr. Calc end time at ...
Example to
Illustrate World 2
Views
Introduction to
SimPy 1
SimPy Example
References
0
0 1 2 3 4 5 6 7 8 9
59. Implementing Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh Use your own C/C++ implementation
Huang
jjhuang takes time to write simulation engine and algorithm code
hard to debug when both are not verified
What is
Simulation and not very convincing
When to Use it?
What is
Discrete-Event
Simulation?
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
60. Implementing Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh Use your own C/C++ implementation
Huang
jjhuang takes time to write simulation engine and algorithm code
hard to debug when both are not verified
What is
Simulation and not very convincing
When to Use it?
What is
Use generalized simulation library, or language
Discrete-Event
Simulation?
SIMULA programming language
C++SIM or JavaSIM [3]
Example to
Illustrate World SimEvents in Simulink/MATLAB
Views
SimPy [4]
Introduction to
SimPy
SimPy Example
References
61. Implementing Discrete-Event Simulation
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh Use your own C/C++ implementation
Huang
jjhuang takes time to write simulation engine and algorithm code
hard to debug when both are not verified
What is
Simulation and not very convincing
When to Use it?
What is
Use generalized simulation library, or language
Discrete-Event
Simulation?
SIMULA programming language
C++SIM or JavaSIM [3]
Example to
Illustrate World SimEvents in Simulink/MATLAB
Views
SimPy [4]
Introduction to
SimPy Use special purpose simulation packages
SimPy Example ns-3 for network simulation [5]
References
62. Introduction to SimPy
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh Uses Python for modeling
Huang
jjhuang Python is a scripting language like MATLAB, but faster!
Python is free!
What is
Simulation and Python is very easy to write and beautiful!
When to Use it?
What is
Discrete-Event
Simulation?
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
63. Introduction to SimPy
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh Uses Python for modeling
Huang
jjhuang Python is a scripting language like MATLAB, but faster!
Python is free!
What is
Simulation and Python is very easy to write and beautiful!
When to Use it?
What is
Process-oriented Discrete-Event Simulation Language
Discrete-Event is easier to write model
Simulation?
provides proven event manager implementation
Example to
Illustrate World lets you focus on algorithm code
Views
Introduction to
SimPy
SimPy Example
References
64. Introduction to SimPy
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh Uses Python for modeling
Huang
jjhuang Python is a scripting language like MATLAB, but faster!
Python is free!
What is
Simulation and Python is very easy to write and beautiful!
When to Use it?
What is
Process-oriented Discrete-Event Simulation Language
Discrete-Event is easier to write model
Simulation?
provides proven event manager implementation
Example to
Illustrate World lets you focus on algorithm code
Views
Introduction to
Uses coroutine to suspend/resume process
SimPy guarantees order of execution
SimPy Example cannot run on parallel machine for a single simulation
References
65. SimPy Terminology: Classes
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang
jjhuang
Process
What is simulates an entity which evolves in time, e.g.
Simulation and
When to Use it? a clerk that serves customers
What is
refered to as thread in [6]
Discrete-Event
Simulation?
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
66. SimPy Terminology: Classes
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang
jjhuang
Process
What is simulates an entity which evolves in time, e.g.
Simulation and
When to Use it? a clerk that serves customers
What is
refered to as thread in [6]
Discrete-Event
Simulation? Resource
Example to simulates something to be requested and
Illustrate World
Views queued if not available now
Introduction to
e.g. a wash machine
SimPy
SimPy Example
References
67. SimPy Terimnology: Functions
Introduction to
Discrete-Event
Simulation activate() used to mark a thread as runnable when it is first
Using SimPy
created
Chun-Chieh
Huang
jjhuang
What is
Simulation and
When to Use it?
What is
Discrete-Event
Simulation?
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
68. SimPy Terimnology: Functions
Introduction to
Discrete-Event
Simulation activate() used to mark a thread as runnable when it is first
Using SimPy
created
Chun-Chieh
Huang
jjhuang simulate() starts the simulation
What is
Simulation and
When to Use it?
What is
Discrete-Event
Simulation?
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
69. SimPy Terimnology: Functions
Introduction to
Discrete-Event
Simulation activate() used to mark a thread as runnable when it is first
Using SimPy
created
Chun-Chieh
Huang
jjhuang simulate() starts the simulation
What is
yield hold put current thread into suspension for a certain
Simulation and
When to Use it?
amount of time
What is
Discrete-Event
Simulation?
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
70. SimPy Terimnology: Functions
Introduction to
Discrete-Event
Simulation activate() used to mark a thread as runnable when it is first
Using SimPy
created
Chun-Chieh
Huang
jjhuang simulate() starts the simulation
What is
yield hold put current thread into suspension for a certain
Simulation and
When to Use it?
amount of time
What is yield passivate put current thread into suspension and
Discrete-Event
Simulation? wait until awakened by some other thread
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
71. SimPy Terimnology: Functions
Introduction to
Discrete-Event
Simulation activate() used to mark a thread as runnable when it is first
Using SimPy
created
Chun-Chieh
Huang
jjhuang simulate() starts the simulation
What is
yield hold put current thread into suspension for a certain
Simulation and
When to Use it?
amount of time
What is yield passivate put current thread into suspension and
Discrete-Event
Simulation? wait until awakened by some other thread
Example to
Illustrate World
reactivate() awakes a previously-passivated thread
Views
Introduction to
SimPy
SimPy Example
References
72. SimPy Terimnology: Functions
Introduction to
Discrete-Event
Simulation activate() used to mark a thread as runnable when it is first
Using SimPy
created
Chun-Chieh
Huang
jjhuang simulate() starts the simulation
What is
yield hold put current thread into suspension for a certain
Simulation and
When to Use it?
amount of time
What is yield passivate put current thread into suspension and
Discrete-Event
Simulation? wait until awakened by some other thread
Example to
Illustrate World
reactivate() awakes a previously-passivated thread
Views
cancel() cancels all the events associated with a
Introduction to
SimPy previously-passivated thread
SimPy Example
References
73. SimPy Terimnology: Functions
Introduction to
Discrete-Event
Simulation activate() used to mark a thread as runnable when it is first
Using SimPy
created
Chun-Chieh
Huang
jjhuang simulate() starts the simulation
What is
yield hold put current thread into suspension for a certain
Simulation and
When to Use it?
amount of time
What is yield passivate put current thread into suspension and
Discrete-Event
Simulation? wait until awakened by some other thread
Example to
Illustrate World
reactivate() awakes a previously-passivated thread
Views
cancel() cancels all the events associated with a
Introduction to
SimPy previously-passivated thread
SimPy Example
yield request requests for a given resource
References
yield release used to indicate that current thread no longer need
the given resource
74. SimPy Example
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh Scenario
Huang
jjhuang A post office with only one clerk.
Customer arrival is a poisson process,
What is
Simulation and i.e. inter-arrival time is exponential distribution.
When to Use it?
Service time is also a poisson process.
What is
Discrete-Event Classical M /M /1 problem in queueing theory
Simulation?
Process
Example to
Illustrate World Arrival
Views
Clerk
Introduction to
SimPy Queue is managed by ourselves
SimPy Example So that we can extend to M /M /m later, i.e. m clerks
References
75. Arrival Pseudo Code
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang
jjhuang
What is
Simulation and Arrival is an infinite loop of the following
When to Use it?
Calculate next arrival time
What is
Discrete-Event Sleep until next arrival
Simulation?
Add customer into queue
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
76. Arrival Process
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang
1 class A r r i v a l C l a s s ( Process ) :
jjhuang
2 " " " An a r r i v a l maintenance c l a s s " " "
3 ArrivalRate = 1/1.0 # r e c i p r o c a l o f mean i n t e r a r r i v a l t i m e
What is 4 def _ _ i n i t _ _ ( s e l f , name ) :
Simulation and 5 Process . _ _ i n i t _ _ ( s e l f )
When to Use it? 6 s e l f . name = name
7
What is 8 def Run ( s e l f ) :
Discrete-Event 9 while True :
Simulation? 10 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 )
11 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
Example to
12 C = Customer ( )
Illustrate World
13 C l e r k C l a s s . Queue . append (C) # a customer a r r i v e s
Views
14 G. NumCustomers += 1
Introduction to 15 i f ClerkClass . I d l e != [ ] : # I s t h e r e any c l e r k i d l e ?
SimPy 16 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 / her up
SimPy Example
References
77. Clerk Pseudo Code
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang
jjhuang
What is
Simulation and Clerk is an infinite loop of the following
When to Use it?
Sleep until waken up by customers
What is
Discrete-Event Serve the customer on waken up
Simulation?
until there is no customer in line
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References
78. Clerk Process
Introduction to
Discrete-Event 1 class C l e r k C l a s s ( Process ) :
Simulation 2 " " " A s e r v e r process , o r c l e r k i n t h e p o s t o f f i c e " " "
Using SimPy 3 ServiceRate = 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
4 MaxQueueLength = 0
Chun-Chieh 5 Queue = [ ] # customer queue
Huang 6 Idle = [ ] # idle clerk l i s t
jjhuang 7 Busy = [ ] # busy c l e r k l i s t
8 NumDone = 0 # No . o f customers being s e r v i c e d
What is 9 def _ _ i n i t _ _ ( s e l f ) :
Simulation and 10 Process . _ _ i n i t _ _ ( s e l f )
When to Use it? 11 C l e r k C l a s s . I d l e . append ( s e l f ) # I n i t i a l l y idle
12 def Run ( s e l f ) :
What is 13 while True :
Discrete-Event 14 y i e l d passivate , s e l f # w a i t u n t i l awaken by customers
Simulation? 15 C l e r k C l a s s . I d l e . remove ( s e l f )
16 C l e r k C l a s s . Busy . append ( s e l f ) # going t o be busy
Example to 17 while C l e r k C l a s s . Queue ! = [ ] :
Illustrate World 18 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 :
Views 19 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 )
20 C = C l e r k C l a s s . Queue . pop ( ) # c a l l n e x t customer i n l i n e
Introduction to
21 # S t a r t s e r v i c e t h e customer
SimPy
22 ServiceTime = G. Rnd . e x p o v a r i a t e ( C l e r k C l a s s . ServiceRate )
SimPy Example 23 y i e l d hold , s e l f , ServiceTime # s t a r t t o serve
24 C . endService ( ) # end o f s e r v i c e
References 25 G. T o t a l W a i t i n g T i m e += now ( ) − C . A r r i v a l T i m e
26 C l e r k C l a s s . NumDone += 1
27 del C # customer i s gone
28 C l e r k C l a s s . Busy . remove ( s e l f )
29 C l e r k C l a s s . I d l e . append ( s e l f )
79. Simulation Main Loop
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang 1 i f DEBUG:
jjhuang 2 from SimPy . S i m u l a t i o n T r a c e import ∗
3 else :
What is 4 from SimPy . S i m u l a t i o n import ∗
Simulation and 5
When to Use it? 6 def main ( ) :
7 initialize () # I n i t i a l i z e s simulator
What is 8 A = A r r i v a l C l a s s ( name= " A r r i v a l " )
Discrete-Event 9 a c t i v a t e ( A , A . Run ( ) ) # Activate a r r i v a l
Simulation? 10
11 S = C l e r k C l a s s ( name= " C l e r k " )
Example to 12 a c t i v a t e ( S , S . Run ( ) ) # Activate clerk
Illustrate World 13
Views 14 s i m u l a t e ( u n t i l =MaxSimTime ) # S t a r t to simulate !
15
Introduction to 16 i f __name__ == ’ __main__ ’ :
SimPy 17 main ( )
SimPy Example
References
80. Concluding Remarks
Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang
jjhuang
What is Simulation is a powerful tool to study physical problems at
Simulation and
When to Use it? cheaper cost.
What is
Discrete-Event
SimPy provides process-oriendted DES framework
Simulation? to write simulation easily and reasonably fast.
Example to
Illustrate World And SimPy is free!
Views
Introduction to
SimPy
SimPy Example
References
81. References
Introduction to
Discrete-Event
Simulation
Using SimPy [1] R. E. Nance, “A history of discrete event simulation
Chun-Chieh programming languages,” in The second ACM SIGPLAN
Huang
jjhuang conference on History of programming languages, ser.
HOPL-II. New York, NY, USA: ACM, 1993, pp. 149–175.
What is
Simulation and [Online]. Available: http://doi.acm.org/10.1145/154766.155368
When to Use it?
What is [2] J. Banks, J. S. Carson, B. L. Nelson, and D. M. Nicol,
Discrete-Event
Simulation? Discrete-Event System Simulation (5th Edition). Prentice
Example to Hall, 2009.
Illustrate World
Views [3] C++SIM and JavaSim, “http://javasim.codehaus.org/.”
Introduction to
SimPy [4] S. S. Package, “http://simpy.sourceforge.net/.”
SimPy Example
[5] ns-3 Network Simulator, “http://www.nsnam.org/.”
References
[6] N. Matloff, “A discrete-event simulation course based on the
simpy language,” Davis, 2006.
82. Introduction to
Discrete-Event
Simulation
Using SimPy
Chun-Chieh
Huang
jjhuang
What is
Simulation and
When to Use it?
What is
Discrete-Event
Simulation?
Q&A
Example to
Illustrate World
Views
Introduction to
SimPy
SimPy Example
References