LAL: Linear Arrangement Library 23.01.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
undirected_graph.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// C++ includes
45#if defined DEBUG
46#include <cassert>
47#endif
48#include <vector>
49
50// lal includes
51#include <lal/basic_types.hpp>
52#include <lal/graphs/graph.hpp>
53
54namespace lal {
55namespace graphs {
56
67class undirected_graph : virtual public graph {
68public:
69 /* CONSTRUCTORS */
70
72 undirected_graph() noexcept { }
77 undirected_graph(uint64_t n) noexcept {
78 init(n);
79 }
84 undirected_graph(const undirected_graph& g) noexcept : graph() {
86 }
87
93 move_full_undirected_graph(std::forward<undirected_graph>(g));
94 }
95
97 virtual ~undirected_graph() noexcept { }
98
99 /* OPERATORS */
100
107 return *this;
108 }
114 move_full_undirected_graph(std::forward<undirected_graph>(g));
115 return *this;
116 }
117
118 /* MODIFIERS */
119
134 (node u, bool norm = true, bool check_norm = true) noexcept;
135
153 (node s, node t, bool norm = true, bool check_norm = true) noexcept;
154
168
169 void finish_bulk_add(bool norm = true, bool check = true) noexcept;
170
191 (const std::vector<edge>& edges, bool norm = true, bool check_norm = true)
192 noexcept;
193
220 (const std::vector<edge>& edges, bool norm = true, bool check_norm = true)
221 noexcept;
222
240 (node s, node t, bool norm = true, bool check_norm = true) noexcept;
241
263 (const std::vector<edge>& edges, bool norm = true, bool check_norm = true)
264 noexcept;
265
286 (node u, bool norm = true, bool check_norm = true)
287 noexcept;
288
300 void disjoint_union(const undirected_graph& g) noexcept;
301
302 /* SETTERS */
303
304 /* GETTERS */
305
306 std::vector<edge_pair> get_Q() const noexcept;
307
308 std::vector<edge> get_edges() const noexcept;
309
315 const neighbourhood& get_neighbours(node u) const noexcept {
316#if defined DEBUG
317 assert(has_node(u));
318#endif
319 return m_adjacency_list[u];
320 }
321
327 uint64_t get_degree(node u) const noexcept {
328#if defined DEBUG
329 assert(has_node(u));
330#endif
331 return m_adjacency_list[u].size();
332 }
333
335 bool has_edge(node u, node v) const noexcept;
336
337 bool is_directed() const noexcept { return false; }
338 bool is_undirected() const noexcept { return true; }
339
340protected:
342 virtual void _init(uint64_t n) noexcept {
343 graph::_init(n);
344 }
346 virtual void _clear() noexcept {
348 }
349
352 // copy parent class
354
355 // copy this class' members
356 }
359 // move-assign parent class
360 move_full_graph(std::forward<undirected_graph>(u));
361
362 // move-assign this class' members
363 }
364
365private:
374 (node u, node v, neighbourhood& out_u, neighbourhood& in_v) noexcept;
375};
376
377} // -- namespace graphs
378} // -- namespace lal
Abstract class for graphs.
Definition: graph.hpp:69
void copy_full_graph(const graph &g) noexcept
Copies all members of this class.
Definition: graph.hpp:255
bool has_node(node u) const noexcept
Returns true if node u is in this graph.
Definition: graph.hpp:192
virtual void init(uint64_t n) noexcept
Allocates the necessary memory for this class.
virtual void _init(uint64_t n) noexcept
Initialises memory of graph class.
Definition: graph.hpp:242
virtual void _clear() noexcept
Clears memory for the graph class.
Definition: graph.hpp:248
graph() noexcept
Empty constructor.
Definition: graph.hpp:74
void move_full_graph(graph &&g) noexcept
Moves all members of this class.
Definition: graph.hpp:261
std::vector< neighbourhood > m_adjacency_list
Data structure that implements the graph.
Definition: graph.hpp:223
Undirected graph class.
Definition: undirected_graph.hpp:67
undirected_graph(uint64_t n) noexcept
Constructor with number of nodes.
Definition: undirected_graph.hpp:77
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
virtual undirected_graph & remove_node(node u, bool norm=true, bool check_norm=true) noexcept
Remove a node from this graph.
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 undirected_graph & remove_edges(const std::vector< edge > &edges, bool norm=true, bool check_norm=true) noexcept
Remove an edge from this graph.
virtual undirected_graph & set_edges(const std::vector< edge > &edges, bool norm=true, bool check_norm=true) noexcept
Sets the edges to the graph.
bool is_undirected() const noexcept
Returns whether this graph is undirected or not.
Definition: undirected_graph.hpp:338
bool has_edge(node u, node v) const noexcept
Returns true if the edge exists in the graph.
virtual undirected_graph & remove_edge(node s, node t, bool norm=true, bool check_norm=true) noexcept
Remove an edge from this graph.
bool is_directed() const noexcept
Returns whether this graph is directed or not.
Definition: undirected_graph.hpp:337
std::vector< edge_pair > get_Q() const noexcept
Returns all independent pairs of edges of this graph.
virtual undirected_graph & remove_edges_incident_to(node u, bool norm=true, bool check_norm=true) noexcept
Remove all edges incident to a given vertex.
virtual undirected_graph & add_edge(node s, node t, bool norm=true, bool check_norm=true) noexcept
Adds an edge to the graph.
undirected_graph(const undirected_graph &g) noexcept
Copy constructor.
Definition: undirected_graph.hpp:84
virtual ~undirected_graph() noexcept
Destructor.
Definition: undirected_graph.hpp:97
void remove_single_edge(node u, node v, neighbourhood &out_u, neighbourhood &in_v) noexcept
Removes a single edge.
uint64_t get_degree(node u) const noexcept
Returns the number of neighbours of u.
Definition: undirected_graph.hpp:327
virtual void _init(uint64_t n) noexcept
Initialises memory of undirected_graph and graph classes.
Definition: undirected_graph.hpp:342
std::vector< edge > get_edges() const noexcept
Returns all edges of this graph.
undirected_graph & operator=(const undirected_graph &g) noexcept
Copy assignment operator.
Definition: undirected_graph.hpp:105
undirected_graph() noexcept
Empty constructor.
Definition: undirected_graph.hpp:72
virtual undirected_graph & add_edges(const std::vector< edge > &edges, bool norm=true, bool check_norm=true) noexcept
Adds a list of edges to the graph.
undirected_graph(undirected_graph &&g) noexcept
Move constructor.
Definition: undirected_graph.hpp:92
const neighbourhood & get_neighbours(node u) const noexcept
Returns the neighbourhood of node u.
Definition: undirected_graph.hpp:315
void finish_bulk_add(bool norm=true, bool check=true) noexcept
Completes the inner structure of the graph after adding a bulk of edges.
undirected_graph & add_edge_bulk(node s, node t) noexcept
Adds an edge to the graph.
Main namespace of the library.
Definition: basic_types.hpp:50
std::pair< edge, edge > edge_pair
Edge pair type.
Definition: basic_types.hpp:60
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
std::vector< node > neighbourhood
List of nodes.
Definition: basic_types.hpp:62