src/lemon/concept/graph_component.h
author alpar
Fri, 05 Nov 2004 07:26:20 +0000
changeset 964 2c0c20e90116
parent 962 1a770e9f80b2
child 980 0f1044b7a3af
permissions -rw-r--r--
Doc improvements
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
alpar@964
    37
    /// base class, this is a template. For Node you should 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
	  Node n;
klao@959
   267
	  Edge e;
klao@962
   268
	  n = graph.tail(e);
klao@962
   269
	  n = graph.head(e);
klao@959
   270
	}      
klao@959
   271
      }
klao@959
   272
      
klao@962
   273
      const Graph& graph;
klao@959
   274
    };
klao@959
   275
klao@959
   276
    /// An empty iterable base graph class.
klao@959
   277
  
klao@959
   278
    /// This class provides beside the core graph features
klao@959
   279
    /// core iterable interface for the graph structure.
klao@959
   280
    /// Most of the base graphs should be conform to this concept.
klao@959
   281
klao@959
   282
    class BaseIterableGraphComponent : virtual public BaseGraphComponent {
klao@959
   283
    public:
klao@959
   284
klao@959
   285
      typedef BaseGraphComponent::Node Node;
klao@959
   286
      typedef BaseGraphComponent::Edge Edge;
klao@959
   287
klao@959
   288
      /// Gives back the first Node in the iterating order.
klao@959
   289
      
klao@959
   290
      /// Gives back the first Node in the iterating order.
klao@959
   291
      ///     
klao@959
   292
      void first(Node&) const {}
klao@959
   293
klao@959
   294
      /// Gives back the next Node in the iterating order.
klao@959
   295
      
klao@959
   296
      /// Gives back the next Node in the iterating order.
klao@959
   297
      ///     
klao@959
   298
      void next(Node&) const {}
klao@959
   299
klao@959
   300
      /// Gives back the first Edge in the iterating order.
klao@959
   301
      
klao@959
   302
      /// Gives back the first Edge in the iterating order.
klao@959
   303
      ///     
klao@959
   304
      void first(Edge&) const {}
klao@959
   305
      /// Gives back the next Edge in the iterating order.
klao@959
   306
      
klao@959
   307
      /// Gives back the next Edge in the iterating order.
klao@959
   308
      ///     
klao@959
   309
      void next(Edge&) const {}
klao@959
   310
klao@959
   311
klao@959
   312
      /// Gives back the first of the Edges point to the given Node.
klao@959
   313
      
klao@959
   314
      /// Gives back the first of the Edges point to the given Node.
klao@959
   315
      ///     
klao@959
   316
      void firstIn(Edge&, const Node&) const {}
klao@959
   317
klao@959
   318
      /// Gives back the next of the Edges points to the given Node.
klao@959
   319
klao@959
   320
klao@959
   321
      /// Gives back the next of the Edges points to the given Node.
klao@959
   322
      ///
klao@959
   323
      void nextIn(Edge&) const {}
klao@959
   324
klao@959
   325
      /// Gives back the first of the Edges start from the given Node.
klao@959
   326
      
klao@959
   327
      /// Gives back the first of the Edges start from the given Node.
klao@959
   328
      ///     
klao@959
   329
      void firstOut(Edge&, const Node&) const {}
klao@959
   330
klao@959
   331
      /// Gives back the next of the Edges start from the given Node.
klao@959
   332
      
klao@959
   333
      /// Gives back the next of the Edges start from the given Node.
klao@959
   334
      ///     
klao@959
   335
      void nextOut(Edge&) const {}
klao@959
   336
    };
klao@959
   337
klao@959
   338
klao@959
   339
    /// Concept check structure for IterableBaseGraph.
klao@959
   340
klao@959
   341
    /// Concept check structure for IterableBaseGraph.
klao@959
   342
    ///
klao@959
   343
    template <typename Graph>
