LAL: Linear Arrangement Library 23.01.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
free_tree.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/linear_arrangement.hpp>
46#include <lal/graphs/undirected_graph.hpp>
47#include <lal/graphs/tree.hpp>
48
49namespace lal {
50namespace graphs {
51
60class free_tree : public undirected_graph, virtual public tree {
61public:
62 /* CONSTRUCTORS */
63
65 free_tree() noexcept : tree(), undirected_graph() { }
70 free_tree(uint64_t n) noexcept : undirected_graph(n) {
72 }
77 free_tree(const free_tree& t) noexcept : graph(), tree(), undirected_graph() {
79 }
80
85 free_tree(free_tree&& t) noexcept {
86 move_full_free_tree(std::forward<free_tree>(t));
87 }
88
94 free_tree(const undirected_graph& t) noexcept;
95
102
104 virtual ~free_tree() noexcept { }
105
106 /* OPERATORS */
107
112 free_tree& operator= (const free_tree& f) noexcept {
114 return *this;
115 }
121 move_full_free_tree(std::forward<free_tree>(f));
122 return *this;
123 }
124
125 /* MODIFIERS */
126
128 (node u, bool norm = true, bool check_norm = true) noexcept;
129
152 (node s, node t, bool norm = true, bool check_norm = true) noexcept;
153
167
174 void finish_bulk_add(bool norm = true, bool check = true) noexcept;
175
200 (const std::vector<edge>& edges, bool norm = true, bool check_norm = true)
201 noexcept;
202
231 (const std::vector<edge>& edges, bool norm = true, bool check_norm = true)
232 noexcept;
233
252 (node s, node t, bool norm = false, bool check_norm = true) noexcept;
253
276 (const std::vector<edge>& edges, bool norm = true, bool check_norm = true)
277 noexcept;
278
300 (node u, bool norm = true, bool check_norm = true)
301 noexcept;
302
320 void disjoint_union(const free_tree& t) noexcept;
321
322 void calculate_tree_type() noexcept;
323
324 /* GETTERS */
325
326 bool is_rooted() const noexcept { return false; }
327
338 const noexcept;
339
340protected:
342 virtual void _init(uint64_t n) noexcept {
345 }
348 virtual void _clear() noexcept {
351 }
352
354 node u, node v,
355 uint64_t * const root_of,
356 uint64_t * const root_size
357 ) noexcept;
359 node u, node v,
360 uint64_t * const root_of,
361 uint64_t * const root_size
362 ) const noexcept;
363
365 node u, node v,
366 uint64_t * const root_of,
367 uint64_t * const root_size
368 ) noexcept;
370 node u, node v,
371 uint64_t * const root_of,
372 uint64_t * const root_size
373 ) const noexcept;
374
376 node u,
377 uint64_t * const root_of, uint64_t * const root_size
378 ) noexcept;
380 node u,
381 uint64_t * const root_of, uint64_t * const root_size
382 ) const noexcept;
383
385 void copy_full_free_tree(const free_tree& f) noexcept {
386 // copy undirected_graph class
388
389 // copy only tree's members
391
392 // copy this class' members
393 }
395 void move_full_free_tree(free_tree&& f) noexcept {
396 // move-assign undirected_graph class
397 move_full_undirected_graph(std::forward<free_tree>(f));
398
399 // move-assign only tree's members
400 tree_only_move(std::forward<free_tree>(f));
401
402 // move this class' members
403 }
404
405private:
407};
408
409} // -- namespace graphs
410} // -- namespace lal
Free tree graph class.
Definition: free_tree.hpp:60
free_tree & add_edge(node s, node t, bool norm=true, bool check_norm=true) noexcept
Adds an edge to the tree.
void copy_full_free_tree(const free_tree &f) noexcept
Copies all members of this class and the parent class.
Definition: free_tree.hpp:385
head_vector get_head_vector(node r=0, const linear_arrangement &arr={}) const noexcept
Converts a free tree into a head vector.
void calculate_tree_type() noexcept
Calculates the type of tree.
virtual void _init(uint64_t n) noexcept
Initialises memory of free_tree, undirected_graph and graph classes.
Definition: free_tree.hpp:342
free_tree & add_edges(const std::vector< edge > &edges, bool norm=true, bool check_norm=true) noexcept
Adds a list of edges to the graph.
free_tree(free_tree &&t) noexcept
Move constructor.
Definition: free_tree.hpp:85
free_tree & add_edge_bulk(node s, node t) noexcept
Adds an edge to the graph.
virtual free_tree & remove_edges_incident_to(node u, bool norm=true, bool check_norm=true) noexcept
Remove all edges incident to a given vertex.
free_tree & set_edges(const std::vector< edge > &edges, bool norm=true, bool check_norm=true) noexcept
Sets the edges to the graph.
void move_full_free_tree(free_tree &&f) noexcept
Moves all members of this class and the parent class.
Definition: free_tree.hpp:395
free_tree(const undirected_graph &t) noexcept
Copy constructor with undirected graph.
free_tree & remove_edge(node s, node t, bool norm=false, bool check_norm=true) noexcept
Remove an edge from this graph.
void update_union_find_after_edge_add(node u, node v, uint64_t *const root_of, uint64_t *const root_size) const noexcept
Update the union find data structure after an edge addition.
void disjoint_union(const free_tree &t) noexcept
Disjoint union of trees.
virtual void _clear() noexcept
Definition: free_tree.hpp:348
free_tree(const free_tree &t) noexcept
Copy constructor.
Definition: free_tree.hpp:77
void finish_bulk_add(bool norm=true, bool check=true) noexcept
Finishes adding edges in bulk.
virtual free_tree & remove_node(node u, bool norm=true, bool check_norm=true) noexcept
Remove a node from this graph.
free_tree & operator=(const free_tree &f) noexcept
Copy assignment operator.
Definition: free_tree.hpp:112
virtual ~free_tree() noexcept
Destructor.
Definition: free_tree.hpp:104
void update_union_find_after_edge_add(node u, node v, uint64_t *const root_of, uint64_t *const root_size) noexcept
Update the union find data structure after an edge addition.
void update_union_find_before_incident_edges_removed(node u, uint64_t *const root_of, uint64_t *const root_size) noexcept
Update the union find data structure before the removal of all edges incident to a node.
free_tree(undirected_graph &&t) noexcept
Move constructor with undirected graph.
void update_union_find_after_edge_remove(node u, node v, uint64_t *const root_of, uint64_t *const root_size) noexcept
Update the union find data structure after an edge removal.
free_tree(uint64_t n) noexcept
Constructor with number of vertices.
Definition: free_tree.hpp:70
void update_union_find_after_edge_remove(node u, node v, uint64_t *const root_of, uint64_t *const root_size) const noexcept
Update the union find data structure after an edge removal.
bool is_rooted() const noexcept
Returns whether this tree is a rooted tree.
Definition: free_tree.hpp:326
free_tree() noexcept
Empty constructor.
Definition: free_tree.hpp:65
void update_union_find_before_incident_edges_removed(node u, uint64_t *const root_of, uint64_t *const root_size) const noexcept
Update the union find data structure before the removal of all edges incident to a node.
free_tree & remove_edges(const std::vector< edge > &edges, bool norm=true, bool check_norm=true) noexcept
Remove an edge from this graph.
Abstract class for graphs.
Definition: graph.hpp:69
Tree graph class.
Definition: tree.hpp:73
tree() noexcept
Empty constructor.
Definition: tree.hpp:78
void tree_only_copy(const tree &t) noexcept
Copies only members of class tree.
Definition: tree.hpp:327
void tree_only_move(tree &&t) noexcept
Moves only members of class tree.
Definition: tree.hpp:335
void tree_only_init(uint64_t n) noexcept
Initialises only the memory of class tree.
Definition: tree.hpp:306
void tree_only_clear() noexcept
Clears the memory used by only class tree.
Definition: tree.hpp:318
Undirected graph class.
Definition: undirected_graph.hpp:67
void disjoint_union(const undirected_graph &g) noexcept
Disjoint union of graphs.
virtual void _clear() noexcept
Clears the memory of undirected_graph and graph classes.
Definition: undirected_graph.hpp:346
void copy_full_undirected_graph(const undirected_graph &u) noexcept
Copies all members of this class and the parent class.
Definition: undirected_graph.hpp:351
void move_full_undirected_graph(undirected_graph &&u) noexcept
Moves all members of this class and the parent class.
Definition: undirected_graph.hpp:358
virtual void _init(uint64_t n) noexcept
Initialises memory of undirected_graph and graph classes.
Definition: undirected_graph.hpp:342
undirected_graph() noexcept
Empty constructor.
Definition: undirected_graph.hpp:72
Linear arrangement of vertices.
Definition: linear_arrangement.hpp:103
Main namespace of the library.
Definition: basic_types.hpp:50
std::vector< uint64_t > head_vector
See Head vector page for further details.
Definition: basic_types.hpp:64
std::pair< node, node > edge
See Edge page for further details.
Definition: basic_types.hpp:58
uint64_t node
Node type. See Node / Vertex page for further details.
Definition: basic_types.hpp:53