src/lemon/concept/graph_component.h
author klao
Thu, 04 Nov 2004 22:04:51 +0000
changeset 961 289d80c33f04
parent 959 c80ef5912903
child 962 1a770e9f80b2
permissions -rw-r--r--
* Somewhat less redundant and a bit more correct graph concepts.
* graph_wrapper_test does not compile
klao@959
     1
/* -*- C++ -*-
klao@959
     2
 * src/lemon/concept/graph_component.h - Part of LEMON, a generic C++ optimization library
klao@959
     3
 *
klao@959
     4
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
klao@959
     5
 * (Egervary Combinatorial Optimization Research Group, 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@959
    17
///\ingroup concept
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
klao@959
    28
namespace lemon {
klao@959
    29
  namespace concept {
klao@959
    30
klao@961
    31
klao@961
    32
    /****************   Graph iterator concepts   ****************/
klao@961
    33
klao@961
    34
    /// Skeleton class for graph Node and Edge
klao@961
    35
klao@961
    36
    /// \note Because Node and Edge are forbidden to inherit from the same
klao@961
    37
    /// base class, this is a template. For Node you shoul instantiate it
klao@961
    38
    /// with character 'n' and for Edge with 'e'.
klao@961
    39
klao@961
    40
    template<char Ch>
klao@961
    41
    class GraphItem {
klao@961
    42
    public:
klao@961
    43
      GraphItem() {}
klao@961
    44
      GraphItem(Invalid) {}
klao@961
    45
klao@961
    46
      // We explicitely list these:
klao@961
    47
      GraphItem(GraphItem const&) {}
klao@961
    48
      GraphItem& operator=(GraphItem const&) { return *this; }
klao@961
    49
klao@961
    50
      bool operator==(GraphItem) const { return false; }
klao@961
    51
      bool operator!=(GraphItem) const { return false; }
klao@961
    52
klao@961
    53
      // Technical requirement. Do we really need this?
klao@961
    54
      bool operator<(GraphItem) const { return false; }
klao@961
    55
    };
klao@961
    56
klao@961
    57
klao@961
    58
    template<typename GI>
klao@961
    59
    struct GraphItemConcept {
klao@961
    60
      void constraints() {
klao@961
    61
	GI i1;
klao@961
    62
	GI i2 = i1;
klao@961
    63
	GI i3 = INVALID;
klao@961
    64
	
klao@961
    65
	i1 = i2 = i3;
klao@961
    66
klao@961
    67
	bool b;
klao@961
    68
	b = (ia == ib) && (ia != ib) && (ia < ib);
klao@961
    69
	b = (ia == INVALID) && (ib != INVALID);
klao@961
    70
      }
klao@961
    71
klao@961
    72
      const GI &ia;
klao@961
    73
      const GI &ib;
klao@961
    74
    };
klao@961
    75
klao@961
    76
klao@961
    77
    template<typename Iter, typename Graph, typename BaseItem>
klao@961
    78
    struct GraphIteratorConcept {
klao@961
    79
      void constraints() {
klao@961
    80
	function_requires< GraphItemConcept<Iter> >();
klao@961
    81
	Iter it1(g);
klao@961
    82
klao@961
    83
	/// \todo Do we need NodeIt(Node) kind of constructor?
klao@961
    84
	//	Iter it2(bj);
klao@961
    85
	Iter it2;
klao@961
    86
klao@961
    87
	it2 = ++it1;
klao@961
    88
	++it2 = it1;
klao@961
    89
	++(++it1);
klao@961
    90
	/// \bug This should be: is_base_and_derived<BaseItem, Iter>
klao@961
    91
	BaseItem bi = it1;
klao@961
    92
	bi = it2;
klao@961
    93
      }
klao@961
    94
klao@961
    95
      BaseItem bj;
klao@961
    96
      Graph g;
klao@961
    97
    };
klao@961
    98
klao@961
    99
    template<typename Iter, typename Graph>
klao@961
   100
    struct GraphIncIteratorConcept {
klao@961
   101
      typedef typename Graph::Node Node;
klao@961
   102
      typedef typename Graph::Edge Edge;
klao@961
   103
      void constraints() {
klao@961
   104
	function_requires< GraphItemConcept<Iter> >();
klao@961
   105
	Iter it1(graph, node);
klao@961
   106
	/// \todo Do we need OutEdgeIt(Edge) kind of constructor?
klao@961
   107
	//	Iter it2(edge);
klao@961
   108
	Iter it2;
klao@961
   109
klao@961
   110
	it2 = ++it1;
klao@961
   111
	++it2 = it1;
klao@961
   112
	++(++it1);
klao@961
   113
	Edge e = it1;
klao@961
   114
	e = it2;
klao@961
   115
      }
klao@961
   116
klao@961
   117
      Edge edge;
klao@961
   118
      Node node;
klao@961
   119
      Graph graph;
klao@961
   120
    };
