The Minimal Set of Multisets Abstract Data Type
Introduction
The Minimal Set of Multisets (MSM) is a data structure that represents a set of multisets. No multiset in a MSM is a subset of another multiset in the MSM. It is the antichain that backs the minimality pruning of the variant generation engine. When you add a new multiset to a MSM, one of two things happens:
- If the new multiset is a superset of an existing multiset, nothing happens and the MSM remains unchanged.
- Otherwise, if the new multiset is not a superset of any existing multiset, it is added to the MSM. Then, any multiset that is a superset of the added multiset is removed from the MSM.
Example
Suppose we have a MSM with the following multisets:
{1: 1, 2: 1, 3: 2}
{1: 1, 2: 2, 4: 1}
{1: 1, 3: 1, 5: 1}
If we add the multiset {1: 3, 2: 3, 3: 1, 4: 1}, nothing happens and the MSM remains unchanged, because the new multiset is a superset of the second multiset.
If we add the multiset {1: 1, 2: 1, 6: 1}, it is added to the MSM:
{1: 1, 2: 1, 3: 2}
{1: 1, 2: 2, 4: 1}
{1: 1, 3: 1, 5: 1}
{1: 1, 2: 1, 6: 1}
If we add the multiset {1: 1, 2: 2}, it is added to the MSM, and all its supersets are removed:
{1: 1, 2: 1, 3: 2}
{1: 1, 3: 1, 5: 1}
{1: 1, 2: 1, 6: 1}
{1: 1, 2: 2}
If we add the multiset {1: 1, 2: 1}, it is added to the MSM, and all its supersets are removed:
{1: 1, 3: 1, 5: 1}
{1: 1, 2: 1}
Implementation
You can find the implementation of the MSM in the minimal_set_of_multisets.py file.
References
These are the papers/links to refer for the implementation of an optimized MSS (Minimal Set of Sets) data structure:
- Stack Overflow Question #1
- Article: "Data structure set-trie for storing and querying sets: Theoretical and empirical analysis"
- Article: "Index Data Structure for Fast Subset and Superset Queries"
- Stack Overflow Question #2
- Stack Overflow Question #3
These are the papers/links to refer for the implementation of an optimized MSM (Minimal Set of Multisets) data structure:
Considerations
Cython works way better with simple Python code than with over-engineered data structures, so the MSM stores its multisets in a plain Python set with two indexes on top. Each multiset is indexed under every element it holds, so that its supersets are looked for among the multisets holding its least shared element, and under a single key, the element of it that was least shared when it was added, so that its subsets are looked for among the multisets keyed by its elements. Elements held by every multiset, like the cards a combo always needs, then never make a search go through the whole collection.