74# ifndef BIDIRECTIONAL_BFS_H
75# define BIDIRECTIONAL_BFS_H
129 static constexpr size_t INF_DIST = std::numeric_limits<size_t>::max();
142#define BIBFS_INFO(p) (static_cast<BFS_Info *>(NODE_COOKIE(p)))
143#define BIBFS_DIR(p) (BIBFS_INFO(p)->dir)
144#define BIBFS_FWD_PARENT(p) (BIBFS_INFO(p)->fwd_parent)
145#define BIBFS_BCK_PARENT(p) (BIBFS_INFO(p)->bck_parent)
146#define BIBFS_FWD_PARC(p) (BIBFS_INFO(p)->fwd_parent_arc)
147#define BIBFS_BCK_PARC(p) (BIBFS_INFO(p)->bck_parent_arc)
148#define BIBFS_FWD_DIST(p) (BIBFS_INFO(p)->fwd_dist)
149#define BIBFS_BCK_DIST(p) (BIBFS_INFO(p)->bck_dist)
186 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
191 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
193 auto p = it.get_curr();
206 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
208 auto p = it.get_curr();
251 template <
template <
typename,
class>
class Itor>
265 auto arc = it.get_current_arc();
317 <<
"Bidirectional_BFS: inconsistent forward parent chain";
319 <<
"Bidirectional_BFS: missing forward parent arc";
323 for (
auto it =
fwd_arcs.get_it(); it.has_curr(); it.next())
324 path.
append(it.get_curr());
330 <<
"Bidirectional_BFS: inconsistent backward parent chain";
332 <<
"Bidirectional_BFS: missing backward parent arc";
466#undef BIBFS_FWD_PARENT
467#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.
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.
Dynamic singly linked list with functional programming support.
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
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Itor lower_bound(Itor beg, Itor end, const T &value)
Find lower bound in a sorted range.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
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.