klao@961
   121
klao@961
   122
klao@961
   123
klao@959
   124
    /// An empty base graph class.
klao@959
   125
  
klao@961
   126
    /// This class provides the minimal set of features needed for a graph
klao@961
   127
    /// structure. All graph concepts have to be conform to this base
klao@961
   128
    /// graph.
klao@961
   129
    ///
klao@961
   130
    /// \bug This is not true. The minimal graph concept is the
klao@961
   131
    /// BaseIterableGraphComponent.
klao@959
   132
klao@959
   133
    class BaseGraphComponent {
klao@959
   134
    public:
klao@959
   135
klao@959
   136
      typedef BaseGraphComponent Graph;
klao@959
   137
      
klao@959
   138
      /// Node class of the graph.
klao@959
   139
klao@959
   140
      /// This class represents the Nodes of the graph. 
klao@959
   141
      ///
klao@959
   142
      class Node {
klao@959
   143
      public:
klao@959
   144
klao@959
   145
	/// Default constructor.
klao@959
   146
klao@959
   147
	/// @warning The default constructor sets the iterator
klao@959
   148
	/// to an undefined value.
klao@959
   149
klao@959
   150
	Node() {}
klao@959
   151
	/// Copy constructor.
klao@959
   152
klao@959
   153
	/// Copy constructor.
klao@959
   154
	///
klao@959
   155
	Node(const Node&) {}
klao@959
   156
klao@959
   157
	/// Invalid constructor \& conversion.
klao@959
   158
klao@959
   159
	/// This constructor initializes the iterator to be invalid.
klao@959
   160
	/// \sa Invalid for more details.
klao@959
   161
	Node(Invalid) {}
klao@959
   162
klao@959
   163
klao@959
   164
	Node& operator=(const Node&) { return *this;}
klao@959
   165
klao@959
   166
	/// Equality operator.
klao@959
   167
klao@959
   168
	/// Two iterators are equal if and only if they represents the
klao@959
   169
	/// same node in the graph or both are invalid.
klao@961
   170
	bool operator==(const Node&) const { return true;}
klao@959
   171
klao@959
   172
klao@959
   173
	/// Inequality operator.
klao@959
   174
	
klao@959
   175
	/// \sa operator==(const Node& n)
klao@959
   176
	///
klao@961
   177
	bool operator!=(const Node&) const { return true;}
klao@959
   178
klao@959
   179
 	/// Comparison operator.
klao@959
   180
klao@959
   181
	/// This is a strict ordering between the nodes.
klao@959
   182
	///
klao@959
   183
	/// This ordering can be different from the iterating order of nodes.
klao@959
   184
	/// \todo Possibly we don't need it.
klao@961
   185
	bool operator<(const Node&) const { return true;}
klao@959
   186
      };
klao@959
   187
klao@959
   188
      /// Edge class of the graph.
klao@959
   189
klao@959
   190
      /// This class represents the Edges of the graph. 
klao@959
   191
      ///
klao@959
   192
      class Edge {
klao@959
   193
      public:
klao@959
   194
klao@959
   195
	/// Default constructor.
klao@959
   196
klao@959
   197
	/// @warning The default constructor sets the iterator
klao@959
   198
	/// to an undefined value.
klao@959
   199
klao@959
   200
	Edge() {}
klao@959
   201
	/// Copy constructor.
klao@959
   202
klao@959
   203
	/// Copy constructor.
klao@959
   204
	///
klao@959
   205
	Edge(const Edge&) {}
klao@959
   206
klao@959
   207
	/// Invalid constructor \& conversion.
klao@959
   208
klao@959
   209
	/// This constructor initializes the iterator to be invalid.
klao@959
   210
	/// \sa Invalid for more details.
klao@959
   211
	Edge(Invalid) {}
klao@959
   212
klao@959
   213
klao@959
   214
	Edge& operator=(const Edge&) { return *this;}
klao@959
   215
klao@959
   216
	/// Equality operator.
klao@959
   217
klao@959
   218
	/// Two iterators are equal if and only if they represents the
klao@959
   219
	/// same edge in the graph or both are invalid.
klao@961
   220
	bool operator==(const Edge&) const { return true;}
klao@959
   221
klao@959
   222
klao@959
   223
	/// Inequality operator.
klao@959
   224
	
klao@959
   225
	/// \sa operator==(const Edge& n)
klao@959
   226
	///
klao@961
   227
	bool operator!=(const Edge&) const { return true;}
klao@959
   228
klao@959
   229
 	/// Comparison operator.
klao@959
   230
klao@959
   231
	/// This is a strict ordering between the edges.
klao@959
   232
	///
klao@959
   233
	/// This ordering can be different from the iterating order of edges.
klao@959
   234
	/// \todo Possibly we don't need it.
klao@961
   235
	bool operator<(const Edge&) const { return true;}
klao@959
   236
      };
klao@959
   237
klao@959
   238
      ///Gives back the head node of an edge.
klao@959
   239
klao@959
   240
      ///Gives back the head node of an edge.
klao@959
   241
      ///
klao@959
   242
      Node head(const Edge&) const { return INVALID;}
klao@959
   243
klao@959
   244
      ///Gives back the tail node of an edge.
klao@959
   245
klao@959
   246
      ///Gives back the tail node of an edge.
klao@959
   247
      ///
klao@959
   248
      Node tail(const Edge&) const { return INVALID;}
klao@959
   249
    };
