1. Learn
  2. /
  3. Courses
  4. /
  5. Discrete Event Simulation in Python

Exercise

Modeling a petrol station: Python generators

Consider that a client wants to build a gas station, and you have been asked to create a discrete-event model to help determine the optimal number of gas pumps and the size of the common fuel tank used by the pumps. This model requires simulating the cars arriving at the gas station and the stations' resources: the pumps and the fuel tank. In this exercise, we will focus on the following two steps:

Step 1: Create a generator to simulate the arrival of the cars at the gas station, requesting a pump, and refilling the car tanks.

Step 2: Create a generator to check the level of the tank and request a refill tank when needed. Also, the behavior of the refill tank needs to be modeled.

In the next exercise, you will create the SimPy environment, add processes and resources, and run simulations.

The number of gas pumps are limited and simulated using a SimPy resource stored in the variable gas_station_pumps.

Instructions 1/2

undefined XP
    1
    2
  • Request a pump.
  • Yield the pump request.
  • Get the requested fuel from the tank.