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