110template <AlephGraph
GT,
114 template <
class,
class,
class>
class HeapT =
ArcHeap>
135#define DNassert(p) (static_cast<Node_Info*>(NODE_COOKIE(p)))
136#define TREENODE(p) (static_cast<Tree_Node_Info*>(NODE_COOKIE(p))->tree_node)
137#define ACC(p) (DNassert(p)->dist)
138#define HEAPNODE(p) (DNassert(p)->heap_node)
139#define DAassert(p) (static_cast<Arc_Info*>(ARC_COOKIE(p)))
140#define ARC_DIST(p) (this->distance(p))
141#define TREEARC(p) (static_cast<Tree_Arc_Info*>(ARC_COOKIE(p))->tree_arc)
142#define POT(p) (DAassert(p)->pot)
190 this->
template init<Initialize_Tree_Node, Initialize_Tree_Arc>(g, start);
192 this->
template uninit_on_exit<Destroy_Tree_Node, Destroy_Tree_Arc>();
201 for (Itor<GT, SA> it(start,
sa); it.has_curr(); it.next_ne())
203 auto arc = it.get_current_arc_ne();
205 heap.put_arc(arc, it.get_tgt_node());
212 auto garc =
heap.get_min_arc();
226 std::swap(gsrc, gtgt);
234 auto tarc = tree.
insert_arc(tsrc, ttgt, garc->get_info());
238 const auto& acc =
ACC(gtgt);
240 for (Itor<GT, SA> it(gtgt,
sa); it.has_curr(); it.next_ne())
242 auto arc = it.get_current_arc_ne();
246 auto tgt = it.get_tgt_node();
251 heap.put_arc(arc, tgt);
281 this->
template init<Initialize_Tree_Node, Initialize_Tree_Arc>(g, start);
283 this->
template uninit_on_exit<Destroy_Tree_Node, Destroy_Tree_Arc>();
291 for (Itor<GT, SA> it(start,
sa); it.has_curr(); it.next_ne())
293 auto arc = it.get_current_arc_ne();
295 heap.put_arc(arc, it.get_tgt_node());
302 auto garc =
heap.get_min_arc();
316 std::swap(gsrc, gtgt);
329 const auto& acc =
ACC(gtgt);
331 for (Itor<GT, SA> it(gtgt,
sa); it.has_curr(); it.next_ne())
333 auto arc = it.get_current_arc_ne();
337 auto tgt = it.get_tgt_node();
342 heap.put_arc(arc, tgt);
369 bool ret_val =
false;
370 this->
template init<Initialize_Node, Initialize_Arc>(g, start);
371 auto guard = this->
template uninit_on_exit<Destroy_Node, Destroy_Arc>();
382 for (Itor<GT, SA> it(start,
sa); it.has_curr(); it.next_ne())
384 auto arc = it.get_current_arc_ne();
386 heap.put_arc(arc, it.get_tgt_node());
392 while (tn < n
and not
heap.is_empty())
394 auto garc =
heap.get_min_arc();
422 const auto& acc =
ACC(tgt);
424 for (Itor<GT, SA> it(tgt,
sa); it.has_curr(); it.next_ne())
426 auto a = it.get_current_arc_ne();
430 auto t = it.get_tgt_node();
460 this->
template init<Initialize_Node, Initialize_Arc>(g, start);
461 auto guard = this->
template uninit_on_exit<Destroy_Node, Destroy_Arc>();
466 for (Itor<GT, SA> it(start,
sa); it.has_curr(); it.next_ne())
468 auto arc = it.get_current_arc_ne();
470 heap.put_arc(arc, it.get_tgt_node());
476 while (tn < n
and not
heap.is_empty())
478 auto garc =
heap.get_min_arc();
500 const auto& acc =
ACC(tgt);
502 for (Itor<GT, SA> it(tgt,
sa); it.has_curr(); it.next_ne())
504 auto a = it.get_current_arc_ne();
508 auto t = it.get_tgt_node();
544 return std::numeric_limits<typename Distance::Distance_Type>::max();
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.
Standard functor implementations and comparison objects.
Arc heap for graph algorithms.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Default distance accessor for arc weights.
Spanning tree calculation of all shortest paths from a given node according to Dijkstra's algorithm.
void operator()(const GT &g, typename GT::Node *s, GT &tree)
Computes the spanning tree of all shortest paths from a given node according to Dijkstra's algorithm.
Distance::Distance_Type get_min_path(typename GT::Node *end, Path< GT > &path)
Extracts a shortest path to end from a previously painted graph.
void paint_min_paths_tree(const GT &g, typename GT::Node *start)
Paints on graph g the spanning tree of all shortest paths starting from start.
Distance::Distance_Type operator()(const GT &g, typename GT::Node *s, typename GT::Node *e, Path< GT > &path)
See find_min_path().
Distance::Distance_Type find_min_path(const GT &g, typename GT::Node *start, typename GT::Node *end, Path< GT > &min_path)
Computes the shortest path between start and end by painting the graph.
GT::Node * compute_min_paths_tree(const GT &g, typename GT::Node *start, GT &tree)
Computes the spanning tree of all shortest paths from the start node.
bool painted
Whether graph has been painted.
void compute_partial_min_paths_tree(const GT &g, typename GT::Node *start, typename GT::Node *end, GT &tree)
Computes the partial spanning tree of all shortest paths from start that contains the path from start...
bool paint_partial_min_paths_tree(const GT &g, typename GT::Node *start, typename GT::Node *end)
Paints on graph g the partial shortest paths tree starting from start and stopping when the end node ...
Dijkstra_Min_Paths(Distance dist=Distance(), SA __sa=SA())
Constructor.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
void empty()
Clean the path: all the nodes and arc are removed.
Base class providing common infrastructure for shortest path algorithms.
Distance::Distance_Type get_min_path(typename GT::Node *end, Path< GT > &path)
Extracts a shortest path to end from a previously painted graph.
void check_beyond_max(const GT &g, typename GT::Node *start, typename GT::Node *end=nullptr) const
After a painting in which a sum went beyond max(), throws if a node that start reaches was left out,...
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.
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.
bool add_if_fits(const typename Distance::Distance_Type &a, const typename Distance::Distance_Type &b, typename Distance::Distance_Type &out)
Adds a tentative distance that may go beyond max().
bool beyond_max
A sum of the painting went beyond max()
GT * ptr_g
Pointer to the graph.
bool painted
Whether graph has been painted.
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
#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
void clear_graph(GT &g)
Clean a graph: all its nodes and arcs are removed and freed.
#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.
Common utilities and base class for shortest path algorithms.
Default filter for filtered iterators on arcs.
Filtered iterator of adjacent arcs of a node.
Information stored in arc cookies for painting version.
Arc cleanup for painting version.
Node cleanup for painting version.
Arc cleanup and mapping for tree-building version.
Node cleanup and mapping for tree-building version.
Arc initialization for painting version.
Node initialization for painting version.
Arc initialization for tree-building version.
Node initialization for tree-building version.
Information stored in node cookies for painting version.
Extended arc info with tree arc mapping.
Extended node info with tree node mapping.
Array-based graph implementation.
Path finding algorithms in graphs.