I'm trying to find if there are any solutions for a problem I've got. I've got X people and Y positions to place them in. Sometimes there might be more people than positions, but in the default case X==Y. I want to allocate the people such that the distance that any one person has to move is minimized. So if I had people 1-5 and positions A-E:
1 2 3 4 5
A B C D E
The trivial implementation I already had was assigning {A2, B3, C4, D5, E1}, which resulted in E moving much further than anyone else, when I would prefer if the matchup was {A1, B2, C3, D4, E5}, which means everyone else moves a little further, but the worst case is much smaller.
I'm currently creating an array for each person, containing each position, sorted by distance (ascending). Then I reverse sort the arrays of all the people such that the player with the highest distance to his best position is first. I allocate him to a position, then remove that position from the list of each other player, and reverse sort and repeat until all positions are filled.
This gives me reasonable results, but seems very inefficient (removing elements from each array and resorting each time)
Obviously the problem doesn't have to deal with people and distances to positions, but can be said to be allocating resources, where each resource can perform a task with a certain fitness, and I want to avoid using a tool that is grossly unsuitable for a given task, even if it means every tool is doing a task that is slightly unsuitable, if that makes sense.
I suspect that there is some classic optimization problem that I'm mirroring here, but I don't know which one.