src/lemon/concept/graph.h
author deba
Thu, 11 Nov 2004 10:17:20 +0000
changeset 981 2e34b796d532
parent 959 c80ef5912903
child 986 e997802b855c
permissions -rw-r--r--
maxUndirEdgeId modified to maxId(UndirEdge)
maxEdgeId modified to maxId(Edge)
klao@959
     1
/* -*- C++ -*-
klao@959
     2
 * src/lemon/concept/graph.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
#ifndef LEMON_CONCEPT_GRAPH_H
klao@959
    18
#define LEMON_CONCEPT_GRAPH_H
klao@959
    19
klao@959
    20
///\ingroup concept
klao@959
    21
///\file
klao@959
    22
///\brief Declaration of Graph.
klao@959
    23
klao@959
    24
#include <lemon/invalid.h>
klao@959
    25
#include <lemon/concept/maps.h>
klao@959
    26
#include <lemon/concept_check.h>
klao@959
    27
#include <lemon/concept/graph_component.h>
klao@959
    28
klao@959
    29
namespace lemon {
klao@959
    30
  namespace concept {
klao@959
    31
    
klao@959
    32
    /// \addtogroup concept
klao@959
    33
    /// @{
klao@959
    34
klao@959
    35
//     /// An empty static graph class.
klao@959
    36
  
klao@959
    37
//     /// This class provides all the common features of a graph structure,
klao@959
    38
//     /// however completely without implementations and real data structures
klao@959
    39
//     /// behind the interface.
klao@959
    40
//     /// All graph algorithms should compile with this class, but it will not
klao@959
    41
//     /// run properly, of course.
klao@959
    42
//     ///
klao@959
    43
//     /// It can be used for checking the interface compatibility,
klao@959
    44
//     /// or it can serve as a skeleton of a new graph structure.
klao@959
    45
//     /// 
klao@959
    46
//     /// Also, you will find here the full documentation of a certain graph
klao@959
    47
//     /// feature, the documentation of a real graph imlementation
klao@959
    48
//     /// like @ref ListGraph or
klao@959
    49
//     /// @ref SmartGraph will just refer to this structure.
klao@959
    50
//     ///
klao@959
    51
//     /// \todo A pages describing the concept of concept description would
klao@959
    52
//     /// be nice.
klao@959
    53
//     class StaticGraph
klao@959
    54
//     {
klao@959
    55
//     public:
klao@959
    56
//       /// Defalult constructor.
klao@959
    57
klao@959
    58
//       /// Defalult constructor.
klao@959
    59
//       ///
klao@959
    60
//       StaticGraph() { }
klao@959
    61
//       ///Copy consructor.
klao@959
    62
klao@959
    63
// //       ///\todo It is not clear, what we expect from a copy constructor.
klao@959
    64
// //       ///E.g. How to assign the nodes/edges to each other? What about maps?
klao@959
    65
// //       StaticGraph(const StaticGraph& g) { }
klao@959
    66
klao@959
    67
//       /// The base type of node iterators, 
klao@959
    68
//       /// or in other words, the trivial node iterator.
klao@959
    69
klao@959
    70
//       /// This is the base type of each node iterator,
klao@959
    71
//       /// thus each kind of node iterator converts to this.
klao@959
    72
//       /// More precisely each kind of node iterator should be inherited 
klao@959
    73
//       /// from the trivial node iterator.
klao@959
    74
//       class Node {
klao@959
    75
//       public:
klao@959
    76
// 	/// Default constructor
klao@959
    77
klao@959
    78
// 	/// @warning The default constructor sets the iterator
klao@959
    79
// 	/// to an undefined value.
klao@959
    80
// 	Node() { }
klao@959
    81
// 	/// Copy constructor.
klao@959
    82
klao@959
    83
// 	/// Copy constructor.
klao@959
    84
// 	///
klao@959
    85
// 	Node(const Node&) { }
klao@959
    86
klao@959
    87
// 	/// Invalid constructor \& conversion.
klao@959
    88
klao@959
    89
// 	/// This constructor initializes the iterator to be invalid.
klao@959
    90
// 	/// \sa Invalid for more details.
klao@959
    91
// 	Node(Invalid) { }
klao@959
    92
// 	/// Equality operator
klao@959
    93
klao@959
    94
// 	/// Two iterators are equal if and only if they point to the
klao@959
    95
// 	/// same object or both are invalid.
klao@959
    96
// 	bool operator==(Node) const { return true; }
klao@959
    97
klao@959
    98
// 	/// Inequality operator
klao@959
    99
	
klao@959
   100
// 	/// \sa operator==(Node n)
klao@959
   101
// 	///
klao@959
   102
// 	bool operator!=(Node) const { return true; }
klao@959
   103
klao@959
   104
//  	///Comparison operator.
klao@959
   105
klao@959
   106
// 	///This is a strict ordering between the nodes.
klao@959
   107
// 	///
klao@959
   108
// 	///This ordering can be different from the order in which NodeIt
klao@959
   109
// 	///goes through the nodes.
klao@959
   110
// 	///\todo Possibly we don't need it.
klao@959
   111
// 	bool operator<(Node) const { return true; }
klao@959
   112
//       };
klao@959
   113
    
klao@959
   114
//       /// This iterator goes through each node.
klao@959
   115
klao@959
   116
//       /// This iterator goes through each node.
klao@959
   117
//       /// Its usage is quite simple, for example you can count the number
klao@959
   118
//       /// of nodes in graph \c g of type \c Graph like this:
klao@959
   119
//       /// \code
klao@959
   120
//       /// int count=0;
klao@959
   121
//       /// for (Graph::NodeIt n(g); n!=INVALID ++n) ++count;
klao@959
   122
//       /// \endcode
klao@959
   123
//       class NodeIt : public Node {
klao@959
   124
//       public:
klao@959
   125
// 	/// Default constructor
klao@959
   126
klao@959
   127
// 	/// @warning The default constructor sets the iterator
klao@959
   128
// 	/// to an undefined value.
klao@959
   129
// 	NodeIt() { }
klao@959
   130
// 	/// Copy constructor.
klao@959
   131
	
klao@959
   132
// 	/// Copy constructor.
klao@959
   133
// 	///
klao@959
   134
// 	NodeIt(const NodeIt&) { }
klao@959
   135
// 	/// Invalid constructor \& conversion.
klao@959
   136
klao@959
   137
// 	/// Initialize the iterator to be invalid.
klao@959
   138
// 	/// \sa Invalid for more details.
klao@959
   139
// 	NodeIt(Invalid) { }
klao@959
   140
// 	/// Sets the iterator to the first node.
klao@959
   141
klao@959
   142
// 	/// Sets the iterator to the first node of \c g.
klao@959
   143
// 	///
klao@959
   144
// 	NodeIt(const StaticGraph& g) { }
klao@959
   145
// 	/// Node -> NodeIt conversion.
klao@959
   146
klao@959
   147
// 	/// Sets the iterator to the node of \c g pointed by the trivial 
klao@959
   148
// 	/// iterator n.
klao@959
   149
// 	/// This feature necessitates that each time we 
klao@959
   150
// 	/// iterate the edge-set, the iteration order is the same.
klao@959
   151
// 	NodeIt(const StaticGraph& g, const Node& n) { }
klao@959
   152
// 	/// Next node.
klao@959
   153
klao@959
   154
// 	/// Assign the iterator to the next node.
klao@959
   155
// 	///
klao@959
   156
// 	NodeIt& operator++() { return *this; }
klao@959
   157
//       };
klao@959
   158
    
klao@959
   159
    
klao@959
   160
//       /// The base type of the edge iterators.
klao@959
   161
klao@959
   162
//       /// The base type of the edge iterators.
klao@959
   163
//       ///
klao@959
   164
//       class Edge {
klao@959
   165
//       public:
klao@959
   166
// 	/// Default constructor
klao@959
   167
klao@959
   168
// 	/// @warning The default constructor sets the iterator
klao@959
   169
// 	/// to an undefined value.
klao@959
   170
// 	Edge() { }
klao@959
   171
// 	/// Copy constructor.
klao@959
   172
klao@959
   173
// 	/// Copy constructor.
klao@959
   174
// 	///
klao@959
   175
// 	Edge(const Edge&) { }
klao@959
   176
// 	/// Initialize the iterator to be invalid.
klao@959
   177
klao@959
   178
// 	/// Initialize the iterator to be invalid.
klao@959
   179
// 	///
klao@959
   180
// 	Edge(Invalid) { }
klao@959
   181
// 	/// Equality operator
klao@959
   182
klao@959
   183
// 	/// Two iterators are equal if and only if they point to the
klao@959
   184
// 	/// same object or both are invalid.
klao@959
   185
// 	bool operator==(Edge) const { return true; }
klao@959
   186
// 	/// Inequality operator
klao@959
   187
klao@959
   188
// 	/// \sa operator==(Node n)
klao@959
   189
// 	///
klao@959
   190
// 	bool operator!=(Edge) const { return true; }
klao@959
   191
//  	///Comparison operator.
klao@959
   192
klao@959
   193
// 	///This is a strict ordering between the nodes.
klao@959
   194
// 	///
klao@959
   195
// 	///This ordering can be different from the order in which NodeIt
klao@959
   196
// 	///goes through the nodes.
klao@959
   197
// 	///\todo Possibly we don't need it.
klao@959
   198
//  	bool operator<(Edge) const { return true; }
klao@959
   199
//       };
klao@959
   200
    
klao@959
   201
//       /// This iterator goes trough the outgoing edges of a node.
klao@959
   202
klao@959
   203
//       /// This iterator goes trough the \e outgoing edges of a certain node
klao@959
   204
//       /// of a graph.
klao@959
   205
//       /// Its usage is quite simple, for example you can count the number
klao@959
   206
//       /// of outgoing edges of a node \c n
klao@959
   207
//       /// in graph \c g of type \c Graph as follows.
klao@959
   208
//       /// \code
klao@959
   209
//       /// int count=0;
klao@959
   210
//       /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
klao@959
   211
//       /// \endcode
klao@959
   212
    
klao@959
   213
//       class OutEdgeIt : public Edge {
klao@959
   214
//       public:
klao@959
   215
// 	/// Default constructor
klao@959
   216
klao@959
   217
// 	/// @warning The default constructor sets the iterator
klao@959
   218
// 	/// to an undefined value.
klao@959
   219
// 	OutEdgeIt() { }
klao@959
   220
// 	/// Copy constructor.
klao@959
   221
klao@959
   222
// 	/// Copy constructor.
klao@959
   223
// 	///
klao@959
   224
// 	OutEdgeIt(const OutEdgeIt&) { }
klao@959
   225
// 	/// Initialize the iterator to be invalid.
klao@959
   226
klao@959
   227
// 	/// Initialize the iterator to be invalid.
klao@959
   228
// 	///
klao@959
   229
// 	OutEdgeIt(Invalid) { }
klao@959
   230
// 	/// This constructor sets the iterator to first outgoing edge.
klao@959
   231
    
klao@959
   232
// 	/// This constructor set the iterator to the first outgoing edge of
klao@959
   233
// 	/// node
klao@959
   234
// 	///@param n the node
klao@959
   235
// 	///@param g the graph
klao@959
   236
// 	OutEdgeIt(const StaticGraph& g, const Node& n) { }
klao@959
   237
// 	/// Edge -> OutEdgeIt conversion
klao@959
   238
klao@959
   239
// 	/// Sets the iterator to the value of the trivial iterator \c e.
klao@959
   240
// 	/// This feature necessitates that each time we 
klao@959
   241
// 	/// iterate the edge-set, the iteration order is the same.
klao@959
   242
// 	OutEdgeIt(const StaticGraph& g, const Edge& e) { }
klao@959
   243
// 	///Next outgoing edge
klao@959
   244
	
klao@959
   245
// 	/// Assign the iterator to the next 
klao@959
   246
// 	/// outgoing edge of the corresponding node.
klao@959
   247
// 	OutEdgeIt& operator++() { return *this; }
klao@959
   248
//       };
klao@959
   249
klao@959
   250
//       /// This iterator goes trough the incoming edges of a node.
klao@959
   251
klao@959
   252
//       /// This iterator goes trough the \e incoming edges of a certain node
klao@959
   253
//       /// of a graph.
klao@959
   254
//       /// Its usage is quite simple, for example you can count the number
klao@959
   255
//       /// of outgoing edges of a node \c n
klao@959
   256
//       /// in graph \c g of type \c Graph as follows.
klao@959
   257
//       /// \code
klao@959
   258
//       /// int count=0;
klao@959
   259
//       /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
klao@959
   260
//       /// \endcode
klao@959
   261
klao@959
   262
//       class InEdgeIt : public Edge {
klao@959
   263
//       public:
klao@959
   264
// 	/// Default constructor
klao@959
   265
klao@959
   266
// 	/// @warning The default constructor sets the iterator
klao@959
   267
// 	/// to an undefined value.
klao@959
   268
// 	InEdgeIt() { }
klao@959
   269
// 	/// Copy constructor.
klao@959
   270
klao@959
   271
// 	/// Copy constructor.
klao@959
   272
// 	///
klao@959
   273
// 	InEdgeIt(const InEdgeIt&) { }
klao@959
   274
// 	/// Initialize the iterator to be invalid.
klao@959
   275
klao@959
   276
// 	/// Initialize the iterator to be invalid.
klao@959
   277
// 	///
klao@959
   278
// 	InEdgeIt(Invalid) { }
klao@959
   279
// 	/// This constructor sets the iterator to first incoming edge.
klao@959
   280
    
klao@959
   281
// 	/// This constructor set the iterator to the first incoming edge of
klao@959
   282
// 	/// node
klao@959
   283
// 	///@param n the node
klao@959
   284
// 	///@param g the graph
klao@959
   285
// 	InEdgeIt(const StaticGraph& g, const Node& n) { }
klao@959
   286
// 	/// Edge -> InEdgeIt conversion
klao@959
   287
klao@959
   288
// 	/// Sets the iterator to the value of the trivial iterator \c e.
klao@959
   289
// 	/// This feature necessitates that each time we 
klao@959
   290
// 	/// iterate the edge-set, the iteration order is the same.
klao@959
   291
// 	InEdgeIt(const StaticGraph& g, const Edge& n) { }
klao@959
   292
// 	/// Next incoming edge
klao@959
   293
klao@959
   294
// 	/// Assign the iterator to the next inedge of the corresponding node.
klao@959
   295
// 	///
klao@959
   296
// 	InEdgeIt& operator++() { return *this; }
klao@959
   297
//       };
klao@959
   298
//       /// This iterator goes through each edge.
klao@959
   299
klao@959
   300
//       /// This iterator goes through each edge of a graph.
klao@959
   301
//       /// Its usage is quite simple, for example you can count the number
klao@959
   302
//       /// of edges in a graph \c g of type \c Graph as follows:
klao@959
   303
//       /// \code
klao@959
   304
//       /// int count=0;
klao@959
   305
//       /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
klao@959
   306
//       /// \endcode
klao@959
   307
//       class EdgeIt : public Edge {
klao@959
   308
//       public:
klao@959
   309
// 	/// Default constructor
klao@959
   310
klao@959
   311
// 	/// @warning The default constructor sets the iterator
klao@959
   312
// 	/// to an undefined value.
klao@959
   313
// 	EdgeIt() { }
klao@959
   314
// 	/// Copy constructor.
klao@959
   315
klao@959
   316
// 	/// Copy constructor.
klao@959
   317
// 	///
klao@959
   318
// 	EdgeIt(const EdgeIt&) { }
klao@959
   319
// 	/// Initialize the iterator to be invalid.
klao@959
   320
klao@959
   321
// 	/// Initialize the iterator to be invalid.
klao@959
   322
// 	///
klao@959
   323
// 	EdgeIt(Invalid) { }
klao@959
   324
// 	/// This constructor sets the iterator to first edge.
klao@959
   325
    
klao@959
   326
// 	/// This constructor set the iterator to the first edge of
klao@959
   327
// 	/// node
klao@959
   328
// 	///@param g the graph
klao@959
   329
// 	EdgeIt(const StaticGraph& g) { }
klao@959
   330
// 	/// Edge -> EdgeIt conversion
klao@959
   331
klao@959
   332
// 	/// Sets the iterator to the value of the trivial iterator \c e.
klao@959
   333
// 	/// This feature necessitates that each time we 
klao@959
   334
// 	/// iterate the edge-set, the iteration order is the same.
klao@959
   335
// 	EdgeIt(const StaticGraph&, const Edge&) { } 
klao@959
   336
//     	///Next edge
klao@959
   337
	
klao@959
   338
// 	/// Assign the iterator to the next 
klao@959
   339
// 	/// edge of the corresponding node.
klao@959
   340
// 	EdgeIt& operator++() { return *this; }
klao@959
   341
//       };
klao@959
   342
klao@959
   343
//       /// First node of the graph.
klao@959
   344
klao@959
   345
//       /// \retval i the first node.
klao@959
   346
//       /// \return the first node.
klao@959
   347
//       ///
klao@959
   348
//       NodeIt& first(NodeIt& i) const { return i; }
klao@959
   349
klao@959
   350
//       /// The first incoming edge.
klao@959
   351
klao@959
   352
//       /// The first incoming edge.
klao@959
   353
//       ///
klao@959
   354
//       InEdgeIt& first(InEdgeIt &i, Node) const { return i; }
klao@959
   355
//       /// The first outgoing edge.
klao@959
   356
klao@959
   357
//       /// The first outgoing edge.
klao@959
   358
//       ///
klao@959
   359
//       OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; }
klao@959
   360
//       /// The first edge of the Graph.
klao@959
   361
klao@959
   362
//       /// The first edge of the Graph.
klao@959
   363
//       ///
klao@959
   364
//       EdgeIt& first(EdgeIt& i) const { return i; }
klao@959
   365
klao@959
   366
//       ///Gives back the head node of an edge.
klao@959
   367
klao@959
   368
//       ///Gives back the head node of an edge.
klao@959
   369
//       ///
klao@959
   370
//       Node head(Edge) const { return INVALID; }
klao@959
   371
//       ///Gives back the tail node of an edge.
klao@959
   372
klao@959
   373
//       ///Gives back the tail node of an edge.
klao@959
   374
//       ///
klao@959
   375
//       Node tail(Edge) const { return INVALID; }
klao@959
   376
  
klao@959
   377
//       ///Gives back the \e id of a node.
klao@959
   378
klao@959
   379
//       ///\warning Not all graph structures provide this feature.
klao@959
   380
//       ///
klao@959
   381
//       ///\todo Should each graph provide \c id?
klao@959
   382
//       int id(const Node&) const { return 0; }
klao@959
   383
//       ///Gives back the \e id of an edge.
klao@959
   384
klao@959
   385
//       ///\warning Not all graph structures provide this feature.
klao@959
   386
//       ///
klao@959
   387
//       ///\todo Should each graph provide \c id?
klao@959
   388
//       int id(const Edge&) const { return 0; }
klao@959
   389
klao@959
   390
//       ///\e
klao@959
   391
      
klao@959
   392
//       ///\todo Should it be in the concept?
klao@959
   393
//       ///
klao@959
   394
//       int nodeNum() const { return 0; }
klao@959
   395
//       ///\e
klao@959
   396
klao@959
   397
//       ///\todo Should it be in the concept?
klao@959
   398
//       ///
klao@959
   399
//       int edgeNum() const { return 0; }
klao@959
   400
klao@959
   401
klao@959
   402
//       ///Reference map of the nodes to type \c T.
klao@959
   403
klao@959
   404
//       /// \ingroup concept
klao@959
   405
//       ///Reference map of the nodes to type \c T.
klao@959
   406
//       /// \sa Reference
klao@959
   407
//       /// \warning Making maps that can handle bool type (NodeMap<bool>)
klao@959
   408
//       /// needs some extra attention!
klao@959
   409
//       template<class T> class NodeMap : public ReferenceMap< Node, T >
klao@959
   410
//       {
klao@959
   411
//       public:
klao@959
   412
klao@959
   413
// 	///\e
klao@959
   414
// 	NodeMap(const StaticGraph&) { }
klao@959
   415
// 	///\e
klao@959
   416
// 	NodeMap(const StaticGraph&, T) { }
klao@959
   417
klao@959
   418
// 	///Copy constructor
klao@959
   419
// 	template<typename TT> NodeMap(const NodeMap<TT>&) { }
klao@959
   420
// 	///Assignment operator
klao@959
   421
// 	template<typename TT> NodeMap& operator=(const NodeMap<TT>&)
klao@959
   422
// 	{ return *this; }
klao@959
   423
//       };
klao@959
   424
klao@959
   425
//       ///Reference map of the edges to type \c T.
klao@959
   426
klao@959
   427
//       /// \ingroup concept
klao@959
   428
//       ///Reference map of the edges to type \c T.
klao@959
   429
//       /// \sa Reference
klao@959
   430
//       /// \warning Making maps that can handle bool type (EdgeMap<bool>)
klao@959
   431
//       /// needs some extra attention!
klao@959
   432
//       template<class T> class EdgeMap
klao@959
   433
// 	: public ReferenceMap<Edge,T>
klao@959
   434
//       {
klao@959
   435
//       public:
klao@959
   436
klao@959
   437
// 	///\e
klao@959
   438
// 	EdgeMap(const StaticGraph&) { }
klao@959
   439
// 	///\e
klao@959
   440
// 	EdgeMap(const StaticGraph&, T) { }
klao@959
   441
    
klao@959
   442
// 	///Copy constructor
klao@959
   443
// 	template<typename TT> EdgeMap(const EdgeMap<TT>&) { }
klao@959
   444
// 	///Assignment operator
klao@959
   445
// 	template<typename TT> EdgeMap &operator=(const EdgeMap<TT>&)
klao@959
   446
// 	{ return *this; }
klao@959
   447
//       };
klao@959
   448
//     };
klao@959
   449
klao@959
   450
//     struct DummyType {
klao@959
   451
//       int value;
klao@959
   452
//       DummyType() {}
klao@959
   453
//       DummyType(int p) : value(p) {}
klao@959
   454
//       DummyType& operator=(int p) { value = p; return *this;}
klao@959
   455
//     };
klao@959
   456
    
klao@959
   457
//     ///\brief Checks whether \c G meets the
klao@959
   458
//     ///\ref lemon::concept::StaticGraph "StaticGraph" concept
klao@959
   459
//     template<class Graph> void checkCompileStaticGraph(Graph &G) 
klao@959
   460
//     {
klao@959
   461
//       typedef typename Graph::Node Node;
klao@959
   462
//       typedef typename Graph::NodeIt NodeIt;
klao@959
   463
//       typedef typename Graph::Edge Edge;
klao@959
   464
//       typedef typename Graph::EdgeIt EdgeIt;
klao@959
   465
//       typedef typename Graph::InEdgeIt InEdgeIt;
klao@959
   466
//       typedef typename Graph::OutEdgeIt OutEdgeIt;
klao@959
   467
  
klao@959
   468
//       {
klao@959
   469
// 	Node i; Node j(i); Node k(INVALID);
klao@959
   470
// 	i=j;
klao@959
   471
// 	bool b; b=true;
klao@959
   472
// 	b=(i==INVALID); b=(i!=INVALID);
klao@959
   473
// 	b=(i==j); b=(i!=j); b=(i<j);
klao@959
   474
//       }
klao@959
   475
//       {
klao@959
   476
// 	NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
klao@959
   477
// 	i=j;
klao@959
   478
// 	j=G.first(i);
klao@959
   479
// 	j=++i;
klao@959
   480
// 	bool b; b=true;
klao@959
   481
// 	b=(i==INVALID); b=(i!=INVALID);
klao@959
   482
// 	Node n(i);
klao@959
   483
// 	n=i;
klao@959
   484
// 	b=(i==j); b=(i!=j); b=(i<j);
klao@959
   485
// 	//Node ->NodeIt conversion
klao@959
   486
// 	NodeIt ni(G,n);
klao@959
   487
//       }
klao@959
   488
//       {
klao@959
   489
// 	Edge i; Edge j(i); Edge k(INVALID);
klao@959
   490
// 	i=j;
klao@959
   491
// 	bool b; b=true;
klao@959
   492
// 	b=(i==INVALID); b=(i!=INVALID);
klao@959
   493
// 	b=(i==j); b=(i!=j); b=(i<j);
klao@959
   494
//       }
klao@959
   495
//       {
klao@959
   496
// 	EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
klao@959
   497
// 	i=j;
klao@959
   498
// 	j=G.first(i);
klao@959
   499
// 	j=++i;
klao@959
   500
// 	bool b; b=true;
klao@959
   501
// 	b=(i==INVALID); b=(i!=INVALID);
klao@959
   502
// 	Edge e(i);
klao@959
   503
// 	e=i;
klao@959
   504
// 	b=(i==j); b=(i!=j); b=(i<j);
klao@959
   505
// 	//Edge ->EdgeIt conversion
klao@959
   506
// 	EdgeIt ei(G,e);
klao@959
   507
//       }
klao@959
   508
//       {
klao@959
   509
// 	Node n;
klao@959
   510
// 	InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
klao@959
   511
// 	i=j;
klao@959
   512
// 	j=G.first(i,n);
klao@959
   513
// 	j=++i;
klao@959
   514
// 	bool b; b=true;
klao@959
   515
// 	b=(i==INVALID); b=(i!=INVALID);
klao@959
   516
// 	Edge e(i);
klao@959
   517
// 	e=i;
klao@959
   518
// 	b=(i==j); b=(i!=j); b=(i<j);
klao@959
   519
// 	//Edge ->InEdgeIt conversion
klao@959
   520
// 	InEdgeIt ei(G,e);
klao@959
   521
//       }
klao@959
   522
//       {
klao@959
   523
// 	Node n;
klao@959
   524
// 	OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
klao@959
   525
// 	i=j;
klao@959
   526
// 	j=G.first(i,n);
klao@959
   527
// 	j=++i;
klao@959
   528
// 	bool b; b=true;
klao@959
   529
// 	b=(i==INVALID); b=(i!=INVALID);
klao@959
   530
// 	Edge e(i);
klao@959
   531
// 	e=i;
klao@959
   532
// 	b=(i==j); b=(i!=j); b=(i<j);
klao@959
   533
// 	//Edge ->OutEdgeIt conversion
klao@959
   534
// 	OutEdgeIt ei(G,e);
klao@959
   535
//       }
klao@959
   536
//       {
klao@959
   537
// 	Node n,m;
klao@959
   538
// 	n=m=INVALID;
klao@959
   539
// 	Edge e;
klao@959
   540
// 	e=INVALID;
klao@959
   541
// 	n=G.tail(e);
klao@959
   542
// 	n=G.head(e);
klao@959
   543
//       }
klao@959
   544
//       // id tests
klao@959
   545
//       { Node n; int i=G.id(n); i=i; }
klao@959
   546
//       { Edge e; int i=G.id(e); i=i; }
klao@959
   547
//       //NodeMap tests
klao@959
   548
//       {
klao@959
   549
// 	Node k;
klao@959
   550
// 	typename Graph::template NodeMap<int> m(G);
klao@959
   551
// 	//Const map
klao@959
   552
// 	typename Graph::template NodeMap<int> const &cm = m;
klao@959
   553
// 	//Inicialize with default value
klao@959
   554
// 	typename Graph::template NodeMap<int> mdef(G,12);
klao@959
   555
// 	//Copy
klao@959
   556
// 	typename Graph::template NodeMap<int> mm(cm);
klao@959
   557
// 	//Copy from another type
klao@959
   558
// 	typename Graph::template NodeMap<double> dm(cm);
klao@959
   559
// 	//Copy to more complex type
klao@959
   560
// 	typename Graph::template NodeMap<DummyType> em(cm);
klao@959
   561
// 	int v;
klao@959
   562
// 	v=m[k]; m[k]=v; m.set(k,v);
klao@959
   563
// 	v=cm[k];
klao@959
   564
    
klao@959
   565
// 	m=cm;  
klao@959
   566
// 	dm=cm; //Copy from another type  
klao@959
   567
// 	em=cm; //Copy to more complex type
klao@959
   568
// 	{
klao@959
   569
// 	  //Check the typedef's
klao@959
   570
// 	  typename Graph::template NodeMap<int>::ValueType val;
klao@959
   571
// 	  val=1;
klao@959
   572
// 	  typename Graph::template NodeMap<int>::KeyType key;
klao@959
   573
// 	  key = typename Graph::NodeIt(G);
klao@959
   574
// 	}
klao@959
   575
//       }  
klao@959
   576
//       { //bool NodeMap
klao@959
   577
// 	Node k;
klao@959
   578
// 	typename Graph::template NodeMap<bool> m(G);
klao@959
   579
// 	typename Graph::template NodeMap<bool> const &cm = m;  //Const map
klao@959
   580
// 	//Inicialize with default value
klao@959
   581
// 	typename Graph::template NodeMap<bool> mdef(G,12);
klao@959
   582
// 	typename Graph::template NodeMap<bool> mm(cm);   //Copy
klao@959
   583
// 	typename Graph::template NodeMap<int> dm(cm); //Copy from another type
klao@959
   584
// 	bool v;
klao@959
   585
// 	v=m[k]; m[k]=v; m.set(k,v);
klao@959
   586
// 	v=cm[k];
klao@959
   587
    
klao@959
   588
// 	m=cm;  
klao@959
   589
// 	dm=cm; //Copy from another type
klao@959
   590
// 	m=dm; //Copy to another type
klao@959
   591
klao@959
   592
// 	{
klao@959
   593
// 	  //Check the typedef's
klao@959
   594
// 	  typename Graph::template NodeMap<bool>::ValueType val;
klao@959
   595
// 	  val=true;
klao@959
   596
// 	  typename Graph::template NodeMap<bool>::KeyType key;
klao@959
   597
// 	  key= typename Graph::NodeIt(G);
klao@959
   598
// 	}
klao@959
   599
//       }
klao@959
   600
//       //EdgeMap tests
klao@959
   601
//       {
klao@959
   602
// 	Edge k;
klao@959
   603
// 	typename Graph::template EdgeMap<int> m(G);
klao@959
   604
// 	typename Graph::template EdgeMap<int> const &cm = m;  //Const map
klao@959
   605
// 	//Inicialize with default value
klao@959
   606
// 	typename Graph::template EdgeMap<int> mdef(G,12);
klao@959
   607
// 	typename Graph::template EdgeMap<int> mm(cm);   //Copy
klao@959
   608
// 	typename Graph::template EdgeMap<double> dm(cm);//Copy from another type
klao@959
   609
// 	int v;
klao@959
   610
// 	v=m[k]; m[k]=v; m.set(k,v);
klao@959
   611
// 	v=cm[k];
klao@959
   612
    
klao@959
   613
// 	m=cm;  
klao@959
   614
// 	dm=cm; //Copy from another type
klao@959
   615
// 	{
klao@959
   616
// 	  //Check the typedef's
klao@959
   617
// 	  typename Graph::template EdgeMap<int>::ValueType val;
klao@959
   618
// 	  val=1;
klao@959
   619
// 	  typename Graph::template EdgeMap<int>::KeyType key;
klao@959
   620
// 	  key= typename Graph::EdgeIt(G);
klao@959
   621
// 	}
klao@959
   622
//       }  
klao@959
   623
//       { //bool EdgeMap
klao@959
   624
// 	Edge k;
klao@959
   625
// 	typename Graph::template EdgeMap<bool> m(G);
klao@959
   626
// 	typename Graph::template EdgeMap<bool> const &cm = m;  //Const map
klao@959
   627
// 	//Inicialize with default value
klao@959
   628
// 	typename Graph::template EdgeMap<bool> mdef(G,12);
klao@959
   629
// 	typename Graph::template EdgeMap<bool> mm(cm);   //Copy
klao@959
   630
// 	typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
klao@959
   631
// 	bool v;
klao@959
   632
// 	v=m[k]; m[k]=v; m.set(k,v);
klao@959
   633
// 	v=cm[k];
klao@959
   634
    
klao@959
   635
// 	m=cm;  
klao@959
   636
// 	dm=cm; //Copy from another type
klao@959
   637
// 	m=dm; //Copy to another type
klao@959
   638
// 	{
klao@959
   639
// 	  //Check the typedef's
klao@959
   640
// 	  typename Graph::template EdgeMap<bool>::ValueType val;
klao@959
   641
// 	  val=true;
klao@959
   642
// 	  typename Graph::template EdgeMap<bool>::KeyType key;
klao@959
   643
// 	  key= typename Graph::EdgeIt(G);
klao@959
   644
// 	}
klao@959
   645
//       }
klao@959
   646
//     }
klao@959
   647
    
klao@959
   648
//     /// An empty non-static graph class.
klao@959
   649
    
klao@959
   650
//     /// This class provides everything that \ref StaticGraph
klao@959
   651
//     /// with additional functionality which enables to build a
klao@959
   652
//     /// graph from scratch.
klao@959
   653
//     class ExtendableGraph : public StaticGraph
klao@959
   654
//     {
klao@959
   655
//     public:
klao@959
   656
//       /// Defalult constructor.
klao@959
   657
klao@959
   658
//       /// Defalult constructor.
klao@959
   659
//       ///
klao@959
   660
//       ExtendableGraph() { }
klao@959
   661
//       ///Add a new node to the graph.
klao@959
   662
klao@959
   663
//       /// \return the new node.
klao@959
   664
//       ///
klao@959
   665
//       Node addNode() { return INVALID; }
klao@959
   666
//       ///Add a new edge to the graph.
klao@959
   667
klao@959
   668
//       ///Add a new edge to the graph with tail node \c t
klao@959
   669
//       ///and head node \c h.
klao@959
   670
//       ///\return the new edge.
klao@959
   671
//       Edge addEdge(Node h, Node t) { return INVALID; }
klao@959
   672
    
klao@959
   673
//       /// Resets the graph.
klao@959
   674
klao@959
   675
//       /// This function deletes all edges and nodes of the graph.
klao@959
   676
//       /// It also frees the memory allocated to store them.
klao@959
   677
//       /// \todo It might belong to \ref ErasableGraph.
klao@959
   678
//       void clear() { }
klao@959
   679
//     };
klao@959
   680
klao@959
   681
    
klao@959
   682
//     ///\brief Checks whether \c G meets the
klao@959
   683
//     ///\ref lemon::concept::ExtendableGraph "ExtendableGraph" concept
klao@959
   684
//     template<class Graph> void checkCompileExtendableGraph(Graph &G) 
klao@959
   685
//     {
klao@959
   686
//       checkCompileStaticGraph(G);
klao@959
   687
klao@959
   688
//       typedef typename Graph::Node Node;
klao@959
   689
//       typedef typename Graph::NodeIt NodeIt;
klao@959
   690
//       typedef typename Graph::Edge Edge;
klao@959
   691
//       typedef typename Graph::EdgeIt EdgeIt;
klao@959
   692
//       typedef typename Graph::InEdgeIt InEdgeIt;
klao@959
   693
//       typedef typename Graph::OutEdgeIt OutEdgeIt;
klao@959
   694
  
klao@959
   695
//       Node n,m;
klao@959
   696
//       n=G.addNode();
klao@959
   697
//       m=G.addNode();
klao@959
   698
//       Edge e;
klao@959
   699
//       e=G.addEdge(n,m); 
klao@959
   700
  
klao@959
   701
//       //  G.clear();
klao@959
   702
//     }
klao@959
   703
klao@959
   704
klao@959
   705
//     /// An empty erasable graph class.
klao@959
   706
  
klao@959
   707
//     /// This class is an extension of \ref ExtendableGraph. It also makes it
klao@959
   708
//     /// possible to erase edges or nodes.
klao@959
   709
//     class ErasableGraph : public ExtendableGraph
klao@959
   710
//     {
klao@959
   711
//     public:
klao@959
   712
//       /// Defalult constructor.
klao@959
   713
klao@959
   714
//       /// Defalult constructor.
klao@959
   715
//       ///
klao@959
   716
//       ErasableGraph() { }
klao@959
   717
//       /// Deletes a node.
klao@959
   718
klao@959
   719
//       /// Deletes node \c n node.
klao@959
   720
//       ///
klao@959
   721
//       void erase(Node n) { }
klao@959
   722
//       /// Deletes an edge.
klao@959
   723
klao@959
   724
//       /// Deletes edge \c e edge.
klao@959
   725
//       ///
klao@959
   726
//       void erase(Edge e) { }
klao@959
   727
//     };
klao@959
   728
    
klao@959
   729
//     template<class Graph> void checkCompileGraphEraseEdge(Graph &G) 
klao@959
   730
//     {
klao@959
   731
//       typename Graph::Edge e;
klao@959
   732
//       G.erase(e);
klao@959
   733
//     }
klao@959
   734
klao@959
   735
//     template<class Graph> void checkCompileGraphEraseNode(Graph &G) 
klao@959
   736
//     {
klao@959
   737
//       typename Graph::Node n;
klao@959
   738
//       G.erase(n);
klao@959
   739
//     }
klao@959
   740
klao@959
   741
//     ///\brief Checks whether \c G meets the
klao@959
   742
//     ///\ref lemon::concept::EresableGraph "EresableGraph" concept
klao@959
   743
//     template<class Graph> void checkCompileErasableGraph(Graph &G) 
klao@959
   744
//     {
klao@959
   745
//       checkCompileExtendableGraph(G);
klao@959
   746
//       checkCompileGraphEraseNode(G);
klao@959
   747
//       checkCompileGraphEraseEdge(G);
klao@959
   748
//     }
klao@959
   749
klao@959
   750
//     ///Checks whether a graph has findEdge() member function.
klao@959
   751
    
klao@959
   752
//     ///\todo findEdge() might be a global function.
klao@959
   753
//     ///
klao@959
   754
//     template<class Graph> void checkCompileGraphFindEdge(Graph &G) 
klao@959
   755
//     {
klao@959
   756
//       typedef typename Graph::NodeIt Node;
klao@959
   757
//       typedef typename Graph::NodeIt NodeIt;
klao@959
   758
klao@959
   759
//       G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
klao@959
   760
//       G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));  
klao@959
   761
//     }
klao@959
   762
klao@959
   763
klao@959
   764
klao@959
   765
    /************* New GraphBase stuff **************/
