[Lemon-commits] Peter Kovacs: Many improvements in bfs.h, dfs.h ...
Lemon HG
hg at lemon.cs.elte.hu
Mon Aug 4 22:03:27 CEST 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/c30731a37f91
changeset: 244:c30731a37f91
user: Peter Kovacs <kpeter [at] inf.elte.hu>
date: Sun Aug 03 13:34:57 2008 +0200
description:
Many improvements in bfs.h, dfs.h and dijkstra.h
- Add run() function to Bfs and run(s,t) function to DfsVisit.
- Add debug checking to addSource() function of Dfs and DfsVisit.
- Add a few missing named parameters (according to \todo notes).
- Small fixes in the code (e.g. missing derivations).
- Many doc improvements.
- Remove \todo and \warning comments which are no longer valid.
- Remove \author commands (see ticket #39).
- Fixes in the the doc (e.g. wrong references).
- Hide the doc of most of the private and protected members.
- Use public typedefs instead of template parameters in public
functions.
- Use better parameter names for some functions.
- Other small changes to make the doc more uniform.
diffstat:
3 files changed, 1578 insertions(+), 1312 deletions(-)
lemon/bfs.h | 1042 +++++++++++++++++++++++++++++-----------------------
lemon/dfs.h | 1073 ++++++++++++++++++++++++++++--------------------------
lemon/dijkstra.h | 775 +++++++++++++++++++++------------------
diffs (truncated from 4971 to 300 lines):
diff -r b67149f0e675 -r c30731a37f91 lemon/bfs.h
--- a/lemon/bfs.h Mon Jul 14 15:40:24 2008 +0100
+++ b/lemon/bfs.h Sun Aug 03 13:34:57 2008 +0200
@@ -21,7 +21,7 @@
///\ingroup search
///\file
-///\brief Bfs algorithm.
+///\brief BFS algorithm.
#include <lemon/list_graph.h>
#include <lemon/graph_utils.h>
@@ -32,8 +32,6 @@
namespace lemon {
-
-
///Default traits class of Bfs class.
///Default traits class of Bfs class.
@@ -41,73 +39,75 @@
template<class GR>
struct BfsDefaultTraits
{
- ///The digraph type the algorithm runs on.
+ ///The type of the digraph the algorithm runs on.
typedef GR Digraph;
- ///\brief The type of the map that stores the last
+
+ ///\brief The type of the map that stores the predecessor
///arcs of the shortest paths.
///
- ///The type of the map that stores the last
+ ///The type of the map that stores the predecessor
///arcs of the shortest paths.
///It must meet the \ref concepts::WriteMap "WriteMap" concept.
- ///
- typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap;
- ///Instantiates a PredMap.
+ typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
+ ///Instantiates a \ref PredMap.
///This function instantiates a \ref PredMap.
- ///\param G is the digraph, to which we would like to define the PredMap.
+ ///\param g is the digraph, to which we would like to define the
+ ///\ref PredMap.
///\todo The digraph alone may be insufficient to initialize
- static PredMap *createPredMap(const GR &G)
+ static PredMap *createPredMap(const Digraph &g)
{
- return new PredMap(G);
+ return new PredMap(g);
}
+
///The type of the map that indicates which nodes are processed.
///The type of the map that indicates which nodes are processed.
///It must meet the \ref concepts::WriteMap "WriteMap" concept.
- ///\todo named parameter to set this type, function to read and write.
+ ///By default it is a NullMap.
typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
- ///Instantiates a ProcessedMap.
+ ///Instantiates a \ref ProcessedMap.
///This function instantiates a \ref ProcessedMap.
///\param g is the digraph, to which
///we would like to define the \ref ProcessedMap
#ifdef DOXYGEN
- static ProcessedMap *createProcessedMap(const GR &g)
+ static ProcessedMap *createProcessedMap(const Digraph &g)
#else
- static ProcessedMap *createProcessedMap(const GR &)
+ static ProcessedMap *createProcessedMap(const Digraph &)
#endif
{
return new ProcessedMap();
}
+
///The type of the map that indicates which nodes are reached.
///The type of the map that indicates which nodes are reached.
- ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
- ///\todo named parameter to set this type, function to read and write.
+ ///It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
typedef typename Digraph::template NodeMap<bool> ReachedMap;
- ///Instantiates a ReachedMap.
+ ///Instantiates a \ref ReachedMap.
///This function instantiates a \ref ReachedMap.
- ///\param G is the digraph, to which
+ ///\param g is the digraph, to which
///we would like to define the \ref ReachedMap.
- static ReachedMap *createReachedMap(const GR &G)
+ static ReachedMap *createReachedMap(const Digraph &g)
{
- return new ReachedMap(G);
+ return new ReachedMap(g);
}
- ///The type of the map that stores the dists of the nodes.
- ///The type of the map that stores the dists of the nodes.
+ ///The type of the map that stores the distances of the nodes.
+
+ ///The type of the map that stores the distances of the nodes.
///It must meet the \ref concepts::WriteMap "WriteMap" concept.
- ///
typedef typename Digraph::template NodeMap<int> DistMap;
- ///Instantiates a DistMap.
+ ///Instantiates a \ref DistMap.
///This function instantiates a \ref DistMap.
- ///\param G is the digraph, to which we would like to define
- ///the \ref DistMap
- static DistMap *createDistMap(const GR &G)
+ ///\param g is the digraph, to which we would like to define the
+ ///\ref DistMap.
+ static DistMap *createDistMap(const Digraph &g)
{
- return new DistMap(G);
+ return new DistMap(g);
}
};
@@ -116,15 +116,18 @@
///\ingroup search
///This class provides an efficient implementation of the %BFS algorithm.
///
- ///\tparam GR The digraph type the algorithm runs on. The default value is
- ///\ref ListDigraph. The value of GR is not used directly by Bfs, it
- ///is only passed to \ref BfsDefaultTraits.
+ ///There is also a \ref bfs() "function type interface" for the BFS
+ ///algorithm, which is convenient in the simplier cases and it can be
+ ///used easier.
+ ///
+ ///\tparam GR The type of the digraph the algorithm runs on.
+ ///The default value is \ref ListDigraph. The value of GR is not used
+ ///directly by \ref Bfs, it is only passed to \ref BfsDefaultTraits.
///\tparam TR Traits class to set various data types used by the algorithm.
///The default traits class is
///\ref BfsDefaultTraits "BfsDefaultTraits<GR>".
///See \ref BfsDefaultTraits for the documentation of
///a Bfs traits class.
-
#ifdef DOXYGEN
template <typename GR,
typename TR>
@@ -134,12 +137,10 @@
#endif
class Bfs {
public:
- /**
- * \brief \ref Exception for uninitialized parameters.
- *
- * This error represents problems in the initialization
- * of the parameters of the algorithms.
- */
+ ///\ref Exception for uninitialized parameters.
+
+ ///This error represents problems in the initialization of the
+ ///parameters of the algorithm.
class UninitializedParameter : public lemon::UninitializedParameter {
public:
virtual const char* what() const throw() {
@@ -147,19 +148,24 @@
}
};
- typedef TR Traits;
- ///The type of the underlying digraph.
+ ///The type of the digraph the algorithm runs on.
typedef typename TR::Digraph Digraph;
- ///\brief The type of the map that stores the last
- ///arcs of the shortest paths.
+ ///\brief The type of the map that stores the predecessor arcs of the
+ ///shortest paths.
typedef typename TR::PredMap PredMap;
- ///The type of the map indicating which nodes are reached.
+ ///The type of the map that stores the distances of the nodes.
+ typedef typename TR::DistMap DistMap;
+ ///The type of the map that indicates which nodes are reached.
typedef typename TR::ReachedMap ReachedMap;
- ///The type of the map indicating which nodes are processed.
+ ///The type of the map that indicates which nodes are processed.
typedef typename TR::ProcessedMap ProcessedMap;
- ///The type of the map that stores the dists of the nodes.
- typedef typename TR::DistMap DistMap;
+ ///The type of the paths.
+ typedef PredMapPath<Digraph, PredMap> Path;
+
+ ///The traits class.
+ typedef TR Traits;
+
private:
typedef typename Digraph::Node Node;
@@ -167,23 +173,23 @@
typedef typename Digraph::Arc Arc;
typedef typename Digraph::OutArcIt OutArcIt;
- /// Pointer to the underlying digraph.
+ //Pointer to the underlying digraph.
const Digraph *G;
- ///Pointer to the map of predecessors arcs.
+ //Pointer to the map of predecessor arcs.
PredMap *_pred;
- ///Indicates if \ref _pred is locally allocated (\c true) or not.
+ //Indicates if _pred is locally allocated (true) or not.
bool local_pred;
- ///Pointer to the map of distances.
+ //Pointer to the map of distances.
DistMap *_dist;
- ///Indicates if \ref _dist is locally allocated (\c true) or not.
+ //Indicates if _dist is locally allocated (true) or not.
bool local_dist;
- ///Pointer to the map of reached status of the nodes.
+ //Pointer to the map of reached status of the nodes.
ReachedMap *_reached;
- ///Indicates if \ref _reached is locally allocated (\c true) or not.
+ //Indicates if _reached is locally allocated (true) or not.
bool local_reached;
- ///Pointer to the map of processed status of the nodes.
+ //Pointer to the map of processed status of the nodes.
ProcessedMap *_processed;
- ///Indicates if \ref _processed is locally allocated (\c true) or not.
+ //Indicates if _processed is locally allocated (true) or not.
bool local_processed;
std::vector<typename Digraph::Node> _queue;
@@ -191,7 +197,6 @@
int _curr_dist;
///Creates the maps if necessary.
-
///\todo Better memory allocation (instead of new).
void create_maps()
{
@@ -234,10 +239,10 @@
}
};
///\brief \ref named-templ-param "Named parameter" for setting
- ///PredMap type
+ ///\ref PredMap type.
///
- ///\ref named-templ-param "Named parameter" for setting PredMap type
- ///
+ ///\ref named-templ-param "Named parameter" for setting
+ ///\ref PredMap type.
template <class T>
struct DefPredMap : public Bfs< Digraph, DefPredMapTraits<T> > {
typedef Bfs< Digraph, DefPredMapTraits<T> > Create;
@@ -252,10 +257,10 @@
}
};
///\brief \ref named-templ-param "Named parameter" for setting
- ///DistMap type
+ ///\ref DistMap type.
///
- ///\ref named-templ-param "Named parameter" for setting DistMap type
- ///
+ ///\ref named-templ-param "Named parameter" for setting
+ ///\ref DistMap type.
template <class T>
struct DefDistMap : public Bfs< Digraph, DefDistMapTraits<T> > {
typedef Bfs< Digraph, DefDistMapTraits<T> > Create;
@@ -270,10 +275,10 @@
}
};
///\brief \ref named-templ-param "Named parameter" for setting
- ///ReachedMap type
+ ///\ref ReachedMap type.
///
- ///\ref named-templ-param "Named parameter" for setting ReachedMap type
- ///
+ ///\ref named-templ-param "Named parameter" for setting
+ ///\ref ReachedMap type.
template <class T>
struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits<T> > {
typedef Bfs< Digraph, DefReachedMapTraits<T> > Create;
@@ -288,10 +293,10 @@
}
};
///\brief \ref named-templ-param "Named parameter" for setting
- ///ProcessedMap type
+ ///\ref ProcessedMap type.
///
- ///\ref named-templ-param "Named parameter" for setting ProcessedMap type
- ///
+ ///\ref named-templ-param "Named parameter" for setting
+ ///\ref ProcessedMap type.
template <class T>
struct DefProcessedMap : public Bfs< Digraph, DefProcessedMapTraits<T> > {
typedef Bfs< Digraph, DefProcessedMapTraits<T> > Create;
@@ -299,16 +304,16 @@
struct DefDigraphProcessedMapTraits : public Traits {
typedef typename Digraph::template NodeMap<bool> ProcessedMap;
- static ProcessedMap *createProcessedMap(const Digraph &G)
+ static ProcessedMap *createProcessedMap(const Digraph &g)
More information about the Lemon-commits
mailing list