src/lemon/concept/graph_component.h
author jacint
Thu, 20 Jan 2005 10:24:38 +0000
changeset 1090 9e9195331ea6
parent 1030 c8a41699e613
child 1106 0a7d604a9763
permissions -rw-r--r--
resetPos deleted
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
klao@959
   300
      /// Gives back an unique integer id for the Edge. 
klao@959
   301
klao@959
   302
      /// Gives back an unique integer id for the Edge. 
klao@959
   303
      ///
klao@959
   304
      int id(const Edge&) const { return -1;}
klao@959
   305
deba@989
   306
      template <typename _Graph>
deba@989
   307
      struct Constraints {
klao@959
   308
deba@989
   309
	void constraints() {
deba@989
   310
	  checkConcept< BaseGraphComponent, _Graph >();
deba@989
   311
	  typename _Graph::Node node;
deba@989
   312
	  int nid = graph.id(node);
deba@989
   313
	  nid = graph.id(node);
deba@989
   314
	  typename _Graph::Edge edge;
deba@989
   315
	  int eid = graph.id(edge);
deba@989
   316
	  eid = graph.id(edge);
deba@989
   317
	}
klao@959
   318
deba@989
   319
	const _Graph& graph;
deba@989
   320
      };
klao@959
   321
    };
klao@959
   322
klao@959
   323
klao@959
   324
    /// An empty max-idable base graph class.
klao@959
   325
  
klao@959
   326
    /// This class provides beside the core graph features
klao@959
   327
    /// core max id functions for the graph structure.
klao@959
   328
    /// The most of the base graphs should be conform to this concept.
klao@959
   329
    /// The id's are unique and immutable.
klao@959
   330
    class MaxIDableGraphComponent : virtual public BaseGraphComponent {
klao@959
   331
    public:
klao@959
   332
klao@959
   333
      /// Gives back an integer greater or equal to the maximum Node id. 
klao@959
   334
klao@959
   335
      /// Gives back an integer greater or equal to the maximum Node id. 
klao@959
   336
      ///
deba@980
   337
      int maxId(Node = INVALID) const { return -1;}
klao@959
   338
klao@959
   339
      /// Gives back an integer greater or equal to the maximum Edge id. 
klao@959
   340
klao@959
   341
      /// Gives back an integer greater or equal to the maximum Edge id. 
klao@959
   342
      ///
deba@980
   343
      int maxId(Edge = INVALID) const { return -1;}
klao@959
   344
deba@989
   345
      template <typename _Graph>
deba@989
   346
      struct Constraints {
klao@959
   347
deba@989
   348
	void constraints() {
deba@989
   349
	  checkConcept<BaseGraphComponent, _Graph>();
deba@989
   350
	  int nid = graph.maxId(typename _Graph::Node());
deba@989
   351
	  ignore_unused_variable_warning(nid);
deba@989
   352
	  int eid = graph.maxId(typename _Graph::Edge());
deba@989
   353
	  ignore_unused_variable_warning(eid);
deba@989
   354
	}
deba@989
   355
      
deba@989
   356
	const _Graph& graph;
deba@989
   357
      };
klao@959
   358
    };
klao@959
   359
klao@959
   360
    /// An empty extendable base graph class.
klao@959
   361
  
klao@959
   362
    /// This class provides beside the core graph features
klao@959
   363
    /// core graph extend interface for the graph structure.
klao@959
   364
    /// The most of the base graphs should be conform to this concept.