klao@959
   766
klao@959
   767
klao@959
   768
    /// A minimal GraphBase concept
klao@959
   769
klao@959
   770
    /// This class describes a minimal concept which can be extended to a
klao@959
   771
    /// full-featured graph with \ref GraphFactory.
klao@959
   772
    class GraphBase {
klao@959
   773
    public:
klao@959
   774
klao@959
   775
      GraphBase() {}
klao@959
   776
klao@961
   777
      /// \bug Should we demand that Node and Edge be subclasses of the
klao@961
   778
      /// Graph class???
klao@959
   779
klao@961
   780
      typedef GraphItem<'n'> Node;
klao@961
   781
      typedef GraphItem<'e'> Edge;
klao@961
   782
klao@961
   783
//       class Node : public BaseGraphItem<'n'> {};
klao@961
   784
//       class Edge : public BaseGraphItem<'e'> {};
klao@959
   785
klao@959
   786
      // Graph operation
klao@959
   787
      void firstNode(Node &n) const { }
klao@959
   788
      void firstEdge(Edge &e) const { }
klao@959
   789
klao@959
   790
      void firstOutEdge(Edge &e, Node) const { }
klao@959
   791
      void firstInEdge(Edge &e, Node) const { }
klao@959
   792
klao@959
   793
      void nextNode(Node &n) const { }
klao@959
   794
      void nextEdge(Edge &e) const { }
klao@959
   795
klao@959
   796
klao@959
   797
      // Question: isn't it reasonable if this methods have a Node
klao@959
   798
      // parameter? Like this:
klao@959
   799
      // Edge& nextOut(Edge &e, Node) const { return e; }
klao@959
   800
      void nextOutEdge(Edge &e) const { }
klao@959
   801
      void nextInEdge(Edge &e) const { }
klao@959
   802
klao@959
   803
      Node head(Edge) const { return Node(); }
klao@959
   804
      Node tail(Edge) const { return Node(); }
klao@959
   805
      
klao@959
   806
klao@959
   807
      // Do we need id, nodeNum, edgeNum and co. in this basic graphbase
klao@959
   808
      // concept?
klao@959
   809
klao@959
   810
klao@959
   811
      // Maps.
klao@959
   812
      //
klao@959
   813
      // We need a special slimer concept which does not provide maps (it
klao@959
   814
      // wouldn't be strictly slimer, cause for map-factory id() & friends
klao@959
   815
      // a required...)
klao@959
   816
klao@959
   817
      template<typename T>
klao@959
   818
      class NodeMap : public GraphMap<Node, T, GraphBase> {};
klao@959
   819
klao@959
   820
      template<typename T>
klao@959
   821
      class EdgeMap : public GraphMap<Edge, T, GraphBase> {};
klao@959
   822
    };