klao@959
   344
    struct BaseIterableGraphComponentConcept {
klao@959
   345
      
klao@961
   346
      void constraints() {
klao@961
   347
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   348
	typename Graph::Node node;      
klao@959
   349
	typename Graph::Edge edge;
klao@959
   350
	{
klao@961
   351
	  graph.first(node);
klao@961
   352
	  graph.next(node);
klao@959
   353
	}
klao@959
   354
	{
klao@961
   355
	  graph.first(edge);
klao@961
   356
	  graph.next(edge);
klao@959
   357
	}
klao@959
   358
	{
klao@961
   359
	  graph.firstIn(edge, node);
klao@961
   360
	  graph.nextIn(edge);
klao@959
   361
	}
klao@959
   362
	{
klao@961
   363
	  graph.firstOut(edge, node);
klao@961
   364
	  graph.nextOut(edge);
klao@959
   365
	}
klao@959
   366
      }
klao@959
   367
klao@961
   368
      const Graph& graph;
klao@959
   369
    };
klao@959
   370
klao@959
   371
    /// An empty idable base graph class.
klao@959
   372
  
klao@959
   373
    /// This class provides beside the core graph features
klao@959
   374
    /// core id functions for the graph structure.
klao@959
   375
    /// The most of the base graphs should be conform to this concept.
klao@959
   376
    /// The id's are unique and immutable.
klao@959
   377
klao@959
   378
    class IDableGraphComponent : virtual public BaseGraphComponent {
klao@959
   379
    public:
klao@959
   380
klao@959
   381
      typedef BaseGraphComponent::Node Node;
klao@959
   382
      typedef BaseGraphComponent::Edge Edge;
klao@959
   383
klao@959
   384
      /// Gives back an unique integer id for the Node. 
klao@959
   385
klao@959
   386
      /// Gives back an unique integer id for the Node. 
klao@959
   387
      ///
klao@959
   388
      int id(const Node&) const { return -1;}
klao@959
   389
klao@959
   390
      /// Gives back an unique integer id for the Edge. 
klao@959
   391
klao@959
   392
      /// Gives back an unique integer id for the Edge. 
klao@959
   393
      ///
klao@959
   394
      int id(const Edge&) const { return -1;}
klao@959
   395
    };
klao@959
   396
klao@959
   397
klao@959
   398
    /// Concept check structure for IdableBaseGraph.
klao@959
   399
klao@959
   400
    /// Concept check structure for IdableBaseGraph.
klao@959
   401
    ///
klao@959
   402
    template <typename Graph>
klao@959
   403
    struct IDableGraphComponentConcept {
klao@959
   404
klao@959
   405
      void constraints() {
klao@961
   406
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   407
	typename Graph::Node node;
klao@961
   408
	int nid = graph.id(node);
klao@961
   409
	nid = graph.id(node);
klao@959
   410
	typename Graph::Edge edge;
klao@961
   411
	int eid = graph.id(edge);
klao@961
   412
	eid = graph.id(edge);
klao@959
   413
      }
klao@959
   414
klao@961
   415
      const Graph& graph;
klao@959
   416
    };
klao@959
   417
klao@959
   418
klao@959
   419
    /// An empty max-idable base graph class.
klao@959
   420
  
klao@959
   421
    /// This class provides beside the core graph features
klao@959
   422
    /// core max id functions for the graph structure.
klao@959
   423
    /// The most of the base graphs should be conform to this concept.
klao@959
   424
    /// The id's are unique and immutable.
klao@959
   425
    class MaxIDableGraphComponent : virtual public BaseGraphComponent {
klao@959
   426
    public:
klao@959
   427
klao@959
   428
      /// Gives back an integer greater or equal to the maximum Node id. 
klao@959
   429
klao@959
   430
      /// Gives back an integer greater or equal to the maximum Node id. 
klao@959
   431
      ///
klao@959
   432
      int maxEdgeId() const { return -1;}
klao@959
   433
klao@959
   434
      /// Gives back an integer greater or equal to the maximum Edge id. 
klao@959
   435
klao@959
   436
      /// Gives back an integer greater or equal to the maximum Edge id. 
klao@959
   437
      ///
klao@959
   438
      int maxNodeId() const { return -1;}
klao@959
   439
    };
