Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT > Class Template Reference

A* algorithm for finding the shortest path between two nodes. More...

#include <AStar.H>

Inheritance diagram for Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >:
[legend]
Collaboration diagram for Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >:
[legend]

Public Member Functions

 AStar_Min_Path (Distance dist=Distance(), Heuristic __heuristic=Heuristic(), SA __sa=SA())
 Constructor.
 
GT::Node * compute_partial_path (const GT &g, typename GT::Node *start, typename GT::Node *end, GT &tree)
 Computes the shortest path from start to end using A*.
 
bool paint_partial_path (const GT &g, typename GT::Node *start, typename GT::Node *end)
 Paints the shortest path from start to end on the graph using A*.
 
Distance::Distance_Type find_path (const GT &g, typename GT::Node *start, typename GT::Node *end, Path< GT > &path)
 Finds the shortest path from start to end using A*.
 
GT::Node * compute_path (const GT &g, typename GT::Node *start, typename GT::Node *end, GT &tree)
 Alias for compute_partial_path (backward compatibility).
 
bool paint_path (const GT &g, typename GT::Node *start, typename GT::Node *end)
 Alias for paint_partial_path (backward compatibility).
 
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.
 
void compute_partial_min_paths_tree (const GT &g, typename GT::Node *start, typename GT::Node *end, GT &tree)
 Computes the partial spanning tree from start to end (without a heuristic).
 
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 (without heuristic).
 
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 (without heuristic).
 
Distance::Distance_Type find_min_path (const GT &g, typename GT::Node *start, typename GT::Node *end, Path< GT > &min_path)
 Computes shortest path by painting the graph (without heuristic).
 
void operator() (const GT &g, typename GT::Node *s, GT &tree)
 Computes the spanning tree of all shortest paths.
 
Distance::Distance_Type operator() (const GT &g, typename GT::Node *s, typename GT::Node *e, Path< GT > &path)
 Finds shortest path using A* heuristic.
 
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 get_min_path (const GT &tree, typename GT::Node *end, Path< GT > &path)
 Extracts path from tree to end node.
 
Distance::Distance_Type copy_painted_min_paths_tree (GT &g, GT &tree)
 Extracts the painted shortest paths tree and puts it in tree.
 
- Public Member Functions inherited from Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >
 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.
 

Private Types

using Base = Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >
 

Private Member Functions

void check_heuristic_admissibility (typename GT::Node *node, typename GT::Node *goal, const typename Distance::Distance_Type &actual_cost)
 

Private Attributes

Heuristic heuristic
 
bool validate_heuristic = true
 
SA sa
 Arc filter.
 
Heap heap
 Priority queue.
 
bool painted
 Whether graph has been painted.
 
GT * ptr_g
 Pointer to the graph.
 
GT::Node * s
 Start node.
 

Additional Inherited Members

- Public Types inherited from Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >
using Heap = HeapT< GT, Get_Potential_Arc, Heap_Info >
 
- Protected Member Functions inherited from Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >
template<class IN , class IA >
void init (const GT &g, typename GT::Node *start)
 Initialize algorithm state.
 
template<class DN , class DA >
auto uninit_on_exit ()
 Returns a guard that calls uninit() when it goes out of scope.
 
template<class DN , class DA >
void uninit ()
 Cleanup algorithm state.
 
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().
 
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, or end if it is given.
 
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 inherited from Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >
SA sa
 Arc filter.
 
Distance distance
 Arc weights.
 
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.
 
bool beyond_max = false
 A sum of the painting went beyond max()
 
bool leave_out_beyond_max = false
 Whether a painting leaves out without throwing the nodes whose distance does not fit.
 

Detailed Description

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
class Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >

A* algorithm for finding the shortest path between two nodes.

This class implements the A* algorithm to find the shortest path from a source node start to a destination node end in a weighted graph.

A* uses a heuristic function h(n) that estimates the cost from node n to the goal. The algorithm expands nodes in order of f(n) = g(n) + h(n) where g(n) is the actual cost from start to n.

For the algorithm to find optimal paths, the heuristic must be admissible (never overestimate the true cost) and consistent (satisfy h(n) <= d(n,m) + h(m) for any edge n->m).

This class also provides Dijkstra-compatible methods (compute_min_paths_tree, paint_min_paths_tree) that use zero heuristic for computing all shortest paths from a source.

Method Categories

A* Methods (with heuristic, for single-target search):

Dijkstra Methods (no heuristic, for multi-target search):

The "partial" methods stop as soon as the target node is reached, while "complete" methods explore all reachable nodes.

The class receives the following template parameters:

  1. GT: graph type.
  2. Distance<GT>: class reading the weight.
  3. Heuristic<GT, Distance>: heuristic functor.
  4. Itor<GT, SA>: arc iterator type (defaults to Node_Arc_Iterator).
  5. SA: arc filter for internal iterators.
  6. HeapT<GT, Distance, Access>: priority-queue adapter.
