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