klao@959
   250
klao@961
   251
klao@959
   252
    /// Concept check structure for BaseGraph.
klao@959
   253
klao@959
   254
    /// Concept check structure for BaseGraph.
klao@959
   255
    ///
klao@959
   256
klao@959
   257
    template <typename Graph>
klao@959
   258
    struct BaseGraphComponentConcept {
klao@959
   259
      typedef typename Graph::Node Node;
klao@959
   260
      typedef typename Graph::Edge Edge;
klao@959
   261
      
klao@959
   262
      void constraints() {
klao@961
   263
	function_requires< GraphItemConcept<Node> >();
klao@961
   264
	function_requires< GraphItemConcept<Edge> >();
klao@959
   265
	{
klao@959
   266
	  const Graph& const_graph = graph;
klao@959
   267
	  Node n;
klao@959
   268
	  Edge e;
klao@959
   269
	  n = const_graph.tail(e);
klao@959
   270
	  n = const_graph.head(e);
klao@959
   271
	}      
klao@959
   272
      }
klao@959
   273
      
klao@959
   274
      Graph& graph;
klao@959
   275
    };
klao@959
   276
klao@959
   277
    /// An empty iterable base graph class.
klao@959
   278
  
klao@959
   279
    /// This class provides beside the core graph features
klao@959
   280
    /// core iterable interface for the graph structure.
klao@959
   281
    /// Most of the base graphs should be conform to this concept.
klao@959
   282
klao@959
   283
    class BaseIterableGraphComponent : virtual public BaseGraphComponent {
klao@959
   284
    public:
klao@959
   285
klao@959
   286
      typedef BaseGraphComponent::Node Node;
klao@959
   287
      typedef BaseGraphComponent::Edge Edge;
klao@959
   288
klao@959
   289
      /// Gives back the first Node in the iterating order.
klao@959
   290
      
klao@959
   291
      /// Gives back the first Node in the iterating order.
klao@959
   292
      ///     
klao@959
   293
      void first(Node&) const {}
klao@959
   294
klao@959
   295
      /// Gives back the next Node in the iterating order.
klao@959
   296
      
klao@959
   297
      /// Gives back the next Node in the iterating order.
klao@959
   298
      ///     
klao@959
   299
      void next(Node&) const {}
klao@959
   300
klao@959
   301
      /// Gives back the first Edge in the iterating order.
klao@959
   302
      
klao@959
   303
      /// Gives back the first Edge in the iterating order.
klao@959
   304
      ///     
klao@959
   305
      void first(Edge&) const {}
klao@959
   306
      /// Gives back the next Edge in the iterating order.
klao@959
   307
      
klao@959
   308
      /// Gives back the next Edge in the iterating order.
klao@959
   309
      ///     
klao@959
   310
      void next(Edge&) const {}
klao@959
   311
klao@959
   312
klao@959
   313
      /// Gives back the first of the Edges point to the given Node.
klao@959
   314
      
klao@959
   315
      /// Gives back the first of the Edges point to the given Node.
klao@959
   316
      ///     
klao@959
   317
      void firstIn(Edge&, const Node&) const {}
klao@959
   318
klao@959
   319
      /// Gives back the next of the Edges points to the given Node.
klao@959
   320
klao@959
   321
klao@959
   322
      /// Gives back the next of the Edges points to the given Node.
klao@959
   323
      ///
klao@959
   324
      void nextIn(Edge&) const {}
klao@959
   325
klao@959
   326
      /// Gives back the first of the Edges start from the given Node.
klao@959
   327
      
klao@959
   328
      /// Gives back the first of the Edges start from the given Node.
klao@959
   329
      ///     
klao@959
   330
      void firstOut(Edge&, const Node&) const {}
klao@959
   331
klao@959
   332
      /// Gives back the next of the Edges start from the given Node.
klao@959
   333
      
klao@959
   334
      /// Gives back the next of the Edges start from the given Node.
klao@959
   335
      ///     
klao@959
   336
      void nextOut(Edge&) const {}
klao@959
   337
    };
klao@959
   338
klao@959
   339
klao@959
   340
    /// Concept check structure for IterableBaseGraph.
klao@959
   341
klao@959
   342
    /// Concept check structure for IterableBaseGraph.
