lemon/concept/graph.h
author alpar
Tue, 11 Jul 2006 16:09:49 +0000
changeset 2128 509846825ddf
parent 2126 2c8adbee9fa6
child 2132 783b1d583be3
permissions -rw-r--r--
- Disable the copy constructor and operator= of {List|Smart}[U]Graph.
- Improve graph doc
- Also put private members into the doc (if they are documented)
klao@959
     1
/* -*- C++ -*-
klao@959
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
klao@959
     8
 *
klao@959
     9
 * Permission to use, modify and distribute this software is granted
klao@959
    10
 * provided that this copyright notice appears in all copies. For
klao@959
    11
 * precise terms see the accompanying LICENSE file.
klao@959
    12
 *
klao@959
    13
 * This software is provided "AS IS" with no warranty of any kind,
klao@959
    14
 * express or implied, and with no claim as to its suitability for any
klao@959
    15
 * purpose.
klao@959
    16
 *
klao@959
    17
 */
klao@959
    18
klao@959
    19
#ifndef LEMON_CONCEPT_GRAPH_H
klao@959
    20
#define LEMON_CONCEPT_GRAPH_H
klao@959
    21
klao@1030
    22
///\ingroup graph_concepts
klao@959
    23
///\file
klao@959
    24
///\brief Declaration of Graph.
klao@959
    25
deba@1993
    26
#include <lemon/bits/invalid.h>
deba@1993
    27
#include <lemon/bits/utility.h>
klao@959
    28
#include <lemon/concept/maps.h>
klao@959
    29
#include <lemon/concept_check.h>
deba@2126
    30
#include <lemon/concept/graph_components.h>
klao@959
    31
klao@959
    32
