14 #ifndef OR_TOOLS_ALGORITHMS_DYNAMIC_PERMUTATION_H_ 15 #define OR_TOOLS_ALGORITHMS_DYNAMIC_PERMUTATION_H_ 21 #include "ortools/base/logging.h" 25 class SparsePermutation;
38 int Size()
const {
return image_.size(); }
47 void AddMappings(
const std::vector<int>& src,
const std::vector<int>& dst);
67 const std::vector<int>&
AllMappingsSrc()
const {
return mapping_src_stack_; }
83 const std::set<int>&
LooseEnds()
const {
return loose_ends_; }
94 std::vector<int> image_;
97 std::vector<int> ancestor_;
102 std::vector<int> mapping_src_stack_;
103 std::vector<int> mapping_src_size_stack_;
106 std::set<int> loose_ends_;
110 mutable std::vector<bool> tmp_mask_;
116 DCHECK_LT(i,
Size());
123 DCHECK_LT(i,
Size());
125 const int j = ancestor_[i];
126 if (j == i)
return i;
133 #endif // OR_TOOLS_ALGORITHMS_DYNAMIC_PERMUTATION_H_ const std::vector< int > & AllMappingsSrc() const
Returns the union of all "src" ever given to AddMappings().
Maintains a 'partial' permutation of [0..n-1] onto itself, with a dynamic API allowing it to be built...
std::unique_ptr< SparsePermutation > CreateSparsePermutation() const
Creates a SparsePermutation representing the current permutation.
void Reset()
Makes the permutation back to the identity (i.e.
std::string DebugString() const
int ImageOf(int i) const
Forced-inline for the speed.
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].
DynamicPermutation(int n)
Upon construction, every element i in [0..n-1] maps to itself.
int RootOf(int i) const
While the permutation is partially being built, the orbit of elements will either form unclosed paths...
void UndoLastMappings(std::vector< int > *undone_mapping_src)
Undoes the last AddMappings() operation, and fills the "undone_mapping_src" vector with the src of th...
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
const std::set< int > & LooseEnds() const
The exhaustive set of the 'loose end' of the incomplete cycles (e.g., paths) built so far.