汽車組裝線:用 SimPy 加入非決定性事件
這個練習聚焦在使用 SimPy 的非決定性流程。
你會修改汽車組裝線模型的 SimPy 版本,重點是用 SimPy 方法加入相同的決定性事件。
回顧一下,「焊接與噴漆」平均需要 15 小時完成,但此工時上下會各變動 5 小時。同樣地,「零件組裝與測試」平均需要 24 小時完成,但此工時上下會各變動 6 小時。
已為你匯入 SimPy 套件。
本練習屬於課程
Python 的離散事件模擬
練習說明
- 以「焊接與噴漆」流程為例,使用
random.randint()方法根據其新提供的變異性來記錄實際耗時。 - 以「零件組裝與測試」流程為例,使用
random.randint()方法根據其新提供的變異性來記錄實際耗時。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
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)