74# ifndef BIDIRECTIONAL_BFS_H
75# define BIDIRECTIONAL_BFS_H
114template <AlephGraph
GT,
131 static constexpr size_t INF_DIST = std::numeric_limits<size_t>::max();
144#define BIBFS_INFO(p) (static_cast<BFS_Info *>(NODE_COOKIE(p)))
145#define BIBFS_DIR(p) (BIBFS_INFO(p)->dir)
146#define BIBFS_FWD_PARENT(p) (BIBFS_INFO(p)->fwd_parent)
147#define BIBFS_BCK_PARENT(p) (BIBFS_INFO(p)->bck_parent)
148#define BIBFS_FWD_PARC(p) (BIBFS_INFO(p)->fwd_parent_arc)
149#define BIBFS_BCK_PARC(p) (BIBFS_INFO(p)->bck_parent_arc)
150#define BIBFS_FWD_DIST(p) (BIBFS_INFO(p)->fwd_dist)
151#define BIBFS_BCK_DIST(p) (BIBFS_INFO(p)->bck_dist)
188 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
193 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
195 auto p = it.get_curr();
208 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
210 auto p = it.get_curr();
253 template <
template <
typename,
class>
class Itor>
267 auto arc = it.get_current_arc();
319 <<
"Bidirectional_BFS: inconsistent forward parent chain";
321 <<
"Bidirectional_BFS: missing forward parent arc";
325 for (
auto it =
fwd_arcs.get_it(); it.has_curr(); it.next())
326 path.
append(it.get_curr());
332 <<
"Bidirectional_BFS: inconsistent backward parent chain";
334 <<
"Bidirectional_BFS: missing backward parent arc";
468#undef BIBFS_FWD_PARENT
469#undef BIBFS_BCK_PARENT
#define BIBFS_FWD_DIST(p)
#define BIBFS_BCK_PARENT(p)
#define BIBFS_BCK_DIST(p)
#define BIBFS_FWD_PARENT(p)
#define BIBFS_BCK_PARC(p)
#define BIBFS_FWD_PARC(p)
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
C++20 concepts for the protocol shared by graph algorithms.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
RAII guard for BiBFS initialization and cleanup.
BiBFS_Init_Guard(const BiBFS_Init_Guard &)=delete
Deleted copy constructor.
BiBFS_Init_Guard & operator=(const BiBFS_Init_Guard &)=delete
Deleted copy assignment.
Bidirectional_BFS * owner
~BiBFS_Init_Guard() noexcept
Destructor.
BiBFS_Init_Guard(BiBFS_Init_Guard &&)=delete
Deleted move constructor.
BiBFS_Init_Guard(Bidirectional_BFS &__owner, const GT &__g) noexcept
Constructor.
Bidirectional BFS for finding shortest unweighted paths.
Path< GT > operator()(const GT &g, Node *start, Node *end)
Finds shortest path (operator interface returning path).
void build_path(const GT &g, Node *start, Node *meeting, Node *end, Path< GT > &path)
Node *& parent_ref(Node *p, const int dir) noexcept
bool is_seen(Node *p, const int dir) const noexcept
static constexpr int UNSEEN
static constexpr int BACKWARD
void mark_seen(Node *p, const int dir) noexcept
void cleanup(const GT &g)
void expand_frontier(const GT &g, DynListQueue< Node * > &frontier, const int my_dir, const int other_dir, size_t &best_len, Node *&best_meeting)
static constexpr size_t INF_DIST
static constexpr int FORWARD
bool find_path(const GT &g, Node *start, Node *end, Path< GT > &path)
Finds the shortest unweighted path between start and end.
Arc *& parent_arc_ref(Node *p, const int dir) noexcept
void set_dist(Node *p, const int dir, const size_t d) noexcept
Bidirectional_BFS(SA __sa=SA())
Constructor.
Bidirectional_BFS(SA &__sa)
Constructor with lvalue arc filter.
size_t get_dist(Node *p, const int dir) const noexcept
bool operator()(const GT &g, Node *start, Node *end, Path< GT > &path)
Finds shortest path (operator interface with path output).
Dynamic queue of elements of generic type T based on single linked list.
T & put(const T &data)
The type of element.
T get()
Remove the oldest item of the queue.
Doubly-linked list (defined in tpl_dynList.H).
T & insert(const T &item)
Graph_Node< Node_Info > Node
The graph type.
Graph_Arc< Arc_Info > Arc
The node class type.
void empty()
Clean the path: all the nodes and arc are removed.
void set_graph(const GT &__g, Node *start_node=nullptr)
Set the graph of the path.
void append(Arc *arc)
Append an arc to the path.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
#define NODE_COOKIE(p)
Return the node cookie
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
Itor lower_bound(Itor beg, Itor end, const T &value)
Find lower bound in a sorted range.
and
Check uniqueness with explicit hash + equality functors.
static std::atomic< bool > init
Default filter for filtered iterators on arcs.
Filtered iterator of adjacent arcs of a node.
Dynamic queue implementation based on linked lists.
Utility algorithms and operations for graphs.