78 : m_directed(directed)
104 std::function<T(
node)> heuristic = [](
node) {
114 m_distance.
init(graph);
115 m_predecessor = &predecessor;
116 m_predecessor->
init(graph);
117 m_heuristic = heuristic;
119 m_folded.
init(graph,
false);
123 m_distance[source] = 0;
124 (*m_predecessor)[target] =
nullptr;
125 m_queue->
push(source, 0);
128 while(!m_queue->
empty()) {
140 OGDF_ASSERT((*m_predecessor)[target] ==
nullptr || validatePath(source, target));
142 return m_distance[target];
148 bool validatePath(
const node source,
const node target)
const {
153 for(
node v = target; v != source;) {
157 edge e = (*m_predecessor)[v];
174 edge e = adj->theEdge();
175 if(!m_directed || e->
target() != v) {
177 T distanceW = m_distance[v] + (*m_cost)[e];
179 m_distance[w] = distanceW;
180 (*m_predecessor)[w] = e;
181 T priority = (T)(m_distance[w] + m_maxGap *
m_heuristic(w));
184 m_queue->
push(w, priority);
node target() const
Returns the target node of the edge.
void pop()
Removes the topmost element from the queue.
NodeArray< T > m_distance
void investigateNode(const node v)
std::enable_if< std::is_integral< T >::value, bool >::type equal(const T &x, const T &y) const
Compare if x is EQUAL to y for integral types.
NodeArray< edge > * m_predecessor
Data type for general directed graphs (adjacency list representation).
void push(const E &element, const P &priority)
Adds a new element to the queue.
void init()
Reinitializes the array. Associates the array with no graph.
T call(const Graph &graph, const EdgeArray< T > &cost, const node source, const node target, NodeArray< edge > &predecessor, std::function< T(node)> heuristic=[](node) { return T(0);})
Computes the shortests path between source and target.
AStarSearch(const bool directed=false, const double maxGap=1, const EpsilonTest &et=EpsilonTest())
Initializes a new A* search algorithm.
const EdgeArray< T > * m_cost
Dynamic arrays indexed with edges.
void clear()
Removes all elements from this queue.
Prioritized queue interface wrapper for heaps.
Compare floating point numbers with epsilons and integral numbers with normal compare operators...
std::enable_if< std::is_integral< T >::value, bool >::type less(const T &x, const T &y) const
Compare if x is LESS than y for integral types.
std::function< T(node)> m_heuristic
const E & topElement() const
Returns the topmost element in the queue.
void decrease(const E &element, const P &priority)
Decreases the priority of the given element.
Class for the representation of edges.
Class for the representation of nodes.
Priority queue interface wrapping various heaps.
node opposite(node v) const
Returns the adjacent node different from v.
NodeArray< bool > m_folded
Includes declaration of graph class.
bool empty() const
Checks whether the queue is empty.
A-Star informed search algorithm.
adjEntry succ() const
Returns the successor in the adjacency list.
const Graph * graphOf() const
Returns a pointer to the associated graph.
bool contains(const E &element) const
Returns whether this queue contains that key.
The namespace for all OGDF objects.
std::enable_if< std::is_integral< T >::value, bool >::type geq(const T &x, const T &y) const
Compare if x is GEQ to y for integral types.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Class for adjacency list elements.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.