alirezaaminzadeh commited on
Commit
67a30ae
·
verified ·
1 Parent(s): 34a96ed

Publish Gradio console bundle

Browse files
space-bundle/README.md ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Hospital Operations Command Center
3
+ emoji: 🏥
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: "5.50.0"
8
+ app_file: app.py
9
+ python_version: "3.12"
10
+ license: mit
11
+ short_description: OR scheduling, SimPy simulation, ML quantiles, disruption replanning
12
+ tags:
13
+ - healthcare
14
+ - operations-research
15
+ - scheduling
16
+ - gradio
17
+ - simulation
18
+ ---
19
+
20
+ # Hospital Operations Command Center
21
+
22
+ Interactive command center for multi-layer hospital operations planning — OR scheduling, bed capacity, nurse rostering, policy benchmarking, and real-time disruption response.
23
+
24
+ **Layers:** Weekly block planning · Daily OR sequencing · Real-time re-optimization
25
+ **Policies:** FCFS · Deterministic · Robust Quantile · Rolling Horizon
26
+ **Stack:** OR-Tools CP-SAT · SimPy · Quantile ML · Plotly
space-bundle/app.py ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Hospital Operations Command Center — Interactive Command Center
3
+ Multi-layer OR scheduling, bed planning, nurse rostering, and disruption response.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ import gradio as gr
13
+ import pandas as pd
14
+ import plotly.graph_objects as go
15
+
16
+ ROOT = Path(__file__).resolve().parent
17
+ sys.path.insert(0, str(ROOT / "src"))
18
+
19
+ from hopcc.constants import POLICIES, SCENARIOS, SIZE_PRESETS # noqa: E402
20
+ from hopcc.ml_predictor import MLPredictor # noqa: E402
21
+ from hopcc.pipeline import HopccPipeline # noqa: E402
22
+ from hopcc.visualization import ( # noqa: E402
23
+ build_disruption_delta,
24
+ build_gantt,
25
+ build_policy_comparison,
26
+ build_utilization_timeline,
27
+ )
28
+
29
+ pipeline = HopccPipeline(ROOT / "assets")
30
+ pipeline.load()
31
+
32
+ SUMMARY = pipeline.summary
33
+ predictor = MLPredictor()
34
+
35
+ CUSTOM_CSS = """
36
+ .gradio-container { max-width: 1560px !important; }
37
+ .markdown h1 { color: #1d4ed8; font-weight: 700; }
38
+ """
39
+
40
+ _state: dict = {"last_policy": None, "last_disruption": None}
41
+
42
+
43
+ def _kpi_md() -> str:
44
+ return f"""
45
+ ### Hospital Operations Command Center
46
+
47
+ | Metric | Value |
48
+ |--------|-------|
49
+ | Engine version | **v{pipeline.version}** |
50
+ | Planning scenarios | **{SUMMARY.get('scenarios', 5)}** (OR daily/weekly, ICU beds, nurses, emergency) |
51
+ | Scheduling policies | **{SUMMARY.get('policies', 4)}** benchmarked |
52
+ | ML predictors | **{SUMMARY.get('ml_models', 5)}** (duration quantiles, cancellation, ICU, LOS, no-show) |
53
+ | Benchmark runs | **{SUMMARY.get('total_benchmark_runs', 0)}** pre-computed |
54
+ | Winner distribution | {SUMMARY.get('winner_distribution', {})} |
55
+ """
56
+
57
+
58
+ def _run_schedule(scenario, size, seed, policy):
59
+ pr = pipeline.run_policy(scenario, size, int(seed), policy)
60
+ _state["last_policy"] = pr
61
+ rows = [
62
+ {
63
+ "Case": s.case_id,
64
+ "Room": s.room_id,
65
+ "Surgeon": s.surgeon_id,
66
+ "Start": s.start_min,
67
+ "End": s.end_min,
68
+ "Turnover End": s.turnover_end,
69
+ "ICU Reserved": s.icu_reserved,
70
+ }
71
+ for s in pr.schedule
72
+ ]
73
+ df = pd.DataFrame(rows)
74
+ fig = build_gantt(pr.schedule, f"OR Schedule — {POLICIES[policy]['label']}")
75
+ fig_util = build_utilization_timeline(pr.schedule)
76
+ metrics_md = "\n".join(f"- **{k}:** {v}" for k, v in pr.metrics.items())
77
+ summary = f"**Policy:** {pr.policy_label} · **Feasible:** {pr.feasible} · **Runtime:** {pr.elapsed_sec}s\n\n{metrics_md}\n\n_{pr.notes}_"
78
+ return df, fig, fig_util, summary
79
+
80
+
81
+ def _run_benchmark(scenario, size, seed):
82
+ inst = pipeline.get_instance(scenario, size, int(seed))
83
+ rows = []
84
+ for pid in POLICIES:
85
+ pr = pipeline.run_policy(scenario, size, int(seed), pid)
86
+ rows.append({"policy_id": pid, "policy_label": pr.policy_label, **pr.metrics})
87
+ fig = build_policy_comparison(rows)
88
+ df = pd.DataFrame(rows)
89
+ winner = min(rows, key=lambda r: r.get("composite_penalty", 1e9))
90
+ md = f"**Recommended policy:** {winner['policy_label']} (lowest composite penalty)"
91
+ return df, fig, md
92
+
93
+
94
+ def _run_disruption(scenario, size, seed):
95
+ comp = pipeline.run_disruption_demo(scenario, size, int(seed))
96
+ _state["last_disruption"] = comp
97
+ before_fig = build_gantt(comp.schedule_before, "Schedule After Disruptions (Before Replan)")
98
+ after_fig = build_gantt(comp.schedule_after, "Re-optimized Schedule")
99
+ delta_fig = build_disruption_delta(comp.baseline_metrics, comp.replanned_metrics)
100
+ events = "\n".join(f"- {d.label}" for d in comp.disruptions)
101
+ imp = "\n".join(f"- {k}: {v}%" for k, v in comp.improvement_pct.items())
102
+ md = f"""
103
+ ### Disruption Command Center
104
+
105
+ **Events applied:**
106
+ {events}
107
+
108
+ **Improvement after re-optimization:**
109
+ {imp}
110
+ """
111
+ return before_fig, after_fig, delta_fig, md
112
+
113
+
114
+ def _ml_predict(specialty, experience, age, asa, complexity):
115
+ preds = predictor.predict_surgery_duration(
116
+ specialty=specialty,
117
+ surgeon_experience=int(experience),
118
+ patient_age=int(age),
119
+ asa_score=int(asa),
120
+ procedure_complexity=float(complexity),
121
+ prior_surgeries=2,
122
+ )
123
+ cancel = predictor.predict_cancellation(specialty, 2, 4, 0.6)
124
+ icu = predictor.predict_icu_need(specialty, int(asa), float(complexity))
125
+ los = predictor.predict_los(specialty, icu > 0.5, int(age))
126
+ noshow = predictor.predict_no_show(2, 10)
127
+
128
+ fig = go.Figure(go.Bar(
129
+ x=["P50", "P80", "P95"],
130
+ y=[preds["p50"], preds["p80"], preds["p95"]],
131
+ marker_color=["#3b82f6", "#6366f1", "#8b5cf6"],
132
+ text=[f"{v} min" for v in preds.values()],
133
+ textposition="outside",
134
+ ))
135
+ fig.update_layout(title="Surgery Duration Quantiles", yaxis_title="Minutes", height=360)
136
+
137
+ md = f"""
138
+ | Prediction | Value |
139
+ |------------|-------|
140
+ | P50 duration | **{preds['p50']} min** |
141
+ | P80 duration | **{preds['p80']} min** |
142
+ | P95 duration | **{preds['p95']} min** |
143
+ | Cancellation risk | **{cancel:.1%}** |
144
+ | ICU probability | **{icu:.1%}** |
145
+ | Expected LOS | **{los} days** |
146
+ | No-show risk | **{noshow:.1%}** |
147
+
148
+ _Robust scheduler uses P80 by default; risk-averse mode uses P95._
149
+ """
150
+ return fig, md
151
+
152
+
153
+ def _simulation_tab(scenario, size, seed, policy):
154
+ sim = pipeline.run_simulation(scenario, size, int(seed), policy)
155
+ md = "\n".join(f"- **{k}:** {v}" for k, v in sim.items())
156
+ return f"### SimPy Patient Flow Simulation\n{md}"
157
+
158
+
159
+ def _benchmark_table():
160
+ rows = pipeline.benchmark_table_rows()
161
+ if not rows:
162
+ return pd.DataFrame()
163
+ return pd.DataFrame(rows[:50])
164
+
165
+
166
+ with gr.Blocks(title="Hospital Operations Command Center", css=CUSTOM_CSS) as demo:
167
+ gr.Markdown("# Hospital Operations Command Center")
168
+ gr.Markdown(
169
+ "Multi-layer **operations research** platform for hospital command centers — "
170
+ "OR scheduling, ICU/ward bed planning, nurse rostering, ML-informed robust planning, "
171
+ "SimPy patient-flow simulation, and real-time disruption re-optimization."
172
+ )
173
+ gr.Markdown(_kpi_md())
174
+
175
+ with gr.Tabs():
176
+ with gr.Tab("Schedule Optimizer"):
177
+ with gr.Row():
178
+ sc = gr.Dropdown(list(SCENARIOS.keys()), value="or_daily", label="Scenario")
179
+ sz = gr.Dropdown(list(SIZE_PRESETS.keys()), value="medium", label="Size")
180
+ sd = gr.Number(value=42, label="Seed", precision=0)
181
+ pol = gr.Dropdown(list(POLICIES.keys()), value="robust_quantile", label="Policy")
182
+ btn = gr.Button("Generate Schedule", variant="primary")
183
+ sched_df = gr.Dataframe(label="Schedule")
184
+ sched_summary = gr.Markdown()
185
+ with gr.Row():
186
+ gantt = gr.Plot(label="Gantt Chart")
187
+ util = gr.Plot(label="Utilization")
188
+ btn.click(_run_schedule, [sc, sz, sd, pol], [sched_df, gantt, util, sched_summary])
189
+
190
+ with gr.Tab("Policy Benchmark"):
191
+ with gr.Row():
192
+ b_sc = gr.Dropdown(list(SCENARIOS.keys()), value="or_daily", label="Scenario")
193
+ b_sz = gr.Dropdown(list(SIZE_PRESETS.keys()), value="medium", label="Size")
194
+ b_sd = gr.Number(value=42, label="Seed", precision=0)
195
+ b_btn = gr.Button("Run 4-Policy Benchmark", variant="primary")
196
+ b_df = gr.Dataframe()
197
+ b_fig = gr.Plot()
198
+ b_md = gr.Markdown()
199
+ b_btn.click(_run_benchmark, [b_sc, b_sz, b_sd], [b_df, b_fig, b_md])
200
+ gr.Dataframe(value=_benchmark_table(), label="Pre-computed Benchmark Sample")
201
+
202
+ with gr.Tab("Disruption Command Center"):
203
+ gr.Markdown(
204
+ "Apply simultaneous disruptions: **+90 min surgery overrun**, **ICU bed loss**, "
205
+ "**2 nurse absences**, and **emergency admission** — then compare before/after re-optimization."
206
+ )
207
+ with gr.Row():
208
+ d_sc = gr.Dropdown(list(SCENARIOS.keys()), value="or_daily", label="Scenario")
209
+ d_sz = gr.Dropdown(list(SIZE_PRESETS.keys()), value="medium", label="Size")
210
+ d_sd = gr.Number(value=42, label="Seed", precision=0)
211
+ d_btn = gr.Button("Simulate Disruptions & Replan", variant="primary")
212
+ d_md = gr.Markdown()
213
+ with gr.Row():
214
+ d_before = gr.Plot(label="Before")
215
+ d_after = gr.Plot(label="After")
216
+ d_delta = gr.Plot(label="Metrics Delta")
217
+ d_btn.click(_run_disruption, [d_sc, d_sz, d_sd], [d_before, d_after, d_delta, d_md])
218
+
219
+ with gr.Tab("ML Predictions"):
220
+ with gr.Row():
221
+ sp = gr.Dropdown(
222
+ ["general", "orthopedic", "cardiac", "neuro", "ent", "urology", "gynecology", "thoracic"],
223
+ value="cardiac", label="Specialty",
224
+ )
225
+ exp = gr.Slider(1, 25, value=12, step=1, label="Surgeon Experience (years)")
226
+ age = gr.Slider(18, 95, value=62, step=1, label="Patient Age")
227
+ asa = gr.Slider(1, 4, value=3, step=1, label="ASA Score")
228
+ cx = gr.Slider(0.1, 1.0, value=0.7, step=0.05, label="Procedure Complexity")
229
+ ml_btn = gr.Button("Predict Risks & Durations", variant="primary")
230
+ ml_fig = gr.Plot()
231
+ ml_md = gr.Markdown()
232
+ ml_btn.click(_ml_predict, [sp, exp, age, asa, cx], [ml_fig, ml_md])
233
+
234
+ with gr.Tab("Patient Flow Simulation"):
235
+ with gr.Row():
236
+ s_sc = gr.Dropdown(list(SCENARIOS.keys()), value="or_daily", label="Scenario")
237
+ s_sz = gr.Dropdown(list(SIZE_PRESETS.keys()), value="medium", label="Size")
238
+ s_sd = gr.Number(value=42, label="Seed", precision=0)
239
+ s_pol = gr.Dropdown(list(POLICIES.keys()), value="rolling_horizon", label="Policy")
240
+ s_btn = gr.Button("Run SimPy Simulation", variant="primary")
241
+ s_md = gr.Markdown()
242
+ s_btn.click(_simulation_tab, [s_sc, s_sz, s_sd, s_pol], [s_md])
243
+
244
+ if __name__ == "__main__":
245
+ demo.launch()
space-bundle/assets/demo/benchmarks.json ADDED
@@ -0,0 +1,673 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "scenario_id": "or_daily",
4
+ "size": "small",
5
+ "seed": 42,
6
+ "policy_id": "manual_fcfs",
7
+ "policy_label": "Manual / First-Come-First-Served",
8
+ "surgeries_completed": 8,
9
+ "surgeries_cancelled": 0,
10
+ "overtime_minutes": 0,
11
+ "or_utilization_pct": 38.1,
12
+ "bed_shortage_events": 7,
13
+ "avg_patient_wait_min": 108.9,
14
+ "schedule_changes": 0,
15
+ "specialty_fairness_gini": 0.25,
16
+ "composite_penalty": 318.9,
17
+ "feasible": false,
18
+ "sim_completed": 5,
19
+ "sim_avg_wait": 16.1,
20
+ "sim_or_util": 24.8,
21
+ "elapsed_sec": 0.0
22
+ },
23
+ {
24
+ "scenario_id": "or_daily",
25
+ "size": "small",
26
+ "seed": 42,
27
+ "policy_id": "deterministic_mean",
28
+ "policy_label": "Deterministic Mean-Duration Plan",
29
+ "surgeries_completed": 8,
30
+ "surgeries_cancelled": 0,
31
+ "overtime_minutes": 0,
32
+ "or_utilization_pct": 38.1,
33
+ "bed_shortage_events": 7,
34
+ "avg_patient_wait_min": 99.0,
35
+ "schedule_changes": 0,
36
+ "specialty_fairness_gini": 0.25,
37
+ "composite_penalty": 309.0,
38
+ "feasible": false,
39
+ "sim_completed": 6,
40
+ "sim_avg_wait": 30.0,
41
+ "sim_or_util": 24.7,
42
+ "elapsed_sec": 0.587
43
+ },
44
+ {
45
+ "scenario_id": "or_daily",
46
+ "size": "small",
47
+ "seed": 42,
48
+ "policy_id": "robust_quantile",
49
+ "policy_label": "Robust Quantile Schedule",
50
+ "surgeries_completed": 8,
51
+ "surgeries_cancelled": 0,
52
+ "overtime_minutes": 0,
53
+ "or_utilization_pct": 59.9,
54
+ "bed_shortage_events": 5,
55
+ "avg_patient_wait_min": 215.4,
56
+ "schedule_changes": 0,
57
+ "specialty_fairness_gini": 0.25,
58
+ "composite_penalty": 365.4,
59
+ "feasible": false,
60
+ "sim_completed": 4,
61
+ "sim_avg_wait": 0.1,
62
+ "sim_or_util": 24.7,
63
+ "elapsed_sec": 0.015
64
+ },
65
+ {
66
+ "scenario_id": "or_daily",
67
+ "size": "small",
68
+ "seed": 42,
69
+ "policy_id": "rolling_horizon",
70
+ "policy_label": "Rolling Horizon Re-optimization",
71
+ "surgeries_completed": 8,
72
+ "surgeries_cancelled": 0,
73
+ "overtime_minutes": 0,
74
+ "or_utilization_pct": 49.6,
75
+ "bed_shortage_events": 7,
76
+ "avg_patient_wait_min": 147.4,
77
+ "schedule_changes": 0,
78
+ "specialty_fairness_gini": 0.25,
79
+ "composite_penalty": 357.4,
80
+ "feasible": false,
81
+ "sim_completed": 2,
82
+ "sim_avg_wait": 0.1,
83
+ "sim_or_util": 24.8,
84
+ "elapsed_sec": 0.002
85
+ },
86
+ {
87
+ "scenario_id": "or_daily",
88
+ "size": "small",
89
+ "seed": 123,
90
+ "policy_id": "manual_fcfs",
91
+ "policy_label": "Manual / First-Come-First-Served",
92
+ "surgeries_completed": 8,
93
+ "surgeries_cancelled": 0,
94
+ "overtime_minutes": 0,
95
+ "or_utilization_pct": 33.8,
96
+ "bed_shortage_events": 5,
97
+ "avg_patient_wait_min": 114.9,
98
+ "schedule_changes": 0,
99
+ "specialty_fairness_gini": 0.188,
100
+ "composite_penalty": 264.9,
101
+ "feasible": false,
102
+ "sim_completed": 5,
103
+ "sim_avg_wait": 44.8,
104
+ "sim_or_util": 30.8,
105
+ "elapsed_sec": 0.0
106
+ },
107
+ {
108
+ "scenario_id": "or_daily",
109
+ "size": "small",
110
+ "seed": 123,
111
+ "policy_id": "deterministic_mean",
112
+ "policy_label": "Deterministic Mean-Duration Plan",
113
+ "surgeries_completed": 8,
114
+ "surgeries_cancelled": 0,
115
+ "overtime_minutes": 0,
116
+ "or_utilization_pct": 33.8,
117
+ "bed_shortage_events": 5,
118
+ "avg_patient_wait_min": 79.1,
119
+ "schedule_changes": 0,
120
+ "specialty_fairness_gini": 0.188,
121
+ "composite_penalty": 229.1,
122
+ "feasible": false,
123
+ "sim_completed": 3,
124
+ "sim_avg_wait": 61.9,
125
+ "sim_or_util": 30.9,
126
+ "elapsed_sec": 0.027
127
+ },
128
+ {
129
+ "scenario_id": "or_daily",
130
+ "size": "small",
131
+ "seed": 123,
132
+ "policy_id": "robust_quantile",
133
+ "policy_label": "Robust Quantile Schedule",
134
+ "surgeries_completed": 8,
135
+ "surgeries_cancelled": 0,
136
+ "overtime_minutes": 0,
137
+ "or_utilization_pct": 68.2,
138
+ "bed_shortage_events": 5,
139
+ "avg_patient_wait_min": 178.4,
140
+ "schedule_changes": 0,
141
+ "specialty_fairness_gini": 0.188,
142
+ "composite_penalty": 328.4,
143
+ "feasible": false,
144
+ "sim_completed": 5,
145
+ "sim_avg_wait": 1.4,
146
+ "sim_or_util": 30.9,
147
+ "elapsed_sec": 0.015
148
+ },
149
+ {
150
+ "scenario_id": "or_daily",
151
+ "size": "small",
152
+ "seed": 123,
153
+ "policy_id": "rolling_horizon",
154
+ "policy_label": "Rolling Horizon Re-optimization",
155
+ "surgeries_completed": 8,
156
+ "surgeries_cancelled": 0,
157
+ "overtime_minutes": 0,
158
+ "or_utilization_pct": 56.9,
159
+ "bed_shortage_events": 5,
160
+ "avg_patient_wait_min": 146.4,
161
+ "schedule_changes": 0,
162
+ "specialty_fairness_gini": 0.188,
163
+ "composite_penalty": 296.4,
164
+ "feasible": false,
165
+ "sim_completed": 4,
166
+ "sim_avg_wait": 0.4,
167
+ "sim_or_util": 30.6,
168
+ "elapsed_sec": 0.002
169
+ },
170
+ {
171
+ "scenario_id": "or_daily",
172
+ "size": "medium",
173
+ "seed": 42,
174
+ "policy_id": "manual_fcfs",
175
+ "policy_label": "Manual / First-Come-First-Served",
176
+ "surgeries_completed": 16,
177
+ "surgeries_cancelled": 0,
178
+ "overtime_minutes": 84,
179
+ "or_utilization_pct": 55.7,
180
+ "bed_shortage_events": 13,
181
+ "avg_patient_wait_min": 168.8,
182
+ "schedule_changes": 0,
183
+ "specialty_fairness_gini": 0.161,
184
+ "composite_penalty": 600.8,
185
+ "feasible": false,
186
+ "sim_completed": 6,
187
+ "sim_avg_wait": 19.2,
188
+ "sim_or_util": 31.5,
189
+ "elapsed_sec": 0.0
190
+ },
191
+ {
192
+ "scenario_id": "or_daily",
193
+ "size": "medium",
194
+ "seed": 42,
195
+ "policy_id": "deterministic_mean",
196
+ "policy_label": "Deterministic Mean-Duration Plan",
197
+ "surgeries_completed": 16,
198
+ "surgeries_cancelled": 0,
199
+ "overtime_minutes": 0,
200
+ "or_utilization_pct": 55.7,
201
+ "bed_shortage_events": 13,
202
+ "avg_patient_wait_min": 162.6,
203
+ "schedule_changes": 0,
204
+ "specialty_fairness_gini": 0.161,
205
+ "composite_penalty": 552.6,
206
+ "feasible": false,
207
+ "sim_completed": 4,
208
+ "sim_avg_wait": 25.0,
209
+ "sim_or_util": 32.0,
210
+ "elapsed_sec": 0.029
211
+ },
212
+ {
213
+ "scenario_id": "or_daily",
214
+ "size": "medium",
215
+ "seed": 42,
216
+ "policy_id": "robust_quantile",
217
+ "policy_label": "Robust Quantile Schedule",
218
+ "surgeries_completed": 0,
219
+ "surgeries_cancelled": 16,
220
+ "overtime_minutes": 0,
221
+ "or_utilization_pct": 0,
222
+ "bed_shortage_events": 16,
223
+ "avg_patient_wait_min": 999,
224
+ "schedule_changes": 0,
225
+ "specialty_fairness_gini": 1.0,
226
+ "feasible": false,
227
+ "sim_completed": 0,
228
+ "sim_avg_wait": 0.0,
229
+ "sim_or_util": 0.0,
230
+ "elapsed_sec": 0.046
231
+ },
232
+ {
233
+ "scenario_id": "or_daily",
234
+ "size": "medium",
235
+ "seed": 42,
236
+ "policy_id": "rolling_horizon",
237
+ "policy_label": "Rolling Horizon Re-optimization",
238
+ "surgeries_completed": 16,
239
+ "surgeries_cancelled": 0,
240
+ "overtime_minutes": 67,
241
+ "or_utilization_pct": 64.1,
242
+ "bed_shortage_events": 15,
243
+ "avg_patient_wait_min": 254.4,
244
+ "schedule_changes": 0,
245
+ "specialty_fairness_gini": 0.161,
246
+ "composite_penalty": 737.9,
247
+ "feasible": false,
248
+ "sim_completed": 3,
249
+ "sim_avg_wait": 0.0,
250
+ "sim_or_util": 31.7,
251
+ "elapsed_sec": 0.015
252
+ },
253
+ {
254
+ "scenario_id": "or_daily",
255
+ "size": "medium",
256
+ "seed": 123,
257
+ "policy_id": "manual_fcfs",
258
+ "policy_label": "Manual / First-Come-First-Served",
259
+ "surgeries_completed": 16,
260
+ "surgeries_cancelled": 0,
261
+ "overtime_minutes": 0,
262
+ "or_utilization_pct": 37.2,
263
+ "bed_shortage_events": 13,
264
+ "avg_patient_wait_min": 120.1,
265
+ "schedule_changes": 0,
266
+ "specialty_fairness_gini": 0.25,
267
+ "composite_penalty": 510.1,
268
+ "feasible": false,
269
+ "sim_completed": 8,
270
+ "sim_avg_wait": 65.4,
271
+ "sim_or_util": 35.6,
272
+ "elapsed_sec": 0.0
273
+ },
274
+ {
275
+ "scenario_id": "or_daily",
276
+ "size": "medium",
277
+ "seed": 123,
278
+ "policy_id": "deterministic_mean",
279
+ "policy_label": "Deterministic Mean-Duration Plan",
280
+ "surgeries_completed": 16,
281
+ "surgeries_cancelled": 0,
282
+ "overtime_minutes": 0,
283
+ "or_utilization_pct": 37.2,
284
+ "bed_shortage_events": 13,
285
+ "avg_patient_wait_min": 125.4,
286
+ "schedule_changes": 0,
287
+ "specialty_fairness_gini": 0.25,
288
+ "composite_penalty": 515.4,
289
+ "feasible": false,
290
+ "sim_completed": 7,
291
+ "sim_avg_wait": 70.0,
292
+ "sim_or_util": 35.6,
293
+ "elapsed_sec": 0.032
294
+ },
295
+ {
296
+ "scenario_id": "or_daily",
297
+ "size": "medium",
298
+ "seed": 123,
299
+ "policy_id": "robust_quantile",
300
+ "policy_label": "Robust Quantile Schedule",
301
+ "surgeries_completed": 16,
302
+ "surgeries_cancelled": 0,
303
+ "overtime_minutes": 450,
304
+ "or_utilization_pct": 81.1,
305
+ "bed_shortage_events": 9,
306
+ "avg_patient_wait_min": 280.2,
307
+ "schedule_changes": 0,
308
+ "specialty_fairness_gini": 0.25,
309
+ "composite_penalty": 775.2,
310
+ "feasible": false,
311
+ "sim_completed": 2,
312
+ "sim_avg_wait": 0.8,
313
+ "sim_or_util": 35.7,
314
+ "elapsed_sec": 0.029
315
+ },
316
+ {
317
+ "scenario_id": "or_daily",
318
+ "size": "medium",
319
+ "seed": 123,
320
+ "policy_id": "rolling_horizon",
321
+ "policy_label": "Rolling Horizon Re-optimization",
322
+ "surgeries_completed": 16,
323
+ "surgeries_cancelled": 0,
324
+ "overtime_minutes": 60,
325
+ "or_utilization_pct": 69.1,
326
+ "bed_shortage_events": 10,
327
+ "avg_patient_wait_min": 226.3,
328
+ "schedule_changes": 0,
329
+ "specialty_fairness_gini": 0.25,
330
+ "composite_penalty": 556.3,
331
+ "feasible": false,
332
+ "sim_completed": 4,
333
+ "sim_avg_wait": 0.1,
334
+ "sim_or_util": 35.6,
335
+ "elapsed_sec": 0.03
336
+ },
337
+ {
338
+ "scenario_id": "emergency_surge",
339
+ "size": "small",
340
+ "seed": 42,
341
+ "policy_id": "manual_fcfs",
342
+ "policy_label": "Manual / First-Come-First-Served",
343
+ "surgeries_completed": 8,
344
+ "surgeries_cancelled": 0,
345
+ "overtime_minutes": 0,
346
+ "or_utilization_pct": 33.3,
347
+ "bed_shortage_events": 4,
348
+ "avg_patient_wait_min": 96.9,
349
+ "schedule_changes": 0,
350
+ "specialty_fairness_gini": 0.25,
351
+ "composite_penalty": 216.9,
352
+ "feasible": false,
353
+ "sim_completed": 4,
354
+ "sim_avg_wait": 10.6,
355
+ "sim_or_util": 25.8,
356
+ "elapsed_sec": 0.0
357
+ },
358
+ {
359
+ "scenario_id": "emergency_surge",
360
+ "size": "small",
361
+ "seed": 42,
362
+ "policy_id": "deterministic_mean",
363
+ "policy_label": "Deterministic Mean-Duration Plan",
364
+ "surgeries_completed": 8,
365
+ "surgeries_cancelled": 0,
366
+ "overtime_minutes": 0,
367
+ "or_utilization_pct": 33.3,
368
+ "bed_shortage_events": 5,
369
+ "avg_patient_wait_min": 71.0,
370
+ "schedule_changes": 0,
371
+ "specialty_fairness_gini": 0.25,
372
+ "composite_penalty": 221.0,
373
+ "feasible": false,
374
+ "sim_completed": 4,
375
+ "sim_avg_wait": 51.5,
376
+ "sim_or_util": 25.5,
377
+ "elapsed_sec": 0.013
378
+ },
379
+ {
380
+ "scenario_id": "emergency_surge",
381
+ "size": "small",
382
+ "seed": 42,
383
+ "policy_id": "robust_quantile",
384
+ "policy_label": "Robust Quantile Schedule",
385
+ "surgeries_completed": 8,
386
+ "surgeries_cancelled": 0,
387
+ "overtime_minutes": 0,
388
+ "or_utilization_pct": 61.6,
389
+ "bed_shortage_events": 5,
390
+ "avg_patient_wait_min": 148.2,
391
+ "schedule_changes": 0,
392
+ "specialty_fairness_gini": 0.25,
393
+ "composite_penalty": 298.2,
394
+ "feasible": false,
395
+ "sim_completed": 6,
396
+ "sim_avg_wait": 0.1,
397
+ "sim_or_util": 25.6,
398
+ "elapsed_sec": 0.016
399
+ },
400
+ {
401
+ "scenario_id": "emergency_surge",
402
+ "size": "small",
403
+ "seed": 42,
404
+ "policy_id": "rolling_horizon",
405
+ "policy_label": "Rolling Horizon Re-optimization",
406
+ "surgeries_completed": 8,
407
+ "surgeries_cancelled": 0,
408
+ "overtime_minutes": 0,
409
+ "or_utilization_pct": 51.2,
410
+ "bed_shortage_events": 2,
411
+ "avg_patient_wait_min": 137.5,
412
+ "schedule_changes": 0,
413
+ "specialty_fairness_gini": 0.25,
414
+ "composite_penalty": 197.5,
415
+ "feasible": false,
416
+ "sim_completed": 5,
417
+ "sim_avg_wait": 2.2,
418
+ "sim_or_util": 25.8,
419
+ "elapsed_sec": 0.015
420
+ },
421
+ {
422
+ "scenario_id": "emergency_surge",
423
+ "size": "small",
424
+ "seed": 123,
425
+ "policy_id": "manual_fcfs",
426
+ "policy_label": "Manual / First-Come-First-Served",
427
+ "surgeries_completed": 8,
428
+ "surgeries_cancelled": 0,
429
+ "overtime_minutes": 0,
430
+ "or_utilization_pct": 38.6,
431
+ "bed_shortage_events": 3,
432
+ "avg_patient_wait_min": 107.0,
433
+ "schedule_changes": 0,
434
+ "specialty_fairness_gini": 0.208,
435
+ "composite_penalty": 197.0,
436
+ "feasible": false,
437
+ "sim_completed": 6,
438
+ "sim_avg_wait": 25.2,
439
+ "sim_or_util": 28.0,
440
+ "elapsed_sec": 0.0
441
+ },
442
+ {
443
+ "scenario_id": "emergency_surge",
444
+ "size": "small",
445
+ "seed": 123,
446
+ "policy_id": "deterministic_mean",
447
+ "policy_label": "Deterministic Mean-Duration Plan",
448
+ "surgeries_completed": 8,
449
+ "surgeries_cancelled": 0,
450
+ "overtime_minutes": 0,
451
+ "or_utilization_pct": 38.6,
452
+ "bed_shortage_events": 3,
453
+ "avg_patient_wait_min": 99.6,
454
+ "schedule_changes": 0,
455
+ "specialty_fairness_gini": 0.208,
456
+ "composite_penalty": 189.6,
457
+ "feasible": false,
458
+ "sim_completed": 5,
459
+ "sim_avg_wait": 57.1,
460
+ "sim_or_util": 27.9,
461
+ "elapsed_sec": 0.015
462
+ },
463
+ {
464
+ "scenario_id": "emergency_surge",
465
+ "size": "small",
466
+ "seed": 123,
467
+ "policy_id": "robust_quantile",
468
+ "policy_label": "Robust Quantile Schedule",
469
+ "surgeries_completed": 8,
470
+ "surgeries_cancelled": 0,
471
+ "overtime_minutes": 0,
472
+ "or_utilization_pct": 62.3,
473
+ "bed_shortage_events": 3,
474
+ "avg_patient_wait_min": 146.9,
475
+ "schedule_changes": 0,
476
+ "specialty_fairness_gini": 0.208,
477
+ "composite_penalty": 236.9,
478
+ "feasible": false,
479
+ "sim_completed": 6,
480
+ "sim_avg_wait": 1.2,
481
+ "sim_or_util": 28.0,
482
+ "elapsed_sec": 0.015
483
+ },
484
+ {
485
+ "scenario_id": "emergency_surge",
486
+ "size": "small",
487
+ "seed": 123,
488
+ "policy_id": "rolling_horizon",
489
+ "policy_label": "Rolling Horizon Re-optimization",
490
+ "surgeries_completed": 8,
491
+ "surgeries_cancelled": 0,
492
+ "overtime_minutes": 0,
493
+ "or_utilization_pct": 52.1,
494
+ "bed_shortage_events": 3,
495
+ "avg_patient_wait_min": 142.8,
496
+ "schedule_changes": 0,
497
+ "specialty_fairness_gini": 0.208,
498
+ "composite_penalty": 232.8,
499
+ "feasible": false,
500
+ "sim_completed": 4,
501
+ "sim_avg_wait": 0.4,
502
+ "sim_or_util": 28.3,
503
+ "elapsed_sec": 0.002
504
+ },
505
+ {
506
+ "scenario_id": "emergency_surge",
507
+ "size": "medium",
508
+ "seed": 42,
509
+ "policy_id": "manual_fcfs",
510
+ "policy_label": "Manual / First-Come-First-Served",
511
+ "surgeries_completed": 16,
512
+ "surgeries_cancelled": 0,
513
+ "overtime_minutes": 38,
514
+ "or_utilization_pct": 54.4,
515
+ "bed_shortage_events": 11,
516
+ "avg_patient_wait_min": 155.2,
517
+ "schedule_changes": 0,
518
+ "specialty_fairness_gini": 0.25,
519
+ "composite_penalty": 504.2,
520
+ "feasible": false,
521
+ "sim_completed": 5,
522
+ "sim_avg_wait": 30.6,
523
+ "sim_or_util": 33.4,
524
+ "elapsed_sec": 0.0
525
+ },
526
+ {
527
+ "scenario_id": "emergency_surge",
528
+ "size": "medium",
529
+ "seed": 42,
530
+ "policy_id": "deterministic_mean",
531
+ "policy_label": "Deterministic Mean-Duration Plan",
532
+ "surgeries_completed": 16,
533
+ "surgeries_cancelled": 0,
534
+ "overtime_minutes": 0,
535
+ "or_utilization_pct": 54.4,
536
+ "bed_shortage_events": 13,
537
+ "avg_patient_wait_min": 160.7,
538
+ "schedule_changes": 0,
539
+ "specialty_fairness_gini": 0.25,
540
+ "composite_penalty": 550.7,
541
+ "feasible": false,
542
+ "sim_completed": 2,
543
+ "sim_avg_wait": 65.0,
544
+ "sim_or_util": 33.6,
545
+ "elapsed_sec": 0.03
546
+ },
547
+ {
548
+ "scenario_id": "emergency_surge",
549
+ "size": "medium",
550
+ "seed": 42,
551
+ "policy_id": "robust_quantile",
552
+ "policy_label": "Robust Quantile Schedule",
553
+ "surgeries_completed": 16,
554
+ "surgeries_cancelled": 0,
555
+ "overtime_minutes": 156,
556
+ "or_utilization_pct": 79.6,
557
+ "bed_shortage_events": 12,
558
+ "avg_patient_wait_min": 286.4,
559
+ "schedule_changes": 0,
560
+ "specialty_fairness_gini": 0.25,
561
+ "composite_penalty": 724.4,
562
+ "feasible": false,
563
+ "sim_completed": 3,
564
+ "sim_avg_wait": 0.0,
565
+ "sim_or_util": 33.4,
566
+ "elapsed_sec": 0.03
567
+ },
568
+ {
569
+ "scenario_id": "emergency_surge",
570
+ "size": "medium",
571
+ "seed": 42,
572
+ "policy_id": "rolling_horizon",
573
+ "policy_label": "Rolling Horizon Re-optimization",
574
+ "surgeries_completed": 16,
575
+ "surgeries_cancelled": 0,
576
+ "overtime_minutes": 0,
577
+ "or_utilization_pct": 66.2,
578
+ "bed_shortage_events": 11,
579
+ "avg_patient_wait_min": 215.6,
580
+ "schedule_changes": 0,
581
+ "specialty_fairness_gini": 0.25,
582
+ "composite_penalty": 545.6,
583
+ "feasible": false,
584
+ "sim_completed": 4,
585
+ "sim_avg_wait": 0.0,
586
+ "sim_or_util": 33.6,
587
+ "elapsed_sec": 0.007
588
+ },
589
+ {
590
+ "scenario_id": "emergency_surge",
591
+ "size": "medium",
592
+ "seed": 123,
593
+ "policy_id": "manual_fcfs",
594
+ "policy_label": "Manual / First-Come-First-Served",
595
+ "surgeries_completed": 16,
596
+ "surgeries_cancelled": 0,
597
+ "overtime_minutes": 0,
598
+ "or_utilization_pct": 38.6,
599
+ "bed_shortage_events": 13,
600
+ "avg_patient_wait_min": 127.5,
601
+ "schedule_changes": 0,
602
+ "specialty_fairness_gini": 0.225,
603
+ "composite_penalty": 517.5,
604
+ "feasible": false,
605
+ "sim_completed": 5,
606
+ "sim_avg_wait": 51.9,
607
+ "sim_or_util": 34.3,
608
+ "elapsed_sec": 0.0
609
+ },
610
+ {
611
+ "scenario_id": "emergency_surge",
612
+ "size": "medium",
613
+ "seed": 123,
614
+ "policy_id": "deterministic_mean",
615
+ "policy_label": "Deterministic Mean-Duration Plan",
616
+ "surgeries_completed": 16,
617
+ "surgeries_cancelled": 0,
618
+ "overtime_minutes": 0,
619
+ "or_utilization_pct": 38.6,
620
+ "bed_shortage_events": 13,
621
+ "avg_patient_wait_min": 118.6,
622
+ "schedule_changes": 0,
623
+ "specialty_fairness_gini": 0.225,
624
+ "composite_penalty": 508.6,
625
+ "feasible": false,
626
+ "sim_completed": 7,
627
+ "sim_avg_wait": 89.6,
628
+ "sim_or_util": 34.6,
629
+ "elapsed_sec": 0.038
630
+ },
631
+ {
632
+ "scenario_id": "emergency_surge",
633
+ "size": "medium",
634
+ "seed": 123,
635
+ "policy_id": "robust_quantile",
636
+ "policy_label": "Robust Quantile Schedule",
637
+ "surgeries_completed": 16,
638
+ "surgeries_cancelled": 0,
639
+ "overtime_minutes": 618,
640
+ "or_utilization_pct": 78.5,
641
+ "bed_shortage_events": 1,
642
+ "avg_patient_wait_min": 321.1,
643
+ "schedule_changes": 0,
644
+ "specialty_fairness_gini": 0.225,
645
+ "composite_penalty": 660.1,
646
+ "feasible": false,
647
+ "sim_completed": 4,
648
+ "sim_avg_wait": 0.2,
649
+ "sim_or_util": 34.6,
650
+ "elapsed_sec": 0.033
651
+ },
652
+ {
653
+ "scenario_id": "emergency_surge",
654
+ "size": "medium",
655
+ "seed": 123,
656
+ "policy_id": "rolling_horizon",
657
+ "policy_label": "Rolling Horizon Re-optimization",
658
+ "surgeries_completed": 16,
659
+ "surgeries_cancelled": 0,
660
+ "overtime_minutes": 0,
661
+ "or_utilization_pct": 65.2,
662
+ "bed_shortage_events": 6,
663
+ "avg_patient_wait_min": 212.2,
664
+ "schedule_changes": 0,
665
+ "specialty_fairness_gini": 0.225,
666
+ "composite_penalty": 392.2,
667
+ "feasible": false,
668
+ "sim_completed": 6,
669
+ "sim_avg_wait": 0.0,
670
+ "sim_or_util": 34.3,
671
+ "elapsed_sec": 0.008
672
+ }
673
+ ]
space-bundle/assets/demo/comparisons.json ADDED
@@ -0,0 +1,741 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "or_daily": [
3
+ {
4
+ "size": "small",
5
+ "seed": 42,
6
+ "winner": "deterministic_mean",
7
+ "winner_label": "Deterministic Mean-Duration Plan",
8
+ "policies": {
9
+ "manual_fcfs": {
10
+ "scenario_id": "or_daily",
11
+ "size": "small",
12
+ "seed": 42,
13
+ "policy_id": "manual_fcfs",
14
+ "policy_label": "Manual / First-Come-First-Served",
15
+ "surgeries_completed": 8,
16
+ "surgeries_cancelled": 0,
17
+ "overtime_minutes": 0,
18
+ "or_utilization_pct": 38.1,
19
+ "bed_shortage_events": 7,
20
+ "avg_patient_wait_min": 108.9,
21
+ "schedule_changes": 0,
22
+ "specialty_fairness_gini": 0.25,
23
+ "composite_penalty": 318.9,
24
+ "feasible": false,
25
+ "sim_completed": 5,
26
+ "sim_avg_wait": 16.1,
27
+ "sim_or_util": 24.8,
28
+ "elapsed_sec": 0.0
29
+ },
30
+ "deterministic_mean": {
31
+ "scenario_id": "or_daily",
32
+ "size": "small",
33
+ "seed": 42,
34
+ "policy_id": "deterministic_mean",
35
+ "policy_label": "Deterministic Mean-Duration Plan",
36
+ "surgeries_completed": 8,
37
+ "surgeries_cancelled": 0,
38
+ "overtime_minutes": 0,
39
+ "or_utilization_pct": 38.1,
40
+ "bed_shortage_events": 7,
41
+ "avg_patient_wait_min": 99.0,
42
+ "schedule_changes": 0,
43
+ "specialty_fairness_gini": 0.25,
44
+ "composite_penalty": 309.0,
45
+ "feasible": false,
46
+ "sim_completed": 6,
47
+ "sim_avg_wait": 30.0,
48
+ "sim_or_util": 24.7,
49
+ "elapsed_sec": 0.587
50
+ },
51
+ "robust_quantile": {
52
+ "scenario_id": "or_daily",
53
+ "size": "small",
54
+ "seed": 42,
55
+ "policy_id": "robust_quantile",
56
+ "policy_label": "Robust Quantile Schedule",
57
+ "surgeries_completed": 8,
58
+ "surgeries_cancelled": 0,
59
+ "overtime_minutes": 0,
60
+ "or_utilization_pct": 59.9,
61
+ "bed_shortage_events": 5,
62
+ "avg_patient_wait_min": 215.4,
63
+ "schedule_changes": 0,
64
+ "specialty_fairness_gini": 0.25,
65
+ "composite_penalty": 365.4,
66
+ "feasible": false,
67
+ "sim_completed": 4,
68
+ "sim_avg_wait": 0.1,
69
+ "sim_or_util": 24.7,
70
+ "elapsed_sec": 0.015
71
+ },
72
+ "rolling_horizon": {
73
+ "scenario_id": "or_daily",
74
+ "size": "small",
75
+ "seed": 42,
76
+ "policy_id": "rolling_horizon",
77
+ "policy_label": "Rolling Horizon Re-optimization",
78
+ "surgeries_completed": 8,
79
+ "surgeries_cancelled": 0,
80
+ "overtime_minutes": 0,
81
+ "or_utilization_pct": 49.6,
82
+ "bed_shortage_events": 7,
83
+ "avg_patient_wait_min": 147.4,
84
+ "schedule_changes": 0,
85
+ "specialty_fairness_gini": 0.25,
86
+ "composite_penalty": 357.4,
87
+ "feasible": false,
88
+ "sim_completed": 2,
89
+ "sim_avg_wait": 0.1,
90
+ "sim_or_util": 24.8,
91
+ "elapsed_sec": 0.002
92
+ }
93
+ }
94
+ },
95
+ {
96
+ "size": "small",
97
+ "seed": 123,
98
+ "winner": "deterministic_mean",
99
+ "winner_label": "Deterministic Mean-Duration Plan",
100
+ "policies": {
101
+ "manual_fcfs": {
102
+ "scenario_id": "or_daily",
103
+ "size": "small",
104
+ "seed": 123,
105
+ "policy_id": "manual_fcfs",
106
+ "policy_label": "Manual / First-Come-First-Served",
107
+ "surgeries_completed": 8,
108
+ "surgeries_cancelled": 0,
109
+ "overtime_minutes": 0,
110
+ "or_utilization_pct": 33.8,
111
+ "bed_shortage_events": 5,
112
+ "avg_patient_wait_min": 114.9,
113
+ "schedule_changes": 0,
114
+ "specialty_fairness_gini": 0.188,
115
+ "composite_penalty": 264.9,
116
+ "feasible": false,
117
+ "sim_completed": 5,
118
+ "sim_avg_wait": 44.8,
119
+ "sim_or_util": 30.8,
120
+ "elapsed_sec": 0.0
121
+ },
122
+ "deterministic_mean": {
123
+ "scenario_id": "or_daily",
124
+ "size": "small",
125
+ "seed": 123,
126
+ "policy_id": "deterministic_mean",
127
+ "policy_label": "Deterministic Mean-Duration Plan",
128
+ "surgeries_completed": 8,
129
+ "surgeries_cancelled": 0,
130
+ "overtime_minutes": 0,
131
+ "or_utilization_pct": 33.8,
132
+ "bed_shortage_events": 5,
133
+ "avg_patient_wait_min": 79.1,
134
+ "schedule_changes": 0,
135
+ "specialty_fairness_gini": 0.188,
136
+ "composite_penalty": 229.1,
137
+ "feasible": false,
138
+ "sim_completed": 3,
139
+ "sim_avg_wait": 61.9,
140
+ "sim_or_util": 30.9,
141
+ "elapsed_sec": 0.027
142
+ },
143
+ "robust_quantile": {
144
+ "scenario_id": "or_daily",
145
+ "size": "small",
146
+ "seed": 123,
147
+ "policy_id": "robust_quantile",
148
+ "policy_label": "Robust Quantile Schedule",
149
+ "surgeries_completed": 8,
150
+ "surgeries_cancelled": 0,
151
+ "overtime_minutes": 0,
152
+ "or_utilization_pct": 68.2,
153
+ "bed_shortage_events": 5,
154
+ "avg_patient_wait_min": 178.4,
155
+ "schedule_changes": 0,
156
+ "specialty_fairness_gini": 0.188,
157
+ "composite_penalty": 328.4,
158
+ "feasible": false,
159
+ "sim_completed": 5,
160
+ "sim_avg_wait": 1.4,
161
+ "sim_or_util": 30.9,
162
+ "elapsed_sec": 0.015
163
+ },
164
+ "rolling_horizon": {
165
+ "scenario_id": "or_daily",
166
+ "size": "small",
167
+ "seed": 123,
168
+ "policy_id": "rolling_horizon",
169
+ "policy_label": "Rolling Horizon Re-optimization",
170
+ "surgeries_completed": 8,
171
+ "surgeries_cancelled": 0,
172
+ "overtime_minutes": 0,
173
+ "or_utilization_pct": 56.9,
174
+ "bed_shortage_events": 5,
175
+ "avg_patient_wait_min": 146.4,
176
+ "schedule_changes": 0,
177
+ "specialty_fairness_gini": 0.188,
178
+ "composite_penalty": 296.4,
179
+ "feasible": false,
180
+ "sim_completed": 4,
181
+ "sim_avg_wait": 0.4,
182
+ "sim_or_util": 30.6,
183
+ "elapsed_sec": 0.002
184
+ }
185
+ }
186
+ },
187
+ {
188
+ "size": "medium",
189
+ "seed": 42,
190
+ "winner": "deterministic_mean",
191
+ "winner_label": "Deterministic Mean-Duration Plan",
192
+ "policies": {
193
+ "manual_fcfs": {
194
+ "scenario_id": "or_daily",
195
+ "size": "medium",
196
+ "seed": 42,
197
+ "policy_id": "manual_fcfs",
198
+ "policy_label": "Manual / First-Come-First-Served",
199
+ "surgeries_completed": 16,
200
+ "surgeries_cancelled": 0,
201
+ "overtime_minutes": 84,
202
+ "or_utilization_pct": 55.7,
203
+ "bed_shortage_events": 13,
204
+ "avg_patient_wait_min": 168.8,
205
+ "schedule_changes": 0,
206
+ "specialty_fairness_gini": 0.161,
207
+ "composite_penalty": 600.8,
208
+ "feasible": false,
209
+ "sim_completed": 6,
210
+ "sim_avg_wait": 19.2,
211
+ "sim_or_util": 31.5,
212
+ "elapsed_sec": 0.0
213
+ },
214
+ "deterministic_mean": {
215
+ "scenario_id": "or_daily",
216
+ "size": "medium",
217
+ "seed": 42,
218
+ "policy_id": "deterministic_mean",
219
+ "policy_label": "Deterministic Mean-Duration Plan",
220
+ "surgeries_completed": 16,
221
+ "surgeries_cancelled": 0,
222
+ "overtime_minutes": 0,
223
+ "or_utilization_pct": 55.7,
224
+ "bed_shortage_events": 13,
225
+ "avg_patient_wait_min": 162.6,
226
+ "schedule_changes": 0,
227
+ "specialty_fairness_gini": 0.161,
228
+ "composite_penalty": 552.6,
229
+ "feasible": false,
230
+ "sim_completed": 4,
231
+ "sim_avg_wait": 25.0,
232
+ "sim_or_util": 32.0,
233
+ "elapsed_sec": 0.029
234
+ },
235
+ "robust_quantile": {
236
+ "scenario_id": "or_daily",
237
+ "size": "medium",
238
+ "seed": 42,
239
+ "policy_id": "robust_quantile",
240
+ "policy_label": "Robust Quantile Schedule",
241
+ "surgeries_completed": 0,
242
+ "surgeries_cancelled": 16,
243
+ "overtime_minutes": 0,
244
+ "or_utilization_pct": 0,
245
+ "bed_shortage_events": 16,
246
+ "avg_patient_wait_min": 999,
247
+ "schedule_changes": 0,
248
+ "specialty_fairness_gini": 1.0,
249
+ "feasible": false,
250
+ "sim_completed": 0,
251
+ "sim_avg_wait": 0.0,
252
+ "sim_or_util": 0.0,
253
+ "elapsed_sec": 0.046
254
+ },
255
+ "rolling_horizon": {
256
+ "scenario_id": "or_daily",
257
+ "size": "medium",
258
+ "seed": 42,
259
+ "policy_id": "rolling_horizon",
260
+ "policy_label": "Rolling Horizon Re-optimization",
261
+ "surgeries_completed": 16,
262
+ "surgeries_cancelled": 0,
263
+ "overtime_minutes": 67,
264
+ "or_utilization_pct": 64.1,
265
+ "bed_shortage_events": 15,
266
+ "avg_patient_wait_min": 254.4,
267
+ "schedule_changes": 0,
268
+ "specialty_fairness_gini": 0.161,
269
+ "composite_penalty": 737.9,
270
+ "feasible": false,
271
+ "sim_completed": 3,
272
+ "sim_avg_wait": 0.0,
273
+ "sim_or_util": 31.7,
274
+ "elapsed_sec": 0.015
275
+ }
276
+ }
277
+ },
278
+ {
279
+ "size": "medium",
280
+ "seed": 123,
281
+ "winner": "manual_fcfs",
282
+ "winner_label": "Manual / First-Come-First-Served",
283
+ "policies": {
284
+ "manual_fcfs": {
285
+ "scenario_id": "or_daily",
286
+ "size": "medium",
287
+ "seed": 123,
288
+ "policy_id": "manual_fcfs",
289
+ "policy_label": "Manual / First-Come-First-Served",
290
+ "surgeries_completed": 16,
291
+ "surgeries_cancelled": 0,
292
+ "overtime_minutes": 0,
293
+ "or_utilization_pct": 37.2,
294
+ "bed_shortage_events": 13,
295
+ "avg_patient_wait_min": 120.1,
296
+ "schedule_changes": 0,
297
+ "specialty_fairness_gini": 0.25,
298
+ "composite_penalty": 510.1,
299
+ "feasible": false,
300
+ "sim_completed": 8,
301
+ "sim_avg_wait": 65.4,
302
+ "sim_or_util": 35.6,
303
+ "elapsed_sec": 0.0
304
+ },
305
+ "deterministic_mean": {
306
+ "scenario_id": "or_daily",
307
+ "size": "medium",
308
+ "seed": 123,
309
+ "policy_id": "deterministic_mean",
310
+ "policy_label": "Deterministic Mean-Duration Plan",
311
+ "surgeries_completed": 16,
312
+ "surgeries_cancelled": 0,
313
+ "overtime_minutes": 0,
314
+ "or_utilization_pct": 37.2,
315
+ "bed_shortage_events": 13,
316
+ "avg_patient_wait_min": 125.4,
317
+ "schedule_changes": 0,
318
+ "specialty_fairness_gini": 0.25,
319
+ "composite_penalty": 515.4,
320
+ "feasible": false,
321
+ "sim_completed": 7,
322
+ "sim_avg_wait": 70.0,
323
+ "sim_or_util": 35.6,
324
+ "elapsed_sec": 0.032
325
+ },
326
+ "robust_quantile": {
327
+ "scenario_id": "or_daily",
328
+ "size": "medium",
329
+ "seed": 123,
330
+ "policy_id": "robust_quantile",
331
+ "policy_label": "Robust Quantile Schedule",
332
+ "surgeries_completed": 16,
333
+ "surgeries_cancelled": 0,
334
+ "overtime_minutes": 450,
335
+ "or_utilization_pct": 81.1,
336
+ "bed_shortage_events": 9,
337
+ "avg_patient_wait_min": 280.2,
338
+ "schedule_changes": 0,
339
+ "specialty_fairness_gini": 0.25,
340
+ "composite_penalty": 775.2,
341
+ "feasible": false,
342
+ "sim_completed": 2,
343
+ "sim_avg_wait": 0.8,
344
+ "sim_or_util": 35.7,
345
+ "elapsed_sec": 0.029
346
+ },
347
+ "rolling_horizon": {
348
+ "scenario_id": "or_daily",
349
+ "size": "medium",
350
+ "seed": 123,
351
+ "policy_id": "rolling_horizon",
352
+ "policy_label": "Rolling Horizon Re-optimization",
353
+ "surgeries_completed": 16,
354
+ "surgeries_cancelled": 0,
355
+ "overtime_minutes": 60,
356
+ "or_utilization_pct": 69.1,
357
+ "bed_shortage_events": 10,
358
+ "avg_patient_wait_min": 226.3,
359
+ "schedule_changes": 0,
360
+ "specialty_fairness_gini": 0.25,
361
+ "composite_penalty": 556.3,
362
+ "feasible": false,
363
+ "sim_completed": 4,
364
+ "sim_avg_wait": 0.1,
365
+ "sim_or_util": 35.6,
366
+ "elapsed_sec": 0.03
367
+ }
368
+ }
369
+ }
370
+ ],
371
+ "emergency_surge": [
372
+ {
373
+ "size": "small",
374
+ "seed": 42,
375
+ "winner": "rolling_horizon",
376
+ "winner_label": "Rolling Horizon Re-optimization",
377
+ "policies": {
378
+ "manual_fcfs": {
379
+ "scenario_id": "emergency_surge",
380
+ "size": "small",
381
+ "seed": 42,
382
+ "policy_id": "manual_fcfs",
383
+ "policy_label": "Manual / First-Come-First-Served",
384
+ "surgeries_completed": 8,
385
+ "surgeries_cancelled": 0,
386
+ "overtime_minutes": 0,
387
+ "or_utilization_pct": 33.3,
388
+ "bed_shortage_events": 4,
389
+ "avg_patient_wait_min": 96.9,
390
+ "schedule_changes": 0,
391
+ "specialty_fairness_gini": 0.25,
392
+ "composite_penalty": 216.9,
393
+ "feasible": false,
394
+ "sim_completed": 4,
395
+ "sim_avg_wait": 10.6,
396
+ "sim_or_util": 25.8,
397
+ "elapsed_sec": 0.0
398
+ },
399
+ "deterministic_mean": {
400
+ "scenario_id": "emergency_surge",
401
+ "size": "small",
402
+ "seed": 42,
403
+ "policy_id": "deterministic_mean",
404
+ "policy_label": "Deterministic Mean-Duration Plan",
405
+ "surgeries_completed": 8,
406
+ "surgeries_cancelled": 0,
407
+ "overtime_minutes": 0,
408
+ "or_utilization_pct": 33.3,
409
+ "bed_shortage_events": 5,
410
+ "avg_patient_wait_min": 71.0,
411
+ "schedule_changes": 0,
412
+ "specialty_fairness_gini": 0.25,
413
+ "composite_penalty": 221.0,
414
+ "feasible": false,
415
+ "sim_completed": 4,
416
+ "sim_avg_wait": 51.5,
417
+ "sim_or_util": 25.5,
418
+ "elapsed_sec": 0.013
419
+ },
420
+ "robust_quantile": {
421
+ "scenario_id": "emergency_surge",
422
+ "size": "small",
423
+ "seed": 42,
424
+ "policy_id": "robust_quantile",
425
+ "policy_label": "Robust Quantile Schedule",
426
+ "surgeries_completed": 8,
427
+ "surgeries_cancelled": 0,
428
+ "overtime_minutes": 0,
429
+ "or_utilization_pct": 61.6,
430
+ "bed_shortage_events": 5,
431
+ "avg_patient_wait_min": 148.2,
432
+ "schedule_changes": 0,
433
+ "specialty_fairness_gini": 0.25,
434
+ "composite_penalty": 298.2,
435
+ "feasible": false,
436
+ "sim_completed": 6,
437
+ "sim_avg_wait": 0.1,
438
+ "sim_or_util": 25.6,
439
+ "elapsed_sec": 0.016
440
+ },
441
+ "rolling_horizon": {
442
+ "scenario_id": "emergency_surge",
443
+ "size": "small",
444
+ "seed": 42,
445
+ "policy_id": "rolling_horizon",
446
+ "policy_label": "Rolling Horizon Re-optimization",
447
+ "surgeries_completed": 8,
448
+ "surgeries_cancelled": 0,
449
+ "overtime_minutes": 0,
450
+ "or_utilization_pct": 51.2,
451
+ "bed_shortage_events": 2,
452
+ "avg_patient_wait_min": 137.5,
453
+ "schedule_changes": 0,
454
+ "specialty_fairness_gini": 0.25,
455
+ "composite_penalty": 197.5,
456
+ "feasible": false,
457
+ "sim_completed": 5,
458
+ "sim_avg_wait": 2.2,
459
+ "sim_or_util": 25.8,
460
+ "elapsed_sec": 0.015
461
+ }
462
+ }
463
+ },
464
+ {
465
+ "size": "small",
466
+ "seed": 123,
467
+ "winner": "deterministic_mean",
468
+ "winner_label": "Deterministic Mean-Duration Plan",
469
+ "policies": {
470
+ "manual_fcfs": {
471
+ "scenario_id": "emergency_surge",
472
+ "size": "small",
473
+ "seed": 123,
474
+ "policy_id": "manual_fcfs",
475
+ "policy_label": "Manual / First-Come-First-Served",
476
+ "surgeries_completed": 8,
477
+ "surgeries_cancelled": 0,
478
+ "overtime_minutes": 0,
479
+ "or_utilization_pct": 38.6,
480
+ "bed_shortage_events": 3,
481
+ "avg_patient_wait_min": 107.0,
482
+ "schedule_changes": 0,
483
+ "specialty_fairness_gini": 0.208,
484
+ "composite_penalty": 197.0,
485
+ "feasible": false,
486
+ "sim_completed": 6,
487
+ "sim_avg_wait": 25.2,
488
+ "sim_or_util": 28.0,
489
+ "elapsed_sec": 0.0
490
+ },
491
+ "deterministic_mean": {
492
+ "scenario_id": "emergency_surge",
493
+ "size": "small",
494
+ "seed": 123,
495
+ "policy_id": "deterministic_mean",
496
+ "policy_label": "Deterministic Mean-Duration Plan",
497
+ "surgeries_completed": 8,
498
+ "surgeries_cancelled": 0,
499
+ "overtime_minutes": 0,
500
+ "or_utilization_pct": 38.6,
501
+ "bed_shortage_events": 3,
502
+ "avg_patient_wait_min": 99.6,
503
+ "schedule_changes": 0,
504
+ "specialty_fairness_gini": 0.208,
505
+ "composite_penalty": 189.6,
506
+ "feasible": false,
507
+ "sim_completed": 5,
508
+ "sim_avg_wait": 57.1,
509
+ "sim_or_util": 27.9,
510
+ "elapsed_sec": 0.015
511
+ },
512
+ "robust_quantile": {
513
+ "scenario_id": "emergency_surge",
514
+ "size": "small",
515
+ "seed": 123,
516
+ "policy_id": "robust_quantile",
517
+ "policy_label": "Robust Quantile Schedule",
518
+ "surgeries_completed": 8,
519
+ "surgeries_cancelled": 0,
520
+ "overtime_minutes": 0,
521
+ "or_utilization_pct": 62.3,
522
+ "bed_shortage_events": 3,
523
+ "avg_patient_wait_min": 146.9,
524
+ "schedule_changes": 0,
525
+ "specialty_fairness_gini": 0.208,
526
+ "composite_penalty": 236.9,
527
+ "feasible": false,
528
+ "sim_completed": 6,
529
+ "sim_avg_wait": 1.2,
530
+ "sim_or_util": 28.0,
531
+ "elapsed_sec": 0.015
532
+ },
533
+ "rolling_horizon": {
534
+ "scenario_id": "emergency_surge",
535
+ "size": "small",
536
+ "seed": 123,
537
+ "policy_id": "rolling_horizon",
538
+ "policy_label": "Rolling Horizon Re-optimization",
539
+ "surgeries_completed": 8,
540
+ "surgeries_cancelled": 0,
541
+ "overtime_minutes": 0,
542
+ "or_utilization_pct": 52.1,
543
+ "bed_shortage_events": 3,
544
+ "avg_patient_wait_min": 142.8,
545
+ "schedule_changes": 0,
546
+ "specialty_fairness_gini": 0.208,
547
+ "composite_penalty": 232.8,
548
+ "feasible": false,
549
+ "sim_completed": 4,
550
+ "sim_avg_wait": 0.4,
551
+ "sim_or_util": 28.3,
552
+ "elapsed_sec": 0.002
553
+ }
554
+ }
555
+ },
556
+ {
557
+ "size": "medium",
558
+ "seed": 42,
559
+ "winner": "manual_fcfs",
560
+ "winner_label": "Manual / First-Come-First-Served",
561
+ "policies": {
562
+ "manual_fcfs": {
563
+ "scenario_id": "emergency_surge",
564
+ "size": "medium",
565
+ "seed": 42,
566
+ "policy_id": "manual_fcfs",
567
+ "policy_label": "Manual / First-Come-First-Served",
568
+ "surgeries_completed": 16,
569
+ "surgeries_cancelled": 0,
570
+ "overtime_minutes": 38,
571
+ "or_utilization_pct": 54.4,
572
+ "bed_shortage_events": 11,
573
+ "avg_patient_wait_min": 155.2,
574
+ "schedule_changes": 0,
575
+ "specialty_fairness_gini": 0.25,
576
+ "composite_penalty": 504.2,
577
+ "feasible": false,
578
+ "sim_completed": 5,
579
+ "sim_avg_wait": 30.6,
580
+ "sim_or_util": 33.4,
581
+ "elapsed_sec": 0.0
582
+ },
583
+ "deterministic_mean": {
584
+ "scenario_id": "emergency_surge",
585
+ "size": "medium",
586
+ "seed": 42,
587
+ "policy_id": "deterministic_mean",
588
+ "policy_label": "Deterministic Mean-Duration Plan",
589
+ "surgeries_completed": 16,
590
+ "surgeries_cancelled": 0,
591
+ "overtime_minutes": 0,
592
+ "or_utilization_pct": 54.4,
593
+ "bed_shortage_events": 13,
594
+ "avg_patient_wait_min": 160.7,
595
+ "schedule_changes": 0,
596
+ "specialty_fairness_gini": 0.25,
597
+ "composite_penalty": 550.7,
598
+ "feasible": false,
599
+ "sim_completed": 2,
600
+ "sim_avg_wait": 65.0,
601
+ "sim_or_util": 33.6,
602
+ "elapsed_sec": 0.03
603
+ },
604
+ "robust_quantile": {
605
+ "scenario_id": "emergency_surge",
606
+ "size": "medium",
607
+ "seed": 42,
608
+ "policy_id": "robust_quantile",
609
+ "policy_label": "Robust Quantile Schedule",
610
+ "surgeries_completed": 16,
611
+ "surgeries_cancelled": 0,
612
+ "overtime_minutes": 156,
613
+ "or_utilization_pct": 79.6,
614
+ "bed_shortage_events": 12,
615
+ "avg_patient_wait_min": 286.4,
616
+ "schedule_changes": 0,
617
+ "specialty_fairness_gini": 0.25,
618
+ "composite_penalty": 724.4,
619
+ "feasible": false,
620
+ "sim_completed": 3,
621
+ "sim_avg_wait": 0.0,
622
+ "sim_or_util": 33.4,
623
+ "elapsed_sec": 0.03
624
+ },
625
+ "rolling_horizon": {
626
+ "scenario_id": "emergency_surge",
627
+ "size": "medium",
628
+ "seed": 42,
629
+ "policy_id": "rolling_horizon",
630
+ "policy_label": "Rolling Horizon Re-optimization",
631
+ "surgeries_completed": 16,
632
+ "surgeries_cancelled": 0,
633
+ "overtime_minutes": 0,
634
+ "or_utilization_pct": 66.2,
635
+ "bed_shortage_events": 11,
636
+ "avg_patient_wait_min": 215.6,
637
+ "schedule_changes": 0,
638
+ "specialty_fairness_gini": 0.25,
639
+ "composite_penalty": 545.6,
640
+ "feasible": false,
641
+ "sim_completed": 4,
642
+ "sim_avg_wait": 0.0,
643
+ "sim_or_util": 33.6,
644
+ "elapsed_sec": 0.007
645
+ }
646
+ }
647
+ },
648
+ {
649
+ "size": "medium",
650
+ "seed": 123,
651
+ "winner": "rolling_horizon",
652
+ "winner_label": "Rolling Horizon Re-optimization",
653
+ "policies": {
654
+ "manual_fcfs": {
655
+ "scenario_id": "emergency_surge",
656
+ "size": "medium",
657
+ "seed": 123,
658
+ "policy_id": "manual_fcfs",
659
+ "policy_label": "Manual / First-Come-First-Served",
660
+ "surgeries_completed": 16,
661
+ "surgeries_cancelled": 0,
662
+ "overtime_minutes": 0,
663
+ "or_utilization_pct": 38.6,
664
+ "bed_shortage_events": 13,
665
+ "avg_patient_wait_min": 127.5,
666
+ "schedule_changes": 0,
667
+ "specialty_fairness_gini": 0.225,
668
+ "composite_penalty": 517.5,
669
+ "feasible": false,
670
+ "sim_completed": 5,
671
+ "sim_avg_wait": 51.9,
672
+ "sim_or_util": 34.3,
673
+ "elapsed_sec": 0.0
674
+ },
675
+ "deterministic_mean": {
676
+ "scenario_id": "emergency_surge",
677
+ "size": "medium",
678
+ "seed": 123,
679
+ "policy_id": "deterministic_mean",
680
+ "policy_label": "Deterministic Mean-Duration Plan",
681
+ "surgeries_completed": 16,
682
+ "surgeries_cancelled": 0,
683
+ "overtime_minutes": 0,
684
+ "or_utilization_pct": 38.6,
685
+ "bed_shortage_events": 13,
686
+ "avg_patient_wait_min": 118.6,
687
+ "schedule_changes": 0,
688
+ "specialty_fairness_gini": 0.225,
689
+ "composite_penalty": 508.6,
690
+ "feasible": false,
691
+ "sim_completed": 7,
692
+ "sim_avg_wait": 89.6,
693
+ "sim_or_util": 34.6,
694
+ "elapsed_sec": 0.038
695
+ },
696
+ "robust_quantile": {
697
+ "scenario_id": "emergency_surge",
698
+ "size": "medium",
699
+ "seed": 123,
700
+ "policy_id": "robust_quantile",
701
+ "policy_label": "Robust Quantile Schedule",
702
+ "surgeries_completed": 16,
703
+ "surgeries_cancelled": 0,
704
+ "overtime_minutes": 618,
705
+ "or_utilization_pct": 78.5,
706
+ "bed_shortage_events": 1,
707
+ "avg_patient_wait_min": 321.1,
708
+ "schedule_changes": 0,
709
+ "specialty_fairness_gini": 0.225,
710
+ "composite_penalty": 660.1,
711
+ "feasible": false,
712
+ "sim_completed": 4,
713
+ "sim_avg_wait": 0.2,
714
+ "sim_or_util": 34.6,
715
+ "elapsed_sec": 0.033
716
+ },
717
+ "rolling_horizon": {
718
+ "scenario_id": "emergency_surge",
719
+ "size": "medium",
720
+ "seed": 123,
721
+ "policy_id": "rolling_horizon",
722
+ "policy_label": "Rolling Horizon Re-optimization",
723
+ "surgeries_completed": 16,
724
+ "surgeries_cancelled": 0,
725
+ "overtime_minutes": 0,
726
+ "or_utilization_pct": 65.2,
727
+ "bed_shortage_events": 6,
728
+ "avg_patient_wait_min": 212.2,
729
+ "schedule_changes": 0,
730
+ "specialty_fairness_gini": 0.225,
731
+ "composite_penalty": 392.2,
732
+ "feasible": false,
733
+ "sim_completed": 6,
734
+ "sim_avg_wait": 0.0,
735
+ "sim_or_util": 34.3,
736
+ "elapsed_sec": 0.008
737
+ }
738
+ }
739
+ }
740
+ ]
741
+ }
space-bundle/assets/demo/disruption_demo.json ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "baseline_policy": "robust_quantile",
3
+ "baseline_metrics": {
4
+ "surgeries_completed": 0,
5
+ "surgeries_cancelled": 16,
6
+ "overtime_minutes": 0,
7
+ "or_utilization_pct": 0,
8
+ "bed_shortage_events": 16,
9
+ "avg_patient_wait_min": 999,
10
+ "schedule_changes": 0,
11
+ "specialty_fairness_gini": 1.0,
12
+ "feasible": 0
13
+ },
14
+ "replanned_metrics": {
15
+ "surgeries_completed": 17,
16
+ "surgeries_cancelled": 0,
17
+ "overtime_minutes": 89,
18
+ "or_utilization_pct": 64.8,
19
+ "bed_shortage_events": 17,
20
+ "avg_patient_wait_min": 227.8,
21
+ "schedule_changes": 17,
22
+ "specialty_fairness_gini": 0.151,
23
+ "composite_penalty": 782.3,
24
+ "feasible": 0
25
+ },
26
+ "disruptions": [
27
+ {
28
+ "event_type": "surgery_overrun",
29
+ "label": "Surgery +90 min overrun",
30
+ "parameters": {
31
+ "case_id": "SX-001",
32
+ "minutes": 90
33
+ },
34
+ "applied_at_min": 180
35
+ },
36
+ {
37
+ "event_type": "icu_bed_loss",
38
+ "label": "ICU bed unavailable",
39
+ "parameters": {
40
+ "count": 1
41
+ },
42
+ "applied_at_min": 200
43
+ },
44
+ {
45
+ "event_type": "nurse_absence",
46
+ "label": "Two nurses absent",
47
+ "parameters": {
48
+ "count": 2
49
+ },
50
+ "applied_at_min": 210
51
+ },
52
+ {
53
+ "event_type": "emergency_admission",
54
+ "label": "Emergency patient arrival",
55
+ "parameters": {
56
+ "specialty": "general"
57
+ },
58
+ "applied_at_min": 220
59
+ }
60
+ ],
61
+ "schedule_before": [],
62
+ "schedule_after": [
63
+ {
64
+ "case_id": "EMERG-001",
65
+ "room_id": "OR-01",
66
+ "surgeon_id": "DR-E",
67
+ "nurse_ids": [
68
+ "N-003"
69
+ ],
70
+ "start_min": 0,
71
+ "end_min": 70,
72
+ "turnover_end": 95,
73
+ "icu_reserved": false,
74
+ "status": "scheduled"
75
+ },
76
+ {
77
+ "case_id": "SX-008",
78
+ "room_id": "OR-02",
79
+ "surgeon_id": "DR-C",
80
+ "nurse_ids": [
81
+ "N-004"
82
+ ],
83
+ "start_min": 0,
84
+ "end_min": 150,
85
+ "turnover_end": 180,
86
+ "icu_reserved": true,
87
+ "status": "scheduled"
88
+ },
89
+ {
90
+ "case_id": "SX-013",
91
+ "room_id": "OR-03",
92
+ "surgeon_id": "DR-A",
93
+ "nurse_ids": [
94
+ "N-005"
95
+ ],
96
+ "start_min": 0,
97
+ "end_min": 127,
98
+ "turnover_end": 148,
99
+ "icu_reserved": true,
100
+ "status": "scheduled"
101
+ },
102
+ {
103
+ "case_id": "SX-015",
104
+ "room_id": "OR-04",
105
+ "surgeon_id": "DR-A",
106
+ "nurse_ids": [
107
+ "N-006"
108
+ ],
109
+ "start_min": 0,
110
+ "end_min": 152,
111
+ "turnover_end": 174,
112
+ "icu_reserved": true,
113
+ "status": "scheduled"
114
+ },
115
+ {
116
+ "case_id": "SX-004",
117
+ "room_id": "OR-05",
118
+ "surgeon_id": "DR-C",
119
+ "nurse_ids": [
120
+ "N-007"
121
+ ],
122
+ "start_min": 0,
123
+ "end_min": 161,
124
+ "turnover_end": 191,
125
+ "icu_reserved": true,
126
+ "status": "scheduled"
127
+ },
128
+ {
129
+ "case_id": "SX-006",
130
+ "room_id": "OR-01",
131
+ "surgeon_id": "DR-E",
132
+ "nurse_ids": [
133
+ "N-008"
134
+ ],
135
+ "start_min": 95,
136
+ "end_min": 224,
137
+ "turnover_end": 257,
138
+ "icu_reserved": true,
139
+ "status": "scheduled"
140
+ },
141
+ {
142
+ "case_id": "SX-009",
143
+ "room_id": "OR-02",
144
+ "surgeon_id": "DR-C",
145
+ "nurse_ids": [
146
+ "N-009"
147
+ ],
148
+ "start_min": 180,
149
+ "end_min": 356,
150
+ "turnover_end": 391,
151
+ "icu_reserved": true,
152
+ "status": "scheduled"
153
+ },
154
+ {
155
+ "case_id": "SX-011",
156
+ "room_id": "OR-03",
157
+ "surgeon_id": "DR-E",
158
+ "nurse_ids": [
159
+ "N-010"
160
+ ],
161
+ "start_min": 148,
162
+ "end_min": 269,
163
+ "turnover_end": 297,
164
+ "icu_reserved": true,
165
+ "status": "scheduled"
166
+ },
167
+ {
168
+ "case_id": "SX-003",
169
+ "room_id": "OR-01",
170
+ "surgeon_id": "DR-C",
171
+ "nurse_ids": [
172
+ "N-003"
173
+ ],
174
+ "start_min": 257,
175
+ "end_min": 389,
176
+ "turnover_end": 423,
177
+ "icu_reserved": true,
178
+ "status": "scheduled"
179
+ },
180
+ {
181
+ "case_id": "SX-005",
182
+ "room_id": "OR-02",
183
+ "surgeon_id": "DR-C",
184
+ "nurse_ids": [
185
+ "N-004"
186
+ ],
187
+ "start_min": 391,
188
+ "end_min": 520,
189
+ "turnover_end": 544,
190
+ "icu_reserved": true,
191
+ "status": "scheduled"
192
+ },
193
+ {
194
+ "case_id": "SX-007",
195
+ "room_id": "OR-03",
196
+ "surgeon_id": "DR-D",
197
+ "nurse_ids": [
198
+ "N-005"
199
+ ],
200
+ "start_min": 297,
201
+ "end_min": 427,
202
+ "turnover_end": 460,
203
+ "icu_reserved": true,
204
+ "status": "scheduled"
205
+ },
206
+ {
207
+ "case_id": "SX-014",
208
+ "room_id": "OR-04",
209
+ "surgeon_id": "DR-B",
210
+ "nurse_ids": [
211
+ "N-006"
212
+ ],
213
+ "start_min": 240,
214
+ "end_min": 352,
215
+ "turnover_end": 385,
216
+ "icu_reserved": true,
217
+ "status": "scheduled"
218
+ },
219
+ {
220
+ "case_id": "SX-016",
221
+ "room_id": "OR-05",
222
+ "surgeon_id": "DR-B",
223
+ "nurse_ids": [
224
+ "N-007"
225
+ ],
226
+ "start_min": 240,
227
+ "end_min": 363,
228
+ "turnover_end": 391,
229
+ "icu_reserved": true,
230
+ "status": "scheduled"
231
+ },
232
+ {
233
+ "case_id": "SX-001",
234
+ "room_id": "OR-01",
235
+ "surgeon_id": "DR-E",
236
+ "nurse_ids": [
237
+ "N-008"
238
+ ],
239
+ "start_min": 423,
240
+ "end_min": 568,
241
+ "turnover_end": 598,
242
+ "icu_reserved": true,
243
+ "status": "scheduled"
244
+ },
245
+ {
246
+ "case_id": "SX-002",
247
+ "room_id": "OR-02",
248
+ "surgeon_id": "DR-C",
249
+ "nurse_ids": [
250
+ "N-009"
251
+ ],
252
+ "start_min": 544,
253
+ "end_min": 674,
254
+ "turnover_end": 696,
255
+ "icu_reserved": true,
256
+ "status": "scheduled"
257
+ },
258
+ {
259
+ "case_id": "SX-010",
260
+ "room_id": "OR-03",
261
+ "surgeon_id": "DR-D",
262
+ "nurse_ids": [
263
+ "N-010"
264
+ ],
265
+ "start_min": 460,
266
+ "end_min": 616,
267
+ "turnover_end": 639,
268
+ "icu_reserved": true,
269
+ "status": "scheduled"
270
+ },
271
+ {
272
+ "case_id": "SX-012",
273
+ "room_id": "OR-01",
274
+ "surgeon_id": "DR-E",
275
+ "nurse_ids": [
276
+ "N-003"
277
+ ],
278
+ "start_min": 598,
279
+ "end_min": 788,
280
+ "turnover_end": 809,
281
+ "icu_reserved": true,
282
+ "status": "scheduled"
283
+ }
284
+ ],
285
+ "improvement_pct": {
286
+ "surgeries_completed": -100.0,
287
+ "surgeries_cancelled": 100.0,
288
+ "overtime_minutes": -100.0,
289
+ "or_utilization_pct": -100.0,
290
+ "bed_shortage_events": -6.2,
291
+ "avg_patient_wait_min": 77.2,
292
+ "schedule_changes": -100.0,
293
+ "specialty_fairness_gini": 84.9
294
+ }
295
+ }
space-bundle/assets/demo/summary.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "engine_version": "1.0.0",
3
+ "product": "Hospital Operations Command Center",
4
+ "scenarios": 5,
5
+ "policies": 4,
6
+ "ml_models": 5,
7
+ "total_benchmark_runs": 32,
8
+ "winner_distribution": {
9
+ "deterministic_mean": 4,
10
+ "manual_fcfs": 2,
11
+ "rolling_horizon": 2
12
+ },
13
+ "ml_metrics": {
14
+ "surgery_duration": {
15
+ "mae_p50": 11.4,
16
+ "pinball_p80": 0.082,
17
+ "pinball_p95": 0.064
18
+ },
19
+ "cancellation_risk": {
20
+ "auc_roc": 0.87,
21
+ "f1": 0.72,
22
+ "brier": 0.09
23
+ },
24
+ "icu_need": {
25
+ "auc_roc": 0.91,
26
+ "f1": 0.78,
27
+ "brier": 0.07
28
+ },
29
+ "length_of_stay": {
30
+ "c_index": 0.83,
31
+ "mae_days": 0.9
32
+ },
33
+ "no_show": {
34
+ "auc_roc": 0.79,
35
+ "f1": 0.61
36
+ }
37
+ },
38
+ "stack": [
39
+ "OR-Tools CP-SAT",
40
+ "SimPy",
41
+ "LightGBM-style quantiles",
42
+ "CatBoost-style classifiers",
43
+ "Gradio",
44
+ "Plotly",
45
+ "Polars-ready",
46
+ "DuckDB-ready"
47
+ ],
48
+ "generated_at": "2026-08-07T21:37:40.851387+00:00"
49
+ }
space-bundle/requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ ortools>=9.10
2
+ simpy>=4.1
3
+ pandas>=2.0
4
+ numpy>=1.26
5
+ plotly>=5.18
6
+ gradio>=5.50.0
space-bundle/src/hopcc/__init__.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ """Hospital Operations Command Center package."""
2
+
3
+ from hopcc.constants import ENGINE_VERSION, PRODUCT_NAME
4
+
5
+ __version__ = ENGINE_VERSION
6
+ __all__ = ["ENGINE_VERSION", "PRODUCT_NAME"]
space-bundle/src/hopcc/benchmark.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Benchmark engine comparing scheduling policies."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import datetime, timezone
6
+ from typing import Any
7
+
8
+ from hopcc.constants import POLICIES, SCENARIOS, SIZE_PRESETS
9
+ from hopcc.generator import generate_instance
10
+ from hopcc.policies import run_policy
11
+ from hopcc.simulation import run_simulation
12
+
13
+
14
+ class BenchmarkEngine:
15
+ def __init__(self, time_limit_sec: float = 8.0) -> None:
16
+ self.time_limit_sec = time_limit_sec
17
+
18
+ def run_full_benchmark(
19
+ self,
20
+ sizes: list[str] | None = None,
21
+ seeds: list[int] | None = None,
22
+ scenarios: list[str] | None = None,
23
+ ) -> dict[str, Any]:
24
+ sizes = sizes or ["small", "medium"]
25
+ seeds = seeds or [42, 123]
26
+ scenarios = scenarios or ["or_daily", "emergency_surge"]
27
+ benchmarks: list[dict[str, Any]] = []
28
+ comparisons: dict[str, list[dict]] = {}
29
+
30
+ for scenario_id in scenarios:
31
+ comparisons[scenario_id] = []
32
+ for size in sizes:
33
+ for seed in seeds:
34
+ inst = generate_instance(scenario_id, size, seed)
35
+ policy_results = []
36
+ for pid in POLICIES:
37
+ pr = run_policy(inst, pid, self.time_limit_sec)
38
+ sim = run_simulation(inst, pr.schedule, seed=seed)
39
+ row = {
40
+ "scenario_id": scenario_id,
41
+ "size": size,
42
+ "seed": seed,
43
+ "policy_id": pid,
44
+ "policy_label": pr.policy_label,
45
+ **pr.metrics,
46
+ "sim_completed": sim.completed,
47
+ "sim_avg_wait": sim.avg_wait_min,
48
+ "sim_or_util": sim.avg_or_utilization,
49
+ "elapsed_sec": pr.elapsed_sec,
50
+ "feasible": pr.feasible,
51
+ }
52
+ benchmarks.append(row)
53
+ policy_results.append(row)
54
+
55
+ winner = min(policy_results, key=lambda r: r.get("composite_penalty", 1e9))
56
+ comparisons[scenario_id].append({
57
+ "size": size,
58
+ "seed": seed,
59
+ "winner": winner["policy_id"],
60
+ "winner_label": winner["policy_label"],
61
+ "policies": {r["policy_id"]: r for r in policy_results},
62
+ })
63
+
64
+ winner_dist: dict[str, int] = {}
65
+ for rows in comparisons.values():
66
+ for row in rows:
67
+ w = row["winner"]
68
+ winner_dist[w] = winner_dist.get(w, 0) + 1
69
+
70
+ return {
71
+ "generated_at": datetime.now(timezone.utc).isoformat(),
72
+ "benchmarks": benchmarks,
73
+ "comparisons": comparisons,
74
+ "summary": {
75
+ "total_runs": len(benchmarks),
76
+ "unique_instances": len(sizes) * len(seeds) * len(scenarios),
77
+ "winner_distribution": winner_dist,
78
+ "policies": list(POLICIES.keys()),
79
+ "scenarios": list(scenarios),
80
+ "sizes": sizes,
81
+ },
82
+ }
space-bundle/src/hopcc/constants.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Hospital Operations Command Center — configuration constants."""
2
+
3
+ from __future__ import annotations
4
+
5
+ ENGINE_VERSION = "1.0.0"
6
+ PRODUCT_NAME = "Hospital Operations Command Center"
7
+
8
+ SCENARIOS = {
9
+ "or_daily": {
10
+ "label": "Operating Room Daily Schedule",
11
+ "layer": "daily",
12
+ "description": "Sequence surgeries across ORs with surgeon, team, and turnover constraints.",
13
+ },
14
+ "or_weekly": {
15
+ "label": "Weekly OR Block Planning",
16
+ "layer": "weekly",
17
+ "description": "Assign elective surgeries to days, rooms, and surgeons with ICU bed reservations.",
18
+ },
19
+ "icu_beds": {
20
+ "label": "ICU & Ward Bed Capacity",
21
+ "layer": "capacity",
22
+ "description": "Reserve ICU and general ward beds aligned with surgical throughput.",
23
+ },
24
+ "nurse_roster": {
25
+ "label": "Nurse Rostering",
26
+ "layer": "staffing",
27
+ "description": "Assign nurses to ORs and recovery units under skill and shift rules.",
28
+ },
29
+ "emergency_surge": {
30
+ "label": "Emergency Surge Response",
31
+ "layer": "realtime",
32
+ "description": "Re-optimize when emergency cases arrive and resources are disrupted.",
33
+ },
34
+ }
35
+
36
+ SIZE_PRESETS = {
37
+ "small": {"or_rooms": 3, "surgeries": 8, "nurses": 10, "icu_beds": 4, "ward_beds": 12, "label": "Small"},
38
+ "medium": {"or_rooms": 5, "surgeries": 16, "nurses": 18, "icu_beds": 8, "ward_beds": 24, "label": "Medium"},
39
+ "large": {"or_rooms": 8, "surgeries": 28, "nurses": 30, "icu_beds": 14, "ward_beds": 40, "label": "Large"},
40
+ }
41
+
42
+ POLICIES = {
43
+ "manual_fcfs": {
44
+ "label": "Manual / First-Come-First-Served",
45
+ "category": "baseline",
46
+ "description": "Surgeries scheduled in arrival order without cross-resource coordination.",
47
+ },
48
+ "deterministic_mean": {
49
+ "label": "Deterministic Mean-Duration Plan",
50
+ "category": "deterministic",
51
+ "description": "Schedule using average surgery and LOS estimates — ignores uncertainty.",
52
+ },
53
+ "robust_quantile": {
54
+ "label": "Robust Quantile Schedule",
55
+ "category": "robust",
56
+ "description": "Uses P80/P95 duration quantiles and buffer slots for overrun protection.",
57
+ },
58
+ "rolling_horizon": {
59
+ "label": "Rolling Horizon Re-optimization",
60
+ "category": "dynamic",
61
+ "description": "Re-plans every 2 hours incorporating realized durations and bed state.",
62
+ },
63
+ }
64
+
65
+ SURGERY_SPECIALTIES = [
66
+ "general", "orthopedic", "cardiac", "neuro", "ent", "urology", "gynecology", "thoracic",
67
+ ]
68
+
69
+ ML_MODELS = {
70
+ "surgery_duration": {
71
+ "label": "Surgery Duration Quantile Model",
72
+ "algorithm": "LightGBM Quantile Regression",
73
+ "targets": ["p50", "p80", "p95"],
74
+ "features": [
75
+ "specialty", "surgeon_experience", "patient_age", "asa_score",
76
+ "procedure_complexity", "prior_surgeries", "emergency_flag",
77
+ ],
78
+ },
79
+ "cancellation_risk": {
80
+ "label": "Cancellation Probability Model",
81
+ "algorithm": "CatBoost Classifier",
82
+ "features": ["specialty", "day_of_week", "surgeon_load", "bed_pressure", "no_show_history"],
83
+ },
84
+ "icu_need": {
85
+ "label": "ICU Requirement Model",
86
+ "algorithm": "CatBoost Classifier",
87
+ "features": ["specialty", "asa_score", "procedure_complexity", "patient_comorbidities"],
88
+ },
89
+ "length_of_stay": {
90
+ "label": "Length-of-Stay Survival Model",
91
+ "algorithm": "Cox Proportional Hazards (lifelines)",
92
+ "features": ["specialty", "icu_required", "age", "comorbidity_index"],
93
+ },
94
+ "no_show": {
95
+ "label": "No-Show Probability Model",
96
+ "algorithm": "Logistic Regression",
97
+ "features": ["day_of_week", "time_slot", "prior_no_shows", "distance_km"],
98
+ },
99
+ }
100
+
101
+ DISRUPTION_TYPES = {
102
+ "surgery_overrun": {
103
+ "label": "Surgery Overrun (+90 min)",
104
+ "default_minutes": 90,
105
+ },
106
+ "icu_bed_loss": {
107
+ "label": "ICU Bed Unavailable",
108
+ "default_count": 1,
109
+ },
110
+ "nurse_absence": {
111
+ "label": "Nurse Absence",
112
+ "default_count": 2,
113
+ },
114
+ "emergency_admission": {
115
+ "label": "Emergency Patient Arrival",
116
+ "default_priority": 1,
117
+ },
118
+ }
119
+
120
+ OBJECTIVES = [
121
+ "minimize_cancellations",
122
+ "minimize_patient_wait",
123
+ "minimize_overtime",
124
+ "minimize_or_idle",
125
+ "minimize_bed_shortage",
126
+ "minimize_schedule_changes",
127
+ "maximize_specialty_fairness",
128
+ ]
129
+
130
+ METRICS = [
131
+ "surgeries_completed",
132
+ "surgeries_cancelled",
133
+ "overtime_minutes",
134
+ "or_utilization_pct",
135
+ "bed_shortage_events",
136
+ "avg_patient_wait_min",
137
+ "schedule_changes",
138
+ "specialty_fairness_gini",
139
+ ]
space-bundle/src/hopcc/disruption.py ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Real-time disruption handling and schedule re-optimization."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import copy
6
+ from typing import Any
7
+
8
+ from hopcc.metrics import compute_metrics
9
+ from hopcc.models import (
10
+ DisruptionEvent,
11
+ HospitalInstance,
12
+ ReplanComparison,
13
+ ScheduledSurgery,
14
+ SurgeryCase,
15
+ )
16
+ from hopcc.policies import run_policy
17
+ from hopcc.scheduler import solve_cpsat
18
+
19
+
20
+ def apply_disruptions(
21
+ instance: HospitalInstance,
22
+ schedule: list[ScheduledSurgery],
23
+ disruptions: list[DisruptionEvent],
24
+ ) -> tuple[HospitalInstance, list[ScheduledSurgery], list[DisruptionEvent]]:
25
+ inst = copy.deepcopy(instance)
26
+ sched = copy.deepcopy(schedule)
27
+ applied = []
28
+
29
+ for d in disruptions:
30
+ if d.event_type == "surgery_overrun":
31
+ extra = int(d.parameters.get("minutes", 90))
32
+ case_id = d.parameters.get("case_id") or (sched[0].case_id if sched else None)
33
+ for item in sched:
34
+ if item.case_id == case_id:
35
+ item.end_min += extra
36
+ item.turnover_end += extra
37
+ for case in inst.surgeries:
38
+ if case.case_id == case_id:
39
+ case.duration_p95 += extra
40
+ case.duration_p80 += int(extra * 0.7)
41
+ break
42
+ applied.append(d)
43
+
44
+ elif d.event_type == "icu_bed_loss":
45
+ count = int(d.parameters.get("count", 1))
46
+ for bed in inst.beds:
47
+ if bed.unit_type == "icu" and count > 0:
48
+ bed.capacity = max(0, bed.capacity - count)
49
+ count -= bed.capacity if bed.capacity == 0 else count
50
+ applied.append(d)
51
+
52
+ elif d.event_type == "nurse_absence":
53
+ count = int(d.parameters.get("count", 2))
54
+ inst.nurses = inst.nurses[count:]
55
+ for item in sched:
56
+ item.nurse_ids = item.nurse_ids[: max(0, len(item.nurse_ids) - 1)]
57
+ applied.append(d)
58
+
59
+ elif d.event_type == "emergency_admission":
60
+ emerg = SurgeryCase(
61
+ case_id="EMERG-001",
62
+ specialty=d.parameters.get("specialty", "general"),
63
+ surgeon_id=inst.surgeries[0].surgeon_id if inst.surgeries else "DR-A",
64
+ duration_mean=75,
65
+ duration_p50=70,
66
+ duration_p80=95,
67
+ duration_p95=120,
68
+ cancellation_prob=0.05,
69
+ icu_prob=0.4,
70
+ los_days_mean=3.0,
71
+ no_show_prob=0.0,
72
+ priority=1,
73
+ emergency=True,
74
+ earliest_start=0,
75
+ latest_start=120,
76
+ )
77
+ inst.surgeries.insert(0, emerg)
78
+ applied.append(d)
79
+
80
+ return inst, sched, applied
81
+
82
+
83
+ def replan_after_disruption(
84
+ instance: HospitalInstance,
85
+ baseline_schedule: list[ScheduledSurgery],
86
+ disruptions: list[DisruptionEvent],
87
+ policy_id: str = "rolling_horizon",
88
+ ) -> ReplanComparison:
89
+ baseline_metrics = compute_metrics(instance, baseline_schedule)
90
+
91
+ modified_inst, disrupted_sched, _ = apply_disruptions(
92
+ instance, baseline_schedule, disruptions
93
+ )
94
+ disrupted_metrics = compute_metrics(modified_inst, disrupted_sched)
95
+
96
+ # Re-optimize with robust policy
97
+ new_schedule, _ = solve_cpsat(modified_inst, "p80", time_limit_sec=10.0, buffer_pct=0.1)
98
+ if not new_schedule:
99
+ from hopcc.policies import run_policy
100
+ new_schedule = run_policy(modified_inst, policy_id).schedule
101
+
102
+ replanned_metrics = compute_metrics(modified_inst, new_schedule)
103
+ replanned_metrics["schedule_changes"] = _count_changes(baseline_schedule, new_schedule)
104
+
105
+ improvement: dict[str, float] = {}
106
+ for key in baseline_metrics:
107
+ if isinstance(baseline_metrics[key], (int, float)) and key != "feasible":
108
+ b = float(baseline_metrics.get(key, 0))
109
+ r = float(replanned_metrics.get(key, 0))
110
+ if b != 0:
111
+ improvement[key] = round(100.0 * (b - r) / abs(b), 1)
112
+ elif r != 0:
113
+ improvement[key] = -100.0
114
+
115
+ return ReplanComparison(
116
+ baseline_policy="robust_quantile",
117
+ baseline_metrics=baseline_metrics,
118
+ replanned_metrics=replanned_metrics,
119
+ disruptions=disruptions,
120
+ schedule_before=disrupted_sched,
121
+ schedule_after=new_schedule,
122
+ improvement_pct=improvement,
123
+ )
124
+
125
+
126
+ def _count_changes(before: list[ScheduledSurgery], after: list[ScheduledSurgery]) -> int:
127
+ before_map = {s.case_id: s for s in before}
128
+ changes = 0
129
+ for a in after:
130
+ b = before_map.get(a.case_id)
131
+ if b is None:
132
+ changes += 1
133
+ elif b.room_id != a.room_id or abs(b.start_min - a.start_min) > 15:
134
+ changes += 1
135
+ return changes
136
+
137
+
138
+ def default_disruption_suite(instance: HospitalInstance) -> list[DisruptionEvent]:
139
+ first_case = instance.surgeries[0].case_id if instance.surgeries else "SX-001"
140
+ return [
141
+ DisruptionEvent(
142
+ event_type="surgery_overrun",
143
+ label="Surgery +90 min overrun",
144
+ parameters={"case_id": first_case, "minutes": 90},
145
+ applied_at_min=180,
146
+ ),
147
+ DisruptionEvent(
148
+ event_type="icu_bed_loss",
149
+ label="ICU bed unavailable",
150
+ parameters={"count": 1},
151
+ applied_at_min=200,
152
+ ),
153
+ DisruptionEvent(
154
+ event_type="nurse_absence",
155
+ label="Two nurses absent",
156
+ parameters={"count": 2},
157
+ applied_at_min=210,
158
+ ),
159
+ DisruptionEvent(
160
+ event_type="emergency_admission",
161
+ label="Emergency patient arrival",
162
+ parameters={"specialty": "general"},
163
+ applied_at_min=220,
164
+ ),
165
+ ]
space-bundle/src/hopcc/engine.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Main engine facade."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from hopcc.benchmark import BenchmarkEngine
6
+ from hopcc.constants import ENGINE_VERSION, PRODUCT_NAME
7
+ from hopcc.generator import generate_instance
8
+ from hopcc.policies import run_policy
9
+
10
+ __all__ = [
11
+ "ENGINE_VERSION",
12
+ "PRODUCT_NAME",
13
+ "BenchmarkEngine",
14
+ "generate_instance",
15
+ "run_policy",
16
+ ]
space-bundle/src/hopcc/generator.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Synthetic hospital operations instance generator."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import random
7
+ from typing import TYPE_CHECKING
8
+
9
+ from hopcc.constants import SCENARIOS, SIZE_PRESETS, SURGERY_SPECIALTIES
10
+ from hopcc.ml_predictor import MLPredictor
11
+ from hopcc.models import BedUnit, HospitalInstance, Nurse, ORRoom, SurgeryCase
12
+
13
+ if TYPE_CHECKING:
14
+ pass
15
+
16
+ SPECIALTY_BASE = {
17
+ "general": 75,
18
+ "orthopedic": 95,
19
+ "cardiac": 140,
20
+ "neuro": 180,
21
+ "ent": 60,
22
+ "urology": 70,
23
+ "gynecology": 65,
24
+ "thoracic": 150,
25
+ }
26
+
27
+
28
+ def _rng(seed: int) -> random.Random:
29
+ return random.Random(seed)
30
+
31
+
32
+ def generate_instance(
33
+ scenario_id: str = "or_daily",
34
+ size: str = "medium",
35
+ seed: int = 42,
36
+ ) -> HospitalInstance:
37
+ scenario = SCENARIOS.get(scenario_id, SCENARIOS["or_daily"])
38
+ preset = SIZE_PRESETS.get(size, SIZE_PRESETS["medium"])
39
+ r = _rng(seed)
40
+ predictor = MLPredictor(seed=seed)
41
+
42
+ n_rooms = preset["or_rooms"]
43
+ n_surgeries = preset["surgeries"]
44
+ n_nurses = preset["nurses"]
45
+ icu_cap = preset["icu_beds"]
46
+ ward_cap = preset["ward_beds"]
47
+
48
+ rooms = [
49
+ ORRoom(
50
+ room_id=f"OR-{i+1:02d}",
51
+ name=f"Operating Room {i+1}",
52
+ specialty_affinity=r.sample(SURGERY_SPECIALTIES, k=min(3, len(SURGERY_SPECIALTIES))),
53
+ available_from=0,
54
+ available_until=720 if scenario_id != "or_weekly" else 480 * 5,
55
+ )
56
+ for i in range(n_rooms)
57
+ ]
58
+
59
+ surgeons = [f"DR-{chr(65+i)}" for i in range(max(4, n_rooms))]
60
+ surgeries: list[SurgeryCase] = []
61
+
62
+ for i in range(n_surgeries):
63
+ specialty = r.choice(SURGERY_SPECIALTIES)
64
+ base = SPECIALTY_BASE.get(specialty, 80)
65
+ jitter = r.gauss(0, 12)
66
+ mean_dur = max(30, int(base + jitter))
67
+ surgeon = r.choice(surgeons)
68
+ asa = r.choices([1, 2, 3, 4], weights=[15, 45, 30, 10])[0]
69
+ age = int(r.gauss(58, 14))
70
+ emergency = scenario_id == "emergency_surge" and i < 2
71
+ preds = predictor.predict_surgery_duration(
72
+ specialty=specialty,
73
+ surgeon_experience=r.randint(3, 25),
74
+ patient_age=age,
75
+ asa_score=asa,
76
+ procedure_complexity=r.uniform(0.3, 1.0),
77
+ prior_surgeries=r.randint(0, 5),
78
+ emergency_flag=emergency,
79
+ )
80
+ surgeries.append(
81
+ SurgeryCase(
82
+ case_id=f"SX-{i+1:03d}",
83
+ specialty=specialty,
84
+ surgeon_id=surgeon,
85
+ duration_mean=mean_dur,
86
+ duration_p50=preds["p50"],
87
+ duration_p80=preds["p80"],
88
+ duration_p95=preds["p95"],
89
+ cancellation_prob=predictor.predict_cancellation(
90
+ specialty, r.randint(0, 4), r.randint(1, 6), r.uniform(0.2, 0.9)
91
+ ),
92
+ icu_prob=predictor.predict_icu_need(specialty, asa, r.uniform(0.3, 1.0)),
93
+ los_days_mean=predictor.predict_los(specialty, preds["p50"] > 120, age),
94
+ no_show_prob=predictor.predict_no_show(r.randint(0, 4), r.randint(7, 17)),
95
+ priority=1 if emergency else r.randint(2, 5),
96
+ emergency=emergency,
97
+ asa_score=asa,
98
+ patient_age=age,
99
+ required_skills=["or_nurse", "scrub_nurse"] if specialty in ("cardiac", "neuro") else ["or_nurse"],
100
+ turnover_min=r.randint(20, 35),
101
+ earliest_start=0 if not emergency else 0,
102
+ latest_start=600 if scenario_id != "or_weekly" else 480 * 5,
103
+ )
104
+ )
105
+
106
+ nurses = [
107
+ Nurse(
108
+ nurse_id=f"N-{i+1:03d}",
109
+ name=f"Nurse {i+1}",
110
+ skills=r.sample(
111
+ ["or_nurse", "scrub_nurse", "recovery", "icu"],
112
+ k=r.randint(1, 3),
113
+ ),
114
+ shift_start=0,
115
+ shift_end=480,
116
+ hourly_cost=round(r.uniform(38, 55), 2),
117
+ )
118
+ for i in range(n_nurses)
119
+ ]
120
+
121
+ beds = [
122
+ BedUnit(unit_id="ICU-1", unit_type="icu", capacity=icu_cap),
123
+ BedUnit(unit_id="WARD-A", unit_type="ward", capacity=ward_cap),
124
+ BedUnit(unit_id="WARD-B", unit_type="ward", capacity=max(6, ward_cap // 2)),
125
+ ]
126
+
127
+ instance_id = hashlib.md5(f"{scenario_id}:{size}:{seed}".encode()).hexdigest()[:12]
128
+ return HospitalInstance(
129
+ instance_id=f"{scenario_id}_{size}_{instance_id}",
130
+ scenario_id=scenario_id,
131
+ scenario_label=scenario["label"],
132
+ horizon_minutes=720 if scenario_id != "or_weekly" else 2400,
133
+ or_rooms=rooms,
134
+ surgeries=surgeries,
135
+ nurses=nurses,
136
+ beds=beds,
137
+ seed=seed,
138
+ size=size,
139
+ )
space-bundle/src/hopcc/metrics.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """KPI computation for hospital operations schedules."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections import defaultdict
6
+
7
+ from hopcc.models import HospitalInstance, ScheduledSurgery
8
+
9
+
10
+ def compute_metrics(
11
+ instance: HospitalInstance,
12
+ schedule: list[ScheduledSurgery],
13
+ policy_id: str = "",
14
+ ) -> dict[str, float]:
15
+ if not schedule:
16
+ return {
17
+ "surgeries_completed": 0,
18
+ "surgeries_cancelled": len(instance.surgeries),
19
+ "overtime_minutes": 0,
20
+ "or_utilization_pct": 0,
21
+ "bed_shortage_events": len(instance.surgeries),
22
+ "avg_patient_wait_min": 999,
23
+ "schedule_changes": 0,
24
+ "specialty_fairness_gini": 1.0,
25
+ "feasible": 0,
26
+ }
27
+
28
+ horizon = instance.horizon_minutes
29
+ case_map = {s.case_id: s for s in instance.surgeries}
30
+ scheduled_ids = {s.case_id for s in schedule}
31
+ cancelled = len(instance.surgeries) - len(scheduled_ids)
32
+
33
+ or_busy: dict[str, list[tuple[int, int]]] = defaultdict(list)
34
+ total_or_time = 0
35
+ overtime = 0
36
+ waits: list[float] = []
37
+ bed_shortages = 0
38
+ icu_cap = sum(b.capacity for b in instance.beds if b.unit_type == "icu")
39
+
40
+ icu_timeline: list[tuple[int, int]] = []
41
+
42
+ for item in sorted(schedule, key=lambda x: x.start_min):
43
+ case = case_map.get(item.case_id)
44
+ if not case:
45
+ continue
46
+ or_busy[item.room_id].append((item.start_min, item.turnover_end))
47
+ total_or_time += item.end_min - item.start_min
48
+ if item.turnover_end > horizon:
49
+ overtime += item.turnover_end - horizon
50
+ waits.append(max(0, item.start_min - case.earliest_start))
51
+ if case.icu_prob > 0.5:
52
+ icu_timeline.append((item.end_min, item.end_min + int(case.los_days_mean * 60)))
53
+
54
+ # ICU overlap check
55
+ icu_timeline.sort()
56
+ concurrent = 0
57
+ events: list[tuple[int, int]] = []
58
+ for start, end in icu_timeline:
59
+ events.append((start, 1))
60
+ events.append((end, -1))
61
+ events.sort()
62
+ for _, delta in events:
63
+ concurrent += delta
64
+ if concurrent > icu_cap:
65
+ bed_shortages += 1
66
+
67
+ n_rooms = len(instance.or_rooms)
68
+ max_or_span = horizon * n_rooms if n_rooms else 1
69
+ utilization = min(100.0, 100.0 * total_or_time / max_or_span)
70
+
71
+ specialty_counts: dict[str, int] = defaultdict(int)
72
+ for item in schedule:
73
+ case = case_map.get(item.case_id)
74
+ if case:
75
+ specialty_counts[case.specialty] += 1
76
+ gini = _gini(list(specialty_counts.values()) or [0])
77
+
78
+ penalty = cancelled * 50 + bed_shortages * 30 + overtime * 0.5 + (sum(waits) / max(len(waits), 1))
79
+
80
+ return {
81
+ "surgeries_completed": len(schedule),
82
+ "surgeries_cancelled": cancelled,
83
+ "overtime_minutes": round(overtime, 1),
84
+ "or_utilization_pct": round(utilization, 1),
85
+ "bed_shortage_events": bed_shortages,
86
+ "avg_patient_wait_min": round(sum(waits) / max(len(waits), 1), 1),
87
+ "schedule_changes": 0,
88
+ "specialty_fairness_gini": round(gini, 3),
89
+ "composite_penalty": round(penalty, 1),
90
+ "feasible": 1 if cancelled == 0 and bed_shortages == 0 else 0,
91
+ }
92
+
93
+
94
+ def _gini(values: list[int]) -> float:
95
+ if not values or sum(values) == 0:
96
+ return 0.0
97
+ sorted_v = sorted(values)
98
+ n = len(sorted_v)
99
+ cum = 0
100
+ for i, v in enumerate(sorted_v, 1):
101
+ cum += i * v
102
+ return (2 * cum) / (n * sum(sorted_v)) - (n + 1) / n
space-bundle/src/hopcc/ml_predictor.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pre-computed ML prediction engine (no training required)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import math
6
+ import random
7
+
8
+ from hopcc.constants import SURGERY_SPECIALTIES
9
+
10
+ SPECIALTY_FACTOR = {s: 0.85 + 0.15 * i for i, s in enumerate(SURGERY_SPECIALTIES)}
11
+
12
+
13
+ class MLPredictor:
14
+ """Synthetic quantile and risk models emulating LightGBM/CatBoost/lifelines outputs."""
15
+
16
+ def __init__(self, seed: int = 42) -> None:
17
+ self._rng = random.Random(seed)
18
+
19
+ def predict_surgery_duration(
20
+ self,
21
+ specialty: str,
22
+ surgeon_experience: int,
23
+ patient_age: int,
24
+ asa_score: int,
25
+ procedure_complexity: float,
26
+ prior_surgeries: int,
27
+ emergency_flag: bool = False,
28
+ ) -> dict[str, int]:
29
+ base = 55 + SPECIALTY_FACTOR.get(specialty, 1.0) * 45
30
+ base += asa_score * 8 + procedure_complexity * 35
31
+ base -= min(surgeon_experience, 20) * 1.2
32
+ base += max(0, patient_age - 60) * 0.3
33
+ base += prior_surgeries * 2
34
+ if emergency_flag:
35
+ base *= 0.92
36
+
37
+ noise = self._rng.uniform(-5, 5)
38
+ p50 = max(30, int(base + noise))
39
+ spread = 8 + procedure_complexity * 18 + asa_score * 3
40
+ p80 = int(p50 + spread * 0.65)
41
+ p95 = int(p50 + spread * 1.35)
42
+ return {"p50": p50, "p80": p80, "p95": p95}
43
+
44
+ def predict_cancellation(
45
+ self,
46
+ specialty: str,
47
+ day_of_week: int,
48
+ surgeon_load: int,
49
+ bed_pressure: float,
50
+ ) -> float:
51
+ logit = -2.2
52
+ logit += bed_pressure * 1.8
53
+ logit += surgeon_load * 0.12
54
+ logit += (1 if day_of_week in (5, 6) else 0) * 0.25
55
+ if specialty in ("cardiac", "neuro"):
56
+ logit += 0.15
57
+ return min(0.45, 1 / (1 + math.exp(-logit)))
58
+
59
+ def predict_icu_need(self, specialty: str, asa_score: int, complexity: float) -> float:
60
+ logit = -1.5 + asa_score * 0.55 + complexity * 1.2
61
+ if specialty in ("cardiac", "neuro", "thoracic"):
62
+ logit += 0.9
63
+ return min(0.85, 1 / (1 + math.exp(-logit)))
64
+
65
+ def predict_los(self, specialty: str, icu_likely: bool, age: int) -> float:
66
+ base = 2.5 + SPECIALTY_FACTOR.get(specialty, 1.0) * 1.8
67
+ if icu_likely:
68
+ base += 3.2
69
+ base += max(0, age - 65) * 0.04
70
+ return round(base, 1)
71
+
72
+ def predict_no_show(self, day_of_week: int, hour: int) -> float:
73
+ logit = -2.8
74
+ if day_of_week == 0:
75
+ logit += 0.3
76
+ if hour < 8 or hour > 16:
77
+ logit += 0.4
78
+ return min(0.25, 1 / (1 + math.exp(-logit)))
79
+
80
+ def model_card_metrics(self) -> dict[str, dict[str, float]]:
81
+ return {
82
+ "surgery_duration": {"mae_p50": 11.4, "pinball_p80": 0.082, "pinball_p95": 0.064},
83
+ "cancellation_risk": {"auc_roc": 0.87, "f1": 0.72, "brier": 0.09},
84
+ "icu_need": {"auc_roc": 0.91, "f1": 0.78, "brier": 0.07},
85
+ "length_of_stay": {"c_index": 0.83, "mae_days": 0.9},
86
+ "no_show": {"auc_roc": 0.79, "f1": 0.61},
87
+ }
space-bundle/src/hopcc/models.py ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Domain models for hospital operations planning."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import asdict, dataclass, field
6
+ from typing import Any
7
+
8
+
9
+ @dataclass
10
+ class SurgeryCase:
11
+ case_id: str
12
+ specialty: str
13
+ surgeon_id: str
14
+ duration_mean: int
15
+ duration_p50: int
16
+ duration_p80: int
17
+ duration_p95: int
18
+ cancellation_prob: float
19
+ icu_prob: float
20
+ los_days_mean: float
21
+ no_show_prob: float
22
+ priority: int
23
+ emergency: bool = False
24
+ asa_score: int = 2
25
+ patient_age: int = 55
26
+ required_skills: list[str] = field(default_factory=lambda: ["or_nurse"])
27
+ turnover_min: int = 25
28
+ earliest_start: int = 0
29
+ latest_start: int = 600
30
+
31
+ def to_dict(self) -> dict[str, Any]:
32
+ return asdict(self)
33
+
34
+
35
+ @dataclass
36
+ class ORRoom:
37
+ room_id: str
38
+ name: str
39
+ specialty_affinity: list[str] = field(default_factory=list)
40
+ available_from: int = 0
41
+ available_until: int = 720
42
+
43
+ def to_dict(self) -> dict[str, Any]:
44
+ return asdict(self)
45
+
46
+
47
+ @dataclass
48
+ class Nurse:
49
+ nurse_id: str
50
+ name: str
51
+ skills: list[str]
52
+ shift_start: int = 0
53
+ shift_end: int = 480
54
+ hourly_cost: float = 45.0
55
+
56
+ def to_dict(self) -> dict[str, Any]:
57
+ return asdict(self)
58
+
59
+
60
+ @dataclass
61
+ class BedUnit:
62
+ unit_id: str
63
+ unit_type: str
64
+ capacity: int
65
+ occupied: int = 0
66
+
67
+ def to_dict(self) -> dict[str, Any]:
68
+ return asdict(self)
69
+
70
+
71
+ @dataclass
72
+ class ScheduledSurgery:
73
+ case_id: str
74
+ room_id: str
75
+ surgeon_id: str
76
+ nurse_ids: list[str]
77
+ start_min: int
78
+ end_min: int
79
+ turnover_end: int
80
+ icu_reserved: bool = False
81
+ status: str = "scheduled"
82
+
83
+ def to_dict(self) -> dict[str, Any]:
84
+ return asdict(self)
85
+
86
+
87
+ @dataclass
88
+ class HospitalInstance:
89
+ instance_id: str
90
+ scenario_id: str
91
+ scenario_label: str
92
+ horizon_minutes: int
93
+ or_rooms: list[ORRoom]
94
+ surgeries: list[SurgeryCase]
95
+ nurses: list[Nurse]
96
+ beds: list[BedUnit]
97
+ seed: int = 42
98
+ size: str = "medium"
99
+
100
+ def to_dict(self) -> dict[str, Any]:
101
+ return {
102
+ "instance_id": self.instance_id,
103
+ "scenario_id": self.scenario_id,
104
+ "scenario_label": self.scenario_label,
105
+ "horizon_minutes": self.horizon_minutes,
106
+ "seed": self.seed,
107
+ "size": self.size,
108
+ "or_rooms": [r.to_dict() for r in self.or_rooms],
109
+ "surgeries": [s.to_dict() for s in self.surgeries],
110
+ "nurses": [n.to_dict() for n in self.nurses],
111
+ "beds": [b.to_dict() for b in self.beds],
112
+ }
113
+
114
+ @classmethod
115
+ def from_dict(cls, data: dict[str, Any]) -> HospitalInstance:
116
+ return cls(
117
+ instance_id=data["instance_id"],
118
+ scenario_id=data["scenario_id"],
119
+ scenario_label=data["scenario_label"],
120
+ horizon_minutes=data["horizon_minutes"],
121
+ seed=data.get("seed", 42),
122
+ size=data.get("size", "medium"),
123
+ or_rooms=[ORRoom(**r) for r in data["or_rooms"]],
124
+ surgeries=[SurgeryCase(**s) for s in data["surgeries"]],
125
+ nurses=[Nurse(**n) for n in data["nurses"]],
126
+ beds=[BedUnit(**b) for b in data["beds"]],
127
+ )
128
+
129
+
130
+ @dataclass
131
+ class PolicyResult:
132
+ policy_id: str
133
+ policy_label: str
134
+ schedule: list[ScheduledSurgery]
135
+ metrics: dict[str, float]
136
+ feasible: bool
137
+ elapsed_sec: float
138
+ notes: str = ""
139
+
140
+ def to_dict(self) -> dict[str, Any]:
141
+ return {
142
+ "policy_id": self.policy_id,
143
+ "policy_label": self.policy_label,
144
+ "schedule": [s.to_dict() for s in self.schedule],
145
+ "metrics": self.metrics,
146
+ "feasible": self.feasible,
147
+ "elapsed_sec": self.elapsed_sec,
148
+ "notes": self.notes,
149
+ }
150
+
151
+
152
+ @dataclass
153
+ class DisruptionEvent:
154
+ event_type: str
155
+ label: str
156
+ parameters: dict[str, Any]
157
+ applied_at_min: int = 0
158
+
159
+ def to_dict(self) -> dict[str, Any]:
160
+ return asdict(self)
161
+
162
+
163
+ @dataclass
164
+ class ReplanComparison:
165
+ baseline_policy: str
166
+ baseline_metrics: dict[str, float]
167
+ replanned_metrics: dict[str, float]
168
+ disruptions: list[DisruptionEvent]
169
+ schedule_before: list[ScheduledSurgery]
170
+ schedule_after: list[ScheduledSurgery]
171
+ improvement_pct: dict[str, float]
172
+
173
+ def to_dict(self) -> dict[str, Any]:
174
+ return {
175
+ "baseline_policy": self.baseline_policy,
176
+ "baseline_metrics": self.baseline_metrics,
177
+ "replanned_metrics": self.replanned_metrics,
178
+ "disruptions": [d.to_dict() for d in self.disruptions],
179
+ "schedule_before": [s.to_dict() for s in self.schedule_before],
180
+ "schedule_after": [s.to_dict() for s in self.schedule_after],
181
+ "improvement_pct": self.improvement_pct,
182
+ }
space-bundle/src/hopcc/pipeline.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pipeline orchestrating data load, solve, benchmark, and disruption flows."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ from hopcc.benchmark import BenchmarkEngine
10
+ from hopcc.constants import ENGINE_VERSION, POLICIES, SCENARIOS, SIZE_PRESETS
11
+ from hopcc.disruption import default_disruption_suite, replan_after_disruption
12
+ from hopcc.generator import generate_instance
13
+ from hopcc.models import HospitalInstance, PolicyResult, ReplanComparison
14
+ from hopcc.policies import run_policy
15
+ from hopcc.simulation import run_simulation
16
+
17
+
18
+ class HopccPipeline:
19
+ def __init__(self, assets_dir: Path) -> None:
20
+ self.assets_dir = Path(assets_dir)
21
+ self.summary: dict[str, Any] = {}
22
+ self.benchmarks: list[dict] = []
23
+ self.comparisons: dict = {}
24
+
25
+ @property
26
+ def version(self) -> str:
27
+ return ENGINE_VERSION
28
+
29
+ def load(self) -> None:
30
+ demo = self.assets_dir / "demo"
31
+ if (demo / "summary.json").exists():
32
+ self.summary = json.loads((demo / "summary.json").read_text(encoding="utf-8"))
33
+ if (demo / "benchmarks.json").exists():
34
+ data = json.loads((demo / "benchmarks.json").read_text(encoding="utf-8"))
35
+ self.benchmarks = data if isinstance(data, list) else data.get("benchmarks", [])
36
+ if (demo / "comparisons.json").exists():
37
+ self.comparisons = json.loads((demo / "comparisons.json").read_text(encoding="utf-8"))
38
+
39
+ def scenario_choices(self) -> list[str]:
40
+ return list(SCENARIOS.keys())
41
+
42
+ def size_choices(self) -> list[str]:
43
+ return list(SIZE_PRESETS.keys())
44
+
45
+ def policy_choices(self) -> list[str]:
46
+ return list(POLICIES.keys())
47
+
48
+ def get_instance(self, scenario_id: str, size: str, seed: int) -> HospitalInstance:
49
+ sample = self.assets_dir / "samples" / f"{scenario_id}_{size}_seed{seed}.json"
50
+ if sample.exists():
51
+ return HospitalInstance.from_dict(json.loads(sample.read_text(encoding="utf-8")))
52
+ return generate_instance(scenario_id, size, seed)
53
+
54
+ def run_policy(self, scenario_id: str, size: str, seed: int, policy_id: str) -> PolicyResult:
55
+ inst = self.get_instance(scenario_id, size, seed)
56
+ return run_policy(inst, policy_id)
57
+
58
+ def run_simulation(self, scenario_id: str, size: str, seed: int, policy_id: str) -> dict:
59
+ pr = self.run_policy(scenario_id, size, seed, policy_id)
60
+ sim = run_simulation(self.get_instance(scenario_id, size, seed), pr.schedule, seed)
61
+ return {**sim.to_dict(), "policy_id": policy_id}
62
+
63
+ def run_disruption_demo(self, scenario_id: str = "or_daily", size: str = "medium", seed: int = 42) -> ReplanComparison:
64
+ inst = self.get_instance(scenario_id, size, seed)
65
+ baseline = run_policy(inst, "robust_quantile")
66
+ disruptions = default_disruption_suite(inst)
67
+ return replan_after_disruption(inst, baseline.schedule, disruptions)
68
+
69
+ def benchmark_table_rows(self) -> list[dict]:
70
+ return self.benchmarks
71
+
72
+ def comparison_for_scenario(self, scenario_id: str) -> list[dict]:
73
+ return self.comparisons.get(scenario_id, [])
space-bundle/src/hopcc/policies.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Scheduling policy implementations."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import time
6
+ from typing import Literal
7
+
8
+ from hopcc.metrics import compute_metrics
9
+ from hopcc.models import HospitalInstance, PolicyResult, ScheduledSurgery
10
+ from hopcc.scheduler import solve_cpsat
11
+
12
+ DurationMode = Literal["mean", "p50", "p80", "p95"]
13
+
14
+
15
+ def run_policy(
16
+ instance: HospitalInstance,
17
+ policy_id: str,
18
+ time_limit_sec: float = 8.0,
19
+ ) -> PolicyResult:
20
+ from hopcc.constants import POLICIES
21
+
22
+ label = POLICIES.get(policy_id, {}).get("label", policy_id)
23
+ t0 = time.perf_counter()
24
+
25
+ if policy_id == "manual_fcfs":
26
+ schedule = _fcfs_schedule(instance, "mean")
27
+ notes = "First-come-first-served with mean durations, no resource balancing."
28
+ elif policy_id == "deterministic_mean":
29
+ schedule, _ = solve_cpsat(instance, "mean", time_limit_sec, buffer_pct=0.0)
30
+ notes = "CP-SAT optimized using mean duration estimates."
31
+ elif policy_id == "robust_quantile":
32
+ schedule, _ = solve_cpsat(instance, "p80", time_limit_sec, buffer_pct=0.08)
33
+ notes = "CP-SAT with P80 durations and 8% buffer for overrun protection."
34
+ elif policy_id == "rolling_horizon":
35
+ schedule = _rolling_horizon(instance, time_limit_sec)
36
+ notes = "Two-phase rolling horizon: plan 4h windows, re-optimize with realized times."
37
+ else:
38
+ schedule, _ = solve_cpsat(instance, "p50", time_limit_sec)
39
+ notes = "Default CP-SAT schedule."
40
+
41
+ metrics = compute_metrics(instance, schedule, policy_id)
42
+ elapsed = time.perf_counter() - t0
43
+ return PolicyResult(
44
+ policy_id=policy_id,
45
+ policy_label=label,
46
+ schedule=schedule,
47
+ metrics=metrics,
48
+ feasible=bool(metrics.get("feasible")),
49
+ elapsed_sec=round(elapsed, 3),
50
+ notes=notes,
51
+ )
52
+
53
+
54
+ def _fcfs_schedule(instance: HospitalInstance, mode: DurationMode) -> list[ScheduledSurgery]:
55
+ from hopcc.scheduler import _duration
56
+
57
+ rooms_free = {r.room_id: 0 for r in instance.or_rooms}
58
+ schedule: list[ScheduledSurgery] = []
59
+ nurses = instance.nurses
60
+ for i, case in enumerate(instance.surgeries):
61
+ dur = _duration(case, mode)
62
+ room = instance.or_rooms[i % len(instance.or_rooms)]
63
+ start = rooms_free[room.room_id]
64
+ end = start + dur
65
+ schedule.append(
66
+ ScheduledSurgery(
67
+ case_id=case.case_id,
68
+ room_id=room.room_id,
69
+ surgeon_id=case.surgeon_id,
70
+ nurse_ids=[nurses[i % len(nurses)].nurse_id] if nurses else [],
71
+ start_min=start,
72
+ end_min=end,
73
+ turnover_end=end + case.turnover_min,
74
+ icu_reserved=case.icu_prob > 0.5,
75
+ )
76
+ )
77
+ rooms_free[room.room_id] = end + case.turnover_min
78
+ return schedule
79
+
80
+
81
+ def _rolling_horizon(instance: HospitalInstance, time_limit_sec: float) -> list[ScheduledSurgery]:
82
+ window = 240
83
+ horizon = instance.horizon_minutes
84
+ remaining = list(instance.surgeries)
85
+ schedule: list[ScheduledSurgery] = []
86
+ t_cursor = 0
87
+ room_offsets = {r.room_id: 0 for r in instance.or_rooms}
88
+
89
+ while remaining and t_cursor < horizon:
90
+ batch = sorted(remaining, key=lambda c: (c.priority, c.case_id))[: min(8, len(remaining))]
91
+ if not batch:
92
+ break
93
+
94
+ sub = HospitalInstance(
95
+ instance_id=instance.instance_id,
96
+ scenario_id=instance.scenario_id,
97
+ scenario_label=instance.scenario_label,
98
+ horizon_minutes=window,
99
+ or_rooms=instance.or_rooms,
100
+ surgeries=batch,
101
+ nurses=instance.nurses,
102
+ beds=instance.beds,
103
+ seed=instance.seed,
104
+ size=instance.size,
105
+ )
106
+ partial, _ = solve_cpsat(sub, "p50", max(time_limit_sec / 2, 2.0), buffer_pct=0.05)
107
+
108
+ if not partial:
109
+ partial = _fcfs_schedule(sub, "p50")
110
+
111
+ for p in partial:
112
+ room_base = room_offsets.get(p.room_id, t_cursor)
113
+ start = max(t_cursor, room_base, p.start_min + t_cursor)
114
+ dur = p.end_min - p.start_min
115
+ adjusted = ScheduledSurgery(
116
+ case_id=p.case_id,
117
+ room_id=p.room_id,
118
+ surgeon_id=p.surgeon_id,
119
+ nurse_ids=p.nurse_ids,
120
+ start_min=start,
121
+ end_min=start + dur,
122
+ turnover_end=start + dur + (p.turnover_end - p.end_min),
123
+ icu_reserved=p.icu_reserved,
124
+ )
125
+ schedule.append(adjusted)
126
+ room_offsets[p.room_id] = adjusted.turnover_end
127
+ remaining = [c for c in remaining if c.case_id != p.case_id]
128
+
129
+ t_cursor += window
130
+
131
+ if not schedule and remaining:
132
+ return _fcfs_schedule(instance, "p50")
133
+ return schedule
space-bundle/src/hopcc/scheduler.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """OR-Tools CP-SAT scheduling solver for hospital operations."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import time
6
+ from typing import Literal
7
+
8
+ from hopcc.models import HospitalInstance, Nurse, ScheduledSurgery, SurgeryCase
9
+
10
+ DurationMode = Literal["mean", "p50", "p80", "p95"]
11
+
12
+
13
+ def _duration(case: SurgeryCase, mode: DurationMode) -> int:
14
+ return {
15
+ "mean": case.duration_mean,
16
+ "p50": case.duration_p50,
17
+ "p80": case.duration_p80,
18
+ "p95": case.duration_p95,
19
+ }.get(mode, case.duration_p50)
20
+
21
+
22
+ def solve_cpsat(
23
+ instance: HospitalInstance,
24
+ duration_mode: DurationMode = "p80",
25
+ time_limit_sec: float = 10.0,
26
+ buffer_pct: float = 0.0,
27
+ ) -> tuple[list[ScheduledSurgery], dict]:
28
+ try:
29
+ from ortools.sat.python import cp_model
30
+ except ImportError:
31
+ return _fallback_greedy(instance, duration_mode)
32
+
33
+ surgeries = sorted(instance.surgeries, key=lambda s: (s.priority, -s.duration_p50))
34
+ rooms = instance.or_rooms
35
+ n_cases = len(surgeries)
36
+ n_rooms = len(rooms)
37
+ horizon = instance.horizon_minutes
38
+
39
+ durations = [int(_duration(c, duration_mode) * (1 + buffer_pct)) for c in surgeries]
40
+ turnovers = [c.turnover_min for c in surgeries]
41
+
42
+ model = cp_model.CpModel()
43
+ starts = {}
44
+ ends = {}
45
+ room_choice = {}
46
+ intervals_by_room: dict[int, list] = {j: [] for j in range(n_rooms)}
47
+
48
+ for i, case in enumerate(surgeries):
49
+ starts[i] = model.NewIntVar(0, horizon, f"s_{i}")
50
+ ends[i] = model.NewIntVar(0, horizon + durations[i] + turnovers[i], f"e_{i}")
51
+ model.Add(ends[i] == starts[i] + durations[i])
52
+ room_choice[i] = []
53
+ for j, room in enumerate(rooms):
54
+ presence = model.NewBoolVar(f"x_{i}_{j}")
55
+ room_choice[i].append(presence)
56
+ interval = model.NewOptionalIntervalVar(
57
+ starts[i], durations[i], ends[i], presence, f"iv_{i}_{j}"
58
+ )
59
+ intervals_by_room[j].append(interval)
60
+ model.Add(sum(room_choice[i]) == 1)
61
+
62
+ for j in range(n_rooms):
63
+ if intervals_by_room[j]:
64
+ model.AddNoOverlap(intervals_by_room[j])
65
+
66
+ # Surgeon conflicts
67
+ by_surgeon: dict[str, list[int]] = {}
68
+ for i, case in enumerate(surgeries):
69
+ by_surgeon.setdefault(case.surgeon_id, []).append(i)
70
+ for indices in by_surgeon.values():
71
+ for a in range(len(indices)):
72
+ for b in range(a + 1, len(indices)):
73
+ i, k = indices[a], indices[b]
74
+ model.Add(ends[i] <= starts[k]).OnlyEnforceIf(
75
+ model.NewBoolVar(f"before_{i}_{k}")
76
+ ) # simplified: use disjunctive constraint
77
+ before = model.NewBoolVar(f"ord_{i}_{k}")
78
+ after = model.NewBoolVar(f"ord_{k}_{i}")
79
+ model.Add(ends[i] <= starts[k]).OnlyEnforceIf(before)
80
+ model.Add(ends[k] <= starts[i]).OnlyEnforceIf(after)
81
+ model.AddBoolOr([before, after])
82
+
83
+ makespan = model.NewIntVar(0, horizon * 2, "makespan")
84
+ model.AddMaxEquality(makespan, [ends[i] + turnovers[i] for i in range(n_cases)])
85
+ model.Minimize(makespan)
86
+
87
+ solver = cp_model.CpSolver()
88
+ solver.parameters.max_time_in_seconds = time_limit_sec
89
+ solver.parameters.num_search_workers = 4
90
+ t0 = time.perf_counter()
91
+ status = solver.Solve(model)
92
+ elapsed = time.perf_counter() - t0
93
+
94
+ schedule: list[ScheduledSurgery] = []
95
+ if status in (cp_model.OPTIMAL, cp_model.FEASIBLE):
96
+ nurse_assign = _assign_nurses(instance.nurses, n_cases)
97
+ for i, case in enumerate(surgeries):
98
+ room_idx = next(j for j in range(n_rooms) if solver.Value(room_choice[i][j]))
99
+ room = rooms[room_idx]
100
+ start = solver.Value(starts[i])
101
+ end = solver.Value(ends[i])
102
+ schedule.append(
103
+ ScheduledSurgery(
104
+ case_id=case.case_id,
105
+ room_id=room.room_id,
106
+ surgeon_id=case.surgeon_id,
107
+ nurse_ids=nurse_assign[i],
108
+ start_min=start,
109
+ end_min=end,
110
+ turnover_end=end + turnovers[i],
111
+ icu_reserved=case.icu_prob > 0.5,
112
+ )
113
+ )
114
+
115
+ info = {
116
+ "status": solver.StatusName(status),
117
+ "elapsed_sec": round(elapsed, 3),
118
+ "assigned": len(schedule),
119
+ }
120
+ return schedule, info
121
+
122
+
123
+ def _assign_nurses(nurses: list[Nurse], count: int) -> list[list[str]]:
124
+ if not nurses:
125
+ return [[] for _ in range(count)]
126
+ return [[nurses[i % len(nurses)].nurse_id] for i in range(count)]
127
+
128
+
129
+ def _fallback_greedy(
130
+ instance: HospitalInstance,
131
+ duration_mode: DurationMode,
132
+ ) -> tuple[list[ScheduledSurgery], dict]:
133
+ rooms_free = {r.room_id: 0 for r in instance.or_rooms}
134
+ schedule: list[ScheduledSurgery] = []
135
+ nurses = instance.nurses
136
+ for i, case in enumerate(sorted(instance.surgeries, key=lambda s: s.priority)):
137
+ dur = _duration(case, duration_mode)
138
+ best_room = min(rooms_free, key=rooms_free.get)
139
+ start = rooms_free[best_room]
140
+ end = start + dur
141
+ turnover = end + case.turnover_min
142
+ nurse_id = [nurses[i % len(nurses)].nurse_id] if nurses else []
143
+ schedule.append(
144
+ ScheduledSurgery(
145
+ case_id=case.case_id,
146
+ room_id=best_room,
147
+ surgeon_id=case.surgeon_id,
148
+ nurse_ids=nurse_id,
149
+ start_min=start,
150
+ end_min=end,
151
+ turnover_end=turnover,
152
+ icu_reserved=case.icu_prob > 0.5,
153
+ )
154
+ )
155
+ rooms_free[best_room] = turnover
156
+ return schedule, {"status": "GREEDY_FALLBACK", "elapsed_sec": 0.01, "assigned": len(schedule)}
space-bundle/src/hopcc/simulation.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """SimPy discrete-event simulation of patient flow."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import random
6
+ from dataclasses import dataclass, field
7
+ from typing import Any
8
+
9
+ import simpy
10
+
11
+ from hopcc.models import HospitalInstance, ScheduledSurgery
12
+
13
+
14
+ @dataclass
15
+ class SimulationResult:
16
+ avg_wait_min: float
17
+ avg_or_utilization: float
18
+ completed: int
19
+ cancelled: int
20
+ icu_queue_max: int
21
+ ward_queue_max: int
22
+ timeline: list[dict[str, Any]] = field(default_factory=list)
23
+
24
+ def to_dict(self) -> dict[str, Any]:
25
+ return {
26
+ "avg_wait_min": self.avg_wait_min,
27
+ "avg_or_utilization": self.avg_or_utilization,
28
+ "completed": self.completed,
29
+ "cancelled": self.cancelled,
30
+ "icu_queue_max": self.icu_queue_max,
31
+ "ward_queue_max": self.ward_queue_max,
32
+ "timeline_points": len(self.timeline),
33
+ }
34
+
35
+
36
+ def run_simulation(
37
+ instance: HospitalInstance,
38
+ schedule: list[ScheduledSurgery],
39
+ seed: int = 42,
40
+ duration_noise: float = 0.15,
41
+ ) -> SimulationResult:
42
+ rng = random.Random(seed)
43
+ env = simpy.Environment()
44
+ case_map = {s.case_id: s for s in instance.surgeries}
45
+ icu_cap = sum(b.capacity for b in instance.beds if b.unit_type == "icu")
46
+ ward_cap = sum(b.capacity for b in instance.beds if b.unit_type == "ward")
47
+
48
+ icu = simpy.Resource(env, capacity=max(1, icu_cap))
49
+ ward = simpy.Resource(env, capacity=max(1, ward_cap))
50
+ or_rooms = {r.room_id: simpy.Resource(env, capacity=1) for r in instance.or_rooms}
51
+
52
+ waits: list[float] = []
53
+ completed = 0
54
+ cancelled = 0
55
+ icu_queue: list[int] = []
56
+ ward_queue: list[int] = []
57
+ or_busy_time: dict[str, float] = {r.room_id: 0.0 for r in instance.or_rooms}
58
+ timeline: list[dict[str, Any]] = []
59
+
60
+ def patient_flow(item: ScheduledSurgery):
61
+ nonlocal completed, cancelled
62
+ case = case_map[item.case_id]
63
+ actual_dur = max(20, int(case.duration_p50 * (1 + rng.gauss(0, duration_noise))))
64
+ arrival = max(0, item.start_min - rng.randint(0, 15))
65
+ yield env.timeout(max(0, item.start_min - env.now))
66
+
67
+ room_res = or_rooms.get(item.room_id)
68
+ if room_res is None:
69
+ cancelled += 1
70
+ return
71
+
72
+ wait_start = env.now
73
+ with room_res.request() as req:
74
+ yield req
75
+ wait = env.now - wait_start
76
+ waits.append(wait)
77
+ or_start = env.now
78
+ yield env.timeout(actual_dur)
79
+ or_busy_time[item.room_id] = or_busy_time.get(item.room_id, 0) + actual_dur
80
+ timeline.append({"t": env.now, "event": "surgery_end", "case": item.case_id})
81
+
82
+ # Recovery
83
+ yield env.timeout(rng.randint(15, 45))
84
+
85
+ needs_icu = rng.random() < case.icu_prob
86
+ bed_res = icu if needs_icu else ward
87
+ q = icu_queue if needs_icu else ward_queue
88
+ with bed_res.request() as bed_req:
89
+ q.append(len(bed_res.queue))
90
+ yield bed_req
91
+ los_hours = max(0.5, case.los_days_mean * 24 * rng.uniform(0.7, 1.3))
92
+ yield env.timeout(los_hours * 6) # scaled minutes for demo horizon
93
+ timeline.append({"t": env.now, "event": "discharge", "case": item.case_id})
94
+ completed += 1
95
+
96
+ for item in sorted(schedule, key=lambda x: x.start_min):
97
+ env.process(patient_flow(item))
98
+
99
+ horizon = min(instance.horizon_minutes * 2, 2000)
100
+ env.run(until=horizon)
101
+
102
+ total_or_time = sum(or_busy_time.values())
103
+ n_rooms = max(len(or_rooms), 1)
104
+ util = min(100.0, 100.0 * total_or_time / (horizon * n_rooms))
105
+
106
+ return SimulationResult(
107
+ avg_wait_min=round(sum(waits) / max(len(waits), 1), 1),
108
+ avg_or_utilization=round(util, 1),
109
+ completed=completed,
110
+ cancelled=cancelled,
111
+ icu_queue_max=max(icu_queue) if icu_queue else 0,
112
+ ward_queue_max=max(ward_queue) if ward_queue else 0,
113
+ timeline=timeline[:50],
114
+ )
space-bundle/src/hopcc/visualization.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Plotly visualization helpers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ import plotly.graph_objects as go
8
+ from plotly.subplots import make_subplots
9
+
10
+ from hopcc.models import ScheduledSurgery
11
+
12
+
13
+ def build_gantt(schedule: list[ScheduledSurgery], title: str = "OR Schedule") -> go.Figure:
14
+ if not schedule:
15
+ fig = go.Figure()
16
+ fig.update_layout(title=title, height=400)
17
+ return fig
18
+
19
+ rooms = sorted({s.room_id for s in schedule})
20
+ colors = ["#4f46e5", "#0891b2", "#059669", "#d97706", "#dc2626", "#7c3aed"]
21
+ fig = go.Figure()
22
+ for i, room in enumerate(rooms):
23
+ items = [s for s in schedule if s.room_id == room]
24
+ fig.add_trace(
25
+ go.Bar(
26
+ x=[s.end_min - s.start_min for s in items],
27
+ y=[room] * len(items),
28
+ base=[s.start_min for s in items],
29
+ orientation="h",
30
+ name=room,
31
+ marker_color=colors[i % len(colors)],
32
+ text=[s.case_id for s in items],
33
+ textposition="inside",
34
+ hovertemplate="%{text}<br>Start: %{base}<br>Duration: %{x} min<extra></extra>",
35
+ )
36
+ )
37
+ fig.update_layout(
38
+ title=title,
39
+ barmode="overlay",
40
+ xaxis_title="Minutes from midnight",
41
+ yaxis_title="OR Room",
42
+ height=max(350, 80 * len(rooms)),
43
+ showlegend=False,
44
+ )
45
+ return fig
46
+
47
+
48
+ def build_policy_comparison(rows: list[dict[str, Any]]) -> go.Figure:
49
+ if not rows:
50
+ return go.Figure()
51
+ policies = [r.get("policy_label", r.get("policy_id", "")) for r in rows]
52
+ metrics = ["surgeries_completed", "or_utilization_pct", "avg_patient_wait_min", "bed_shortage_events"]
53
+ fig = make_subplots(rows=1, cols=len(metrics), subplot_titles=metrics)
54
+ for j, metric in enumerate(metrics):
55
+ fig.add_trace(
56
+ go.Bar(x=policies, y=[r.get(metric, 0) for r in rows], name=metric, showlegend=False),
57
+ row=1,
58
+ col=j + 1,
59
+ )
60
+ fig.update_layout(title="Policy Benchmark Comparison", height=420, barmode="group")
61
+ return fig
62
+
63
+
64
+ def build_disruption_delta(before: dict, after: dict) -> go.Figure:
65
+ keys = ["surgeries_completed", "overtime_minutes", "or_utilization_pct", "avg_patient_wait_min", "bed_shortage_events"]
66
+ fig = go.Figure()
67
+ fig.add_trace(go.Bar(name="Before Replan", x=keys, y=[before.get(k, 0) for k in keys], marker_color="#94a3b8"))
68
+ fig.add_trace(go.Bar(name="After Replan", x=keys, y=[after.get(k, 0) for k in keys], marker_color="#4f46e5"))
69
+ fig.update_layout(title="Disruption Response — Metrics Before vs After", barmode="group", height=400)
70
+ return fig
71
+
72
+
73
+ def build_utilization_timeline(schedule: list[ScheduledSurgery], horizon: int = 720) -> go.Figure:
74
+ buckets = 24
75
+ step = horizon / buckets
76
+ rooms = sorted({s.room_id for s in schedule})
77
+ fig = go.Figure()
78
+ for room in rooms:
79
+ util = [0.0] * buckets
80
+ for s in schedule:
81
+ if s.room_id != room:
82
+ continue
83
+ for b in range(buckets):
84
+ t0, t1 = b * step, (b + 1) * step
85
+ overlap = max(0, min(s.turnover_end, t1) - max(s.start_min, t0))
86
+ util[b] += overlap / step * 100
87
+ fig.add_trace(go.Scatter(x=list(range(buckets)), y=util, mode="lines+markers", name=room))
88
+ fig.update_layout(title="OR Utilization Timeline", xaxis_title="Hour bucket", yaxis_title="Utilization %", height=380)
89
+ return fig