83# ifndef ZERO_ONE_BFS_H
84# define ZERO_ONE_BFS_H
89# include <type_traits>
127template <AlephGraph
GT,
146 std::numeric_limits<Distance_Type>::max();
160#define ZOB_INFO(p) (static_cast<Node_Info *>(NODE_COOKIE(p)))
161#define ZOB_DIST(p) (ZOB_INFO(p)->dist)
162#define ZOB_PARENT(p) (ZOB_INFO(p)->parent)
163#define ZOB_PARENT_ARC(p) (ZOB_INFO(p)->parent_arc)
169 auto item = it.get_curr();
171 auto info = item.second;
200 :
owner(&__owner),
g(&__g)
232 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
234 auto p = it.get_curr();
238 for (
typename GT::Arc_Iterator it(g); it.has_curr(); it.next())
243 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
245 auto p = it.get_curr();
275 auto [p, info] = it.get_curr();
277 NODE_COUNTER(p) = info->dist ==
Inf ? 0 :
static_cast<long>(info->dist);
285 if (
ptr_g ==
nullptr)
290 for (
typename GT::Node_Iterator it(*
ptr_g); it.has_curr(); it.next())
292 auto p = it.get_curr();
296 for (
typename GT::Arc_Iterator it(*
ptr_g); it.has_curr(); it.next())
308 while (not
deque.is_empty())
310 auto curr =
deque.remove_first();
313 if (end !=
nullptr and curr == end)
316 for (Itor<GT, SA> it(curr,
sa); it.has_curr(); it.next())
318 auto arc = it.get_current_arc();
323 <<
"Zero_One_BFS: arc weight must be 0 or 1, got " <<
w;
325 auto new_dist = curr_dist +
w;
330 if (prev_parent_arc !=
nullptr)
371 delete it.get_curr().second;
441 <<
"node is not reachable from start";
475 for (
auto curr = end; curr !=
s;)
478 if (parent ==
nullptr)
482 for (Itor<GT, SA> it(parent,
sa); it.has_curr(); it.next())
484 auto arc = it.get_current_arc();
499 for (
auto it =
arcs.get_it(); it.has_curr(); it.next())
500 path.
append(it.get_curr());
#define ZOB_PARENT_ARC(p)
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_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
Default distance accessor for arc weights.
Dynamic doubly linked list with O(1) size and bidirectional access.
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.
RAII guard for Zero_One_BFS initialization and cleanup.
ZOB_Init_Guard(const ZOB_Init_Guard &)=delete
Deleted copy constructor.
void commit() noexcept
Commits the operation, preventing cleanup on destruction.
ZOB_Init_Guard & operator=(const ZOB_Init_Guard &)=delete
Deleted copy assignment.
~ZOB_Init_Guard() noexcept
Destructor.
ZOB_Init_Guard(ZOB_Init_Guard &&)=delete
Deleted move constructor.
ZOB_Init_Guard(Zero_One_BFS &__owner, const GT &__g) noexcept
Constructor.
0-1 BFS algorithm for shortest paths in graphs with 0/1 weights.
~Zero_One_BFS() noexcept
Destructor.
bool is_painted() const noexcept
Check if a computation has been performed.
void release_owned_node_infos() noexcept
static constexpr Distance_Type Inf
void uninit_paint() noexcept
GT * get_graph() const noexcept
Get the graph of the last computation.
Distance_Type operator()(const GT &g, Node *start, Node *end, Path< GT > &path)
Computes shortest path (operator interface).
Distance_Type get_min_path(Node *end, Path< GT > &path)
Extracts a shortest path from a previously painted graph.
void run_bfs(const GT &g, Node *start, Node *end=nullptr)
typename Distance::Distance_Type Distance_Type
DynList< std::pair< Node *, Node_Info * > > owned_node_infos
Zero_One_BFS(Distance dist=Distance(), SA __sa=SA())
Constructor.
Distance_Type find_min_path(const GT &g, Node *start, Node *end, Path< GT > &path)
Computes the shortest path from start to end.
void reset_state_after_failure() noexcept
void paint_min_paths_tree(const GT &g, Node *start)
Paints the shortest paths tree on the graph from start.
Distance_Type get_distance(Node *node)
Gets the accumulated distance to a node after painting.
Node * get_start_node() const noexcept
Get the start node of the last computation.
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.
void reset_bit(Node *node, int bit) const noexcept
Reset the bit of node (to zero)
DynArray< Graph::Arc * > arcs
#define NODE_COUNTER(p)
Get the counter of a node.
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
#define ARC_BITS(p)
Return the control bits of arc p.
#define NODE_COOKIE(p)
Return the node cookie
#define IS_ARC_VISITED(p, bit)
Determine whether the bit field is or not set to one.
#define NODE_BITS(p)
Get the control bits of a node.
Main namespace for Aleph-w library functions.
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 doubly linked list implementation.
Utility algorithms and operations for graphs.