# HG changeset patch # User klao # Date 1104935640 0 # Node ID 90f8696360b2958c45980e5b6ace1f947c56548e # Parent 172ce6c3ac6ea8f5b13fbd81968a6d71cb842368 UndirGraphs: invalid edge bug diff -r 172ce6c3ac6e -r 90f8696360b2 src/lemon/graph_utils.h --- a/src/lemon/graph_utils.h Wed Jan 05 12:26:59 2005 +0000 +++ b/src/lemon/graph_utils.h Wed Jan 05 14:34:00 2005 +0000 @@ -103,17 +103,33 @@ return _countEdges(g); } - /// \brief Function to count the symmetric edges in the graph. + // Undirected edge counting: + + template + inline + typename enable_if::type + _countUndirEdges(const Graph &g) { + return g.undirEdgeNum(); + } + + template + inline int _countUndirEdges(Wrap w) { + return countItems(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 - inline int countSymEdges(const Graph& _g) { - return countItems(_g); + inline int countUndirEdges(const Graph& g) { + return _countUndirEdges(g); } + template inline int countNodeDegree(const Graph& _g, const typename Graph::Node& _n) { int num = 0; diff -r 172ce6c3ac6e -r 90f8696360b2 src/lemon/undir_graph_extender.h --- a/src/lemon/undir_graph_extender.h Wed Jan 05 12:26:59 2005 +0000 +++ b/src/lemon/undir_graph_extender.h Wed Jan 05 14:34:00 2005 +0000 @@ -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); diff -r 172ce6c3ac6e -r 90f8696360b2 src/test/undir_graph_test.cc --- a/src/test/undir_graph_test.cc Wed Jan 05 12:26:59 2005 +0000 +++ b/src/test/undir_graph_test.cc Wed Jan 05 14:34:00 2005 +0000 @@ -6,14 +6,15 @@ #include #include +#include + #include "test_tools.h" using namespace lemon; using namespace lemon::concept; - -int main() { +void check_concepts() { typedef UndirGraphExtender UndirListGraphBase; typedef IterableUndirGraphExtender< @@ -40,6 +41,66 @@ checkConcept(); checkConcept(); +} + +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; }