1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
 
     3  * This file is a part of LEMON, a generic C++ optimization library.
 
     5  * Copyright (C) 2003-2011
 
     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 Concept class for \c Node, \c Arc and \c Edge types.
 
    36     /// This class describes the concept of \c Node, \c Arc and \c Edge
 
    37     /// subtypes of digraph and 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 that \c Node
 
    41     /// and \c Arc (or \c Edge) types should \e not derive from the same
 
    42     /// base class. For \c Node you should instantiate it with character
 
    43     /// \c 'n', for \c Arc with \c 'a' and for \c Edge with \c 'e'.
 
    45     template <char sel = '0'>
 
    49       /// \brief Default constructor.
 
    51       /// 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
 
    57       /// \brief Copy constructor.
 
    60       GraphItem(const GraphItem &) {}
 
    62       /// \brief Constructor for conversion from \c INVALID.
 
    64       /// Constructor for conversion from \c INVALID.
 
    65       /// It initializes the item to be invalid.
 
    66       /// \sa Invalid for more details.
 
    69       /// \brief Assignment operator.
 
    71       /// Assignment operator for the item.
 
    72       GraphItem& operator=(const GraphItem&) { return *this; }
 
    74       /// \brief Assignment operator for INVALID.
 
    76       /// This operator makes the item invalid.
 
    77       GraphItem& operator=(Invalid) { return *this; }
 
    79       /// \brief Equality operator.
 
    81       /// Equality operator.
 
    82       bool operator==(const GraphItem&) const { return false; }
 
    84       /// \brief Inequality operator.
 
    86       /// Inequality operator.
 
    87       bool operator!=(const GraphItem&) const { return false; }
 
    89       /// \brief Ordering operator.
 
    91       /// This operator defines an ordering of the items.
 
    92       /// It makes possible to use graph item types as key types in
 
    93       /// associative containers (e.g. \c std::map).
 
    95       /// \note This operator only have to define some strict ordering of
 
    96       /// the items; this order has nothing to do with the iteration
 
    97       /// ordering of the items.
 
    98       bool operator<(const GraphItem&) const { return false; }
 
   100       template<typename _GraphItem>
 
   106           _GraphItem i3 = INVALID;
 
   111           b = (ia == ib) && (ia != ib);
 
   112           b = (ia == INVALID) && (ib != INVALID);
 
   116         const _GraphItem &ia;
 
   117         const _GraphItem &ib;
 
   121     /// \brief Base skeleton class for directed graphs.
 
   123     /// This class describes the base interface of directed graph types.
 
   124     /// All digraph %concepts have to conform to this class.
 
   125     /// It just provides types for nodes and arcs and functions
 
   126     /// to get the source and the target nodes of arcs.
 
   127     class BaseDigraphComponent {
 
   130       typedef BaseDigraphComponent Digraph;
 
   132       /// \brief Node class of the digraph.
 
   134       /// This class represents the nodes of the digraph.
 
   135       typedef GraphItem<'n'> Node;
 
   137       /// \brief Arc class of the digraph.
 
   139       /// This class represents the arcs of the digraph.
 
   140       typedef GraphItem<'a'> Arc;
 
   142       /// \brief Return the source node of an arc.
 
   144       /// This function returns the source node of an arc.
 
   145       Node source(const Arc&) const { return INVALID; }
 
   147       /// \brief Return the target node of an arc.
 
   149       /// This function returns the target node of an arc.
 
   150       Node target(const Arc&) const { return INVALID; }
 
   152       /// \brief Return the opposite node on the given arc.
 
   154       /// This function returns the opposite node on the given arc.
 
   155       Node oppositeNode(const Node&, const Arc&) const {
 
   159       template <typename _Digraph>
 
   161         typedef typename _Digraph::Node Node;
 
   162         typedef typename _Digraph::Arc Arc;
 
   165           checkConcept<GraphItem<'n'>, Node>();
 
   166           checkConcept<GraphItem<'a'>, Arc>();
 
   170             n = digraph.source(e);
 
   171             n = digraph.target(e);
 
   172             n = digraph.oppositeNode(n, e);
 
   176         const _Digraph& digraph;
 
   180     /// \brief Base skeleton class for undirected graphs.
 
   182     /// This class describes the base interface of undirected graph types.
 
   183     /// All graph %concepts have to conform to this class.
 
   184     /// It extends the interface of \ref BaseDigraphComponent with an
 
   185     /// \c Edge type and functions to get the end nodes of edges,
 
   186     /// to convert from arcs to edges and to get both direction of edges.
 
   187     class BaseGraphComponent : public BaseDigraphComponent {
 
   190       typedef BaseGraphComponent Graph;
 
   192       typedef BaseDigraphComponent::Node Node;
 
   193       typedef BaseDigraphComponent::Arc Arc;
 
   195       /// \brief Undirected edge class of the graph.
 
   197       /// This class represents the undirected edges of the graph.
 
   198       /// Undirected graphs can be used as directed graphs, each edge is
 
   199       /// represented by two opposite directed arcs.
 
   200       class Edge : public GraphItem<'e'> {
 
   201         typedef GraphItem<'e'> Parent;
 
   204         /// \brief Default constructor.
 
   206         /// Default constructor.
 
   207         /// \warning The default constructor is not required to set
 
   208         /// the item to some well-defined value. So you should consider it
 
   209         /// as uninitialized.
 
   212         /// \brief Copy constructor.
 
   214         /// Copy constructor.
 
   215         Edge(const Edge &) : Parent() {}
 
   217         /// \brief Constructor for conversion from \c INVALID.
 
   219         /// Constructor for conversion from \c INVALID.
 
   220         /// It initializes the item to be invalid.
 
   221         /// \sa Invalid for more details.
 
   224         /// \brief Constructor for conversion from an arc.
 
   226         /// Constructor for conversion from an arc.
 
   227         /// Besides the core graph item functionality each arc should
 
   228         /// be convertible to the represented edge.
 
   232       /// \brief Return one end node of an edge.
 
   234       /// This function returns one end node of an edge.
 
   235       Node u(const Edge&) const { return INVALID; }
 
   237       /// \brief Return the other end node of an edge.
 
   239       /// This function returns the other end node of an edge.
 
   240       Node v(const Edge&) const { return INVALID; }
 
   242       /// \brief Return a directed arc related to an edge.
 
   244       /// This function returns a directed arc from its direction and the
 
   245       /// represented edge.
 
   246       Arc direct(const Edge&, bool) const { return INVALID; }
 
   248       /// \brief Return a directed arc related to an edge.
 
   250       /// This function returns a directed arc from its source node and the
 
   251       /// represented edge.
 
   252       Arc direct(const Edge&, const Node&) const { return INVALID; }
 
   254       /// \brief Return the direction of the arc.
 
   256       /// Returns the direction of the arc. Each arc represents an
 
   257       /// edge with a direction. It gives back the
 
   259       bool direction(const Arc&) const { return true; }
 
   261       /// \brief Return the opposite arc.
 
   263       /// This function returns the opposite arc, i.e. the arc representing
 
   264       /// the same edge and has opposite direction.
 
   265       Arc oppositeArc(const Arc&) const { return INVALID; }
 
   267       template <typename _Graph>
 
   269         typedef typename _Graph::Node Node;
 
   270         typedef typename _Graph::Arc Arc;
 
   271         typedef typename _Graph::Edge Edge;
 
   274           checkConcept<BaseDigraphComponent, _Graph>();
 
   275           checkConcept<GraphItem<'e'>, Edge>();
 
   282             e = graph.direct(ue, true);
 
   283             e = graph.direct(ue, false);
 
   284             e = graph.direct(ue, n);
 
   285             e = graph.oppositeArc(e);
 
   287             bool d = graph.direction(e);
 
   288             ignore_unused_variable_warning(d);
 
   297     /// \brief Skeleton class for \e idable directed graphs.
 
   299     /// This class describes the interface of \e idable directed graphs.
 
   300     /// It extends \ref BaseDigraphComponent with the core ID functions.
 
   301     /// The ids of the items must be unique and immutable.
 
   302     /// This concept is part of the Digraph concept.
 
   303     template <typename BAS = BaseDigraphComponent>
 
   304     class IDableDigraphComponent : public BAS {
 
   308       typedef typename Base::Node Node;
 
   309       typedef typename Base::Arc Arc;
 
   311       /// \brief Return a unique integer id for the given node.
 
   313       /// This function returns a unique integer id for the given node.
 
   314       int id(const Node&) const { return -1; }
 
   316       /// \brief Return the node by its unique id.
 
   318       /// This function returns the node by its unique id.
 
   319       /// If the digraph does not contain a node with the given id,
 
   320       /// then the result of the function is undefined.
 
   321       Node nodeFromId(int) const { return INVALID; }
 
   323       /// \brief Return a unique integer id for the given arc.
 
   325       /// This function returns a unique integer id for the given arc.
 
   326       int id(const Arc&) const { return -1; }
 
   328       /// \brief Return the arc by its unique id.
 
   330       /// This function returns the arc by its unique id.
 
   331       /// If the digraph does not contain an arc with the given id,
 
   332       /// then the result of the function is undefined.
 
   333       Arc arcFromId(int) const { return INVALID; }
 
   335       /// \brief Return an integer greater or equal to the maximum
 
   338       /// This function returns an integer greater or equal to the
 
   340       int maxNodeId() const { return -1; }
 
   342       /// \brief Return an integer greater or equal to the maximum
 
   345       /// This function returns an integer greater or equal to the
 
   347       int maxArcId() const { return -1; }
 
   349       template <typename _Digraph>
 
   353           checkConcept<Base, _Digraph >();
 
   354           typename _Digraph::Node node;
 
   356           int nid = digraph.id(node);
 
   357           nid = digraph.id(node);
 
   358           node = digraph.nodeFromId(nid);
 
   359           typename _Digraph::Arc arc;
 
   361           int eid = digraph.id(arc);
 
   362           eid = digraph.id(arc);
 
   363           arc = digraph.arcFromId(eid);
 
   365           nid = digraph.maxNodeId();
 
   366           ignore_unused_variable_warning(nid);
 
   367           eid = digraph.maxArcId();
 
   368           ignore_unused_variable_warning(eid);
 
   371         const _Digraph& digraph;
 
   375     /// \brief Skeleton class for \e idable undirected graphs.
 
   377     /// This class describes the interface of \e idable undirected
 
   378     /// graphs. It extends \ref IDableDigraphComponent with the core ID
 
   379     /// functions of undirected graphs.
 
   380     /// The ids of the items must be unique and immutable.
 
   381     /// This concept is part of the Graph concept.
 
   382     template <typename BAS = BaseGraphComponent>
 
   383     class IDableGraphComponent : public IDableDigraphComponent<BAS> {
 
   387       typedef typename Base::Edge Edge;
 
   389       using IDableDigraphComponent<Base>::id;
 
   391       /// \brief Return a unique integer id for the given edge.
 
   393       /// This function returns a unique integer id for the given edge.
 
   394       int id(const Edge&) const { return -1; }
 
   396       /// \brief Return the edge by its unique id.
 
   398       /// This function returns the edge by its unique id.
 
   399       /// If the graph does not contain an edge with the given id,
 
   400       /// then the result of the function is undefined.
 
   401       Edge edgeFromId(int) const { return INVALID; }
 
   403       /// \brief Return an integer greater or equal to the maximum
 
   406       /// This function returns an integer greater or equal to the
 
   408       int maxEdgeId() const { return -1; }
 
   410       template <typename _Graph>
 
   414           checkConcept<IDableDigraphComponent<Base>, _Graph >();
 
   415           typename _Graph::Edge edge;
 
   416           int ueid = graph.id(edge);
 
   417           ueid = graph.id(edge);
 
   418           edge = graph.edgeFromId(ueid);
 
   419           ueid = graph.maxEdgeId();
 
   420           ignore_unused_variable_warning(ueid);
 
   427     /// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types.
 
   429     /// This class describes the concept of \c NodeIt, \c ArcIt and
 
   430     /// \c EdgeIt subtypes of digraph and graph types.
 
   431     template <typename GR, typename Item>
 
   432     class GraphItemIt : public Item {
 
   434       /// \brief Default constructor.
 
   436       /// Default constructor.
 
   437       /// \warning The default constructor is not required to set
 
   438       /// the iterator to some well-defined value. So you should consider it
 
   439       /// as uninitialized.
 
   442       /// \brief Copy constructor.
 
   444       /// Copy constructor.
 
   445       GraphItemIt(const GraphItemIt& it) : Item(it) {}
 
   447       /// \brief Constructor that sets the iterator to the first item.
 
   449       /// Constructor that sets the iterator to the first item.
 
   450       explicit GraphItemIt(const GR&) {}
 
   452       /// \brief Constructor for conversion from \c INVALID.
 
   454       /// Constructor for conversion from \c INVALID.
 
   455       /// It initializes the iterator to be invalid.
 
   456       /// \sa Invalid for more details.
 
   457       GraphItemIt(Invalid) {}
 
   459       /// \brief Assignment operator.
 
   461       /// Assignment operator for the iterator.
 
   462       GraphItemIt& operator=(const GraphItemIt&) { return *this; }
 
   464       /// \brief Increment the iterator.
 
   466       /// This operator increments the iterator, i.e. assigns it to the
 
   468       GraphItemIt& operator++() { return *this; }
 
   470       /// \brief Equality operator
 
   472       /// Equality operator.
 
   473       /// Two iterators are equal if and only if they point to the
 
   474       /// same object or both are invalid.
 
   475       bool operator==(const GraphItemIt&) const { return true;}
 
   477       /// \brief Inequality operator
 
   479       /// Inequality operator.
 
   480       /// Two iterators are equal if and only if they point to the
 
   481       /// same object or both are invalid.
 
   482       bool operator!=(const GraphItemIt&) const { return true;}
 
   484       template<typename _GraphItemIt>
 
   487           checkConcept<GraphItem<>, _GraphItemIt>();
 
   490           _GraphItemIt it3 = it1;
 
   491           _GraphItemIt it4 = INVALID;
 
   504     /// \brief Concept class for \c InArcIt, \c OutArcIt and
 
   505     /// \c IncEdgeIt types.
 
   507     /// This class describes the concept of \c InArcIt, \c OutArcIt
 
   508     /// and \c IncEdgeIt subtypes of digraph and graph types.
 
   510     /// \note Since these iterator classes do not inherit from the same
 
   511     /// base class, there is an additional template parameter (selector)
 
   512     /// \c sel. For \c InArcIt you should instantiate it with character
 
   513     /// \c 'i', for \c OutArcIt with \c 'o' and for \c IncEdgeIt with \c 'e'.
 
   514     template <typename GR,
 
   515               typename Item = typename GR::Arc,
 
   516               typename Base = typename GR::Node,
 
   518     class GraphIncIt : public Item {
 
   520       /// \brief Default constructor.
 
   522       /// Default constructor.
 
   523       /// \warning The default constructor is not required to set
 
   524       /// the iterator to some well-defined value. So you should consider it
 
   525       /// as uninitialized.
 
   528       /// \brief Copy constructor.
 
   530       /// Copy constructor.
 
   531       GraphIncIt(const GraphIncIt& it) : Item(it) {}
 
   533       /// \brief Constructor that sets the iterator to the first
 
   534       /// incoming or outgoing arc.
 
   536       /// Constructor that sets the iterator to the first arc
 
   537       /// incoming to or outgoing from the given node.
 
   538       explicit GraphIncIt(const GR&, const Base&) {}
 
   540       /// \brief Constructor for conversion from \c INVALID.
 
   542       /// Constructor for conversion from \c INVALID.
 
   543       /// It initializes the iterator to be invalid.
 
   544       /// \sa Invalid for more details.
 
   545       GraphIncIt(Invalid) {}
 
   547       /// \brief Assignment operator.
 
   549       /// Assignment operator for the iterator.
 
   550       GraphIncIt& operator=(const GraphIncIt&) { return *this; }
 
   552       /// \brief Increment the iterator.
 
   554       /// This operator increments the iterator, i.e. assigns it to the
 
   555       /// next arc incoming to or outgoing from the given node.
 
   556       GraphIncIt& operator++() { return *this; }
 
   558       /// \brief Equality operator
 
   560       /// Equality operator.
 
   561       /// Two iterators are equal if and only if they point to the
 
   562       /// same object or both are invalid.
 
   563       bool operator==(const GraphIncIt&) const { return true;}
 
   565       /// \brief Inequality operator
 
   567       /// Inequality operator.
 
   568       /// Two iterators are equal if and only if they point to the
 
   569       /// same object or both are invalid.
 
   570       bool operator!=(const GraphIncIt&) const { return true;}
 
   572       template <typename _GraphIncIt>
 
   575           checkConcept<GraphItem<sel>, _GraphIncIt>();
 
   576           _GraphIncIt it1(graph, node);
 
   578           _GraphIncIt it3 = it1;
 
   579           _GraphIncIt it4 = INVALID;
 
   592     /// \brief Skeleton class for iterable directed graphs.
 
   594     /// This class describes the interface of iterable directed
 
   595     /// graphs. It extends \ref BaseDigraphComponent with the core
 
   596     /// iterable interface.
 
   597     /// This concept is part of the Digraph concept.
 
   598     template <typename BAS = BaseDigraphComponent>
 
   599     class IterableDigraphComponent : public BAS {
 
   604       typedef typename Base::Node Node;
 
   605       typedef typename Base::Arc Arc;
 
   607       typedef IterableDigraphComponent Digraph;
 
   609       /// \name Base Iteration
 
   611       /// This interface provides functions for iteration on digraph items.
 
   615       /// \brief Return the first node.
 
   617       /// This function gives back the first node in the iteration order.
 
   618       void first(Node&) const {}
 
   620       /// \brief Return the next node.
 
   622       /// This function gives back the next node in the iteration order.
 
   623       void next(Node&) const {}
 
   625       /// \brief Return the first arc.
 
   627       /// This function gives back the first arc in the iteration order.
 
   628       void first(Arc&) const {}
 
   630       /// \brief Return the next arc.
 
   632       /// This function gives back the next arc in the iteration order.
 
   633       void next(Arc&) const {}
 
   635       /// \brief Return the first arc incomming to the given node.
 
   637       /// This function gives back the first arc incomming to the
 
   639       void firstIn(Arc&, const Node&) const {}
 
   641       /// \brief Return the next arc incomming to the given node.
 
   643       /// This function gives back the next arc incomming to the
 
   645       void nextIn(Arc&) const {}
 
   647       /// \brief Return the first arc outgoing form the given node.
 
   649       /// This function gives back the first arc outgoing form the
 
   651       void firstOut(Arc&, const Node&) const {}
 
   653       /// \brief Return the next arc outgoing form the given node.
 
   655       /// This function gives back the next arc outgoing form the
 
   657       void nextOut(Arc&) const {}
 
   661       /// \name Class Based Iteration
 
   663       /// This interface provides iterator classes for digraph items.
 
   667       /// \brief This iterator goes through each node.
 
   669       /// This iterator goes through each node.
 
   671       typedef GraphItemIt<Digraph, Node> NodeIt;
 
   673       /// \brief This iterator goes through each arc.
 
   675       /// This iterator goes through each arc.
 
   677       typedef GraphItemIt<Digraph, Arc> ArcIt;
 
   679       /// \brief This iterator goes trough the incoming arcs of a node.
 
   681       /// This iterator goes trough the \e incoming arcs of a certain node
 
   683       typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt;
 
   685       /// \brief This iterator goes trough the outgoing arcs of a node.
 
   687       /// This iterator goes trough the \e outgoing arcs of a certain node
 
   689       typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt;
 
   691       /// \brief The base node of the iterator.
 
   693       /// This function gives back the base node of the iterator.
 
   694       /// It is always the target node of the pointed arc.
 
   695       Node baseNode(const InArcIt&) const { return INVALID; }
 
   697       /// \brief The running node of the iterator.
 
   699       /// This function gives back the running node of the iterator.
 
   700       /// It is always the source node of the pointed arc.
 
   701       Node runningNode(const InArcIt&) const { return INVALID; }
 
   703       /// \brief The base node of the iterator.
 
   705       /// This function gives back the base node of the iterator.
 
   706       /// It is always the source node of the pointed arc.
 
   707       Node baseNode(const OutArcIt&) const { return INVALID; }
 
   709       /// \brief The running node of the iterator.
 
   711       /// This function gives back the running node of the iterator.
 
   712       /// It is always the target node of the pointed arc.
 
   713       Node runningNode(const OutArcIt&) const { return INVALID; }
 
   717       template <typename _Digraph>
 
   720           checkConcept<Base, _Digraph>();
 
   723             typename _Digraph::Node node(INVALID);
 
   724             typename _Digraph::Arc arc(INVALID);
 
   734               digraph.firstIn(arc, node);
 
   738               digraph.firstOut(arc, node);
 
   739               digraph.nextOut(arc);
 
   744             checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>,
 
   745               typename _Digraph::ArcIt >();
 
   746             checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>,
 
   747               typename _Digraph::NodeIt >();
 
   748             checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
 
   749               typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>();
 
   750             checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
 
   751               typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>();
 
   753             typename _Digraph::Node n;
 
   754             const typename _Digraph::InArcIt iait(INVALID);
 
   755             const typename _Digraph::OutArcIt oait(INVALID);
 
   756             n = digraph.baseNode(iait);
 
   757             n = digraph.runningNode(iait);
 
   758             n = digraph.baseNode(oait);
 
   759             n = digraph.runningNode(oait);
 
   760             ignore_unused_variable_warning(n);
 
   764         const _Digraph& digraph;
 
   768     /// \brief Skeleton class for iterable undirected graphs.
 
   770     /// This class describes the interface of iterable undirected
 
   771     /// graphs. It extends \ref IterableDigraphComponent with the core
 
   772     /// iterable interface of undirected graphs.
 
   773     /// This concept is part of the Graph concept.
 
   774     template <typename BAS = BaseGraphComponent>
 
   775     class IterableGraphComponent : public IterableDigraphComponent<BAS> {
 
   779       typedef typename Base::Node Node;
 
   780       typedef typename Base::Arc Arc;
 
   781       typedef typename Base::Edge Edge;
 
   784       typedef IterableGraphComponent Graph;
 
   786       /// \name Base Iteration
 
   788       /// This interface provides functions for iteration on edges.
 
   792       using IterableDigraphComponent<Base>::first;
 
   793       using IterableDigraphComponent<Base>::next;
 
   795       /// \brief Return the first edge.
 
   797       /// This function gives back the first edge in the iteration order.
 
   798       void first(Edge&) const {}
 
   800       /// \brief Return the next edge.
 
   802       /// This function gives back the next edge in the iteration order.
 
   803       void next(Edge&) const {}
 
   805       /// \brief Return the first edge incident to the given node.
 
   807       /// This function gives back the first edge incident to the given
 
   808       /// node. The bool parameter gives back the direction for which the
 
   809       /// source node of the directed arc representing the edge is the
 
   811       void firstInc(Edge&, bool&, const Node&) const {}
 
   813       /// \brief Gives back the next of the edges from the
 
   816       /// This function gives back the next edge incident to the given
 
   817       /// node. The bool parameter should be used as \c firstInc() use it.
 
   818       void nextInc(Edge&, bool&) const {}
 
   820       using IterableDigraphComponent<Base>::baseNode;
 
   821       using IterableDigraphComponent<Base>::runningNode;
 
   825       /// \name Class Based Iteration
 
   827       /// This interface provides iterator classes for edges.
 
   831       /// \brief This iterator goes through each edge.
 
   833       /// This iterator goes through each edge.
 
   834       typedef GraphItemIt<Graph, Edge> EdgeIt;
 
   836       /// \brief This iterator goes trough the incident edges of a
 
   839       /// This iterator goes trough the incident edges of a certain
 
   841       typedef GraphIncIt<Graph, Edge, Node, 'e'> IncEdgeIt;
 
   843       /// \brief The base node of the iterator.
 
   845       /// This function gives back the base node of the iterator.
 
   846       Node baseNode(const IncEdgeIt&) const { return INVALID; }
 
   848       /// \brief The running node of the iterator.
 
   850       /// This function gives back the running node of the iterator.
 
   851       Node runningNode(const IncEdgeIt&) const { return INVALID; }
 
   855       template <typename _Graph>
 
   858           checkConcept<IterableDigraphComponent<Base>, _Graph>();
 
   861             typename _Graph::Node node(INVALID);
 
   862             typename _Graph::Edge edge(INVALID);
 
   869               graph.firstInc(edge, dir, node);
 
   870               graph.nextInc(edge, dir);
 
   876             checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>,
 
   877               typename _Graph::EdgeIt >();
 
   878             checkConcept<GraphIncIt<_Graph, typename _Graph::Edge,
 
   879               typename _Graph::Node, 'e'>, typename _Graph::IncEdgeIt>();
 
   881             typename _Graph::Node n;
 
   882             const typename _Graph::IncEdgeIt ieit(INVALID);
 
   883             n = graph.baseNode(ieit);
 
   884             n = graph.runningNode(ieit);
 
   892     /// \brief Skeleton class for alterable directed graphs.
 
   894     /// This class describes the interface of alterable directed
 
   895     /// graphs. It extends \ref BaseDigraphComponent with the alteration
 
   896     /// notifier interface. It implements
 
   897     /// an observer-notifier pattern for each digraph item. More
 
   898     /// obsevers can be registered into the notifier and whenever an
 
   899     /// alteration occured in the digraph all the observers will be
 
   900     /// notified about it.
 
   901     template <typename BAS = BaseDigraphComponent>
 
   902     class AlterableDigraphComponent : public BAS {
 
   906       typedef typename Base::Node Node;
 
   907       typedef typename Base::Arc Arc;
 
   910       /// Node alteration notifier class.
 
   911       typedef AlterationNotifier<AlterableDigraphComponent, Node>
 
   913       /// Arc alteration notifier class.
 
   914       typedef AlterationNotifier<AlterableDigraphComponent, Arc>
 
   917       /// \brief Return the node alteration notifier.
 
   919       /// This function gives back the node alteration notifier.
 
   920       NodeNotifier& notifier(Node) const {
 
   921          return NodeNotifier();
 
   924       /// \brief Return the arc alteration notifier.
 
   926       /// This function gives back the arc alteration notifier.
 
   927       ArcNotifier& notifier(Arc) const {
 
   928         return ArcNotifier();
 
   931       template <typename _Digraph>
 
   934           checkConcept<Base, _Digraph>();
 
   935           typename _Digraph::NodeNotifier& nn
 
   936             = digraph.notifier(typename _Digraph::Node());
 
   938           typename _Digraph::ArcNotifier& en
 
   939             = digraph.notifier(typename _Digraph::Arc());
 
   941           ignore_unused_variable_warning(nn);
 
   942           ignore_unused_variable_warning(en);
 
   945         const _Digraph& digraph;
 
   949     /// \brief Skeleton class for alterable undirected graphs.
 
   951     /// This class describes the interface of alterable undirected
 
   952     /// graphs. It extends \ref AlterableDigraphComponent with the alteration
 
   953     /// notifier interface of undirected graphs. It implements
 
   954     /// an observer-notifier pattern for the edges. More
 
   955     /// obsevers can be registered into the notifier and whenever an
 
   956     /// alteration occured in the graph all the observers will be
 
   957     /// notified about it.
 
   958     template <typename BAS = BaseGraphComponent>
 
   959     class AlterableGraphComponent : public AlterableDigraphComponent<BAS> {
 
   963       typedef typename Base::Edge Edge;
 
   966       /// Edge alteration notifier class.
 
   967       typedef AlterationNotifier<AlterableGraphComponent, Edge>
 
   970       /// \brief Return the edge alteration notifier.
 
   972       /// This function gives back the edge alteration notifier.
 
   973       EdgeNotifier& notifier(Edge) const {
 
   974         return EdgeNotifier();
 
   977       template <typename _Graph>
 
   980           checkConcept<AlterableDigraphComponent<Base>, _Graph>();
 
   981           typename _Graph::EdgeNotifier& uen
 
   982             = graph.notifier(typename _Graph::Edge());
 
   983           ignore_unused_variable_warning(uen);
 
   990     /// \brief Concept class for standard graph maps.
 
   992     /// This class describes the concept of standard graph maps, i.e.
 
   993     /// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and
 
   994     /// graph types, which can be used for associating data to graph items.
 
   995     /// The standard graph maps must conform to the ReferenceMap concept.
 
   996     template <typename GR, typename K, typename V>
 
   997     class GraphMap : public ReferenceMap<K, V, V&, const V&> {
 
   998       typedef ReferenceMap<K, V, V&, const V&> Parent;
 
  1002       /// The key type of the map.
 
  1004       /// The value type of the map.
 
  1006       /// The reference type of the map.
 
  1007       typedef Value& Reference;
 
  1008       /// The const reference type of the map.
 
  1009       typedef const Value& ConstReference;
 
  1011       // The reference map tag.
 
  1012       typedef True ReferenceMapTag;
 
  1014       /// \brief Construct a new map.
 
  1016       /// Construct a new map for the graph.
 
  1017       explicit GraphMap(const GR&) {}
 
  1018       /// \brief Construct a new map with default value.
 
  1020       /// Construct a new map for the graph and initalize the values.
 
  1021       GraphMap(const GR&, const Value&) {}
 
  1024       /// \brief Copy constructor.
 
  1026       /// Copy Constructor.
 
  1027       GraphMap(const GraphMap&) : Parent() {}
 
  1029       /// \brief Assignment operator.
 
  1031       /// Assignment operator. It does not mofify the underlying graph,
 
  1032       /// it just iterates on the current item set and set the  map
 
  1033       /// with the value returned by the assigned map.
 
  1034       template <typename CMap>
 
  1035       GraphMap& operator=(const CMap&) {
 
  1036         checkConcept<ReadMap<Key, Value>, CMap>();
 
  1041       template<typename _Map>
 
  1042       struct Constraints {
 
  1043         void constraints() {
 
  1045             <ReferenceMap<Key, Value, Value&, const Value&>, _Map>();
 
  1052           // Assignment operator
 
  1053           // ReadMap<Key, Value> cmap;
 
  1056           ignore_unused_variable_warning(m1);
 
  1057           ignore_unused_variable_warning(m2);
 
  1058           // ignore_unused_variable_warning(m3);
 
  1063         const typename GraphMap::Value &t;
 
  1068     /// \brief Skeleton class for mappable directed graphs.
 
  1070     /// This class describes the interface of mappable directed graphs.
 
  1071     /// It extends \ref BaseDigraphComponent with the standard digraph
 
  1072     /// map classes, namely \c NodeMap and \c ArcMap.
 
  1073     /// This concept is part of the Digraph concept.
 
  1074     template <typename BAS = BaseDigraphComponent>
 
  1075     class MappableDigraphComponent : public BAS  {
 
  1079       typedef typename Base::Node Node;
 
  1080       typedef typename Base::Arc Arc;
 
  1082       typedef MappableDigraphComponent Digraph;
 
  1084       /// \brief Standard graph map for the nodes.
 
  1086       /// Standard graph map for the nodes.
 
  1087       /// It conforms to the ReferenceMap concept.
 
  1088       template <typename V>
 
  1089       class NodeMap : public GraphMap<MappableDigraphComponent, Node, V> {
 
  1090         typedef GraphMap<MappableDigraphComponent, Node, V> Parent;
 
  1093         /// \brief Construct a new map.
 
  1095         /// Construct a new map for the digraph.
 
  1096         explicit NodeMap(const MappableDigraphComponent& digraph)
 
  1097           : Parent(digraph) {}
 
  1099         /// \brief Construct a new map with default value.
 
  1101         /// Construct a new map for the digraph and initalize the values.
 
  1102         NodeMap(const MappableDigraphComponent& digraph, const V& value)
 
  1103           : Parent(digraph, value) {}
 
  1106         /// \brief Copy constructor.
 
  1108         /// Copy Constructor.
 
  1109         NodeMap(const NodeMap& nm) : Parent(nm) {}
 
  1111         /// \brief Assignment operator.
 
  1113         /// Assignment operator.
 
  1114         template <typename CMap>
 
  1115         NodeMap& operator=(const CMap&) {
 
  1116           checkConcept<ReadMap<Node, V>, CMap>();
 
  1122       /// \brief Standard graph map for the arcs.
 
  1124       /// Standard graph map for the arcs.
 
  1125       /// It conforms to the ReferenceMap concept.
 
  1126       template <typename V>
 
  1127       class ArcMap : public GraphMap<MappableDigraphComponent, Arc, V> {
 
  1128         typedef GraphMap<MappableDigraphComponent, Arc, V> Parent;
 
  1131         /// \brief Construct a new map.
 
  1133         /// Construct a new map for the digraph.
 
  1134         explicit ArcMap(const MappableDigraphComponent& digraph)
 
  1135           : Parent(digraph) {}
 
  1137         /// \brief Construct a new map with default value.
 
  1139         /// Construct a new map for the digraph and initalize the values.
 
  1140         ArcMap(const MappableDigraphComponent& digraph, const V& value)
 
  1141           : Parent(digraph, value) {}
 
  1144         /// \brief Copy constructor.
 
  1146         /// Copy Constructor.
 
  1147         ArcMap(const ArcMap& nm) : Parent(nm) {}
 
  1149         /// \brief Assignment operator.
 
  1151         /// Assignment operator.
 
  1152         template <typename CMap>
 
  1153         ArcMap& operator=(const CMap&) {
 
  1154           checkConcept<ReadMap<Arc, V>, CMap>();
 
  1161       template <typename _Digraph>
 
  1162       struct Constraints {
 
  1166           Dummy() : value(0) {}
 
  1167           Dummy(int _v) : value(_v) {}
 
  1170         void constraints() {
 
  1171           checkConcept<Base, _Digraph>();
 
  1173             typedef typename _Digraph::template NodeMap<int> IntNodeMap;
 
  1174             checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>,
 
  1176           } { // bool map test
 
  1177             typedef typename _Digraph::template NodeMap<bool> BoolNodeMap;
 
  1178             checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>,
 
  1180           } { // Dummy map test
 
  1181             typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap;
 
  1182             checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>,
 
  1187             typedef typename _Digraph::template ArcMap<int> IntArcMap;
 
  1188             checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
 
  1190           } { // bool map test
 
  1191             typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
 
  1192             checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
 
  1194           } { // Dummy map test
 
  1195             typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
 
  1196             checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>,
 
  1201         const _Digraph& digraph;
 
  1205     /// \brief Skeleton class for mappable undirected graphs.
 
  1207     /// This class describes the interface of mappable undirected graphs.
 
  1208     /// It extends \ref MappableDigraphComponent with the standard graph
 
  1209     /// map class for edges (\c EdgeMap).
 
  1210     /// This concept is part of the Graph concept.
 
  1211     template <typename BAS = BaseGraphComponent>
 
  1212     class MappableGraphComponent : public MappableDigraphComponent<BAS>  {
 
  1216       typedef typename Base::Edge Edge;
 
  1218       typedef MappableGraphComponent Graph;
 
  1220       /// \brief Standard graph map for the edges.
 
  1222       /// Standard graph map for the edges.
 
  1223       /// It conforms to the ReferenceMap concept.
 
  1224       template <typename V>
 
  1225       class EdgeMap : public GraphMap<MappableGraphComponent, Edge, V> {
 
  1226         typedef GraphMap<MappableGraphComponent, Edge, V> Parent;
 
  1229         /// \brief Construct a new map.
 
  1231         /// Construct a new map for the graph.
 
  1232         explicit EdgeMap(const MappableGraphComponent& graph)
 
  1235         /// \brief Construct a new map with default value.
 
  1237         /// Construct a new map for the graph and initalize the values.
 
  1238         EdgeMap(const MappableGraphComponent& graph, const V& value)
 
  1239           : Parent(graph, value) {}
 
  1242         /// \brief Copy constructor.
 
  1244         /// Copy Constructor.
 
  1245         EdgeMap(const EdgeMap& nm) : Parent(nm) {}
 
  1247         /// \brief Assignment operator.
 
  1249         /// Assignment operator.
 
  1250         template <typename CMap>
 
  1251         EdgeMap& operator=(const CMap&) {
 
  1252           checkConcept<ReadMap<Edge, V>, CMap>();
 
  1259       template <typename _Graph>
 
  1260       struct Constraints {
 
  1264           Dummy() : value(0) {}
 
  1265           Dummy(int _v) : value(_v) {}
 
  1268         void constraints() {
 
  1269           checkConcept<MappableDigraphComponent<Base>, _Graph>();
 
  1272             typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
 
  1273             checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
 
  1275           } { // bool map test
 
  1276             typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
 
  1277             checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
 
  1279           } { // Dummy map test
 
  1280             typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
 
  1281             checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>,
 
  1286         const _Graph& graph;
 
  1290     /// \brief Skeleton class for extendable directed graphs.
 
  1292     /// This class describes the interface of extendable directed graphs.
 
  1293     /// It extends \ref BaseDigraphComponent with functions for adding
 
  1294     /// nodes and arcs to the digraph.
 
  1295     /// This concept requires \ref AlterableDigraphComponent.
 
  1296     template <typename BAS = BaseDigraphComponent>
 
  1297     class ExtendableDigraphComponent : public BAS {
 
  1301       typedef typename Base::Node Node;
 
  1302       typedef typename Base::Arc Arc;
 
  1304       /// \brief Add a new node to the digraph.
 
  1306       /// This function adds a new node to the digraph.
 
  1311       /// \brief Add a new arc connecting the given two nodes.
 
  1313       /// This function adds a new arc connecting the given two nodes
 
  1315       Arc addArc(const Node&, const Node&) {
 
  1319       template <typename _Digraph>
 
  1320       struct Constraints {
 
  1321         void constraints() {
 
  1322           checkConcept<Base, _Digraph>();
 
  1323           typename _Digraph::Node node_a, node_b;
 
  1324           node_a = digraph.addNode();
 
  1325           node_b = digraph.addNode();
 
  1326           typename _Digraph::Arc arc;
 
  1327           arc = digraph.addArc(node_a, node_b);
 
  1334     /// \brief Skeleton class for extendable undirected graphs.
 
  1336     /// This class describes the interface of extendable undirected graphs.
 
  1337     /// It extends \ref BaseGraphComponent with functions for adding
 
  1338     /// nodes and edges to the graph.
 
  1339     /// This concept requires \ref AlterableGraphComponent.
 
  1340     template <typename BAS = BaseGraphComponent>
 
  1341     class ExtendableGraphComponent : public BAS {
 
  1345       typedef typename Base::Node Node;
 
  1346       typedef typename Base::Edge Edge;
 
  1348       /// \brief Add a new node to the digraph.
 
  1350       /// This function adds a new node to the digraph.
 
  1355       /// \brief Add a new edge connecting the given two nodes.
 
  1357       /// This function adds a new edge connecting the given two nodes
 
  1359       Edge addEdge(const Node&, const Node&) {
 
  1363       template <typename _Graph>
 
  1364       struct Constraints {
 
  1365         void constraints() {
 
  1366           checkConcept<Base, _Graph>();
 
  1367           typename _Graph::Node node_a, node_b;
 
  1368           node_a = graph.addNode();
 
  1369           node_b = graph.addNode();
 
  1370           typename _Graph::Edge edge;
 
  1371           edge = graph.addEdge(node_a, node_b);
 
  1378     /// \brief Skeleton class for erasable directed graphs.
 
  1380     /// This class describes the interface of erasable directed graphs.
 
  1381     /// It extends \ref BaseDigraphComponent with functions for removing
 
  1382     /// nodes and arcs from the digraph.
 
  1383     /// This concept requires \ref AlterableDigraphComponent.
 
  1384     template <typename BAS = BaseDigraphComponent>
 
  1385     class ErasableDigraphComponent : public BAS {
 
  1389       typedef typename Base::Node Node;
 
  1390       typedef typename Base::Arc Arc;
 
  1392       /// \brief Erase a node from the digraph.
 
  1394       /// This function erases the given node from the digraph and all arcs
 
  1395       /// connected to the node.
 
  1396       void erase(const Node&) {}
 
  1398       /// \brief Erase an arc from the digraph.
 
  1400       /// This function erases the given arc from the digraph.
 
  1401       void erase(const Arc&) {}
 
  1403       template <typename _Digraph>
 
  1404       struct Constraints {
 
  1405         void constraints() {
 
  1406           checkConcept<Base, _Digraph>();
 
  1407           const typename _Digraph::Node node(INVALID);
 
  1408           digraph.erase(node);
 
  1409           const typename _Digraph::Arc arc(INVALID);
 
  1417     /// \brief Skeleton class for erasable undirected graphs.
 
  1419     /// This class describes the interface of erasable undirected graphs.
 
  1420     /// It extends \ref BaseGraphComponent with functions for removing
 
  1421     /// nodes and edges from the graph.
 
  1422     /// This concept requires \ref AlterableGraphComponent.
 
  1423     template <typename BAS = BaseGraphComponent>
 
  1424     class ErasableGraphComponent : public BAS {
 
  1428       typedef typename Base::Node Node;
 
  1429       typedef typename Base::Edge Edge;
 
  1431       /// \brief Erase a node from the graph.
 
  1433       /// This function erases the given node from the graph and all edges
 
  1434       /// connected to the node.
 
  1435       void erase(const Node&) {}
 
  1437       /// \brief Erase an edge from the digraph.
 
  1439       /// This function erases the given edge from the digraph.
 
  1440       void erase(const Edge&) {}
 
  1442       template <typename _Graph>
 
  1443       struct Constraints {
 
  1444         void constraints() {
 
  1445           checkConcept<Base, _Graph>();
 
  1446           const typename _Graph::Node node(INVALID);
 
  1448           const typename _Graph::Edge edge(INVALID);
 
  1456     /// \brief Skeleton class for clearable directed graphs.
 
  1458     /// This class describes the interface of clearable directed graphs.
 
  1459     /// It extends \ref BaseDigraphComponent with a function for clearing
 
  1461     /// This concept requires \ref AlterableDigraphComponent.
 
  1462     template <typename BAS = BaseDigraphComponent>
 
  1463     class ClearableDigraphComponent : public BAS {
 
  1468       /// \brief Erase all nodes and arcs from the digraph.
 
  1470       /// This function erases all nodes and arcs from the digraph.
 
  1473       template <typename _Digraph>
 
  1474       struct Constraints {
 
  1475         void constraints() {
 
  1476           checkConcept<Base, _Digraph>();
 
  1484     /// \brief Skeleton class for clearable undirected graphs.
 
  1486     /// This class describes the interface of clearable undirected graphs.
 
  1487     /// It extends \ref BaseGraphComponent with a function for clearing
 
  1489     /// This concept requires \ref AlterableGraphComponent.
 
  1490     template <typename BAS = BaseGraphComponent>
 
  1491     class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {
 
  1496       /// \brief Erase all nodes and edges from the graph.
 
  1498       /// This function erases all nodes and edges from the graph.
 
  1501       template <typename _Graph>
 
  1502       struct Constraints {
 
  1503         void constraints() {
 
  1504           checkConcept<Base, _Graph>();