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.

Its values have the properties:

Examples

// Prints a random 1-based permutation of size 10 that start with 2.
std::cout << tgen::permutation(10).fix(0, 1).gen().add_1() << std::endl;
// "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;
// "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;
// "4 2 3 1 0"
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:341
value & add_1()
Adds 1 for printing.
Definition tgen.h:1842
Permutation generator.
Definition tgen.h:1725
value gen() const
Generates a random value from the set of valid permutations.
Definition tgen.h:1863
permutation & cycles(const std::vector< int > &cycle_sizes)
Restricts generator s.t. cycle sizes are fixed.
Definition tgen.h:1744
permutation & fix(int idx, int val)
Restricts generator s.t. value at index is fixed.
Definition tgen.h:1736