lemon/concepts/graph_components.h
author Peter Kovacs <kpeter@inf.elte.hu>
Sun, 29 Mar 2009 23:08:20 +0200
changeset 559 c5fd2d996909
parent 534 6d3a9eec82b4
child 579 d11bf7998905
permissions -rw-r--r--
Various doc improvements (#248)
- Rename all the ugly template parameters (too long and/or starting
with an underscore).
- Rename function parameters starting with an underscore.
- Extend the doc for many classes.
- Use LaTeX-style O(...) expressions only for the complicated ones.
- A lot of small unification changes.
- Small fixes.
- Some other improvements.
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@57
     2
 *
alpar@209
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@57
     4
 *
alpar@440
     5
 * Copyright (C) 2003-2009
deba@57
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@57
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@57
     8
 *
deba@57
     9
 * Permission to use, modify and distribute this software is granted
deba@57
    10
 * provided that this copyright notice appears in all copies. For
deba@57
    11
 * precise terms see the accompanying LICENSE file.
deba@57
    12
 *
deba@57
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@57
    14
 * express or implied, and with no claim as to its suitability for any
deba@57
    15
 * purpose.
deba@57
    16
 *
deba@57
    17
 */
deba@57
    18
deba@57
    19
///\ingroup graph_concepts
deba@57
    20
///\file
deba@57
    21
///\brief The concept of graph components.
deba@57
    22
deba@529
    23
#ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H
deba@529
    24
#define LEMON_CONCEPTS_GRAPH_COMPONENTS_H
deba@57
    25
deba@220
    26
#include <lemon/core.h>
deba@57
    27
#include <lemon/concepts/maps.h>
deba@57
    28
deba@57
    29
#include <lemon/bits/alteration_notifier.h>
deba@57
    30
deba@57
    31
namespace lemon {
deba@57
    32
  namespace concepts {
deba@57
    33
deba@57
    34
    /// \brief Skeleton class for graph Node and Arc types
deba@57
    35
    ///
deba@57
    36
    /// This class describes the interface of Node and Arc (and Edge
deba@57
    37
    /// in undirected graphs) subtypes of graph types.
deba@57
    38
    ///
deba@57
    39
    /// \note This class is a template class so that we can use it to
deba@57
    40
    /// create graph skeleton classes. The reason for this is than Node
deba@57
    41
    /// and Arc types should \em not derive from the same base class.
deba@57
    42
    /// For Node you should instantiate it with character 'n' and for Arc
deba@57
    43
    /// with 'a'.
deba@57
    44
deba@57
    45
#ifndef DOXYGEN
kpeter@559
    46
    template <char sel = '0'>
deba@57
    47
#endif
deba@57
    48
    class GraphItem {
deba@57
    49
    public:
deba@57
    50
      /// \brief Default constructor.
alpar@209
    51
      ///
deba@57
    52
      /// \warning The default constructor is not required to set
deba@57
    53
      /// the item to some well-defined value. So you should consider it
deba@57
    54
      /// as uninitialized.
deba@57
    55
      GraphItem() {}
deba@57
    56
      /// \brief Copy constructor.
deba@57
    57
      ///
deba@57
    58
      /// Copy constructor.
deba@57
    59
      ///
deba@57
    60
      GraphItem(const GraphItem &) {}
deba@57
    61
      /// \brief Invalid constructor \& conversion.
deba@57
    62
      ///
deba@57
    63
      /// This constructor initializes the item to be invalid.
deba@57
    64
      /// \sa Invalid for more details.
deba@57
    65
      GraphItem(Invalid) {}
deba@57
    66
      /// \brief Assign operator for nodes.
deba@57
    67
      ///
alpar@209
    68
      /// The nodes are assignable.
deba@57
    69
      ///
deba@57
    70
      GraphItem& operator=(GraphItem const&) { return *this; }
deba@57
    71
      /// \brief Equality operator.
deba@57
    72
      ///
deba@57
    73
      /// Two iterators are equal if and only if they represents the
deba@57
    74
      /// same node in the graph or both are invalid.
deba@57
    75
      bool operator==(GraphItem) const { return false; }
deba@57
    76
      /// \brief Inequality operator.
deba@57
    77
      ///
deba@57
    78
      /// \sa operator==(const Node& n)
deba@57
    79
      ///
deba@57
    80
      bool operator!=(GraphItem) const { return false; }
deba@57
    81
deba@57
    82
      /// \brief Artificial ordering operator.
deba@57
    83
      ///
deba@57
    84
      /// To allow the use of graph descriptors as key type in std::map or
deba@57
    85
      /// similar associative container we require this.
deba@57
    86
      ///
deba@57
    87
      /// \note This operator only have to define some strict ordering of
deba@57
    88
      /// the items; this order has nothing to do with the iteration
deba@57
    89
      /// ordering of the items.
deba@57
    90
      bool operator<(GraphItem) const { return false; }
deba@57
    91
deba@57
    92
      template<typename _GraphItem>
deba@57
    93
      struct Constraints {
alpar@209
    94
        void constraints() {
alpar@209
    95
          _GraphItem i1;
alpar@209
    96
          _GraphItem i2 = i1;
alpar@209
    97
          _GraphItem i3 = INVALID;
deba@57
    98
alpar@209
    99
          i1 = i2 = i3;
alpar@209
   100
alpar@209
   101
          bool b;
alpar@209
   102
          //          b = (ia == ib) && (ia != ib) && (ia < ib);
alpar@209
   103
          b = (ia == ib) && (ia != ib);
alpar@209
   104
          b = (ia == INVALID) && (ib != INVALID);
deba@57
   105
          b = (ia < ib);
alpar@209
   106
        }
deba@57
   107
alpar@209
   108
        const _GraphItem &ia;
alpar@209
   109
        const _GraphItem &ib;
deba@57
   110
      };
deba@57
   111
    };
deba@57
   112
deba@57
   113
    /// \brief An empty base directed graph class.
alpar@209
   114
    ///
deba@57
   115
    /// This class provides the minimal set of features needed for a
kpeter@492
   116
    /// directed graph structure. All digraph concepts have to
deba@57
   117
    /// conform to this base directed graph. It just provides types
deba@57
   118
    /// for nodes and arcs and functions to get the source and the
deba@57
   119
    /// target of the arcs.
deba@57
   120
    class BaseDigraphComponent {
deba@57
   121
    public:
deba@57
   122
deba@57
   123
      typedef BaseDigraphComponent Digraph;
alpar@209
   124
deba@57
   125
      /// \brief Node class of the digraph.
deba@57
   126
      ///
alpar@209
   127
      /// This class represents the Nodes of the digraph.
deba@57
   128
      ///
deba@57
   129
      typedef GraphItem<'n'> Node;
deba@57
   130
deba@57
   131
      /// \brief Arc class of the digraph.
deba@57
   132
      ///
alpar@209
   133
      /// This class represents the Arcs of the digraph.
deba@57
   134
      ///
deba@57
   135
      typedef GraphItem<'e'> Arc;
deba@57
   136
deba@57
   137
      /// \brief Gives back the target node of an arc.
deba@57
   138
      ///
deba@57
   139
      /// Gives back the target node of an arc.
deba@57
   140
      ///
deba@57
   141
      Node target(const Arc&) const { return INVALID;}
deba@57
   142
deba@57
   143
      /// \brief Gives back the source node of an arc.
deba@57
   144
      ///
deba@57
   145
      /// Gives back the source node of an arc.
deba@57
   146
      ///
deba@57
   147
      Node source(const Arc&) const { return INVALID;}
deba@57
   148
deba@57
   149
      /// \brief Gives back the opposite node on the given arc.
deba@57
   150
      ///
deba@57
   151
      /// Gives back the opposite node on the given arc.
deba@57
   152
      Node oppositeNode(const Node&, const Arc&) const {
deba@57
   153
        return INVALID;
deba@57
   154
      }
deba@57
   155
deba@57
   156
      template <typename _Digraph>
deba@57
   157
      struct Constraints {
alpar@209
   158
        typedef typename _Digraph::Node Node;
alpar@209
   159
        typedef typename _Digraph::Arc Arc;
alpar@209
   160
alpar@209
   161
        void constraints() {
alpar@209
   162
          checkConcept<GraphItem<'n'>, Node>();
alpar@209
   163
          checkConcept<GraphItem<'a'>, Arc>();
alpar@209
   164
          {
alpar@209
   165
            Node n;
alpar@209
   166
            Arc e(INVALID);
alpar@209
   167
            n = digraph.source(e);
alpar@209
   168
            n = digraph.target(e);
deba@57
   169
            n = digraph.oppositeNode(n, e);
alpar@209
   170
          }
alpar@209
   171
        }
alpar@209
   172
alpar@209
   173
        const _Digraph& digraph;
deba@57
   174
      };
deba@57
   175
    };
deba@57
   176
deba@57
   177
    /// \brief An empty base undirected graph class.
alpar@209
   178
    ///
deba@57
   179
    /// This class provides the minimal set of features needed for an
deba@57
   180
    /// undirected graph structure. All undirected graph concepts have
kpeter@492
   181
    /// to conform to this base graph. It just provides types for
deba@57
   182
    /// nodes, arcs and edges and functions to get the
deba@57
   183
    /// source and the target of the arcs and edges,
deba@57
   184
    /// conversion from arcs to edges and function to get
deba@57
   185
    /// both direction of the edges.
deba@57
   186
    class BaseGraphComponent : public BaseDigraphComponent {
deba@57
   187
    public:
deba@57
   188
      typedef BaseDigraphComponent::Node Node;
deba@57
   189
      typedef BaseDigraphComponent::Arc Arc;
deba@57
   190
      /// \brief Undirected arc class of the graph.
deba@57
   191
      ///
deba@57
   192
      /// This class represents the edges of the graph.
deba@57
   193
      /// The undirected graphs can be used as a directed graph which
deba@57
   194
      /// for each arc contains the opposite arc too so the graph is
deba@57
   195
      /// bidirected. The edge represents two opposite
deba@57
   196
      /// directed arcs.
deba@57
   197
      class Edge : public GraphItem<'u'> {
deba@57
   198
      public:
deba@57
   199
        typedef GraphItem<'u'> Parent;
deba@57
   200
        /// \brief Default constructor.
alpar@209
   201
        ///
deba@57
   202
        /// \warning The default constructor is not required to set
deba@57
   203
        /// the item to some well-defined value. So you should consider it
deba@57
   204
        /// as uninitialized.
deba@57
   205
        Edge() {}
deba@57
   206
        /// \brief Copy constructor.
deba@57
   207
        ///
deba@57
   208
        /// Copy constructor.
deba@57
   209
        ///
deba@57
   210
        Edge(const Edge &) : Parent() {}
deba@57
   211
        /// \brief Invalid constructor \& conversion.
deba@57
   212
        ///
deba@57
   213
        /// This constructor initializes the item to be invalid.
deba@57
   214
        /// \sa Invalid for more details.
deba@57
   215
        Edge(Invalid) {}
deba@57
   216
        /// \brief Converter from arc to edge.
deba@57
   217
        ///
deba@57
   218
        /// Besides the core graph item functionality each arc should
alpar@209
   219
        /// be convertible to the represented edge.
deba@57
   220
        Edge(const Arc&) {}
deba@57
   221
        /// \brief Assign arc to edge.
deba@57
   222
        ///
deba@57
   223
        /// Besides the core graph item functionality each arc should
alpar@209
   224
        /// be convertible to the represented edge.
deba@57
   225
        Edge& operator=(const Arc&) { return *this; }
deba@57
   226
      };
deba@57
   227
deba@57
   228
      /// \brief Returns the direction of the arc.
deba@57
   229
      ///
deba@57
   230
      /// Returns the direction of the arc. Each arc represents an
deba@57
   231
      /// edge with a direction. It gives back the
deba@57
   232
      /// direction.
deba@57
   233
      bool direction(const Arc&) const { return true; }
deba@57
   234
deba@57
   235
      /// \brief Returns the directed arc.
deba@57
   236
      ///
deba@57
   237
      /// Returns the directed arc from its direction and the
deba@57
   238
      /// represented edge.
alpar@209
   239
      Arc direct(const Edge&, bool) const { return INVALID;}
deba@57
   240
deba@57
   241
      /// \brief Returns the directed arc.
deba@57
   242
      ///
deba@57
   243
      /// Returns the directed arc from its source and the
deba@57
   244
      /// represented edge.
alpar@209
   245
      Arc direct(const Edge&, const Node&) const { return INVALID;}
deba@57
   246
deba@57
   247
      /// \brief Returns the opposite arc.
deba@57
   248
      ///
deba@57
   249
      /// Returns the opposite arc. It is the arc representing the
deba@57
   250
      /// same edge and has opposite direction.
deba@57
   251
      Arc oppositeArc(const Arc&) const { return INVALID;}
deba@57
   252
deba@57
   253
      /// \brief Gives back one ending of an edge.
deba@57
   254
      ///
deba@57
   255
      /// Gives back one ending of an edge.
deba@57
   256
      Node u(const Edge&) const { return INVALID;}
deba@57
   257
deba@57
   258
      /// \brief Gives back the other ending of an edge.
deba@57
   259
      ///
deba@57
   260
      /// Gives back the other ending of an edge.
deba@57
   261
      Node v(const Edge&) const { return INVALID;}
alpar@209
   262
deba@57
   263
      template <typename _Graph>
deba@57
   264
      struct Constraints {
alpar@209
   265
        typedef typename _Graph::Node Node;
alpar@209
   266
        typedef typename _Graph::Arc Arc;
alpar@209
   267
        typedef typename _Graph::Edge Edge;
alpar@209
   268
alpar@209
   269
        void constraints() {
deba@57
   270
          checkConcept<BaseDigraphComponent, _Graph>();
alpar@209
   271
          checkConcept<GraphItem<'u'>, Edge>();
alpar@209
   272
          {
alpar@209
   273
            Node n;
alpar@209
   274
            Edge ue(INVALID);
deba@57
   275
            Arc e;
alpar@209
   276
            n = graph.u(ue);
alpar@209
   277
            n = graph.v(ue);
deba@57
   278
            e = graph.direct(ue, true);
deba@57
   279
            e = graph.direct(ue, n);
deba@57
   280
            e = graph.oppositeArc(e);
deba@57
   281
            ue = e;
deba@57
   282
            bool d = graph.direction(e);
deba@57
   283
            ignore_unused_variable_warning(d);
alpar@209
   284
          }
alpar@209
   285
        }
alpar@209
   286
alpar@209
   287
        const _Graph& graph;
deba@57
   288
      };
deba@57
   289
deba@57
   290
    };
deba@57
   291
deba@57
   292
    /// \brief An empty idable base digraph class.
alpar@209
   293
    ///
deba@57
   294
    /// This class provides beside the core digraph features
deba@57
   295
    /// core id functions for the digraph structure.
kpeter@492
   296
    /// The most of the base digraphs should conform to this concept.
deba@57
   297
    /// The id's are unique and immutable.
kpeter@559
   298
    template <typename BAS = BaseDigraphComponent>
kpeter@559
   299
    class IDableDigraphComponent : public BAS {
deba@57
   300
    public:
deba@57
   301
kpeter@559
   302
      typedef BAS Base;
deba@57
   303
      typedef typename Base::Node Node;
deba@57
   304
      typedef typename Base::Arc Arc;
deba@57
   305
alpar@209
   306
      /// \brief Gives back an unique integer id for the Node.
deba@57
   307
      ///
alpar@209
   308
      /// Gives back an unique integer id for the Node.
deba@57
   309
      ///
deba@57
   310
      int id(const Node&) const { return -1;}
deba@57
   311
deba@57
   312
      /// \brief Gives back the node by the unique id.
deba@57
   313
      ///
deba@57
   314
      /// Gives back the node by the unique id.
deba@57
   315
      /// If the digraph does not contain node with the given id
alpar@209
   316
      /// then the result of the function is undetermined.
deba@57
   317
      Node nodeFromId(int) const { return INVALID;}
deba@57
   318
alpar@209
   319
      /// \brief Gives back an unique integer id for the Arc.
deba@57
   320
      ///
alpar@209
   321
      /// Gives back an unique integer id for the Arc.
deba@57
   322
      ///
deba@57
   323
      int id(const Arc&) const { return -1;}
deba@57
   324
deba@57
   325
      /// \brief Gives back the arc by the unique id.
deba@57
   326
      ///
deba@57
   327
      /// Gives back the arc by the unique id.
deba@57
   328
      /// If the digraph does not contain arc with the given id
alpar@209
   329
      /// then the result of the function is undetermined.
deba@57
   330
      Arc arcFromId(int) const { return INVALID;}
deba@57
   331
deba@57
   332
      /// \brief Gives back an integer greater or equal to the maximum
deba@57
   333
      /// Node id.
deba@57
   334
      ///
deba@57
   335
      /// Gives back an integer greater or equal to the maximum Node
deba@57
   336
      /// id.
deba@57
   337
      int maxNodeId() const { return -1;}
deba@57
   338
deba@57
   339
      /// \brief Gives back an integer greater or equal to the maximum
deba@57
   340
      /// Arc id.
deba@57
   341
      ///
deba@57
   342
      /// Gives back an integer greater or equal to the maximum Arc
deba@57
   343
      /// id.
deba@57
   344
      int maxArcId() const { return -1;}
deba@57
   345
deba@57
   346
      template <typename _Digraph>
deba@57
   347
      struct Constraints {
deba@57
   348
alpar@209
   349
        void constraints() {
alpar@209
   350
          checkConcept<Base, _Digraph >();
alpar@209
   351
          typename _Digraph::Node node;
alpar@209
   352
          int nid = digraph.id(node);
alpar@209
   353
          nid = digraph.id(node);
alpar@209
   354
          node = digraph.nodeFromId(nid);
alpar@209
   355
          typename _Digraph::Arc arc;
alpar@209
   356
          int eid = digraph.id(arc);
alpar@209
   357
          eid = digraph.id(arc);
alpar@209
   358
          arc = digraph.arcFromId(eid);
deba@57
   359
alpar@209
   360
          nid = digraph.maxNodeId();
alpar@209
   361
          ignore_unused_variable_warning(nid);
alpar@209
   362
          eid = digraph.maxArcId();
alpar@209
   363
          ignore_unused_variable_warning(eid);
alpar@209
   364
        }
deba@57
   365
alpar@209
   366
        const _Digraph& digraph;
deba@57
   367
      };
deba@57
   368
    };
deba@57
   369
deba@57
   370
    /// \brief An empty idable base undirected graph class.
alpar@209
   371
    ///
deba@57
   372
    /// This class provides beside the core undirected graph features
deba@57
   373
    /// core id functions for the undirected graph structure.  The
kpeter@492
   374
    /// most of the base undirected graphs should conform to this
deba@57
   375
    /// concept.  The id's are unique and immutable.
kpeter@559
   376
    template <typename BAS = BaseGraphComponent>
kpeter@559
   377
    class IDableGraphComponent : public IDableDigraphComponent<BAS> {
deba@57
   378
    public:
deba@57
   379
kpeter@559
   380
      typedef BAS Base;
deba@57
   381
      typedef typename Base::Edge Edge;
deba@57
   382
kpeter@559
   383
      using IDableDigraphComponent<Base>::id;
deba@57
   384
alpar@209
   385
      /// \brief Gives back an unique integer id for the Edge.
deba@57
   386
      ///
alpar@209
   387
      /// Gives back an unique integer id for the Edge.
deba@57
   388
      ///
deba@57
   389
      int id(const Edge&) const { return -1;}
deba@57
   390
deba@57
   391
      /// \brief Gives back the edge by the unique id.
deba@57
   392
      ///
deba@57
   393
      /// Gives back the edge by the unique id.  If the
deba@57
   394
      /// graph does not contain arc with the given id then the
deba@57
   395
      /// result of the function is undetermined.
deba@57
   396
      Edge edgeFromId(int) const { return INVALID;}
deba@57
   397
deba@57
   398
      /// \brief Gives back an integer greater or equal to the maximum
deba@57
   399
      /// Edge id.
deba@57
   400
      ///
deba@57
   401
      /// Gives back an integer greater or equal to the maximum Edge
deba@57
   402
      /// id.
deba@57
   403
      int maxEdgeId() const { return -1;}
deba@57
   404
deba@57
   405
      template <typename _Graph>
deba@57
   406
      struct Constraints {
deba@57
   407
alpar@209
   408
        void constraints() {
alpar@209
   409
          checkConcept<Base, _Graph >();
alpar@209
   410
          checkConcept<IDableDigraphComponent<Base>, _Graph >();
alpar@209
   411
          typename _Graph::Edge edge;
alpar@209
   412
          int ueid = graph.id(edge);
alpar@209
   413
          ueid = graph.id(edge);
alpar@209
   414
          edge = graph.edgeFromId(ueid);
alpar@209
   415
          ueid = graph.maxEdgeId();
alpar@209
   416
          ignore_unused_variable_warning(ueid);
alpar@209
   417
        }
deba@57
   418
alpar@209
   419
        const _Graph& graph;
deba@57
   420
      };
deba@57
   421
    };
deba@57
   422
deba@57
   423
    /// \brief Skeleton class for graph NodeIt and ArcIt
deba@57
   424
    ///
deba@57
   425
    /// Skeleton class for graph NodeIt and ArcIt.
deba@57
   426
    ///
kpeter@559
   427
    template <typename GR, typename Item>
kpeter@559
   428
    class GraphItemIt : public Item {
deba@57
   429
    public:
deba@57
   430
      /// \brief Default constructor.
deba@57
   431
      ///
deba@57
   432
      /// @warning The default constructor sets the iterator
deba@57
   433
      /// to an undefined value.
deba@57
   434
      GraphItemIt() {}
deba@57
   435
      /// \brief Copy constructor.
deba@57
   436
      ///
deba@57
   437
      /// Copy constructor.
deba@57
   438
      ///
deba@57
   439
      GraphItemIt(const GraphItemIt& ) {}
deba@57
   440
      /// \brief Sets the iterator to the first item.
deba@57
   441
      ///
deba@57
   442
      /// Sets the iterator to the first item of \c the graph.
deba@57
   443
      ///
kpeter@559
   444
      explicit GraphItemIt(const GR&) {}
deba@57
   445
      /// \brief Invalid constructor \& conversion.
deba@57
   446
      ///
deba@57
   447
      /// This constructor initializes the item to be invalid.
deba@57
   448
      /// \sa Invalid for more details.
deba@57
   449
      GraphItemIt(Invalid) {}
deba@57
   450
      /// \brief Assign operator for items.
deba@57
   451
      ///
alpar@209
   452
      /// The items are assignable.
deba@57
   453
      ///
alpar@209
   454
      GraphItemIt& operator=(const GraphItemIt&) { return *this; }
deba@57
   455
      /// \brief Next item.
alpar@209
   456
      ///
deba@57
   457
      /// Assign the iterator to the next item.
deba@57
   458
      ///
deba@57
   459
      GraphItemIt& operator++() { return *this; }
deba@57
   460
      /// \brief Equality operator
alpar@209
   461
      ///
deba@57
   462
      /// Two iterators are equal if and only if they point to the
deba@57
   463
      /// same object or both are invalid.
deba@57
   464
      bool operator==(const GraphItemIt&) const { return true;}
deba@57
   465
      /// \brief Inequality operator
alpar@209
   466
      ///
deba@57
   467
      /// \sa operator==(Node n)
deba@57
   468
      ///
deba@57
   469
      bool operator!=(const GraphItemIt&) const { return true;}
alpar@209
   470
deba@57
   471
      template<typename _GraphItemIt>
deba@57
   472
      struct Constraints {
alpar@209
   473
        void constraints() {
alpar@209
   474
          _GraphItemIt it1(g);
alpar@209
   475
          _GraphItemIt it2;
deba@57
   476
alpar@209
   477
          it2 = ++it1;
alpar@209
   478
          ++it2 = it1;
alpar@209
   479
          ++(++it1);
deba@57
   480
kpeter@559
   481
          Item bi = it1;
alpar@209
   482
          bi = it2;
alpar@209
   483
        }
kpeter@559
   484
        GR& g;
deba@57
   485
      };
deba@57
   486
    };
deba@57
   487
deba@57
   488
    /// \brief Skeleton class for graph InArcIt and OutArcIt
deba@57
   489
    ///
deba@57
   490
    /// \note Because InArcIt and OutArcIt may not inherit from the same
kpeter@559
   491
    /// base class, the \c sel is a additional template parameter (selector).
kpeter@559
   492
    /// For InArcIt you should instantiate it with character 'i' and for
deba@57
   493
    /// OutArcIt with 'o'.
kpeter@559
   494
    template <typename GR,
kpeter@559
   495
              typename Item = typename GR::Arc,
kpeter@559
   496
              typename Base = typename GR::Node,
kpeter@559
   497
              char sel = '0'>
kpeter@559
   498
    class GraphIncIt : public Item {
deba@57
   499
    public:
deba@57
   500
      /// \brief Default constructor.
deba@57
   501
      ///
deba@57
   502
      /// @warning The default constructor sets the iterator
deba@57
   503
      /// to an undefined value.
deba@57
   504
      GraphIncIt() {}
deba@57
   505
      /// \brief Copy constructor.
deba@57
   506
      ///
deba@57
   507
      /// Copy constructor.
deba@57
   508
      ///
kpeter@559
   509
      GraphIncIt(GraphIncIt const& gi) : Item(gi) {}
alpar@209
   510
      /// \brief Sets the iterator to the first arc incoming into or outgoing
deba@57
   511
      /// from the node.
deba@57
   512
      ///
alpar@209
   513
      /// Sets the iterator to the first arc incoming into or outgoing
deba@57
   514
      /// from the node.
deba@57
   515
      ///
kpeter@559
   516
      explicit GraphIncIt(const GR&, const Base&) {}
deba@57
   517
      /// \brief Invalid constructor \& conversion.
deba@57
   518
      ///
deba@57
   519
      /// This constructor initializes the item to be invalid.
deba@57
   520
      /// \sa Invalid for more details.
deba@57
   521
      GraphIncIt(Invalid) {}
deba@57
   522
      /// \brief Assign operator for iterators.
deba@57
   523
      ///
alpar@209
   524
      /// The iterators are assignable.
deba@57
   525
      ///
alpar@209
   526
      GraphIncIt& operator=(GraphIncIt const&) { return *this; }
deba@57
   527
      /// \brief Next item.
deba@57
   528
      ///
deba@57
   529
      /// Assign the iterator to the next item.
deba@57
   530
      ///
deba@57
   531
      GraphIncIt& operator++() { return *this; }
deba@57
   532
deba@57
   533
      /// \brief Equality operator
deba@57
   534
      ///
deba@57
   535
      /// Two iterators are equal if and only if they point to the
deba@57
   536
      /// same object or both are invalid.
deba@57
   537
      bool operator==(const GraphIncIt&) const { return true;}
deba@57
   538
deba@57
   539
      /// \brief Inequality operator
deba@57
   540
      ///
deba@57
   541
      /// \sa operator==(Node n)
deba@57
   542
      ///
deba@57
   543
      bool operator!=(const GraphIncIt&) const { return true;}
deba@57
   544
deba@57
   545
      template <typename _GraphIncIt>
deba@57
   546
      struct Constraints {
alpar@209
   547
        void constraints() {
kpeter@559
   548
          checkConcept<GraphItem<sel>, _GraphIncIt>();
alpar@209
   549
          _GraphIncIt it1(graph, node);
alpar@209
   550
          _GraphIncIt it2;
deba@57
   551
alpar@209
   552
          it2 = ++it1;
alpar@209
   553
          ++it2 = it1;
alpar@209
   554
          ++(++it1);
kpeter@559
   555
          Item e = it1;
alpar@209
   556
          e = it2;
deba@57
   557
alpar@209
   558
        }
deba@57
   559
kpeter@559
   560
        Item arc;
kpeter@559
   561
        Base node;
kpeter@559
   562
        GR graph;
alpar@209
   563
        _GraphIncIt it;
deba@57
   564
      };
deba@57
   565
    };
deba@57
   566
deba@57
   567
deba@57
   568
    /// \brief An empty iterable digraph class.
deba@57
   569
    ///
deba@57
   570
    /// This class provides beside the core digraph features
deba@57
   571
    /// iterator based iterable interface for the digraph structure.
deba@57
   572
    /// This concept is part of the Digraph concept.
kpeter@559
   573
    template <typename BAS = BaseDigraphComponent>
kpeter@559
   574
    class IterableDigraphComponent : public BAS {
deba@57
   575
deba@57
   576
    public:
alpar@209
   577
kpeter@559
   578
      typedef BAS Base;
deba@57
   579
      typedef typename Base::Node Node;
deba@57
   580
      typedef typename Base::Arc Arc;
deba@57
   581
deba@57
   582
      typedef IterableDigraphComponent Digraph;
deba@57
   583
deba@57
   584
      /// \name Base iteration
alpar@209
   585
      ///
deba@57
   586
      /// This interface provides functions for iteration on digraph items
deba@57
   587
      ///
alpar@209
   588
      /// @{
deba@57
   589
deba@57
   590
      /// \brief Gives back the first node in the iterating order.
alpar@209
   591
      ///
deba@57
   592
      /// Gives back the first node in the iterating order.
alpar@209
   593
      ///
deba@57
   594
      void first(Node&) const {}
deba@57
   595
deba@57
   596
      /// \brief Gives back the next node in the iterating order.
deba@57
   597
      ///
deba@57
   598
      /// Gives back the next node in the iterating order.
alpar@209
   599
      ///
deba@57
   600
      void next(Node&) const {}
deba@57
   601
deba@57
   602
      /// \brief Gives back the first arc in the iterating order.
deba@57
   603
      ///
deba@57
   604
      /// Gives back the first arc in the iterating order.
alpar@209
   605
      ///
deba@57
   606
      void first(Arc&) const {}
deba@57
   607
deba@57
   608
      /// \brief Gives back the next arc in the iterating order.
deba@57
   609
      ///
deba@57
   610
      /// Gives back the next arc in the iterating order.
alpar@209
   611
      ///
deba@57
   612
      void next(Arc&) const {}
deba@57
   613
deba@57
   614
deba@57
   615
      /// \brief Gives back the first of the arcs point to the given
deba@57
   616
      /// node.
deba@57
   617
      ///
deba@57
   618
      /// Gives back the first of the arcs point to the given node.
alpar@209
   619
      ///
deba@57
   620
      void firstIn(Arc&, const Node&) const {}
deba@57
   621
deba@57
   622
      /// \brief Gives back the next of the arcs points to the given
deba@57
   623
      /// node.
deba@57
   624
      ///
deba@57
   625
      /// Gives back the next of the arcs points to the given node.
deba@57
   626
      ///
deba@57
   627
      void nextIn(Arc&) const {}
deba@57
   628
deba@57
   629
      /// \brief Gives back the first of the arcs start from the
deba@57
   630
      /// given node.
alpar@209
   631
      ///
deba@57
   632
      /// Gives back the first of the arcs start from the given node.
alpar@209
   633
      ///
deba@57
   634
      void firstOut(Arc&, const Node&) const {}
deba@57
   635
deba@57
   636
      /// \brief Gives back the next of the arcs start from the given
deba@57
   637
      /// node.
deba@57
   638
      ///
deba@57
   639
      /// Gives back the next of the arcs start from the given node.
alpar@209
   640
      ///
deba@57
   641
      void nextOut(Arc&) const {}
deba@57
   642
deba@57
   643
      /// @}
deba@57
   644
deba@57
   645
      /// \name Class based iteration
alpar@209
   646
      ///
deba@57
   647
      /// This interface provides functions for iteration on digraph items
deba@57
   648
      ///
deba@57
   649
      /// @{
deba@57
   650
deba@57
   651
      /// \brief This iterator goes through each node.
deba@57
   652
      ///
deba@57
   653
      /// This iterator goes through each node.
deba@57
   654
      ///
deba@57
   655
      typedef GraphItemIt<Digraph, Node> NodeIt;
deba@57
   656
deba@57
   657
      /// \brief This iterator goes through each node.
deba@57
   658
      ///
deba@57
   659
      /// This iterator goes through each node.
deba@57
   660
      ///
deba@57
   661
      typedef GraphItemIt<Digraph, Arc> ArcIt;
deba@57
   662
deba@57
   663
      /// \brief This iterator goes trough the incoming arcs of a node.
deba@57
   664
      ///
deba@57
   665
      /// This iterator goes trough the \e inccoming arcs of a certain node
deba@57
   666
      /// of a digraph.
deba@57
   667
      typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt;
deba@57
   668
deba@57
   669
      /// \brief This iterator goes trough the outgoing arcs of a node.
deba@57
   670
      ///
deba@57
   671
      /// This iterator goes trough the \e outgoing arcs of a certain node
deba@57
   672
      /// of a digraph.
deba@57
   673
      typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt;
deba@57
   674
deba@57
   675
      /// \brief The base node of the iterator.
deba@57
   676
      ///
deba@57
   677
      /// Gives back the base node of the iterator.
deba@57
   678
      /// It is always the target of the pointed arc.
deba@57
   679
      Node baseNode(const InArcIt&) const { return INVALID; }
deba@57
   680
deba@57
   681
      /// \brief The running node of the iterator.
deba@57
   682
      ///
deba@57
   683
      /// Gives back the running node of the iterator.
deba@57
   684
      /// It is always the source of the pointed arc.
deba@57
   685
      Node runningNode(const InArcIt&) const { return INVALID; }
deba@57
   686
deba@57
   687
      /// \brief The base node of the iterator.
deba@57
   688
      ///
deba@57
   689
      /// Gives back the base node of the iterator.
deba@57
   690
      /// It is always the source of the pointed arc.
deba@57
   691
      Node baseNode(const OutArcIt&) const { return INVALID; }
deba@57
   692
deba@57
   693
      /// \brief The running node of the iterator.
deba@57
   694
      ///
deba@57
   695
      /// Gives back the running node of the iterator.
deba@57
   696
      /// It is always the target of the pointed arc.
deba@57
   697
      Node runningNode(const OutArcIt&) const { return INVALID; }
deba@57
   698
deba@57
   699
      /// @}
deba@57
   700
alpar@209
   701
      template <typename _Digraph>
deba@57
   702
      struct Constraints {
alpar@209
   703
        void constraints() {
alpar@209
   704
          checkConcept<Base, _Digraph>();
deba@57
   705
deba@57
   706
          {
alpar@209
   707
            typename _Digraph::Node node(INVALID);
deba@57
   708
            typename _Digraph::Arc arc(INVALID);
deba@57
   709
            {
deba@57
   710
              digraph.first(node);
deba@57
   711
              digraph.next(node);
deba@57
   712
            }
deba@57
   713
            {
deba@57
   714
              digraph.first(arc);
deba@57
   715
              digraph.next(arc);
deba@57
   716
            }
deba@57
   717
            {
deba@57
   718
              digraph.firstIn(arc, node);
deba@57
   719
              digraph.nextIn(arc);
deba@57
   720
            }
deba@57
   721
            {
deba@57
   722
              digraph.firstOut(arc, node);
deba@57
   723
              digraph.nextOut(arc);
deba@57
   724
            }
alpar@209
   725
          }
deba@57
   726
deba@57
   727
          {
deba@57
   728
            checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>,
deba@57
   729
              typename _Digraph::ArcIt >();
deba@57
   730
            checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>,
deba@57
   731
              typename _Digraph::NodeIt >();
alpar@209
   732
            checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
deba@57
   733
              typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>();
alpar@209
   734
            checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
deba@57
   735
              typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>();
deba@57
   736
deba@57
   737
            typename _Digraph::Node n;
deba@57
   738
            typename _Digraph::InArcIt ieit(INVALID);
deba@57
   739
            typename _Digraph::OutArcIt oeit(INVALID);
deba@57
   740
            n = digraph.baseNode(ieit);
deba@57
   741
            n = digraph.runningNode(ieit);
deba@57
   742
            n = digraph.baseNode(oeit);
deba@57
   743
            n = digraph.runningNode(oeit);
deba@57
   744
            ignore_unused_variable_warning(n);
deba@57
   745
          }
deba@57
   746
        }
alpar@209
   747
alpar@209
   748
        const _Digraph& digraph;
alpar@209
   749
deba@57
   750
      };
deba@57
   751
    };
deba@57
   752
deba@57
   753
    /// \brief An empty iterable undirected graph class.
deba@57
   754
    ///
deba@57
   755
    /// This class provides beside the core graph features iterator
deba@57
   756
    /// based iterable interface for the undirected graph structure.
deba@57
   757
    /// This concept is part of the Graph concept.
kpeter@559
   758
    template <typename BAS = BaseGraphComponent>
kpeter@559
   759
    class IterableGraphComponent : public IterableDigraphComponent<BAS> {
deba@57
   760
    public:
deba@57
   761
kpeter@559
   762
      typedef BAS Base;
deba@57
   763
      typedef typename Base::Node Node;
deba@57
   764
      typedef typename Base::Arc Arc;
deba@57
   765
      typedef typename Base::Edge Edge;
deba@57
   766
alpar@209
   767
deba@57
   768
      typedef IterableGraphComponent Graph;
deba@57
   769
deba@57
   770
      /// \name Base iteration
alpar@209
   771
      ///
deba@57
   772
      /// This interface provides functions for iteration on graph items
alpar@209
   773
      /// @{
deba@57
   774
kpeter@559
   775
      using IterableDigraphComponent<Base>::first;
kpeter@559
   776
      using IterableDigraphComponent<Base>::next;
deba@57
   777
deba@57
   778
      /// \brief Gives back the first edge in the iterating
deba@57
   779
      /// order.
deba@57
   780
      ///
deba@57
   781
      /// Gives back the first edge in the iterating order.
alpar@209
   782
      ///
deba@57
   783
      void first(Edge&) const {}
deba@57
   784
deba@57
   785
      /// \brief Gives back the next edge in the iterating
deba@57
   786
      /// order.
deba@57
   787
      ///
deba@57
   788
      /// Gives back the next edge in the iterating order.
alpar@209
   789
      ///
deba@57
   790
      void next(Edge&) const {}
deba@57
   791
deba@57
   792
deba@57
   793
      /// \brief Gives back the first of the edges from the
deba@57
   794
      /// given node.
deba@57
   795
      ///
deba@57
   796
      /// Gives back the first of the edges from the given
deba@57
   797
      /// node. The bool parameter gives back that direction which
deba@57
   798
      /// gives a good direction of the edge so the source of the
deba@57
   799
      /// directed arc is the given node.
deba@57
   800
      void firstInc(Edge&, bool&, const Node&) const {}
deba@57
   801
deba@57
   802
      /// \brief Gives back the next of the edges from the
deba@57
   803
      /// given node.
deba@57
   804
      ///
deba@57
   805
      /// Gives back the next of the edges from the given
deba@57
   806
      /// node. The bool parameter should be used as the \c firstInc()
deba@57
   807
      /// use it.
deba@57
   808
      void nextInc(Edge&, bool&) const {}
deba@57
   809
kpeter@559
   810
      using IterableDigraphComponent<Base>::baseNode;
kpeter@559
   811
      using IterableDigraphComponent<Base>::runningNode;
deba@57
   812
deba@57
   813
      /// @}
deba@57
   814
deba@57
   815
      /// \name Class based iteration
alpar@209
   816
      ///
deba@57
   817
      /// This interface provides functions for iteration on graph items
deba@57
   818
      ///
deba@57
   819
      /// @{
deba@57
   820
deba@57
   821
      /// \brief This iterator goes through each node.
deba@57
   822
      ///
deba@57
   823
      /// This iterator goes through each node.
deba@57
   824
      typedef GraphItemIt<Graph, Edge> EdgeIt;
deba@57
   825
      /// \brief This iterator goes trough the incident arcs of a
deba@57
   826
      /// node.
deba@57
   827
      ///
deba@57
   828
      /// This iterator goes trough the incident arcs of a certain
deba@57
   829
      /// node of a graph.
deba@78
   830
      typedef GraphIncIt<Graph, Edge, Node, 'u'> IncEdgeIt;
deba@57
   831
      /// \brief The base node of the iterator.
deba@57
   832
      ///
deba@57
   833
      /// Gives back the base node of the iterator.
deba@78
   834
      Node baseNode(const IncEdgeIt&) const { return INVALID; }
deba@57
   835
deba@57
   836
      /// \brief The running node of the iterator.
deba@57
   837
      ///
deba@57
   838
      /// Gives back the running node of the iterator.
deba@78
   839
      Node runningNode(const IncEdgeIt&) const { return INVALID; }
deba@57
   840
deba@57
   841
      /// @}
deba@57
   842
alpar@209
   843
      template <typename _Graph>
deba@57
   844
      struct Constraints {
alpar@209
   845
        void constraints() {
alpar@209
   846
          checkConcept<IterableDigraphComponent<Base>, _Graph>();
deba@57
   847
deba@57
   848
          {
deba@57
   849
            typename _Graph::Node node(INVALID);
deba@57
   850
            typename _Graph::Edge edge(INVALID);
deba@57
   851
            bool dir;
deba@57
   852
            {
deba@57
   853
              graph.first(edge);
deba@57
   854
              graph.next(edge);
deba@57
   855
            }
deba@57
   856
            {
deba@57
   857
              graph.firstInc(edge, dir, node);
deba@57
   858
              graph.nextInc(edge, dir);
deba@57
   859
            }
alpar@209
   860
alpar@209
   861
          }
alpar@209
   862
deba@57
   863
          {
deba@57
   864
            checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>,
deba@57
   865
              typename _Graph::EdgeIt >();
alpar@209
   866
            checkConcept<GraphIncIt<_Graph, typename _Graph::Edge,
deba@78
   867
              typename _Graph::Node, 'u'>, typename _Graph::IncEdgeIt>();
alpar@209
   868
deba@57
   869
            typename _Graph::Node n;
deba@78
   870
            typename _Graph::IncEdgeIt ueit(INVALID);
deba@57
   871
            n = graph.baseNode(ueit);
deba@57
   872
            n = graph.runningNode(ueit);
deba@57
   873
          }
deba@57
   874
        }
alpar@209
   875
alpar@209
   876
        const _Graph& graph;
deba@57
   877
      };
deba@57
   878
    };
deba@57
   879
deba@57
   880
    /// \brief An empty alteration notifier digraph class.
alpar@209
   881
    ///
deba@57
   882
    /// This class provides beside the core digraph features alteration
deba@57
   883
    /// notifier interface for the digraph structure.  This implements
deba@57
   884
    /// an observer-notifier pattern for each digraph item. More
deba@57
   885
    /// obsevers can be registered into the notifier and whenever an
deba@57
   886
    /// alteration occured in the digraph all the observers will
deba@57
   887
    /// notified about it.
kpeter@559
   888
    template <typename BAS = BaseDigraphComponent>
kpeter@559
   889
    class AlterableDigraphComponent : public BAS {
deba@57
   890
    public:
deba@57
   891
kpeter@559
   892
      typedef BAS Base;
deba@57
   893
      typedef typename Base::Node Node;
deba@57
   894
      typedef typename Base::Arc Arc;
deba@57
   895
deba@57
   896
deba@57
   897
      /// The node observer registry.
alpar@209
   898
      typedef AlterationNotifier<AlterableDigraphComponent, Node>
deba@57
   899
      NodeNotifier;
deba@57
   900
      /// The arc observer registry.
alpar@209
   901
      typedef AlterationNotifier<AlterableDigraphComponent, Arc>
deba@57
   902
      ArcNotifier;
alpar@209
   903
deba@57
   904
      /// \brief Gives back the node alteration notifier.
deba@57
   905
      ///
deba@57
   906
      /// Gives back the node alteration notifier.
deba@57
   907
      NodeNotifier& notifier(Node) const {
alpar@209
   908
        return NodeNotifier();
deba@57
   909
      }
alpar@209
   910
deba@57
   911
      /// \brief Gives back the arc alteration notifier.
deba@57
   912
      ///
deba@57
   913
      /// Gives back the arc alteration notifier.
deba@57
   914
      ArcNotifier& notifier(Arc) const {
alpar@209
   915
        return ArcNotifier();
deba@57
   916
      }
deba@57
   917
alpar@209
   918
      template <typename _Digraph>
deba@57
   919
      struct Constraints {
alpar@209
   920
        void constraints() {
alpar@209
   921
          checkConcept<Base, _Digraph>();
alpar@209
   922
          typename _Digraph::NodeNotifier& nn
deba@57
   923
            = digraph.notifier(typename _Digraph::Node());
deba@57
   924
alpar@209
   925
          typename _Digraph::ArcNotifier& en
deba@57
   926
            = digraph.notifier(typename _Digraph::Arc());
alpar@209
   927
deba@57
   928
          ignore_unused_variable_warning(nn);
deba@57
   929
          ignore_unused_variable_warning(en);
alpar@209
   930
        }
alpar@209
   931
alpar@209
   932
        const _Digraph& digraph;
alpar@209
   933
deba@57
   934
      };
alpar@209
   935
deba@57
   936
    };
deba@57
   937
deba@57
   938
    /// \brief An empty alteration notifier undirected graph class.
alpar@209
   939
    ///
deba@57
   940
    /// This class provides beside the core graph features alteration
deba@57
   941
    /// notifier interface for the graph structure.  This implements
deba@57
   942
    /// an observer-notifier pattern for each graph item. More
deba@57
   943
    /// obsevers can be registered into the notifier and whenever an
deba@57
   944
    /// alteration occured in the graph all the observers will
deba@57
   945
    /// notified about it.
kpeter@559
   946
    template <typename BAS = BaseGraphComponent>
kpeter@559
   947
    class AlterableGraphComponent : public AlterableDigraphComponent<BAS> {
deba@57
   948
    public:
deba@57
   949
kpeter@559
   950
      typedef BAS Base;
deba@57
   951
      typedef typename Base::Edge Edge;
deba@57
   952
deba@57
   953
deba@57
   954
      /// The arc observer registry.
alpar@209
   955
      typedef AlterationNotifier<AlterableGraphComponent, Edge>
deba@57
   956
      EdgeNotifier;
alpar@209
   957
deba@57
   958
      /// \brief Gives back the arc alteration notifier.
deba@57
   959
      ///
deba@57
   960
      /// Gives back the arc alteration notifier.
deba@57
   961
      EdgeNotifier& notifier(Edge) const {
alpar@209
   962
        return EdgeNotifier();
deba@57
   963
      }
deba@57
   964
alpar@209
   965
      template <typename _Graph>
deba@57
   966
      struct Constraints {
alpar@209
   967
        void constraints() {
alpar@209
   968
          checkConcept<AlterableGraphComponent<Base>, _Graph>();
alpar@209
   969
          typename _Graph::EdgeNotifier& uen
deba@57
   970
            = graph.notifier(typename _Graph::Edge());
deba@57
   971
          ignore_unused_variable_warning(uen);
alpar@209
   972
        }
alpar@209
   973
alpar@209
   974
        const _Graph& graph;
deba@57
   975
      };
deba@57
   976
    };
deba@57
   977
deba@57
   978
    /// \brief Class describing the concept of graph maps
alpar@209
   979
    ///
deba@57
   980
    /// This class describes the common interface of the graph maps
kpeter@313
   981
    /// (NodeMap, ArcMap), that is maps that can be used to
deba@57
   982
    /// associate data to graph descriptors (nodes or arcs).
kpeter@559
   983
    template <typename GR, typename K, typename V>
kpeter@559
   984
    class GraphMap : public ReadWriteMap<K, V> {
deba@57
   985
    public:
deba@57
   986
kpeter@559
   987
      typedef ReadWriteMap<K, V> Parent;
deba@57
   988
deba@57
   989
      /// The graph type of the map.
kpeter@559
   990
      typedef GR Graph;
deba@57
   991
      /// The key type of the map.
kpeter@559
   992
      typedef K Key;
deba@57
   993
      /// The value type of the map.
kpeter@559
   994
      typedef V Value;
deba@57
   995
deba@57
   996
      /// \brief Construct a new map.
deba@57
   997
      ///
deba@57
   998
      /// Construct a new map for the graph.
deba@57
   999
      explicit GraphMap(const Graph&) {}
deba@57
  1000
      /// \brief Construct a new map with default value.
deba@57
  1001
      ///
deba@57
  1002
      /// Construct a new map for the graph and initalise the values.
deba@57
  1003
      GraphMap(const Graph&, const Value&) {}
kpeter@263
  1004
kpeter@263
  1005
    private:
deba@57
  1006
      /// \brief Copy constructor.
deba@57
  1007
      ///
deba@57
  1008
      /// Copy Constructor.
deba@57
  1009
      GraphMap(const GraphMap&) : Parent() {}
alpar@209
  1010
deba@57
  1011
      /// \brief Assign operator.
deba@57
  1012
      ///
deba@57
  1013
      /// Assign operator. It does not mofify the underlying graph,
deba@57
  1014
      /// it just iterates on the current item set and set the  map
alpar@209
  1015
      /// with the value returned by the assigned map.
deba@57
  1016
      template <typename CMap>
alpar@209
  1017
      GraphMap& operator=(const CMap&) {
deba@57
  1018
        checkConcept<ReadMap<Key, Value>, CMap>();
deba@57
  1019
        return *this;
deba@57
  1020
      }
deba@57
  1021
kpeter@263
  1022
    public:
deba@57
  1023
      template<typename _Map>
deba@57
  1024
      struct Constraints {
alpar@209
  1025
        void constraints() {
alpar@209
  1026
          checkConcept<ReadWriteMap<Key, Value>, _Map >();
alpar@209
  1027
          // Construction with a graph parameter
alpar@209
  1028
          _Map a(g);
alpar@209
  1029
          // Constructor with a graph and a default value parameter
alpar@209
  1030
          _Map a2(g,t);
alpar@209
  1031
          // Copy constructor.
kpeter@263
  1032
          // _Map b(c);
alpar@209
  1033
kpeter@263
  1034
          // ReadMap<Key, Value> cmap;
kpeter@263
  1035
          // b = cmap;
deba@57
  1036
kpeter@263
  1037
          ignore_unused_variable_warning(a);
alpar@209
  1038
          ignore_unused_variable_warning(a2);
kpeter@263
  1039
          // ignore_unused_variable_warning(b);
alpar@209
  1040
        }
deba@57
  1041
alpar@209
  1042
        const _Map &c;
alpar@209
  1043
        const Graph &g;
alpar@209
  1044
        const typename GraphMap::Value &t;
deba@57
  1045
      };
deba@57
  1046
deba@57
  1047
    };
deba@57
  1048
deba@57
  1049
    /// \brief An empty mappable digraph class.
deba@57
  1050
    ///
deba@57
  1051
    /// This class provides beside the core digraph features
deba@57
  1052
    /// map interface for the digraph structure.
deba@57
  1053
    /// This concept is part of the Digraph concept.
kpeter@559
  1054
    template <typename BAS = BaseDigraphComponent>
kpeter@559
  1055
    class MappableDigraphComponent : public BAS  {
deba@57
  1056
    public:
deba@57
  1057
kpeter@559
  1058
      typedef BAS Base;
deba@57
  1059
      typedef typename Base::Node Node;
deba@57
  1060
      typedef typename Base::Arc Arc;
deba@57
  1061
deba@57
  1062
      typedef MappableDigraphComponent Digraph;
deba@57
  1063
deba@57
  1064
      /// \brief ReadWrite map of the nodes.
deba@57
  1065
      ///
deba@57
  1066
      /// ReadWrite map of the nodes.
deba@57
  1067
      ///
kpeter@559
  1068
      template <typename V>
kpeter@559
  1069
      class NodeMap : public GraphMap<Digraph, Node, V> {
deba@57
  1070
      public:
kpeter@559
  1071
        typedef GraphMap<MappableDigraphComponent, Node, V> Parent;
deba@57
  1072
alpar@209
  1073
        /// \brief Construct a new map.
alpar@209
  1074
        ///
alpar@209
  1075
        /// Construct a new map for the digraph.
alpar@209
  1076
        explicit NodeMap(const MappableDigraphComponent& digraph)
deba@57
  1077
          : Parent(digraph) {}
deba@57
  1078
alpar@209
  1079
        /// \brief Construct a new map with default value.
alpar@209
  1080
        ///
alpar@209
  1081
        /// Construct a new map for the digraph and initalise the values.
kpeter@559
  1082
        NodeMap(const MappableDigraphComponent& digraph, const V& value)
deba@57
  1083
          : Parent(digraph, value) {}
deba@57
  1084
kpeter@263
  1085
      private:
alpar@209
  1086
        /// \brief Copy constructor.
alpar@209
  1087
        ///
alpar@209
  1088
        /// Copy Constructor.
alpar@209
  1089
        NodeMap(const NodeMap& nm) : Parent(nm) {}
deba@57
  1090
alpar@209
  1091
        /// \brief Assign operator.
alpar@209
  1092
        ///
alpar@209
  1093
        /// Assign operator.
deba@57
  1094
        template <typename CMap>
alpar@209
  1095
        NodeMap& operator=(const CMap&) {
kpeter@559
  1096
          checkConcept<ReadMap<Node, V>, CMap>();
deba@57
  1097
          return *this;
deba@57
  1098
        }
deba@57
  1099
deba@57
  1100
      };
deba@57
  1101
deba@57
  1102
      /// \brief ReadWrite map of the arcs.
deba@57
  1103
      ///
deba@57
  1104
      /// ReadWrite map of the arcs.
deba@57
  1105
      ///
kpeter@559
  1106
      template <typename V>
kpeter@559
  1107
      class ArcMap : public GraphMap<Digraph, Arc, V> {
deba@57
  1108
      public:
kpeter@559
  1109
        typedef GraphMap<MappableDigraphComponent, Arc, V> Parent;
deba@57
  1110
alpar@209
  1111
        /// \brief Construct a new map.
alpar@209
  1112
        ///
alpar@209
  1113
        /// Construct a new map for the digraph.
alpar@209
  1114
        explicit ArcMap(const MappableDigraphComponent& digraph)
deba@57
  1115
          : Parent(digraph) {}
deba@57
  1116
alpar@209
  1117
        /// \brief Construct a new map with default value.
alpar@209
  1118
        ///
alpar@209
  1119
        /// Construct a new map for the digraph and initalise the values.
kpeter@559
  1120
        ArcMap(const MappableDigraphComponent& digraph, const V& value)
deba@57
  1121
          : Parent(digraph, value) {}
deba@57
  1122
kpeter@263
  1123
      private:
alpar@209
  1124
        /// \brief Copy constructor.
alpar@209
  1125
        ///
alpar@209
  1126
        /// Copy Constructor.
alpar@209
  1127
        ArcMap(const ArcMap& nm) : Parent(nm) {}
deba@57
  1128
alpar@209
  1129
        /// \brief Assign operator.
alpar@209
  1130
        ///
alpar@209
  1131
        /// Assign operator.
deba@57
  1132
        template <typename CMap>
alpar@209
  1133
        ArcMap& operator=(const CMap&) {
kpeter@559
  1134
          checkConcept<ReadMap<Arc, V>, CMap>();
deba@57
  1135
          return *this;
deba@57
  1136
        }
deba@57
  1137
deba@57
  1138
      };
deba@57
  1139
deba@57
  1140
deba@57
  1141
      template <typename _Digraph>
deba@57
  1142
      struct Constraints {
deba@57
  1143
alpar@209
  1144
        struct Dummy {
alpar@209
  1145
          int value;
alpar@209
  1146
          Dummy() : value(0) {}
alpar@209
  1147
          Dummy(int _v) : value(_v) {}
alpar@209
  1148
        };
deba@57
  1149
alpar@209
  1150
        void constraints() {
alpar@209
  1151
          checkConcept<Base, _Digraph>();
alpar@209
  1152
          { // int map test
alpar@209
  1153
            typedef typename _Digraph::template NodeMap<int> IntNodeMap;
alpar@209
  1154
            checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>,
alpar@209
  1155
              IntNodeMap >();
alpar@209
  1156
          } { // bool map test
alpar@209
  1157
            typedef typename _Digraph::template NodeMap<bool> BoolNodeMap;
alpar@209
  1158
            checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>,
alpar@209
  1159
              BoolNodeMap >();
alpar@209
  1160
          } { // Dummy map test
alpar@209
  1161
            typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap;
alpar@209
  1162
            checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>,
alpar@209
  1163
              DummyNodeMap >();
alpar@209
  1164
          }
deba@57
  1165
alpar@209
  1166
          { // int map test
alpar@209
  1167
            typedef typename _Digraph::template ArcMap<int> IntArcMap;
alpar@209
  1168
            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
alpar@209
  1169
              IntArcMap >();
alpar@209
  1170
          } { // bool map test
alpar@209
  1171
            typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
alpar@209
  1172
            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
alpar@209
  1173
              BoolArcMap >();
alpar@209
  1174
          } { // Dummy map test
alpar@209
  1175
            typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
alpar@209
  1176
            checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>,
alpar@209
  1177
              DummyArcMap >();
alpar@209
  1178
          }
alpar@209
  1179
        }
deba@57
  1180
alpar@209
  1181
        _Digraph& digraph;
deba@57
  1182
      };
deba@57
  1183
    };
deba@57
  1184
deba@57
  1185
    /// \brief An empty mappable base bipartite graph class.
deba@57
  1186
    ///
deba@57
  1187
    /// This class provides beside the core graph features
deba@57
  1188
    /// map interface for the graph structure.
deba@57
  1189
    /// This concept is part of the Graph concept.
kpeter@559
  1190
    template <typename BAS = BaseGraphComponent>
kpeter@559
  1191
    class MappableGraphComponent : public MappableDigraphComponent<BAS>  {
deba@57
  1192
    public:
deba@57
  1193
kpeter@559
  1194
      typedef BAS Base;
deba@57
  1195
      typedef typename Base::Edge Edge;
deba@57
  1196
deba@57
  1197
      typedef MappableGraphComponent Graph;
deba@57
  1198
deba@57
  1199
      /// \brief ReadWrite map of the edges.
deba@57
  1200
      ///
deba@57
  1201
      /// ReadWrite map of the edges.
deba@57
  1202
      ///
kpeter@559
  1203
      template <typename V>
kpeter@559
  1204
      class EdgeMap : public GraphMap<Graph, Edge, V> {
deba@57
  1205
      public:
kpeter@559
  1206
        typedef GraphMap<MappableGraphComponent, Edge, V> Parent;
deba@57
  1207
alpar@209
  1208
        /// \brief Construct a new map.
alpar@209
  1209
        ///
alpar@209
  1210
        /// Construct a new map for the graph.
alpar@209
  1211
        explicit EdgeMap(const MappableGraphComponent& graph)
deba@57
  1212
          : Parent(graph) {}
deba@57
  1213
alpar@209
  1214
        /// \brief Construct a new map with default value.
alpar@209
  1215
        ///
alpar@209
  1216
        /// Construct a new map for the graph and initalise the values.
kpeter@559
  1217
        EdgeMap(const MappableGraphComponent& graph, const V& value)
deba@57
  1218
          : Parent(graph, value) {}
deba@57
  1219
kpeter@263
  1220
      private:
alpar@209
  1221
        /// \brief Copy constructor.
alpar@209
  1222
        ///
alpar@209
  1223
        /// Copy Constructor.
alpar@209
  1224
        EdgeMap(const EdgeMap& nm) : Parent(nm) {}
deba@57
  1225
alpar@209
  1226
        /// \brief Assign operator.
alpar@209
  1227
        ///
alpar@209
  1228
        /// Assign operator.
deba@57
  1229
        template <typename CMap>
alpar@209
  1230
        EdgeMap& operator=(const CMap&) {
kpeter@559
  1231
          checkConcept<ReadMap<Edge, V>, CMap>();
deba@57
  1232
          return *this;
deba@57
  1233
        }
deba@57
  1234
deba@57
  1235
      };
deba@57
  1236
deba@57
  1237
deba@57
  1238
      template <typename _Graph>
deba@57
  1239
      struct Constraints {
deba@57
  1240
alpar@209
  1241
        struct Dummy {
alpar@209
  1242
          int value;
alpar@209
  1243
          Dummy() : value(0) {}
alpar@209
  1244
          Dummy(int _v) : value(_v) {}
alpar@209
  1245
        };
deba@57
  1246
alpar@209
  1247
        void constraints() {
alpar@209
  1248
          checkConcept<MappableGraphComponent<Base>, _Graph>();
deba@57
  1249
alpar@209
  1250
          { // int map test
alpar@209
  1251
            typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
alpar@209
  1252
            checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
alpar@209
  1253
              IntEdgeMap >();
alpar@209
  1254
          } { // bool map test
alpar@209
  1255
            typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
alpar@209
  1256
            checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
alpar@209
  1257
              BoolEdgeMap >();
alpar@209
  1258
          } { // Dummy map test
alpar@209
  1259
            typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
alpar@209
  1260
            checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>,
alpar@209
  1261
              DummyEdgeMap >();
alpar@209
  1262
          }
alpar@209
  1263
        }
deba@57
  1264
alpar@209
  1265
        _Graph& graph;
deba@57
  1266
      };
deba@57
  1267
    };
deba@57
  1268
deba@57
  1269
    /// \brief An empty extendable digraph class.
deba@57
  1270
    ///
deba@57
  1271
    /// This class provides beside the core digraph features digraph
deba@57
  1272
    /// extendable interface for the digraph structure.  The main
deba@57
  1273
    /// difference between the base and this interface is that the
deba@57
  1274
    /// digraph alterations should handled already on this level.
kpeter@559
  1275
    template <typename BAS = BaseDigraphComponent>
kpeter@559
  1276
    class ExtendableDigraphComponent : public BAS {
deba@57
  1277
    public:
kpeter@559
  1278
      typedef BAS Base;
deba@57
  1279
kpeter@559
  1280
      typedef typename Base::Node Node;
kpeter@559
  1281
      typedef typename Base::Arc Arc;
deba@57
  1282
deba@57
  1283
      /// \brief Adds a new node to the digraph.
deba@57
  1284
      ///
deba@57
  1285
      /// Adds a new node to the digraph.
deba@57
  1286
      ///
deba@57
  1287
      Node addNode() {
alpar@209
  1288
        return INVALID;
deba@57
  1289
      }
alpar@209
  1290
deba@57
  1291
      /// \brief Adds a new arc connects the given two nodes.
deba@57
  1292
      ///
deba@57
  1293
      /// Adds a new arc connects the the given two nodes.
deba@57
  1294
      Arc addArc(const Node&, const Node&) {
alpar@209
  1295
        return INVALID;
deba@57
  1296
      }
deba@57
  1297
deba@57
  1298
      template <typename _Digraph>
deba@57
  1299
      struct Constraints {
alpar@209
  1300
        void constraints() {
deba@57
  1301
          checkConcept<Base, _Digraph>();
alpar@209
  1302
          typename _Digraph::Node node_a, node_b;
alpar@209
  1303
          node_a = digraph.addNode();
alpar@209
  1304
          node_b = digraph.addNode();
alpar@209
  1305
          typename _Digraph::Arc arc;
alpar@209
  1306
          arc = digraph.addArc(node_a, node_b);
alpar@209
  1307
        }
deba@57
  1308
alpar@209
  1309
        _Digraph& digraph;
deba@57
  1310
      };
deba@57
  1311
    };
deba@57
  1312
deba@57
  1313
    /// \brief An empty extendable base undirected graph class.
deba@57
  1314
    ///
deba@57
  1315
    /// This class provides beside the core undirected graph features
deba@57
  1316
    /// core undircted graph extend interface for the graph structure.
deba@57
  1317
    /// The main difference between the base and this interface is
deba@57
  1318
    /// that the graph alterations should handled already on this
deba@57
  1319
    /// level.
kpeter@559
  1320
    template <typename BAS = BaseGraphComponent>
kpeter@559
  1321
    class ExtendableGraphComponent : public BAS {
deba@57
  1322
    public:
deba@57
  1323
kpeter@559
  1324
      typedef BAS Base;
kpeter@559
  1325
      typedef typename Base::Node Node;
kpeter@559
  1326
      typedef typename Base::Edge Edge;
deba@57
  1327
deba@57
  1328
      /// \brief Adds a new node to the graph.
deba@57
  1329
      ///
deba@57
  1330
      /// Adds a new node to the graph.
deba@57
  1331
      ///
deba@57
  1332
      Node addNode() {
alpar@209
  1333
        return INVALID;
deba@57
  1334
      }
alpar@209
  1335
deba@57
  1336
      /// \brief Adds a new arc connects the given two nodes.
deba@57
  1337
      ///
deba@57
  1338
      /// Adds a new arc connects the the given two nodes.
deba@57
  1339
      Edge addArc(const Node&, const Node&) {
alpar@209
  1340
        return INVALID;
deba@57
  1341
      }
deba@57
  1342
deba@57
  1343
      template <typename _Graph>
deba@57
  1344
      struct Constraints {
alpar@209
  1345
        void constraints() {
alpar@209
  1346
          checkConcept<Base, _Graph>();
alpar@209
  1347
          typename _Graph::Node node_a, node_b;
alpar@209
  1348
          node_a = graph.addNode();
alpar@209
  1349
          node_b = graph.addNode();
alpar@209
  1350
          typename _Graph::Edge edge;
alpar@209
  1351
          edge = graph.addEdge(node_a, node_b);
alpar@209
  1352
        }
deba@57
  1353
alpar@209
  1354
        _Graph& graph;
deba@57
  1355
      };
deba@57
  1356
    };
deba@57
  1357
deba@57
  1358
    /// \brief An empty erasable digraph class.
alpar@209
  1359
    ///
deba@57
  1360
    /// This class provides beside the core digraph features core erase
deba@57
  1361
    /// functions for the digraph structure. The main difference between
deba@57
  1362
    /// the base and this interface is that the digraph alterations
deba@57
  1363
    /// should handled already on this level.
kpeter@559
  1364
    template <typename BAS = BaseDigraphComponent>
kpeter@559
  1365
    class ErasableDigraphComponent : public BAS {
deba@57
  1366
    public:
deba@57
  1367
kpeter@559
  1368
      typedef BAS Base;
deba@57
  1369
      typedef typename Base::Node Node;
deba@57
  1370
      typedef typename Base::Arc Arc;
deba@57
  1371
deba@57
  1372
      /// \brief Erase a node from the digraph.
deba@57
  1373
      ///
alpar@209
  1374
      /// Erase a node from the digraph. This function should
deba@57
  1375
      /// erase all arcs connecting to the node.
alpar@209
  1376
      void erase(const Node&) {}
deba@57
  1377
deba@57
  1378
      /// \brief Erase an arc from the digraph.
deba@57
  1379
      ///
deba@57
  1380
      /// Erase an arc from the digraph.
deba@57
  1381
      ///
deba@57
  1382
      void erase(const Arc&) {}
deba@57
  1383
deba@57
  1384
      template <typename _Digraph>
deba@57
  1385
      struct Constraints {
alpar@209
  1386
        void constraints() {
deba@57
  1387
          checkConcept<Base, _Digraph>();
alpar@209
  1388
          typename _Digraph::Node node;
alpar@209
  1389
          digraph.erase(node);
alpar@209
  1390
          typename _Digraph::Arc arc;
alpar@209
  1391
          digraph.erase(arc);
alpar@209
  1392
        }
deba@57
  1393
alpar@209
  1394
        _Digraph& digraph;
deba@57
  1395
      };
deba@57
  1396
    };
deba@57
  1397
deba@57
  1398
    /// \brief An empty erasable base undirected graph class.
alpar@209
  1399
    ///
deba@57
  1400
    /// This class provides beside the core undirected graph features
deba@57
  1401
    /// core erase functions for the undirceted graph structure. The
deba@57
  1402
    /// main difference between the base and this interface is that
deba@57
  1403
    /// the graph alterations should handled already on this level.
kpeter@559
  1404
    template <typename BAS = BaseGraphComponent>
kpeter@559
  1405
    class ErasableGraphComponent : public BAS {
deba@57
  1406
    public:
deba@57
  1407
kpeter@559
  1408
      typedef BAS Base;
deba@57
  1409
      typedef typename Base::Node Node;
deba@57
  1410
      typedef typename Base::Edge Edge;
deba@57
  1411
deba@57
  1412
      /// \brief Erase a node from the graph.
deba@57
  1413
      ///
deba@57
  1414
      /// Erase a node from the graph. This function should erase
deba@57
  1415
      /// arcs connecting to the node.
alpar@209
  1416
      void erase(const Node&) {}
deba@57
  1417
deba@57
  1418
      /// \brief Erase an arc from the graph.
deba@57
  1419
      ///
deba@57
  1420
      /// Erase an arc from the graph.
deba@57
  1421
      ///
deba@57
  1422
      void erase(const Edge&) {}
deba@57
  1423
deba@57
  1424
      template <typename _Graph>
deba@57
  1425
      struct Constraints {
alpar@209
  1426
        void constraints() {
deba@57
  1427
          checkConcept<Base, _Graph>();
alpar@209
  1428
          typename _Graph::Node node;
alpar@209
  1429
          graph.erase(node);
alpar@209
  1430
          typename _Graph::Edge edge;
alpar@209
  1431
          graph.erase(edge);
alpar@209
  1432
        }
deba@57
  1433
alpar@209
  1434
        _Graph& graph;
deba@57
  1435
      };
deba@57
  1436
    };
deba@57
  1437
deba@57
  1438
    /// \brief An empty clearable base digraph class.
deba@57
  1439
    ///
deba@57
  1440
    /// This class provides beside the core digraph features core clear
deba@57
  1441
    /// functions for the digraph structure. The main difference between
deba@57
  1442
    /// the base and this interface is that the digraph alterations
deba@57
  1443
    /// should handled already on this level.
kpeter@559
  1444
    template <typename BAS = BaseDigraphComponent>
kpeter@559
  1445
    class ClearableDigraphComponent : public BAS {
deba@57
  1446
    public:
deba@57
  1447
kpeter@559
  1448
      typedef BAS Base;
deba@57
  1449
deba@57
  1450
      /// \brief Erase all nodes and arcs from the digraph.
deba@57
  1451
      ///
deba@57
  1452
      /// Erase all nodes and arcs from the digraph.
deba@57
  1453
      ///
alpar@209
  1454
      void clear() {}
deba@57
  1455
deba@57
  1456
      template <typename _Digraph>
deba@57
  1457
      struct Constraints {
alpar@209
  1458
        void constraints() {
deba@57
  1459
          checkConcept<Base, _Digraph>();
alpar@209
  1460
          digraph.clear();
alpar@209
  1461
        }
deba@57
  1462
alpar@209
  1463
        _Digraph digraph;
deba@57
  1464
      };
deba@57
  1465
    };
deba@57
  1466
deba@57
  1467
    /// \brief An empty clearable base undirected graph class.
deba@57
  1468
    ///
deba@57
  1469
    /// This class provides beside the core undirected graph features
deba@57
  1470
    /// core clear functions for the undirected graph structure. The
deba@57
  1471
    /// main difference between the base and this interface is that
deba@57
  1472
    /// the graph alterations should handled already on this level.
kpeter@559
  1473
    template <typename BAS = BaseGraphComponent>
kpeter@559
  1474
    class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {
deba@57
  1475
    public:
deba@57
  1476
kpeter@559
  1477
      typedef BAS Base;
deba@57
  1478
deba@57
  1479
      template <typename _Graph>
deba@57
  1480
      struct Constraints {
alpar@209
  1481
        void constraints() {
deba@57
  1482
          checkConcept<ClearableGraphComponent<Base>, _Graph>();
alpar@209
  1483
        }
deba@57
  1484
alpar@209
  1485
        _Graph graph;
deba@57
  1486
      };
deba@57
  1487
    };
deba@57
  1488
deba@57
  1489
  }
deba@57
  1490
deba@57
  1491
}
deba@57
  1492
deba@57
  1493
#endif