tgen
Loading...
Searching...
No Matches

Sequence generator. More...

Inheritance diagram for tgen::sequence< T >:

Classes

struct  instance
 Sequence instance. More...

Public Member Functions

 sequence (int size, T value_l, T value_r)
 Creates sequence generator define by size and range of values.
 sequence (int size, std::set< T > values)
 Creates sequence generator define by value set.
sequencefix (int idx, T value)
 Restricts generator s.t. value at index is fixed.
sequenceequal (int idx_1, int idx_2)
 Restricts generator s.t. values at two indices are the same.
sequenceequal_range (int left, int right)
 Restricts generator s.t. all values at index range are the same.
sequencedistinct (std::set< int > indices)
 Restricts generator s.t. all values in index set are distinct.
sequencedifferent (int idx_1, int idx_2)
 Restricts generator s.t. values at two indices are different.
sequencedistinct ()
 Restricts generator s.t. all values are distinct.
instance gen () const
 Generates a random instance from the set of valid sequences.
Public Member Functions inherited from tgen::gen_base< sequence< T > >
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

template<typename T>
struct tgen::sequence< T >

Sequence generator.

Defines a set of sequences, subject to restrictions.

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

Definition at line 1135 of file tgen.h.

Constructor & Destructor Documentation

◆ sequence() [1/2]

template<typename T>
tgen::sequence< T >::sequence ( int size,
T value_l,
T value_r )
inline

Creates sequence generator define by size and range of values.

Parameters
sizeSize of the sequence.
value_lLeft endpoint of value range.
value_rRight endpoint of value range.

Defines a generator of sequences of length size with values in [value_l, value_r].

Examples

// Sequences of 10 ints from 1 to 100.
auto seq_gen = tgen::sequence<int>(10, 1, 100);
Sequence generator.
Definition tgen.h:1135

Definition at line 1149 of file tgen.h.

◆ sequence() [2/2]

template<typename T>
tgen::sequence< T >::sequence ( int size,
std::set< T > values )
inline

Creates sequence generator define by value set.

Parameters
sizeSize of the sequence.
valuesValue set.

Defines a generator of sequences of length size with values in values.

Examples

// Sequences of 10 ints that are either 3, 6, or 9.
auto seq_gen = tgen::sequence<int>(10, {3, 6, 9});

Definition at line 1159 of file tgen.h.

Member Function Documentation

◆ different()

template<typename T>
sequence & tgen::sequence< T >::different ( int idx_1,
int idx_2 )
inline

Restricts generator s.t. values at two indices are different.

Parameters
idx_1First index.
idx_2Second index.

Equivalent to tgen::sequence::distinct({idx_1, idx_2}).

Examples

// Sequences of 10 ints from 1 to 5 with the first and last values different.
auto seq_gen = tgen::sequence<int>(10, 1, 5).different(0, 9);
sequence & different(int idx_1, int idx_2)
Restricts generator s.t. values at two indices are different.
Definition tgen.h:1228

Definition at line 1228 of file tgen.h.

◆ distinct() [1/2]

template<typename T>
sequence & tgen::sequence< T >::distinct ( )
inline

Restricts generator s.t. all values are distinct.

Equivalent to tgen::sequence::distinct({0, 1, ... size-1}).

Note
If you add this restriction, do not add another tgen::sequence::distinct restriction! Generation might fail otherwise.

Examples

// Sequences of 5 distinct ints from 1 to 5.
auto seq_gen = tgen::sequence<int>(5, 1, 5).distinct();
sequence & distinct(std::set< int > indices)
Restricts generator s.t. all values in index set are distinct.
Definition tgen.h:1221

Definition at line 1234 of file tgen.h.

◆ distinct() [2/2]

template<typename T>
sequence & tgen::sequence< T >::distinct ( std::set< int > indices)
inline

Restricts generator s.t. all values in index set are distinct.

Parameters
indicesIndex set.
Note
Generation might fail if restrictions are considered to be too complex! The restrictions are considered too complex if the following condition does not hold. Consider the graph defined with vertices as the tgen::sequence::distinct sets added, and there is an edge between two vertices if they share an index. Note that you need to consider indices (directed or indirectly) connected by equality restrictions as being the same. This resulting graph must be a acyclic. Moreover, for every tree in this graph, all of its indices with a tgen::sequence::set operation must be covered by a single distinct restriction set.
Exceptions
std::runtime_errorif generation fails.

Examples

// Sequences of 10 ints from 1 to 5 with the first half distinct.
auto seq_gen = tgen::sequence<int>(10, 1, 5).distinct({0, 1, 2, 3, 4});

Definition at line 1221 of file tgen.h.

◆ equal()

template<typename T>
sequence & tgen::sequence< T >::equal ( int idx_1,
int idx_2 )
inline

Restricts generator s.t. values at two indices are the same.

Parameters
idx_1First index.
idx_2Second index.

Examples

// Sequences of 10 ints from 1 to 5 that start and end with the same value.
auto seq_gen = tgen::sequence<int>(10, 1, 5).equal(0, 9);
sequence & equal(int idx_1, int idx_2)
Restricts generator s.t. values at two indices are the same.
Definition tgen.h:1197

Definition at line 1197 of file tgen.h.

◆ equal_range()

template<typename T>
sequence & tgen::sequence< T >::equal_range ( int left,
int right )
inline

Restricts generator s.t. all values at index range are the same.

Parameters
leftLeft endpoint of index range (inclusive).
rightRight endpoint of index range (inclusive).

Examples

// Sequences of 10 ints from 1 to 5 with the first half all equal.
auto seq_gen = tgen::sequence<int>(10, 1, 5).equal_range(0, 4);
sequence & equal_range(int left, int right)
Restricts generator s.t. all values at index range are the same.
Definition tgen.h:1210

Definition at line 1210 of file tgen.h.

◆ fix()

template<typename T>
sequence & tgen::sequence< T >::fix ( int idx,
T value )
inline

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

Parameters
idxIndex.
valueValue.
Exceptions
std::runtime_errorif value is not in the value range/set.

Examples

// Sequences of 10 ints from 1 to 5 that start with 1.
auto seq_gen = tgen::sequence<int>(10, 1, 5).fix(0, 1);
sequence & fix(int idx, T value)
Restricts generator s.t. value at index is fixed.
Definition tgen.h:1172

Definition at line 1172 of file tgen.h.

◆ gen()

template<typename T>
instance tgen::sequence< T >::gen ( ) const
inline

Generates a random instance from the set of valid sequences.

Returns
A uniformly random tgen::sequence::instance from the set of valid sequences, given the added restrictions.
Exceptions
std::runtime_errorif there is no valid sequence satisfying all added restrictions, or if the added restrictions are considered to be too complex (see tgen::sequence::distinct).

Complexity

O(n log n).

Examples

// Generates and prints a random sequence of 5 ints from 1 to 5.
auto inst = tgen::sequence<int>(5, 1, 5).gen();
std::cout << inst << std::endl;
instance gen() const
Generates a random instance from the set of valid sequences.
Definition tgen.h:1367

Definition at line 1367 of file tgen.h.


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