lemon/concept/graph_component.h
author deba
Mon, 12 Sep 2005 11:24:54 +0000
changeset 1681 84e43c7ca1e3
parent 1644 62548b317e65
child 1875 98698b69a902
permissions -rw-r--r--
SubGraphAdaptors with edge checking functionality.

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