klao@959
   365
    class BaseExtendableGraphComponent : virtual public BaseGraphComponent {
klao@959
   366
    public:
klao@959
   367
klao@959
   368
      typedef BaseGraphComponent::Node Node;
klao@959
   369
      typedef BaseGraphComponent::Edge Edge;
klao@959
   370
klao@959
   371
      /// Adds a new Node to the graph.
klao@959
   372
klao@959
   373
      /// Adds a new Node to the graph.
klao@959
   374
      ///
klao@959
   375
      Node addNode() {
klao@959
   376
	return INVALID;
klao@959
   377
      }
klao@959
   378
    
klao@959
   379
      /// Adds a new Edge connects the two Nodes to the graph.
klao@959
   380
klao@959
   381
      /// Adds a new Edge connects the two Nodes to the graph.
klao@959
   382
      ///
klao@959
   383
      Edge addEdge(const Node& from, const Node& to) {
klao@959
   384
	return INVALID;
klao@959
   385
      }
klao@959
   386
deba@989
   387
      template <typename _Graph>
deba@989
   388
      struct Constraints {
deba@989
   389
	void constraints() {
deba@989
   390
	  checkConcept<BaseGraphComponent, _Graph >();
deba@989
   391
	  typename _Graph::Node node_a, node_b;
deba@989
   392
	  node_a = graph.addNode();
deba@989
   393
	  typename _Graph::Edge edge;
deba@989
   394
	  edge = graph.addEdge(node_a, node_b);
deba@989
   395
	}
klao@959
   396
deba@989
   397
	_Graph& graph;
deba@989
   398
      };
klao@959
   399
    };
klao@959
   400
klao@959
   401
    /// An empty erasable base graph class.
klao@959
   402
  
klao@959
   403
    /// This class provides beside the core graph features
klao@959
   404
    /// core erase functions for the graph structure.
klao@959
   405
    /// The most of the base graphs should be conform to this concept.
klao@959
   406
    class BaseErasableGraphComponent : virtual public BaseGraphComponent {
klao@959
   407
    public:
klao@959
   408
klao@959
   409
      typedef BaseGraphComponent::Node Node;
klao@959
   410
      typedef BaseGraphComponent::Edge Edge;
klao@959
   411
klao@959
   412
      /// Erase a Node from the graph.
klao@959
   413
      
klao@959
   414
      /// Erase a Node from the graph. This function should not
klao@959
   415
      /// erase edges connecting to the Node.
klao@959
   416
      void erase(const Node&) {}    
klao@959
   417
klao@959
   418
      /// Erase an Edge from the graph.
klao@959
   419
klao@959
   420
      /// Erase an Edge from the graph.
klao@959
   421
      ///
klao@959
   422
      void erase(const Edge&) {}
klao@959
   423
deba@989
   424
      template <typename _Graph>
deba@989
   425
      struct Constraints {
deba@989
   426
	void constraints() {
deba@989
   427
	  checkConcept<BaseGraphComponent, _Graph>();
deba@989
   428
	  typename _Graph::Node node;
deba@989
   429
	  graph.erase(node);
deba@989
   430
	  typename _Graph::Edge edge;
deba@989
   431
	  graph.erase(edge);
deba@989
   432
	}
klao@959
   433
deba@989
   434
	_Graph& graph;
deba@989
   435
      };
klao@959
   436
    };
klao@959
   437
klao@959
   438
    /// An empty clearable base graph class.
klao@959
   439
  
klao@959
   440
    /// This class provides beside the core graph features
klao@959
   441
    /// core clear functions for the graph structure.
klao@959
   442
    /// The most of the base graphs should be conform to this concept.
klao@1022
   443
    class ClearableGraphComponent : virtual public BaseGraphComponent {
klao@959
   444
    public:
klao@959
   445
klao@959
   446
      /// Erase all the Nodes and Edges from the graph.
klao@959
   447
klao@959
   448
      /// Erase all the Nodes and Edges from the graph.
klao@959
   449
      ///
klao@959
   450
      void clear() {}    
deba@989
   451
deba@989
   452
      template <typename _Graph>
deba@989
   453
      struct Constraints {
deba@989
   454
	void constraints() {
klao@1022
   455
	  checkConcept<BaseGraphComponent, _Graph>();
deba@989
   456
	  graph.clear();
deba@989
   457
	}
deba@989
   458
klao@1022
   459
	_Graph graph;
deba@989
   460
      };
klao@959
   461
    };
