lemon/concepts/ugraph.h
author deba
Tue, 30 Oct 2007 20:44:53 +0000
changeset 2506 216c6bd5c18c
parent 2474 e6368948d5f7
child 2553 bfced05fa852
permissions -rw-r--r--
Change to new union-find interface
alpar@2260
     1
/* -*- C++ -*-
alpar@2260
     2
 *
alpar@2260
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@2260
     4
 *
alpar@2391
     5
 * Copyright (C) 2003-2007
alpar@2260
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@2260
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@2260
     8
 *
alpar@2260
     9
 * Permission to use, modify and distribute this software is granted
alpar@2260
    10
 * provided that this copyright notice appears in all copies. For
alpar@2260
    11
 * precise terms see the accompanying LICENSE file.
alpar@2260
    12
 *
alpar@2260
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@2260
    14
 * express or implied, and with no claim as to its suitability for any
alpar@2260
    15
 * purpose.
alpar@2260
    16
 *
alpar@2260
    17
 */
alpar@2260
    18
alpar@2260
    19
///\ingroup graph_concepts
alpar@2260
    20
///\file
kpeter@2474
    21
///\brief The concept of Undirected Graphs.
alpar@2260
    22
alpar@2260
    23
#ifndef LEMON_CONCEPT_UGRAPH_H
alpar@2260
    24
#define LEMON_CONCEPT_UGRAPH_H
alpar@2260
    25
alpar@2260
    26
#include <lemon/concepts/graph_components.h>
alpar@2260
    27
#include <lemon/concepts/graph.h>
alpar@2260
    28
#include <lemon/bits/utility.h>
alpar@2260
    29
alpar@2260
    30
