lemon/concept/graph_component.h
author deba
Mon, 18 Jul 2005 15:07:28 +0000
changeset 1565 96244ea562a3
parent 1494 ae55ba000ebb
child 1620 09feafe81053
permissions -rw-r--r--
Improve findEdge interface
ConEdgeIt is a high level replacement of findEdge
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@1563
   680
deba@1563
   681
      /// \brief The base node of the iterator.
deba@1563
   682
      ///
deba@1563
   683
      /// Gives back the base node of the iterator.
deba@1563
   684
      Node baseNode(const InEdgeIt&) const { return INVALID; }
deba@1563
   685
deba@1563
   686
      /// \brief The running node of the iterator.
deba@1563
   687
      ///
deba@1563
   688
      /// Gives back the running node of the iterator.
deba@1563
   689
      Node runningNode(const InEdgeIt&) const { return INVALID; }
deba@1563
   690
deba@1563
   691
      /// \brief The base node of the iterator.
deba@1563
   692
      ///
deba@1563
   693
      /// Gives back the base node of the iterator.
deba@1563
   694
      Node baseNode(const OutEdgeIt&) const { return INVALID; }
deba@1563
   695
deba@1563
   696
      /// \brief The running node of the iterator.
deba@1563
   697
      ///
deba@1563
   698
      /// Gives back the running node of the iterator.
deba@1563
   699
      Node runningNode(const OutEdgeIt&) const { return INVALID; }
deba@1563
   700
deba@989
   701
    
deba@1563
   702
      template <typename _Graph> 
deba@1563
   703
      struct Constraints {
deba@1563
   704
	void constraints() {
deba@1563
   705
	  checkConcept< BaseGraphComponent, _Graph>();
deba@1563
   706
	  
deba@1563
   707
	  checkConcept<GraphIterator<_Graph, typename _Graph::Edge>,
deba@1563
   708
	    typename _Graph::EdgeIt >();
deba@1563
   709
	  checkConcept<GraphIterator<_Graph, typename _Graph::Node>,
deba@1563
   710
	    typename _Graph::NodeIt >();
deba@1563
   711
	  checkConcept<GraphIncIterator<_Graph>, typename _Graph::InEdgeIt>();
deba@1563
   712
	  checkConcept<GraphIncIterator<_Graph>, typename _Graph::OutEdgeIt>();
deba@1563
   713
	}
deba@1563
   714
      };
deba@989
   715
    };
klao@959
   716
deba@1134
   717
    /// An empty alteration notifier base graph class.
deba@1134
   718
  
deba@1134
   719
    /// This class provides beside the core graph features
deba@1134
   720
    /// alteration notifier interface for the graph structure.
deba@1134
   721
    /// This is an observer-notifier pattern. More Obsevers can
deba@1134
   722
    /// be registered into the notifier and whenever an alteration
deba@1134
   723
    /// occured in the graph all the observers will notified about it.
deba@1134
   724
    class AlterableGraphComponent : virtual public BaseGraphComponent {
deba@1134
   725
    public:
deba@1134
   726
deba@1134
   727
      /// The edge observer registry.
deba@1134
   728
      typedef AlterationNotifier<Edge> EdgeNotifier;
deba@1134
   729
      /// The node observer registry.
deba@1134
   730
      typedef AlterationNotifier<Node> NodeNotifier;
deba@1134
   731
      
deba@1134
   732
      /// \brief Gives back the edge alteration notifier.
deba@1134
   733
      ///
deba@1134
   734
      /// Gives back the edge alteration notifier.
deba@1134
   735
      EdgeNotifier getNotifier(Edge) const {
deba@1134
   736
	return EdgeNotifier();
deba@1134
   737
      }
deba@1134
   738
      
deba@1134
   739
      /// \brief Gives back the node alteration notifier.
deba@1134
   740
      ///
deba@1134
   741
      /// Gives back the node alteration notifier.
deba@1134
   742
      NodeNotifier getNotifier(Node) const {
deba@1134
   743
	return NodeNotifier();
deba@1134
   744
      }
deba@1134
   745
      
deba@1134
   746
    };
deba@1134
   747
klao@959
   748
klao@1030
   749
    /// Class describing the concept of graph maps
klao@1030
   750
klao@1030
   751
    /// This class describes the common interface of the graph maps
