[Lemon-commits] [lemon_svn] marci: r371 - in hugo/trunk/src/work: . marci

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


Author: marci
Date: Tue Mar 30 15:37:21 2004
New Revision: 371

Modified:
   hugo/trunk/src/work/edmonds_karp.h
   hugo/trunk/src/work/iterator_bfs_demo.cc
   hugo/trunk/src/work/list_graph.h
   hugo/trunk/src/work/marci/graph_wrapper.h

Log:
GraphWrappers


Modified: hugo/trunk/src/work/edmonds_karp.h
==============================================================================
--- hugo/trunk/src/work/edmonds_karp.h	(original)
+++ hugo/trunk/src/work/edmonds_karp.h	Tue Mar 30 15:37:21 2004
@@ -479,8 +479,8 @@
 //       }
 
       MutableGraph F;
-      typedef SubGraphWrapper<AugGraph, DistanceMap<AugGraph> > FilterResGraph;
-      FilterResGraph filter_res_graph(res_graph, dist);
+      //typedef SubGraphWrapper<AugGraph, DistanceMap<AugGraph> > FilterResGraph;
+      //FilterResGraph filter_res_graph(res_graph, dist);
       typename AugGraph::NodeMap<typename MutableGraph::Node> 
 	res_graph_to_F(res_graph);
       for(typename AugGraph::NodeIt n=res_graph.template first<typename AugGraph::NodeIt>(); res_graph.valid(n); res_graph.next(n)) {
@@ -495,7 +495,9 @@
 
       //Making F to the graph containing the edges of the residual graph 
       //which are in some shortest paths
-      for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); res_graph.valid(e); res_graph.next(e)) {
+      for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); 
+	  res_graph.valid(e); 
+	  res_graph.next(e)) {
 	if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
 	  typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
 	  original_edge.update();

Modified: hugo/trunk/src/work/iterator_bfs_demo.cc
==============================================================================
--- hugo/trunk/src/work/iterator_bfs_demo.cc	(original)
+++ hugo/trunk/src/work/iterator_bfs_demo.cc	Tue Mar 30 15:37:21 2004
@@ -99,7 +99,9 @@
     EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
     
     cout << "bfs and dfs iterator demo on the directed graph" << endl;
-    for(GW::NodeIt n=gw.first<GW::NodeIt>(); gw.valid(n); gw.next(n)) { 
+    for(GW::NodeIt n=gw.first<GW::NodeIt>(); 
+	gw.valid(n); 
+	gw.next(n)) { 
       cout << node_name.get(n) << ": ";
       cout << "out edges: ";
       for(GW::OutEdgeIt e=gw.first<GW::OutEdgeIt>(n); gw.valid(e); gw.next(e)) 

Modified: hugo/trunk/src/work/list_graph.h
==============================================================================
--- hugo/trunk/src/work/list_graph.h	(original)
+++ hugo/trunk/src/work/list_graph.h	Tue Mar 30 15:37:21 2004
@@ -310,8 +310,14 @@
     bool valid(Edge e) const { return e.valid(); }
     
     template <typename It> It getNext(It it) const { 
-      It tmp(it); return next(tmp); }
-    template <typename It> It& next(It& it) const { return ++it; }
+      It tmp(it); next(tmp); return tmp; }
+//     NodeIt& next(NodeIt& it) const { return ++it; }
+//     EdgeIt& next(EdgeIt& it) const { return ++it; }
+//     OutEdgeIt& next(OutEdgeIt& it) const { return ++it; }
+//     InEdgeIt& next(InEdgeIt& it) const { return ++it; }
+//     SymEdgeIt& next(SymEdgeIt& it) const { return ++it; }
+//    template <typename It> It& next(It& it) const { return ++it; }
+    template <typename It> It& next(It& it) const { ++it; return it; }
    
 
     /* for getting id's of graph objects */

Modified: hugo/trunk/src/work/marci/graph_wrapper.h
==============================================================================
--- hugo/trunk/src/work/marci/graph_wrapper.h	(original)
+++ hugo/trunk/src/work/marci/graph_wrapper.h	Tue Mar 30 15:37:21 2004
@@ -15,27 +15,80 @@
     typedef Graph BaseGraph;
 
     typedef typename Graph::Node Node;
-    typedef typename Graph::NodeIt NodeIt;
-
+    class NodeIt : public Graph::NodeIt { 
+    public:
+      NodeIt() { }
+      NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { }
+      NodeIt(const Invalid& i) : Graph::NodeIt(i) { }
+      NodeIt(const TrivGraphWrapper<Graph>& _G) : 
+	Graph::NodeIt(*(_G.graph)) { }
+    };
     typedef typename Graph::Edge Edge;
-    typedef typename Graph::OutEdgeIt OutEdgeIt;
-    typedef typename Graph::InEdgeIt InEdgeIt;
+    //typedef typename Graph::OutEdgeIt OutEdgeIt;
+    class OutEdgeIt : public Graph::OutEdgeIt { 
+    public:
+      OutEdgeIt() { }
+      OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { }
+      OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { }
+      OutEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) : 
+	Graph::OutEdgeIt(*(_G.graph), n) { }
+    };
+    //typedef typename Graph::InEdgeIt InEdgeIt;
+    class InEdgeIt : public Graph::InEdgeIt { 
+    public:
+      InEdgeIt() { }
+      InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { }
+      InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { }
+      InEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) : 
+	Graph::InEdgeIt(*(_G.graph), n) { }
+    };
     //typedef typename Graph::SymEdgeIt SymEdgeIt;
