You have a graph where the nodes are in groups. You want to create edges between all nodes that are in different groups.
For example, given the following groups:
[[1, 2], [3], [4, 5]]
The graph should looke like:
def edges(all_groups)
all_groups.combination(2).flat_map do |group, antigroup|
group.product(antigroup)
end
end
[1] pry(main)> groups = [[1, 2], [3], [4, 5]]
[2] pry(main)> groups.combination(2).flat_map { |g, ag| g.product(ag) }
# => [[1, 3], [2, 3], [1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]]