问题
So I want to write a small program that would be able to take a group of people (100-200) and divide them into several equal groups (10-15) with constraints.
Each person has a city they came from (usually around 8-12 different cities total). Each person was in a group of people before this new division (10-20 different groups). Thats it for the example.
Now I want to divide those people in different group such that we strive to have same number of people from different cities in each team (so not all new yorkes are in the same team etc) and strive that people who have been in the same team before wont team up again.
Cant find an algorithm that can help me.
回答1:
There is an np-complete feeling about finding an absolute best answer. But you just want a pretty good answer, pretty fast, it isn't hard to come up with a heuristic.
Set up your empty teams. Decide on the maximum team size. Sort people by the number of other people to avoid (same city or past same team) descending. Put each person in the non-full team with the least other people you are trying to avoid, breaking ties for the team with smaller people, and randomly breaking any remaining ties.
This is not guaranteed to produce optimal results. But it is simple and will produce pretty good ones.
来源:https://stackoverflow.com/questions/27133372/divide-a-group-of-people-into-teams-with-constraints