lemon/concepts/graph_components.h
author Peter Kovacs <kpeter@inf.elte.hu>
Fri, 03 Apr 2009 18:59:15 +0200
changeset 600 6ac5d9ae1d3d
parent 514 f5bc148f7e1f
parent 519 9605e051942f
child 550 c5fd2d996909
permissions -rw-r--r--
Support real types + numerical stability fix in NS (#254)

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