Changes in lemon/core.h [1159:7fdaa05a69a1:1341:c199e9976d93] in lemon
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/core.h
r1159 r1341 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 2003-201 05 * Copyright (C) 2003-2013 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 20 20 #define LEMON_CORE_H 21 21 22 #include <vector>23 #include <algorithm>24 25 #include <lemon/config.h>26 #include <lemon/bits/enable_if.h>27 #include <lemon/bits/traits.h>28 #include <lemon/assert.h>29 30 // Disable the following warnings when compiling with MSVC:31 // C4250: 'class1' : inherits 'class2::member' via dominance32 // C4355: 'this' : used in base member initializer list33 // C4503: 'function' : decorated name length exceeded, name was truncated34 // C4800: 'type' : forcing value to bool 'true' or 'false' (performance warning)35 // C4996: 'function': was declared deprecated36 #ifdef _MSC_VER37 #pragma warning( disable : 4250 4355 4503 4800 4996 )38 #endif39 40 22 ///\file 41 23 ///\brief LEMON core utilities. … … 44 26 ///It is automatically included by all graph types, therefore it usually 45 27 ///do not have to be included directly. 28 29 // Disable the following warnings when compiling with MSVC: 30 // C4250: 'class1' : inherits 'class2::member' via dominance 31 // C4267: conversion from 'size_t' to 'type', possible loss of data 32 // C4355: 'this' : used in base member initializer list 33 // C4503: 'function' : decorated name length exceeded, name was truncated 34 // C4800: 'type' : forcing value to bool 'true' or 'false' (performance warning) 35 // C4996: 'function': was declared deprecated 36 #ifdef _MSC_VER 37 #pragma warning( disable : 4250 4267 4355 4503 4800 4996 ) 38 #endif 39 40 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) 41 // Needed by the [DI]GRAPH_TYPEDEFS marcos for gcc 4.8 42 #pragma GCC diagnostic ignored "-Wunused-local-typedefs" 43 #endif 44 45 #include <vector> 46 #include <algorithm> 47 48 #include <lemon/config.h> 49 #include <lemon/bits/enable_if.h> 50 #include <lemon/bits/traits.h> 51 #include <lemon/assert.h> 52 53 46 54 47 55 namespace lemon { … … 149 157 typedef typename Graph::template EdgeMap<double> DoubleEdgeMap 150 158 159 ///Create convenience typedefs for the bipartite graph types and iterators 160 161 ///This \c \#define creates the same convenient type definitions as 162 ///defined by \ref GRAPH_TYPEDEFS(BpGraph) and ten more, namely it 163 ///creates \c RedNode, \c RedNodeIt, \c BoolRedNodeMap, 164 ///\c IntRedNodeMap, \c DoubleRedNodeMap, \c BlueNode, \c BlueNodeIt, 165 ///\c BoolBlueNodeMap, \c IntBlueNodeMap, \c DoubleBlueNodeMap. 166 /// 167 ///\note If the graph type is a dependent type, ie. the graph type depend 168 ///on a template parameter, then use \c TEMPLATE_BPGRAPH_TYPEDEFS() 169 ///macro. 170 #define BPGRAPH_TYPEDEFS(BpGraph) \ 171 GRAPH_TYPEDEFS(BpGraph); \ 172 typedef BpGraph::RedNode RedNode; \ 173 typedef BpGraph::RedNodeIt RedNodeIt; \ 174 typedef BpGraph::RedNodeMap<bool> BoolRedNodeMap; \ 175 typedef BpGraph::RedNodeMap<int> IntRedNodeMap; \ 176 typedef BpGraph::RedNodeMap<double> DoubleRedNodeMap; \ 177 typedef BpGraph::BlueNode BlueNode; \ 178 typedef BpGraph::BlueNodeIt BlueNodeIt; \ 179 typedef BpGraph::BlueNodeMap<bool> BoolBlueNodeMap; \ 180 typedef BpGraph::BlueNodeMap<int> IntBlueNodeMap; \ 181 typedef BpGraph::BlueNodeMap<double> DoubleBlueNodeMap 182 183 ///Create convenience typedefs for the bipartite graph types and iterators 184 185 ///\see BPGRAPH_TYPEDEFS 186 /// 187 ///\note Use this macro, if the graph type is a dependent type, 188 ///ie. the graph type depend on a template parameter. 189 #define TEMPLATE_BPGRAPH_TYPEDEFS(BpGraph) \ 190 TEMPLATE_GRAPH_TYPEDEFS(BpGraph); \ 191 typedef typename BpGraph::RedNode RedNode; \ 192 typedef typename BpGraph::RedNodeIt RedNodeIt; \ 193 typedef typename BpGraph::template RedNodeMap<bool> BoolRedNodeMap; \ 194 typedef typename BpGraph::template RedNodeMap<int> IntRedNodeMap; \ 195 typedef typename BpGraph::template RedNodeMap<double> DoubleRedNodeMap; \ 196 typedef typename BpGraph::BlueNode BlueNode; \ 197 typedef typename BpGraph::BlueNodeIt BlueNodeIt; \ 198 typedef typename BpGraph::template BlueNodeMap<bool> BoolBlueNodeMap; \ 199 typedef typename BpGraph::template BlueNodeMap<int> IntBlueNodeMap; \ 200 typedef typename BpGraph::template BlueNodeMap<double> DoubleBlueNodeMap 201 151 202 /// \brief Function to count the items in a graph. 152 203 /// … … 200 251 } 201 252 253 namespace _graph_utils_bits { 254 255 template <typename Graph, typename Enable = void> 256 struct CountRedNodesSelector { 257 static int count(const Graph &g) { 258 return countItems<Graph, typename Graph::RedNode>(g); 259 } 260 }; 261 262 template <typename Graph> 263 struct CountRedNodesSelector< 264 Graph, typename 265 enable_if<typename Graph::NodeNumTag, void>::type> 266 { 267 static int count(const Graph &g) { 268 return g.redNum(); 269 } 270 }; 271 } 272 273 /// \brief Function to count the red nodes in the graph. 274 /// 275 /// This function counts the red nodes in the graph. 276 /// The complexity of the function is O(n) but for some 277 /// graph structures it is specialized to run in O(1). 278 /// 279 /// If the graph contains a \e redNum() member function and a 280 /// \e NodeNumTag tag then this function calls directly the member 281 /// function to query the cardinality of the node set. 282 template <typename Graph> 283 inline int countRedNodes(const Graph& g) { 284 return _graph_utils_bits::CountRedNodesSelector<Graph>::count(g); 285 } 286 287 namespace _graph_utils_bits { 288 289 template <typename Graph, typename Enable = void> 290 struct CountBlueNodesSelector { 291 static int count(const Graph &g) { 292 return countItems<Graph, typename Graph::BlueNode>(g); 293 } 294 }; 295 296 template <typename Graph> 297 struct CountBlueNodesSelector< 298 Graph, typename 299 enable_if<typename Graph::NodeNumTag, void>::type> 300 { 301 static int count(const Graph &g) { 302 return g.blueNum(); 303 } 304 }; 305 } 306 307 /// \brief Function to count the blue nodes in the graph. 308 /// 309 /// This function counts the blue nodes in the graph. 310 /// The complexity of the function is O(n) but for some 311 /// graph structures it is specialized to run in O(1). 312 /// 313 /// If the graph contains a \e blueNum() member function and a 314 /// \e NodeNumTag tag then this function calls directly the member 315 /// function to query the cardinality of the node set. 316 template <typename Graph> 317 inline int countBlueNodes(const Graph& g) { 318 return _graph_utils_bits::CountBlueNodesSelector<Graph>::count(g); 319 } 320 202 321 // Arc counting: 203 322 … … 441 560 template <typename From, typename NodeRefMap, typename EdgeRefMap> 442 561 static void copy(const From& from, Graph &to, 443 NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) { 562 NodeRefMap& nodeRefMap, 563 EdgeRefMap& edgeRefMap) { 444 564 to.build(from, nodeRefMap, edgeRefMap); 445 565 } 446 566 }; 447 567 568 template <typename BpGraph, typename Enable = void> 569 struct BpGraphCopySelector { 570 template <typename From, typename RedNodeRefMap, 571 typename BlueNodeRefMap, typename EdgeRefMap> 572 static void copy(const From& from, BpGraph &to, 573 RedNodeRefMap& redNodeRefMap, 574 BlueNodeRefMap& blueNodeRefMap, 575 EdgeRefMap& edgeRefMap) { 576 to.clear(); 577 for (typename From::RedNodeIt it(from); it != INVALID; ++it) { 578 redNodeRefMap[it] = to.addRedNode(); 579 } 580 for (typename From::BlueNodeIt it(from); it != INVALID; ++it) { 581 blueNodeRefMap[it] = to.addBlueNode(); 582 } 583 for (typename From::EdgeIt it(from); it != INVALID; ++it) { 584 edgeRefMap[it] = to.addEdge(redNodeRefMap[from.redNode(it)], 585 blueNodeRefMap[from.blueNode(it)]); 586 } 587 } 588 }; 589 590 template <typename BpGraph> 591 struct BpGraphCopySelector< 592 BpGraph, 593 typename enable_if<typename BpGraph::BuildTag, void>::type> 594 { 595 template <typename From, typename RedNodeRefMap, 596 typename BlueNodeRefMap, typename EdgeRefMap> 597 static void copy(const From& from, BpGraph &to, 598 RedNodeRefMap& redNodeRefMap, 599 BlueNodeRefMap& blueNodeRefMap, 600 EdgeRefMap& edgeRefMap) { 601 to.build(from, redNodeRefMap, blueNodeRefMap, edgeRefMap); 602 } 603 }; 604 448 605 } 606 607 /// \brief Check whether a graph is undirected. 608 /// 609 /// This function returns \c true if the given graph is undirected. 610 #ifdef DOXYGEN 611 template <typename GR> 612 bool undirected(const GR& g) { return false; } 613 #else 614 template <typename GR> 615 typename enable_if<UndirectedTagIndicator<GR>, bool>::type 616 undirected(const GR&) { 617 return true; 618 } 619 template <typename GR> 620 typename disable_if<UndirectedTagIndicator<GR>, bool>::type 621 undirected(const GR&) { 622 return false; 623 } 624 #endif 449 625 450 626 /// \brief Class to copy a digraph. … … 971 1147 graphCopy(const From& from, To& to) { 972 1148 return GraphCopy<From, To>(from, to); 1149 } 1150 1151 /// \brief Class to copy a bipartite graph. 1152 /// 1153 /// Class to copy a bipartite graph to another graph (duplicate a 1154 /// graph). The simplest way of using it is through the 1155 /// \c bpGraphCopy() function. 1156 /// 1157 /// This class not only make a copy of a bipartite graph, but it can 1158 /// create references and cross references between the nodes, edges 1159 /// and arcs of the two graphs, and it can copy maps for using with 1160 /// the newly created graph. 1161 /// 1162 /// To make a copy from a graph, first an instance of BpGraphCopy 1163 /// should be created, then the data belongs to the graph should 1164 /// assigned to copy. In the end, the \c run() member should be 1165 /// called. 1166 /// 1167 /// The next code copies a graph with several data: 1168 ///\code 1169 /// BpGraphCopy<OrigBpGraph, NewBpGraph> cg(orig_graph, new_graph); 1170 /// // Create references for the nodes 1171 /// OrigBpGraph::NodeMap<NewBpGraph::Node> nr(orig_graph); 1172 /// cg.nodeRef(nr); 1173 /// // Create cross references (inverse) for the edges 1174 /// NewBpGraph::EdgeMap<OrigBpGraph::Edge> ecr(new_graph); 1175 /// cg.edgeCrossRef(ecr); 1176 /// // Copy a red node map 1177 /// OrigBpGraph::RedNodeMap<double> ormap(orig_graph); 1178 /// NewBpGraph::RedNodeMap<double> nrmap(new_graph); 1179 /// cg.redNodeMap(ormap, nrmap); 1180 /// // Copy a node 1181 /// OrigBpGraph::Node on; 1182 /// NewBpGraph::Node nn; 1183 /// cg.node(on, nn); 1184 /// // Execute copying 1185 /// cg.run(); 1186 ///\endcode 1187 template <typename From, typename To> 1188 class BpGraphCopy { 1189 private: 1190 1191 typedef typename From::Node Node; 1192 typedef typename From::RedNode RedNode; 1193 typedef typename From::BlueNode BlueNode; 1194 typedef typename From::NodeIt NodeIt; 1195 typedef typename From::Arc Arc; 1196 typedef typename From::ArcIt ArcIt; 1197 typedef typename From::Edge Edge; 1198 typedef typename From::EdgeIt EdgeIt; 1199 1200 typedef typename To::Node TNode; 1201 typedef typename To::RedNode TRedNode; 1202 typedef typename To::BlueNode TBlueNode; 1203 typedef typename To::Arc TArc; 1204 typedef typename To::Edge TEdge; 1205 1206 typedef typename From::template RedNodeMap<TRedNode> RedNodeRefMap; 1207 typedef typename From::template BlueNodeMap<TBlueNode> BlueNodeRefMap; 1208 typedef typename From::template EdgeMap<TEdge> EdgeRefMap; 1209 1210 struct NodeRefMap { 1211 NodeRefMap(const From& from, const RedNodeRefMap& red_node_ref, 1212 const BlueNodeRefMap& blue_node_ref) 1213 : _from(from), _red_node_ref(red_node_ref), 1214 _blue_node_ref(blue_node_ref) {} 1215 1216 typedef typename From::Node Key; 1217 typedef typename To::Node Value; 1218 1219 Value operator[](const Key& key) const { 1220 if (_from.red(key)) { 1221 return _red_node_ref[_from.asRedNodeUnsafe(key)]; 1222 } else { 1223 return _blue_node_ref[_from.asBlueNodeUnsafe(key)]; 1224 } 1225 } 1226 1227 const From& _from; 1228 const RedNodeRefMap& _red_node_ref; 1229 const BlueNodeRefMap& _blue_node_ref; 1230 }; 1231 1232 struct ArcRefMap { 1233 ArcRefMap(const From& from, const To& to, const EdgeRefMap& edge_ref) 1234 : _from(from), _to(to), _edge_ref(edge_ref) {} 1235 1236 typedef typename From::Arc Key; 1237 typedef typename To::Arc Value; 1238 1239 Value operator[](const Key& key) const { 1240 return _to.direct(_edge_ref[key], _from.direction(key)); 1241 } 1242 1243 const From& _from; 1244 const To& _to; 1245 const EdgeRefMap& _edge_ref; 1246 }; 1247 1248 public: 1249 1250 /// \brief Constructor of BpGraphCopy. 1251 /// 1252 /// Constructor of BpGraphCopy for copying the content of the 1253 /// \c from graph into the \c to graph. 1254 BpGraphCopy(const From& from, To& to) 1255 : _from(from), _to(to) {} 1256 1257 /// \brief Destructor of BpGraphCopy 1258 /// 1259 /// Destructor of BpGraphCopy. 1260 ~BpGraphCopy() { 1261 for (int i = 0; i < int(_node_maps.size()); ++i) { 1262 delete _node_maps[i]; 1263 } 1264 for (int i = 0; i < int(_red_maps.size()); ++i) { 1265 delete _red_maps[i]; 1266 } 1267 for (int i = 0; i < int(_blue_maps.size()); ++i) { 1268 delete _blue_maps[i]; 1269 } 1270 for (int i = 0; i < int(_arc_maps.size()); ++i) { 1271 delete _arc_maps[i]; 1272 } 1273 for (int i = 0; i < int(_edge_maps.size()); ++i) { 1274 delete _edge_maps[i]; 1275 } 1276 } 1277 1278 /// \brief Copy the node references into the given map. 1279 /// 1280 /// This function copies the node references into the given map. 1281 /// The parameter should be a map, whose key type is the Node type of 1282 /// the source graph, while the value type is the Node type of the 1283 /// destination graph. 1284 template <typename NodeRef> 1285 BpGraphCopy& nodeRef(NodeRef& map) { 1286 _node_maps.push_back(new _core_bits::RefCopy<From, Node, 1287 NodeRefMap, NodeRef>(map)); 1288 return *this; 1289 } 1290 1291 /// \brief Copy the node cross references into the given map. 1292 /// 1293 /// This function copies the node cross references (reverse references) 1294 /// into the given map. The parameter should be a map, whose key type 1295 /// is the Node type of the destination graph, while the value type is 1296 /// the Node type of the source graph. 1297 template <typename NodeCrossRef> 1298 BpGraphCopy& nodeCrossRef(NodeCrossRef& map) { 1299 _node_maps.push_back(new _core_bits::CrossRefCopy<From, Node, 1300 NodeRefMap, NodeCrossRef>(map)); 1301 return *this; 1302 } 1303 1304 /// \brief Make a copy of the given node map. 1305 /// 1306 /// This function makes a copy of the given node map for the newly 1307 /// created graph. 1308 /// The key type of the new map \c tmap should be the Node type of the 1309 /// destination graph, and the key type of the original map \c map 1310 /// should be the Node type of the source graph. 1311 template <typename FromMap, typename ToMap> 1312 BpGraphCopy& nodeMap(const FromMap& map, ToMap& tmap) { 1313 _node_maps.push_back(new _core_bits::MapCopy<From, Node, 1314 NodeRefMap, FromMap, ToMap>(map, tmap)); 1315 return *this; 1316 } 1317 1318 /// \brief Make a copy of the given node. 1319 /// 1320 /// This function makes a copy of the given node. 1321 BpGraphCopy& node(const Node& node, TNode& tnode) { 1322 _node_maps.push_back(new _core_bits::ItemCopy<From, Node, 1323 NodeRefMap, TNode>(node, tnode)); 1324 return *this; 1325 } 1326 1327 /// \brief Copy the red node references into the given map. 1328 /// 1329 /// This function copies the red node references into the given 1330 /// map. The parameter should be a map, whose key type is the 1331 /// Node type of the source graph with the red item set, while the 1332 /// value type is the Node type of the destination graph. 1333 template <typename RedRef> 1334 BpGraphCopy& redRef(RedRef& map) { 1335 _red_maps.push_back(new _core_bits::RefCopy<From, RedNode, 1336 RedNodeRefMap, RedRef>(map)); 1337 return *this; 1338 } 1339 1340 /// \brief Copy the red node cross references into the given map. 1341 /// 1342 /// This function copies the red node cross references (reverse 1343 /// references) into the given map. The parameter should be a map, 1344 /// whose key type is the Node type of the destination graph with 1345 /// the red item set, while the value type is the Node type of the 1346 /// source graph. 1347 template <typename RedCrossRef> 1348 BpGraphCopy& redCrossRef(RedCrossRef& map) { 1349 _red_maps.push_back(new _core_bits::CrossRefCopy<From, RedNode, 1350 RedNodeRefMap, RedCrossRef>(map)); 1351 return *this; 1352 } 1353 1354 /// \brief Make a copy of the given red node map. 1355 /// 1356 /// This function makes a copy of the given red node map for the newly 1357 /// created graph. 1358 /// The key type of the new map \c tmap should be the Node type of 1359 /// the destination graph with the red items, and the key type of 1360 /// the original map \c map should be the Node type of the source 1361 /// graph. 1362 template <typename FromMap, typename ToMap> 1363 BpGraphCopy& redNodeMap(const FromMap& map, ToMap& tmap) { 1364 _red_maps.push_back(new _core_bits::MapCopy<From, RedNode, 1365 RedNodeRefMap, FromMap, ToMap>(map, tmap)); 1366 return *this; 1367 } 1368 1369 /// \brief Make a copy of the given red node. 1370 /// 1371 /// This function makes a copy of the given red node. 1372 BpGraphCopy& redNode(const RedNode& node, TRedNode& tnode) { 1373 _red_maps.push_back(new _core_bits::ItemCopy<From, RedNode, 1374 RedNodeRefMap, TRedNode>(node, tnode)); 1375 return *this; 1376 } 1377 1378 /// \brief Copy the blue node references into the given map. 1379 /// 1380 /// This function copies the blue node references into the given 1381 /// map. The parameter should be a map, whose key type is the 1382 /// Node type of the source graph with the blue item set, while the 1383 /// value type is the Node type of the destination graph. 1384 template <typename BlueRef> 1385 BpGraphCopy& blueRef(BlueRef& map) { 1386 _blue_maps.push_back(new _core_bits::RefCopy<From, BlueNode, 1387 BlueNodeRefMap, BlueRef>(map)); 1388 return *this; 1389 } 1390 1391 /// \brief Copy the blue node cross references into the given map. 1392 /// 1393 /// This function copies the blue node cross references (reverse 1394 /// references) into the given map. The parameter should be a map, 1395 /// whose key type is the Node type of the destination graph with 1396 /// the blue item set, while the value type is the Node type of the 1397 /// source graph. 1398 template <typename BlueCrossRef> 1399 BpGraphCopy& blueCrossRef(BlueCrossRef& map) { 1400 _blue_maps.push_back(new _core_bits::CrossRefCopy<From, BlueNode, 1401 BlueNodeRefMap, BlueCrossRef>(map)); 1402 return *this; 1403 } 1404 1405 /// \brief Make a copy of the given blue node map. 1406 /// 1407 /// This function makes a copy of the given blue node map for the newly 1408 /// created graph. 1409 /// The key type of the new map \c tmap should be the Node type of 1410 /// the destination graph with the blue items, and the key type of 1411 /// the original map \c map should be the Node type of the source 1412 /// graph. 1413 template <typename FromMap, typename ToMap> 1414 BpGraphCopy& blueNodeMap(const FromMap& map, ToMap& tmap) { 1415 _blue_maps.push_back(new _core_bits::MapCopy<From, BlueNode, 1416 BlueNodeRefMap, FromMap, ToMap>(map, tmap)); 1417 return *this; 1418 } 1419 1420 /// \brief Make a copy of the given blue node. 1421 /// 1422 /// This function makes a copy of the given blue node. 1423 BpGraphCopy& blueNode(const BlueNode& node, TBlueNode& tnode) { 1424 _blue_maps.push_back(new _core_bits::ItemCopy<From, BlueNode, 1425 BlueNodeRefMap, TBlueNode>(node, tnode)); 1426 return *this; 1427 } 1428 1429 /// \brief Copy the arc references into the given map. 1430 /// 1431 /// This function copies the arc references into the given map. 1432 /// The parameter should be a map, whose key type is the Arc type of 1433 /// the source graph, while the value type is the Arc type of the 1434 /// destination graph. 1435 template <typename ArcRef> 1436 BpGraphCopy& arcRef(ArcRef& map) { 1437 _arc_maps.push_back(new _core_bits::RefCopy<From, Arc, 1438 ArcRefMap, ArcRef>(map)); 1439 return *this; 1440 } 1441 1442 /// \brief Copy the arc cross references into the given map. 1443 /// 1444 /// This function copies the arc cross references (reverse references) 1445 /// into the given map. The parameter should be a map, whose key type 1446 /// is the Arc type of the destination graph, while the value type is 1447 /// the Arc type of the source graph. 1448 template <typename ArcCrossRef> 1449 BpGraphCopy& arcCrossRef(ArcCrossRef& map) { 1450 _arc_maps.push_back(new _core_bits::CrossRefCopy<From, Arc, 1451 ArcRefMap, ArcCrossRef>(map)); 1452 return *this; 1453 } 1454 1455 /// \brief Make a copy of the given arc map. 1456 /// 1457 /// This function makes a copy of the given arc map for the newly 1458 /// created graph. 1459 /// The key type of the new map \c tmap should be the Arc type of the 1460 /// destination graph, and the key type of the original map \c map 1461 /// should be the Arc type of the source graph. 1462 template <typename FromMap, typename ToMap> 1463 BpGraphCopy& arcMap(const FromMap& map, ToMap& tmap) { 1464 _arc_maps.push_back(new _core_bits::MapCopy<From, Arc, 1465 ArcRefMap, FromMap, ToMap>(map, tmap)); 1466 return *this; 1467 } 1468 1469 /// \brief Make a copy of the given arc. 1470 /// 1471 /// This function makes a copy of the given arc. 1472 BpGraphCopy& arc(const Arc& arc, TArc& tarc) { 1473 _arc_maps.push_back(new _core_bits::ItemCopy<From, Arc, 1474 ArcRefMap, TArc>(arc, tarc)); 1475 return *this; 1476 } 1477 1478 /// \brief Copy the edge references into the given map. 1479 /// 1480 /// This function copies the edge references into the given map. 1481 /// The parameter should be a map, whose key type is the Edge type of 1482 /// the source graph, while the value type is the Edge type of the 1483 /// destination graph. 1484 template <typename EdgeRef> 1485 BpGraphCopy& edgeRef(EdgeRef& map) { 1486 _edge_maps.push_back(new _core_bits::RefCopy<From, Edge, 1487 EdgeRefMap, EdgeRef>(map)); 1488 return *this; 1489 } 1490 1491 /// \brief Copy the edge cross references into the given map. 1492 /// 1493 /// This function copies the edge cross references (reverse references) 1494 /// into the given map. The parameter should be a map, whose key type 1495 /// is the Edge type of the destination graph, while the value type is 1496 /// the Edge type of the source graph. 1497 template <typename EdgeCrossRef> 1498 BpGraphCopy& edgeCrossRef(EdgeCrossRef& map) { 1499 _edge_maps.push_back(new _core_bits::CrossRefCopy<From, 1500 Edge, EdgeRefMap, EdgeCrossRef>(map)); 1501 return *this; 1502 } 1503 1504 /// \brief Make a copy of the given edge map. 1505 /// 1506 /// This function makes a copy of the given edge map for the newly 1507 /// created graph. 1508 /// The key type of the new map \c tmap should be the Edge type of the 1509 /// destination graph, and the key type of the original map \c map 1510 /// should be the Edge type of the source graph. 1511 template <typename FromMap, typename ToMap> 1512 BpGraphCopy& edgeMap(const FromMap& map, ToMap& tmap) { 1513 _edge_maps.push_back(new _core_bits::MapCopy<From, Edge, 1514 EdgeRefMap, FromMap, ToMap>(map, tmap)); 1515 return *this; 1516 } 1517 1518 /// \brief Make a copy of the given edge. 1519 /// 1520 /// This function makes a copy of the given edge. 1521 BpGraphCopy& edge(const Edge& edge, TEdge& tedge) { 1522 _edge_maps.push_back(new _core_bits::ItemCopy<From, Edge, 1523 EdgeRefMap, TEdge>(edge, tedge)); 1524 return *this; 1525 } 1526 1527 /// \brief Execute copying. 1528 /// 1529 /// This function executes the copying of the graph along with the 1530 /// copying of the assigned data. 1531 void run() { 1532 RedNodeRefMap redNodeRefMap(_from); 1533 BlueNodeRefMap blueNodeRefMap(_from); 1534 NodeRefMap nodeRefMap(_from, redNodeRefMap, blueNodeRefMap); 1535 EdgeRefMap edgeRefMap(_from); 1536 ArcRefMap arcRefMap(_from, _to, edgeRefMap); 1537 _core_bits::BpGraphCopySelector<To>:: 1538 copy(_from, _to, redNodeRefMap, blueNodeRefMap, edgeRefMap); 1539 for (int i = 0; i < int(_node_maps.size()); ++i) { 1540 _node_maps[i]->copy(_from, nodeRefMap); 1541 } 1542 for (int i = 0; i < int(_red_maps.size()); ++i) { 1543 _red_maps[i]->copy(_from, redNodeRefMap); 1544 } 1545 for (int i = 0; i < int(_blue_maps.size()); ++i) { 1546 _blue_maps[i]->copy(_from, blueNodeRefMap); 1547 } 1548 for (int i = 0; i < int(_edge_maps.size()); ++i) { 1549 _edge_maps[i]->copy(_from, edgeRefMap); 1550 } 1551 for (int i = 0; i < int(_arc_maps.size()); ++i) { 1552 _arc_maps[i]->copy(_from, arcRefMap); 1553 } 1554 } 1555 1556 private: 1557 1558 const From& _from; 1559 To& _to; 1560 1561 std::vector<_core_bits::MapCopyBase<From, Node, NodeRefMap>* > 1562 _node_maps; 1563 1564 std::vector<_core_bits::MapCopyBase<From, RedNode, RedNodeRefMap>* > 1565 _red_maps; 1566 1567 std::vector<_core_bits::MapCopyBase<From, BlueNode, BlueNodeRefMap>* > 1568 _blue_maps; 1569 1570 std::vector<_core_bits::MapCopyBase<From, Arc, ArcRefMap>* > 1571 _arc_maps; 1572 1573 std::vector<_core_bits::MapCopyBase<From, Edge, EdgeRefMap>* > 1574 _edge_maps; 1575 1576 }; 1577 1578 /// \brief Copy a graph to another graph. 1579 /// 1580 /// This function copies a graph to another graph. 1581 /// The complete usage of it is detailed in the BpGraphCopy class, 1582 /// but a short example shows a basic work: 1583 ///\code 1584 /// graphCopy(src, trg).nodeRef(nr).edgeCrossRef(ecr).run(); 1585 ///\endcode 1586 /// 1587 /// After the copy the \c nr map will contain the mapping from the 1588 /// nodes of the \c from graph to the nodes of the \c to graph and 1589 /// \c ecr will contain the mapping from the edges of the \c to graph 1590 /// to the edges of the \c from graph. 1591 /// 1592 /// \see BpGraphCopy 1593 template <typename From, typename To> 1594 BpGraphCopy<From, To> 1595 bpGraphCopy(const From& from, To& to) { 1596 return BpGraphCopy<From, To>(from, to); 973 1597 } 974 1598
Note: See TracChangeset
for help on using the changeset viewer.