I've been looking through social choice theory textbooks and videos trying to find the right sort of algorithm for this, but struggling. Basically I have N (say 21) people that I need to assign into G (say 5) groups. Each of these 21 voters have a ranked choice ballot and I want to be able to maximize it in a way so that we get as many people as close to their first choice as possible.
One way I thought of doing it is by having a score, S, that we want to minimize. When someone gets into their first choice, we add 1^2 to that score. Second choice gets 4=2^2 added to that, third choice gets 9=3^2 added, etc.
One situation I thought about that makes it seem really complicated is when you have, for example, 2 people who both have a first choice pick for a group with a single spot left, you'd have to be able to look and see that if person1 got that spot then person2 could just go to their second choice. But if person2 got that spot, person1 would have to go to their 3rd or 4th choice.
I'm not sure if party-list proportional representation systems are a good fit or not. I've been trying to figure out how the Hamilton, D'Hondt, Sainte-Lague, or other methods would fit into this, but struggling.
Any tips would be highly appreciated