klao@959
   462
klao@959
   463
deba@989
   464
    /// Skeleton class for graph NodeIt and EdgeIt
deba@989
   465
deba@989
   466
    /// Skeleton class for graph NodeIt and EdgeIt.
klao@959
   467
    ///
deba@989
   468
    template <typename _Graph, typename _Item>
deba@989
   469
    class GraphIterator : public _Item {
deba@989
   470
    public:
deba@989
   471
      /// \todo Don't we need the Item type as typedef?
klao@959
   472
deba@989
   473
      /// Default constructor.
deba@989
   474
      
deba@989
   475
      /// @warning The default constructor sets the iterator
deba@989
   476
      /// to an undefined value.
deba@989
   477
      GraphIterator() {}
deba@989
   478
      /// Copy constructor.
deba@989
   479
      
deba@989
   480
      /// Copy constructor.
deba@989
   481
      ///
deba@989
   482
      GraphIterator(GraphIterator const&) {}
deba@989
   483
      /// Sets the iterator to the first item.
deba@989
   484
      
deba@989
   485
      /// Sets the iterator to the first item of \c the graph.
deba@989
   486
      ///
deba@989
   487
      explicit GraphIterator(const _Graph&) {}
deba@989
   488
      /// Invalid constructor \& conversion.
deba@989
   489
deba@989
   490
      /// This constructor initializes the item to be invalid.
deba@989
   491
      /// \sa Invalid for more details.
deba@989
   492
      GraphIterator(Invalid) {}
deba@989
   493
      /// Assign operator for items.
deba@989
   494
deba@989
   495
      /// The items are assignable. 
deba@989
   496
      ///
deba@989
   497
      GraphIterator& operator=(GraphIterator const&) { return *this; }      
deba@989
   498
      /// Next item.
deba@989
   499
deba@989
   500
      /// Assign the iterator to the next item.
deba@989
   501
      ///
deba@989
   502
      GraphIterator& operator++() { return *this; }
deba@989
   503
      //	Node operator*() const { return INVALID; }
deba@989
   504
      /// Equality operator
deba@989
   505
deba@989
   506
      /// Two iterators are equal if and only if they point to the
deba@989
   507
      /// same object or both are invalid.
deba@989
   508
      bool operator==(const GraphIterator&) const { return true;}
deba@989
   509
      /// Inequality operator
deba@989
   510
	
deba@989
   511
      /// \sa operator==(Node n)
deba@989
   512
      ///
deba@989
   513
      bool operator!=(const GraphIterator&) const { return true;}
deba@989
   514
      
deba@989
   515
      template<typename _GraphIterator>
deba@989
   516
      struct Constraints {
deba@989
   517
	void constraints() {
deba@989
   518
	  //	  checkConcept< Item, _GraphIterator >();
deba@989
   519
	  _GraphIterator it1(g);
deba@989
   520
	
deba@989
   521
	  /// \todo Do we need NodeIt(Node) kind of constructor?
deba@989
   522
	  //	_GraphIterator it2(bj);
deba@989
   523
	  _GraphIterator it2;
deba@989
   524
deba@989
   525
	  it2 = ++it1;
deba@989
   526
	  ++it2 = it1;
deba@989
   527
	  ++(++it1);
deba@989
   528
	  /// \bug This should be: is_base_and_derived<BaseItem, _GraphIterator>
deba@989
   529
	  _Item bi = it1;
deba@989
   530
	  bi = it2;
deba@989
   531
	}
deba@989
   532
	_Graph& g;
deba@989
   533
      };
klao@959
   534
    };
klao@959
   535
deba@989
   536
    /// Skeleton class for graph InEdgeIt and OutEdgeIt
klao@959
   537
deba@989
   538
    /// \note Because InEdgeIt and OutEdgeIt may not inherit from the same
deba@989
   539
    /// base class, the _selector is a additional template parameter. For 
deba@989
   540
    /// InEdgeIt you should instantiate it with character 'i' and for 