klao@959
   440
klao@959
   441
    /// Concept check structure for MaxIdableBaseGraph.
klao@959
   442
klao@959
   443
    /// Concept check structure for MaxIdableBaseGraph.
klao@959
   444
    ///
klao@959
   445
    template <typename Graph>
klao@959
   446
    struct MaxIDableGraphComponentConcept {
klao@959
   447
klao@959
   448
      void constraints() {
klao@961
   449
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@961
   450
	int nid = graph.maxEdgeId();
klao@959
   451
	ignore_unused_variable_warning(nid);
klao@961
   452
	int eid = graph.maxNodeId();
klao@959
   453
	ignore_unused_variable_warning(eid);
klao@959
   454
      }
klao@959
   455
klao@961
   456
      const Graph& graph;
klao@959
   457
    };
klao@959
   458
klao@959
   459
    /// An empty extendable base graph class.
klao@959
   460
  
klao@959
   461
    /// This class provides beside the core graph features
klao@959
   462
    /// core graph extend interface for the graph structure.
klao@959
   463
    /// The most of the base graphs should be conform to this concept.
klao@959
   464
    class BaseExtendableGraphComponent : virtual public BaseGraphComponent {
klao@959
   465
    public:
klao@959
   466
klao@959
   467
      typedef BaseGraphComponent::Node Node;
klao@959
   468
      typedef BaseGraphComponent::Edge Edge;
klao@959
   469
klao@959
   470
      /// Adds a new Node to the graph.
klao@959
   471
klao@959
   472
      /// Adds a new Node to the graph.
klao@959
   473
      ///
klao@959
   474
      Node addNode() {
klao@959
   475
	return INVALID;
klao@959
   476
      }
klao@959
   477
    
klao@959
   478
      /// Adds a new Edge connects the two Nodes to the graph.
klao@959
   479
klao@959
   480
      /// Adds a new Edge connects the two Nodes to the graph.
klao@959
   481
      ///
klao@959
   482
      Edge addEdge(const Node& from, const Node& to) {
klao@959
   483
	return INVALID;
klao@959
   484
      }
klao@959
   485
klao@959
   486
    };
klao@959
   487
klao@959
   488
    /// Concept check structure for ExtendableBaseGraph.
klao@959
   489
klao@959
   490
    /// Concept check structure for ExtendableBaseGraph.
klao@959
   491
    ///
klao@959
   492
    template <typename Graph>
klao@959
   493
    struct BaseExtendableGraphComponentConcept {
klao@959
   494
      void constraints() {
klao@961
   495
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   496
	typename Graph::Node node_a, node_b;
klao@959
   497
	node_a = graph.addNode();
klao@959
   498
	typename Graph::Edge edge;
klao@959
   499
	edge = graph.addEdge(node_a, node_b);
klao@959
   500
      }
klao@959
   501
klao@959
   502
      Graph& graph;
klao@959
   503
    };
klao@959
   504
klao@959
   505
    /// An empty erasable base graph class.
klao@959
   506
  
klao@959
   507
    /// This class provides beside the core graph features
klao@959
   508
    /// core erase functions for the graph structure.
klao@959
   509
    /// The most of the base graphs should be conform to this concept.
klao@959
   510
    class BaseErasableGraphComponent : virtual public BaseGraphComponent {
klao@959
   511
    public:
klao@959
   512
klao@959
   513
      typedef BaseGraphComponent::Node Node;
klao@959
   514
      typedef BaseGraphComponent::Edge Edge;
klao@959
   515
klao@959
   516
      /// Erase a Node from the graph.
klao@959
   517
      
klao@959
   518
      /// Erase a Node from the graph. This function should not
klao@959
   519
      /// erase edges connecting to the Node.
klao@959
   520
      void erase(const Node&) {}    
klao@959
   521
klao@959
   522
      /// Erase an Edge from the graph.
klao@959
   523
klao@959
   524
      /// Erase an Edge from the graph.
klao@959
   525
      ///
klao@959
   526
      void erase(const Edge&) {}
klao@959
   527
klao@959
   528
    };
