[Lemon-commits] [lemon_svn] klao: r1447 - in hugo/trunk/src: lemon test

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:45:31 CET 2006


Author: klao
Date: Wed Jan  5 15:34:00 2005
New Revision: 1447

Modified:
   hugo/trunk/src/lemon/graph_utils.h
   hugo/trunk/src/lemon/undir_graph_extender.h
   hugo/trunk/src/test/undir_graph_test.cc

Log:
UndirGraphs: invalid edge bug

Modified: hugo/trunk/src/lemon/graph_utils.h
==============================================================================
--- hugo/trunk/src/lemon/graph_utils.h	(original)
+++ hugo/trunk/src/lemon/graph_utils.h	Wed Jan  5 15:34:00 2005
@@ -103,17 +103,33 @@
     return _countEdges<Graph>(g);
   }
 
-  /// \brief Function to count the symmetric edges in the graph.
+  // Undirected edge counting:
+
+  template <typename Graph>
+  inline
+  typename enable_if<typename Graph::EdgeNumTag, int>::type
+  _countUndirEdges(const Graph &g) {
+    return g.undirEdgeNum();
+  }
+
+  template <typename Graph>
+  inline int _countUndirEdges(Wrap<Graph> w) {
+    return countItems<Graph, typename Graph::UndirEdgeIt>(w.value);
+  }
+
+  /// \brief Function to count the edges in the graph.
   ///
-  /// This function counts the symmetric edges in the graph.
+  /// This function counts the edges in the graph.
   /// The complexity of the function is O(e) but for some
   /// graph structure it is specialized to run in O(1).
+
   template <typename Graph>
-  inline int countSymEdges(const Graph& _g) {
-    return countItems<Graph, typename Graph::SymEdgeIt>(_g);
+  inline int countUndirEdges(const Graph& g) {
+    return _countUndirEdges<Graph>(g);
   }
 
 
+
   template <typename Graph, typename DegIt>
   inline int countNodeDegree(const Graph& _g, const typename Graph::Node& _n) {
     int num = 0;

Modified: hugo/trunk/src/lemon/undir_graph_extender.h
==============================================================================
--- hugo/trunk/src/lemon/undir_graph_extender.h	(original)
+++ hugo/trunk/src/lemon/undir_graph_extender.h	Wed Jan  5 15:34:00 2005
@@ -48,7 +48,7 @@
       Edge(const UndirEdge &ue, bool _forward) :
 	UndirEdge(ue), forward(_forward) {}
       /// Invalid edge constructor
-      Edge(Invalid i) : UndirEdge(i), forward(false) {}
+      Edge(Invalid i) : UndirEdge(i), forward(true) {}
 
       bool operator==(const Edge &that) const {
 	return forward==that.forward && UndirEdge(*this)==UndirEdge(that);

Modified: hugo/trunk/src/test/undir_graph_test.cc
==============================================================================
--- hugo/trunk/src/test/undir_graph_test.cc	(original)
+++ hugo/trunk/src/test/undir_graph_test.cc	Wed Jan  5 15:34:00 2005
@@ -6,14 +6,15 @@
 #include <lemon/smart_graph.h>
 #include <lemon/full_graph.h>
 
+#include <lemon/graph_utils.h>
+
 #include "test_tools.h"
 
 
 using namespace lemon;
 using namespace lemon::concept;
 
-
-int main() {
+void check_concepts() {
   typedef UndirGraphExtender<ListGraphBase> UndirListGraphBase;
 
   typedef IterableUndirGraphExtender<
@@ -40,6 +41,66 @@
   checkConcept<ExtendableUndirGraph, UndirSmartGraph>();
 
   checkConcept<UndirGraph, UndirGraph>();
+}
+
+typedef UndirListGraph Graph;
+typedef Graph::Node Node;
+typedef Graph::UndirEdge UEdge;
+typedef Graph::Edge Edge;
+typedef Graph::NodeIt NodeIt;
+typedef Graph::UndirEdgeIt UEdgeIt;
+typedef Graph::EdgeIt EdgeIt;
+
+void check_item_counts(Graph &g, int n, int e) {
+  check(countNodes(g)==n, "Wrong node number.");
+  check(countEdges(g)==2*e, "Wrong edge number.");
+}
+
+void print_items(Graph &g) {
+  cout << "Nodes" << endl;
+  int i=0;
+  for(NodeIt it(g); it!=INVALID; ++it, ++i) {
+    cout << "  " << i << ": " << g.id(it) << endl;
+  }
+
+  cout << "UndirEdge" << endl;
+  i=0;
+  for(UEdgeIt it(g); it!=INVALID; ++it, ++i) {
+    cout << "  " << i << ": " << g.id(it) 
+	 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 
+	 << ")" << endl;
+  }
+
+  cout << "Edge" << endl;
+  i=0;
+  for(EdgeIt it(g); it!=INVALID; ++it, ++i) {
+    cout << "  " << i << ": " << g.id(it)
+	 << " (" << g.id(g.source(it)) << ", " << g.id(g.target(it)) 
+	 << ")" << endl;
+  }
+
+}
+
+int main() {
+  check_concepts();
+
+
+  Graph g;
+
+  check_item_counts(g,0,0);
+
+  Node
+    n1 = g.addNode(),
+    n2 = g.addNode(),
+    n3 = g.addNode();
+
+  UEdge
+    e1 = g.addEdge(n1, n2),
+    e2 = g.addEdge(n2, n3);
+
+  // print_items(g);
+
+  check_item_counts(g,3,2);
 
   return 0;
 }



More information about the Lemon-commits mailing list