klao@959
   343
    ///
klao@959
   344
    template <typename Graph>
klao@959
   345
    struct BaseIterableGraphComponentConcept {
klao@959
   346
      
klao@961
   347
      void constraints() {
klao@961
   348
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   349
	typename Graph::Node node;      
klao@959
   350
	typename Graph::Edge edge;
klao@959
   351
	{
klao@961
   352
	  graph.first(node);
klao@961
   353
	  graph.next(node);
klao@959
   354
	}
klao@959
   355
	{
klao@961
   356
	  graph.first(edge);
klao@961
   357
	  graph.next(edge);
klao@959
   358
	}
klao@959
   359
	{
klao@961
   360
	  graph.firstIn(edge, node);
klao@961
   361
	  graph.nextIn(edge);
klao@959
   362
	}
klao@959
   363
	{
klao@961
   364
	  graph.firstOut(edge, node);
klao@961
   365
	  graph.nextOut(edge);
klao@959
   366
	}
klao@959
   367
      }
klao@959
   368
klao@961
   369
      const Graph& graph;
klao@959
   370
    };
klao@959
   371
klao@959
   372
    /// An empty idable base graph class.
klao@959
   373
  
klao@959
   374
    /// This class provides beside the core graph features
klao@959
   375
    /// core id functions for the graph structure.
klao@959
   376
    /// The most of the base graphs should be conform to this concept.
klao@959
   377
    /// The id's are unique and immutable.
klao@959
   378
klao@959
   379
    class IDableGraphComponent : virtual public BaseGraphComponent {
klao@959
   380
    public:
klao@959
   381
klao@959
   382
      typedef BaseGraphComponent::Node Node;
klao@959
   383
      typedef BaseGraphComponent::Edge Edge;
klao@959
   384
klao@959
   385
      /// Gives back an unique integer id for the Node. 
klao@959
   386
klao@959
   387
      /// Gives back an unique integer id for the Node. 
klao@959
   388
      ///
klao@959
   389
      int id(const Node&) const { return -1;}
klao@959
   390
klao@959
   391
      /// Gives back an unique integer id for the Edge. 
klao@959
   392
klao@959
   393
      /// Gives back an unique integer id for the Edge. 
klao@959
   394
      ///
klao@959
   395
      int id(const Edge&) const { return -1;}
klao@959
   396
    };
klao@959
   397
klao@959
   398
klao@959
   399
    /// Concept check structure for IdableBaseGraph.
klao@959
   400
klao@959
   401
    /// Concept check structure for IdableBaseGraph.
klao@959
   402
    ///
klao@959
   403
    template <typename Graph>
klao@959
   404
    struct IDableGraphComponentConcept {
klao@959
   405
klao@959
   406
      void constraints() {
klao@961
   407
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   408
	typename Graph::Node node;
klao@961
   409
	int nid = graph.id(node);
klao@961
   410
	nid = graph.id(node);
klao@959
   411
	typename Graph::Edge edge;
klao@961
   412
	int eid = graph.id(edge);
klao@961
   413
	eid = graph.id(edge);
klao@959
   414
      }
klao@959
   415
klao@961
   416
      const Graph& graph;
klao@959
   417
    };
klao@959
   418
klao@959
   419
klao@959
   420
    /// An empty max-idable base graph class.
klao@959
   421
  
klao@959
   422
    /// This class provides beside the core graph features
klao@959
   423
    /// core max id functions for the graph structure.
klao@959
   424
    /// The most of the base graphs should be conform to this concept.
klao@959
   425
    /// The id's are unique and immutable.
klao@959
   426
    class MaxIDableGraphComponent : virtual public BaseGraphComponent {
klao@959
   427
    public:
klao@959
   428
klao@959
   429
      /// Gives back an integer greater or equal to the maximum Node id. 
klao@959
   430
klao@959
   431
      /// Gives back an integer greater or equal to the maximum Node id. 
klao@959
   432
      ///
klao@959
   433
      int maxEdgeId() const { return -1;}
klao@959
   434
klao@959
   435
      /// Gives back an integer greater or equal to the maximum Edge id. 
klao@959
   436
klao@959
   437
      /// Gives back an integer greater or equal to the maximum Edge id. 
klao@959
   438
      ///
klao@959
   439
      int maxNodeId() const { return -1;}
klao@959
   440
    };
klao@959
   441
klao@959
   442
    /// Concept check structure for MaxIdableBaseGraph.
klao@959
   443
klao@959
   444
    /// Concept check structure for MaxIdableBaseGraph.
klao@959
   445
    ///
klao@959
   446
    template <typename Graph>
