Modeling a car production line: Python generators
You have been asked to build a discrete-event model to help optimize a car production line. To get started, you had to identify the main groups of processes involved in the production line. These are (1) welding and painting and (2) assembly and testing. Of course, each of these groups of processes involves many sub-processes and tasks, but for now, you are focused on coding a first, high-level version of the model.
Since you have already identified the critical groups of processes, it's time to determine the average time each process takes to complete. You did your research and came up with 15 hours for welding and painting and 24 hours for assembling parts and testing.
The simpy
package has been imported for you.
Time in the model is in hours.
This is a part of the course
“Discrete Event Simulation in Python”
Exercise instructions
- Define the Python generator with the name
car_production_line_gen
. - Clock the time requirement for welding and panting into the production line.
- Similarly, clock in the time taken to complete assembly of parts and testing.
- Print the current simulation time.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Defining a Generator that includes the processes
def ____(env):
car_number = 0
while True:
car_number += 1
# Process 1: Clock the time requirement for welding and painting
yield env.____(____)
print(f"Car {car_number}: Welding and painting (completed) => time = {env.now}")
# Process 2: Clock in time for process 2 and yield it
____
print(f"Car {car_number}: Assembly of parts and testing (completed) => time = {env.now}")
# Print car ready for shipment
print(f"Car {car_number}: Car ready for shipping! time = {env.____} hours")