Commit ·
a300abd
1
Parent(s): 26daa9f
社保加入PTの「9時間未満の希望」をハード禁止からソフト制約に緩和(Issue #7拡張)
Browse files従来はSOCIAL_INSURANCE_MIN_HOURS(9h)未満の希望は出勤日が無くなり、
社会保険加入PTでも8h未満の希望を出すと丸ごと割当不可になっていた。
従業員ごとの新設定 si_allow_short_shift をONにすると、9時間未満の
希望のみハード禁止からSI_SHORT_SHIFT_PENALTY(100,000)のソフト制約に
変わり、希望提出が無い日は従来通りハード禁止のまま維持される。
EXPLICIT_PREF_PENALTY(200,000) > SI_SHORT_SHIFT_PENALTY(100,000)
> SI_PREF_PENALTY(50,000) の関係を保つことで、明示希望は割当を
優先しつつ、社保加入者優先や人員不足対応の優先度は変えない。
Files changed (6)
381 unmodified lines382383384385386387381 unmodified lines("employees", "kitchen_skill_dinner", "TEXT NOT NULL DEFAULT 'beginner'"),("reservation_counts", "is_special_day", "INTEGER NOT NULL DEFAULT 0"),("schedule_periods", "google_form_id", "TEXT"),]_INDEXES = [381 unmodified lines382383384385386387388381 unmodified lines("employees", "kitchen_skill_dinner", "TEXT NOT NULL DEFAULT 'beginner'"),("reservation_counts", "is_special_day", "INTEGER NOT NULL DEFAULT 0"),("schedule_periods", "google_form_id", "TEXT"),("employees", "si_allow_short_shift", "INTEGER NOT NULL DEFAULT 0"),]_INDEXES = [
58 unmodified lines596061626364656667686970717273747576125 unmodified lines20220320420520620710 unmodified lines21821922022122222311 unmodified lines23523623723823924058 unmodified linesavail_b = int(emp.always_available_breakfast)avail_d = int(emp.always_available_dinner)si = int(emp.has_social_insurance)if emp.id is None:# 末尾に追加されるよう MAX(display_order)+1 をセットrow = conn.execute("SELECT COALESCE(MAX(display_order), -1) AS max_order FROM employees").fetchone()next_order = (row["max_order"] if row else -1) + 1emp.id = conn.execute_insert("INSERT INTO employees (name, employment_type, hall_skill_breakfast, hall_skill_dinner, kitchen_skill_breakfast, kitchen_skill_dinner, primary_position, output_position, primary_timeslot, can_work_both_positions, can_open, can_cleanup, always_available_breakfast, always_available_dinner, hourly_wage, has_social_insurance, is_active, display_order) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",(emp.name, emp.employment_type.value, emp.hall_skill_breakfast.value, emp.hall_skill_dinner.value, emp.kitchen_skill_breakfast.value, emp.kitchen_skill_dinner.value, pp, op, pt, both, opn, cln, avail_b, avail_d, emp.hourly_wage, si, 1, next_order))else:conn.execute("UPDATE employees SET name=?, employment_type=?, hall_skill_breakfast=?, hall_skill_dinner=?, kitchen_skill_breakfast=?, kitchen_skill_dinner=?, primary_position=?, output_position=?, primary_timeslot=?, can_work_both_positions=?, can_open=?, can_cleanup=?, always_available_breakfast=?, always_available_dinner=?, hourly_wage=?, has_social_insurance=?, is_active=? WHERE id=?",(emp.name, emp.employment_type.value, emp.hall_skill_breakfast.value, emp.hall_skill_dinner.value, emp.kitchen_skill_breakfast.value, emp.kitchen_skill_dinner.value, pp, op, pt, both, opn, cln, avail_b, avail_d, emp.hourly_wage, si, int(emp.is_active), emp.id))conn.commit()conn.close()125 unmodified linesalways_available_dinner=bool(row["always_available_dinner"]) if "always_available_dinner" in keys else False,hourly_wage=int(row["hourly_wage"]) if "hourly_wage" in keys and row["hourly_wage"] else 0,has_social_insurance=bool(row["has_social_insurance"]) if "has_social_insurance" in keys else False,is_active=bool(row["is_active"]),)10 unmodified linesavail_d_val = bool(row["always_available_dinner"]) if "always_available_dinner" in keys else Falsewage_val = int(row["hourly_wage"]) if "hourly_wage" in keys and row["hourly_wage"] else 0si_val = bool(row["has_social_insurance"]) if "has_social_insurance" in keys else Falsereturn Employee(id=row["id"],name=row["name"],11 unmodified linesalways_available_dinner=avail_d_val,hourly_wage=wage_val,has_social_insurance=si_val,primary_timeslot=TimeSlot(pt_val) if pt_val else None,is_active=bool(row["is_active"]),)58 unmodified lines59606162636465666768697071727374757677125 unmodified lines20320420520620720820910 unmodified lines22022122222322422522611 unmodified lines23823924024124224324458 unmodified linesavail_b = int(emp.always_available_breakfast)avail_d = int(emp.always_available_dinner)si = int(emp.has_social_insurance)si_short = int(emp.si_allow_short_shift)if emp.id is None:# 末尾に追加されるよう MAX(display_order)+1 をセットrow = conn.execute("SELECT COALESCE(MAX(display_order), -1) AS max_order FROM employees").fetchone()next_order = (row["max_order"] if row else -1) + 1emp.id = conn.execute_insert("INSERT INTO employees (name, employment_type, hall_skill_breakfast, hall_skill_dinner, kitchen_skill_breakfast, kitchen_skill_dinner, primary_position, output_position, primary_timeslot, can_work_both_positions, can_open, can_cleanup, always_available_breakfast, always_available_dinner, hourly_wage, has_social_insurance, si_allow_short_shift, is_active, display_order) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",(emp.name, emp.employment_type.value, emp.hall_skill_breakfast.value, emp.hall_skill_dinner.value, emp.kitchen_skill_breakfast.value, emp.kitchen_skill_dinner.value, pp, op, pt, both, opn, cln, avail_b, avail_d, emp.hourly_wage, si, si_short, 1, next_order))else:conn.execute("UPDATE employees SET name=?, employment_type=?, hall_skill_breakfast=?, hall_skill_dinner=?, kitchen_skill_breakfast=?, kitchen_skill_dinner=?, primary_position=?, output_position=?, primary_timeslot=?, can_work_both_positions=?, can_open=?, can_cleanup=?, always_available_breakfast=?, always_available_dinner=?, hourly_wage=?, has_social_insurance=?, si_allow_short_shift=?, is_active=? WHERE id=?",(emp.name, emp.employment_type.value, emp.hall_skill_breakfast.value, emp.hall_skill_dinner.value, emp.kitchen_skill_breakfast.value, emp.kitchen_skill_dinner.value, pp, op, pt, both, opn, cln, avail_b, avail_d, emp.hourly_wage, si, si_short, int(emp.is_active), emp.id))conn.commit()conn.close()125 unmodified linesalways_available_dinner=bool(row["always_available_dinner"]) if "always_available_dinner" in keys else False,hourly_wage=int(row["hourly_wage"]) if "hourly_wage" in keys and row["hourly_wage"] else 0,has_social_insurance=bool(row["has_social_insurance"]) if "has_social_insurance" in keys else False,si_allow_short_shift=bool(row["si_allow_short_shift"]) if "si_allow_short_shift" in keys else False,is_active=bool(row["is_active"]),)10 unmodified linesavail_d_val = bool(row["always_available_dinner"]) if "always_available_dinner" in keys else Falsewage_val = int(row["hourly_wage"]) if "hourly_wage" in keys and row["hourly_wage"] else 0si_val = bool(row["has_social_insurance"]) if "has_social_insurance" in keys else Falsesi_short_val = bool(row["si_allow_short_shift"]) if "si_allow_short_shift" in keys else Falsereturn Employee(id=row["id"],name=row["name"],11 unmodified linesalways_available_dinner=avail_d_val,hourly_wage=wage_val,has_social_insurance=si_val,si_allow_short_shift=si_short_val,primary_timeslot=TimeSlot(pt_val) if pt_val else None,is_active=bool(row["is_active"]),)
21 unmodified lines22232425262721 unmodified linesprimary_timeslot: Optional[TimeSlot] = None # None = どちらでも可hourly_wage: int = 0has_social_insurance: bool = Falseis_active: bool = Truedef skill_for(self, position: str, time_slot: TimeSlot) -> SkillLevel:21 unmodified lines2223242526272821 unmodified linesprimary_timeslot: Optional[TimeSlot] = None # None = どちらでも可hourly_wage: int = 0has_social_insurance: bool = Falsesi_allow_short_shift: bool = False # True = 社保加入でも9時間未満の希望を割当対象にする(ソフト制約)is_active: bool = Truedef skill_for(self, position: str, time_slot: TimeSlot) -> SkillLevel:
38 unmodified lines394041424344255 unmodified lines3003013023033043053063073084 unmodified lines313314315316317318319320321322303 unmodified lines62662762862963063165 unmodified lines697698699700701702703704705706707708709710711712713714715716289 unmodified lines1006100710081009101010111012101310141015101625 unmodified lines1042104310441045104610471 unmodified line10491050105110521053105410551 unmodified line10571058105910601061106221 unmodified lines108410851086108710881089109010911092109316 unmodified lines111011111112111311141115133 unmodified lines1249125012511252125312541255125612571258125912601261126212631264126534 unmodified lines13001301130213031304130538 unmodified lines# 最適値とのギャップがこの割合以内なら探索を打ち切る(Issue #48)RELATIVE_GAP_LIMIT = 0.01def _solver_workers() -> int:"""CP-SATの並列探索ワーカー数を返す(Issue #48)。255 unmodified lineslogger.info("-" * 60)logger.info("[従業員DBダンプ] 本番DBから読み込んだ全従業員情報")logger.info(f" {'ID':>4} {'名前':<12} {'雇用':>5} {'H/B':>6} {'H/D':>6} {'K/B':>6} {'K/D':>6} "f"{'主担当':>8} {'両P':>3} {'おまB':>4} {'おまD':>4} {'社保':>3} {'時給':>5}")logger.info(f" {'-'*4} {'-'*12} {'-'*5} {'-'*6} {'-'*6} {'-'*6} {'-'*6} "f"{'-'*8} {'-'*3} {'-'*4} {'-'*4} {'-'*3} {'-'*5}")for e in active_employees:hb = e.hall_skill_breakfast.value if hasattr(e, 'hall_skill_breakfast') else '?'hd = e.hall_skill_dinner.value if hasattr(e, 'hall_skill_dinner') else '?'4 unmodified linesomab = '○' if e.always_available_breakfast else '×'omad = '○' if e.always_available_dinner else '×'si = '○' if e.has_social_insurance else '×'wage = getattr(e, 'hourly_wage', 0) or 0emp_type = 'FT' if e.employment_type == EmploymentType.FULL_TIME else 'PT'logger.info(f" {e.id:>4} {e.name:<12} {emp_type:>5} {hb:>6} {hd:>6} {kb:>6} {kd:>6} "f"{pp:>8} {both:>3} {omab:>4} {omad:>4} {si:>3} {wage:>5}")logger.info("-" * 60)# DB から制約・予約客数・アプリ設定を読み込む303 unmodified linesand not (emp.employment_type != EmploymentType.FULL_TIMEand emp.has_social_insuranceand (req_hours.get((emp.id, ds, TimeSlot.BREAKFAST.value)) or 0) < SOCIAL_INSURANCE_MIN_HOURS)]65 unmodified lines# 実働8h + 法定休憩1h = 総拘束9h 以上のパターンのみ割当可とする。# 例: 5:45〜14:45(b_long = 9h) → 実働8h → 割当可# 6:30〜11:30(b_std = 5h) → 実働4h → 割当不可for emp in active_employees:if emp.employment_type == EmploymentType.FULL_TIME or not emp.has_social_insurance:continuefor ds in date_strs:for slot in slots:dur = req_hours.get((emp.id, ds, slot.value))if dur is None or dur < SOCIAL_INSURANCE_MIN_HOURS:for pos in positions:model.add(assign[emp.id][ds][slot.value][pos.value] == 0)# ── ソフト制約(ペナルティ最小化) ──────────────────────────────────penalty_terms = []# P1: 人件費最小化 = 実勤務時間を最小化(パターン別の時間を使���)DEFAULT_SLOT_HOURS = {TimeSlot.BREAKFAST: 5.0, TimeSlot.DINNER: 6.0}for emp in active_employees:289 unmodified linesassigned_b = defaultdict(int)assigned_d = defaultdict(int)for a in assignments:if a.time_slot == TimeSlot.BREAKFAST:assigned_b[a.employee_id] += 1else:assigned_d[a.employee_id] += 1# ── リーダー要件チェック ────────────────────────────────────────────logger.info(" [リーダー要件チェック]")25 unmodified linessi_assigned = 0; si_req_8h = 0; si_emps_count = 0non_si_assigned = 0; non_si_emps_count = 0for emp in sorted(pt_emps, key=lambda e: (not e.has_social_insurance, e.name)):# 希望提出日数1 unmodified linereq_d_days = [ds for ds in date_strs if req_map.get((emp.id, ds, TimeSlot.DINNER.value))]# SI加入者: 8h互換パターン数(割当可能な日数)h8_count = 0h8_blocked = []if emp.has_social_insurance:for ds in date_strs:for slot in slots:1 unmodified lineh = req_hours.get((emp.id, ds, slot.value), DEFAULT_SLOT_HOURS[slot])if h >= SOCIAL_INSURANCE_MIN_HOURS:h8_count += 1else:h8_blocked.append(f"{ds}({h}h)")# リーダー能力21 unmodified linesif emp.has_social_insurance:if not req_b_days and not req_d_days:notes.append("希望未提出→全日ブロック")elif h8_count == 0 and (req_b_days or req_d_days):notes.append("8h希望ゼロ→全日ブロック")elif h8_blocked:notes.append(f"8h非該当{len(h8_blocked)}日ブロック")si_assigned += total_assignedsi_req_8h += h8_countsi_emps_count += 116 unmodified linesif si_req_8h == 0 and si_emps_count > 0:logger.warning(" ⚠️ 社保加入PT全員が8h希望を提出していません。""8時間のシフトパターンを提出するか、おまかせ(朝食・ディナー両方)で8hを設定してください。")def _log_assignment_summary(assignments, date_strs):133 unmodified linesmodel.add(worked_b + worked_d <= 1)# 社会保険加入アルバイトは、出勤する場合は必ず実働8時間勤務になるようハード制約(Issue #7)# 総拘束9h以上(実働8h + 休憩1h)のパターンのみ割当可SOCIAL_INSURANCE_MIN_HOURS = 9.0for emp in active_employees:if emp.employment_type == EmploymentType.FULL_TIME or not emp.has_social_insurance:continuefor ds in date_strs:for slot in slots:dur = req_hours.get((emp.id, ds, slot.value))if dur is None or dur < SOCIAL_INSURANCE_MIN_HOURS:for pos in positions:model.add(assign[emp.id][ds][slot.value][pos.value] == 0)# 日をまたいだ朝食⇄ディナーの連続勤務を禁止(休息時間確保のハード制約 / Issue #8)for emp in active_employees:34 unmodified linesSTAFF_PENALTY = 1_000_000 # 人数不足ペナルティ(非常に高い)LEADER_PENALTY = 800_000 # リーダー不足ペナルティrc_map = reservation_counts or {}for ds in date_strs:rc = rc_map.get(ds, {})38 unmodified lines394041424344454647484950515253255 unmodified lines3093103113123133143153163174 unmodified lines322323324325326327328329330331332303 unmodified lines63663763863964064164265 unmodified lines708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743289 unmodified lines103310341035103610371038103910401041104210431044104525 unmodified lines10711072107310741075107610771 unmodified line107910801081108210831084108510861 unmodified line1088108910901091109210931094109521 unmodified lines11171118111911201121112211231124112511261127112811291130113116 unmodified lines114811491150115111521153115411551156133 unmodified lines129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131734 unmodified lines135213531354135513561357135813591360136138 unmodified lines# 最適値とのギャップがこの割合以内なら探索を打ち切る(Issue #48)RELATIVE_GAP_LIMIT = 0.01# 社保加入アルバイトで「9時間未満の希望でも割当対象にする」設定の人に課す# 短時間勤務ペナルティ(Issue #7拡張)。# SI_PREF_PENALTY(50,000)より重く、EXPLICIT_PREF_PENALTY(200,000)より軽くすることで、# 「短時間でも本人の希望を割当てる」(P1人件費+本ペナルティ ≈ 150,000) が# 「明示希望を不履行にする」(200,000)より安くなり、希望が優先的に拾われる。# 一方、人員/リーダー不足ペナルティ(800,000〜1,000,000)よりは十分小さく、# 不足解消のための割当にも使われる。SI_SHORT_SHIFT_PENALTY = 100_000def _solver_workers() -> int:"""CP-SATの並列探索ワーカー数を返す(Issue #48)。255 unmodified lineslogger.info("-" * 60)logger.info("[従業員DBダンプ] 本番DBから読み込んだ全従業員情報")logger.info(f" {'ID':>4} {'名前':<12} {'雇用':>5} {'H/B':>6} {'H/D':>6} {'K/B':>6} {'K/D':>6} "f"{'主担当':>8} {'両P':>3} {'おまB':>4} {'おまD':>4} {'社保':>3} {'SI短':>4} {'時給':>5}")logger.info(f" {'-'*4} {'-'*12} {'-'*5} {'-'*6} {'-'*6} {'-'*6} {'-'*6} "f"{'-'*8} {'-'*3} {'-'*4} {'-'*4} {'-'*3} {'-'*4} {'-'*5}")for e in active_employees:hb = e.hall_skill_breakfast.value if hasattr(e, 'hall_skill_breakfast') else '?'hd = e.hall_skill_dinner.value if hasattr(e, 'hall_skill_dinner') else '?'4 unmodified linesomab = '○' if e.always_available_breakfast else '×'omad = '○' if e.always_available_dinner else '×'si = '○' if e.has_social_insurance else '×'si_short = '○' if e.si_allow_short_shift else '×'wage = getattr(e, 'hourly_wage', 0) or 0emp_type = 'FT' if e.employment_type == EmploymentType.FULL_TIME else 'PT'logger.info(f" {e.id:>4} {e.name:<12} {emp_type:>5} {hb:>6} {hd:>6} {kb:>6} {kd:>6} "f"{pp:>8} {both:>3} {omab:>4} {omad:>4} {si:>3} {si_short:>4} {wage:>5}")logger.info("-" * 60)# DB から制約・予約客数・アプリ設定を読み込む303 unmodified linesand not (emp.employment_type != EmploymentType.FULL_TIMEand emp.has_social_insuranceand not emp.si_allow_short_shiftand (req_hours.get((emp.id, ds, TimeSlot.BREAKFAST.value)) or 0) < SOCIAL_INSURANCE_MIN_HOURS)]65 unmodified lines# 実働8h + 法定休憩1h = 総拘束9h 以上のパターンのみ割当可とする。# 例: 5:45〜14:45(b_long = 9h) → 実働8h → 割当可# 6:30〜11:30(b_std = 5h) → 実働4h → 割当不可# ただし si_allow_short_shift=True の従業員は、希望提出はあるが9時間未満の場合に限り# ハード禁止ではなくソフト制約(SI_SHORT_SHIFT_PENALTY)に緩和する(Issue #7拡張)。# 希望自体が未提出(dur is None)の日は変わらずハード禁止。si_short_shift_terms = []for emp in active_employees:if emp.employment_type == EmploymentType.FULL_TIME or not emp.has_social_insurance:continuefor ds in date_strs:for slot in slots:dur = req_hours.get((emp.id, ds, slot.value))if dur is None:for pos in positions:model.add(assign[emp.id][ds][slot.value][pos.value] == 0)elif dur < SOCIAL_INSURANCE_MIN_HOURS:if emp.si_allow_short_shift:si_short_shift_terms.append(sum(assign[emp.id][ds][slot.value][pos.value] for pos in positions))else:for pos in positions:model.add(assign[emp.id][ds][slot.value][pos.value] == 0)# ── ソフト制約(ペナルティ最小化) ──────────────────────────────────penalty_terms = []# P0: 社保加入・短時間勤務許可者が9時間未満の希望で割当された場合のペナルティ(Issue #7拡張)for term in si_short_shift_terms:penalty_terms.append(SI_SHORT_SHIFT_PENALTY * term)# P1: 人件費最小化 = 実勤務時間を最小化(パターン別の時間を使���)DEFAULT_SLOT_HOURS = {TimeSlot.BREAKFAST: 5.0, TimeSlot.DINNER: 6.0}for emp in active_employees:289 unmodified linesassigned_b = defaultdict(int)assigned_d = defaultdict(int)assigned_set: set[tuple[int, str, str]] = set()for a in assignments:if a.time_slot == TimeSlot.BREAKFAST:assigned_b[a.employee_id] += 1else:assigned_d[a.employee_id] += 1assigned_set.add((a.employee_id, a.date, a.time_slot.value))# ── リーダー要件チェック ────────────────────────────────────────────logger.info(" [リーダー要件チェック]")25 unmodified linessi_assigned = 0; si_req_8h = 0; si_emps_count = 0non_si_assigned = 0; non_si_emps_count = 0si_short_total_penalty = 0for emp in sorted(pt_emps, key=lambda e: (not e.has_social_insurance, e.name)):# 希望提出日数1 unmodified linereq_d_days = [ds for ds in date_strs if req_map.get((emp.id, ds, TimeSlot.DINNER.value))]# SI加入者: 8h互換パターン数(割当可能な日数)h8_count = 0h8_blocked = [] # 9h未満で割当されなかった日h8_short_assigned = [] # si_allow_short_shift により9h未満でも割当された日if emp.has_social_insurance:for ds in date_strs:for slot in slots:1 unmodified lineh = req_hours.get((emp.id, ds, slot.value), DEFAULT_SLOT_HOURS[slot])if h >= SOCIAL_INSURANCE_MIN_HOURS:h8_count += 1elif emp.si_allow_short_shift and (emp.id, ds, slot.value) in assigned_set:h8_short_assigned.append(f"{ds}({h}h)")else:h8_blocked.append(f"{ds}({h}h)")# リーダー能力21 unmodified linesif emp.has_social_insurance:if not req_b_days and not req_d_days:notes.append("希望未提出→全日ブロック")elif h8_count == 0 and not h8_short_assigned and (req_b_days or req_d_days):notes.append("8h希望ゼロ→全日ブロック")else:if h8_short_assigned:short_pen = SI_SHORT_SHIFT_PENALTY * len(h8_short_assigned)notes.append(f"9h未満希望{len(h8_short_assigned)}日を短時間勤務許可で割当(ペナ{short_pen:,})")si_short_total_penalty += short_penif h8_blocked:notes.append(f"8h非該当{len(h8_blocked)}日ブロック")si_assigned += total_assignedsi_req_8h += h8_countsi_emps_count += 116 unmodified linesif si_req_8h == 0 and si_emps_count > 0:logger.warning(" ⚠️ 社保加入PT全員が8h希望を提出していません。""8時間のシフトパターンを提出するか、おまかせ(朝食・ディナー両方)で8hを設定してください。")if si_short_total_penalty:logger.info(f" 短時間勤務許可による9h未満割当ペナルティ計={si_short_total_penalty:,}"f"(SI_SHORT_SHIFT_PENALTY={SI_SHORT_SHIFT_PENALTY:,}/件)")def _log_assignment_summary(assignments, date_strs):133 unmodified linesmodel.add(worked_b + worked_d <= 1)# 社会保険加入アルバイトは、出勤する場合は必ず実働8時間勤務になるようハード制約(Issue #7)# 総拘束9h以上(実働8h + 休憩1h)のパターンのみ割当可。# si_allow_short_shift=True の従業員は、希望提出はあるが9時間未満の場合に限り# ハード禁止ではなくソフト制約(SI_SHORT_SHIFT_PENALTY)に緩和する(Issue #7拡張)。SOCIAL_INSURANCE_MIN_HOURS = 9.0si_short_shift_terms = []for emp in active_employees:if emp.employment_type == EmploymentType.FULL_TIME or not emp.has_social_insurance:continuefor ds in date_strs:for slot in slots:dur = req_hours.get((emp.id, ds, slot.value))if dur is None:for pos in positions:model.add(assign[emp.id][ds][slot.value][pos.value] == 0)elif dur < SOCIAL_INSURANCE_MIN_HOURS:if emp.si_allow_short_shift:si_short_shift_terms.append(sum(assign[emp.id][ds][slot.value][pos.value] for pos in positions))else:for pos in positions:model.add(assign[emp.id][ds][slot.value][pos.value] == 0)# 日をまたいだ朝食⇄ディナーの連続勤務を禁止(休息時間確保のハード制約 / Issue #8)for emp in active_employees:34 unmodified linesSTAFF_PENALTY = 1_000_000 # 人数不足ペナルティ(非常に高い)LEADER_PENALTY = 800_000 # リーダー不足ペナルティ# P0: 社保加入・短時間勤務許可者が9時間未満の希望で割当された場合のペナルティ(Issue #7拡張)for term in si_short_shift_terms:penalty_terms.append(SI_SHORT_SHIFT_PENALTY * term)rc_map = reservation_counts or {}for ds in date_strs:rc = rc_map.get(ds, {})
146 unmodified lines147148149150151152146 unmodified linesemployment_type=EmploymentType(f["employment_type"]),hourly_wage=int(f.get("hourly_wage") or 0),has_social_insurance=bool(f.get("has_social_insurance")),hall_skill_breakfast=SkillLevel(f.get("hall_skill_breakfast") or "beginner"),hall_skill_dinner=SkillLevel(f.get("hall_skill_dinner") or "beginner"),kitchen_skill_breakfast=SkillLevel(f.get("kitchen_skill_breakfast") or "beginner"),146 unmodified lines147148149150151152153146 unmodified linesemployment_type=EmploymentType(f["employment_type"]),hourly_wage=int(f.get("hourly_wage") or 0),has_social_insurance=bool(f.get("has_social_insurance")),si_allow_short_shift=bool(f.get("si_allow_short_shift")),hall_skill_breakfast=SkillLevel(f.get("hall_skill_breakfast") or "beginner"),hall_skill_dinner=SkillLevel(f.get("hall_skill_dinner") or "beginner"),kitchen_skill_breakfast=SkillLevel(f.get("kitchen_skill_breakfast") or "beginner"),
101 unmodified lines102103104105106107108101 unmodified lines{{ 'checked' if emp and emp.has_social_insurance else '' }}><label class="form-check-label small" for="has_si">社会保険に加入している<span class="text-muted fw-normal">(シフト生成時に優先配置)</span></label></div></div>101 unmodified lines102103104105106107108109110111112113114115116117101 unmodified lines{{ 'checked' if emp and emp.has_social_insurance else '' }}><label class="form-check-label small" for="has_si">社会保険に加入している<span class="text-muted fw-normal">(シフト生成時に優先配置・出勤日は原則8時間勤務)</span></label></div><div class="form-check mt-1"><input class="form-check-input" type="checkbox" name="si_allow_short_shift"id="si_short" value="1"{{ 'checked' if emp and emp.si_allow_short_shift else '' }}><label class="form-check-label small" for="si_short">9時間未満の希望でも割当対象にする<span class="text-muted fw-normal">(社会保険加入者向け。ペナルティ付きで許可)</span></label></div></div>
db/database.py+1
db/repositories.py+8-4
models/employee.py+1
optimizer/solver.py+66-10
routes/employees.py+1
templates/employees/form.html+10-1