deba@989
   541
    /// OutEdgeIt with 'o'.
klao@1021
   542
    /// \todo Is this a good name for this concept?
klao@1021
   543
    template <typename Graph,
klao@1021
   544
	      typename Edge = typename Graph::Edge,
klao@1021
   545
	      char _selector = '0'>
klao@1021
   546
    class GraphIncIterator : public Edge {
deba@989
   547
    public:
deba@989
   548
      /// Default constructor.
deba@989
   549
      
deba@989
   550
      /// @warning The default constructor sets the iterator
deba@989
   551
      /// to an undefined value.
klao@1021
   552
      GraphIncIterator() {}
deba@989
   553
      /// Copy constructor.
deba@989
   554
      
deba@989
   555
      /// Copy constructor.
deba@989
   556
      ///
klao@1021
   557
      GraphIncIterator(GraphIncIterator const&) {}
deba@989
   558
      /// Sets the iterator to the first edge incoming into or outgoing from the node.
deba@989
   559
      
deba@989
   560
      /// Sets the iterator to the first edge incoming into or outgoing from the node.
deba@989
   561
      ///
klao@1021
   562
      explicit GraphIncIterator(const Graph&, const typename Graph::Node&) {}
deba@989
   563
      /// Invalid constructor \& conversion.
deba@989
   564
deba@989
   565
      /// This constructor initializes the item to be invalid.
deba@989
   566
      /// \sa Invalid for more details.
klao@1021
   567
      GraphIncIterator(Invalid) {}
deba@989
   568
      /// Assign operator for nodes.
deba@989
   569
deba@989
   570
      /// The nodes are assignable. 
deba@989
   571
      ///
klao@1021
   572
      GraphIncIterator& operator=(GraphIncIterator const&) { return *this; }      
deba@989
   573
      /// Next edge.
deba@989
   574
deba@989
   575
      /// Assign the iterator to the next node.
deba@989
   576
      ///
klao@1021
   577
      GraphIncIterator& operator++() { return *this; }
klao@1021
   578
deba@989
   579
      //	Node operator*() const { return INVALID; }
klao@1021
   580
deba@989
   581
      /// Equality operator
deba@989
   582
deba@989
   583
      /// Two iterators are equal if and only if they point to the
deba@989
   584
      /// same object or both are invalid.
klao@1021
   585
      bool operator==(const GraphIncIterator&) const { return true;}
klao@1021
   586
deba@989
   587
      /// Inequality operator
deba@989
   588
	
deba@989
   589
      /// \sa operator==(Node n)
deba@989
   590
      ///
klao@1021
   591
      bool operator!=(const GraphIncIterator&) const { return true;}
deba@989
   592
klao@1021
   593
      template <typename _GraphIncIterator>
deba@989
   594
      struct Constraints {
klao@1021
   595
	typedef typename Graph::Node Node;
deba@989
   596
	void constraints() {
klao@1021
   597
	  checkConcept<GraphItem<'e'>, _GraphIncIterator>();
klao@1021
   598
	  _GraphIncIterator it1(graph, node);
deba@989
   599
	  /// \todo Do we need OutEdgeIt(Edge) kind of constructor?
klao@1021
   600
	  //	_GraphIncIterator it2(edge);
klao@1021
   601
	  _GraphIncIterator it2;
deba@989
   602
deba@989
   603
	  it2 = ++it1;
deba@989
   604
	  ++it2 = it1;
deba@989
   605
	  ++(++it1);
deba@989
   606
	  Edge e = it1;
deba@989
   607
	  e = it2;
deba@989
   608
	}
deba@989
   609
deba@989
   610
	Edge& edge;
deba@989
   611
	Node& node;
klao@1021
   612
	Graph& graph;
deba@989
   613
      };
deba@989
   614
    };
klao@1021
   615
klao@1021
   616
deba@989
   617
    /// An empty iterable base graph class.
deba@989
   618
  
