LAL: Linear Arrangement Library 23.01.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
all_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 - 2023
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 (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// lal includes
45#include <lal/graphs/rooted_tree.hpp>
46#include <lal/generate/tree_generator.hpp>
47#include <lal/detail/data_array.hpp>
48
49namespace lal {
50namespace generate {
51
99class all_ulab_rooted_trees : public _tree_generator<graphs::rooted_tree> {
100public:
101 /* CONSTRUCTORS */
102
104 all_ulab_rooted_trees() noexcept : _tree_generator<graphs::rooted_tree>()
105 { }
106
111 all_ulab_rooted_trees(uint64_t n) noexcept {
112 init(n);
113 }
114
120
126
128 ~all_ulab_rooted_trees() noexcept = default;
129
131 all_ulab_rooted_trees& operator= (const all_ulab_rooted_trees& g) noexcept = default;
133 all_ulab_rooted_trees& operator= (all_ulab_rooted_trees&& g) noexcept = default;
134
135 /* INITIALIZE */
136
141 void init(uint64_t n) noexcept {
143 // resize the memory
144 m_save.resize(m_n + 1);
145 m_prev.resize(m_n + 1);
146 m_L.resize(m_n + 1);
147 // reset the state of the generator
148 reset();
149 }
150
155 void clear() noexcept {
157 m_save.clear();
158 m_prev.clear();
159 m_L.clear();
160 }
161
162 /* GETTERS */
163
165 bool end() const noexcept { return m_reached_end; }
166
167 /* MODIFIERS */
168
176 void next() noexcept;
177
183 void reset() noexcept {
184 __reset();
185 next();
186 }
187
189 const auto t = get_tree();
190 next();
191 return t;
192 }
193
194protected:
203
205 void __reset() noexcept;
206
207private:
209 bool m_is_last = false;
211 bool m_is_first = false;
213 bool m_reached_end = false;
214
216 uint64_t m_p = 0;
218 detail::data_array<node> m_save;
220 detail::data_array<node> m_prev;
222 detail::data_array<node> m_L;
223};
224
225} // -- namespace generate
226} // -- namespace lal
Base class for tree generators.
Definition: tree_generator.hpp:123
uint64_t m_n
Number of vertices.
Definition: tree_generator.hpp:296
void init(uint64_t n) noexcept
Initializes the tree generator.
Definition: tree_generator.hpp:159
void clear() noexcept
Clears the memory used by the generator.
Definition: tree_generator.hpp:165
graphs::rooted_tree get_tree() noexcept
Retrieve the generated tree.
Definition: tree_generator.hpp:195
Exhaustive enumeration of unlabelled rooted trees.
Definition: all_ulab_rooted_trees.hpp:99
uint64_t m_p
Pointer as in the paper.
Definition: all_ulab_rooted_trees.hpp:216
void next() noexcept
Generates the next tree.
all_ulab_rooted_trees() noexcept
Empty constructor.
Definition: all_ulab_rooted_trees.hpp:104
bool end() const noexcept
Returns true if the end of the iteration was reached.
Definition: all_ulab_rooted_trees.hpp:165
detail::data_array< node > m_prev
Sequence PREV.
Definition: all_ulab_rooted_trees.hpp:220
detail::data_array< node > m_L
Level sequence of the tree.
Definition: all_ulab_rooted_trees.hpp:222
graphs::rooted_tree yield_tree() noexcept
Yields a tree, advancing the generator if necessary.
Definition: all_ulab_rooted_trees.hpp:188
void clear() noexcept
Clears the memory used.
Definition: all_ulab_rooted_trees.hpp:155
bool m_reached_end
Has the end of the generation been reached?
Definition: all_ulab_rooted_trees.hpp:213
graphs::rooted_tree __get_tree() noexcept
Constructs the current tree.
void reset() noexcept
Sets the generator to its initial state.
Definition: all_ulab_rooted_trees.hpp:183
void __reset() noexcept
Sets the generator to its initial state.
all_ulab_rooted_trees(uint64_t n) noexcept
Constructor with number of nodes.
Definition: all_ulab_rooted_trees.hpp:111
detail::data_array< node > m_save
Sequence SAVE.
Definition: all_ulab_rooted_trees.hpp:218
all_ulab_rooted_trees(all_ulab_rooted_trees &&Gen)=default
Move constructor.
void init(uint64_t n) noexcept
Initializes the generator with a given number of vertices.
Definition: all_ulab_rooted_trees.hpp:141
bool m_is_last
Is the current tree the last tree to be generated?
Definition: all_ulab_rooted_trees.hpp:209
bool m_is_first
Is the current tree the first tree to be generated?
Definition: all_ulab_rooted_trees.hpp:211
~all_ulab_rooted_trees() noexcept=default
Default destructor.
all_ulab_rooted_trees(const all_ulab_rooted_trees &Gen)=default
Copy constructor.
Rooted tree graph class.
Definition: rooted_tree.hpp:103
Main namespace of the library.
Definition: basic_types.hpp:50
uint64_t node
Node type. See Node / Vertex page for further details.
Definition: basic_types.hpp:53
void resize(std::size_t new_size) noexcept
Resize the array.
Definition: data_array.hpp:175
void clear() noexcept
Clear the contents of the array.
Definition: data_array.hpp:162