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