src/work/marci/bipartite_graph_wrapper.h
changeset 768 a5e9303a5511
parent 762 511200bdb71f
child 902 309d81806228
     1.1 --- a/src/work/marci/bipartite_graph_wrapper.h	Thu Aug 19 11:34:48 2004 +0000
     1.2 +++ b/src/work/marci/bipartite_graph_wrapper.h	Mon Aug 23 11:06:00 2004 +0000
     1.3 @@ -30,9 +30,10 @@
     1.4    /// \author Marton Makai
     1.5    template<typename Graph> 
     1.6    class BipartiteGraphWrapper : public GraphWrapper<Graph> {
     1.7 -  protected:
     1.8 +  public:
     1.9      typedef IterableBoolMap< typename Graph::template NodeMap<int> > 
    1.10      SFalseTTrueMap;
    1.11 +  protected:
    1.12      SFalseTTrueMap* s_false_t_true_map;
    1.13  
    1.14      BipartiteGraphWrapper() : GraphWrapper<Graph>()/*, 
    1.15 @@ -46,6 +47,12 @@
    1.16      //FIXME vhogy igy kellene, csak az en forditom nem eszi meg
    1.17      static const bool S_CLASS;
    1.18      static const bool T_CLASS;
    1.19 +
    1.20 +    /// This method is to reach the iterable maps of the bipartite graph or 
    1.21 +    /// bipartite graph wrapper.
    1.22 +    const SFalseTTrueMap& sFalseTTrueMap() const { 
    1.23 +      return *s_false_t_true_map; 
    1.24 +    }
    1.25      
    1.26      //bool S_CLASS;
    1.27      //bool T_CLASS;
    1.28 @@ -211,13 +218,13 @@
    1.29    /// does not work well.
    1.30    template<typename Graph>
    1.31    class BipartiteGraph : public BipartiteGraphWrapper<Graph> {
    1.32 -    typedef IterableBoolMap< typename Graph::template NodeMap<int> > 
    1.33 -    SFalseTTrueMap;
    1.34 +//     typedef IterableBoolMap< typename Graph::template NodeMap<int> > 
    1.35 +//     SFalseTTrueMap;
    1.36      typedef BipartiteGraphWrapper<Graph> Parent;
    1.37    protected:
    1.38      Graph gr;
    1.39      typename Graph::template NodeMap<int> bipartite_map;
    1.40 -    SFalseTTrueMap s_false_t_true_map;
    1.41 +    typename Parent::SFalseTTrueMap s_false_t_true_map;
    1.42    public:
    1.43      typedef typename Parent::Node Node;
    1.44      typedef typename Parent::Edge Edge;
    1.45 @@ -258,9 +265,20 @@
    1.46      }
    1.47    };
    1.48  
    1.49 +  template<typename Graph, typename sIterableMap, typename tIterableMap>
    1.50 +  class stGraphWrapper;
    1.51  
    1.52 +  /// Easier stuff for bipartite graphs.
    1.53    template<typename Graph>
    1.54 -  class stGraphWrapper;
    1.55 +  class stBipartiteGraphWrapper : public 
    1.56 +  stGraphWrapper<Graph, typename Graph::SFalseTTrueMap, 
    1.57 +		 typename Graph::SFalseTTrueMap> {
    1.58 +  public:
    1.59 +    typedef stGraphWrapper<Graph, typename Graph::SFalseTTrueMap, 
    1.60 +			   typename Graph::SFalseTTrueMap> Parent;
    1.61 +    stBipartiteGraphWrapper(Graph& _graph) : 
    1.62 +      Parent(_graph, _graph.sFalseTTrueMap(), _graph.sFalseTTrueMap()) { }
    1.63 +  };
    1.64  
    1.65  //   template<typename Graph> 
    1.66  //   std::ostream& 
    1.67 @@ -287,13 +305,16 @@
    1.68    /// graph have to be oriented from S to T.
    1.69    ///
    1.70    /// \author Marton Makai
    1.71 -  template<typename Graph>
    1.72 +  template<typename Graph, typename sIterableMap, typename tIterableMap>
    1.73    class stGraphWrapper : public GraphWrapper<Graph> {
    1.74 +  protected:    
    1.75 +    const sIterableMap* s_iterable_map;
    1.76 +    const tIterableMap* t_iterable_map;
    1.77    public:
    1.78      class Node; 
    1.79      friend class Node;
    1.80  //GN, int
    1.81 -//0 normalis, 1 s, 2, true, ez az iteralasi sorrend, 
    1.82 +//0 normalis, 1 s, 2 t, ez az iteralasi sorrend, 
    1.83  //es a vege a false azaz (invalid, 3)    
    1.84      class NodeIt;
    1.85      friend class NodeIt;
    1.86 @@ -334,9 +355,15 @@
    1.87      static const bool S_CLASS=false;
    1.88      static const bool T_CLASS=true;
    1.89  
    1.90 -    stGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) , 
    1.91 -				    S_NODE(INVALID, 1), 
    1.92 -				    T_NODE(INVALID, 2) { }
    1.93 +    // \bug not too nice constructor.
    1.94 +    stGraphWrapper(Graph& _graph, 
    1.95 +		   const sIterableMap& _s_iterable_map, 
    1.96 +		   const tIterableMap& _t_iterable_map) : 
    1.97 +      GraphWrapper<Graph>(_graph), 
    1.98 +      s_iterable_map(&_s_iterable_map), 
    1.99 +      t_iterable_map(&_t_iterable_map), 
   1.100 +      S_NODE(INVALID, 1), 
   1.101 +      T_NODE(INVALID, 2) { }
   1.102  
   1.103      
   1.104  //    std::ostream& 
   1.105 @@ -349,7 +376,7 @@
   1.106      class Node : public Graph::Node {
   1.107      protected:
   1.108        friend class GraphWrapper<Graph>;
   1.109 -      friend class stGraphWrapper<Graph>;
   1.110 +      friend class stGraphWrapper<Graph, sIterableMap, tIterableMap>;
   1.111        template <typename T> friend class NodeMap;
   1.112        friend class Edge;
   1.113        friend class OutEdgeIt;
   1.114 @@ -380,7 +407,7 @@
   1.115  
   1.116      class NodeIt { 
   1.117        friend class GraphWrapper<Graph>;
   1.118 -      friend class stGraphWrapper<Graph>;
   1.119 +      friend class stGraphWrapper<Graph, sIterableMap, tIterableMap>;
   1.120        typename Graph::NodeIt n;
   1.121        int spec; 
   1.122       public:
   1.123 @@ -388,7 +415,8 @@
   1.124        NodeIt(const typename Graph::NodeIt& _n, int _spec) : 
   1.125  	n(_n), spec(_spec) { }
   1.126        NodeIt(const Invalid& i) : n(i), spec(3) { }
   1.127 -      NodeIt(const stGraphWrapper<Graph>& _G) : n(*(_G.graph)), spec(0) { 
   1.128 +      NodeIt(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G) 
   1.129 +	: n(*(_G.graph)), spec(0) { 
   1.130  	if (!_G.graph->valid(n)) spec=1;
   1.131        }
   1.132        operator Node() const { return Node(n, spec); }
   1.133 @@ -396,7 +424,7 @@
   1.134  
   1.135      class Edge : public Graph::Edge {
   1.136        friend class GraphWrapper<Graph>;
   1.137 -      friend class stGraphWrapper<Graph>;
   1.138 +      friend class stGraphWrapper<Graph, sIterableMap, tIterableMap>;
   1.139        template <typename T> friend class EdgeMap;
   1.140        int spec;
   1.141        typename Graph::Node n;
   1.142 @@ -429,7 +457,7 @@
   1.143  
   1.144      class OutEdgeIt { 
   1.145        friend class GraphWrapper<Graph>;
   1.146 -      friend class stGraphWrapper<Graph>;
   1.147 +      friend class stGraphWrapper<Graph, sIterableMap, tIterableMap>;
   1.148        typename Graph::OutEdgeIt e;
   1.149        int spec;
   1.150        typename Graph::ClassNodeIt n;
   1.151 @@ -440,7 +468,8 @@
   1.152  	e(_e), spec(_spec), n(_n) { 
   1.153        }
   1.154        OutEdgeIt(const Invalid& i) : e(i), spec(3), n(i) { }
   1.155 -      OutEdgeIt(const stGraphWrapper<Graph>& _G, const Node& _n) {
   1.156 +      OutEdgeIt(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G, 
   1.157 +		const Node& _n) {
   1.158  	switch (_n.spec) {
   1.159  	  case 0 : 
   1.160  	    if (_G.graph->inSClass(_n)) { //S, van normalis kiel 
   1.161 @@ -473,7 +502,7 @@
   1.162  
   1.163      class InEdgeIt { 
   1.164        friend class GraphWrapper<Graph>;
   1.165 -      friend class stGraphWrapper<Graph>;
   1.166 +      friend class stGraphWrapper<Graph, sIterableMap, tIterableMap>;
   1.167        typename Graph::InEdgeIt e;
   1.168        int spec;
   1.169        typename Graph::ClassNodeIt n;
   1.170 @@ -484,7 +513,8 @@
   1.171  	e(_e), spec(_spec), n(_n) { 
   1.172        }
   1.173        InEdgeIt(const Invalid& i) : e(i), spec(3), n(i) { }
   1.174 -      InEdgeIt(const stGraphWrapper<Graph>& _G, const Node& _n) {
   1.175 +      InEdgeIt(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G, 
   1.176 +	       const Node& _n) {
   1.177  	switch (_n.spec) {
   1.178  	  case 0 : 
   1.179  	    if (_G.graph->inTClass(_n)) { //T, van normalis beel 
   1.180 @@ -517,7 +547,7 @@
   1.181  
   1.182      class EdgeIt { 
   1.183        friend class GraphWrapper<Graph>;
   1.184 -      friend class stGraphWrapper<Graph>;
   1.185 +      friend class stGraphWrapper<Graph, sIterableMap, tIterableMap>;
   1.186        typename Graph::EdgeIt e;
   1.187        int spec;
   1.188        typename Graph::ClassNodeIt n;
   1.189 @@ -527,7 +557,7 @@
   1.190  	     const typename Graph::ClassNodeIt& _n) : 
   1.191  	e(_e), spec(_spec), n(_n) { }
   1.192        EdgeIt(const Invalid& i) : e(i), spec(3), n(i) { }
   1.193 -      EdgeIt(const stGraphWrapper<Graph>& _G) : 
   1.194 +      EdgeIt(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G) : 
   1.195  	e(*(_G.graph)), spec(0), n(INVALID) { 
   1.196  	if (!_G.graph->valid(e)) {
   1.197  	  spec=1;
   1.198 @@ -718,12 +748,14 @@
   1.199      protected:
   1.200        T s_value, t_value;
   1.201      public:
   1.202 -      NodeMap(const stGraphWrapper<Graph>& _G) :  Parent(_G), 
   1.203 -						  s_value(), 
   1.204 -						  t_value() { }
   1.205 -      NodeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
   1.206 -						      s_value(a), 
   1.207 -						      t_value(a) { }
   1.208 +      NodeMap(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G) : 
   1.209 +	Parent(_G), 
   1.210 +	s_value(), 
   1.211 +	t_value() { }
   1.212 +      NodeMap(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G, T a) 
   1.213 +	: Parent(_G, a), 
   1.214 +	  s_value(a), 
   1.215 +	  t_value(a) { }
   1.216        T operator[](const Node& n) const { 
   1.217  	switch (n.spec) {
   1.218  	case 0: 
   1.219 @@ -753,7 +785,7 @@
   1.220  
   1.221      /// This class is to wrap a node-map of \c Graph and two variables 
   1.222      /// storing values for \c S_NODE and \c T_NODE to a node-map of 
   1.223 -    /// stGraphWrapper<Graph>.
   1.224 +    /// stGraphWrapper<Graph, sIterableMap, tIterableMap>.
   1.225      template<typename NM> class NodeMapWrapper { 
   1.226      public:
   1.227        typedef Node KeyType;
   1.228 @@ -797,10 +829,12 @@
   1.229      protected:
   1.230        typename GraphWrapper<Graph>::template NodeMap<T> node_value;
   1.231      public:
   1.232 -      EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G), 
   1.233 -						 node_value(_G) { }
   1.234 -      EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
   1.235 -						      node_value(_G, a) { }
   1.236 +      EdgeMap(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G) 
   1.237 +	: Parent(_G), 
   1.238 +	  node_value(_G) { }
   1.239 +      EdgeMap(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G, T a) 
   1.240 +	: Parent(_G, a), 
   1.241 +	  node_value(_G, a) { }
   1.242        T operator[](const Edge& e) const { 
   1.243  	switch (e.spec) {
   1.244  	case 0: 
   1.245 @@ -829,7 +863,7 @@
   1.246      };
   1.247  
   1.248      /// This class is to wrap an edge-map and a node-map of \c Graph 
   1.249 -    /// to an edge-map of stGraphWrapper<Graph>.
   1.250 +    /// to an edge-map of stGraphWrapper<Graph, sIterableMap, tIterableMap>.
   1.251      template<typename EM, typename NM> 
   1.252      class EdgeMapWrapper {
   1.253      public: