Static maps for bipartite graphs.
authordeba
Wed, 23 Nov 2005 11:20:14 +0000
changeset 1828fd3771591a5c
parent 1827 dc660ed95b31
child 1829 183b4cbf9733
Static maps for bipartite graphs.
lemon/bits/static_map.h
lemon/full_graph.h
     1.1 --- a/lemon/bits/static_map.h	Tue Nov 22 15:15:31 2005 +0000
     1.2 +++ b/lemon/bits/static_map.h	Wed Nov 23 11:20:14 2005 +0000
     1.3 @@ -343,7 +343,271 @@
     1.4        }
     1.5      };
     1.6  
     1.7 +  };
     1.8  
     1.9 +  template <typename _Base>
    1.10 +  class StaticMappableUndirBipartiteGraphExtender : public _Base {
    1.11 +  public:
    1.12 +
    1.13 +    typedef _Base Parent;
    1.14 +    typedef StaticMappableUndirBipartiteGraphExtender Graph;
    1.15 +
    1.16 +    typedef typename Parent::Node Node;
    1.17 +    typedef typename Parent::UpperNode UpperNode;
    1.18 +    typedef typename Parent::LowerNode LowerNode;
    1.19 +    typedef typename Parent::Edge Edge;
    1.20 +    typedef typename Parent::UndirEdge UndirEdge;
    1.21 +    
    1.22 +    template <typename _Value>
    1.23 +    class UpperNodeMap 
    1.24 +      : public IterableMapExtender<StaticMap<Graph, UpperNode, _Value> > {
    1.25 +    public:
    1.26 +      typedef StaticMappableUndirBipartiteGraphExtender Graph;
    1.27 +      typedef IterableMapExtender<StaticMap<Graph, UpperNode, _Value> > 
    1.28 +      Parent;
    1.29 +    
    1.30 +      UpperNodeMap(const Graph& _g) 
    1.31 +	: Parent(_g) {}
    1.32 +      UpperNodeMap(const Graph& _g, const _Value& _v) 
    1.33 +	: Parent(_g, _v) {}
    1.34 +    
    1.35 +      UpperNodeMap& operator=(const UpperNodeMap& cmap) {
    1.36 +	return operator=<UpperNodeMap>(cmap);
    1.37 +      }
    1.38 +    
    1.39 +
    1.40 +      /// \brief Template assign operator.
    1.41 +      ///
    1.42 +      /// The given parameter should be conform to the ReadMap
    1.43 +      /// concept and could be indiced by the current item set of
    1.44 +      /// the UpperNodeMap. In this case the value for each item
    1.45 +      /// is assigned by the value of the given ReadMap. 
    1.46 +      template <typename CMap>
    1.47 +      UpperNodeMap& operator=(const CMap& cmap) {
    1.48 +	checkConcept<concept::ReadMap<UpperNode, _Value>, CMap>();
    1.49 +	const typename Parent::Graph* graph = Parent::getGraph();
    1.50 +	UpperNode it;
    1.51 +	for (graph->first(it); it != INVALID; graph->next(it)) {
    1.52 +	  Parent::set(it, cmap[it]);
    1.53 +	}
    1.54 +	return *this;
    1.55 +      }
    1.56 +    
    1.57 +    };
    1.58 +
    1.59 +    template <typename _Value>
    1.60 +    class LowerNodeMap 
    1.61 +      : public IterableMapExtender<StaticMap<Graph, LowerNode, _Value> > {
    1.62 +    public:
    1.63 +      typedef StaticMappableUndirBipartiteGraphExtender Graph;
    1.64 +      typedef IterableMapExtender<StaticMap<Graph, LowerNode, _Value> > 
    1.65 +      Parent;
    1.66 +    
    1.67 +      LowerNodeMap(const Graph& _g) 
    1.68 +	: Parent(_g) {}
    1.69 +      LowerNodeMap(const Graph& _g, const _Value& _v) 
    1.70 +	: Parent(_g, _v) {}
    1.71 +    
    1.72 +      LowerNodeMap& operator=(const LowerNodeMap& cmap) {
    1.73 +	return operator=<LowerNodeMap>(cmap);
    1.74 +      }
    1.75 +    
    1.76 +
    1.77 +      /// \brief Template assign operator.
    1.78 +      ///
    1.79 +      /// The given parameter should be conform to the ReadMap
    1.80 +      /// concept and could be indiced by the current item set of
    1.81 +      /// the LowerNodeMap. In this case the value for each item
    1.82 +      /// is assigned by the value of the given ReadMap. 
    1.83 +      template <typename CMap>
    1.84 +      LowerNodeMap& operator=(const CMap& cmap) {
    1.85 +	checkConcept<concept::ReadMap<LowerNode, _Value>, CMap>();
    1.86 +	const typename Parent::Graph* graph = Parent::getGraph();
    1.87 +	LowerNode it;
    1.88 +	for (graph->first(it); it != INVALID; graph->next(it)) {
    1.89 +	  Parent::set(it, cmap[it]);
    1.90 +	}
    1.91 +	return *this;
    1.92 +      }
    1.93 +    
    1.94 +    };
    1.95 +
    1.96 +  protected:
    1.97 +
    1.98 +    template <typename _Value>
    1.99 +    class NodeMapBase : public Parent::NodeNotifier::ObserverBase {
   1.100 +    public:
   1.101 +      typedef StaticMappableUndirBipartiteGraphExtender Graph;
   1.102 +
   1.103 +      typedef Node Key;
   1.104 +      typedef _Value Value;
   1.105 +
   1.106 +      /// The reference type of the map;
   1.107 +      typedef typename LowerNodeMap<_Value>::Reference Reference;
   1.108 +      /// The pointer type of the map;
   1.109 +      typedef typename LowerNodeMap<_Value>::Pointer Pointer;
   1.110 +      
   1.111 +      /// The const value type of the map.
   1.112 +      typedef const Value ConstValue;
   1.113 +      /// The const reference type of the map;
   1.114 +      typedef typename LowerNodeMap<_Value>::ConstReference ConstReference;
   1.115 +      /// The pointer type of the map;
   1.116 +      typedef typename LowerNodeMap<_Value>::ConstPointer ConstPointer;
   1.117 +
   1.118 +      typedef True ReferenceMapTag;
   1.119 +
   1.120 +      NodeMapBase(const Graph& _g) 
   1.121 +	: graph(&_g), lowerMap(_g), upperMap(_g) {
   1.122 +	Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
   1.123 +      }
   1.124 +      NodeMapBase(const Graph& _g, const _Value& _v) 
   1.125 +	: graph(&_g), lowerMap(_g, _v), 
   1.126 +	  upperMap(_g, _v) {
   1.127 +	Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
   1.128 +      }
   1.129 +
   1.130 +      virtual ~NodeMapBase() {      
   1.131 +	if (Parent::NodeNotifier::ObserverBase::attached()) {
   1.132 +	  Parent::NodeNotifier::ObserverBase::detach();
   1.133 +	}
   1.134 +      }
   1.135 +    
   1.136 +      ConstReference operator[](const Key& node) const {
   1.137 +	if (Parent::upper(node)) {
   1.138 +	  return upperMap[node];
   1.139 +	} else {
   1.140 +	  return lowerMap[node];
   1.141 +	}
   1.142 +      } 
   1.143 +
   1.144 +      Reference operator[](const Key& node) {
   1.145 +	if (Parent::upper(node)) {
   1.146 +	  return upperMap[node];
   1.147 +	} else {
   1.148 +	  return lowerMap[node];
   1.149 +	}
   1.150 +      }
   1.151 +
   1.152 +      void set(const Key& node, const Value& value) {
   1.153 +	if (Parent::upper(node)) {
   1.154 +	  upperMap.set(node, value);
   1.155 +	} else {
   1.156 +	  lowerMap.set(node, value);
   1.157 +	}
   1.158 +      }
   1.159 +
   1.160 +    protected:
   1.161 +      
   1.162 +      virtual void add(const Node&) {}
   1.163 +      virtual void erase(const Node&) {}
   1.164 +      virtual void clear() {}
   1.165 +      virtual void build() {}
   1.166 +
   1.167 +      const Graph* getGraph() const { return graph; }
   1.168 +      
   1.169 +    private:
   1.170 +      const Graph* graph;
   1.171 +      LowerNodeMap<_Value> lowerMap;
   1.172 +      UpperNodeMap<_Value> upperMap;
   1.173 +    };
   1.174 +    
   1.175 +  public:
   1.176 +
   1.177 +    template <typename _Value>
   1.178 +    class NodeMap 
   1.179 +      : public IterableMapExtender<NodeMapBase<_Value> > {
   1.180 +    public:
   1.181 +      typedef StaticMappableUndirBipartiteGraphExtender Graph;
   1.182 +      typedef IterableMapExtender< NodeMapBase<_Value> > Parent;
   1.183 +    
   1.184 +      NodeMap(const Graph& _g) 
   1.185 +	: Parent(_g) {}
   1.186 +      NodeMap(const Graph& _g, const _Value& _v) 
   1.187 +	: Parent(_g, _v) {}
   1.188 +    
   1.189 +      NodeMap& operator=(const NodeMap& cmap) {
   1.190 +	return operator=<NodeMap>(cmap);
   1.191 +      }
   1.192 +    
   1.193 +
   1.194 +      /// \brief Template assign operator.
   1.195 +      ///
   1.196 +      /// The given parameter should be conform to the ReadMap
   1.197 +      /// concept and could be indiced by the current item set of
   1.198 +      /// the NodeMap. In this case the value for each item
   1.199 +      /// is assigned by the value of the given ReadMap. 
   1.200 +      template <typename CMap>
   1.201 +      NodeMap& operator=(const CMap& cmap) {
   1.202 +	checkConcept<concept::ReadMap<Node, _Value>, CMap>();
   1.203 +	const typename Parent::Graph* graph = Parent::getGraph();
   1.204 +	Node it;
   1.205 +	for (graph->first(it); it != INVALID; graph->next(it)) {
   1.206 +	  Parent::set(it, cmap[it]);
   1.207 +	}
   1.208 +	return *this;
   1.209 +      }
   1.210 +    
   1.211 +    };
   1.212 +
   1.213 +
   1.214 +
   1.215 +    template <typename _Value>
   1.216 +    class EdgeMap 
   1.217 +      : public IterableMapExtender<StaticMap<Graph, Edge, _Value> > {
   1.218 +    public:
   1.219 +      typedef StaticMappableUndirBipartiteGraphExtender Graph;
   1.220 +      typedef IterableMapExtender<StaticMap<Graph, Edge, _Value> > Parent;
   1.221 +    
   1.222 +      EdgeMap(const Graph& _g) 
   1.223 +	: Parent(_g) {}
   1.224 +      EdgeMap(const Graph& _g, const _Value& _v) 
   1.225 +	: Parent(_g, _v) {}
   1.226 +    
   1.227 +      EdgeMap& operator=(const EdgeMap& cmap) {
   1.228 +	return operator=<EdgeMap>(cmap);
   1.229 +      }
   1.230 +    
   1.231 +      template <typename CMap>
   1.232 +      EdgeMap& operator=(const CMap& cmap) {
   1.233 +	checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
   1.234 +	const typename Parent::Graph* graph = Parent::getGraph();
   1.235 +	Edge it;
   1.236 +	for (graph->first(it); it != INVALID; graph->next(it)) {
   1.237 +	  Parent::set(it, cmap[it]);
   1.238 +	}
   1.239 +	return *this;
   1.240 +      }
   1.241 +    };
   1.242 +
   1.243 +    template <typename _Value>
   1.244 +    class UndirEdgeMap 
   1.245 +      : public IterableMapExtender<StaticMap<Graph, UndirEdge, _Value> > {
   1.246 +    public:
   1.247 +      typedef StaticMappableUndirBipartiteGraphExtender Graph;
   1.248 +      typedef IterableMapExtender<StaticMap<Graph, UndirEdge, _Value> > 
   1.249 +      Parent;
   1.250 +    
   1.251 +      UndirEdgeMap(const Graph& _g) 
   1.252 +	: Parent(_g) {}
   1.253 +      UndirEdgeMap(const Graph& _g, const _Value& _v) 
   1.254 +	: Parent(_g, _v) {}
   1.255 +    
   1.256 +      UndirEdgeMap& operator=(const UndirEdgeMap& cmap) {
   1.257 +	return operator=<UndirEdgeMap>(cmap);
   1.258 +      }
   1.259 +    
   1.260 +      template <typename CMap>
   1.261 +      UndirEdgeMap& operator=(const CMap& cmap) {
   1.262 +	checkConcept<concept::ReadMap<UndirEdge, _Value>, CMap>();
   1.263 +	const typename Parent::Graph* graph = Parent::getGraph();
   1.264 +	UndirEdge it;
   1.265 +	for (graph->first(it); it != INVALID; graph->next(it)) {
   1.266 +	  Parent::set(it, cmap[it]);
   1.267 +	}
   1.268 +	return *this;
   1.269 +      }
   1.270 +    };
   1.271 +  
   1.272    };
   1.273  
   1.274  }
     2.1 --- a/lemon/full_graph.h	Tue Nov 22 15:15:31 2005 +0000
     2.2 +++ b/lemon/full_graph.h	Wed Nov 23 11:20:14 2005 +0000
     2.3 @@ -575,7 +575,7 @@
     2.4    };
     2.5  
     2.6  
     2.7 -  typedef MappableUndirBipartiteGraphExtender<
     2.8 +  typedef StaticMappableUndirBipartiteGraphExtender<
     2.9      IterableUndirBipartiteGraphExtender<
    2.10      AlterableUndirBipartiteGraphExtender<
    2.11      UndirBipartiteGraphExtender <