← comparison
tgen
Loading...
Searching...
No Matches
Permutations

Generation of permutations. More...

Classes

struct  tgen::permutation
 Permutation generator. More...
struct  tgen::permutation::value
 Permutation value. More...

Detailed Description

Generation of permutations.

Examples

Prints a random 1-based permutation of size 10 that starts with 2.

std::cout << tgen::permutation(10).fix(0, 1).gen().add_1() << std::endl;
value & add_1()
Adds 1 for printing.
Definition tgen.h:2312
Permutation generator.
Definition tgen.h:2195
value gen() const
Generates a uniformly random value from the set of valid permutations.
Definition tgen.h:2359
permutation & fix(int idx, int val)
Restricts generator s.t. value at index is fixed.
Definition tgen.h:2206
2 7 10 4 3 9 1 5 8 6

Prints a random permutation of size 5 with only one cycle.

std::cout << tgen::permutation(5).cycles({5}).gen() << std::endl;
permutation & cycles(const std::vector< int > &cycle_sizes)
Restricts generator s.t. cycle sizes are fixed.
Definition tgen.h:2214
1 4 3 0 2

Prints the inverse of a random odd permutation of size 5.

std::cout <<
.gen_until([](const auto &perm) { return perm.parity() == -1; }, 100)
.inverse()
<< std::endl;
auto gen_until(Pred predicate, int max_tries, Args &&...args) const
Generates a random value from the valid set until a condition is met.
Definition tgen.h:421
4 2 3 1 0