klao@959
   529
klao@959
   530
    /// Concept check structure for ErasableBaseGraph.
klao@959
   531
klao@959
   532
    /// Concept check structure for ErasableBaseGraph.
klao@959
   533
    ///
klao@959
   534
    template <typename Graph>
klao@959
   535
    struct BaseErasableGraphComponentConcept {
klao@959
   536
      void constraints() {
klao@961
   537
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   538
	typename Graph::Node node;
klao@959
   539
	graph.erase(node);
klao@959
   540
	typename Graph::Edge edge;
klao@959
   541
	graph.erase(edge);
klao@959
   542
      }
klao@959
   543
klao@959
   544
      Graph& graph;
klao@959
   545
    };
klao@959
   546
klao@959
   547
    /// An empty clearable base graph class.
klao@959
   548
  
klao@959
   549
    /// This class provides beside the core graph features
klao@959
   550
    /// core clear functions for the graph structure.
klao@959
   551
    /// The most of the base graphs should be conform to this concept.
klao@959
   552
    class BaseClearableGraphComponent : virtual public BaseGraphComponent {
klao@959
   553
    public:
klao@959
   554
klao@959
   555
      /// Erase all the Nodes and Edges from the graph.
klao@959
   556
klao@959
   557
      /// Erase all the Nodes and Edges from the graph.
klao@959
   558
      ///
klao@959
   559
      void clear() {}    
klao@959
   560
    };
klao@959
   561
klao@959
   562
    /// Concept check function for ErasableBaseGraph.
klao@959
   563
klao@959
   564
    /// Concept check function for ErasableBaseGraph.
klao@959
   565
    ///
klao@959
   566
    template <typename Graph>
klao@959
   567
    struct BaseClearableGraphComponentConcept {
klao@959
   568
      void constraints() {
klao@961
   569
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   570
	graph.clear();
klao@959
   571
      }
klao@959
   572
klao@959
   573
      Graph& graph;
klao@959
   574
    };
klao@959
   575
klao@959
   576
klao@961
   577
    class IterableGraphComponent :
klao@961
   578
      virtual public BaseIterableGraphComponent {
klao@959
   579
klao@959
   580
    public:
klao@959
   581
    
klao@959
   582
      typedef IterableGraphComponent Graph;
klao@959
   583
klao@959
   584
      typedef BaseGraphComponent::Node Node;
klao@959
   585
      typedef BaseGraphComponent::Edge Edge;
klao@959
   586
klao@959
   587
      class NodeIt : public Node {
klao@959
   588
      public:
klao@959
   589
	NodeIt() {}
klao@959
   590
	NodeIt(Invalid) {}
klao@961
   591
	// explicit NodeIt(Node) {}
klao@961
   592
	explicit NodeIt(const Graph&) {}
klao@959
   593
klao@959
   594
	NodeIt& operator++() { return *this; }
klao@959
   595
	//	Node operator*() const { return INVALID; }
klao@959
   596
klao@961
   597
	bool operator==(const NodeIt&) const { return true;}
klao@961
   598
	bool operator!=(const NodeIt&) const { return true;}
klao@959
   599
      };
klao@959
   600
klao@959
   601
      class EdgeIt : public Edge {
klao@959
   602
      public:
klao@959
   603
	EdgeIt() {}
klao@959
   604
	EdgeIt(Invalid) {}
klao@961
   605
	// explicit EdgeIt(Edge) {}
klao@961
   606
	explicit EdgeIt(const Graph&) {}
klao@959
   607
klao@959
   608
	EdgeIt& operator++() { return *this; }
klao@959
   609
	//	Edge operator*() const { return INVALID; }
klao@959
   610
klao@961
   611
	bool operator==(const EdgeIt&) const { return true;}
klao@961
   612
	bool operator!=(const EdgeIt&) const { return true;}
klao@959
   613
      };
klao@959
   614
klao@959
   615
      class InEdgeIt : public Edge {
klao@959
   616
      public:
klao@959
   617
	InEdgeIt() {}
klao@959
   618
	InEdgeIt(Invalid) {}
klao@961
   619
	// explicit InEdgeIt(Edge) {}
klao@961
   620
	explicit InEdgeIt(const Graph&, const Node&) {}
klao@959
   621
klao@959
   622
	InEdgeIt& operator++() { return *this; }
klao@959
   623
	//	Edge operator*() const { return INVALID; }
klao@959
   624
klao@961
   625
	bool operator==(const InEdgeIt&) const { return true;}
klao@961
   626
	bool operator!=(const InEdgeIt&) const { return true;}
klao@959
   627
      };
klao@959
   628
klao@959
   629
      class OutEdgeIt : public Edge {
klao@959
   630
      public:
klao@959
   631
	OutEdgeIt() {}
klao@959
   632
	OutEdgeIt(Invalid) {}
klao@961
   633
	// explicit OutEdgeIt(Edge) {}
klao@961
   634
	explicit OutEdgeIt(const Graph&, const Node&) {}
klao@959
   635
klao@959
   636
	OutEdgeIt& operator++() { return *this; }
klao@959
   637
	//	Edge operator*() const { return INVALID; }
klao@959
   638
klao@961
   639
	bool operator==(const OutEdgeIt&) const { return true;}
klao@961
   640
	bool operator!=(const OutEdgeIt&) const { return true;}
klao@959
   641
      };
klao@959
   642
klao@959
   643
    };
