src/lemon/list_graph.h
author marci
Sat, 20 Nov 2004 14:23:27 +0000
changeset 1014 aae850a2394d
parent 1011 5bd6c7671c9e
child 1034 be6ee857b72d
permissions -rw-r--r--
Modifications for hugo 0.2
alpar@948
     1
/* -*- C++ -*-
alpar@948
     2
 * src/lemon/list_graph.h - Part of LEMON, a generic C++ optimization library
alpar@948
     3
 *
alpar@948
     4
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@948
     5
 * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@948
     6
 *
alpar@948
     7
 * Permission to use, modify and distribute this software is granted
alpar@948
     8
 * provided that this copyright notice appears in all copies. For
alpar@948
     9
 * precise terms see the accompanying LICENSE file.
alpar@948
    10
 *
alpar@948
    11
 * This software is provided "AS IS" with no warranty of any kind,
alpar@948
    12
 * express or implied, and with no claim as to its suitability for any
alpar@948
    13
 * purpose.
alpar@948
    14
 *
alpar@948
    15
 */
alpar@395
    16
alpar@921
    17
#ifndef LEMON_LIST_GRAPH_H
alpar@921
    18
#define LEMON_LIST_GRAPH_H
alpar@395
    19
alpar@948
    20
///\ingroup graphs
alpar@948
    21
///\file
alpar@948
    22
///\brief ListGraph, SymListGraph, NodeSet and EdgeSet classes.
alpar@948
    23
klao@946
    24
#include <lemon/erasable_graph_extender.h>
klao@946
    25
#include <lemon/clearable_graph_extender.h>
klao@946
    26
#include <lemon/extendable_graph_extender.h>
alpar@395
    27
klao@946
    28
#include <lemon/iterable_graph_extender.h>
alpar@395
    29
klao@946
    30
#include <lemon/alteration_observer_registry.h>
deba@782
    31
klao@946
    32
#include <lemon/default_map.h>
deba@782
    33
alpar@1011
    34
#include <list>
deba@782
    35
alpar@921
    36
