Working example 02 Genetic algorithm

Conflicting operational constraints

“Every change to the schedule creates a problem somewhere else.”

A service centre open 06:00–22:00, seven days a week, must match staff to an uneven demand curve while respecting contracts, rest rules, availability and supervisor cover.

How it works

The method in three steps

  1. Encode a rosterEach chromosome holds a shift start (06, 08, 10, 12, 14) or a day off for every person and every day.genes = staff × 7 days, values ∈ {off, 06, 08, 10, 12, 14}
  2. Score every ruleUnderstaffing, overstaffing, rest periods under 11 hours, contracts other than five days, availability and supervisor gaps all add penalties.penalty = 10·under + w·over + 60·rest + 60·contract + 30·supervisor + 60·availability
  3. EvolveTournament selection, crossover of whole personal rosters, and mutations that move a day off or a start time. The two best rosters always survive.population 120 · up to 600 generations · elitism 2

Try it

The working example

Search settings

Run the algorithm and watch the roster improve.

Changing it restarts the search
Understaffing costs 10 per hour
Share of personal rosters altered per child
Generation0
Understaffed hours–
Overstaffed hours–
Rule breaches–

Search progress

Penalty of the best roster in each generation.

Staffing against demand

Rostered staff minus required staff, by day and hour.

Best roster found

Shift start and end times for each person.

StaffMonTueWedThuFriSatSun

Interpretation

From example to engagement

What the example shows

The hand-built roster is reasonable on paper — fixed shifts, fair patterns — yet misses demand peaks and breaks rest rules. The algorithm finds arrangements of the same people that no planner would think to try, and makes the trade-off between service and idle time explicit through the penalty weights.

With real data

  • Forecast demand by interval, contracts, skills, leave and preferences.
  • Hard legal rules kept as constraints; soft preferences as weighted penalties.
  • Alternatives: mixed-integer programming or constraint programming where proofs of optimality matter.