alpar@1043
   752
    /// (NodeMap, EdgeMap), that is \ref maps-pages "maps" which can be used to
klao@1030
   753
    /// associate data to graph descriptors (nodes or edges).
deba@989
   754
    template <typename Graph, typename Item, typename _Value>
deba@989
   755
    class GraphMap : public ReadWriteMap<Item, _Value> {
deba@989
   756
    protected:      
deba@989
   757
      GraphMap() {}
deba@989
   758
    public:
deba@1134
   759
      /// \brief Construct a new map.
deba@1134
   760
      ///
deba@1134
   761
      /// Construct a new map for the graph.
deba@989
   762
      explicit GraphMap(const Graph&) {}
deba@1134
   763
      /// \brief Construct a new map with default value.
deba@1134
   764
      ///
deba@1134
   765
      /// Construct a new map for the graph and initalise the values.
deba@989
   766
      GraphMap(const Graph&, const _Value&) {}
deba@1134
   767
      /// \brief Copy constructor.
deba@1134
   768
      ///
deba@1134
   769
      /// Copy Constructor.
alpar@1367
   770
      GraphMap(const GraphMap& gm) :ReadWriteMap<Item, _Value>(gm) {}
deba@989
   771
      
deba@1134
   772
      /// \brief Assign operator.
deba@1134
   773
      ///
deba@1134
   774
      /// Assign operator.
deba@989
   775
      GraphMap& operator=(const GraphMap&) { return *this;}
klao@959
   776
deba@989
   777
      template<typename _Map>
deba@989
   778
      struct Constraints {
deba@989
   779
	void constraints() {
deba@989
   780
	  checkConcept<ReadWriteMap<Item, _Value>, _Map >();
deba@989
   781
	  // Construction with a graph parameter
deba@989
   782
	  _Map a(g);
deba@989
   783
	  // Constructor with a graph and a default value parameter
deba@989
   784
	  _Map a2(g,t);
deba@989
   785
	  // Copy constructor. Do we need it?
deba@989
   786
	  _Map b=c;
deba@989
   787
	  // Copy operator. Do we need it?
deba@989
   788
	  a=b;
klao@959
   789
deba@989
   790
	  ignore_unused_variable_warning(a2);
deba@989
   791
	}
klao@959
   792
deba@989
   793
	const _Map &c;
deba@989
   794
	const Graph &g;
deba@989
   795
	const typename GraphMap::Value &t;
klao@959
   796
      };
klao@959
   797
klao@959
   798
    };
klao@961
   799
deba@989
   800
    /// An empty mappable base graph class.
klao@959
   801
  
deba@989
   802
    /// This class provides beside the core graph features
deba@989
   803
    /// map interface for the graph structure.
deba@989
   804
    /// This concept is part of the StaticGraphConcept.