deba@989
   619
    /// This class provides beside the core graph features
deba@989
   620
    /// iterator based iterable interface for the graph structure.
deba@989
   621
    /// This concept is part of the StaticGraphConcept.
deba@989
   622
    class IterableGraphComponent : virtual public BaseGraphComponent {
klao@959
   623
klao@959
   624
    public:
klao@959
   625
    
klao@959
   626
      typedef IterableGraphComponent Graph;
klao@959
   627
klao@959
   628
      typedef BaseGraphComponent::Node Node;
klao@959
   629
      typedef BaseGraphComponent::Edge Edge;
klao@959
   630
deba@989
   631
      /// This iterator goes through each node.
klao@959
   632
deba@989
   633
      /// This iterator goes through each node.
deba@989
   634
      ///
deba@989
   635
      typedef GraphIterator<Graph, Node> NodeIt;
deba@989
   636
      /// This iterator goes through each node.
klao@959
   637
deba@989
   638
      /// This iterator goes through each node.
deba@989
   639
      ///
deba@989
   640
      typedef GraphIterator<Graph, Edge> EdgeIt;
deba@989
   641
      /// This iterator goes trough the incoming edges of a node.
klao@959
   642
deba@989
   643
      /// This iterator goes trough the \e inccoming edges of a certain node
deba@989
   644
      /// of a graph.
klao@1021
   645
      typedef GraphIncIterator<Graph, Edge, 'i'> InEdgeIt;
deba@989
   646
      /// This iterator goes trough the outgoing edges of a node.
klao@959
   647
deba@989
   648
      /// This iterator goes trough the \e outgoing edges of a certain node
deba@989
   649
      /// of a graph.
klao@1021
   650
      typedef GraphIncIterator<Graph, Edge, 'o'> OutEdgeIt;
deba@989
   651
    };
deba@989
   652
    
deba@989
   653
    template <typename _Graph> 
deba@989
   654
    struct Constraints {
deba@989
   655
      void constraints() {
deba@989
   656
  	checkConcept< BaseGraphComponent, _Graph>();
klao@959
   657
deba@989
   658
	checkConcept<GraphIterator<_Graph, typename _Graph::Edge>, typename _Graph::EdgeIt >();
deba@989
   659
	checkConcept<GraphIterator<_Graph, typename _Graph::Node>, typename _Graph::NodeIt >();
klao@1021
   660
	checkConcept<GraphIncIterator<_Graph>, typename _Graph::InEdgeIt >();
klao@1021
   661
	checkConcept<GraphIncIterator<_Graph>, typename _Graph::OutEdgeIt >();
deba@989
   662
      }
deba@989
   663
    };
klao@959
   664
klao@959
   665
klao@1030
   666
    /// Class describing the concept of graph maps
klao@1030
   667
klao@1030
   668
    /// This class describes the common interface of the graph maps
alpar@1043
   669
    /// (NodeMap, EdgeMap), that is \ref maps-pages "maps" which can be used to
klao@1030
   670
    /// associate data to graph descriptors (nodes or edges).
deba@989
   671
    template <typename Graph, typename Item, typename _Value>
deba@989
   672
    class GraphMap : public ReadWriteMap<Item, _Value> {
deba@989
   673
    protected:      
deba@989
   674
      GraphMap() {}
deba@989
   675
    public:
deba@989
   676
      explicit GraphMap(const Graph&) {}
deba@989
   677
      GraphMap(const Graph&, const _Value&) {}
deba@989
   678
      GraphMap(const GraphMap&) {}
deba@989
   679
      
deba@989
   680
      GraphMap& operator=(const GraphMap&) { return *this;}
klao@959
   681
deba@989
   682
      template<typename _Map>
deba@989
   683
      struct Constraints {
deba@989
   684
	void constraints() {
deba@989
   685
	  checkConcept<ReadWriteMap<Item, _Value>, _Map >();
deba@989
   686
	  // Construction with a graph parameter
deba@989
   687
	  _Map a(g);
deba@989
   688
	  // Constructor with a graph and a default value parameter
deba@989
   689
	  _Map a2(g,t);
deba@989
   690
	  // Copy constructor. Do we need it?
deba@989
   691
	  _Map b=c;
deba@989
   692
	  // Copy operator. Do we need it?
deba@989
   693
	  a=b;
klao@959
   694
deba@989
   695
	  ignore_unused_variable_warning(a2);
deba@989
   696
	}
klao@959
   697
deba@989
   698
	const _Map &c;
deba@989
   699
	const Graph &g;
deba@989
   700
	const typename GraphMap::Value &t;
klao@959
   701
      };
klao@959
   702
klao@959
   703
    };
