[Lemon-commits] [lemon_svn] alpar: r321 - hugo/trunk/src/work/alpar/dijkstra
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:38:44 CET 2006
Author: alpar
Date: Sun Mar 21 15:59:51 2004
New Revision: 321
Modified:
hugo/trunk/src/work/alpar/dijkstra/bin_heap.hh
hugo/trunk/src/work/alpar/dijkstra/dijkstra.h
hugo/trunk/src/work/alpar/dijkstra/fib_heap.h
Log:
Some doc added
Modified: hugo/trunk/src/work/alpar/dijkstra/bin_heap.hh
==============================================================================
--- hugo/trunk/src/work/alpar/dijkstra/bin_heap.hh (original)
+++ hugo/trunk/src/work/alpar/dijkstra/bin_heap.hh Sun Mar 21 15:59:51 2004
@@ -65,6 +65,7 @@
namespace hugo {
+ /// A Binary Heap implementation.
template <typename Key, typename Val, typename KeyIntMap,
typename Compare = std::less<Val> >
class BinHeap {
Modified: hugo/trunk/src/work/alpar/dijkstra/dijkstra.h
==============================================================================
--- hugo/trunk/src/work/alpar/dijkstra/dijkstra.h (original)
+++ hugo/trunk/src/work/alpar/dijkstra/dijkstra.h Sun Mar 21 15:59:51 2004
@@ -32,14 +32,37 @@
namespace hugo {
//Alpar: Changed the order of the parameters
+
+ ///Dijkstra algorithm class.
+
+ ///This class provides an efficient implementation of Dijkstra algorithm.
+ ///The edge lengths are passed to the algorithm using a
+ ///\ref ReadMapSkeleton "readable map",
+ ///so it is easy to change it to any kind of length.
+ ///
+ ///The type of the length is determined by the \c ValueType of the length map.
+ ///
+ ///It is also posible to change the underlying priority heap.
+ ///
+ ///\param Graph The graph type the algorithm runs on.
+ ///\param LengthMap This read-only EdgeMap determines the
+ ///lengths of the edges. It is read once for each edge, so the map
+ ///may involve in relatively time consuming process to compute the edge
+ ///length if it is necessary.
+ ///\param Heap The heap type used by the Dijkstra
+ ///algorithm. The default
+ ///is using \ref BinHeap "binary heap".
template <typename Graph,
typename LengthMap=typename Graph::EdgeMap<int>,
- typename Heap=FibHeap<typename Graph::Node,
+ typename Heap=BinHeap<typename Graph::Node,
typename LengthMap::ValueType,
typename Graph::NodeMap<int> > >
class Dijkstra{
public:
typedef typename LengthMap::ValueType ValueType;
+ typedef typename Graph::NodeMap<Edge> PredMap;
+ typedef typename Graph::NodeMap<Node> PredNodeMap;
+ typedef typename Graph::NodeMap<ValueType> DistMap;
private:
typedef typename Graph::Node Node;
@@ -49,12 +72,9 @@
const Graph& G;
const LengthMap& length;
- typedef typename Graph::NodeMap<Edge> PredMap;
PredMap predecessor;
//In place of reach:
- typedef typename Graph::NodeMap<Node> PredNodeMap;
PredNodeMap pred_node;
- typedef typename Graph::NodeMap<ValueType> DistMap;
DistMap distance;
//I don't like this:
// //FIXME:
@@ -72,30 +92,76 @@
void run(Node s);
+ ///The distance of a node from the source.
+
+ ///Returns the distance of a node from the source.
+ ///\pre \ref run() must be called before using this function.
+ ///\warning If node \c v in unreachable from \c s the return value
+ ///of this funcion is undefined.
ValueType dist(Node v) const { return distance[v]; }
+ ///Returns the edges of the shortest path tree.
+
+ ///For a node \c v it returns the last edge of the shortest path
+ ///from \c s to \c v or INVALID if \c v is unreachable from \c s.
+ ///\pre \ref run() must be called before using this function.
Edge pred(Node v) const { return predecessor[v]; }
+ ///Returns the nodes of the shortest paths.
+
+ ///For a node \c v it returns the last but one node of the shortest path
+ ///from \c s to \c v or INVALID if \c v is unreachable from \c s.
+ ///\pre \ref run() must be called before using this function.
Node predNode(Node v) const { return pred_node[v]; }
+ ///Returns a reference to the NodeMap of distances.
+
+ ///\pre \ref run() must be called before using this function.
+ ///
const DistMap &distMap() const { return distance;}
+ ///Returns a reference to the shortest path tree map.
+
+ ///Returns a reference to the NodeMap of the edges of the
+ ///shortest path tree.
+ ///\pre \ref run() must be called before using this function.
const PredMap &predMap() const { return predecessor;}
+ ///Returns a reference to the map of nodes of shortest paths.
+
+ ///Returns a reference to the NodeMap of the last but one nodes of the
+ ///shortest paths.
+ ///\pre \ref run() must be called before using this function.
const PredNodeMap &predNodeMap() const { return pred_node;}
// bool reached(Node v) { return reach[v]; }
- ///\warning \c s is not reached!
+
+ ///Chech if a node is reachable from \c s.
+
+ ///Returns \c true if \c v is reachable from \c s.
+ ///\warning \c s is reported to be unreached!
+ ///\todo Is this what we want?
+ ///\pre \ref run() must be called before using this function.
///
bool reached(Node v) { return G.valid(predecessor[v]); }
};
- // IMPLEMENTATIONS
-
+ // **********************************************************************
+ // IMPLEMENTATIONS
+ // **********************************************************************
+
+ ///Runs Dijkstra algorithm from node \c s.
+
+ ///This method runs the Dijkstra algorithm from 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.
template <typename Graph, typename LengthMap, typename Heap >
void Dijkstra<Graph,LengthMap,Heap>::run(Node s) {
NodeIt u;
for ( G.first(u) ; G.valid(u) ; G.next(u) ) {
predecessor.set(u,INVALID);
+ pred_node.set(u,INVALID);
// If a node is unreacheable, then why should be the dist=0?
// distance.set(u,0);
// reach.set(u,false);
Modified: hugo/trunk/src/work/alpar/dijkstra/fib_heap.h
==============================================================================
--- hugo/trunk/src/work/alpar/dijkstra/fib_heap.h (original)
+++ hugo/trunk/src/work/alpar/dijkstra/fib_heap.h Sun Mar 21 15:59:51 2004
@@ -57,11 +57,11 @@
namespace hugo {
+ /// A Fibonacci Heap implementation.
template <typename Item, typename Prio, typename ItemIntMap,
- typename Compare = std::less<Prio> >
-
+ typename Compare = std::less<Prio> >
class FibHeap {
-
+
typedef Prio PrioType;
class store;
More information about the Lemon-commits
mailing list