Partition class that supports incremental splitting, with backtracking. More...
#include <dynamic_partition.h>
Classes | |
| struct | IterablePart |
Public Types | |
| enum | DebugStringSorting { SORT_LEXICOGRAPHICALLY, SORT_BY_PART } |
| Dump the partition to a std::string. More... | |
Public Member Functions | |
| DynamicPartition (int num_elements) | |
| Creates a DynamicPartition on n elements, numbered 0..n-1. More... | |
| DynamicPartition (const std::vector< int > &initial_part_of_element) | |
| Ditto, but specify the initial part of each elements. More... | |
| int | NumElements () const |
| Accessors. More... | |
| const int | NumParts () const |
| IterablePart | ElementsInPart (int i) const |
| *** Implementation of inline methods of the above classes. *** More... | |
| int | PartOf (int element) const |
| int | SizeOfPart (int part) const |
| int | ParentOfPart (int part) const |
| IterablePart | ElementsInSamePartAs (int i) const |
| A handy shortcut to ElementsInPart(PartOf(e)). More... | |
| uint64 | FprintOfPart (int part) const |
| Returns a fingerprint of the given part. More... | |
| void | Refine (const std::vector< int > &distinguished_subset) |
| Refines the partition such that elements that are in distinguished_subset never share the same part as elements that aren't in that subset. More... | |
| void | UndoRefineUntilNumPartsEqual (int original_num_parts) |
| Undo one or several Refine() operations, until the number of parts becomes equal to "original_num_parts". More... | |
| std::string | DebugString (DebugStringSorting sorting) const |
| const std::vector< int > & | ElementsInHierarchicalOrder () const |
| ADVANCED USAGE: All elements (0..n-1) of the partition, sorted in a way that's compatible with the hierarchical partitioning: More... | |
Partition class that supports incremental splitting, with backtracking.
See http://en.wikipedia.org/wiki/Partition_refinement . More precisely, the supported edit operations are:
S <<< N) of elements are all considered non-equivalent to any element in ¬S. Typically, this should be done in O(S).Undo the above operations (backtracking).
Definition at line 49 of file dynamic_partition.h.
Dump the partition to a std::string.
There might be different conventions for sorting the parts and the elements inside them.
| Enumerator | |
|---|---|
| SORT_LEXICOGRAPHICALLY | Elements are sorted within parts, and parts are then sorted lexicographically. |
| SORT_BY_PART | Elements are sorted within parts, and parts are kept in order. |
Definition at line 117 of file dynamic_partition.h.
|
explicit |
Creates a DynamicPartition on n elements, numbered 0..n-1.
Start with the trivial partition (only one subset containing all elements).
|
explicit |
Ditto, but specify the initial part of each elements.
Part indices must form a dense integer set starting at 0; eg. [2, 1, 0, 1, 1, 3, 0] is valid.
| std::string operations_research::DynamicPartition::DebugString | ( | DebugStringSorting | sorting | ) | const |
|
inline |
ADVANCED USAGE: All elements (0..n-1) of the partition, sorted in a way that's compatible with the hierarchical partitioning:
Definition at line 136 of file dynamic_partition.h.
|
inline |
*** Implementation of inline methods of the above classes. ***
Definition at line 276 of file dynamic_partition.h.
|
inline |
A handy shortcut to ElementsInPart(PartOf(e)).
The returned IterablePart will never be empty, since it contains at least i.
Definition at line 303 of file dynamic_partition.h.
|
inline |
Returns a fingerprint of the given part.
While collisions are possible, their probability is quite low. Two parts that have the same size and the same fingerprint are most likely identical. Also, two parts that have the exact same set of elements will always have the same fingerprint.
Definition at line 308 of file dynamic_partition.h.
|
inline |
Accessors.
Definition at line 60 of file dynamic_partition.h.
|
inline |
Definition at line 61 of file dynamic_partition.h.
|
inline |
Definition at line 297 of file dynamic_partition.h.
|
inline |
Definition at line 284 of file dynamic_partition.h.
| void operations_research::DynamicPartition::Refine | ( | const std::vector< int > & | distinguished_subset | ) |
Refines the partition such that elements that are in distinguished_subset never share the same part as elements that aren't in that subset.
This might be a no-op: in that case, NumParts() won't change, but the order of elements inside each part may change.
ORDERING OF PARTS: For each i such that Part #i has a non-trivial intersection with "distinguished_subset" (neither empty, nor the full Part); Part #i is stripped out of all elements that are in "distinguished_subset", and those elements are sent to a newly created part, whose parent_part = i. The parts newly created by a single Refine() operations are sorted by parent_part. Example: a Refine() on a partition with 6 parts causes parts #1, #3 and #4 to be split: the partition will now contain 3 new parts: part #6 (with parent_part = 1), part #7 (with parent_part = 3) and part #8 (with parent_part = 4).
|
inline |
Definition at line 290 of file dynamic_partition.h.
| void operations_research::DynamicPartition::UndoRefineUntilNumPartsEqual | ( | int | original_num_parts | ) |
Undo one or several Refine() operations, until the number of parts becomes equal to "original_num_parts".
Prerequisite: NumParts() >= original_num_parts.