[Lemon-commits] Balazs Dezso: Improvements in graph adaptors (#67)

Lemon HG hg at lemon.cs.elte.hu
Tue Dec 2 16:35:20 CET 2008


details:   http://lemon.cs.elte.hu/hg/lemon/rev/4b6112235fad
changeset: 431:4b6112235fad
user:      Balazs Dezso <deba [at] inf.elte.hu>
date:      Sun Nov 30 19:00:30 2008 +0100
description:
	Improvements in graph adaptors (#67)

	Remove DigraphAdaptor and GraphAdaptor Remove docs of base classes
	Move the member documentations to real adaptors Minor improvements
	in documentation

diffstat:

3 files changed, 329 insertions(+), 372 deletions(-)
lemon/digraph_adaptor.h    |  397 ++++++++++++++++++++++----------------------
lemon/graph_adaptor.h      |  216 +++++++++++++----------
test/graph_adaptor_test.cc |   88 ---------

diffs (truncated from 1123 to 300 lines):

diff -r 05357da973ce -r 4b6112235fad lemon/digraph_adaptor.h
--- a/lemon/digraph_adaptor.h	Sun Nov 30 18:57:18 2008 +0100
+++ b/lemon/digraph_adaptor.h	Sun Nov 30 19:00:30 2008 +0100
@@ -23,7 +23,7 @@
 ///\file
 ///\brief Several digraph adaptors.
 ///
-///This file contains several useful digraph adaptor functions.
+///This file contains several useful digraph adaptor classes.
 
 #include <lemon/core.h>
 #include <lemon/maps.h>
@@ -38,17 +38,6 @@
 
 namespace lemon {
 
-  ///\brief Base type for the Digraph Adaptors
-  ///
-  ///Base type for the Digraph Adaptors
-  ///
-  ///This is the base type for most of LEMON digraph adaptors. This
-  ///class implements a trivial digraph adaptor i.e. it only wraps the
-  ///functions and types of the digraph. The purpose of this class is
-  ///to make easier implementing digraph adaptors. E.g. if an adaptor
-  ///is considered which differs from the wrapped digraph only in some
-  ///of its functions or types, then it can be derived from
-  ///DigraphAdaptor, and only the differences should be implemented.
   template<typename _Digraph>
   class DigraphAdaptorBase {
   public:
@@ -166,35 +155,6 @@
 
   };
 
-  ///\ingroup graph_adaptors
-  ///
-  ///\brief Trivial Digraph Adaptor
-  /// 
-  /// This class is an adaptor which does not change the adapted
-  /// digraph.  It can be used only to test the digraph adaptors.
-  template <typename _Digraph>
-  class DigraphAdaptor :
-    public DigraphAdaptorExtender<DigraphAdaptorBase<_Digraph> > { 
-  public:
-    typedef _Digraph Digraph;
-    typedef DigraphAdaptorExtender<DigraphAdaptorBase<_Digraph> > Parent;
-  protected:
-    DigraphAdaptor() : Parent() { }
-
-  public:
-    explicit DigraphAdaptor(Digraph& digraph) { setDigraph(digraph); }
-  };
-
-  /// \brief Just gives back a digraph adaptor
-  ///
-  /// Just gives back a digraph adaptor which 
-  /// should be provide original digraph
-  template<typename Digraph>
-  DigraphAdaptor<const Digraph>
-  digraphAdaptor(const Digraph& digraph) {
-    return DigraphAdaptor<const Digraph>(digraph);
-  }
-
 
   template <typename _Digraph>
   class RevDigraphAdaptorBase : public DigraphAdaptorBase<_Digraph> {
@@ -231,27 +191,25 @@
   ///
   /// If \c g is defined as
   ///\code
-  /// ListDigraph g;
+  /// ListDigraph dg;
   ///\endcode
   /// then
   ///\code
-  /// RevDigraphAdaptor<ListDigraph> ga(g);
+  /// RevDigraphAdaptor<ListDigraph> dga(dg);
   ///\endcode
-  /// implements the digraph obtained from \c g by 
+  /// implements the digraph obtained from \c dg by 
   /// reversing the orientation of its arcs.
   ///
-  /// A good example of using RevDigraphAdaptor is to decide that the
-  /// directed graph is wheter strongly connected or not. If from one
-  /// node each node is reachable and from each node is reachable this
-  /// node then and just then the digraph is strongly
-  /// connected. Instead of this condition we use a little bit
-  /// different. From one node each node ahould be reachable in the
-  /// digraph and in the reversed digraph. Now this condition can be
-  /// checked with the Dfs algorithm class and the RevDigraphAdaptor
-  /// algorithm class.
+  /// A good example of using RevDigraphAdaptor is to decide whether
+  /// the directed graph is strongly connected or not. The digraph is
+  /// strongly connected iff each node is reachable from one node and
+  /// this node is reachable from the others. Instead of this
+  /// condition we use a slightly different, from one node each node
+  /// is reachable both in the digraph and the reversed digraph. Now
+  /// this condition can be checked with the Dfs algorithm and the
+  /// RevDigraphAdaptor class.
   ///
-  /// And look at the code:
-  ///
+  /// The implementation:
   ///\code
   /// bool stronglyConnected(const Digraph& digraph) {
   ///   if (NodeIt(digraph) == INVALID) return true;
@@ -284,6 +242,10 @@
   protected:
     RevDigraphAdaptor() { }
   public:
+
+    /// \brief Constructor
+    ///
+    /// Creates a reverse graph adaptor for the given digraph
     explicit RevDigraphAdaptor(Digraph& digraph) { 
       Parent::setDigraph(digraph); 
     }
@@ -374,44 +336,13 @@
 	     || !(*_node_filter)[Parent::target(i)])) Parent::nextOut(i); 
     }
 
-    ///\e
-
-    /// This function hides \c n in the digraph, i.e. the iteration 
-    /// jumps over it. This is done by simply setting the value of \c n  
-    /// to be false in the corresponding node-map.
     void hide(const Node& n) const { _node_filter->set(n, false); }
-
-    ///\e
-
-    /// This function hides \c a in the digraph, i.e. the iteration 
-    /// jumps over it. This is done by simply setting the value of \c a
-    /// to be false in the corresponding arc-map.
     void hide(const Arc& a) const { _arc_filter->set(a, false); }
 
-    ///\e
-
-    /// The value of \c n is set to be true in the node-map which stores 
-    /// hide information. If \c n was hidden previuosly, then it is shown 
-    /// again
-     void unHide(const Node& n) const { _node_filter->set(n, true); }
-
-    ///\e
-
-    /// The value of \c a is set to be true in the arc-map which stores 
-    /// hide information. If \c a was hidden previuosly, then it is shown 
-    /// again
+    void unHide(const Node& n) const { _node_filter->set(n, true); }
     void unHide(const Arc& a) const { _arc_filter->set(a, true); }
 
-    /// Returns true if \c n is hidden.
-    
-    ///\e
-    ///
     bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
-
-    /// Returns true if \c a is hidden.
-    
-    ///\e
-    ///
     bool hidden(const Arc& a) const { return !(*_arc_filter)[a]; }
 
     typedef False NodeNumTag;
@@ -548,44 +479,13 @@
       while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i); 
     }
 