klao@959
   447
    struct MaxIDableGraphComponentConcept {
klao@959
   448
klao@959
   449
      void constraints() {
klao@961
   450
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@961
   451
	int nid = graph.maxEdgeId();
klao@959
   452
	ignore_unused_variable_warning(nid);
klao@961
   453
	int eid = graph.maxNodeId();
klao@959
   454
	ignore_unused_variable_warning(eid);
klao@959
   455
      }
klao@959
   456
klao@961
   457
      const Graph& graph;
klao@959
   458
    };
klao@959
   459
klao@959
   460
    /// An empty extendable base graph class.
klao@959
   461
  
klao@959
   462
    /// This class provides beside the core graph features
klao@959
   463
    /// core graph extend interface for the graph structure.
klao@959
   464
    /// The most of the base graphs should be conform to this concept.
klao@959
   465
    class BaseExtendableGraphComponent : virtual public BaseGraphComponent {
klao@959
   466
    public:
klao@959
   467
klao@959
   468
      typedef BaseGraphComponent::Node Node;
klao@959
   469
      typedef BaseGraphComponent::Edge Edge;
klao@959
   470
klao@959
   471
      /// Adds a new Node to the graph.
klao@959
   472
klao@959
   473
      /// Adds a new Node to the graph.
klao@959
   474
      ///
klao@959
   475
      Node addNode() {
klao@959
   476
	return INVALID;
klao@959
   477
      }
klao@959
   478
    
klao@959
   479
      /// Adds a new Edge connects the two Nodes to the graph.
klao@959
   480
klao@959
   481
      /// Adds a new Edge connects the two Nodes to the graph.
klao@959
   482
      ///
klao@959
   483
      Edge addEdge(const Node& from, const Node& to) {
klao@959
   484
	return INVALID;
klao@959
   485
      }
klao@959
   486
klao@959
   487
    };
klao@959
   488
klao@959
   489
    /// Concept check structure for ExtendableBaseGraph.
klao@959
   490
klao@959
   491
    /// Concept check structure for ExtendableBaseGraph.
klao@959
   492
    ///
klao@959
   493
    template <typename Graph>
klao@959
   494
    struct BaseExtendableGraphComponentConcept {
klao@959
   495
      void constraints() {
klao@961
   496
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   497
	typename Graph::Node node_a, node_b;
klao@959
   498
	node_a = graph.addNode();
klao@959
   499
	typename Graph::Edge edge;
klao@959
   500
	edge = graph.addEdge(node_a, node_b);
klao@959
   501
      }
klao@959
   502
klao@959
   503
      Graph& graph;
klao@959
   504
    };
klao@959
   505
klao@959
   506
    /// An empty erasable base graph class.
klao@959
   507
  
klao@959
   508
    /// This class provides beside the core graph features
klao@959
   509
    /// core erase functions for the graph structure.
klao@959
   510
    /// The most of the base graphs should be conform to this concept.
klao@959
   511
    class BaseErasableGraphComponent : virtual public BaseGraphComponent {
klao@959
   512
    public:
klao@959
   513
klao@959
   514
      typedef BaseGraphComponent::Node Node;
klao@959
   515
      typedef BaseGraphComponent::Edge Edge;
klao@959
   516
klao@959
   517
      /// Erase a Node from the graph.
klao@959
   518
      
klao@959
   519
      /// Erase a Node from the graph. This function should not
klao@959
   520
      /// erase edges connecting to the Node.
klao@959
   521
      void erase(const Node&) {}    
klao@959
   522
klao@959
   523
      /// Erase an Edge from the graph.
klao@959
   524
klao@959
   525
      /// Erase an Edge from the graph.
klao@959
   526
      ///
klao@959
   527
      void erase(const Edge&) {}
klao@959
   528
klao@959
   529
    };
klao@959
   530
klao@959
   531
    /// Concept check structure for ErasableBaseGraph.
klao@959
   532
klao@959
   533
    /// Concept check structure for ErasableBaseGraph.
klao@959
   534
    ///
klao@959
   535
    template <typename Graph>
klao@959
   536
    struct BaseErasableGraphComponentConcept {
klao@959
   537
      void constraints() {
klao@961
   538
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   539
	typename Graph::Node node;
klao@959
   540
	graph.erase(node);
klao@959
   541
	typename Graph::Edge edge;
klao@959
   542
	graph.erase(edge);
klao@959
   543
      }
klao@959
   544
klao@959
   545
      Graph& graph;
klao@959
   546
    };
klao@959
   547
klao@959
   548
    /// An empty clearable base graph class.
klao@959
   549
  
klao@959
   550
    /// This class provides beside the core graph features
klao@959
   551
    /// core clear functions for the graph structure.
klao@959
   552
    /// The most of the base graphs should be conform to this concept.
klao@959
   553
    class BaseClearableGraphComponent : virtual public BaseGraphComponent {
klao@959
   554
    public:
klao@959
   555
klao@959
   556
      /// Erase all the Nodes and Edges from the graph.
klao@959
   557
klao@959
   558
      /// Erase all the Nodes and Edges from the graph.
klao@959
   559
      ///
klao@959
   560
      void clear() {}    
klao@959
   561
    };
