lemon/graph_utils.h
author athos
Fri, 24 Jun 2005 21:03:08 +0000
changeset 1514 c9b9bc63db4e
parent 1470 9b6f8c3587f0
child 1515 dd7616b51333
permissions -rw-r--r--
Improved getsart.dox and quicktour.dox
klao@946
     1
/* -*- C++ -*-
ladanyi@1435
     2
 * lemon/graph_utils.h - Part of LEMON, a generic C++ optimization library
klao@946
     3
 *
alpar@1164
     4
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     5
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
klao@946
     6
 *
klao@946
     7
 * Permission to use, modify and distribute this software is granted
klao@946
     8
 * provided that this copyright notice appears in all copies. For
klao@946
     9
 * precise terms see the accompanying LICENSE file.
klao@946
    10
 *
klao@946
    11
 * This software is provided "AS IS" with no warranty of any kind,
klao@946
    12
 * express or implied, and with no claim as to its suitability for any
klao@946
    13
 * purpose.
klao@946
    14
 *
klao@946
    15
 */
klao@946
    16
klao@946
    17
#ifndef LEMON_GRAPH_UTILS_H
klao@946
    18
#define LEMON_GRAPH_UTILS_H
klao@946
    19
klao@946
    20
#include <iterator>
deba@1419
    21
#include <vector>
alpar@1402
    22
#include <map>
klao@946
    23
klao@946
    24
#include <lemon/invalid.h>
klao@977
    25
#include <lemon/utility.h>
deba@1413
    26
#include <lemon/maps.h>
alpar@1459
    27
#include <lemon/bits/alteration_notifier.h>
klao@946
    28
alpar@947
    29
///\ingroup gutils
klao@946
    30
///\file
alpar@947
    31
///\brief Graph utilities.
klao@946
    32
///
alpar@964
    33
///\todo Please
alpar@964
    34
///revise the documentation.
alpar@964
    35
///
klao@946
    36
klao@946
    37
klao@946
    38
