1#ifndef ROUTING_KIT_PERMUTATION_H
2#define ROUTING_KIT_PERMUTATION_H
20 std::vector<bool>found(p.size(),
false);
35 assert(p.size() == q.size() &&
"p and q must permute the same number of objects");
36 std::vector<unsigned>r(p.size());
37 for(
unsigned i=0; i<r.size(); ++i)
50 assert(p.size() == v.size() &&
"permutation and vector must have the same size");
52 std::vector<T>r(v.size());
53 for(
unsigned i = 0; i<v.size(); ++i)
62 assert(p.size() == v.size() &&
"permutation and vector must have the same size");
64 std::vector<T>r(v.size());
65 for(
unsigned i = 0; i<v.size(); ++i)
66 r[i] = std::move(v[p[i]]);
74 assert(p.size() == v.size() &&
"permutation and vector must have the same size");
76 std::vector<T>r(v.size());
77 for(
unsigned i = 0; i<v.size(); ++i)
86 assert(p.size() == v.size() &&
"permutation and vector must have the same size");
88 std::vector<T>r(v.size());
89 for(
unsigned i = 0; i<v.size(); ++i)
90 r[p[i]] = std::move(v[i]);
98 assert(std::all_of(v.begin(), v.end(), [&](
unsigned x){return x < p.size();}) &&
"v has an out of bounds element");
100 for(
unsigned i=0; i<v.size(); ++i)
107 assert(std::all_of(v.begin(), v.end(), [&](
unsigned x){return x < p.size();}) &&
"v has an out of bounds element");
109 std::vector<unsigned> r = v;
118 assert(std::all_of(v.begin(), v.end(), [&](
unsigned x){return x < p.size() || x == invalid_id;}) &&
"v has an out of bounds element");
120 for(
unsigned i=0; i<v.size(); ++i)
128 assert(std::all_of(v.begin(), v.end(), [&](
unsigned x){return x < p.size() || x == invalid_id;}) &&
"v has an out of bounds element");
130 std::vector<unsigned> r = v;
140 std::vector<unsigned> inv_p(p.size());
141 for(
unsigned i=0; i<p.size(); ++i)
149 std::vector<unsigned> p(n);
150 for(
unsigned i=0; i<n; ++i)
155template<
class RandomGenerator>
158 std::shuffle(r.begin(), r.end(), std::forward<RandomGenerator>(gen));
std::vector< unsigned > chain_permutation_first_left_then_right(const std::vector< unsigned > &p, const std::vector< unsigned > &q)
std::vector< unsigned > chain_permutation_first_right_then_left(const std::vector< unsigned > &p, const std::vector< unsigned > &q)
void inplace_apply_permutation_to_elements_of(const std::vector< unsigned > &p, std::vector< unsigned > &v)
std::vector< T > apply_permutation(const std::vector< unsigned > &p, const std::vector< T > &v)
std::vector< T > apply_inverse_permutation(const std::vector< unsigned > &p, const std::vector< T > &v)
std::vector< unsigned > random_permutation(unsigned n, RandomGenerator &&gen)
std::vector< unsigned > apply_permutation_to_possibly_invalid_elements_of(const std::vector< unsigned > &p, const std::vector< unsigned > &v)
std::vector< unsigned > invert_permutation(const std::vector< unsigned > &p)
bool is_permutation(const std::vector< unsigned > &p)
std::vector< unsigned > apply_permutation_to_elements_of(const std::vector< unsigned > &p, const std::vector< unsigned > &v)
std::vector< unsigned > identity_permutation(unsigned n)
const unsigned invalid_id
void inplace_apply_permutation_to_possibly_invalid_elements_of(const std::vector< unsigned > &p, std::vector< unsigned > &v)