Maintains a 'partial' permutation of [0..n-1] onto itself, with a dynamic API allowing it to be built incrementally, and allowing some backtracking. More...
#include <dynamic_permutation.h>
Public Member Functions | |
| DynamicPermutation (int n) | |
| Upon construction, every element i in [0..n-1] maps to itself. More... | |
| int | Size () const |
| void | AddMappings (const std::vector< int > &src, const std::vector< int > &dst) |
| Declares a set of mappings for this permutation: src[i] will map to dst[i]. More... | |
| void | UndoLastMappings (std::vector< int > *undone_mapping_src) |
| Undoes the last AddMappings() operation, and fills the "undone_mapping_src" vector with the src of that last operation. More... | |
| void | Reset () |
| Makes the permutation back to the identity (i.e. More... | |
| int | ImageOf (int i) const |
| Forced-inline for the speed. More... | |
| const std::vector< int > & | AllMappingsSrc () const |
| Returns the union of all "src" ever given to AddMappings(). More... | |
| int | RootOf (int i) const |
| While the permutation is partially being built, the orbit of elements will either form unclosed paths, or closed cycles. More... | |
| const std::set< int > & | LooseEnds () const |
| The exhaustive set of the 'loose end' of the incomplete cycles (e.g., paths) built so far. More... | |
| std::unique_ptr< SparsePermutation > | CreateSparsePermutation () const |
| Creates a SparsePermutation representing the current permutation. More... | |
| std::string | DebugString () const |
Maintains a 'partial' permutation of [0..n-1] onto itself, with a dynamic API allowing it to be built incrementally, and allowing some backtracking.
This is tuned for a specific usage by ./find_graph_symmetries.cc.
RAM usage: as of 2014-04, this class needs less than: 32.125 * (n + 2 * support_size) bytes.
Definition at line 33 of file dynamic_permutation.h.
|
explicit |
Upon construction, every element i in [0..n-1] maps to itself.
| void operations_research::DynamicPermutation::AddMappings | ( | const std::vector< int > & | src, |
| const std::vector< int > & | dst | ||
| ) |
Declares a set of mappings for this permutation: src[i] will map to dst[i].
Requirements that are DCHECKed:
Complexity: amortized O(src.size()).
|
inline |
Returns the union of all "src" ever given to AddMappings().
Definition at line 67 of file dynamic_permutation.h.
| std::unique_ptr<SparsePermutation> operations_research::DynamicPermutation::CreateSparsePermutation | ( | ) | const |
Creates a SparsePermutation representing the current permutation.
Requirements: the permutation must only have cycles.
Complexity: O(support size).
| std::string operations_research::DynamicPermutation::DebugString | ( | ) | const |
|
inline |
Forced-inline for the speed.
Definition at line 114 of file dynamic_permutation.h.
|
inline |
The exhaustive set of the 'loose end' of the incomplete cycles (e.g., paths) built so far.
Definition at line 83 of file dynamic_permutation.h.
| void operations_research::DynamicPermutation::Reset | ( | ) |
Makes the permutation back to the identity (i.e.
like right after construction). Complexity: O(support size).
|
inline |
While the permutation is partially being built, the orbit of elements will either form unclosed paths, or closed cycles.
Forced-inline for the speed.
In the former case, RootOf(i) returns the start of the path where i lies. If i is on a cycle, RootOf(i) will return some element of its cycle (meaning that if i maps to itself, RootOf(i) = i).
Complexity: O(log(orbit size)) in average, assuming that the mappings are added in a random order. O(orbit size) in the worst case.
Definition at line 121 of file dynamic_permutation.h.
|
inline |
Definition at line 38 of file dynamic_permutation.h.
| void operations_research::DynamicPermutation::UndoLastMappings | ( | std::vector< int > * | undone_mapping_src | ) |
Undoes the last AddMappings() operation, and fills the "undone_mapping_src" vector with the src of that last operation.
This works like an undo stack. For example, applying the sequence (Add, Add, Add, Undo, Add, Undo, Undo) has exactly the same effect as applying the first Add() alone. If you call this too may times (i.e. there is nothing left to undo), it is simply a no-op.
Complexity: same as the AddMappings() operation being undone.