klao@959
   644
    
klao@959
   645
    template <typename Graph> 
klao@959
   646
    struct IterableGraphComponentConcept {
klao@959
   647
      void constraints() {
klao@961
   648
  	function_requires< BaseIterableGraphComponentConcept<Graph> >();
klao@961
   649
klao@959
   650
	typedef typename Graph::Node Node;
klao@959
   651
	typedef typename Graph::NodeIt NodeIt;
klao@959
   652
	typedef typename Graph::Edge Edge;
klao@959
   653
	typedef typename Graph::EdgeIt EdgeIt;
klao@959
   654
	typedef typename Graph::InEdgeIt InEdgeIt;
klao@959
   655
	typedef typename Graph::OutEdgeIt OutEdgeIt;
klao@959
   656
  
klao@961
   657
	function_requires< GraphIteratorConcept<NodeIt, Graph, Node> >();
klao@961
   658
	function_requires< GraphIteratorConcept<EdgeIt, Graph, Edge> >();
klao@961
   659
	function_requires< GraphIncIteratorConcept<OutEdgeIt, Graph> >();
klao@961
   660
	function_requires< GraphIncIteratorConcept<InEdgeIt, Graph> >();
klao@959
   661
      }
klao@959
   662
    };
klao@959
   663
klao@959
   664
klao@959
   665
    class IdMappableGraphComponent : virtual public BaseGraphComponent {
klao@959
   666
klao@959
   667
      typedef IdMappableGraphComponent Graph;
klao@959
   668
klao@961
   669
    public:
klao@961
   670
klao@959
   671
      typedef BaseGraphComponent::Node Node;
klao@959
   672
      typedef BaseGraphComponent::Edge Edge;
klao@959
   673
klao@959
   674
      class NodeIdMap : public ReadMap<Node, int> {
klao@959
   675
      public:
klao@959
   676
	NodeIdMap(const Graph&) {}
klao@959
   677
	int maxId() const { return -1;}
klao@959
   678
      };
klao@959
   679
klao@959
   680
      class EdgeIdMap : public ReadMap<Edge, int> {
klao@959
   681
      public:
klao@959
   682
	EdgeIdMap(const Graph&) {}
klao@959
   683
	int maxId() const { return -1;}
klao@959
   684
      };
klao@959
   685
klao@959
   686
    };
klao@959
   687
    
klao@959
   688
    template <typename Graph>
