The problem
The Nurse Scheduling Problem (NSP) assigns nurses to shifts across a week so that every shift is covered without overworking anyone or ignoring their requests. It is a classic NP-hard combinatorial optimization problem — there are exponentially many possible schedules and no shortcut to the best one.
A schedule has two kinds of rules:
- Hard constraints — must be satisfied: per-shift staffing (min/max nurses on duty), no consecutive shifts for the same nurse, and a weekly shift cap. Violations carry a heavy penalty.
- Soft constraints — preferences: each nurse can mark shifts they would rather not work. Breaking a preference adds a small penalty.
The total cost is HARD_PENALTY × hard_violations + preference_breaks. The lab visualizes seven different algorithms searching for low-cost schedules.
How to use the lab
- Set the problem size in the left sidebar: number of nurses, days, and shifts per day.
- Fill the Nurse Requests table in the middle of the page (see the next section for details). Click cells to mark shifts a nurse wants off, or use Randomize / Clear in the sidebar.
- (Optional) Tune hard constraints via the Hard Constraints button — adjust the weekly cap, the penalty weight, and per-shift staffing min/max, or pick a preset (Quiet / Balanced / Busy / Strict).
- Pick an algorithm from the bar at the bottom and click it to launch a live 3D run. A popup window opens showing the schedule cube updating in real time.
- Watch and compare: telemetry shows current cost, best cost, hard violations, preference breaks, and the cost trajectory. Use Stop in the popup or Esc to close.
- Click the small ℹ on any algorithm card to read its description and view the actual Python source from
OptimizationGui/.
Filling the Nurse Requests table
The Nurse Requests table is where you tell the algorithm which shifts each nurse would prefer not to work. You edit one nurse at a time:
- Pick a nurse — the row of pill-shaped tabs above the table lists every nurse. Click one to switch which nurse you are editing; the active tab is highlighted in cyan/violet. The small number on each tab is how many off-requests that nurse already has.
- (Optional) Rename the nurse — type a name in the Rename field below the tabs (e.g. "Alice", "Night-only"). The new name immediately appears on the tab and in the schedule view.
- Toggle off-requests — the table rows are days and the columns are shifts. Click any cell to flip its state:
- Ok (empty / dim) — the nurse is available for this shift.
- Off (magenta tint) — the nurse has requested this shift off. Algorithms try to avoid scheduling them here; if forced to, it counts as a preference break.
- Work (green tint, with a green dot) — appears after a run finishes; this is a shift the algorithm assigned to this nurse.
- Off + Work (red tint) — appears after a run; the algorithm had to assign a shift the nurse asked off, so this cell is a preference break.
- Rename days or shifts — the column headers (shift names like Morning / Evening / Night) and row headers (day names like Mon / Tue / …) are editable. Click the header text and type to rename. Useful for ward-specific shift labels.
- Repeat for every nurse — switch tabs and mark each nurse's preferences. You don't have to fill every nurse; nurses left blank simply have no off-requests.
- Bulk fill — use Randomize in the sidebar to scatter random off-requests across all nurses (useful for quickly testing an algorithm), or Clear to wipe all preferences and start clean.
After a run, a small chip below the table summarises that nurse's outcome: how many shifts they were scheduled for and how many of their preferences were broken.
The 3D visualization
Axes
X — days · Y — shifts in the day · Z — individual nurses. A glowing cyan cube is an assigned shift; a magenta tint means it violates a nurse's off-request.
Camera
Drag to orbit · scroll to zoom · use Top / Iso / Front for preset views. Toggle Auto-rotate for an idle cinematic spin.
Telemetry
The right panel of the popup tracks current cost, best cost so far, iteration count, hard violations, preference breaks, and a live cost trajectory chart.
Speed
The Run speed slider in the popup controls how fast iterations are visualized — it does not change the algorithm itself, only the playback rate.
Keyboard shortcuts
- Space — run / pause the selected algorithm
- R — reset the problem instance
- A — toggle camera auto-rotate
- E — open the Hard Constraints editor
- Esc — close any open popup or modal