14 #ifndef OR_TOOLS_ALGORITHMS_SPARSE_PERMUTATION_H_ 15 #define OR_TOOLS_ALGORITHMS_SPARSE_PERMUTATION_H_ 20 #include "ortools/base/logging.h" 32 int Size()
const {
return size_; }
33 int NumCycles()
const {
return cycle_ends_.size(); }
37 const std::vector<int>&
Support()
const {
return cycles_; }
43 Iterator
Cycle(
int i)
const;
69 void RemoveCycles(
const std::vector<int>& cycle_indices);
80 std::vector<int> cycles_;
81 std::vector<int> cycle_ends_;
91 if (cycle_ends_.empty()) {
92 DCHECK_GE(cycles_.size(), 2);
94 DCHECK_GE(cycles_.size(), cycle_ends_.back() + 2);
96 cycle_ends_.push_back(cycles_.size());
105 Iterator(
const std::vector<int>::const_iterator& b,
106 const std::vector<int>::const_iterator& e)
110 std::vector<int>::const_iterator
end()
const {
return end_; }
111 const std::vector<int>::const_iterator
begin_;
112 const std::vector<int>::const_iterator
end_;
120 return Iterator(cycles_.begin() + (i == 0 ? 0 : cycle_ends_[i - 1]),
121 cycles_.begin() + cycle_ends_[i]);
126 DCHECK_LT(i, cycle_ends_.size());
127 DCHECK_GT(cycle_ends_[i], i == 0 ? 0 : cycle_ends_[i - 1]);
128 return cycles_[cycle_ends_[i] - 1];
133 #endif // OR_TOOLS_ALGORITHMS_SPARSE_PERMUTATION_H_
Iterator Cycle(int i) const
void RemoveCycles(const std::vector< int > &cycle_indices)
Removes the cycles with given indices from the permutation.
int value_type
These typedefs allow this iterator to be used within testing::ElementsAre.
std::vector< int >::const_iterator begin() const
std::string DebugString() const
Output all non-identity cycles of the permutation, sorted lexicographically (each cycle is described ...
Iterator(const std::vector< int >::const_iterator &b, const std::vector< int >::const_iterator &e)
std::vector< int >::const_iterator const_iterator
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
const std::vector< int >::const_iterator end_
int LastElementInCycle(int i) const
This is useful for iterating over the pair {element, image} of a permutation:
const std::vector< int > & Support() const
Returns the "support" of this permutation; that is, the set of elements displaced by it.
std::vector< int >::const_iterator end() const
void AddToCurrentCycle(int x)
To add a cycle to the permutation, repeatedly call AddToCurrentCycle() with the cycle's orbit,...
const std::vector< int >::const_iterator begin_
A compact representation for permutations of {0..N-1} that displaces few elements: it needs only O(K)...
SparsePermutation(int size)