开发者

Separate groups of people based on members

开发者 https://www.devze.com 2022-12-27 10:58 出处:网络
I have groups of people. I need to move groups with at least one same member as far as possible from each other.

I have groups of people. I need to move groups with at least one same member as far as possible from each other.

Example:

GroupA - John, Bob, Nick
GroupB - Jack, Nick
GroupC - Brian, Alex, Steve

As you can see GroupA and GroupB overlap(they both contain Nick) I need an algorithm to set groups as GroupA->Grou开发者_高级运维pC->GroupB

Thank you


This depends on how you define the problem exactly -- with overlaps and costs and things.

This might reduces to Travelling salesman problem -- you can set edge weights as 0 if group i and j has nothing in common, and some function f(i,j) that depends on the number of common items between them. Then, you want a list that goes from one group to the last group, visiting each group once, minimizing some function of overlap.

You can probably reduce TSP to a version of this (really depending on how specific you mean by "farthest as possible", with regards to competing overlaps) similarly.

Unfortunately, this is NP-complete, which means you should start looking for something that's "good enough".


This problem does not have a unique or even meaningful solution if you have arbitrary groups. See for example:

GroupA = {Alice, Bob}
GroupB = {Bob, David}
GroupC = {David, Alice}
0

精彩评论

暂无评论...
验证码 换一张
取 消