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