m1m02530125 commited on
Commit
16e8602
·
1 Parent(s): df01c4b

fix: 客数が少ない日は人員配置の最多数を最少数に制限

Browse files

予約客数による増員(extra)が無い日でも、設定上のmax_staffまで
余分にスタッフを配置できてしまい、最少3人で足りる日に4人
配置されるケースがあった。effective_min_max()で増員が無い日は
max=minに制限し、ソルバーが必要以上の人員を割り当てないようにする。

Files changed (2) hide show
  1. optimizer/solver.py +7 -17
  2. utils/reservation.py +19 -0
optimizer/solver.py CHANGED
@@ -10,7 +10,7 @@ from utils.constants import (
10
  LATE_NIGHT_START
11
  )
12
  from utils.solver_logger import logger
13
- from utils.reservation import tiered_extra
14
  from utils.shift_patterns import is_long_breakfast_pattern
15
 
16
 
@@ -346,19 +346,14 @@ def solve(
346
  constraint = shift_constraints.get(key)
347
  if not constraint:
348
  continue
349
- base_min = constraint["min"]
350
- base_max = constraint["max"]
351
  # 予約超過時の増員
352
  if slot == TimeSlot.BREAKFAST:
353
  extra = tiered_extra(b_count, reserv_tiers_b)
354
- if extra:
355
- base_min += extra
356
- base_max = max(base_max, base_min)
357
  elif slot == TimeSlot.DINNER:
358
  extra = tiered_extra(d_count, reserv_tiers_d)
359
- if extra:
360
- base_min += extra
361
- base_max = max(base_max, base_min)
362
  staff_vars = [
363
  assign[emp.id][ds][slot.value][pos.value]
364
  for emp in active_employees
@@ -1141,18 +1136,13 @@ def _solve_best_effort(
1141
  constraint = shift_constraints.get((slot, pos))
1142
  if not constraint:
1143
  continue
1144
- min_req = constraint["min"]
1145
- max_req = constraint["max"]
1146
  if slot == TimeSlot.BREAKFAST:
1147
  extra = tiered_extra(b_count, reserv_tiers_b)
1148
- if extra:
1149
- min_req += extra
1150
- max_req = max(max_req, min_req)
1151
  elif slot == TimeSlot.DINNER:
1152
  extra = tiered_extra(d_count, reserv_tiers_d)
1153
- if extra:
1154
- min_req += extra
1155
- max_req = max(max_req, min_req)
1156
  staff_vars = [assign[emp.id][ds][slot.value][pos.value] for emp in active_employees]
1157
 
1158
  # 最大は引き続き絶対制約
 
10
  LATE_NIGHT_START
11
  )
12
  from utils.solver_logger import logger
13
+ from utils.reservation import tiered_extra, effective_min_max
14
  from utils.shift_patterns import is_long_breakfast_pattern
15
 
16
 
 
346
  constraint = shift_constraints.get(key)
347
  if not constraint:
348
  continue
 
 
349
  # 予約超過時の増員
350
  if slot == TimeSlot.BREAKFAST:
351
  extra = tiered_extra(b_count, reserv_tiers_b)
 
 
 
352
  elif slot == TimeSlot.DINNER:
353
  extra = tiered_extra(d_count, reserv_tiers_d)
354
+ else:
355
+ extra = 0
356
+ base_min, base_max = effective_min_max(constraint, extra)
357
  staff_vars = [
358
  assign[emp.id][ds][slot.value][pos.value]
359
  for emp in active_employees
 
1136
  constraint = shift_constraints.get((slot, pos))
1137
  if not constraint:
1138
  continue
 
 
1139
  if slot == TimeSlot.BREAKFAST:
1140
  extra = tiered_extra(b_count, reserv_tiers_b)
 
 
 
1141
  elif slot == TimeSlot.DINNER:
1142
  extra = tiered_extra(d_count, reserv_tiers_d)
1143
+ else:
1144
+ extra = 0
1145
+ min_req, max_req = effective_min_max(constraint, extra)
1146
  staff_vars = [assign[emp.id][ds][slot.value][pos.value] for emp in active_employees]
1147
 
1148
  # 最大は引き続き絶対制約
utils/reservation.py CHANGED
@@ -16,3 +16,22 @@ def tiered_extra(count: int, tiers: list[tuple[int, int]]) -> int:
16
  if threshold > 0 and count >= threshold:
17
  extra = max(extra, amount)
18
  return extra
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  if threshold > 0 and count >= threshold:
17
  extra = max(extra, amount)
18
  return extra
19
+
20
+
21
+ def effective_min_max(constraint: dict, extra: int) -> tuple[int, int]:
22
+ """
23
+ シフト制約 {"min": int, "max": int, ...} と予約客数による増員数 extra から、
24
+ その日・スロット・ポジションの実効的な最低人数・最大人数を返す。
25
+
26
+ 増員がない(客数が少ない)日は max を min と同じ値に制限し、
27
+ 設定上の max まで余分に人員を配置できないようにする。
28
+ 増員がある日は設定上の max と (min+extra) の大きい方を上限とする。
29
+ """
30
+ base_min = constraint.get("min", 0)
31
+ base_max = constraint.get("max", 0)
32
+ if extra:
33
+ base_min += extra
34
+ base_max = max(base_max, base_min)
35
+ else:
36
+ base_max = base_min
37
+ return base_min, base_max