Divide a group of people into teams with constraints

a 夏天 提交于 2021-02-11 18:18:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!