lemon/graph_utils.h
changeset 2493 6231d9d3957b
parent 2476 059dcdda37c5
child 2510 bb523a4758f7
equal deleted inserted replaced
66:ba74d8cb4203 67:fbf765cdfbaf
   144   ///
   144   ///
   145   /// This function counts the nodes in the graph.
   145   /// This function counts the nodes in the graph.
   146   /// The complexity of the function is O(n) but for some
   146   /// The complexity of the function is O(n) but for some
   147   /// graph structures it is specialized to run in O(1).
   147   /// graph structures it is specialized to run in O(1).
   148   ///
   148   ///
   149   /// \todo Refer how to specialize it.
   149   /// If the graph contains a \e nodeNum() member function and a 
   150 
   150   /// \e NodeNumTag tag then this function calls directly the member
       
   151   /// function to query the cardinality of the node set.
   151   template <typename Graph>
   152   template <typename Graph>
   152   inline int countNodes(const Graph& g) {
   153   inline int countNodes(const Graph& g) {
   153     return _graph_utils_bits::CountNodesSelector<Graph>::count(g);
   154     return _graph_utils_bits::CountNodesSelector<Graph>::count(g);
   154   }
   155   }
   155 
   156 
   177   ///
   178   ///
   178   /// This function counts the anodes in the graph.
   179   /// This function counts the anodes in the graph.
   179   /// The complexity of the function is O(an) but for some
   180   /// The complexity of the function is O(an) but for some
   180   /// graph structures it is specialized to run in O(1).
   181   /// graph structures it is specialized to run in O(1).
   181   ///
   182   ///
   182   /// \todo Refer how to specialize it.
   183   /// If the graph contains an \e aNodeNum() member function and a 
   183 
   184   /// \e NodeNumTag tag then this function calls directly the member
       
   185   /// function to query the cardinality of the A-node set.
   184   template <typename Graph>
   186   template <typename Graph>
   185   inline int countANodes(const Graph& g) {
   187   inline int countANodes(const Graph& g) {
   186     return _graph_utils_bits::CountANodesSelector<Graph>::count(g);
   188     return _graph_utils_bits::CountANodesSelector<Graph>::count(g);
   187   }
   189   }
   188 
   190 
   210   ///
   212   ///
   211   /// This function counts the bnodes in the graph.
   213   /// This function counts the bnodes in the graph.
   212   /// The complexity of the function is O(bn) but for some
   214   /// The complexity of the function is O(bn) but for some
   213   /// graph structures it is specialized to run in O(1).
   215   /// graph structures it is specialized to run in O(1).
   214   ///
   216   ///
   215   /// \todo Refer how to specialize it.
   217   /// If the graph contains a \e bNodeNum() member function and a 
   216 
   218   /// \e NodeNumTag tag then this function calls directly the member
       
   219   /// function to query the cardinality of the B-node set.
   217   template <typename Graph>
   220   template <typename Graph>
   218   inline int countBNodes(const Graph& g) {
   221   inline int countBNodes(const Graph& g) {
   219     return _graph_utils_bits::CountBNodesSelector<Graph>::count(g);
   222     return _graph_utils_bits::CountBNodesSelector<Graph>::count(g);
   220   }
   223   }
   221 
   224 
   245   /// \brief Function to count the edges in the graph.
   248   /// \brief Function to count the edges in the graph.
   246   ///
   249   ///
   247   /// This function counts the edges in the graph.
   250   /// This function counts the edges in the graph.
   248   /// The complexity of the function is O(e) but for some
   251   /// The complexity of the function is O(e) but for some
   249   /// graph structures it is specialized to run in O(1).
   252   /// graph structures it is specialized to run in O(1).
   250 
   253   ///
       
   254   /// If the graph contains a \e edgeNum() member function and a 
       
   255   /// \e EdgeNumTag tag then this function calls directly the member
       
   256   /// function to query the cardinality of the edge set.
   251   template <typename Graph>
   257   template <typename Graph>
   252   inline int countEdges(const Graph& g) {
   258   inline int countEdges(const Graph& g) {
   253     return _graph_utils_bits::CountEdgesSelector<Graph>::count(g);
   259     return _graph_utils_bits::CountEdgesSelector<Graph>::count(g);
   254   }
   260   }
   255 
   261 
   277   /// \brief Function to count the undirected edges in the graph.
   283   /// \brief Function to count the undirected edges in the graph.
   278   ///
   284   ///
   279   /// This function counts the undirected edges in the graph.
   285   /// This function counts the undirected edges in the graph.
   280   /// The complexity of the function is O(e) but for some
   286   /// The complexity of the function is O(e) but for some
   281   /// graph structures it is specialized to run in O(1).
   287   /// graph structures it is specialized to run in O(1).
   282 
   288   ///
       
   289   /// If the graph contains a \e uEdgeNum() member function and a 
       
   290   /// \e EdgeNumTag tag then this function calls directly the member
       
   291   /// function to query the cardinality of the undirected edge set.
   283   template <typename Graph>
   292   template <typename Graph>
   284   inline int countUEdges(const Graph& g) {
   293   inline int countUEdges(const Graph& g) {
   285     return _graph_utils_bits::CountUEdgesSelector<Graph>::count(g);
   294     return _graph_utils_bits::CountUEdgesSelector<Graph>::count(g);
   286 
   295 
   287   }
   296   }
   557     const Graph& graph;
   566     const Graph& graph;
   558   };
   567   };
   559 
   568 
   560   /// \brief Copy a map.
   569   /// \brief Copy a map.
   561   ///
   570   ///
   562   /// This function copies the \c source map to the \c target map. It uses the
   571   /// This function copies the \c from map to the \c to map. It uses the
   563   /// given iterator to iterate on the data structure and it uses the \c ref
   572   /// given iterator to iterate on the data structure and it uses the \c ref
   564   /// mapping to convert the source's keys to the target's keys.
   573   /// mapping to convert the from's keys to the to's keys.
   565   template <typename Target, typename Source, 
   574   template <typename To, typename From, 
   566 	    typename ItemIt, typename Ref>	    
   575 	    typename ItemIt, typename Ref>	    
   567   void copyMap(Target& target, const Source& source, 
   576   void copyMap(To& to, const From& from, 
   568 	       ItemIt it, const Ref& ref) {
   577 	       ItemIt it, const Ref& ref) {
   569     for (; it != INVALID; ++it) {
   578     for (; it != INVALID; ++it) {
   570       target[ref[it]] = source[it];
   579       to[ref[it]] = from[it];
   571     }
   580     }
   572   }
   581   }
   573 
   582 
   574   /// \brief Copy the source map to the target map.
   583   /// \brief Copy the from map to the to map.
   575   ///
   584   ///
   576   /// Copy the \c source map to the \c target map. It uses the given iterator
   585   /// Copy the \c from map to the \c to map. It uses the given iterator
   577   /// to iterate on the data structure.
   586   /// to iterate on the data structure.
   578   template <typename Target, typename Source, typename ItemIt>	    
   587   template <typename To, typename From, typename ItemIt>	    
   579   void copyMap(Target& target, const Source& source, ItemIt it) {
   588   void copyMap(To& to, const From& from, ItemIt it) {
   580     for (; it != INVALID; ++it) {
   589     for (; it != INVALID; ++it) {
   581       target[it] = source[it];
   590       to[it] = from[it];
   582     }
   591     }
   583   }
   592   }
   584 
   593 
   585   namespace _graph_utils_bits {
   594   namespace _graph_utils_bits {
   586 
   595 
   587     template <typename Graph, typename Item, typename RefMap>
   596     template <typename Graph, typename Item, typename RefMap>
   588     class MapCopyBase {
   597     class MapCopyBase {
   589     public:
   598     public:
   590       virtual void copy(const Graph& source, const RefMap& refMap) = 0;
   599       virtual void copy(const Graph& from, const RefMap& refMap) = 0;
   591       
   600       
   592       virtual ~MapCopyBase() {}
   601       virtual ~MapCopyBase() {}
   593     };
   602     };
   594 
   603 
   595     template <typename Graph, typename Item, typename RefMap, 
   604     template <typename Graph, typename Item, typename RefMap, 
   596               typename TargetMap, typename SourceMap>
   605               typename ToMap, typename FromMap>
   597     class MapCopy : public MapCopyBase<Graph, Item, RefMap> {
   606     class MapCopy : public MapCopyBase<Graph, Item, RefMap> {
   598     public:
   607     public:
   599 
   608 
   600       MapCopy(TargetMap& tmap, const SourceMap& map) 
   609       MapCopy(ToMap& tmap, const FromMap& map) 
   601         : _tmap(tmap), _map(map) {}
   610         : _tmap(tmap), _map(map) {}
   602       
   611       
   603       virtual void copy(const Graph& graph, const RefMap& refMap) {
   612       virtual void copy(const Graph& graph, const RefMap& refMap) {
   604         typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
   613         typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt;
   605         for (ItemIt it(graph); it != INVALID; ++it) {
   614         for (ItemIt it(graph); it != INVALID; ++it) {
   606           _tmap.set(refMap[it], _map[it]);
   615           _tmap.set(refMap[it], _map[it]);
   607         }
   616         }
   608       }
   617       }
   609 
   618 
   610     private:
   619     private:
   611       TargetMap& _tmap;
   620       ToMap& _tmap;
   612       const SourceMap& _map;
   621       const FromMap& _map;
   613     };
   622     };
   614 
   623 
   615     template <typename Graph, typename Item, typename RefMap, typename It>
   624     template <typename Graph, typename Item, typename RefMap, typename It>
   616     class ItemCopy : public MapCopyBase<Graph, Item, RefMap> {
   625     class ItemCopy : public MapCopyBase<Graph, Item, RefMap> {
   617     public:
   626     public:
   662       CrossRef& _cmap;
   671       CrossRef& _cmap;
   663     };
   672     };
   664 
   673 
   665     template <typename Graph, typename Enable = void>
   674     template <typename Graph, typename Enable = void>
   666     struct GraphCopySelector {
   675     struct GraphCopySelector {
   667       template <typename Source, typename NodeRefMap, typename EdgeRefMap>
   676       template <typename From, typename NodeRefMap, typename EdgeRefMap>
   668       static void copy(Graph &target, const Source& source,
   677       static void copy(Graph &to, const From& from,
   669                        NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
   678                        NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
   670         for (typename Source::NodeIt it(source); it != INVALID; ++it) {
   679         for (typename From::NodeIt it(from); it != INVALID; ++it) {
   671           nodeRefMap[it] = target.addNode();
   680           nodeRefMap[it] = to.addNode();
   672         }
   681         }
   673         for (typename Source::EdgeIt it(source); it != INVALID; ++it) {
   682         for (typename From::EdgeIt it(from); it != INVALID; ++it) {
   674           edgeRefMap[it] = target.addEdge(nodeRefMap[source.source(it)], 
   683           edgeRefMap[it] = to.addEdge(nodeRefMap[from.source(it)], 
   675                                           nodeRefMap[source.target(it)]);
   684                                           nodeRefMap[from.target(it)]);
   676         }
   685         }
   677       }
   686       }
   678     };
   687     };
   679 
   688 
   680     template <typename Graph>
   689     template <typename Graph>
   681     struct GraphCopySelector<
   690     struct GraphCopySelector<
   682       Graph, 
   691       Graph, 
   683       typename enable_if<typename Graph::BuildTag, void>::type> 
   692       typename enable_if<typename Graph::BuildTag, void>::type> 
   684     {
   693     {
   685       template <typename Source, typename NodeRefMap, typename EdgeRefMap>
   694       template <typename From, typename NodeRefMap, typename EdgeRefMap>
   686       static void copy(Graph &target, const Source& source,
   695       static void copy(Graph &to, const From& from,
   687                        NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
   696                        NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
   688         target.build(source, nodeRefMap, edgeRefMap);
   697         to.build(from, nodeRefMap, edgeRefMap);
   689       }
   698       }
   690     };
   699     };
   691 
   700 
   692     template <typename UGraph, typename Enable = void>
   701     template <typename UGraph, typename Enable = void>
   693     struct UGraphCopySelector {
   702     struct UGraphCopySelector {
   694       template <typename Source, typename NodeRefMap, typename UEdgeRefMap>
   703       template <typename From, typename NodeRefMap, typename UEdgeRefMap>
   695       static void copy(UGraph &target, const Source& source,
   704       static void copy(UGraph &to, const From& from,
   696                        NodeRefMap& nodeRefMap, UEdgeRefMap& uEdgeRefMap) {
   705                        NodeRefMap& nodeRefMap, UEdgeRefMap& uEdgeRefMap) {
   697         for (typename Source::NodeIt it(source); it != INVALID; ++it) {
   706         for (typename From::NodeIt it(from); it != INVALID; ++it) {
   698           nodeRefMap[it] = target.addNode();
   707           nodeRefMap[it] = to.addNode();
   699         }
   708         }
   700         for (typename Source::UEdgeIt it(source); it != INVALID; ++it) {
   709         for (typename From::UEdgeIt it(from); it != INVALID; ++it) {
   701           uEdgeRefMap[it] = target.addEdge(nodeRefMap[source.source(it)], 
   710           uEdgeRefMap[it] = to.addEdge(nodeRefMap[from.source(it)], 
   702                                           nodeRefMap[source.target(it)]);
   711 				       nodeRefMap[from.target(it)]);
   703         }
   712         }
   704       }
   713       }
   705     };
   714     };
   706 
   715 
   707     template <typename UGraph>
   716     template <typename UGraph>
   708     struct UGraphCopySelector<
   717     struct UGraphCopySelector<
   709       UGraph, 
   718       UGraph, 
   710       typename enable_if<typename UGraph::BuildTag, void>::type> 
   719       typename enable_if<typename UGraph::BuildTag, void>::type> 
   711     {
   720     {
   712       template <typename Source, typename NodeRefMap, typename UEdgeRefMap>
   721       template <typename From, typename NodeRefMap, typename UEdgeRefMap>
   713       static void copy(UGraph &target, const Source& source,
   722       static void copy(UGraph &to, const From& from,
   714                        NodeRefMap& nodeRefMap, UEdgeRefMap& uEdgeRefMap) {
   723                        NodeRefMap& nodeRefMap, UEdgeRefMap& uEdgeRefMap) {
   715         target.build(source, nodeRefMap, uEdgeRefMap);
   724         to.build(from, nodeRefMap, uEdgeRefMap);
   716       }
   725       }
   717     };
   726     };
   718 
   727 
   719     template <typename BpUGraph, typename Enable = void>
   728     template <typename BpUGraph, typename Enable = void>
   720     struct BpUGraphCopySelector {
   729     struct BpUGraphCopySelector {
   721       template <typename Source, typename ANodeRefMap, 
   730       template <typename From, typename ANodeRefMap, 
   722                 typename BNodeRefMap, typename UEdgeRefMap>
   731                 typename BNodeRefMap, typename UEdgeRefMap>
   723       static void copy(BpUGraph &target, const Source& source,
   732       static void copy(BpUGraph &to, const From& from,
   724                        ANodeRefMap& aNodeRefMap, BNodeRefMap& bNodeRefMap,
   733                        ANodeRefMap& aNodeRefMap, BNodeRefMap& bNodeRefMap,
   725                        UEdgeRefMap& uEdgeRefMap) {
   734                        UEdgeRefMap& uEdgeRefMap) {
   726         for (typename Source::ANodeIt it(source); it != INVALID; ++it) {
   735         for (typename From::ANodeIt it(from); it != INVALID; ++it) {
   727           aNodeRefMap[it] = target.addANode();
   736           aNodeRefMap[it] = to.addANode();
   728         }
   737         }
   729         for (typename Source::BNodeIt it(source); it != INVALID; ++it) {
   738         for (typename From::BNodeIt it(from); it != INVALID; ++it) {
   730           bNodeRefMap[it] = target.addBNode();
   739           bNodeRefMap[it] = to.addBNode();
   731         }
   740         }
   732         for (typename Source::UEdgeIt it(source); it != INVALID; ++it) {
   741         for (typename From::UEdgeIt it(from); it != INVALID; ++it) {
   733           uEdgeRefMap[it] = target.addEdge(aNodeRefMap[source.aNode(it)], 
   742           uEdgeRefMap[it] = to.addEdge(aNodeRefMap[from.aNode(it)], 
   734                                            bNodeRefMap[source.bNode(it)]);
   743                                            bNodeRefMap[from.bNode(it)]);
   735         }
   744         }
   736       }
   745       }
   737     };
   746     };
   738 
   747 
   739     template <typename BpUGraph>
   748     template <typename BpUGraph>
   740     struct BpUGraphCopySelector<
   749     struct BpUGraphCopySelector<
   741       BpUGraph, 
   750       BpUGraph, 
   742       typename enable_if<typename BpUGraph::BuildTag, void>::type> 
   751       typename enable_if<typename BpUGraph::BuildTag, void>::type> 
   743     {
   752     {
   744       template <typename Source, typename ANodeRefMap, 
   753       template <typename From, typename ANodeRefMap, 
   745                 typename BNodeRefMap, typename UEdgeRefMap>
   754                 typename BNodeRefMap, typename UEdgeRefMap>
   746       static void copy(BpUGraph &target, const Source& source,
   755       static void copy(BpUGraph &to, const From& from,
   747                        ANodeRefMap& aNodeRefMap, BNodeRefMap& bNodeRefMap,
   756                        ANodeRefMap& aNodeRefMap, BNodeRefMap& bNodeRefMap,
   748                        UEdgeRefMap& uEdgeRefMap) {
   757                        UEdgeRefMap& uEdgeRefMap) {
   749         target.build(source, aNodeRefMap, bNodeRefMap, uEdgeRefMap);
   758         to.build(from, aNodeRefMap, bNodeRefMap, uEdgeRefMap);
   750       }
   759       }
   751     };
   760     };
   752     
   761     
   753 
   762 
   754   }
   763   }
   755 
   764 
   756   /// \brief Class to copy a graph.
   765   /// \brief Class to copy a graph.
   757   ///
   766   ///
   758   /// Class to copy a graph to another graph (duplicate a graph). The
   767   /// Class to copy a graph to another graph (duplicate a graph). The
   759   /// simplest way of using it is through the \c copyGraph() function.
   768   /// simplest way of using it is through the \c copyGraph() function.
   760   template <typename Target, typename Source>
   769   template <typename To, typename From>
   761   class GraphCopy {
   770   class GraphCopy {
   762   private:
   771   private:
   763 
   772 
   764     typedef typename Source::Node Node;
   773     typedef typename From::Node Node;
   765     typedef typename Source::NodeIt NodeIt;
   774     typedef typename From::NodeIt NodeIt;
   766     typedef typename Source::Edge Edge;
   775     typedef typename From::Edge Edge;
   767     typedef typename Source::EdgeIt EdgeIt;
   776     typedef typename From::EdgeIt EdgeIt;
   768 
   777 
   769     typedef typename Target::Node TNode;
   778     typedef typename To::Node TNode;
   770     typedef typename Target::Edge TEdge;
   779     typedef typename To::Edge TEdge;
   771 
   780 
   772     typedef typename Source::template NodeMap<TNode> NodeRefMap;
   781     typedef typename From::template NodeMap<TNode> NodeRefMap;
   773     typedef typename Source::template EdgeMap<TEdge> EdgeRefMap;
   782     typedef typename From::template EdgeMap<TEdge> EdgeRefMap;
   774     
   783     
   775     
   784     
   776   public: 
   785   public: 
   777 
   786 
   778 
   787 
   779     /// \brief Constructor for the GraphCopy.
   788     /// \brief Constructor for the GraphCopy.
   780     ///
   789     ///
   781     /// It copies the content of the \c _source graph into the
   790     /// It copies the content of the \c _from graph into the
   782     /// \c _target graph.
   791     /// \c _to graph.
   783     GraphCopy(Target& _target, const Source& _source) 
   792     GraphCopy(To& _to, const From& _from) 
   784       : source(_source), target(_target) {}
   793       : from(_from), to(_to) {}
   785 
   794 
   786     /// \brief Destructor of the GraphCopy
   795     /// \brief Destructor of the GraphCopy
   787     ///
   796     ///
   788     /// Destructor of the GraphCopy
   797     /// Destructor of the GraphCopy
   789     ~GraphCopy() {
   798     ~GraphCopy() {
   799     /// \brief Copies the node references into the given map.
   808     /// \brief Copies the node references into the given map.
   800     ///
   809     ///
   801     /// Copies the node references into the given map.
   810     /// Copies the node references into the given map.
   802     template <typename NodeRef>
   811     template <typename NodeRef>
   803     GraphCopy& nodeRef(NodeRef& map) {
   812     GraphCopy& nodeRef(NodeRef& map) {
   804       nodeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, Node, 
   813       nodeMapCopies.push_back(new _graph_utils_bits::RefCopy<From, Node, 
   805                               NodeRefMap, NodeRef>(map));
   814                               NodeRefMap, NodeRef>(map));
   806       return *this;
   815       return *this;
   807     }
   816     }
   808 
   817 
   809     /// \brief Copies the node cross references into the given map.
   818     /// \brief Copies the node cross references into the given map.
   810     ///
   819     ///
   811     ///  Copies the node cross references (reverse references) into
   820     ///  Copies the node cross references (reverse references) into
   812     ///  the given map.
   821     ///  the given map.
   813     template <typename NodeCrossRef>
   822     template <typename NodeCrossRef>
   814     GraphCopy& nodeCrossRef(NodeCrossRef& map) {
   823     GraphCopy& nodeCrossRef(NodeCrossRef& map) {
   815       nodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, Node,
   824       nodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<From, Node,
   816                               NodeRefMap, NodeCrossRef>(map));
   825                               NodeRefMap, NodeCrossRef>(map));
   817       return *this;
   826       return *this;
   818     }
   827     }
   819 
   828 
   820     /// \brief Make copy of the given map.
   829     /// \brief Make copy of the given map.
   821     ///
   830     ///
   822     /// Makes copy of the given map for the newly created graph. 
   831     /// Makes copy of the given map for the newly created graph. 
   823     /// The new map's key type is the target graph's node type,
   832     /// The new map's key type is the to graph's node type,
   824     /// and the copied map's key type is the source graph's node
   833     /// and the copied map's key type is the from graph's node
   825     /// type.  
   834     /// type.  
   826     template <typename TargetMap, typename SourceMap>
   835     template <typename ToMap, typename FromMap>
   827     GraphCopy& nodeMap(TargetMap& tmap, const SourceMap& map) {
   836     GraphCopy& nodeMap(ToMap& tmap, const FromMap& map) {
   828       nodeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, Node, 
   837       nodeMapCopies.push_back(new _graph_utils_bits::MapCopy<From, Node, 
   829                               NodeRefMap, TargetMap, SourceMap>(tmap, map));
   838                               NodeRefMap, ToMap, FromMap>(tmap, map));
   830       return *this;
   839       return *this;
   831     }
   840     }
   832 
   841 
   833     /// \brief Make a copy of the given node.
   842     /// \brief Make a copy of the given node.
   834     ///
   843     ///
   835     /// Make a copy of the given node.
   844     /// Make a copy of the given node.
   836     GraphCopy& node(TNode& tnode, const Node& snode) {
   845     GraphCopy& node(TNode& tnode, const Node& snode) {
   837       nodeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, Node, 
   846       nodeMapCopies.push_back(new _graph_utils_bits::ItemCopy<From, Node, 
   838                               NodeRefMap, TNode>(tnode, snode));
   847                               NodeRefMap, TNode>(tnode, snode));
   839       return *this;
   848       return *this;
   840     }
   849     }
   841 
   850 
   842     /// \brief Copies the edge references into the given map.
   851     /// \brief Copies the edge references into the given map.
   843     ///
   852     ///
   844     /// Copies the edge references into the given map.
   853     /// Copies the edge references into the given map.
   845     template <typename EdgeRef>
   854     template <typename EdgeRef>
   846     GraphCopy& edgeRef(EdgeRef& map) {
   855     GraphCopy& edgeRef(EdgeRef& map) {
   847       edgeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, Edge, 
   856       edgeMapCopies.push_back(new _graph_utils_bits::RefCopy<From, Edge, 
   848                               EdgeRefMap, EdgeRef>(map));
   857                               EdgeRefMap, EdgeRef>(map));
   849       return *this;
   858       return *this;
   850     }
   859     }
   851 
   860 
   852     /// \brief Copies the edge cross references into the given map.
   861     /// \brief Copies the edge cross references into the given map.
   853     ///
   862     ///
   854     ///  Copies the edge cross references (reverse references) into
   863     ///  Copies the edge cross references (reverse references) into
   855     ///  the given map.
   864     ///  the given map.
   856     template <typename EdgeCrossRef>
   865     template <typename EdgeCrossRef>
   857     GraphCopy& edgeCrossRef(EdgeCrossRef& map) {
   866     GraphCopy& edgeCrossRef(EdgeCrossRef& map) {
   858       edgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, Edge,
   867       edgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<From, Edge,
   859                               EdgeRefMap, EdgeCrossRef>(map));
   868                               EdgeRefMap, EdgeCrossRef>(map));
   860       return *this;
   869       return *this;
   861     }
   870     }
   862 
   871 
   863     /// \brief Make copy of the given map.
   872     /// \brief Make copy of the given map.
   864     ///
   873     ///
   865     /// Makes copy of the given map for the newly created graph. 
   874     /// Makes copy of the given map for the newly created graph. 
   866     /// The new map's key type is the target graph's edge type,
   875     /// The new map's key type is the to graph's edge type,
   867     /// and the copied map's key type is the source graph's edge
   876     /// and the copied map's key type is the from graph's edge
   868     /// type.  
   877     /// type.  
   869     template <typename TargetMap, typename SourceMap>
   878     template <typename ToMap, typename FromMap>
   870     GraphCopy& edgeMap(TargetMap& tmap, const SourceMap& map) {
   879     GraphCopy& edgeMap(ToMap& tmap, const FromMap& map) {
   871       edgeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, Edge, 
   880       edgeMapCopies.push_back(new _graph_utils_bits::MapCopy<From, Edge, 
   872                               EdgeRefMap, TargetMap, SourceMap>(tmap, map));
   881                               EdgeRefMap, ToMap, FromMap>(tmap, map));
   873       return *this;
   882       return *this;
   874     }
   883     }
   875 
   884 
   876     /// \brief Make a copy of the given edge.
   885     /// \brief Make a copy of the given edge.
   877     ///
   886     ///
   878     /// Make a copy of the given edge.
   887     /// Make a copy of the given edge.
   879     GraphCopy& edge(TEdge& tedge, const Edge& sedge) {
   888     GraphCopy& edge(TEdge& tedge, const Edge& sedge) {
   880       edgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, Edge, 
   889       edgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<From, Edge, 
   881                               EdgeRefMap, TEdge>(tedge, sedge));
   890                               EdgeRefMap, TEdge>(tedge, sedge));
   882       return *this;
   891       return *this;
   883     }
   892     }
   884 
   893 
   885     /// \brief Executes the copies.
   894     /// \brief Executes the copies.
   886     ///
   895     ///
   887     /// Executes the copies.
   896     /// Executes the copies.
   888     void run() {
   897     void run() {
   889       NodeRefMap nodeRefMap(source);
   898       NodeRefMap nodeRefMap(from);
   890       EdgeRefMap edgeRefMap(source);
   899       EdgeRefMap edgeRefMap(from);
   891       _graph_utils_bits::GraphCopySelector<Target>::
   900       _graph_utils_bits::GraphCopySelector<To>::
   892         copy(target, source, nodeRefMap, edgeRefMap);
   901         copy(to, from, nodeRefMap, edgeRefMap);
   893       for (int i = 0; i < int(nodeMapCopies.size()); ++i) {
   902       for (int i = 0; i < int(nodeMapCopies.size()); ++i) {
   894         nodeMapCopies[i]->copy(source, nodeRefMap);
   903         nodeMapCopies[i]->copy(from, nodeRefMap);
   895       }
   904       }
   896       for (int i = 0; i < int(edgeMapCopies.size()); ++i) {
   905       for (int i = 0; i < int(edgeMapCopies.size()); ++i) {
   897         edgeMapCopies[i]->copy(source, edgeRefMap);
   906         edgeMapCopies[i]->copy(from, edgeRefMap);
   898       }      
   907       }      
   899     }
   908     }
   900 
   909 
   901   protected:
   910   protected:
   902 
   911 
   903 
   912 
   904     const Source& source;
   913     const From& from;
   905     Target& target;
   914     To& to;
   906 
   915 
   907     std::vector<_graph_utils_bits::MapCopyBase<Source, Node, NodeRefMap>* > 
   916     std::vector<_graph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* > 
   908     nodeMapCopies;
   917     nodeMapCopies;
   909 
   918 
   910     std::vector<_graph_utils_bits::MapCopyBase<Source, Edge, EdgeRefMap>* > 
   919     std::vector<_graph_utils_bits::MapCopyBase<From, Edge, EdgeRefMap>* > 
   911     edgeMapCopies;
   920     edgeMapCopies;
   912 
   921 
   913   };
   922   };
   914 
   923 
   915   /// \brief Copy a graph to another graph.
   924   /// \brief Copy a graph to another graph.
   920   ///\code
   929   ///\code
   921   /// copyGraph(trg, src).nodeRef(nr).edgeCrossRef(ecr).run();
   930   /// copyGraph(trg, src).nodeRef(nr).edgeCrossRef(ecr).run();
   922   ///\endcode
   931   ///\endcode
   923   /// 
   932   /// 
   924   /// After the copy the \c nr map will contain the mapping from the
   933   /// After the copy the \c nr map will contain the mapping from the
   925   /// source graph's nodes to the target graph's nodes and the \c ecr will
   934   /// from graph's nodes to the to graph's nodes and the \c ecr will
   926   /// contain the mapping from the target graph's edges to the source's
   935   /// contain the mapping from the to graph's edges to the from's
   927   /// edges.
   936   /// edges.
   928   ///
   937   ///
   929   /// \see GraphCopy 
   938   /// \see GraphCopy 
   930   template <typename Target, typename Source>
   939   template <typename To, typename From>
   931   GraphCopy<Target, Source> copyGraph(Target& target, const Source& source) {
   940   GraphCopy<To, From> copyGraph(To& to, const From& from) {
   932     return GraphCopy<Target, Source>(target, source);
   941     return GraphCopy<To, From>(to, from);
   933   }
   942   }
   934 
   943 
   935   /// \brief Class to copy an undirected graph.
   944   /// \brief Class to copy an undirected graph.
   936   ///
   945   ///
   937   /// Class to copy an undirected graph to another graph (duplicate a graph).
   946   /// Class to copy an undirected graph to another graph (duplicate a graph).
   938   /// The simplest way of using it is through the \c copyUGraph() function.
   947   /// The simplest way of using it is through the \c copyUGraph() function.
   939   template <typename Target, typename Source>
   948   template <typename To, typename From>
   940   class UGraphCopy {
   949   class UGraphCopy {
   941   private:
   950   private:
   942 
   951 
   943     typedef typename Source::Node Node;
   952     typedef typename From::Node Node;
   944     typedef typename Source::NodeIt NodeIt;
   953     typedef typename From::NodeIt NodeIt;
   945     typedef typename Source::Edge Edge;
   954     typedef typename From::Edge Edge;
   946     typedef typename Source::EdgeIt EdgeIt;
   955     typedef typename From::EdgeIt EdgeIt;
   947     typedef typename Source::UEdge UEdge;
   956     typedef typename From::UEdge UEdge;
   948     typedef typename Source::UEdgeIt UEdgeIt;
   957     typedef typename From::UEdgeIt UEdgeIt;
   949 
   958 
   950     typedef typename Target::Node TNode;
   959     typedef typename To::Node TNode;
   951     typedef typename Target::Edge TEdge;
   960     typedef typename To::Edge TEdge;
   952     typedef typename Target::UEdge TUEdge;
   961     typedef typename To::UEdge TUEdge;
   953 
   962 
   954     typedef typename Source::template NodeMap<TNode> NodeRefMap;
   963     typedef typename From::template NodeMap<TNode> NodeRefMap;
   955     typedef typename Source::template UEdgeMap<TUEdge> UEdgeRefMap;
   964     typedef typename From::template UEdgeMap<TUEdge> UEdgeRefMap;
   956 
   965 
   957     struct EdgeRefMap {
   966     struct EdgeRefMap {
   958       EdgeRefMap(const Target& _target, const Source& _source,
   967       EdgeRefMap(const To& _to, const From& _from,
   959                  const UEdgeRefMap& _uedge_ref, const NodeRefMap& _node_ref) 
   968                  const UEdgeRefMap& _uedge_ref, const NodeRefMap& _node_ref) 
   960         : target(_target), source(_source), 
   969         : to(_to), from(_from), 
   961           uedge_ref(_uedge_ref), node_ref(_node_ref) {}
   970           uedge_ref(_uedge_ref), node_ref(_node_ref) {}
   962 
   971 
   963       typedef typename Source::Edge Key;
   972       typedef typename From::Edge Key;
   964       typedef typename Target::Edge Value;
   973       typedef typename To::Edge Value;
   965 
   974 
   966       Value operator[](const Key& key) const {
   975       Value operator[](const Key& key) const {
   967         bool forward = 
   976         bool forward = 
   968           (source.direction(key) == 
   977           (from.direction(key) == 
   969            (node_ref[source.source(static_cast<const UEdge&>(key))] == 
   978            (node_ref[from.source(static_cast<const UEdge&>(key))] == 
   970             target.source(uedge_ref[static_cast<const UEdge&>(key)])));
   979             to.source(uedge_ref[static_cast<const UEdge&>(key)])));
   971 	return target.direct(uedge_ref[key], forward); 
   980 	return to.direct(uedge_ref[key], forward); 
   972       }
   981       }
   973       
   982       
   974       const Target& target;
   983       const To& to;
   975       const Source& source;
   984       const From& from;
   976       const UEdgeRefMap& uedge_ref;
   985       const UEdgeRefMap& uedge_ref;
   977       const NodeRefMap& node_ref;
   986       const NodeRefMap& node_ref;
   978     };
   987     };
   979 
   988 
   980     
   989     
   981   public: 
   990   public: 
   982 
   991 
   983 
   992 
   984     /// \brief Constructor for the GraphCopy.
   993     /// \brief Constructor for the GraphCopy.
   985     ///
   994     ///
   986     /// It copies the content of the \c _source graph into the
   995     /// It copies the content of the \c _from graph into the
   987     /// \c _target graph.
   996     /// \c _to graph.
   988     UGraphCopy(Target& _target, const Source& _source) 
   997     UGraphCopy(To& _to, const From& _from) 
   989       : source(_source), target(_target) {}
   998       : from(_from), to(_to) {}
   990 
   999 
   991     /// \brief Destructor of the GraphCopy
  1000     /// \brief Destructor of the GraphCopy
   992     ///
  1001     ///
   993     /// Destructor of the GraphCopy
  1002     /// Destructor of the GraphCopy
   994     ~UGraphCopy() {
  1003     ~UGraphCopy() {
  1007     /// \brief Copies the node references into the given map.
  1016     /// \brief Copies the node references into the given map.
  1008     ///
  1017     ///
  1009     /// Copies the node references into the given map.
  1018     /// Copies the node references into the given map.
  1010     template <typename NodeRef>
  1019     template <typename NodeRef>
  1011     UGraphCopy& nodeRef(NodeRef& map) {
  1020     UGraphCopy& nodeRef(NodeRef& map) {
  1012       nodeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, Node, 
  1021       nodeMapCopies.push_back(new _graph_utils_bits::RefCopy<From, Node, 
  1013                               NodeRefMap, NodeRef>(map));
  1022                               NodeRefMap, NodeRef>(map));
  1014       return *this;
  1023       return *this;
  1015     }
  1024     }
  1016 
  1025 
  1017     /// \brief Copies the node cross references into the given map.
  1026     /// \brief Copies the node cross references into the given map.
  1018     ///
  1027     ///
  1019     ///  Copies the node cross references (reverse references) into
  1028     ///  Copies the node cross references (reverse references) into
  1020     ///  the given map.
  1029     ///  the given map.
  1021     template <typename NodeCrossRef>
  1030     template <typename NodeCrossRef>
  1022     UGraphCopy& nodeCrossRef(NodeCrossRef& map) {
  1031     UGraphCopy& nodeCrossRef(NodeCrossRef& map) {
  1023       nodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, Node,
  1032       nodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<From, Node,
  1024                               NodeRefMap, NodeCrossRef>(map));
  1033                               NodeRefMap, NodeCrossRef>(map));
  1025       return *this;
  1034       return *this;
  1026     }
  1035     }
  1027 
  1036 
  1028     /// \brief Make copy of the given map.
  1037     /// \brief Make copy of the given map.
  1029     ///
  1038     ///
  1030     /// Makes copy of the given map for the newly created graph. 
  1039     /// Makes copy of the given map for the newly created graph. 
  1031     /// The new map's key type is the target graph's node type,
  1040     /// The new map's key type is the to graph's node type,
  1032     /// and the copied map's key type is the source graph's node
  1041     /// and the copied map's key type is the from graph's node
  1033     /// type.  
  1042     /// type.  
  1034     template <typename TargetMap, typename SourceMap>
  1043     template <typename ToMap, typename FromMap>
  1035     UGraphCopy& nodeMap(TargetMap& tmap, const SourceMap& map) {
  1044     UGraphCopy& nodeMap(ToMap& tmap, const FromMap& map) {
  1036       nodeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, Node, 
  1045       nodeMapCopies.push_back(new _graph_utils_bits::MapCopy<From, Node, 
  1037                               NodeRefMap, TargetMap, SourceMap>(tmap, map));
  1046                               NodeRefMap, ToMap, FromMap>(tmap, map));
  1038       return *this;
  1047       return *this;
  1039     }
  1048     }
  1040 
  1049 
  1041     /// \brief Make a copy of the given node.
  1050     /// \brief Make a copy of the given node.
  1042     ///
  1051     ///
  1043     /// Make a copy of the given node.
  1052     /// Make a copy of the given node.
  1044     UGraphCopy& node(TNode& tnode, const Node& snode) {
  1053     UGraphCopy& node(TNode& tnode, const Node& snode) {
  1045       nodeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, Node, 
  1054       nodeMapCopies.push_back(new _graph_utils_bits::ItemCopy<From, Node, 
  1046                               NodeRefMap, TNode>(tnode, snode));
  1055                               NodeRefMap, TNode>(tnode, snode));
  1047       return *this;
  1056       return *this;
  1048     }
  1057     }
  1049 
  1058 
  1050     /// \brief Copies the edge references into the given map.
  1059     /// \brief Copies the edge references into the given map.
  1051     ///
  1060     ///
  1052     /// Copies the edge references into the given map.
  1061     /// Copies the edge references into the given map.
  1053     template <typename EdgeRef>
  1062     template <typename EdgeRef>
  1054     UGraphCopy& edgeRef(EdgeRef& map) {
  1063     UGraphCopy& edgeRef(EdgeRef& map) {
  1055       edgeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, Edge, 
  1064       edgeMapCopies.push_back(new _graph_utils_bits::RefCopy<From, Edge, 
  1056                               EdgeRefMap, EdgeRef>(map));
  1065                               EdgeRefMap, EdgeRef>(map));
  1057       return *this;
  1066       return *this;
  1058     }
  1067     }
  1059 
  1068 
  1060     /// \brief Copies the edge cross references into the given map.
  1069     /// \brief Copies the edge cross references into the given map.
  1061     ///
  1070     ///
  1062     ///  Copies the edge cross references (reverse references) into
  1071     ///  Copies the edge cross references (reverse references) into
  1063     ///  the given map.
  1072     ///  the given map.
  1064     template <typename EdgeCrossRef>
  1073     template <typename EdgeCrossRef>
  1065     UGraphCopy& edgeCrossRef(EdgeCrossRef& map) {
  1074     UGraphCopy& edgeCrossRef(EdgeCrossRef& map) {
  1066       edgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, Edge,
  1075       edgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<From, Edge,
  1067                               EdgeRefMap, EdgeCrossRef>(map));
  1076                               EdgeRefMap, EdgeCrossRef>(map));
  1068       return *this;
  1077       return *this;
  1069     }
  1078     }
  1070 
  1079 
  1071     /// \brief Make copy of the given map.
  1080     /// \brief Make copy of the given map.
  1072     ///
  1081     ///
  1073     /// Makes copy of the given map for the newly created graph. 
  1082     /// Makes copy of the given map for the newly created graph. 
  1074     /// The new map's key type is the target graph's edge type,
  1083     /// The new map's key type is the to graph's edge type,
  1075     /// and the copied map's key type is the source graph's edge
  1084     /// and the copied map's key type is the from graph's edge
  1076     /// type.  
  1085     /// type.  
  1077     template <typename TargetMap, typename SourceMap>
  1086     template <typename ToMap, typename FromMap>
  1078     UGraphCopy& edgeMap(TargetMap& tmap, const SourceMap& map) {
  1087     UGraphCopy& edgeMap(ToMap& tmap, const FromMap& map) {
  1079       edgeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, Edge, 
  1088       edgeMapCopies.push_back(new _graph_utils_bits::MapCopy<From, Edge, 
  1080                               EdgeRefMap, TargetMap, SourceMap>(tmap, map));
  1089                               EdgeRefMap, ToMap, FromMap>(tmap, map));
  1081       return *this;
  1090       return *this;
  1082     }
  1091     }
  1083 
  1092 
  1084     /// \brief Make a copy of the given edge.
  1093     /// \brief Make a copy of the given edge.
  1085     ///
  1094     ///
  1086     /// Make a copy of the given edge.
  1095     /// Make a copy of the given edge.
  1087     UGraphCopy& edge(TEdge& tedge, const Edge& sedge) {
  1096     UGraphCopy& edge(TEdge& tedge, const Edge& sedge) {
  1088       edgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, Edge, 
  1097       edgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<From, Edge, 
  1089                               EdgeRefMap, TEdge>(tedge, sedge));
  1098                               EdgeRefMap, TEdge>(tedge, sedge));
  1090       return *this;
  1099       return *this;
  1091     }
  1100     }
  1092 
  1101 
  1093     /// \brief Copies the undirected edge references into the given map.
  1102     /// \brief Copies the undirected edge references into the given map.
  1094     ///
  1103     ///
  1095     /// Copies the undirected edge references into the given map.
  1104     /// Copies the undirected edge references into the given map.
  1096     template <typename UEdgeRef>
  1105     template <typename UEdgeRef>
  1097     UGraphCopy& uEdgeRef(UEdgeRef& map) {
  1106     UGraphCopy& uEdgeRef(UEdgeRef& map) {
  1098       uEdgeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, UEdge, 
  1107       uEdgeMapCopies.push_back(new _graph_utils_bits::RefCopy<From, UEdge, 
  1099                                UEdgeRefMap, UEdgeRef>(map));
  1108                                UEdgeRefMap, UEdgeRef>(map));
  1100       return *this;
  1109       return *this;
  1101     }
  1110     }
  1102 
  1111 
  1103     /// \brief Copies the undirected edge cross references into the given map.
  1112     /// \brief Copies the undirected edge cross references into the given map.
  1104     ///
  1113     ///
  1105     /// Copies the undirected edge cross references (reverse
  1114     /// Copies the undirected edge cross references (reverse
  1106     /// references) into the given map.
  1115     /// references) into the given map.
  1107     template <typename UEdgeCrossRef>
  1116     template <typename UEdgeCrossRef>
  1108     UGraphCopy& uEdgeCrossRef(UEdgeCrossRef& map) {
  1117     UGraphCopy& uEdgeCrossRef(UEdgeCrossRef& map) {
  1109       uEdgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, 
  1118       uEdgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<From, 
  1110                                UEdge, UEdgeRefMap, UEdgeCrossRef>(map));
  1119                                UEdge, UEdgeRefMap, UEdgeCrossRef>(map));
  1111       return *this;
  1120       return *this;
  1112     }
  1121     }
  1113 
  1122 
  1114     /// \brief Make copy of the given map.
  1123     /// \brief Make copy of the given map.
  1115     ///
  1124     ///
  1116     /// Makes copy of the given map for the newly created graph. 
  1125     /// Makes copy of the given map for the newly created graph. 
  1117     /// The new map's key type is the target graph's undirected edge type,
  1126     /// The new map's key type is the to graph's undirected edge type,
  1118     /// and the copied map's key type is the source graph's undirected edge
  1127     /// and the copied map's key type is the from graph's undirected edge
  1119     /// type.  
  1128     /// type.  
  1120     template <typename TargetMap, typename SourceMap>
  1129     template <typename ToMap, typename FromMap>
  1121     UGraphCopy& uEdgeMap(TargetMap& tmap, const SourceMap& map) {
  1130     UGraphCopy& uEdgeMap(ToMap& tmap, const FromMap& map) {
  1122       uEdgeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, UEdge, 
  1131       uEdgeMapCopies.push_back(new _graph_utils_bits::MapCopy<From, UEdge, 
  1123                                UEdgeRefMap, TargetMap, SourceMap>(tmap, map));
  1132                                UEdgeRefMap, ToMap, FromMap>(tmap, map));
  1124       return *this;
  1133       return *this;
  1125     }
  1134     }
  1126 
  1135 
  1127     /// \brief Make a copy of the given undirected edge.
  1136     /// \brief Make a copy of the given undirected edge.
  1128     ///
  1137     ///
  1129     /// Make a copy of the given undirected edge.
  1138     /// Make a copy of the given undirected edge.
  1130     UGraphCopy& uEdge(TUEdge& tuedge, const UEdge& suedge) {
  1139     UGraphCopy& uEdge(TUEdge& tuedge, const UEdge& suedge) {
  1131       uEdgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, UEdge, 
  1140       uEdgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<From, UEdge, 
  1132                                UEdgeRefMap, TUEdge>(tuedge, suedge));
  1141                                UEdgeRefMap, TUEdge>(tuedge, suedge));
  1133       return *this;
  1142       return *this;
  1134     }
  1143     }
  1135 
  1144 
  1136     /// \brief Executes the copies.
  1145     /// \brief Executes the copies.
  1137     ///
  1146     ///
  1138     /// Executes the copies.
  1147     /// Executes the copies.
  1139     void run() {
  1148     void run() {
  1140       NodeRefMap nodeRefMap(source);
  1149       NodeRefMap nodeRefMap(from);
  1141       UEdgeRefMap uEdgeRefMap(source);
  1150       UEdgeRefMap uEdgeRefMap(from);
  1142       EdgeRefMap edgeRefMap(target, source, uEdgeRefMap, nodeRefMap);
  1151       EdgeRefMap edgeRefMap(to, from, uEdgeRefMap, nodeRefMap);
  1143       _graph_utils_bits::UGraphCopySelector<Target>::
  1152       _graph_utils_bits::UGraphCopySelector<To>::
  1144         copy(target, source, nodeRefMap, uEdgeRefMap);
  1153         copy(to, from, nodeRefMap, uEdgeRefMap);
  1145       for (int i = 0; i < int(nodeMapCopies.size()); ++i) {
  1154       for (int i = 0; i < int(nodeMapCopies.size()); ++i) {
  1146         nodeMapCopies[i]->copy(source, nodeRefMap);
  1155         nodeMapCopies[i]->copy(from, nodeRefMap);
  1147       }
  1156       }
  1148       for (int i = 0; i < int(uEdgeMapCopies.size()); ++i) {
  1157       for (int i = 0; i < int(uEdgeMapCopies.size()); ++i) {
  1149         uEdgeMapCopies[i]->copy(source, uEdgeRefMap);
  1158         uEdgeMapCopies[i]->copy(from, uEdgeRefMap);
  1150       }
  1159       }
  1151       for (int i = 0; i < int(edgeMapCopies.size()); ++i) {
  1160       for (int i = 0; i < int(edgeMapCopies.size()); ++i) {
  1152         edgeMapCopies[i]->copy(source, edgeRefMap);
  1161         edgeMapCopies[i]->copy(from, edgeRefMap);
  1153       }
  1162       }
  1154     }
  1163     }
  1155 
  1164 
  1156   private:
  1165   private:
  1157     
  1166     
  1158     const Source& source;
  1167     const From& from;
  1159     Target& target;
  1168     To& to;
  1160 
  1169 
  1161     std::vector<_graph_utils_bits::MapCopyBase<Source, Node, NodeRefMap>* > 
  1170     std::vector<_graph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* > 
  1162     nodeMapCopies;
  1171     nodeMapCopies;
  1163 
  1172 
  1164     std::vector<_graph_utils_bits::MapCopyBase<Source, Edge, EdgeRefMap>* > 
  1173     std::vector<_graph_utils_bits::MapCopyBase<From, Edge, EdgeRefMap>* > 
  1165     edgeMapCopies;
  1174     edgeMapCopies;
  1166 
  1175 
  1167     std::vector<_graph_utils_bits::MapCopyBase<Source, UEdge, UEdgeRefMap>* > 
  1176     std::vector<_graph_utils_bits::MapCopyBase<From, UEdge, UEdgeRefMap>* > 
  1168     uEdgeMapCopies;
  1177     uEdgeMapCopies;
  1169 
  1178 
  1170   };
  1179   };
  1171 
  1180 
  1172   /// \brief Copy an undirected graph to another graph.
  1181   /// \brief Copy an undirected graph to another graph.
  1177   ///\code
  1186   ///\code
  1178   /// copyUGraph(trg, src).nodeRef(nr).edgeCrossRef(ecr).run();
  1187   /// copyUGraph(trg, src).nodeRef(nr).edgeCrossRef(ecr).run();
  1179   ///\endcode
  1188   ///\endcode
  1180   /// 
  1189   /// 
  1181   /// After the copy the \c nr map will contain the mapping from the
  1190   /// After the copy the \c nr map will contain the mapping from the
  1182   /// source graph's nodes to the target graph's nodes and the \c ecr will
  1191   /// from graph's nodes to the to graph's nodes and the \c ecr will
  1183   /// contain the mapping from the target graph's edges to the source's
  1192   /// contain the mapping from the to graph's edges to the from's
  1184   /// edges.
  1193   /// edges.
  1185   ///
  1194   ///
  1186   /// \see UGraphCopy 
  1195   /// \see UGraphCopy 
  1187   template <typename Target, typename Source>
  1196   template <typename To, typename From>
  1188   UGraphCopy<Target, Source> 
  1197   UGraphCopy<To, From> 
  1189   copyUGraph(Target& target, const Source& source) {
  1198   copyUGraph(To& to, const From& from) {
  1190     return UGraphCopy<Target, Source>(target, source);
  1199     return UGraphCopy<To, From>(to, from);
  1191   }
  1200   }
  1192 
  1201 
  1193   /// \brief Class to copy a bipartite undirected graph.
  1202   /// \brief Class to copy a bipartite undirected graph.
  1194   ///
  1203   ///
  1195   /// Class to copy a bipartite undirected graph to another graph
  1204   /// Class to copy a bipartite undirected graph to another graph
  1196   /// (duplicate a graph).  The simplest way of using it is through
  1205   /// (duplicate a graph).  The simplest way of using it is through
  1197   /// the \c copyBpUGraph() function.
  1206   /// the \c copyBpUGraph() function.
  1198   template <typename Target, typename Source>
  1207   template <typename To, typename From>
  1199   class BpUGraphCopy {
  1208   class BpUGraphCopy {
  1200   private:
  1209   private:
  1201 
  1210 
  1202     typedef typename Source::Node Node;
  1211     typedef typename From::Node Node;
  1203     typedef typename Source::ANode ANode;
  1212     typedef typename From::ANode ANode;
  1204     typedef typename Source::BNode BNode;
  1213     typedef typename From::BNode BNode;
  1205     typedef typename Source::NodeIt NodeIt;
  1214     typedef typename From::NodeIt NodeIt;
  1206     typedef typename Source::Edge Edge;
  1215     typedef typename From::Edge Edge;
  1207     typedef typename Source::EdgeIt EdgeIt;
  1216     typedef typename From::EdgeIt EdgeIt;
  1208     typedef typename Source::UEdge UEdge;
  1217     typedef typename From::UEdge UEdge;
  1209     typedef typename Source::UEdgeIt UEdgeIt;
  1218     typedef typename From::UEdgeIt UEdgeIt;
  1210 
  1219 
  1211     typedef typename Target::Node TNode;
  1220     typedef typename To::Node TNode;
  1212     typedef typename Target::Edge TEdge;
  1221     typedef typename To::Edge TEdge;
  1213     typedef typename Target::UEdge TUEdge;
  1222     typedef typename To::UEdge TUEdge;
  1214 
  1223 
  1215     typedef typename Source::template ANodeMap<TNode> ANodeRefMap;
  1224     typedef typename From::template ANodeMap<TNode> ANodeRefMap;
  1216     typedef typename Source::template BNodeMap<TNode> BNodeRefMap;
  1225     typedef typename From::template BNodeMap<TNode> BNodeRefMap;
  1217     typedef typename Source::template UEdgeMap<TUEdge> UEdgeRefMap;
  1226     typedef typename From::template UEdgeMap<TUEdge> UEdgeRefMap;
  1218 
  1227 
  1219     struct NodeRefMap {
  1228     struct NodeRefMap {
  1220       NodeRefMap(const Source& _source, const ANodeRefMap& _anode_ref,
  1229       NodeRefMap(const From& _from, const ANodeRefMap& _anode_ref,
  1221                  const BNodeRefMap& _bnode_ref)
  1230                  const BNodeRefMap& _bnode_ref)
  1222         : source(_source), anode_ref(_anode_ref), bnode_ref(_bnode_ref) {}
  1231         : from(_from), anode_ref(_anode_ref), bnode_ref(_bnode_ref) {}
  1223 
  1232 
  1224       typedef typename Source::Node Key;
  1233       typedef typename From::Node Key;
  1225       typedef typename Target::Node Value;
  1234       typedef typename To::Node Value;
  1226 
  1235 
  1227       Value operator[](const Key& key) const {
  1236       Value operator[](const Key& key) const {
  1228 	return source.aNode(key) ? anode_ref[key] : bnode_ref[key]; 
  1237 	return from.aNode(key) ? anode_ref[key] : bnode_ref[key]; 
  1229       }
  1238       }
  1230       
  1239       
  1231       const Source& source;
  1240       const From& from;
  1232       const ANodeRefMap& anode_ref;
  1241       const ANodeRefMap& anode_ref;
  1233       const BNodeRefMap& bnode_ref;
  1242       const BNodeRefMap& bnode_ref;
  1234     };
  1243     };
  1235 
  1244 
  1236     struct EdgeRefMap {
  1245     struct EdgeRefMap {
  1237       EdgeRefMap(const Target& _target, const Source& _source,
  1246       EdgeRefMap(const To& _to, const From& _from,
  1238                  const UEdgeRefMap& _uedge_ref, const NodeRefMap& _node_ref) 
  1247                  const UEdgeRefMap& _uedge_ref, const NodeRefMap& _node_ref) 
  1239         : target(_target), source(_source), 
  1248         : to(_to), from(_from), 
  1240           uedge_ref(_uedge_ref), node_ref(_node_ref) {}
  1249           uedge_ref(_uedge_ref), node_ref(_node_ref) {}
  1241 
  1250 
  1242       typedef typename Source::Edge Key;
  1251       typedef typename From::Edge Key;
  1243       typedef typename Target::Edge Value;
  1252       typedef typename To::Edge Value;
  1244 
  1253 
  1245       Value operator[](const Key& key) const {
  1254       Value operator[](const Key& key) const {
  1246         bool forward = 
  1255         bool forward = 
  1247           (source.direction(key) == 
  1256           (from.direction(key) == 
  1248            (node_ref[source.source(static_cast<const UEdge&>(key))] == 
  1257            (node_ref[from.source(static_cast<const UEdge&>(key))] == 
  1249             target.source(uedge_ref[static_cast<const UEdge&>(key)])));
  1258             to.source(uedge_ref[static_cast<const UEdge&>(key)])));
  1250 	return target.direct(uedge_ref[key], forward); 
  1259 	return to.direct(uedge_ref[key], forward); 
  1251       }
  1260       }
  1252       
  1261       
  1253       const Target& target;
  1262       const To& to;
  1254       const Source& source;
  1263       const From& from;
  1255       const UEdgeRefMap& uedge_ref;
  1264       const UEdgeRefMap& uedge_ref;
  1256       const NodeRefMap& node_ref;
  1265       const NodeRefMap& node_ref;
  1257     };
  1266     };
  1258     
  1267     
  1259   public: 
  1268   public: 
  1260 
  1269 
  1261 
  1270 
  1262     /// \brief Constructor for the GraphCopy.
  1271     /// \brief Constructor for the GraphCopy.
  1263     ///
  1272     ///
  1264     /// It copies the content of the \c _source graph into the
  1273     /// It copies the content of the \c _from graph into the
  1265     /// \c _target graph.
  1274     /// \c _to graph.
  1266     BpUGraphCopy(Target& _target, const Source& _source) 
  1275     BpUGraphCopy(To& _to, const From& _from) 
  1267       : source(_source), target(_target) {}
  1276       : from(_from), to(_to) {}
  1268 
  1277 
  1269     /// \brief Destructor of the GraphCopy
  1278     /// \brief Destructor of the GraphCopy
  1270     ///
  1279     ///
  1271     /// Destructor of the GraphCopy
  1280     /// Destructor of the GraphCopy
  1272     ~BpUGraphCopy() {
  1281     ~BpUGraphCopy() {
  1291     /// \brief Copies the A-node references into the given map.
  1300     /// \brief Copies the A-node references into the given map.
  1292     ///
  1301     ///
  1293     /// Copies the A-node references into the given map.
  1302     /// Copies the A-node references into the given map.
  1294     template <typename ANodeRef>
  1303     template <typename ANodeRef>
  1295     BpUGraphCopy& aNodeRef(ANodeRef& map) {
  1304     BpUGraphCopy& aNodeRef(ANodeRef& map) {
  1296       aNodeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, ANode, 
  1305       aNodeMapCopies.push_back(new _graph_utils_bits::RefCopy<From, ANode, 
  1297                                ANodeRefMap, ANodeRef>(map));
  1306                                ANodeRefMap, ANodeRef>(map));
  1298       return *this;
  1307       return *this;
  1299     }
  1308     }
  1300 
  1309 
  1301     /// \brief Copies the A-node cross references into the given map.
  1310     /// \brief Copies the A-node cross references into the given map.
  1302     ///
  1311     ///
  1303     /// Copies the A-node cross references (reverse references) into
  1312     /// Copies the A-node cross references (reverse references) into
  1304     /// the given map.
  1313     /// the given map.
  1305     template <typename ANodeCrossRef>
  1314     template <typename ANodeCrossRef>
  1306     BpUGraphCopy& aNodeCrossRef(ANodeCrossRef& map) {
  1315     BpUGraphCopy& aNodeCrossRef(ANodeCrossRef& map) {
  1307       aNodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, 
  1316       aNodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<From, 
  1308                                ANode, ANodeRefMap, ANodeCrossRef>(map));
  1317                                ANode, ANodeRefMap, ANodeCrossRef>(map));
  1309       return *this;
  1318       return *this;
  1310     }
  1319     }
  1311 
  1320 
  1312     /// \brief Make copy of the given A-node map.
  1321     /// \brief Make copy of the given A-node map.
  1313     ///
  1322     ///
  1314     /// Makes copy of the given map for the newly created graph. 
  1323     /// Makes copy of the given map for the newly created graph. 
  1315     /// The new map's key type is the target graph's node type,
  1324     /// The new map's key type is the to graph's node type,
  1316     /// and the copied map's key type is the source graph's node
  1325     /// and the copied map's key type is the from graph's node
  1317     /// type.  
  1326     /// type.  
  1318     template <typename TargetMap, typename SourceMap>
  1327     template <typename ToMap, typename FromMap>
  1319     BpUGraphCopy& aNodeMap(TargetMap& tmap, const SourceMap& map) {
  1328     BpUGraphCopy& aNodeMap(ToMap& tmap, const FromMap& map) {
  1320       aNodeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, ANode, 
  1329       aNodeMapCopies.push_back(new _graph_utils_bits::MapCopy<From, ANode, 
  1321                                ANodeRefMap, TargetMap, SourceMap>(tmap, map));
  1330                                ANodeRefMap, ToMap, FromMap>(tmap, map));
  1322       return *this;
  1331       return *this;
  1323     }
  1332     }
  1324 
  1333 
  1325     /// \brief Copies the B-node references into the given map.
  1334     /// \brief Copies the B-node references into the given map.
  1326     ///
  1335     ///
  1327     /// Copies the B-node references into the given map.
  1336     /// Copies the B-node references into the given map.
  1328     template <typename BNodeRef>
  1337     template <typename BNodeRef>
  1329     BpUGraphCopy& bNodeRef(BNodeRef& map) {
  1338     BpUGraphCopy& bNodeRef(BNodeRef& map) {
  1330       bNodeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, BNode, 
  1339       bNodeMapCopies.push_back(new _graph_utils_bits::RefCopy<From, BNode, 
  1331                                BNodeRefMap, BNodeRef>(map));
  1340                                BNodeRefMap, BNodeRef>(map));
  1332       return *this;
  1341       return *this;
  1333     }
  1342     }
  1334 
  1343 
  1335     /// \brief Copies the B-node cross references into the given map.
  1344     /// \brief Copies the B-node cross references into the given map.
  1336     ///
  1345     ///
  1337     ///  Copies the B-node cross references (reverse references) into
  1346     ///  Copies the B-node cross references (reverse references) into
  1338     ///  the given map.
  1347     ///  the given map.
  1339     template <typename BNodeCrossRef>
  1348     template <typename BNodeCrossRef>
  1340     BpUGraphCopy& bNodeCrossRef(BNodeCrossRef& map) {
  1349     BpUGraphCopy& bNodeCrossRef(BNodeCrossRef& map) {
  1341       bNodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, 
  1350       bNodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<From, 
  1342                               BNode, BNodeRefMap, BNodeCrossRef>(map));
  1351                               BNode, BNodeRefMap, BNodeCrossRef>(map));
  1343       return *this;
  1352       return *this;
  1344     }
  1353     }
  1345 
  1354 
  1346     /// \brief Make copy of the given B-node map.
  1355     /// \brief Make copy of the given B-node map.
  1347     ///
  1356     ///
  1348     /// Makes copy of the given map for the newly created graph. 
  1357     /// Makes copy of the given map for the newly created graph. 
  1349     /// The new map's key type is the target graph's node type,
  1358     /// The new map's key type is the to graph's node type,
  1350     /// and the copied map's key type is the source graph's node
  1359     /// and the copied map's key type is the from graph's node
  1351     /// type.  
  1360     /// type.  
  1352     template <typename TargetMap, typename SourceMap>
  1361     template <typename ToMap, typename FromMap>
  1353     BpUGraphCopy& bNodeMap(TargetMap& tmap, const SourceMap& map) {
  1362     BpUGraphCopy& bNodeMap(ToMap& tmap, const FromMap& map) {
  1354       bNodeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, BNode, 
  1363       bNodeMapCopies.push_back(new _graph_utils_bits::MapCopy<From, BNode, 
  1355                                BNodeRefMap, TargetMap, SourceMap>(tmap, map));
  1364                                BNodeRefMap, ToMap, FromMap>(tmap, map));
  1356       return *this;
  1365       return *this;
  1357     }
  1366     }
  1358     /// \brief Copies the node references into the given map.
  1367     /// \brief Copies the node references into the given map.
  1359     ///
  1368     ///
  1360     /// Copies the node references into the given map.
  1369     /// Copies the node references into the given map.
  1361     template <typename NodeRef>
  1370     template <typename NodeRef>
  1362     BpUGraphCopy& nodeRef(NodeRef& map) {
  1371     BpUGraphCopy& nodeRef(NodeRef& map) {
  1363       nodeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, Node, 
  1372       nodeMapCopies.push_back(new _graph_utils_bits::RefCopy<From, Node, 
  1364                               NodeRefMap, NodeRef>(map));
  1373                               NodeRefMap, NodeRef>(map));
  1365       return *this;
  1374       return *this;
  1366     }
  1375     }
  1367 
  1376 
  1368     /// \brief Copies the node cross references into the given map.
  1377     /// \brief Copies the node cross references into the given map.
  1369     ///
  1378     ///
  1370     ///  Copies the node cross references (reverse references) into
  1379     ///  Copies the node cross references (reverse references) into
  1371     ///  the given map.
  1380     ///  the given map.
  1372     template <typename NodeCrossRef>
  1381     template <typename NodeCrossRef>
  1373     BpUGraphCopy& nodeCrossRef(NodeCrossRef& map) {
  1382     BpUGraphCopy& nodeCrossRef(NodeCrossRef& map) {
  1374       nodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, Node,
  1383       nodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<From, Node,
  1375                               NodeRefMap, NodeCrossRef>(map));
  1384                               NodeRefMap, NodeCrossRef>(map));
  1376       return *this;
  1385       return *this;
  1377     }
  1386     }
  1378 
  1387 
  1379     /// \brief Make copy of the given map.
  1388     /// \brief Make copy of the given map.
  1380     ///
  1389     ///
  1381     /// Makes copy of the given map for the newly created graph. 
  1390     /// Makes copy of the given map for the newly created graph. 
  1382     /// The new map's key type is the target graph's node type,
  1391     /// The new map's key type is the to graph's node type,
  1383     /// and the copied map's key type is the source graph's node
  1392     /// and the copied map's key type is the from graph's node
  1384     /// type.  
  1393     /// type.  
  1385     template <typename TargetMap, typename SourceMap>
  1394     template <typename ToMap, typename FromMap>
  1386     BpUGraphCopy& nodeMap(TargetMap& tmap, const SourceMap& map) {
  1395     BpUGraphCopy& nodeMap(ToMap& tmap, const FromMap& map) {
  1387       nodeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, Node, 
  1396       nodeMapCopies.push_back(new _graph_utils_bits::MapCopy<From, Node, 
  1388                               NodeRefMap, TargetMap, SourceMap>(tmap, map));
  1397                               NodeRefMap, ToMap, FromMap>(tmap, map));
  1389       return *this;
  1398       return *this;
  1390     }
  1399     }
  1391 
  1400 
  1392     /// \brief Make a copy of the given node.
  1401     /// \brief Make a copy of the given node.
  1393     ///
  1402     ///
  1394     /// Make a copy of the given node.
  1403     /// Make a copy of the given node.
  1395     BpUGraphCopy& node(TNode& tnode, const Node& snode) {
  1404     BpUGraphCopy& node(TNode& tnode, const Node& snode) {
  1396       nodeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, Node, 
  1405       nodeMapCopies.push_back(new _graph_utils_bits::ItemCopy<From, Node, 
  1397                               NodeRefMap, TNode>(tnode, snode));
  1406                               NodeRefMap, TNode>(tnode, snode));
  1398       return *this;
  1407       return *this;
  1399     }
  1408     }
  1400 
  1409 
  1401     /// \brief Copies the edge references into the given map.
  1410     /// \brief Copies the edge references into the given map.
  1402     ///
  1411     ///
  1403     /// Copies the edge references into the given map.
  1412     /// Copies the edge references into the given map.
  1404     template <typename EdgeRef>
  1413     template <typename EdgeRef>
  1405     BpUGraphCopy& edgeRef(EdgeRef& map) {
  1414     BpUGraphCopy& edgeRef(EdgeRef& map) {
  1406       edgeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, Edge, 
  1415       edgeMapCopies.push_back(new _graph_utils_bits::RefCopy<From, Edge, 
  1407                               EdgeRefMap, EdgeRef>(map));
  1416                               EdgeRefMap, EdgeRef>(map));
  1408       return *this;
  1417       return *this;
  1409     }
  1418     }
  1410 
  1419 
  1411     /// \brief Copies the edge cross references into the given map.
  1420     /// \brief Copies the edge cross references into the given map.
  1412     ///
  1421     ///
  1413     ///  Copies the edge cross references (reverse references) into
  1422     ///  Copies the edge cross references (reverse references) into
  1414     ///  the given map.
  1423     ///  the given map.
  1415     template <typename EdgeCrossRef>
  1424     template <typename EdgeCrossRef>
  1416     BpUGraphCopy& edgeCrossRef(EdgeCrossRef& map) {
  1425     BpUGraphCopy& edgeCrossRef(EdgeCrossRef& map) {
  1417       edgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, Edge,
  1426       edgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<From, Edge,
  1418                               EdgeRefMap, EdgeCrossRef>(map));
  1427                               EdgeRefMap, EdgeCrossRef>(map));
  1419       return *this;
  1428       return *this;
  1420     }
  1429     }
  1421 
  1430 
  1422     /// \brief Make copy of the given map.
  1431     /// \brief Make copy of the given map.
  1423     ///
  1432     ///
  1424     /// Makes copy of the given map for the newly created graph. 
  1433     /// Makes copy of the given map for the newly created graph. 
  1425     /// The new map's key type is the target graph's edge type,
  1434     /// The new map's key type is the to graph's edge type,
  1426     /// and the copied map's key type is the source graph's edge
  1435     /// and the copied map's key type is the from graph's edge
  1427     /// type.  
  1436     /// type.  
  1428     template <typename TargetMap, typename SourceMap>
  1437     template <typename ToMap, typename FromMap>
  1429     BpUGraphCopy& edgeMap(TargetMap& tmap, const SourceMap& map) {
  1438     BpUGraphCopy& edgeMap(ToMap& tmap, const FromMap& map) {
  1430       edgeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, Edge, 
  1439       edgeMapCopies.push_back(new _graph_utils_bits::MapCopy<From, Edge, 
  1431                               EdgeRefMap, TargetMap, SourceMap>(tmap, map));
  1440                               EdgeRefMap, ToMap, FromMap>(tmap, map));
  1432       return *this;
  1441       return *this;
  1433     }
  1442     }
  1434 
  1443 
  1435     /// \brief Make a copy of the given edge.
  1444     /// \brief Make a copy of the given edge.
  1436     ///
  1445     ///
  1437     /// Make a copy of the given edge.
  1446     /// Make a copy of the given edge.
  1438     BpUGraphCopy& edge(TEdge& tedge, const Edge& sedge) {
  1447     BpUGraphCopy& edge(TEdge& tedge, const Edge& sedge) {
  1439       edgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, Edge, 
  1448       edgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<From, Edge, 
  1440                               EdgeRefMap, TEdge>(tedge, sedge));
  1449                               EdgeRefMap, TEdge>(tedge, sedge));
  1441       return *this;
  1450       return *this;
  1442     }
  1451     }
  1443 
  1452 
  1444     /// \brief Copies the undirected edge references into the given map.
  1453     /// \brief Copies the undirected edge references into the given map.
  1445     ///
  1454     ///
  1446     /// Copies the undirected edge references into the given map.
  1455     /// Copies the undirected edge references into the given map.
  1447     template <typename UEdgeRef>
  1456     template <typename UEdgeRef>
  1448     BpUGraphCopy& uEdgeRef(UEdgeRef& map) {
  1457     BpUGraphCopy& uEdgeRef(UEdgeRef& map) {
  1449       uEdgeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, UEdge, 
  1458       uEdgeMapCopies.push_back(new _graph_utils_bits::RefCopy<From, UEdge, 
  1450                                UEdgeRefMap, UEdgeRef>(map));
  1459                                UEdgeRefMap, UEdgeRef>(map));
  1451       return *this;
  1460       return *this;
  1452     }
  1461     }
  1453 
  1462 
  1454     /// \brief Copies the undirected edge cross references into the given map.
  1463     /// \brief Copies the undirected edge cross references into the given map.
  1455     ///
  1464     ///
  1456     /// Copies the undirected edge cross references (reverse
  1465     /// Copies the undirected edge cross references (reverse
  1457     /// references) into the given map.
  1466     /// references) into the given map.
  1458     template <typename UEdgeCrossRef>
  1467     template <typename UEdgeCrossRef>
  1459     BpUGraphCopy& uEdgeCrossRef(UEdgeCrossRef& map) {
  1468     BpUGraphCopy& uEdgeCrossRef(UEdgeCrossRef& map) {
  1460       uEdgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, 
  1469       uEdgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<From, 
  1461                                UEdge, UEdgeRefMap, UEdgeCrossRef>(map));
  1470                                UEdge, UEdgeRefMap, UEdgeCrossRef>(map));
  1462       return *this;
  1471       return *this;
  1463     }
  1472     }
  1464 
  1473 
  1465     /// \brief Make copy of the given map.
  1474     /// \brief Make copy of the given map.
  1466     ///
  1475     ///
  1467     /// Makes copy of the given map for the newly created graph. 
  1476     /// Makes copy of the given map for the newly created graph. 
  1468     /// The new map's key type is the target graph's undirected edge type,
  1477     /// The new map's key type is the to graph's undirected edge type,
  1469     /// and the copied map's key type is the source graph's undirected edge
  1478     /// and the copied map's key type is the from graph's undirected edge
  1470     /// type.  
  1479     /// type.  
  1471     template <typename TargetMap, typename SourceMap>
  1480     template <typename ToMap, typename FromMap>
  1472     BpUGraphCopy& uEdgeMap(TargetMap& tmap, const SourceMap& map) {
  1481     BpUGraphCopy& uEdgeMap(ToMap& tmap, const FromMap& map) {
  1473       uEdgeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, UEdge, 
  1482       uEdgeMapCopies.push_back(new _graph_utils_bits::MapCopy<From, UEdge, 
  1474                                UEdgeRefMap, TargetMap, SourceMap>(tmap, map));
  1483                                UEdgeRefMap, ToMap, FromMap>(tmap, map));
  1475       return *this;
  1484       return *this;
  1476     }
  1485     }
  1477 
  1486 
  1478     /// \brief Make a copy of the given undirected edge.
  1487     /// \brief Make a copy of the given undirected edge.
  1479     ///
  1488     ///
  1480     /// Make a copy of the given undirected edge.
  1489     /// Make a copy of the given undirected edge.
  1481     BpUGraphCopy& uEdge(TUEdge& tuedge, const UEdge& suedge) {
  1490     BpUGraphCopy& uEdge(TUEdge& tuedge, const UEdge& suedge) {
  1482       uEdgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, UEdge, 
  1491       uEdgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<From, UEdge, 
  1483                                UEdgeRefMap, TUEdge>(tuedge, suedge));
  1492                                UEdgeRefMap, TUEdge>(tuedge, suedge));
  1484       return *this;
  1493       return *this;
  1485     }
  1494     }
  1486 
  1495 
  1487     /// \brief Executes the copies.
  1496     /// \brief Executes the copies.
  1488     ///
  1497     ///
  1489     /// Executes the copies.
  1498     /// Executes the copies.
  1490     void run() {
  1499     void run() {
  1491       ANodeRefMap aNodeRefMap(source);
  1500       ANodeRefMap aNodeRefMap(from);
  1492       BNodeRefMap bNodeRefMap(source);
  1501       BNodeRefMap bNodeRefMap(from);
  1493       NodeRefMap nodeRefMap(source, aNodeRefMap, bNodeRefMap);
  1502       NodeRefMap nodeRefMap(from, aNodeRefMap, bNodeRefMap);
  1494       UEdgeRefMap uEdgeRefMap(source);
  1503       UEdgeRefMap uEdgeRefMap(from);
  1495       EdgeRefMap edgeRefMap(target, source, uEdgeRefMap, nodeRefMap);
  1504       EdgeRefMap edgeRefMap(to, from, uEdgeRefMap, nodeRefMap);
  1496       _graph_utils_bits::BpUGraphCopySelector<Target>::
  1505       _graph_utils_bits::BpUGraphCopySelector<To>::
  1497         copy(target, source, aNodeRefMap, bNodeRefMap, uEdgeRefMap);
  1506         copy(to, from, aNodeRefMap, bNodeRefMap, uEdgeRefMap);
  1498       for (int i = 0; i < int(aNodeMapCopies.size()); ++i) {
  1507       for (int i = 0; i < int(aNodeMapCopies.size()); ++i) {
  1499         aNodeMapCopies[i]->copy(source, aNodeRefMap);
  1508         aNodeMapCopies[i]->copy(from, aNodeRefMap);
  1500       }
  1509       }
  1501       for (int i = 0; i < int(bNodeMapCopies.size()); ++i) {
  1510       for (int i = 0; i < int(bNodeMapCopies.size()); ++i) {
  1502         bNodeMapCopies[i]->copy(source, bNodeRefMap);
  1511         bNodeMapCopies[i]->copy(from, bNodeRefMap);
  1503       }
  1512       }
  1504       for (int i = 0; i < int(nodeMapCopies.size()); ++i) {
  1513       for (int i = 0; i < int(nodeMapCopies.size()); ++i) {
  1505         nodeMapCopies[i]->copy(source, nodeRefMap);
  1514         nodeMapCopies[i]->copy(from, nodeRefMap);
  1506       }
  1515       }
  1507       for (int i = 0; i < int(uEdgeMapCopies.size()); ++i) {
  1516       for (int i = 0; i < int(uEdgeMapCopies.size()); ++i) {
  1508         uEdgeMapCopies[i]->copy(source, uEdgeRefMap);
  1517         uEdgeMapCopies[i]->copy(from, uEdgeRefMap);
  1509       }
  1518       }
  1510       for (int i = 0; i < int(edgeMapCopies.size()); ++i) {
  1519       for (int i = 0; i < int(edgeMapCopies.size()); ++i) {
  1511         edgeMapCopies[i]->copy(source, edgeRefMap);
  1520         edgeMapCopies[i]->copy(from, edgeRefMap);
  1512       }
  1521       }
  1513     }
  1522     }
  1514 
  1523 
  1515   private:
  1524   private:
  1516     
  1525     
  1517     const Source& source;
  1526     const From& from;
  1518     Target& target;
  1527     To& to;
  1519 
  1528 
  1520     std::vector<_graph_utils_bits::MapCopyBase<Source, ANode, ANodeRefMap>* > 
  1529     std::vector<_graph_utils_bits::MapCopyBase<From, ANode, ANodeRefMap>* > 
  1521     aNodeMapCopies;
  1530     aNodeMapCopies;
  1522 
  1531 
  1523     std::vector<_graph_utils_bits::MapCopyBase<Source, BNode, BNodeRefMap>* > 
  1532     std::vector<_graph_utils_bits::MapCopyBase<From, BNode, BNodeRefMap>* > 
  1524     bNodeMapCopies;
  1533     bNodeMapCopies;
  1525 
  1534 
  1526     std::vector<_graph_utils_bits::MapCopyBase<Source, Node, NodeRefMap>* > 
  1535     std::vector<_graph_utils_bits::MapCopyBase<From, Node, NodeRefMap>* > 
  1527     nodeMapCopies;
  1536     nodeMapCopies;
  1528 
  1537 
  1529     std::vector<_graph_utils_bits::MapCopyBase<Source, Edge, EdgeRefMap>* > 
  1538     std::vector<_graph_utils_bits::MapCopyBase<From, Edge, EdgeRefMap>* > 
  1530     edgeMapCopies;
  1539     edgeMapCopies;
  1531 
  1540 
  1532     std::vector<_graph_utils_bits::MapCopyBase<Source, UEdge, UEdgeRefMap>* > 
  1541     std::vector<_graph_utils_bits::MapCopyBase<From, UEdge, UEdgeRefMap>* > 
  1533     uEdgeMapCopies;
  1542     uEdgeMapCopies;
  1534 
  1543 
  1535   };
  1544   };
  1536 
  1545 
  1537   /// \brief Copy a bipartite undirected graph to another graph.
  1546   /// \brief Copy a bipartite undirected graph to another graph.
  1542   ///\code
  1551   ///\code
  1543   /// copyBpUGraph(trg, src).aNodeRef(anr).edgeCrossRef(ecr).run();
  1552   /// copyBpUGraph(trg, src).aNodeRef(anr).edgeCrossRef(ecr).run();
  1544   ///\endcode
  1553   ///\endcode
  1545   /// 
  1554   /// 
  1546   /// After the copy the \c nr map will contain the mapping from the
  1555   /// After the copy the \c nr map will contain the mapping from the
  1547   /// source graph's nodes to the target graph's nodes and the \c ecr will
  1556   /// from graph's nodes to the to graph's nodes and the \c ecr will
  1548   /// contain the mapping from the target graph's edges to the source's
  1557   /// contain the mapping from the to graph's edges to the from's
  1549   /// edges.
  1558   /// edges.
  1550   ///
  1559   ///
  1551   /// \see BpUGraphCopy
  1560   /// \see BpUGraphCopy
  1552   template <typename Target, typename Source>
  1561   template <typename To, typename From>
  1553   BpUGraphCopy<Target, Source> 
  1562   BpUGraphCopy<To, From> 
  1554   copyBpUGraph(Target& target, const Source& source) {
  1563   copyBpUGraph(To& to, const From& from) {
  1555     return BpUGraphCopy<Target, Source>(target, source);
  1564     return BpUGraphCopy<To, From>(to, from);
  1556   }
  1565   }
  1557 
  1566 
  1558 
  1567 
  1559   /// @}
  1568   /// @}
  1560 
  1569