0

I have an interesting problem that others mot likely have run into at one point. I will be doing this in Java and figuring out the code, but first I need to figure out the best algorithm (or AN algorithm).

I have several groups (g1, g2, g3, g4, g5, ...). Each group has a set of members (so call them s1, s2, s3, s4, s5, ... respectively). Members are not limited to one group, so a member of group 1 could be a member of group 2 and/or 3 and/or ...

I am trying to find the minimum number of members so that all groups are represented. The obvious solution is to take one member from each group, but that is not necessarily the minimum number. The optimal solution, which will work only a small fraction of the time, is to do s1.retainsAll(s2).retainAll(s3).retainAll(s4).retainAll(s5)... but there is a high probability this will yield the empty set.

I could examine two sets, and then examine a third, etc. But who knows what order would be the best to do this.

This reminds me sort of of a least common multiple problem, but it does not really translate so well (unless there is some math genius who can tell me how to translate it ;-) ).

Has anyone else had to solve this? Can you offer any suggestions?

Tony
  • 1,127
  • 1
  • 18
  • 29
  • 3
    https://en.wikipedia.org/wiki/Set_cover_problem – David Eisenstat Mar 10 '16 at 14:25
  • Thanks. That will give me some help. My situation is a little different I think, but maybe I can figure out how that is. – Tony Mar 10 '16 at 14:39
  • Just invert your problem. For every member, calculate the set of groups that contain that member. Then you want to find the minimum number of sets (i.e. members) whose union contains all groups. This formulation is then the original set cover problem as David pointed out. – Nico Schertler Mar 10 '16 at 15:07

0 Answers0