LAL: Linear Arrangement Library 23.01.00
A library focused on algorithms on linear arrangements of graphs.
|
Uniformly random generation of unlabelled rooted trees. More...
#include <rand_ulab_rooted_trees.hpp>
Public Member Functions | |
_rand_ulab_rooted_trees () noexcept | |
Empty constructor. | |
_rand_ulab_rooted_trees (uint64_t n, uint64_t seed=0) noexcept | |
Constructor with size of tree and seed for the random number generator. More... | |
_rand_ulab_rooted_trees (const _rand_ulab_rooted_trees &Gen)=default | |
Copy constructor. More... | |
_rand_ulab_rooted_trees (_rand_ulab_rooted_trees &&Gen)=default | |
Move constructor. More... | |
virtual | ~_rand_ulab_rooted_trees ()=default |
Destructor. | |
_rand_ulab_rooted_trees & | operator= (const _rand_ulab_rooted_trees &g) noexcept=default |
Copy assignment operator. | |
_rand_ulab_rooted_trees & | operator= (_rand_ulab_rooted_trees &&g) noexcept=default |
Move assignment operator. | |
void | init (uint64_t n, uint64_t seed=0) noexcept |
Sets the size of the unlabelled trees to generate. More... | |
void | clear () noexcept |
Clears the memory used. More... | |
graphs::rooted_tree | get_tree () noexcept |
Generates uniformly at random a free unlabelled tree. More... | |
Protected Member Functions | |
std::pair< uint64_t, uint64_t > | ranrut (uint64_t n, uint64_t lr, uint64_t nt) noexcept |
Generates uniformly at random a rooted unlabelled tree of n nodes. More... | |
void | init_rn () noexcept |
Initialiases m_rn with values from the OEIS (see [36]). | |
const numeric::integer & | get_rn (uint64_t n) noexcept |
Computes all the values \(t_i\) for \(i \in [1,n]\). More... | |
std::pair< uint64_t, uint64_t > | choose_jd_from_T (uint64_t n) noexcept |
Chooses uniformly at random a pair \((j,d)\), according to some probability. More... | |
Protected Attributes | |
uint64_t | m_n |
Number of nodes of the tree. | |
std::mt19937 | m_gen |
Random number generator. | |
std::uniform_real_distribution< double > | m_unif |
Distribution of the numbers. | |
std::vector< numeric::integer > | m_rn |
The number of unlabelled rooted trees. More... | |
detail::data_array< uint64_t > | m_head_vector |
The head vector of the tree under construction. More... | |
Uniformly random generation of unlabelled rooted trees.
Users should refrain from using this class. The generation of random labelled trees should be done using the wrapper class rand_ulab_rooted_trees. This class, however, contains the actual code to generate labelled rooted trees uniformly at random.
Every call to get_tree generates rooted unlabelled trees uniformly at random using the ranrut procedure (see [30], chapter 29).
|
inlinenoexcept |
Constructor with size of tree and seed for the random number generator.
In case the seed given is '0', a random seed will be generated.
n | Number of nodes. |
seed | The seed used for the random number generator. If the seed is 0 then a random seed is generated and used. |
|
default |
Copy constructor.
Gen | Random unlabelled rooted tree generator. |
|
default |
Move constructor.
Gen | Random unlabelled rooted tree generator. |
|
protectednoexcept |
Chooses uniformly at random a pair \((j,d)\), according to some probability.
Probability of choosing \((j,d)\) is: \(\frac{d \cdot t_{k - jd} \cdot t_d}{(k - 1)t_k}\).
n | Number of nodes. |
|
inlinenoexcept |
Clears the memory used.
In order to save computation time, this class has been designed to reuse memory when generating trees. For example, since it needs the values of well-known integer sequences (see attribute m_rn) that are costly to compute every time they are needed, they are stored in memory and reused over time.
So, if the user wants to generate trees of 1000 nodes there will be too much memory occupied (and unused) if then this class is used to generate trees of 10 nodes. In cases like this it is recommended to clear the memory occupied.
|
protectednoexcept |
Computes all the values \(t_i\) for \(i \in [1,n]\).
Here \(n\) is m_n. In case these values have already been calculated, this method does nothing.
|
noexcept |
Generates uniformly at random a free unlabelled tree.
|
inlinenoexcept |
Sets the size of the unlabelled trees to generate.
Adds the remaining necessary values to m_rn..
Initialises the random number generator with seed. When seed is 0, a random seed is used.
n | Number of vertices. |
seed | Integer value used to seed the random number generator. |
|
protectednoexcept |
Generates uniformly at random a rooted unlabelled tree of n nodes.
The first call to this method should have lr = m_n + 1.
n | Number of nodes of the rooted tree to generate. |
lr | Pointer to the root of the last tree added. m_head_vector[lr] is the node that the root points to. |
nt | Index to m_head_vector where we have to place the new tree. |
|
protected |
The head vector of the tree under construction.
This list has n values for m_n nodes. The first position contains the root vertex.
Do not use its actual type (lal::head_vector) in an attempt to make memory usage a bit more efficient.
|
protected |
The number of unlabelled rooted trees.
Contains \(r_n\) for \(n\ge 0\).