Technical Deep Dive
A plain-English explanation of the AI scheduling system behind Shift Optimizer — written for hiring managers, not just engineers.
Instead of manually juggling spreadsheets, this app mathematically proves the best possible schedule — handling impossible constraints gracefully while maximizing employee happiness.
The Technology
One guarantees rules, one maximizes happiness, and the newest layer ensures the system never crashes even when the math is "impossible".
Layer 1
Google's CP-SAT solver assigns shifts across 30 employees, 3 departments, and 7 days simultaneously. It doesn't try schedules one by one — it reasons over all possibilities at once using constraint propagation and branch-and-bound search. The result is a mathematically proven optimal schedule, not a heuristic guess.
Provably optimal — not trial and errorLayer 2
Beyond just satisfying rules, the optimizer minimizes a penalty score representing employee dissatisfaction. "Must-off" days are hard constraints (never violated). "Prefer-off" days and shift preference mismatches carry numerical penalties. The solver finds the schedule that minimizes total employee unhappiness.
Hard rules guaranteed + soft preferences maximizedLayer 3 (New)
Traditional solvers crash or return "No Solution" when constraints are too tight (like having too few staff). This engine intercepts impossible scenarios with a heuristic pre-check. If needed, a "Best Effort Mode" converts hard minimum-staffing rules into soft constraints using slack variables with massive penalties. It mathematically guarantees the best possible schedule even when short-staffed, flagging the gaps for the manager.
Heuristic Pre-check · Slack Variables · FeasibilityConstraint Design
The key engineering decision: which rules must never be broken, and which are best-effort goals the optimizer tries to satisfy?
The Process
Here's exactly what happens when you click "Optimize Shifts."
For every combination of employee × day × shift, a binary variable is created: 1 = assigned, 0 = not assigned. With 30 employees × 7 days × 3 shifts, that's 630 variables the solver must assign simultaneously.
Each business rule becomes a mathematical constraint. However, if "Best Effort Mode" is enabled, minimum staffing requirements are relaxed using *slack variables* so the solver doesn't fail when understaffed.
Prefer-off days and shift preferences are converted into penalty terms. The solver's objective is to minimize the total penalty score — meaning it will try its hardest to honor soft preferences, but won't break hard rules to do so.
The solver explores the solution space using constraint propagation (eliminating impossible assignments early) and branch-and-bound search (proving no better solution exists). It returns the schedule with minimum penalty score within the time limit, along with a satisfaction score for each employee.
Business Applications
Mathematical optimization transforms shift scheduling from a painful weekly chore into a solved, scalable, and auditable process.
Manually building schedules for 30+ staff typically takes hours each week. The optimizer produces a valid, optimized schedule in under 15 seconds. If understaffed, it flags exactly where the gaps are, allowing managers to make targeted human decisions rather than starting from scratch.
Labor rules (max consecutive days, minimum certified coverage, mandatory manager presence) are guaranteed by the model — not enforced by human memory. Every schedule produced is provably compliant with every configured rule.
The optimizer explicitly quantifies and minimizes employee dissatisfaction. Rather than ignoring preferences when scheduling gets complex, it mathematically balances fairness across the entire team — reducing turnover-inducing schedule conflicts.
Why It Matters
Shift scheduling is a classic OR problem. Formulating it correctly — choosing which constraints are hard vs. soft, using slack variables to prevent crashes, and weighting penalty terms — requires deep understanding of both the business problem and the solver's capabilities.
OR-Tools CP-SAT is the same solver used internally at Google. Using it in a portfolio project demonstrates familiarity with enterprise-grade optimization tools, not just academic toy problems.
The app goes from user input to deployed web product: Streamlit UI, Python optimization engine, Plotly visualizations, bilingual i18n, and Streamlit Cloud deployment. End-to-end data product thinking.
The satisfaction score and per-employee breakdown make optimization results auditable and understandable — not a black box. Managers can see exactly why each schedule was chosen and where trade-offs were made.
Try It
The app is live. Randomize preferences and constraints, then click Optimize.