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