3 *template <Graph, T, Heap=FibHeap>
8 *Dijkstra(Graph G, NodeIt s, Graph::EdgeMap<T> length)
16 * The following function should be used after run() was already run.
19 *T dist(NodeIt v) : returns the distance from s to v.
20 * It is 0 if v is not reachable from s.
23 *EdgeIt pred(NodeIt v) : returns the last edge
24 * of a shortest s-v path. Returns an invalid iterator
25 * if v=s or v is not reachable from s.
28 *bool reach(NodeIt v) : true iff v is reachable from s
39 template <typename Graph, typename T,
40 typename Heap=FibHeap<typename Graph::NodeIt, T,
41 typename Graph::NodeMap<int> > >
43 typedef typename Graph::NodeIt NodeIt;
44 typedef typename Graph::EdgeIt EdgeIt;
45 typedef typename Graph::OutEdgeIt OutEdgeIt;
49 typename Graph::NodeMap<EdgeIt> predecessor;
50 typename Graph::NodeMap<T> distance;
51 typename Graph::EdgeMap<T>& length;
52 typename Graph::NodeMap<bool> reached;
57 The distance of the nodes is 0.
59 Dijkstra(Graph& _G, NodeIt const _s,
60 typename Graph::EdgeMap<T>& _length) :
61 G(_G), s(_s), predecessor(G), distance(G),
62 length(_length), reached(G, false) { }
67 typename Graph::NodeMap<bool> scanned(G, false);
68 typename Graph::NodeMap<int> heap_map(G,-1);
75 while ( !heap.empty() ) {
78 T oldvalue=heap.get(v);
79 distance.set(v, oldvalue);
83 for( G.getFirst(e,v); G.valid(e); G.next(e)) {
86 if ( !scanned.get(w) ) {
87 if ( !reached.get(w) ) {
89 heap.push(w,oldvalue+length.get(e));
92 } else if ( oldvalue+length.get(e) < heap.get(w) ) {
94 heap.decrease(w, oldvalue+length.get(e));
104 return distance.get(v);
108 EdgeIt pred(NodeIt v) {
109 if ( v!=s ) return predecessor.get(v);
110 else return EdgeIt();
114 bool reach(NodeIt v) {
115 return reached.get(v);