lemon/concepts/graph_components.h
author Peter Kovacs <kpeter@inf.elte.hu>
Tue, 12 May 2009 12:06:40 +0200
changeset 663 8b0df68370a4
parent 584 33c6b6e755cd
child 666 1993af615e68
permissions -rw-r--r--
Fix the GEQ/LEQ handling in NetworkSimplex + improve doc (#291)

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