[Lemon-commits] [lemon_svn] marci: r1046 - in hugo/branches/hugo++/src: hugo work/marci

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


Author: marci
Date: Thu Aug 26 17:18:33 2004
New Revision: 1046

Modified:
   hugo/branches/hugo++/src/hugo/graph_wrapper.h
   hugo/branches/hugo++/src/work/marci/bfs_dfs.h
   hugo/branches/hugo++/src/work/marci/iterator_bfs_demo.cc

Log:
GraphWrapper<Graph>, RevGraphWrapper<Graph> in 0.2


Modified: hugo/branches/hugo++/src/hugo/graph_wrapper.h
==============================================================================
--- hugo/branches/hugo++/src/hugo/graph_wrapper.h	(original)
+++ hugo/branches/hugo++/src/hugo/graph_wrapper.h	Thu Aug 26 17:18:33 2004
@@ -12,7 +12,7 @@
 
 #include <hugo/invalid.h>
 #include <hugo/maps.h>
-//#include <iter_map.h>
+#include <iostream>
 
 namespace hugo {
 
@@ -96,70 +96,97 @@
     typedef Graph ParentGraph;
 
     GraphWrapper(Graph& _graph) : graph(&_graph) { }
+    GraphWrapper(const GraphWrapper<Graph>& gw) : graph(gw.graph) { }
 //     Graph& getGraph() const { return *graph; }
  
-//    typedef typename Graph::Node Node;
-    class Node : public Graph::Node {
-      friend class GraphWrapper<Graph>;
-    public:
-      Node() { }
-      Node(const typename Graph::Node& _n) : Graph::Node(_n) { }
-      // /// \bug construction throughrthr multiple levels should be 
-      // /// handled better
-      // Node(const typename ParentGraph::ParentGraph::Node& _n) : 
-      // Graph::Node(_n) { }
-      Node(const Invalid& i) : Graph::Node(i) { }
-    };
-    class NodeIt { 
+    typedef typename Graph::Node Node;
+//     class Node : public Graph::Node {
+//       friend class GraphWrapper<Graph>;
+//     public:
+//       Node() { }
+//       Node(const typename Graph::Node& _n) : Graph::Node(_n) { }
+//       // /// \bug construction throughrthr multiple levels should be 
+//       // /// handled better
+//       // Node(const typename ParentGraph::ParentGraph::Node& _n) : 
+//       // Graph::Node(_n) { }
+//       Node(const Invalid& i) : Graph::Node(i) { }
+//     };
+    class NodeIt : public Node { 
+      const GraphWrapper<Graph>* gw;
       friend class GraphWrapper<Graph>;
-      typename Graph::NodeIt n;
      public:
       NodeIt() { }
-      NodeIt(const typename Graph::NodeIt& _n) : n(_n) { }
-      NodeIt(const Invalid& i) : n(i) { }
-      NodeIt(const GraphWrapper<Graph>& _G) : n(*(_G.graph)) { }
-      operator Node() const { return Node(typename Graph::Node(n)); }
-    };
-//    typedef typename Graph::Edge Edge;
-    class Edge : public Graph::Edge {
-      friend class GraphWrapper<Graph>;
-    public:
-      Edge() { }
-      Edge(const typename Graph::Edge& _e) : Graph::Edge(_e) { }
-      Edge(const Invalid& i) : Graph::Edge(i) { }
+      NodeIt(const Node& n) : Node(n) { }
+      NodeIt(Invalid i) : Node(i) { }
+      NodeIt(const GraphWrapper<Graph>& _gw) : 
+	Node(typename Graph::NodeIt(*(_gw.graph))), gw(&_gw) { }
+      NodeIt(const GraphWrapper<Graph>& _gw, const Node& n) : 
+	Node(n), gw(&_gw) { }
+      NodeIt& operator++() { 
+	*(static_cast<Node*>(this))=
+	  ++(typename Graph::NodeIt(*(gw->graph), *this));
+	return *this; 
+      }
     };
-    class OutEdgeIt { 
+    typedef typename Graph::Edge Edge;
+//     class Edge : public Graph::Edge {
+//       friend class GraphWrapper<Graph>;
+//     public:
+//       Edge() { }
+//       Edge(const typename Graph::Edge& _e) : Graph::Edge(_e) { }
+//       Edge(const Invalid& i) : Graph::Edge(i) { }
+//     };
+    class OutEdgeIt : public Edge { 
+      const GraphWrapper<Graph>* gw;
       friend class GraphWrapper<Graph>;
-      typename Graph::OutEdgeIt e;
-    public:
+     public:
       OutEdgeIt() { }
-      OutEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
-      OutEdgeIt(const Invalid& i) : e(i) { }
-      OutEdgeIt(const GraphWrapper<Graph>& _G, const Node& _n) : 
-	e(*(_G.graph), typename Graph::Node(_n)) { }
-      operator Edge() const { return Edge(typename Graph::Edge(e)); }
+      OutEdgeIt(const Edge& e) : Edge(e) { }
+      OutEdgeIt(Invalid i) : Edge(i) { }
+      OutEdgeIt(const GraphWrapper<Graph>& _gw, const Node& n) : 
+	Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
+      OutEdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 
+	Edge(e), gw(&_gw) { }
+      OutEdgeIt& operator++() { 
+	*(static_cast<Edge*>(this))=
+	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+	return *this; 
+      }
     };
-    class InEdgeIt { 
+    class InEdgeIt : public Edge { 
+      const GraphWrapper<Graph>* gw;
       friend class GraphWrapper<Graph>;
-      typename Graph::InEdgeIt e;
-    public:
+     public:
       InEdgeIt() { }
-      InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
-      InEdgeIt(const Invalid& i) : e(i) { }
-      InEdgeIt(const GraphWrapper<Graph>& _G, const Node& _n) : 
-	e(*(_G.graph), typename Graph::Node(_n)) { }
-      operator Edge() const { return Edge(typename Graph::Edge(e)); }
+      InEdgeIt(const Edge& e) : Edge(e) { }
+      InEdgeIt(Invalid i) : Edge(i) { }
+      InEdgeIt(const GraphWrapper<Graph>& _gw, const Node& n) : 
+	Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
+      InEdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 
+	Edge(e), gw(&_gw) { }
+      InEdgeIt& operator++() { 
+	*(static_cast<Edge*>(this))=
+	  ++(typename Graph::InEdgeIt(*(gw->graph), *this));
+	return *this; 
+      }
     };
     //typedef typename Graph::SymEdgeIt SymEdgeIt;
-    class EdgeIt { 
+    class EdgeIt : public Edge { 
+      const GraphWrapper<Graph>* gw;
       friend class GraphWrapper<Graph>;
-      typename Graph::EdgeIt e;
-    public:
+     public:
       EdgeIt() { }
-      EdgeIt(const typename Graph::EdgeIt& _e) : e(_e) { }
-      EdgeIt(const Invalid& i) : e(i) { }
-      EdgeIt(const GraphWrapper<Graph>& _G) : e(*(_G.graph)) { }
-      operator Edge() const { return Edge(typename Graph::Edge(e)); }
+      EdgeIt(const Edge& e) : Node(e) { }
+      EdgeIt(Invalid i) : Edge(i) { }
+      EdgeIt(const GraphWrapper<Graph>& _gw) : 
+	Edge(typename Graph::EdgeIt(*(_gw.graph))), gw(&_gw) { }
+      EdgeIt(const GraphWrapper<Graph>& _gw, const Edge& e) : 
+	Edge(w), gw(&_gw) { }
+      EdgeIt& operator++() { 
+	*(static_cast<Edge*>(this))=
+	  ++(typename Graph::EdgeIt(*(gw->graph), *this));
+	return *this; 
+      }
     };
    
     NodeIt& first(NodeIt& i) const { 
@@ -175,28 +202,28 @@
       i=EdgeIt(*this); return i;
     }
 
-    NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; }
-    OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i.e); return i; }
-    InEdgeIt& next(InEdgeIt& i) const { graph->next(i.e); return i; }
-    EdgeIt& next(EdgeIt& i) const { graph->next(i.e); return i; }    
+//     NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; }
+//     OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i.e); return i; }
+//     InEdgeIt& next(InEdgeIt& i) const { graph->next(i.e); return i; }
+//     EdgeIt& next(EdgeIt& i) const { graph->next(i.e); return i; }    
 
     Node tail(const Edge& e) const { 
       return Node(graph->tail(static_cast<typename Graph::Edge>(e))); }
     Node head(const Edge& e) const { 
       return Node(graph->head(static_cast<typename Graph::Edge>(e))); }
 
-    bool valid(const Node& n) const { 
-      return graph->valid(static_cast<typename Graph::Node>(n)); }
-    bool valid(const Edge& e) const { 
-      return graph->valid(static_cast<typename Graph::Edge>(e)); }
+//     bool valid(const Node& n) const { 
+//       return graph->valid(static_cast<typename Graph::Node>(n)); }
+//     bool valid(const Edge& e) const { 
+//       return graph->valid(static_cast<typename Graph::Edge>(e)); }
 
     int nodeNum() const { return graph->nodeNum(); }
     int edgeNum() const { return graph->edgeNum(); }
   
-    Node aNode(const OutEdgeIt& e) const { return Node(graph->aNode(e.e)); }
-    Node aNode(const InEdgeIt& e) const { return Node(graph->aNode(e.e)); }
-    Node bNode(const OutEdgeIt& e) const { return Node(graph->bNode(e.e)); }
-    Node bNode(const InEdgeIt& e) const { return Node(graph->bNode(e.e)); }
+//     Node aNode(const OutEdgeIt& e) const { return Node(graph->aNode(e.e)); }
+//     Node aNode(const InEdgeIt& e) const { return Node(graph->aNode(e.e)); }
+//     Node bNode(const OutEdgeIt& e) const { return Node(graph->bNode(e.e)); }
+//     Node bNode(const InEdgeIt& e) const { return Node(graph->bNode(e.e)); }
   
     Node addNode() const { return Node(graph->addNode()); }
     Edge addEdge(const Node& tail, const Node& head) const { 
@@ -218,15 +245,15 @@
     template<typename T> class NodeMap : public Graph::template NodeMap<T> { 
       typedef typename Graph::template NodeMap<T> Parent;
     public:
-      NodeMap(const GraphWrapper<Graph>& _G) :  Parent(*(_G.graph)) { }
-      NodeMap(const GraphWrapper<Graph>& _G, T a) : Parent(*(_G.graph), a) { }
+      NodeMap(const GraphWrapper<Graph>& gw) :  Parent(*(gw.graph)) { }
+      NodeMap(const GraphWrapper<Graph>& gw, T a) : Parent(*(gw.graph), a) { }
     };
 
     template<typename T> class EdgeMap : public Graph::template EdgeMap<T> { 
       typedef typename Graph::template EdgeMap<T> Parent;
     public:
-      EdgeMap(const GraphWrapper<Graph>& _G) : Parent(*(_G.graph)) { }
-      EdgeMap(const GraphWrapper<Graph>& _G, T a) : Parent(*(_G.graph), a) { }
+      EdgeMap(const GraphWrapper<Graph>& gw) : Parent(*(gw.graph)) { }
+      EdgeMap(const GraphWrapper<Graph>& gw, T a) : Parent(*(gw.graph), a) { }
     };
   };
 
@@ -246,6 +273,7 @@
     RevGraphWrapper() : GraphWrapper<Graph>() { }
   public:
     RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
+    RevGraphWrapper(const RevGraphWrapper<Graph>& gw) : Parent(gw) { }
 
     typedef typename GraphWrapper<Graph>::Node Node;
     typedef typename GraphWrapper<Graph>::Edge Edge;
@@ -256,29 +284,39 @@
     //typedef typename GraphWrapper<Graph>::OutEdgeIt InEdgeIt;
     //typedef typename GraphWrapper<Graph>::InEdgeIt OutEdgeIt;
 
-    class OutEdgeIt { 
+    class OutEdgeIt : public Edge { 
+      const RevGraphWrapper<Graph>* gw;
       friend class GraphWrapper<Graph>;
-      friend class RevGraphWrapper<Graph>;
-      typename Graph::InEdgeIt e;
-    public:
+     public:
       OutEdgeIt() { }
-      OutEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
-      OutEdgeIt(const Invalid& i) : e(i) { }
-      OutEdgeIt(const RevGraphWrapper<Graph>& _G, const Node& _n) : 
-	e(*(_G.graph), typename Graph::Node(_n)) { }
-      operator Edge() const { return Edge(typename Graph::Edge(e)); }
+      OutEdgeIt(const Edge& e) : Edge(e) { }
+      OutEdgeIt(Invalid i) : Edge(i) { }
+      OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) : 
+	Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
+      OutEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) : 
+	Edge(e), gw(&_gw) { }
+      OutEdgeIt& operator++() { 
+	*(static_cast<Edge*>(this))=
+	  ++(typename Graph::InEdgeIt(*(gw->graph), *this));
+	return *this; 
+      }
     };
-    class InEdgeIt { 
+    class InEdgeIt : public Edge { 
+      const RevGraphWrapper<Graph>* gw;
       friend class GraphWrapper<Graph>;
-      friend class RevGraphWrapper<Graph>;
-      typename Graph::OutEdgeIt e;
-    public:
+     public:
       InEdgeIt() { }
-      InEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
-      InEdgeIt(const Invalid& i) : e(i) { }
-      InEdgeIt(const RevGraphWrapper<Graph>& _G, const Node& _n) : 
-	e(*(_G.graph), typename Graph::Node(_n)) { }
-      operator Edge() const { return Edge(typename Graph::Edge(e)); }
+      InEdgeIt(const Edge& e) : Edge(e) { }
+      InEdgeIt(Invalid i) : Edge(i) { }
+      InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Node& n) : 
+	Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) { }
+      InEdgeIt(const RevGraphWrapper<Graph>& _gw, const Edge& e) : 
+	Edge(e), gw(&_gw) { }
+      InEdgeIt& operator++() { 
+	*(static_cast<Edge*>(this))=
+	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+	return *this; 
+      }
     };
 
     using GraphWrapper<Graph>::first;
