开始使用免费开始使用

建模汽车生产线:Python 生成器

您受托构建一个离散事件模型,以帮助优化某汽车生产线。为此,您需要先识别生产线中的主要流程组,分别为:(1) 焊接与喷漆,(2) 装配与测试。每个流程组都包含许多子流程与任务,但目前您只需编写模型的首个高层版本。

既然关键流程组已经确定,接下来需要估计每个流程的平均完成时间。经过调研,您得到:焊接与喷漆为 15 小时,零部件装配与测试为 24 小时。

simpy 包已为您导入。

模型中的时间单位为 小时

本练习是课程的一部分

Python 中的离散事件模拟

查看课程

练习说明

  • 定义名为 car_production_line_gen 的 Python 生成器。
  • 将焊接与喷漆的用时计入生产线流程。
  • 同样,将零部件装配与测试的用时计入流程。
  • 打印当前仿真时间。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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")
编辑并运行代码