|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Base class providing common infrastructure for shortest path algorithms. More...
#include <shortest_path_common.H>
Classes | |
| struct | Arc_Info |
| Information stored in arc cookies for painting version. More... | |
| struct | Destroy_Arc |
| Arc cleanup for painting version. More... | |
| struct | Destroy_Node |
| Node cleanup for painting version. More... | |
| struct | Destroy_Tree_Arc |
| Arc cleanup and mapping for tree-building version. More... | |
| struct | Destroy_Tree_Node |
| Node cleanup and mapping for tree-building version. More... | |
| struct | Get_Potential_Arc |
| Functor to get arc potential for heap ordering. More... | |
| struct | Heap_Info |
| Functor to access heap node handle from node cookie. More... | |
| struct | Initialize_Arc |
| Arc initialization for painting version. More... | |
| struct | Initialize_Node |
| Node initialization for painting version. More... | |
| struct | Initialize_Tree_Arc |
| Arc initialization for tree-building version. More... | |
| struct | Initialize_Tree_Node |
| Node initialization for tree-building version. More... | |
| struct | Node_Info |
| Information stored in node cookies for painting version. More... | |
| struct | Total |
| Distance totalizer class for path copying. More... | |
| struct | Tree_Arc_Info |
| Extended arc info with tree arc mapping. More... | |
| struct | Tree_Node_Info |
| Extended node info with tree node mapping. More... | |
Public Types | |
| using | Heap = HeapT< GT, Get_Potential_Arc, Heap_Info > |
Public Member Functions | |
| Shortest_Path_Base (Distance dist=Distance(), SA __sa=SA()) | |
| Default constructor. | |
| bool | has_computation () const noexcept |
| Check if a computation has been performed. | |
| bool | is_painted () const noexcept |
| Check if the graph has been painted. | |
| GT::Node * | get_start_node () const noexcept |
| Get the start node of the last computation. | |
| 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. | |
| Distance::Distance_Type | get_min_path (typename GT::Node *end, Path< GT > &path) |
| Extracts a shortest path to end from a previously painted graph. | |
| Distance::Distance_Type | copy_painted_min_paths_tree (GT &g, GT &tree) |
| Extracts the painted shortest paths tree and puts it in tree. | |
| Distance::Distance_Type | get_min_path (const GT &tree, typename GT::Node *end, Path< GT > &path) |
| Extracts path from tree to end node. | |
Protected Member Functions | |
| template<class IN , class IA > | |
| void | init (const GT &g, typename GT::Node *start) |
| Initialize algorithm state. | |
| template<class DN , class DA > | |
| void | uninit () |
| Cleanup algorithm state. | |
| Distance::Distance_Type | checked_add (const typename Distance::Distance_Type &a, const typename Distance::Distance_Type &b) const |
| Checked addition to prevent integer overflow. | |
Protected Attributes | |
| SA | sa |
| Arc filter. | |
| Get_Potential_Arc | get_pot |
| Potential accessor. | |
| Heap | heap |
| Priority queue. | |
| bool | painted = false |
| Whether graph has been painted. | |
| GT * | ptr_g = nullptr |
| Pointer to the graph. | |
| GT::Node * | s = nullptr |
| Start node. | |
Base class providing common infrastructure for shortest path algorithms.
This template class encapsulates shared functionality between Dijkstra's algorithm, A*, and similar shortest path algorithms. It provides:
| GT | Graph type. |
| Distance | Distance accessor functor. |
| Itor | Arc iterator template. |
| SA | Arc filter for iterators. |
| HeapT | Priority queue template. |
Definition at line 164 of file shortest_path_common.H.
| using Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::Heap = HeapT<GT, Get_Potential_Arc, Heap_Info> |
Definition at line 354 of file shortest_path_common.H.
|
inline |
Default constructor.
| dist | Distance functor for arc weights. |
| __sa | Arc filter for iterators. |
Definition at line 431 of file shortest_path_common.H.
|
inlineprotected |
Checked addition to prevent integer overflow.
| a | First operand. |
| b | Second operand. |
| std::overflow_error | If overflow would occur. |
Definition at line 415 of file shortest_path_common.H.
References Aleph::shortest_path_detail::checked_add().
Referenced by Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::compute_min_paths_tree(), Aleph::Dijkstra_Min_Paths< GT, Distance, Itor, SA, HeapT >::compute_min_paths_tree(), Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::compute_partial_min_paths_tree(), Aleph::Dijkstra_Min_Paths< GT, Distance, Itor, SA, HeapT >::compute_partial_min_paths_tree(), Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::compute_partial_path(), Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::paint_min_paths_tree(), Aleph::Dijkstra_Min_Paths< GT, Distance, Itor, SA, HeapT >::paint_min_paths_tree(), Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::paint_partial_min_paths_tree(), Aleph::Dijkstra_Min_Paths< GT, Distance, Itor, SA, HeapT >::paint_partial_min_paths_tree(), and Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::paint_partial_path().
|
inline |
Extracts the painted shortest paths tree and puts it in tree.
| [in] | g | The previously painted graph. |
| [out] | tree | The graph where the spanning tree will be copied. |
| bad_alloc | If there is not enough memory. |
| domain_error | If the graph has not been previously painted. |
Definition at line 566 of file shortest_path_common.H.
References ah_domain_error_if, Aleph::maps(), and Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::painted.
|
inline |
Gets the accumulated distance to a node after painting.
After painting the graph with a shortest path tree, this method traverses the path from the start node to the given node and computes the total distance.
| [in] | node | The destination node. |
| domain_error | If the graph has not been painted or if node is not reachable from the start node. |
Definition at line 480 of file shortest_path_common.H.
References ah_domain_error_if, IS_ARC_VISITED, IS_NODE_VISITED, Aleph::maps(), NODE_COOKIE, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::painted, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::s, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::sa, and Aleph::Spanning_Tree.
|
inlinenoexcept |
Get the graph of the last computation.
Definition at line 460 of file shortest_path_common.H.
References Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::ptr_g.
|
inline |
Extracts path from tree to end node.
| [in] | tree | The spanning tree built by compute_min_paths_tree. |
| [in] | end | Destination node in the original graph. |
| [out] | path | Path where result will be stored (in original graph). |
Definition at line 585 of file shortest_path_common.H.
References ah_domain_error_if, Aleph::Path< GT >::append(), Aleph::Path< GT >::empty(), LocateFunctions< Container, Type >::get_it(), Aleph::Path< GT >::init(), Aleph::maps(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::ptr_g, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::s, and Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::sa.
|
inline |
Extracts a shortest path to end from a previously painted graph.
Takes a graph on which shortest paths have been painted and extracts the shortest path to end, storing it in path.
| [in] | end | Destination node of the path. |
| [out] | path | Path where the shortest path will be stored. |
| bad_alloc | If there is not enough memory. |
| domain_error | If the graph has not been previously painted. |
Definition at line 531 of file shortest_path_common.H.
References ah_domain_error_if, Aleph::maps(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::painted, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::ptr_g, and Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::s.
|
inlinenoexcept |
Get the start node of the last computation.
Definition at line 455 of file shortest_path_common.H.
References Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::s.
|
inlinenoexcept |
Check if a computation has been performed.
Definition at line 445 of file shortest_path_common.H.
References Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::ptr_g.
|
inlineprotected |
Initialize algorithm state.
| IN | Node initializer functor type. |
| IA | Arc initializer functor type. |
| g | The graph. |
| start | The starting node. |
Definition at line 380 of file shortest_path_common.H.
References Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::heap, Aleph::maps(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::ptr_g, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::s, and Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::sa.
|
inlinenoexcept |
Check if the graph has been painted.
Definition at line 450 of file shortest_path_common.H.
References Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::painted.
|
inlineprotected |
Cleanup algorithm state.
| DN | Node destroyer functor type. |
| DA | Arc destroyer functor type. |
Definition at line 397 of file shortest_path_common.H.
References Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::heap, Aleph::maps(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::ptr_g, and Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::sa.
|
protected |
Potential accessor.
Definition at line 362 of file shortest_path_common.H.
|
protected |
Priority queue.
Definition at line 363 of file shortest_path_common.H.
Referenced by Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::init(), and Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::uninit().
|
protected |
Whether graph has been painted.
Definition at line 364 of file shortest_path_common.H.
Referenced by Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::copy_painted_min_paths_tree(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_distance(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_min_path(), and Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::is_painted().
|
protected |
Pointer to the graph.
Definition at line 365 of file shortest_path_common.H.
Referenced by Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_graph(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_min_path(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_min_path(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::has_computation(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::init(), and Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::uninit().
|
protected |
Start node.
Definition at line 366 of file shortest_path_common.H.
Referenced by Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_distance(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_min_path(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_min_path(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_start_node(), and Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::init().
|
protected |
Arc filter.
Definition at line 361 of file shortest_path_common.H.
Referenced by Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_distance(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_min_path(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::init(), and Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::uninit().