LAL: Linear Arrangement Library 21.07.01
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
rand_ulab_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 - 2021
7 *
8 * This file is part of Linear Arrangement Library. To see the full code
9 * visit the webpage:
10 * https://github.com/lluisalemanypuig/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 (lalemany@cs.upc.edu)
28 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
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 * LARCA (Laboratory for Relational Algorithmics, Complexity and Learning)
35 * CQL (Complexity and Quantitative Linguistics Lab)
36 * Office S124, 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/tree_generator.hpp>
50#include <lal/numeric/integer.hpp>
51#include <lal/internal/data_array.hpp>
52
53namespace lal {
54namespace generate {
55
68public:
69 /* CONSTRUCTORS */
70
79 _rand_ulab_rooted_trees(uint32_t n, uint32_t seed = 0) noexcept;
85#ifndef SWIG
91#endif
93 virtual ~_rand_ulab_rooted_trees() = default;
94
95 /* GETTERS */
96
103
122 void clear() noexcept;
123
124protected:
126 const uint32_t m_n;
127
129 std::mt19937 m_gen;
131 std::uniform_real_distribution<double> m_unif;
132
138 std::vector<numeric::integer> m_rn;
139
149 internal::data_array<uint32_t> m_head_vector;
150
151protected:
161 virtual void init(uint32_t seed = 0) noexcept;
162
174 std::pair<uint32_t,uint32_t>
175 ranrut(uint32_t n, uint32_t lr, uint32_t nt) noexcept;
176
178 void init_rn() noexcept;
185 const numeric::integer& get_rn(uint32_t n) noexcept;
186
197 std::pair<uint32_t,uint32_t> choose_jd_from_T(uint32_t n) noexcept;
198};
199
224class rand_ulab_rooted_trees : public _tree_generator<graphs::rooted_tree> {
225public:
226 /* CONSTRUCTORS */
227
235 rand_ulab_rooted_trees(uint32_t n, uint32_t seed = 0) noexcept
236 : _tree_generator<graphs::rooted_tree>(n), m_Gen(n, seed) { }
242#ifndef SWIG
248#endif
250 ~rand_ulab_rooted_trees() noexcept = default;
251
252 inline graphs::rooted_tree yield_tree() noexcept {
253 return get_tree();
254 }
255
256protected:
263 inline graphs::rooted_tree __get_tree() noexcept { return m_Gen.get_tree(); }
264
265protected:
268};
269
270} // -- namespace generate
271} // -- namespace lal
Uniformly random generation of unlabelled rooted trees.
Definition rand_ulab_rooted_trees.hpp:67
void init_rn() noexcept
Initialiases m_rn with 31 values from the OEIS (see OEIS_A000081).
const uint32_t m_n
Number of nodes of the tree.
Definition rand_ulab_rooted_trees.hpp:126
virtual ~_rand_ulab_rooted_trees()=default
Destructor.
std::vector< numeric::integer > m_rn
The number of unlabelled rooted trees.
Definition rand_ulab_rooted_trees.hpp:138
std::pair< uint32_t, uint32_t > ranrut(uint32_t n, uint32_t lr, uint32_t nt) noexcept
Generates uniformly at random a rooted unlabelled tree of n nodes.
std::pair< uint32_t, uint32_t > choose_jd_from_T(uint32_t n) noexcept
Chooses uniformly at random a pair , according to some probability.
virtual void init(uint32_t seed=0) noexcept
Sets the size of the unlabelled trees to generate.
_rand_ulab_rooted_trees(_rand_ulab_rooted_trees &&Gen)=default
Move constructor.
_rand_ulab_rooted_trees(uint32_t n, uint32_t seed=0) noexcept
Constructor with size of tree and seed for the random number generator.
std::mt19937 m_gen
Random number generator.
Definition rand_ulab_rooted_trees.hpp:129
graphs::rooted_tree get_tree() noexcept
Generates uniformly at random a free unlabelled tree.
std::uniform_real_distribution< double > m_unif
Distribution of the numbers.
Definition rand_ulab_rooted_trees.hpp:131
internal::data_array< uint32_t > m_head_vector
The head vector of the tree under construction.
Definition rand_ulab_rooted_trees.hpp:149
void clear() noexcept
Clears the memory occupied.
const numeric::integer & get_rn(uint32_t n) noexcept
Computes all the values for .
Base class for tree generators.
Definition tree_generator.hpp:87
Uniformly random generation of unlabelled rooted trees.
Definition rand_ulab_rooted_trees.hpp:224
rand_ulab_rooted_trees(rand_ulab_rooted_trees &&Gen)=default
Move constructor.
~rand_ulab_rooted_trees() noexcept=default
Default destructor.
rand_ulab_rooted_trees(const rand_ulab_rooted_trees &Gen)=default
Copy constructor.
graphs::rooted_tree __get_tree() noexcept
Returns an unlabelled rooted tree chosen uniformly at random.
Definition rand_ulab_rooted_trees.hpp:263
_rand_ulab_rooted_trees m_Gen
See _rand_ulab_rooted_trees for details.
Definition rand_ulab_rooted_trees.hpp:267
rand_ulab_rooted_trees(uint32_t n, uint32_t seed=0) noexcept
Constructor with size of tree and seed for the random number generator.
Definition rand_ulab_rooted_trees.hpp:235
Rooted tree graph class.
Definition rooted_tree.hpp:107
Main namespace of the library.
Definition definitions.hpp:48