This is an algorithmic problem. If I miss any existing function in Python that helps, please give a shout.
Given a set s
of n
elements, we can use itertools.combinations()
function in Python to find all the unique k-element subsets. Let's call the set containing all these subsets S
. Notice that each such subset has k
distinct elements.
The problem is 2-step. First, given these k-distinct-element subsets, I want to compose (some of) them such that (a composition is simply a superset of some subsets):
The intersection between any two subsets within a composition is empty
The union between all the subsets in a composition gives exactly the original set
s
Second, I want to find the compositions that:
Do not share any subset
Their union gives exactly the
S
, i.e. the set of all thek
-element subsets
As a concrete example here, consider the original set s = {a, b, c, d}
and k = 2
, we then will have the following three compositions/supersets:
{{a, b}, {c, d}}, {{a, c}, {b, d}}, {{a, d}, {b, c}}
Obviously, the size of s
can be large and k >= 2
, so an efficient (especially the speed) algorithm is needed here.
P.S. I phrase the problem in 2 steps, but it may well be that an efficient algorithm attacks the problem from a different angle.
I implemented the integral maximum flow construction that's used to prove Baranyai's theorem. More details in your favorite textbook covering factors of a complete hypergraph.