namespace lemon {
alpar@2260
    31
  namespace concepts {
alpar@2260
    32
deba@2485
    33
    /// \ingroup graph_concepts
kpeter@2474
    34
    ///
alpar@2260
    35
    /// \brief Class describing the concept of Undirected Graphs.
alpar@2260
    36
    ///
alpar@2260
    37
    /// This class describes the common interface of all Undirected
alpar@2260
    38
    /// Graphs.
alpar@2260
    39
    ///
alpar@2260
    40
    /// As all concept describing classes it provides only interface
alpar@2260
    41
    /// without any sensible implementation. So any algorithm for
alpar@2260
    42
    /// undirected graph should compile with this class, but it will not
alpar@2260
    43
    /// run properly, of course.
alpar@2260
    44
    ///
alpar@2260
    45
    /// The LEMON undirected graphs also fulfill the concept of
alpar@2260
    46
    /// directed graphs (\ref lemon::concepts::Graph "Graph
alpar@2260
    47
    /// Concept"). Each undirected edges can be seen as two opposite
alpar@2260
    48
    /// directed edge and consequently the undirected graph can be
alpar@2260
    49
    /// seen as the direceted graph of these directed edges. The
alpar@2260
    50
    /// UGraph has the UEdge inner class for the undirected edges and
alpar@2260
    51
    /// the Edge type for the directed edges. The Edge type is
alpar@2260
    52
    /// convertible to UEdge or inherited from it so from a directed
alpar@2260
    53
    /// edge we can get the represented undirected edge.
alpar@2260
    54
    ///
alpar@2260
    55
    /// In the sense of the LEMON each undirected edge has a default
alpar@2260
    56
    /// direction (it should be in every computer implementation,
alpar@2260
    57
    /// because the order of undirected edge's nodes defines an
alpar@2260
    58
    /// orientation). With the default orientation we can define that
alpar@2260
    59
    /// the directed edge is forward or backward directed. With the \c
alpar@2260
    60
    /// direction() and \c direct() function we can get the direction
alpar@2260
    61
    /// of the directed edge and we can direct an undirected edge.
alpar@2260
    62
    ///
alpar@2260
    63
    /// The UEdgeIt is an iterator for the undirected edges. We can use
alpar@2260
    64
    /// the UEdgeMap to map values for the undirected edges. The InEdgeIt and
alpar@2260
    65
    /// OutEdgeIt iterates on the same undirected edges but with opposite
alpar@2260
    66
    /// direction. The IncEdgeIt iterates also on the same undirected edges
alpar@2260
    67
    /// as the OutEdgeIt and InEdgeIt but it is not convertible to Edge just
alpar@2260
    68
    /// to UEdge.  
alpar@2260
    69
    class UGraph {
alpar@2260
    70
    public:
alpar@2260
    71
      /// \brief The undirected graph should be tagged by the
alpar@2260
    72
      /// UndirectedTag.
alpar@2260
    73
      ///
alpar@2260
    74
      /// The undirected graph should be tagged by the UndirectedTag. This
alpar@2260
    75
      /// tag helps the enable_if technics to make compile time 
alpar@2260
    76
      /// specializations for undirected graphs.  
alpar@2260
    77
      typedef True UndirectedTag;
alpar@2260
    78
alpar@2260
    79
      /// \brief The base type of node iterators, 
alpar@2260
    80
      /// or in other words, the trivial node iterator.
alpar@2260
    81
      ///
alpar@2260
    82
      /// This is the base type of each node iterator,
alpar@2260
    83
      /// thus each kind of node iterator converts to this.
alpar@2260
    84
      /// More precisely each kind of node iterator should be inherited 
alpar@2260
    85
      /// from the trivial node iterator.
alpar@2260
    86
      class Node {
alpar@2260
    87
      public:
alpar@2260
    88
        /// Default constructor
alpar@2260
    89
alpar@2260
    90
        /// @warning The default constructor sets the iterator
alpar@2260
    91
        /// to an undefined value.
alpar@2260
    92
        Node() { }
alpar@2260
    93
        /// Copy constructor.
alpar@2260
    94
alpar@2260
    95
        /// Copy constructor.
alpar@2260
    96
        ///
alpar@2260
    97
        Node(const Node&) { }
alpar@2260
    98
alpar@2260
    99
        /// Invalid constructor \& conversion.
alpar@2260
   100
alpar@2260
   101
        /// This constructor initializes the iterator to be invalid.
alpar@2260
   102
        /// \sa Invalid for more details.
alpar@2260
   103
        Node(Invalid) { }
alpar@2260
   104
        /// Equality operator
alpar@2260
   105
alpar@2260
   106
        /// Two iterators are equal if and only if they point to the
alpar@2260
   107
        /// same object or both are invalid.
alpar@2260
   108
        bool operator==(Node) const { return true; }
alpar@2260
   109
alpar@2260
   110
        /// Inequality operator
alpar@2260
   111
        
alpar@2260
   112
        /// \sa operator==(Node n)
alpar@2260
   113
        ///
alpar@2260
   114
        bool operator!=(Node) const { return true; }
alpar@2260
   115
alpar@2260
   116
	/// Artificial ordering operator.
alpar@2260
   117
	
alpar@2260
   118
	/// To allow the use of graph descriptors as key type in std::map or
alpar@2260
   119
	/// similar associative container we require this.
alpar@2260
   120
	///
alpar@2260
   121
	/// \note This operator only have to define some strict ordering of
alpar@2260
   122
	/// the items; this order has nothing to do with the iteration
alpar@2260
   123
	/// ordering of the items.
alpar@2260
   124
	bool operator<(Node) const { return false; }
alpar@2260
   125
alpar@2260
   126
      };
alpar@2260
   127
    
alpar@2260
   128
      /// This iterator goes through each node.
alpar@2260
   129
alpar@2260
   130
      /// This iterator goes through each node.
alpar@2260
   131
      /// Its usage is quite simple, for example you can count the number
alpar@2260
   132
      /// of nodes in graph \c g of type \c Graph like this:
alpar@2260
   133
      ///\code
alpar@2260
   134
      /// int count=0;
alpar@2260
   135
      /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
alpar@2260
   136
      ///\endcode
alpar@2260
   137
      class NodeIt : public Node {
alpar@2260
   138
      public:
alpar@2260
   139
        /// Default constructor
alpar@2260
   140
alpar@2260
   141
        /// @warning The default constructor sets the iterator
alpar@2260
   142
        /// to an undefined value.
alpar@2260
   143
        NodeIt() { }
alpar@2260
   144
        /// Copy constructor.
alpar@2260
   145
        
alpar@2260
   146
        /// Copy constructor.
alpar@2260
   147
        ///
alpar@2260
   148
        NodeIt(const NodeIt& n) : Node(n) { }
alpar@2260
   149
        /// Invalid constructor \& conversion.
alpar@2260
   150
alpar@2260
   151
        /// Initialize the iterator to be invalid.
alpar@2260
   152
        /// \sa Invalid for more details.
alpar@2260
   153
        NodeIt(Invalid) { }
alpar@2260
   154
        /// Sets the iterator to the first node.
alpar@2260
   155
alpar@2260
   156
        /// Sets the iterator to the first node of \c g.
alpar@2260
   157
        ///
alpar@2260
   158
        NodeIt(const UGraph&) { }
alpar@2260
   159
        /// Node -> NodeIt conversion.
alpar@2260
   160
alpar@2260
   161
        /// Sets the iterator to the node of \c the graph pointed by 
alpar@2260
   162
	/// the trivial iterator.
alpar@2260
   163
        /// This feature necessitates that each time we 
alpar@2260
   164
        /// iterate the edge-set, the iteration order is the same.
alpar@2260
   165
        NodeIt(const UGraph&, const Node&) { }
alpar@2260
   166
        /// Next node.
alpar@2260
   167
alpar@2260
   168
        /// Assign the iterator to the next node.
alpar@2260
   169
        ///
alpar@2260
   170
        NodeIt& operator++() { return *this; }
alpar@2260
   171
      };
alpar@2260
   172
    
alpar@2260
   173
    
alpar@2260
   174
      /// The base type of the undirected edge iterators.
alpar@2260
   175
alpar@2260
   176
      /// The base type of the undirected edge iterators.
alpar@2260
   177
      ///
alpar@2260
   178
      class UEdge {
alpar@2260
   179
      public:
alpar@2260
   180
        /// Default constructor
alpar@2260
   181
alpar@2260
   182
        /// @warning The default constructor sets the iterator
alpar@2260
   183
        /// to an undefined value.
alpar@2260
   184
        UEdge() { }
alpar@2260
   185
        /// Copy constructor.
alpar@2260
   186
alpar@2260
   187
        /// Copy constructor.
alpar@2260
   188
        ///
alpar@2260
   189
        UEdge(const UEdge&) { }
alpar@2260
   190
        /// Initialize the iterator to be invalid.
alpar@2260
   191
alpar@2260
   192
        /// Initialize the iterator to be invalid.
alpar@2260
   193
        ///
alpar@2260
   194
        UEdge(Invalid) { }
alpar@2260
   195
        /// Equality operator
alpar@2260
   196
alpar@2260
   197
        /// Two iterators are equal if and only if they point to the
alpar@2260
   198
        /// same object or both are invalid.
alpar@2260
   199
        bool operator==(UEdge) const { return true; }
alpar@2260
   200
        /// Inequality operator
alpar@2260
   201
alpar@2260
   202
        /// \sa operator==(UEdge n)
alpar@2260
   203
        ///
alpar@2260
   204
        bool operator!=(UEdge) const { return true; }
alpar@2260
   205
alpar@2260
   206
	/// Artificial ordering operator.
alpar@2260
   207
	
alpar@2260
   208
	/// To allow the use of graph descriptors as key type in std::map or
alpar@2260
   209
	/// similar associative container we require this.
alpar@2260
   210
	///
alpar@2260
   211
	/// \note This operator only have to define some strict ordering of
alpar@2260
   212
	/// the items; this order has nothing to do with the iteration
alpar@2260
   213
	/// ordering of the items.
alpar@2260
   214
	bool operator<(UEdge) const { return false; }
alpar@2260
   215
      };
alpar@2260
   216
alpar@2260
   217
      /// This iterator goes through each undirected edge.
alpar@2260
   218
alpar@2260
   219
      /// This iterator goes through each undirected edge of a graph.
alpar@2260
   220
      /// Its usage is quite simple, for example you can count the number
alpar@2260
   221
      /// of undirected edges in a graph \c g of type \c Graph as follows:
alpar@2260
   222
      ///\code
alpar@2260
   223
      /// int count=0;
alpar@2260
   224
      /// for(Graph::UEdgeIt e(g); e!=INVALID; ++e) ++count;
alpar@2260
   225
      ///\endcode
alpar@2260
   226
      class UEdgeIt : public UEdge {
alpar@2260
   227
      public:
alpar@2260
   228
        /// Default constructor
alpar@2260
   229
alpar@2260
   230
        /// @warning The default constructor sets the iterator
alpar@2260
   231
        /// to an undefined value.
alpar@2260
   232
        UEdgeIt() { }
alpar@2260
   233
        /// Copy constructor.
alpar@2260
   234
alpar@2260
   235
        /// Copy constructor.
alpar@2260
   236
        ///
alpar@2260
   237
        UEdgeIt(const UEdgeIt& e) : UEdge(e) { }
alpar@2260
   238
        /// Initialize the iterator to be invalid.
alpar@2260
   239
alpar@2260
   240
        /// Initialize the iterator to be invalid.
alpar@2260
   241
        ///
alpar@2260
   242
        UEdgeIt(Invalid) { }
alpar@2260
   243
        /// This constructor sets the iterator to the first undirected edge.
alpar@2260
   244
    
alpar@2260
   245
        /// This constructor sets the iterator to the first undirected edge.
alpar@2260
   246
        UEdgeIt(const UGraph&) { }
alpar@2260
   247
        /// UEdge -> UEdgeIt conversion
alpar@2260
   248
alpar@2260
   249
        /// Sets the iterator to the value of the trivial iterator.
alpar@2260
   250
        /// This feature necessitates that each time we
alpar@2260
   251
        /// iterate the undirected edge-set, the iteration order is the 
alpar@2260
   252
	/// same.
alpar@2260
   253
        UEdgeIt(const UGraph&, const UEdge&) { } 
alpar@2260
   254
        /// Next undirected edge
alpar@2260
   255
        
alpar@2260
   256
        /// Assign the iterator to the next undirected edge.
alpar@2260
   257
        UEdgeIt& operator++() { return *this; }
alpar@2260
   258
      };
alpar@2260
   259
alpar@2260
   260
      /// \brief This iterator goes trough the incident undirected 
alpar@2260
   261
      /// edges of a node.
alpar@2260
   262
      ///
alpar@2260
   263
      /// This iterator goes trough the incident undirected edges
alpar@2260
   264
      /// of a certain node of a graph. You should assume that the 
alpar@2260
   265
      /// loop edges will be iterated twice.
alpar@2260
   266
      /// 
alpar@2260
   267
      /// Its usage is quite simple, for example you can compute the
alpar@2260
   268
      /// degree (i.e. count the number of incident edges of a node \c n
alpar@2260
   269
      /// in graph \c g of type \c Graph as follows. 
alpar@2260
   270
      ///
alpar@2260
   271
      ///\code
alpar@2260
   272
      /// int count=0;
alpar@2260
   273
      /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
alpar@2260
   274
      ///\endcode
alpar@2260
   275
      class IncEdgeIt : public UEdge {
alpar@2260
   276
      public:
alpar@2260
   277
        /// Default constructor
alpar@2260
   278
alpar@2260
   279
        /// @warning The default constructor sets the iterator
alpar@2260
   280
        /// to an undefined value.
alpar@2260
   281
        IncEdgeIt() { }
alpar@2260
   282
        /// Copy constructor.
alpar@2260
   283
alpar@2260
   284
        /// Copy constructor.
alpar@2260
   285
        ///
alpar@2260
   286
        IncEdgeIt(const IncEdgeIt& e) : UEdge(e) { }
alpar@2260
   287
        /// Initialize the iterator to be invalid.
alpar@2260
   288
alpar@2260
   289
        /// Initialize the iterator to be invalid.
alpar@2260
   290
        ///
alpar@2260
   291
        IncEdgeIt(Invalid) { }
alpar@2260
   292
        /// This constructor sets the iterator to first incident edge.
alpar@2260
   293
    
alpar@2260
   294
        /// This constructor set the iterator to the first incident edge of
alpar@2260
   295
        /// the node.
alpar@2260
   296
        IncEdgeIt(const UGraph&, const Node&) { }
alpar@2260
   297
        /// UEdge -> IncEdgeIt conversion
alpar@2260
   298
alpar@2260
   299
        /// Sets the iterator to the value of the trivial iterator \c e.
alpar@2260
   300
        /// This feature necessitates that each time we 
alpar@2260
   301
        /// iterate the edge-set, the iteration order is the same.
alpar@2260
   302
        IncEdgeIt(const UGraph&, const UEdge&) { }
alpar@2260
   303
        /// Next incident edge
alpar@2260
   304
alpar@2260
   305
        /// Assign the iterator to the next incident edge
alpar@2260
   306
	/// of the corresponding node.
alpar@2260
   307
        IncEdgeIt& operator++() { return *this; }
alpar@2260
   308
      };
alpar@2260
   309
alpar@2260
   310
      /// The directed edge type.
alpar@2260
   311
alpar@2260
   312
      /// The directed edge type. It can be converted to the
alpar@2260
   313
      /// undirected edge or it should be inherited from the undirected
alpar@2260
   314
      /// edge.
alpar@2260
   315
      class Edge : public UEdge {
alpar@2260
   316
      public:
alpar@2260
   317
        /// Default constructor
alpar@2260
   318
alpar@2260
   319
        /// @warning The default constructor sets the iterator
alpar@2260
   320
        /// to an undefined value.
alpar@2260
   321
        Edge() { }
alpar@2260
   322
        /// Copy constructor.
alpar@2260
   323
alpar@2260
   324
        /// Copy constructor.
alpar@2260
   325
        ///
alpar@2260
   326
        Edge(const Edge& e) : UEdge(e) { }
alpar@2260
   327
        /// Initialize the iterator to be invalid.
alpar@2260
   328
alpar@2260
   329
        /// Initialize the iterator to be invalid.
alpar@2260
   330
        ///
alpar@2260
   331
        Edge(Invalid) { }
alpar@2260
   332
        /// Equality operator
alpar@2260
   333
alpar@2260
   334
        /// Two iterators are equal if and only if they point to the
alpar@2260
   335
        /// same object or both are invalid.
alpar@2260
   336
        bool operator==(Edge) const { return true; }
alpar@2260
   337
        /// Inequality operator
alpar@2260
   338
alpar@2260
   339
        /// \sa operator==(Edge n)
alpar@2260
   340
        ///
alpar@2260
   341
        bool operator!=(Edge) const { return true; }
alpar@2260
   342
alpar@2260
   343
	/// Artificial ordering operator.
alpar@2260
   344
	
alpar@2260
   345
	/// To allow the use of graph descriptors as key type in std::map or
alpar@2260
   346
	/// similar associative container we require this.
alpar@2260
   347
	///
alpar@2260
   348
	/// \note This operator only have to define some strict ordering of
alpar@2260
   349
	/// the items; this order has nothing to do with the iteration
alpar@2260
   350
	/// ordering of the items.
alpar@2260
   351
	bool operator<(Edge) const { return false; }
alpar@2260
   352
	
alpar@2260
   353
      }; 
alpar@2260
   354
      /// This iterator goes through each directed edge.
alpar@2260
   355
alpar@2260
   356
      /// This iterator goes through each edge of a graph.
alpar@2260
   357
      /// Its usage is quite simple, for example you can count the number
alpar@2260
   358
      /// of edges in a graph \c g of type \c Graph as follows:
alpar@2260
   359
      ///\code
alpar@2260
   360
      /// int count=0;
alpar@2260
   361
      /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
alpar@2260
   362
      ///\endcode
alpar@2260
   363
      class EdgeIt : public Edge {
alpar@2260
   364
      public:
alpar@2260
   365
        /// Default constructor
alpar@2260
   366
alpar@2260
   367
        /// @warning The default constructor sets the iterator
alpar@2260
   368
        /// to an undefined value.
alpar@2260
   369
        EdgeIt() { }
alpar@2260
   370
        /// Copy constructor.
alpar@2260
   371
alpar@2260
   372
        /// Copy constructor.
alpar@2260
   373
        ///
alpar@2260
   374
        EdgeIt(const EdgeIt& e) : Edge(e) { }
alpar@2260
   375
        /// Initialize the iterator to be invalid.
alpar@2260
   376
alpar@2260
   377
        /// Initialize the iterator to be invalid.
alpar@2260
   378
        ///
alpar@2260
   379
        EdgeIt(Invalid) { }
alpar@2260
   380
        /// This constructor sets the iterator to the first edge.
alpar@2260
   381
    
alpar@2260
   382
        /// This constructor sets the iterator to the first edge of \c g.
alpar@2260
   383
        ///@param g the graph
alpar@2260
   384
        EdgeIt(const UGraph &g) { ignore_unused_variable_warning(g); }
alpar@2260
   385
        /// Edge -> EdgeIt conversion
alpar@2260
   386
alpar@2260
   387
        /// Sets the iterator to the value of the trivial iterator \c e.
alpar@2260
   388
        /// This feature necessitates that each time we 
alpar@2260
   389
        /// iterate the edge-set, the iteration order is the same.
alpar@2260
   390
        EdgeIt(const UGraph&, const Edge&) { } 
alpar@2260
   391
        ///Next edge
alpar@2260
   392
        
alpar@2260
   393
        /// Assign the iterator to the next edge.
alpar@2260
   394
        EdgeIt& operator++() { return *this; }
alpar@2260
   395
      };
alpar@2260
   396
   
alpar@2260
   397
      /// This iterator goes trough the outgoing directed edges of a node.
alpar@2260
   398
alpar@2260
   399
      /// This iterator goes trough the \e outgoing edges of a certain node
alpar@2260
   400
      /// of a graph.
alpar@2260
   401
      /// Its usage is quite simple, for example you can count the number
alpar@2260
   402
      /// of outgoing edges of a node \c n
alpar@2260
   403
      /// in graph \c g of type \c Graph as follows.
alpar@2260
   404
      ///\code
alpar@2260
   405
      /// int count=0;
alpar@2260
   406
      /// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
alpar@2260
   407
      ///\endcode
alpar@2260
   408
    
alpar@2260
   409
      class OutEdgeIt : public Edge {
alpar@2260
   410
      public:
alpar@2260
   411
        /// Default constructor
alpar@2260
   412
alpar@2260
   413
        /// @warning The default constructor sets the iterator
alpar@2260
   414
        /// to an undefined value.
alpar@2260
   415
        OutEdgeIt() { }
alpar@2260
   416
        /// Copy constructor.
alpar@2260
   417
alpar@2260
   418
        /// Copy constructor.
alpar@2260
   419
        ///
alpar@2260
   420
        OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
alpar@2260
   421
        /// Initialize the iterator to be invalid.
alpar@2260
   422
alpar@2260
   423
        /// Initialize the iterator to be invalid.
alpar@2260
   424
        ///
alpar@2260
   425
        OutEdgeIt(Invalid) { }
alpar@2260
   426
        /// This constructor sets the iterator to the first outgoing edge.
alpar@2260
   427
    
alpar@2260
   428
        /// This constructor sets the iterator to the first outgoing edge of
alpar@2260
   429
        /// the node.
alpar@2260
   430
        ///@param n the node
alpar@2260
   431
        ///@param g the graph
alpar@2260
   432
        OutEdgeIt(const UGraph& n, const Node& g) {
alpar@2260
   433
	  ignore_unused_variable_warning(n);
alpar@2260
   434
	  ignore_unused_variable_warning(g);
alpar@2260
   435
	}
alpar@2260
   436
        /// Edge -> OutEdgeIt conversion
alpar@2260
   437
alpar@2260
   438
        /// Sets the iterator to the value of the trivial iterator.
alpar@2260
   439
	/// This feature necessitates that each time we 
alpar@2260
   440
        /// iterate the edge-set, the iteration order is the same.
alpar@2260
   441
        OutEdgeIt(const UGraph&, const Edge&) { }
alpar@2260
   442
        ///Next outgoing edge
alpar@2260
   443
        
alpar@2260
   444
        /// Assign the iterator to the next 
alpar@2260
   445
        /// outgoing edge of the corresponding node.
alpar@2260
   446
        OutEdgeIt& operator++() { return *this; }
alpar@2260
   447
      };
alpar@2260
   448
alpar@2260
   449
      /// This iterator goes trough the incoming directed edges of a node.
alpar@2260
   450
alpar@2260
   451
      /// This iterator goes trough the \e incoming edges of a certain node
alpar@2260
   452
      /// of a graph.
alpar@2260
   453
      /// Its usage is quite simple, for example you can count the number
alpar@2260
   454
      /// of outgoing edges of a node \c n
alpar@2260
   455
      /// in graph \c g of type \c Graph as follows.
alpar@2260
   456
      ///\code
alpar@2260
   457
      /// int count=0;
alpar@2260
   458
      /// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
alpar@2260
   459
      ///\endcode
alpar@2260
   460
alpar@2260
   461
      class InEdgeIt : public Edge {
alpar@2260
   462
      public:
alpar@2260
   463
        /// Default constructor
alpar@2260
   464
alpar@2260
   465
        /// @warning The default constructor sets the iterator
alpar@2260
   466
        /// to an undefined value.
alpar@2260
   467
        InEdgeIt() { }
alpar@2260
   468
        /// Copy constructor.
alpar@2260
   469
alpar@2260
   470
        /// Copy constructor.
alpar@2260
   471
        ///
alpar@2260
   472
        InEdgeIt(const InEdgeIt& e) : Edge(e) { }
alpar@2260
   473
        /// Initialize the iterator to be invalid.
alpar@2260
   474
alpar@2260
   475
        /// Initialize the iterator to be invalid.
alpar@2260
   476
        ///
alpar@2260
   477
        InEdgeIt(Invalid) { }
alpar@2260
   478
        /// This constructor sets the iterator to first incoming edge.
alpar@2260
   479
    
alpar@2260
   480
        /// This constructor set the iterator to the first incoming edge of
alpar@2260
   481
        /// the node.
alpar@2260
   482
        ///@param n the node
alpar@2260
   483
        ///@param g the graph
alpar@2260
   484
        InEdgeIt(const UGraph& g, const Node& n) { 
alpar@2260
   485
	  ignore_unused_variable_warning(n);
alpar@2260
   486
	  ignore_unused_variable_warning(g);
alpar@2260
   487
	}
alpar@2260
   488
        /// Edge -> InEdgeIt conversion
alpar@2260
   489
alpar@2260
   490
        /// Sets the iterator to the value of the trivial iterator \c e.
alpar@2260
   491
        /// This feature necessitates that each time we 
alpar@2260
   492
        /// iterate the edge-set, the iteration order is the same.
alpar@2260
   493
        InEdgeIt(const UGraph&, const Edge&) { }
alpar@2260
   494
        /// Next incoming edge
alpar@2260
   495
alpar@2260
   496
        /// Assign the iterator to the next inedge of the corresponding node.
alpar@2260
   497
        ///
alpar@2260
   498
        InEdgeIt& operator++() { return *this; }
alpar@2260
   499
      };
alpar@2260
   500
alpar@2260
   501
      /// \brief Read write map of the nodes to type \c T.
alpar@2260
   502
      /// 
alpar@2260
   503
      /// ReadWrite map of the nodes to type \c T.
alpar@2260
   504
      /// \sa Reference
alpar@2260
   505
      template<class T> 
alpar@2260
   506
      class NodeMap : public ReadWriteMap< Node, T >
alpar@2260
   507
      {
alpar@2260
   508
      public:
alpar@2260
   509
alpar@2260
   510
        ///\e
alpar@2260
   511
        NodeMap(const UGraph&) { }
alpar@2260
   512
        ///\e
alpar@2260
   513
        NodeMap(const UGraph&, T) { }
alpar@2260
   514
alpar@2260
   515
        ///Copy constructor
alpar@2260
   516
        NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
alpar@2260
   517
        ///Assignment operator
alpar@2260
   518
        template <typename CMap>
alpar@2260
   519
        NodeMap& operator=(const CMap&) { 
alpar@2260
   520
          checkConcept<ReadMap<Node, T>, CMap>();
alpar@2260
   521
          return *this; 
alpar@2260
   522
        }
alpar@2260
   523
      };
alpar@2260
   524
alpar@2260
   525
      /// \brief Read write map of the directed edges to type \c T.
alpar@2260
   526
      ///
alpar@2260
   527
      /// Reference map of the directed edges to type \c T.
alpar@2260
   528
      /// \sa Reference
alpar@2260
   529
      template<class T> 
alpar@2260
   530
      class EdgeMap : public ReadWriteMap<Edge,T>
alpar@2260
   531
      {
alpar@2260
   532
      public:
alpar@2260
   533
alpar@2260
   534
        ///\e
alpar@2260
   535
        EdgeMap(const UGraph&) { }
alpar@2260
   536
        ///\e
alpar@2260
   537
        EdgeMap(const UGraph&, T) { }
alpar@2260
   538
        ///Copy constructor
alpar@2260
   539
        EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
alpar@2260
   540
        ///Assignment operator
alpar@2260
   541
        template <typename CMap>
alpar@2260
   542
        EdgeMap& operator=(const CMap&) { 
alpar@2260
   543
          checkConcept<ReadMap<Edge, T>, CMap>();
alpar@2260
   544
          return *this; 
alpar@2260
   545
        }
alpar@2260
   546
      };
alpar@2260
   547
alpar@2260
   548
      /// Read write map of the undirected edges to type \c T.
alpar@2260
   549
alpar@2260
   550
      /// Reference map of the edges to type \c T.
alpar@2260
   551
      /// \sa Reference
alpar@2260
   552
      template<class T> 
alpar@2260
   553
      class UEdgeMap : public ReadWriteMap<UEdge,T>
alpar@2260
   554
      {
alpar@2260
   555
      public:
alpar@2260
   556
alpar@2260
   557
        ///\e
alpar@2260
   558
        UEdgeMap(const UGraph&) { }
alpar@2260
   559
        ///\e
alpar@2260
   560
        UEdgeMap(const UGraph&, T) { }
alpar@2260
   561
        ///Copy constructor
alpar@2260
   562
        UEdgeMap(const UEdgeMap& em) : ReadWriteMap<UEdge,T>(em) {}
alpar@2260
   563
        ///Assignment operator
alpar@2260
   564
        template <typename CMap>
alpar@2260
   565
        UEdgeMap& operator=(const CMap&) { 
alpar@2260
   566
          checkConcept<ReadMap<UEdge, T>, CMap>();
alpar@2260
   567
          return *this; 
alpar@2260
   568
        }
alpar@2260
   569
      };
alpar@2260
   570
alpar@2260
   571
      /// \brief Direct the given undirected edge.
alpar@2260
   572
      ///
alpar@2260
   573
      /// Direct the given undirected edge. The returned edge source
alpar@2260
   574
      /// will be the given node.
alpar@2260
   575
      Edge direct(const UEdge&, const Node&) const {
alpar@2260
   576
	return INVALID;
alpar@2260
   577
      }
alpar@2260
   578
alpar@2260
   579
      /// \brief Direct the given undirected edge.
alpar@2260
   580
      ///
alpar@2260
   581
      /// Direct the given undirected edge. The returned edge
deba@2291
   582
      /// represents the given undirected edge and the direction comes
alpar@2260
   583
      /// from the given bool.  The source of the undirected edge and
alpar@2260
   584
      /// the directed edge is the same when the given bool is true.
alpar@2260
   585
      Edge direct(const UEdge&, bool) const {
alpar@2260
   586
	return INVALID;
alpar@2260
   587
      }
alpar@2260
   588
alpar@2260
   589
      /// \brief Returns true if the edge has default orientation.
alpar@2260
   590
      ///
alpar@2260
   591
      /// Returns whether the given directed edge is same orientation as
alpar@2260
   592
      /// the corresponding undirected edge's default orientation.
alpar@2260
   593
      bool direction(Edge) const { return true; }
alpar@2260
   594
alpar@2260
   595
      /// \brief Returns the opposite directed edge.
alpar@2260
   596
      ///
alpar@2260
   597
      /// Returns the opposite directed edge.
alpar@2260
   598
      Edge oppositeEdge(Edge) const { return INVALID; }
alpar@2260
   599
alpar@2260
   600
      /// \brief Opposite node on an edge
alpar@2260
   601
      ///
alpar@2260
   602
      /// \return the opposite of the given Node on the given UEdge
alpar@2260
   603
      Node oppositeNode(Node, UEdge) const { return INVALID; }
alpar@2260
   604
alpar@2260
   605
      /// \brief First node of the undirected edge.
alpar@2260
   606
      ///
alpar@2260
   607
      /// \return the first node of the given UEdge.
alpar@2260
   608
      ///
alpar@2260
   609
      /// Naturally undirected edges don't have direction and thus
alpar@2260
   610
      /// don't have source and target node. But we use these two methods
alpar@2260
   611
      /// to query the two nodes of the edge. The direction of the edge
alpar@2260
   612
      /// which arises this way is called the inherent direction of the
alpar@2260
   613
      /// undirected edge, and is used to define the "default" direction
alpar@2260
   614
      /// of the directed versions of the edges.
alpar@2260
   615
      /// \sa direction
alpar@2260
   616
      Node source(UEdge) const { return INVALID; }
alpar@2260
   617
alpar@2260
   618
      /// \brief Second node of the undirected edge.
alpar@2260
   619
      Node target(UEdge) const { return INVALID; }
alpar@2260
   620
alpar@2260
   621
      /// \brief Source node of the directed edge.
alpar@2260
   622
      Node source(Edge) const { return INVALID; }
alpar@2260
   623
alpar@2260
   624
      /// \brief Target node of the directed edge.
alpar@2260
   625
      Node target(Edge) const { return INVALID; }
alpar@2260
   626
alpar@2260
   627
      void first(Node&) const {}
alpar@2260
   628
      void next(Node&) const {}
alpar@2260
   629
alpar@2260
   630
      void first(UEdge&) const {}
alpar@2260
   631
      void next(UEdge&) const {}
alpar@2260
   632
alpar@2260
   633
      void first(Edge&) const {}
alpar@2260
   634
      void next(Edge&) const {}
alpar@2260
   635
alpar@2260
   636
      void firstOut(Edge&, Node) const {}
alpar@2260
   637
      void nextOut(Edge&) const {}
alpar@2260
   638
alpar@2260
   639
      void firstIn(Edge&, Node) const {}
alpar@2260
   640
      void nextIn(Edge&) const {}
alpar@2260
   641
alpar@2260
   642
alpar@2260
   643
      void firstInc(UEdge &, bool &, const Node &) const {}
alpar@2260
   644
      void nextInc(UEdge &, bool &) const {}
alpar@2260
   645
alpar@2260
   646
      /// \brief Base node of the iterator
alpar@2260
   647
      ///
alpar@2260
   648
      /// Returns the base node (the source in this case) of the iterator
alpar@2260
   649
      Node baseNode(OutEdgeIt e) const {
alpar@2260
   650
	return source(e);
alpar@2260
   651
      }
alpar@2260
   652
      /// \brief Running node of the iterator
alpar@2260
   653
      ///
alpar@2260
   654
      /// Returns the running node (the target in this case) of the
alpar@2260
   655
      /// iterator
alpar@2260
   656
      Node runningNode(OutEdgeIt e) const {
alpar@2260
   657
	return target(e);
alpar@2260
   658
      }
alpar@2260
   659
alpar@2260
   660
      /// \brief Base node of the iterator
alpar@2260
   661
      ///
alpar@2260
   662
      /// Returns the base node (the target in this case) of the iterator
alpar@2260
   663
      Node baseNode(InEdgeIt e) const {
alpar@2260
   664
	return target(e);
alpar@2260
   665
      }
alpar@2260
   666
      /// \brief Running node of the iterator
alpar@2260
   667
      ///
alpar@2260
   668
      /// Returns the running node (the source in this case) of the
alpar@2260
   669
      /// iterator
alpar@2260
   670
      Node runningNode(InEdgeIt e) const {
alpar@2260
   671
	return source(e);
alpar@2260
   672
      }
alpar@2260
   673
alpar@2260
   674
      /// \brief Base node of the iterator
alpar@2260
   675
      ///
alpar@2260
   676
      /// Returns the base node of the iterator
alpar@2260
   677
      Node baseNode(IncEdgeIt) const {
alpar@2260
   678
	return INVALID;
alpar@2260
   679
      }
alpar@2260
   680
      
alpar@2260
   681
      /// \brief Running node of the iterator
alpar@2260
   682
      ///
alpar@2260
   683
      /// Returns the running node of the iterator
alpar@2260
   684
      Node runningNode(IncEdgeIt) const {
alpar@2260
   685
	return INVALID;
alpar@2260
   686
      }
alpar@2260
   687
alpar@2260
   688
      template <typename Graph>
alpar@2260
   689
      struct Constraints {
alpar@2260
   690
	void constraints() {
alpar@2260
   691
	  checkConcept<IterableUGraphComponent<>, Graph>();
alpar@2260
   692
	  checkConcept<MappableUGraphComponent<>, Graph>();
alpar@2260
   693
	}
alpar@2260
   694
      };
alpar@2260
   695
alpar@2260
   696
    };
alpar@2260
   697
alpar@2260
   698
  }
alpar@2260
   699
alpar@2260
   700
}
alpar@2260
   701
alpar@2260
   702
#endif