GraphWrappers
authormarci
Tue, 30 Mar 2004 13:37:21 +0000
changeset 265bf7aea53635a
parent 264 fe81c4b117f4
child 266 4cec4981dfd1
GraphWrappers
src/work/edmonds_karp.h
src/work/iterator_bfs_demo.cc
src/work/list_graph.h
src/work/marci/graph_wrapper.h
     1.1 --- a/src/work/edmonds_karp.h	Tue Mar 30 13:18:10 2004 +0000
     1.2 +++ b/src/work/edmonds_karp.h	Tue Mar 30 13:37:21 2004 +0000
     1.3 @@ -479,8 +479,8 @@
     1.4  //       }
     1.5  
     1.6        MutableGraph F;
     1.7 -      typedef SubGraphWrapper<AugGraph, DistanceMap<AugGraph> > FilterResGraph;
     1.8 -      FilterResGraph filter_res_graph(res_graph, dist);
     1.9 +      //typedef SubGraphWrapper<AugGraph, DistanceMap<AugGraph> > FilterResGraph;
    1.10 +      //FilterResGraph filter_res_graph(res_graph, dist);
    1.11        typename AugGraph::NodeMap<typename MutableGraph::Node> 
    1.12  	res_graph_to_F(res_graph);
    1.13        for(typename AugGraph::NodeIt n=res_graph.template first<typename AugGraph::NodeIt>(); res_graph.valid(n); res_graph.next(n)) {
    1.14 @@ -495,7 +495,9 @@
    1.15  
    1.16        //Making F to the graph containing the edges of the residual graph 
    1.17        //which are in some shortest paths
    1.18 -      for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); res_graph.valid(e); res_graph.next(e)) {
    1.19 +      for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); 
    1.20 +	  res_graph.valid(e); 
    1.21 +	  res_graph.next(e)) {
    1.22  	if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
    1.23  	  typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
    1.24  	  original_edge.update();
     2.1 --- a/src/work/iterator_bfs_demo.cc	Tue Mar 30 13:18:10 2004 +0000
     2.2 +++ b/src/work/iterator_bfs_demo.cc	Tue Mar 30 13:37:21 2004 +0000
     2.3 @@ -99,7 +99,9 @@
     2.4      EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
     2.5      
     2.6      cout << "bfs and dfs iterator demo on the directed graph" << endl;
     2.7 -    for(GW::NodeIt n=gw.first<GW::NodeIt>(); gw.valid(n); gw.next(n)) { 
     2.8 +    for(GW::NodeIt n=gw.first<GW::NodeIt>(); 
     2.9 +	gw.valid(n); 
    2.10 +	gw.next(n)) { 
    2.11        cout << node_name.get(n) << ": ";
    2.12        cout << "out edges: ";
    2.13        for(GW::OutEdgeIt e=gw.first<GW::OutEdgeIt>(n); gw.valid(e); gw.next(e)) 
     3.1 --- a/src/work/list_graph.h	Tue Mar 30 13:18:10 2004 +0000
     3.2 +++ b/src/work/list_graph.h	Tue Mar 30 13:37:21 2004 +0000
     3.3 @@ -310,8 +310,14 @@
     3.4      bool valid(Edge e) const { return e.valid(); }
     3.5      
     3.6      template <typename It> It getNext(It it) const { 
     3.7 -      It tmp(it); return next(tmp); }
     3.8 -    template <typename It> It& next(It& it) const { return ++it; }
     3.9 +      It tmp(it); next(tmp); return tmp; }
    3.10 +//     NodeIt& next(NodeIt& it) const { return ++it; }
    3.11 +//     EdgeIt& next(EdgeIt& it) const { return ++it; }
    3.12 +//     OutEdgeIt& next(OutEdgeIt& it) const { return ++it; }
    3.13 +//     InEdgeIt& next(InEdgeIt& it) const { return ++it; }
    3.14 +//     SymEdgeIt& next(SymEdgeIt& it) const { return ++it; }
    3.15 +//    template <typename It> It& next(It& it) const { return ++it; }
    3.16 +    template <typename It> It& next(It& it) const { ++it; return it; }
    3.17     
    3.18  
    3.19      /* for getting id's of graph objects */
     4.1 --- a/src/work/marci/graph_wrapper.h	Tue Mar 30 13:18:10 2004 +0000
     4.2 +++ b/src/work/marci/graph_wrapper.h	Tue Mar 30 13:37:21 2004 +0000
     4.3 @@ -15,27 +15,80 @@
     4.4      typedef Graph BaseGraph;
     4.5  
     4.6      typedef typename Graph::Node Node;
     4.7 -    typedef typename Graph::NodeIt NodeIt;
     4.8 -
     4.9 +    class NodeIt : public Graph::NodeIt { 
    4.10 +    public:
    4.11 +      NodeIt() { }
    4.12 +      NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { }
    4.13 +      NodeIt(const Invalid& i) : Graph::NodeIt(i) { }
    4.14 +      NodeIt(const TrivGraphWrapper<Graph>& _G) : 
    4.15 +	Graph::NodeIt(*(_G.graph)) { }
    4.16 +    };
    4.17      typedef typename Graph::Edge Edge;
    4.18 -    typedef typename Graph::OutEdgeIt OutEdgeIt;
    4.19 -    typedef typename Graph::InEdgeIt InEdgeIt;
    4.20 +    //typedef typename Graph::OutEdgeIt OutEdgeIt;
    4.21 +    class OutEdgeIt : public Graph::OutEdgeIt { 
    4.22 +    public:
    4.23 +      OutEdgeIt() { }
    4.24 +      OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { }
    4.25 +      OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { }
    4.26 +      OutEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) : 
    4.27 +	Graph::OutEdgeIt(*(_G.graph), n) { }
    4.28 +    };
    4.29 +    //typedef typename Graph::InEdgeIt InEdgeIt;
    4.30 +    class InEdgeIt : public Graph::InEdgeIt { 
    4.31 +    public:
    4.32 +      InEdgeIt() { }
    4.33 +      InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { }
    4.34 +      InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { }
    4.35 +      InEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) : 
    4.36 +	Graph::InEdgeIt(*(_G.graph), n) { }
    4.37 +    };
    4.38      //typedef typename Graph::SymEdgeIt SymEdgeIt;
    4.39 -    typedef typename Graph::EdgeIt EdgeIt;
    4.40 +    //typedef typename Graph::EdgeIt EdgeIt;
    4.41 +    class EdgeIt : public Graph::EdgeIt { 
    4.42 +    public:
    4.43 +      EdgeIt() { }
    4.44 +      EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { }
    4.45 +      EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { }
    4.46 +      EdgeIt(const TrivGraphWrapper<Graph>& _G) : 
    4.47 +	Graph::EdgeIt(*(_G.graph)) { }
    4.48 +    };
    4.49  
    4.50      //TrivGraphWrapper() : graph(0) { }
    4.51      TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
    4.52  
    4.53 -    void setGraph(Graph& _graph) { graph = &_graph; }
    4.54 -    Graph& getGraph() const { return (*graph); }
    4.55 +//    void setGraph(Graph& _graph) { graph = &_graph; }
    4.56 +//    Graph& getGraph() const { return (*graph); }
    4.57 +
    4.58 +    NodeIt& first(NodeIt& i) const { 
    4.59 +      i=NodeIt(*this);
    4.60 +      return i;
    4.61 +    }
    4.62 +    EdgeIt& first(EdgeIt& i) const { 
    4.63 +      i=EdgeIt(*this);
    4.64 +      return i;
    4.65 +    }
    4.66 +//     template<typename I> I& first(I& i) const { 
    4.67 +//       //return graph->first(i); 
    4.68 +//       i=I(*this);
    4.69 +//       return i;
    4.70 +//     }
    4.71 +    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
    4.72 +      i=OutEdgeIt(*this, p);
    4.73 +      return i;
    4.74 +    }
    4.75 +    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
    4.76 +      i=InEdgeIt(*this, p);
    4.77 +      return i;
    4.78 +    }
    4.79 +//     template<typename I, typename P> I& first(I& i, const P& p) const { 
    4.80 +//       //return graph->first(i, p);
    4.81 +//       i=I(*this, p);
    4.82 +//       return i;
    4.83 +//     }
    4.84      
    4.85 -    template<typename I> I& first(I& i) const { return graph->first(i); }
    4.86 -    template<typename I, typename P> I& first(I& i, const P& p) const { 
    4.87 -      return graph->first(i, p); }
    4.88 -    
    4.89 -    template<typename I> I getNext(const I& i) const { 
    4.90 -      return graph->getNext(i); }
    4.91 -    template<typename I> I& next(I &i) const { return graph->next(i); }    
    4.92 +//    template<typename I> I getNext(const I& i) const { 
    4.93 +//      return graph->getNext(i); }
    4.94 +    template<typename I> I& next(I &i) const { graph->next(i); return i; }    
    4.95  
    4.96      template< typename It > It first() const { 
    4.97        It e; first(e); return e; }
    4.98 @@ -71,17 +124,17 @@
    4.99      template<typename T> class NodeMap : public Graph::NodeMap<T> { 
   4.100      public:
   4.101        NodeMap(const TrivGraphWrapper<Graph>& _G) : 
   4.102 -	Graph::NodeMap<T>(_G.getGraph()) { }
   4.103 +	Graph::NodeMap<T>(*(_G.graph)) { }
   4.104        NodeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
   4.105 -	Graph::NodeMap<T>(_G.getGraph(), a) { }
   4.106 +	Graph::NodeMap<T>(*(_G.graph), a) { }
   4.107      };
   4.108  
   4.109      template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
   4.110      public:
   4.111        EdgeMap(const TrivGraphWrapper<Graph>& _G) : 
   4.112 -	Graph::EdgeMap<T>(_G.getGraph()) { }
   4.113 +	Graph::EdgeMap<T>(*(_G.graph)) { }
   4.114        EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
   4.115 -	Graph::EdgeMap<T>(_G.getGraph(), a) { }
   4.116 +	Graph::EdgeMap<T>(*(_G.graph), a) { }
   4.117      };
   4.118    };
   4.119  
   4.120 @@ -93,14 +146,58 @@
   4.121    public:
   4.122      //typedef typename GraphWrapper::BaseGraph BaseGraph;
   4.123  
   4.124 +//     typedef typename GraphWrapper::Node Node;
   4.125 +//     typedef typename GraphWrapper::NodeIt NodeIt;
   4.126 +
   4.127 +//     typedef typename GraphWrapper::Edge Edge;
   4.128 +//     typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
   4.129 +//     typedef typename GraphWrapper::InEdgeIt InEdgeIt;
   4.130 +//     //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
   4.131 +//     typedef typename GraphWrapper::EdgeIt EdgeIt;
   4.132 +
   4.133      typedef typename GraphWrapper::Node Node;
   4.134 -    typedef typename GraphWrapper::NodeIt NodeIt;
   4.135 +    class NodeIt : public GraphWrapper::NodeIt { 
   4.136 +    public:
   4.137 +      NodeIt() { }
   4.138 +      NodeIt(const typename GraphWrapper::NodeIt& n) : 
   4.139 +	GraphWrapper::NodeIt(n) { }
   4.140 +      NodeIt(const Invalid& i) : GraphWrapper::NodeIt(i) { }
   4.141 +      NodeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
   4.142 +	GraphWrapper::NodeIt(_G.gw) { }
   4.143 +    };
   4.144 +    typedef typename GraphWrapper::Edge Edge;
   4.145 +    //typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
   4.146 +    class OutEdgeIt : public GraphWrapper::OutEdgeIt { 
   4.147 +    public:
   4.148 +      OutEdgeIt() { }
   4.149 +      OutEdgeIt(const typename GraphWrapper::OutEdgeIt& e) : 
   4.150 +	GraphWrapper::OutEdgeIt(e) { }
   4.151 +      OutEdgeIt(const Invalid& i) : GraphWrapper::OutEdgeIt(i) { }
   4.152 +      OutEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) : 
   4.153 +	GraphWrapper::OutEdgeIt(_G.gw, n) { }
   4.154 +    };
   4.155 +    //typedef typename GraphWrapper::InEdgeIt InEdgeIt;
   4.156 +    class InEdgeIt : public GraphWrapper::InEdgeIt { 
   4.157 +    public:
   4.158 +      InEdgeIt() { }
   4.159 +      InEdgeIt(const typename GraphWrapper::InEdgeIt& e) : 
   4.160 +	GraphWrapper::InEdgeIt(e) { }
   4.161 +      InEdgeIt(const Invalid& i) : GraphWrapper::InEdgeIt(i) { }
   4.162 +      InEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) : 
   4.163 +	GraphWrapper::InEdgeIt(_G.gw, n) { }
   4.164 +    };
   4.165 +    //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
   4.166 +    //typedef typename GraphWrapper::EdgeIt EdgeIt;
   4.167 +    class EdgeIt : public GraphWrapper::EdgeIt { 
   4.168 +    public:
   4.169 +      EdgeIt() { }
   4.170 +      EdgeIt(const typename GraphWrapper::EdgeIt& e) : 
   4.171 +	GraphWrapper::EdgeIt(e) { }
   4.172 +      EdgeIt(const Invalid& i) : GraphWrapper::EdgeIt(i) { }
   4.173 +      EdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
   4.174 +	GraphWrapper::EdgeIt(_G.gw) { }
   4.175 +    };
   4.176  
   4.177 -    typedef typename GraphWrapper::Edge Edge;
   4.178 -    typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
   4.179 -    typedef typename GraphWrapper::InEdgeIt InEdgeIt;
   4.180 -    //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
   4.181 -    typedef typename GraphWrapper::EdgeIt EdgeIt;
   4.182  
   4.183      //GraphWrapperSkeleton() : gw() { }
   4.184      GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
   4.185 @@ -108,12 +205,17 @@
   4.186      //void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
   4.187      //BaseGraph& getGraph() const { return gw.getGraph(); }
   4.188      
   4.189 -    template<typename I> I& first(I& i) const { return gw.first(i); }
   4.190 +    template<typename I> I& first(I& i) const {       
   4.191 +      i=I(*this);
   4.192 +      return i;
   4.193 +    }
   4.194      template<typename I, typename P> I& first(I& i, const P& p) const { 
   4.195 -      return gw.first(i, p); }
   4.196 +      i=I(*this, p);
   4.197 +      return i; 
   4.198 +    }
   4.199      
   4.200 -    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
   4.201 -    template<typename I> I& next(I &i) const { return gw.next(i); }    
   4.202 +//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
   4.203 +    template<typename I> I& next(I &i) const { gw.next(i); return i; }    
   4.204  
   4.205      template< typename It > It first() const { 
   4.206        It e; this->first(e); return e; }
   4.207 @@ -655,9 +757,9 @@
   4.208        return e;
   4.209      }
   4.210  
   4.211 -    template<typename I> I& first(I& i) const { return gw.first(i); }
   4.212 +    template<typename I> I& first(I& i) const { gw.first(i); return i; }
   4.213      template<typename I, typename P> I& first(I& i, const P& p) const { 
   4.214 -      return graph->first(i, p); }
   4.215 +      graph->first(i, p); return i; }
   4.216  
   4.217      OutEdgeIt& next(OutEdgeIt& e) const {
   4.218        if (e.out_or_in) {
   4.219 @@ -681,7 +783,7 @@
   4.220      }
   4.221  
   4.222      template<typename I> I& next(I &i) const { return gw.next(i); }    
   4.223 -    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
   4.224 +//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
   4.225  
   4.226      template< typename It > It first() const { 
   4.227        It e; first(e); return e; }
   4.228 @@ -813,14 +915,14 @@
   4.229    class ResGraphWrapper {
   4.230    public:
   4.231      //typedef Graph BaseGraph;
   4.232 -    typedef typename Graph::Node Node;
   4.233 -    typedef typename Graph::NodeIt NodeIt;
   4.234 +    typedef TrivGraphWrapper<const Graph> GraphWrapper;
   4.235 +    typedef typename GraphWrapper::Node Node;
   4.236 +    typedef typename GraphWrapper::NodeIt NodeIt;
   4.237    private:
   4.238 -    typedef typename Graph::OutEdgeIt OldOutEdgeIt;
   4.239 -    typedef typename Graph::InEdgeIt OldInEdgeIt;
   4.240 +    typedef typename GraphWrapper::OutEdgeIt OldOutEdgeIt;
   4.241 +    typedef typename GraphWrapper::InEdgeIt OldInEdgeIt;
   4.242    protected:
   4.243      //const Graph* graph;
   4.244 -    typedef TrivGraphWrapper<const Graph> GraphWrapper;
   4.245      GraphWrapper gw;
   4.246      FlowMap* flow;
   4.247      const CapacityMap* capacity;
   4.248 @@ -871,7 +973,7 @@
   4.249        //FIXME
   4.250        OutEdgeIt(const Edge& e) : Edge(e) { }
   4.251        OutEdgeIt(const Invalid& i) : Edge(i) { }
   4.252 -    private:
   4.253 +    protected:
   4.254        OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() { 
   4.255  	resG.gw.first(out, v);
   4.256  	while( resG.gw.valid(out) && !(resG.free(out)>0) ) { resG.gw.next(out); }
   4.257 @@ -905,7 +1007,7 @@
   4.258  
   4.259      class EdgeIt : public Edge {
   4.260        friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
   4.261 -      typename Graph::NodeIt v;
   4.262 +      NodeIt v; 
   4.263      public:
   4.264        EdgeIt() { }
   4.265        //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }