78 : m_directed(directed), m_maxGap(maxGap), m_et(et) {
101 std::function<T(
node)> heuristic = [](
node) {
111 m_distance.
init(graph);
112 m_predecessor = &predecessor;
113 m_predecessor->
init(graph);
114 m_heuristic = heuristic;
116 m_folded.
init(graph,
false);
120 m_distance[source] = 0;
121 (*m_predecessor)[target] =
nullptr;
122 m_queue->
push(source, 0);
125 while(!m_queue->
empty()) {
137 OGDF_ASSERT((*m_predecessor)[target] ==
nullptr || validatePath(source, target));
139 return m_distance[target];
145 bool validatePath(
const node source,
const node target) {
150 for(
node v = target; v != source;) {
154 edge e = (*m_predecessor)[v];
171 edge e = adj->theEdge();
172 if(!m_directed || e->
target() != v) {
174 T distanceW = m_distance[v] + (*m_cost)[e];
176 m_distance[w] = distanceW;
177 (*m_predecessor)[w] = e;
178 T priority = (T)(m_distance[w] + m_maxGap *
m_heuristic(w));
181 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.