src/work/marci/graph_wrapper.h
changeset 368 0beed7a49063
parent 363 7a05119c121a
child 371 b2acba449222
     1.1 --- a/src/work/marci/graph_wrapper.h	Wed Apr 21 19:52:09 2004 +0000
     1.2 +++ b/src/work/marci/graph_wrapper.h	Wed Apr 21 20:48:00 2004 +0000
     1.3 @@ -3,6 +3,7 @@
     1.4  #define HUGO_GRAPH_WRAPPER_H
     1.5  
     1.6  #include <invalid.h>
     1.7 +#include <iter_map.h>
     1.8  
     1.9  namespace hugo {
    1.10  
    1.11 @@ -865,6 +866,115 @@
    1.12      }
    1.13    };
    1.14  
    1.15 +  /// A wrapper for composing a bipartite graph.
    1.16 +  /// \c _graph have to be a reference to an undirected graph \c Graph 
    1.17 +  /// and 
    1.18 +  /// \c _s_false_t_true_map is an \c IterableBoolMap 
    1.19 +  /// reference containing the elements for the 
    1.20 +  /// color classes S and T.
    1.21 +  /// It results in a directed graph such that the edges are oriented from 
    1.22 +  /// S to T.
    1.23 +  template<typename Graph> 
    1.24 +  class BipartiteGraphWrapper : public GraphWrapper<Graph> {
    1.25 +    typedef IterableBoolMap< typename Graph::NodeMap<int> > SFalseTTrueMap;
    1.26 +    SFalseTTrueMap* s_false_t_true_map;
    1.27 +    
    1.28 +  public:
    1.29 +    BipartiteGraphWrapper(Graph& _graph, SFalseTTrueMap& _s_false_t_true_map) 
    1.30 +      : GraphWrapper<Graph>(_graph), s_false_t_true_map(&_s_false_t_true_map) {
    1.31 +    }
    1.32 +    typedef typename GraphWrapper<Graph>::Node Node;
    1.33 +    //using GraphWrapper<Graph>::NodeIt;
    1.34 +    typedef typename GraphWrapper<Graph>::Edge Edge;
    1.35 +    //using GraphWrapper<Graph>::EdgeIt;
    1.36 +    class SNodeIt {
    1.37 +      Node n;
    1.38 +    public:
    1.39 +      SNodeIt() { }
    1.40 +      SNodeIt(const Invalid& i) : n(i) { }
    1.41 +      SNodeIt(const BipartiteGraphWrapper<Graph>& _G) { 
    1.42 +	_G.s_false_t_true_map->first(n, false); 
    1.43 +      }
    1.44 +      operator Node() const { return n; }
    1.45 +    };
    1.46 +    class TNodeIt {
    1.47 +      Node n;
    1.48 +    public:
    1.49 +      TNodeIt() { }
    1.50 +      TNodeIt(const Invalid& i) : n(i) { }
    1.51 +      TNodeIt(const BipartiteGraphWrapper<Graph>& _G) { 
    1.52 +	_G.s_false_t_true_map->first(n, true); 
    1.53 +      }
    1.54 +      operator Node() const { return n; }
    1.55 +    };
    1.56 +    class OutEdgeIt { 
    1.57 +    public:
    1.58 +      typename Graph::OutEdgeIt e;
    1.59 +    public:
    1.60 +      OutEdgeIt() { }
    1.61 +      OutEdgeIt(const Invalid& i) : e(i) { }
    1.62 +      OutEdgeIt(const BipartiteGraphWrapper<Graph>& _G, const Node& _n) {
    1.63 +	if (!(*(_G.s_false_t_true_map))[_n]) 
    1.64 +	  e=OutEdgeIt(*(_G.graph), typename Graph::Node(_n));
    1.65 +	else 
    1.66 +	  e=INVALID;
    1.67 +      }
    1.68 +      operator Edge() const { return Edge(typename Graph::Edge(e)); }
    1.69 +    };
    1.70 +    class InEdgeIt { 
    1.71 +    public:
    1.72 +      typename Graph::InEdgeIt e;
    1.73 +    public:
    1.74 +      InEdgeIt() { }
    1.75 +      InEdgeIt(const Invalid& i) : e(i) { }
    1.76 +      InEdgeIt(const BipartiteGraphWrapper<Graph>& _G, const Node& _n) {
    1.77 +	if ((*(_G.s_false_t_true_map))[_n]) 
    1.78 +	  e=InEdgeIt(*(_G.graph), typename Graph::Node(_n));
    1.79 +	else 
    1.80 +	  e=INVALID;
    1.81 +      }
    1.82 +      operator Edge() const { return Edge(typename Graph::Edge(e)); }
    1.83 +    };
    1.84 +
    1.85 +    using GraphWrapper<Graph>::first;
    1.86 +    SNodeIt& first(SNodeIt& n) const { n=SNodeIt(*this); return n; }
    1.87 +    TNodeIt& first(TNodeIt& n) const { n=TNodeIt(*this); return n; }
    1.88 +
    1.89 +    using GraphWrapper<Graph>::next;
    1.90 +    SNodeIt& next(SNodeIt& n) const { 
    1.91 +      this->s_false_t_true_map->next(n); return n; 
    1.92 +    }
    1.93 +    TNodeIt& next(TNodeIt& n) const { 
    1.94 +      this->s_false_t_true_map->next(n); return n; 
    1.95 +    }
    1.96 +
    1.97 +    Node tail(const Edge& e) { 
    1.98 +      if (!(*(this->s_false_t_true_map))[this->graph->tail(e)]) 
    1.99 +	return Node(this->graph->tail(e));
   1.100 +      else
   1.101 +	return Node(this->graph->head(e));	
   1.102 +    }
   1.103 +    Node head(const Edge& e) { 
   1.104 +      if (!(*(this->s_false_t_true_map))[this->graph->tail(e)]) 
   1.105 +	return Node(this->graph->head(e));
   1.106 +      else
   1.107 +	return Node(this->graph->tail(e));	
   1.108 +    }
   1.109 +
   1.110 +    Node aNode(const OutEdgeIt& e) const { 
   1.111 +      return Node(this->graph->aNode(e.e)); 
   1.112 +    }
   1.113 +    Node aNode(const InEdgeIt& e) const { 
   1.114 +      return Node(this->graph->aNode(e.e)); 
   1.115 +    }
   1.116 +    Node bNode(const OutEdgeIt& e) const { 
   1.117 +      return Node(this->graph->bNode(e.e)); 
   1.118 +    }
   1.119 +    Node bNode(const InEdgeIt& e) const { 
   1.120 +      return Node(this->graph->bNode(e.e)); 
   1.121 +    }
   1.122 +  };
   1.123 +
   1.124  
   1.125  
   1.126  //   /// experimentral, do not try it.