# HG changeset patch # User alpar # Date 1089108468 0 # Node ID 2d87cefb35b22f6e5ec4946b7794229ea41ea5e9 # Parent 80164e89dcbc037f5145116b92879ce34b1a474d I moved run() into the body of class Dijkstra, because Doxygen handles external member function definitions very poorly. diff -r 80164e89dcbc -r 2d87cefb35b2 src/hugo/dijkstra.h --- a/src/hugo/dijkstra.h Tue Jul 06 09:52:04 2004 +0000 +++ b/src/hugo/dijkstra.h Tue Jul 06 10:07:48 2004 +0000 @@ -84,7 +84,7 @@ ///Initialize maps - ///\todo Error if \c G or are \c NULL. What about \c length + ///\todo Error if \c G or are \c NULL. What about \c length? ///\todo Better memory allocation (instead of new). void init_maps() { @@ -196,7 +196,64 @@ return *this; } - void run(Node s); + ///Runs %Dijkstra algorithm from node \c s. + + ///This method runs the %Dijkstra algorithm from a root node \c s + ///in order to + ///compute the + ///shortest path to each node. The algorithm computes + ///- The shortest path tree. + ///- The distance of each node from the root. + + void run(Node s) { + + init_maps(); + + for ( NodeIt u(*G) ; G->valid(u) ; G->next(u) ) { + predecessor->set(u,INVALID); + pred_node->set(u,INVALID); + } + + typename GR::template NodeMap heap_map(*G,-1); + + typedef Heap, + std::less > + HeapType; + + HeapType heap(heap_map); + + heap.push(s,0); + + while ( !heap.empty() ) { + + Node v=heap.top(); + ValueType oldvalue=heap[v]; + heap.pop(); + distance->set(v, oldvalue); + + + for(OutEdgeIt e(*G,v); G->valid(e); G->next(e)) { + Node w=G->bNode(e); + + switch(heap.state(w)) { + case HeapType::PRE_HEAP: + heap.push(w,oldvalue+(*length)[e]); + predecessor->set(w,e); + pred_node->set(w,v); + break; + case HeapType::IN_HEAP: + if ( oldvalue+(*length)[e] < heap[w] ) { + heap.decrease(w, oldvalue+(*length)[e]); + predecessor->set(w,e); + pred_node->set(w,v); + } + break; + case HeapType::POST_HEAP: + break; + } + } + } + } ///The distance of a node from the root. @@ -263,66 +320,6 @@ // IMPLEMENTATIONS // ********************************************************************** - ///Runs %Dijkstra algorithm from node the root. - - ///This method runs the %Dijkstra algorithm from a root node \c s - ///in order to - ///compute the - ///shortest path to each node. The algorithm computes - ///- The shortest path tree. - ///- The distance of each node from the root. - template class Heap > - void Dijkstra::run(Node s) { - - init_maps(); - - for ( NodeIt u(*G) ; G->valid(u) ; G->next(u) ) { - predecessor->set(u,INVALID); - pred_node->set(u,INVALID); - } - - typename GR::template NodeMap heap_map(*G,-1); - - typedef Heap, - std::less > - HeapType; - - HeapType heap(heap_map); - - heap.push(s,0); - - while ( !heap.empty() ) { - - Node v=heap.top(); - ValueType oldvalue=heap[v]; - heap.pop(); - distance->set(v, oldvalue); - - - for(OutEdgeIt e(*G,v); G->valid(e); G->next(e)) { - Node w=G->bNode(e); - - switch(heap.state(w)) { - case HeapType::PRE_HEAP: - heap.push(w,oldvalue+(*length)[e]); - predecessor->set(w,e); - pred_node->set(w,v); - break; - case HeapType::IN_HEAP: - if ( oldvalue+(*length)[e] < heap[w] ) { - heap.decrease(w, oldvalue+(*length)[e]); - predecessor->set(w,e); - pred_node->set(w,v); - } - break; - case HeapType::POST_HEAP: - break; - } - } - } - } - /// @} } //END OF NAMESPACE HUGO