klao@959
   689
    struct IdMappableGraphComponentConcept {
klao@959
   690
      void constraints() {	
klao@961
   691
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   692
	{
klao@959
   693
	  typedef typename Graph::EdgeIdMap EdgeIdMap;
klao@959
   694
	  function_requires<ReadMapConcept<EdgeIdMap> >();
klao@959
   695
	  EdgeIdMap edge_map(graph);
klao@959
   696
	  int n = edge_map.maxId();
klao@959
   697
	  ignore_unused_variable_warning(n);
klao@959
   698
	}
klao@959
   699
	{
klao@959
   700
	  typedef typename Graph::NodeIdMap NodeIdMap;
klao@959
   701
	  function_requires<ReadMapConcept<NodeIdMap> >();
klao@959
   702
	  NodeIdMap node_map(graph);
klao@959
   703
	  int n = node_map.maxId();
klao@959
   704
	  ignore_unused_variable_warning(n);
klao@959
   705
	}
klao@959
   706
      }
klao@959
   707
      Graph& graph;
klao@959
   708
    };
klao@959
   709
klao@959
   710
klao@959
   711
    class MappableGraphComponent : virtual public BaseGraphComponent {
klao@959
   712
    public:
klao@959
   713
klao@959
   714
      typedef MappableGraphComponent Graph;
klao@959
   715
klao@959
   716
      typedef BaseGraphComponent::Node Node;
klao@959
   717
      typedef BaseGraphComponent::Edge Edge;
klao@959
   718
klao@959
   719
      template <typename Value>
klao@959
   720
      class NodeMap : public ReferenceMap<Node, Value> {
klao@959
   721
      public:
klao@959
   722
	NodeMap(const Graph&) {}
klao@959
   723
	NodeMap(const Graph&, const Value&) {}
klao@959
   724
	NodeMap(const NodeMap&) {}
klao@959
   725
klao@959
   726
	NodeMap& operator=(const NodeMap&) { return *this;}
klao@959
   727
	
klao@959
   728
      };
klao@959
   729
klao@959
   730
      template <typename Value>
klao@959
   731
      class EdgeMap : public ReferenceMap<Edge, Value> {
klao@959
   732
      public:
klao@959
   733
	EdgeMap(const Graph&) {}
klao@959
   734
	EdgeMap(const Graph&, const Value&) {}
klao@959
   735
	EdgeMap(const EdgeMap&) {}
klao@959
   736
klao@959
   737
	EdgeMap& operator=(const EdgeMap&) { return *this;}
klao@959
   738
	
klao@959
   739
      };
klao@959
   740
klao@959
   741
    };
klao@959
   742
klao@959
   743
    template <typename Graph>
klao@959
   744
    struct MappableGraphComponentConcept {
klao@959
   745
klao@959
   746
      struct Type {
klao@959
   747
	int value;
klao@959
   748
	Type() : value(0) {}
klao@959
   749
	Type(int _v) : value(_v) {}
klao@959
   750
      };
klao@959
   751
klao@959
   752
      void constraints() {
klao@961
   753
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   754
	{ // int map test
klao@959
   755
	  typedef typename Graph::template NodeMap<int> IntNodeMap;
klao@959
   756
	  function_requires<GraphMapConcept<IntNodeMap,Graph> >();
klao@959
   757
	} { // bool map test
klao@959
   758
	  typedef typename Graph::template NodeMap<bool> BoolNodeMap;
klao@959
   759
	  function_requires<GraphMapConcept<BoolNodeMap,Graph> >();
klao@959
   760
	} { // Type map test
klao@959
   761
	  typedef typename Graph::template NodeMap<Type> TypeNodeMap;
klao@959
   762
	  function_requires<GraphMapConcept<TypeNodeMap,Graph> >();
klao@959
   763
	} 
klao@959
   764
klao@959
   765
	{ // int map test
klao@959
   766
	  typedef typename Graph::template EdgeMap<int> IntEdgeMap;
klao@959
   767
	  function_requires<GraphMapConcept<IntEdgeMap,Graph> >();
klao@959
   768
	} { // bool map test
klao@959
   769
	  typedef typename Graph::template EdgeMap<bool> BoolEdgeMap;
klao@959
   770
	  function_requires<GraphMapConcept<BoolEdgeMap,Graph> >();
klao@959
   771
	} { // Type map test
klao@959
   772
	  typedef typename Graph::template EdgeMap<Type> TypeEdgeMap;
klao@959
   773
	  function_requires<GraphMapConcept<TypeEdgeMap,Graph> >();
klao@959
   774
	} 
klao@959
   775
      }
klao@959
   776
klao@959
   777
      Graph& graph;
klao@959
   778
    };