klao@959
   562
klao@959
   563
    /// Concept check function for ErasableBaseGraph.
klao@959
   564
klao@959
   565
    /// Concept check function for ErasableBaseGraph.
klao@959
   566
    ///
klao@959
   567
    template <typename Graph>
klao@959
   568
    struct BaseClearableGraphComponentConcept {
klao@959
   569
      void constraints() {
klao@961
   570
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   571
	graph.clear();
klao@959
   572
      }
klao@959
   573
klao@959
   574
      Graph& graph;
klao@959
   575
    };
klao@959
   576
klao@959
   577
klao@961
   578
    class IterableGraphComponent :
klao@961
   579
      virtual public BaseIterableGraphComponent {
klao@959
   580
klao@959
   581
    public:
klao@959
   582
    
klao@959
   583
      typedef IterableGraphComponent Graph;
klao@959
   584
klao@959
   585
      typedef BaseGraphComponent::Node Node;
klao@959
   586
      typedef BaseGraphComponent::Edge Edge;
klao@959
   587
klao@959
   588
      class NodeIt : public Node {
klao@959
   589
      public:
klao@959
   590
	NodeIt() {}
klao@959
   591
	NodeIt(Invalid) {}
klao@961
   592
	// explicit NodeIt(Node) {}
klao@961
   593
	explicit NodeIt(const Graph&) {}
klao@959
   594
klao@959
   595
	NodeIt& operator++() { return *this; }
klao@959
   596
	//	Node operator*() const { return INVALID; }
klao@959
   597
klao@961
   598
	bool operator==(const NodeIt&) const { return true;}
klao@961
   599
	bool operator!=(const NodeIt&) const { return true;}
klao@959
   600
      };
klao@959
   601
klao@959
   602
      class EdgeIt : public Edge {
klao@959
   603
      public:
klao@959
   604
	EdgeIt() {}
klao@959
   605
	EdgeIt(Invalid) {}
klao@961
   606
	// explicit EdgeIt(Edge) {}
klao@961
   607
	explicit EdgeIt(const Graph&) {}
klao@959
   608
klao@959
   609
	EdgeIt& operator++() { return *this; }
klao@959
   610
	//	Edge operator*() const { return INVALID; }
klao@959
   611
klao@961
   612
	bool operator==(const EdgeIt&) const { return true;}
klao@961
   613
	bool operator!=(const EdgeIt&) const { return true;}
klao@959
   614
      };
klao@959
   615
klao@959
   616
      class InEdgeIt : public Edge {
klao@959
   617
      public:
klao@959
   618
	InEdgeIt() {}
klao@959
   619
	InEdgeIt(Invalid) {}
klao@961
   620
	// explicit InEdgeIt(Edge) {}
klao@961
   621
	explicit InEdgeIt(const Graph&, const Node&) {}
klao@959
   622
klao@959
   623
	InEdgeIt& operator++() { return *this; }
klao@959
   624
	//	Edge operator*() const { return INVALID; }
klao@959
   625
klao@961
   626
	bool operator==(const InEdgeIt&) const { return true;}
klao@961
   627
	bool operator!=(const InEdgeIt&) const { return true;}
klao@959
   628
      };
klao@959
   629
klao@959
   630
      class OutEdgeIt : public Edge {
klao@959
   631
      public:
klao@959
   632
	OutEdgeIt() {}
klao@959
   633
	OutEdgeIt(Invalid) {}
klao@961
   634
	// explicit OutEdgeIt(Edge) {}
klao@961
   635
	explicit OutEdgeIt(const Graph&, const Node&) {}
klao@959
   636
klao@959
   637
	OutEdgeIt& operator++() { return *this; }
klao@959
   638
	//	Edge operator*() const { return INVALID; }
klao@959
   639
klao@961
   640
	bool operator==(const OutEdgeIt&) const { return true;}
klao@961
   641
	bool operator!=(const OutEdgeIt&) const { return true;}
klao@959
   642
      };
klao@959
   643
klao@959
   644
    };
klao@959
   645
    
klao@959
   646
    template <typename Graph> 
klao@959
   647
    struct IterableGraphComponentConcept {
klao@959
   648
klao@959
   649
      void constraints() {
klao@961
   650
  	function_requires< BaseIterableGraphComponentConcept<Graph> >();
klao@961
   651
klao@959
   652
	typedef typename Graph::Node Node;
klao@959
   653
	typedef typename Graph::NodeIt NodeIt;
klao@959
   654
	typedef typename Graph::Edge Edge;
klao@959
   655
	typedef typename Graph::EdgeIt EdgeIt;
klao@959
   656
	typedef typename Graph::InEdgeIt InEdgeIt;
klao@959
   657
	typedef typename Graph::OutEdgeIt OutEdgeIt;
klao@959
   658
  
klao@961
   659
	function_requires< GraphIteratorConcept<NodeIt, Graph, Node> >();
klao@961
   660
	function_requires< GraphIteratorConcept<EdgeIt, Graph, Edge> >();
klao@961
   661
	function_requires< GraphIncIteratorConcept<OutEdgeIt, Graph> >();
klao@961
   662
	function_requires< GraphIncIteratorConcept<InEdgeIt, Graph> >();
klao@959
   663
      }
klao@959
   664
      Graph& graph;
klao@959
   665
    };
