src/work/marci/merge_node_graph_wrapper.h
changeset 1025 3b1ad8bc21da
parent 1016 18d009b23e42
child 1026 bd7ea1a718e2
     1.1 --- a/src/work/marci/merge_node_graph_wrapper.h	Mon Nov 29 16:11:51 2004 +0000
     1.2 +++ b/src/work/marci/merge_node_graph_wrapper.h	Mon Nov 29 17:55:46 2004 +0000
     1.3 @@ -40,13 +40,8 @@
     1.4    };
     1.5  
     1.6  
     1.7 -  /*! A graph wrapper base class 
     1.8 -    for merging the node-set of two node-disjoint graphs 
     1.9 -    into the node-set of one graph. 
    1.10 -    Generic implementation for unrelated _Graph1::Node and _Graph2::Node.
    1.11 -   */
    1.12    template <typename _Graph1, typename _Graph2, typename Enable=void>
    1.13 -  class MergeNodeGraphWrapperBase : 
    1.14 +  class MergeNodeGraphWrapperBaseBase : 
    1.15      public P1<_Graph1>, public P2<_Graph2> {
    1.16    public:
    1.17      static void printNode() { std::cout << "node: generic" << std::endl; }
    1.18 @@ -57,13 +52,11 @@
    1.19      typedef typename Parent1::Node Graph1Node;
    1.20      typedef typename Parent2::Node Graph2Node;
    1.21    protected:
    1.22 -    MergeNodeGraphWrapperBase() { }
    1.23 +    MergeNodeGraphWrapperBaseBase() { }
    1.24    public:
    1.25 -    template <typename _Value> class NodeMap;
    1.26  
    1.27      class Node : public Graph1Node, public Graph2Node {
    1.28 -      friend class MergeNodeGraphWrapperBase<_Graph1, _Graph2>;
    1.29 -      template <typename _Value> friend class NodeMap;
    1.30 +      friend class MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2>;
    1.31      protected:
    1.32        bool backward; //true, iff backward
    1.33      public:
    1.34 @@ -88,79 +81,15 @@
    1.35        }
    1.36      };
    1.37  
    1.38 -    //typedef void Edge;
    1.39 -    class Edge { };
    1.40 -    
    1.41 -    void first(Node& i) const {
    1.42 -      Parent1::graph->first(*static_cast<Graph1Node*>(&i));
    1.43 -      i.backward=false;
    1.44 -      if (*static_cast<Graph1Node*>(&i)==INVALID) {
    1.45 -	Parent2::graph->first(*static_cast<Graph2Node*>(&i));
    1.46 -	i.backward=true;
    1.47 -      }
    1.48 -    }
    1.49 -    void next(Node& i) const {
    1.50 -      if (!(i.backward)) {
    1.51 -	Parent1::graph->next(*static_cast<Graph1Node*>(&i));
    1.52 -	if (*static_cast<Graph1Node*>(&i)==INVALID) {
    1.53 -	  Parent2::graph->first(*static_cast<Graph2Node*>(&i));
    1.54 -	  i.backward=true;
    1.55 -	}
    1.56 -      } else {
    1.57 -	Parent2::graph->next(*static_cast<Graph2Node*>(&i));
    1.58 -      }
    1.59 -    }
    1.60 -
    1.61 -    int id(const Node& n) const { 
    1.62 -      if (!n.backward) 
    1.63 -	return this->Parent1::graph->id(n);
    1.64 -      else
    1.65 -	return this->Parent2::graph->id(n);
    1.66 -    }
    1.67 -
    1.68 -    template <typename _Value> 
    1.69 -    class NodeMap { 
    1.70 -    protected:
    1.71 -      typedef typename _Graph1::template NodeMap<_Value> ParentMap1;
    1.72 -      typedef typename _Graph2::template NodeMap<_Value> ParentMap2;
    1.73 -      ParentMap1 forward_map;
    1.74 -      ParentMap2 backward_map;
    1.75 -    public:
    1.76 -      typedef _Value Value;
    1.77 -      typedef Node Key;
    1.78 -      NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw) : 
    1.79 -	forward_map(*(gw.Parent1::graph)), 
    1.80 -	backward_map(*(gw.Parent2::graph)) { }
    1.81 -      NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw, 
    1.82 -	      const _Value& value) : 
    1.83 -	forward_map(*(gw.Parent1::graph), value), 
    1.84 -	backward_map(*(gw.Parent2::graph), value) { }
    1.85 -      _Value operator[](const Node& n) const {
    1.86 -	if (!n.backward) 
    1.87 -	  return forward_map[n];
    1.88 -	else 
    1.89 -	  return backward_map[n];
    1.90 -      }
    1.91 -      void set(const Node& n, const _Value& value) {
    1.92 -	if (!n.backward) 
    1.93 -	  forward_map.set(n, value);
    1.94 -	else 
    1.95 -	  backward_map.set(n, value);
    1.96 -      }
    1.97 -//       using ParentMap1::operator[];
    1.98 -//       using ParentMap2::operator[];
    1.99 -    };
   1.100 -
   1.101 +    static bool forward(const Node& n) { return !n.backward; }
   1.102 +    static bool backward(const Node& n) { return n.backward; }
   1.103 +    static void setForward(Node& n) { n.backward=false; }
   1.104 +    static void setBackward(Node& n) { n.backward=true; }    
   1.105    };
   1.106  
   1.107  
   1.108 -  /*! A graph wrapper base class 
   1.109 -    for merging the node-set of two node-disjoint graphs 
   1.110 -    into the node-set of one graph. 
   1.111 -    Specialization for the case when _Graph1::Node are the same _Graph2::Node.
   1.112 -   */
   1.113    template <typename _Graph1, typename _Graph2>
   1.114 -  class MergeNodeGraphWrapperBase<
   1.115 +  class MergeNodeGraphWrapperBaseBase<
   1.116      _Graph1, _Graph2, typename boost::enable_if<
   1.117      boost::is_same<typename _Graph1::Node, typename _Graph2::Node> >::type> : 
   1.118      public P1<_Graph1>, public P2<_Graph2> {
   1.119 @@ -173,13 +102,11 @@
   1.120      typedef typename Parent1::Node Graph1Node;
   1.121      typedef typename Parent2::Node Graph2Node;
   1.122    protected:
   1.123 -    MergeNodeGraphWrapperBase() { }
   1.124 +    MergeNodeGraphWrapperBaseBase() { }
   1.125    public:
   1.126 -    template <typename _Value> class NodeMap;
   1.127  
   1.128      class Node : public Graph1Node {
   1.129 -      friend class MergeNodeGraphWrapperBase<_Graph1, _Graph2>;
   1.130 -      template <typename _Value> friend class NodeMap;
   1.131 +      friend class MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2>;
   1.132      protected:
   1.133        bool backward; //true, iff backward
   1.134      public:
   1.135 @@ -189,7 +116,7 @@
   1.136        /// original one, otherwise its oppositely directed pair is obtained.
   1.137        Node(const Graph1Node& n1, 
   1.138  	   const Graph2Node& n2, bool _backward) : 
   1.139 -	Graph1Node(!backward ? n1 : n2), backward(_backward) { }
   1.140 +	Graph1Node(!_backward ? n1 : n2), backward(_backward) { }
   1.141        Node(Invalid i) : Graph1Node(i), backward(true) { }
   1.142        bool operator==(const Node& v) const { 
   1.143  	return (backward==v.backward && 
   1.144 @@ -200,80 +127,15 @@
   1.145        }
   1.146      };
   1.147  
   1.148 -    //typedef void Edge;
   1.149 -    class Edge { };
   1.150 -    
   1.151 -    void first(Node& i) const {
   1.152 -      Parent1::graph->first(*static_cast<Graph1Node*>(&i));
   1.153 -      i.backward=false;
   1.154 -      if (*static_cast<Graph1Node*>(&i)==INVALID) {
   1.155 -	Parent2::graph->first(*static_cast<Graph1Node*>(&i));
   1.156 -	i.backward=true;
   1.157 -      }
   1.158 -    }
   1.159 -    void next(Node& i) const {
   1.160 -      if (!(i.backward)) {
   1.161 -	Parent1::graph->next(*static_cast<Graph1Node*>(&i));
   1.162 -	if (*static_cast<Graph1Node*>(&i)==INVALID) {
   1.163 -	  Parent2::graph->first(*static_cast<Graph1Node*>(&i));
   1.164 -	  i.backward=true;
   1.165 -	}
   1.166 -      } else {
   1.167 -	Parent2::graph->next(*static_cast<Graph1Node*>(&i));
   1.168 -      }
   1.169 -    }
   1.170 -
   1.171 -    int id(const Node& n) const { 
   1.172 -      if (!n.backward) 
   1.173 -	return this->Parent1::graph->id(n);
   1.174 -      else
   1.175 -	return this->Parent2::graph->id(n);
   1.176 -    }
   1.177 -
   1.178 -    template <typename _Value> 
   1.179 -    class NodeMap { 
   1.180 -    protected:
   1.181 -      typedef typename _Graph1::template NodeMap<_Value> ParentMap1;
   1.182 -      typedef typename _Graph2::template NodeMap<_Value> ParentMap2;
   1.183 -      ParentMap1 forward_map;
   1.184 -      ParentMap2 backward_map;
   1.185 -    public:
   1.186 -      typedef _Value Value;
   1.187 -      typedef Node Key;
   1.188 -      NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw) : 
   1.189 -	forward_map(*(gw.Parent1::graph)), 
   1.190 -	backward_map(*(gw.Parent2::graph)) { }
   1.191 -      NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw, 
   1.192 -	      const _Value& value) : 
   1.193 -	forward_map(*(gw.Parent1::graph), value), 
   1.194 -	backward_map(*(gw.Parent2::graph), value) { }
   1.195 -      _Value operator[](const Node& n) const {
   1.196 -	if (!n.backward) 
   1.197 -	  return forward_map[n];
   1.198 -	else 
   1.199 -	  return backward_map[n];
   1.200 -      }
   1.201 -      void set(const Node& n, const _Value& value) {
   1.202 -	if (!n.backward) 
   1.203 -	  forward_map.set(n, value);
   1.204 -	else 
   1.205 -	  backward_map.set(n, value);
   1.206 -      }
   1.207 -//       using ParentMap1::operator[];
   1.208 -//       using ParentMap2::operator[];
   1.209 -    };
   1.210 -
   1.211 +    static bool forward(const Node& n) { return !n.backward; }
   1.212 +    static bool backward(const Node& n) { return n.backward; }
   1.213 +    static void setForward(Node& n) { n.backward=false; }
   1.214 +    static void setBackward(Node& n) { n.backward=true; }
   1.215    };
   1.216  
   1.217  
   1.218 -  /*! A graph wrapper base class 
   1.219 -    for merging the node-set of two node-disjoint graphs 
   1.220 -    into the node-set of one graph. 
   1.221 -    Specialization for the case when 
   1.222 -    _Graph1::Node is a base class and _Graph2::Node is derived from it.
   1.223 -   */
   1.224    template <typename _Graph1, typename _Graph2>
   1.225 -  class MergeNodeGraphWrapperBase<
   1.226 +  class MergeNodeGraphWrapperBaseBase<
   1.227      _Graph1, _Graph2, typename boost::enable_if<
   1.228      boost::is_base_and_derived<typename _Graph1::Node, typename _Graph2::Node> >::type> : 
   1.229      public P1<_Graph1>, public P2<_Graph2> {
   1.230 @@ -286,13 +148,11 @@
   1.231      typedef typename Parent1::Node Graph1Node;
   1.232      typedef typename Parent2::Node Graph2Node;
   1.233    protected:
   1.234 -    MergeNodeGraphWrapperBase() { }
   1.235 +    MergeNodeGraphWrapperBaseBase() { }
   1.236    public:
   1.237 -    template <typename _Value> class NodeMap;
   1.238  
   1.239      class Node : public Graph2Node {
   1.240 -      friend class MergeNodeGraphWrapperBase<_Graph1, _Graph2>;
   1.241 -      template <typename _Value> friend class NodeMap;
   1.242 +      friend class MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2>;
   1.243      protected:
   1.244        bool backward; //true, iff backward
   1.245      public:
   1.246 @@ -319,80 +179,15 @@
   1.247        }
   1.248      };
   1.249  
   1.250 -    //typedef void Edge;
   1.251 -    class Edge { };
   1.252 -    
   1.253 -    void first(Node& i) const {
   1.254 -      Parent1::graph->first(*static_cast<Graph1Node*>(&i));
   1.255 -      i.backward=false;
   1.256 -      if (*static_cast<Graph1Node*>(&i)==INVALID) {
   1.257 -	Parent2::graph->first(*static_cast<Graph2Node*>(&i));
   1.258 -	i.backward=true;
   1.259 -      }
   1.260 -    }
   1.261 -    void next(Node& i) const {
   1.262 -      if (!(i.backward)) {
   1.263 -	Parent1::graph->next(*static_cast<Graph1Node*>(&i));
   1.264 -	if (*static_cast<Graph1Node*>(&i)==INVALID) {
   1.265 -	  Parent2::graph->first(*static_cast<Graph2Node*>(&i));
   1.266 -	  i.backward=true;
   1.267 -	}
   1.268 -      } else {
   1.269 -	Parent2::graph->next(*static_cast<Graph2Node*>(&i));
   1.270 -      }
   1.271 -    }
   1.272 +    static bool forward(const Node& n) { return !n.backward; }
   1.273 +    static bool backward(const Node& n) { return n.backward; }
   1.274 +    static void setForward(Node& n) { n.backward=false; }
   1.275 +    static void setBackward(Node& n) { n.backward=true; }
   1.276 +  };
   1.277 +  
   1.278  
   1.279 -    int id(const Node& n) const { 
   1.280 -      if (!n.backward) 
   1.281 -	return this->Parent1::graph->id(n);
   1.282 -      else
   1.283 -	return this->Parent2::graph->id(n);
   1.284 -    }
   1.285 -
   1.286 -    template <typename _Value> 
   1.287 -    class NodeMap { 
   1.288 -    protected:
   1.289 -      typedef typename _Graph1::template NodeMap<_Value> ParentMap1;
   1.290 -      typedef typename _Graph2::template NodeMap<_Value> ParentMap2;
   1.291 -      ParentMap1 forward_map;
   1.292 -      ParentMap2 backward_map;
   1.293 -    public:
   1.294 -      typedef _Value Value;
   1.295 -      typedef Node Key;
   1.296 -      NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw) : 
   1.297 -	forward_map(*(gw.Parent1::graph)), 
   1.298 -	backward_map(*(gw.Parent2::graph)) { }
   1.299 -      NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw, 
   1.300 -	      const _Value& value) : 
   1.301 -	forward_map(*(gw.Parent1::graph), value), 
   1.302 -	backward_map(*(gw.Parent2::graph), value) { }
   1.303 -      _Value operator[](const Node& n) const {
   1.304 -	if (!n.backward) 
   1.305 -	  return forward_map[n];
   1.306 -	else 
   1.307 -	  return backward_map[n];
   1.308 -      }
   1.309 -      void set(const Node& n, const _Value& value) {
   1.310 -	if (!n.backward) 
   1.311 -	  forward_map.set(n, value);
   1.312 -	else 
   1.313 -	  backward_map.set(n, value);
   1.314 -      }
   1.315 -//       using ParentMap1::operator[];
   1.316 -//       using ParentMap2::operator[];
   1.317 -    };
   1.318 -
   1.319 -  };
   1.320 -
   1.321 -
   1.322 -  /*! A graph wrapper base class 
   1.323 -    for merging the node-set of two node-disjoint graphs 
   1.324 -    into the node-set of one graph. 
   1.325 -    Specialized implementaton for the case when _Graph1::Node is derived 
   1.326 -    from _Graph2::Node.
   1.327 -   */
   1.328    template <typename _Graph1, typename _Graph2>
   1.329 -  class MergeNodeGraphWrapperBase<
   1.330 +  class MergeNodeGraphWrapperBaseBase<
   1.331      _Graph1, _Graph2, typename boost::enable_if<
   1.332      boost::is_base_and_derived<typename _Graph2::Node, typename _Graph1::Node> >::type> : 
   1.333      public P1<_Graph1>, public P2<_Graph2> {
   1.334 @@ -405,13 +200,11 @@
   1.335      typedef typename Parent1::Node Graph1Node;
   1.336      typedef typename Parent2::Node Graph2Node;
   1.337    protected:
   1.338 -    MergeNodeGraphWrapperBase() { }
   1.339 +    MergeNodeGraphWrapperBaseBase() { }
   1.340    public:
   1.341 -    template <typename _Value> class NodeMap;
   1.342  
   1.343      class Node : public Graph1Node {
   1.344 -      friend class MergeNodeGraphWrapperBase<_Graph1, _Graph2>;
   1.345 -      template <typename _Value> friend class NodeMap;
   1.346 +      friend class MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2>;
   1.347      protected:
   1.348        bool backward; //true, iff backward
   1.349      public:
   1.350 @@ -438,23 +231,42 @@
   1.351        }
   1.352      };
   1.353  
   1.354 -    //typedef void Edge;
   1.355 +    static bool forward(const Node& n) { return !n.backward; }
   1.356 +    static bool backward(const Node& n) { return n.backward; }
   1.357 +    static void setForward(Node& n) { n.backward=false; }
   1.358 +    static void setBackward(Node& n) { n.backward=true; }
   1.359 +  };
   1.360 +
   1.361 +
   1.362 +  template <typename _Graph1, typename _Graph2>
   1.363 +  class MergeNodeGraphWrapperBase : 
   1.364 +    public MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2> {
   1.365 +  public:
   1.366 +    typedef MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2> Parent;
   1.367 +    typedef _Graph1 Graph1;
   1.368 +    typedef _Graph2 Graph2;
   1.369 +    typedef P1<_Graph1> Parent1;
   1.370 +    typedef P2<_Graph2> Parent2;
   1.371 +    typedef typename Parent1::Node Graph1Node;
   1.372 +    typedef typename Parent2::Node Graph2Node;
   1.373 +
   1.374 +    typedef typename Parent::Node Node; 
   1.375      class Edge { };
   1.376      
   1.377      void first(Node& i) const {
   1.378        Parent1::graph->first(*static_cast<Graph1Node*>(&i));
   1.379 -      i.backward=false;
   1.380 +      this->setForward(i);
   1.381        if (*static_cast<Graph1Node*>(&i)==INVALID) {
   1.382  	Parent2::graph->first(*static_cast<Graph2Node*>(&i));
   1.383 -	i.backward=true;
   1.384 +	this->setBackward(i);
   1.385        }
   1.386      }
   1.387      void next(Node& i) const {
   1.388 -      if (!(i.backward)) {
   1.389 +      if (this->forward(i)) {
   1.390  	Parent1::graph->next(*static_cast<Graph1Node*>(&i));
   1.391  	if (*static_cast<Graph1Node*>(&i)==INVALID) {
   1.392  	  Parent2::graph->first(*static_cast<Graph2Node*>(&i));
   1.393 -	  i.backward=true;
   1.394 +	  this->setBackward(i);
   1.395  	}
   1.396        } else {
   1.397  	Parent2::graph->next(*static_cast<Graph2Node*>(&i));
   1.398 @@ -462,7 +274,7 @@
   1.399      }
   1.400  
   1.401      int id(const Node& n) const { 
   1.402 -      if (!n.backward) 
   1.403 +      if (this->forward(n)) 
   1.404  	return this->Parent1::graph->id(n);
   1.405        else
   1.406  	return this->Parent2::graph->id(n);
   1.407 @@ -486,13 +298,13 @@
   1.408  	forward_map(*(gw.Parent1::graph), value), 
   1.409  	backward_map(*(gw.Parent2::graph), value) { }
   1.410        _Value operator[](const Node& n) const {
   1.411 -	if (!n.backward) 
   1.412 +	if (Parent::forward(n)) 
   1.413  	  return forward_map[n];
   1.414  	else 
   1.415  	  return backward_map[n];
   1.416        }
   1.417        void set(const Node& n, const _Value& value) {
   1.418 -	if (!n.backward) 
   1.419 +	if (Parent::forward(n)) 
   1.420  	  forward_map.set(n, value);
   1.421  	else 
   1.422  	  backward_map.set(n, value);
   1.423 @@ -505,11 +317,24 @@
   1.424  
   1.425  
   1.426    /*! A graph wrapper class 
   1.427 -    fors merging the node-set of two node-disjoint graphs 
   1.428 -    into one node-set. It does not satisfy 
   1.429 +    for merging the node-set of two node-disjoint graphs 
   1.430 +    into the node-set of one graph. 
   1.431 +    Different implementations are according to the relation of 
   1.432 +    _Graph1::Node and _Graph2::Node. 
   1.433 +    If _Graph1::Node and _Graph2::Node are unrelated, then 
   1.434 +    MergeNodeGraphWrapper<_Graph1, _Graph2>::Node 
   1.435 +    is derived from both. 
   1.436 +    If _Graph1::Node and _Graph2::Node are the same type, then 
   1.437 +    MergeNodeGraphWrapper<_Graph1, _Graph2>::Node 
   1.438 +    is derived from _Graph1::Node. 
   1.439 +    If one of _Graph1::Node and _Graph2::Node 
   1.440 +    is derived from the other one, then 
   1.441 +    MergeNodeGraphWrapper<_Graph1, _Graph2>::Node 
   1.442 +    is derived from the derived type.
   1.443 +    It does not satisfy 
   1.444      StaticGraph concept as it has no edge-set which 
   1.445      works together with the node-set.
   1.446 -   */
   1.447 +  */
   1.448    template <typename _Graph1, typename _Graph2>
   1.449    class MergeNodeGraphWrapper : public 
   1.450    IterableGraphExtender<MergeNodeGraphWrapperBase<_Graph1, _Graph2> > {
   1.451 @@ -582,6 +407,11 @@
   1.452        }
   1.453      };
   1.454  
   1.455 +    using Parent::forward;
   1.456 +    using Parent::backward;
   1.457 +    bool forward(const Edge& e) const { return !e.backward; }
   1.458 +    bool backward(const Edge& e) const { return e.backward; }
   1.459 +
   1.460      using Parent::first;
   1.461      void first(Edge& i) const {
   1.462        Parent1::graph->first(*static_cast<Graph1Edge*>(&i));
   1.463 @@ -592,17 +422,25 @@
   1.464        }
   1.465      }
   1.466      void firstIn(Edge& i, const Node& n) const {
   1.467 -      Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
   1.468 -      i.backward=false;
   1.469 -      if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.470 +      if (!backward(n)) {
   1.471 +	Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
   1.472 +	if (*static_cast<Graph1Edge*>(&i)==INVALID) 
   1.473 +	  i=INVALID;
   1.474 +	else
   1.475 +	  i.backward=false;
   1.476 +      } else {
   1.477  	Parent2::graph->firstIn(*static_cast<Graph2Edge*>(&i), n);
   1.478  	i.backward=true;
   1.479        }
   1.480      }
   1.481      void firstOut(Edge& i, const Node& n) const {
   1.482 -      Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
   1.483 -      i.backward=false;
   1.484 -      if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.485 +      if (!backward(n)) {
   1.486 +	Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
   1.487 +	if (*static_cast<Graph1Edge*>(&i)==INVALID) 
   1.488 +	  i=INVALID;
   1.489 +	else
   1.490 +	  i.backward=false;
   1.491 +      } else {
   1.492  	Parent2::graph->firstOut(*static_cast<Graph2Edge*>(&i), n);
   1.493  	i.backward=true;
   1.494        }
   1.495 @@ -623,10 +461,7 @@
   1.496      void nextIn(Edge& i) const {
   1.497        if (!(i.backward)) {
   1.498  	Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i));
   1.499 -	if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.500 -	  Parent2::graph->first(*static_cast<Graph2Edge*>(&i));
   1.501 -	  i.backward=true;
   1.502 -	}
   1.503 + 	if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
   1.504        } else {
   1.505  	Parent2::graph->nextIn(*static_cast<Graph2Edge*>(&i));
   1.506        }
   1.507 @@ -634,10 +469,7 @@
   1.508      void nextOut(Edge& i) const {
   1.509        if (!(i.backward)) {
   1.510  	Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i));
   1.511 -	if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.512 -	  Parent2::graph->first(*static_cast<Graph2Edge*>(&i));
   1.513 -	  i.backward=true;
   1.514 -	}
   1.515 + 	if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
   1.516        } else {
   1.517  	Parent2::graph->nextOut(*static_cast<Graph2Edge*>(&i));
   1.518        }
   1.519 @@ -749,7 +581,7 @@
   1.520        /// original one, otherwise its oppositely directed pair is obtained.
   1.521        Edge(const Graph1Edge& n1, 
   1.522  	   const Graph2Edge& n2, bool _backward) : 
   1.523 -	Graph1Edge(!backward ? n1 : n2), backward(_backward) { }
   1.524 +	Graph1Edge(!_backward ? n1 : n2), backward(_backward) { }
   1.525        Edge(Invalid i) : Graph1Edge(i), backward(true) { }
   1.526        bool operator==(const Edge& v) const { 
   1.527  	return (backward==v.backward && 
   1.528 @@ -760,6 +592,11 @@
   1.529        }
   1.530      };
   1.531  
   1.532 +    using Parent::forward;
   1.533 +    using Parent::backward;
   1.534 +    bool forward(const Edge& e) const { return !e.backward; }
   1.535 +    bool backward(const Edge& e) const { return e.backward; }
   1.536 +
   1.537      using Parent::first;
   1.538      void first(Edge& i) const {
   1.539        Parent1::graph->first(*static_cast<Graph1Edge*>(&i));
   1.540 @@ -770,17 +607,25 @@
   1.541        }
   1.542      }
   1.543      void firstIn(Edge& i, const Node& n) const {
   1.544 -      Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
   1.545 -      i.backward=false;
   1.546 -      if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.547 +      if (!backward(n)) {
   1.548 +	Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
   1.549 +	if (*static_cast<Graph1Edge*>(&i)==INVALID) 
   1.550 +	  i=INVALID;
   1.551 +	else
   1.552 +	  i.backward=false;
   1.553 +      } else {
   1.554  	Parent2::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
   1.555  	i.backward=true;
   1.556        }
   1.557      }
   1.558      void firstOut(Edge& i, const Node& n) const {
   1.559 -      Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
   1.560 -      i.backward=false;
   1.561 -      if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.562 +      if (!backward(n)) {
   1.563 +	Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
   1.564 +	if (*static_cast<Graph1Edge*>(&i)==INVALID) 
   1.565 +	  i=INVALID;
   1.566 +	else
   1.567 +	  i.backward=false;
   1.568 +      } else {
   1.569  	Parent2::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
   1.570  	i.backward=true;
   1.571        }
   1.572 @@ -801,10 +646,7 @@
   1.573      void nextIn(Edge& i) const {
   1.574        if (!(i.backward)) {
   1.575  	Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i));
   1.576 -	if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.577 -	  Parent2::graph->first(*static_cast<Graph1Edge*>(&i));
   1.578 -	  i.backward=true;
   1.579 -	}
   1.580 + 	if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
   1.581        } else {
   1.582  	Parent2::graph->nextIn(*static_cast<Graph1Edge*>(&i));
   1.583        }
   1.584 @@ -812,10 +654,7 @@
   1.585      void nextOut(Edge& i) const {
   1.586        if (!(i.backward)) {
   1.587  	Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i));
   1.588 -	if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.589 -	  Parent2::graph->first(*static_cast<Graph1Edge*>(&i));
   1.590 -	  i.backward=true;
   1.591 -	}
   1.592 + 	if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
   1.593        } else {
   1.594  	Parent2::graph->nextOut(*static_cast<Graph1Edge*>(&i));
   1.595        }
   1.596 @@ -945,6 +784,11 @@
   1.597        }
   1.598      };
   1.599  
   1.600 +    using Parent::forward;
   1.601 +    using Parent::backward;
   1.602 +    bool forward(const Edge& e) const { return !e.backward; }
   1.603 +    bool backward(const Edge& e) const { return e.backward; }
   1.604 +
   1.605      using Parent::first;
   1.606      void first(Edge& i) const {
   1.607        Parent1::graph->first(*static_cast<Graph1Edge*>(&i));
   1.608 @@ -955,17 +799,25 @@
   1.609        }
   1.610      }
   1.611      void firstIn(Edge& i, const Node& n) const {
   1.612 -      Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
   1.613 -      i.backward=false;
   1.614 -      if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.615 +      if (!backward(n)) {
   1.616 +	Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
   1.617 +	if (*static_cast<Graph1Edge*>(&i)==INVALID) 
   1.618 +	  i=INVALID;
   1.619 +	else
   1.620 +	  i.backward=false;
   1.621 +      } else {
   1.622  	Parent2::graph->firstIn(*static_cast<Graph2Edge*>(&i), n);
   1.623  	i.backward=true;
   1.624        }
   1.625      }
   1.626      void firstOut(Edge& i, const Node& n) const {
   1.627 -      Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
   1.628 -      i.backward=false;
   1.629 -      if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.630 +      if (!backward(n)) {
   1.631 +	Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
   1.632 +	if (*static_cast<Graph1Edge*>(&i)==INVALID) 
   1.633 +	  i=INVALID;
   1.634 +	else	
   1.635 +	  i.backward=false;
   1.636 +      } else {
   1.637  	Parent2::graph->firstOut(*static_cast<Graph2Edge*>(&i), n);
   1.638  	i.backward=true;
   1.639        }
   1.640 @@ -986,10 +838,7 @@
   1.641      void nextIn(Edge& i) const {
   1.642        if (!(i.backward)) {
   1.643  	Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i));
   1.644 -	if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.645 -	  Parent2::graph->first(*static_cast<Graph2Edge*>(&i));
   1.646 -	  i.backward=true;
   1.647 -	}
   1.648 + 	if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
   1.649        } else {
   1.650  	Parent2::graph->nextIn(*static_cast<Graph2Edge*>(&i));
   1.651        }
   1.652 @@ -997,10 +846,7 @@
   1.653      void nextOut(Edge& i) const {
   1.654        if (!(i.backward)) {
   1.655  	Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i));
   1.656 -	if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.657 -	  Parent2::graph->first(*static_cast<Graph2Edge*>(&i));
   1.658 -	  i.backward=true;
   1.659 -	}
   1.660 + 	if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
   1.661        } else {
   1.662  	Parent2::graph->nextOut(*static_cast<Graph2Edge*>(&i));
   1.663        }
   1.664 @@ -1129,6 +975,11 @@
   1.665        }
   1.666      };
   1.667  
   1.668 +    using Parent::forward;
   1.669 +    using Parent::backward;
   1.670 +    bool forward(const Edge& e) const { return !e.backward; }
   1.671 +    bool backward(const Edge& e) const { return e.backward; }
   1.672 +
   1.673      using Parent::first;
   1.674      void first(Edge& i) const {
   1.675        Parent1::graph->first(*static_cast<Graph1Edge*>(&i));
   1.676 @@ -1139,17 +990,25 @@
   1.677        }
   1.678      }
   1.679      void firstIn(Edge& i, const Node& n) const {
   1.680 -      Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
   1.681 -      i.backward=false;
   1.682 -      if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.683 +      if (!backward(n)) {
   1.684 +	Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n);
   1.685 +	if (*static_cast<Graph1Edge*>(&i)==INVALID) 
   1.686 +	  i=INVALID;
   1.687 +	else
   1.688 +	  i.backward=false;
   1.689 +      } else {
   1.690  	Parent2::graph->firstIn(*static_cast<Graph2Edge*>(&i), n);
   1.691  	i.backward=true;
   1.692        }
   1.693      }
   1.694      void firstOut(Edge& i, const Node& n) const {
   1.695 -      Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
   1.696 -      i.backward=false;
   1.697 -      if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.698 +      if (!backward(n)) {
   1.699 +	Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n);
   1.700 +	if (*static_cast<Graph1Edge*>(&i)==INVALID) 
   1.701 +	  i=INVALID;
   1.702 +	else	
   1.703 +	  i.backward=false;
   1.704 +      } else {
   1.705  	Parent2::graph->firstOut(*static_cast<Graph2Edge*>(&i), n);
   1.706  	i.backward=true;
   1.707        }
   1.708 @@ -1170,10 +1029,7 @@
   1.709      void nextIn(Edge& i) const {
   1.710        if (!(i.backward)) {
   1.711  	Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i));
   1.712 -	if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.713 -	  Parent2::graph->first(*static_cast<Graph2Edge*>(&i));
   1.714 -	  i.backward=true;
   1.715 -	}
   1.716 + 	if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
   1.717        } else {
   1.718  	Parent2::graph->nextIn(*static_cast<Graph2Edge*>(&i));
   1.719        }
   1.720 @@ -1181,10 +1037,7 @@
   1.721      void nextOut(Edge& i) const {
   1.722        if (!(i.backward)) {
   1.723  	Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i));
   1.724 -	if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.725 -	  Parent2::graph->first(*static_cast<Graph2Edge*>(&i));
   1.726 -	  i.backward=true;
   1.727 -	}
   1.728 + 	if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID;
   1.729        } else {
   1.730  	Parent2::graph->nextOut(*static_cast<Graph2Edge*>(&i));
   1.731        }
   1.732 @@ -1347,6 +1200,14 @@
   1.733  
   1.734      int edgeNum() const { return edge_set_graph->edgeNum(); }
   1.735  
   1.736 +//     NNode addOldNode() {
   1.737 +//       return Parent::addNode();
   1.738 +//     }
   1.739 +
   1.740 +//     ENode addNewNode() {
   1.741 +//       return edge_set_graph->addNode();
   1.742 +//     }
   1.743 +
   1.744      Edge addEdge(const Node& u, const Node& v) {
   1.745        return edge_set_graph->addEdge((*e_node)[u], (*e_node)[v]);
   1.746      }
   1.747 @@ -1392,7 +1253,7 @@
   1.748      typedef _Graph Graph;
   1.749      typedef _EdgeSetGraph EdgeSetGraph;
   1.750      typedef IterableGraphExtender<
   1.751 -      NewEdgeSetGraphWrapper<_Graph, _EdgeSetGraph> > Parent;
   1.752 +      NewEdgeSetGraphWrapperBase<_Graph, _EdgeSetGraph> > Parent;
   1.753    protected:
   1.754      NewEdgeSetGraphWrapper() { }
   1.755    public:
   1.756 @@ -1409,6 +1270,51 @@
   1.757      }
   1.758    };
   1.759  
   1.760 +  /*! A graph wrapper class for the following functionality.
   1.761 +    The same as NewEdgeSetGrapWrapper, but the bijection and the graph of 
   1.762 +    new edges is andled inthe class.
   1.763 +   */
   1.764 +  template <typename _Graph, typename _EdgeSetGraph>
   1.765 +  class NewEdgeSetGraphWrapper2 : 
   1.766 +    public IterableGraphExtender<
   1.767 +    NewEdgeSetGraphWrapperBase<_Graph, _EdgeSetGraph> > {
   1.768 +  public:
   1.769 +    typedef _Graph Graph;
   1.770 +    typedef _EdgeSetGraph EdgeSetGraph;
   1.771 +    typedef IterableGraphExtender<
   1.772 +      NewEdgeSetGraphWrapperBase<_Graph, _EdgeSetGraph> > Parent;
   1.773 +  protected:
   1.774 +    _EdgeSetGraph _edge_set_graph;
   1.775 +    typename Graph::template NodeMap<typename EdgeSetGraph::Node> _e_node;
   1.776 +    typename EdgeSetGraph::template NodeMap<typename Graph::Node> _n_node;
   1.777 +    NewEdgeSetGraphWrapper2() { }
   1.778 +  public:
   1.779 +    typedef typename Graph::Node Node;
   1.780 +    //    typedef typename Parent::Edge Edge;
   1.781 +
   1.782 +    NewEdgeSetGraphWrapper2(_Graph& _graph) : 
   1.783 +      _edge_set_graph(), 
   1.784 +      _e_node(_graph), _n_node(_edge_set_graph) { 
   1.785 +      setGraph(_graph);
   1.786 +      setEdgeSetGraph(_edge_set_graph);
   1.787 +      setNodeMap(_n_node); setENodeMap(_e_node);
   1.788 +      Node n;
   1.789 +      for (this->first(n); n!=INVALID; this->next(n)) {
   1.790 +	typename EdgeSetGraph::Node e=_edge_set_graph.addNode();
   1.791 +	_e_node.set(n, e);
   1.792 +	_n_node.set(e, n);
   1.793 +      }
   1.794 +    }
   1.795 +
   1.796 +//     Node addNode() {
   1.797 +//       Node n=(*this).Parent::addNode();
   1.798 +//       typename EdgeSetGraph::Node e=_edge_set_graph.addNode();
   1.799 +//       _e_node.set(n, e);
   1.800 +//       _n_node.set(e, n);
   1.801 +//       return n;
   1.802 +//     }
   1.803 +
   1.804 +  };
   1.805  
   1.806    /*! A graph wrapper base class 
   1.807      for merging graphs of type _Graph1 and _Graph2 
   1.808 @@ -1417,6 +1323,9 @@
   1.809      into one graph.
   1.810      In an other point of view, _Graph1 is extended with 
   1.811      the edge-set of _Graph2.
   1.812 +    \warning we need specialize dimplementations
   1.813 +    \todo we need specialize dimplementations
   1.814 +    \bug we need specialize dimplementations
   1.815     */
   1.816    template <typename _Graph1, typename _Graph2, typename Enable=void>
   1.817    class AugmentingGraphWrapperBase : 
   1.818 @@ -1506,9 +1415,10 @@
   1.819      }
   1.820      void nextIn(Edge& i) const {
   1.821        if (!(i.backward)) {
   1.822 +	Node n=target(i);
   1.823  	Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i));
   1.824  	if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.825 -	  graph2->first(*static_cast<Graph2Edge*>(&i));
   1.826 +	  graph2->firstIn(*static_cast<Graph2Edge*>(&i), n);
   1.827  	  i.backward=true;
   1.828  	}
   1.829        } else {
   1.830 @@ -1517,9 +1427,10 @@
   1.831      }
   1.832      void nextOut(Edge& i) const {
   1.833        if (!(i.backward)) {
   1.834 +	Node n=source(i);
   1.835  	Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i));
   1.836  	if (*static_cast<Graph1Edge*>(&i)==INVALID) {
   1.837 -	  graph2->first(*static_cast<Graph2Edge*>(&i));
   1.838 +	  graph2->firstOut(*static_cast<Graph2Edge*>(&i), n);
   1.839  	  i.backward=true;
   1.840  	}
   1.841        } else {