| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | from ortools.linear_solver import pywraplp |
| | from math import ceil |
| | from src.config.constants import ShiftType, LineType, KitLevel |
| |
|
| | |
| | from src.config.optimization_config import ( |
| | DATE_SPAN, |
| | get_product_list, |
| | get_employee_type_list, |
| | get_active_shift_list, |
| | get_line_list, |
| | get_line_cnt_per_type, |
| | get_demand_dictionary, |
| | get_cost_list_per_emp_shift, |
| | get_max_employee_per_type_on_day, |
| | MAX_HOUR_PER_PERSON_PER_DAY, |
| | get_max_hour_per_shift_per_person, |
| | get_per_product_speed, |
| | get_max_parallel_workers, |
| | FIXED_STAFF_CONSTRAINT_MODE, |
| | get_team_requirements, |
| | get_payment_mode_config, |
| | KIT_LINE_MATCH_DICT, |
| | EVENING_SHIFT_MODE, |
| | EVENING_SHIFT_DEMAND_THRESHOLD, |
| | |
| | KIT_LEVELS, |
| | KIT_DEPENDENCIES, |
| | PRODUCTION_PRIORITY_ORDER, |
| | |
| | get_fixed_min_unicef_per_day, |
| | ) |
| |
|
| |
|
| |
|
| | |
| | KIT_LINE_MATCH_DICT |
| | print("KIT_LINE_MATCH_DICT",KIT_LINE_MATCH_DICT) |
| |
|
| | |
| | |
| | |
| |
|
| |
|
| | def build_lines(): |
| | """List of line instances. |
| | line_tuples elements are (line_type_id, idx) tuples. e.g., (6,1), (6,2), (7,1), ... |
| | """ |
| | line_tuples = [] |
| | LINE_LIST = get_line_list() |
| | LINE_CNT_PER_TYPE = get_line_cnt_per_type() |
| | |
| | for lt in LINE_LIST: |
| | cnt = int(LINE_CNT_PER_TYPE.get(lt, 0)) |
| | for i in range(1, cnt + 1): |
| | line_tuples.append((lt, i)) |
| | return line_tuples |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | def sort_products_by_hierarchy(product_list): |
| | """ |
| | Sort products by hierarchy levels and dependencies using topological sorting. |
| | Returns products in optimal production order: prepacks โ subkits โ masters |
| | Dependencies within the same level are properly ordered. |
| | """ |
| | from collections import defaultdict, deque |
| | |
| | |
| | products_with_hierarchy = [p for p in product_list if p in KIT_LEVELS] |
| | products_without_hierarchy = [p for p in product_list if p not in KIT_LEVELS] |
| | |
| | if products_without_hierarchy: |
| | print(f"[HIERARCHY] Products without hierarchy data: {products_without_hierarchy}") |
| | |
| | |
| | graph = defaultdict(list) |
| | in_degree = defaultdict(int) |
| | |
| | |
| | for product in products_with_hierarchy: |
| | in_degree[product] = 0 |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | for product in products_with_hierarchy: |
| | deps = KIT_DEPENDENCIES.get(product, []) |
| | for dep in deps: |
| | if dep in products_with_hierarchy: |
| | |
| | |
| | |
| | graph[dep].append(product) |
| | in_degree[product] += 1 |
| | |
| | |
| | sorted_products = [] |
| | |
| | queue = deque() |
| | |
| | |
| | for product in products_with_hierarchy: |
| | if in_degree[product] == 0: |
| | queue.append(product) |
| | |
| | while queue: |
| | current = queue.popleft() |
| | sorted_products.append(current) |
| | |
| | |
| | for dependent in sorted(graph[current], key=lambda p: (KIT_LEVELS.get(p, 999), p)): |
| | in_degree[dependent] -= 1 |
| | if in_degree[dependent] == 0: |
| | queue.append(dependent) |
| | |
| | |
| | if len(sorted_products) != len(products_with_hierarchy): |
| | remaining = [p for p in products_with_hierarchy if p not in sorted_products] |
| | print(f"[HIERARCHY] WARNING: Potential circular dependencies detected in: {remaining}") |
| | |
| | remaining_sorted = sorted(remaining, key=lambda p: (KIT_LEVELS.get(p, 999), p)) |
| | sorted_products.extend(remaining_sorted) |
| | |
| | |
| | sorted_products.extend(sorted(products_without_hierarchy)) |
| | |
| | print(f"[HIERARCHY] Dependency-aware production order: {len(sorted_products)} products") |
| | for i, p in enumerate(sorted_products[:10]): |
| | level = KIT_LEVELS.get(p, "unknown") |
| | level_name = KitLevel.get_name(level) |
| | deps = KIT_DEPENDENCIES.get(p, []) |
| | deps_in_list = [d for d in deps if d in products_with_hierarchy] |
| | print(f" {i+1}. {p} (level {level}={level_name}, deps: {len(deps_in_list)})") |
| | if deps_in_list: |
| | print(f" Dependencies: {deps_in_list}") |
| | |
| | if len(sorted_products) > 10: |
| | print(f" ... and {len(sorted_products) - 10} more products") |
| | |
| | return sorted_products |
| |
|
| | |
| | |
| |
|
| | def run_optimization_for_week(): |
| | |
| | print("\n" + "="*60) |
| | print("๐ LOADING FRESH DATA FOR OPTIMIZATION") |
| | print("="*60) |
| | |
| | |
| | PRODUCT_LIST = get_product_list() |
| | DEMAND_DICTIONARY = get_demand_dictionary() |
| | TEAM_REQ_PER_PRODUCT = get_team_requirements(PRODUCT_LIST) |
| | |
| | print(f"๐ฆ LOADED PRODUCTS: {len(PRODUCT_LIST)} products") |
| | print(f"๐ LOADED DEMAND: {sum(DEMAND_DICTIONARY.values())} total units") |
| | print(f"๐ฅ LOADED TEAM REQUIREMENTS: {len(TEAM_REQ_PER_PRODUCT)} employee types") |
| | |
| | |
| | ACTIVE = {t: {p: 1 for p in PRODUCT_LIST} for t in DATE_SPAN} |
| | |
| | |
| | date_span_list = list(DATE_SPAN) |
| | |
| | active_shift_list = sorted(list(get_active_shift_list())) |
| | employee_type_list = list(get_employee_type_list()) |
| | print("employee_type_list",employee_type_list) |
| | |
| | print("\n" + "="*60) |
| | print("๐ APPLYING HIERARCHY-BASED PRODUCTION ORDERING") |
| | print("="*60) |
| | sorted_product_list = sort_products_by_hierarchy(list(PRODUCT_LIST)) |
| | |
| | line_tuples = build_lines() |
| | print("Lines",line_tuples) |
| | |
| | |
| | PER_PRODUCT_SPEED = get_per_product_speed() |
| | print("PER_PRODUCT_SPEED",PER_PRODUCT_SPEED) |
| |
|
| | |
| | Hmax_s = dict(get_max_hour_per_shift_per_person()) |
| | Hmax_daily = MAX_HOUR_PER_PERSON_PER_DAY |
| | max_workers_line = dict(get_max_parallel_workers()) |
| | max_employee_type_day = get_max_employee_per_type_on_day() |
| | cost = get_cost_list_per_emp_shift() |
| | |
| | |
| | |
| | for p in sorted_product_list: |
| | req_total = sum(TEAM_REQ_PER_PRODUCT[e][p] for e in employee_type_list) |
| | lt = KIT_LINE_MATCH_DICT.get(p, 6) |
| | if p not in KIT_LINE_MATCH_DICT: |
| | print(f"[WARN] Product {p}: No line type mapping found, defaulting to long line (6)") |
| | if req_total > max_workers_line.get(lt, 1e9): |
| | print(f"[WARN] Product {p}: team size {req_total} > MAX_PARALLEL_WORKERS[{lt}] " |
| | f"= {max_workers_line.get(lt)}. Blocked.") |
| |
|
| | |
| | if EVENING_SHIFT_MODE == "normal": |
| | total_demand = sum(DEMAND_DICTIONARY.get(p, 0) for p in sorted_product_list) |
| | |
| | |
| | regular_overtime_shifts = [s for s in active_shift_list if s in ShiftType.REGULAR_AND_OVERTIME] |
| | max_capacity = 0 |
| | |
| | for p in sorted_product_list: |
| | if p in PER_PRODUCT_SPEED: |
| | product_speed = PER_PRODUCT_SPEED[p] |
| | |
| | max_hours_per_product = 0 |
| | for ell in line_tuples: |
| | for s in regular_overtime_shifts: |
| | for t in date_span_list: |
| | max_hours_per_product += Hmax_s[s] |
| | |
| | max_capacity += product_speed * max_hours_per_product |
| | |
| | capacity_ratio = max_capacity / total_demand if total_demand > 0 else float('inf') |
| | |
| | print(f"[CAPACITY CHECK] Total demand: {total_demand}") |
| | print(f"[CAPACITY CHECK] Max capacity (Regular + Overtime): {max_capacity:.1f}") |
| | print(f"[CAPACITY CHECK] Capacity ratio: {capacity_ratio:.2f}") |
| | |
| | if capacity_ratio < EVENING_SHIFT_DEMAND_THRESHOLD: |
| | print(f"\n๐จ [ALERT] DEMAND TOO HIGH!") |
| | print(f" Current capacity can only meet {capacity_ratio*100:.1f}% of demand") |
| | print(f" Threshold: {EVENING_SHIFT_DEMAND_THRESHOLD*100:.1f}%") |
| | print(f" RECOMMENDATION: Change EVENING_SHIFT_MODE to 'activate_evening' to enable evening shift") |
| | print(f" This will add shift 3 to increase capacity\n") |
| |
|
| |
|
| | |
| | solver = pywraplp.Solver.CreateSolver('CBC') |
| | if not solver: |
| | raise RuntimeError("CBC solver not found.") |
| | INF = solver.infinity() |
| |
|
| | |
| | |
| | Z, T, U = {}, {}, {} |
| | for p in sorted_product_list: |
| | for ell in line_tuples: |
| | for s in active_shift_list: |
| | for t in date_span_list: |
| | Z[p, ell, s, t] = solver.BoolVar(f"Z_{p}_{ell[0]}_{ell[1]}_s{s}_d{t}") |
| | T[p, ell, s, t] = solver.NumVar(0, Hmax_s[s], f"T_{p}_{ell[0]}_{ell[1]}_s{s}_d{t}") |
| | U[p, ell, s, t] = solver.NumVar(0, INF, f"U_{p}_{ell[0]}_{ell[1]}_s{s}_d{t}") |
| | |
| | |
| | IDLE = {} |
| | for e in employee_type_list: |
| | for s in active_shift_list: |
| | for t in date_span_list: |
| | max_idle = max_employee_type_day[e][t] |
| | IDLE[e, s, t] = solver.IntVar(0, max_idle, f"IDLE_{e}_s{s}_d{t}") |
| |
|
| | |
| |
|
| | |
| | PAYMENT_MODE_CONFIG = get_payment_mode_config() |
| | print(f"Payment mode configuration: {PAYMENT_MODE_CONFIG}") |
| | |
| | |
| | cost_terms = [] |
| | |
| | for e in employee_type_list: |
| | for s in active_shift_list: |
| | payment_mode = PAYMENT_MODE_CONFIG.get(s, "partial") |
| | |
| | if payment_mode == "partial": |
| | |
| | for p in sorted_product_list: |
| | for ell in line_tuples: |
| | for t in date_span_list: |
| | cost_terms.append(cost[e][s] * TEAM_REQ_PER_PRODUCT[e][p] * T[p, ell, s, t]) |
| | |
| | elif payment_mode == "bulk": |
| | |
| | |
| | for p in sorted_product_list: |
| | for ell in line_tuples: |
| | for t in date_span_list: |
| | |
| | |
| | |
| | |
| | |
| | |
| | work_binary = solver.BoolVar(f"work_{e}_s{s}_{p}_{ell[0]}{ell[1]}_d{t}") |
| | |
| | |
| | solver.Add(T[p, ell, s, t] <= Hmax_s[s] * work_binary) |
| | solver.Add(work_binary * 0.001 <= T[p, ell, s, t]) |
| | |
| | |
| | cost_terms.append(cost[e][s] * Hmax_s[s] * TEAM_REQ_PER_PRODUCT[e][p] * work_binary) |
| | |
| | |
| | for e in employee_type_list: |
| | for s in active_shift_list: |
| | for t in date_span_list: |
| | cost_terms.append(cost[e][s] * Hmax_s[s] * IDLE[e, s, t]) |
| | |
| | total_cost = solver.Sum(cost_terms) |
| | |
| | |
| | |
| | solver.Minimize(total_cost) |
| |
|
| | |
| |
|
| | |
| | for p in sorted_product_list: |
| | total_production = solver.Sum(U[p, ell, s, t] for ell in line_tuples for s in active_shift_list for t in date_span_list) |
| | demand = DEMAND_DICTIONARY.get(p, 0) |
| | |
| | |
| | solver.Add(total_production >= demand) |
| | |
| | |
| | solver.Add(total_production <= demand) |
| |
|
| | |
| | for ell in line_tuples: |
| | for s in active_shift_list: |
| | for t in date_span_list: |
| | solver.Add(solver.Sum(Z[p, ell, s, t] for p in sorted_product_list) <= 1) |
| | for p in sorted_product_list: |
| | solver.Add(T[p, ell, s, t] <= Hmax_s[s] * Z[p, ell, s, t]) |
| |
|
| | |
| | for p in sorted_product_list: |
| | req_lt = KIT_LINE_MATCH_DICT.get(p, LineType.LONG_LINE) |
| | req_total = sum(TEAM_REQ_PER_PRODUCT[e][p] for e in employee_type_list) |
| | for ell in line_tuples: |
| | allowed = (ell[0] == req_lt) and (req_total <= max_workers_line.get(ell[0], 1e9)) |
| | for s in active_shift_list: |
| | for t in date_span_list: |
| | if ACTIVE[t][p] == 0 or not allowed: |
| | solver.Add(Z[p, ell, s, t] == 0) |
| | solver.Add(T[p, ell, s, t] == 0) |
| | solver.Add(U[p, ell, s, t] == 0) |
| |
|
| | |
| | for p in sorted_product_list: |
| | for ell in line_tuples: |
| | for s in active_shift_list: |
| | for t in date_span_list: |
| | |
| | if p in PER_PRODUCT_SPEED: |
| | |
| | speed = PER_PRODUCT_SPEED[p] |
| | |
| | solver.Add( |
| | U[p, ell, s, t] <= speed * T[p, ell, s, t] |
| | ) |
| | |
| | solver.Add( |
| | U[p, ell, s, t] >= speed * T[p, ell, s, t] |
| | ) |
| | else: |
| | |
| | default_speed = 800 / 7.5 |
| | print(f"Warning: No speed data for product {p}, using default {default_speed:.1f} per hour") |
| | |
| | solver.Add( |
| | U[p, ell, s, t] <= default_speed * T[p, ell, s, t] |
| | ) |
| | |
| | solver.Add( |
| | U[p, ell, s, t] >= default_speed * T[p, ell, s, t] |
| | ) |
| |
|
| | |
| | for e in employee_type_list: |
| | for s in active_shift_list: |
| | for t in date_span_list: |
| | |
| | |
| | solver.Add(IDLE[e, s, t] <= max_employee_type_day[e][t]) |
| | |
| | |
| | solver.Add( |
| | solver.Sum(TEAM_REQ_PER_PRODUCT[e][p] * T[p, ell, s, t] for p in sorted_product_list for ell in line_tuples) |
| | <= Hmax_s[s] * max_employee_type_day[e][t] |
| | ) |
| |
|
| | |
| | for e in employee_type_list: |
| | for t in date_span_list: |
| | solver.Add( |
| | solver.Sum(TEAM_REQ_PER_PRODUCT[e][p] * T[p, ell, s, t] for s in active_shift_list for p in sorted_product_list for ell in line_tuples) |
| | <= MAX_HOUR_PER_PERSON_PER_DAY * max_employee_type_day[e][t] |
| | ) |
| |
|
| | |
| | |
| | if ShiftType.EVENING in active_shift_list and ShiftType.REGULAR in active_shift_list: |
| | for e in employee_type_list: |
| | for t in date_span_list: |
| | solver.Add( |
| | solver.Sum(TEAM_REQ_PER_PRODUCT[e][p] * T[p, ell, ShiftType.EVENING, t] for p in sorted_product_list for ell in line_tuples) |
| | <= |
| | solver.Sum(TEAM_REQ_PER_PRODUCT[e][p] * T[p, ell, ShiftType.REGULAR, t] for p in sorted_product_list for ell in line_tuples) |
| | ) |
| | |
| | |
| | if ShiftType.OVERTIME in active_shift_list and ShiftType.REGULAR in active_shift_list: |
| | print("\n[OVERTIME] Adding constraints to ensure overtime only when regular shift is insufficient...") |
| | |
| | for e in employee_type_list: |
| | for t in date_span_list: |
| | |
| | regular_capacity = max_employee_type_day[e][t] |
| | |
| | |
| | regular_usage = solver.Sum( |
| | TEAM_REQ_PER_PRODUCT[e][p] * T[p, ell, ShiftType.REGULAR, t] |
| | for p in sorted_product_list for ell in line_tuples |
| | ) |
| | |
| | |
| | overtime_usage = solver.Sum( |
| | TEAM_REQ_PER_PRODUCT[e][p] * T[p, ell, ShiftType.OVERTIME, t] |
| | for p in sorted_product_list for ell in line_tuples |
| | ) |
| | |
| | |
| | using_overtime = solver.IntVar(0, 1, f'using_overtime_{e}_{t}') |
| | |
| | |
| | |
| | min_regular_for_overtime = int(0.9 * regular_capacity) |
| | |
| | |
| | solver.Add(regular_usage >= min_regular_for_overtime * using_overtime) |
| | |
| | |
| | solver.Add(overtime_usage <= regular_capacity * using_overtime) |
| | |
| | overtime_constraints_added = len(employee_type_list) * len(date_span_list) * 2 |
| | print(f"[OVERTIME] Added {overtime_constraints_added} constraints ensuring overtime only when regular shifts are at 90%+ capacity") |
| | |
| | |
| | |
| | |
| | |
| | FIXED_MIN_UNICEF_PER_DAY = get_fixed_min_unicef_per_day() |
| | if 'UNICEF Fixed term' in employee_type_list and FIXED_MIN_UNICEF_PER_DAY > 0: |
| | print(f"\n[FIXED STAFFING] Adding constraint for minimum {FIXED_MIN_UNICEF_PER_DAY} UNICEF employees per day...") |
| | |
| | unicef_constraints_added = 0 |
| | for t in date_span_list: |
| | |
| | |
| | |
| | |
| | |
| | all_unicef_hours = solver.Sum( |
| | TEAM_REQ_PER_PRODUCT.get('UNICEF Fixed term', {}).get(p, 0) * T[p, ell, s, t] |
| | for p in sorted_product_list |
| | for ell in line_tuples |
| | for s in active_shift_list |
| | ) |
| | |
| | |
| | idle_unicef_employees = solver.Sum( |
| | IDLE['UNICEF Fixed term', s, t] for s in active_shift_list |
| | ) |
| | |
| | |
| | |
| | solver.Add(all_unicef_hours + idle_unicef_employees * MAX_HOUR_PER_PERSON_PER_DAY >= FIXED_MIN_UNICEF_PER_DAY * MAX_HOUR_PER_PERSON_PER_DAY) |
| | |
| | |
| | |
| | total_unicef_hours_needed_for_production = solver.Sum( |
| | TEAM_REQ_PER_PRODUCT.get('UNICEF Fixed term', {}).get(p, 0) * T[p, ell, s, t] |
| | for p in sorted_product_list for ell in line_tuples for s in active_shift_list |
| | ) |
| | |
| | |
| | |
| | |
| | unicef_constraints_added += 1 |
| | |
| | print(f"[FIXED STAFFING] Added {unicef_constraints_added} constraints ensuring >= {FIXED_MIN_UNICEF_PER_DAY} UNICEF employees per day") |
| | |
| | |
| | |
| | print("\n[HIERARCHY] Adding dependency constraints...") |
| | dependency_constraints_added = 0 |
| | |
| | for p in sorted_product_list: |
| | dependencies = KIT_DEPENDENCIES.get(p, []) |
| | if dependencies: |
| | |
| | p_level = KIT_LEVELS.get(p, 2) |
| | |
| | for dep in dependencies: |
| | if dep in sorted_product_list: |
| | |
| | p_completion = solver.Sum( |
| | t * T[p, ell, s, t] for ell in line_tuples for s in active_shift_list for t in date_span_list |
| | ) |
| | dep_completion = solver.Sum( |
| | t * T[dep, ell, s, t] for ell in line_tuples for s in active_shift_list for t in date_span_list |
| | ) |
| | |
| | |
| | solver.Add(dep_completion <= p_completion) |
| | dependency_constraints_added += 1 |
| | |
| | print(f" Added constraint: {dep} (dependency) <= {p} (level {p_level})") |
| | |
| | print(f"[HIERARCHY] Added {dependency_constraints_added} dependency constraints") |
| |
|
| | |
| | status = solver.Solve() |
| | if status != pywraplp.Solver.OPTIMAL: |
| | status_names = {pywraplp.Solver.INFEASIBLE: "INFEASIBLE", pywraplp.Solver.UNBOUNDED: "UNBOUNDED"} |
| | print(f"No optimal solution. Status: {status} ({status_names.get(status, 'UNKNOWN')})") |
| | |
| | |
| | |
| | return None |
| |
|
| | |
| | result = {} |
| | result['objective'] = solver.Objective().Value() |
| |
|
| | |
| | prod_week = {p: sum(U[p, ell, s, t].solution_value() for ell in line_tuples for s in active_shift_list for t in date_span_list) for p in sorted_product_list} |
| | result['weekly_production'] = prod_week |
| |
|
| | |
| | schedule = [] |
| | for t in date_span_list: |
| | for ell in line_tuples: |
| | for s in active_shift_list: |
| | chosen = [p for p in sorted_product_list if Z[p, ell, s, t].solution_value() > 0.5] |
| | if chosen: |
| | p = chosen[0] |
| | schedule.append({ |
| | 'day': t, |
| | 'line_type_id': ell[0], |
| | 'line_idx': ell[1], |
| | 'shift': s, |
| | 'product': p, |
| | 'run_hours': T[p, ell, s, t].solution_value(), |
| | 'units': U[p, ell, s, t].solution_value(), |
| | }) |
| | result['run_schedule'] = schedule |
| |
|
| | |
| | headcount = [] |
| | for e in employee_type_list: |
| | for s in active_shift_list: |
| | for t in date_span_list: |
| | used_ph = sum(TEAM_REQ_PER_PRODUCT[e][p] * T[p, ell, s, t].solution_value() for p in sorted_product_list for ell in line_tuples) |
| | need = ceil(used_ph / (Hmax_s[s] + 1e-9)) |
| | headcount.append({'emp_type': e, 'shift': s, 'day': t, |
| | 'needed': need, 'available': max_employee_type_day[e][t]}) |
| | result['headcount_per_shift'] = headcount |
| |
|
| | |
| | ph_by_day = [] |
| | for e in employee_type_list: |
| | for t in date_span_list: |
| | used = sum(TEAM_REQ_PER_PRODUCT[e][p] * T[p, ell, s, t].solution_value() for s in active_shift_list for p in sorted_product_list for ell in line_tuples) |
| | ph_by_day.append({'emp_type': e, 'day': t, |
| | 'used_person_hours': used, |
| | 'cap_person_hours': Hmax_daily * max_employee_type_day[e][t]}) |
| | result['person_hours_by_day'] = ph_by_day |
| |
|
| | |
| | idle_employees = [] |
| | for e in employee_type_list: |
| | for s in active_shift_list: |
| | for t in date_span_list: |
| | idle_count = IDLE[e, s, t].solution_value() |
| | if idle_count > 0: |
| | idle_employees.append({ |
| | 'emp_type': e, |
| | 'shift': s, |
| | 'day': t, |
| | 'idle_count': idle_count |
| | }) |
| | result['idle_employees'] = idle_employees |
| |
|
| | |
| | print("Objective (min cost):", result['objective']) |
| | print("\n--- Weekly production by product ---") |
| | for p, u in prod_week.items(): |
| | print(f"{p}: {u:.1f} / demand {DEMAND_DICTIONARY.get(p,0)}") |
| |
|
| | print("\n--- Schedule (line, shift, day) ---") |
| | for row in schedule: |
| | shift_name = ShiftType.get_name(row['shift']) |
| | line_name = LineType.get_name(row['line_type_id']) |
| | print(f"date_span_list{row['day']} {line_name}-{row['line_idx']} {shift_name}: " |
| | f"{row['product']} T={row['run_hours']:.2f}h U={row['units']:.1f}") |
| |
|
| | print("\n--- Implied headcount need (per type/shift/day) ---") |
| | for row in headcount: |
| | shift_name = ShiftType.get_name(row['shift']) |
| | print(f"{row['emp_type']}, {shift_name}, date_span_list{row['day']}: " |
| | f"need={row['needed']} (avail {row['available']})") |
| |
|
| | print("\n--- Total person-hours by type/day ---") |
| | for row in ph_by_day: |
| | print(f"{row['emp_type']}, date_span_list{row['day']}: used={row['used_person_hours']:.1f} " |
| | f"(cap {row['cap_person_hours']})") |
| |
|
| | |
| | print("\n--- Idle employees (per type/shift/day) ---") |
| | idle_found = False |
| | for e in employee_type_list: |
| | for s in active_shift_list: |
| | for t in date_span_list: |
| | idle_count = IDLE[e, s, t].solution_value() |
| | if idle_count > 0: |
| | shift_name = ShiftType.get_name(s) |
| | print(f"{e}, {shift_name}, date_span_list{t}: idle={idle_count}") |
| | idle_found = True |
| | if not idle_found: |
| | print("No idle employees scheduled") |
| |
|
| | return result |
| |
|
| |
|
| | if __name__ == "__main__": |
| | run_optimization_for_week() |