Get startedGet started for free

Car Assembly line: adding non-deterministic events with SimPy

This exercise focuses on non-deterministic processes using SimPy.

You'll modify the SimPy version of your car assembly line model, focusing on adding the same deterministic events using SimPy methods.

Recall that "Welding and painting" take an average of 15 hours complete, but that duration varies by five hours (up or down). In turn, "Assembly of parts and testing" took an average of 24 hours to finish, but that duration varies by six hours (up or down)

The SimPy library has been imported for you.

This exercise is part of the course

Discrete Event Simulation in Python

View Course

Exercise instructions

  • Clock-in the duration of the process "Welding and painting", taking into account the new information about its variability using the method random.randint().
  • Clock-in the duration of the process "Assembly of parts and testing_", taking into account the new information about its variability using the method random.randint().

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

def car_production_line(env):
    car_number = 0
    while True:
        car_number += 1

        # Adding process 1: Clock-in time requirement for Welding and Painting
        yield env.____(random.____(10, 20))
        print(f"Time = {env.now:7.4f} | Car {car_number:02d} | Welding and Painting")

        # Adding process 2: Return/yield time after completing the process and print the current time
        yield env.____(random.____(18, 30))
        print(f"Time = {env.now:7.4f} | Car {car_number:02d} | Assembly of parts and Testing")
        print(f"Time = {env.now:7.4f} | Car {car_number:02d} | Car ready for shipping!")

env = simpy.Environment()
env.process(car_production_line(env))
env.run(until=SIMULATION_TIME)
Edit and Run Code