klao@961
   704
deba@989
   705
    /// An empty mappable base graph class.
klao@959
   706
  
deba@989
   707
    /// This class provides beside the core graph features
deba@989
   708
    /// map interface for the graph structure.
deba@989
   709
    /// This concept is part of the StaticGraphConcept.
klao@959
   710
    class MappableGraphComponent : virtual public BaseGraphComponent {
klao@959
   711
    public:
klao@959
   712
klao@959
   713
      typedef MappableGraphComponent Graph;
klao@959
   714
klao@959
   715
      typedef BaseGraphComponent::Node Node;
klao@959
   716
      typedef BaseGraphComponent::Edge Edge;
klao@959
   717
deba@989
   718
      /// ReadWrite map of the nodes.
deba@989
   719
    
deba@989
   720
      /// ReadWrite map of the nodes.
deba@989
   721
      ///
alpar@987
   722
      template <typename _Value>
deba@989
   723
      class NodeMap : public GraphMap<Graph, Node, _Value> {
deba@989
   724
      private:
deba@989
   725
	NodeMap();
klao@959
   726
      public:
deba@989
   727
	// \todo call the right parent class constructor
deba@989
   728
	explicit NodeMap(const Graph&) {}
alpar@987
   729
	NodeMap(const Graph&, const _Value&) {}
klao@959
   730
	NodeMap(const NodeMap&) {}
klao@959
   731
klao@959
   732
	NodeMap& operator=(const NodeMap&) { return *this;}
deba@989
   733
klao@959
   734
      };
klao@959
   735
deba@989
   736
      /// ReadWrite map of the edges.
deba@989
   737
    
deba@989
   738
      /// ReadWrite map of the edges.
deba@989
   739
      ///
alpar@987
   740
      template <typename _Value>
deba@989
   741
      class EdgeMap : public GraphMap<Graph, Edge, _Value> {
deba@989
   742
      private:
deba@989
   743
	EdgeMap();
klao@959
   744
      public:
deba@989
   745
	// \todo call the right parent class constructor
deba@989
   746
	explicit EdgeMap(const Graph&) {}
alpar@987
   747
	EdgeMap(const Graph&, const _Value&) {}
klao@959
   748
	EdgeMap(const EdgeMap&) {}
klao@959
   749
klao@959
   750
	EdgeMap& operator=(const EdgeMap&) { return *this;}
deba@989
   751
klao@959
   752
      };
klao@959
   753
deba@989
   754
      template <typename _Graph>
deba@989
   755
      struct Constraints {
klao@959
   756
deba@989
   757
	struct Type {
deba@989
   758
	  int value;
deba@989
   759
	  Type() : value(0) {}
deba@989
   760
	  Type(int _v) : value(_v) {}
deba@989
   761
	};
klao@959
   762
deba@989
   763
	void constraints() {
deba@989
   764
	  checkConcept<BaseGraphComponent, _Graph>();
deba@989
   765
	  { // int map test
deba@989
   766
	    typedef typename _Graph::template NodeMap<int> IntNodeMap;
deba@989
   767
	    checkConcept<GraphMap<_Graph, typename _Graph::Node, int>, IntNodeMap >();
deba@989
   768
	  } { // bool map test
deba@989
   769
	    typedef typename _Graph::template NodeMap<bool> BoolNodeMap;
deba@989
   770
	    checkConcept<GraphMap<_Graph, typename _Graph::Node, bool>, BoolNodeMap >();
deba@989
   771
	  } { // Type map test
deba@989
   772
	    typedef typename _Graph::template NodeMap<Type> TypeNodeMap;
deba@989
   773
	    checkConcept<GraphMap<_Graph, typename _Graph::Node, Type>, TypeNodeMap >();
deba@989
   774
	  } 
deba@989
   775
deba@989
   776
	  { // int map test
deba@989
   777
	    typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
deba@989
   778
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>, IntEdgeMap >();
deba@989
   779
	  } { // bool map test
deba@989
   780
	    typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
deba@989
   781
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>, BoolEdgeMap >();
deba@989
   782
	  } { // Type map test
deba@989
   783
	    typedef typename _Graph::template EdgeMap<Type> TypeEdgeMap;
deba@989
   784
	    checkConcept<GraphMap<_Graph, typename _Graph::Edge, Type>, TypeEdgeMap >();
deba@989
   785
	  } 
deba@989
   786
	}
deba@989
   787
deba@989
   788
	_Graph& graph;
klao@959
   789
      };
klao@959
   790
    };
