SlideShare a Scribd company logo
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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!
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 )
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
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
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.
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

More Related Content

PDF
Manual del modulo Sympy
PDF
A Peer-to-Peer Simulator
PPT
Chapter3 general principles of discrete event simulation
PPT
S6 l04 analytical and numerical methods of structural analysis
PPTX
Unit 5 general principles, simulation software
PPT
Simulation
PPT
Simulation and Modeling
Manual del modulo Sympy
A Peer-to-Peer Simulator
Chapter3 general principles of discrete event simulation
S6 l04 analytical and numerical methods of structural analysis
Unit 5 general principles, simulation software
Simulation
Simulation and Modeling

Viewers also liked (20)

PPT
Simulation Techniques
PPT
Simulation Powerpoint- Lecture Notes
DOCX
Atm simulation program using python
PDF
ETOS discrete event simulation framework focused on easier team cooperation
PPT
Alopecia
PPT
Alopecia
PPTX
Histopathology of alopecia
PPTX
Androgenetic alopecia
PPT
Queuing analysis
PPTX
Guide to Queuing System
PDF
Operating Systems - Queuing Systems
PPT
14 queuing
PPTX
Female hair loss
PPTX
Unit 6 input modeling problems
PPTX
Unit 1 introduction contd
PPTX
A discrete Event Simulation Model of Asphalt Paving Operations, Ramzi Labban ...
PPTX
Alopecia - scaring & non-scaring type.
Simulation Techniques
Simulation Powerpoint- Lecture Notes
Atm simulation program using python
ETOS discrete event simulation framework focused on easier team cooperation
Alopecia
Alopecia
Histopathology of alopecia
Androgenetic alopecia
Queuing analysis
Guide to Queuing System
Operating Systems - Queuing Systems
14 queuing
Female hair loss
Unit 6 input modeling problems
Unit 1 introduction contd
A discrete Event Simulation Model of Asphalt Paving Operations, Ramzi Labban ...
Alopecia - scaring & non-scaring type.
Ad

Similar to Introduction to Discrete-Event Simulation Using SimPy (20)

PPT
What is sim?ulation
PPTX
Strategy for Social Media MK Plan by Slidesgo.pptx
PPTX
Simulation theory
PDF
Unleashing Real-World Simulations: A Python Tutorial by Avjinder Kaler
PPT
Cs854 lecturenotes01
PDF
PPT
cs1538.ppt
PPTX
Advantages and disadvantages of Simulation
PDF
O2DESUltra - a new appoach to acceleration simulation-opimization using machi...
PPTX
Basics of modeling and simulation
PPT
Simulation with ARENA Chapter 1: What is Simulation?
PPTX
simulation chapter simulation chapter 1 info
PPTX
Introduction to simulation and modeling
PPTX
Velocity 2015: Building Self-Healing Systems
PPTX
Velocity 2015 building self healing systems (slide share version)
PDF
Simulation and modeling
PDF
SLAM Zero to One
PPTX
SIMULATION
PDF
4_5821003798000177081.pdf
PDF
Manual Simpy
What is sim?ulation
Strategy for Social Media MK Plan by Slidesgo.pptx
Simulation theory
Unleashing Real-World Simulations: A Python Tutorial by Avjinder Kaler
Cs854 lecturenotes01
cs1538.ppt
Advantages and disadvantages of Simulation
O2DESUltra - a new appoach to acceleration simulation-opimization using machi...
Basics of modeling and simulation
Simulation with ARENA Chapter 1: What is Simulation?
simulation chapter simulation chapter 1 info
Introduction to simulation and modeling
Velocity 2015: Building Self-Healing Systems
Velocity 2015 building self healing systems (slide share version)
Simulation and modeling
SLAM Zero to One
SIMULATION
4_5821003798000177081.pdf
Manual Simpy
Ad

More from pycontw (15)

PDF
Network Security and Analysis with Python
PDF
Python on FreeBSD
ODP
讓 Python Script 擁有圖形化介面的簡單方法
PDF
CyberLink Meets Python
PDF
PyKinect: Body Iteration Application Development Using Python
PDF
Developing Python Apps on Windows Azure
PDF
Qt Quick GUI Programming with PySide
PDF
STAF 在自動化測試上的延伸應用 -- TMSTAF (TrendMicro STAF)
PDF
Grid Job Management
PDF
Small Python Tools for Software Release Engineering
PDF
Python and Startup
PPTX
Panoramic Video in Environmental Monitoring Software Development and Applica...
PDF
那些年 Python 攻佔了 GIS / The Year Python Takes Over GIS
PDF
Python and the Web
PDF
Large-scale Array-oriented Computing with Python
Network Security and Analysis with Python
Python on FreeBSD
讓 Python Script 擁有圖形化介面的簡單方法
CyberLink Meets Python
PyKinect: Body Iteration Application Development Using Python
Developing Python Apps on Windows Azure
Qt Quick GUI Programming with PySide
STAF 在自動化測試上的延伸應用 -- TMSTAF (TrendMicro STAF)
Grid Job Management
Small Python Tools for Software Release Engineering
Python and Startup
Panoramic Video in Environmental Monitoring Software Development and Applica...
那些年 Python 攻佔了 GIS / The Year Python Takes Over GIS
Python and the Web
Large-scale Array-oriented Computing with Python

Recently uploaded (20)

PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Approach and Philosophy of On baking technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Spectroscopy.pptx food analysis technology
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
Teaching material agriculture food technology
PPTX
A Presentation on Artificial Intelligence
PDF
cuic standard and advanced reporting.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Assigned Numbers - 2025 - Bluetooth® Document
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation_ Review paper, used for researhc scholars
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The Rise and Fall of 3GPP – Time for a Sabbatical?
Approach and Philosophy of On baking technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Spectroscopy.pptx food analysis technology
A comparative analysis of optical character recognition models for extracting...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
A Presentation on Artificial Intelligence
cuic standard and advanced reporting.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The AUB Centre for AI in Media Proposal.docx
Per capita expenditure prediction using model stacking based on satellite ima...

Introduction to 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