klao@959
   805
    class MappableGraphComponent : virtual public BaseGraphComponent {
klao@959
   806
    public:
klao@959
   807
klao@959
   808
      typedef MappableGraphComponent Graph;
klao@959
   809
klao@959
   810
      typedef BaseGraphComponent::Node Node;
klao@959
   811
      typedef BaseGraphComponent::Edge Edge;
klao@959
   812
deba@989
   813
      /// ReadWrite map of the nodes.
deba@989
   814
    
deba@989
   815
      /// ReadWrite map of the nodes.
deba@989
   816
      ///
alpar@987
   817
      template <typename _Value>
deba@989
   818
      class NodeMap : public GraphMap<Graph, Node, _Value> {
deba@989
   819
      private:
deba@989
   820
	NodeMap();
klao@959
   821
      public:
deba@1134
   822
	/// \brief Construct a new map.
deba@1134
   823
	///
deba@1134
   824
	/// Construct a new map for the graph.
deba@1134
   825
	/// \todo call the right parent class constructor
deba@989
   826
	explicit NodeMap(const Graph&) {}
deba@1134
   827
	/// \brief Construct a new map with default value.
deba@1134
   828
	///
deba@1134
   829
	/// Construct a new map for the graph and initalise the values.
alpar@987
   830
	NodeMap(const Graph&, const _Value&) {}
deba@1134
   831
	/// \brief Copy constructor.
deba@1134
   832
	///
deba@1134
   833
	/// Copy Constructor.
alpar@1367
   834
	NodeMap(const NodeMap& nm) : GraphMap<Graph, Node, _Value>(nm) {}
klao@959
   835
deba@1134
   836
	/// \brief Assign operator.
deba@1134
   837
	///
deba@1134
   838
	/// Assign operator.
klao@959
   839
	NodeMap& operator=(const NodeMap&) { return *this;}
deba@989
   840
klao@959
   841
      };
klao@959
   842
deba@989
   843
      /// ReadWrite map of the edges.
deba@989
   844
    
deba@989
   845
      /// ReadWrite map of the edges.
deba@989
   846
      ///
alpar@987
   847
      template <typename _Value>
deba@989
   848
      class EdgeMap : public GraphMap<Graph, Edge, _Value> {
deba@989
   849
      private:
deba@989
   850
	EdgeMap();
klao@959
   851
      public:
deba@1134
   852
	/// \brief Construct a new map.
deba@1134
   853
	///
deba@1134
   854
	/// Construct a new map for the graph.
deba@1134
   855
	/// \todo call the right parent class constructor
deba@989
   856
	explicit EdgeMap(const Graph&) {}
deba@1134
   857
	/// \brief Construct a new map with default value.
deba@1134
   858
	///
deba@1134
   859
	/// Construct a new map for the graph and initalise the values.
alpar@987
   860
	EdgeMap(const Graph&, const _Value&) {}
deba@1134
   861
	/// \brief Copy constructor.
deba@1134
   862
	///
deba@1134
   863
	/// Copy Constructor.
alpar@1367
   864
	EdgeMap(const EdgeMap& em) :GraphMap<Graph, Edge, _Value>(em) {}
klao@959
   865
deba@1134
   866
	/// \brief Assign operator.
deba@1134
   867
	///
deba@1134
   868
	/// Assign operator.
klao@959
   869
	EdgeMap& operator=(const EdgeMap&) { return *this;}
deba@989
   870
klao@959
   871
      };
klao@959
   872
deba@989
   873
      template <typename _Graph>
deba@989
   874
      struct Constraints {
klao@959
   875
deba@989
   876
	struct Type {
deba@989
   877
	  int value;
deba@989
   878
	  Type() : value(0) {}
deba@989
   879
	  Type(int _v) : value(_v) {}
deba@989
   880
	};
klao@959
   881
deba@989
   882
	void constraints() {
deba@989
   883
	  checkConcept<BaseGraphComponent, _Graph>();
deba@989
   884
	  { // int map test
deba@989
   885
	    typedef typename _Graph::template NodeMap<int> IntNodeMap;
deba@1134
   886
	    checkConcept<GraphMap<_Graph, typename _Graph::Node, int>, 
deba@1134
   887
	      IntNodeMap >();
deba@989
   888
	  } { // bool map test
deba@989
   889
	    typedef typename _Graph::template NodeMap<bool> BoolNodeMap;
deba@1134
   890
	    checkConcept<GraphMap<_Graph, typename _Graph::Node, bool>,
deba@1134
   891
	      BoolNodeMap >();
deba@989
   892
	  } { // Type map test
deba@989
   893
	    typedef typename _Graph::template NodeMap<Type> TypeNodeMap;
deba@1134
   894
	    checkConcept<GraphMap<_Graph, typename _Graph::Node, Type>,
deba@1134
   895
	      TypeNodeMap >();
deba@989
   896
	  } 
deba@989
   897
deba@989
   898
	  { // int map test
deba@989
   899
	    typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
deba@1134
   900
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
deba@1134
   901
	      IntEdgeMap >();
deba@989
   902
	  } { // bool map test
deba@989
   903
	    typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
deba@1134
   904
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
deba@1134
   905
	      BoolEdgeMap >();
deba@989
   906
	  } { // Type map test
deba@989
   907
	    typedef typename _Graph::template EdgeMap<Type> TypeEdgeMap;
deba@1134
   908
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, Type>, 
deba@1134
   909
	      TypeEdgeMap >();
deba@989
   910
	  } 
deba@989
   911
	}
deba@989
   912
deba@989
   913
	_Graph& graph;
klao@959
   914
      };
klao@959
   915
    };
klao@959
   916
deba@1134
   917
    /// \brief An empty extendable extended graph class.
