建構汽車生產線模型: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")