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

Generation of permutations. More...

Topics

 Permutation generators
 Defines a set of permutations, subject to restrictions.
 Permutation instances
 Instance of a permutation.

Detailed Description

Generation of permutations.

Examples

// Prints a random 1-based permutation of size 10 that start with 2.
std::cout <<
tgen::permutation(10).set(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).gen({5}) << 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"
instance gen() const
Generates a random instance from the set of valid permutations.
Definition tgen.h:1213
instance gen_until(Pred predicate, int max_tries, Args &&... args) const
Generates a random instance from the set of valid permutations until a condition is met.
permutation & set(int idx, int value)
Restricts generator s.t. value at index is fixed.
Definition tgen.h:1112
instance & add_1()
Adds 1 for printing.
Definition tgen.h:1191
Permutation generator.
Definition tgen.h:1102