deba@1134
   918
    ///
deba@1134
   919
    /// This class provides beside the core graph features
deba@1134
   920
    /// item addition interface for the graph structure.
deba@1134
   921
    /// The difference between this class and the 
deba@1134
   922
    /// \c BaseExtendableGraphComponent is that it should
deba@1134
   923
    /// notify the item alteration observers.
klao@959
   924
    class ExtendableGraphComponent : virtual public BaseGraphComponent {
klao@959
   925
    public:
klao@959
   926
klao@959
   927
      typedef ExtendableGraphComponent Graph;
klao@959
   928
klao@959
   929
      typedef BaseGraphComponent::Node Node;
klao@959
   930
      typedef BaseGraphComponent::Edge Edge;
klao@959
   931
deba@1134
   932
      /// \brief Add a node to the graph.
deba@1134
   933
      ///
deba@1134
   934
      /// Add a node to the graph and notify the observers.
klao@959
   935
      Node addNode() {
klao@959
   936
	return INVALID;
klao@959
   937
      }
klao@959
   938
    
deba@1134
   939
      /// \brief Add an edge to the graph.
deba@1134
   940
      ///
deba@1134
   941
      /// Add an edge to the graph and notify the observers.
alpar@1367
   942
      Edge addEdge(const Node&, const Node&) {
klao@959
   943
	return INVALID;
klao@959
   944
      }
klao@959
   945
deba@989
   946
      template <typename _Graph>
deba@989
   947
      struct Constraints {
deba@989
   948
	void constraints() {
deba@989
   949
	  checkConcept<BaseGraphComponent, _Graph >();
deba@989
   950
	  typename _Graph::Node node_a, node_b;
deba@989
   951
	  node_a = graph.addNode();
alpar@1494
   952
	  node_b = graph.addNode();
deba@989
   953
	  typename _Graph::Edge edge;
deba@989
   954
	  edge = graph.addEdge(node_a, node_b);      
deba@989
   955
	}
deba@989
   956
	_Graph& graph;
deba@989
   957
      };
klao@959
   958
    };
deba@1134
   959
deba@1134
   960
    /// \brief An empty erasable extended graph class.
deba@1134
   961
    ///
deba@1134
   962
    /// This class provides beside the core graph features
deba@1134
   963
    /// item erase interface for the graph structure.
deba@1134
   964
    /// The difference between this class and the 
deba@1134
   965
    /// \c BaseErasableGraphComponent is that it should
deba@1134
   966
    /// notify the item alteration observers.
klao@959
   967
    class ErasableGraphComponent : virtual public BaseGraphComponent {
klao@959
   968
    public:
klao@959
   969
klao@959
   970
      typedef ErasableGraphComponent Graph;
klao@959
   971
klao@959
   972
      typedef BaseGraphComponent::Node Node;
klao@959
   973
      typedef BaseGraphComponent::Edge Edge;
klao@959
   974
deba@1134
   975
      /// \brief Erase the Node and notify the node alteration observers.
deba@1134
   976
      ///
deba@1134
   977
      ///  Erase the Node and notify the node alteration observers.
klao@959
   978
      void erase(const Node&) {}    
deba@1134
   979
deba@1134
   980
      /// \brief Erase the Edge and notify the edge alteration observers.
deba@1134
   981
      ///
deba@1134
   982
      ///  Erase the Edge and notify the edge alteration observers.
klao@959
   983
      void erase(const Edge&) {}
klao@959
   984
deba@989
   985
      template <typename _Graph>
deba@989
   986
      struct Constraints {
deba@989
   987
	void constraints() {
deba@989
   988
	  checkConcept<BaseGraphComponent, _Graph >();
deba@989
   989
	  typename _Graph::Node node;
deba@989
   990
	  graph.erase(node);
deba@989
   991
	  typename _Graph::Edge edge;
deba@989
   992
	  graph.erase(edge);      
deba@989
   993
	}
klao@959
   994
deba@989
   995
	_Graph& graph;
deba@989
   996
      };
klao@959
   997
    };
klao@959
   998
klao@1030
   999
    /// @}
klao@1030
  1000
klao@959
  1001
  }
klao@959
  1002
klao@959
  1003
}
klao@959
  1004
klao@959
  1005
#endif