Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <sparse_permutation.h>
Classes | |
struct | Iterator |
Public Member Functions | |
SparsePermutation (int size) | |
int | Size () const |
int | NumCycles () const |
const std::vector< int > & | Support () const |
Iterator | Cycle (int i) const |
int | LastElementInCycle (int i) const |
void | AddToCurrentCycle (int x) |
void | CloseCurrentCycle () |
void | RemoveCycles (absl::Span< const int > cycle_indices) |
std::string | DebugString () const |
A compact representation for permutations of {0..N-1} that displaces few elements: it needs only O(K) memory for a permutation that displaces K elements.
Definition at line 28 of file sparse_permutation.h.
|
inlineexplicit |
Definition at line 30 of file sparse_permutation.h.
|
inline |
To add a cycle to the permutation, repeatedly call AddToCurrentCycle() with the cycle's orbit, then call CloseCurrentCycle(); This shouldn't be called on trivial cycles (of length 1).
Definition at line 85 of file sparse_permutation.h.
|
inline |
Definition at line 91 of file sparse_permutation.h.
|
inline |
Definition at line 118 of file sparse_permutation.h.
std::string operations_research::SparsePermutation::DebugString | ( | ) | const |
Output all non-identity cycles of the permutation, sorted lexicographically (each cycle is described starting by its smallest element; and all cycles are sorted lexicographically against each other). This isn't efficient; use for debugging only. Example: "(1 4 3) (5 9) (6 8 7)".
Find the minimum.
Definition at line 56 of file sparse_permutation.cc.
|
inline |
This is useful for iterating over the pair {element, image} of a permutation:
for (int c = 0; c < perm.NumCycles(); ++c) { int element = LastElementInCycle(c); for (int image : perm.Cycle(c)) { ///< The pair is (element, image). ... element = image; } }
Definition at line 125 of file sparse_permutation.h.
|
inline |
Definition at line 34 of file sparse_permutation.h.
void operations_research::SparsePermutation::RemoveCycles | ( | absl::Span< const int > | cycle_indices | ) |
Removes the cycles with given indices from the permutation. This works in O(K) for a permutation displacing K elements.
Definition at line 27 of file sparse_permutation.cc.
|
inline |
Definition at line 33 of file sparse_permutation.h.
|
inline |
Returns the "support" of this permutation; that is, the set of elements displaced by it.
Definition at line 38 of file sparse_permutation.h.