Trainees and Rotas: an Assignment Problem
- 6 minsI saw this tweet last night on Twitter:
The worst solution is:
— Graham McCracken (@grahamccracken) January 30, 2020
Line A - Person 1
B - 2
C - 8
D - 6
E - 4
F - 3
G - 7
H - 5
This has a mean choice of 6.5 out of 8.
What's the best combination? https://t.co/HKPrn5MizT pic.twitter.com/ZeWnCVmHhC
Graham McCracken raised a problem that is frequently encountered by hospital consultants and junior doctors who are in charge of the rota: fairly assigning rota slots to trainees according to their preferences. Of course this is essentially an example of the Assignment Problem.
So I decided to have a go at solving this problem using the lpSolve
package in R
.
After loading up the lpSolve
package, we set up the Trainees’ (numbered 1 to 8) preferences (prefT
) for particular rota lines (A to H) in a matrix. After we have set up the preferences, we can use the lp.assign()
function to perform the match.
The lp.assign()
returns the solution of the match as a matrix. There should be more than 1 permutation of the solution available but in this instance, the function only returns one permutation. We can then view the result.
Rota | Trainee | Preference |
---|---|---|
A | 8 | 1 |
B | 5 | 2 |
C | 1 | 3 |
D | 4 | 3 |
E | 3 | 3 |
F | 6 | 3 |
G | 2 | 2 |
H | 7 | 3 |
As you can see, 1 Trainee received their 1st choice, 2 received their 2nd choices, and the remaining 5 received their 3rd choices. This gives a mean preference ranking of 2.5 for this solution, which is the best result if you were to try every single permutation of Rota and Trainee there is available. For 8 Rota lines and 8 Trainees, the number of possible permutations would be 8! = 40320.
Also, in this example we have 8 trainees for 8 rota lines, but we could presumably also reformulate it for fewer trainees if there are rota gaps.