LAL: Linear Arrangement Library 23.01.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
all_ulab_free_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/free_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_free_trees : public _tree_generator<graphs::free_tree> {
100public:
102 all_ulab_free_trees() noexcept : _tree_generator<graphs::free_tree>() { }
103
108 all_ulab_free_trees(uint64_t n) noexcept {
109 init(n);
110 }
116
122
124 ~all_ulab_free_trees() noexcept = default;
125
127 all_ulab_free_trees& operator= (const all_ulab_free_trees& g) noexcept = default;
129 all_ulab_free_trees& operator= (all_ulab_free_trees&& g) noexcept = default;
130
131 /* INITIALIZE */
132
137 void init(uint64_t n) noexcept {
139 m_L.resize(m_n + 1);
140 m_W.resize(m_n + 1);
141 reset();
142 }
143
148 void clear() noexcept {
150 m_L.clear();
151 m_W.clear();
152 }
153
154 /* GETTERS */
155
157 bool end() const noexcept { return m_reached_end; }
158
159 /* MODIFIERS */
160
168 void next() noexcept;
169
171 void reset() noexcept {
172 __reset();
173 next();
174 }
175
177 const auto t = get_tree();
178 next();
179 return t;
180 }
181
182protected:
190
192 void __reset() noexcept;
193
194private:
196 detail::data_array<uint64_t> m_L;
201 detail::data_array<uint64_t> m_W;
202
204 uint64_t m_p;
206 uint64_t m_q;
207
209 uint64_t m_h1;
211 uint64_t m_h2;
212
218 uint64_t m_c;
224 uint64_t m_r;
225
227 bool m_is_last = false;
229 bool m_first_it = true;
231 bool m_reached_end = false;
232};
233
234} // -- namespace generate
235} // -- 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::free_tree get_tree() noexcept
Retrieve the generated tree.
Definition: tree_generator.hpp:195
Exhaustive enumeration of unlabelled free trees.
Definition: all_ulab_free_trees.hpp:99
bool m_reached_end
Has the end of the generation been reached?
Definition: all_ulab_free_trees.hpp:231
void reset() noexcept
Sets the generator to its initial state.
Definition: all_ulab_free_trees.hpp:171
all_ulab_free_trees() noexcept
Empty constructor.
Definition: all_ulab_free_trees.hpp:102
uint64_t m_q
Largest integer such that .
Definition: all_ulab_free_trees.hpp:206
void __reset() noexcept
Sets the generator to its initial state.
detail::data_array< uint64_t > m_L
Canonical level sequence of the tree.
Definition: all_ulab_free_trees.hpp:196
uint64_t m_p
Largest integer such that .
Definition: all_ulab_free_trees.hpp:204
bool end() const noexcept
Returns true if the end of the iteration was reached.
Definition: all_ulab_free_trees.hpp:157
bool m_is_last
Was the last tree generated?
Definition: all_ulab_free_trees.hpp:227
bool m_first_it
First time calling next().
Definition: all_ulab_free_trees.hpp:229
void clear() noexcept
Clears the memory used.
Definition: all_ulab_free_trees.hpp:148
detail::data_array< uint64_t > m_W
is the subscript of the level number in corresponding to the parent of the node corresponding to .
Definition: all_ulab_free_trees.hpp:201
uint64_t m_h1
Maximum level number in the first principal subsequence.
Definition: all_ulab_free_trees.hpp:209
all_ulab_free_trees(uint64_t n) noexcept
Constructor with number of nodes.
Definition: all_ulab_free_trees.hpp:108
graphs::free_tree yield_tree() noexcept
Yields a tree, advancing the generator if necessary.
Definition: all_ulab_free_trees.hpp:176
uint64_t m_h2
Maximum level number in the second principal subsequence.
Definition: all_ulab_free_trees.hpp:211
~all_ulab_free_trees() noexcept=default
Default destructor.
uint64_t m_r
Exactly .
Definition: all_ulab_free_trees.hpp:224
all_ulab_free_trees(const all_ulab_free_trees &Gen)=default
Copy constructor.
void next() noexcept
Generates next tree.
graphs::free_tree __get_tree() noexcept
Constructs the current tree.
all_ulab_free_trees(all_ulab_free_trees &&Gen)=default
Move constructor.
uint64_t m_c
An index to the first element of .
Definition: all_ulab_free_trees.hpp:218
void init(uint64_t n) noexcept
Initializes the generator with a given number of vertices.
Definition: all_ulab_free_trees.hpp:137
Free tree graph class.
Definition: free_tree.hpp:60
Main namespace of the library.
Definition: basic_types.hpp:50
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