Naming conventions...
3 *template <Graph, T, Heap=FibHeap, LengthMap=Graph::EdgeMap<T> >
7 *Dijkstra(Graph G, LengthMap length)
14 *T dist(Node v) : After run(s) was run, it returns the distance from s to v.
15 * Returns T() if v is not reachable from s.
17 *Edge pred(Node v) : After run(s) was run, it returns the last
18 * edge of a shortest s-v path. It is INVALID for s and for
19 * the nodes not reachable from s.
21 *bool reached(Node v) : After run(s) was run, it is true iff v is
26 #ifndef HUGO_DIJKSTRA_H
27 #define HUGO_DIJKSTRA_H
34 template <typename Graph, typename T,
35 typename Heap=FibHeap<typename Graph::Node, T,
36 typename Graph::NodeMap<int> >,
37 typename LengthMap=typename Graph::EdgeMap<T> >
39 typedef typename Graph::Node Node;
40 typedef typename Graph::NodeIt NodeIt;
41 typedef typename Graph::Edge Edge;
42 typedef typename Graph::OutEdgeIt OutEdgeIt;
45 const LengthMap& length;
46 typename Graph::NodeMap<Edge> predecessor;
47 typename Graph::NodeMap<T> distance;
49 typename Graph::NodeMap<bool> reach;
50 //typename Graph::NodeMap<int> reach;
55 The distance of the nodes is 0.
57 Dijkstra(Graph& _G, LengthMap& _length) : G(_G),
58 length(_length), predecessor(_G), distance(_G), reach(_G) { }
64 for ( G.first(u) ; G.valid(u) ; G.next(u) ) {
65 predecessor.set(u,INVALID);
71 typename Graph::NodeMap<bool> scanned(G,false);
72 //typename Graph::NodeMap<int> scanned(G,false);
73 typename Graph::NodeMap<int> heap_map(G,-1);
80 while ( !heap.empty() ) {
83 T oldvalue=heap.get(v);
85 distance.set(v, oldvalue);
89 for( G.first(e,v); G.valid(e); G.next(e)) {
95 heap.push(w,oldvalue+length[e]);
97 } else if ( oldvalue+length[e] < heap.get(w) ) {
99 heap.decrease(w, oldvalue+length[e]);
111 return predecessor[v];
114 bool reached(Node v) {