Note
To use a Fibonacci heap, pass ArcFibonacciHeap as HeapT.
Reusability: This class can be reused for multiple searches. Each call to find_path(), compute_*(), or paint_*() clears state.
If a method throws (for lack of memory, an overflow of the distances or an exception of Distance, Heuristic or the filter), the cookies it set are freed and the graph can be used again; a tree being built keeps the part already built. With a filter that can throw (see nothrow_arc_filter_v), a method marks with the bit Min the arcs to which it gives a cookie, and frees them by that mark, without calling the filter again; the mark stays.
With an integral Distance_Type, a tentative sum beyond max() does not throw by itself: std::overflow_error comes only when the distance to a node that the start reaches, or to the end, does not fit. The methods with a heuristic leave out an arc whose g + h does not fit: if the heuristic does not overestimate, no path through it fits, and with one that overestimates, they can throw for an end whose distance fits.
Warning
This class is not thread-safe. Concurrent calls require external synchronization.
Negative weights: This algorithm does NOT support graphs with negative edge weights. Use Bellman-Ford for such graphs. Behavior with negative weights is undefined.
Inadmissible heuristics: If the heuristic overestimates (violates admissibility), A* may return suboptimal paths. In debug mode, validation checks are performed when possible.
See also
Dijkstra_Min_Paths Floyd_All_Shortest_Paths Bellman_Ford_Min_Paths

Definition at line 174 of file AStar.H.

Member Typedef Documentation

◆ Base

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
using Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::Base = Shortest_Path_Base<GT, Distance, Itor, SA, HeapT>
private

Definition at line 177 of file AStar.H.

Constructor & Destructor Documentation

◆ AStar_Min_Path()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::AStar_Min_Path ( Distance  dist = Distance(),
Heuristic  __heuristic = Heuristic(),
SA  __sa = SA() 
)
inline

Constructor.

Parameters
[in]distDistance functor for arc weights.
[in]__heuristicHeuristic functor for estimating remaining cost.
[in]__saArc filter for iterators.

Definition at line 244 of file AStar.H.

Member Function Documentation

◆ check_heuristic_admissibility()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
void Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::check_heuristic_admissibility ( typename GT::Node *  node,
typename GT::Node *  goal,
const typename Distance::Distance_Type &  actual_cost 
)
inlineprivate

◆ compute_min_paths_tree()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
GT::Node * Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::compute_min_paths_tree ( const GT &  g,
typename GT::Node *  start,
GT &  tree 
)
inline

Computes the spanning tree of ALL shortest paths from the start node.

This method uses zero heuristic, making it equivalent to Dijkstra's algorithm. Use this when you need the complete shortest paths tree from a source to all reachable nodes.

Parameters
[in]gThe graph.
[in]startThe starting node for all shortest paths.
[out]treeThe spanning tree of all shortest paths starting from start, mapped via cookies to the graph g.
Returns
Pointer to the tree node corresponding to the start node.
Note
For disconnected graphs, the resulting tree spans only the component reachable from start.
Exceptions
bad_allocIf there is not enough memory.
domain_errorIf start is nullptr or g is empty.

Definition at line 556 of file AStar.H.

References AACC, AARC_DIST, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::add_if_fits(), ah_domain_error_if, Aleph::and, APOT, ARC_BITS, ATREEARC, ATREENODE, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::beyond_max, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::check_beyond_max(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::checked_add(), Aleph::clear_graph(), GTNodeCommon< NodeInfo >::get_info(), GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::heap, Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), IS_ARC_VISITED, IS_NODE_VISITED, NODE_BITS, NODE_COOKIE, Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::sa, and Aleph::Spanning_Tree.

Referenced by main(), Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::operator()(), TEST(), TEST(), TEST_F(), and TEST_F().

◆ compute_partial_min_paths_tree()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
void Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::compute_partial_min_paths_tree ( const GT &  g,
typename GT::Node *  start,
typename GT::Node *  end,
GT &  tree 
)
inline

◆ compute_partial_path()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
GT::Node * Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::compute_partial_path ( const GT &  g,
typename GT::Node *  start,
typename GT::Node *  end,
GT &  tree 
)
inline

Computes the shortest path from start to end using A*.

Builds a partial spanning tree containing the shortest path from start to end, stopping as soon as end is reached.

Parameters
[in]gThe graph.
[in]startThe starting node.
[in]endThe destination node.
[out]treeThe partial tree containing the path, mapped to g.
Returns
Pointer to tree node corresponding to end, or nullptr if no path exists.
Exceptions
bad_allocIf there is not enough memory.
domain_errorIf start or end is nullptr, or g is empty.

Definition at line 280 of file AStar.H.