@@ -289,18 +327,18 @@
       i=InEdgeIt(*this, p); return i;
     }
 
-    using GraphWrapper<Graph>::next;
-    OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; }
-    InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; }
-
-    Node aNode(const OutEdgeIt& e) const { 
-      return Node(this->graph->aNode(e.e)); }
-    Node aNode(const InEdgeIt& e) const { 
-      return Node(this->graph->aNode(e.e)); }
-    Node bNode(const OutEdgeIt& e) const { 
-      return Node(this->graph->bNode(e.e)); }
-    Node bNode(const InEdgeIt& e) const { 
-      return Node(this->graph->bNode(e.e)); }
+//     using GraphWrapper<Graph>::next;
+//     OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; }
+//     InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; }
+
+//     Node aNode(const OutEdgeIt& e) const { 
+//       return Node(this->graph->aNode(e.e)); }
+//     Node aNode(const InEdgeIt& e) const { 
+//       return Node(this->graph->aNode(e.e)); }
+//     Node bNode(const OutEdgeIt& e) const { 
+//       return Node(this->graph->bNode(e.e)); }
+//     Node bNode(const InEdgeIt& e) const { 
+//       return Node(this->graph->bNode(e.e)); }
 
     Node tail(const Edge& e) const { 
       return GraphWrapper<Graph>::head(e); }
