lemon/concepts/graph_components.h
author Akos Ladanyi <ladanyi@tmit.bme.hu>
Sun, 13 Apr 2008 13:22:52 +0200
changeset 141 96f81c791f0c
parent 78 c46b3453455f
child 169 5b507a86ad72
permissions -rw-r--r--
CMake based build system
deba@57
     1
/* -*- C++ -*-
deba@57
     2
 *
deba@57
     3
 * This file is a part of LEMON, a generic C++ optimization library
deba@57
     4
 *
alpar@107
     5
 * Copyright (C) 2003-2008
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@57
    24
#ifndef LEMON_CONCEPT_GRAPH_COMPONENTS_H
deba@57
    25
#define LEMON_CONCEPT_GRAPH_COMPONENTS_H
deba@57
    26
deba@57
    27
#include <lemon/bits/invalid.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.
deba@57
    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
      ///
deba@57
    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 {
deba@57
    95
	void constraints() {
deba@57
    96
	  _GraphItem i1;
deba@57
    97
	  _GraphItem i2 = i1;
deba@57
    98
	  _GraphItem i3 = INVALID;
deba@57
    99
	  
deba@57
   100
	  i1 = i2 = i3;
deba@57
   101
deba@57
   102
	  bool b;
deba@57
   103
	  //	  b = (ia == ib) && (ia != ib) && (ia < ib);
deba@57
   104
	  b = (ia == ib) && (ia != ib);
deba@57
   105
	  b = (ia == INVALID) && (ib != INVALID);
deba@57
   106
          b = (ia < ib);
deba@57
   107
	}
deba@57
   108
deba@57
   109
	const _GraphItem &ia;
deba@57
   110
	const _GraphItem &ib;
deba@57
   111
      };
deba@57
   112
    };
deba@57
   113
deba@57
   114
    /// \brief An empty base directed graph class.
deba@57
   115
    ///  
deba@57
   116
    /// This class provides the minimal set of features needed for a
deba@57
   117
    /// directed graph structure. All digraph concepts have to be
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;
deba@57
   125
      
deba@57
   126
      /// \brief Node class of the digraph.
deba@57
   127
      ///
deba@57
   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
      ///
deba@57
   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 {
deba@57
   159
	typedef typename _Digraph::Node Node;
deba@57
   160
	typedef typename _Digraph::Arc Arc;
deba@57
   161
      
deba@57
   162
	void constraints() {
deba@57
   163
	  checkConcept<GraphItem<'n'>, Node>();
deba@57
   164
	  checkConcept<GraphItem<'a'>, Arc>();
deba@57
   165
	  {
deba@57
   166
	    Node n;
deba@57
   167
	    Arc e(INVALID);
deba@57
   168
	    n = digraph.source(e);
deba@57
   169
	    n = digraph.target(e);
deba@57
   170
            n = digraph.oppositeNode(n, e);
deba@57
   171
	  }      
deba@57
   172
	}
deba@57
   173
      
deba@57
   174
	const _Digraph& digraph;
deba@57
   175
      };
deba@57
   176
    };
deba@57
   177
deba@57
   178
    /// \brief An empty base undirected graph class.
deba@57
   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
deba@57
   182
    /// to be 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.
deba@57
   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
deba@57
   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
deba@57
   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.
deba@57
   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.
deba@57
   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;}
deba@57
   263
      
deba@57
   264
      template <typename _Graph>
deba@57
   265
      struct Constraints {
deba@57
   266
	typedef typename _Graph::Node Node;
deba@57
   267
	typedef typename _Graph::Arc Arc;
deba@57
   268
	typedef typename _Graph::Edge Edge;
deba@57
   269
      
deba@57
   270
	void constraints() {
deba@57
   271
          checkConcept<BaseDigraphComponent, _Graph>();
deba@57
   272
	  checkConcept<GraphItem<'u'>, Edge>();
deba@57
   273
	  {
deba@57
   274
	    Node n;
deba@57
   275
	    Edge ue(INVALID);
deba@57
   276
            Arc e;
deba@57
   277
	    n = graph.u(ue);
deba@57
   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);
deba@57
   285
	  }      
deba@57
   286
	}
deba@57
   287
      
deba@57
   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.
deba@57
   294
    ///  
deba@57
   295
    /// This class provides beside the core digraph features
deba@57
   296
    /// core id functions for the digraph structure.
deba@57
   297
    /// The most of the base digraphs should be 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
deba@57
   307
      /// \brief Gives back an unique integer id for the Node. 
deba@57
   308
      ///
deba@57
   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
deba@57
   317
      /// then the result of the function is undetermined. 
deba@57
   318
      Node nodeFromId(int) const { return INVALID;}
deba@57
   319
deba@57
   320
      /// \brief Gives back an unique integer id for the Arc. 
deba@57
   321
      ///
deba@57
   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
deba@57
   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
deba@57
   350
	void constraints() {
deba@57
   351
	  checkConcept<Base, _Digraph >();
deba@57
   352
	  typename _Digraph::Node node;
deba@57
   353
	  int nid = digraph.id(node);
deba@57
   354
	  nid = digraph.id(node);
deba@57
   355
	  node = digraph.nodeFromId(nid);
deba@57
   356
	  typename _Digraph::Arc arc;
deba@57
   357
	  int eid = digraph.id(arc);
deba@57
   358
	  eid = digraph.id(arc);
deba@57
   359
	  arc = digraph.arcFromId(eid);
deba@57
   360
deba@57
   361
	  nid = digraph.maxNodeId();
deba@57
   362
	  ignore_unused_variable_warning(nid);
deba@57
   363
	  eid = digraph.maxArcId();
deba@57
   364
	  ignore_unused_variable_warning(eid);
deba@57
   365
	}
deba@57
   366
deba@57
   367
	const _Digraph& digraph;
deba@57
   368
      };
deba@57
   369
    };
deba@57
   370
deba@57
   371
    /// \brief An empty idable base undirected graph class.
deba@57
   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
deba@57
   375
    /// most of the base undirected graphs should be 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
deba@57
   386
      /// \brief Gives back an unique integer id for the Edge. 
deba@57
   387
      ///
deba@57
   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
deba@57
   409
	void constraints() {
deba@57
   410
	  checkConcept<Base, _Graph >();
deba@57
   411
	  checkConcept<IDableDigraphComponent<Base>, _Graph >();
deba@57
   412
	  typename _Graph::Edge edge;
deba@57
   413
	  int ueid = graph.id(edge);
deba@57
   414
	  ueid = graph.id(edge);
deba@57
   415
	  edge = graph.edgeFromId(ueid);
deba@57
   416
	  ueid = graph.maxEdgeId();
deba@57
   417
	  ignore_unused_variable_warning(ueid);
deba@57
   418
	}
deba@57
   419
deba@57
   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
      ///
deba@57
   453
      /// The items are assignable. 
deba@57
   454
      ///
deba@57
   455
      GraphItemIt& operator=(const GraphItemIt&) { return *this; }      
deba@57
   456
      /// \brief Next item.
deba@57
   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
deba@57
   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
deba@57
   467
      ///	
deba@57
   468
      /// \sa operator==(Node n)
deba@57
   469
      ///
deba@57
   470
      bool operator!=(const GraphItemIt&) const { return true;}
deba@57
   471
      
deba@57
   472
      template<typename _GraphItemIt>
deba@57
   473
      struct Constraints {
deba@57
   474
	void constraints() {
deba@57
   475
	  _GraphItemIt it1(g);	
deba@57
   476
	  _GraphItemIt it2;
deba@57
   477
deba@57
   478
	  it2 = ++it1;
deba@57
   479
	  ++it2 = it1;
deba@57
   480
	  ++(++it1);
deba@57
   481
deba@57
   482
	  _Item bi = it1;
deba@57
   483
	  bi = it2;
deba@57
   484
	}
deba@57
   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
deba@57
   492
    /// base class, the _selector is a additional template parameter. For 
deba@57
   493
    /// InArcIt you should instantiate it with character 'i' and for 
deba@57
   494
    /// OutArcIt with 'o'.
deba@57
   495
    template <typename _Graph,
deba@57
   496
	      typename _Item = typename _Graph::Arc,
deba@57
   497
              typename _Base = typename _Graph::Node, 
deba@57
   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) {}
deba@57
   511
      /// \brief Sets the iterator to the first arc incoming into or outgoing 
deba@57
   512
      /// from the node.
deba@57
   513
      ///
deba@57
   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
      ///
deba@57
   525
      /// The iterators are assignable. 
deba@57
   526
      ///
deba@57
   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 {
deba@57
   548
	void constraints() {
deba@57
   549
	  checkConcept<GraphItem<_selector>, _GraphIncIt>();
deba@57
   550
	  _GraphIncIt it1(graph, node);
deba@57
   551
	  _GraphIncIt it2;
deba@57
   552
deba@57
   553
	  it2 = ++it1;
deba@57
   554
	  ++it2 = it1;
deba@57
   555
	  ++(++it1);
deba@57
   556
	  _Item e = it1;
deba@57
   557
	  e = it2;
deba@57
   558
deba@57
   559
	}
deba@57
   560
deba@57
   561
	_Item arc;
deba@57
   562
	_Base node;
deba@57
   563
	_Graph graph;
deba@57
   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:
deba@57
   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
deba@57
   586
      /// 
deba@57
   587
      /// This interface provides functions for iteration on digraph items
deba@57
   588
      ///
deba@57
   589
      /// @{  
deba@57
   590
deba@57
   591
      /// \brief Gives back the first node in the iterating order.
deba@57
   592
      ///      
deba@57
   593
      /// Gives back the first node in the iterating order.
deba@57
   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.
deba@57
   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.
deba@57
   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.
deba@57
   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.
deba@57
   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.
deba@57
   632
      ///      
deba@57
   633
      /// Gives back the first of the arcs start from the given node.
deba@57
   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.
deba@57
   641
      ///     
deba@57
   642
      void nextOut(Arc&) const {}
deba@57
   643
deba@57
   644
      /// @}
deba@57
   645
deba@57
   646
      /// \name Class based iteration
deba@57
   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
deba@57
   702
      template <typename _Digraph> 
deba@57
   703
      struct Constraints {
deba@57
   704
	void constraints() {
deba@57
   705
	  checkConcept<Base, _Digraph>();
deba@57
   706
deba@57
   707
          {
deba@57
   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
            }
deba@57
   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 >();
deba@57
   733
            checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, 
deba@57
   734
              typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>();
deba@57
   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
        }
deba@57
   748
	
deba@57
   749
	const _Digraph& digraph;
deba@57
   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
deba@57
   768
    
deba@57
   769
      typedef IterableGraphComponent Graph;
deba@57
   770
deba@57
   771
      /// \name Base iteration
deba@57
   772
      /// 
deba@57
   773
      /// This interface provides functions for iteration on graph items
deba@57
   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.
deba@57
   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.
deba@57
   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
deba@57
   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
deba@57
   844
      template <typename _Graph> 
deba@57
   845
      struct Constraints {
deba@57
   846
	void constraints() {
deba@57
   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
            }
deba@57
   861
            
deba@57
   862
          }	
deba@57
   863
  
deba@57
   864
          {
deba@57
   865
            checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>,
deba@57
   866
              typename _Graph::EdgeIt >();
deba@57
   867
            checkConcept<GraphIncIt<_Graph, typename _Graph::Edge, 
deba@78
   868
              typename _Graph::Node, 'u'>, typename _Graph::IncEdgeIt>();
deba@57
   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
        }
deba@57
   876
	
deba@57
   877
	const _Graph& graph;
deba@57
   878
	
deba@57
   879
      };
deba@57
   880
    };
deba@57
   881
deba@57
   882
    /// \brief An empty alteration notifier digraph class.
deba@57
   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.
deba@57
   900
      typedef AlterationNotifier<AlterableDigraphComponent, Node> 
deba@57
   901
      NodeNotifier;
deba@57
   902
      /// The arc observer registry.
deba@57
   903
      typedef AlterationNotifier<AlterableDigraphComponent, Arc> 
deba@57
   904
      ArcNotifier;
deba@57
   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 {
deba@57
   910
	return NodeNotifier();
deba@57
   911
      }
deba@57
   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 {
deba@57
   917
	return ArcNotifier();
deba@57
   918
      }
deba@57
   919
deba@57
   920
      template <typename _Digraph> 
deba@57
   921
      struct Constraints {
deba@57
   922
	void constraints() {
deba@57
   923
	  checkConcept<Base, _Digraph>();
deba@57
   924
          typename _Digraph::NodeNotifier& nn 
deba@57
   925
            = digraph.notifier(typename _Digraph::Node());
deba@57
   926
deba@57
   927
          typename _Digraph::ArcNotifier& en 
deba@57
   928
            = digraph.notifier(typename _Digraph::Arc());
deba@57
   929
          
deba@57
   930
          ignore_unused_variable_warning(nn);
deba@57
   931
          ignore_unused_variable_warning(en);
deba@57
   932
	}
deba@57
   933
	
deba@57
   934
	const _Digraph& digraph;
deba@57
   935
	
deba@57
   936
      };
deba@57
   937
      
deba@57
   938
    };
deba@57
   939
deba@57
   940
    /// \brief An empty alteration notifier undirected graph class.
deba@57
   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.
deba@57
   957
      typedef AlterationNotifier<AlterableGraphComponent, Edge> 
deba@57
   958
      EdgeNotifier;
deba@57
   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 {
deba@57
   964
	return EdgeNotifier();
deba@57
   965
      }
deba@57
   966
deba@57
   967
      template <typename _Graph> 
deba@57
   968
      struct Constraints {
deba@57
   969
	void constraints() {
deba@57
   970
	  checkConcept<AlterableGraphComponent<Base>, _Graph>();
deba@57
   971
          typename _Graph::EdgeNotifier& uen 
deba@57
   972
            = graph.notifier(typename _Graph::Edge());
deba@57
   973
          ignore_unused_variable_warning(uen);
deba@57
   974
	}
deba@57
   975
	
deba@57
   976
	const _Graph& graph;
deba@57
   977
	
deba@57
   978
      };
deba@57
   979
      
deba@57
   980
    };
deba@57
   981
deba@57
   982
    /// \brief Class describing the concept of graph maps
deba@57
   983
    /// 
deba@57
   984
    /// This class describes the common interface of the graph maps
deba@57
   985
    /// (NodeMap, ArcMap), that is \ref maps-page "maps" which 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&) {}
deba@57
  1008
      /// \brief Copy constructor.
deba@57
  1009
      ///
deba@57
  1010
      /// Copy Constructor.
deba@57
  1011
      GraphMap(const GraphMap&) : Parent() {}
deba@57
  1012
      
deba@57
  1013
      /// \brief Assign operator.
deba@57
  1014
      ///
deba@57
  1015
      /// Assign operator. It does not mofify the underlying graph,
deba@57
  1016
      /// it just iterates on the current item set and set the  map
deba@57
  1017
      /// with the value returned by the assigned map. 
deba@57
  1018
      template <typename CMap>
deba@57
  1019
      GraphMap& operator=(const CMap&) { 
deba@57
  1020
        checkConcept<ReadMap<Key, Value>, CMap>();
deba@57
  1021
        return *this;
deba@57
  1022
      }
deba@57
  1023
deba@57
  1024
      template<typename _Map>
deba@57
  1025
      struct Constraints {
deba@57
  1026
	void constraints() {
deba@57
  1027
	  checkConcept<ReadWriteMap<Key, Value>, _Map >();
deba@57
  1028
	  // Construction with a graph parameter
deba@57
  1029
	  _Map a(g);
deba@57
  1030
	  // Constructor with a graph and a default value parameter
deba@57
  1031
	  _Map a2(g,t);
deba@57
  1032
	  // Copy constructor.
deba@57
  1033
	  _Map b(c);
deba@57
  1034
          
deba@57
  1035
          ReadMap<Key, Value> cmap;
deba@57
  1036
          b = cmap;
deba@57
  1037
deba@57
  1038
	  ignore_unused_variable_warning(a2);
deba@57
  1039
	  ignore_unused_variable_warning(b);
deba@57
  1040
	}
deba@57
  1041
deba@57
  1042
	const _Map &c;
deba@57
  1043
	const Graph &g;
deba@57
  1044
	const typename GraphMap::Value &t;
deba@57
  1045
      };
deba@57
  1046
deba@57
  1047
    };
deba@57
  1048
deba@57
  1049
    /// \brief An empty mappable digraph class.
deba@57
  1050
    ///
deba@57
  1051
    /// This class provides beside the core digraph features
deba@57
  1052
    /// map interface for the digraph structure.
deba@57
  1053
    /// This concept is part of the Digraph concept.
deba@57
  1054
    template <typename _Base = BaseDigraphComponent>
deba@57
  1055
    class MappableDigraphComponent : public _Base  {
deba@57
  1056
    public:
deba@57
  1057
deba@57
  1058
      typedef _Base Base;
deba@57
  1059
      typedef typename Base::Node Node;
deba@57
  1060
      typedef typename Base::Arc Arc;
deba@57
  1061
deba@57
  1062
      typedef MappableDigraphComponent Digraph;
deba@57
  1063
deba@57
  1064
      /// \brief ReadWrite map of the nodes.
deba@57
  1065
      ///
deba@57
  1066
      /// ReadWrite map of the nodes.
deba@57
  1067
      ///
deba@57
  1068
      template <typename _Value>
deba@57
  1069
      class NodeMap : public GraphMap<Digraph, Node, _Value> {
deba@57
  1070
      public:
deba@57
  1071
        typedef GraphMap<MappableDigraphComponent, Node, _Value> Parent;
deba@57
  1072
deba@57
  1073
	/// \brief Construct a new map.
deba@57
  1074
	///
deba@57
  1075
	/// Construct a new map for the digraph.
deba@57
  1076
	explicit NodeMap(const MappableDigraphComponent& digraph) 
deba@57
  1077
          : Parent(digraph) {}
deba@57
  1078
deba@57
  1079
	/// \brief Construct a new map with default value.
deba@57
  1080
	///
deba@57
  1081
	/// Construct a new map for the digraph and initalise the values.
deba@57
  1082
	NodeMap(const MappableDigraphComponent& digraph, const _Value& value)
deba@57
  1083
          : Parent(digraph, value) {}
deba@57
  1084
deba@57
  1085
	/// \brief Copy constructor.
deba@57
  1086
	///
deba@57
  1087
	/// Copy Constructor.
deba@57
  1088
	NodeMap(const NodeMap& nm) : Parent(nm) {}
deba@57
  1089
deba@57
  1090
	/// \brief Assign operator.
deba@57
  1091
	///
deba@57
  1092
	/// Assign operator.
deba@57
  1093
        template <typename CMap>
deba@57
  1094
        NodeMap& operator=(const CMap&) { 
deba@57
  1095
          checkConcept<ReadMap<Node, _Value>, CMap>();
deba@57
  1096
          return *this;
deba@57
  1097
        }
deba@57
  1098
deba@57
  1099
      };
deba@57
  1100
deba@57
  1101
      /// \brief ReadWrite map of the arcs.
deba@57
  1102
      ///
deba@57
  1103
      /// ReadWrite map of the arcs.
deba@57
  1104
      ///
deba@57
  1105
      template <typename _Value>
deba@57
  1106
      class ArcMap : public GraphMap<Digraph, Arc, _Value> {
deba@57
  1107
      public:
deba@57
  1108
        typedef GraphMap<MappableDigraphComponent, Arc, _Value> Parent;
deba@57
  1109
deba@57
  1110
	/// \brief Construct a new map.
deba@57
  1111
	///
deba@57
  1112
	/// Construct a new map for the digraph.
deba@57
  1113
	explicit ArcMap(const MappableDigraphComponent& digraph) 
deba@57
  1114
          : Parent(digraph) {}
deba@57
  1115
deba@57
  1116
	/// \brief Construct a new map with default value.
deba@57
  1117
	///
deba@57
  1118
	/// Construct a new map for the digraph and initalise the values.
deba@57
  1119
	ArcMap(const MappableDigraphComponent& digraph, const _Value& value)
deba@57
  1120
          : Parent(digraph, value) {}
deba@57
  1121
deba@57
  1122
	/// \brief Copy constructor.
deba@57
  1123
	///
deba@57
  1124
	/// Copy Constructor.
deba@57
  1125
	ArcMap(const ArcMap& nm) : Parent(nm) {}
deba@57
  1126
deba@57
  1127
	/// \brief Assign operator.
deba@57
  1128
	///
deba@57
  1129
	/// Assign operator.
deba@57
  1130
        template <typename CMap>
deba@57
  1131
        ArcMap& operator=(const CMap&) { 
deba@57
  1132
          checkConcept<ReadMap<Arc, _Value>, CMap>();
deba@57
  1133
          return *this;
deba@57
  1134
        }
deba@57
  1135
deba@57
  1136
      };
deba@57
  1137
deba@57
  1138
deba@57
  1139
      template <typename _Digraph>
deba@57
  1140
      struct Constraints {
deba@57
  1141
deba@57
  1142
	struct Dummy {
deba@57
  1143
	  int value;
deba@57
  1144
	  Dummy() : value(0) {}
deba@57
  1145
	  Dummy(int _v) : value(_v) {}
deba@57
  1146
	};
deba@57
  1147
deba@57
  1148
	void constraints() {
deba@57
  1149
	  checkConcept<Base, _Digraph>();
deba@57
  1150
	  { // int map test
deba@57
  1151
	    typedef typename _Digraph::template NodeMap<int> IntNodeMap;
deba@57
  1152
	    checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>, 
deba@57
  1153
	      IntNodeMap >();
deba@57
  1154
	  } { // bool map test
deba@57
  1155
	    typedef typename _Digraph::template NodeMap<bool> BoolNodeMap;
deba@57
  1156
	    checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>,
deba@57
  1157
	      BoolNodeMap >();
deba@57
  1158
	  } { // Dummy map test
deba@57
  1159
	    typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap;
deba@57
  1160
	    checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>,
deba@57
  1161
	      DummyNodeMap >();
deba@57
  1162
	  } 
deba@57
  1163
deba@57
  1164
	  { // int map test
deba@57
  1165
	    typedef typename _Digraph::template ArcMap<int> IntArcMap;
deba@57
  1166
	    checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
deba@57
  1167
	      IntArcMap >();
deba@57
  1168
	  } { // bool map test
deba@57
  1169
	    typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
deba@57
  1170
	    checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
deba@57
  1171
	      BoolArcMap >();
deba@57
  1172
	  } { // Dummy map test
deba@57
  1173
	    typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
deba@57
  1174
	    checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>, 
deba@57
  1175
	      DummyArcMap >();
deba@57
  1176
	  } 
deba@57
  1177
	}
deba@57
  1178
deba@57
  1179
	_Digraph& digraph;
deba@57
  1180
      };
deba@57
  1181
    };
deba@57
  1182
deba@57
  1183
    /// \brief An empty mappable base bipartite graph class.
deba@57
  1184
    ///
deba@57
  1185
    /// This class provides beside the core graph features
deba@57
  1186
    /// map interface for the graph structure.
deba@57
  1187
    /// This concept is part of the Graph concept.
deba@57
  1188
    template <typename _Base = BaseGraphComponent>
deba@57
  1189
    class MappableGraphComponent : public MappableDigraphComponent<_Base>  {
deba@57
  1190
    public:
deba@57
  1191
deba@57
  1192
      typedef _Base Base;
deba@57
  1193
      typedef typename Base::Edge Edge;
deba@57
  1194
deba@57
  1195
      typedef MappableGraphComponent Graph;
deba@57
  1196
deba@57
  1197
      /// \brief ReadWrite map of the edges.
deba@57
  1198
      ///
deba@57
  1199
      /// ReadWrite map of the edges.
deba@57
  1200
      ///
deba@57
  1201
      template <typename _Value>
deba@57
  1202
      class EdgeMap : public GraphMap<Graph, Edge, _Value> {  
deba@57
  1203
      public:
deba@57
  1204
        typedef GraphMap<MappableGraphComponent, Edge, _Value> Parent;
deba@57
  1205
deba@57
  1206
	/// \brief Construct a new map.
deba@57
  1207
	///
deba@57
  1208
	/// Construct a new map for the graph.
deba@57
  1209
	explicit EdgeMap(const MappableGraphComponent& graph) 
deba@57
  1210
          : Parent(graph) {}
deba@57
  1211
deba@57
  1212
	/// \brief Construct a new map with default value.
deba@57
  1213
	///
deba@57
  1214
	/// Construct a new map for the graph and initalise the values.
deba@57
  1215
	EdgeMap(const MappableGraphComponent& graph, const _Value& value)
deba@57
  1216
          : Parent(graph, value) {}
deba@57
  1217
deba@57
  1218
	/// \brief Copy constructor.
deba@57
  1219
	///
deba@57
  1220
	/// Copy Constructor.
deba@57
  1221
	EdgeMap(const EdgeMap& nm) : Parent(nm) {}
deba@57
  1222
deba@57
  1223
	/// \brief Assign operator.
deba@57
  1224
	///
deba@57
  1225
	/// Assign operator.
deba@57
  1226
        template <typename CMap>
deba@57
  1227
        EdgeMap& operator=(const CMap&) { 
deba@57
  1228
          checkConcept<ReadMap<Edge, _Value>, CMap>();
deba@57
  1229
          return *this;
deba@57
  1230
        }
deba@57
  1231
deba@57
  1232
      };
deba@57
  1233
deba@57
  1234
deba@57
  1235
      template <typename _Graph>
deba@57
  1236
      struct Constraints {
deba@57
  1237
deba@57
  1238
	struct Dummy {
deba@57
  1239
	  int value;
deba@57
  1240
	  Dummy() : value(0) {}
deba@57
  1241
	  Dummy(int _v) : value(_v) {}
deba@57
  1242
	};
deba@57
  1243
deba@57
  1244
	void constraints() {
deba@57
  1245
	  checkConcept<MappableGraphComponent<Base>, _Graph>();
deba@57
  1246
deba@57
  1247
	  { // int map test
deba@57
  1248
	    typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
deba@57
  1249
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
deba@57
  1250
	      IntEdgeMap >();
deba@57
  1251
	  } { // bool map test
deba@57
  1252
	    typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
deba@57
  1253
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
deba@57
  1254
	      BoolEdgeMap >();
deba@57
  1255
	  } { // Dummy map test
deba@57
  1256
	    typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
deba@57
  1257
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>, 
deba@57
  1258
	      DummyEdgeMap >();
deba@57
  1259
	  } 
deba@57
  1260
	}
deba@57
  1261
deba@57
  1262
	_Graph& graph;
deba@57
  1263
      };
deba@57
  1264
    };
deba@57
  1265
deba@57
  1266
    /// \brief An empty extendable digraph class.
deba@57
  1267
    ///
deba@57
  1268
    /// This class provides beside the core digraph features digraph
deba@57
  1269
    /// extendable interface for the digraph structure.  The main
deba@57
  1270
    /// difference between the base and this interface is that the
deba@57
  1271
    /// digraph alterations should handled already on this level.
deba@57
  1272
    template <typename _Base = BaseDigraphComponent>
deba@57
  1273
    class ExtendableDigraphComponent : public _Base {
deba@57
  1274
    public:
deba@57
  1275
      typedef _Base Base;
deba@57
  1276
deba@57
  1277
      typedef typename _Base::Node Node;
deba@57
  1278
      typedef typename _Base::Arc Arc;
deba@57
  1279
deba@57
  1280
      /// \brief Adds a new node to the digraph.
deba@57
  1281
      ///
deba@57
  1282
      /// Adds a new node to the digraph.
deba@57
  1283
      ///
deba@57
  1284
      Node addNode() {
deba@57
  1285
	return INVALID;
deba@57
  1286
      }
deba@57
  1287
    
deba@57
  1288
      /// \brief Adds a new arc connects the given two nodes.
deba@57
  1289
      ///
deba@57
  1290
      /// Adds a new arc connects the the given two nodes.
deba@57
  1291
      Arc addArc(const Node&, const Node&) {
deba@57
  1292
	return INVALID;
deba@57
  1293
      }
deba@57
  1294
deba@57
  1295
      template <typename _Digraph>
deba@57
  1296
      struct Constraints {
deba@57
  1297
	void constraints() {
deba@57
  1298
          checkConcept<Base, _Digraph>();
deba@57
  1299
	  typename _Digraph::Node node_a, node_b;
deba@57
  1300
	  node_a = digraph.addNode();
deba@57
  1301
	  node_b = digraph.addNode();
deba@57
  1302
	  typename _Digraph::Arc arc;
deba@57
  1303
	  arc = digraph.addArc(node_a, node_b);
deba@57
  1304
	}
deba@57
  1305
deba@57
  1306
	_Digraph& digraph;
deba@57
  1307
      };
deba@57
  1308
    };
deba@57
  1309
deba@57
  1310
    /// \brief An empty extendable base undirected graph class.
deba@57
  1311
    ///
deba@57
  1312
    /// This class provides beside the core undirected graph features
deba@57
  1313
    /// core undircted graph extend interface for the graph structure.
deba@57
  1314
    /// The main difference between the base and this interface is
deba@57
  1315
    /// that the graph alterations should handled already on this
deba@57
  1316
    /// level.
deba@57
  1317
    template <typename _Base = BaseGraphComponent>
deba@57
  1318
    class ExtendableGraphComponent : public _Base {
deba@57
  1319
    public:
deba@57
  1320
deba@57
  1321
      typedef _Base Base;
deba@57
  1322
      typedef typename _Base::Node Node;
deba@57
  1323
      typedef typename _Base::Edge Edge;
deba@57
  1324
deba@57
  1325
      /// \brief Adds a new node to the graph.
deba@57
  1326
      ///
deba@57
  1327
      /// Adds a new node to the graph.
deba@57
  1328
      ///
deba@57
  1329
      Node addNode() {
deba@57
  1330
	return INVALID;
deba@57
  1331
      }
deba@57
  1332
    
deba@57
  1333
      /// \brief Adds a new arc connects the given two nodes.
deba@57
  1334
      ///
deba@57
  1335
      /// Adds a new arc connects the the given two nodes.
deba@57
  1336
      Edge addArc(const Node&, const Node&) {
deba@57
  1337
	return INVALID;
deba@57
  1338
      }
deba@57
  1339
deba@57
  1340
      template <typename _Graph>
deba@57
  1341
      struct Constraints {
deba@57
  1342
	void constraints() {
deba@57
  1343
	  checkConcept<Base, _Graph>();
deba@57
  1344
	  typename _Graph::Node node_a, node_b;
deba@57
  1345
	  node_a = graph.addNode();
deba@57
  1346
	  node_b = graph.addNode();
deba@57
  1347
	  typename _Graph::Edge edge;
deba@57
  1348
	  edge = graph.addEdge(node_a, node_b);
deba@57
  1349
	}
deba@57
  1350
deba@57
  1351
	_Graph& graph;
deba@57
  1352
      };
deba@57
  1353
    };
deba@57
  1354
deba@57
  1355
    /// \brief An empty erasable digraph class.
deba@57
  1356
    ///  
deba@57
  1357
    /// This class provides beside the core digraph features core erase
deba@57
  1358
    /// functions for the digraph structure. The main difference between
deba@57
  1359
    /// the base and this interface is that the digraph alterations
deba@57
  1360
    /// should handled already on this level.
deba@57
  1361
    template <typename _Base = BaseDigraphComponent>
deba@57
  1362
    class ErasableDigraphComponent : public _Base {
deba@57
  1363
    public:
deba@57
  1364
deba@57
  1365
      typedef _Base Base;
deba@57
  1366
      typedef typename Base::Node Node;
deba@57
  1367
      typedef typename Base::Arc Arc;
deba@57
  1368
deba@57
  1369
      /// \brief Erase a node from the digraph.
deba@57
  1370
      ///
deba@57
  1371
      /// Erase a node from the digraph. This function should 
deba@57
  1372
      /// erase all arcs connecting to the node.
deba@57
  1373
      void erase(const Node&) {}    
deba@57
  1374
deba@57
  1375
      /// \brief Erase an arc from the digraph.
deba@57
  1376
      ///
deba@57
  1377
      /// Erase an arc from the digraph.
deba@57
  1378
      ///
deba@57
  1379
      void erase(const Arc&) {}
deba@57
  1380
deba@57
  1381
      template <typename _Digraph>
deba@57
  1382
      struct Constraints {
deba@57
  1383
	void constraints() {
deba@57
  1384
          checkConcept<Base, _Digraph>();
deba@57
  1385
	  typename _Digraph::Node node;
deba@57
  1386
	  digraph.erase(node);
deba@57
  1387
	  typename _Digraph::Arc arc;
deba@57
  1388
	  digraph.erase(arc);
deba@57
  1389
	}
deba@57
  1390
deba@57
  1391
	_Digraph& digraph;
deba@57
  1392
      };
deba@57
  1393
    };
deba@57
  1394
deba@57
  1395
    /// \brief An empty erasable base undirected graph class.
deba@57
  1396
    ///  
deba@57
  1397
    /// This class provides beside the core undirected graph features
deba@57
  1398
    /// core erase functions for the undirceted graph structure. The
deba@57
  1399
    /// main difference between the base and this interface is that
deba@57
  1400
    /// the graph alterations should handled already on this level.
deba@57
  1401
    template <typename _Base = BaseGraphComponent>
deba@57
  1402
    class ErasableGraphComponent : public _Base {
deba@57
  1403
    public:
deba@57
  1404
deba@57
  1405
      typedef _Base Base;
deba@57
  1406
      typedef typename Base::Node Node;
deba@57
  1407
      typedef typename Base::Edge Edge;
deba@57
  1408
deba@57
  1409
      /// \brief Erase a node from the graph.
deba@57
  1410
      ///
deba@57
  1411
      /// Erase a node from the graph. This function should erase
deba@57
  1412
      /// arcs connecting to the node.
deba@57
  1413
      void erase(const Node&) {}    
deba@57
  1414
deba@57
  1415
      /// \brief Erase an arc from the graph.
deba@57
  1416
      ///
deba@57
  1417
      /// Erase an arc from the graph.
deba@57
  1418
      ///
deba@57
  1419
      void erase(const Edge&) {}
deba@57
  1420
deba@57
  1421
      template <typename _Graph>
deba@57
  1422
      struct Constraints {
deba@57
  1423
	void constraints() {
deba@57
  1424
          checkConcept<Base, _Graph>();
deba@57
  1425
	  typename _Graph::Node node;
deba@57
  1426
	  graph.erase(node);
deba@57
  1427
	  typename _Graph::Arc arc;
deba@57
  1428
	  graph.erase(arc);
deba@57
  1429
	}
deba@57
  1430
deba@57
  1431
	_Graph& graph;
deba@57
  1432
      };
deba@57
  1433
    };
deba@57
  1434
deba@57
  1435
    /// \brief An empty clearable base digraph class.
deba@57
  1436
    ///
deba@57
  1437
    /// This class provides beside the core digraph features core clear
deba@57
  1438
    /// functions for the digraph structure. The main difference between
deba@57
  1439
    /// the base and this interface is that the digraph alterations
deba@57
  1440
    /// should handled already on this level.
deba@57
  1441
    template <typename _Base = BaseDigraphComponent>
deba@57
  1442
    class ClearableDigraphComponent : public _Base {
deba@57
  1443
    public:
deba@57
  1444
deba@57
  1445
      typedef _Base Base;
deba@57
  1446
deba@57
  1447
      /// \brief Erase all nodes and arcs from the digraph.
deba@57
  1448
      ///
deba@57
  1449
      /// Erase all nodes and arcs from the digraph.
deba@57
  1450
      ///
deba@57
  1451
      void clear() {}    
deba@57
  1452
deba@57
  1453
      template <typename _Digraph>
deba@57
  1454
      struct Constraints {
deba@57
  1455
	void constraints() {
deba@57
  1456
          checkConcept<Base, _Digraph>();
deba@57
  1457
	  digraph.clear();
deba@57
  1458
	}
deba@57
  1459
deba@57
  1460
	_Digraph digraph;
deba@57
  1461
      };
deba@57
  1462
    };
deba@57
  1463
deba@57
  1464
    /// \brief An empty clearable base undirected graph class.
deba@57
  1465
    ///
deba@57
  1466
    /// This class provides beside the core undirected graph features
deba@57
  1467
    /// core clear functions for the undirected graph structure. The
deba@57
  1468
    /// main difference between the base and this interface is that
deba@57
  1469
    /// the graph alterations should handled already on this level.
deba@57
  1470
    template <typename _Base = BaseGraphComponent>
deba@57
  1471
    class ClearableGraphComponent : public ClearableDigraphComponent<_Base> {
deba@57
  1472
    public:
deba@57
  1473
deba@57
  1474
      typedef _Base Base;
deba@57
  1475
deba@57
  1476
      template <typename _Graph>
deba@57
  1477
      struct Constraints {
deba@57
  1478
	void constraints() {
deba@57
  1479
          checkConcept<ClearableGraphComponent<Base>, _Graph>();
deba@57
  1480
	}
deba@57
  1481
deba@57
  1482
	_Graph graph;
deba@57
  1483
      };
deba@57
  1484
    };
deba@57
  1485
deba@57
  1486
  }
deba@57
  1487
deba@57
  1488
}
deba@57
  1489
deba@57
  1490
#endif