Commit ·
daf9bc1
1
Parent(s): 5ac7c81
fix: INFEASIBLE診断で正社員を考慮するよう修正
Browse files_diagnose_infeasible が req_map のみで可用性チェックしていたため、
シフト希望を提出しない正社員が常に「候補なし」として扱われ
「リーダーが0名」などの誤診断が出ていたバグを修正。
正社員は off_map(休み希望・有休)と fixed_unavailable_dates で
可否を判断するよう修正し、診断メッセージも「希望者」→「出勤可能者」
に改め、リーダー不足時は候補者名も表示するよう強化。
- optimizer/solver.py +23 -10
optimizer/solver.py
CHANGED
|
@@ -748,7 +748,7 @@ def solve(
|
|
| 748 |
else:
|
| 749 |
logger.error(f" [INFEASIBLE/UNKNOWN] status={status_name} → フェーズ2へ移行")
|
| 750 |
# 実行不可能 → 制約違反の診断メッセージを収集
|
| 751 |
-
errs = _diagnose_infeasible(active_employees, date_strs, req_map)
|
| 752 |
for e in errs:
|
| 753 |
logger.error(f" [診断] {e}")
|
| 754 |
|
|
@@ -1244,12 +1244,14 @@ def _diagnose_infeasible(
|
|
| 1244 |
employees: list[Employee],
|
| 1245 |
date_strs: list[str],
|
| 1246 |
req_map: dict,
|
|
|
|
| 1247 |
) -> list[str]:
|
| 1248 |
"""実行不可能の原因を診断してエラーメッセージを返す"""
|
| 1249 |
errors = []
|
| 1250 |
-
from collections import defaultdict
|
| 1251 |
from db import repositories as repo
|
| 1252 |
shift_constraints = repo.get_shift_constraints()
|
|
|
|
|
|
|
| 1253 |
|
| 1254 |
for ds in date_strs:
|
| 1255 |
d = date.fromisoformat(ds)
|
|
@@ -1263,12 +1265,22 @@ def _diagnose_infeasible(
|
|
| 1263 |
if not constraint:
|
| 1264 |
continue
|
| 1265 |
|
| 1266 |
-
|
| 1267 |
-
|
| 1268 |
-
|
| 1269 |
-
if
|
| 1270 |
-
|
| 1271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1272 |
leaders = [e for e in available if e.is_leader(pos.value, slot)]
|
| 1273 |
min_req = constraint["min"]
|
| 1274 |
min_leader = constraint.get("min_leader", 0)
|
|
@@ -1276,12 +1288,13 @@ def _diagnose_infeasible(
|
|
| 1276 |
if len(available) < min_req:
|
| 1277 |
errors.append(
|
| 1278 |
f"❌ {label} {slot.short_label()} {pos.label()}: "
|
| 1279 |
-
f"
|
| 1280 |
)
|
| 1281 |
elif len(leaders) < min_leader:
|
|
|
|
| 1282 |
errors.append(
|
| 1283 |
f"❌ {label} {slot.short_label()} {pos.label()}: "
|
| 1284 |
-
f"リーダーが{len(leaders)}名(必要: {min_leader}名以上)"
|
| 1285 |
)
|
| 1286 |
|
| 1287 |
if not errors:
|
|
|
|
| 748 |
else:
|
| 749 |
logger.error(f" [INFEASIBLE/UNKNOWN] status={status_name} → フェーズ2へ移行")
|
| 750 |
# 実行不可能 → 制約違反の診断メッセージを収集
|
| 751 |
+
errs = _diagnose_infeasible(active_employees, date_strs, req_map, off_map)
|
| 752 |
for e in errs:
|
| 753 |
logger.error(f" [診断] {e}")
|
| 754 |
|
|
|
|
| 1244 |
employees: list[Employee],
|
| 1245 |
date_strs: list[str],
|
| 1246 |
req_map: dict,
|
| 1247 |
+
off_map: dict | None = None,
|
| 1248 |
) -> list[str]:
|
| 1249 |
"""実行不可能の原因を診断してエラーメッセージを返す"""
|
| 1250 |
errors = []
|
|
|
|
| 1251 |
from db import repositories as repo
|
| 1252 |
shift_constraints = repo.get_shift_constraints()
|
| 1253 |
+
if off_map is None:
|
| 1254 |
+
off_map = {}
|
| 1255 |
|
| 1256 |
for ds in date_strs:
|
| 1257 |
d = date.fromisoformat(ds)
|
|
|
|
| 1265 |
if not constraint:
|
| 1266 |
continue
|
| 1267 |
|
| 1268 |
+
available = []
|
| 1269 |
+
for e in employees:
|
| 1270 |
+
# ポジション互換チェック
|
| 1271 |
+
if not (e.can_work_both_positions or e.primary_position is None
|
| 1272 |
+
or e.primary_position.value == pos.value):
|
| 1273 |
+
continue
|
| 1274 |
+
if e.employment_type == EmploymentType.FULL_TIME:
|
| 1275 |
+
# 正社員: off_map と固定休日のみで可否判断
|
| 1276 |
+
if off_map.get((e.id, ds), False) or ds in e.fixed_unavailable_dates:
|
| 1277 |
+
continue
|
| 1278 |
+
available.append(e)
|
| 1279 |
+
else:
|
| 1280 |
+
# アルバイト: req_map で可否判断
|
| 1281 |
+
if req_map.get((e.id, ds, slot.value), False):
|
| 1282 |
+
available.append(e)
|
| 1283 |
+
|
| 1284 |
leaders = [e for e in available if e.is_leader(pos.value, slot)]
|
| 1285 |
min_req = constraint["min"]
|
| 1286 |
min_leader = constraint.get("min_leader", 0)
|
|
|
|
| 1288 |
if len(available) < min_req:
|
| 1289 |
errors.append(
|
| 1290 |
f"❌ {label} {slot.short_label()} {pos.label()}: "
|
| 1291 |
+
f"出勤可能者が{len(available)}名(必要: {min_req}名以上)"
|
| 1292 |
)
|
| 1293 |
elif len(leaders) < min_leader:
|
| 1294 |
+
lnames = ", ".join(e.name for e in leaders) or "なし"
|
| 1295 |
errors.append(
|
| 1296 |
f"❌ {label} {slot.short_label()} {pos.label()}: "
|
| 1297 |
+
f"リーダーが{len(leaders)}名(必要: {min_leader}名以上、候補: {lnames})"
|
| 1298 |
)
|
| 1299 |
|
| 1300 |
if not errors:
|