klao@959
   666
klao@959
   667
klao@959
   668
    class IdMappableGraphComponent : virtual public BaseGraphComponent {
klao@959
   669
klao@959
   670
      typedef IdMappableGraphComponent Graph;
klao@959
   671
klao@961
   672
    public:
klao@961
   673
klao@959
   674
      typedef BaseGraphComponent::Node Node;
klao@959
   675
      typedef BaseGraphComponent::Edge Edge;
klao@959
   676
klao@959
   677
      class NodeIdMap : public ReadMap<Node, int> {
klao@959
   678
      public:
klao@959
   679
	NodeIdMap(const Graph&) {}
klao@959
   680
	int maxId() const { return -1;}
klao@959
   681
      };
klao@959
   682
klao@959
   683
      class EdgeIdMap : public ReadMap<Edge, int> {
klao@959
   684
      public:
klao@959
   685
	EdgeIdMap(const Graph&) {}
klao@959
   686
	int maxId() const { return -1;}
klao@959
   687
      };
klao@959
   688
klao@959
   689
    };
klao@959
   690
    
klao@959
   691
    template <typename Graph>
klao@959
   692
    struct IdMappableGraphComponentConcept {
klao@959
   693
      void constraints() {	
klao@961
   694
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   695
	{
klao@959
   696
	  typedef typename Graph::EdgeIdMap EdgeIdMap;
klao@959
   697
	  function_requires<ReadMapConcept<EdgeIdMap> >();
klao@959
   698
	  EdgeIdMap edge_map(graph);
klao@959
   699
	  int n = edge_map.maxId();
klao@959
   700
	  ignore_unused_variable_warning(n);
klao@959
   701
	}
klao@959
   702
	{
klao@959
   703
	  typedef typename Graph::NodeIdMap NodeIdMap;
klao@959
   704
	  function_requires<ReadMapConcept<NodeIdMap> >();
klao@959
   705
	  NodeIdMap node_map(graph);
klao@959
   706
	  int n = node_map.maxId();
klao@959
   707
	  ignore_unused_variable_warning(n);
klao@959
   708
	}
klao@959
   709
      }
klao@959
   710
      Graph& graph;
klao@959
   711
    };
klao@959
   712
klao@959
   713
klao@959
   714
    class MappableGraphComponent : virtual public BaseGraphComponent {
klao@959
   715
    public:
klao@959
   716
klao@959
   717
      typedef MappableGraphComponent Graph;
klao@959
   718
klao@959
   719
      typedef BaseGraphComponent::Node Node;
klao@959
   720
      typedef BaseGraphComponent::Edge Edge;
klao@959
   721
klao@959
   722
      template <typename Value>
klao@959
   723
      class NodeMap : public ReferenceMap<Node, Value> {
klao@959
   724
      public:
klao@959
   725
	NodeMap(const Graph&) {}
klao@959
   726
	NodeMap(const Graph&, const Value&) {}
klao@959
   727
	NodeMap(const NodeMap&) {}
klao@959
   728
klao@959
   729
	NodeMap& operator=(const NodeMap&) { return *this;}
klao@959
   730
	
klao@959
   731
      };
klao@959
   732
klao@959
   733
      template <typename Value>
klao@959
   734
      class EdgeMap : public ReferenceMap<Edge, Value> {
klao@959
   735
      public:
klao@959
   736
	EdgeMap(const Graph&) {}
klao@959
   737
	EdgeMap(const Graph&, const Value&) {}
klao@959
   738
	EdgeMap(const EdgeMap&) {}
klao@959
   739
klao@959
   740
	EdgeMap& operator=(const EdgeMap&) { return *this;}
klao@959
   741
	
klao@959
   742
      };
klao@959
   743
klao@959
   744
    };
klao@959
   745
klao@959
   746
    template <typename Graph>
