tgen
Loading...
Searching...
No Matches

Permutation generator. More...

Inheritance diagram for tgen::permutation:

Classes

struct  instance
 Permutation instance. More...

Public Member Functions

 permutation (int size)
 Creates permutation generator defined by size.
permutationfix (int idx, int value)
 Restricts generator s.t. value at index is fixed.
permutationcycles (const std::vector< int > &cycle_sizes)
 Restricts generator s.t. cycle sizes are fixed.
instance gen () const
 Generates a random instance 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 instance from the valid set until a condition is met.
auto unique (Args &&...args) const
 Creates unique generator for current generator.

Detailed Description

Permutation generator.

Defines a set of permutations, subject to restrictions.

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

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

Definition at line 1648 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();
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

Definition at line 1661 of file tgen.h.

◆ fix()

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

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

Parameters
idxIndex.
valueValue.

Examples

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

Definition at line 1653 of file tgen.h.

◆ gen()

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

Generates a random instance from the set of valid permutations.

Returns
A uniformly random tgen::permutation::instance 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 1783 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