LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
rand_lab_rooted_trees.hpp
1/*********************************************************************
2 *
3 * Linear Arrangement Library - A library that implements a collection
4 * algorithms for linear arrangments of graphs.
5 *
6 * Copyright (C) 2019 - 2024
7 *
8 * This file is part of Linear Arrangement Library. The full code is available
9 * at:
10 * https://github.com/LAL-project/linear-arrangement-library.git
11 *
12 * Linear Arrangement Library is free software: you can redistribute it
13 * and/or modify it under the terms of the GNU Affero General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * Linear Arrangement Library is distributed in the hope that it will be
18 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
21 *
22 * You should have received a copy of the GNU Affero General Public License
23 * along with Linear Arrangement Library. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * Contact:
26 *
27 * LluĂ­s Alemany Puig (lluis.alemany.puig@upc.edu)
28 * LQMC (Quantitative, Mathematical, and Computational Linguisitcs)
29 * CQL (Complexity and Quantitative Linguistics Lab)
30 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
31 * Webpage: https://cqllab.upc.edu/people/lalemany/
32 *
33 * Ramon Ferrer i Cancho (rferrericancho@cs.upc.edu)
34 * LQMC (Quantitative, Mathematical, and Computational Linguisitcs)
35 * CQL (Complexity and Quantitative Linguistics Lab)
36 * Office 220, Omega building
37 * Jordi Girona St 1-3, Campus Nord UPC, 08034 Barcelona. CATALONIA, SPAIN
38 * Webpage: https://cqllab.upc.edu/people/rferrericancho/
39 *
40 ********************************************************************/
41
42#pragma once
43
44// C++ includes
45#include <random>
46
47// lal includes
48#include <lal/graphs/rooted_tree.hpp>
49#include <lal/generate/rand_lab_free_trees.hpp>
50
51namespace lal {
52namespace generate {
53
68public:
69 /* CONSTRUCTORS */
70
73
81 _rand_lab_rooted_trees(const uint64_t n, const uint64_t seed = 0) noexcept
82 : _rand_lab_free_trees(n, seed) { }
87 _rand_lab_rooted_trees(const _rand_lab_rooted_trees& Gen) noexcept = default;
88
94
97
102
103 /* INITIALIZE */
104
111 void init(const uint64_t n, const uint64_t seed = 0) noexcept {
113 }
114
115 /* GETTERS */
116
122 [[nodiscard]] graphs::rooted_tree get_tree() noexcept {
124 const node r = m_unif(m_gen);
125 return graphs::rooted_tree(t, r);
126 }
127};
128
153class rand_lab_rooted_trees : public _tree_generator<graphs::rooted_tree> {
154public:
155 /* CONSTRUCTORS */
156
158 rand_lab_rooted_trees() noexcept : _tree_generator<graphs::rooted_tree>() { }
159
168 rand_lab_rooted_trees(const uint64_t n, const uint64_t seed = 0) noexcept :
169 _tree_generator<graphs::rooted_tree>(n), m_Gen(n, seed) { }
175
181
184
189
196 void init(const uint64_t n, const uint64_t seed = 0) noexcept {
198 m_Gen.init(n, seed);
199 }
200
202 void clear() noexcept {
204 m_Gen.clear();
205 }
206
207 [[nodiscard]] graphs::rooted_tree yield_tree() noexcept {
208 return get_tree();
209 }
210
211protected:
218 [[nodiscard]] graphs::rooted_tree __get_tree() noexcept { return m_Gen.get_tree(); }
219
220protected:
223};
224
225} // -- namespace generate
226} // -- namespace lal
Uniformly random selection of labelled free trees.
Definition rand_lab_free_trees.hpp:68
void init(const uint64_t n, const uint64_t seed=0) noexcept
Initializes the generator with the number of nodes and a seed.
Definition rand_lab_free_trees.hpp:115
graphs::free_tree get_tree() noexcept
Returns a labelled free tree chosen uniformly at random.
void clear() noexcept
Clears the memory used.
Definition rand_lab_free_trees.hpp:133
std::uniform_int_distribution< uint64_t > m_unif
Distribution of the numbers.
Definition rand_lab_free_trees.hpp:149
std::mt19937 m_gen
Random number generator.
Definition rand_lab_free_trees.hpp:147
Uniformly random selection of labelled rooted trees.
Definition rand_lab_rooted_trees.hpp:67
void init(const uint64_t n, const uint64_t seed=0) noexcept
Initializes the generator with the number of nodes and a seed.
Definition rand_lab_rooted_trees.hpp:111
_rand_lab_rooted_trees(const _rand_lab_rooted_trees &Gen) noexcept=default
Copy constructor.
_rand_lab_rooted_trees() noexcept
Empty constructor.
Definition rand_lab_rooted_trees.hpp:72
~_rand_lab_rooted_trees()=default
Default destructor.
_rand_lab_rooted_trees(_rand_lab_rooted_trees &&Gen) noexcept=default
Move constructor.
_rand_lab_rooted_trees(const uint64_t n, const uint64_t seed=0) noexcept
Constructor with size of tree and seed for the random number generator.
Definition rand_lab_rooted_trees.hpp:81
_rand_lab_rooted_trees & operator=(const _rand_lab_rooted_trees &g) noexcept=default
Copy assignment operator.
graphs::rooted_tree get_tree() noexcept
Generates uniformly at random a labelled rooted tree.
Definition rand_lab_rooted_trees.hpp:122
Base class for tree generators.
Definition tree_generator.hpp:123
void clear() noexcept
Clears the memory used by the generator.
Definition tree_generator.hpp:166
void init(const uint64_t n) noexcept
Initializes the tree generator.
Definition tree_generator.hpp:160
graphs::rooted_tree get_tree() noexcept
Definition tree_generator.hpp:196
Uniformly random selection of labelled rooted trees.
Definition rand_lab_rooted_trees.hpp:153
rand_lab_rooted_trees(const rand_lab_rooted_trees &Gen)=default
Copy constructor.
rand_lab_rooted_trees(rand_lab_rooted_trees &&Gen)=default
Move constructor.
~rand_lab_rooted_trees()=default
Default destructor.
rand_lab_rooted_trees & operator=(const rand_lab_rooted_trees &g) noexcept=default
Copy assignment operator.
void init(const uint64_t n, const uint64_t seed=0) noexcept
Initializes the generator with the number of nodes and a seed.
Definition rand_lab_rooted_trees.hpp:196
rand_lab_rooted_trees() noexcept
Empty constructor.
Definition rand_lab_rooted_trees.hpp:158
rand_lab_rooted_trees(const uint64_t n, const uint64_t seed=0) noexcept
Constructor with size of tree and seed for the random number generator.
Definition rand_lab_rooted_trees.hpp:168
void clear() noexcept
Clear the memory used by the generator.
Definition rand_lab_rooted_trees.hpp:202
graphs::rooted_tree yield_tree() noexcept
Yields a tree, advancing the generator if necessary.
Definition rand_lab_rooted_trees.hpp:207
_rand_lab_rooted_trees m_Gen
See _rand_lab_rooted_trees for details.
Definition rand_lab_rooted_trees.hpp:222
graphs::rooted_tree __get_tree() noexcept
Returns a labelled rooted tree chosen uniformly at random.
Definition rand_lab_rooted_trees.hpp:218
Free tree graph class.
Definition free_tree.hpp:60
Rooted tree graph class.
Definition rooted_tree.hpp:109
Main namespace of the library.
Definition basic_types.hpp:48
uint64_t node
Node type. See Node / Vertex page for further details.
Definition basic_types.hpp:51