None Notebook

This notebook contains material from cbe30338-2021; content is available on Github.

< 7.0 Discrete Event Systems | Contents | Tag Index | 7.2 Agent Based Models >

Open in Colab

Download

7.1 Introduction to Simpy

Simpy is a Python library for the simulation of systems that interact through discrete events. There are two essential to using Simpy:

  1. The simulation environment that manages the simulation.
  2. Processes you create to model system behavior.

This notebook introduces these concepts using a toy example.

7.1.1 Creating a simulation environment

A simulation environment is created with simpy.Environment(). The resulting object provides a collection of methods for setting and controlling a simulation.

That's all it takes to create and run a simulation. But we didn't give the simulation anything to do, so there are no details to report.

7.1.2 Creating simulation processes

System behavior is modeled as a system of Simpy processes. Processes are implemented with the Python yield statement, and attached to the simulation environment with env.process().

A process communicates with the simulation environment through the yield statement. The yield statement sends an event back to the simulation environment. The the passage of time is modeled with env.timeout(delay) event.

The generator may include parameters to create unique instances. This is the foundation of "agent-based" modeling.

Note that the simulation environment correctly orders the events!

7.1.3 Events

Simpy includes many different event types that are managed by the simulation environment. The env.timeout(delay) demonstrated above is a mainstay in Simpy models. Many applications require nothing more.

What we observe is that the simulation environment is scheduling tasks and executng them in a time ordered sequence, not the order in which they are created.


Study Question: Use simpy.AnyOf(env, events) to produce a message when the first process has completed.


7.1.4 Ready to Roomba

7.1.5 Chemotaxis

< 7.0 Discrete Event Systems | Contents | Tag Index | 7.2 Agent Based Models >

Open in Colab

Download