lemon/concept/graph_component.h
author hegyi
Thu, 23 Jun 2005 17:56:24 +0000
changeset 1509 f9113440b667
parent 1435 8e85e6bbefdf
child 1563 0853ed07a677
permissions -rw-r--r--
A bug, explored by Alpar is corrected, but with value-checking, and not with correct values. (There is some problem with map values of new items! Maybe refreshemnt is the responsible thing?)
klao@959
     1
/* -*- C++ -*-
ladanyi@1435
     2
 * lemon/concept/graph_component.h - Part of LEMON, a generic C++ optimization library
klao@959
     3
 *
alpar@1164
     4
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     5
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
klao@959
     6
 *
klao@959
     7
 * Permission to use, modify and distribute this software is granted
klao@959
     8
 * provided that this copyright notice appears in all copies. For
klao@959
     9
 * precise terms see the accompanying LICENSE file.
klao@959
    10
 *
klao@959
    11
 * This software is provided "AS IS" with no warranty of any kind,
klao@959
    12
 * express or implied, and with no claim as to its suitability for any
klao@959
    13
 * purpose.
klao@959
    14
 *
klao@959
    15
 */
klao@959
    16
klao@1030
    17
///\ingroup graph_concepts
klao@959
    18
///\file
klao@959
    19
///\brief The graph components.
klao@959
    20
klao@959
    21
klao@959
    22
#ifndef LEMON_CONCEPT_GRAPH_COMPONENT_H
klao@959
    23
#define LEMON_CONCEPT_GRAPH_COMPONENT_H
klao@959
    24
klao@959
    25
#include <lemon/invalid.h>
klao@959
    26
#include <lemon/concept/maps.h>
klao@959
    27
deba@1307
    28
#include <lemon/bits/alteration_notifier.h>
deba@1134
    29
klao@959
    30