-    ///\e
-
-    /// This function hides \c n in the digraph, i.e. the iteration 
-    /// jumps over it. This is done by simply setting the value of \c n  
-    /// to be false in the corresponding node-map.
     void hide(const Node& n) const { _node_filter->set(n, false); }
-
-    ///\e
-
-    /// This function hides \c e in the digraph, i.e. the iteration 
-    /// jumps over it. This is done by simply setting the value of \c e  
-    /// to be false in the corresponding arc-map.
     void hide(const Arc& e) const { _arc_filter->set(e, false); }
 
-    ///\e
-
-    /// The value of \c n is set to be true in the node-map which stores 
-    /// hide information. If \c n was hidden previuosly, then it is shown 
-    /// again
-     void unHide(const Node& n) const { _node_filter->set(n, true); }
-
-    ///\e
-
-    /// The value of \c e is set to be true in the arc-map which stores 
-    /// hide information. If \c e was hidden previuosly, then it is shown 
-    /// again
+    void unHide(const Node& n) const { _node_filter->set(n, true); }
     void unHide(const Arc& e) const { _arc_filter->set(e, true); }
 
-    /// Returns true if \c n is hidden.
-    
-    ///\e
-    ///
     bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
-
-    /// Returns true if \c n is hidden.
-    
-    ///\e
-    ///
     bool hidden(const Arc& e) const { return !(*_arc_filter)[e]; }
 
     typedef False NodeNumTag;
@@ -661,26 +561,14 @@
   /// \brief A digraph adaptor for hiding nodes and arcs from a digraph.
   /// 
   /// SubDigraphAdaptor shows the digraph with filtered node-set and 
