[Lemon-commits] Alpar Juttner: Merge
Lemon HG
hg at lemon.cs.elte.hu
Thu Mar 20 13:13:48 CET 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/70f3967ca6eb
changeset: 101:70f3967ca6eb
user: Alpar Juttner <alpar [at] cs.elte.hu>
date: Thu Mar 20 12:12:24 2008 +0000
description:
Merge
diffstat:
17 files changed, 10389 insertions(+), 2 deletions(-)
lemon/Makefile.am | 10
lemon/bfs.h | 1597 ++++++++++++++++++++++++
lemon/bin_heap.h | 346 +++++
lemon/bits/path_dump.h | 174 ++
lemon/concepts/heap.h | 226 +++
lemon/concepts/path.h | 307 ++++
lemon/dfs.h | 1543 +++++++++++++++++++++++
lemon/dijkstra.h | 1209 ++++++++++++++++++
lemon/graph_utils.h | 3179 ++++++++++++++++++++++++++++++++++++++++++++++++
lemon/path.h | 1079 ++++++++++++++++
test/Makefile.am | 8
test/bfs_test.cc | 141 ++
test/dfs_test.cc | 130 +
test/heap_test.cc | 140 ++
test/heap_test.h | 123 +
test/path_test.cc | 44
test/test_tools.h | 135 ++
diffs (truncated from 10527 to 300 lines):
diff -r cc7e6b8b59bf -r 70f3967ca6eb lemon/Makefile.am
--- a/lemon/Makefile.am Tue Mar 18 16:45:21 2008 +0100
+++ b/lemon/Makefile.am Thu Mar 20 12:12:24 2008 +0000
@@ -17,12 +17,17 @@ lemon_libemon_la_LDFLAGS = $(GLPK_LIBS)
lemon_HEADERS += \
lemon/arg_parser.h \
- lemon/concept_check.h \
+ lemon/bfs.h \
+ lemon/bin_heap.h \
+ lemon/dfs.h \
+ lemon/dijkstra.h \
lemon/dim2.h \
lemon/error.h \
+ lemon/graph_utils.h \
lemon/list_graph.h \
lemon/maps.h \
lemon/math.h \
+ lemon/path.h \
lemon/random.h \
lemon/tolerance.h
@@ -34,6 +39,7 @@ bits_HEADERS += \
lemon/bits/graph_extender.h \
lemon/bits/invalid.h \
lemon/bits/map_extender.h \
+ lemon/bits/path_dump.h \
lemon/bits/traits.h \
lemon/bits/utility.h \
lemon/bits/vector_map.h
@@ -42,5 +48,7 @@ concept_HEADERS += \
lemon/concept_check.h \
lemon/concepts/digraph.h \
lemon/concepts/graph.h \
+ lemon/concepts/heap.h \
lemon/concepts/maps.h \
+ lemon/concepts/path.h \
lemon/concepts/graph_components.h
diff -r cc7e6b8b59bf -r 70f3967ca6eb lemon/bfs.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lemon/bfs.h Thu Mar 20 12:12:24 2008 +0000
@@ -0,0 +1,1597 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2008
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_BFS_H
+#define LEMON_BFS_H
+
+///\ingroup search
+///\file
+///\brief Bfs algorithm.
+
+#include <lemon/list_graph.h>
+#include <lemon/graph_utils.h>
+#include <lemon/bits/path_dump.h>
+#include <lemon/bits/invalid.h>
+#include <lemon/error.h>
+#include <lemon/maps.h>
+
+namespace lemon {
+
+
+
+ ///Default traits class of Bfs class.
+
+ ///Default traits class of Bfs class.
+ ///\param GR Digraph type.
+ template<class GR>
+ struct BfsDefaultTraits
+ {
+ ///The digraph type the algorithm runs on.
+ typedef GR Digraph;
+ ///\brief The type of the map that stores the last
+ ///arcs of the shortest paths.
+ ///
+ ///The type of the map that stores the last
+ ///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.
+
+ ///This function instantiates a \ref PredMap.
+ ///\param G is the digraph, to which we would like to define the PredMap.
+ ///\todo The digraph alone may be insufficient to initialize
+ static PredMap *createPredMap(const GR &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.
+ typedef NullMap<typename Digraph::Node,bool> ProcessedMap;
+ ///Instantiates a 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)
+#else
+ static ProcessedMap *createProcessedMap(const GR &)
+#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.
+ typedef typename Digraph::template NodeMap<bool> ReachedMap;
+ ///Instantiates a ReachedMap.
+
+ ///This function instantiates a \ref ReachedMap.
+ ///\param G is the digraph, to which
+ ///we would like to define the \ref ReachedMap.
+ static ReachedMap *createReachedMap(const GR &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.
+ ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
+ ///
+ typedef typename Digraph::template NodeMap<int> DistMap;
+ ///Instantiates a 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)
+ {
+ return new DistMap(G);
+ }
+ };
+
+ ///%BFS algorithm class.
+
+ ///\ingroup search
+ ///This class provides an efficient implementation of the %BFS algorithm.
+ ///
+ ///\param 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.
+ ///\param 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.
+ ///
+ ///\author Alpar Juttner
+
+#ifdef DOXYGEN
+ template <typename GR,
+ typename TR>
+#else
+ template <typename GR=ListDigraph,
+ typename TR=BfsDefaultTraits<GR> >
+#endif
+ class Bfs {
+ public:
+ /**
+ * \brief \ref Exception for uninitialized parameters.
+ *
+ * This error represents problems in the initialization
+ * of the parameters of the algorithms.
+ */
+ class UninitializedParameter : public lemon::UninitializedParameter {
+ public:
+ virtual const char* what() const throw() {
+ return "lemon::Bfs::UninitializedParameter";
+ }
+ };
+
+ typedef TR Traits;
+ ///The type of the underlying digraph.
+ typedef typename TR::Digraph Digraph;
+
+ ///\brief The type of the map that stores the last
+ ///arcs of the shortest paths.
+ typedef typename TR::PredMap PredMap;
+ ///The type of the map indicating which nodes are reached.
+ typedef typename TR::ReachedMap ReachedMap;
+ ///The type of the map indicating 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;
+ private:
+
+ typedef typename Digraph::Node Node;
+ typedef typename Digraph::NodeIt NodeIt;
+ typedef typename Digraph::Arc Arc;
+ typedef typename Digraph::OutArcIt OutArcIt;
+
+ /// Pointer to the underlying digraph.
+ const Digraph *G;
+ ///Pointer to the map of predecessors arcs.
+ PredMap *_pred;
+ ///Indicates if \ref _pred is locally allocated (\c true) or not.
+ bool local_pred;
+ ///Pointer to the map of distances.
+ DistMap *_dist;
+ ///Indicates if \ref _dist is locally allocated (\c true) or not.
+ bool local_dist;
+ ///Pointer to the map of reached status of the nodes.
+ ReachedMap *_reached;
+ ///Indicates if \ref _reached is locally allocated (\c true) or not.
+ bool local_reached;
+ ///Pointer to the map of processed status of the nodes.
+ ProcessedMap *_processed;
+ ///Indicates if \ref _processed is locally allocated (\c true) or not.
+ bool local_processed;
+
+ std::vector<typename Digraph::Node> _queue;
+ int _queue_head,_queue_tail,_queue_next_dist;
+ int _curr_dist;
+
+ ///Creates the maps if necessary.
+
+ ///\todo Better memory allocation (instead of new).
+ void create_maps()
+ {
+ if(!_pred) {
+ local_pred = true;
+ _pred = Traits::createPredMap(*G);
+ }
+ if(!_dist) {
+ local_dist = true;
+ _dist = Traits::createDistMap(*G);
+ }
+ if(!_reached) {
+ local_reached = true;
+ _reached = Traits::createReachedMap(*G);
+ }
+ if(!_processed) {
+ local_processed = true;
+ _processed = Traits::createProcessedMap(*G);
+ }
+ }
+
+ protected:
+
+ Bfs() {}
+
+ public:
+
+ typedef Bfs Create;
+
+ ///\name Named template parameters
+
+ ///@{
+
+ template <class T>
+ struct DefPredMapTraits : public Traits {
+ typedef T PredMap;
+ static PredMap *createPredMap(const Digraph &)
+ {
+ throw UninitializedParameter();
+ }
+ };
+ ///\brief \ref named-templ-param "Named parameter" for setting
+ ///PredMap type
+ ///
+ ///\ref named-templ-param "Named parameter" for setting PredMap type
+ ///
+ template <class T>
+ struct DefPredMap : public Bfs< Digraph, DefPredMapTraits<T> > {
+ typedef Bfs< Digraph, DefPredMapTraits<T> > Create;
+ };
+
+ template <class T>
+ struct DefDistMapTraits : public Traits {
+ typedef T DistMap;
+ static DistMap *createDistMap(const Digraph &)
+ {
+ throw UninitializedParameter();
+ }
+ };
+ ///\brief \ref named-templ-param "Named parameter" for setting
+ ///DistMap type
+ ///
+ ///\ref named-templ-param "Named parameter" for setting DistMap type
More information about the Lemon-commits
mailing list