tgen
Loading...
Searching...
No Matches
Permutations

Generation of permutations. More...

Classes

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

Detailed Description

Generation of permutations.

Its instances 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 instance from the valid set until a condition is met.
Definition tgen.h:335
instance & add_1()
Adds 1 for printing.
Definition tgen.h:1761
Permutation generator.
Definition tgen.h:1642
permutation & cycles(const std::vector< int > &cycle_sizes)
Restricts generator s.t. cycle sizes are fixed.
Definition tgen.h:1661
instance gen() const
Generates a random instance from the set of valid permutations.
Definition tgen.h:1783
permutation & fix(int idx, int value)
Restricts generator s.t. value at index is fixed.
Definition tgen.h:1653