This project implements an Enterprise-Grade Nurse Scheduling System (NSS) using Mixed-Integer Programming (MIP). The system is designed to generate optimal staff schedules that minimize labor costs while strictly adhering to complex labor laws, hospital policies, and employee preferences. The core optimization engine is built using Gurobi Optimizer integrated with a modern FastAPI backend and Next.js frontend.
The scheduling problem involves assigning a set of employees (nurses, doctors) to specific shifts over a defined planning horizon (e.g., 1-4 weeks) to meet fluctuating demand for various skills.
-
Employees (
$E$ ): Staff members with specific roles, skills, hourly costs, and availability constraints. -
Shifts (
$S$ ): Defined work periods (e.g., Morning, Afternoon, Night) with specific start/end times. -
Days (
$T$ ): The planning horizon (e.g.,$t=1 \dots 7$ ). -
Skills (
$K$ ): Qualifications required for shifts (e.g., "RN", "Senior", "ICU").
The problem is formulated as a Mixed-Integer Linear Program (MILP).
-
Assignment Variable:
$$x_{e,t,s} \in {0, 1}$$ Equals 1 if employee$e$ is assigned to shift$s$ on day$t$ , 0 otherwise. -
Slack Variable (Elastic Demand):
$$y_{t,s,k} \ge 0$$ Represents the amount of uncovered demand (shortage) for skill$k$ on shift$s$ at day$t$ . This allows the solver to find "best effort" solutions even when perfect coverage is impossible.
The objective is to minimize the weighted sum of Labor Cost, Uncovered Demand Penalty, and Preference Violations.
Where:
-
$C_e$ : Hourly cost of employee$e$ . -
$L_s$ : Length of shift$s$ in hours. -
$W_1, W_2, W_3$ : Weights for Cost, Coverage, and Preferences respectively. -
$P_{avoid}$ : Set of assignments that violate employee preferences.
Ensure enough skilled staff are assigned, or record the shortage in the slack variable.
Where
An employee cannot work more than one shift per day.
Employees must not exceed their maximum contract hours.
Employees must have at least
Where a pair is forbidden if
Employees cannot work more than
For critical shifts (e.g., ICU), the number of Senior staff must equal or exceed Junior staff.
Limit the burden of night shifts on any single employee.
Ensure every employee gets a minimum number of shifts (if available) to distribute work fairly.
If an employee works on Saturday, they must also work on Sunday (and vice versa), preventing split weekends.
- Language: Python 3.10+
- Solver: Gurobi Optimizer (via
gurobipy) - API: FastAPI (Asynchronous job processing)
- Database: SQLite (SQLAlchemy ORM)
The system implements Irreducible Inconsistent Subsystem (IIS) computation. If the model is infeasible (e.g., demand exceeds total capacity), the solver identifies the specific set of conflicting constraints and logs them. This allows administrators to pinpoint exactly why a schedule cannot be generated (e.g., "Insufficient staff for ICU Night Shift on Tuesday").
The model uses a weighted objective function to balance competing goals:
- Cost Efficiency: Minimizing total payroll.
-
Service Level: Minimizing uncovered shifts (via high penalty
$W_2$ ). - Employee Satisfaction: Minimizing assignments to "avoid" shifts.
This project demonstrates a sophisticated application of Operations Research in a healthcare setting. By incorporating real-world constraints like Forward Rotation, Skill Ratios, and Complete Weekends, the model moves beyond academic exercises to address actual hospital scheduling challenges. The integration of Elastic Constraints ensures the system remains robust and usable even under high-demand scenarios where perfect coverage is mathematically impossible.