48#include <lal/basic_types.hpp>
49#include <lal/graphs/directed_graph.hpp>
50#include <lal/graphs/undirected_graph.hpp>
51#include <lal/detail/array.hpp>
52#include <lal/detail/queue_array.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) {
251 assert(vis == 0 or vis == 1);
260 return m_vis[u] == 1;
269 [[nodiscard]]
const graph_t&
get_graph() const noexcept {
return m_G; }
304 const bool add_node =
320 for (
const node& t :
m_G.get_neighbors(s)) {
330 for (
const node& t :
m_G.get_out_neighbors(s)) {
338 for (
const node& t :
m_G.get_in_neighbors(s)) {
Abstract graph Breadth-First Search traversal.
Definition traversal.hpp:89
std::function< void(const BFS< graph_t > &, const node, const node, const bool)> BFS_process_two
Two nodes processing function.
Definition traversal.hpp:94
void process_neighbors(const node s) noexcept
Process the neighbors of node s.
Definition traversal.hpp:316
void do_traversal() noexcept
Traversal through the graph's vertices.
Definition traversal.hpp:396
bool m_process_visited_neighbors
Should the traversal process previously-visitied neighbors?
Definition traversal.hpp:424
void start_at(const node source) noexcept
Start traversal at a given node.
Definition traversal.hpp:152
BFS_bool_one m_terminate
Early terminating function.
Definition traversal.hpp:443
static constexpr bool is_graph_directed
Is the graph used to initiliaze the object directed?
Definition traversal.hpp:107
bool m_is_add_node_set
Is function m_add_node set?
Definition traversal.hpp:481
void clear_queue() noexcept
Clear the memory allocated for this structure.
Definition traversal.hpp:240
std::function< bool(const BFS< graph_t > &, const node)> BFS_bool_one
One node decision function.
Definition traversal.hpp:96
void reset() noexcept
Set the graph traversal to its default state.
Definition traversal.hpp:135
void set_visited(const node u, const char vis) noexcept
Set node u as visited or not.
Definition traversal.hpp:249
std::function< bool(const BFS< graph_t > &, const node, const node, const bool)> BFS_bool_two
Two nodes decision function.
Definition traversal.hpp:98
void set_process_current(const BFS_process_one &f) noexcept
Set the function that controls the processing of the current node.
Definition traversal.hpp:192
const graph_t & m_G
Constant reference to the graph.
Definition traversal.hpp:416
void set_terminate(const BFS_bool_one &f) noexcept
Set the function that controls the termination of the loop.
Definition traversal.hpp:181
BFS(const graph_t &g) noexcept
Constructor.
Definition traversal.hpp:114
bool m_is_process_current_set
Is function m_process_current set?
Definition traversal.hpp:456
bool all_visited() const noexcept
Have all nodes been visited?
Definition traversal.hpp:264
void deal_with_neighbour(const node s, const node t, const bool ltr) noexcept
Deal with a neighbour of an input node.
Definition traversal.hpp:292
BFS_process_one m_process_current
Node processing function.
Definition traversal.hpp:454
void set_node_add_default() noexcept
Set the default value of m_add_node.
Definition traversal.hpp:209
void set_terminate_default() noexcept
Set the default value of m_terminate.
Definition traversal.hpp:176
void set_process_visited_neighbors(const bool v) noexcept
Should the algorithm call the neighbour processing function for already visited neighbors?
Definition traversal.hpp:224
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:214
bool m_use_rev_edges
In directed graphs, traverse edges in the reverse direction.
Definition traversal.hpp:433
std::function< void(const BFS< graph_t > &, const node)> BFS_process_one
Single node processing function.
Definition traversal.hpp:92
bool node_was_visited(const node u) const noexcept
Returns whether or not node u has been visited.
Definition traversal.hpp:259
void set_process_neighbour(const BFS_process_two &f) noexcept
Set the function that controls the processing of the current neighbour.
Definition traversal.hpp:203
void clear_visited() noexcept
Sets all nodes to not visited.
Definition traversal.hpp:233
const graph_t & get_graph() const noexcept
Returns a constant reference to the graph.
Definition traversal.hpp:269
~BFS() noexcept=default
Destructor.
BFS_process_two m_process_neighbour
Node processing function.
Definition traversal.hpp:468
bool m_is_terminate_set
Is function m_terminate set?
Definition traversal.hpp:445
void set_use_rev_edges(const bool use) noexcept
Set whether the traversal can use reversed edges.
Definition traversal.hpp:173
bool m_is_process_neighbour_set
Is function m_process_neighbour set?
Definition traversal.hpp:470
void start_at(const std::vector< node > &sources) noexcept
Start the traversal at every given node.
Definition traversal.hpp:162
BFS_bool_two m_add_node
Node addition function.
Definition traversal.hpp:479
queue_array< node > m_queue
The structure of the traversal.
Definition traversal.hpp:419
void set_process_current_default() noexcept
Set the default value of m_process_current.
Definition traversal.hpp:187
const array< char > & get_visited() const noexcept
Return visited nodes information.
Definition traversal.hpp:272
void set_process_neighbour_default() noexcept
Set the default value of m_process_neighbour.
Definition traversal.hpp:198
array< char > m_vis
The set of visited nodes.
Definition traversal.hpp:422
Simple array-like fixed-size queue.
Definition queue_array.hpp:69
void init(const std::size_t n) noexcept
Initializes the queue to hold n elements.
Definition queue_array.hpp:72
void reset() noexcept
Makes the queue usable again.
Definition queue_array.hpp:131
std::size_t size() const noexcept
Returns the size of the queue.
Definition queue_array.hpp:121
value_t && pop() noexcept
Pops the first element of the queue.
Definition queue_array.hpp:98
void push(const value_t &v) noexcept
Insert a new element to the queue.
Definition queue_array.hpp:79
Main namespace of the library.
Definition basic_types.hpp:48
uint64_t node
Node type. See Node / Vertex page for further details.
Definition basic_types.hpp:51
Wrapper of a C array for automatic deallocation of memory.
Definition array.hpp:59
void fill(const T &v) noexcept
Assign the same value to every element in the data.
Definition array.hpp:272
T * begin() noexcept
Non-constant raw pointer to first element.
Definition array.hpp:300
T * end() noexcept
Non-constant raw pointer to last+1 element.
Definition array.hpp:302