48#ifndef SHORTEST_PATH_COMMON_H
49#define SHORTEST_PATH_COMMON_H
67#define SP_NODE_INFO(p) (static_cast<typename Shortest_Path_Base::Node_Info*>(NODE_COOKIE(p)))
70#define SP_TREE_NODE_INFO(p) (static_cast<typename Shortest_Path_Base::Tree_Node_Info*>(NODE_COOKIE(p)))
73#define SP_ACC(p) (SP_NODE_INFO(p)->dist)
76#define SP_HEAPNODE(p) (SP_NODE_INFO(p)->heap_node)
79#define SP_PARENT(p) (SP_NODE_INFO(p)->ret_node)
82#define SP_TREENODE(p) (SP_TREE_NODE_INFO(p)->tree_node)
85#define SP_ARC_INFO(p) (static_cast<typename Shortest_Path_Base::Arc_Info*>(ARC_COOKIE(p)))
88#define SP_TREE_ARC_INFO(p) (static_cast<typename Shortest_Path_Base::Tree_Arc_Info*>(ARC_COOKIE(p)))
91#define SP_POT(p) (SP_ARC_INFO(p)->pot)
94#define SP_TREEARC(p) (SP_TREE_ARC_INFO(p)->tree_arc)
97#define SP_ARC_DIST(p) (Distance()(p))
105namespace shortest_path_detail
122 if constexpr (std::is_integral_v<T>)
125 <<
"Integer overflow in distance addition: " << a <<
" + " << b;
128 <<
"Integer underflow in distance addition: " << a <<
" + " << b;
161 template <
typename,
class>
class Itor,
163 template <
class,
class,
class>
class HeapT>
379 template <
class IN,
class IA>
396 template <
class DN,
class DA>
489 <<
"node is not reachable from start";
493 for (
auto curr = node; curr !=
s;)
496 if (parent ==
nullptr)
501 auto arc = it.get_current_arc_ne();
502 auto tgt = it.get_tgt_node();
601 auto tree_node = it.get_curr();
620#undef SP_TREE_NODE_INFO
626#undef SP_TREE_ARC_INFO
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
_Graph_Node Node
The graph type.
_Graph_Arc Arc
The node class type.
void empty()
Clean the path: all the nodes and arc are removed.
void init(Node *start_node)
Set the first node of a path.
void append(Arc *arc)
Append an arc to the path.
Base class providing common infrastructure for shortest path algorithms.
Shortest_Path_Base(Distance dist=Distance(), SA __sa=SA())
Default constructor.
Distance::Distance_Type get_min_path(typename GT::Node *end, Path< GT > &path)
Extracts a shortest path to end from a previously painted graph.
Get_Potential_Arc get_pot
Potential accessor.
Distance::Distance_Type copy_painted_min_paths_tree(GT &g, GT &tree)
Extracts the painted shortest paths tree and puts it in tree.
bool is_painted() const noexcept
Check if the graph has been painted.
Distance::Distance_Type get_min_path(const GT &tree, typename GT::Node *end, Path< GT > &path)
Extracts path from tree to end node.
bool has_computation() const noexcept
Check if a computation has been performed.
Distance::Distance_Type checked_add(const typename Distance::Distance_Type &a, const typename Distance::Distance_Type &b) const
Checked addition to prevent integer overflow.
GT * get_graph() const noexcept
Get the graph of the last computation.
Distance::Distance_Type get_distance(typename GT::Node *node)
Gets the accumulated distance to a node after painting.
GT::Node * get_start_node() const noexcept
Get the start node of the last computation.
void uninit()
Cleanup algorithm state.
GT * ptr_g
Pointer to the graph.
bool painted
Whether graph has been painted.
HeapT< GT, Get_Potential_Arc, Heap_Info > Heap
void init(const GT &g, typename GT::Node *start)
Initialize algorithm state.
static void map_arcs(A1 *p, A2 *q) noexcept
Map the arcs through their cookies.
void reset_bit(Node *node, int bit) const noexcept
Reset the bit of node (to zero)
static void map_nodes(N1 *p, N2 *q) noexcept
Map the nodes through their cookies.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
List_Graph< Graph_Node< int >, Graph_Arc< int > > GT
#define ARC_COOKIE(p)
Return the arc cookie
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
#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.
T checked_add(const T &a, const T &b)
Safely add two distance values with overflow checking.
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
DynList< T > maps(const C &c, Op op)
Classic map operation.
#define SP_TREE_ARC_INFO(p)
Convert arc cookie to Tree_Arc_Info pointer.
#define SP_TREE_NODE_INFO(p)
Convert node cookie to Tree_Node_Info pointer.
#define SP_ARC_INFO(p)
Convert arc cookie to Arc_Info pointer.
#define SP_PARENT(p)
Access parent pointer from node cookie.
#define SP_POT(p)
Access arc potential from arc cookie.
#define SP_TREEARC(p)
Access tree arc mapping from arc cookie.
#define SP_NODE_INFO(p)
Convert node cookie to Node_Info pointer.
#define SP_HEAPNODE(p)
Access heap node handle from node cookie.
#define SP_TREENODE(p)
Access tree node mapping from node cookie.
Arc of graph implemented with double-linked adjacency lists.
Filter of painter arcs with that are set the Spanning_Tree control bit.
Information stored in arc cookies for painting version.
Distance::Distance_Type pot
Arc potential (priority)
Arc cleanup for painting version.
void operator()(const GT &, typename GT::Arc *ga) const noexcept
Node cleanup for painting version.
void operator()(const GT &, typename GT::Node *p) const noexcept
Arc cleanup and mapping for tree-building version.
void operator()(const GT &, typename GT::Arc *ga) const noexcept
Node cleanup and mapping for tree-building version.
void operator()(const GT &, typename GT::Node *p) const noexcept
Functor to get arc potential for heap ordering.
Distance::Distance_Type operator()(typename GT::Arc *a) const noexcept
Get_Potential_Arc(Distance &d) noexcept
Get_Potential_Arc()=default
Functor to access heap node handle from node cookie.
void *& operator()(typename GT::Node *p) const noexcept
Arc initialization for painting version.
void operator()(const GT &g, typename GT::Arc *a) const
Node initialization for painting version.
void operator()(const GT &g, typename GT::Node *p) const
Arc initialization for tree-building version.
void operator()(const GT &g, typename GT::Arc *a) const
Node initialization for tree-building version.
void operator()(const GT &g, typename GT::Node *p) const
Information stored in node cookies for painting version.
Distance::Distance_Type dist
Accumulated distance from start.
void * heap_node
Handle in priority queue.
void * ret_node
Parent node (for backtracking)
Distance totalizer class for path copying.
Distance::Distance_Type dist
Extended arc info with tree arc mapping.
GT::Arc * tree_arc
Corresponding arc in spanning tree.
Extended node info with tree node mapping.
GT::Node * tree_node
Corresponding node in spanning tree.
Path finding algorithms in graphs.
Generic graph and digraph implementations.