-    typedef typename Graph::EdgeIt EdgeIt;
+    //typedef typename Graph::EdgeIt EdgeIt;
+    class EdgeIt : public Graph::EdgeIt { 
+    public:
+      EdgeIt() { }
+      EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { }
+      EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { }
+      EdgeIt(const TrivGraphWrapper<Graph>& _G) : 
+	Graph::EdgeIt(*(_G.graph)) { }
+    };
 
     //TrivGraphWrapper() : graph(0) { }
     TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
 
-    void setGraph(Graph& _graph) { graph = &_graph; }
-    Graph& getGraph() const { return (*graph); }
-    
-    template<typename I> I& first(I& i) const { return graph->first(i); }
-    template<typename I, typename P> I& first(I& i, const P& p) const { 
-      return graph->first(i, p); }
+//    void setGraph(Graph& _graph) { graph = &_graph; }
+//    Graph& getGraph() const { return (*graph); }
+
+    NodeIt& first(NodeIt& i) const { 
+      i=NodeIt(*this);
+      return i;
+    }
+    EdgeIt& first(EdgeIt& i) const { 
+      i=EdgeIt(*this);
+      return i;
+    }
+//     template<typename I> I& first(I& i) const { 
+//       //return graph->first(i); 
+//       i=I(*this);
+//       return i;
+//     }
+    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
+      i=OutEdgeIt(*this, p);
+      return i;
+    }
+    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
+      i=InEdgeIt(*this, p);
+      return i;
+    }
+//     template<typename I, typename P> I& first(I& i, const P& p) const { 
+//       //return graph->first(i, p);
+//       i=I(*this, p);
+//       return i;
+//     }
     
-    template<typename I> I getNext(const I& i) const { 
-      return graph->getNext(i); }
-    template<typename I> I& next(I &i) const { return graph->next(i); }    
+//    template<typename I> I getNext(const I& i) const { 
+//      return graph->getNext(i); }
+    template<typename I> I& next(I &i) const { graph->next(i); return i; }    
 
     template< typename It > It first() const { 
       It e; first(e); return e; }
@@ -71,17 +124,17 @@
     template<typename T> class NodeMap : public Graph::NodeMap<T> { 
     public:
       NodeMap(const TrivGraphWrapper<Graph>& _G) : 
-	Graph::NodeMap<T>(_G.getGraph()) { }
+	Graph::NodeMap<T>(*(_G.graph)) { }
       NodeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
-	Graph::NodeMap<T>(_G.getGraph(), a) { }
+	Graph::NodeMap<T>(*(_G.graph), a) { }
     };
 
     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
     public:
       EdgeMap(const TrivGraphWrapper<Graph>& _G) : 
-	Graph::EdgeMap<T>(_G.getGraph()) { }
+	Graph::EdgeMap<T>(*(_G.graph)) { }
       EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
-	Graph::EdgeMap<T>(_G.getGraph(), a) { }
+	Graph::EdgeMap<T>(*(_G.graph), a) { }
     };
   };
 
@@ -93,14 +146,58 @@
   public:
     //typedef typename GraphWrapper::BaseGraph BaseGraph;
 
-    typedef typename GraphWrapper::Node Node;
-    typedef typename GraphWrapper::NodeIt NodeIt;
+//     typedef typename GraphWrapper::Node Node;
+//     typedef typename GraphWrapper::NodeIt NodeIt;
 
+//     typedef typename GraphWrapper::Edge Edge;
+//     typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
+//     typedef typename GraphWrapper::InEdgeIt InEdgeIt;
+//     //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
+//     typedef typename GraphWrapper::EdgeIt EdgeIt;
+
+    typedef typename GraphWrapper::Node Node;
+    class NodeIt : public GraphWrapper::NodeIt { 
+    public:
+      NodeIt() { }
+      NodeIt(const typename GraphWrapper::NodeIt& n) : 
+	GraphWrapper::NodeIt(n) { }
+      NodeIt(const Invalid& i) : GraphWrapper::NodeIt(i) { }
+      NodeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
+	GraphWrapper::NodeIt(_G.gw) { }
+    };
     typedef typename GraphWrapper::Edge Edge;
