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