Changeset 2290:f30867b359a8 in lemon0.x
 Timestamp:
 11/03/06 15:20:24 (14 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@3055
 Files:

 1 added
 4 edited
Legend:
 Unmodified
 Added
 Removed

lemon/bits/graph_extender.h
r2283 r2290 283 283 } 284 284 285 template <typename Graph, typename NodeRefMap, typename EdgeRefMap> 286 void clone(const Graph& graph, NodeRefMap& nodeRef, EdgeRefMap& edgeRef) { 287 Parent::clone(graph, nodeRef, edgeRef); 288 getNotifier(Node()).build(); 289 getNotifier(Edge()).build(); 290 } 285 291 286 292 void erase(const Node& node) { … … 686 692 getNotifier(Node()).clear(); 687 693 Parent::clear(); 694 } 695 696 template <typename Graph, typename NodeRefMap, typename UEdgeRefMap> 697 void clone(const Graph& graph, NodeRefMap& nodeRef, 698 UEdgeRefMap& uEdgeRef) { 699 Parent::clone(graph, nodeRef, uEdgeRef); 700 getNotifier(Node()).build(); 701 getNotifier(UEdge()).build(); 702 getNotifier(Edge()).build(); 688 703 } 689 704 … … 1302 1317 } 1303 1318 1319 template <typename Graph, typename ANodeRefMap, 1320 typename BNodeRefMap, typename UEdgeRefMap> 1321 void clone(const Graph& graph, ANodeRefMap& aNodeRef, 1322 BNodeRefMap& bNodeRef, UEdgeRefMap& uEdgeRef) { 1323 Parent::clone(graph, aNodeRef, bNodeRef, uEdgeRef); 1324 getNotifier(ANode()).build(); 1325 getNotifier(BNode()).build(); 1326 getNotifier(Node()).build(); 1327 getNotifier(UEdge()).build(); 1328 getNotifier(Edge()).build(); 1329 } 1330 1304 1331 void erase(const Node& node) { 1305 1332 UEdge uedge; 
lemon/bits/traits.h
r2039 r2290 324 324 }; 325 325 326 326 template <typename Graph, typename Enable = void> 327 struct CloneableTagIndicator { 328 static const bool value = false; 329 }; 330 331 template <typename Graph> 332 struct CloneableTagIndicator< 333 Graph, 334 typename enable_if<typename Graph::CloneableTag, void>::type 335 > { 336 static const bool value = true; 337 }; 327 338 328 339 } 
lemon/graph_utils.h
r2287 r2290 616 616 }; 617 617 618 template <typename Graph, typename Item, typename RefMap, typename It> 619 class ItemCopy : public MapCopyBase<Graph, Item, RefMap> { 620 public: 621 622 ItemCopy(It& it, const Item& item) : _it(it), _item(item) {} 623 624 virtual void copy(const Graph&, const RefMap& refMap) { 625 _it = refMap[_item]; 626 } 627 628 private: 629 It& _it; 630 Item _item; 631 }; 632 618 633 template <typename Graph, typename Item, typename RefMap, typename Ref> 619 634 class RefCopy : public MapCopyBase<Graph, Item, RefMap> { … … 651 666 }; 652 667 668 template <typename Graph, typename Enable = void> 669 struct GraphCopySelector { 670 template <typename Source, typename NodeRefMap, typename EdgeRefMap> 671 static void copy(Graph &target, const Source& source, 672 NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { 673 for (typename Source::NodeIt it(source); it != INVALID; ++it) { 674 nodeRefMap[it] = target.addNode(); 675 } 676 for (typename Source::EdgeIt it(source); it != INVALID; ++it) { 677 edgeRefMap[it] = target.addEdge(nodeRefMap[source.source(it)], 678 nodeRefMap[source.target(it)]); 679 } 680 } 681 }; 682 683 template <typename Graph> 684 struct GraphCopySelector< 685 Graph, 686 typename enable_if<typename Graph::CloneableTag, void>::type> 687 { 688 template <typename Source, typename NodeRefMap, typename EdgeRefMap> 689 static void copy(Graph &target, const Source& source, 690 NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { 691 target.clone(source, nodeRefMap, edgeRefMap); 692 } 693 }; 694 695 template <typename UGraph, typename Enable = void> 696 struct UGraphCopySelector { 697 template <typename Source, typename NodeRefMap, typename UEdgeRefMap> 698 static void copy(UGraph &target, const Source& source, 699 NodeRefMap& nodeRefMap, UEdgeRefMap& uEdgeRefMap) { 700 for (typename Source::NodeIt it(source); it != INVALID; ++it) { 701 nodeRefMap[it] = target.addNode(); 702 } 703 for (typename Source::UEdgeIt it(source); it != INVALID; ++it) { 704 uEdgeRefMap[it] = target.addEdge(nodeRefMap[source.source(it)], 705 nodeRefMap[source.target(it)]); 706 } 707 } 708 }; 709 710 template <typename UGraph> 711 struct UGraphCopySelector< 712 UGraph, 713 typename enable_if<typename UGraph::CloneableTag, void>::type> 714 { 715 template <typename Source, typename NodeRefMap, typename UEdgeRefMap> 716 static void copy(UGraph &target, const Source& source, 717 NodeRefMap& nodeRefMap, UEdgeRefMap& uEdgeRefMap) { 718 target.clone(source, nodeRefMap, uEdgeRefMap); 719 } 720 }; 721 722 template <typename BpUGraph, typename Enable = void> 723 struct BpUGraphCopySelector { 724 template <typename Source, typename ANodeRefMap, 725 typename BNodeRefMap, typename UEdgeRefMap> 726 static void copy(BpUGraph &target, const Source& source, 727 ANodeRefMap& aNodeRefMap, BNodeRefMap& bNodeRefMap, 728 UEdgeRefMap& uEdgeRefMap) { 729 for (typename Source::ANodeIt it(source); it != INVALID; ++it) { 730 aNodeRefMap[it] = target.addANode(); 731 } 732 for (typename Source::BNodeIt it(source); it != INVALID; ++it) { 733 bNodeRefMap[it] = target.addBNode(); 734 } 735 for (typename Source::UEdgeIt it(source); it != INVALID; ++it) { 736 uEdgeRefMap[it] = target.addEdge(aNodeRefMap[source.aNode(it)], 737 bNodeRefMap[source.bNode(it)]); 738 } 739 } 740 }; 741 742 template <typename BpUGraph> 743 struct BpUGraphCopySelector< 744 BpUGraph, 745 typename enable_if<typename BpUGraph::CloneableTag, void>::type> 746 { 747 template <typename Source, typename ANodeRefMap, 748 typename BNodeRefMap, typename UEdgeRefMap> 749 static void copy(BpUGraph &target, const Source& source, 750 ANodeRefMap& aNodeRefMap, BNodeRefMap& bNodeRefMap, 751 UEdgeRefMap& uEdgeRefMap) { 752 target.clone(source, aNodeRefMap, bNodeRefMap, uEdgeRefMap); 753 } 754 }; 755 756 653 757 } 654 758 … … 706 810 } 707 811 708 /// \brief Reverse and copies the node references into the given map. 709 /// 710 /// Reverse and copies the node references into the given map. 812 /// \brief Copies the node cross references into the given map. 813 /// 814 /// Copies the node cross references (reverse references) into 815 /// the given map. 711 816 template <typename NodeCrossRef> 712 817 GraphCopy& nodeCrossRef(NodeCrossRef& map) { … … 729 834 } 730 835 836 /// \brief Make a copy of the given node. 837 /// 838 /// Make a copy of the given node. 839 GraphCopy& node(TNode& tnode, const Node& node) { 840 nodeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, Node, 841 NodeRefMap, TNode>(tnode, node)); 842 return *this; 843 } 844 731 845 /// \brief Copies the edge references into the given map. 732 846 /// … … 739 853 } 740 854 741 /// \brief Reverse and copies the edge references into the given map. 742 /// 743 /// Reverse and copies the edge references into the given map. 855 /// \brief Copies the edge cross references into the given map. 856 /// 857 /// Copies the edge cross references (reverse references) into 858 /// the given map. 744 859 template <typename EdgeCrossRef> 745 860 GraphCopy& edgeCrossRef(EdgeCrossRef& map) { … … 762 877 } 763 878 879 /// \brief Make a copy of the given edge. 880 /// 881 /// Make a copy of the given edge. 882 GraphCopy& edge(TEdge& tedge, const Edge& edge) { 883 edgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, Edge, 884 EdgeRefMap, TEdge>(tedge, edge)); 885 return *this; 886 } 887 764 888 /// \brief Executes the copies. 765 889 /// … … 767 891 void run() { 768 892 NodeRefMap nodeRefMap(source); 769 for (NodeIt it(source); it != INVALID; ++it) {770 nodeRefMap[it] = target.addNode(); 771 }893 EdgeRefMap edgeRefMap(source); 894 _graph_utils_bits::GraphCopySelector<Target>:: 895 copy(target, source, nodeRefMap, edgeRefMap); 772 896 for (int i = 0; i < (int)nodeMapCopies.size(); ++i) { 773 897 nodeMapCopies[i]>copy(source, nodeRefMap); 774 898 } 775 EdgeRefMap edgeRefMap(source);776 for (EdgeIt it(source); it != INVALID; ++it) {777 edgeRefMap[it] = target.addEdge(nodeRefMap[source.source(it)],778 nodeRefMap[source.target(it)]);779 }780 899 for (int i = 0; i < (int)edgeMapCopies.size(); ++i) { 781 900 edgeMapCopies[i]>copy(source, edgeRefMap); 782 } 783 } 784 785 private: 786 901 } 902 } 903 904 protected: 905 906 787 907 const Source& source; 788 908 Target& target; … … 809 929 /// contain the mapping from the target graph's edges to the source's 810 930 /// edges. 931 /// 932 /// \see GraphCopy 811 933 template <typename Target, typename Source> 812 934 GraphCopy<Target, Source> copyGraph(Target& target, const Source& source) { … … 895 1017 } 896 1018 897 /// \brief Reverse and copies the node references into the given map. 898 /// 899 /// Reverse and copies the node references into the given map. 1019 /// \brief Copies the node cross references into the given map. 1020 /// 1021 /// Copies the node cross references (reverse references) into 1022 /// the given map. 900 1023 template <typename NodeCrossRef> 901 1024 UGraphCopy& nodeCrossRef(NodeCrossRef& map) { … … 918 1041 } 919 1042 1043 /// \brief Make a copy of the given node. 1044 /// 1045 /// Make a copy of the given node. 1046 UGraphCopy& node(TNode& tnode, const Node& node) { 1047 nodeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, Node, 1048 NodeRefMap, TNode>(tnode, node)); 1049 return *this; 1050 } 1051 920 1052 /// \brief Copies the edge references into the given map. 921 1053 /// … … 928 1060 } 929 1061 930 /// \brief Reverse and copies the edge references into the given map. 931 /// 932 /// Reverse and copies the edge references into the given map. 1062 /// \brief Copies the edge cross references into the given map. 1063 /// 1064 /// Copies the edge cross references (reverse references) into 1065 /// the given map. 933 1066 template <typename EdgeCrossRef> 934 1067 UGraphCopy& edgeCrossRef(EdgeCrossRef& map) { … … 951 1084 } 952 1085 953 /// \brief Copies the uEdge references into the given map. 954 /// 955 /// Copies the uEdge references into the given map. 1086 /// \brief Make a copy of the given edge. 1087 /// 1088 /// Make a copy of the given edge. 1089 UGraphCopy& edge(TEdge& tedge, const Edge& edge) { 1090 edgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, Edge, 1091 EdgeRefMap, TEdge>(tedge, edge)); 1092 return *this; 1093 } 1094 1095 /// \brief Copies the undirected edge references into the given map. 1096 /// 1097 /// Copies the undirected edge references into the given map. 956 1098 template <typename UEdgeRef> 957 1099 UGraphCopy& uEdgeRef(UEdgeRef& map) { … … 961 1103 } 962 1104 963 /// \brief Reverse and copies the uEdge references into the given map. 964 /// 965 /// Reverse and copies the uEdge references into the given map. 1105 /// \brief Copies the undirected edge cross references into the given map. 1106 /// 1107 /// Copies the undirected edge cross references (reverse 1108 /// references) into the given map. 966 1109 template <typename UEdgeCrossRef> 967 1110 UGraphCopy& uEdgeCrossRef(UEdgeCrossRef& map) { … … 974 1117 /// 975 1118 /// Makes copy of the given map for the newly created graph. 976 /// The new map's key type is the target graph's u Edge type,977 /// and the copied map's key type is the source graph's u Edge1119 /// The new map's key type is the target graph's undirected edge type, 1120 /// and the copied map's key type is the source graph's undirected edge 978 1121 /// type. 979 1122 template <typename TargetMap, typename SourceMap> … … 984 1127 } 985 1128 1129 /// \brief Make a copy of the given undirected edge. 1130 /// 1131 /// Make a copy of the given undirected edge. 1132 UGraphCopy& uEdge(TUEdge& tuedge, const UEdge& uedge) { 1133 uEdgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, UEdge, 1134 UEdgeRefMap, TUEdge>(tuedge, uedge)); 1135 return *this; 1136 } 1137 986 1138 /// \brief Executes the copies. 987 1139 /// … … 989 1141 void run() { 990 1142 NodeRefMap nodeRefMap(source); 991 for (NodeIt it(source); it != INVALID; ++it) { 992 nodeRefMap[it] = target.addNode(); 993 } 1143 UEdgeRefMap uEdgeRefMap(source); 1144 EdgeRefMap edgeRefMap(target, source, uEdgeRefMap, nodeRefMap); 1145 _graph_utils_bits::UGraphCopySelector<Target>:: 1146 copy(target, source, nodeRefMap, uEdgeRefMap); 994 1147 for (int i = 0; i < (int)nodeMapCopies.size(); ++i) { 995 1148 nodeMapCopies[i]>copy(source, nodeRefMap); 996 1149 } 997 UEdgeRefMap uEdgeRefMap(source);998 EdgeRefMap edgeRefMap(target, source, uEdgeRefMap, nodeRefMap);999 for (UEdgeIt it(source); it != INVALID; ++it) {1000 uEdgeRefMap[it] = target.addEdge(nodeRefMap[source.source(it)],1001 nodeRefMap[source.target(it)]);1002 }1003 1150 for (int i = 0; i < (int)uEdgeMapCopies.size(); ++i) { 1004 1151 uEdgeMapCopies[i]>copy(source, uEdgeRefMap); … … 1025 1172 }; 1026 1173 1027 /// \brief Copy a graph to another graph.1028 /// 1029 /// Copy a graph to another graph.1174 /// \brief Copy an undirected graph to another graph. 1175 /// 1176 /// Copy an undirected graph to another graph. 1030 1177 /// The usage of the function: 1031 1178 /// … … 1038 1185 /// contain the mapping from the target graph's edges to the source's 1039 1186 /// edges. 1187 /// 1188 /// \see UGraphCopy 1040 1189 template <typename Target, typename Source> 1041 1190 UGraphCopy<Target, Source> 1042 1191 copyUGraph(Target& target, const Source& source) { 1043 1192 return UGraphCopy<Target, Source>(target, source); 1193 } 1194 1195 /// \brief Class to copy a bipartite undirected graph. 1196 /// 1197 /// Class to copy a bipartite undirected graph to another graph 1198 /// (duplicate a graph). The simplest way of using it is through 1199 /// the \c copyBpUGraph() function. 1200 template <typename Target, typename Source> 1201 class BpUGraphCopy { 1202 private: 1203 1204 typedef typename Source::Node Node; 1205 typedef typename Source::ANode ANode; 1206 typedef typename Source::BNode BNode; 1207 typedef typename Source::NodeIt NodeIt; 1208 typedef typename Source::Edge Edge; 1209 typedef typename Source::EdgeIt EdgeIt; 1210 typedef typename Source::UEdge UEdge; 1211 typedef typename Source::UEdgeIt UEdgeIt; 1212 1213 typedef typename Target::Node TNode; 1214 typedef typename Target::Edge TEdge; 1215 typedef typename Target::UEdge TUEdge; 1216 1217 typedef typename Source::template ANodeMap<TNode> ANodeRefMap; 1218 typedef typename Source::template BNodeMap<TNode> BNodeRefMap; 1219 typedef typename Source::template UEdgeMap<TUEdge> UEdgeRefMap; 1220 1221 struct NodeRefMap { 1222 NodeRefMap(const Source& _source, const ANodeRefMap& _anode_ref, 1223 const BNodeRefMap& _bnode_ref) 1224 : source(_source), anode_ref(_anode_ref), bnode_ref(_bnode_ref) {} 1225 1226 typedef typename Source::Node Key; 1227 typedef typename Target::Node Value; 1228 1229 Value operator[](const Key& key) const { 1230 return source.aNode(key) ? anode_ref[key] : bnode_ref[key]; 1231 } 1232 1233 const Source& source; 1234 const ANodeRefMap& anode_ref; 1235 const BNodeRefMap& bnode_ref; 1236 }; 1237 1238 struct EdgeRefMap { 1239 EdgeRefMap(const Target& _target, const Source& _source, 1240 const UEdgeRefMap& _uedge_ref, const NodeRefMap& _node_ref) 1241 : target(_target), source(_source), 1242 uedge_ref(_uedge_ref), node_ref(_node_ref) {} 1243 1244 typedef typename Source::Edge Key; 1245 typedef typename Target::Edge Value; 1246 1247 Value operator[](const Key& key) const { 1248 bool forward = (source.direction(key) == 1249 (node_ref[source.source((UEdge)key)] == 1250 target.source(uedge_ref[(UEdge)key]))); 1251 return target.direct(uedge_ref[key], forward); 1252 } 1253 1254 const Target& target; 1255 const Source& source; 1256 const UEdgeRefMap& uedge_ref; 1257 const NodeRefMap& node_ref; 1258 }; 1259 1260 public: 1261 1262 1263 /// \brief Constructor for the GraphCopy. 1264 /// 1265 /// It copies the content of the \c _source graph into the 1266 /// \c _target graph. 1267 BpUGraphCopy(Target& _target, const Source& _source) 1268 : source(_source), target(_target) {} 1269 1270 /// \brief Destructor of the GraphCopy 1271 /// 1272 /// Destructor of the GraphCopy 1273 ~BpUGraphCopy() { 1274 for (int i = 0; i < (int)aNodeMapCopies.size(); ++i) { 1275 delete aNodeMapCopies[i]; 1276 } 1277 for (int i = 0; i < (int)bNodeMapCopies.size(); ++i) { 1278 delete bNodeMapCopies[i]; 1279 } 1280 for (int i = 0; i < (int)nodeMapCopies.size(); ++i) { 1281 delete nodeMapCopies[i]; 1282 } 1283 for (int i = 0; i < (int)edgeMapCopies.size(); ++i) { 1284 delete edgeMapCopies[i]; 1285 } 1286 for (int i = 0; i < (int)uEdgeMapCopies.size(); ++i) { 1287 delete uEdgeMapCopies[i]; 1288 } 1289 1290 } 1291 1292 /// \brief Copies the Anode references into the given map. 1293 /// 1294 /// Copies the Anode references into the given map. 1295 template <typename ANodeRef> 1296 BpUGraphCopy& aNodeRef(ANodeRef& map) { 1297 aNodeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, ANode, 1298 ANodeRefMap, ANodeRef>(map)); 1299 return *this; 1300 } 1301 1302 /// \brief Copies the Anode cross references into the given map. 1303 /// 1304 /// Copies the Anode cross references (reverse references) into 1305 /// the given map. 1306 template <typename ANodeCrossRef> 1307 BpUGraphCopy& aNodeCrossRef(ANodeCrossRef& map) { 1308 aNodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, 1309 ANode, ANodeRefMap, ANodeCrossRef>(map)); 1310 return *this; 1311 } 1312 1313 /// \brief Make copy of the given Anode map. 1314 /// 1315 /// Makes copy of the given map for the newly created graph. 1316 /// The new map's key type is the target graph's node type, 1317 /// and the copied map's key type is the source graph's node 1318 /// type. 1319 template <typename TargetMap, typename SourceMap> 1320 BpUGraphCopy& aNodeMap(TargetMap& tmap, const SourceMap& map) { 1321 aNodeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, ANode, 1322 ANodeRefMap, TargetMap, SourceMap>(tmap, map)); 1323 return *this; 1324 } 1325 1326 /// \brief Copies the Bnode references into the given map. 1327 /// 1328 /// Copies the Bnode references into the given map. 1329 template <typename BNodeRef> 1330 BpUGraphCopy& bNodeRef(BNodeRef& map) { 1331 bNodeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, BNode, 1332 BNodeRefMap, BNodeRef>(map)); 1333 return *this; 1334 } 1335 1336 /// \brief Copies the Bnode cross references into the given map. 1337 /// 1338 /// Copies the Bnode cross references (reverse references) into 1339 /// the given map. 1340 template <typename BNodeCrossRef> 1341 BpUGraphCopy& bNodeCrossRef(BNodeCrossRef& map) { 1342 bNodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, 1343 BNode, BNodeRefMap, BNodeCrossRef>(map)); 1344 return *this; 1345 } 1346 1347 /// \brief Make copy of the given Bnode map. 1348 /// 1349 /// Makes copy of the given map for the newly created graph. 1350 /// The new map's key type is the target graph's node type, 1351 /// and the copied map's key type is the source graph's node 1352 /// type. 1353 template <typename TargetMap, typename SourceMap> 1354 BpUGraphCopy& bNodeMap(TargetMap& tmap, const SourceMap& map) { 1355 bNodeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, BNode, 1356 BNodeRefMap, TargetMap, SourceMap>(tmap, map)); 1357 return *this; 1358 } 1359 /// \brief Copies the node references into the given map. 1360 /// 1361 /// Copies the node references into the given map. 1362 template <typename NodeRef> 1363 BpUGraphCopy& nodeRef(NodeRef& map) { 1364 nodeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, Node, 1365 NodeRefMap, NodeRef>(map)); 1366 return *this; 1367 } 1368 1369 /// \brief Copies the node cross references into the given map. 1370 /// 1371 /// Copies the node cross references (reverse references) into 1372 /// the given map. 1373 template <typename NodeCrossRef> 1374 BpUGraphCopy& nodeCrossRef(NodeCrossRef& map) { 1375 nodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, Node, 1376 NodeRefMap, NodeCrossRef>(map)); 1377 return *this; 1378 } 1379 1380 /// \brief Make copy of the given map. 1381 /// 1382 /// Makes copy of the given map for the newly created graph. 1383 /// The new map's key type is the target graph's node type, 1384 /// and the copied map's key type is the source graph's node 1385 /// type. 1386 template <typename TargetMap, typename SourceMap> 1387 BpUGraphCopy& nodeMap(TargetMap& tmap, const SourceMap& map) { 1388 nodeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, Node, 1389 NodeRefMap, TargetMap, SourceMap>(tmap, map)); 1390 return *this; 1391 } 1392 1393 /// \brief Make a copy of the given node. 1394 /// 1395 /// Make a copy of the given node. 1396 BpUGraphCopy& node(TNode& tnode, const Node& node) { 1397 nodeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, Node, 1398 NodeRefMap, TNode>(tnode, node)); 1399 return *this; 1400 } 1401 1402 /// \brief Copies the edge references into the given map. 1403 /// 1404 /// Copies the edge references into the given map. 1405 template <typename EdgeRef> 1406 BpUGraphCopy& edgeRef(EdgeRef& map) { 1407 edgeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, Edge, 1408 EdgeRefMap, EdgeRef>(map)); 1409 return *this; 1410 } 1411 1412 /// \brief Copies the edge cross references into the given map. 1413 /// 1414 /// Copies the edge cross references (reverse references) into 1415 /// the given map. 1416 template <typename EdgeCrossRef> 1417 BpUGraphCopy& edgeCrossRef(EdgeCrossRef& map) { 1418 edgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, Edge, 1419 EdgeRefMap, EdgeCrossRef>(map)); 1420 return *this; 1421 } 1422 1423 /// \brief Make copy of the given map. 1424 /// 1425 /// Makes copy of the given map for the newly created graph. 1426 /// The new map's key type is the target graph's edge type, 1427 /// and the copied map's key type is the source graph's edge 1428 /// type. 1429 template <typename TargetMap, typename SourceMap> 1430 BpUGraphCopy& edgeMap(TargetMap& tmap, const SourceMap& map) { 1431 edgeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, Edge, 1432 EdgeRefMap, TargetMap, SourceMap>(tmap, map)); 1433 return *this; 1434 } 1435 1436 /// \brief Make a copy of the given edge. 1437 /// 1438 /// Make a copy of the given edge. 1439 BpUGraphCopy& edge(TEdge& tedge, const Edge& edge) { 1440 edgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, Edge, 1441 EdgeRefMap, TEdge>(tedge, edge)); 1442 return *this; 1443 } 1444 1445 /// \brief Copies the undirected edge references into the given map. 1446 /// 1447 /// Copies the undirected edge references into the given map. 1448 template <typename UEdgeRef> 1449 BpUGraphCopy& uEdgeRef(UEdgeRef& map) { 1450 uEdgeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, UEdge, 1451 UEdgeRefMap, UEdgeRef>(map)); 1452 return *this; 1453 } 1454 1455 /// \brief Copies the undirected edge cross references into the given map. 1456 /// 1457 /// Copies the undirected edge cross references (reverse 1458 /// references) into the given map. 1459 template <typename UEdgeCrossRef> 1460 BpUGraphCopy& uEdgeCrossRef(UEdgeCrossRef& map) { 1461 uEdgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, 1462 UEdge, UEdgeRefMap, UEdgeCrossRef>(map)); 1463 return *this; 1464 } 1465 1466 /// \brief Make copy of the given map. 1467 /// 1468 /// Makes copy of the given map for the newly created graph. 1469 /// The new map's key type is the target graph's undirected edge type, 1470 /// and the copied map's key type is the source graph's undirected edge 1471 /// type. 1472 template <typename TargetMap, typename SourceMap> 1473 BpUGraphCopy& uEdgeMap(TargetMap& tmap, const SourceMap& map) { 1474 uEdgeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, UEdge, 1475 UEdgeRefMap, TargetMap, SourceMap>(tmap, map)); 1476 return *this; 1477 } 1478 1479 /// \brief Make a copy of the given undirected edge. 1480 /// 1481 /// Make a copy of the given undirected edge. 1482 BpUGraphCopy& uEdge(TUEdge& tuedge, const UEdge& uedge) { 1483 uEdgeMapCopies.push_back(new _graph_utils_bits::ItemCopy<Source, UEdge, 1484 UEdgeRefMap, TUEdge>(tuedge, uedge)); 1485 return *this; 1486 } 1487 1488 /// \brief Executes the copies. 1489 /// 1490 /// Executes the copies. 1491 void run() { 1492 ANodeRefMap aNodeRefMap(source); 1493 BNodeRefMap bNodeRefMap(source); 1494 NodeRefMap nodeRefMap(source, aNodeRefMap, bNodeRefMap); 1495 UEdgeRefMap uEdgeRefMap(source); 1496 EdgeRefMap edgeRefMap(target, source, uEdgeRefMap, nodeRefMap); 1497 _graph_utils_bits::BpUGraphCopySelector<Target>:: 1498 copy(target, source, aNodeRefMap, bNodeRefMap, uEdgeRefMap); 1499 for (int i = 0; i < (int)aNodeMapCopies.size(); ++i) { 1500 aNodeMapCopies[i]>copy(source, aNodeRefMap); 1501 } 1502 for (int i = 0; i < (int)bNodeMapCopies.size(); ++i) { 1503 bNodeMapCopies[i]>copy(source, bNodeRefMap); 1504 } 1505 for (int i = 0; i < (int)nodeMapCopies.size(); ++i) { 1506 nodeMapCopies[i]>copy(source, nodeRefMap); 1507 } 1508 for (int i = 0; i < (int)uEdgeMapCopies.size(); ++i) { 1509 uEdgeMapCopies[i]>copy(source, uEdgeRefMap); 1510 } 1511 for (int i = 0; i < (int)edgeMapCopies.size(); ++i) { 1512 edgeMapCopies[i]>copy(source, edgeRefMap); 1513 } 1514 } 1515 1516 private: 1517 1518 const Source& source; 1519 Target& target; 1520 1521 std::vector<_graph_utils_bits::MapCopyBase<Source, ANode, ANodeRefMap>* > 1522 aNodeMapCopies; 1523 1524 std::vector<_graph_utils_bits::MapCopyBase<Source, BNode, BNodeRefMap>* > 1525 bNodeMapCopies; 1526 1527 std::vector<_graph_utils_bits::MapCopyBase<Source, Node, NodeRefMap>* > 1528 nodeMapCopies; 1529 1530 std::vector<_graph_utils_bits::MapCopyBase<Source, Edge, EdgeRefMap>* > 1531 edgeMapCopies; 1532 1533 std::vector<_graph_utils_bits::MapCopyBase<Source, UEdge, UEdgeRefMap>* > 1534 uEdgeMapCopies; 1535 1536 }; 1537 1538 /// \brief Copy a bipartite undirected graph to another graph. 1539 /// 1540 /// Copy a bipartite undirected graph to another graph. 1541 /// The usage of the function: 1542 /// 1543 ///\code 1544 /// copyBpUGraph(trg, src).aNodeRef(anr).edgeCrossRef(ecr).run(); 1545 ///\endcode 1546 /// 1547 /// After the copy the \c nr map will contain the mapping from the 1548 /// source graph's nodes to the target graph's nodes and the \c ecr will 1549 /// contain the mapping from the target graph's edges to the source's 1550 /// edges. 1551 /// 1552 /// \see BpUGraphCopy 1553 template <typename Target, typename Source> 1554 BpUGraphCopy<Target, Source> 1555 copyBpUGraph(Target& target, const Source& source) { 1556 return BpUGraphCopy<Target, Source>(target, source); 1044 1557 } 1045 1558 
test/Makefile.am
r2231 r2290 23 23 test/edge_set_test \ 24 24 test/graph_adaptor_test \ 25 test/graph_copy_test \ 25 26 test/graph_test \ 26 27 test/graph_utils_test \ … … 66 67 test_edge_set_test_SOURCES = test/edge_set_test.cc 67 68 test_graph_adaptor_test_SOURCES = test/graph_adaptor_test.cc 69 test_graph_copy_test_SOURCES = test/graph_copy_test.cc 68 70 test_graph_test_SOURCES = test/graph_test.cc 69 71 test_graph_utils_test_SOURCES = test/graph_utils_test.cc
Note: See TracChangeset
for help on using the changeset viewer.