src/work/marci/graph_wrapper.h
changeset 264 fe81c4b117f4
parent 259 509ba9f136d2
child 265 bf7aea53635a
equal deleted inserted replaced
18:8a2881f722da 19:bf251a3fe414
    89   class GraphWrapperSkeleton {
    89   class GraphWrapperSkeleton {
    90   protected:
    90   protected:
    91     GraphWrapper gw;
    91     GraphWrapper gw;
    92   
    92   
    93   public:
    93   public:
    94     typedef typename GraphWrapper::BaseGraph BaseGraph;
    94     //typedef typename GraphWrapper::BaseGraph BaseGraph;
    95 
    95 
    96     typedef typename GraphWrapper::Node Node;
    96     typedef typename GraphWrapper::Node Node;
    97     typedef typename GraphWrapper::NodeIt NodeIt;
    97     typedef typename GraphWrapper::NodeIt NodeIt;
    98 
    98 
    99     typedef typename GraphWrapper::Edge Edge;
    99     typedef typename GraphWrapper::Edge Edge;
   103     typedef typename GraphWrapper::EdgeIt EdgeIt;
   103     typedef typename GraphWrapper::EdgeIt EdgeIt;
   104 
   104 
   105     //GraphWrapperSkeleton() : gw() { }
   105     //GraphWrapperSkeleton() : gw() { }
   106     GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
   106     GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
   107 
   107 
   108     void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
   108     //void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
   109     BaseGraph& getGraph() const { return gw.getGraph(); }
   109     //BaseGraph& getGraph() const { return gw.getGraph(); }
   110     
   110     
   111     template<typename I> I& first(I& i) const { return gw.first(i); }
   111     template<typename I> I& first(I& i) const { return gw.first(i); }
   112     template<typename I, typename P> I& first(I& i, const P& p) const { 
   112     template<typename I, typename P> I& first(I& i, const P& p) const { 
   113       return gw.first(i, p); }
   113       return gw.first(i, p); }
   114     
   114     
   340       { return GraphWrapperSkeleton<GraphWrapper>::tail(e); }
   340       { return GraphWrapperSkeleton<GraphWrapper>::tail(e); }
   341     Node tail(const Edge& e) const 
   341     Node tail(const Edge& e) const 
   342       { return GraphWrapperSkeleton<GraphWrapper>::head(e); }
   342       { return GraphWrapperSkeleton<GraphWrapper>::head(e); }
   343   };
   343   };
   344 
   344 
       
   345   //Subgraph on the same node-set and partial edge-set
       
   346   template<typename GraphWrapper, typename EdgeFilterMap>
       
   347   class SubGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
       
   348   protected:
       
   349     EdgeFilterMap* filter_map;
       
   350   public:
       
   351     typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
       
   352     typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
       
   353     typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
       
   354     typedef typename GraphWrapperSkeleton<GraphWrapper>::EdgeIt EdgeIt;
       
   355     typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt InEdgeIt;
       
   356     typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt OutEdgeIt;
       
   357 
       
   358     SubGraphWrapper(GraphWrapper _gw, EdgeFilterMap& _filter_map) : 
       
   359       GraphWrapperSkeleton<GraphWrapper>(_gw), filter_map(&_filter_map) { }  
       
   360 
       
   361     template<typename I> I& first(I& i) const { 
       
   362       gw.first(i); 
       
   363       while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
       
   364       return i;
       
   365     }
       
   366     template<typename I, typename P> I& first(I& i, const P& p) const { 
       
   367       gw.first(i, p); 
       
   368       while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
       
   369       return i;
       
   370     }
       
   371     
       
   372     //template<typename I> I getNext(const I& i) const { 
       
   373     //  return gw.getNext(i); 
       
   374     //}
       
   375     template<typename I> I& next(I &i) const { 
       
   376       gw.next(i); 
       
   377       while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
       
   378       return i;
       
   379     }
       
   380     
       
   381     template< typename It > It first() const { 
       
   382       It e; this->first(e); return e; }
       
   383     
       
   384     template< typename It > It first(const Node& v) const { 
       
   385       It e; this->first(e, v); return e; }
       
   386   };
   345 
   387 
   346 //   template<typename GraphWrapper>
   388 //   template<typename GraphWrapper>
   347 //   class UndirGraphWrapper {
   389 //   class UndirGraphWrapper {
   348 //   protected:
   390 //   protected:
   349 //     //Graph* graph;
   391 //     //Graph* graph;
   855 // 	  while( in.valid() && !(Edge::free()>0) ) { ++in; } 
   897 // 	  while( in.valid() && !(Edge::free()>0) ) { ++in; } 
   856 // 	}
   898 // 	}
   857 // 	return *this; 
   899 // 	return *this; 
   858 //       }
   900 //       }
   859     };
   901     };
       
   902 
       
   903     //FIXME This is just for having InEdgeIt
       
   904     typedef void InEdgeIt;
   860 
   905 
   861     class EdgeIt : public Edge {
   906     class EdgeIt : public Edge {
   862       friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
   907       friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
   863       typename Graph::NodeIt v;
   908       typename Graph::NodeIt v;
   864     public:
   909     public:
  1003     Node aNode(OutEdgeIt e) const { 
  1048     Node aNode(OutEdgeIt e) const { 
  1004       return ((e.out_or_in) ? gw.aNode(e.out) : gw.aNode(e.in)); }
  1049       return ((e.out_or_in) ? gw.aNode(e.out) : gw.aNode(e.in)); }
  1005     Node bNode(OutEdgeIt e) const { 
  1050     Node bNode(OutEdgeIt e) const { 
  1006       return ((e.out_or_in) ? gw.bNode(e.out) : gw.bNode(e.in)); }
  1051       return ((e.out_or_in) ? gw.bNode(e.out) : gw.bNode(e.in)); }
  1007 
  1052 
       
  1053     int nodeNum() const { return gw.nodeNum(); }
       
  1054     //FIXME
       
  1055     //int edgeNum() const { return gw.edgeNum(); }
       
  1056 
       
  1057 
  1008     int id(Node v) const { return gw.id(v); }
  1058     int id(Node v) const { return gw.id(v); }
  1009 
  1059 
  1010     bool valid(Node n) const { return gw.valid(n); }
  1060     bool valid(Node n) const { return gw.valid(n); }
  1011     bool valid(Edge e) const { 
  1061     bool valid(Edge e) const { 
  1012       return e.out_or_in ? gw.valid(e.out) : gw.valid(e.in); }
  1062       return e.out_or_in ? gw.valid(e.out) : gw.valid(e.in); }