-    typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
-    typedef typename GraphWrapper::InEdgeIt InEdgeIt;
+    //typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
+    class OutEdgeIt : public GraphWrapper::OutEdgeIt { 
+    public:
+      OutEdgeIt() { }
+      OutEdgeIt(const typename GraphWrapper::OutEdgeIt& e) : 
+	GraphWrapper::OutEdgeIt(e) { }
+      OutEdgeIt(const Invalid& i) : GraphWrapper::OutEdgeIt(i) { }
+      OutEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) : 
+	GraphWrapper::OutEdgeIt(_G.gw, n) { }
+    };
+    //typedef typename GraphWrapper::InEdgeIt InEdgeIt;
+    class InEdgeIt : public GraphWrapper::InEdgeIt { 
+    public:
+      InEdgeIt() { }
+      InEdgeIt(const typename GraphWrapper::InEdgeIt& e) : 
+	GraphWrapper::InEdgeIt(e) { }
+      InEdgeIt(const Invalid& i) : GraphWrapper::InEdgeIt(i) { }
+      InEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) : 
+	GraphWrapper::InEdgeIt(_G.gw, n) { }
+    };
     //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
-    typedef typename GraphWrapper::EdgeIt EdgeIt;
+    //typedef typename GraphWrapper::EdgeIt EdgeIt;
+    class EdgeIt : public GraphWrapper::EdgeIt { 
+    public:
+      EdgeIt() { }
+      EdgeIt(const typename GraphWrapper::EdgeIt& e) : 
+	GraphWrapper::EdgeIt(e) { }
+      EdgeIt(const Invalid& i) : GraphWrapper::EdgeIt(i) { }
+      EdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
+	GraphWrapper::EdgeIt(_G.gw) { }
+    };
+
 
     //GraphWrapperSkeleton() : gw() { }
     GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
@@ -108,12 +205,17 @@
     //void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
     //BaseGraph& getGraph() const { return gw.getGraph(); }
     
-    template<typename I> I& first(I& i) const { return gw.first(i); }
+    template<typename I> I& first(I& i) const {       
+      i=I(*this);
+      return i;
+    }
     template<typename I, typename P> I& first(I& i, const P& p) const { 
-      return gw.first(i, p); }
+      i=I(*this, p);
+      return i; 
+    }
     
-    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
-    template<typename I> I& next(I &i) const { return gw.next(i); }    
+//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
+    template<typename I> I& next(I &i) const { gw.next(i); return i; }    
 
     template< typename It > It first() const { 
       It e; this->first(e); return e; }
@@ -655,9 +757,9 @@
       return e;
     }
 
-    template<typename I> I& first(I& i) const { return gw.first(i); }
+    template<typename I> I& first(I& i) const { gw.first(i); return i; }
     template<typename I, typename P> I& first(I& i, const P& p) const { 
-      return graph->first(i, p); }
+      graph->first(i, p); return i; }
 
     OutEdgeIt& next(OutEdgeIt& e) const {
       if (e.out_or_in) {
@@ -681,7 +783,7 @@
     }
 
     template<typename I> I& next(I &i) const { return gw.next(i); }    
-    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
+//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
 
     template< typename It > It first() const { 
       It e; first(e); return e; }
@@ -813,14 +915,14 @@
   class ResGraphWrapper {
   public:
     //typedef Graph BaseGraph;
-    typedef typename Graph::Node Node;
-    typedef typename Graph::NodeIt NodeIt;
+    typedef TrivGraphWrapper<const Graph> GraphWrapper;
+    typedef typename GraphWrapper::Node Node;
+    typedef typename GraphWrapper::NodeIt NodeIt;
   private:
-    typedef typename Graph::OutEdgeIt OldOutEdgeIt;
-    typedef typename Graph::InEdgeIt OldInEdgeIt;
+    typedef typename GraphWrapper::OutEdgeIt OldOutEdgeIt;
+    typedef typename GraphWrapper::InEdgeIt OldInEdgeIt;
   protected:
     //const Graph* graph;
-    typedef TrivGraphWrapper<const Graph> GraphWrapper;
     GraphWrapper gw;
     FlowMap* flow;
     const CapacityMap* capacity;
@@ -871,7 +973,7 @@
       //FIXME
       OutEdgeIt(const Edge& e) : Edge(e) { }
       OutEdgeIt(const Invalid& i) : Edge(i) { }
-    private:
+    protected:
       OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() { 
 	resG.gw.first(out, v);
 	while( resG.gw.valid(out) && !(resG.free(out)>0) ) { resG.gw.next(out); }
@@ -905,7 +1007,7 @@
 
     class EdgeIt : public Edge {
       friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
-      typename Graph::NodeIt v;
+      NodeIt v; 
     public:
       EdgeIt() { }
       //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }



More information about the Lemon-commits mailing list