m1m02530125 Claude Sonnet 4.6 commited on
Commit
f07b267
·
1 Parent(s): 570216a

feat: slot_pref_scale - P5 priority is baseline, UI setting scales it

Browse files

SolverConfig.slot_pref_scale controls the strength of the breakfast/
dinner slot assignment priority (P5 penalty). P5 is always active
(hard-coded base values), and the UI slider multiplies the strength:

低 (0.1): 3,000 / 2,000 - allows more mixing
中 (1.0): 30,000 / 20,000 - baseline (current strong preference)
高 (10.0):300,000 /200,000 - very strict separation

Added "朝食/ディナー 分業強度" slider to generate/index.html with
popover explanation. Default is 中 (baseline behavior preserved).

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

optimizer/solver.py CHANGED
@@ -33,6 +33,7 @@ class SolverConfig:
33
  double_penalty_scale: float = 1.0 # 正社員両掛け持ち回避
34
  balance_scale: float = 1.0 # 人員バランス均等化
35
  late_night_scale: float = 1.0 # 深夜勤務分散
 
36
 
37
 
38
  class SolveProgressCallback(cp_model.CpSolverSolutionCallback):
@@ -488,14 +489,13 @@ def solve(
488
  # ダミーで総勤務回数の二乗偏差を線形近似
489
  penalty_terms.append(balance_w * total_worked)
490
 
491
- # P5: スロット別雇用形態優先度
492
- # P1 の人件費コストは 1件あたり ~50,000(5時間×1000×10)のため、
493
- # P5 も同オーダーにしないとソルバーに無視される。
494
- # 朝食:社員配置 +30,000 → PT だけで最低人数を満たせる日は社員不使用
495
- # ディナー:アルバイト配置 +20,000 → 社員を優先、不足時のみ PT
496
- # 人員不足の場合はハード制約(最低人数)がこのペナルティを上回り配置される
497
- BREAKFAST_FT_COST = 30_000
498
- DINNER_PT_COST = 20_000
499
  for emp in active_employees:
500
  for ds in date_strs:
501
  for pos in positions:
 
33
  double_penalty_scale: float = 1.0 # 正社員両掛け持ち回避
34
  balance_scale: float = 1.0 # 人員バランス均等化
35
  late_night_scale: float = 1.0 # 深夜勤務分散
36
+ slot_pref_scale: float = 1.0 # 朝食/ディナー分業(P5基準値のスケール)
37
 
38
 
39
  class SolveProgressCallback(cp_model.CpSolverSolutionCallback):
 
489
  # ダミーで総勤務回数の二乗偏差を線形近似
490
  penalty_terms.append(balance_w * total_worked)
491
 
492
+ # P5: スロット別雇用形態優先度(大前提:優先度設定はこの上に乗る)
493
+ # slot_pref_scale=1.0(中)が基準値。低・高で強弱を調整できる。
494
+ # 基準値は P1 の人件費コスト(~50,000/件)と同オーダーに設定済み。
495
+ BREAKFAST_FT_BASE = 30_000 # 社員が朝食に入る基本コスト
496
+ DINNER_PT_BASE = 20_000 # アルバイトがディナーに入る基本コスト
497
+ BREAKFAST_FT_COST = max(1, int(BREAKFAST_FT_BASE * config.slot_pref_scale))
498
+ DINNER_PT_COST = max(1, int(DINNER_PT_BASE * config.slot_pref_scale))
 
499
  for emp in active_employees:
500
  for ds in date_strs:
501
  for pos in positions:
routes/generate.py CHANGED
@@ -88,6 +88,7 @@ def run():
88
  double_penalty_scale=_scale("double_penalty_scale"),
89
  balance_scale=_scale("balance_scale"),
90
  late_night_scale=_scale("late_night_scale"),
 
91
  )
92
 
93
  # 生成中ステータスに更新してバックグラウンドで実行
 
88
  double_penalty_scale=_scale("double_penalty_scale"),
89
  balance_scale=_scale("balance_scale"),
90
  late_night_scale=_scale("late_night_scale"),
91
+ slot_pref_scale=_scale("slot_pref_scale"),
92
  )
93
 
94
  # 生成中ステータスに更新してバックグラウンドで実行
templates/generate/index.html CHANGED
@@ -95,6 +95,10 @@
95
  'title': '深夜勤務分散',
96
  'body': 'ディナー時間帯(22時以降)の勤務が特定のスタッフに集中しないよう分散させます。「高」にすると深夜シフトが均等に割り振られます。',
97
  },
 
 
 
 
98
  } %}
99
 
100
  {% for key, label in [
@@ -103,6 +107,7 @@
103
  ('double_penalty_scale', '正社員 両掛け持ち回避'),
104
  ('balance_scale', '人員バランス均等化'),
105
  ('late_night_scale', '深夜勤務分散'),
 
106
  ] %}
107
  {% set h = help_texts[key] %}
108
  <div class="mb-3">
 
95
  'title': '深夜勤務分散',
96
  'body': 'ディナー時間帯(22時以降)の勤務が特定のスタッフに集中しないよう分散させます。「高」にすると深夜シフトが均等に割り振られます。',
97
  },
98
+ 'slot_pref_scale': {
99
+ 'title': '朝食/ディナー 分業強度',
100
+ 'body': '朝食はアルバイト中心・ディナーは社員中心という配置ルールの強さを調整します。「中」が基準値です。「高」にするとより厳密に分業され、「低」にすると混合配置が許容されやすくなります。アルバイトが不足する朝食では設定に関わらず社員が補填されます。',
101
+ },
102
  } %}
103
 
104
  {% for key, label in [
 
107
  ('double_penalty_scale', '正社員 両掛け持ち回避'),
108
  ('balance_scale', '人員バランス均等化'),
109
  ('late_night_scale', '深夜勤務分散'),
110
+ ('slot_pref_scale', '朝食/ディナー 分業強度'),
111
  ] %}
112
  {% set h = help_texts[key] %}
113
  <div class="mb-3">