-  /// arc-set. If the \c checked parameter is true then it filters the arcset
-  /// to do not get invalid arcs without source or target.
-  /// Let \f$ G=(V, A) \f$ be a directed digraph
-  /// and suppose that the digraph instance \c g of type ListDigraph
-  /// implements \f$ G \f$.
-  /// Let moreover \f$ b_V \f$ and \f$ b_A \f$ be bool-valued functions resp.
-  /// on the node-set and arc-set.
-  /// SubDigraphAdaptor<...>::NodeIt iterates 
-  /// on the node-set \f$ \{v\in V : b_V(v)=true\} \f$ and 
-  /// SubDigraphAdaptor<...>::ArcIt iterates 
-  /// on the arc-set \f$ \{e\in A : b_A(e)=true\} \f$. Similarly, 
-  /// SubDigraphAdaptor<...>::OutArcIt and
-  /// SubDigraphAdaptor<...>::InArcIt iterates 
-  /// only on arcs leaving and entering a specific node which have true value.
+  /// arc-set. If the \c checked parameter is true then it filters the arc-set
+  /// respect to the source and target.
   /// 
-  /// If the \c checked template parameter is false then we have to
-  /// note that the node-iterator cares only the filter on the
-  /// node-set, and the arc-iterator cares only the filter on the
-  /// arc-set.  This way the arc-map should filter all arcs which's
-  /// source or target is filtered by the node-filter.
+  /// If the \c checked template parameter is false then the
+  /// node-iterator cares only the filter on the node-set, and the
+  /// arc-iterator cares only the filter on the arc-set.  Therefore
+  /// the arc-map have to filter all arcs which's source or target is
+  /// filtered by the node-filter.
   ///\code
   /// typedef ListDigraph Digraph;
   /// DIGRAPH_TYPEDEFS(Digraph);
@@ -693,21 +581,19 @@
   /// nm.set(u, false);
   /// BoolArcMap am(g, true);
   /// am.set(a, false);
-  /// typedef SubDigraphAdaptor<Digraph, BoolNodeMap, BoolArcMap> SubGA;
-  /// SubGA ga(g, nm, am);
-  /// for (SubGA::NodeIt n(ga); n!=INVALID; ++n)
+  /// typedef SubDigraphAdaptor<Digraph, BoolNodeMap, BoolArcMap> SubDGA;
+  /// SubDGA ga(g, nm, am);
+  /// for (SubDGA::NodeIt n(ga); n!=INVALID; ++n)
   ///   std::cout << g.id(n) << std::endl;
-  /// std::cout << ":-)" << std::endl;
-  /// for (SubGA::ArcIt a(ga); a!=INVALID; ++a) 
+  /// for (SubDGA::ArcIt a(ga); a!=INVALID; ++a) 
   ///   std::cout << g.id(a) << std::endl;
   ///\endcode
   /// The output of the above code is the following.
   ///\code
   /// 1
-  /// :-)
   /// 1
   ///\endcode
-  /// Note that \c n is of type \c SubGA::NodeIt, but it can be converted to
+  /// Note that \c n is of type \c SubDGA::NodeIt, but it can be converted to
   /// \c Digraph::Node that is why \c g.id(n) can be applied.
   /// 
   /// For other examples see also the documentation of
@@ -728,10 +614,17 @@
       SubDigraphAdaptorBase<Digraph, NodeFilterMap, ArcFilterMap, checked> >
     Parent;
 
+    typedef typename Parent::Node Node;
+    typedef typename Parent::Arc Arc;
+
   protected:
     SubDigraphAdaptor() { }
   public:
 
+    /// \brief Constructor
+    ///
+    /// Creates a sub-digraph-adaptor for the given digraph with
+    /// given node and arc map filters.
     SubDigraphAdaptor(Digraph& digraph, NodeFilterMap& node_filter, 
 		      ArcFilterMap& arc_filter) { 
       setDigraph(digraph);
@@ -739,11 +632,51 @@
       setArcFilterMap(arc_filter);
     }
 
+    /// \brief Hides the node of the graph
+    ///
+    /// This function hides \c n in the digraph, i.e. the iteration 
+    /// jumps over it. This is done by simply setting the value of \c n  
+    /// to be false in the corresponding node-map.
+    void hide(const Node& n) const { Parent::hide(n); }
+
+    /// \brief Hides the arc of the graph



More information about the Lemon-commits mailing list