LAL: Linear Arrangement Library 21.07.01
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 - 2021
7 *
8 * This file is part of Linear Arrangement Library. To see the full code
9 * visit the webpage:
10 * https://github.com/lluisalemanypuig/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/definitions.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(uint32_t n) noexcept {
78 init(n);
79 }
87#ifndef SWIG
93 move_full_undirected_graph(std::move(g));
94 }
95#endif
97 virtual ~undirected_graph() noexcept { }
98
99 /* OPERATORS */
100
101#ifndef SWIG
108 return *this;
109 }
115 move_full_undirected_graph(std::move(g));
116 return *this;
117 }
118#endif
119
120 /* MODIFIERS */
121
139 (node s, node t, bool norm = true, bool check_norm = true) noexcept;
140
154
155 void finish_bulk_add(bool norm = true, bool check = true) noexcept;
156
177 (const std::vector<edge>& edges, bool norm = true, bool check_norm = true)
178 noexcept;
179
206 (const std::vector<edge>& edges, bool norm = true, bool check_norm = true)
207 noexcept;
208
226 (node s, node t, bool norm = false, bool check_norm = true) noexcept;
227
249 (const std::vector<edge>& edges, bool norm = true, bool check_norm = true)
250 noexcept;
251
272 (node u, bool norm = true, bool check_norm = true)
273 noexcept;
274
286 void disjoint_union(const undirected_graph& g) noexcept;
287
288 /* SETTERS */
289
290 /* GETTERS */
291
292 std::vector<edge_pair> get_Q() const noexcept;
293
294 std::vector<edge> get_edges() const noexcept;
295
301 inline const neighbourhood& get_neighbours(node u) const noexcept {
302#if defined DEBUG
303 assert(has_node(u));
304#endif
305 return m_adjacency_list[u];
306 }
307
313 inline uint32_t get_degree(node u) const noexcept {
314#if defined DEBUG
315 assert(has_node(u));
316#endif
317 return static_cast<uint32_t>(m_adjacency_list[u].size());
318 }
319
321 bool has_edge(node u, node v) const noexcept;
322
323 inline bool is_directed() const noexcept { return false; }
324 inline bool is_undirected() const noexcept { return true; }
325
326protected:
328 virtual void _init(uint32_t n) noexcept;
330 virtual void _clear() noexcept;
331
336
337private:
346 (node u, node v, neighbourhood& out_u, neighbourhood& in_v) noexcept;
347};
348
349} // -- namespace graphs
350} // -- namespace lal
Abstract class for graphs.
Definition graph.hpp:69
bool has_node(node u) const noexcept
Returns true if node u is in this graph.
Definition graph.hpp:188
graph() noexcept
Empty constructor.
Definition graph.hpp:74
virtual void init(uint32_t n) noexcept
Allocates the necessary memory for this class.
std::vector< neighbourhood > m_adjacency_list
Data structure that implements the graph.
Definition graph.hpp:219
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.
void copy_full_undirected_graph(const undirected_graph &u) noexcept
Copies all members of this class and the parent class.
void move_full_undirected_graph(undirected_graph &&u) noexcept
Moves all members of this class and the parent class.
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:324
bool has_edge(node u, node v) const noexcept
Returns true if the edge exists in the graph.
bool is_directed() const noexcept
Returns whether this graph is directed or not.
Definition undirected_graph.hpp:323
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.
virtual void _init(uint32_t n) noexcept
Initialises memory of undirected_graph and graph classes.
virtual undirected_graph & remove_edge(node s, node t, bool norm=false, bool check_norm=true) noexcept
Remove an edge from this graph.
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:106
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
uint32_t get_degree(node u) const noexcept
Returns the number of neighbours of u.
Definition undirected_graph.hpp:313
const neighbourhood & get_neighbours(node u) const noexcept
Returns the neighbourhood of node u.
Definition undirected_graph.hpp:301
undirected_graph(uint32_t n) noexcept
Constructor with number of nodes.
Definition undirected_graph.hpp:77
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 definitions.hpp:48
std::pair< edge, edge > edge_pair
Edge pair type.
Definition definitions.hpp:77
std::pair< node, node > edge
Edge type.
Definition definitions.hpp:75
uint32_t node
Node type.
Definition definitions.hpp:51
std::vector< node > neighbourhood
List of nodes.
Definition definitions.hpp:79