COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/core.h

    r1000 r1027  
    149149  typedef typename Graph::template EdgeMap<double> DoubleEdgeMap
    150150
     151  ///Create convenience typedefs for the bipartite graph types and iterators
     152
     153  ///This \c \#define creates the same convenient type definitions as
     154  ///defined by \ref GRAPH_TYPEDEFS(BpGraph) and ten more, namely it
     155  ///creates \c RedNode, \c RedNodeIt, \c BoolRedNodeMap,
     156  ///\c IntRedNodeMap, \c DoubleRedNodeMap, \c BlueNode, \c BlueNodeIt,
     157  ///\c BoolBlueNodeMap, \c IntBlueNodeMap, \c DoubleBlueNodeMap.
     158  ///
     159  ///\note If the graph type is a dependent type, ie. the graph type depend
     160  ///on a template parameter, then use \c TEMPLATE_BPGRAPH_TYPEDEFS()
     161  ///macro.
     162#define BPGRAPH_TYPEDEFS(BpGraph)                                       \
     163  GRAPH_TYPEDEFS(BpGraph);                                              \
     164  typedef BpGraph::RedNode RedNode;                                     \
     165  typedef BpGraph::RedNodeIt RedNodeIt;                                 \
     166  typedef BpGraph::RedNodeMap<bool> BoolRedNodeMap;                     \
     167  typedef BpGraph::RedNodeMap<int> IntRedNodeMap;                       \
     168  typedef BpGraph::RedNodeMap<double> DoubleRedNodeMap;                 \
     169  typedef BpGraph::BlueNode BlueNode;                                   \
     170  typedef BpGraph::BlueNodeIt BlueNodeIt;                               \
     171  typedef BpGraph::BlueNodeMap<bool> BoolBlueNodeMap;                   \
     172  typedef BpGraph::BlueNodeMap<int> IntBlueNodeMap;                     \
     173  typedef BpGraph::BlueNodeMap<double> DoubleBlueNodeMap
     174
     175  ///Create convenience typedefs for the bipartite graph types and iterators
     176
     177  ///\see BPGRAPH_TYPEDEFS
     178  ///
     179  ///\note Use this macro, if the graph type is a dependent type,
     180  ///ie. the graph type depend on a template parameter.
     181#define TEMPLATE_BPGRAPH_TYPEDEFS(BpGraph)                                  \
     182  TEMPLATE_GRAPH_TYPEDEFS(BpGraph);                                         \
     183  typedef typename BpGraph::RedNode RedNode;                                \
     184  typedef typename BpGraph::RedNodeIt RedNodeIt;                            \
     185  typedef typename BpGraph::template RedNodeMap<bool> BoolRedNodeMap;       \
     186  typedef typename BpGraph::template RedNodeMap<int> IntRedNodeMap;         \
     187  typedef typename BpGraph::template RedNodeMap<double> DoubleRedNodeMap;   \
     188  typedef typename BpGraph::BlueNode BlueNode;                              \
     189  typedef typename BpGraph::BlueNodeIt BlueNodeIt;                          \
     190  typedef typename BpGraph::template BlueNodeMap<bool> BoolBlueNodeMap;     \
     191  typedef typename BpGraph::template BlueNodeMap<int> IntBlueNodeMap;       \
     192  typedef typename BpGraph::template BlueNodeMap<double> DoubleBlueNodeMap
     193
    151194  /// \brief Function to count the items in a graph.
    152195  ///
     
    200243  }
    201244
     245  namespace _graph_utils_bits {
     246   
     247    template <typename Graph, typename Enable = void>
     248    struct CountRedNodesSelector {
     249      static int count(const Graph &g) {
     250        return countItems<Graph, typename Graph::RedNode>(g);
     251      }
     252    };
     253
     254    template <typename Graph>
     255    struct CountRedNodesSelector<
     256      Graph, typename
     257      enable_if<typename Graph::NodeNumTag, void>::type>
     258    {
     259      static int count(const Graph &g) {
     260        return g.redNum();
     261      }
     262    };   
     263  }
     264
     265  /// \brief Function to count the red nodes in the graph.
     266  ///
     267  /// This function counts the red nodes in the graph.
     268  /// The complexity of the function is O(n) but for some
     269  /// graph structures it is specialized to run in O(1).
     270  ///
     271  /// If the graph contains a \e redNum() member function and a
     272  /// \e NodeNumTag tag then this function calls directly the member
     273  /// function to query the cardinality of the node set.
     274  template <typename Graph>
     275  inline int countRedNodes(const Graph& g) {
     276    return _graph_utils_bits::CountRedNodesSelector<Graph>::count(g);
     277  }
     278
     279  namespace _graph_utils_bits {
     280   
     281    template <typename Graph, typename Enable = void>
     282    struct CountBlueNodesSelector {
     283      static int count(const Graph &g) {
     284        return countItems<Graph, typename Graph::BlueNode>(g);
     285      }
     286    };
     287
     288    template <typename Graph>
     289    struct CountBlueNodesSelector<
     290      Graph, typename
     291      enable_if<typename Graph::NodeNumTag, void>::type>
     292    {
     293      static int count(const Graph &g) {
     294        return g.blueNum();
     295      }
     296    };   
     297  }
     298
     299  /// \brief Function to count the blue nodes in the graph.
     300  ///
     301  /// This function counts the blue nodes in the graph.
     302  /// The complexity of the function is O(n) but for some
     303  /// graph structures it is specialized to run in O(1).
     304  ///
     305  /// If the graph contains a \e blueNum() member function and a
     306  /// \e NodeNumTag tag then this function calls directly the member
     307  /// function to query the cardinality of the node set.
     308  template <typename Graph>
     309  inline int countBlueNodes(const Graph& g) {
     310    return _graph_utils_bits::CountBlueNodesSelector<Graph>::count(g);
     311  }
     312
    202313  // Arc counting:
    203314
     
    441552      template <typename From, typename NodeRefMap, typename EdgeRefMap>
    442553      static void copy(const From& from, Graph &to,
    443                        NodeRefMap& nodeRefMap, EdgeRefMap& edgeRefMap) {
     554                       NodeRefMap& nodeRefMap,
     555                       EdgeRefMap& edgeRefMap) {
    444556        to.build(from, nodeRefMap, edgeRefMap);
     557      }
     558    };
     559
     560    template <typename BpGraph, typename Enable = void>
     561    struct BpGraphCopySelector {
     562      template <typename From, typename RedNodeRefMap,
     563                typename BlueNodeRefMap, typename EdgeRefMap>
     564      static void copy(const From& from, BpGraph &to,
     565                       RedNodeRefMap& redNodeRefMap,
     566                       BlueNodeRefMap& blueNodeRefMap,
     567                       EdgeRefMap& edgeRefMap) {
     568        to.clear();
     569        for (typename From::RedNodeIt it(from); it != INVALID; ++it) {
     570          redNodeRefMap[it] = to.addRedNode();
     571        }
     572        for (typename From::BlueNodeIt it(from); it != INVALID; ++it) {
     573          blueNodeRefMap[it] = to.addBlueNode();
     574        }
     575        for (typename From::EdgeIt it(from); it != INVALID; ++it) {
     576          edgeRefMap[it] = to.addEdge(redNodeRefMap[from.redNode(it)],
     577                                      blueNodeRefMap[from.blueNode(it)]);
     578        }
     579      }
     580    };
     581
     582    template <typename BpGraph>
     583    struct BpGraphCopySelector<
     584      BpGraph,
     585      typename enable_if<typename BpGraph::BuildTag, void>::type>
     586    {
     587      template <typename From, typename RedNodeRefMap,
     588                typename BlueNodeRefMap, typename EdgeRefMap>
     589      static void copy(const From& from, BpGraph &to,
     590                       RedNodeRefMap& redNodeRefMap,
     591                       BlueNodeRefMap& blueNodeRefMap,
     592                       EdgeRefMap& edgeRefMap) {
     593        to.build(from, redNodeRefMap, blueNodeRefMap, edgeRefMap);
    445594      }
    446595    };
     
    9901139  graphCopy(const From& from, To& to) {
    9911140    return GraphCopy<From, To>(from, to);
     1141  }
     1142
     1143  /// \brief Class to copy a bipartite graph.
     1144  ///
     1145  /// Class to copy a bipartite graph to another graph (duplicate a
     1146  /// graph). The simplest way of using it is through the
     1147  /// \c bpGraphCopy() function.
     1148  ///
     1149  /// This class not only make a copy of a bipartite graph, but it can
     1150  /// create references and cross references between the nodes, edges
     1151  /// and arcs of the two graphs, and it can copy maps for using with
     1152  /// the newly created graph.
     1153  ///
     1154  /// To make a copy from a graph, first an instance of BpGraphCopy
     1155  /// should be created, then the data belongs to the graph should
     1156  /// assigned to copy. In the end, the \c run() member should be
     1157  /// called.
     1158  ///
     1159  /// The next code copies a graph with several data:
     1160  ///\code
     1161  ///  BpGraphCopy<OrigBpGraph, NewBpGraph> cg(orig_graph, new_graph);
     1162  ///  // Create references for the nodes
     1163  ///  OrigBpGraph::NodeMap<NewBpGraph::Node> nr(orig_graph);
     1164  ///  cg.nodeRef(nr);
     1165  ///  // Create cross references (inverse) for the edges
     1166  ///  NewBpGraph::EdgeMap<OrigBpGraph::Edge> ecr(new_graph);
     1167  ///  cg.edgeCrossRef(ecr);
     1168  ///  // Copy a red node map
     1169  ///  OrigBpGraph::RedNodeMap<double> ormap(orig_graph);
     1170  ///  NewBpGraph::RedNodeMap<double> nrmap(new_graph);
     1171  ///  cg.redNodeMap(ormap, nrmap);
     1172  ///  // Copy a node
     1173  ///  OrigBpGraph::Node on;
     1174  ///  NewBpGraph::Node nn;
     1175  ///  cg.node(on, nn);
     1176  ///  // Execute copying
     1177  ///  cg.run();
     1178  ///\endcode
     1179  template <typename From, typename To>
     1180  class BpGraphCopy {
     1181  private:
     1182
     1183    typedef typename From::Node Node;
     1184    typedef typename From::RedNode RedNode;
     1185    typedef typename From::BlueNode BlueNode;
     1186    typedef typename From::NodeIt NodeIt;
     1187    typedef typename From::Arc Arc;
     1188    typedef typename From::ArcIt ArcIt;
     1189    typedef typename From::Edge Edge;
     1190    typedef typename From::EdgeIt EdgeIt;
     1191
     1192    typedef typename To::Node TNode;
     1193    typedef typename To::RedNode TRedNode;
     1194    typedef typename To::BlueNode TBlueNode;
     1195    typedef typename To::Arc TArc;
     1196    typedef typename To::Edge TEdge;
     1197
     1198    typedef typename From::template RedNodeMap<TRedNode> RedNodeRefMap;
     1199    typedef typename From::template BlueNodeMap<TBlueNode> BlueNodeRefMap;
     1200    typedef typename From::template EdgeMap<TEdge> EdgeRefMap;
     1201
     1202    struct NodeRefMap {
     1203      NodeRefMap(const From& from, const RedNodeRefMap& red_node_ref,
     1204                 const BlueNodeRefMap& blue_node_ref)
     1205        : _from(from), _red_node_ref(red_node_ref),
     1206          _blue_node_ref(blue_node_ref) {}
     1207
     1208      typedef typename From::Node Key;
     1209      typedef typename To::Node Value;
     1210
     1211      Value operator[](const Key& key) const {
     1212        if (_from.red(key)) {
     1213          return _red_node_ref[_from.asRedNodeUnsafe(key)];
     1214        } else {
     1215          return _blue_node_ref[_from.asBlueNodeUnsafe(key)];
     1216        }
     1217      }
     1218
     1219      const From& _from;
     1220      const RedNodeRefMap& _red_node_ref;
     1221      const BlueNodeRefMap& _blue_node_ref;
     1222    };
     1223
     1224    struct ArcRefMap {
     1225      ArcRefMap(const From& from, const To& to, const EdgeRefMap& edge_ref)
     1226        : _from(from), _to(to), _edge_ref(edge_ref) {}
     1227
     1228      typedef typename From::Arc Key;
     1229      typedef typename To::Arc Value;
     1230
     1231      Value operator[](const Key& key) const {
     1232        return _to.direct(_edge_ref[key], _from.direction(key));
     1233      }
     1234
     1235      const From& _from;
     1236      const To& _to;
     1237      const EdgeRefMap& _edge_ref;
     1238    };
     1239
     1240  public:
     1241
     1242    /// \brief Constructor of BpGraphCopy.
     1243    ///
     1244    /// Constructor of BpGraphCopy for copying the content of the
     1245    /// \c from graph into the \c to graph.
     1246    BpGraphCopy(const From& from, To& to)
     1247      : _from(from), _to(to) {}
     1248
     1249    /// \brief Destructor of BpGraphCopy
     1250    ///
     1251    /// Destructor of BpGraphCopy.
     1252    ~BpGraphCopy() {
     1253      for (int i = 0; i < int(_node_maps.size()); ++i) {
     1254        delete _node_maps[i];
     1255      }
     1256      for (int i = 0; i < int(_red_maps.size()); ++i) {
     1257        delete _red_maps[i];
     1258      }
     1259      for (int i = 0; i < int(_blue_maps.size()); ++i) {
     1260        delete _blue_maps[i];
     1261      }
     1262      for (int i = 0; i < int(_arc_maps.size()); ++i) {
     1263        delete _arc_maps[i];
     1264      }
     1265      for (int i = 0; i < int(_edge_maps.size()); ++i) {
     1266        delete _edge_maps[i];
     1267      }
     1268    }
     1269
     1270    /// \brief Copy the node references into the given map.
     1271    ///
     1272    /// This function copies the node references into the given map.
     1273    /// The parameter should be a map, whose key type is the Node type of
     1274    /// the source graph, while the value type is the Node type of the
     1275    /// destination graph.
     1276    template <typename NodeRef>
     1277    BpGraphCopy& nodeRef(NodeRef& map) {
     1278      _node_maps.push_back(new _core_bits::RefCopy<From, Node,
     1279                           NodeRefMap, NodeRef>(map));
     1280      return *this;
     1281    }
     1282
     1283    /// \brief Copy the node cross references into the given map.
     1284    ///
     1285    /// This function copies the node cross references (reverse references)
     1286    /// into the given map. The parameter should be a map, whose key type
     1287    /// is the Node type of the destination graph, while the value type is
     1288    /// the Node type of the source graph.
     1289    template <typename NodeCrossRef>
     1290    BpGraphCopy& nodeCrossRef(NodeCrossRef& map) {
     1291      _node_maps.push_back(new _core_bits::CrossRefCopy<From, Node,
     1292                           NodeRefMap, NodeCrossRef>(map));
     1293      return *this;
     1294    }
     1295
     1296    /// \brief Make a copy of the given node map.
     1297    ///
     1298    /// This function makes a copy of the given node map for the newly
     1299    /// created graph.
     1300    /// The key type of the new map \c tmap should be the Node type of the
     1301    /// destination graph, and the key type of the original map \c map
     1302    /// should be the Node type of the source graph.
     1303    template <typename FromMap, typename ToMap>
     1304    BpGraphCopy& nodeMap(const FromMap& map, ToMap& tmap) {
     1305      _node_maps.push_back(new _core_bits::MapCopy<From, Node,
     1306                           NodeRefMap, FromMap, ToMap>(map, tmap));
     1307      return *this;
     1308    }
     1309
     1310    /// \brief Make a copy of the given node.
     1311    ///
     1312    /// This function makes a copy of the given node.
     1313    BpGraphCopy& node(const Node& node, TNode& tnode) {
     1314      _node_maps.push_back(new _core_bits::ItemCopy<From, Node,
     1315                           NodeRefMap, TNode>(node, tnode));
     1316      return *this;
     1317    }
     1318
     1319    /// \brief Copy the red node references into the given map.
     1320    ///
     1321    /// This function copies the red node references into the given
     1322    /// map.  The parameter should be a map, whose key type is the
     1323    /// Node type of the source graph with the red item set, while the
     1324    /// value type is the Node type of the destination graph.
     1325    template <typename RedRef>
     1326    BpGraphCopy& redRef(RedRef& map) {
     1327      _red_maps.push_back(new _core_bits::RefCopy<From, RedNode,
     1328                          RedNodeRefMap, RedRef>(map));
     1329      return *this;
     1330    }
     1331
     1332    /// \brief Copy the red node cross references into the given map.
     1333    ///
     1334    /// This function copies the red node cross references (reverse
     1335    /// references) into the given map. The parameter should be a map,
     1336    /// whose key type is the Node type of the destination graph with
     1337    /// the red item set, while the value type is the Node type of the
     1338    /// source graph.
     1339    template <typename RedCrossRef>
     1340    BpGraphCopy& redCrossRef(RedCrossRef& map) {
     1341      _red_maps.push_back(new _core_bits::CrossRefCopy<From, RedNode,
     1342                          RedNodeRefMap, RedCrossRef>(map));
     1343      return *this;
     1344    }
     1345
     1346    /// \brief Make a copy of the given red node map.
     1347    ///
     1348    /// This function makes a copy of the given red node map for the newly
     1349    /// created graph.
     1350    /// The key type of the new map \c tmap should be the Node type of
     1351    /// the destination graph with the red items, and the key type of
     1352    /// the original map \c map should be the Node type of the source
     1353    /// graph.
     1354    template <typename FromMap, typename ToMap>
     1355    BpGraphCopy& redNodeMap(const FromMap& map, ToMap& tmap) {
     1356      _red_maps.push_back(new _core_bits::MapCopy<From, RedNode,
     1357                          RedNodeRefMap, FromMap, ToMap>(map, tmap));
     1358      return *this;
     1359    }
     1360
     1361    /// \brief Make a copy of the given red node.
     1362    ///
     1363    /// This function makes a copy of the given red node.
     1364    BpGraphCopy& redNode(const RedNode& node, TRedNode& tnode) {
     1365      _red_maps.push_back(new _core_bits::ItemCopy<From, RedNode,
     1366                          RedNodeRefMap, TRedNode>(node, tnode));
     1367      return *this;
     1368    }
     1369
     1370    /// \brief Copy the blue node references into the given map.
     1371    ///
     1372    /// This function copies the blue node references into the given
     1373    /// map.  The parameter should be a map, whose key type is the
     1374    /// Node type of the source graph with the blue item set, while the
     1375    /// value type is the Node type of the destination graph.
     1376    template <typename BlueRef>
     1377    BpGraphCopy& blueRef(BlueRef& map) {
     1378      _blue_maps.push_back(new _core_bits::RefCopy<From, BlueNode,
     1379                           BlueNodeRefMap, BlueRef>(map));
     1380      return *this;
     1381    }
     1382
     1383    /// \brief Copy the blue node cross references into the given map.
     1384    ///
     1385    /// This function copies the blue node cross references (reverse
     1386    /// references) into the given map. The parameter should be a map,
     1387    /// whose key type is the Node type of the destination graph with
     1388    /// the blue item set, while the value type is the Node type of the
     1389    /// source graph.
     1390    template <typename BlueCrossRef>
     1391    BpGraphCopy& blueCrossRef(BlueCrossRef& map) {
     1392      _blue_maps.push_back(new _core_bits::CrossRefCopy<From, BlueNode,
     1393                           BlueNodeRefMap, BlueCrossRef>(map));
     1394      return *this;
     1395    }
     1396
     1397    /// \brief Make a copy of the given blue node map.
     1398    ///
     1399    /// This function makes a copy of the given blue node map for the newly
     1400    /// created graph.
     1401    /// The key type of the new map \c tmap should be the Node type of
     1402    /// the destination graph with the blue items, and the key type of
     1403    /// the original map \c map should be the Node type of the source
     1404    /// graph.
     1405    template <typename FromMap, typename ToMap>
     1406    BpGraphCopy& blueNodeMap(const FromMap& map, ToMap& tmap) {
     1407      _blue_maps.push_back(new _core_bits::MapCopy<From, BlueNode,
     1408                           BlueNodeRefMap, FromMap, ToMap>(map, tmap));
     1409      return *this;
     1410    }
     1411
     1412    /// \brief Make a copy of the given blue node.
     1413    ///
     1414    /// This function makes a copy of the given blue node.
     1415    BpGraphCopy& blueNode(const BlueNode& node, TBlueNode& tnode) {
     1416      _blue_maps.push_back(new _core_bits::ItemCopy<From, BlueNode,
     1417                           BlueNodeRefMap, TBlueNode>(node, tnode));
     1418      return *this;
     1419    }
     1420
     1421    /// \brief Copy the arc references into the given map.
     1422    ///
     1423    /// This function copies the arc references into the given map.
     1424    /// The parameter should be a map, whose key type is the Arc type of
     1425    /// the source graph, while the value type is the Arc type of the
     1426    /// destination graph.
     1427    template <typename ArcRef>
     1428    BpGraphCopy& arcRef(ArcRef& map) {
     1429      _arc_maps.push_back(new _core_bits::RefCopy<From, Arc,
     1430                          ArcRefMap, ArcRef>(map));
     1431      return *this;
     1432    }
     1433
     1434    /// \brief Copy the arc cross references into the given map.
     1435    ///
     1436    /// This function copies the arc cross references (reverse references)
     1437    /// into the given map. The parameter should be a map, whose key type
     1438    /// is the Arc type of the destination graph, while the value type is
     1439    /// the Arc type of the source graph.
     1440    template <typename ArcCrossRef>
     1441    BpGraphCopy& arcCrossRef(ArcCrossRef& map) {
     1442      _arc_maps.push_back(new _core_bits::CrossRefCopy<From, Arc,
     1443                          ArcRefMap, ArcCrossRef>(map));
     1444      return *this;
     1445    }
     1446
     1447    /// \brief Make a copy of the given arc map.
     1448    ///
     1449    /// This function makes a copy of the given arc map for the newly
     1450    /// created graph.
     1451    /// The key type of the new map \c tmap should be the Arc type of the
     1452    /// destination graph, and the key type of the original map \c map
     1453    /// should be the Arc type of the source graph.
     1454    template <typename FromMap, typename ToMap>
     1455    BpGraphCopy& arcMap(const FromMap& map, ToMap& tmap) {
     1456      _arc_maps.push_back(new _core_bits::MapCopy<From, Arc,
     1457                          ArcRefMap, FromMap, ToMap>(map, tmap));
     1458      return *this;
     1459    }
     1460
     1461    /// \brief Make a copy of the given arc.
     1462    ///
     1463    /// This function makes a copy of the given arc.
     1464    BpGraphCopy& arc(const Arc& arc, TArc& tarc) {
     1465      _arc_maps.push_back(new _core_bits::ItemCopy<From, Arc,
     1466                          ArcRefMap, TArc>(arc, tarc));
     1467      return *this;
     1468    }
     1469
     1470    /// \brief Copy the edge references into the given map.
     1471    ///
     1472    /// This function copies the edge references into the given map.
     1473    /// The parameter should be a map, whose key type is the Edge type of
     1474    /// the source graph, while the value type is the Edge type of the
     1475    /// destination graph.
     1476    template <typename EdgeRef>
     1477    BpGraphCopy& edgeRef(EdgeRef& map) {
     1478      _edge_maps.push_back(new _core_bits::RefCopy<From, Edge,
     1479                           EdgeRefMap, EdgeRef>(map));
     1480      return *this;
     1481    }
     1482
     1483    /// \brief Copy the edge cross references into the given map.
     1484    ///
     1485    /// This function copies the edge cross references (reverse references)
     1486    /// into the given map. The parameter should be a map, whose key type
     1487    /// is the Edge type of the destination graph, while the value type is
     1488    /// the Edge type of the source graph.
     1489    template <typename EdgeCrossRef>
     1490    BpGraphCopy& edgeCrossRef(EdgeCrossRef& map) {
     1491      _edge_maps.push_back(new _core_bits::CrossRefCopy<From,
     1492                           Edge, EdgeRefMap, EdgeCrossRef>(map));
     1493      return *this;
     1494    }
     1495
     1496    /// \brief Make a copy of the given edge map.
     1497    ///
     1498    /// This function makes a copy of the given edge map for the newly
     1499    /// created graph.
     1500    /// The key type of the new map \c tmap should be the Edge type of the
     1501    /// destination graph, and the key type of the original map \c map
     1502    /// should be the Edge type of the source graph.
     1503    template <typename FromMap, typename ToMap>
     1504    BpGraphCopy& edgeMap(const FromMap& map, ToMap& tmap) {
     1505      _edge_maps.push_back(new _core_bits::MapCopy<From, Edge,
     1506                           EdgeRefMap, FromMap, ToMap>(map, tmap));
     1507      return *this;
     1508    }
     1509
     1510    /// \brief Make a copy of the given edge.
     1511    ///
     1512    /// This function makes a copy of the given edge.
     1513    BpGraphCopy& edge(const Edge& edge, TEdge& tedge) {
     1514      _edge_maps.push_back(new _core_bits::ItemCopy<From, Edge,
     1515                           EdgeRefMap, TEdge>(edge, tedge));
     1516      return *this;
     1517    }
     1518
     1519    /// \brief Execute copying.
     1520    ///
     1521    /// This function executes the copying of the graph along with the
     1522    /// copying of the assigned data.
     1523    void run() {
     1524      RedNodeRefMap redNodeRefMap(_from);
     1525      BlueNodeRefMap blueNodeRefMap(_from);
     1526      NodeRefMap nodeRefMap(_from, redNodeRefMap, blueNodeRefMap);
     1527      EdgeRefMap edgeRefMap(_from);
     1528      ArcRefMap arcRefMap(_from, _to, edgeRefMap);
     1529      _core_bits::BpGraphCopySelector<To>::
     1530        copy(_from, _to, redNodeRefMap, blueNodeRefMap, edgeRefMap);
     1531      for (int i = 0; i < int(_node_maps.size()); ++i) {
     1532        _node_maps[i]->copy(_from, nodeRefMap);
     1533      }
     1534      for (int i = 0; i < int(_red_maps.size()); ++i) {
     1535        _red_maps[i]->copy(_from, redNodeRefMap);
     1536      }
     1537      for (int i = 0; i < int(_blue_maps.size()); ++i) {
     1538        _blue_maps[i]->copy(_from, blueNodeRefMap);
     1539      }
     1540      for (int i = 0; i < int(_edge_maps.size()); ++i) {
     1541        _edge_maps[i]->copy(_from, edgeRefMap);
     1542      }
     1543      for (int i = 0; i < int(_arc_maps.size()); ++i) {
     1544        _arc_maps[i]->copy(_from, arcRefMap);
     1545      }
     1546    }
     1547
     1548  private:
     1549
     1550    const From& _from;
     1551    To& _to;
     1552
     1553    std::vector<_core_bits::MapCopyBase<From, Node, NodeRefMap>* >
     1554      _node_maps;
     1555
     1556    std::vector<_core_bits::MapCopyBase<From, RedNode, RedNodeRefMap>* >
     1557      _red_maps;
     1558
     1559    std::vector<_core_bits::MapCopyBase<From, BlueNode, BlueNodeRefMap>* >
     1560      _blue_maps;
     1561
     1562    std::vector<_core_bits::MapCopyBase<From, Arc, ArcRefMap>* >
     1563      _arc_maps;
     1564
     1565    std::vector<_core_bits::MapCopyBase<From, Edge, EdgeRefMap>* >
     1566      _edge_maps;
     1567
     1568  };
     1569
     1570  /// \brief Copy a graph to another graph.
     1571  ///
     1572  /// This function copies a graph to another graph.
     1573  /// The complete usage of it is detailed in the BpGraphCopy class,
     1574  /// but a short example shows a basic work:
     1575  ///\code
     1576  /// graphCopy(src, trg).nodeRef(nr).edgeCrossRef(ecr).run();
     1577  ///\endcode
     1578  ///
     1579  /// After the copy the \c nr map will contain the mapping from the
     1580  /// nodes of the \c from graph to the nodes of the \c to graph and
     1581  /// \c ecr will contain the mapping from the edges of the \c to graph
     1582  /// to the edges of the \c from graph.
     1583  ///
     1584  /// \see BpGraphCopy
     1585  template <typename From, typename To>
     1586  BpGraphCopy<From, To>
     1587  bpGraphCopy(const From& from, To& to) {
     1588    return BpGraphCopy<From, To>(from, to);
    9921589  }
    9931590
     
    12581855    /// The Digraph type
    12591856    typedef GR Digraph;
    1260 
     1857   
    12611858  protected:
    12621859
Note: See TracChangeset for help on using the changeset viewer.