1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
 
     3  * This file is a part of LEMON, a generic C++ optimization library.
 
     5  * Copyright (C) 2003-2009
 
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
 
     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.
 
    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
 
    19 ///\ingroup graph_concepts
 
    21 ///\brief The concept of graph components.
 
    23 #ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H
 
    24 #define LEMON_CONCEPTS_GRAPH_COMPONENTS_H
 
    26 #include <lemon/core.h>
 
    27 #include <lemon/concepts/maps.h>
 
    29 #include <lemon/bits/alteration_notifier.h>
 
    34     /// \brief Skeleton class for graph Node and Arc types
 
    36     /// This class describes the interface of Node and Arc (and Edge
 
    37     /// in undirected graphs) subtypes of graph types.
 
    39     /// \note This class is a template class so that we can use it to
 
    40     /// create graph skeleton classes. The reason for this is than Node
 
    41     /// and Arc types should \em not derive from the same base class.
 
    42     /// For Node you should instantiate it with character 'n' and for Arc
 
    46     template <char sel = '0'>
 
    50       /// \brief Default constructor.
 
    52       /// \warning The default constructor is not required to set
 
    53       /// the item to some well-defined value. So you should consider it
 
    56       /// \brief Copy constructor.
 
    60       GraphItem(const GraphItem &) {}
 
    61       /// \brief Invalid constructor \& conversion.
 
    63       /// This constructor initializes the item to be invalid.
 
    64       /// \sa Invalid for more details.
 
    66       /// \brief Assign operator for nodes.
 
    68       /// The nodes are assignable.
 
    70       GraphItem& operator=(GraphItem const&) { return *this; }
 
    71       /// \brief Equality operator.
 
    73       /// Two iterators are equal if and only if they represents the
 
    74       /// same node in the graph or both are invalid.
 
    75       bool operator==(GraphItem) const { return false; }
 
    76       /// \brief Inequality operator.
 
    78       /// \sa operator==(const Node& n)
 
    80       bool operator!=(GraphItem) const { return false; }
 
    82       /// \brief Artificial ordering operator.
 
    84       /// To allow the use of graph descriptors as key type in std::map or
 
    85       /// similar associative container we require this.
 
    87       /// \note This operator only have to define some strict ordering of
 
    88       /// the items; this order has nothing to do with the iteration
 
    89       /// ordering of the items.
 
    90       bool operator<(GraphItem) const { return false; }
 
    92       template<typename _GraphItem>
 
    97           _GraphItem i3 = INVALID;
 
   102           //          b = (ia == ib) && (ia != ib) && (ia < ib);
 
   103           b = (ia == ib) && (ia != ib);
 
   104           b = (ia == INVALID) && (ib != INVALID);
 
   108         const _GraphItem &ia;
 
   109         const _GraphItem &ib;
 
   113     /// \brief An empty base directed graph class.
 
   115     /// This class provides the minimal set of features needed for a
 
   116     /// directed graph structure. All digraph concepts have to
 
   117     /// conform to this base directed graph. It just provides types
 
   118     /// for nodes and arcs and functions to get the source and the
 
   119     /// target of the arcs.
 
   120     class BaseDigraphComponent {
 
   123       typedef BaseDigraphComponent Digraph;
 
   125       /// \brief Node class of the digraph.
 
   127       /// This class represents the Nodes of the digraph.
 
   129       typedef GraphItem<'n'> Node;
 
   131       /// \brief Arc class of the digraph.
 
   133       /// This class represents the Arcs of the digraph.
 
   135       typedef GraphItem<'e'> Arc;
 
   137       /// \brief Gives back the target node of an arc.
 
   139       /// Gives back the target node of an arc.
 
   141       Node target(const Arc&) const { return INVALID;}
 
   143       /// \brief Gives back the source node of an arc.
 
   145       /// Gives back the source node of an arc.
 
   147       Node source(const Arc&) const { return INVALID;}
 
   149       /// \brief Gives back the opposite node on the given arc.
 
   151       /// Gives back the opposite node on the given arc.
 
   152       Node oppositeNode(const Node&, const Arc&) const {
 
   156       template <typename _Digraph>
 
   158         typedef typename _Digraph::Node Node;
 
   159         typedef typename _Digraph::Arc Arc;
 
   162           checkConcept<GraphItem<'n'>, Node>();
 
   163           checkConcept<GraphItem<'a'>, Arc>();
 
   167             n = digraph.source(e);
 
   168             n = digraph.target(e);
 
   169             n = digraph.oppositeNode(n, e);
 
   173         const _Digraph& digraph;
 
   177     /// \brief An empty base undirected graph class.
 
   179     /// This class provides the minimal set of features needed for an
 
   180     /// undirected graph structure. All undirected graph concepts have
 
   181     /// to conform to this base graph. It just provides types for
 
   182     /// nodes, arcs and edges and functions to get the
 
   183     /// source and the target of the arcs and edges,
 
   184     /// conversion from arcs to edges and function to get
 
   185     /// both direction of the edges.
 
   186     class BaseGraphComponent : public BaseDigraphComponent {
 
   188       typedef BaseDigraphComponent::Node Node;
 
   189       typedef BaseDigraphComponent::Arc Arc;
 
   190       /// \brief Undirected arc class of the graph.
 
   192       /// This class represents the edges of the graph.
 
   193       /// The undirected graphs can be used as a directed graph which
 
   194       /// for each arc contains the opposite arc too so the graph is
 
   195       /// bidirected. The edge represents two opposite
 
   197       class Edge : public GraphItem<'u'> {
 
   199         typedef GraphItem<'u'> Parent;
 
   200         /// \brief Default constructor.
 
   202         /// \warning The default constructor is not required to set
 
   203         /// the item to some well-defined value. So you should consider it
 
   204         /// as uninitialized.
 
   206         /// \brief Copy constructor.
 
   208         /// Copy constructor.
 
   210         Edge(const Edge &) : Parent() {}
 
   211         /// \brief Invalid constructor \& conversion.
 
   213         /// This constructor initializes the item to be invalid.
 
   214         /// \sa Invalid for more details.
 
   216         /// \brief Converter from arc to edge.
 
   218         /// Besides the core graph item functionality each arc should
 
   219         /// be convertible to the represented edge.
 
   221         /// \brief Assign arc to edge.
 
   223         /// Besides the core graph item functionality each arc should
 
   224         /// be convertible to the represented edge.
 
   225         Edge& operator=(const Arc&) { return *this; }
 
   228       /// \brief Returns the direction of the arc.
 
   230       /// Returns the direction of the arc. Each arc represents an
 
   231       /// edge with a direction. It gives back the
 
   233       bool direction(const Arc&) const { return true; }
 
   235       /// \brief Returns the directed arc.
 
   237       /// Returns the directed arc from its direction and the
 
   238       /// represented edge.
 
   239       Arc direct(const Edge&, bool) const { return INVALID;}
 
   241       /// \brief Returns the directed arc.
 
   243       /// Returns the directed arc from its source and the
 
   244       /// represented edge.
 
   245       Arc direct(const Edge&, const Node&) const { return INVALID;}
 
   247       /// \brief Returns the opposite arc.
 
   249       /// Returns the opposite arc. It is the arc representing the
 
   250       /// same edge and has opposite direction.
 
   251       Arc oppositeArc(const Arc&) const { return INVALID;}
 
   253       /// \brief Gives back one ending of an edge.
 
   255       /// Gives back one ending of an edge.
 
   256       Node u(const Edge&) const { return INVALID;}
 
   258       /// \brief Gives back the other ending of an edge.
 
   260       /// Gives back the other ending of an edge.
 
   261       Node v(const Edge&) const { return INVALID;}
 
   263       template <typename _Graph>
 
   265         typedef typename _Graph::Node Node;
 
   266         typedef typename _Graph::Arc Arc;
 
   267         typedef typename _Graph::Edge Edge;
 
   270           checkConcept<BaseDigraphComponent, _Graph>();
 
   271           checkConcept<GraphItem<'u'>, Edge>();
 
   278             e = graph.direct(ue, true);
 
   279             e = graph.direct(ue, n);
 
   280             e = graph.oppositeArc(e);
 
   282             bool d = graph.direction(e);
 
   283             ignore_unused_variable_warning(d);
 
   292     /// \brief An empty idable base digraph class.
 
   294     /// This class provides beside the core digraph features
 
   295     /// core id functions for the digraph structure.
 
   296     /// The most of the base digraphs should conform to this concept.
 
   297     /// The id's are unique and immutable.
 
   298     template <typename BAS = BaseDigraphComponent>
 
   299     class IDableDigraphComponent : public BAS {
 
   303       typedef typename Base::Node Node;
 
   304       typedef typename Base::Arc Arc;
 
   306       /// \brief Gives back an unique integer id for the Node.
 
   308       /// Gives back an unique integer id for the Node.
 
   310       int id(const Node&) const { return -1;}
 
   312       /// \brief Gives back the node by the unique id.
 
   314       /// Gives back the node by the unique id.
 
   315       /// If the digraph does not contain node with the given id
 
   316       /// then the result of the function is undetermined.
 
   317       Node nodeFromId(int) const { return INVALID;}
 
   319       /// \brief Gives back an unique integer id for the Arc.
 
   321       /// Gives back an unique integer id for the Arc.
 
   323       int id(const Arc&) const { return -1;}
 
   325       /// \brief Gives back the arc by the unique id.
 
   327       /// Gives back the arc by the unique id.
 
   328       /// If the digraph does not contain arc with the given id
 
   329       /// then the result of the function is undetermined.
 
   330       Arc arcFromId(int) const { return INVALID;}
 
   332       /// \brief Gives back an integer greater or equal to the maximum
 
   335       /// Gives back an integer greater or equal to the maximum Node
 
   337       int maxNodeId() const { return -1;}
 
   339       /// \brief Gives back an integer greater or equal to the maximum
 
   342       /// Gives back an integer greater or equal to the maximum Arc
 
   344       int maxArcId() const { return -1;}
 
   346       template <typename _Digraph>
 
   350           checkConcept<Base, _Digraph >();
 
   351           typename _Digraph::Node node;
 
   352           int nid = digraph.id(node);
 
   353           nid = digraph.id(node);
 
   354           node = digraph.nodeFromId(nid);
 
   355           typename _Digraph::Arc arc;
 
   356           int eid = digraph.id(arc);
 
   357           eid = digraph.id(arc);
 
   358           arc = digraph.arcFromId(eid);
 
   360           nid = digraph.maxNodeId();
 
   361           ignore_unused_variable_warning(nid);
 
   362           eid = digraph.maxArcId();
 
   363           ignore_unused_variable_warning(eid);
 
   366         const _Digraph& digraph;
 
   370     /// \brief An empty idable base undirected graph class.
 
   372     /// This class provides beside the core undirected graph features
 
   373     /// core id functions for the undirected graph structure.  The
 
   374     /// most of the base undirected graphs should conform to this
 
   375     /// concept.  The id's are unique and immutable.
 
   376     template <typename BAS = BaseGraphComponent>
 
   377     class IDableGraphComponent : public IDableDigraphComponent<BAS> {
 
   381       typedef typename Base::Edge Edge;
 
   383       using IDableDigraphComponent<Base>::id;
 
   385       /// \brief Gives back an unique integer id for the Edge.
 
   387       /// Gives back an unique integer id for the Edge.
 
   389       int id(const Edge&) const { return -1;}
 
   391       /// \brief Gives back the edge by the unique id.
 
   393       /// Gives back the edge by the unique id.  If the
 
   394       /// graph does not contain arc with the given id then the
 
   395       /// result of the function is undetermined.
 
   396       Edge edgeFromId(int) const { return INVALID;}
 
   398       /// \brief Gives back an integer greater or equal to the maximum
 
   401       /// Gives back an integer greater or equal to the maximum Edge
 
   403       int maxEdgeId() const { return -1;}
 
   405       template <typename _Graph>
 
   409           checkConcept<Base, _Graph >();
 
   410           checkConcept<IDableDigraphComponent<Base>, _Graph >();
 
   411           typename _Graph::Edge edge;
 
   412           int ueid = graph.id(edge);
 
   413           ueid = graph.id(edge);
 
   414           edge = graph.edgeFromId(ueid);
 
   415           ueid = graph.maxEdgeId();
 
   416           ignore_unused_variable_warning(ueid);
 
   423     /// \brief Skeleton class for graph NodeIt and ArcIt
 
   425     /// Skeleton class for graph NodeIt and ArcIt.
 
   427     template <typename GR, typename Item>
 
   428     class GraphItemIt : public Item {
 
   430       /// \brief Default constructor.
 
   432       /// @warning The default constructor sets the iterator
 
   433       /// to an undefined value.
 
   435       /// \brief Copy constructor.
 
   437       /// Copy constructor.
 
   439       GraphItemIt(const GraphItemIt& ) {}
 
   440       /// \brief Sets the iterator to the first item.
 
   442       /// Sets the iterator to the first item of \c the graph.
 
   444       explicit GraphItemIt(const GR&) {}
 
   445       /// \brief Invalid constructor \& conversion.
 
   447       /// This constructor initializes the item to be invalid.
 
   448       /// \sa Invalid for more details.
 
   449       GraphItemIt(Invalid) {}
 
   450       /// \brief Assign operator for items.
 
   452       /// The items are assignable.
 
   454       GraphItemIt& operator=(const GraphItemIt&) { return *this; }
 
   455       /// \brief Next item.
 
   457       /// Assign the iterator to the next item.
 
   459       GraphItemIt& operator++() { return *this; }
 
   460       /// \brief Equality operator
 
   462       /// Two iterators are equal if and only if they point to the
 
   463       /// same object or both are invalid.
 
   464       bool operator==(const GraphItemIt&) const { return true;}
 
   465       /// \brief Inequality operator
 
   467       /// \sa operator==(Node n)
 
   469       bool operator!=(const GraphItemIt&) const { return true;}
 
   471       template<typename _GraphItemIt>
 
   488     /// \brief Skeleton class for graph InArcIt and OutArcIt
 
   490     /// \note Because InArcIt and OutArcIt may not inherit from the same
 
   491     /// base class, the \c sel is a additional template parameter (selector).
 
   492     /// For InArcIt you should instantiate it with character 'i' and for
 
   493     /// OutArcIt with 'o'.
 
   494     template <typename GR,
 
   495               typename Item = typename GR::Arc,
 
   496               typename Base = typename GR::Node,
 
   498     class GraphIncIt : public Item {
 
   500       /// \brief Default constructor.
 
   502       /// @warning The default constructor sets the iterator
 
   503       /// to an undefined value.
 
   505       /// \brief Copy constructor.
 
   507       /// Copy constructor.
 
   509       GraphIncIt(GraphIncIt const& gi) : Item(gi) {}
 
   510       /// \brief Sets the iterator to the first arc incoming into or outgoing
 
   513       /// Sets the iterator to the first arc incoming into or outgoing
 
   516       explicit GraphIncIt(const GR&, const Base&) {}
 
   517       /// \brief Invalid constructor \& conversion.
 
   519       /// This constructor initializes the item to be invalid.
 
   520       /// \sa Invalid for more details.
 
   521       GraphIncIt(Invalid) {}
 
   522       /// \brief Assign operator for iterators.
 
   524       /// The iterators are assignable.
 
   526       GraphIncIt& operator=(GraphIncIt const&) { return *this; }
 
   527       /// \brief Next item.
 
   529       /// Assign the iterator to the next item.
 
   531       GraphIncIt& operator++() { return *this; }
 
   533       /// \brief Equality operator
 
   535       /// Two iterators are equal if and only if they point to the
 
   536       /// same object or both are invalid.
 
   537       bool operator==(const GraphIncIt&) const { return true;}
 
   539       /// \brief Inequality operator
 
   541       /// \sa operator==(Node n)
 
   543       bool operator!=(const GraphIncIt&) const { return true;}
 
   545       template <typename _GraphIncIt>
 
   548           checkConcept<GraphItem<sel>, _GraphIncIt>();
 
   549           _GraphIncIt it1(graph, node);
 
   568     /// \brief An empty iterable digraph class.
 
   570     /// This class provides beside the core digraph features
 
   571     /// iterator based iterable interface for the digraph structure.
 
   572     /// This concept is part of the Digraph concept.
 
   573     template <typename BAS = BaseDigraphComponent>
 
   574     class IterableDigraphComponent : public BAS {
 
   579       typedef typename Base::Node Node;
 
   580       typedef typename Base::Arc Arc;
 
   582       typedef IterableDigraphComponent Digraph;
 
   584       /// \name Base iteration
 
   586       /// This interface provides functions for iteration on digraph items
 
   590       /// \brief Gives back the first node in the iterating order.
 
   592       /// Gives back the first node in the iterating order.
 
   594       void first(Node&) const {}
 
   596       /// \brief Gives back the next node in the iterating order.
 
   598       /// Gives back the next node in the iterating order.
 
   600       void next(Node&) const {}
 
   602       /// \brief Gives back the first arc in the iterating order.
 
   604       /// Gives back the first arc in the iterating order.
 
   606       void first(Arc&) const {}
 
   608       /// \brief Gives back the next arc in the iterating order.
 
   610       /// Gives back the next arc in the iterating order.
 
   612       void next(Arc&) const {}
 
   615       /// \brief Gives back the first of the arcs point to the given
 
   618       /// Gives back the first of the arcs point to the given node.
 
   620       void firstIn(Arc&, const Node&) const {}
 
   622       /// \brief Gives back the next of the arcs points to the given
 
   625       /// Gives back the next of the arcs points to the given node.
 
   627       void nextIn(Arc&) const {}
 
   629       /// \brief Gives back the first of the arcs start from the
 
   632       /// Gives back the first of the arcs start from the given node.
 
   634       void firstOut(Arc&, const Node&) const {}
 
   636       /// \brief Gives back the next of the arcs start from the given
 
   639       /// Gives back the next of the arcs start from the given node.
 
   641       void nextOut(Arc&) const {}
 
   645       /// \name Class based iteration
 
   647       /// This interface provides functions for iteration on digraph items
 
   651       /// \brief This iterator goes through each node.
 
   653       /// This iterator goes through each node.
 
   655       typedef GraphItemIt<Digraph, Node> NodeIt;
 
   657       /// \brief This iterator goes through each node.
 
   659       /// This iterator goes through each node.
 
   661       typedef GraphItemIt<Digraph, Arc> ArcIt;
 
   663       /// \brief This iterator goes trough the incoming arcs of a node.
 
   665       /// This iterator goes trough the \e inccoming arcs of a certain node
 
   667       typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt;
 
   669       /// \brief This iterator goes trough the outgoing arcs of a node.
 
   671       /// This iterator goes trough the \e outgoing arcs of a certain node
 
   673       typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt;
 
   675       /// \brief The base node of the iterator.
 
   677       /// Gives back the base node of the iterator.
 
   678       /// It is always the target of the pointed arc.
 
   679       Node baseNode(const InArcIt&) const { return INVALID; }
 
   681       /// \brief The running node of the iterator.
 
   683       /// Gives back the running node of the iterator.
 
   684       /// It is always the source of the pointed arc.
 
   685       Node runningNode(const InArcIt&) const { return INVALID; }
 
   687       /// \brief The base node of the iterator.
 
   689       /// Gives back the base node of the iterator.
 
   690       /// It is always the source of the pointed arc.
 
   691       Node baseNode(const OutArcIt&) const { return INVALID; }
 
   693       /// \brief The running node of the iterator.
 
   695       /// Gives back the running node of the iterator.
 
   696       /// It is always the target of the pointed arc.
 
   697       Node runningNode(const OutArcIt&) const { return INVALID; }
 
   701       template <typename _Digraph>
 
   704           checkConcept<Base, _Digraph>();
 
   707             typename _Digraph::Node node(INVALID);
 
   708             typename _Digraph::Arc arc(INVALID);
 
   718               digraph.firstIn(arc, node);
 
   722               digraph.firstOut(arc, node);
 
   723               digraph.nextOut(arc);
 
   728             checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>,
 
   729               typename _Digraph::ArcIt >();
 
   730             checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>,
 
   731               typename _Digraph::NodeIt >();
 
   732             checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
 
   733               typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>();
 
   734             checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
 
   735               typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>();
 
   737             typename _Digraph::Node n;
 
   738             typename _Digraph::InArcIt ieit(INVALID);
 
   739             typename _Digraph::OutArcIt oeit(INVALID);
 
   740             n = digraph.baseNode(ieit);
 
   741             n = digraph.runningNode(ieit);
 
   742             n = digraph.baseNode(oeit);
 
   743             n = digraph.runningNode(oeit);
 
   744             ignore_unused_variable_warning(n);
 
   748         const _Digraph& digraph;
 
   753     /// \brief An empty iterable undirected graph class.
 
   755     /// This class provides beside the core graph features iterator
 
   756     /// based iterable interface for the undirected graph structure.
 
   757     /// This concept is part of the Graph concept.
 
   758     template <typename BAS = BaseGraphComponent>
 
   759     class IterableGraphComponent : public IterableDigraphComponent<BAS> {
 
   763       typedef typename Base::Node Node;
 
   764       typedef typename Base::Arc Arc;
 
   765       typedef typename Base::Edge Edge;
 
   768       typedef IterableGraphComponent Graph;
 
   770       /// \name Base iteration
 
   772       /// This interface provides functions for iteration on graph items
 
   775       using IterableDigraphComponent<Base>::first;
 
   776       using IterableDigraphComponent<Base>::next;
 
   778       /// \brief Gives back the first edge in the iterating
 
   781       /// Gives back the first edge in the iterating order.
 
   783       void first(Edge&) const {}
 
   785       /// \brief Gives back the next edge in the iterating
 
   788       /// Gives back the next edge in the iterating order.
 
   790       void next(Edge&) const {}
 
   793       /// \brief Gives back the first of the edges from the
 
   796       /// Gives back the first of the edges from the given
 
   797       /// node. The bool parameter gives back that direction which
 
   798       /// gives a good direction of the edge so the source of the
 
   799       /// directed arc is the given node.
 
   800       void firstInc(Edge&, bool&, const Node&) const {}
 
   802       /// \brief Gives back the next of the edges from the
 
   805       /// Gives back the next of the edges from the given
 
   806       /// node. The bool parameter should be used as the \c firstInc()
 
   808       void nextInc(Edge&, bool&) const {}
 
   810       using IterableDigraphComponent<Base>::baseNode;
 
   811       using IterableDigraphComponent<Base>::runningNode;
 
   815       /// \name Class based iteration
 
   817       /// This interface provides functions for iteration on graph items
 
   821       /// \brief This iterator goes through each node.
 
   823       /// This iterator goes through each node.
 
   824       typedef GraphItemIt<Graph, Edge> EdgeIt;
 
   825       /// \brief This iterator goes trough the incident arcs of a
 
   828       /// This iterator goes trough the incident arcs of a certain
 
   830       typedef GraphIncIt<Graph, Edge, Node, 'u'> IncEdgeIt;
 
   831       /// \brief The base node of the iterator.
 
   833       /// Gives back the base node of the iterator.
 
   834       Node baseNode(const IncEdgeIt&) const { return INVALID; }
 
   836       /// \brief The running node of the iterator.
 
   838       /// Gives back the running node of the iterator.
 
   839       Node runningNode(const IncEdgeIt&) const { return INVALID; }
 
   843       template <typename _Graph>
 
   846           checkConcept<IterableDigraphComponent<Base>, _Graph>();
 
   849             typename _Graph::Node node(INVALID);
 
   850             typename _Graph::Edge edge(INVALID);
 
   857               graph.firstInc(edge, dir, node);
 
   858               graph.nextInc(edge, dir);
 
   864             checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>,
 
   865               typename _Graph::EdgeIt >();
 
   866             checkConcept<GraphIncIt<_Graph, typename _Graph::Edge,
 
   867               typename _Graph::Node, 'u'>, typename _Graph::IncEdgeIt>();
 
   869             typename _Graph::Node n;
 
   870             typename _Graph::IncEdgeIt ueit(INVALID);
 
   871             n = graph.baseNode(ueit);
 
   872             n = graph.runningNode(ueit);
 
   880     /// \brief An empty alteration notifier digraph class.
 
   882     /// This class provides beside the core digraph features alteration
 
   883     /// notifier interface for the digraph structure.  This implements
 
   884     /// an observer-notifier pattern for each digraph item. More
 
   885     /// obsevers can be registered into the notifier and whenever an
 
   886     /// alteration occured in the digraph all the observers will
 
   887     /// notified about it.
 
   888     template <typename BAS = BaseDigraphComponent>
 
   889     class AlterableDigraphComponent : public BAS {
 
   893       typedef typename Base::Node Node;
 
   894       typedef typename Base::Arc Arc;
 
   897       /// The node observer registry.
 
   898       typedef AlterationNotifier<AlterableDigraphComponent, Node>
 
   900       /// The arc observer registry.
 
   901       typedef AlterationNotifier<AlterableDigraphComponent, Arc>
 
   904       /// \brief Gives back the node alteration notifier.
 
   906       /// Gives back the node alteration notifier.
 
   907       NodeNotifier& notifier(Node) const {
 
   908         return NodeNotifier();
 
   911       /// \brief Gives back the arc alteration notifier.
 
   913       /// Gives back the arc alteration notifier.
 
   914       ArcNotifier& notifier(Arc) const {
 
   915         return ArcNotifier();
 
   918       template <typename _Digraph>
 
   921           checkConcept<Base, _Digraph>();
 
   922           typename _Digraph::NodeNotifier& nn
 
   923             = digraph.notifier(typename _Digraph::Node());
 
   925           typename _Digraph::ArcNotifier& en
 
   926             = digraph.notifier(typename _Digraph::Arc());
 
   928           ignore_unused_variable_warning(nn);
 
   929           ignore_unused_variable_warning(en);
 
   932         const _Digraph& digraph;
 
   938     /// \brief An empty alteration notifier undirected graph class.
 
   940     /// This class provides beside the core graph features alteration
 
   941     /// notifier interface for the graph structure.  This implements
 
   942     /// an observer-notifier pattern for each graph item. More
 
   943     /// obsevers can be registered into the notifier and whenever an
 
   944     /// alteration occured in the graph all the observers will
 
   945     /// notified about it.
 
   946     template <typename BAS = BaseGraphComponent>
 
   947     class AlterableGraphComponent : public AlterableDigraphComponent<BAS> {
 
   951       typedef typename Base::Edge Edge;
 
   954       /// The arc observer registry.
 
   955       typedef AlterationNotifier<AlterableGraphComponent, Edge>
 
   958       /// \brief Gives back the arc alteration notifier.
 
   960       /// Gives back the arc alteration notifier.
 
   961       EdgeNotifier& notifier(Edge) const {
 
   962         return EdgeNotifier();
 
   965       template <typename _Graph>
 
   968           checkConcept<AlterableGraphComponent<Base>, _Graph>();
 
   969           typename _Graph::EdgeNotifier& uen
 
   970             = graph.notifier(typename _Graph::Edge());
 
   971           ignore_unused_variable_warning(uen);
 
   978     /// \brief Class describing the concept of graph maps
 
   980     /// This class describes the common interface of the graph maps
 
   981     /// (NodeMap, ArcMap), that is maps that can be used to
 
   982     /// associate data to graph descriptors (nodes or arcs).
 
   983     template <typename GR, typename K, typename V>
 
   984     class GraphMap : public ReadWriteMap<K, V> {
 
   987       typedef ReadWriteMap<K, V> Parent;
 
   989       /// The graph type of the map.
 
   991       /// The key type of the map.
 
   993       /// The value type of the map.
 
   996       /// \brief Construct a new map.
 
   998       /// Construct a new map for the graph.
 
   999       explicit GraphMap(const Graph&) {}
 
  1000       /// \brief Construct a new map with default value.
 
  1002       /// Construct a new map for the graph and initalise the values.
 
  1003       GraphMap(const Graph&, const Value&) {}
 
  1006       /// \brief Copy constructor.
 
  1008       /// Copy Constructor.
 
  1009       GraphMap(const GraphMap&) : Parent() {}
 
  1011       /// \brief Assign operator.
 
  1013       /// Assign operator. It does not mofify the underlying graph,
 
  1014       /// it just iterates on the current item set and set the  map
 
  1015       /// with the value returned by the assigned map.
 
  1016       template <typename CMap>
 
  1017       GraphMap& operator=(const CMap&) {
 
  1018         checkConcept<ReadMap<Key, Value>, CMap>();
 
  1023       template<typename _Map>
 
  1024       struct Constraints {
 
  1025         void constraints() {
 
  1026           checkConcept<ReadWriteMap<Key, Value>, _Map >();
 
  1027           // Construction with a graph parameter
 
  1029           // Constructor with a graph and a default value parameter
 
  1031           // Copy constructor.
 
  1034           // ReadMap<Key, Value> cmap;
 
  1037           ignore_unused_variable_warning(a);
 
  1038           ignore_unused_variable_warning(a2);
 
  1039           // ignore_unused_variable_warning(b);
 
  1044         const typename GraphMap::Value &t;
 
  1049     /// \brief An empty mappable digraph class.
 
  1051     /// This class provides beside the core digraph features
 
  1052     /// map interface for the digraph structure.
 
  1053     /// This concept is part of the Digraph concept.
 
  1054     template <typename BAS = BaseDigraphComponent>
 
  1055     class MappableDigraphComponent : public BAS  {
 
  1059       typedef typename Base::Node Node;
 
  1060       typedef typename Base::Arc Arc;
 
  1062       typedef MappableDigraphComponent Digraph;
 
  1064       /// \brief ReadWrite map of the nodes.
 
  1066       /// ReadWrite map of the nodes.
 
  1068       template <typename V>
 
  1069       class NodeMap : public GraphMap<Digraph, Node, V> {
 
  1071         typedef GraphMap<MappableDigraphComponent, Node, V> Parent;
 
  1073         /// \brief Construct a new map.
 
  1075         /// Construct a new map for the digraph.
 
  1076         explicit NodeMap(const MappableDigraphComponent& digraph)
 
  1077           : Parent(digraph) {}
 
  1079         /// \brief Construct a new map with default value.
 
  1081         /// Construct a new map for the digraph and initalise the values.
 
  1082         NodeMap(const MappableDigraphComponent& digraph, const V& value)
 
  1083           : Parent(digraph, value) {}
 
  1086         /// \brief Copy constructor.
 
  1088         /// Copy Constructor.
 
  1089         NodeMap(const NodeMap& nm) : Parent(nm) {}
 
  1091         /// \brief Assign operator.
 
  1093         /// Assign operator.
 
  1094         template <typename CMap>
 
  1095         NodeMap& operator=(const CMap&) {
 
  1096           checkConcept<ReadMap<Node, V>, CMap>();
 
  1102       /// \brief ReadWrite map of the arcs.
 
  1104       /// ReadWrite map of the arcs.
 
  1106       template <typename V>
 
  1107       class ArcMap : public GraphMap<Digraph, Arc, V> {
 
  1109         typedef GraphMap<MappableDigraphComponent, Arc, V> Parent;
 
  1111         /// \brief Construct a new map.
 
  1113         /// Construct a new map for the digraph.
 
  1114         explicit ArcMap(const MappableDigraphComponent& digraph)
 
  1115           : Parent(digraph) {}
 
  1117         /// \brief Construct a new map with default value.
 
  1119         /// Construct a new map for the digraph and initalise the values.
 
  1120         ArcMap(const MappableDigraphComponent& digraph, const V& value)
 
  1121           : Parent(digraph, value) {}
 
  1124         /// \brief Copy constructor.
 
  1126         /// Copy Constructor.
 
  1127         ArcMap(const ArcMap& nm) : Parent(nm) {}
 
  1129         /// \brief Assign operator.
 
  1131         /// Assign operator.
 
  1132         template <typename CMap>
 
  1133         ArcMap& operator=(const CMap&) {
 
  1134           checkConcept<ReadMap<Arc, V>, CMap>();
 
  1141       template <typename _Digraph>
 
  1142       struct Constraints {
 
  1146           Dummy() : value(0) {}
 
  1147           Dummy(int _v) : value(_v) {}
 
  1150         void constraints() {
 
  1151           checkConcept<Base, _Digraph>();
 
  1153             typedef typename _Digraph::template NodeMap<int> IntNodeMap;
 
  1154             checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>,
 
  1156           } { // bool map test
 
  1157             typedef typename _Digraph::template NodeMap<bool> BoolNodeMap;
 
  1158             checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>,
 
  1160           } { // Dummy map test
 
  1161             typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap;
 
  1162             checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>,
 
  1167             typedef typename _Digraph::template ArcMap<int> IntArcMap;
 
  1168             checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
 
  1170           } { // bool map test
 
  1171             typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
 
  1172             checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
 
  1174           } { // Dummy map test
 
  1175             typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
 
  1176             checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>,
 
  1185     /// \brief An empty mappable base bipartite graph class.
 
  1187     /// This class provides beside the core graph features
 
  1188     /// map interface for the graph structure.
 
  1189     /// This concept is part of the Graph concept.
 
  1190     template <typename BAS = BaseGraphComponent>
 
  1191     class MappableGraphComponent : public MappableDigraphComponent<BAS>  {
 
  1195       typedef typename Base::Edge Edge;
 
  1197       typedef MappableGraphComponent Graph;
 
  1199       /// \brief ReadWrite map of the edges.
 
  1201       /// ReadWrite map of the edges.
 
  1203       template <typename V>
 
  1204       class EdgeMap : public GraphMap<Graph, Edge, V> {
 
  1206         typedef GraphMap<MappableGraphComponent, Edge, V> Parent;
 
  1208         /// \brief Construct a new map.
 
  1210         /// Construct a new map for the graph.
 
  1211         explicit EdgeMap(const MappableGraphComponent& graph)
 
  1214         /// \brief Construct a new map with default value.
 
  1216         /// Construct a new map for the graph and initalise the values.
 
  1217         EdgeMap(const MappableGraphComponent& graph, const V& value)
 
  1218           : Parent(graph, value) {}
 
  1221         /// \brief Copy constructor.
 
  1223         /// Copy Constructor.
 
  1224         EdgeMap(const EdgeMap& nm) : Parent(nm) {}
 
  1226         /// \brief Assign operator.
 
  1228         /// Assign operator.
 
  1229         template <typename CMap>
 
  1230         EdgeMap& operator=(const CMap&) {
 
  1231           checkConcept<ReadMap<Edge, V>, CMap>();
 
  1238       template <typename _Graph>
 
  1239       struct Constraints {
 
  1243           Dummy() : value(0) {}
 
  1244           Dummy(int _v) : value(_v) {}
 
  1247         void constraints() {
 
  1248           checkConcept<MappableGraphComponent<Base>, _Graph>();
 
  1251             typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
 
  1252             checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
 
  1254           } { // bool map test
 
  1255             typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
 
  1256             checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
 
  1258           } { // Dummy map test
 
  1259             typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
 
  1260             checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>,
 
  1269     /// \brief An empty extendable digraph class.
 
  1271     /// This class provides beside the core digraph features digraph
 
  1272     /// extendable interface for the digraph structure.  The main
 
  1273     /// difference between the base and this interface is that the
 
  1274     /// digraph alterations should handled already on this level.
 
  1275     template <typename BAS = BaseDigraphComponent>
 
  1276     class ExtendableDigraphComponent : public BAS {
 
  1280       typedef typename Base::Node Node;
 
  1281       typedef typename Base::Arc Arc;
 
  1283       /// \brief Adds a new node to the digraph.
 
  1285       /// Adds a new node to the digraph.
 
  1291       /// \brief Adds a new arc connects the given two nodes.
 
  1293       /// Adds a new arc connects the the given two nodes.
 
  1294       Arc addArc(const Node&, const Node&) {
 
  1298       template <typename _Digraph>
 
  1299       struct Constraints {
 
  1300         void constraints() {
 
  1301           checkConcept<Base, _Digraph>();
 
  1302           typename _Digraph::Node node_a, node_b;
 
  1303           node_a = digraph.addNode();
 
  1304           node_b = digraph.addNode();
 
  1305           typename _Digraph::Arc arc;
 
  1306           arc = digraph.addArc(node_a, node_b);
 
  1313     /// \brief An empty extendable base undirected graph class.
 
  1315     /// This class provides beside the core undirected graph features
 
  1316     /// core undircted graph extend interface for the graph structure.
 
  1317     /// The main difference between the base and this interface is
 
  1318     /// that the graph alterations should handled already on this
 
  1320     template <typename BAS = BaseGraphComponent>
 
  1321     class ExtendableGraphComponent : public BAS {
 
  1325       typedef typename Base::Node Node;
 
  1326       typedef typename Base::Edge Edge;
 
  1328       /// \brief Adds a new node to the graph.
 
  1330       /// Adds a new node to the graph.
 
  1336       /// \brief Adds a new arc connects the given two nodes.
 
  1338       /// Adds a new arc connects the the given two nodes.
 
  1339       Edge addArc(const Node&, const Node&) {
 
  1343       template <typename _Graph>
 
  1344       struct Constraints {
 
  1345         void constraints() {
 
  1346           checkConcept<Base, _Graph>();
 
  1347           typename _Graph::Node node_a, node_b;
 
  1348           node_a = graph.addNode();
 
  1349           node_b = graph.addNode();
 
  1350           typename _Graph::Edge edge;
 
  1351           edge = graph.addEdge(node_a, node_b);
 
  1358     /// \brief An empty erasable digraph class.
 
  1360     /// This class provides beside the core digraph features core erase
 
  1361     /// functions for the digraph structure. The main difference between
 
  1362     /// the base and this interface is that the digraph alterations
 
  1363     /// should handled already on this level.
 
  1364     template <typename BAS = BaseDigraphComponent>
 
  1365     class ErasableDigraphComponent : public BAS {
 
  1369       typedef typename Base::Node Node;
 
  1370       typedef typename Base::Arc Arc;
 
  1372       /// \brief Erase a node from the digraph.
 
  1374       /// Erase a node from the digraph. This function should
 
  1375       /// erase all arcs connecting to the node.
 
  1376       void erase(const Node&) {}
 
  1378       /// \brief Erase an arc from the digraph.
 
  1380       /// Erase an arc from the digraph.
 
  1382       void erase(const Arc&) {}
 
  1384       template <typename _Digraph>
 
  1385       struct Constraints {
 
  1386         void constraints() {
 
  1387           checkConcept<Base, _Digraph>();
 
  1388           typename _Digraph::Node node;
 
  1389           digraph.erase(node);
 
  1390           typename _Digraph::Arc arc;
 
  1398     /// \brief An empty erasable base undirected graph class.
 
  1400     /// This class provides beside the core undirected graph features
 
  1401     /// core erase functions for the undirceted graph structure. The
 
  1402     /// main difference between the base and this interface is that
 
  1403     /// the graph alterations should handled already on this level.
 
  1404     template <typename BAS = BaseGraphComponent>
 
  1405     class ErasableGraphComponent : public BAS {
 
  1409       typedef typename Base::Node Node;
 
  1410       typedef typename Base::Edge Edge;
 
  1412       /// \brief Erase a node from the graph.
 
  1414       /// Erase a node from the graph. This function should erase
 
  1415       /// arcs connecting to the node.
 
  1416       void erase(const Node&) {}
 
  1418       /// \brief Erase an arc from the graph.
 
  1420       /// Erase an arc from the graph.
 
  1422       void erase(const Edge&) {}
 
  1424       template <typename _Graph>
 
  1425       struct Constraints {
 
  1426         void constraints() {
 
  1427           checkConcept<Base, _Graph>();
 
  1428           typename _Graph::Node node;
 
  1430           typename _Graph::Edge edge;
 
  1438     /// \brief An empty clearable base digraph class.
 
  1440     /// This class provides beside the core digraph features core clear
 
  1441     /// functions for the digraph structure. The main difference between
 
  1442     /// the base and this interface is that the digraph alterations
 
  1443     /// should handled already on this level.
 
  1444     template <typename BAS = BaseDigraphComponent>
 
  1445     class ClearableDigraphComponent : public BAS {
 
  1450       /// \brief Erase all nodes and arcs from the digraph.
 
  1452       /// Erase all nodes and arcs from the digraph.
 
  1456       template <typename _Digraph>
 
  1457       struct Constraints {
 
  1458         void constraints() {
 
  1459           checkConcept<Base, _Digraph>();
 
  1467     /// \brief An empty clearable base undirected graph class.
 
  1469     /// This class provides beside the core undirected graph features
 
  1470     /// core clear functions for the undirected graph structure. The
 
  1471     /// main difference between the base and this interface is that
 
  1472     /// the graph alterations should handled already on this level.
 
  1473     template <typename BAS = BaseGraphComponent>
 
  1474     class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {
 
  1479       template <typename _Graph>
 
  1480       struct Constraints {
 
  1481         void constraints() {
 
  1482           checkConcept<ClearableGraphComponent<Base>, _Graph>();