0% found this document useful (0 votes)
2 views

BANA7030_DES_Python_Intro

The document provides an overview of discrete-event simulation (DES) using Python, specifically through the SimPy library. It explains key concepts such as entities, generators, processes, and resources, highlighting how simulation models replicate real-world systems and their behaviors. Additionally, it contrasts generators with conventional functions in Python and describes the process-oriented nature of SimPy for modeling DES effectively.

Uploaded by

Baldev Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

BANA7030_DES_Python_Intro

The document provides an overview of discrete-event simulation (DES) using Python, specifically through the SimPy library. It explains key concepts such as entities, generators, processes, and resources, highlighting how simulation models replicate real-world systems and their behaviors. Additionally, it contrasts generators with conventional functions in Python and describes the process-oriented nature of SimPy for modeling DES effectively.

Uploaded by

Baldev Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Discrete-Event Simulation in Python

BANA7030
Denise L. White, PhD MBA

Examples used in the lecture came from this source:


Session 5B : Building a Discrete Event Simulation model using SimPy - YouTube
Value of Simulation
• What is simulation?
– A computer program that acts as an approximate
replication of a process or system
• Why do we use simulation?
– Allow us to view how a system behaves and see how it
reacts to changes in the parameters
Simulation Modeling Basics
• Entities – things flowing through the sequential process in the model
• Generators – the way in which entities enter the model and come into being
• Inter-arrival times – the time between entities being generated
• Activities/Servers – activities that happen to entities
• Activity/Server Time – the amount of time it takes for an activity to happen to an entity
• Resources – things required for activities to take place. May be shared between
activities
• Queues – where entities are held until an activity has capacity and the required
resources to begin
• Sinks – how entities leave the model.
Generators
• What is a Generator?
– Generators are function in python that
remember where they were when control is
passed back. They retain their local state and
can be used for powerful iterations.
Generator vs Conventional
def keep_count_generator(): def conventional_keep_count():
count = 0 count = 0
while True:
while True:
#Add 1 to count
#Add 1 to count count += 1
count += 1 return count
yield count a = conventional_keep_count()
print(a)
my_generator = keep_count_generator() a = conventional_keep_count()
print(a)
print(next(my_generator))
a = conventional_keep_count()
print(next(my_generator))
print(a)
print(next(my_generator)) a = conventional_keep_count()
print(next(my_generator)) print(a)
print(next(my_generator)) a = conventional_keep_count()
Generator will produce values 1, 2,
print(next(my_generator)) 3, 4,… print(a)

Conventional will produce 1, 1, 1, 1,….


Model = Generator_Example
Python Discrete Event Simulation Package

SIMPY
Introduction to SimPy
• Uses Python for DES modeling
• Process-oriented DES language
– Easier to write model
– Proven event manager implementation
– Guarantees order of execution
SimPy Terminology
• Process
– Simulates an entity that evolves over time
– Referred to as a thread
• Resource
– Simulates something to be requested and queued if not
available

https://www.slideshare.net/pycontw/introduction-to-simpy
Basic Concepts
• Modeled with processes that live in an environment
• Processes interact with the environment via events
• Processes are described as generators in Python
• During their lifetime, processes create events and
yield them in order to wait to be triggered

https://simpy.readthedocs.io/en/latest/simpy_intro/index.html
Basic Concepts
• When a process yields an event, the process gets
suspended and resumes when the event is triggered
• An important event type is Timeout. Events of this type are
triggered after an amount of time has passed.
• A Timeout and all other events can be created by calling the
appropriate method of the Environment that the process lives
in. (For example, Environment.timeout())

https://simpy.readthedocs.io/en/latest/simpy_intro/index.html

You might also like