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