src/lemon/concept/graph_component.h
author alpar
Tue, 19 Apr 2005 14:15:01 +0000
changeset 1375 ebdce4f68ac4
parent 1367 a490662291b9
permissions -rw-r--r--
Get rid of all '-Wall -W' warnings.
klao@959
     1
/* -*- C++ -*-
klao@959
     2
 * src/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();
deba@989
   411
	  typename _Graph::Edge edge;
deba@989
   412
	  edge = graph.addEdge(node_a, node_b);
deba@989
   413
	}
klao@959
   414
deba@989
   415
	_Graph& graph;
deba@989
   416
      };
klao@959
   417
    };
klao@959
   418
klao@959
   419
    /// An empty erasable base graph class.
klao@959
   420
  
klao@959
   421
    /// This class provides beside the core graph features
klao@959
   422
    /// core erase functions for the graph structure.
klao@959
   423
    /// The most of the base graphs should be conform to this concept.
klao@959
   424
    class BaseErasableGraphComponent : virtual public BaseGraphComponent {
klao@959
   425
    public:
klao@959
   426
klao@959
   427
      typedef BaseGraphComponent::Node Node;
klao@959
   428
      typedef BaseGraphComponent::Edge Edge;
klao@959
   429
klao@959
   430
      /// Erase a Node from the graph.
klao@959
   431
      
klao@959
   432
      /// Erase a Node from the graph. This function should not
klao@959
   433
      /// erase edges connecting to the Node.
klao@959
   434
      void erase(const Node&) {}    
klao@959
   435
klao@959
   436
      /// Erase an Edge from the graph.
klao@959
   437
klao@959
   438
      /// Erase an Edge from the graph.
klao@959
   439
      ///
klao@959
   440
      void erase(const Edge&) {}
klao@959
   441
deba@989
   442
      template <typename _Graph>
deba@989
   443
      struct Constraints {
deba@989
   444
	void constraints() {
deba@989
   445
	  checkConcept<BaseGraphComponent, _Graph>();
deba@989
   446
	  typename _Graph::Node node;
deba@989
   447
	  graph.erase(node);
deba@989
   448
	  typename _Graph::Edge edge;
deba@989
   449
	  graph.erase(edge);
deba@989
   450
	}
klao@959
   451
deba@989
   452
	_Graph& graph;
deba@989
   453
      };
klao@959
   454
    };
klao@959
   455
klao@959
   456
    /// An empty clearable base graph class.
klao@959
   457
  
klao@959
   458
    /// This class provides beside the core graph features
klao@959
   459
    /// core clear functions for the graph structure.
klao@959
   460
    /// The most of the base graphs should be conform to this concept.
klao@1022
   461
    class ClearableGraphComponent : virtual public BaseGraphComponent {
klao@959
   462
    public:
klao@959
   463
klao@959
   464
      /// Erase all the Nodes and Edges from the graph.
klao@959
   465
klao@959
   466
      /// Erase all the Nodes and Edges from the graph.
klao@959
   467
      ///
klao@959
   468
      void clear() {}    
deba@989
   469
deba@989
   470
      template <typename _Graph>
deba@989
   471
      struct Constraints {
deba@989
   472
	void constraints() {
klao@1022
   473
	  checkConcept<BaseGraphComponent, _Graph>();
deba@989
   474
	  graph.clear();
deba@989
   475
	}
deba@989
   476
klao@1022
   477
	_Graph graph;
deba@989
   478
      };
klao@959
   479
    };
klao@959
   480
klao@959
   481
deba@989
   482
    /// Skeleton class for graph NodeIt and EdgeIt
deba@989
   483
deba@989
   484
    /// Skeleton class for graph NodeIt and EdgeIt.
klao@959
   485
    ///
deba@989
   486
    template <typename _Graph, typename _Item>
deba@989
   487
    class GraphIterator : public _Item {
deba@989
   488
    public:
deba@989
   489
      /// \todo Don't we need the Item type as typedef?
klao@959
   490
deba@989
   491
      /// Default constructor.
deba@989
   492
      
deba@989
   493
      /// @warning The default constructor sets the iterator
deba@989
   494
      /// to an undefined value.
deba@989
   495
      GraphIterator() {}
deba@989
   496
      /// Copy constructor.
deba@989
   497
      
deba@989
   498
      /// Copy constructor.
deba@989
   499
      ///
deba@989
   500
      GraphIterator(GraphIterator const&) {}
deba@989
   501
      /// Sets the iterator to the first item.
deba@989
   502
      
deba@989
   503
      /// Sets the iterator to the first item of \c the graph.
deba@989
   504
      ///
deba@989
   505
      explicit GraphIterator(const _Graph&) {}
deba@989
   506
      /// Invalid constructor \& conversion.
deba@989
   507
deba@989
   508
      /// This constructor initializes the item to be invalid.
deba@989
   509
      /// \sa Invalid for more details.
deba@989
   510
      GraphIterator(Invalid) {}
deba@989
   511
      /// Assign operator for items.
deba@989
   512
deba@989
   513
      /// The items are assignable. 
deba@989
   514
      ///
deba@989
   515
      GraphIterator& operator=(GraphIterator const&) { return *this; }      
deba@989
   516
      /// Next item.
deba@989
   517
deba@989
   518
      /// Assign the iterator to the next item.
deba@989
   519
      ///
deba@989
   520
      GraphIterator& operator++() { return *this; }
deba@989
   521
      //	Node operator*() const { return INVALID; }
deba@989
   522
      /// Equality operator
deba@989
   523
deba@989
   524
      /// Two iterators are equal if and only if they point to the
deba@989
   525
      /// same object or both are invalid.
deba@989
   526
      bool operator==(const GraphIterator&) const { return true;}
deba@989
   527
      /// Inequality operator
deba@989
   528
	
deba@989
   529
      /// \sa operator==(Node n)
deba@989
   530
      ///
deba@989
   531
      bool operator!=(const GraphIterator&) const { return true;}
deba@989
   532
      
deba@989
   533
      template<typename _GraphIterator>
deba@989
   534
      struct Constraints {
deba@989
   535
	void constraints() {
deba@989
   536
	  //	  checkConcept< Item, _GraphIterator >();
deba@989
   537
	  _GraphIterator it1(g);
deba@989
   538
	
deba@989
   539
	  /// \todo Do we need NodeIt(Node) kind of constructor?
deba@989
   540
	  //	_GraphIterator it2(bj);
deba@989
   541
	  _GraphIterator it2;
deba@989
   542
deba@989
   543
	  it2 = ++it1;
deba@989
   544
	  ++it2 = it1;
deba@989
   545
	  ++(++it1);
deba@989
   546
	  /// \bug This should be: is_base_and_derived<BaseItem, _GraphIterator>
deba@989
   547
	  _Item bi = it1;
deba@989
   548
	  bi = it2;
deba@989
   549
	}
deba@989
   550
	_Graph& g;
deba@989
   551
      };
klao@959
   552
    };
klao@959
   553
deba@989
   554
    /// Skeleton class for graph InEdgeIt and OutEdgeIt
klao@959
   555
deba@989
   556
    /// \note Because InEdgeIt and OutEdgeIt may not inherit from the same
deba@989
   557
    /// base class, the _selector is a additional template parameter. For 
deba@989
   558
    /// InEdgeIt you should instantiate it with character 'i' and for 
deba@989
   559
    /// OutEdgeIt with 'o'.
klao@1021
   560
    /// \todo Is this a good name for this concept?
klao@1021
   561
    template <typename Graph,
klao@1021
   562
	      typename Edge = typename Graph::Edge,
klao@1021
   563
	      char _selector = '0'>
klao@1021
   564
    class GraphIncIterator : public Edge {
deba@989
   565
    public:
deba@989
   566
      /// Default constructor.
deba@989
   567
      
deba@989
   568
      /// @warning The default constructor sets the iterator
deba@989
   569
      /// to an undefined value.
klao@1021
   570
      GraphIncIterator() {}
deba@989
   571
      /// Copy constructor.
deba@989
   572
      
deba@989
   573
      /// Copy constructor.
deba@989
   574
      ///
alpar@1375
   575
      GraphIncIterator(GraphIncIterator const& gi) :Edge(gi) {}
deba@1134
   576
      /// Sets the iterator to the first edge incoming into or outgoing 
deba@1134
   577
      /// from the node.
deba@989
   578
      
deba@1134
   579
      /// Sets the iterator to the first edge incoming into or outgoing 
deba@1134
   580
      /// from the node.
deba@989
   581
      ///
klao@1021
   582
      explicit GraphIncIterator(const Graph&, const typename Graph::Node&) {}
deba@989
   583
      /// Invalid constructor \& conversion.
deba@989
   584
deba@989
   585
      /// This constructor initializes the item to be invalid.
deba@989
   586
      /// \sa Invalid for more details.
klao@1021
   587
      GraphIncIterator(Invalid) {}
deba@989
   588
      /// Assign operator for nodes.
deba@989
   589
deba@989
   590
      /// The nodes are assignable. 
deba@989
   591
      ///
klao@1021
   592
      GraphIncIterator& operator=(GraphIncIterator const&) { return *this; }      
deba@989
   593
      /// Next edge.
deba@989
   594
deba@989
   595
      /// Assign the iterator to the next node.
deba@989
   596
      ///
klao@1021
   597
      GraphIncIterator& operator++() { return *this; }
klao@1021
   598
deba@989
   599
      //	Node operator*() const { return INVALID; }
klao@1021
   600
deba@989
   601
      /// Equality operator
deba@989
   602
deba@989
   603
      /// Two iterators are equal if and only if they point to the
deba@989
   604
      /// same object or both are invalid.
klao@1021
   605
      bool operator==(const GraphIncIterator&) const { return true;}
klao@1021
   606
deba@989
   607
      /// Inequality operator
deba@989
   608
	
deba@989
   609
      /// \sa operator==(Node n)
deba@989
   610
      ///
klao@1021
   611
      bool operator!=(const GraphIncIterator&) const { return true;}
deba@989
   612
klao@1021
   613
      template <typename _GraphIncIterator>
deba@989
   614
      struct Constraints {
klao@1021
   615
	typedef typename Graph::Node Node;
deba@989
   616
	void constraints() {
klao@1021
   617
	  checkConcept<GraphItem<'e'>, _GraphIncIterator>();
klao@1021
   618
	  _GraphIncIterator it1(graph, node);
deba@989
   619
	  /// \todo Do we need OutEdgeIt(Edge) kind of constructor?
klao@1021
   620
	  //	_GraphIncIterator it2(edge);
klao@1021
   621
	  _GraphIncIterator it2;
deba@989
   622
deba@989
   623
	  it2 = ++it1;
deba@989
   624
	  ++it2 = it1;
deba@989
   625
	  ++(++it1);
deba@989
   626
	  Edge e = it1;
deba@989
   627
	  e = it2;
klao@1158
   628
klao@1158
   629
	  const_constraits();
deba@989
   630
	}
deba@989
   631
klao@1158
   632
	void const_constraits() {
klao@1158
   633
	  Node n = graph.baseNode(it);
klao@1158
   634
	  n = graph.runningNode(it);
klao@1158
   635
	}
klao@1158
   636
klao@1158
   637
	Edge edge;
klao@1158
   638
	Node node;
klao@1158
   639
	Graph graph;
klao@1158
   640
	_GraphIncIterator it;
deba@989
   641
      };
deba@989
   642
    };
klao@1021
   643
klao@1021
   644
deba@989
   645
    /// An empty iterable base graph class.
deba@989
   646
  
deba@989
   647
    /// This class provides beside the core graph features
deba@989
   648
    /// iterator based iterable interface for the graph structure.
deba@989
   649
    /// This concept is part of the StaticGraphConcept.
deba@989
   650
    class IterableGraphComponent : virtual public BaseGraphComponent {
klao@959
   651
klao@959
   652
    public:
klao@959
   653
    
klao@959
   654
      typedef IterableGraphComponent Graph;
klao@959
   655
klao@959
   656
      typedef BaseGraphComponent::Node Node;
klao@959
   657
      typedef BaseGraphComponent::Edge Edge;
klao@959
   658
deba@989
   659
      /// This iterator goes through each node.
klao@959
   660
deba@989
   661
      /// This iterator goes through each node.
deba@989
   662
      ///
deba@989
   663
      typedef GraphIterator<Graph, Node> NodeIt;
deba@989
   664
      /// This iterator goes through each node.
klao@959
   665
deba@989
   666
      /// This iterator goes through each node.
deba@989
   667
      ///
deba@989
   668
      typedef GraphIterator<Graph, Edge> EdgeIt;
deba@989
   669
      /// This iterator goes trough the incoming edges of a node.
klao@959
   670
deba@989
   671
      /// This iterator goes trough the \e inccoming edges of a certain node
deba@989
   672
      /// of a graph.
klao@1021
   673
      typedef GraphIncIterator<Graph, Edge, 'i'> InEdgeIt;
deba@989
   674
      /// This iterator goes trough the outgoing edges of a node.
klao@959
   675
deba@989
   676
      /// This iterator goes trough the \e outgoing edges of a certain node
deba@989
   677
      /// of a graph.
klao@1021
   678
      typedef GraphIncIterator<Graph, Edge, 'o'> OutEdgeIt;
deba@989
   679
    };
deba@989
   680
    
deba@989
   681
    template <typename _Graph> 
deba@989
   682
    struct Constraints {
deba@989
   683
      void constraints() {
deba@989
   684
  	checkConcept< BaseGraphComponent, _Graph>();
klao@959
   685
deba@1134
   686
	checkConcept<GraphIterator<_Graph, typename _Graph::Edge>,
deba@1134
   687
	  typename _Graph::EdgeIt >();
deba@1134
   688
	checkConcept<GraphIterator<_Graph, typename _Graph::Node>,
deba@1134
   689
	  typename _Graph::NodeIt >();
klao@1021
   690
	checkConcept<GraphIncIterator<_Graph>, typename _Graph::InEdgeIt >();
klao@1021
   691
	checkConcept<GraphIncIterator<_Graph>, typename _Graph::OutEdgeIt >();
deba@989
   692
      }
deba@989
   693
    };
klao@959
   694
deba@1134
   695
    /// An empty alteration notifier base graph class.
deba@1134
   696
  
deba@1134
   697
    /// This class provides beside the core graph features
deba@1134
   698
    /// alteration notifier interface for the graph structure.
deba@1134
   699
    /// This is an observer-notifier pattern. More Obsevers can
deba@1134
   700
    /// be registered into the notifier and whenever an alteration
deba@1134
   701
    /// occured in the graph all the observers will notified about it.
deba@1134
   702
    class AlterableGraphComponent : virtual public BaseGraphComponent {
deba@1134
   703
    public:
deba@1134
   704
deba@1134
   705
      /// The edge observer registry.
deba@1134
   706
      typedef AlterationNotifier<Edge> EdgeNotifier;
deba@1134
   707
      /// The node observer registry.
deba@1134
   708
      typedef AlterationNotifier<Node> NodeNotifier;
deba@1134
   709
      
deba@1134
   710
      /// \brief Gives back the edge alteration notifier.
deba@1134
   711
      ///
deba@1134
   712
      /// Gives back the edge alteration notifier.
deba@1134
   713
      EdgeNotifier getNotifier(Edge) const {
deba@1134
   714
	return EdgeNotifier();
deba@1134
   715
      }
deba@1134
   716
      
deba@1134
   717
      /// \brief Gives back the node alteration notifier.
deba@1134
   718
      ///
deba@1134
   719
      /// Gives back the node alteration notifier.
deba@1134
   720
      NodeNotifier getNotifier(Node) const {
deba@1134
   721
	return NodeNotifier();
deba@1134
   722
      }
deba@1134
   723
      
deba@1134
   724
    };
deba@1134
   725
klao@959
   726
klao@1030
   727
    /// Class describing the concept of graph maps
klao@1030
   728
klao@1030
   729
    /// This class describes the common interface of the graph maps
alpar@1043
   730
    /// (NodeMap, EdgeMap), that is \ref maps-pages "maps" which can be used to
klao@1030
   731
    /// associate data to graph descriptors (nodes or edges).
deba@989
   732
    template <typename Graph, typename Item, typename _Value>
deba@989
   733
    class GraphMap : public ReadWriteMap<Item, _Value> {
deba@989
   734
    protected:      
deba@989
   735
      GraphMap() {}
deba@989
   736
    public:
deba@1134
   737
      /// \brief Construct a new map.
deba@1134
   738
      ///
deba@1134
   739
      /// Construct a new map for the graph.
deba@989
   740
      explicit GraphMap(const Graph&) {}
deba@1134
   741
      /// \brief Construct a new map with default value.
deba@1134
   742
      ///
deba@1134
   743
      /// Construct a new map for the graph and initalise the values.
deba@989
   744
      GraphMap(const Graph&, const _Value&) {}
deba@1134
   745
      /// \brief Copy constructor.
deba@1134
   746
      ///
deba@1134
   747
      /// Copy Constructor.
alpar@1367
   748
      GraphMap(const GraphMap& gm) :ReadWriteMap<Item, _Value>(gm) {}
deba@989
   749
      
deba@1134
   750
      /// \brief Assign operator.
deba@1134
   751
      ///
deba@1134
   752
      /// Assign operator.
deba@989
   753
      GraphMap& operator=(const GraphMap&) { return *this;}
klao@959
   754
deba@989
   755
      template<typename _Map>
deba@989
   756
      struct Constraints {
deba@989
   757
	void constraints() {
deba@989
   758
	  checkConcept<ReadWriteMap<Item, _Value>, _Map >();
deba@989
   759
	  // Construction with a graph parameter
deba@989
   760
	  _Map a(g);
deba@989
   761
	  // Constructor with a graph and a default value parameter
deba@989
   762
	  _Map a2(g,t);
deba@989
   763
	  // Copy constructor. Do we need it?
deba@989
   764
	  _Map b=c;
deba@989
   765
	  // Copy operator. Do we need it?
deba@989
   766
	  a=b;
klao@959
   767
deba@989
   768
	  ignore_unused_variable_warning(a2);
deba@989
   769
	}
klao@959
   770
deba@989
   771
	const _Map &c;
deba@989
   772
	const Graph &g;
deba@989
   773
	const typename GraphMap::Value &t;
klao@959
   774
      };
klao@959
   775
klao@959
   776
    };
klao@961
   777
deba@989
   778
    /// An empty mappable base graph class.
klao@959
   779
  
deba@989
   780
    /// This class provides beside the core graph features
deba@989
   781
    /// map interface for the graph structure.
deba@989
   782
    /// This concept is part of the StaticGraphConcept.
klao@959
   783
    class MappableGraphComponent : virtual public BaseGraphComponent {
klao@959
   784
    public:
klao@959
   785
klao@959
   786
      typedef MappableGraphComponent Graph;
klao@959
   787
klao@959
   788
      typedef BaseGraphComponent::Node Node;
klao@959
   789
      typedef BaseGraphComponent::Edge Edge;
klao@959
   790
deba@989
   791
      /// ReadWrite map of the nodes.
deba@989
   792
    
deba@989
   793
      /// ReadWrite map of the nodes.
deba@989
   794
      ///
alpar@987
   795
      template <typename _Value>
deba@989
   796
      class NodeMap : public GraphMap<Graph, Node, _Value> {
deba@989
   797
      private:
deba@989
   798
	NodeMap();
klao@959
   799
      public:
deba@1134
   800
	/// \brief Construct a new map.
deba@1134
   801
	///
deba@1134
   802
	/// Construct a new map for the graph.
deba@1134
   803
	/// \todo call the right parent class constructor
deba@989
   804
	explicit NodeMap(const Graph&) {}
deba@1134
   805
	/// \brief Construct a new map with default value.
deba@1134
   806
	///
deba@1134
   807
	/// Construct a new map for the graph and initalise the values.
alpar@987
   808
	NodeMap(const Graph&, const _Value&) {}
deba@1134
   809
	/// \brief Copy constructor.
deba@1134
   810
	///
deba@1134
   811
	/// Copy Constructor.
alpar@1367
   812
	NodeMap(const NodeMap& nm) : GraphMap<Graph, Node, _Value>(nm) {}
klao@959
   813
deba@1134
   814
	/// \brief Assign operator.
deba@1134
   815
	///
deba@1134
   816
	/// Assign operator.
klao@959
   817
	NodeMap& operator=(const NodeMap&) { return *this;}
deba@989
   818
klao@959
   819
      };
klao@959
   820
deba@989
   821
      /// ReadWrite map of the edges.
deba@989
   822
    
deba@989
   823
      /// ReadWrite map of the edges.
deba@989
   824
      ///
alpar@987
   825
      template <typename _Value>
deba@989
   826
      class EdgeMap : public GraphMap<Graph, Edge, _Value> {
deba@989
   827
      private:
deba@989
   828
	EdgeMap();
klao@959
   829
      public:
deba@1134
   830
	/// \brief Construct a new map.
deba@1134
   831
	///
deba@1134
   832
	/// Construct a new map for the graph.
deba@1134
   833
	/// \todo call the right parent class constructor
deba@989
   834
	explicit EdgeMap(const Graph&) {}
deba@1134
   835
	/// \brief Construct a new map with default value.
deba@1134
   836
	///
deba@1134
   837
	/// Construct a new map for the graph and initalise the values.
alpar@987
   838
	EdgeMap(const Graph&, const _Value&) {}
deba@1134
   839
	/// \brief Copy constructor.
deba@1134
   840
	///
deba@1134
   841
	/// Copy Constructor.
alpar@1367
   842
	EdgeMap(const EdgeMap& em) :GraphMap<Graph, Edge, _Value>(em) {}
klao@959
   843
deba@1134
   844
	/// \brief Assign operator.
deba@1134
   845
	///
deba@1134
   846
	/// Assign operator.
klao@959
   847
	EdgeMap& operator=(const EdgeMap&) { return *this;}
deba@989
   848
klao@959
   849
      };
klao@959
   850
deba@989
   851
      template <typename _Graph>
deba@989
   852
      struct Constraints {
klao@959
   853
deba@989
   854
	struct Type {
deba@989
   855
	  int value;
deba@989
   856
	  Type() : value(0) {}
deba@989
   857
	  Type(int _v) : value(_v) {}
deba@989
   858
	};
klao@959
   859
deba@989
   860
	void constraints() {
deba@989
   861
	  checkConcept<BaseGraphComponent, _Graph>();
deba@989
   862
	  { // int map test
deba@989
   863
	    typedef typename _Graph::template NodeMap<int> IntNodeMap;
deba@1134
   864
	    checkConcept<GraphMap<_Graph, typename _Graph::Node, int>, 
deba@1134
   865
	      IntNodeMap >();
deba@989
   866
	  } { // bool map test
deba@989
   867
	    typedef typename _Graph::template NodeMap<bool> BoolNodeMap;
deba@1134
   868
	    checkConcept<GraphMap<_Graph, typename _Graph::Node, bool>,
deba@1134
   869
	      BoolNodeMap >();
deba@989
   870
	  } { // Type map test
deba@989
   871
	    typedef typename _Graph::template NodeMap<Type> TypeNodeMap;
deba@1134
   872
	    checkConcept<GraphMap<_Graph, typename _Graph::Node, Type>,
deba@1134
   873
	      TypeNodeMap >();
deba@989
   874
	  } 
deba@989
   875
deba@989
   876
	  { // int map test
deba@989
   877
	    typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
deba@1134
   878
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
deba@1134
   879
	      IntEdgeMap >();
deba@989
   880
	  } { // bool map test
deba@989
   881
	    typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
deba@1134
   882
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
deba@1134
   883
	      BoolEdgeMap >();
deba@989
   884
	  } { // Type map test
deba@989
   885
	    typedef typename _Graph::template EdgeMap<Type> TypeEdgeMap;
deba@1134
   886
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, Type>, 
deba@1134
   887
	      TypeEdgeMap >();
deba@989
   888
	  } 
deba@989
   889
	}
deba@989
   890
deba@989
   891
	_Graph& graph;
klao@959
   892
      };
klao@959
   893
    };
klao@959
   894
deba@1134
   895
    /// \brief An empty extendable extended graph class.
deba@1134
   896
    ///
deba@1134
   897
    /// This class provides beside the core graph features
deba@1134
   898
    /// item addition interface for the graph structure.
deba@1134
   899
    /// The difference between this class and the 
deba@1134
   900
    /// \c BaseExtendableGraphComponent is that it should
deba@1134
   901
    /// notify the item alteration observers.
klao@959
   902
    class ExtendableGraphComponent : virtual public BaseGraphComponent {
klao@959
   903
    public:
klao@959
   904
klao@959
   905
      typedef ExtendableGraphComponent Graph;
klao@959
   906
klao@959
   907
      typedef BaseGraphComponent::Node Node;
klao@959
   908
      typedef BaseGraphComponent::Edge Edge;
klao@959
   909
deba@1134
   910
      /// \brief Add a node to the graph.
deba@1134
   911
      ///
deba@1134
   912
      /// Add a node to the graph and notify the observers.
klao@959
   913
      Node addNode() {
klao@959
   914
	return INVALID;
klao@959
   915
      }
klao@959
   916
    
deba@1134
   917
      /// \brief Add an edge to the graph.
deba@1134
   918
      ///
deba@1134
   919
      /// Add an edge to the graph and notify the observers.
alpar@1367
   920
      Edge addEdge(const Node&, const Node&) {
klao@959
   921
	return INVALID;
klao@959
   922
      }
klao@959
   923
deba@989
   924
      template <typename _Graph>
deba@989
   925
      struct Constraints {
deba@989
   926
	void constraints() {
deba@989
   927
	  checkConcept<BaseGraphComponent, _Graph >();
deba@989
   928
	  typename _Graph::Node node_a, node_b;
deba@989
   929
	  node_a = graph.addNode();
deba@989
   930
	  typename _Graph::Edge edge;
deba@989
   931
	  edge = graph.addEdge(node_a, node_b);      
deba@989
   932
	}
deba@989
   933
	_Graph& graph;
deba@989
   934
      };
klao@959
   935
    };
deba@1134
   936
deba@1134
   937
    /// \brief An empty erasable extended graph class.
deba@1134
   938
    ///
deba@1134
   939
    /// This class provides beside the core graph features
deba@1134
   940
    /// item erase interface for the graph structure.
deba@1134
   941
    /// The difference between this class and the 
deba@1134
   942
    /// \c BaseErasableGraphComponent is that it should
deba@1134
   943
    /// notify the item alteration observers.
klao@959
   944
    class ErasableGraphComponent : virtual public BaseGraphComponent {
klao@959
   945
    public:
klao@959
   946
klao@959
   947
      typedef ErasableGraphComponent Graph;
klao@959
   948
klao@959
   949
      typedef BaseGraphComponent::Node Node;
klao@959
   950
      typedef BaseGraphComponent::Edge Edge;
klao@959
   951
deba@1134
   952
      /// \brief Erase the Node and notify the node alteration observers.
deba@1134
   953
      ///
deba@1134
   954
      ///  Erase the Node and notify the node alteration observers.
klao@959
   955
      void erase(const Node&) {}    
deba@1134
   956
deba@1134
   957
      /// \brief Erase the Edge and notify the edge alteration observers.
deba@1134
   958
      ///
deba@1134
   959
      ///  Erase the Edge and notify the edge alteration observers.
klao@959
   960
      void erase(const Edge&) {}
klao@959
   961
deba@989
   962
      template <typename _Graph>
deba@989
   963
      struct Constraints {
deba@989
   964
	void constraints() {
deba@989
   965
	  checkConcept<BaseGraphComponent, _Graph >();
deba@989
   966
	  typename _Graph::Node node;
deba@989
   967
	  graph.erase(node);
deba@989
   968
	  typename _Graph::Edge edge;
deba@989
   969
	  graph.erase(edge);      
deba@989
   970
	}
klao@959
   971
deba@989
   972
	_Graph& graph;
deba@989
   973
      };
klao@959
   974
    };
klao@959
   975
klao@1030
   976
    /// @}
klao@1030
   977
klao@959
   978
  }
klao@959
   979
klao@959
   980
}
klao@959
   981
klao@959
   982
#endif