namespace lemon {
klao@946
    39
deba@1267
    40
  /// \addtogroup gutils
deba@1267
    41
  /// @{
alpar@947
    42
klao@946
    43
  /// \brief Function to count the items in the graph.
klao@946
    44
  ///
klao@946
    45
  /// This function counts the items in the graph.
klao@946
    46
  /// The complexity of the function is O(n) because
klao@946
    47
  /// it iterates on all of the items.
klao@946
    48
klao@946
    49
  template <typename Graph, typename ItemIt>
klao@977
    50
  inline int countItems(const Graph& g) {
klao@946
    51
    int num = 0;
klao@977
    52
    for (ItemIt it(g); it != INVALID; ++it) {
klao@946
    53
      ++num;
klao@946
    54
    }
klao@946
    55
    return num;
klao@946
    56
  }
klao@946
    57
klao@977
    58
  // Node counting:
klao@977
    59
klao@977
    60
  template <typename Graph>
klao@977
    61
  inline
klao@977
    62
  typename enable_if<typename Graph::NodeNumTag, int>::type
klao@977
    63
  _countNodes(const Graph &g) {
klao@977
    64
    return g.nodeNum();
klao@977
    65
  }
klao@977
    66
klao@977
    67
  template <typename Graph>
klao@977
    68
  inline int _countNodes(Wrap<Graph> w) {
klao@977
    69
    return countItems<Graph, typename Graph::NodeIt>(w.value);
klao@977
    70
  }
klao@977
    71
klao@946
    72
  /// \brief Function to count the nodes in the graph.
klao@946
    73
  ///
klao@946
    74
  /// This function counts the nodes in the graph.
klao@946
    75
  /// The complexity of the function is O(n) but for some
alpar@964
    76
  /// graph structure it is specialized to run in O(1).
klao@977
    77
  ///
klao@977
    78
  /// \todo refer how to specialize it
klao@946
    79
klao@946
    80
  template <typename Graph>
klao@977
    81
  inline int countNodes(const Graph& g) {
klao@977
    82
    return _countNodes<Graph>(g);
klao@977
    83
  }
klao@977
    84
klao@977
    85
  // Edge counting:
klao@977
    86
klao@977
    87
  template <typename Graph>
klao@977
    88
  inline
klao@977
    89
  typename enable_if<typename Graph::EdgeNumTag, int>::type
klao@977
    90
  _countEdges(const Graph &g) {
klao@977
    91
    return g.edgeNum();
klao@977
    92
  }
klao@977
    93
klao@977
    94
  template <typename Graph>
klao@977
    95
  inline int _countEdges(Wrap<Graph> w) {
klao@977
    96
    return countItems<Graph, typename Graph::EdgeIt>(w.value);
klao@946
    97
  }
klao@946
    98
klao@946
    99
  /// \brief Function to count the edges in the graph.
klao@946
   100
  ///
klao@946
   101
  /// This function counts the edges in the graph.
klao@946
   102
  /// The complexity of the function is O(e) but for some
alpar@964
   103
  /// graph structure it is specialized to run in O(1).
klao@977
   104
klao@946
   105
  template <typename Graph>
klao@977
   106
  inline int countEdges(const Graph& g) {
klao@977
   107
    return _countEdges<Graph>(g);
klao@946
   108
  }
klao@946
   109
klao@1053
   110
  // Undirected edge counting:
klao@1053
   111
klao@1053
   112
  template <typename Graph>
klao@1053
   113
  inline
klao@1053
   114
  typename enable_if<typename Graph::EdgeNumTag, int>::type
klao@1053
   115
  _countUndirEdges(const Graph &g) {
klao@1053
   116
    return g.undirEdgeNum();
klao@1053
   117
  }
klao@1053
   118
klao@1053
   119
  template <typename Graph>
klao@1053
   120
  inline int _countUndirEdges(Wrap<Graph> w) {
klao@1053
   121
    return countItems<Graph, typename Graph::UndirEdgeIt>(w.value);
klao@1053
   122
  }
klao@1053
   123
klao@1053
   124
  /// \brief Function to count the edges in the graph.
klao@946
   125
  ///
klao@1053
   126
  /// This function counts the edges in the graph.
klao@946
   127
  /// The complexity of the function is O(e) but for some
alpar@964
   128
  /// graph structure it is specialized to run in O(1).
klao@1053
   129
klao@946
   130
  template <typename Graph>
klao@1053
   131
  inline int countUndirEdges(const Graph& g) {
klao@1053
   132
    return _countUndirEdges<Graph>(g);
klao@946
   133
  }
klao@946
   134
klao@977
   135
klao@1053
   136
klao@946
   137
  template <typename Graph, typename DegIt>
klao@946
   138
  inline int countNodeDegree(const Graph& _g, const typename Graph::Node& _n) {
klao@946
   139
    int num = 0;
klao@946
   140
    for (DegIt it(_g, _n); it != INVALID; ++it) {
klao@946
   141
      ++num;
klao@946
   142
    }
klao@946
   143
    return num;
klao@946
   144
  }
alpar@967
   145
alpar@967
   146
  /// Finds an edge between two nodes of a graph.
alpar@967
   147
alpar@967
   148
  /// Finds an edge from node \c u to node \c v in graph \c g.
alpar@967
   149
  ///
alpar@967
   150
  /// If \c prev is \ref INVALID (this is the default value), then
alpar@967
   151
  /// it finds the first edge from \c u to \c v. Otherwise it looks for
alpar@967
   152
  /// the next edge from \c u to \c v after \c prev.
alpar@967
   153
  /// \return The found edge or \ref INVALID if there is no such an edge.
alpar@967
   154
  ///
alpar@967
   155
  /// Thus you can iterate through each edge from \c u to \c v as it follows.
alpar@967
   156
  /// \code
alpar@967
   157
  /// for(Edge e=findEdge(g,u,v);e!=INVALID;e=findEdge(g,u,v,e)) {
alpar@967
   158
  ///   ...
alpar@967
   159
  /// }
alpar@967
   160
  /// \endcode
alpar@967
   161
  /// \todo We may want to use the \ref concept::GraphBase "GraphBase"
alpar@967
   162
  /// interface here...
alpar@967
   163
  /// \bug Untested ...
alpar@967
   164
  template <typename Graph>
alpar@967
   165
  typename Graph::Edge findEdge(const Graph &g,
deba@1267
   166
				typename Graph::Node u, typename Graph::Node v,
deba@1267
   167
				typename Graph::Edge prev = INVALID) 
alpar@967
   168
  {
alpar@967
   169
    typename Graph::OutEdgeIt e(g,prev);
alpar@1079
   170
    //    if(prev==INVALID) g.first(e,u);
alpar@1079
   171
    if(prev==INVALID) e=typename Graph::OutEdgeIt(g,u);
alpar@967
   172
    else ++e;
alpar@1079
   173
    while(e!=INVALID && g.target(e)!=v) ++e;
alpar@967
   174
    return e;
alpar@967
   175
  }
alpar@964
   176
  
alpar@964
   177
  ///\e
klao@946
   178
alpar@964
   179
  ///\todo Please document.
alpar@964
   180
  ///
klao@946
   181
  template <typename Graph>
klao@946
   182
  inline int countOutEdges(const Graph& _g,  const typename Graph::Node& _n) {
klao@946
   183
    return countNodeDegree<Graph, typename Graph::OutEdgeIt>(_g, _n);
klao@946
   184
  }
klao@946
   185
alpar@964
   186
  ///\e
alpar@964
   187
alpar@964
   188
  ///\todo Please document.
alpar@964
   189
  ///
klao@946
   190
  template <typename Graph>
klao@946
   191
  inline int countInEdges(const Graph& _g,  const typename Graph::Node& _n) {
klao@946
   192
    return countNodeDegree<Graph, typename Graph::InEdgeIt>(_g, _n);
klao@946
   193
  }
klao@946
   194
klao@946
   195
  // graph copy
klao@946
   196
klao@946
   197
  template <
klao@946
   198
    typename DestinationGraph, 
klao@946
   199
    typename SourceGraph, 
klao@946
   200
    typename NodeBijection>
klao@946
   201
  void copyNodes(DestinationGraph& _d, const SourceGraph& _s, 
klao@946
   202
		 NodeBijection& _nb) {    
klao@946
   203
    for (typename SourceGraph::NodeIt it(_s); it != INVALID; ++it) {
klao@946
   204
      _nb[it] = _d.addNode();
klao@946
   205
    }
klao@946
   206
  }
klao@946
   207
klao@946
   208
  template <
klao@946
   209
    typename DestinationGraph, 
klao@946
   210
    typename SourceGraph, 
klao@946
   211
    typename NodeBijection,
klao@946
   212
    typename EdgeBijection>
klao@946
   213
  void copyEdges(DestinationGraph& _d, const SourceGraph& _s,
klao@946
   214
		 const NodeBijection& _nb, EdgeBijection& _eb) {    
klao@946
   215
    for (typename SourceGraph::EdgeIt it(_s); it != INVALID; ++it) {
alpar@986
   216
      _eb[it] = _d.addEdge(_nb[_s.source(it)], _nb[_s.target(it)]);
klao@946
   217
    }
klao@946
   218
  }
klao@946
   219
klao@946
   220
  template <
klao@946
   221
    typename DestinationGraph, 
klao@946
   222
    typename SourceGraph, 
klao@946
   223
    typename NodeBijection,
klao@946
   224
    typename EdgeBijection>
klao@946
   225
  void copyGraph(DestinationGraph& _d, const SourceGraph& _s, 
klao@946
   226
		 NodeBijection& _nb, EdgeBijection& _eb) {
klao@946
   227
    nodeCopy(_d, _s, _nb);
klao@946
   228
    edgeCopy(_d, _s, _nb, _eb);
klao@946
   229
  }
klao@946
   230
 
deba@1267
   231
  template <
klao@946
   232
    typename _DestinationGraph, 
klao@946
   233
    typename _SourceGraph, 
klao@946
   234
    typename _NodeBijection 
klao@946
   235
    =typename _SourceGraph::template NodeMap<typename _DestinationGraph::Node>,
klao@946
   236
    typename _EdgeBijection 
deba@1267
   237
    = typename _SourceGraph::template EdgeMap<typename _DestinationGraph::Edge>
deba@1267
   238
  >
deba@1267
   239
  class GraphCopy {
deba@1267
   240
  public:
deba@1267
   241
    
deba@1267
   242
    typedef _DestinationGraph DestinationGraph;
deba@1267
   243
    typedef _SourceGraph SourceGraph;
klao@946
   244
deba@1267
   245
    typedef _NodeBijection NodeBijection;
deba@1267
   246
    typedef _EdgeBijection EdgeBijection;
deba@1267
   247
    
deba@1267
   248
  protected:          
deba@1267
   249
    
deba@1267
   250
    NodeBijection node_bijection;
deba@1267
   251
    EdgeBijection edge_bijection;     
klao@946
   252
deba@1267
   253
  public:
deba@1267
   254
     
deba@1267
   255
    GraphCopy(DestinationGraph& _d, const SourceGraph& _s) {
deba@1267
   256
      copyGraph(_d, _s, node_bijection, edge_bijection);
deba@1267
   257
    }
deba@1267
   258
    
deba@1267
   259
    const NodeBijection& getNodeBijection() const {
deba@1267
   260
      return node_bijection;
deba@1267
   261
    }
klao@946
   262
deba@1267
   263
    const EdgeBijection& getEdgeBijection() const {
deba@1267
   264
      return edge_bijection;
deba@1267
   265
    }
deba@1267
   266
     
deba@1267
   267
  };
klao@946
   268
klao@946
   269
deba@1267
   270
  template <typename _Graph, typename _Item>
deba@1419
   271
  class ItemSetTraits {};
deba@1192
   272
  
deba@1192
   273
  template <typename _Graph>
deba@1267
   274
  class ItemSetTraits<_Graph, typename _Graph::Node> {
deba@1192
   275
  public:
deba@1192
   276
    
deba@1192
   277
    typedef _Graph Graph;
alpar@947
   278
deba@1192
   279
    typedef typename Graph::Node Item;
deba@1192
   280
    typedef typename Graph::NodeIt ItemIt;
deba@1192
   281
deba@1192
   282
    template <typename _Value>
deba@1192
   283
    class Map : public Graph::template NodeMap<_Value> {
deba@1192
   284
    public:
deba@1192
   285
      typedef typename Graph::template NodeMap<_Value> Parent; 
deba@1192
   286
      typedef typename Parent::Value Value;
deba@1192
   287
deba@1192
   288
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1192
   289
      Map(const Graph& _graph, const Value& _value) 
deba@1192
   290
	: Parent(_graph, _value) {}
deba@1192
   291
    };
deba@1192
   292
deba@1192
   293
  };
deba@1192
   294
deba@1192
   295
  template <typename _Graph>
deba@1267
   296
  class ItemSetTraits<_Graph, typename _Graph::Edge> {
deba@1192
   297
  public:
deba@1192
   298
    
deba@1192
   299
    typedef _Graph Graph;
deba@1192
   300
deba@1192
   301
    typedef typename Graph::Edge Item;
deba@1192
   302
    typedef typename Graph::EdgeIt ItemIt;
deba@1192
   303
deba@1192
   304
    template <typename _Value>
deba@1192
   305
    class Map : public Graph::template EdgeMap<_Value> {
deba@1192
   306
    public:
deba@1192
   307
      typedef typename Graph::template EdgeMap<_Value> Parent; 
deba@1192
   308
      typedef typename Parent::Value Value;
deba@1192
   309
deba@1192
   310
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1192
   311
      Map(const Graph& _graph, const Value& _value) 
deba@1192
   312
	: Parent(_graph, _value) {}
deba@1192
   313
    };
deba@1192
   314
deba@1192
   315
  };
deba@1192
   316
deba@1267
   317
  template <typename _Graph>
deba@1267
   318
  class ItemSetTraits<_Graph, typename _Graph::UndirEdge> {
deba@1267
   319
  public:
deba@1267
   320
    
deba@1267
   321
    typedef _Graph Graph;
deba@1267
   322
deba@1267
   323
    typedef typename Graph::UndirEdge Item;
deba@1267
   324
    typedef typename Graph::UndirEdgeIt ItemIt;
deba@1267
   325
deba@1267
   326
    template <typename _Value>
deba@1267
   327
    class Map : public Graph::template UndirEdgeMap<_Value> {
deba@1267
   328
    public:
deba@1267
   329
      typedef typename Graph::template UndirEdgeMap<_Value> Parent; 
deba@1267
   330
      typedef typename Parent::Value Value;
deba@1267
   331
deba@1267
   332
      Map(const Graph& _graph) : Parent(_graph) {}
deba@1267
   333
      Map(const Graph& _graph, const Value& _value) 
deba@1267
   334
	: Parent(_graph, _value) {}
deba@1267
   335
    };
deba@1267
   336
deba@1267
   337
  };
deba@1192
   338
deba@1192
   339
  /// @}
alpar@1402
   340
alpar@1402
   341
  /// \addtogroup graph_maps
alpar@1402
   342
  /// @{
alpar@1402
   343
alpar@1402
   344
  template <typename Map, typename Enable = void>
alpar@1402
   345
  struct ReferenceMapTraits {
alpar@1402
   346
    typedef typename Map::Value Value;
alpar@1402
   347
    typedef typename Map::Value& Reference;
alpar@1402
   348
    typedef const typename Map::Value& ConstReference;
alpar@1402
   349
    typedef typename Map::Value* Pointer;
alpar@1402
   350
    typedef const typename Map::Value* ConstPointer;
alpar@1402
   351
  };
alpar@1402
   352
alpar@1402
   353
  template <typename Map>
alpar@1402
   354
  struct ReferenceMapTraits<
alpar@1402
   355
    Map, 
alpar@1402
   356
    typename enable_if<typename Map::FullTypeTag, void>::type
alpar@1402
   357
  > {
alpar@1402
   358
    typedef typename Map::Value Value;
alpar@1402
   359
    typedef typename Map::Reference Reference;
alpar@1402
   360
    typedef typename Map::ConstReference ConstReference;
alpar@1402
   361
    typedef typename Map::Pointer Pointer;
alpar@1402
   362
    typedef typename Map::ConstPointer ConstPointer;
alpar@1402
   363
  };
alpar@1402
   364
deba@1413
   365
  /// Provides an immutable and unique id for each item in the graph.
deba@1413
   366
deba@1413
   367
  /// The IdMap class provides an unique and immutable mapping for each item
deba@1413
   368
  /// in the graph.
deba@1413
   369
  ///
deba@1413
   370
  template <typename _Graph, typename _Item>
deba@1413
   371
  class IdMap {
deba@1413
   372
  public:
deba@1413
   373
    typedef _Graph Graph;
deba@1413
   374
    typedef int Value;
deba@1413
   375
    typedef _Item Item;
deba@1413
   376
    typedef _Item Key;
deba@1413
   377
deba@1419
   378
    typedef True NeedCopy;
deba@1419
   379
deba@1413
   380
    /// \brief Constructor.
deba@1413
   381
    ///
deba@1413
   382
    /// Constructor for creating id map.
deba@1413
   383
    IdMap(const Graph& _graph) : graph(&_graph) {}
deba@1413
   384
deba@1413
   385
    /// \brief Gives back the \e id of the item.
deba@1413
   386
    ///
deba@1413
   387
    /// Gives back the immutable and unique \e id of the map.
deba@1413
   388
    int operator[](const Item& item) const { return graph->id(item);}
deba@1413
   389
deba@1413
   390
deba@1413
   391
  private:
deba@1413
   392
    const Graph* graph;
deba@1413
   393
deba@1413
   394
  public:
deba@1413
   395
deba@1413
   396
    /// \brief The class represents the inverse of the map.
deba@1413
   397
    ///
deba@1413
   398
    /// The class represents the inverse of the map.
deba@1413
   399
    /// \see inverse()
deba@1413
   400
    class InverseMap {
deba@1413
   401
    public:
deba@1419
   402
deba@1419
   403
      typedef True NeedCopy;
deba@1419
   404
deba@1413
   405
      /// \brief Constructor.
deba@1413
   406
      ///
deba@1413
   407
      /// Constructor for creating an id-to-item map.
deba@1413
   408
      InverseMap(const Graph& _graph) : graph(&_graph) {}
deba@1413
   409
deba@1413
   410
      /// \brief Constructor.
deba@1413
   411
      ///
deba@1413
   412
      /// Constructor for creating an id-to-item map.
deba@1413
   413
      InverseMap(const IdMap& idMap) : graph(idMap.graph) {}
deba@1413
   414
deba@1413
   415
      /// \brief Gives back the given item from its id.
deba@1413
   416
      ///
deba@1413
   417
      /// Gives back the given item from its id.
deba@1413
   418
      /// 
deba@1413
   419
      Item operator[](int id) const { return graph->fromId(id, Item());}
deba@1413
   420
    private:
deba@1413
   421
      const Graph* graph;
deba@1413
   422
    };
deba@1413
   423
deba@1413
   424
    /// \brief Gives back the inverse of the map.
deba@1413
   425
    ///
deba@1413
   426
    /// Gives back the inverse of the map.
deba@1413
   427
    InverseMap inverse() const { return InverseMap(*graph);} 
deba@1413
   428
deba@1413
   429
  };
deba@1413
   430
deba@1413
   431
  
alpar@1402
   432
  /// \brief General inversable graph-map type.
alpar@1402
   433
alpar@1402
   434
  /// This type provides simple inversable map functions. 
alpar@1402
   435
  /// The InversableMap wraps an arbitrary ReadWriteMap 
alpar@1402
   436
  /// and if a key is setted to a new value then store it
alpar@1402
   437
  /// in the inverse map.
alpar@1402
   438
  /// \param _Graph The graph type.
alpar@1402
   439
  /// \param _Map The map to extend with inversable functionality. 
alpar@1402
   440
  template <
alpar@1402
   441
    typename _Graph,
alpar@1402
   442
    typename _Item, 
alpar@1402
   443
    typename _Value,
alpar@1402
   444
    typename _Map 
deba@1413
   445
    = typename ItemSetTraits<_Graph, _Item>::template Map<_Value>::Parent 
alpar@1402
   446
  >
deba@1413
   447
  class InvertableMap : protected _Map {
alpar@1402
   448
alpar@1402
   449
  public:
alpar@1402
   450
 
alpar@1402
   451
    typedef _Map Map;
alpar@1402
   452
    typedef _Graph Graph;
deba@1413
   453
deba@1413
   454
    /// The key type of InvertableMap (Node, Edge, UndirEdge).
alpar@1402
   455
    typedef typename _Map::Key Key;
deba@1413
   456
    /// The value type of the InvertableMap.
alpar@1402
   457
    typedef typename _Map::Value Value;
alpar@1402
   458
alpar@1402
   459
    /// \brief Constructor.
alpar@1402
   460
    ///
deba@1413
   461
    /// Construct a new InvertableMap for the graph.
alpar@1402
   462
    ///
deba@1413
   463
    InvertableMap(const Graph& graph) : Map(graph) {} 
alpar@1402
   464
    
alpar@1402
   465
    /// \brief The setter function of the map.
alpar@1402
   466
    ///
deba@1413
   467
    /// Sets the mapped value.
alpar@1402
   468
    void set(const Key& key, const Value& val) {
alpar@1402
   469
      Value oldval = Map::operator[](key);
deba@1413
   470
      typename Container::iterator it = invMap.find(oldval);
alpar@1402
   471
      if (it != invMap.end() && it->second == key) {
alpar@1402
   472
	invMap.erase(it);
alpar@1402
   473
      }      
alpar@1402
   474
      invMap.insert(make_pair(val, key));
alpar@1402
   475
      Map::set(key, val);
alpar@1402
   476
    }
alpar@1402
   477
alpar@1402
   478
    /// \brief The getter function of the map.
alpar@1402
   479
    ///
alpar@1402
   480
    /// It gives back the value associated with the key.
deba@1413
   481
    const Value operator[](const Key& key) const {
alpar@1402
   482
      return Map::operator[](key);
alpar@1402
   483
    }
alpar@1402
   484
alpar@1402
   485
    /// \brief Add a new key to the map.
alpar@1402
   486
    ///
alpar@1402
   487
    /// Add a new key to the map. It is called by the
alpar@1402
   488
    /// \c AlterationNotifier.
alpar@1402
   489
    virtual void add(const Key& key) {
alpar@1402
   490
      Map::add(key);
alpar@1402
   491
    }
alpar@1402
   492
alpar@1402
   493
    /// \brief Erase the key from the map.
alpar@1402
   494
    ///
alpar@1402
   495
    /// Erase the key to the map. It is called by the
alpar@1402
   496
    /// \c AlterationNotifier.
alpar@1402
   497
    virtual void erase(const Key& key) {
alpar@1402
   498
      Value val = Map::operator[](key);
deba@1413
   499
      typename Container::iterator it = invMap.find(val);
alpar@1402
   500
      if (it != invMap.end() && it->second == key) {
alpar@1402
   501
	invMap.erase(it);
alpar@1402
   502
      }
alpar@1402
   503
      Map::erase(key);
alpar@1402
   504
    }
alpar@1402
   505
alpar@1402
   506
    /// \brief Clear the keys from the map and inverse map.
alpar@1402
   507
    ///
alpar@1402
   508
    /// Clear the keys from the map and inverse map. It is called by the
alpar@1402
   509
    /// \c AlterationNotifier.
alpar@1402
   510
    virtual void clear() {
alpar@1402
   511
      invMap.clear();
alpar@1402
   512
      Map::clear();
alpar@1402
   513
    }
alpar@1402
   514
deba@1413
   515
  private:
deba@1413
   516
    
deba@1413
   517
    typedef std::map<Value, Key> Container;
deba@1413
   518
    Container invMap;    
deba@1413
   519
deba@1413
   520
  public:
deba@1413
   521
deba@1413
   522
    /// \brief The inverse map type.
deba@1413
   523
    ///
deba@1413
   524
    /// The inverse of this map. The subscript operator of the map
deba@1413
   525
    /// gives back always the item what was last assigned to the value. 
deba@1413
   526
    class InverseMap {
deba@1413
   527
    public:
deba@1413
   528
      /// \brief Constructor of the InverseMap.
deba@1413
   529
      ///
deba@1413
   530
      /// Constructor of the InverseMap.
deba@1413
   531
      InverseMap(const InvertableMap& _inverted) : inverted(_inverted) {}
deba@1413
   532
deba@1413
   533
      /// The value type of the InverseMap.
deba@1413
   534
      typedef typename InvertableMap::Key Value;
deba@1413
   535
      /// The key type of the InverseMap.
deba@1413
   536
      typedef typename InvertableMap::Value Key; 
deba@1413
   537
deba@1413
   538
      /// \brief Subscript operator. 
deba@1413
   539
      ///
deba@1413
   540
      /// Subscript operator. It gives back always the item 
deba@1413
   541
      /// what was last assigned to the value.
deba@1413
   542
      Value operator[](const Key& key) const {
deba@1413
   543
	typename Container::const_iterator it = inverted.invMap.find(key);
deba@1413
   544
	return it->second;
deba@1413
   545
      }
deba@1413
   546
      
deba@1413
   547
    private:
deba@1413
   548
      const InvertableMap& inverted;
deba@1413
   549
    };
deba@1413
   550
alpar@1402
   551
    /// \brief It gives back the just readeable inverse map.
alpar@1402
   552
    ///
alpar@1402
   553
    /// It gives back the just readeable inverse map.
deba@1413
   554
    InverseMap inverse() const {
deba@1413
   555
      return InverseMap(*this);
alpar@1402
   556
    } 
alpar@1402
   557
alpar@1402
   558
deba@1413
   559
    
alpar@1402
   560
  };
alpar@1402
   561
alpar@1402
   562
  /// \brief Provides a mutable, continuous and unique descriptor for each 
alpar@1402
   563
  /// item in the graph.
alpar@1402
   564
  ///
alpar@1402
   565
  /// The DescriptorMap class provides a mutable, continuous and immutable
deba@1413
   566
  /// mapping for each item in the graph. The value for an item may mutated
deba@1413
   567
  /// on each operation when the an item erased or added to graph.
alpar@1402
   568
  ///
alpar@1402
   569
  /// \param _Graph The graph class the \c DescriptorMap belongs to.
alpar@1402
   570
  /// \param _Item The Item is the Key of the Map. It may be Node, Edge or 
alpar@1402
   571
  /// UndirEdge.
alpar@1402
   572
  /// \param _Map A ReadWriteMap mapping from the item type to integer.
alpar@1402
   573
  template <
alpar@1402
   574
    typename _Graph,   
alpar@1402
   575
    typename _Item,
deba@1413
   576
    typename _Map 
deba@1413
   577
    = typename ItemSetTraits<_Graph, _Item>::template Map<int>::Parent
alpar@1402
   578
  >
alpar@1402
   579
  class DescriptorMap : protected _Map {
alpar@1402
   580
alpar@1402
   581
    typedef _Item Item;
alpar@1402
   582
    typedef _Map Map;
alpar@1402
   583
alpar@1402
   584
  public:
alpar@1402
   585
    /// The graph class of DescriptorMap.
alpar@1402
   586
    typedef _Graph Graph;
alpar@1402
   587
alpar@1402
   588
    /// The key type of DescriptorMap (Node, Edge, UndirEdge).
alpar@1402
   589
    typedef typename _Map::Key Key;
alpar@1402
   590
    /// The value type of DescriptorMap.
alpar@1402
   591
    typedef typename _Map::Value Value;
alpar@1402
   592
alpar@1402
   593
    /// \brief Constructor.
alpar@1402
   594
    ///
deba@1413
   595
    /// Constructor for descriptor map.
alpar@1402
   596
    DescriptorMap(const Graph& _graph) : Map(_graph) {
alpar@1402
   597
      build();
alpar@1402
   598
    }
alpar@1402
   599
alpar@1402
   600
    /// \brief Add a new key to the map.
alpar@1402
   601
    ///
alpar@1402
   602
    /// Add a new key to the map. It is called by the
alpar@1402
   603
    /// \c AlterationNotifier.
alpar@1402
   604
    virtual void add(const Item& item) {
alpar@1402
   605
      Map::add(item);
alpar@1402
   606
      Map::set(item, invMap.size());
alpar@1402
   607
      invMap.push_back(item);
alpar@1402
   608
    }
alpar@1402
   609
alpar@1402
   610
    /// \brief Erase the key from the map.
alpar@1402
   611
    ///
alpar@1402
   612
    /// Erase the key to the map. It is called by the
alpar@1402
   613
    /// \c AlterationNotifier.
alpar@1402
   614
    virtual void erase(const Item& item) {
alpar@1402
   615
      Map::set(invMap.back(), Map::operator[](item));
alpar@1402
   616
      invMap[Map::operator[](item)] = invMap.back();
deba@1413
   617
      invMap.pop_back();
alpar@1402
   618
      Map::erase(item);
alpar@1402
   619
    }
alpar@1402
   620
alpar@1402
   621
    /// \brief Build the unique map.
alpar@1402
   622
    ///
alpar@1402
   623
    /// Build the unique map. It is called by the
alpar@1402
   624
    /// \c AlterationNotifier.
alpar@1402
   625
    virtual void build() {
alpar@1402
   626
      Map::build();
alpar@1402
   627
      Item it;
alpar@1402
   628
      const typename Map::Graph* graph = Map::getGraph(); 
alpar@1402
   629
      for (graph->first(it); it != INVALID; graph->next(it)) {
alpar@1402
   630
	Map::set(it, invMap.size());
alpar@1402
   631
	invMap.push_back(it);	
alpar@1402
   632
      }      
alpar@1402
   633
    }
alpar@1402
   634
    
alpar@1402
   635
    /// \brief Clear the keys from the map.
alpar@1402
   636
    ///
alpar@1402
   637
    /// Clear the keys from the map. It is called by the
alpar@1402
   638
    /// \c AlterationNotifier.
alpar@1402
   639
    virtual void clear() {
alpar@1402
   640
      invMap.clear();
alpar@1402
   641
      Map::clear();
alpar@1402
   642
    }
alpar@1402
   643
alpar@1402
   644
    /// \brief Gives back the \e descriptor of the item.
alpar@1402
   645
    ///
alpar@1402
   646
    /// Gives back the mutable and unique \e descriptor of the map.
alpar@1402
   647
    int operator[](const Item& item) const {
alpar@1402
   648
      return Map::operator[](item);
alpar@1402
   649
    }
alpar@1402
   650
    
deba@1413
   651
  private:
deba@1413
   652
deba@1413
   653
    typedef std::vector<Item> Container;
deba@1413
   654
    Container invMap;
deba@1413
   655
deba@1413
   656
  public:
deba@1413
   657
    /// \brief The inverse map type.
deba@1413
   658
    ///
deba@1413
   659
    /// The inverse map type.
deba@1413
   660
    class InverseMap {
deba@1413
   661
    public:
deba@1413
   662
      /// \brief Constructor of the InverseMap.
deba@1413
   663
      ///
deba@1413
   664
      /// Constructor of the InverseMap.
deba@1413
   665
      InverseMap(const DescriptorMap& _inverted) 
deba@1413
   666
	: inverted(_inverted) {}
deba@1413
   667
deba@1413
   668
deba@1413
   669
      /// The value type of the InverseMap.
deba@1413
   670
      typedef typename DescriptorMap::Key Value;
deba@1413
   671
      /// The key type of the InverseMap.
deba@1413
   672
      typedef typename DescriptorMap::Value Key; 
deba@1413
   673
deba@1413
   674
      /// \brief Subscript operator. 
deba@1413
   675
      ///
deba@1413
   676
      /// Subscript operator. It gives back the item 
deba@1413
   677
      /// that the descriptor belongs to currently.
deba@1413
   678
      Value operator[](const Key& key) const {
deba@1413
   679
	return inverted.invMap[key];
deba@1413
   680
      }
deba@1470
   681
deba@1470
   682
      /// \brief Size of the map.
deba@1470
   683
      ///
deba@1470
   684
      /// Returns the size of the map.
deba@1470
   685
      unsigned size() const {
deba@1470
   686
	return inverted.invMap.size();
deba@1470
   687
      }
deba@1413
   688
      
deba@1413
   689
    private:
deba@1413
   690
      const DescriptorMap& inverted;
deba@1413
   691
    };
deba@1413
   692
alpar@1402
   693
    /// \brief Gives back the inverse of the map.
alpar@1402
   694
    ///
alpar@1402
   695
    /// Gives back the inverse of the map.
alpar@1402
   696
    const InverseMap inverse() const {
deba@1413
   697
      return InverseMap(*this);
alpar@1402
   698
    }
alpar@1402
   699
  };
alpar@1402
   700
alpar@1402
   701
  /// \brief Returns the source of the given edge.
alpar@1402
   702
  ///
alpar@1402
   703
  /// The SourceMap gives back the source Node of the given edge. 
alpar@1402
   704
  /// \author Balazs Dezso
alpar@1402
   705
  template <typename Graph>
alpar@1402
   706
  class SourceMap {
alpar@1402
   707
  public:
deba@1419
   708
deba@1419
   709
    typedef True NeedCopy;
deba@1419
   710
alpar@1402
   711
    typedef typename Graph::Node Value;
alpar@1402
   712
    typedef typename Graph::Edge Key;
alpar@1402
   713
alpar@1402
   714
    /// \brief Constructor
alpar@1402
   715
    ///
alpar@1402
   716
    /// Constructor
alpar@1402
   717
    /// \param _graph The graph that the map belongs to.
alpar@1402
   718
    SourceMap(const Graph& _graph) : graph(_graph) {}
alpar@1402
   719
alpar@1402
   720
    /// \brief The subscript operator.
alpar@1402
   721
    ///
alpar@1402
   722
    /// The subscript operator.
alpar@1402
   723
    /// \param edge The edge 
alpar@1402
   724
    /// \return The source of the edge 
alpar@1402
   725
    Value operator[](const Key& edge) {
alpar@1402
   726
      return graph.source(edge);
alpar@1402
   727
    }
alpar@1402
   728
alpar@1402
   729
  private:
alpar@1402
   730
    const Graph& graph;
alpar@1402
   731
  };
alpar@1402
   732
alpar@1402
   733
  /// \brief Returns a \ref SourceMap class
alpar@1402
   734
  ///
alpar@1402
   735
  /// This function just returns an \ref SourceMap class.
alpar@1402
   736
  /// \relates SourceMap
alpar@1402
   737
  template <typename Graph>
alpar@1402
   738
  inline SourceMap<Graph> sourceMap(const Graph& graph) {
alpar@1402
   739
    return SourceMap<Graph>(graph);
alpar@1402
   740
  } 
alpar@1402
   741
alpar@1402
   742
  /// \brief Returns the target of the given edge.
alpar@1402
   743
  ///
alpar@1402
   744
  /// The TargetMap gives back the target Node of the given edge. 
alpar@1402
   745
  /// \author Balazs Dezso
alpar@1402
   746
  template <typename Graph>
alpar@1402
   747
  class TargetMap {
alpar@1402
   748
  public:
deba@1419
   749
deba@1419
   750
    typedef True NeedCopy;
deba@1419
   751
alpar@1402
   752
    typedef typename Graph::Node Value;
alpar@1402
   753
    typedef typename Graph::Edge Key;
alpar@1402
   754
alpar@1402
   755
    /// \brief Constructor
alpar@1402
   756
    ///
alpar@1402
   757
    /// Constructor
alpar@1402
   758
    /// \param _graph The graph that the map belongs to.
alpar@1402
   759
    TargetMap(const Graph& _graph) : graph(_graph) {}
alpar@1402
   760
alpar@1402
   761
    /// \brief The subscript operator.
alpar@1402
   762
    ///
alpar@1402
   763
    /// The subscript operator.
alpar@1402
   764
    /// \param edge The edge 
alpar@1402
   765
    /// \return The target of the edge 
alpar@1402
   766
    Value operator[](const Key& key) {
alpar@1402
   767
      return graph.target(key);
alpar@1402
   768
    }
alpar@1402
   769
alpar@1402
   770
  private:
alpar@1402
   771
    const Graph& graph;
alpar@1402
   772
  };
alpar@1402
   773
alpar@1402
   774
  /// \brief Returns a \ref TargetMap class
alpar@1402
   775
alpar@1402
   776
  /// This function just returns an \ref TargetMap class.
alpar@1402
   777
  /// \relates TargetMap
alpar@1402
   778
  template <typename Graph>
alpar@1402
   779
  inline TargetMap<Graph> targetMap(const Graph& graph) {
alpar@1402
   780
    return TargetMap<Graph>(graph);
alpar@1402
   781
  }
alpar@1402
   782
deba@1419
   783
  /// \brief Returns the "forward" directed edge view of undirected edge.
deba@1419
   784
  ///
deba@1419
   785
  /// Returns the "forward" directed edge view of undirected edge.
deba@1419
   786
  /// \author Balazs Dezso
deba@1419
   787
  template <typename Graph>
deba@1419
   788
  class ForwardMap {
deba@1419
   789
  public:
deba@1419
   790
deba@1419
   791
    typedef True NeedCopy;
deba@1419
   792
deba@1419
   793
    typedef typename Graph::Edge Value;
deba@1419
   794
    typedef typename Graph::UndirEdge Key;
deba@1419
   795
deba@1419
   796
    /// \brief Constructor
deba@1419
   797
    ///
deba@1419
   798
    /// Constructor
deba@1419
   799
    /// \param _graph The graph that the map belongs to.
deba@1419
   800
    ForwardMap(const Graph& _graph) : graph(_graph) {}
deba@1419
   801
deba@1419
   802
    /// \brief The subscript operator.
deba@1419
   803
    ///
deba@1419
   804
    /// The subscript operator.
deba@1419
   805
    /// \param key An undirected edge 
deba@1419
   806
    /// \return The "forward" directed edge view of undirected edge 
deba@1419
   807
    Value operator[](const Key& key) const {
deba@1419
   808
      return graph.edgeWithSource(key, graph.source(key));
deba@1419
   809
    }
deba@1419
   810
deba@1419
   811
  private:
deba@1419
   812
    const Graph& graph;
deba@1419
   813
  };
deba@1419
   814
deba@1419
   815
  /// \brief Returns a \ref ForwardMap class
deba@1419
   816
deba@1419
   817
  /// This function just returns an \ref ForwardMap class.
deba@1419
   818
  /// \relates ForwardMap
deba@1419
   819
  template <typename Graph>
deba@1419
   820
  inline ForwardMap<Graph> forwardMap(const Graph& graph) {
deba@1419
   821
    return ForwardMap<Graph>(graph);
deba@1419
   822
  }
deba@1419
   823
deba@1419
   824
  /// \brief Returns the "backward" directed edge view of undirected edge.
deba@1419
   825
  ///
deba@1419
   826
  /// Returns the "backward" directed edge view of undirected edge.
deba@1419
   827
  /// \author Balazs Dezso
deba@1419
   828
  template <typename Graph>
deba@1419
   829
  class BackwardMap {
deba@1419
   830
  public:
deba@1419
   831
    typedef True NeedCopy;
deba@1419
   832
deba@1419
   833
    typedef typename Graph::Edge Value;
deba@1419
   834
    typedef typename Graph::UndirEdge Key;
deba@1419
   835
deba@1419
   836
    /// \brief Constructor
deba@1419
   837
    ///
deba@1419
   838
    /// Constructor
deba@1419
   839
    /// \param _graph The graph that the map belongs to.
deba@1419
   840
    BackwardMap(const Graph& _graph) : graph(_graph) {}
deba@1419
   841
deba@1419
   842
    /// \brief The subscript operator.
deba@1419
   843
    ///
deba@1419
   844
    /// The subscript operator.
deba@1419
   845
    /// \param key An undirected edge 
deba@1419
   846
    /// \return The "backward" directed edge view of undirected edge 
deba@1419
   847
    Value operator[](const Key& key) const {
deba@1419
   848
      return graph.edgeWithSource(key, graph.target(key));
deba@1419
   849
    }
deba@1419
   850
deba@1419
   851
  private:
deba@1419
   852
    const Graph& graph;
deba@1419
   853
  };
deba@1419
   854
deba@1419
   855
  /// \brief Returns a \ref BackwardMap class
deba@1419
   856
deba@1419
   857
  /// This function just returns an \ref BackwardMap class.
deba@1419
   858
  /// \relates BackwardMap
deba@1419
   859
  template <typename Graph>
deba@1419
   860
  inline BackwardMap<Graph> backwardMap(const Graph& graph) {
deba@1419
   861
    return BackwardMap<Graph>(graph);
deba@1419
   862
  }
deba@1419
   863
alpar@1402
   864
alpar@1453
   865
alpar@1459
   866
  /// Map of the node in-degrees.
alpar@1453
   867
alpar@1459
   868
  ///This map returns the in-degree of a node. Ones it is constructed,
alpar@1459
   869
  ///the degrees are stored in a standard NodeMap, so each query is done
alpar@1459
   870
  ///in constant time. On the other hand, the values updates automatically
alpar@1459
   871
  ///whenever the graph changes.
alpar@1453
   872
  ///
alpar@1459
   873
  ///\sa OutDegMap
alpar@1453
   874
  template <typename _Graph>
alpar@1453
   875
  class InDegMap  :
alpar@1459
   876
    protected _Graph::template NodeMap<int>,
alpar@1459
   877
    protected AlterationNotifier<typename _Graph::Edge>::ObserverBase
alpar@1453
   878
  {
alpar@1459
   879
    const _Graph& graph;
alpar@1453
   880
  public:
alpar@1453
   881
    typedef int Value;
alpar@1453
   882
    typedef typename _Graph::Node Key;
alpar@1453
   883
alpar@1453
   884
    /// \brief Constructor.
alpar@1453
   885
    ///
alpar@1453
   886
    /// Constructor for creating in-degree map.
alpar@1459
   887
    InDegMap(const _Graph& _graph) :
ladanyi@1467
   888
      _Graph::template NodeMap<int>(_graph,0),
alpar@1459
   889
      graph(_graph)
alpar@1453
   890
    {
alpar@1459
   891
      AlterationNotifier<typename _Graph::Edge>
alpar@1459
   892
	::ObserverBase::attach(graph.getNotifier(typename _Graph::Edge()));
alpar@1453
   893
klao@1454
   894
      for(typename _Graph::NodeIt n(graph);n!=INVALID;++n)
klao@1454
   895
	for(typename _Graph::InEdgeIt e(graph,n);e!=INVALID;++e)
alpar@1459
   896
	  _Graph::template NodeMap<int>::operator[](graph.target(e))++;
alpar@1453
   897
    }
alpar@1453
   898
alpar@1459
   899
    virtual ~InDegMap() 
alpar@1453
   900
    {
alpar@1459
   901
      AlterationNotifier<typename _Graph::Edge>::
alpar@1453
   902
	ObserverBase::detach();
alpar@1453
   903
    }
alpar@1453
   904
    
alpar@1459
   905
    /// Gives back the in-degree of a Node.
alpar@1459
   906
    int operator[](const Key& k) const {
alpar@1459
   907
      return _Graph::template NodeMap<int>::operator[](k);
alpar@1459
   908
    }
alpar@1453
   909
alpar@1453
   910
  protected:
alpar@1453
   911
    virtual void add(const typename _Graph::Node& n) {
alpar@1459
   912
      _Graph::template NodeMap<int>::add(n);
alpar@1459
   913
       _Graph::template NodeMap<int>::operator[](n)=0;
klao@1454
   914
    }
alpar@1459
   915
    virtual void erase(const typename _Graph::Node&n) 
alpar@1453
   916
    {
alpar@1459
   917
      _Graph::template NodeMap<int>::erase(n);
alpar@1453
   918
    }
klao@1454
   919
    virtual void add(const typename _Graph::Edge& e) {
alpar@1459
   920
      _Graph::template NodeMap<int>::operator[](graph.target(e))++;
klao@1454
   921
    }
klao@1454
   922
    virtual void erase(const typename _Graph::Edge& e) {
alpar@1459
   923
      _Graph::template NodeMap<int>::operator[](graph.target(e))--;
alpar@1453
   924
    }
alpar@1453
   925
alpar@1506
   926
    ///\e
alpar@1506
   927
    
alpar@1506
   928
    ///\bug Unimplemented
alpar@1506
   929
    ///
alpar@1459
   930
    virtual void build() {}
alpar@1506
   931
    ///\e
alpar@1506
   932
    
alpar@1506
   933
    ///\bug Unimplemented
alpar@1506
   934
    ///
alpar@1459
   935
    virtual void clear() {}
alpar@1459
   936
alpar@1459
   937
  };
alpar@1459
   938
alpar@1459
   939
alpar@1459
   940
  /// Map of the node out-degrees.
alpar@1459
   941
alpar@1459
   942
  ///This map returns the out-degree of a node. One it is constructed,
alpar@1459
   943
  ///the degrees are stored in a standard NodeMap, so each query is done
alpar@1459
   944
  ///in constant time. On the other hand, the values updates automatically
alpar@1459
   945
  ///whenever the graph changes.
alpar@1459
   946
  ///
alpar@1459
   947
  ///\sa OutDegMap
alpar@1459
   948
  template <typename _Graph>
alpar@1459
   949
  class OutDegMap  :
alpar@1459
   950
    protected _Graph::template NodeMap<int>,
alpar@1459
   951
    protected AlterationNotifier<typename _Graph::Edge>::ObserverBase
alpar@1459
   952
  {
alpar@1459
   953
    const _Graph& graph;
alpar@1459
   954
  public:
alpar@1459
   955
    typedef int Value;
alpar@1459
   956
    typedef typename _Graph::Node Key;
alpar@1459
   957
alpar@1459
   958
    /// \brief Constructor.
alpar@1459
   959
    ///
alpar@1459
   960
    /// Constructor for creating out-degree map.
alpar@1459
   961
    OutDegMap(const _Graph& _graph) :
ladanyi@1467
   962
      _Graph::template NodeMap<int>(_graph,0),
alpar@1459
   963
      graph(_graph)
alpar@1459
   964
    {
alpar@1459
   965
      AlterationNotifier<typename _Graph::Edge>
alpar@1459
   966
	::ObserverBase::attach(graph.getNotifier(typename _Graph::Edge()));
alpar@1459
   967
alpar@1459
   968
      for(typename _Graph::NodeIt n(graph);n!=INVALID;++n)
alpar@1459
   969
	for(typename _Graph::InEdgeIt e(graph,n);e!=INVALID;++e)
alpar@1459
   970
	  _Graph::template NodeMap<int>::operator[](graph.source(e))++;
alpar@1459
   971
    }
alpar@1459
   972
alpar@1459
   973
    ~OutDegMap() 
alpar@1459
   974
    {
alpar@1459
   975
      AlterationNotifier<typename _Graph::Edge>::
alpar@1459
   976
	ObserverBase::detach();
alpar@1459
   977
    }
alpar@1459
   978
    
alpar@1459
   979
    /// Gives back the in-degree of a Node.
alpar@1459
   980
    int operator[](const Key& k) const {
alpar@1459
   981
      return _Graph::template NodeMap<int>::operator[](k);
alpar@1459
   982
    }
alpar@1459
   983
alpar@1459
   984
  protected:
alpar@1459
   985
    virtual void add(const typename _Graph::Node& n) {
alpar@1459
   986
      _Graph::template NodeMap<int>::add(n);
alpar@1459
   987
       _Graph::template NodeMap<int>::operator[](n)=0;
alpar@1459
   988
    }
alpar@1459
   989
    virtual void erase(const typename _Graph::Node&n) 
alpar@1459
   990
    {
alpar@1459
   991
      _Graph::template NodeMap<int>::erase(n);
alpar@1459
   992
    }
alpar@1459
   993
    virtual void add(const typename _Graph::Edge& e) {
alpar@1459
   994
      _Graph::template NodeMap<int>::operator[](graph.source(e))++;
alpar@1459
   995
    }
alpar@1459
   996
    virtual void erase(const typename _Graph::Edge& e) {
alpar@1459
   997
      _Graph::template NodeMap<int>::operator[](graph.source(e))--;
alpar@1459
   998
    }
alpar@1459
   999
alpar@1506
  1000
    ///\e
alpar@1506
  1001
    
alpar@1506
  1002
    ///\bug Unimplemented
alpar@1506
  1003
    ///
alpar@1459
  1004
    virtual void build() {}
alpar@1506
  1005
    ///\e
alpar@1506
  1006
    
alpar@1506
  1007
    ///\bug Unimplemented
alpar@1506
  1008
    ///
alpar@1459
  1009
    virtual void clear() {}
alpar@1453
  1010
alpar@1453
  1011
  };
alpar@1453
  1012
alpar@1453
  1013
alpar@1453
  1014
alpar@1453
  1015
alpar@1402
  1016
  /// @}
alpar@1402
  1017
alpar@947
  1018
} //END OF NAMESPACE LEMON
klao@946
  1019
klao@946
  1020
#endif