namespace lemon {
klao@959
    31
  namespace concept {
klao@959
    32
klao@1030
    33
    /// \addtogroup graph_concepts
klao@1030
    34
    /// @{
klao@961
    35
klao@961
    36
    /****************   Graph iterator concepts   ****************/
klao@961
    37
klao@1030
    38
    /// Skeleton class for graph Node and Edge types
klao@961
    39
klao@1030
    40
    /// This class describes the interface of Node and Edge (and UndirEdge
klao@1030
    41
    /// in undirected graphs) subtypes of graph types.
klao@1030
    42
    ///
klao@1030
    43
    /// \note This class is a template class so that we can use it to
klao@1030
    44
    /// create graph skeleton classes. The reason for this is than Node
klao@1030
    45
    /// and Edge types should \em not derive from the same base class.
klao@1030
    46
    /// For Node you should instantiate it with character 'n' and for Edge
klao@1030
    47
    /// with 'e'.
klao@961
    48
klao@1030
    49
#ifndef DOXYGEN
klao@1030
    50
    template <char _selector = '0'>
klao@1030
    51
#endif
klao@961
    52
    class GraphItem {
klao@961
    53
    public:
deba@989
    54
      /// Default constructor.
deba@989
    55
      
klao@1030
    56
      /// \warning The default constructor is not required to set
klao@1030
    57
      /// the item to some well-defined value. So you should consider it
klao@1030
    58
      /// as uninitialized.
klao@961
    59
      GraphItem() {}
deba@989
    60
      /// Copy constructor.
deba@989
    61
      
deba@989
    62
      /// Copy constructor.
deba@989
    63
      ///
deba@989
    64
      GraphItem(GraphItem const&) {}
deba@989
    65
      /// Invalid constructor \& conversion.
deba@989
    66
deba@989
    67
      /// This constructor initializes the item to be invalid.
deba@989
    68
      /// \sa Invalid for more details.
klao@961
    69
      GraphItem(Invalid) {}
deba@989
    70
      /// Assign operator for nodes.
klao@961
    71
deba@989
    72
      /// The nodes are assignable. 
deba@989
    73
      ///
klao@961
    74
      GraphItem& operator=(GraphItem const&) { return *this; }
deba@989
    75
      /// Equality operator.
deba@989
    76
      
deba@989
    77
      /// Two iterators are equal if and only if they represents the
deba@989
    78
      /// same node in the graph or both are invalid.
klao@961
    79
      bool operator==(GraphItem) const { return false; }
deba@989
    80
      /// Inequality operator.
deba@989
    81
	
deba@989
    82
      /// \sa operator==(const Node& n)
deba@989
    83
      ///
klao@961
    84
      bool operator!=(GraphItem) const { return false; }
klao@961
    85
klao@1030
    86
      /// Artificial ordering operator.
deba@989
    87
klao@1030
    88
      /// To allow the use of graph descriptors as key type in std::map or
klao@1030
    89
      /// similar associative container we require this.
klao@1030
    90
      ///
klao@1030
    91
      /// \note This operator only have to define some strict ordering of
klao@1030
    92
      /// the items; this order has nothing to do with the iteration
klao@1030
    93
      /// ordering of the items.
klao@1030
    94
      ///
klao@1030
    95
      /// \bug This is a technical requirement. Do we really need this?
klao@1030
    96
      bool operator<(GraphItem) const { return false; }
deba@989
    97
deba@989
    98
      template<typename _GraphItem>
deba@989
    99
      struct Constraints {
deba@989
   100
	void constraints() {
deba@989
   101
	  _GraphItem i1;
deba@989
   102
	  _GraphItem i2 = i1;
deba@989
   103
	  _GraphItem i3 = INVALID;
deba@989
   104
	  
deba@989
   105
	  i1 = i2 = i3;
deba@989
   106
deba@989
   107
	  bool b;
deba@989
   108
	  //	  b = (ia == ib) && (ia != ib) && (ia < ib);
deba@989
   109
	  b = (ia == ib) && (ia != ib);
deba@989
   110
	  b = (ia == INVALID) && (ib != INVALID);
deba@1136
   111
	  //	  b = (ia < ib);
deba@989
   112
	}
deba@989
   113
deba@989
   114
	const _GraphItem &ia;
deba@989
   115
	const _GraphItem &ib;
deba@989
   116
      };
klao@961
   117
    };
klao@961
   118
klao@1030
   119
    /// A type describing the concept of graph node
klao@1030
   120
klao@1030
   121
    /// This is an instantiation of \ref GraphItem which can be used as a
klao@1030
   122
    /// Node subtype in graph skeleton definitions
klao@1030
   123
    typedef GraphItem<'n'> GraphNode;
klao@1030
   124
klao@1030
   125
    /// A type describing the concept of graph edge
klao@1030
   126
klao@1030
   127
    /// This is an instantiation of \ref GraphItem which can be used as a
klao@1030
   128
    /// Edge subtype in graph skeleton definitions
klao@1030
   129
    typedef GraphItem<'e'> GraphEdge;
klao@1030
   130
klao@1030
   131
klao@1030
   132
    /**************** Basic features of graphs ****************/
klao@1030
   133
klao@959
   134
    /// An empty base graph class.
klao@959
   135
  
klao@961
   136
    /// This class provides the minimal set of features needed for a graph
klao@961
   137
    /// structure. All graph concepts have to be conform to this base
klao@961
   138
    /// graph.
klao@961
   139
    ///
klao@961
   140
    /// \bug This is not true. The minimal graph concept is the
klao@961
   141
    /// BaseIterableGraphComponent.
klao@959
   142
klao@959
   143
    class BaseGraphComponent {
klao@959
   144
    public:
klao@959
   145
klao@959
   146
      typedef BaseGraphComponent Graph;
klao@959
   147
      
klao@959
   148
      /// Node class of the graph.
klao@959
   149
klao@959
   150
      /// This class represents the Nodes of the graph. 
klao@959
   151
      ///
deba@989
   152
      typedef GraphItem<'n'> Node;
klao@959
   153
klao@959
   154
      /// Edge class of the graph.
klao@959
   155
klao@959
   156
      /// This class represents the Edges of the graph. 
klao@959
   157
      ///
deba@989
   158
      typedef GraphItem<'e'> Edge;
klao@959
   159
alpar@986
   160
      ///Gives back the target node of an edge.
klao@959
   161
alpar@986
   162
      ///Gives back the target node of an edge.
klao@959
   163
      ///
alpar@986
   164
      Node target(const Edge&) const { return INVALID;}
klao@959
   165
alpar@986
   166
      ///Gives back the source node of an edge.
klao@959
   167
alpar@986
   168
      ///Gives back the source node of an edge.
klao@959
   169
      ///
alpar@986
   170
      Node source(const Edge&) const { return INVALID;}
klao@959
   171
klao@961
   172
deba@989
   173
      template <typename _Graph>
deba@989
   174
      struct Constraints {
deba@989
   175
	typedef typename _Graph::Node Node;
deba@989
   176
	typedef typename _Graph::Edge Edge;
klao@959
   177
      
deba@989
   178
	void constraints() {
deba@989
   179
	  checkConcept<GraphItem<'n'>, Node>();
deba@989
   180
	  checkConcept<GraphItem<'e'>, Edge>();
deba@989
   181
	  {
deba@989
   182
	    Node n;
deba@989
   183
	    Edge e;
deba@989
   184
	    n = graph.source(e);
deba@989
   185
	    n = graph.target(e);
deba@989
   186
	  }      
deba@989
   187
	}
klao@959
   188
      
deba@989
   189
	const _Graph& graph;
deba@989
   190
      };
klao@959
   191
    };
klao@959
   192
klao@959
   193
    /// An empty iterable base graph class.
klao@959
   194
  
klao@959
   195
    /// This class provides beside the core graph features
klao@959
   196
    /// core iterable interface for the graph structure.
klao@959
   197
    /// Most of the base graphs should be conform to this concept.
klao@959
   198
klao@959
   199
    class BaseIterableGraphComponent : virtual public BaseGraphComponent {
klao@959
   200
    public:
klao@959
   201
klao@959
   202
      typedef BaseGraphComponent::Node Node;
klao@959
   203
      typedef BaseGraphComponent::Edge Edge;
klao@959
   204
klao@959
   205
      /// Gives back the first Node in the iterating order.
klao@959
   206
      
klao@959
   207
      /// Gives back the first Node in the iterating order.
klao@959
   208
      ///     
klao@959
   209
      void first(Node&) const {}
klao@959
   210
klao@959
   211
      /// Gives back the next Node in the iterating order.
klao@959
   212
      
klao@959
   213
      /// Gives back the next Node in the iterating order.
klao@959
   214
      ///     
klao@959
   215
      void next(Node&) const {}
klao@959
   216
klao@959
   217
      /// Gives back the first Edge in the iterating order.
klao@959
   218
      
klao@959
   219
      /// Gives back the first Edge in the iterating order.
klao@959
   220
      ///     
klao@959
   221
      void first(Edge&) const {}
klao@959
   222
      /// Gives back the next Edge in the iterating order.
klao@959
   223
      
klao@959
   224
      /// Gives back the next Edge in the iterating order.
klao@959
   225
      ///     
klao@959
   226
      void next(Edge&) const {}
klao@959
   227
klao@959
   228
klao@959
   229
      /// Gives back the first of the Edges point to the given Node.
klao@959
   230
      
klao@959
   231
      /// Gives back the first of the Edges point to the given Node.
klao@959
   232
      ///     
klao@959
   233
      void firstIn(Edge&, const Node&) const {}
klao@959
   234
klao@959
   235
      /// Gives back the next of the Edges points to the given Node.
klao@959
   236
klao@959
   237
klao@959
   238
      /// Gives back the next of the Edges points to the given Node.
klao@959
   239
      ///
klao@959
   240
      void nextIn(Edge&) const {}
klao@959
   241
klao@959
   242
      /// Gives back the first of the Edges start from the given Node.
klao@959
   243
      
klao@959
   244
      /// Gives back the first of the Edges start from the given Node.
klao@959
   245
      ///     
klao@959
   246
      void firstOut(Edge&, const Node&) const {}
klao@959
   247
klao@959
   248
      /// Gives back the next of the Edges start from the given Node.
klao@959
   249
      
klao@959
   250
      /// Gives back the next of the Edges start from the given Node.
klao@959
   251
      ///     
klao@959
   252
      void nextOut(Edge&) const {}
klao@959
   253
klao@959
   254
deba@989
   255
      template <typename _Graph>
deba@989
   256
      struct Constraints {
deba@989
   257
      
deba@989
   258
	void constraints() {
deba@989
   259
	  checkConcept< BaseGraphComponent, _Graph >();
deba@989
   260
	  typename _Graph::Node node;      
deba@989
   261
	  typename _Graph::Edge edge;
deba@989
   262
	  {
deba@989
   263
	    graph.first(node);
deba@989
   264
	    graph.next(node);
deba@989
   265
	  }
deba@989
   266
	  {
deba@989
   267
	    graph.first(edge);
deba@989
   268
	    graph.next(edge);
deba@989
   269
	  }
deba@989
   270
	  {
deba@989
   271
	    graph.firstIn(edge, node);
deba@989
   272
	    graph.nextIn(edge);
deba@989
   273
	  }
deba@989
   274
	  {
deba@989
   275
	    graph.firstOut(edge, node);
deba@989
   276
	    graph.nextOut(edge);
deba@989
   277
	  }
deba@989
   278
	}
klao@959
   279
deba@989
   280
	const _Graph& graph;
deba@989
   281
      };
klao@959
   282
    };
klao@959
   283
klao@959
   284
    /// An empty idable base graph class.
klao@959
   285
  
klao@959
   286
    /// This class provides beside the core graph features
klao@959
   287
    /// core id functions for the graph structure.
klao@959
   288
    /// The most of the base graphs should be conform to this concept.
klao@959
   289
    /// The id's are unique and immutable.
klao@959
   290
    class IDableGraphComponent : virtual public BaseGraphComponent {
klao@959
   291
    public:
klao@959
   292
klao@959
   293
      typedef BaseGraphComponent::Node Node;
klao@959
   294
      typedef BaseGraphComponent::Edge Edge;
klao@959
   295
klao@959
   296
      /// Gives back an unique integer id for the Node. 
klao@959
   297
klao@959
   298
      /// Gives back an unique integer id for the Node. 
klao@959
   299
      ///
klao@959
   300
      int id(const Node&) const { return -1;}
klao@959
   301
deba@1106
   302
      /// \brief Gives back the node by the unique id.
deba@1106
   303
      ///
deba@1106
   304
      /// Gives back the node by the unique id.
deba@1106
   305
      /// If the graph does not contain node with the given id
deba@1106
   306
      /// then the result of the function is undetermined. 
alpar@1367
   307
      Node fromId(int , Node) const { return INVALID;}
klao@959
   308
deba@1106
   309
      /// \brief Gives back an unique integer id for the Edge. 
deba@1106
   310
      ///
klao@959
   311
      /// Gives back an unique integer id for the Edge. 
klao@959
   312
      ///
klao@959
   313
      int id(const Edge&) const { return -1;}
klao@959
   314
deba@1106
   315
      /// \brief Gives back the edge by the unique id.
deba@1106
   316
      ///
deba@1106
   317
      /// Gives back the edge by the unique id.
deba@1106
   318
      /// If the graph does not contain edge with the given id
deba@1106
   319
      /// then the result of the function is undetermined. 
alpar@1367
   320
      Edge fromId(int, Edge) const { return INVALID;}
deba@1106
   321
deba@989
   322
      template <typename _Graph>
deba@989
   323
      struct Constraints {
klao@959
   324
deba@989
   325
	void constraints() {
deba@989
   326
	  checkConcept< BaseGraphComponent, _Graph >();
deba@989
   327
	  typename _Graph::Node node;
deba@989
   328
	  int nid = graph.id(node);
deba@989
   329
	  nid = graph.id(node);
deba@1106
   330
	  node = graph.fromId(nid, Node());
deba@989
   331
	  typename _Graph::Edge edge;
deba@989
   332
	  int eid = graph.id(edge);
deba@989
   333
	  eid = graph.id(edge);
deba@1106
   334
	  edge = graph.fromId(eid, Edge());
deba@989
   335
	}
klao@959
   336
deba@989
   337
	const _Graph& graph;
deba@989
   338
      };
klao@959
   339
    };
klao@959
   340
klao@959
   341
klao@959
   342
    /// An empty max-idable base graph class.
klao@959
   343
  
klao@959
   344
    /// This class provides beside the core graph features
klao@959
   345
    /// core max id functions for the graph structure.
klao@959
   346
    /// The most of the base graphs should be conform to this concept.
klao@959
   347
    /// The id's are unique and immutable.
klao@959
   348
    class MaxIDableGraphComponent : virtual public BaseGraphComponent {
klao@959
   349
    public:
klao@959
   350
klao@959
   351
      /// Gives back an integer greater or equal to the maximum Node id. 
klao@959
   352
klao@959
   353
      /// Gives back an integer greater or equal to the maximum Node id. 
klao@959
   354
      ///
deba@980
   355
      int maxId(Node = INVALID) const { return -1;}
klao@959
   356
klao@959
   357
      /// Gives back an integer greater or equal to the maximum Edge id. 
klao@959
   358
klao@959
   359
      /// Gives back an integer greater or equal to the maximum Edge id. 
klao@959
   360
      ///
deba@980
   361
      int maxId(Edge = INVALID) const { return -1;}
klao@959
   362
deba@989
   363
      template <typename _Graph>
deba@989
   364
      struct Constraints {
klao@959
   365
deba@989
   366
	void constraints() {
deba@989
   367
	  checkConcept<BaseGraphComponent, _Graph>();
deba@989
   368
	  int nid = graph.maxId(typename _Graph::Node());
deba@989
   369
	  ignore_unused_variable_warning(nid);
deba@989
   370
	  int eid = graph.maxId(typename _Graph::Edge());
deba@989
   371
	  ignore_unused_variable_warning(eid);
deba@989
   372
	}
deba@989
   373
      
deba@989
   374
	const _Graph& graph;
deba@989
   375
      };
klao@959
   376
    };
klao@959
   377
klao@959
   378
    /// An empty extendable base graph class.
klao@959
   379
  
klao@959
   380
    /// This class provides beside the core graph features
klao@959
   381
    /// core graph extend interface for the graph structure.
klao@959
   382
    /// The most of the base graphs should be conform to this concept.
klao@959
   383
    class BaseExtendableGraphComponent : virtual public BaseGraphComponent {
klao@959
   384
    public:
klao@959
   385
klao@959
   386
      typedef BaseGraphComponent::Node Node;
klao@959
   387
      typedef BaseGraphComponent::Edge Edge;
klao@959
   388
klao@959
   389
      /// Adds a new Node to the graph.
klao@959
   390
klao@959
   391
      /// Adds a new Node to the graph.
klao@959
   392
      ///
klao@959
   393
      Node addNode() {
klao@959
   394
	return INVALID;
klao@959
   395
      }
klao@959
   396
    
klao@959
   397
      /// Adds a new Edge connects the two Nodes to the graph.
klao@959
   398
klao@959
   399
      /// Adds a new Edge connects the two Nodes to the graph.
klao@959
   400
      ///
alpar@1367
   401
      Edge addEdge(const Node&, const Node&) {
klao@959
   402
	return INVALID;
klao@959
   403
      }
klao@959
   404
deba@989
   405
      template <typename _Graph>
deba@989
   406
      struct Constraints {
deba@989
   407
	void constraints() {
deba@989
   408
	  checkConcept<BaseGraphComponent, _Graph >();
deba@989
   409
	  typename _Graph::Node node_a, node_b;
deba@989
   410
	  node_a = graph.addNode();
alpar@1494
   411
	  node_b = graph.addNode();
deba@989
   412
	  typename _Graph::Edge edge;
deba@989
   413
	  edge = graph.addEdge(node_a, node_b);
deba@989
   414
	}
klao@959
   415
deba@989
   416
	_Graph& graph;
deba@989
   417
      };
klao@959
   418
    };
klao@959
   419
klao@959
   420
    /// An empty erasable base graph class.
klao@959
   421
  
klao@959
   422
    /// This class provides beside the core graph features
klao@959
   423
    /// core erase functions for the graph structure.
klao@959
   424
    /// The most of the base graphs should be conform to this concept.
klao@959
   425
    class BaseErasableGraphComponent : virtual public BaseGraphComponent {
klao@959
   426
    public:
klao@959
   427
klao@959
   428
      typedef BaseGraphComponent::Node Node;
klao@959
   429
      typedef BaseGraphComponent::Edge Edge;
klao@959
   430
klao@959
   431
      /// Erase a Node from the graph.
klao@959
   432
      
klao@959
   433
      /// Erase a Node from the graph. This function should not
klao@959
   434
      /// erase edges connecting to the Node.
klao@959
   435
      void erase(const Node&) {}    
klao@959
   436
klao@959
   437
      /// Erase an Edge from the graph.
klao@959
   438
klao@959
   439
      /// Erase an Edge from the graph.
klao@959
   440
      ///
klao@959
   441
      void erase(const Edge&) {}
klao@959
   442
deba@989
   443
      template <typename _Graph>
deba@989
   444
      struct Constraints {
deba@989
   445
	void constraints() {
deba@989
   446
	  checkConcept<BaseGraphComponent, _Graph>();
deba@989
   447
	  typename _Graph::Node node;
deba@989
   448
	  graph.erase(node);
deba@989
   449
	  typename _Graph::Edge edge;
deba@989
   450
	  graph.erase(edge);
deba@989
   451
	}
klao@959
   452
deba@989
   453
	_Graph& graph;
deba@989
   454
      };
klao@959
   455
    };
klao@959
   456
klao@959
   457
    /// An empty clearable base graph class.
klao@959
   458
  
klao@959
   459
    /// This class provides beside the core graph features
klao@959
   460
    /// core clear functions for the graph structure.
klao@959
   461
    /// The most of the base graphs should be conform to this concept.
klao@1022
   462
    class ClearableGraphComponent : virtual public BaseGraphComponent {
klao@959
   463
    public:
klao@959
   464
klao@959
   465
      /// Erase all the Nodes and Edges from the graph.
klao@959
   466
klao@959
   467
      /// Erase all the Nodes and Edges from the graph.
klao@959
   468
      ///
klao@959
   469
      void clear() {}    
deba@989
   470
deba@989
   471
      template <typename _Graph>
deba@989
   472
      struct Constraints {
deba@989
   473
	void constraints() {
klao@1022
   474
	  checkConcept<BaseGraphComponent, _Graph>();
deba@989
   475
	  graph.clear();
deba@989
   476
	}
deba@989
   477
klao@1022
   478
	_Graph graph;
deba@989
   479
      };
klao@959
   480
    };
klao@959
   481
klao@959
   482
deba@989
   483
    /// Skeleton class for graph NodeIt and EdgeIt
deba@989
   484
deba@989
   485
    /// Skeleton class for graph NodeIt and EdgeIt.
klao@959
   486
    ///
deba@989
   487
    template <typename _Graph, typename _Item>
deba@989
   488
    class GraphIterator : public _Item {
deba@989
   489
    public:
deba@989
   490
      /// \todo Don't we need the Item type as typedef?
klao@959
   491
deba@989
   492
      /// Default constructor.
deba@989
   493
      
deba@989
   494
      /// @warning The default constructor sets the iterator
deba@989
   495
      /// to an undefined value.
deba@989
   496
      GraphIterator() {}
deba@989
   497
      /// Copy constructor.
deba@989
   498
      
deba@989
   499
      /// Copy constructor.
deba@989
   500
      ///
deba@989
   501
      GraphIterator(GraphIterator const&) {}
deba@989
   502
      /// Sets the iterator to the first item.
deba@989
   503
      
deba@989
   504
      /// Sets the iterator to the first item of \c the graph.
deba@989
   505
      ///
deba@989
   506
      explicit GraphIterator(const _Graph&) {}
deba@989
   507
      /// Invalid constructor \& conversion.
deba@989
   508
deba@989
   509
      /// This constructor initializes the item to be invalid.
deba@989
   510
      /// \sa Invalid for more details.
deba@989
   511
      GraphIterator(Invalid) {}
deba@989
   512
      /// Assign operator for items.
deba@989
   513
deba@989
   514
      /// The items are assignable. 
deba@989
   515
      ///
deba@989
   516
      GraphIterator& operator=(GraphIterator const&) { return *this; }      
deba@989
   517
      /// Next item.
deba@989
   518
deba@989
   519
      /// Assign the iterator to the next item.
deba@989
   520
      ///
deba@989
   521
      GraphIterator& operator++() { return *this; }
deba@989
   522
      //	Node operator*() const { return INVALID; }
deba@989
   523
      /// Equality operator
deba@989
   524
deba@989
   525
      /// Two iterators are equal if and only if they point to the
deba@989
   526
      /// same object or both are invalid.
deba@989
   527
      bool operator==(const GraphIterator&) const { return true;}
deba@989
   528
      /// Inequality operator
deba@989
   529
	
deba@989
   530
      /// \sa operator==(Node n)
deba@989
   531
      ///
deba@989
   532
      bool operator!=(const GraphIterator&) const { return true;}
deba@989
   533
      
deba@989
   534
      template<typename _GraphIterator>
deba@989
   535
      struct Constraints {
deba@989
   536
	void constraints() {
deba@989
   537
	  //	  checkConcept< Item, _GraphIterator >();
deba@989
   538
	  _GraphIterator it1(g);
deba@989
   539
	
deba@989
   540
	  /// \todo Do we need NodeIt(Node) kind of constructor?
deba@989
   541
	  //	_GraphIterator it2(bj);
deba@989
   542
	  _GraphIterator it2;
deba@989
   543
deba@989
   544
	  it2 = ++it1;
deba@989
   545
	  ++it2 = it1;
deba@989
   546
	  ++(++it1);
deba@989
   547
	  /// \bug This should be: is_base_and_derived<BaseItem, _GraphIterator>
deba@989
   548
	  _Item bi = it1;
deba@989
   549
	  bi = it2;
deba@989
   550
	}
deba@989
   551
	_Graph& g;
deba@989
   552
      };
klao@959
   553
    };
klao@959
   554
deba@989
   555
    /// Skeleton class for graph InEdgeIt and OutEdgeIt
klao@959
   556
deba@989
   557
    /// \note Because InEdgeIt and OutEdgeIt may not inherit from the same
deba@989
   558
    /// base class, the _selector is a additional template parameter. For 
deba@989
   559
    /// InEdgeIt you should instantiate it with character 'i' and for 
deba@989
   560
    /// OutEdgeIt with 'o'.
klao@1021
   561
    /// \todo Is this a good name for this concept?
klao@1021
   562
    template <typename Graph,
klao@1021
   563
	      typename Edge = typename Graph::Edge,
klao@1021
   564
	      char _selector = '0'>
klao@1021
   565
    class GraphIncIterator : public Edge {
deba@989
   566
    public:
deba@989
   567
      /// Default constructor.
deba@989
   568
      
deba@989
   569
      /// @warning The default constructor sets the iterator
deba@989
   570
      /// to an undefined value.
klao@1021
   571
      GraphIncIterator() {}
deba@989
   572
      /// Copy constructor.
deba@989
   573
      
deba@989
   574
      /// Copy constructor.
deba@989
   575
      ///
alpar@1375
   576
      GraphIncIterator(GraphIncIterator const& gi) :Edge(gi) {}
deba@1134
   577
      /// Sets the iterator to the first edge incoming into or outgoing 
deba@1134
   578
      /// from the node.
deba@989
   579
      
deba@1134
   580
      /// Sets the iterator to the first edge incoming into or outgoing 
deba@1134
   581
      /// from the node.
deba@989
   582
      ///
klao@1021
   583
      explicit GraphIncIterator(const Graph&, const typename Graph::Node&) {}
deba@989
   584
      /// Invalid constructor \& conversion.
deba@989
   585
deba@989
   586
      /// This constructor initializes the item to be invalid.
deba@989
   587
      /// \sa Invalid for more details.
klao@1021
   588
      GraphIncIterator(Invalid) {}
deba@989
   589
      /// Assign operator for nodes.
deba@989
   590
deba@989
   591
      /// The nodes are assignable. 
deba@989
   592
      ///
klao@1021
   593
      GraphIncIterator& operator=(GraphIncIterator const&) { return *this; }      
deba@989
   594
      /// Next edge.
deba@989
   595
deba@989
   596
      /// Assign the iterator to the next node.
deba@989
   597
      ///
klao@1021
   598
      GraphIncIterator& operator++() { return *this; }
klao@1021
   599
deba@989
   600
      //	Node operator*() const { return INVALID; }
klao@1021
   601
deba@989
   602
      /// Equality operator
deba@989
   603
deba@989
   604
      /// Two iterators are equal if and only if they point to the
deba@989
   605
      /// same object or both are invalid.
klao@1021
   606
      bool operator==(const GraphIncIterator&) const { return true;}
klao@1021
   607
deba@989
   608
      /// Inequality operator
deba@989
   609
	
deba@989
   610
      /// \sa operator==(Node n)
deba@989
   611
      ///
klao@1021
   612
      bool operator!=(const GraphIncIterator&) const { return true;}
deba@989
   613
klao@1021
   614
      template <typename _GraphIncIterator>
deba@989
   615
      struct Constraints {
klao@1021
   616
	typedef typename Graph::Node Node;
deba@989
   617
	void constraints() {
klao@1021
   618
	  checkConcept<GraphItem<'e'>, _GraphIncIterator>();
klao@1021
   619
	  _GraphIncIterator it1(graph, node);
deba@989
   620
	  /// \todo Do we need OutEdgeIt(Edge) kind of constructor?
klao@1021
   621
	  //	_GraphIncIterator it2(edge);
klao@1021
   622
	  _GraphIncIterator it2;
deba@989
   623
deba@989
   624
	  it2 = ++it1;
deba@989
   625
	  ++it2 = it1;
deba@989
   626
	  ++(++it1);
deba@989
   627
	  Edge e = it1;
deba@989
   628
	  e = it2;
klao@1158
   629
klao@1158
   630
	  const_constraits();
deba@989
   631
	}
deba@989
   632
klao@1158
   633
	void const_constraits() {
klao@1158
   634
	  Node n = graph.baseNode(it);
klao@1158
   635
	  n = graph.runningNode(it);
klao@1158
   636
	}
klao@1158
   637
klao@1158
   638
	Edge edge;
klao@1158
   639
	Node node;
klao@1158
   640
	Graph graph;
klao@1158
   641
	_GraphIncIterator it;
deba@989
   642
      };
deba@989
   643
    };
klao@1021
   644
klao@1021
   645
deba@989
   646
    /// An empty iterable base graph class.
deba@989
   647
  
deba@989
   648
    /// This class provides beside the core graph features
deba@989
   649
    /// iterator based iterable interface for the graph structure.
deba@989
   650
    /// This concept is part of the StaticGraphConcept.
deba@989
   651
    class IterableGraphComponent : virtual public BaseGraphComponent {
klao@959
   652
klao@959
   653
    public:
klao@959
   654
    
klao@959
   655
      typedef IterableGraphComponent Graph;
klao@959
   656
klao@959
   657
      typedef BaseGraphComponent::Node Node;
klao@959
   658
      typedef BaseGraphComponent::Edge Edge;
klao@959
   659
deba@989
   660
      /// This iterator goes through each node.
klao@959
   661
deba@989
   662
      /// This iterator goes through each node.
deba@989
   663
      ///
deba@989
   664
      typedef GraphIterator<Graph, Node> NodeIt;
deba@989
   665
      /// This iterator goes through each node.
klao@959
   666
deba@989
   667
      /// This iterator goes through each node.
deba@989
   668
      ///
deba@989
   669
      typedef GraphIterator<Graph, Edge> EdgeIt;
deba@989
   670
      /// This iterator goes trough the incoming edges of a node.
klao@959
   671
deba@989
   672
      /// This iterator goes trough the \e inccoming edges of a certain node
deba@989
   673
      /// of a graph.
klao@1021
   674
      typedef GraphIncIterator<Graph, Edge, 'i'> InEdgeIt;
deba@989
   675
      /// This iterator goes trough the outgoing edges of a node.
klao@959
   676
deba@989
   677
      /// This iterator goes trough the \e outgoing edges of a certain node
deba@989
   678
      /// of a graph.
klao@1021
   679
      typedef GraphIncIterator<Graph, Edge, 'o'> OutEdgeIt;
deba@989
   680
    };
deba@989
   681
    
deba@989
   682
    template <typename _Graph> 
deba@989
   683
    struct Constraints {
deba@989
   684
      void constraints() {
deba@989
   685
  	checkConcept< BaseGraphComponent, _Graph>();
klao@959
   686
deba@1134
   687
	checkConcept<GraphIterator<_Graph, typename _Graph::Edge>,
deba@1134
   688
	  typename _Graph::EdgeIt >();
deba@1134
   689
	checkConcept<GraphIterator<_Graph, typename _Graph::Node>,
deba@1134
   690
	  typename _Graph::NodeIt >();
klao@1021
   691
	checkConcept<GraphIncIterator<_Graph>, typename _Graph::InEdgeIt >();
klao@1021
   692
	checkConcept<GraphIncIterator<_Graph>, typename _Graph::OutEdgeIt >();
deba@989
   693
      }
deba@989
   694
    };
klao@959
   695
deba@1134
   696
    /// An empty alteration notifier base graph class.
deba@1134
   697
  
deba@1134
   698
    /// This class provides beside the core graph features
deba@1134
   699
    /// alteration notifier interface for the graph structure.
deba@1134
   700
    /// This is an observer-notifier pattern. More Obsevers can
deba@1134
   701
    /// be registered into the notifier and whenever an alteration
deba@1134
   702
    /// occured in the graph all the observers will notified about it.
deba@1134
   703
    class AlterableGraphComponent : virtual public BaseGraphComponent {
deba@1134
   704
    public:
deba@1134
   705
deba@1134
   706
      /// The edge observer registry.
deba@1134
   707
      typedef AlterationNotifier<Edge> EdgeNotifier;
deba@1134
   708
      /// The node observer registry.
deba@1134
   709
      typedef AlterationNotifier<Node> NodeNotifier;
deba@1134
   710
      
deba@1134
   711
      /// \brief Gives back the edge alteration notifier.
deba@1134
   712
      ///
deba@1134
   713
      /// Gives back the edge alteration notifier.
deba@1134
   714
      EdgeNotifier getNotifier(Edge) const {
deba@1134
   715
	return EdgeNotifier();
deba@1134
   716
      }
deba@1134
   717
      
deba@1134
   718
      /// \brief Gives back the node alteration notifier.
deba@1134
   719
      ///
deba@1134
   720
      /// Gives back the node alteration notifier.
deba@1134
   721
      NodeNotifier getNotifier(Node) const {
deba@1134
   722
	return NodeNotifier();
deba@1134
   723
      }
deba@1134
   724
      
deba@1134
   725
    };
deba@1134
   726
klao@959
   727
klao@1030
   728
    /// Class describing the concept of graph maps
klao@1030
   729
klao@1030
   730
    /// This class describes the common interface of the graph maps
alpar@1043
   731
    /// (NodeMap, EdgeMap), that is \ref maps-pages "maps" which can be used to
klao@1030
   732
    /// associate data to graph descriptors (nodes or edges).
deba@989
   733
    template <typename Graph, typename Item, typename _Value>
deba@989
   734
    class GraphMap : public ReadWriteMap<Item, _Value> {
deba@989
   735
    protected:      
deba@989
   736
      GraphMap() {}
deba@989
   737
    public:
deba@1134
   738
      /// \brief Construct a new map.
deba@1134
   739
      ///
deba@1134
   740
      /// Construct a new map for the graph.
deba@989
   741
      explicit GraphMap(const Graph&) {}
deba@1134
   742
      /// \brief Construct a new map with default value.
deba@1134
   743
      ///
deba@1134
   744
      /// Construct a new map for the graph and initalise the values.
deba@989
   745
      GraphMap(const Graph&, const _Value&) {}
deba@1134
   746
      /// \brief Copy constructor.
deba@1134
   747
      ///
deba@1134
   748
      /// Copy Constructor.
alpar@1367
   749
      GraphMap(const GraphMap& gm) :ReadWriteMap<Item, _Value>(gm) {}
deba@989
   750
      
deba@1134
   751
      /// \brief Assign operator.
deba@1134
   752
      ///
deba@1134
   753
      /// Assign operator.
deba@989
   754
      GraphMap& operator=(const GraphMap&) { return *this;}
klao@959
   755
deba@989
   756
      template<typename _Map>
deba@989
   757
      struct Constraints {
deba@989
   758
	void constraints() {
deba@989
   759
	  checkConcept<ReadWriteMap<Item, _Value>, _Map >();
deba@989
   760
	  // Construction with a graph parameter
deba@989
   761
	  _Map a(g);
deba@989
   762
	  // Constructor with a graph and a default value parameter
deba@989
   763
	  _Map a2(g,t);
deba@989
   764
	  // Copy constructor. Do we need it?
deba@989
   765
	  _Map b=c;
deba@989
   766
	  // Copy operator. Do we need it?
deba@989
   767
	  a=b;
klao@959
   768
deba@989
   769
	  ignore_unused_variable_warning(a2);
deba@989
   770
	}
klao@959
   771
deba@989
   772
	const _Map &c;
deba@989
   773
	const Graph &g;
deba@989
   774
	const typename GraphMap::Value &t;
klao@959
   775
      };
klao@959
   776
klao@959
   777
    };
klao@961
   778
deba@989
   779
    /// An empty mappable base graph class.
klao@959
   780
  
deba@989
   781
    /// This class provides beside the core graph features
deba@989
   782
    /// map interface for the graph structure.
deba@989
   783
    /// This concept is part of the StaticGraphConcept.
klao@959
   784
    class MappableGraphComponent : virtual public BaseGraphComponent {
klao@959
   785
    public:
klao@959
   786
klao@959
   787
      typedef MappableGraphComponent Graph;
klao@959
   788
klao@959
   789
      typedef BaseGraphComponent::Node Node;
klao@959
   790
      typedef BaseGraphComponent::Edge Edge;
klao@959
   791
deba@989
   792
      /// ReadWrite map of the nodes.
deba@989
   793
    
deba@989
   794
      /// ReadWrite map of the nodes.
deba@989
   795
      ///
alpar@987
   796
      template <typename _Value>
deba@989
   797
      class NodeMap : public GraphMap<Graph, Node, _Value> {
deba@989
   798
      private:
deba@989
   799
	NodeMap();
klao@959
   800
      public:
deba@1134
   801
	/// \brief Construct a new map.
deba@1134
   802
	///
deba@1134
   803
	/// Construct a new map for the graph.
deba@1134
   804
	/// \todo call the right parent class constructor
deba@989
   805
	explicit NodeMap(const Graph&) {}
deba@1134
   806
	/// \brief Construct a new map with default value.
deba@1134
   807
	///
deba@1134
   808
	/// Construct a new map for the graph and initalise the values.
alpar@987
   809
	NodeMap(const Graph&, const _Value&) {}
deba@1134
   810
	/// \brief Copy constructor.
deba@1134
   811
	///
deba@1134
   812
	/// Copy Constructor.
alpar@1367
   813
	NodeMap(const NodeMap& nm) : GraphMap<Graph, Node, _Value>(nm) {}
klao@959
   814
deba@1134
   815
	/// \brief Assign operator.
deba@1134
   816
	///
deba@1134
   817
	/// Assign operator.
klao@959
   818
	NodeMap& operator=(const NodeMap&) { return *this;}
deba@989
   819
klao@959
   820
      };
klao@959
   821
deba@989
   822
      /// ReadWrite map of the edges.
deba@989
   823
    
deba@989
   824
      /// ReadWrite map of the edges.
deba@989
   825
      ///
alpar@987
   826
      template <typename _Value>
deba@989
   827
      class EdgeMap : public GraphMap<Graph, Edge, _Value> {
deba@989
   828
      private:
deba@989
   829
	EdgeMap();
klao@959
   830
      public:
deba@1134
   831
	/// \brief Construct a new map.
deba@1134
   832
	///
deba@1134
   833
	/// Construct a new map for the graph.
deba@1134
   834
	/// \todo call the right parent class constructor
deba@989
   835
	explicit EdgeMap(const Graph&) {}
deba@1134
   836
	/// \brief Construct a new map with default value.
deba@1134
   837
	///
deba@1134
   838
	/// Construct a new map for the graph and initalise the values.
alpar@987
   839
	EdgeMap(const Graph&, const _Value&) {}
deba@1134
   840
	/// \brief Copy constructor.
deba@1134
   841
	///
deba@1134
   842
	/// Copy Constructor.
alpar@1367
   843
	EdgeMap(const EdgeMap& em) :GraphMap<Graph, Edge, _Value>(em) {}
klao@959
   844
deba@1134
   845
	/// \brief Assign operator.
deba@1134
   846
	///
deba@1134
   847
	/// Assign operator.
klao@959
   848
	EdgeMap& operator=(const EdgeMap&) { return *this;}
deba@989
   849
klao@959
   850
      };
klao@959
   851
deba@989
   852
      template <typename _Graph>
deba@989
   853
      struct Constraints {
klao@959
   854
deba@989
   855
	struct Type {
deba@989
   856
	  int value;
deba@989
   857
	  Type() : value(0) {}
deba@989
   858
	  Type(int _v) : value(_v) {}
deba@989
   859
	};
klao@959
   860
deba@989
   861
	void constraints() {
deba@989
   862
	  checkConcept<BaseGraphComponent, _Graph>();
deba@989
   863
	  { // int map test
deba@989
   864
	    typedef typename _Graph::template NodeMap<int> IntNodeMap;
deba@1134
   865
	    checkConcept<GraphMap<_Graph, typename _Graph::Node, int>, 
deba@1134
   866
	      IntNodeMap >();
deba@989
   867
	  } { // bool map test
deba@989
   868
	    typedef typename _Graph::template NodeMap<bool> BoolNodeMap;
deba@1134
   869
	    checkConcept<GraphMap<_Graph, typename _Graph::Node, bool>,
deba@1134
   870
	      BoolNodeMap >();
deba@989
   871
	  } { // Type map test
deba@989
   872
	    typedef typename _Graph::template NodeMap<Type> TypeNodeMap;
deba@1134
   873
	    checkConcept<GraphMap<_Graph, typename _Graph::Node, Type>,
deba@1134
   874
	      TypeNodeMap >();
deba@989
   875
	  } 
deba@989
   876
deba@989
   877
	  { // int map test
deba@989
   878
	    typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
deba@1134
   879
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
deba@1134
   880
	      IntEdgeMap >();
deba@989
   881
	  } { // bool map test
deba@989
   882
	    typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
deba@1134
   883
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
deba@1134
   884
	      BoolEdgeMap >();
deba@989
   885
	  } { // Type map test
deba@989
   886
	    typedef typename _Graph::template EdgeMap<Type> TypeEdgeMap;
deba@1134
   887
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, Type>, 
deba@1134
   888
	      TypeEdgeMap >();
deba@989
   889
	  } 
deba@989
   890
	}
deba@989
   891
deba@989
   892
	_Graph& graph;
klao@959
   893
      };
klao@959
   894
    };
klao@959
   895
deba@1134
   896
    /// \brief An empty extendable extended graph class.
deba@1134
   897
    ///
deba@1134
   898
    /// This class provides beside the core graph features
deba@1134
   899
    /// item addition interface for the graph structure.
deba@1134
   900
    /// The difference between this class and the 
deba@1134
   901
    /// \c BaseExtendableGraphComponent is that it should
deba@1134
   902
    /// notify the item alteration observers.
klao@959
   903
    class ExtendableGraphComponent : virtual public BaseGraphComponent {
klao@959
   904
    public:
klao@959
   905
klao@959
   906
      typedef ExtendableGraphComponent Graph;
klao@959
   907
klao@959
   908
      typedef BaseGraphComponent::Node Node;
klao@959
   909
      typedef BaseGraphComponent::Edge Edge;
klao@959
   910
deba@1134
   911
      /// \brief Add a node to the graph.
deba@1134
   912
      ///
deba@1134
   913
      /// Add a node to the graph and notify the observers.
klao@959
   914
      Node addNode() {
klao@959
   915
	return INVALID;
klao@959
   916
      }
klao@959
   917
    
deba@1134
   918
      /// \brief Add an edge to the graph.
deba@1134
   919
      ///
deba@1134
   920
      /// Add an edge to the graph and notify the observers.
alpar@1367
   921
      Edge addEdge(const Node&, const Node&) {
klao@959
   922
	return INVALID;
klao@959
   923
      }
klao@959
   924
deba@989
   925
      template <typename _Graph>
deba@989
   926
      struct Constraints {
deba@989
   927
	void constraints() {
deba@989
   928
	  checkConcept<BaseGraphComponent, _Graph >();
deba@989
   929
	  typename _Graph::Node node_a, node_b;
deba@989
   930
	  node_a = graph.addNode();
alpar@1494
   931
	  node_b = graph.addNode();
deba@989
   932
	  typename _Graph::Edge edge;
deba@989
   933
	  edge = graph.addEdge(node_a, node_b);      
deba@989
   934
	}
deba@989
   935
	_Graph& graph;
deba@989
   936
      };
klao@959
   937
    };
deba@1134
   938
deba@1134
   939
    /// \brief An empty erasable extended graph class.
deba@1134
   940
    ///
deba@1134
   941
    /// This class provides beside the core graph features
deba@1134
   942
    /// item erase interface for the graph structure.
deba@1134
   943
    /// The difference between this class and the 
deba@1134
   944
    /// \c BaseErasableGraphComponent is that it should
deba@1134
   945
    /// notify the item alteration observers.
klao@959
   946
    class ErasableGraphComponent : virtual public BaseGraphComponent {
klao@959
   947
    public:
klao@959
   948
klao@959
   949
      typedef ErasableGraphComponent Graph;
klao@959
   950
klao@959
   951
      typedef BaseGraphComponent::Node Node;
klao@959
   952
      typedef BaseGraphComponent::Edge Edge;
klao@959
   953
deba@1134
   954
      /// \brief Erase the Node and notify the node alteration observers.
deba@1134
   955
      ///
deba@1134
   956
      ///  Erase the Node and notify the node alteration observers.
klao@959
   957
      void erase(const Node&) {}    
deba@1134
   958
deba@1134
   959
      /// \brief Erase the Edge and notify the edge alteration observers.
deba@1134
   960
      ///
deba@1134
   961
      ///  Erase the Edge and notify the edge alteration observers.
klao@959
   962
      void erase(const Edge&) {}
klao@959
   963
deba@989
   964
      template <typename _Graph>
deba@989
   965
      struct Constraints {
deba@989
   966
	void constraints() {
deba@989
   967
	  checkConcept<BaseGraphComponent, _Graph >();
deba@989
   968
	  typename _Graph::Node node;
deba@989
   969
	  graph.erase(node);
deba@989
   970
	  typename _Graph::Edge edge;
deba@989
   971
	  graph.erase(edge);      
deba@989
   972
	}
klao@959
   973
deba@989
   974
	_Graph& graph;
deba@989
   975
      };
klao@959
   976
    };
klao@959
   977
klao@1030
   978
    /// @}
klao@1030
   979
klao@959
   980
  }
klao@959
   981
klao@959
   982
}
klao@959
   983
klao@959
   984
#endif