Given S * E distinguishable objects, this class helps enumerate all partitions into S groups of size E. More...
#include <Partitioner.h>
Public Member Functions | |
Partitioner (unsigned s, unsigned e) | |
Constructor. More... | |
bool | next_partition () |
Advance underlying state to the next partition. More... | |
std::vector< std::vector < unsigned > > | partitions () const |
Generate sets of element indices within their respective partitions. More... | |
unsigned | s () const |
Number of groups. | |
unsigned | e () const |
Number of elements per group. | |
const std::vector< unsigned > & | map () const |
Access to underlying flat map from element index to group index. | |
Static Public Member Functions | |
static bool | isOrderedMapping (const std::vector< unsigned > &mapping) |
Check whether the sets as specified by the mapping are ordered. More... | |
Private Attributes | |
unsigned | S |
Number of groups. | |
unsigned | E |
Number of elements per group. | |
std::vector< unsigned > | mapping |
Flat map from element index to group index. | |
Given S * E distinguishable objects, this class helps enumerate all partitions into S groups of size E.
The challenge with writing such a class is getting complexity less than \(\Theta((S\cdot E)!)\) considering that the sets themselves are indistinguishable. For instance, for the trivial example \(S = 2, E = 2\), there are only three distinct solutions:
There are two orders at play here, the sets are lexicographically ordered and the elements within them are too.
Scine::Molassembler::Shapes::Partitioner::Partitioner | ( | unsigned | s, |
unsigned | e | ||
) |
Constructor.
s | Number of groups |
e | Number of elements per group |
s
is not zero and e
is not zeroComplexity \(\Theta(S\cdot E)\)
|
static |
Check whether the sets as specified by the mapping are ordered.
Complexity \(O(S\cdot E)\)
bool Scine::Molassembler::Shapes::Partitioner::next_partition | ( | ) |
Advance underlying state to the next partition.
Complexity \(O(S\cdot E)\)
std::vector< std::vector<unsigned> > Scine::Molassembler::Shapes::Partitioner::partitions | ( | ) | const |
Generate sets of element indices within their respective partitions.
Complexity \(\Theta(S\cdot E)\)