Inspiration

Every Monday morning, a production planner at a brewery faces the same puzzle: 53 SKUs, 3 lines, dozens of possible changeovers — and a gut feeling that the sequence they just approved is leaving hours on the table.

We wanted to replace that gut feeling with evidence. Not a static spreadsheet, but a living graph that remembers every transition ever made and uses that memory to suggest something better.

What it does

Operations Lab is a two-panel decision-support tool:

  • Operation Lab — Generative Bayesian Graphs: animates 53 weeks of real 2025 production as an evolving transition graph. Each node is a SKU; each edge encodes a Bayesian posterior over changeover duration built from every observed instance. Black-spot edges (high-cost transitions) glow red. A shared slider + Gantt lets you scrub through the full year and watch the network grow in real time.

  • Optimización 2026: loads the actual planned and executed schedule for 18–22 May 2026, then runs a Genetic Algorithm or Simulated Annealing optimizer against the same Bayesian changeover model. The result is a side-by-side comparison of Planner teórico, Real ejecutado, and AI Óptimo — with OEE deltas, dead-hour breakdowns, and uncertainty bands (HDI lower / upper) so the planner knows the best and worst-case range.

How we built it

  1. Data pipeline — raw OEE, cambios, and volumen Excel files are cleaned into changeovers.csv, frames_2025.csv, and historical_weeks.csv.

  2. Bayesian changeover model — for each (line, prev_sku, next_sku) pair we fit a Gamma-Exponential conjugate model. The prior is anchored to the line mean; the posterior combines all observed samples. Four query modes: bayes_mean, observed_mean, hdi_lower, hdi_upper.

  3. Generative graphbuild_combined_dashboard renders a Bokeh layout (Gantt + 3 transition graphs) wired to a single JS slider. All animation is client-side CustomJS so the dashboard stays fluid without Streamlit reruns.

  4. Optimizer — a standard GA (evolve) and SA (run_sa) share the same OptimizerContext, which holds the Bayesian changeover cache. Urgent orders can be injected at runtime and are tracked back to their final position in the sequence.

  5. Frontend — Streamlit + Bokeh + Plotly. No external database; everything runs from local CSV/XLSX files.

Challenges

  • Backward-compatible context — adding changeover_stats, changeover_mode, and the HDI cache to OptimizerContext without breaking the existing GA fitness function required careful dataclass field ordering and a set_changeover_policy mutator instead of re-instantiating the context.

  • Client-side animation at scale — pushing ~3 000 Gantt bars and three graphs into a single Bokeh layout and keeping it smooth meant pre-computing all per-tick state in Python and shipping it as flat arrays to CustomJS, rather than calling back to the server on every slider tick.

  • Apples-to-apples comparison — the planner's Excel uses different volume columns than the real-execution export. context_for_plan_week reconciles SKU eligibility, volume maps, and format lookups so all three scenarios (planner, real, AI) are evaluated with identical cost functions.

What we learned

Bayesian inference on small samples (sometimes 1–2 observations per transition) is far more useful than a simple mean: the HDI bands give planners an honest picture of uncertainty, and the prior prevents extreme outliers from dominating the optimizer's decisions.

Built With

Share this project:

Updates