83# ifndef ZERO_ONE_BFS_H
84# define ZERO_ONE_BFS_H
87# include <type_traits>
144 std::numeric_limits<Distance_Type>::max();
165#define ZOB_INFO(p) (static_cast<Node_Info *>(NODE_COOKIE(p)))
166#define ZOB_PNTD(p) (static_cast<Painted_Info *>(NODE_COOKIE(p)))
167#define ZOB_DIST(p) (ZOB_INFO(p)->dist)
168#define ZOB_PARENT(p) (ZOB_INFO(p)->parent)
169#define ZOB_PARENT_ARC(p) (ZOB_INFO(p)->parent_arc)
175 auto item = it.get_curr();
177 auto info = item.second;
190 auto item = it.get_curr();
192 auto info = item.second;
254 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
256 auto p = it.get_curr();
260 for (
typename GT::Arc_Iterator it(g); it.has_curr(); it.next())
265 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
267 auto p = it.get_curr();
298 for (
typename GT::Node_Iterator it(*
ptr_g); it.has_curr(); it.next())
300 auto p = it.get_curr();
307 for (
auto it = pending.
get_it(); it.has_curr(); it.next())
308 delete it.get_curr().second;
314 for (
auto it = pending.
get_it(); it.has_curr(); it.next())
316 auto item = it.get_curr();
318 auto pinfo = item.second;
326 if (
ptr_g ==
nullptr)
332 for (
typename GT::Node_Iterator it(*
ptr_g); it.has_curr(); it.next())
334 auto p = it.get_curr();
338 for (
typename GT::Arc_Iterator it(*
ptr_g); it.has_curr(); it.next())
352 auto curr =
deque.remove_first();
355 if (end !=
nullptr and curr == end)
360 auto arc = it.get_current_arc();
365 <<
"Zero_One_BFS: arc weight must be 0 or 1, got " <<
w;
449 if (
ptr_g !=
nullptr)
482 <<
"node is not reachable from start";
485 auto dist_val =
ZOB_PNTD(node)->dist;
491 for (
auto curr = node; curr !=
s;)
494 auto parent =
pinfo->parent;
495 if (parent ==
nullptr)
500 auto arc = it.get_current_arc();
542 for (
auto curr = end; curr !=
s;)
544 auto parent =
ZOB_PNTD(curr)->parent;
545 if (parent ==
nullptr)
551 auto arc = it.get_current_arc();
566 for (
auto it =
arcs.get_it(); it.has_curr(); it.next())
567 path.
append(it.get_curr());
596 if (
ptr_g !=
nullptr)
#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.
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.
Dynamic singly linked list with functional programming support.
T & insert(const T &item)
T & append(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.
void release_owned_painted_infos() noexcept
~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
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.
DynList< std::pair< Node *, Painted_Info * > > owned_painted_infos
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)
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
DynArray< Graph::Arc * > arcs
#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.
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.
Stores parent and distance after painting for O(1) access.
Dynamic doubly linked list implementation.
Utility algorithms and operations for graphs.