レストランモデル:テーブル管理と待ち時間の最適化
サンフランシスコの人気エリアでレストランを開くとします。提供できる顧客数を最大化しつつ、初期投資と運用コストを抑えるためには、テーブル数やキッチンの処理能力の決定が非常に重要です。離散事象モデルを使えば、テーブルの稼働状況、顧客の待ち時間、過度な待ち時間で列を離脱する顧客数をシミュレーションし、この投資判断を支援できます。
まずは、テーブルの要求と、待ち時間に応じて待つか離脱するかという顧客の意思決定をシミュレートするジェネレーターを定義しましょう。次の演習では、モデルを構築して実行し、結果を分析します。モデル内の時間単位は分です。
この演習はコースの一部です
Pythonで学ぶ離散事象シミュレーション
演習の手順
- 顧客がレストランに到着したら、テーブル要求を
reqとして開きます。 - ビット和(bitwise-or)演算子を使い、テーブルが空く(
req)か、顧客の我慢時間が切れる(env.timeout(patience))まで待機します。 - 顧客がテーブルを占有する時間(変数
time_at_tablesで与えられます)を yield します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
def customer(env, name, tables):
global customers_served, customers_quiting_waiting
arrive = env.now
# Request a table
with tables.request() as ____:
patience = random.uniform(MIN_PATIENCE, MAX_PATIENCE)
# Wait until a table is free or the customer runs out of patience
results = yield ____ | ____
wait = env.now - arrive
if req in results:
print(f"{env.now:7.4f} {name} > Waited {wait:6.3f} minutes for a table!")
time_at_tables = random.uniform(MIN_SEATING_TIME, MAX_SEATING_TIME)
# Yield the time the table is occupied by the customer
____ env.timeout(time_at_tables)
print(f"{env.now:7.4f} {name} > Finished meal :)")
costumers_served += 1
else:
print(f"{env.now:7.4f} {name} > Gave up waiting and left after waiting {wait:7.4f} minutes :(")
customers_quiting_waiting += 1