klao@959
   823
klao@959
   824
klao@959
   825
klao@959
   826
klao@961
   827
    /**************** The full-featured graph concepts ****************/
klao@959
   828
klao@959
   829
    
klao@959
   830
    class StaticGraph 
klao@961
   831
      :  virtual public BaseGraphComponent,
klao@961
   832
	 public IterableGraphComponent, public MappableGraphComponent {
klao@959
   833
    public:
klao@959
   834
      typedef BaseGraphComponent::Node Node;
klao@959
   835
      typedef BaseGraphComponent::Edge Edge;
klao@959
   836
    };
klao@959
   837
klao@959
   838
    template <typename Graph>
klao@959
   839
    struct StaticGraphConcept {
klao@959
   840
      void constraints() {
klao@959
   841
	function_requires<IterableGraphComponentConcept<Graph> >();
klao@959
   842
	function_requires<MappableGraphComponentConcept<Graph> >();
klao@959
   843
      }
klao@959
   844
    };
klao@959
   845
klao@959
   846
    class ExtendableGraph 
klao@961
   847
      :  virtual public BaseGraphComponent, public StaticGraph,
klao@961
   848
	 public ExtendableGraphComponent, public ClearableGraphComponent {
klao@959
   849
    public:
klao@959
   850
      typedef BaseGraphComponent::Node Node;
klao@959
   851
      typedef BaseGraphComponent::Edge Edge;
klao@959
   852
    };