References AACC, AARC_DIST, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::add_if_fits(), ah_domain_error_if, Aleph::and, APOT, ARC_BITS, ATREEARC, ATREENODE, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::beyond_max, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::check_beyond_max(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::checked_add(), Aleph::clear_graph(), GTNodeCommon< NodeInfo >::get_info(), GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), h, Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::heap, Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::heuristic, Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), IS_ARC_VISITED, IS_NODE_VISITED, NODE_BITS, NODE_COOKIE, Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::sa, and Aleph::Spanning_Tree.

Referenced by Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::compute_path(), and TEST().

◆ compute_path()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
GT::Node * Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::compute_path ( const GT &  g,
typename GT::Node *  start,
typename GT::Node *  end,
GT &  tree 
)
inline

Alias for compute_partial_path (backward compatibility).

Definition at line 523 of file AStar.H.

References Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::compute_partial_path().

Referenced by TEST_F().

◆ copy_painted_min_paths_tree()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
Distance::Distance_Type Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::copy_painted_min_paths_tree ( GT &  g,
GT &  tree 
)
inline

Extracts the painted shortest paths tree and puts it in tree.

Only the nodes that the painting reaches are copied, as compute_min_paths_tree() does. The nodes and arcs of g and of tree are mapped through their cookies; the cookies of the nodes that are not reached are null. Since the cookies held the painting, the painting cannot be used afterwards and is_painted() becomes false.

Parameters
[in]gThe previously painted graph.
[out]treeThe graph where the spanning tree will be copied.
Returns
The total distance of the spanning tree.
Exceptions
bad_allocIf there is not enough memory.
domain_errorIf the graph has not been previously painted.

Definition at line 863 of file shortest_path_common.H.

Referenced by TEST(), TEST(), and TEST_F().

◆ find_min_path()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
Distance::Distance_Type Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::find_min_path ( const GT &  g,
typename GT::Node *  start,
typename GT::Node *  end,
Path< GT > &  min_path 
)
inline

Computes shortest path by painting the graph (without heuristic).

Dijkstra-compatible interface.

Parameters
[in]gThe graph.
[in]startThe starting node.
[in]endThe destination node.
[out]min_pathThe shortest path.
Returns
The total cost, or max value if no path.
Exceptions
bad_allocIf there is not enough memory.

Definition at line 924 of file AStar.H.

References Aleph::Path< GT >::empty(), Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::get_min_path(), and Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::paint_partial_min_paths_tree().

Referenced by main(), TEST(), and TEST_F().

◆ find_path()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
Distance::Distance_Type Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::find_path ( const GT &  g,
typename GT::Node *  start,
typename GT::Node *  end,
Path< GT > &  path 
)
inline

Finds the shortest path from start to end using A*.

This is the recommended entry point for A* with heuristic. It paints the graph and extracts the path in one call.

Parameters
[in]gThe graph.
[in]startThe starting node.
[in]endThe destination node.
[out]pathThe shortest path (empty if no path exists).
Returns
The total cost, or max value if no path exists.
Exceptions
bad_allocIf there is not enough memory.

Definition at line 505 of file AStar.H.

References Aleph::Path< GT >::empty(), Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::get_min_path(), and Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::paint_partial_path().

