m1m02530125 Claude Sonnet 4.6 commited on
Commit
083bfe5
·
1 Parent(s): 5c52a9e

fix: フェーズ2(ベストエフォート)にも客数による増員ロジックを適用

Browse files

フェーズ1が制約違反で失敗しフェーズ2に移行する際、
_solve_best_effort に reservation_counts が渡されておらず
客数による増員制約が完全に無視されていたバグを修正。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. optimizer/solver.py +17 -1
optimizer/solver.py CHANGED
@@ -621,7 +621,10 @@ def solve(
621
  logger.info(" [フェーズ2] ベストエフォート求解開始")
622
  best_assignments, best_warnings = _solve_best_effort(
623
  active_employees, date_strs, slots, positions,
624
- req_map, off_map, req_hours, config, shift_constraints
 
 
 
625
  )
626
  _check_warnings(best_assignments, date_strs, best_warnings)
627
  _log_assignment_summary(best_assignments, date_strs)
@@ -687,6 +690,9 @@ def _solve_best_effort(
687
  active_employees, date_strs, slots, positions,
688
  req_map, off_map, req_hours, config: SolverConfig | None = None,
689
  shift_constraints: dict | None = None,
 
 
 
690
  ) -> tuple[list[ShiftAssignment], list[str]]:
691
  """人数・リーダー制約をソフト化してベストエフォートのシフトを生成する"""
692
  import time
@@ -762,7 +768,11 @@ def _solve_best_effort(
762
  STAFF_PENALTY = 1_000_000 # 人数不足ペナルティ(非常に高い)
763
  LEADER_PENALTY = 800_000 # リーダー不足ペナルティ
764
 
 
765
  for ds in date_strs:
 
 
 
766
  for slot in slots:
767
  for pos in positions:
768
  constraint = shift_constraints.get((slot, pos))
@@ -770,6 +780,12 @@ def _solve_best_effort(
770
  continue
771
  min_req = constraint["min"]
772
  max_req = constraint["max"]
 
 
 
 
 
 
773
  staff_vars = [assign[emp.id][ds][slot.value][pos.value] for emp in active_employees]
774
 
775
  # 最大は引き続き絶対制約
 
621
  logger.info(" [フェーズ2] ベストエフォート求解開始")
622
  best_assignments, best_warnings = _solve_best_effort(
623
  active_employees, date_strs, slots, positions,
624
+ req_map, off_map, req_hours, config, shift_constraints,
625
+ reservation_counts=reservation_counts,
626
+ reserv_thresh_b=reserv_thresh_b, reserv_extra_b=reserv_extra_b,
627
+ reserv_thresh_d=reserv_thresh_d, reserv_extra_d=reserv_extra_d,
628
  )
629
  _check_warnings(best_assignments, date_strs, best_warnings)
630
  _log_assignment_summary(best_assignments, date_strs)
 
690
  active_employees, date_strs, slots, positions,
691
  req_map, off_map, req_hours, config: SolverConfig | None = None,
692
  shift_constraints: dict | None = None,
693
+ reservation_counts: dict | None = None,
694
+ reserv_thresh_b: int = 0, reserv_extra_b: int = 0,
695
+ reserv_thresh_d: int = 0, reserv_extra_d: int = 0,
696
  ) -> tuple[list[ShiftAssignment], list[str]]:
697
  """人数・リーダー制約をソフト化してベストエフォートのシフトを生成する"""
698
  import time
 
768
  STAFF_PENALTY = 1_000_000 # 人数不足ペナルティ(非常に高い)
769
  LEADER_PENALTY = 800_000 # リーダー不足ペナルティ
770
 
771
+ rc_map = reservation_counts or {}
772
  for ds in date_strs:
773
+ rc = rc_map.get(ds, {})
774
+ b_count = rc.get("breakfast", 0)
775
+ d_count = rc.get("dinner", 0)
776
  for slot in slots:
777
  for pos in positions:
778
  constraint = shift_constraints.get((slot, pos))
 
780
  continue
781
  min_req = constraint["min"]
782
  max_req = constraint["max"]
783
+ if slot == TimeSlot.BREAKFAST and b_count >= reserv_thresh_b > 0:
784
+ min_req += reserv_extra_b
785
+ max_req = max(max_req, min_req)
786
+ elif slot == TimeSlot.DINNER and d_count >= reserv_thresh_d > 0:
787
+ min_req += reserv_extra_d
788
+ max_req = max(max_req, min_req)
789
  staff_vars = [assign[emp.id][ds][slot.value][pos.value] for emp in active_employees]
790
 
791
  # 最大は引き続き絶対制約