@@ -309,8 +347,6 @@
 
   };
 
-
-
   /// A graph wrapper for hiding nodes and edges from a graph.
   
   /// This wrapper shows a graph with filtered node-set and 

Modified: hugo/branches/hugo++/src/work/marci/bfs_dfs.h
==============================================================================
--- hugo/branches/hugo++/src/work/marci/bfs_dfs.h	(original)
+++ hugo/branches/hugo++/src/work/marci/bfs_dfs.h	Thu Aug 26 17:18:33 2004
@@ -60,8 +60,8 @@
       if (bfs_queue.empty()) {
 	bfs_queue.push(s);
 	graph->first(actual_edge, s);
-	if (graph->valid(actual_edge)) { 
-	  Node w=graph->bNode(actual_edge);
+	if (actual_edge!=INVALID) { 
+	  Node w=graph->head(actual_edge);
 	  if (!reached[w]) {
 	    bfs_queue.push(w);
 	    reached.set(w, true);
@@ -78,10 +78,10 @@
     /// its \c operator++() iterates on the edges in a bfs order.
     BfsIterator<Graph, /*OutEdgeIt,*/ ReachedMap>& 
     operator++() { 
-      if (graph->valid(actual_edge)) { 
-	graph->next(actual_edge);
-	if (graph->valid(actual_edge)) {
-	  Node w=graph->bNode(actual_edge);
+      if (actual_edge!=INVALID) { 
+	++actual_edge;
+	if (actual_edge!=INVALID) {
+	  Node w=graph->head(actual_edge);
 	  if (!reached[w]) {
 	    bfs_queue.push(w);
 	    reached.set(w, true);
@@ -94,8 +94,8 @@
 	bfs_queue.pop(); 
 	if (!bfs_queue.empty()) {
 	  graph->first(actual_edge, bfs_queue.front());
-	  if (graph->valid(actual_edge)) {
-	    Node w=graph->bNode(actual_edge);
+	  if (actual_edge!=INVALID) {
+	    Node w=graph->head(actual_edge);
 	    if (!reached[w]) {
 	      bfs_queue.push(w);
 	      reached.set(w, true);
@@ -117,7 +117,7 @@
     /// Returns if b-node has been reached just now.
     bool isBNodeNewlyReached() const { return b_node_newly_reached; }
     /// Returns if a-node is examined.
-    bool isANodeExamined() const { return !(graph->valid(actual_edge)); }
+    bool isANodeExamined() const { return actual_edge==INVALID; }
     /// Returns a-node of the actual edge, so does if the edge is invalid.
     Node aNode() const { return bfs_queue.front(); }
     /// \pre The actual edge have to be valid.
@@ -237,8 +237,8 @@
     operator++() { 
       actual_edge=dfs_stack.top();
       //actual_node=G.aNode(actual_edge);
-      if (graph->valid(actual_edge)/*.valid()*/) { 
-	Node w=graph->bNode(actual_edge);
+      if (actual_edge!=INVALID/*.valid()*/) { 
+	Node w=graph->head(actual_edge);
 	actual_node=w;
 	if (!reached[w]) {
 	  OutEdgeIt e;
@@ -247,8 +247,8 @@
 	  reached.set(w, true);
 	  b_node_newly_reached=true;
 	} else {
-	  actual_node=graph->aNode(actual_edge);
-	  graph->next(dfs_stack.top());
+	  actual_node=graph->tail(actual_edge);
+	  ++dfs_stack.top();
 	  b_node_newly_reached=false;
 	}
       } else {
@@ -266,7 +266,7 @@
     /// Returns if b-node has been reached just now.
     bool isBNodeNewlyReached() const { return b_node_newly_reached; }
     /// Returns if a-node is examined.
-    bool isANodeExamined() const { return !(graph->valid(actual_edge)); }
+    bool isANodeExamined() const { return actual_edge==INVALID; }
     /// Returns a-node of the actual edge, so does if the edge is invalid.
     Node aNode() const { return actual_node; /*FIXME*/}
     /// Returns b-node of the actual edge. 

Modified: hugo/branches/hugo++/src/work/marci/iterator_bfs_demo.cc
==============================================================================
--- hugo/branches/hugo++/src/work/marci/iterator_bfs_demo.cc	(original)
+++ hugo/branches/hugo++/src/work/marci/iterator_bfs_demo.cc	Thu Aug 26 17:18:33 2004
@@ -4,7 +4,7 @@
 #include <string>
 
 #include <sage_graph.h>
-//#include <smart_graph.h>
+#include <hugo/smart_graph.h>
 #include <bfs_dfs.h>
 #include <hugo/graph_wrapper.h>
 
@@ -91,13 +91,13 @@
     EdgeNameMap< Graph, Graph::NodeMap<string> > edge_name(G, node_name);
     
     cout << "bfs and dfs iterator demo on the directed graph" << endl;
-    for(Graph::NodeIt n(G); G.valid(n); G.next(n)) { 
+    for(Graph::NodeIt n(G); n!=INVALID; ++n) { 
       cout << node_name[n] << ": ";
       cout << "out edges: ";
-      for(Graph::OutEdgeIt e(G, n); G.valid(e); G.next(e)) 
+      for(Graph::OutEdgeIt e(G, n); e!=INVALID; ++e) 
 	cout << edge_name[e] << " ";
       cout << "in edges: ";
-      for(Graph::InEdgeIt e(G, n); G.valid(e); G.next(e)) 
+      for(Graph::InEdgeIt e(G, n); e!=INVALID; ++e) 
 	cout << edge_name[e] << " ";
       cout << endl;
     }
@@ -107,11 +107,11 @@
     bfs.pushAndSetReached(s);
     while (!bfs.finished()) {
       //cout << "edge: ";
-      if (G.valid(bfs)) {
+      if (Graph::Edge(Graph::OutEdgeIt(bfs))!=INVALID) {
 	cout << edge_name[bfs] << /*endl*/", " << 
-	  node_name[G.aNode(bfs)] << 
+	  node_name[G.tail(bfs)] << 
 	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
-	  node_name[G.bNode(bfs)] << 
+	  node_name[G.head(bfs)] << 
 	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
 	   ": is not newly reached.");
       } else { 
@@ -141,11 +141,11 @@
     while (!dfs.finished()) {
       ++dfs;
       //cout << "edge: ";
-      if (G.valid(dfs)) {
+      if (Graph::Edge(Graph::OutEdgeIt(dfs))!=INVALID) {
 	cout << edge_name[dfs] << /*endl*/", " << 
-	  node_name[G.aNode(dfs)] << 
+	  node_name[G.tail(dfs)] << 
 	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
-	  node_name[G.bNode(dfs)] << 
+	  node_name[G.head(dfs)] << 
 	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
 	   ": is not newly reached.");
       } else { 
@@ -167,13 +167,13 @@
     EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
     
     cout << "bfs and dfs iterator demo on the reversed directed graph" << endl;
-    for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
+    for(GW::NodeIt n(gw); n!=INVALID; ++n) { 
       cout << node_name[GW::Node(n)] << ": ";
       cout << "out edges: ";
-      for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
+      for(GW::OutEdgeIt e(gw, n); e!=INVALID; ++e) 
 	cout << edge_name[e] << " ";
       cout << "in edges: ";
-      for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
+      for(GW::InEdgeIt e(gw, n); e!=INVALID; ++e) 
 	cout << edge_name[e] << " ";
       cout << endl;
     }
@@ -183,11 +183,11 @@
     bfs.pushAndSetReached(t);
     while (!bfs.finished()) {
       //cout << "edge: ";
-      if (gw.valid(GW::OutEdgeIt(bfs))) {
+      if (GW::Edge(GW::OutEdgeIt(bfs))!=INVALID) {
 	cout << edge_name[GW::OutEdgeIt(bfs)] << /*endl*/", " << 
-	  node_name[gw.aNode(bfs)] << 
+	  node_name[gw.tail(bfs)] << 
 	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
-	  node_name[gw.bNode(bfs)] << 
+	  node_name[gw.head(bfs)] << 
 	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
 	   ": is not newly reached.");
       } else { 
@@ -217,11 +217,11 @@
     while (!dfs.finished()) {
       ++dfs;
       //cout << "edge: ";
-      if (gw.valid(GW::OutEdgeIt(dfs))) {
+      if (GW::OutEdgeIt(dfs)!=INVALID) {
 	cout << edge_name[GW::OutEdgeIt(dfs)] << /*endl*/", " << 
-	  node_name[gw.aNode(dfs)] << 
+	  node_name[gw.tail(dfs)] << 
 	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
-	  node_name[gw.bNode(dfs)] << 
+	  node_name[gw.head(dfs)] << 
 	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
 	   ": is not newly reached.");
       } else { 
@@ -235,167 +235,165 @@
     }
   }
 
-  {
-    typedef UndirGraphWrapper<const Graph> GW;
-    GW gw(G);
+//   {
+//     typedef UndirGraphWrapper<const Graph> GW;
+//     GW gw(G);
     
-    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
+//     EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
     
-    cout << "bfs and dfs iterator demo on the undirected graph" << endl;
-    for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
-      cout << node_name[GW::Node(n)] << ": ";
-      cout << "out edges: ";
-      for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
-	cout << edge_name[e] << " ";
-      cout << "in edges: ";
-      for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
-	cout << edge_name[e] << " ";
-      cout << endl;
-    }
-//     for(GW::EdgeIt e=gw.first<GW::EdgeIt>(); gw.valid(e); gw.next(e)) { 
-//       cout << edge_name.get(e) << " ";
+//     cout << "bfs and dfs iterator demo on the undirected graph" << endl;
+//     for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
+//       cout << node_name[GW::Node(n)] << ": ";
+//       cout << "out edges: ";
+//       for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
+// 	cout << edge_name[e] << " ";
+//       cout << "in edges: ";
+//       for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
+// 	cout << edge_name[e] << " ";
+//       cout << endl;
 //     }
-//     cout << endl;
-
-    cout << "bfs from t ..." << endl;
-    BfsIterator< GW, GW::NodeMap<bool> > bfs(gw);
-    bfs.pushAndSetReached(t);
-    while (!bfs.finished()) {
-      //cout << "edge: ";
-      if (gw.valid(GW::OutEdgeIt(bfs))) {
-	cout << edge_name[GW::OutEdgeIt(bfs)] << /*endl*/", " << 
-	  node_name[gw.aNode(bfs)] << 
-	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
-	  node_name[gw.bNode(bfs)] << 
-	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
-	   ": is not newly reached.");
-      } else { 
-	cout << "invalid" << /*endl*/", " << 
-	  node_name[bfs.aNode()] << 
-	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
+// //     for(GW::EdgeIt e=gw.first<GW::EdgeIt>(); gw.valid(e); gw.next(e)) { 
+// //       cout << edge_name.get(e) << " ";
+// //     }
+// //     cout << endl;
+
+//     cout << "bfs from t ..." << endl;
+//     BfsIterator< GW, GW::NodeMap<bool> > bfs(gw);
+//     bfs.pushAndSetReached(t);
+//     while (!bfs.finished()) {
+//       //cout << "edge: ";
+//       if (gw.valid(GW::OutEdgeIt(bfs))) {
+// 	cout << edge_name[GW::OutEdgeIt(bfs)] << /*endl*/", " << 
+// 	  node_name[gw.aNode(bfs)] << 
+// 	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
+// 	  node_name[gw.bNode(bfs)] << 
+// 	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
+// 	   ": is not newly reached.");
+//       } else { 
+// 	cout << "invalid" << /*endl*/", " << 
+// 	  node_name[bfs.aNode()] << 
+// 	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
 	  
-	  "invalid.";
-      }
-      cout << endl;
-      ++bfs;
-    }
+// 	  "invalid.";
+//       }
+//       cout << endl;
+//       ++bfs;
+//     }
 
-    cout << "    /-->    ------------->            "<< endl;
-    cout << "   / /-- v1 <-\\      /---- v3-\\      "<< endl;
-    cout << "  / |          |    /  /->     \\     "<< endl;
-    cout << " /  |          |   /  |    ^    \\  "<< endl;
-    cout << "s   |          |  /   |    |     \\->  t "<< endl;
-    cout << " \\  |          | /    |    |     /->  "<< endl;
-    cout << "  \\ |       --/ /     |    |    /     "<< endl;
-    cout << "   \\ \\-> v2 <--/       \\-- v4 -/      "<< endl;
-    cout << "    \\-->    ------------->         "<< endl;
+//     cout << "    /-->    ------------->            "<< endl;
+//     cout << "   / /-- v1 <-\\      /---- v3-\\      "<< endl;
+//     cout << "  / |          |    /  /->     \\     "<< endl;
+//     cout << " /  |          |   /  |    ^    \\  "<< endl;
+//     cout << "s   |          |  /   |    |     \\->  t "<< endl;
+//     cout << " \\  |          | /    |    |     /->  "<< endl;
+//     cout << "  \\ |       --/ /     |    |    /     "<< endl;
+//     cout << "   \\ \\-> v2 <--/       \\-- v4 -/      "<< endl;
+//     cout << "    \\-->    ------------->         "<< endl;
     
-    cout << "dfs from t ..." << endl;
-    DfsIterator< GW, GW::NodeMap<bool> > dfs(gw);
-    dfs.pushAndSetReached(t);
-    while (!dfs.finished()) {
-      ++dfs;
-      //cout << "edge: ";
-      if (gw.valid(GW::OutEdgeIt(dfs))) {
-	cout << edge_name[GW::OutEdgeIt(dfs)] << /*endl*/", " << 
-	  node_name[gw.aNode(dfs)] << 
-	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
-	  node_name[gw.bNode(dfs)] << 
-	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
-	   ": is not newly reached.");
-      } else { 
-	cout << "invalid" << /*endl*/", " << 
-	  node_name[dfs.aNode()] << 
-	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
+//     cout << "dfs from t ..." << endl;
+//     DfsIterator< GW, GW::NodeMap<bool> > dfs(gw);
+//     dfs.pushAndSetReached(t);
+//     while (!dfs.finished()) {
+//       ++dfs;
+//       //cout << "edge: ";
+//       if (gw.valid(GW::OutEdgeIt(dfs))) {
+// 	cout << edge_name[GW::OutEdgeIt(dfs)] << /*endl*/", " << 
+// 	  node_name[gw.aNode(dfs)] << 
+// 	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
+// 	  node_name[gw.bNode(dfs)] << 
+// 	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
+// 	   ": is not newly reached.");
+//       } else { 
+// 	cout << "invalid" << /*endl*/", " << 
+// 	  node_name[dfs.aNode()] << 
+// 	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
 	  
-	  "invalid.";
-      }
-      cout << endl;
-    }
-  }
+// 	  "invalid.";
+//       }
+//       cout << endl;
+//     }
+//   }
 
 
 
-  {
-    typedef BidirGraphWrapper<const Graph> GW;
-    GW gw(G);
+//   {
+//     typedef BidirGraphWrapper<const Graph> GW;
+//     GW gw(G);
     
-    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
+//     EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
     
-    cout << "bfs and dfs iterator demo on the undirected graph" << endl;
-    for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
-      cout << node_name[GW::Node(n)] << ": ";
-      cout << "out edges: ";
-      for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
-	cout << edge_name[e] << " ";
-      cout << "in edges: ";
-      for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
-	cout << edge_name[e] << " ";
-      cout << endl;
-    }
-//     for(GW::EdgeIt e=gw.first<GW::EdgeIt>(); gw.valid(e); gw.next(e)) { 
-//       cout << edge_name.get(e) << " ";
+//     cout << "bfs and dfs iterator demo on the undirected graph" << endl;
+//     for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
+//       cout << node_name[GW::Node(n)] << ": ";
+//       cout << "out edges: ";
+//       for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
+// 	cout << edge_name[e] << " ";
+//       cout << "in edges: ";
+//       for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
+// 	cout << edge_name[e] << " ";
+//       cout << endl;
 //     }
-//     cout << endl;
-
-    cout << "bfs from t ..." << endl;
-    BfsIterator< GW, GW::NodeMap<bool> > bfs(gw);
-    bfs.pushAndSetReached(t);
-    while (!bfs.finished()) {
-      //cout << "edge: ";
-      if (gw.valid(GW::OutEdgeIt(bfs))) {
-	cout << edge_name[GW::OutEdgeIt(bfs)] << /*endl*/", " << 
-	  node_name[gw.aNode(bfs)] << 
-	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
-	  node_name[gw.bNode(bfs)] << 
-	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
-	   ": is not newly reached.");
-      } else { 
-	cout << "invalid" << /*endl*/", " << 
-	  node_name[bfs.aNode()] << 
-	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
+// //     for(GW::EdgeIt e=gw.first<GW::EdgeIt>(); gw.valid(e); gw.next(e)) { 
+// //       cout << edge_name.get(e) << " ";
+// //     }
+// //     cout << endl;
+
+//     cout << "bfs from t ..." << endl;
+//     BfsIterator< GW, GW::NodeMap<bool> > bfs(gw);
+//     bfs.pushAndSetReached(t);
+//     while (!bfs.finished()) {
+//       //cout << "edge: ";
+//       if (gw.valid(GW::OutEdgeIt(bfs))) {
+// 	cout << edge_name[GW::OutEdgeIt(bfs)] << /*endl*/", " << 
+// 	  node_name[gw.aNode(bfs)] << 
+// 	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
+// 	  node_name[gw.bNode(bfs)] << 
+// 	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
+// 	   ": is not newly reached.");
+//       } else { 
+// 	cout << "invalid" << /*endl*/", " << 
+// 	  node_name[bfs.aNode()] << 
+// 	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
 	  
-	  "invalid.";
-      }
-      cout << endl;
-      ++bfs;
-    }
+// 	  "invalid.";
+//       }
+//       cout << endl;
+//       ++bfs;
+//     }
 
-    cout << "    /-->    ------------->            "<< endl;
-    cout << "   / /-- v1 <-\\      /---- v3-\\      "<< endl;
-    cout << "  / |          |    /  /->     \\     "<< endl;
-    cout << " /  |          |   /  |    ^    \\  "<< endl;
-    cout << "s   |          |  /   |    |     \\->  t "<< endl;
-    cout << " \\  |          | /    |    |     /->  "<< endl;
-    cout << "  \\ |       --/ /     |    |    /     "<< endl;
-    cout << "   \\ \\-> v2 <--/       \\-- v4 -/      "<< endl;
-    cout << "    \\-->    ------------->         "<< endl;
+//     cout << "    /-->    ------------->            "<< endl;
+//     cout << "   / /-- v1 <-\\      /---- v3-\\      "<< endl;
+//     cout << "  / |          |    /  /->     \\     "<< endl;
+//     cout << " /  |          |   /  |    ^    \\  "<< endl;
+//     cout << "s   |          |  /   |    |     \\->  t "<< endl;
+//     cout << " \\  |          | /    |    |     /->  "<< endl;
+//     cout << "  \\ |       --/ /     |    |    /     "<< endl;
+//     cout << "   \\ \\-> v2 <--/       \\-- v4 -/      "<< endl;
+//     cout << "    \\-->    ------------->         "<< endl;
     
-    cout << "dfs from t ..." << endl;
-    DfsIterator< GW, GW::NodeMap<bool> > dfs(gw);
-    dfs.pushAndSetReached(t);
-    while (!dfs.finished()) {
-      ++dfs;
-      //cout << "edge: ";
-      if (gw.valid(GW::OutEdgeIt(dfs))) {
-	cout << edge_name[GW::OutEdgeIt(dfs)] << /*endl*/", " << 
-	  node_name[gw.aNode(dfs)] << 
-	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
-	  node_name[gw.bNode(dfs)] << 
-	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
-	   ": is not newly reached.");
-      } else { 
-	cout << "invalid" << /*endl*/", " << 
-	  node_name[dfs.aNode()] << 
-	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
+//     cout << "dfs from t ..." << endl;
+//     DfsIterator< GW, GW::NodeMap<bool> > dfs(gw);
+//     dfs.pushAndSetReached(t);
+//     while (!dfs.finished()) {
+//       ++dfs;
+//       //cout << "edge: ";
+//       if (gw.valid(GW::OutEdgeIt(dfs))) {
+// 	cout << edge_name[GW::OutEdgeIt(dfs)] << /*endl*/", " << 
+// 	  node_name[gw.aNode(dfs)] << 
+// 	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
+// 	  node_name[gw.bNode(dfs)] << 
+// 	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
+// 	   ": is not newly reached.");
+//       } else { 
+// 	cout << "invalid" << /*endl*/", " << 
+// 	  node_name[dfs.aNode()] << 
+// 	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
 	  
-	  "invalid.";
-      }
-      cout << endl;
-    }
-  }
-
-
+// 	  "invalid.";
+//       }
+//       cout << endl;
+//     }
+//   }
 
   return 0;
 }



More information about the Lemon-commits mailing list