Referenced by main(), Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::operator()(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ get_distance()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
Distance::Distance_Type Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_distance ( typename GT::Node *  node)
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.

Parameters
[in]nodeThe destination node.
Returns
The accumulated distance from start to node.
Exceptions
domain_errorIf the graph has not been painted or if node is not reachable from the start node.
Note
Time complexity: O(path_length)

Definition at line 730 of file shortest_path_common.H.

Referenced by TEST(), TEST(), and TEST_F().

◆ get_graph()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
GT * Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_graph ( ) const
inlinenoexcept

Get the graph of the last computation.

Returns
Pointer to the graph, or nullptr if no computation done.

Definition at line 710 of file shortest_path_common.H.

Referenced by TEST_F().

◆ get_min_path() [1/2]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
Distance::Distance_Type Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_min_path ( const GT &  tree,
typename GT::Node *  end,
Path< GT > &  path 
)
inline

Extracts path from tree to end node.

Parameters
[in]treeThe spanning tree built by compute_min_paths_tree.
[in]endDestination node (in original graph).
[out]pathPath where result will be stored (in original graph), made of the arcs of g that those of the tree map to.
Returns
The total cost of the path, by the distance of the arcs of g.
Exceptions
domain_errorIf the minimum paths tree has not been computed, or end is not in the tree, nor reached in it from the start.
bad_allocIf there is not enough memory.

Definition at line 901 of file shortest_path_common.H.

◆ get_min_path() [2/2]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
Distance::Distance_Type Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_min_path ( typename GT::Node *  end,
Path< GT > &  path 
)
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.

Parameters
[in]endDestination node of the path.
[out]pathPath where the shortest path will be stored.
Returns
The total cost of the path.
Exceptions
bad_allocIf there is not enough memory.
domain_errorIf the graph has not been previously painted.

Definition at line 781 of file shortest_path_common.H.

Referenced by Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::find_min_path(), Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::find_path(), main(), TEST(), TEST_F(), TEST_F(), and TEST_F().

◆ get_start_node()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
GT::Node * Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::get_start_node ( ) const
inlinenoexcept

Get the start node of the last computation.

Returns
Pointer to the start node, or nullptr if no computation done.

Definition at line 705 of file shortest_path_common.H.

Referenced by TEST_F(), and TEST_F().

◆ has_computation()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
bool Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::has_computation ( ) const
inlinenoexcept

Check if a computation has been performed.

Returns
true if a graph has been processed, false otherwise.

Definition at line 690 of file shortest_path_common.H.

Referenced by TEST_F(), and TEST_F().

◆ is_painted()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
bool Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::is_painted ( ) const
inlinenoexcept

Check if the graph has been painted.

Every computation resets the bits and cookies of the previous one, so only a painting that ended normally can be used.

Returns
true if the last computation was a painting and ended normally, false otherwise.

Definition at line 700 of file shortest_path_common.H.

Referenced by TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ operator()() [1/2]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
void Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::operator() ( const GT &  g,
typename GT::Node *  s,
GT &  tree 
)
inline

Computes the spanning tree of all shortest paths.

Dijkstra-compatible operator interface.

Parameters
[in]gThe graph.
[in]sThe starting node.
[out]treeThe spanning tree.

Definition at line 948 of file AStar.H.

References Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::compute_min_paths_tree(), and Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::s.

◆ operator()() [2/2]

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
Distance::Distance_Type Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::operator() ( const GT &  g,
typename GT::Node *  s,
typename GT::Node *  e,
Path< GT > &  path 
)
inline

Finds shortest path using A* heuristic.

Parameters
[in]gThe graph.
[in]sThe starting node.
[in]eThe destination node.
[out]pathThe shortest path.
Returns
The total cost.

Definition at line 961 of file AStar.H.

References Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::find_path(), and Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::s.

◆ paint_min_paths_tree()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
void Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::paint_min_paths_tree ( const GT &  g,
typename GT::Node *  start 
)
inline

◆ paint_partial_min_paths_tree()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
bool Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::paint_partial_min_paths_tree ( const GT &  g,
typename GT::Node *  start,
typename GT::Node *  end 
)
inline

◆ paint_partial_path()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
bool Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::paint_partial_path ( const GT &  g,
typename GT::Node *  start,
typename GT::Node *  end 
)
inline

Paints the shortest path from start to end on the graph using A*.

This is the memory-efficient version that marks the path directly on the graph using spanning tree bits.

Parameters
[in]gThe graph.
[in]startThe starting node.
[in]endThe destination node.
Returns
true if a path was found, false otherwise.
Exceptions
bad_allocIf there is not enough memory.
domain_errorIf start or end is nullptr, or g is empty.

Definition at line 398 of file AStar.H.

References AACC, AARC_DIST, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::add_if_fits(), ah_domain_error_if, Aleph::and, APARENT, APOT, ARC_BITS, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::beyond_max, Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::check_beyond_max(), Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::checked_add(), GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), h, Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::heap, Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::heuristic, IS_ARC_VISITED, IS_NODE_VISITED, NODE_BITS, Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::painted, Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::sa, and Aleph::Spanning_Tree.

Referenced by Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::find_path(), and Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::paint_path().

◆ paint_path()

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
bool Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::paint_path ( const GT &  g,
typename GT::Node *  start,
typename GT::Node *  end 
)
inline

Alias for paint_partial_path (backward compatibility).

Definition at line 530 of file AStar.H.

References Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::paint_partial_path().

Referenced by TEST(), TEST_F(), and TEST_F().

Member Data Documentation

◆ heap

◆ heuristic

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
Heuristic Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::heuristic
private

◆ painted

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
bool Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::painted
private

◆ ptr_g

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
GT* Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::ptr_g
private

Pointer to the graph.

Definition at line 435 of file shortest_path_common.H.

◆ s

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
GT::Node* Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::s
private

◆ sa

◆ validate_heuristic

template<AlephGraph GT, ArcDistance< GT > Distance = Dft_Dist<GT>, class Heuristic = Zero_Heuristic<GT, Distance>, template< typename, class > class Itor = Node_Arc_Iterator, ArcFilter< GT > SA = Dft_Show_Arc<GT>, template< class, class, class > class HeapT = ArcHeap>
bool Aleph::AStar_Min_Path< GT, Distance, Heuristic, Itor, SA, HeapT >::validate_heuristic = true
private

The documentation for this class was generated from the following file: