管理結帳佇列
一家服飾店在尖峰時段非常忙碌,顧客常常排隊結帳。現在只有 1 位收銀員,你被要求做一份成本效益分析,判斷需要多少位收銀員,才能盡可能縮短等待時間並提升獲利。
你決定建立一個離散事件模型。你已知:
- 尖峰時段平均每 15 秒會有一位新顧客加入排隊;
- 顧客通常會帶多樣商品,典型介於 1 到 20 件;以及
- 收銀台掃描每件商品平均需要 3 秒,付款通常還要再花 20 秒。
引數 counter 儲存 SimPy 資源,而引數 customer_num 會追蹤顧客編號。
讓我們執行這個模型,計算在不同收銀員人數下,服務 30 位顧客需要多久時間。
本練習屬於課程
Python 的離散事件模擬
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
def customer(env, customer_num, counter):
num_items = random.randint(1, 20)
print(f"Time: {env.now:7.4f} sec | Customer {customer_num:02d} > Joining the queue with {num_items:02d} items!")
# Open the resource counter request
with counter.____() as request:
yield request
print(f"Time: {env.now:7.4f} sec | Customer {customer_num:02d} > Got to cashier!")
time_counter = TIME_PAY + random.randint(1, 20) * TIME_SCAN_PER_ITEM
# Yield the processing time
yield env.____(time_counter)
print(f"Time: {env.now:7.4f} sec | Customer {customer_num:02d} > Finished ")
env = simpy.Environment()
# Create resource
counter = simpy.Resource(env, capacity=____)
env.process(source(env, NEW_CUSTOMERS, INTERVAL_CUSTOMERS, counter))
env.run()