lemon/concepts/bpgraph.h
author Alpar Juttner <alpar@cs.elte.hu>
Wed, 29 Jul 2020 14:56:10 +0200
changeset 1433 a278d16bd2d0
parent 1336 0759d974de81
permissions -rw-r--r--
Fix clang compilation issue (#634)
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     5  * Copyright (C) 2003-2013
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 ///\ingroup graph_concepts
    20 ///\file
    21 ///\brief The concept of undirected graphs.
    22 
    23 #ifndef LEMON_CONCEPTS_BPGRAPH_H
    24 #define LEMON_CONCEPTS_BPGRAPH_H
    25 
    26 #include <lemon/concepts/graph_components.h>
    27 #include <lemon/concepts/maps.h>
    28 #include <lemon/concept_check.h>
    29 #include <lemon/core.h>
    30 #include <lemon/bits/stl_iterators.h>
    31 
    32 namespace lemon {
    33   namespace concepts {
    34 
    35     /// \ingroup graph_concepts
    36     ///
    37     /// \brief Class describing the concept of undirected bipartite graphs.
    38     ///
    39     /// This class describes the common interface of all undirected
    40     /// bipartite graphs.
    41     ///
    42     /// Like all concept classes, it only provides an interface
    43     /// without any sensible implementation. So any general algorithm for
    44     /// undirected bipartite graphs should compile with this class,
    45     /// but it will not run properly, of course.
    46     /// An actual graph implementation like \ref ListBpGraph or
    47     /// \ref SmartBpGraph may have additional functionality.
    48     ///
    49     /// The bipartite graphs also fulfill the concept of \ref Graph
    50     /// "undirected graphs". Bipartite graphs provide a bipartition of
    51     /// the node set, namely a red and blue set of the nodes. The
    52     /// nodes can be iterated with the RedNodeIt and BlueNodeIt in the
    53     /// two node sets. With RedNodeMap and BlueNodeMap values can be
    54     /// assigned to the nodes in the two sets.
    55     ///
    56     /// The edges of the graph cannot connect two nodes of the same
    57     /// set. The edges inherent orientation is from the red nodes to
    58     /// the blue nodes.
    59     ///
    60     /// \sa Graph
    61     class BpGraph {
    62     private:
    63       /// BpGraphs are \e not copy constructible. Use bpGraphCopy instead.
    64       BpGraph(const BpGraph&) {}
    65       /// \brief Assignment of a graph to another one is \e not allowed.
    66       /// Use bpGraphCopy instead.
    67       void operator=(const BpGraph&) {}
    68 
    69     public:
    70       /// Default constructor.
    71       BpGraph() {}
    72 
    73       /// \brief Undirected graphs should be tagged with \c UndirectedTag.
    74       ///
    75       /// Undirected graphs should be tagged with \c UndirectedTag.
    76       ///
    77       /// This tag helps the \c enable_if technics to make compile time
    78       /// specializations for undirected graphs.
    79       typedef True UndirectedTag;
    80 
    81       /// The node type of the graph
    82 
    83       /// This class identifies a node of the graph. It also serves
    84       /// as a base class of the node iterators,
    85       /// thus they convert to this type.
    86       class Node {
    87       public:
    88         /// Default constructor
    89 
    90         /// Default constructor.
    91         /// \warning It sets the object to an undefined value.
    92         Node() { }
    93         /// Copy constructor.
    94 
    95         /// Copy constructor.
    96         ///
    97         Node(const Node&) { }
    98         /// Assignment operator
    99 
   100         /// Assignment operator.
   101         ///
   102         const Node &operator=(const Node&) { return *this; }
   103 
   104         /// %Invalid constructor \& conversion.
   105 
   106         /// Initializes the object to be invalid.
   107         /// \sa Invalid for more details.
   108         Node(Invalid) { }
   109         /// Equality operator
   110 
   111         /// Equality operator.
   112         ///
   113         /// Two iterators are equal if and only if they point to the
   114         /// same object or both are \c INVALID.
   115         bool operator==(Node) const { return true; }
   116 
   117         /// Inequality operator
   118 
   119         /// Inequality operator.
   120         bool operator!=(Node) const { return true; }
   121 
   122         /// Artificial ordering operator.
   123 
   124         /// Artificial ordering operator.
   125         ///
   126         /// \note This operator only has to define some strict ordering of
   127         /// the items; this order has nothing to do with the iteration
   128         /// ordering of the items.
   129         bool operator<(Node) const { return false; }
   130 
   131       };
   132 
   133       /// Class to represent red nodes.
   134 
   135       /// This class represents the red nodes of the graph. It does
   136       /// not supposed to be used directly, because the nodes can be
   137       /// represented as Node instances. This class can be used as
   138       /// template parameter for special map classes.
   139       class RedNode : public Node {
   140       public:
   141         /// Default constructor
   142 
   143         /// Default constructor.
   144         /// \warning It sets the object to an undefined value.
   145         RedNode() { }
   146         /// Copy constructor.
   147 
   148         /// Copy constructor.
   149         ///
   150         RedNode(const RedNode&) : Node() { }
   151         /// Assignment operator
   152 
   153         /// Assignment operator.
   154         ///
   155         const RedNode &operator=(const RedNode&) { return *this; }
   156 
   157         /// %Invalid constructor \& conversion.
   158 
   159         /// Initializes the object to be invalid.
   160         /// \sa Invalid for more details.
   161         RedNode(Invalid) { }
   162 
   163       };
   164 
   165       /// Class to represent blue nodes.
   166 
   167       /// This class represents the blue nodes of the graph. It does
   168       /// not supposed to be used directly, because the nodes can be
   169       /// represented as Node instances. This class can be used as
   170       /// template parameter for special map classes.
   171       class BlueNode : public Node {
   172       public:
   173         /// Default constructor
   174 
   175         /// Default constructor.
   176         /// \warning It sets the object to an undefined value.
   177         BlueNode() { }
   178         /// Copy constructor.
   179 
   180         /// Copy constructor.
   181         ///
   182         BlueNode(const BlueNode&) : Node() { }
   183         /// Assignment operator
   184 
   185         /// Assignment operator.
   186         ///
   187         const BlueNode &operator=(const BlueNode&) { return *this; }
   188 
   189 
   190         /// %Invalid constructor \& conversion.
   191 
   192         /// Initializes the object to be invalid.
   193         /// \sa Invalid for more details.
   194         BlueNode(Invalid) { }
   195 
   196       };
   197 
   198       /// Iterator class for the red nodes.
   199 
   200       /// This iterator goes through each red node of the graph.
   201       /// Its usage is quite simple, for example, you can count the number
   202       /// of red nodes in a graph \c g of type \c %BpGraph like this:
   203       ///\code
   204       /// int count=0;
   205       /// for (BpGraph::RedNodeIt n(g); n!=INVALID; ++n) ++count;
   206       ///\endcode
   207       class RedNodeIt : public RedNode {
   208       public:
   209         /// Default constructor
   210 
   211         /// Default constructor.
   212         /// \warning It sets the iterator to an undefined value.
   213         RedNodeIt() { }
   214         /// Copy constructor.
   215 
   216         /// Copy constructor.
   217         ///
   218         RedNodeIt(const RedNodeIt& n) : RedNode(n) { }
   219         /// Assignment operator
   220 
   221         /// Assignment operator.
   222         ///
   223         const RedNodeIt &operator=(const RedNodeIt&) { return *this; }
   224         /// %Invalid constructor \& conversion.
   225 
   226         /// Initializes the iterator to be invalid.
   227         /// \sa Invalid for more details.
   228         RedNodeIt(Invalid) { }
   229         /// Sets the iterator to the first red node.
   230 
   231         /// Sets the iterator to the first red node of the given
   232         /// digraph.
   233         explicit RedNodeIt(const BpGraph&) { }
   234         /// Sets the iterator to the given red node.
   235 
   236         /// Sets the iterator to the given red node of the given
   237         /// digraph.
   238         RedNodeIt(const BpGraph&, const RedNode&) { }
   239         /// Next node.
   240 
   241         /// Assign the iterator to the next red node.
   242         ///
   243         RedNodeIt& operator++() { return *this; }
   244       };
   245 
   246       /// \brief Gets the collection of the red nodes of the graph.
   247       ///
   248       /// This function can be used for iterating on
   249       /// the red nodes of the graph. It returns a wrapped RedNodeIt,
   250       /// which looks like an STL container (by having begin() and end())
   251       /// which you can use in range-based for loops, stl algorithms, etc.
   252       /// For example if g is a BpGraph, you can write:
   253       ///\code
   254       /// for(auto v: g.redNodes())
   255       ///   doSomething(v);
   256       ///\endcode
   257       LemonRangeWrapper1<RedNodeIt, BpGraph> redNodes() const {
   258         return LemonRangeWrapper1<RedNodeIt, BpGraph>(*this);
   259       }
   260 
   261 
   262       /// Iterator class for the blue nodes.
   263 
   264       /// This iterator goes through each blue node of the graph.
   265       /// Its usage is quite simple, for example, you can count the number
   266       /// of blue nodes in a graph \c g of type \c %BpGraph like this:
   267       ///\code
   268       /// int count=0;
   269       /// for (BpGraph::BlueNodeIt n(g); n!=INVALID; ++n) ++count;
   270       ///\endcode
   271       class BlueNodeIt : public BlueNode {
   272       public:
   273         /// Default constructor
   274 
   275         /// Default constructor.
   276         /// \warning It sets the iterator to an undefined value.
   277         BlueNodeIt() { }
   278         /// Copy constructor.
   279 
   280         /// Copy constructor.
   281         ///
   282         BlueNodeIt(const BlueNodeIt& n) : BlueNode(n) { }
   283         /// Assignment operator
   284 
   285         /// Assignment operator.
   286         ///
   287         const BlueNodeIt &operator=(const BlueNodeIt&) { return *this; }
   288         /// %Invalid constructor \& conversion.
   289 
   290         /// Initializes the iterator to be invalid.
   291         /// \sa Invalid for more details.
   292         BlueNodeIt(Invalid) { }
   293         /// Sets the iterator to the first blue node.
   294 
   295         /// Sets the iterator to the first blue node of the given
   296         /// digraph.
   297         explicit BlueNodeIt(const BpGraph&) { }
   298         /// Sets the iterator to the given blue node.
   299 
   300         /// Sets the iterator to the given blue node of the given
   301         /// digraph.
   302         BlueNodeIt(const BpGraph&, const BlueNode&) { }
   303         /// Next node.
   304 
   305         /// Assign the iterator to the next blue node.
   306         ///
   307         BlueNodeIt& operator++() { return *this; }
   308       };
   309 
   310       /// \brief Gets the collection of the blue nodes of the graph.
   311       ///
   312       /// This function can be used for iterating on
   313       /// the blue nodes of the graph. It returns a wrapped BlueNodeIt,
   314       /// which looks like an STL container (by having begin() and end())
   315       /// which you can use in range-based for loops, stl algorithms, etc.
   316       /// For example if g is a BpGraph, you can write:
   317       ///\code
   318       /// for(auto v: g.blueNodes())
   319       ///   doSomething(v);
   320       ///\endcode
   321       LemonRangeWrapper1<BlueNodeIt, BpGraph> blueNodes() const {
   322         return LemonRangeWrapper1<BlueNodeIt, BpGraph>(*this);
   323       }
   324 
   325 
   326       /// Iterator class for the nodes.
   327 
   328       /// This iterator goes through each node of the graph.
   329       /// Its usage is quite simple, for example, you can count the number
   330       /// of nodes in a graph \c g of type \c %BpGraph like this:
   331       ///\code
   332       /// int count=0;
   333       /// for (BpGraph::NodeIt n(g); n!=INVALID; ++n) ++count;
   334       ///\endcode
   335       class NodeIt : public Node {
   336       public:
   337         /// Default constructor
   338 
   339         /// Default constructor.
   340         /// \warning It sets the iterator to an undefined value.
   341         NodeIt() { }
   342         /// Copy constructor.
   343 
   344         /// Copy constructor.
   345         ///
   346         NodeIt(const NodeIt& n) : Node(n) { }
   347         /// Assignment operator
   348 
   349         /// Assignment operator.
   350         ///
   351         const NodeIt &operator=(const NodeIt&) { return *this; }
   352         /// %Invalid constructor \& conversion.
   353 
   354         /// Initializes the iterator to be invalid.
   355         /// \sa Invalid for more details.
   356         NodeIt(Invalid) { }
   357         /// Sets the iterator to the first node.
   358 
   359         /// Sets the iterator to the first node of the given digraph.
   360         ///
   361         explicit NodeIt(const BpGraph&) { }
   362         /// Sets the iterator to the given node.
   363 
   364         /// Sets the iterator to the given node of the given digraph.
   365         ///
   366         NodeIt(const BpGraph&, const Node&) { }
   367         /// Next node.
   368 
   369         /// Assign the iterator to the next node.
   370         ///
   371         NodeIt& operator++() { return *this; }
   372       };
   373 
   374       /// \brief Gets the collection of the nodes of the graph.
   375       ///
   376       /// This function can be used for iterating on
   377       /// the nodes of the graph. It returns a wrapped NodeIt,
   378       /// which looks like an STL container (by having begin() and end())
   379       /// which you can use in range-based for loops, stl algorithms, etc.
   380       /// For example if g is a BpGraph, you can write:
   381       ///\code
   382       /// for(auto v: g.nodes())
   383       ///   doSomething(v);
   384       ///\endcode
   385       LemonRangeWrapper1<NodeIt, BpGraph> nodes() const {
   386         return LemonRangeWrapper1<NodeIt, BpGraph>(*this);
   387       }
   388 
   389 
   390 
   391       /// The edge type of the graph
   392 
   393       /// This class identifies an edge of the graph. It also serves
   394       /// as a base class of the edge iterators,
   395       /// thus they will convert to this type.
   396       class Edge {
   397       public:
   398         /// Default constructor
   399 
   400         /// Default constructor.
   401         /// \warning It sets the object to an undefined value.
   402         Edge() { }
   403         /// Copy constructor.
   404 
   405         /// Copy constructor.
   406         ///
   407         Edge(const Edge&) { }
   408         /// Assignment operator
   409 
   410         /// Assignment operator.
   411         ///
   412         const Edge &operator=(const Edge&) { return *this; }
   413         /// %Invalid constructor \& conversion.
   414 
   415         /// Initializes the object to be invalid.
   416         /// \sa Invalid for more details.
   417         Edge(Invalid) { }
   418         /// Equality operator
   419 
   420         /// Equality operator.
   421         ///
   422         /// Two iterators are equal if and only if they point to the
   423         /// same object or both are \c INVALID.
   424         bool operator==(Edge) const { return true; }
   425         /// Inequality operator
   426 
   427         /// Inequality operator.
   428         bool operator!=(Edge) const { return true; }
   429 
   430         /// Artificial ordering operator.
   431 
   432         /// Artificial ordering operator.
   433         ///
   434         /// \note This operator only has to define some strict ordering of
   435         /// the edges; this order has nothing to do with the iteration
   436         /// ordering of the edges.
   437         bool operator<(Edge) const { return false; }
   438       };
   439 
   440       /// Iterator class for the edges.
   441 
   442       /// This iterator goes through each edge of the graph.
   443       /// Its usage is quite simple, for example, you can count the number
   444       /// of edges in a graph \c g of type \c %BpGraph as follows:
   445       ///\code
   446       /// int count=0;
   447       /// for(BpGraph::EdgeIt e(g); e!=INVALID; ++e) ++count;
   448       ///\endcode
   449       class EdgeIt : public Edge {
   450       public:
   451         /// Default constructor
   452 
   453         /// Default constructor.
   454         /// \warning It sets the iterator to an undefined value.
   455         EdgeIt() { }
   456         /// Copy constructor.
   457 
   458         /// Copy constructor.
   459         ///
   460         EdgeIt(const EdgeIt& e) : Edge(e) { }
   461         /// Assignment operator
   462 
   463         /// Assignment operator.
   464         ///
   465         const EdgeIt &operator=(const EdgeIt&) { return *this; }
   466         /// %Invalid constructor \& conversion.
   467 
   468         /// Initializes the iterator to be invalid.
   469         /// \sa Invalid for more details.
   470         EdgeIt(Invalid) { }
   471         /// Sets the iterator to the first edge.
   472 
   473         /// Sets the iterator to the first edge of the given graph.
   474         ///
   475         explicit EdgeIt(const BpGraph&) { }
   476         /// Sets the iterator to the given edge.
   477 
   478         /// Sets the iterator to the given edge of the given graph.
   479         ///
   480         EdgeIt(const BpGraph&, const Edge&) { }
   481         /// Next edge
   482 
   483         /// Assign the iterator to the next edge.
   484         ///
   485         EdgeIt& operator++() { return *this; }
   486       };
   487 
   488       /// \brief Gets the collection of the edges of the graph.
   489       ///
   490       /// This function can be used for iterating on the
   491       /// edges of the graph. It returns a wrapped
   492       /// EdgeIt, which looks like an STL container
   493       /// (by having begin() and end()) which you can use in range-based
   494       /// for loops, stl algorithms, etc.
   495       /// For example if g is a BpGraph, you can write:
   496       ///\code
   497       /// for(auto e: g.edges())
   498       ///   doSomething(e);
   499       ///\endcode
   500       LemonRangeWrapper1<EdgeIt, BpGraph> edges() const {
   501         return LemonRangeWrapper1<EdgeIt, BpGraph>(*this);
   502       }
   503 
   504 
   505       /// Iterator class for the incident edges of a node.
   506 
   507       /// This iterator goes trough the incident undirected edges
   508       /// of a certain node of a graph.
   509       /// Its usage is quite simple, for example, you can compute the
   510       /// degree (i.e. the number of incident edges) of a node \c n
   511       /// in a graph \c g of type \c %BpGraph as follows.
   512       ///
   513       ///\code
   514       /// int count=0;
   515       /// for(BpGraph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
   516       ///\endcode
   517       ///
   518       /// \warning Loop edges will be iterated twice.
   519       class IncEdgeIt : public Edge {
   520       public:
   521         /// Default constructor
   522 
   523         /// Default constructor.
   524         /// \warning It sets the iterator to an undefined value.
   525         IncEdgeIt() { }
   526         /// Copy constructor.
   527 
   528         /// Copy constructor.
   529         ///
   530         IncEdgeIt(const IncEdgeIt& e) : Edge(e) { }
   531         /// Assignment operator
   532 
   533         /// Assignment operator.
   534         ///
   535         const IncEdgeIt &operator=(const IncEdgeIt&) { return *this; }
   536         /// %Invalid constructor \& conversion.
   537 
   538         /// Initializes the iterator to be invalid.
   539         /// \sa Invalid for more details.
   540         IncEdgeIt(Invalid) { }
   541         /// Sets the iterator to the first incident edge.
   542 
   543         /// Sets the iterator to the first incident edge of the given node.
   544         ///
   545         IncEdgeIt(const BpGraph&, const Node&) { }
   546         /// Sets the iterator to the given edge.
   547 
   548         /// Sets the iterator to the given edge of the given graph.
   549         ///
   550         IncEdgeIt(const BpGraph&, const Edge&) { }
   551         /// Next incident edge
   552 
   553         /// Assign the iterator to the next incident edge
   554         /// of the corresponding node.
   555         IncEdgeIt& operator++() { return *this; }
   556       };
   557 
   558       /// \brief Gets the collection of the incident edges
   559       ///  of a certain node of the graph.
   560       ///
   561       /// This function can be used for iterating on the
   562       /// incident undirected edges of a certain node of the graph.
   563       /// It returns a wrapped
   564       /// IncEdgeIt, which looks like an STL container
   565       /// (by having begin() and end()) which you can use in range-based
   566       /// for loops, stl algorithms, etc.
   567       /// For example if g is a BpGraph and u is a Node, you can write:
   568       ///\code
   569       /// for(auto e: g.incEdges(u))
   570       ///   doSomething(e);
   571       ///\endcode
   572       LemonRangeWrapper2<IncEdgeIt, BpGraph, Node> incEdges(const Node& u) const {
   573         return LemonRangeWrapper2<IncEdgeIt, BpGraph, Node>(*this, u);
   574       }
   575 
   576 
   577       /// The arc type of the graph
   578 
   579       /// This class identifies a directed arc of the graph. It also serves
   580       /// as a base class of the arc iterators,
   581       /// thus they will convert to this type.
   582       class Arc {
   583       public:
   584         /// Default constructor
   585 
   586         /// Default constructor.
   587         /// \warning It sets the object to an undefined value.
   588         Arc() { }
   589         /// Copy constructor.
   590 
   591         /// Copy constructor.
   592         ///
   593         Arc(const Arc&) { }
   594         /// Assignment operator
   595 
   596         /// Assignment operator.
   597         ///
   598         const Arc &operator=(const Arc&) { return *this; }
   599         /// %Invalid constructor \& conversion.
   600 
   601         /// Initializes the object to be invalid.
   602         /// \sa Invalid for more details.
   603         Arc(Invalid) { }
   604         /// Equality operator
   605 
   606         /// Equality operator.
   607         ///
   608         /// Two iterators are equal if and only if they point to the
   609         /// same object or both are \c INVALID.
   610         bool operator==(Arc) const { return true; }
   611         /// Inequality operator
   612 
   613         /// Inequality operator.
   614         bool operator!=(Arc) const { return true; }
   615 
   616         /// Artificial ordering operator.
   617 
   618         /// Artificial ordering operator.
   619         ///
   620         /// \note This operator only has to define some strict ordering of
   621         /// the arcs; this order has nothing to do with the iteration
   622         /// ordering of the arcs.
   623         bool operator<(Arc) const { return false; }
   624 
   625         /// Converison to \c Edge
   626 
   627         /// Converison to \c Edge.
   628         ///
   629         operator Edge() const { return Edge(); }
   630       };
   631 
   632       /// Iterator class for the arcs.
   633 
   634       /// This iterator goes through each directed arc of the graph.
   635       /// Its usage is quite simple, for example, you can count the number
   636       /// of arcs in a graph \c g of type \c %BpGraph as follows:
   637       ///\code
   638       /// int count=0;
   639       /// for(BpGraph::ArcIt a(g); a!=INVALID; ++a) ++count;
   640       ///\endcode
   641       class ArcIt : public Arc {
   642       public:
   643         /// Default constructor
   644 
   645         /// Default constructor.
   646         /// \warning It sets the iterator to an undefined value.
   647         ArcIt() { }
   648         /// Copy constructor.
   649 
   650         /// Copy constructor.
   651         ///
   652         ArcIt(const ArcIt& e) : Arc(e) { }
   653         /// Assignment operator
   654 
   655         /// Assignment operator.
   656         ///
   657         const ArcIt &operator=(const ArcIt&) { return *this; }
   658         /// %Invalid constructor \& conversion.
   659 
   660         /// Initializes the iterator to be invalid.
   661         /// \sa Invalid for more details.
   662         ArcIt(Invalid) { }
   663         /// Sets the iterator to the first arc.
   664 
   665         /// Sets the iterator to the first arc of the given graph.
   666         ///
   667         explicit ArcIt(const BpGraph &g)
   668         {
   669           ::lemon::ignore_unused_variable_warning(g);
   670         }
   671         /// Sets the iterator to the given arc.
   672 
   673         /// Sets the iterator to the given arc of the given graph.
   674         ///
   675         ArcIt(const BpGraph&, const Arc&) { }
   676         /// Next arc
   677 
   678         /// Assign the iterator to the next arc.
   679         ///
   680         ArcIt& operator++() { return *this; }
   681       };
   682 
   683       /// \brief Gets the collection of the directed arcs of the graph.
   684       ///
   685       /// This function can be used for iterating on the
   686       /// arcs of the graph. It returns a wrapped
   687       /// ArcIt, which looks like an STL container
   688       /// (by having begin() and end()) which you can use in range-based
   689       /// for loops, stl algorithms, etc.
   690       /// For example if g is a BpGraph you can write:
   691       ///\code
   692       /// for(auto a: g.arcs())
   693       ///   doSomething(a);
   694       ///\endcode
   695       LemonRangeWrapper1<ArcIt, BpGraph> arcs() const {
   696         return LemonRangeWrapper1<ArcIt, BpGraph>(*this);
   697       }
   698 
   699 
   700       /// Iterator class for the outgoing arcs of a node.
   701 
   702       /// This iterator goes trough the \e outgoing directed arcs of a
   703       /// certain node of a graph.
   704       /// Its usage is quite simple, for example, you can count the number
   705       /// of outgoing arcs of a node \c n
   706       /// in a graph \c g of type \c %BpGraph as follows.
   707       ///\code
   708       /// int count=0;
   709       /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
   710       ///\endcode
   711       class OutArcIt : public Arc {
   712       public:
   713         /// Default constructor
   714 
   715         /// Default constructor.
   716         /// \warning It sets the iterator to an undefined value.
   717         OutArcIt() { }
   718         /// Copy constructor.
   719 
   720         /// Copy constructor.
   721         ///
   722         OutArcIt(const OutArcIt& e) : Arc(e) { }
   723         /// Assignment operator
   724 
   725         /// Assignment operator.
   726         ///
   727         const OutArcIt &operator=(const OutArcIt&) { return *this; }
   728         /// %Invalid constructor \& conversion.
   729 
   730         /// Initializes the iterator to be invalid.
   731         /// \sa Invalid for more details.
   732         OutArcIt(Invalid) { }
   733         /// Sets the iterator to the first outgoing arc.
   734 
   735         /// Sets the iterator to the first outgoing arc of the given node.
   736         ///
   737         OutArcIt(const BpGraph& n, const Node& g) {
   738           ::lemon::ignore_unused_variable_warning(n);
   739           ::lemon::ignore_unused_variable_warning(g);
   740         }
   741         /// Sets the iterator to the given arc.
   742 
   743         /// Sets the iterator to the given arc of the given graph.
   744         ///
   745         OutArcIt(const BpGraph&, const Arc&) { }
   746         /// Next outgoing arc
   747 
   748         /// Assign the iterator to the next
   749         /// outgoing arc of the corresponding node.
   750         OutArcIt& operator++() { return *this; }
   751       };
   752 
   753       /// \brief Gets the collection of the outgoing directed arcs of a
   754       /// certain node of the graph.
   755       ///
   756       /// This function can be used for iterating on the
   757       /// outgoing arcs of a certain node of the graph. It returns a wrapped
   758       /// OutArcIt, which looks like an STL container
   759       /// (by having begin() and end()) which you can use in range-based
   760       /// for loops, stl algorithms, etc.
   761       /// For example if g is a BpGraph and u is a Node, you can write:
   762       ///\code
   763       /// for(auto a: g.outArcs(u))
   764       ///   doSomething(a);
   765       ///\endcode
   766       LemonRangeWrapper2<OutArcIt, BpGraph, Node> outArcs(const Node& u) const {
   767         return LemonRangeWrapper2<OutArcIt, BpGraph, Node>(*this, u);
   768       }
   769 
   770 
   771       /// Iterator class for the incoming arcs of a node.
   772 
   773       /// This iterator goes trough the \e incoming directed arcs of a
   774       /// certain node of a graph.
   775       /// Its usage is quite simple, for example, you can count the number
   776       /// of incoming arcs of a node \c n
   777       /// in a graph \c g of type \c %BpGraph as follows.
   778       ///\code
   779       /// int count=0;
   780       /// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
   781       ///\endcode
   782       class InArcIt : public Arc {
   783       public:
   784         /// Default constructor
   785 
   786         /// Default constructor.
   787         /// \warning It sets the iterator to an undefined value.
   788         InArcIt() { }
   789         /// Copy constructor.
   790 
   791         /// Copy constructor.
   792         ///
   793         InArcIt(const InArcIt& e) : Arc(e) { }
   794         /// Assignment operator
   795 
   796         /// Assignment operator.
   797         ///
   798         const InArcIt &operator=(const InArcIt&) { return *this; }
   799         /// %Invalid constructor \& conversion.
   800 
   801         /// Initializes the iterator to be invalid.
   802         /// \sa Invalid for more details.
   803         InArcIt(Invalid) { }
   804         /// Sets the iterator to the first incoming arc.
   805 
   806         /// Sets the iterator to the first incoming arc of the given node.
   807         ///
   808         InArcIt(const BpGraph& g, const Node& n) {
   809           ::lemon::ignore_unused_variable_warning(n);
   810           ::lemon::ignore_unused_variable_warning(g);
   811         }
   812         /// Sets the iterator to the given arc.
   813 
   814         /// Sets the iterator to the given arc of the given graph.
   815         ///
   816         InArcIt(const BpGraph&, const Arc&) { }
   817         /// Next incoming arc
   818 
   819         /// Assign the iterator to the next
   820         /// incoming arc of the corresponding node.
   821         InArcIt& operator++() { return *this; }
   822       };
   823 
   824       /// \brief Gets the collection of the incoming directed arcs of a
   825       /// certain node of the graph.
   826       ///
   827       /// This function can be used for iterating on the
   828       /// incoming arcs of a certain node of the graph. It returns a wrapped
   829       /// InArcIt, which looks like an STL container
   830       /// (by having begin() and end()) which you can use in range-based
   831       /// for loops, stl algorithms, etc.
   832       /// For example if g is a BpGraph and u is a Node, you can write:
   833       ///\code
   834       /// for(auto a: g.inArcs(u))
   835       ///   doSomething(a);
   836       ///\endcode
   837       LemonRangeWrapper2<InArcIt, BpGraph, Node> inArcs(const Node& u) const {
   838         return LemonRangeWrapper2<InArcIt, BpGraph, Node>(*this, u);
   839       }
   840 
   841 
   842       /// \brief Standard graph map type for the nodes.
   843       ///
   844       /// Standard graph map type for the nodes.
   845       /// It conforms to the ReferenceMap concept.
   846       template<class T>
   847       class NodeMap : public ReferenceMap<Node, T, T&, const T&>
   848       {
   849       public:
   850 
   851         /// Constructor
   852         explicit NodeMap(const BpGraph&) { }
   853         /// Constructor with given initial value
   854         NodeMap(const BpGraph&, T) { }
   855 
   856       private:
   857         ///Copy constructor
   858         NodeMap(const NodeMap& nm) :
   859           ReferenceMap<Node, T, T&, const T&>(nm) { }
   860         ///Assignment operator
   861         template <typename CMap>
   862         NodeMap& operator=(const CMap&) {
   863           checkConcept<ReadMap<Node, T>, CMap>();
   864           return *this;
   865         }
   866       };
   867 
   868       /// \brief Standard graph map type for the red nodes.
   869       ///
   870       /// Standard graph map type for the red nodes.
   871       /// It conforms to the ReferenceMap concept.
   872       template<class T>
   873       class RedNodeMap : public ReferenceMap<Node, T, T&, const T&>
   874       {
   875       public:
   876 
   877         /// Constructor
   878         explicit RedNodeMap(const BpGraph&) { }
   879         /// Constructor with given initial value
   880         RedNodeMap(const BpGraph&, T) { }
   881 
   882       private:
   883         ///Copy constructor
   884         RedNodeMap(const RedNodeMap& nm) :
   885           ReferenceMap<Node, T, T&, const T&>(nm) { }
   886         ///Assignment operator
   887         template <typename CMap>
   888         RedNodeMap& operator=(const CMap&) {
   889           checkConcept<ReadMap<Node, T>, CMap>();
   890           return *this;
   891         }
   892       };
   893 
   894       /// \brief Standard graph map type for the blue nodes.
   895       ///
   896       /// Standard graph map type for the blue nodes.
   897       /// It conforms to the ReferenceMap concept.
   898       template<class T>
   899       class BlueNodeMap : public ReferenceMap<Node, T, T&, const T&>
   900       {
   901       public:
   902 
   903         /// Constructor
   904         explicit BlueNodeMap(const BpGraph&) { }
   905         /// Constructor with given initial value
   906         BlueNodeMap(const BpGraph&, T) { }
   907 
   908       private:
   909         ///Copy constructor
   910         BlueNodeMap(const BlueNodeMap& nm) :
   911           ReferenceMap<Node, T, T&, const T&>(nm) { }
   912         ///Assignment operator
   913         template <typename CMap>
   914         BlueNodeMap& operator=(const CMap&) {
   915           checkConcept<ReadMap<Node, T>, CMap>();
   916           return *this;
   917         }
   918       };
   919 
   920       /// \brief Standard graph map type for the arcs.
   921       ///
   922       /// Standard graph map type for the arcs.
   923       /// It conforms to the ReferenceMap concept.
   924       template<class T>
   925       class ArcMap : public ReferenceMap<Arc, T, T&, const T&>
   926       {
   927       public:
   928 
   929         /// Constructor
   930         explicit ArcMap(const BpGraph&) { }
   931         /// Constructor with given initial value
   932         ArcMap(const BpGraph&, T) { }
   933 
   934       private:
   935         ///Copy constructor
   936         ArcMap(const ArcMap& em) :
   937           ReferenceMap<Arc, T, T&, const T&>(em) { }
   938         ///Assignment operator
   939         template <typename CMap>
   940         ArcMap& operator=(const CMap&) {
   941           checkConcept<ReadMap<Arc, T>, CMap>();
   942           return *this;
   943         }
   944       };
   945 
   946       /// \brief Standard graph map type for the edges.
   947       ///
   948       /// Standard graph map type for the edges.
   949       /// It conforms to the ReferenceMap concept.
   950       template<class T>
   951       class EdgeMap : public ReferenceMap<Edge, T, T&, const T&>
   952       {
   953       public:
   954 
   955         /// Constructor
   956         explicit EdgeMap(const BpGraph&) { }
   957         /// Constructor with given initial value
   958         EdgeMap(const BpGraph&, T) { }
   959 
   960       private:
   961         ///Copy constructor
   962         EdgeMap(const EdgeMap& em) :
   963           ReferenceMap<Edge, T, T&, const T&>(em) {}
   964         ///Assignment operator
   965         template <typename CMap>
   966         EdgeMap& operator=(const CMap&) {
   967           checkConcept<ReadMap<Edge, T>, CMap>();
   968           return *this;
   969         }
   970       };
   971 
   972       /// \brief Gives back %true for red nodes.
   973       ///
   974       /// Gives back %true for red nodes.
   975       bool red(const Node&) const { return true; }
   976 
   977       /// \brief Gives back %true for blue nodes.
   978       ///
   979       /// Gives back %true for blue nodes.
   980       bool blue(const Node&) const { return true; }
   981 
   982       /// \brief Converts the node to red node object.
   983       ///
   984       /// This function converts unsafely the node to red node
   985       /// object. It should be called only if the node is from the red
   986       /// partition or INVALID.
   987       RedNode asRedNodeUnsafe(const Node&) const { return RedNode(); }
   988 
   989       /// \brief Converts the node to blue node object.
   990       ///
   991       /// This function converts unsafely the node to blue node
   992       /// object. It should be called only if the node is from the red
   993       /// partition or INVALID.
   994       BlueNode asBlueNodeUnsafe(const Node&) const { return BlueNode(); }
   995 
   996       /// \brief Converts the node to red node object.
   997       ///
   998       /// This function converts safely the node to red node
   999       /// object. If the node is not from the red partition, then it
  1000       /// returns INVALID.
  1001       RedNode asRedNode(const Node&) const { return RedNode(); }
  1002 
  1003       /// \brief Converts the node to blue node object.
  1004       ///
  1005       /// This function converts unsafely the node to blue node
  1006       /// object. If the node is not from the blue partition, then it
  1007       /// returns INVALID.
  1008       BlueNode asBlueNode(const Node&) const { return BlueNode(); }
  1009 
  1010       /// \brief Gives back the red end node of the edge.
  1011       ///
  1012       /// Gives back the red end node of the edge.
  1013       RedNode redNode(const Edge&) const { return RedNode(); }
  1014 
  1015       /// \brief Gives back the blue end node of the edge.
  1016       ///
  1017       /// Gives back the blue end node of the edge.
  1018       BlueNode blueNode(const Edge&) const { return BlueNode(); }
  1019 
  1020       /// \brief The first node of the edge.
  1021       ///
  1022       /// It is a synonim for the \c redNode().
  1023       Node u(Edge) const { return INVALID; }
  1024 
  1025       /// \brief The second node of the edge.
  1026       ///
  1027       /// It is a synonim for the \c blueNode().
  1028       Node v(Edge) const { return INVALID; }
  1029 
  1030       /// \brief The source node of the arc.
  1031       ///
  1032       /// Returns the source node of the given arc.
  1033       Node source(Arc) const { return INVALID; }
  1034 
  1035       /// \brief The target node of the arc.
  1036       ///
  1037       /// Returns the target node of the given arc.
  1038       Node target(Arc) const { return INVALID; }
  1039 
  1040       /// \brief The ID of the node.
  1041       ///
  1042       /// Returns the ID of the given node.
  1043       int id(Node) const { return -1; }
  1044 
  1045       /// \brief The red ID of the node.
  1046       ///
  1047       /// Returns the red ID of the given node.
  1048       int id(RedNode) const { return -1; }
  1049 
  1050       /// \brief The blue ID of the node.
  1051       ///
  1052       /// Returns the blue ID of the given node.
  1053       int id(BlueNode) const { return -1; }
  1054 
  1055       /// \brief The ID of the edge.
  1056       ///
  1057       /// Returns the ID of the given edge.
  1058       int id(Edge) const { return -1; }
  1059 
  1060       /// \brief The ID of the arc.
  1061       ///
  1062       /// Returns the ID of the given arc.
  1063       int id(Arc) const { return -1; }
  1064 
  1065       /// \brief The node with the given ID.
  1066       ///
  1067       /// Returns the node with the given ID.
  1068       /// \pre The argument should be a valid node ID in the graph.
  1069       Node nodeFromId(int) const { return INVALID; }
  1070 
  1071       /// \brief The edge with the given ID.
  1072       ///
  1073       /// Returns the edge with the given ID.
  1074       /// \pre The argument should be a valid edge ID in the graph.
  1075       Edge edgeFromId(int) const { return INVALID; }
  1076 
  1077       /// \brief The arc with the given ID.
  1078       ///
  1079       /// Returns the arc with the given ID.
  1080       /// \pre The argument should be a valid arc ID in the graph.
  1081       Arc arcFromId(int) const { return INVALID; }
  1082 
  1083       /// \brief An upper bound on the node IDs.
  1084       ///
  1085       /// Returns an upper bound on the node IDs.
  1086       int maxNodeId() const { return -1; }
  1087 
  1088       /// \brief An upper bound on the red IDs.
  1089       ///
  1090       /// Returns an upper bound on the red IDs.
  1091       int maxRedId() const { return -1; }
  1092 
  1093       /// \brief An upper bound on the blue IDs.
  1094       ///
  1095       /// Returns an upper bound on the blue IDs.
  1096       int maxBlueId() const { return -1; }
  1097 
  1098       /// \brief An upper bound on the edge IDs.
  1099       ///
  1100       /// Returns an upper bound on the edge IDs.
  1101       int maxEdgeId() const { return -1; }
  1102 
  1103       /// \brief An upper bound on the arc IDs.
  1104       ///
  1105       /// Returns an upper bound on the arc IDs.
  1106       int maxArcId() const { return -1; }
  1107 
  1108       /// \brief The direction of the arc.
  1109       ///
  1110       /// Returns \c true if the given arc goes from a red node to a blue node.
  1111       bool direction(Arc) const { return true; }
  1112 
  1113       /// \brief Direct the edge.
  1114       ///
  1115       /// Direct the given edge. The returned arc
  1116       /// represents the given edge and its direction comes
  1117       /// from the bool parameter. If it is \c true, then the source of the node
  1118       /// will be a red node.
  1119       Arc direct(Edge, bool) const {
  1120         return INVALID;
  1121       }
  1122 
  1123       /// \brief Direct the edge.
  1124       ///
  1125       /// Direct the given edge. The returned arc represents the given
  1126       /// edge and its source node is the given node.
  1127       Arc direct(Edge, Node) const {
  1128         return INVALID;
  1129       }
  1130 
  1131       /// \brief The oppositely directed arc.
  1132       ///
  1133       /// Returns the oppositely directed arc representing the same edge.
  1134       Arc oppositeArc(Arc) const { return INVALID; }
  1135 
  1136       /// \brief The opposite node on the edge.
  1137       ///
  1138       /// Returns the opposite node on the given edge.
  1139       Node oppositeNode(Node, Edge) const { return INVALID; }
  1140 
  1141       void first(Node&) const {}
  1142       void next(Node&) const {}
  1143 
  1144       void firstRed(RedNode&) const {}
  1145       void nextRed(RedNode&) const {}
  1146 
  1147       void firstBlue(BlueNode&) const {}
  1148       void nextBlue(BlueNode&) const {}
  1149 
  1150       void first(Edge&) const {}
  1151       void next(Edge&) const {}
  1152 
  1153       void first(Arc&) const {}
  1154       void next(Arc&) const {}
  1155 
  1156       void firstOut(Arc&, Node) const {}
  1157       void nextOut(Arc&) const {}
  1158 
  1159       void firstIn(Arc&, Node) const {}
  1160       void nextIn(Arc&) const {}
  1161 
  1162       void firstInc(Edge &, bool &, const Node &) const {}
  1163       void nextInc(Edge &, bool &) const {}
  1164 
  1165       // The second parameter is dummy.
  1166       Node fromId(int, Node) const { return INVALID; }
  1167       // The second parameter is dummy.
  1168       Edge fromId(int, Edge) const { return INVALID; }
  1169       // The second parameter is dummy.
  1170       Arc fromId(int, Arc) const { return INVALID; }
  1171 
  1172       // Dummy parameter.
  1173       int maxId(Node) const { return -1; }
  1174       // Dummy parameter.
  1175       int maxId(RedNode) const { return -1; }
  1176       // Dummy parameter.
  1177       int maxId(BlueNode) const { return -1; }
  1178       // Dummy parameter.
  1179       int maxId(Edge) const { return -1; }
  1180       // Dummy parameter.
  1181       int maxId(Arc) const { return -1; }
  1182 
  1183       /// \brief The base node of the iterator.
  1184       ///
  1185       /// Returns the base node of the given incident edge iterator.
  1186       Node baseNode(IncEdgeIt) const { return INVALID; }
  1187 
  1188       /// \brief The running node of the iterator.
  1189       ///
  1190       /// Returns the running node of the given incident edge iterator.
  1191       Node runningNode(IncEdgeIt) const { return INVALID; }
  1192 
  1193       /// \brief The base node of the iterator.
  1194       ///
  1195       /// Returns the base node of the given outgoing arc iterator
  1196       /// (i.e. the source node of the corresponding arc).
  1197       Node baseNode(OutArcIt) const { return INVALID; }
  1198 
  1199       /// \brief The running node of the iterator.
  1200       ///
  1201       /// Returns the running node of the given outgoing arc iterator
  1202       /// (i.e. the target node of the corresponding arc).
  1203       Node runningNode(OutArcIt) const { return INVALID; }
  1204 
  1205       /// \brief The base node of the iterator.
  1206       ///
  1207       /// Returns the base node of the given incoming arc iterator
  1208       /// (i.e. the target node of the corresponding arc).
  1209       Node baseNode(InArcIt) const { return INVALID; }
  1210 
  1211       /// \brief The running node of the iterator.
  1212       ///
  1213       /// Returns the running node of the given incoming arc iterator
  1214       /// (i.e. the source node of the corresponding arc).
  1215       Node runningNode(InArcIt) const { return INVALID; }
  1216 
  1217       template <typename _BpGraph>
  1218       struct Constraints {
  1219         void constraints() {
  1220           checkConcept<BaseBpGraphComponent, _BpGraph>();
  1221           checkConcept<IterableBpGraphComponent<>, _BpGraph>();
  1222           checkConcept<IDableBpGraphComponent<>, _BpGraph>();
  1223           checkConcept<MappableBpGraphComponent<>, _BpGraph>();
  1224         }
  1225       };
  1226 
  1227     };
  1228 
  1229   }
  1230 
  1231 }
  1232 
  1233 #endif