klao@959
   853
klao@959
   854
    template <typename Graph>
klao@959
   855
    struct ExtendableGraphConcept {
klao@959
   856
      void constraints() {
klao@959
   857
	function_requires<StaticGraphConcept<Graph> >();
klao@959
   858
	function_requires<ExtendableGraphComponentConcept<Graph> >();
klao@959
   859
	function_requires<ClearableGraphComponentConcept<Graph> >();
klao@959
   860
      }
klao@959
   861
    };
klao@959
   862
klao@959
   863
    class ErasableGraph 
klao@961
   864
      :  virtual public BaseGraphComponent, public ExtendableGraph,
klao@961
   865
	 public ErasableGraphComponent {
klao@959
   866
    public:
klao@959
   867
      typedef BaseGraphComponent::Node Node;
klao@959
   868
      typedef BaseGraphComponent::Edge Edge;
klao@959
   869
    };
klao@959
   870
klao@959
   871
    template <typename Graph>
klao@959
   872
    struct ErasableGraphConcept {
klao@959
   873
      void constraints() {
klao@959
   874
	function_requires<ExtendableGraphConcept<Graph> >();
klao@959
   875
	function_requires<ErasableGraphComponentConcept<Graph> >();
klao@959
   876
      }
klao@959
   877
    };
klao@959
   878
klao@959
   879
    // @}
klao@959
   880
  } //namespace concept  
klao@959
   881
} //namespace lemon
klao@959
   882
klao@959
   883
klao@959
   884
klao@959
   885
#endif // LEMON_CONCEPT_GRAPH_H