48#include <lal/basic_types.hpp>
49#include <lal/graphs/directed_graph.hpp>
50#include <lal/graphs/undirected_graph.hpp>
51#include <lal/detail/data_array.hpp>
52#include <lal/detail/linear_queue.hpp>
87 std::enable_if_t< std::is_base_of_v<graphs::graph, graph_t>,
bool > =
true
108 std::is_base_of_v<graphs::directed_graph, graph_t>;
114 BFS(
const graph_t& g) noexcept :
162 void start_at(
const std::vector<node>& sources)
noexcept {
163 for (
const node& u : sources) {
234 assert(vis == 0 or vis == 1);
281 if ((not t_vis) and
m_add_node(*
this, s, t)) {
293 for (
const node& t :
m_G.get_neighbours(s)) {
303 for (
const node& t :
m_G.get_out_neighbours(s)) {
311 for (
const node& t :
m_G.get_in_neighbours(s)) {
378 if (
m_term(*
this, s)) {
break; }
Abstract graph Breadth-First Search traversal.
Definition: traversal.hpp:89
void do_traversal() noexcept
Traversal through the graph's vertices.
Definition: traversal.hpp:370
void set_visited(node u, char vis) noexcept
Set node u as visited or not.
Definition: traversal.hpp:232
void deal_with_neighbour(node s, node t, bool ltr) noexcept
Deal with a neighbour of an input node.
Definition: traversal.hpp:273
std::function< bool(const BFS< graph_t > &, node)> BFS_bool_one
One node decision function.
Definition: traversal.hpp:96
static constexpr bool is_graph_directed
Is the graph used to initiliaze the object directed?
Definition: traversal.hpp:107
void clear_queue() noexcept
Clear the memory allocated for this structure.
Definition: traversal.hpp:223
void process_neighbours(node s) noexcept
Process the neighbours of node s.
Definition: traversal.hpp:289
void reset() noexcept
Set the graph traversal to its default state.
Definition: traversal.hpp:135
BFS_bool_one m_term
graph_traversal early terminating function.
Definition: traversal.hpp:413
void set_process_current(const BFS_process_one &f) noexcept
Set the function that controls the processing of the current node.
Definition: traversal.hpp:186
const graph_t & m_G
Constant reference to the graph.
Definition: traversal.hpp:386
std::function< bool(const BFS< graph_t > &, node, node)> BFS_bool_two
Two nodes decision function.
Definition: traversal.hpp:98
std::function< void(const BFS< graph_t > &, node, node, bool)> BFS_process_two
Two nodes processing function.
Definition: traversal.hpp:94
std::function< void(const BFS< graph_t > &, node)> BFS_process_one
Single node processing function.
Definition: traversal.hpp:92
linear_queue< node > m_queue
The structure of the traversal.
Definition: traversal.hpp:389
void set_terminate(const BFS_bool_one &f) noexcept
Set the function that controls the termination of the loop.
Definition: traversal.hpp:179
BFS(const graph_t &g) noexcept
Constructor.
Definition: traversal.hpp:114
bool all_visited() const noexcept
Have all nodes been visited?
Definition: traversal.hpp:245
void set_node_add_default() noexcept
Set the default value of m_add_node.
Definition: traversal.hpp:197
void set_terminate_default() noexcept
Set the default value of m_term.
Definition: traversal.hpp:176
void start_at(node source) noexcept
Start traversal at a given node.
Definition: traversal.hpp:152
void set_node_add(const BFS_bool_two &f) noexcept
Set the function that controls when a node is to be added to the queue.
Definition: traversal.hpp:200
bool m_use_rev_edges
In directed graphs, traverse edges in the reverse direction.
Definition: traversal.hpp:403
bool node_was_visited(node u) const noexcept
Returns whether or not node u has been visited.
Definition: traversal.hpp:242
void set_process_neighbour(const BFS_process_two &f) noexcept
Set the function that controls the processing of the current neighbour.
Definition: traversal.hpp:193
data_array< char > m_vis
The set of visited nodes.
Definition: traversal.hpp:392
void clear_visited() noexcept
Sets all nodes to not visited.
Definition: traversal.hpp:216
const graph_t & get_graph() const noexcept
Returns a constant reference to the graph.
Definition: traversal.hpp:250
~BFS() noexcept=default
Destructor.
const data_array< char > & get_visited() const noexcept
Return visited nodes information.
Definition: traversal.hpp:253
void set_process_visited_neighbours(bool v) noexcept
Should the algorithm call the neighbour processing function for already visited neighbours?
Definition: traversal.hpp:208
void start_at(const std::vector< node > &sources) noexcept
Start the traversal at every given node.
Definition: traversal.hpp:162
bool m_proc_vis_neighs
Should the traversal process previously-visitied neighbours?
Definition: traversal.hpp:394
BFS_bool_two m_add_node
graph_traversal node addition function.
Definition: traversal.hpp:443
void set_process_current_default() noexcept
Set the default value of m_proc_cur.
Definition: traversal.hpp:183
void set_use_rev_edges(bool use) noexcept
Set whether the traversal can use reversed edges.
Definition: traversal.hpp:173
void set_process_neighbour_default() noexcept
Set the default value of m_proc_neigh.
Definition: traversal.hpp:190
BFS_process_two m_proc_neigh
graph_traversal neighbour node processing function.
Definition: traversal.hpp:434
BFS_process_one m_proc_cur
graph_traversal node processing function.
Definition: traversal.hpp:422
Simple array-like fixed-size queue.
Definition: linear_queue.hpp:69
T && pop() noexcept
Pops the first element of the queue.
Definition: linear_queue.hpp:98
void reset() noexcept
Makes the queue usable again.
Definition: linear_queue.hpp:131
std::size_t size() const noexcept
Returns the size of the queue.
Definition: linear_queue.hpp:121
void push(const T &v) noexcept
Insert a new element to the queue.
Definition: linear_queue.hpp:79
void init(std::size_t n) noexcept
Initializes the queue to hold n elements.
Definition: linear_queue.hpp:72
Main namespace of the library.
Definition: basic_types.hpp:50
uint64_t node
Node type. See Node / Vertex page for further details.
Definition: basic_types.hpp:53
Wrapper of a C array for autmatic deallocation of memory.
Definition: data_array.hpp:59
void fill(const T &v) noexcept
Assign the same value to every element in the data.
Definition: data_array.hpp:263
T * end() noexcept
Non-constant raw pointer to last+1 element.
Definition: data_array.hpp:293
T * begin() noexcept
Non-constant raw pointer to first element.
Definition: data_array.hpp:291