tgen
Loading...
Searching...
No Matches

Permutation generator. More...

Inheritance diagram for tgen::permutation:

Classes

struct  value
 Permutation value. More...

Public Member Functions

 permutation (int size)
 Creates permutation generator defined by size.
permutationfix (int idx, int val)
 Restricts generator s.t. value at index is fixed.
permutationcycles (const std::vector< int > &cycle_sizes)
 Restricts generator s.t. cycle sizes are fixed.
value gen () const
 Generates a random value from the set of valid permutations.
Public Member Functions inherited from tgen::gen_base< permutation >
auto gen_list (int size, Args &&...args) const
 Generates a list of several generation calls.
auto gen_until (Pred predicate, int max_tries, Args &&...args) const
 Generates a random value from the valid set until a condition is met.
auto distinct (Args &&...args) const
 Creates distinct generator for current generator.

Detailed Description

Permutation generator.

Defines a set of permutations, subject to restrictions.

A uniformly random tgen::permutation::value from this set of permutations (that satisfies the restrictions) can be generated with tgen::permutation::gen.

Definition at line 1725 of file tgen.h.

Constructor & Destructor Documentation

◆ permutation()

tgen::permutation::permutation ( int size)
inline

Creates permutation generator defined by size.

Parameters
sizeSize of the permutation.

Examples

// Permutations of size 10.
auto perm_gen = tgen::permutation(10);
Permutation generator.
Definition tgen.h:1725

Definition at line 1731 of file tgen.h.

Member Function Documentation

◆ cycles()

permutation & tgen::permutation::cycles ( const std::vector< int > & cycle_sizes)
inline

Restricts generator s.t. cycle sizes are fixed.

Parameters
cycle_sizesSizes of cycles.

The sizes of cycles of the generated permuttion will be cycle_sizes.

Examples

// Permutations of size 5 with only one cycle.
auto perm_gen = tgen::permutation(5).cycles({5}).gen();
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

Definition at line 1744 of file tgen.h.

◆ fix()

permutation & tgen::permutation::fix ( int idx,
int val )
inline

Restricts generator s.t. value at index is fixed.

Parameters
idxIndex.
valValue.

Examples

// Permutations of size 10 that start with 1.
auto perm_gen = tgen::permutation(10).fix(0, 1);
permutation & fix(int idx, int val)
Restricts generator s.t. value at index is fixed.
Definition tgen.h:1736

Definition at line 1736 of file tgen.h.

◆ gen()

value tgen::permutation::gen ( ) const
inline

Generates a random value from the set of valid permutations.

Returns
A uniformly random tgen::permutation::value from the set of valid permutations, given the added restrictions.
Exceptions
std::runtime_errorif there is no valid permutation satisfying all added restrictions.

Complexity

O(n).

Examples

// Generates and prints a random permutation of size 5.
auto inst = tgen::permutation(5).gen();
std::cout << inst << std::endl;

Definition at line 1863 of file tgen.h.


The documentation for this struct was generated from the following files:
  • /home/runner/work/tgen/tgen/single_include/tgen.h
  • permutation.dox