klao@959
   791
klao@959
   792
klao@959
   793
    class ExtendableGraphComponent : virtual public BaseGraphComponent {
klao@959
   794
    public:
klao@959
   795
klao@959
   796
      typedef ExtendableGraphComponent Graph;
klao@959
   797
klao@959
   798
      typedef BaseGraphComponent::Node Node;
klao@959
   799
      typedef BaseGraphComponent::Edge Edge;
klao@959
   800
klao@959
   801
      Node addNode() {
klao@959
   802
	return INVALID;
klao@959
   803
      }
klao@959
   804
    
klao@959
   805
      Edge addEdge(const Node& from, const Node& to) {
klao@959
   806
	return INVALID;
klao@959
   807
      }
klao@959
   808
deba@989
   809
      template <typename _Graph>
deba@989
   810
      struct Constraints {
deba@989
   811
	void constraints() {
deba@989
   812
	  checkConcept<BaseGraphComponent, _Graph >();
deba@989
   813
	  typename _Graph::Node node_a, node_b;
deba@989
   814
	  node_a = graph.addNode();
deba@989
   815
	  typename _Graph::Edge edge;
deba@989
   816
	  edge = graph.addEdge(node_a, node_b);      
deba@989
   817
	}
deba@989
   818
	_Graph& graph;
deba@989
   819
      };
klao@959
   820
    };
klao@959
   821
    class ErasableGraphComponent : virtual public BaseGraphComponent {
klao@959
   822
    public:
klao@959
   823
klao@959
   824
      typedef ErasableGraphComponent Graph;
klao@959
   825
klao@959
   826
      typedef BaseGraphComponent::Node Node;
klao@959
   827
      typedef BaseGraphComponent::Edge Edge;
klao@959
   828
klao@959
   829
      void erase(const Node&) {}    
klao@959
   830
      void erase(const Edge&) {}
klao@959
   831
deba@989
   832
      template <typename _Graph>
deba@989
   833
      struct Constraints {
deba@989
   834
	void constraints() {
deba@989
   835
	  checkConcept<BaseGraphComponent, _Graph >();
deba@989
   836
	  typename _Graph::Node node;
deba@989
   837
	  graph.erase(node);
deba@989
   838
	  typename _Graph::Edge edge;
deba@989
   839
	  graph.erase(edge);      
deba@989
   840
	}
klao@959
   841
deba@989
   842
	_Graph& graph;
deba@989
   843
      };
klao@959
   844
    };
klao@959
   845
klao@1030
   846
    /// @}
klao@1030
   847
klao@959
   848
  }
klao@959
   849
klao@959
   850
}
klao@959
   851
klao@959
   852
#endif