Skip to content

Introduction To DES With Simpy

Jessi Lanum edited this page Jun 16, 2023 · 2 revisions

Simpy Overview

For this program, we use Simpy, a discrete-event simulation (DES) framework for Python. In normal speak:

  • We tell the computer what to do in the programming language Python.
  • We tell Python how to do discrete-event simulation with Simpy.

Simpy Components

Simpy needs to following things in order to create a system.

  • Simulation environment
  • Resource definitions
  • Generator
  • System

Simpy needs the additional following things to run the system.

  • Model definition
  • Model process
  • Run parameters

To Create A System

Example

intro_to_des_with_simpy_create

Here we can see all the components described in the first list. def __init__(self):means that every time the simulation runs, these things will initialize. In other words, each simulation is a fresh instance. Each fresh instance needs to be told what is true about itself each time.

Each time, we specify that self.env (aka System.env) is a Simpy environment. Then we define what resources are in the environment.

Next, we have a function that acts as our generator. This function creates a fresh Marine, and plunks them into the triage system.

Lastly, we have the system itself, represented as the function triage.

To Run A System

Example

intro_to_des_with_simpy_run

Here we can see all the components described in the second list. We tell Simpy that the model is our System class. We specify that the process we are simulating is the marine_generator. Remember, the marine_generator creates a Marine and then pushes them through the triage system. Lastly, we tell it to run until the set amount of runs specified by our beginning variables has completed.

Important note here, your starting process (model.env.process(model.marine_generator())) is a generator. If you wanted to make your Simpy simulation more complicated, you can have your generator make your entity, and start them in the system, like triage. But then within the triage function, you could call another Simpy process... Which could call another... Simpy has the ability to model both abstracted and detailed systems due to this ability to continuously break things apart.