LAL: Linear Arrangement Library 24.10.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 - 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// 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:
64 friend class rooted_tree;
65
66public:
67 /* CONSTRUCTORS */
68
70 free_tree() noexcept : tree(), undirected_graph() { }
75 free_tree(const uint64_t n) noexcept {
77 }
82 free_tree(const free_tree& t) noexcept : graph(), tree(), undirected_graph() {
84 }
85
90 free_tree(free_tree&& t) noexcept {
91 move_full_free_tree(std::forward<free_tree>(t));
92 }
93
99 free_tree(const undirected_graph& t) noexcept;
100
107
109 ~free_tree() noexcept { }
110
111 /* OPERATORS */
112
117 free_tree& operator= (const free_tree& f) noexcept {
119 return *this;
120 }
126 move_full_free_tree(std::forward<free_tree>(f));
127 return *this;
128 }
129
130 /* MODIFIERS */
131
132 free_tree& add_node() noexcept {
135 return *this;
136 }
137
139 (
140 const node u,
141 const bool norm = true,
142 const bool check_norm = true
143 )
144 noexcept;
145
168 (
169 const node s,
170 const node t,
171 const bool norm = true,
172 const bool check_norm = true
173 )
174 noexcept;
175
188 free_tree& add_edge_bulk(const node s, const node t) noexcept;
189
198 void finish_bulk_add(const bool norm = true, const bool check = true) noexcept;
199
200 void finish_bulk_add_complete(const bool norm = true, const bool check = true) noexcept;
201
223 (
224 const std::vector<edge>& edges,
225 const bool norm = true,
226 const bool check_norm = true
227 )
228 noexcept;
229
258 (
259 const std::vector<edge>& edges,
260 const bool norm = true,
261 const bool check_norm = true
262 )
263 noexcept;
264
283 (
284 const node s,
285 const node t,
286 const bool norm = false,
287 const bool check_norm = true
288 )
289 noexcept;
290
303 free_tree& remove_edge_bulk(const node s, const node t) noexcept;
304
313 void finish_bulk_remove(const bool norm = true, const bool check = true) noexcept;
314
315 void finish_bulk_remove_complete(const bool norm = true, const bool check = true) noexcept;
316
336 (
337 const std::vector<edge>& edges,
338 const bool norm = true,
339 const bool check_norm = true
340 )
341 noexcept;
342
360 (
361 const node u,
362 const bool norm = true,
363 const bool check_norm = true
364 )
365 noexcept;
366
384 free_tree& disjoint_union(const free_tree& t) noexcept;
385
386 void calculate_tree_type() noexcept;
387
388 /* GETTERS */
389
390 bool is_rooted() const noexcept { return false; }
391
402 (const node r = 0, const linear_arrangement& arr = {})
403 const noexcept;
404
405protected:
414 void _init(const uint64_t n) noexcept {
417 }
424 void _clear() noexcept {
427 }
428
429 void actions_after_add_edge(const node u, const node v) noexcept;
430
431 void actions_after_add_edges(const edge_list& e) noexcept;
432
434
435 void actions_after_remove_edge(const node u, const node v) noexcept;
436
437 void actions_after_remove_edges(const edge_list& e) noexcept;
438
440
441 void actions_after_remove_node(const node u) noexcept;
442
444
446 (
447 const node u,
448 const node v,
449 uint64_t * const root_of,
450 uint64_t * const root_size
451 )
452 const noexcept;
453
455 (
456 const edge_list& edges,
457 uint64_t * const root_of,
458 uint64_t * const root_size
459 )
460 const noexcept;
461
463 (
464 uint64_t * const root_of,
465 uint64_t * const root_size
466 )
467 const noexcept;
468
470 (
471 const node u,
472 const node v,
473 uint64_t * const root_of,
474 uint64_t * const root_size
475 )
476 const noexcept;
477
479 (
480 const edge_list& edges,
481 uint64_t * const root_of,
482 uint64_t * const root_size
483 )
484 const noexcept;
485
487 (
488 uint64_t * const root_of,
489 uint64_t * const root_size
490 )
491 const noexcept;
492
494 const node u,
495 uint64_t * const root_of,
496 uint64_t * const root_size
497 )
498 const noexcept;
499
501 void copy_full_free_tree(const free_tree& f) noexcept {
502 // copy undirected_graph class
504
505 // copy only tree's members
507
508 // copy this class' members
509 }
511 void move_full_free_tree(free_tree&& f) noexcept {
512 // move-assign undirected_graph class
513 move_full_undirected_graph(std::forward<free_tree>(f));
514
515 // move-assign only tree's members
516 tree_only_move(std::forward<free_tree>(f));
517
518 // move this class' members
519 }
520
521private:
523};
524
525} // -- namespace graphs
526} // -- namespace lal
Free tree graph class.
Definition free_tree.hpp:60
void update_union_find_after_remove_edges(const edge_list &edges, uint64_t *const root_of, uint64_t *const root_size) const noexcept
Update the union find data structure after the removal of a set of edges.
void copy_full_free_tree(const free_tree &f) noexcept
Copies all members of this class and the parent classes.
Definition free_tree.hpp:501
free_tree & remove_edges(const std::vector< edge > &edges, const bool norm=true, const bool check_norm=true) noexcept
Remove an edge from this graph.
void calculate_tree_type() noexcept
Calculates the type of tree.
void update_union_find_after_add_edges_bulk(uint64_t *const root_of, uint64_t *const root_size) const noexcept
Update the union find data structure after the addition of several edges.
void _clear() noexcept
Clears the memory in the graph hierarchy.
Definition free_tree.hpp:424
void finish_bulk_remove_complete(const bool norm=true, const bool check=true) noexcept
Completes the inner structure of the tree after removing edges in bulk.
void finish_bulk_remove(const bool norm=true, const bool check=true) noexcept
Finishes removing edges in bulk.
free_tree(free_tree &&t) noexcept
Move constructor.
Definition free_tree.hpp:90
void finish_bulk_add(const bool norm=true, const bool check=true) noexcept
Finishes adding edges in bulk.
free_tree & remove_edges_incident_to(const node u, const bool norm=true, const bool check_norm=true) noexcept
Remove all edges incident to a given vertex.
free_tree & disjoint_union(const free_tree &t) noexcept
Disjoint union of trees.
free_tree & set_edges(const std::vector< edge > &edges, const bool norm=true, const 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 classes.
Definition free_tree.hpp:511
void actions_after_remove_edges(const edge_list &e) noexcept
Do some extra work after the removal of several edges.
~free_tree() noexcept
Destructor.
Definition free_tree.hpp:109
void actions_before_remove_edges_incident_to(const node u) noexcept
Do some work before all edges incident to a node is removed.
free_tree(const undirected_graph &t) noexcept
Copy constructor with undirected graph.
head_vector get_head_vector(const node r=0, const linear_arrangement &arr={}) const noexcept
Converts a free tree into a head vector.
void _init(const uint64_t n) noexcept
Initializes the memory in the graph hierarchy.
Definition free_tree.hpp:414
void actions_after_add_edges_bulk() noexcept
Do some extra work after the addition of several edges in bulk.
free_tree & remove_edge_bulk(const node s, const node t) noexcept
Removes an edge from the tree.
void update_union_find_after_remove_edge(const node u, const node v, uint64_t *const root_of, uint64_t *const root_size) const noexcept
Update the union find data structure after an edge removal.
free_tree(const uint64_t n) noexcept
Constructor with number of vertices.
Definition free_tree.hpp:75
free_tree(const free_tree &t) noexcept
Copy constructor.
Definition free_tree.hpp:82
void actions_after_add_edges(const edge_list &e) noexcept
Do some extra work after the addition of several edges.
void update_union_find_after_remove_edges_bulk(uint64_t *const root_of, uint64_t *const root_size) const noexcept
Update the union find data structure after the removal of several edges.
free_tree & add_edges(const std::vector< edge > &edges, const bool norm=true, const bool check_norm=true) noexcept
Adds a list of edges to the graph.
free_tree & operator=(const free_tree &f) noexcept
Copy assignment operator.
Definition free_tree.hpp:117
void update_union_find_after_add_edge(const node u, const 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 update_union_find_after_add_edges(const edge_list &edges, uint64_t *const root_of, uint64_t *const root_size) const noexcept
Update the union find data structure after the addition of a set of edges.
free_tree & remove_node(const node u, const bool norm=true, const bool check_norm=true) noexcept
Remove a node from this graph.
free_tree & add_node() noexcept
Adds a vertex to the graph.
Definition free_tree.hpp:132
void actions_after_remove_edge(const node u, const node v) noexcept
Do some extra work after the removal of an edge.
void update_union_find_before_remove_incident_edges_to(const 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.
void actions_after_add_edge(const node u, const node v) noexcept
Do some extra work after the addition of an edge.
free_tree & add_edge_bulk(const node s, const node t) noexcept
Adds an edge to the tree.
void actions_after_remove_node(const node u) noexcept
Do some work before the removal of a vertex.
free_tree(undirected_graph &&t) noexcept
Move constructor with undirected graph.
void finish_bulk_add_complete(const bool norm=true, const bool check=true) noexcept
Completes the inner structure of the tree after adding edges in bulk.
free_tree & remove_edge(const node s, const node t, const bool norm=false, const bool check_norm=true) noexcept
Remove an edge from this graph.
bool is_rooted() const noexcept
Returns whether this tree is a rooted tree.
Definition free_tree.hpp:390
free_tree() noexcept
Empty constructor.
Definition free_tree.hpp:70
free_tree & add_edge(const node s, const node t, const bool norm=true, const bool check_norm=true) noexcept
Adds an edge to the tree.
void actions_after_remove_edges_bulk() noexcept
Do some extra work after the removal of several edges in bulk.
graph() noexcept
Empty constructor.
Definition graph.hpp:73
Rooted tree graph class.
Definition rooted_tree.hpp:109
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:359
void tree_only_move(tree &&t) noexcept
Moves only members of class tree.
Definition tree.hpp:367
void tree_only_add_node() noexcept
Adds a node to this tree.
Definition tree.hpp:382
void tree_only_init(const uint64_t n) noexcept
Initializes only the memory of class tree.
Definition tree.hpp:340
void tree_only_clear() noexcept
Clears the memory used by only class tree.
Definition tree.hpp:351
Undirected graph class.
Definition undirected_graph.hpp:66
virtual void _clear() noexcept
Clears the memory of undirected_graph and graph classes.
Definition undirected_graph.hpp:413
void copy_full_undirected_graph(const undirected_graph &u) noexcept
Copies all members of this class and the parent class.
Definition undirected_graph.hpp:434
void move_full_undirected_graph(undirected_graph &&u) noexcept
Moves all members of this class and the parent class.
Definition undirected_graph.hpp:441
virtual void _init(const uint64_t n) noexcept
Initializes the memory in the graph hierarchy.
Definition undirected_graph.hpp:409
virtual undirected_graph & add_node() noexcept
Adds a vertex to the graph.
Definition undirected_graph.hpp:135
undirected_graph & disjoint_union(const undirected_graph &g) noexcept
Disjoint union of graphs.
undirected_graph() noexcept
Empty constructor.
Definition undirected_graph.hpp:71
Linear arrangement of vertices.
Definition linear_arrangement.hpp:103
Main namespace of the library.
Definition basic_types.hpp:48
std::vector< uint64_t > head_vector
See Head vector page for further details.
Definition basic_types.hpp:58
std::pair< node, node > edge
See Edge page for further details.
Definition basic_types.hpp:56
std::vector< edge > edge_list
See Edge list page for further details.
Definition basic_types.hpp:60
uint64_t node
Node type. See Node / Vertex page for further details.
Definition basic_types.hpp:51