namespace lemon {
klao@959
    33
  namespace concept {
deba@1136
    34
alpar@1620
    35
    /// \addtogroup graph_concepts
alpar@1620
    36
    /// @{
alpar@1620
    37
alpar@2117
    38
    /// The directed graph concept
alpar@2117
    39
alpar@2117
    40
    /// This class describes the \ref concept "concept" of the
alpar@2117
    41
    /// immutable directed graphs.
deba@1136
    42
    ///
alpar@2117
    43
    /// Note that actual graph implementation like @ref ListGraph or
alpar@2117
    44
    /// @ref SmartGraph may have several additional functionality.
deba@1136
    45
    ///
alpar@2117
    46
    /// \sa concept
deba@2111
    47
    class Graph {
deba@1136
    48
    public:
alpar@1448
    49
      ///\e
alpar@1448
    50
deba@1136
    51
      /// Defalult constructor.
deba@1136
    52
deba@1136
    53
      /// Defalult constructor.
deba@1136
    54
      ///
deba@2111
    55
      Graph() { }
alpar@2128
    56
      /// Class for identifying a node of the graph
deba@1136
    57
alpar@2128
    58
      /// This class identifies a node of the graph. It also serves
alpar@2128
    59
      /// as a base class of the node iterators,
alpar@2128
    60
      /// thus they will convert to this type.
deba@1136
    61
      class Node {
deba@1136
    62
      public:
ladanyi@1426
    63
        /// Default constructor
deba@1136
    64
ladanyi@1426
    65
        /// @warning The default constructor sets the iterator
ladanyi@1426
    66
        /// to an undefined value.
ladanyi@1426
    67
        Node() { }
ladanyi@1426
    68
        /// Copy constructor.
deba@1136
    69
ladanyi@1426
    70
        /// Copy constructor.
ladanyi@1426
    71
        ///
ladanyi@1426
    72
        Node(const Node&) { }
deba@1136
    73
ladanyi@1426
    74
        /// Invalid constructor \& conversion.
deba@1136
    75
ladanyi@1426
    76
        /// This constructor initializes the iterator to be invalid.
ladanyi@1426
    77
        /// \sa Invalid for more details.
ladanyi@1426
    78
        Node(Invalid) { }
ladanyi@1426
    79
        /// Equality operator
deba@1136
    80
ladanyi@1426
    81
        /// Two iterators are equal if and only if they point to the
ladanyi@1426
    82
        /// same object or both are invalid.
ladanyi@1426
    83
        bool operator==(Node) const { return true; }
deba@1136
    84
ladanyi@1426
    85
        /// Inequality operator
ladanyi@1426
    86
        
ladanyi@1426
    87
        /// \sa operator==(Node n)
ladanyi@1426
    88
        ///
ladanyi@1426
    89
        bool operator!=(Node) const { return true; }
deba@1136
    90
deba@1622
    91
	/// Artificial ordering operator.
deba@1622
    92
	
deba@1622
    93
	/// To allow the use of graph descriptors as key type in std::map or
deba@1622
    94
	/// similar associative container we require this.
deba@1622
    95
	///
deba@1622
    96
	/// \note This operator only have to define some strict ordering of
deba@1622
    97
	/// the items; this order has nothing to do with the iteration
deba@1622
    98
	/// ordering of the items.
deba@1622
    99
	bool operator<(Node) const { return false; }
deba@1622
   100
deba@1136
   101
      };
deba@1136
   102
    
deba@1136
   103
      /// This iterator goes through each node.
deba@1136
   104
deba@1136
   105
      /// This iterator goes through each node.
deba@1136
   106
      /// Its usage is quite simple, for example you can count the number
deba@1136
   107
      /// of nodes in graph \c g of type \c Graph like this:
alpar@1946
   108
      ///\code
deba@1136
   109
      /// int count=0;
ladanyi@1426
   110
      /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
alpar@1946
   111
      ///\endcode
deba@1136
   112
      class NodeIt : public Node {
deba@1136
   113
      public:
ladanyi@1426
   114
        /// Default constructor
deba@1136
   115
ladanyi@1426
   116
        /// @warning The default constructor sets the iterator
ladanyi@1426
   117
        /// to an undefined value.
ladanyi@1426
   118
        NodeIt() { }
ladanyi@1426
   119
        /// Copy constructor.
ladanyi@1426
   120
        
ladanyi@1426
   121
        /// Copy constructor.
ladanyi@1426
   122
        ///
ladanyi@1426
   123
        NodeIt(const NodeIt& n) : Node(n) { }
ladanyi@1426
   124
        /// Invalid constructor \& conversion.
deba@1136
   125
ladanyi@1426
   126
        /// Initialize the iterator to be invalid.
ladanyi@1426
   127
        /// \sa Invalid for more details.
ladanyi@1426
   128
        NodeIt(Invalid) { }
ladanyi@1426
   129
        /// Sets the iterator to the first node.
deba@1136
   130
ladanyi@1426
   131
        /// Sets the iterator to the first node of \c g.
ladanyi@1426
   132
        ///
deba@2111
   133
        NodeIt(const Graph&) { }
ladanyi@1426
   134
        /// Node -> NodeIt conversion.
deba@1136
   135
deba@1470
   136
        /// Sets the iterator to the node of \c the graph pointed by 
deba@1470
   137
	/// the trivial iterator.
ladanyi@1426
   138
        /// This feature necessitates that each time we 
ladanyi@1426
   139
        /// iterate the edge-set, the iteration order is the same.
deba@2111
   140
        NodeIt(const Graph&, const Node&) { }
ladanyi@1426
   141
        /// Next node.
deba@1136
   142
ladanyi@1426
   143
        /// Assign the iterator to the next node.
ladanyi@1426
   144
        ///
ladanyi@1426
   145
        NodeIt& operator++() { return *this; }
deba@1136
   146
      };
deba@1136
   147
    
deba@1136
   148
    
alpar@2128
   149
      /// Class for identifying an edge of the graph
deba@1136
   150
alpar@2128
   151
      /// This class identifies an edge of the graph. It also serves
alpar@2128
   152
      /// as a base class of the edge iterators,
alpar@2128
   153
      /// thus they will convert to this type.
deba@1136
   154
      class Edge {
deba@1136
   155
      public:
ladanyi@1426
   156
        /// Default constructor
deba@1136
   157
ladanyi@1426
   158
        /// @warning The default constructor sets the iterator
ladanyi@1426
   159
        /// to an undefined value.
ladanyi@1426
   160
        Edge() { }
ladanyi@1426
   161
        /// Copy constructor.
deba@1136
   162
ladanyi@1426
   163
        /// Copy constructor.
ladanyi@1426
   164
        ///
ladanyi@1426
   165
        Edge(const Edge&) { }
ladanyi@1426
   166
        /// Initialize the iterator to be invalid.
deba@1136
   167
ladanyi@1426
   168
        /// Initialize the iterator to be invalid.
ladanyi@1426
   169
        ///
ladanyi@1426
   170
        Edge(Invalid) { }
ladanyi@1426
   171
        /// Equality operator
deba@1136
   172
ladanyi@1426
   173
        /// Two iterators are equal if and only if they point to the
ladanyi@1426
   174
        /// same object or both are invalid.
ladanyi@1426
   175
        bool operator==(Edge) const { return true; }
ladanyi@1426
   176
        /// Inequality operator
deba@1136
   177
alpar@1620
   178
        /// \sa operator==(Edge n)
ladanyi@1426
   179
        ///
ladanyi@1426
   180
        bool operator!=(Edge) const { return true; }
deba@1622
   181
deba@1622
   182
	/// Artificial ordering operator.
deba@1622
   183
	
deba@1622
   184
	/// To allow the use of graph descriptors as key type in std::map or
deba@1622
   185
	/// similar associative container we require this.
deba@1622
   186
	///
deba@1622
   187
	/// \note This operator only have to define some strict ordering of
deba@1622
   188
	/// the items; this order has nothing to do with the iteration
deba@1622
   189
	/// ordering of the items.
deba@1622
   190
	bool operator<(Edge) const { return false; }
deba@1136
   191
      };
deba@1136
   192
    
deba@1136
   193
      /// This iterator goes trough the outgoing edges of a node.
deba@1136
   194
deba@1136
   195
      /// This iterator goes trough the \e outgoing edges of a certain node
deba@1136
   196
      /// of a graph.
deba@1136
   197
      /// Its usage is quite simple, for example you can count the number
deba@1136
   198
      /// of outgoing edges of a node \c n
deba@1136
   199
      /// in graph \c g of type \c Graph as follows.
alpar@1946
   200
      ///\code
deba@1136
   201
      /// int count=0;
deba@1136
   202
      /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
alpar@1946
   203
      ///\endcode
deba@1136
   204
    
deba@1136
   205
      class OutEdgeIt : public Edge {
deba@1136
   206
      public:
ladanyi@1426
   207
        /// Default constructor
deba@1136
   208
ladanyi@1426
   209
        /// @warning The default constructor sets the iterator
ladanyi@1426
   210
        /// to an undefined value.
ladanyi@1426
   211
        OutEdgeIt() { }
ladanyi@1426
   212
        /// Copy constructor.
deba@1136
   213
ladanyi@1426
   214
        /// Copy constructor.
ladanyi@1426
   215
        ///
ladanyi@1426
   216
        OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
ladanyi@1426
   217
        /// Initialize the iterator to be invalid.
deba@1136
   218
ladanyi@1426
   219
        /// Initialize the iterator to be invalid.
ladanyi@1426
   220
        ///
ladanyi@1426
   221
        OutEdgeIt(Invalid) { }
ladanyi@1426
   222
        /// This constructor sets the iterator to the first outgoing edge.
deba@1136
   223
    
ladanyi@1426
   224
        /// This constructor sets the iterator to the first outgoing edge of
ladanyi@1426
   225
        /// the node.
deba@2111
   226
        OutEdgeIt(const Graph&, const Node&) { }
ladanyi@1426
   227
        /// Edge -> OutEdgeIt conversion
deba@1136
   228
deba@1470
   229
        /// Sets the iterator to the value of the trivial iterator.
deba@1470
   230
	/// This feature necessitates that each time we 
ladanyi@1426
   231
        /// iterate the edge-set, the iteration order is the same.
deba@2111
   232
        OutEdgeIt(const Graph&, const Edge&) { }
ladanyi@1426
   233
        ///Next outgoing edge
ladanyi@1426
   234
        
ladanyi@1426
   235
        /// Assign the iterator to the next 
ladanyi@1426
   236
        /// outgoing edge of the corresponding node.
ladanyi@1426
   237
        OutEdgeIt& operator++() { return *this; }
deba@1136
   238
      };
deba@1136
   239
deba@1136
   240
      /// This iterator goes trough the incoming edges of a node.
deba@1136
   241
deba@1136
   242
      /// This iterator goes trough the \e incoming edges of a certain node
deba@1136
   243
      /// of a graph.
deba@1136
   244
      /// Its usage is quite simple, for example you can count the number
deba@1136
   245
      /// of outgoing edges of a node \c n
deba@1136
   246
      /// in graph \c g of type \c Graph as follows.
alpar@1946
   247
      ///\code
deba@1136
   248
      /// int count=0;
deba@1136
   249
      /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
alpar@1946
   250
      ///\endcode
deba@1136
   251
deba@1136
   252
      class InEdgeIt : public Edge {
deba@1136
   253
      public:
ladanyi@1426
   254
        /// Default constructor
deba@1136
   255
ladanyi@1426
   256
        /// @warning The default constructor sets the iterator
ladanyi@1426
   257
        /// to an undefined value.
ladanyi@1426
   258
        InEdgeIt() { }
ladanyi@1426
   259
        /// Copy constructor.
deba@1136
   260
ladanyi@1426
   261
        /// Copy constructor.
ladanyi@1426
   262
        ///
ladanyi@1426
   263
        InEdgeIt(const InEdgeIt& e) : Edge(e) { }
ladanyi@1426
   264
        /// Initialize the iterator to be invalid.
deba@1136
   265
ladanyi@1426
   266
        /// Initialize the iterator to be invalid.
ladanyi@1426
   267
        ///
ladanyi@1426
   268
        InEdgeIt(Invalid) { }
ladanyi@1426
   269
        /// This constructor sets the iterator to first incoming edge.
deba@1136
   270
    
ladanyi@1426
   271
        /// This constructor set the iterator to the first incoming edge of
ladanyi@1426
   272
        /// the node.
deba@2111
   273
        InEdgeIt(const Graph&, const Node&) { }
ladanyi@1426
   274
        /// Edge -> InEdgeIt conversion
deba@1136
   275
ladanyi@1426
   276
        /// Sets the iterator to the value of the trivial iterator \c e.
ladanyi@1426
   277
        /// This feature necessitates that each time we 
ladanyi@1426
   278
        /// iterate the edge-set, the iteration order is the same.
deba@2111
   279
        InEdgeIt(const Graph&, const Edge&) { }
ladanyi@1426
   280
        /// Next incoming edge
deba@1136
   281
ladanyi@1426
   282
        /// Assign the iterator to the next inedge of the corresponding node.
ladanyi@1426
   283
        ///
ladanyi@1426
   284
        InEdgeIt& operator++() { return *this; }
deba@1136
   285
      };
deba@1136
   286
      /// This iterator goes through each edge.
deba@1136
   287
deba@1136
   288
      /// This iterator goes through each edge of a graph.
deba@1136
   289
      /// Its usage is quite simple, for example you can count the number
deba@1136
   290
      /// of edges in a graph \c g of type \c Graph as follows:
alpar@1946
   291
      ///\code
deba@1136
   292
      /// int count=0;
deba@1136
   293
      /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
alpar@1946
   294
      ///\endcode
deba@1136
   295
      class EdgeIt : public Edge {
deba@1136
   296
      public:
ladanyi@1426
   297
        /// Default constructor
deba@1136
   298
ladanyi@1426
   299
        /// @warning The default constructor sets the iterator
ladanyi@1426
   300
        /// to an undefined value.
ladanyi@1426
   301
        EdgeIt() { }
ladanyi@1426
   302
        /// Copy constructor.
deba@1136
   303
ladanyi@1426
   304
        /// Copy constructor.
ladanyi@1426
   305
        ///
ladanyi@1426
   306
        EdgeIt(const EdgeIt& e) : Edge(e) { }
ladanyi@1426
   307
        /// Initialize the iterator to be invalid.
deba@1136
   308
ladanyi@1426
   309
        /// Initialize the iterator to be invalid.
ladanyi@1426
   310
        ///
ladanyi@1426
   311
        EdgeIt(Invalid) { }
ladanyi@1426
   312
        /// This constructor sets the iterator to the first edge.
deba@1136
   313
    
ladanyi@1426
   314
        /// This constructor sets the iterator to the first edge of \c g.
ladanyi@1426
   315
        ///@param g the graph
deba@2111
   316
        EdgeIt(const Graph& g) { ignore_unused_variable_warning(g); }
ladanyi@1426
   317
        /// Edge -> EdgeIt conversion
deba@1136
   318
ladanyi@1426
   319
        /// Sets the iterator to the value of the trivial iterator \c e.
ladanyi@1426
   320
        /// This feature necessitates that each time we 
ladanyi@1426
   321
        /// iterate the edge-set, the iteration order is the same.
deba@2111
   322
        EdgeIt(const Graph&, const Edge&) { } 
ladanyi@1426
   323
        ///Next edge
ladanyi@1426
   324
        
ladanyi@1426
   325
        /// Assign the iterator to the next edge.
ladanyi@1426
   326
        EdgeIt& operator++() { return *this; }
deba@1136
   327
      };
deba@1136
   328
      ///Gives back the target node of an edge.
deba@1136
   329
deba@1136
   330
      ///Gives back the target node of an edge.
deba@1136
   331
      ///
deba@1136
   332
      Node target(Edge) const { return INVALID; }
deba@1136
   333
      ///Gives back the source node of an edge.
deba@1136
   334
deba@1136
   335
      ///Gives back the source node of an edge.
deba@1136
   336
      ///
deba@1136
   337
      Node source(Edge) const { return INVALID; }
deba@1563
   338
deba@1563
   339
      void first(Node&) const {}
deba@1563
   340
      void next(Node&) const {}
deba@1563
   341
deba@1563
   342
      void first(Edge&) const {}
deba@1563
   343
      void next(Edge&) const {}
deba@1563
   344
deba@1563
   345
deba@1563
   346
      void firstIn(Edge&, const Node&) const {}
deba@1563
   347
      void nextIn(Edge&) const {}
deba@1563
   348
deba@1563
   349
      void firstOut(Edge&, const Node&) const {}
deba@1563
   350
      void nextOut(Edge&) const {}
deba@1563
   351
deba@1563
   352
      /// \brief The base node of the iterator.
deba@1563
   353
      ///
deba@1563
   354
      /// Gives back the base node of the iterator.
deba@1627
   355
      /// It is always the target of the pointed edge.
deba@1563
   356
      Node baseNode(const InEdgeIt&) const { return INVALID; }
deba@1563
   357
deba@1563
   358
      /// \brief The running node of the iterator.
deba@1563
   359
      ///
deba@1563
   360
      /// Gives back the running node of the iterator.
deba@1627
   361
      /// It is always the source of the pointed edge.
deba@1563
   362
      Node runningNode(const InEdgeIt&) const { return INVALID; }
deba@1563
   363
deba@1563
   364
      /// \brief The base node of the iterator.
deba@1563
   365
      ///
deba@1563
   366
      /// Gives back the base node of the iterator.
deba@1627
   367
      /// It is always the source of the pointed edge.
deba@1563
   368
      Node baseNode(const OutEdgeIt&) const { return INVALID; }
deba@1563
   369
deba@1563
   370
      /// \brief The running node of the iterator.
deba@1563
   371
      ///
deba@1563
   372
      /// Gives back the running node of the iterator.
deba@1627
   373
      /// It is always the target of the pointed edge.
deba@1563
   374
      Node runningNode(const OutEdgeIt&) const { return INVALID; }
deba@1136
   375
deba@1627
   376
      /// \brief The opposite node on the given edge.
deba@1627
   377
      ///
deba@1627
   378
      /// Gives back the opposite node on the given edge.
deba@1627
   379
      Node oppositeNode(const Node&, const Edge&) const { return INVALID; }
deba@1627
   380
deba@1627
   381
      /// \brief Read write map of the nodes to type \c T.
deba@1627
   382
      /// 
deba@1136
   383
      /// ReadWrite map of the nodes to type \c T.
deba@1136
   384
      /// \sa Reference
deba@1136
   385
      template<class T> 
deba@2121
   386
      class NodeMap : public ReadWriteMap< Node, T > {
deba@1136
   387
      public:
deba@1136
   388
ladanyi@1426
   389
        ///\e
deba@2111
   390
        NodeMap(const Graph&) { }
ladanyi@1426
   391
        ///\e
deba@2111
   392
        NodeMap(const Graph&, T) { }
deba@1136
   393
ladanyi@1426
   394
        ///Copy constructor
ladanyi@1426
   395
        NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
ladanyi@1426
   396
        ///Assignment operator
deba@2121
   397
        template <typename CMap>
deba@2121
   398
        NodeMap& operator=(const CMap&) { 
deba@2121
   399
          checkConcept<ReadMap<Node, T>, CMap>();
deba@2121
   400
          return *this; 
deba@2121
   401
        }
deba@1136
   402
      };
deba@1136
   403
deba@1627
   404
      /// \brief Read write map of the edges to type \c T.
deba@1627
   405
      ///
deba@1627
   406
      /// Reference map of the edges to type \c T.
deba@1136
   407
      /// \sa Reference
deba@1136
   408
      template<class T> 
deba@2121
   409
      class EdgeMap : public ReadWriteMap<Edge,T> {
deba@1136
   410
      public:
deba@1136
   411
ladanyi@1426
   412
        ///\e
deba@2111
   413
        EdgeMap(const Graph&) { }
ladanyi@1426
   414
        ///\e
deba@2111
   415
        EdgeMap(const Graph&, T) { }
ladanyi@1426
   416
        ///Copy constructor
ladanyi@1426
   417
        EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
ladanyi@1426
   418
        ///Assignment operator
deba@2121
   419
        template <typename CMap>
deba@2121
   420
        EdgeMap& operator=(const CMap&) { 
deba@2121
   421
          checkConcept<ReadMap<Edge, T>, CMap>();
deba@2121
   422
          return *this; 
deba@2121
   423
        }
deba@1136
   424
      };
deba@1136
   425
deba@2111
   426
      template <typename RGraph>
deba@2121
   427
      struct Constraints {
deba@2121
   428
        void constraints() {
deba@2121
   429
          checkConcept<BaseIterableGraphComponent<>, Graph>();
deba@2121
   430
          checkConcept<IterableGraphComponent<>, Graph>();
deba@2121
   431
          checkConcept<MappableGraphComponent<>, Graph>();
deba@2121
   432
        }
deba@2121
   433
      };
deba@1136
   434
deba@1136
   435
    };
deba@1136
   436
    
klao@959
   437
    // @}
klao@959
   438
  } //namespace concept  
klao@959
   439
} //namespace lemon
klao@959
   440
klao@959
   441
klao@959
   442
klao@959
   443
#endif // LEMON_CONCEPT_GRAPH_H