klao@959
   779
klao@959
   780
klao@959
   781
    class ExtendableGraphComponent : virtual public BaseGraphComponent {
klao@959
   782
    public:
klao@959
   783
klao@959
   784
      typedef ExtendableGraphComponent Graph;
klao@959
   785
klao@959
   786
      typedef BaseGraphComponent::Node Node;
klao@959
   787
      typedef BaseGraphComponent::Edge Edge;
klao@959
   788
klao@959
   789
      Node addNode() {
klao@959
   790
	return INVALID;
klao@959
   791
      }
klao@959
   792
    
klao@959
   793
      Edge addEdge(const Node& from, const Node& to) {
klao@959
   794
	return INVALID;
klao@959
   795
      }
klao@959
   796
klao@959
   797
    };
klao@959
   798
klao@959
   799
    template <typename Graph>
klao@959
   800
    struct ExtendableGraphComponentConcept {
klao@959
   801
      void constraints() {
klao@961
   802
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   803
	typename Graph::Node node_a, node_b;
klao@959
   804
	node_a = graph.addNode();
klao@959
   805
	typename Graph::Edge edge;
klao@959
   806
	edge = graph.addEdge(node_a, node_b);      
klao@959
   807
      }
klao@959
   808
      Graph& graph;
klao@959
   809
    };
klao@959
   810
klao@959
   811
    class ErasableGraphComponent : virtual public BaseGraphComponent {
klao@959
   812
    public:
klao@959
   813
klao@959
   814
      typedef ErasableGraphComponent Graph;
klao@959
   815
klao@959
   816
      typedef BaseGraphComponent::Node Node;
klao@959
   817
      typedef BaseGraphComponent::Edge Edge;
klao@959
   818
klao@959
   819
      void erase(const Node&) {}    
klao@959
   820
      void erase(const Edge&) {}
klao@959
   821
klao@959
   822
    };
klao@959
   823
klao@959
   824
    template <typename Graph>
klao@959
   825
    struct ErasableGraphComponentConcept {
klao@959
   826
      void constraints() {
klao@961
   827
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   828
	typename Graph::Node node;
klao@959
   829
	graph.erase(node);
klao@959
   830
	typename Graph::Edge edge;
klao@959
   831
	graph.erase(edge);      
klao@959
   832
      }
klao@959
   833
klao@959
   834
      Graph& graph;
klao@959
   835
    };
klao@959
   836
klao@959
   837
    class ClearableGraphComponent : virtual public BaseGraphComponent {
klao@959
   838
    public:
klao@959
   839
klao@959
   840
      typedef ClearableGraphComponent Graph;
klao@959
   841
klao@959
   842
      typedef BaseGraphComponent::Node Node;
klao@959
   843
      typedef BaseGraphComponent::Edge Edge;
klao@959
   844
klao@959
   845
      void clear() {}    
klao@959
   846
klao@959
   847
    };
klao@959
   848
klao@959
   849
    template <typename Graph>
klao@959
   850
    struct ClearableGraphComponentConcept {
klao@959
   851
      void constraints() {
klao@961
   852
	function_requires< BaseGraphComponentConcept<Graph> >();
klao@959
   853
	graph.clear();
klao@959
   854
      }
klao@959
   855
      Graph& graph;
klao@959
   856
    };
klao@959
   857
klao@959
   858
  }
klao@959
   859
klao@959
   860
}
klao@959
   861
klao@959
   862
#endif