klao@959
   747
    struct MappableGraphComponentConcept {
klao@959
   748
klao@959
   749
      struct Type {
klao@959
   750
	int value;
klao@959
   751
	Type() : value(0) {}
klao@959
   752
	Type(int _v) : value(_v) {}
klao@959
   753
      };
klao@959
   754
klao@959
   755
      void constraints() {
klao@961
   756
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   757
	{ // int map test
klao@959
   758
	  typedef typename Graph::template NodeMap<int> IntNodeMap;
klao@959
   759
	  function_requires<GraphMapConcept<IntNodeMap,Graph> >();
klao@959
   760
	} { // bool map test
klao@959
   761
	  typedef typename Graph::template NodeMap<bool> BoolNodeMap;
klao@959
   762
	  function_requires<GraphMapConcept<BoolNodeMap,Graph> >();
klao@959
   763
	} { // Type map test
klao@959
   764
	  typedef typename Graph::template NodeMap<Type> TypeNodeMap;
klao@959
   765
	  function_requires<GraphMapConcept<TypeNodeMap,Graph> >();
klao@959
   766
	} 
klao@959
   767
klao@959
   768
	{ // int map test
klao@959
   769
	  typedef typename Graph::template EdgeMap<int> IntEdgeMap;
klao@959
   770
	  function_requires<GraphMapConcept<IntEdgeMap,Graph> >();
klao@959
   771
	} { // bool map test
klao@959
   772
	  typedef typename Graph::template EdgeMap<bool> BoolEdgeMap;
klao@959
   773
	  function_requires<GraphMapConcept<BoolEdgeMap,Graph> >();
klao@959
   774
	} { // Type map test
klao@959
   775
	  typedef typename Graph::template EdgeMap<Type> TypeEdgeMap;
klao@959
   776
	  function_requires<GraphMapConcept<TypeEdgeMap,Graph> >();
klao@959
   777
	} 
klao@959
   778
      }
klao@959
   779
klao@959
   780
      Graph& graph;
klao@959
   781
    };
klao@959
   782
klao@959
   783
klao@959
   784
    class ExtendableGraphComponent : virtual public BaseGraphComponent {
klao@959
   785
    public:
klao@959
   786
klao@959
   787
      typedef ExtendableGraphComponent Graph;
klao@959
   788
klao@959
   789
      typedef BaseGraphComponent::Node Node;
klao@959
   790
      typedef BaseGraphComponent::Edge Edge;
klao@959
   791
klao@959
   792
      Node addNode() {
klao@959
   793
	return INVALID;
klao@959
   794
      }
klao@959
   795
    
klao@959
   796
      Edge addEdge(const Node& from, const Node& to) {
klao@959
   797
	return INVALID;
klao@959
   798
      }
klao@959
   799
klao@959
   800
    };
klao@959
   801
klao@959
   802
    template <typename Graph>
klao@959
   803
    struct ExtendableGraphComponentConcept {
klao@959
   804
      void constraints() {
klao@961
   805
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   806
	typename Graph::Node node_a, node_b;
klao@959
   807
	node_a = graph.addNode();
klao@959
   808
	typename Graph::Edge edge;
klao@959
   809
	edge = graph.addEdge(node_a, node_b);      
klao@959
   810
      }
klao@959
   811
      Graph& graph;
klao@959
   812
    };
klao@959
   813
klao@959
   814
    class ErasableGraphComponent : virtual public BaseGraphComponent {
klao@959
   815
    public:
klao@959
   816
klao@959
   817
      typedef ErasableGraphComponent Graph;
klao@959
   818
klao@959
   819
      typedef BaseGraphComponent::Node Node;
klao@959
   820
      typedef BaseGraphComponent::Edge Edge;
klao@959
   821
klao@959
   822
      void erase(const Node&) {}    
klao@959
   823
      void erase(const Edge&) {}
klao@959
   824
klao@959
   825
    };
klao@959
   826
klao@959
   827
    template <typename Graph>
klao@959
   828
    struct ErasableGraphComponentConcept {
klao@959
   829
      void constraints() {
klao@961
   830
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   831
	typename Graph::Node node;
klao@959
   832
	graph.erase(node);
klao@959
   833
	typename Graph::Edge edge;
klao@959
   834
	graph.erase(edge);      
klao@959
   835
      }
klao@959
   836
klao@959
   837
      Graph& graph;
klao@959
   838
    };
klao@959
   839
klao@959
   840
    class ClearableGraphComponent : virtual public BaseGraphComponent {
klao@959
   841
    public:
klao@959
   842
klao@959
   843
      typedef ClearableGraphComponent Graph;
klao@959
   844
klao@959
   845
      typedef BaseGraphComponent::Node Node;
klao@959
   846
      typedef BaseGraphComponent::Edge Edge;
klao@959
   847
klao@959
   848
      void clear() {}    
klao@959
   849
klao@959
   850
    };
klao@959
   851
klao@959
   852
    template <typename Graph>
klao@959
   853
    struct ClearableGraphComponentConcept {
klao@959
   854
      void constraints() {
klao@961
   855
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   856
	graph.clear();
klao@959
   857
      }
klao@959
   858
      Graph& graph;
klao@959
   859
    };
klao@959
   860
klao@959
   861
  }
klao@959
   862
klao@959
   863
}
klao@959
   864
klao@959
   865
#endif