Dijkstra, bin_heap, fib_heap added to the doc.
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 //Alpar: Changed the order of the parameters
35 template <typename Graph,
36 typename LengthMap=typename Graph::EdgeMap<int>,
37 typename Heap=FibHeap<typename Graph::Node,
38 typename LengthMap::ValueType,
39 typename Graph::NodeMap<int> > >
42 typedef typename LengthMap::ValueType ValueType;
45 typedef typename Graph::Node Node;
46 typedef typename Graph::NodeIt NodeIt;
47 typedef typename Graph::Edge Edge;
48 typedef typename Graph::OutEdgeIt OutEdgeIt;
51 const LengthMap& length;
52 typedef typename Graph::NodeMap<Edge> PredMap;
55 typedef typename Graph::NodeMap<Node> PredNodeMap;
56 PredNodeMap pred_node;
57 typedef typename Graph::NodeMap<ValueType> DistMap;
61 // typename Graph::NodeMap<bool> reach;
62 // //typename Graph::NodeMap<int> reach;
67 The distance of the nodes is 0.
69 Dijkstra(Graph& _G, LengthMap& _length) :
70 G(_G), length(_length), predecessor(_G), pred_node(_G), distance(_G) { }
75 ValueType dist(Node v) const { return distance[v]; }
76 Edge pred(Node v) const { return predecessor[v]; }
77 Node predNode(Node v) const { return pred_node[v]; }
79 const DistMap &distMap() const { return distance;}
80 const PredMap &predMap() const { return predecessor;}
81 const PredNodeMap &predNodeMap() const { return pred_node;}
83 // bool reached(Node v) { return reach[v]; }
84 ///\warning \c s is not reached!
86 bool reached(Node v) { return G.valid(predecessor[v]); }
93 template <typename Graph, typename LengthMap, typename Heap >
94 void Dijkstra<Graph,LengthMap,Heap>::run(Node s) {
97 for ( G.first(u) ; G.valid(u) ; G.next(u) ) {
98 predecessor.set(u,INVALID);
99 // If a node is unreacheable, then why should be the dist=0?
100 // distance.set(u,0);
101 // reach.set(u,false);
104 //We don't need it at all.
106 // typename Graph::NodeMap<bool> scanned(G,false);
107 // //typename Graph::NodeMap<int> scanned(G,false);
108 typename Graph::NodeMap<int> heap_map(G,-1);
113 // reach.set(s, true);
115 while ( !heap.empty() ) {
118 ValueType oldvalue=heap[v];
120 distance.set(v, oldvalue);
122 for(OutEdgeIt e(G,v); G.valid(e); G.next(e)) {
125 switch(heap.state(w)) {
127 // reach.set(w,true);
128 heap.push(w,oldvalue+length[e]);
129 predecessor.set(w,e);
133 if ( oldvalue+length[e] < heap[w] ) {
134 heap.decrease(w, oldvalue+length[e]);
135 predecessor.set(w,e);
139 case Heap::POST_HEAP:
146 } //END OF NAMESPACE HUGO