tgen 1.4.0
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.
permutation & fix (int idx, int val)
 Restricts generator s.t. value at index is fixed.
permutation & cycles (const std::vector< int > &cycle_sizes)
 Restricts generator s.t. cycle sizes are fixed.
value gen () const
 Generates a uniformly 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 2210 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:2210

Definition at line 2216 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 permutation 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 uniformly random value from the set of valid permutations.
Definition tgen.h:2385
permutation & cycles(const std::vector< int > &cycle_sizes)
Restricts generator s.t. cycle sizes are fixed.
Definition tgen.h:2229

Definition at line 2229 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:2221

Definition at line 2221 of file tgen.h.

◆ gen()

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

Generates a uniformly 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.

Time complexity

O(n).

Examples

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

Definition at line 2385 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