COIN-OR::LEMON - Graph Library

Changeset 1261:97f1760dcd13 in lemon for lemon


Ignore:
Timestamp:
08/07/13 07:04:58 (11 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Parents:
1256:cae19e9eeca4 (diff), 1260:a337a0dd3f75 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

Merge #294

Location:
lemon
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • lemon/concepts/digraph.h

    r1217 r1261  
    313313        /// Sets the iterator to the first arc of the given digraph.
    314314        ///
    315         explicit ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
     315        explicit ArcIt(const Digraph& g) { ::lemon::ignore_unused_variable_warning(g); }
    316316        /// Sets the iterator to the given arc.
    317317
  • lemon/concepts/digraph.h

    r1259 r1261  
    410410      /// \brief The base node of the iterator.
    411411      ///
    412       /// Returns the base node of the given incomming arc iterator
     412      /// Returns the base node of the given incoming arc iterator
    413413      /// (i.e. the target node of the corresponding arc).
    414414      Node baseNode(InArcIt) const { return INVALID; }
     
    416416      /// \brief The running node of the iterator.
    417417      ///
    418       /// Returns the running node of the given incomming arc iterator
     418      /// Returns the running node of the given incoming arc iterator
    419419      /// (i.e. the source node of the corresponding arc).
    420420      Node runningNode(InArcIt) const { return INVALID; }
  • lemon/concepts/graph.h

    r1217 r1261  
    397397        /// Sets the iterator to the first arc of the given graph.
    398398        ///
    399         explicit ArcIt(const Graph &g) { ignore_unused_variable_warning(g); }
     399        explicit ArcIt(const Graph &g) { ::lemon::ignore_unused_variable_warning(g); }
    400400        /// Sets the iterator to the given arc.
    401401
     
    443443        ///
    444444        OutArcIt(const Graph& n, const Node& g) {
    445           ignore_unused_variable_warning(n);
    446           ignore_unused_variable_warning(g);
     445          ::lemon::ignore_unused_variable_warning(n);
     446          ::lemon::ignore_unused_variable_warning(g);
    447447        }
    448448        /// Sets the iterator to the given arc.
     
    491491        ///
    492492        InArcIt(const Graph& g, const Node& n) {
    493           ignore_unused_variable_warning(n);
    494           ignore_unused_variable_warning(g);
     493          ::lemon::ignore_unused_variable_warning(n);
     494          ::lemon::ignore_unused_variable_warning(g);
    495495        }
    496496        /// Sets the iterator to the given arc.
  • lemon/concepts/graph.h

    r1259 r1261  
    7373    class Graph {
    7474    private:
    75       /// Graphs are \e not copy constructible. Use DigraphCopy instead.
     75      /// Graphs are \e not copy constructible. Use GraphCopy instead.
    7676      Graph(const Graph&) {}
    7777      /// \brief Assignment of a graph to another one is \e not allowed.
    78       /// Use DigraphCopy instead.
     78      /// Use GraphCopy instead.
    7979      void operator=(const Graph&) {}
    8080
     
    758758      /// \brief The base node of the iterator.
    759759      ///
    760       /// Returns the base node of the given incomming arc iterator
     760      /// Returns the base node of the given incoming arc iterator
    761761      /// (i.e. the target node of the corresponding arc).
    762762      Node baseNode(InArcIt) const { return INVALID; }
     
    764764      /// \brief The running node of the iterator.
    765765      ///
    766       /// Returns the running node of the given incomming arc iterator
     766      /// Returns the running node of the given incoming arc iterator
    767767      /// (i.e. the source node of the corresponding arc).
    768768      Node runningNode(InArcIt) const { return INVALID; }
  • lemon/concepts/graph_components.h

    r1217 r1261  
    109109
    110110          bool b;
    111           ignore_unused_variable_warning(b);
     111          ::lemon::ignore_unused_variable_warning(b);
    112112
    113113          b = (ia == ib) && (ia != ib);
     
    290290            ue = e;
    291291            bool d = graph.direction(e);
    292             ignore_unused_variable_warning(d);
     292            ::lemon::ignore_unused_variable_warning(d);
    293293          }
    294294        }
     
    535535
    536536          nid = digraph.maxNodeId();
    537           ignore_unused_variable_warning(nid);
     537          ::lemon::ignore_unused_variable_warning(nid);
    538538          eid = digraph.maxArcId();
    539           ignore_unused_variable_warning(eid);
     539          ::lemon::ignore_unused_variable_warning(eid);
    540540        }
    541541
     
    590590          edge = graph.edgeFromId(ueid);
    591591          ueid = graph.maxEdgeId();
    592           ignore_unused_variable_warning(ueid);
     592          ::lemon::ignore_unused_variable_warning(ueid);
    593593        }
    594594
     
    727727          _GraphItemIt it3 = it1;
    728728          _GraphItemIt it4 = INVALID;
    729           ignore_unused_variable_warning(it3);
    730           ignore_unused_variable_warning(it4);
     729          ::lemon::ignore_unused_variable_warning(it3);
     730          ::lemon::ignore_unused_variable_warning(it4);
    731731
    732732          it2 = ++it1;
     
    818818          _GraphIncIt it3 = it1;
    819819          _GraphIncIt it4 = INVALID;
    820           ignore_unused_variable_warning(it3);
    821           ignore_unused_variable_warning(it4);
     820          ::lemon::ignore_unused_variable_warning(it3);
     821          ::lemon::ignore_unused_variable_warning(it4);
    822822
    823823          it2 = ++it1;
     
    10011001            n = digraph.baseNode(oait);
    10021002            n = digraph.runningNode(oait);
    1003             ignore_unused_variable_warning(n);
     1003            ::lemon::ignore_unused_variable_warning(n);
    10041004          }
    10051005        }
     
    12781278            = digraph.notifier(typename _Digraph::Arc());
    12791279
    1280           ignore_unused_variable_warning(nn);
    1281           ignore_unused_variable_warning(en);
     1280          ::lemon::ignore_unused_variable_warning(nn);
     1281          ::lemon::ignore_unused_variable_warning(en);
    12821282        }
    12831283
     
    13261326          typename _Graph::EdgeNotifier& uen
    13271327            = graph.notifier(typename _Graph::Edge());
    1328           ignore_unused_variable_warning(uen);
     1328          ::lemon::ignore_unused_variable_warning(uen);
    13291329        }
    13301330
     
    14621462          // m3 = cmap;
    14631463
    1464           ignore_unused_variable_warning(m1);
    1465           ignore_unused_variable_warning(m2);
    1466           // ignore_unused_variable_warning(m3);
     1464          ::lemon::ignore_unused_variable_warning(m1);
     1465          ::lemon::ignore_unused_variable_warning(m2);
     1466          // ::lemon::ignore_unused_variable_warning(m3);
    14671467        }
    14681468
  • lemon/concepts/graph_components.h

    r1259 r1261  
    300300    };
    301301
     302    /// \brief Base skeleton class for undirected bipartite graphs.
     303    ///
     304    /// This class describes the base interface of undirected
     305    /// bipartite graph types.  All bipartite graph %concepts have to
     306    /// conform to this class.  It extends the interface of \ref
     307    /// BaseGraphComponent with an \c Edge type and functions to get
     308    /// the end nodes of edges, to convert from arcs to edges and to
     309    /// get both direction of edges.
     310    class BaseBpGraphComponent : public BaseGraphComponent {
     311    public:
     312
     313      typedef BaseBpGraphComponent BpGraph;
     314
     315      typedef BaseDigraphComponent::Node Node;
     316      typedef BaseDigraphComponent::Arc Arc;
     317
     318      /// \brief Class to represent red nodes.
     319      ///
     320      /// This class represents the red nodes of the graph. The red
     321      /// nodes can also be used as normal nodes.
     322      class RedNode : public Node {
     323        typedef Node Parent;
     324
     325      public:
     326        /// \brief Default constructor.
     327        ///
     328        /// Default constructor.
     329        /// \warning The default constructor is not required to set
     330        /// the item to some well-defined value. So you should consider it
     331        /// as uninitialized.
     332        RedNode() {}
     333
     334        /// \brief Copy constructor.
     335        ///
     336        /// Copy constructor.
     337        RedNode(const RedNode &) : Parent() {}
     338
     339        /// \brief Constructor for conversion from \c INVALID.
     340        ///
     341        /// Constructor for conversion from \c INVALID.
     342        /// It initializes the item to be invalid.
     343        /// \sa Invalid for more details.
     344        RedNode(Invalid) {}
     345      };
     346
     347      /// \brief Class to represent blue nodes.
     348      ///
     349      /// This class represents the blue nodes of the graph. The blue
     350      /// nodes can also be used as normal nodes.
     351      class BlueNode : public Node {
     352        typedef Node Parent;
     353
     354      public:
     355        /// \brief Default constructor.
     356        ///
     357        /// Default constructor.
     358        /// \warning The default constructor is not required to set
     359        /// the item to some well-defined value. So you should consider it
     360        /// as uninitialized.
     361        BlueNode() {}
     362
     363        /// \brief Copy constructor.
     364        ///
     365        /// Copy constructor.
     366        BlueNode(const BlueNode &) : Parent() {}
     367
     368        /// \brief Constructor for conversion from \c INVALID.
     369        ///
     370        /// Constructor for conversion from \c INVALID.
     371        /// It initializes the item to be invalid.
     372        /// \sa Invalid for more details.
     373        BlueNode(Invalid) {}
     374
     375        /// \brief Constructor for conversion from a node.
     376        ///
     377        /// Constructor for conversion from a node. The conversion can
     378        /// be invalid, since the Node can be member of the red
     379        /// set.
     380        BlueNode(const Node&) {}
     381      };
     382
     383      /// \brief Gives back %true for red nodes.
     384      ///
     385      /// Gives back %true for red nodes.
     386      bool red(const Node&) const { return true; }
     387
     388      /// \brief Gives back %true for blue nodes.
     389      ///
     390      /// Gives back %true for blue nodes.
     391      bool blue(const Node&) const { return true; }
     392
     393      /// \brief Gives back the red end node of the edge.
     394      ///
     395      /// Gives back the red end node of the edge.
     396      RedNode redNode(const Edge&) const { return RedNode(); }
     397
     398      /// \brief Gives back the blue end node of the edge.
     399      ///
     400      /// Gives back the blue end node of the edge.
     401      BlueNode blueNode(const Edge&) const { return BlueNode(); }
     402
     403      /// \brief Converts the node to red node object.
     404      ///
     405      /// This function converts unsafely the node to red node
     406      /// object. It should be called only if the node is from the red
     407      /// partition or INVALID.
     408      RedNode asRedNodeUnsafe(const Node&) const { return RedNode(); }
     409
     410      /// \brief Converts the node to blue node object.
     411      ///
     412      /// This function converts unsafely the node to blue node
     413      /// object. It should be called only if the node is from the red
     414      /// partition or INVALID.
     415      BlueNode asBlueNodeUnsafe(const Node&) const { return BlueNode(); }
     416
     417      /// \brief Converts the node to red node object.
     418      ///
     419      /// This function converts safely the node to red node
     420      /// object. If the node is not from the red partition, then it
     421      /// returns INVALID.
     422      RedNode asRedNode(const Node&) const { return RedNode(); }
     423
     424      /// \brief Converts the node to blue node object.
     425      ///
     426      /// This function converts unsafely the node to blue node
     427      /// object. If the node is not from the blue partition, then it
     428      /// returns INVALID.
     429      BlueNode asBlueNode(const Node&) const { return BlueNode(); }
     430
     431      template <typename _BpGraph>
     432      struct Constraints {
     433        typedef typename _BpGraph::Node Node;
     434        typedef typename _BpGraph::RedNode RedNode;
     435        typedef typename _BpGraph::BlueNode BlueNode;
     436        typedef typename _BpGraph::Arc Arc;
     437        typedef typename _BpGraph::Edge Edge;
     438
     439        void constraints() {
     440          checkConcept<BaseGraphComponent, _BpGraph>();
     441          checkConcept<GraphItem<'n'>, RedNode>();
     442          checkConcept<GraphItem<'n'>, BlueNode>();
     443          {
     444            Node n;
     445            RedNode rn;
     446            BlueNode bn;
     447            Node rnan = rn;
     448            Node bnan = bn;
     449            Edge e;
     450            bool b;
     451            b = bpgraph.red(rnan);
     452            b = bpgraph.blue(bnan);
     453            rn = bpgraph.redNode(e);
     454            bn = bpgraph.blueNode(e);
     455            rn = bpgraph.asRedNodeUnsafe(rnan);
     456            bn = bpgraph.asBlueNodeUnsafe(bnan);
     457            rn = bpgraph.asRedNode(rnan);
     458            bn = bpgraph.asBlueNode(bnan);
     459            ignore_unused_variable_warning(b);
     460          }
     461        }
     462
     463        const _BpGraph& bpgraph;
     464      };
     465
     466    };
     467
    302468    /// \brief Skeleton class for \e idable directed graphs.
    303469    ///
     
    432598    };
    433599
     600    /// \brief Skeleton class for \e idable undirected bipartite graphs.
     601    ///
     602    /// This class describes the interface of \e idable undirected
     603    /// bipartite graphs. It extends \ref IDableGraphComponent with
     604    /// the core ID functions of undirected bipartite graphs. Beside
     605    /// the regular node ids, this class also provides ids within the
     606    /// the red and blue sets of the nodes. This concept is part of
     607    /// the BpGraph concept.
     608    template <typename BAS = BaseBpGraphComponent>
     609    class IDableBpGraphComponent : public IDableGraphComponent<BAS> {
     610    public:
     611
     612      typedef BAS Base;
     613      typedef IDableGraphComponent<BAS> Parent;
     614      typedef typename Base::Node Node;
     615      typedef typename Base::RedNode RedNode;
     616      typedef typename Base::BlueNode BlueNode;
     617
     618      using Parent::id;
     619
     620      /// \brief Return a unique integer id for the given node in the red set.
     621      ///
     622      /// Return a unique integer id for the given node in the red set.
     623      int id(const RedNode&) const { return -1; }
     624
     625      /// \brief Return a unique integer id for the given node in the blue set.
     626      ///
     627      /// Return a unique integer id for the given node in the blue set.
     628      int id(const BlueNode&) const { return -1; }
     629
     630      /// \brief Return an integer greater or equal to the maximum
     631      /// node id in the red set.
     632      ///
     633      /// Return an integer greater or equal to the maximum
     634      /// node id in the red set.
     635      int maxRedId() const { return -1; }
     636
     637      /// \brief Return an integer greater or equal to the maximum
     638      /// node id in the blue set.
     639      ///
     640      /// Return an integer greater or equal to the maximum
     641      /// node id in the blue set.
     642      int maxBlueId() const { return -1; }
     643
     644      template <typename _BpGraph>
     645      struct Constraints {
     646
     647        void constraints() {
     648          checkConcept<IDableGraphComponent<Base>, _BpGraph>();
     649          typename _BpGraph::Node node;
     650          typename _BpGraph::RedNode red;
     651          typename _BpGraph::BlueNode blue;
     652          int rid = bpgraph.id(red);
     653          int bid = bpgraph.id(blue);
     654          rid = bpgraph.maxRedId();
     655          bid = bpgraph.maxBlueId();
     656          ignore_unused_variable_warning(rid);
     657          ignore_unused_variable_warning(bid);
     658        }
     659
     660        const _BpGraph& bpgraph;
     661      };
     662    };
     663
    434664    /// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types.
    435665    ///
     
    646876      void next(Arc&) const {}
    647877
    648       /// \brief Return the first arc incomming to the given node.
    649       ///
    650       /// This function gives back the first arc incomming to the
     878      /// \brief Return the first arc incoming to the given node.
     879      ///
     880      /// This function gives back the first arc incoming to the
    651881      /// given node.
    652882      void firstIn(Arc&, const Node&) const {}
    653883
    654       /// \brief Return the next arc incomming to the given node.
    655       ///
    656       /// This function gives back the next arc incomming to the
     884      /// \brief Return the next arc incoming to the given node.
     885      ///
     886      /// This function gives back the next arc incoming to the
    657887      /// given node.
    658888      void nextIn(Arc&) const {}
     
    9051135    };
    9061136
     1137    /// \brief Skeleton class for iterable undirected bipartite graphs.
     1138    ///
     1139    /// This class describes the interface of iterable undirected
     1140    /// bipartite graphs. It extends \ref IterableGraphComponent with
     1141    /// the core iterable interface of undirected bipartite graphs.
     1142    /// This concept is part of the BpGraph concept.
     1143    template <typename BAS = BaseBpGraphComponent>
     1144    class IterableBpGraphComponent : public IterableGraphComponent<BAS> {
     1145    public:
     1146
     1147      typedef BAS Base;
     1148      typedef typename Base::Node Node;
     1149      typedef typename Base::RedNode RedNode;
     1150      typedef typename Base::BlueNode BlueNode;
     1151      typedef typename Base::Arc Arc;
     1152      typedef typename Base::Edge Edge;
     1153     
     1154      typedef IterableBpGraphComponent BpGraph;
     1155
     1156      using IterableGraphComponent<BAS>::first;
     1157      using IterableGraphComponent<BAS>::next;
     1158
     1159      /// \name Base Iteration
     1160      ///
     1161      /// This interface provides functions for iteration on red and blue nodes.
     1162      ///
     1163      /// @{
     1164
     1165      /// \brief Return the first red node.
     1166      ///
     1167      /// This function gives back the first red node in the iteration order.
     1168      void first(RedNode&) const {}
     1169
     1170      /// \brief Return the next red node.
     1171      ///
     1172      /// This function gives back the next red node in the iteration order.
     1173      void next(RedNode&) const {}
     1174
     1175      /// \brief Return the first blue node.
     1176      ///
     1177      /// This function gives back the first blue node in the iteration order.
     1178      void first(BlueNode&) const {}
     1179
     1180      /// \brief Return the next blue node.
     1181      ///
     1182      /// This function gives back the next blue node in the iteration order.
     1183      void next(BlueNode&) const {}
     1184
     1185
     1186      /// @}
     1187
     1188      /// \name Class Based Iteration
     1189      ///
     1190      /// This interface provides iterator classes for red and blue nodes.
     1191      ///
     1192      /// @{
     1193
     1194      /// \brief This iterator goes through each red node.
     1195      ///
     1196      /// This iterator goes through each red node.
     1197      typedef GraphItemIt<BpGraph, RedNode> RedNodeIt;
     1198
     1199      /// \brief This iterator goes through each blue node.
     1200      ///
     1201      /// This iterator goes through each blue node.
     1202      typedef GraphItemIt<BpGraph, BlueNode> BlueNodeIt;
     1203
     1204      /// @}
     1205
     1206      template <typename _BpGraph>
     1207      struct Constraints {
     1208        void constraints() {
     1209          checkConcept<IterableGraphComponent<Base>, _BpGraph>();
     1210
     1211          typename _BpGraph::RedNode rn(INVALID);
     1212          bpgraph.first(rn);
     1213          bpgraph.next(rn);
     1214          typename _BpGraph::BlueNode bn(INVALID);
     1215          bpgraph.first(bn);
     1216          bpgraph.next(bn);
     1217
     1218          checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::RedNode>,
     1219            typename _BpGraph::RedNodeIt>();
     1220          checkConcept<GraphItemIt<_BpGraph, typename _BpGraph::BlueNode>,
     1221            typename _BpGraph::BlueNodeIt>();
     1222        }
     1223
     1224        const _BpGraph& bpgraph;
     1225      };
     1226    };
     1227
    9071228    /// \brief Skeleton class for alterable directed graphs.
    9081229    ///
     
    9301251      ArcNotifier;
    9311252
     1253      mutable NodeNotifier node_notifier;
     1254      mutable ArcNotifier arc_notifier;
     1255
    9321256      /// \brief Return the node alteration notifier.
    9331257      ///
    9341258      /// This function gives back the node alteration notifier.
    9351259      NodeNotifier& notifier(Node) const {
    936          return NodeNotifier();
     1260        return node_notifier;
    9371261      }
    9381262
     
    9411265      /// This function gives back the arc alteration notifier.
    9421266      ArcNotifier& notifier(Arc) const {
    943         return ArcNotifier();
     1267        return arc_notifier;
    9441268      }
    9451269
     
    9771301
    9781302      typedef BAS Base;
     1303      typedef AlterableDigraphComponent<Base> Parent;
    9791304      typedef typename Base::Edge Edge;
    9801305
     
    9841309      EdgeNotifier;
    9851310
     1311      mutable EdgeNotifier edge_notifier;
     1312
     1313      using Parent::notifier;
     1314
    9861315      /// \brief Return the edge alteration notifier.
    9871316      ///
    9881317      /// This function gives back the edge alteration notifier.
    9891318      EdgeNotifier& notifier(Edge) const {
    990         return EdgeNotifier();
     1319        return edge_notifier;
    9911320      }
    9921321
     
    10021331        const _Graph& graph;
    10031332        Constraints() {}
     1333      };
     1334    };
     1335
     1336    /// \brief Skeleton class for alterable undirected bipartite graphs.
     1337    ///
     1338    /// This class describes the interface of alterable undirected
     1339    /// bipartite graphs. It extends \ref AlterableGraphComponent with
     1340    /// the alteration notifier interface of bipartite graphs. It
     1341    /// implements an observer-notifier pattern for the red and blue
     1342    /// nodes. More obsevers can be registered into the notifier and
     1343    /// whenever an alteration occured in the graph all the observers
     1344    /// will be notified about it.
     1345    template <typename BAS = BaseBpGraphComponent>
     1346    class AlterableBpGraphComponent : public AlterableGraphComponent<BAS> {
     1347    public:
     1348
     1349      typedef BAS Base;
     1350      typedef AlterableGraphComponent<Base> Parent;
     1351      typedef typename Base::RedNode RedNode;
     1352      typedef typename Base::BlueNode BlueNode;
     1353
     1354
     1355      /// Red node alteration notifier class.
     1356      typedef AlterationNotifier<AlterableBpGraphComponent, RedNode>
     1357      RedNodeNotifier;
     1358
     1359      /// Blue node alteration notifier class.
     1360      typedef AlterationNotifier<AlterableBpGraphComponent, BlueNode>
     1361      BlueNodeNotifier;
     1362
     1363      mutable RedNodeNotifier red_node_notifier;
     1364      mutable BlueNodeNotifier blue_node_notifier;
     1365
     1366      using Parent::notifier;
     1367
     1368      /// \brief Return the red node alteration notifier.
     1369      ///
     1370      /// This function gives back the red node alteration notifier.
     1371      RedNodeNotifier& notifier(RedNode) const {
     1372        return red_node_notifier;
     1373      }
     1374
     1375      /// \brief Return the blue node alteration notifier.
     1376      ///
     1377      /// This function gives back the blue node alteration notifier.
     1378      BlueNodeNotifier& notifier(BlueNode) const {
     1379        return blue_node_notifier;
     1380      }
     1381
     1382      template <typename _BpGraph>
     1383      struct Constraints {
     1384        void constraints() {
     1385          checkConcept<AlterableGraphComponent<Base>, _BpGraph>();
     1386          typename _BpGraph::RedNodeNotifier& rnn
     1387            = bpgraph.notifier(typename _BpGraph::RedNode());
     1388          typename _BpGraph::BlueNodeNotifier& bnn
     1389            = bpgraph.notifier(typename _BpGraph::BlueNode());
     1390          ignore_unused_variable_warning(rnn);
     1391          ignore_unused_variable_warning(bnn);
     1392        }
     1393
     1394        const _BpGraph& bpgraph;
    10041395      };
    10051396    };
     
    13081699    };
    13091700
     1701    /// \brief Skeleton class for mappable undirected bipartite graphs.
     1702    ///
     1703    /// This class describes the interface of mappable undirected
     1704    /// bipartite graphs.  It extends \ref MappableGraphComponent with
     1705    /// the standard graph map class for red and blue nodes (\c
     1706    /// RedNodeMap and BlueNodeMap). This concept is part of the
     1707    /// BpGraph concept.
     1708    template <typename BAS = BaseBpGraphComponent>
     1709    class MappableBpGraphComponent : public MappableGraphComponent<BAS>  {
     1710    public:
     1711
     1712      typedef BAS Base;
     1713      typedef typename Base::Node Node;
     1714
     1715      typedef MappableBpGraphComponent BpGraph;
     1716
     1717      /// \brief Standard graph map for the red nodes.
     1718      ///
     1719      /// Standard graph map for the red nodes.
     1720      /// It conforms to the ReferenceMap concept.
     1721      template <typename V>
     1722      class RedNodeMap : public GraphMap<MappableBpGraphComponent, Node, V> {
     1723        typedef GraphMap<MappableBpGraphComponent, Node, V> Parent;
     1724
     1725      public:
     1726        /// \brief Construct a new map.
     1727        ///
     1728        /// Construct a new map for the graph.
     1729        explicit RedNodeMap(const MappableBpGraphComponent& graph)
     1730          : Parent(graph) {}
     1731
     1732        /// \brief Construct a new map with default value.
     1733        ///
     1734        /// Construct a new map for the graph and initalize the values.
     1735        RedNodeMap(const MappableBpGraphComponent& graph, const V& value)
     1736          : Parent(graph, value) {}
     1737
     1738      private:
     1739        /// \brief Copy constructor.
     1740        ///
     1741        /// Copy Constructor.
     1742        RedNodeMap(const RedNodeMap& nm) : Parent(nm) {}
     1743
     1744        /// \brief Assignment operator.
     1745        ///
     1746        /// Assignment operator.
     1747        template <typename CMap>
     1748        RedNodeMap& operator=(const CMap&) {
     1749          checkConcept<ReadMap<Node, V>, CMap>();
     1750          return *this;
     1751        }
     1752
     1753      };
     1754
     1755      /// \brief Standard graph map for the blue nodes.
     1756      ///
     1757      /// Standard graph map for the blue nodes.
     1758      /// It conforms to the ReferenceMap concept.
     1759      template <typename V>
     1760      class BlueNodeMap : public GraphMap<MappableBpGraphComponent, Node, V> {
     1761        typedef GraphMap<MappableBpGraphComponent, Node, V> Parent;
     1762
     1763      public:
     1764        /// \brief Construct a new map.
     1765        ///
     1766        /// Construct a new map for the graph.
     1767        explicit BlueNodeMap(const MappableBpGraphComponent& graph)
     1768          : Parent(graph) {}
     1769
     1770        /// \brief Construct a new map with default value.
     1771        ///
     1772        /// Construct a new map for the graph and initalize the values.
     1773        BlueNodeMap(const MappableBpGraphComponent& graph, const V& value)
     1774          : Parent(graph, value) {}
     1775
     1776      private:
     1777        /// \brief Copy constructor.
     1778        ///
     1779        /// Copy Constructor.
     1780        BlueNodeMap(const BlueNodeMap& nm) : Parent(nm) {}
     1781
     1782        /// \brief Assignment operator.
     1783        ///
     1784        /// Assignment operator.
     1785        template <typename CMap>
     1786        BlueNodeMap& operator=(const CMap&) {
     1787          checkConcept<ReadMap<Node, V>, CMap>();
     1788          return *this;
     1789        }
     1790
     1791      };
     1792
     1793
     1794      template <typename _BpGraph>
     1795      struct Constraints {
     1796
     1797        struct Dummy {
     1798          int value;
     1799          Dummy() : value(0) {}
     1800          Dummy(int _v) : value(_v) {}
     1801        };
     1802
     1803        void constraints() {
     1804          checkConcept<MappableGraphComponent<Base>, _BpGraph>();
     1805
     1806          { // int map test
     1807            typedef typename _BpGraph::template RedNodeMap<int>
     1808              IntRedNodeMap;
     1809            checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, int>,
     1810              IntRedNodeMap >();
     1811          } { // bool map test
     1812            typedef typename _BpGraph::template RedNodeMap<bool>
     1813              BoolRedNodeMap;
     1814            checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, bool>,
     1815              BoolRedNodeMap >();
     1816          } { // Dummy map test
     1817            typedef typename _BpGraph::template RedNodeMap<Dummy>
     1818              DummyRedNodeMap;
     1819            checkConcept<GraphMap<_BpGraph, typename _BpGraph::RedNode, Dummy>,
     1820              DummyRedNodeMap >();
     1821          }
     1822
     1823          { // int map test
     1824            typedef typename _BpGraph::template BlueNodeMap<int>
     1825              IntBlueNodeMap;
     1826            checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, int>,
     1827              IntBlueNodeMap >();
     1828          } { // bool map test
     1829            typedef typename _BpGraph::template BlueNodeMap<bool>
     1830              BoolBlueNodeMap;
     1831            checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, bool>,
     1832              BoolBlueNodeMap >();
     1833          } { // Dummy map test
     1834            typedef typename _BpGraph::template BlueNodeMap<Dummy>
     1835              DummyBlueNodeMap;
     1836            checkConcept<GraphMap<_BpGraph, typename _BpGraph::BlueNode, Dummy>,
     1837              DummyBlueNodeMap >();
     1838          }
     1839        }
     1840
     1841        const _BpGraph& bpgraph;
     1842      };
     1843    };
     1844
    13101845    /// \brief Skeleton class for extendable directed graphs.
    13111846    ///
     
    13981933    };
    13991934
     1935    /// \brief Skeleton class for extendable undirected bipartite graphs.
     1936    ///
     1937    /// This class describes the interface of extendable undirected
     1938    /// bipartite graphs. It extends \ref BaseGraphComponent with
     1939    /// functions for adding nodes and edges to the graph. This
     1940    /// concept requires \ref AlterableBpGraphComponent.
     1941    template <typename BAS = BaseBpGraphComponent>
     1942    class ExtendableBpGraphComponent : public BAS {
     1943    public:
     1944
     1945      typedef BAS Base;
     1946      typedef typename Base::Node Node;
     1947      typedef typename Base::RedNode RedNode;
     1948      typedef typename Base::BlueNode BlueNode;
     1949      typedef typename Base::Edge Edge;
     1950
     1951      /// \brief Add a new red node to the digraph.
     1952      ///
     1953      /// This function adds a red new node to the digraph.
     1954      RedNode addRedNode() {
     1955        return INVALID;
     1956      }
     1957
     1958      /// \brief Add a new blue node to the digraph.
     1959      ///
     1960      /// This function adds a blue new node to the digraph.
     1961      BlueNode addBlueNode() {
     1962        return INVALID;
     1963      }
     1964
     1965      /// \brief Add a new edge connecting the given two nodes.
     1966      ///
     1967      /// This function adds a new edge connecting the given two nodes
     1968      /// of the graph. The first node has to be a red node, and the
     1969      /// second one a blue node.
     1970      Edge addEdge(const RedNode&, const BlueNode&) {
     1971        return INVALID;
     1972      }
     1973      Edge addEdge(const BlueNode&, const RedNode&) {
     1974        return INVALID;
     1975      }
     1976
     1977      template <typename _BpGraph>
     1978      struct Constraints {
     1979        void constraints() {
     1980          checkConcept<Base, _BpGraph>();
     1981          typename _BpGraph::RedNode red_node;
     1982          typename _BpGraph::BlueNode blue_node;
     1983          red_node = bpgraph.addRedNode();
     1984          blue_node = bpgraph.addBlueNode();
     1985          typename _BpGraph::Edge edge;
     1986          edge = bpgraph.addEdge(red_node, blue_node);
     1987          edge = bpgraph.addEdge(blue_node, red_node);
     1988        }
     1989
     1990        _BpGraph& bpgraph;
     1991      };
     1992    };
     1993
    14001994    /// \brief Skeleton class for erasable directed graphs.
    14011995    ///
     
    14782072    };
    14792073
     2074    /// \brief Skeleton class for erasable undirected graphs.
     2075    ///
     2076    /// This class describes the interface of erasable undirected
     2077    /// bipartite graphs. It extends \ref BaseBpGraphComponent with
     2078    /// functions for removing nodes and edges from the graph. This
     2079    /// concept requires \ref AlterableBpGraphComponent.
     2080    template <typename BAS = BaseBpGraphComponent>
     2081    class ErasableBpGraphComponent : public ErasableGraphComponent<BAS> {};
     2082
    14802083    /// \brief Skeleton class for clearable directed graphs.
    14812084    ///
     
    15142117    /// This concept requires \ref AlterableGraphComponent.
    15152118    template <typename BAS = BaseGraphComponent>
    1516     class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {
    1517     public:
    1518 
    1519       typedef BAS Base;
    1520 
    1521       /// \brief Erase all nodes and edges from the graph.
    1522       ///
    1523       /// This function erases all nodes and edges from the graph.
    1524       void clear() {}
    1525 
    1526       template <typename _Graph>
    1527       struct Constraints {
    1528         void constraints() {
    1529           checkConcept<Base, _Graph>();
    1530           graph.clear();
    1531         }
    1532 
    1533         _Graph& graph;
    1534         Constraints() {}
    1535       };
    1536     };
     2119    class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {};
     2120
     2121    /// \brief Skeleton class for clearable undirected biparite graphs.
     2122    ///
     2123    /// This class describes the interface of clearable undirected
     2124    /// bipartite graphs. It extends \ref BaseBpGraphComponent with a
     2125    /// function for clearing the graph.  This concept requires \ref
     2126    /// AlterableBpGraphComponent.
     2127    template <typename BAS = BaseBpGraphComponent>
     2128    class ClearableBpGraphComponent : public ClearableGraphComponent<BAS> {};
    15372129
    15382130  }
  • lemon/core.h

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