namespace lemon {
alpar@395
    37
klao@946
    38
  class ListGraphBase {
alpar@406
    39
alpar@949
    40
  protected:
klao@946
    41
    struct NodeT {
alpar@397
    42
      int first_in,first_out;
alpar@397
    43
      int prev, next;
alpar@395
    44
    };
klao@946
    45
 
klao@946
    46
    struct EdgeT {
alpar@986
    47
      int target, source;
alpar@397
    48
      int prev_in, prev_out;
alpar@397
    49
      int next_in, next_out;
alpar@395
    50
    };
alpar@395
    51
alpar@395
    52
    std::vector<NodeT> nodes;
klao@946
    53
alpar@397
    54
    int first_node;
klao@946
    55
alpar@397
    56
    int first_free_node;
klao@946
    57
alpar@395
    58
    std::vector<EdgeT> edges;
klao@946
    59
alpar@397
    60
    int first_free_edge;
alpar@395
    61
    
deba@782
    62
  public:
alpar@395
    63
    
klao@946
    64
    typedef ListGraphBase Graph;
alpar@397
    65
    
klao@946
    66
    class Node {
marci@975
    67
      friend class ListGraphBase;
klao@946
    68
    protected:
alpar@395
    69
klao@946
    70
      int id;
klao@946
    71
      Node(int pid) { id = pid;}
alpar@395
    72
klao@946
    73
    public:
klao@946
    74
      Node() {}
klao@946
    75
      Node (Invalid) { id = -1; }
klao@946
    76
      bool operator==(const Node& node) const {return id == node.id;}
klao@946
    77
      bool operator!=(const Node& node) const {return id != node.id;}
klao@946
    78
      bool operator<(const Node& node) const {return id < node.id;}
klao@946
    79
    };
deba@782
    80
klao@946
    81
    class Edge {
marci@975
    82
      friend class ListGraphBase;
klao@946
    83
    protected:
deba@782
    84
klao@946
    85
      int id;
klao@946
    86
      Edge(int pid) { id = pid;}
alpar@395
    87
klao@946
    88
    public:
klao@946
    89
      Edge() {}
klao@946
    90
      Edge (Invalid) { id = -1; }
klao@946
    91
      bool operator==(const Edge& edge) const {return id == edge.id;}
klao@946
    92
      bool operator!=(const Edge& edge) const {return id != edge.id;}
klao@946
    93
      bool operator<(const Edge& edge) const {return id < edge.id;}
klao@946
    94
    };
klao@946
    95
klao@946
    96
klao@946
    97
klao@946
    98
    ListGraphBase()
deba@782
    99
      : nodes(), first_node(-1),
deba@782
   100
	first_free_node(-1), edges(), first_free_edge(-1) {}
deba@782
   101
alpar@395
   102
    
alpar@813
   103
    /// Maximum node ID.
alpar@813
   104
    
alpar@813
   105
    /// Maximum node ID.
alpar@813
   106
    ///\sa id(Node)
deba@980
   107
    int maxId(Node = INVALID) const { return nodes.size()-1; } 
klao@946
   108
alpar@813
   109
    /// Maximum edge ID.
alpar@813
   110
    
alpar@813
   111
    /// Maximum edge ID.
alpar@813
   112
    ///\sa id(Edge)
deba@980
   113
    int maxId(Edge = INVALID) const { return edges.size()-1; }
alpar@395
   114
alpar@986
   115
    Node source(Edge e) const { return edges[e.id].source; }
alpar@986
   116
    Node target(Edge e) const { return edges[e.id].target; }
alpar@395
   117
alpar@395
   118
klao@946
   119
    void first(Node& node) const { 
klao@946
   120
      node.id = first_node;
klao@946
   121
    }
klao@946
   122
klao@946
   123
    void next(Node& node) const {
klao@946
   124
      node.id = nodes[node.id].next;
klao@946
   125
    }
klao@946
   126
klao@946
   127
klao@946
   128
    void first(Edge& e) const { 
klao@946
   129
      int n;
klao@946
   130
      for(n = first_node; 
klao@946
   131
	  n!=-1 && nodes[n].first_in == -1; 
klao@946
   132
	  n = nodes[n].next);
klao@946
   133
      e.id = (n == -1) ? -1 : nodes[n].first_in;
klao@946
   134
    }
klao@946
   135
klao@946
   136
    void next(Edge& edge) const {
klao@946
   137
      if (edges[edge.id].next_in != -1) {
klao@946
   138
	edge.id = edges[edge.id].next_in;
klao@946
   139
      } else {
klao@946
   140
	int n;
alpar@986
   141
	for(n = nodes[edges[edge.id].target].next;
klao@946
   142
	  n!=-1 && nodes[n].first_in == -1; 
klao@946
   143
	  n = nodes[n].next);
klao@946
   144
	edge.id = (n == -1) ? -1 : nodes[n].first_in;
klao@946
   145
      }      
klao@946
   146
    }
klao@946
   147
klao@946
   148
    void firstOut(Edge &e, const Node& v) const {
klao@946
   149
      e.id = nodes[v.id].first_out;
klao@946
   150
    }
klao@946
   151
    void nextOut(Edge &e) const {
klao@946
   152
      e.id=edges[e.id].next_out;
klao@946
   153
    }
klao@946
   154
klao@946
   155
    void firstIn(Edge &e, const Node& v) const {
klao@946
   156
      e.id = nodes[v.id].first_in;
klao@946
   157
    }
klao@946
   158
    void nextIn(Edge &e) const {
klao@946
   159
      e.id=edges[e.id].next_in;
klao@946
   160
    }
klao@946
   161
alpar@813
   162
    
klao@946
   163
    static int id(Node v) { return v.id; }
klao@946
   164
    static int id(Edge e) { return e.id; }
alpar@395
   165
alpar@397
   166
    /// Adds a new node to the graph.
alpar@397
   167
alpar@813
   168
    /// \warning It adds the new node to the front of the list.
alpar@397
   169
    /// (i.e. the lastly added node becomes the first.)
klao@946
   170
    Node addNode() {     
alpar@397
   171
      int n;
alpar@397
   172
      
klao@946
   173
      if(first_free_node==-1) {
klao@946
   174
	n = nodes.size();
klao@946
   175
	nodes.push_back(NodeT());
klao@946
   176
      } else {
alpar@397
   177
	n = first_free_node;
alpar@397
   178
	first_free_node = nodes[n].next;
alpar@397
   179
      }
alpar@397
   180
      
alpar@397
   181
      nodes[n].next = first_node;
alpar@397
   182
      if(first_node != -1) nodes[first_node].prev = n;
alpar@397
   183
      first_node = n;
alpar@397
   184
      nodes[n].prev = -1;
alpar@397
   185
      
alpar@397
   186
      nodes[n].first_in = nodes[n].first_out = -1;
alpar@397
   187
      
klao@946
   188
      return Node(n);
alpar@395
   189
    }
alpar@395
   190
    
alpar@395
   191
    Edge addEdge(Node u, Node v) {
klao@946
   192
      int n;      
klao@946
   193
klao@946
   194
      if (first_free_edge == -1) {
klao@946
   195
	n = edges.size();
klao@946
   196
	edges.push_back(EdgeT());
klao@946
   197
      } else {
alpar@397
   198
	n = first_free_edge;
alpar@397
   199
	first_free_edge = edges[n].next_in;
alpar@397
   200
      }
alpar@397
   201
      
alpar@986
   202
      edges[n].source = u.id; 
alpar@986
   203
      edges[n].target = v.id;
alpar@395
   204
klao@946
   205
      edges[n].next_out = nodes[u.id].first_out;
klao@946
   206
      if(nodes[u.id].first_out != -1) {
klao@946
   207
	edges[nodes[u.id].first_out].prev_out = n;
klao@946
   208
      }
klao@946
   209
      
klao@946
   210
      edges[n].next_in = nodes[v.id].first_in;
klao@946
   211
      if(nodes[v.id].first_in != -1) {
klao@946
   212
	edges[nodes[v.id].first_in].prev_in = n;
klao@946
   213
      }
klao@946
   214
      
alpar@397
   215
      edges[n].prev_in = edges[n].prev_out = -1;
alpar@397
   216
	
klao@946
   217
      nodes[u.id].first_out = nodes[v.id].first_in = n;
alpar@397
   218
klao@946
   219
      return Edge(n);
alpar@395
   220
    }
alpar@774
   221
    
klao@946
   222
    void erase(const Node& node) {
klao@946
   223
      int n = node.id;
klao@946
   224
      
klao@946
   225
      if(nodes[n].next != -1) {
klao@946
   226
	nodes[nodes[n].next].prev = nodes[n].prev;
klao@946
   227
      }
klao@946
   228
      
klao@946
   229
      if(nodes[n].prev != -1) {
klao@946
   230
	nodes[nodes[n].prev].next = nodes[n].next;
klao@946
   231
      } else {
klao@946
   232
	first_node = nodes[n].next;
klao@946
   233
      }
klao@946
   234
      
klao@946
   235
      nodes[n].next = first_free_node;
klao@946
   236
      first_free_node = n;
alpar@395
   237
alpar@774
   238
    }
alpar@774
   239
    
klao@946
   240
    void erase(const Edge& edge) {
klao@946
   241
      int n = edge.id;
alpar@397
   242
      
klao@946
   243
      if(edges[n].next_in!=-1) {
alpar@397
   244
	edges[edges[n].next_in].prev_in = edges[n].prev_in;
klao@946
   245
      }
klao@946
   246
klao@946
   247
      if(edges[n].prev_in!=-1) {
alpar@397
   248
	edges[edges[n].prev_in].next_in = edges[n].next_in;
klao@946
   249
      } else {
alpar@986
   250
	nodes[edges[n].target].first_in = edges[n].next_in;
klao@946
   251
      }
klao@946
   252
alpar@397
   253
      
klao@946
   254
      if(edges[n].next_out!=-1) {
alpar@397
   255
	edges[edges[n].next_out].prev_out = edges[n].prev_out;
klao@946
   256
      } 
klao@946
   257
klao@946
   258
      if(edges[n].prev_out!=-1) {
alpar@397
   259
	edges[edges[n].prev_out].next_out = edges[n].next_out;
klao@946
   260
      } else {
alpar@986
   261
	nodes[edges[n].source].first_out = edges[n].next_out;
klao@946
   262
      }
alpar@397
   263
      
alpar@397
   264
      edges[n].next_in = first_free_edge;
alpar@695
   265
      first_free_edge = n;      
alpar@397
   266
alpar@397
   267
    }
alpar@397
   268
alpar@397
   269
    void clear() {
deba@782
   270
      edges.clear();
deba@782
   271
      nodes.clear();
klao@946
   272
      first_node = first_free_node = first_free_edge = -1;
deba@937
   273
    }
deba@937
   274
alpar@949
   275
  protected:
alpar@986
   276
    void _moveTarget(Edge e, Node n) 
alpar@949
   277
    {
alpar@949
   278
      if(edges[e.id].next_in != -1)
alpar@949
   279
	edges[edges[e.id].next_in].prev_in = edges[e.id].prev_in;
alpar@949
   280
      if(edges[e.id].prev_in != -1)
alpar@949
   281
	edges[edges[e.id].prev_in].next_in = edges[e.id].next_in;
alpar@986
   282
      else nodes[edges[e.id].target].first_in = edges[e.id].next_in;
alpar@986
   283
      edges[e.id].target = n.id;
alpar@949
   284
      edges[e.id].prev_in = -1;
alpar@949
   285
      edges[e.id].next_in = nodes[n.id].first_in;
alpar@949
   286
      nodes[n.id].first_in = e.id;
alpar@949
   287
    }
alpar@986
   288
    void _moveSource(Edge e, Node n) 
alpar@949
   289
    {
alpar@949
   290
      if(edges[e.id].next_out != -1)
alpar@949
   291
	edges[edges[e.id].next_out].prev_out = edges[e.id].prev_out;
alpar@949
   292
      if(edges[e.id].prev_out != -1)
alpar@949
   293
	edges[edges[e.id].prev_out].next_out = edges[e.id].next_out;
alpar@986
   294
      else nodes[edges[e.id].source].first_out = edges[e.id].next_out;
alpar@986
   295
      edges[e.id].source = n.id;
alpar@949
   296
      edges[e.id].prev_out = -1;
alpar@949
   297
      edges[e.id].next_out = nodes[n.id].first_out;
alpar@949
   298
      nodes[n.id].first_out = e.id;
alpar@949
   299
    }
alpar@949
   300
alpar@919
   301
  };
deba@909
   302
klao@946
   303
  typedef AlterableGraphExtender<ListGraphBase> AlterableListGraphBase;
klao@946
   304
  typedef IterableGraphExtender<AlterableListGraphBase> IterableListGraphBase;
deba@980
   305
  typedef DefaultMappableGraphExtender<IterableListGraphBase> MappableListGraphBase;
klao@946
   306
  typedef ExtendableGraphExtender<MappableListGraphBase> ExtendableListGraphBase;
klao@946
   307
  typedef ClearableGraphExtender<ExtendableListGraphBase> ClearableListGraphBase;
klao@946
   308
  typedef ErasableGraphExtender<ClearableListGraphBase> ErasableListGraphBase;
alpar@400
   309
alpar@948
   310
/// \addtogroup graphs
alpar@948
   311
/// @{
alpar@400
   312
alpar@948
   313
  ///A list graph class.
alpar@400
   314
alpar@948
   315
  ///This is a simple and fast erasable graph implementation.
alpar@948
   316
  ///
alpar@1010
   317
  ///It addition that it conforms to the
alpar@1010
   318
  ///\ref concept::ErasableGraph "ErasableGraph" concept,
alpar@1010
   319
  ///it also provides several additional useful extra functionalities.
klao@959
   320
  ///\sa concept::ErasableGraph.
deba@782
   321
alpar@948
   322
  class ListGraph : public ErasableListGraphBase 
alpar@948
   323
  {
alpar@948
   324
  public:
alpar@986
   325
    /// Moves the target of \c e to \c n
alpar@948
   326
alpar@986
   327
    /// Moves the target of \c e to \c n
alpar@948
   328
    ///
alpar@1010
   329
    ///\note The <tt>Edge</tt>'s and <tt>OutEdge</tt>'s
alpar@1010
   330
    ///referencing the moved edge remain
alpar@1010
   331
    ///valid. However <tt>InEdge</tt>'s are invalidated.
alpar@986
   332
    void moveTarget(Edge e, Node n) { _moveTarget(e,n); }
alpar@986
   333
    /// Moves the source of \c e to \c n
alpar@948
   334
alpar@986
   335
    /// Moves the source of \c e to \c n
alpar@948
   336
    ///
alpar@1010
   337
    ///\note The <tt>Edge</tt>'s and <tt>InEdge</tt>'s
alpar@1010
   338
    ///referencing the moved edge remain
alpar@1010
   339
    ///valid. However <tt>OutEdge</tt>'s are invalidated.
alpar@986
   340
    void moveSource(Edge e, Node n) { _moveSource(e,n); }
alpar@949
   341
alpar@1010
   342
    /// Invert the direction of an edge.
alpar@1010
   343
alpar@1010
   344
    ///\note The <tt>Edge</tt>'s
alpar@1010
   345
    ///referencing the moved edge remain
alpar@1010
   346
    ///valid. However <tt>OutEdge</tt>'s  and <tt>InEdge</tt>'s are invalidated.
alpar@1010
   347
    void reverseEdge(Edge e) {
alpar@1010
   348
      Node t=target(e);
alpar@1010
   349
      _moveTarget(e,source(e));
alpar@1010
   350
      _moveSource(e,t);
alpar@1010
   351
    }
alpar@1010
   352
alpar@1010
   353
    ///Using this it possible to avoid the superfluous memory allocation.
alpar@1010
   354
alpar@949
   355
    ///Using this it possible to avoid the superfluous memory allocation.
alpar@949
   356
    ///\todo more docs...
alpar@949
   357
    void reserveEdge(int n) { edges.reserve(n); };
alpar@1010
   358
alpar@1010
   359
    ///Contract two nodes.
alpar@1010
   360
alpar@1010
   361
    ///This function contracts two nodes.
alpar@1010
   362
    ///
alpar@1010
   363
    ///Node \p b will be removed but instead of deleting
alpar@1010
   364
    ///its neighboring edges, they will be joined to \p a.
alpar@1010
   365
    ///The last parameter \p r controls whether to remove loops. \c true
alpar@1010
   366
    ///means that loops will be removed.
alpar@1010
   367
    ///
alpar@1010
   368
    ///\note The <tt>Edge</tt>s
alpar@1010
   369
    ///referencing the moved edge remain
alpar@1010
   370
    ///valid. However <tt>InEdge</tt>'s and <tt>OutEdge</tt>'s
alpar@1010
   371
    ///may be invalidated.
alpar@1010
   372
    void contract(Node a,Node b,bool r=true) 
alpar@1010
   373
    {
alpar@1010
   374
      for(OutEdgeIt e(*this,b);e!=INVALID;) {
alpar@1010
   375
	OutEdgeIt f=e;
alpar@1010
   376
	++f;
alpar@1010
   377
	if(r && target(e)==a) erase(e);
alpar@1010
   378
	else moveSource(e,b);
alpar@1010
   379
	e=f;
alpar@1010
   380
      }
alpar@1010
   381
      for(InEdgeIt e(*this,b);e!=INVALID;) {
alpar@1010
   382
	InEdgeIt f=e;
alpar@1010
   383
	++f;
alpar@1010
   384
	if(r && source(e)==a) erase(e);
alpar@1010
   385
	else moveTarget(e,b);
alpar@1010
   386
	e=f;
alpar@1010
   387
      }
alpar@1010
   388
      erase(b);
alpar@1010
   389
    }
alpar@1011
   390
alpar@1011
   391
alpar@1011
   392
    ///Class to make a snapshot of the graph and to restrore to it later.
alpar@1011
   393
alpar@1011
   394
    ///Class to make a snapshot of the graph and to restrore to it later.
alpar@1011
   395
    ///
alpar@1011
   396
    ///The newly added nodes and edges can be removed using the
alpar@1011
   397
    ///restore() function.
alpar@1011
   398
    ///
alpar@1011
   399
    ///\warning Edge and node deletions cannot be restored.
alpar@1011
   400
    ///\warning SnapShots cannot be nested.
alpar@1011
   401
    ///\ingroup graphs
alpar@1012
   402
    class SnapShot : protected AlterationObserverRegistry<Node>::ObserverBase,
alpar@1012
   403
		     protected AlterationObserverRegistry<Edge>::ObserverBase
alpar@1011
   404
    {
alpar@1011
   405
      protected:
alpar@1011
   406
      
alpar@1011
   407
      ListGraph *g;
alpar@1011
   408
      std::list<Node> added_nodes;
alpar@1011
   409
      std::list<Edge> added_edges;
alpar@1011
   410
      
alpar@1011
   411
      bool active;
alpar@1011
   412
      virtual void add(const Node& n) {
alpar@1011
   413
	added_nodes.push_back(n);
alpar@1011
   414
      };
alpar@1011
   415
      ///\bug Exception...
alpar@1011
   416
      ///
alpar@1011
   417
      virtual void erase(const Node&) 
alpar@1011
   418
      {
alpar@1011
   419
	exit(1);
alpar@1011
   420
      }
alpar@1011
   421
      virtual void add(const Edge& n) {
alpar@1011
   422
	added_edges.push_back(n);
alpar@1011
   423
      };
alpar@1011
   424
      ///\bug Exception...
alpar@1011
   425
      ///
alpar@1011
   426
      virtual void erase(const Edge&) 
alpar@1011
   427
      {
alpar@1011
   428
	exit(1);
alpar@1011
   429
      }
alpar@1011
   430
alpar@1011
   431
      void regist(ListGraph &_g) {
alpar@1011
   432
	g=&_g;
alpar@1011
   433
	AlterationObserverRegistry<Node>::ObserverBase::
alpar@1011
   434
	  attach(g->node_observers);
alpar@1011
   435
	AlterationObserverRegistry<Edge>::ObserverBase::
alpar@1011
   436
	  attach(g->edge_observers);
alpar@1011
   437
      }
alpar@1011
   438
            
alpar@1011
   439
      void deregist() {
alpar@1011
   440
	AlterationObserverRegistry<Node>::ObserverBase::
alpar@1011
   441
	  detach();
alpar@1011
   442
	AlterationObserverRegistry<Edge>::ObserverBase::
alpar@1011
   443
	  detach();
alpar@1011
   444
	g=0;
alpar@1011
   445
      }
alpar@1011
   446
            
alpar@1011
   447
    public:
alpar@1011
   448
      ///Default constructur.
alpar@1011
   449
      
alpar@1011
   450
      ///Default constructur.
alpar@1011
   451
      ///To actually make a snapshot you must call save().
alpar@1011
   452
      ///
alpar@1011
   453
      SnapShot() : g(0) {}
alpar@1011
   454
      ///Constructor that immediately makes a snapshot.
alpar@1011
   455
      
alpar@1011
   456
      ///This constructor immediately makes a snapshot of the graph.
alpar@1011
   457
      ///\param _g The graph we make a snapshot of.
alpar@1011
   458
      SnapShot(ListGraph &_g) {
alpar@1011
   459
	regist(_g);
alpar@1011
   460
      }
alpar@1011
   461
      ///\bug Is it necessary?
alpar@1011
   462
      ///
alpar@1011
   463
      ~SnapShot() 
alpar@1011
   464
      {
alpar@1011
   465
	if(g) deregist();
alpar@1011
   466
      }
alpar@1011
   467
      
alpar@1011
   468
      ///Make a snapshot.
alpar@1011
   469
alpar@1011
   470
      ///Make a snapshot of the graph.
alpar@1011
   471
      ///
alpar@1011
   472
      ///This function can be called more than once. In case of a repeated
alpar@1011
   473
      ///call, the previous snapshot gets lost.
alpar@1011
   474
      ///\param _g The graph we make the snapshot of.
alpar@1011
   475
      void save(ListGraph &_g) 
alpar@1011
   476
      {
alpar@1011
   477
	if(g!=&_g) {
alpar@1011
   478
	  if(g) deregist();
alpar@1011
   479
	  regist(_g);
alpar@1011
   480
	}
alpar@1011
   481
	added_nodes.clear();
alpar@1011
   482
	added_edges.clear();
alpar@1011
   483
      }
alpar@1011
   484
      
alpar@1011
   485
    ///Undo the changes until the last snapshot.
alpar@1011
   486
alpar@1011
   487
    ///Undo the changes until last snapshot created by save().
alpar@1011
   488
    ///
alpar@1011
   489
    ///\todo This function might be called undo().
alpar@1011
   490
      void restore() {
alpar@1011
   491
	deregist();
alpar@1011
   492
	while(!added_edges.empty()) {
alpar@1011
   493
	  g->erase(added_edges.front());
alpar@1011
   494
	  added_edges.pop_front();
alpar@1011
   495
	}
alpar@1011
   496
 	while(!added_nodes.empty()) {
alpar@1011
   497
	  g->erase(added_nodes.front());
alpar@1011
   498
	  added_nodes.pop_front();
alpar@1011
   499
	}
alpar@1011
   500
      }
alpar@1011
   501
    };
alpar@1011
   502
    
alpar@949
   503
  };
alpar@949
   504
  
alpar@948
   505
  /// @}  
alpar@948
   506
} //namespace lemon
klao@946
   507
  
alpar@400
   508
klao@946
   509
#endif