src/hugo/graph_wrapper.h
author athos
Tue, 11 May 2004 15:42:11 +0000
changeset 607 327f7cf13843
parent 593 b83b36ee7f10
child 612 0856a9a87eb9
permissions -rw-r--r--
Finished MinLengthPaths: a specialization of MinCostFlows.
marci@556
     1
// -*- c++ -*-
marci@556
     2
#ifndef HUGO_GRAPH_WRAPPER_H
marci@556
     3
#define HUGO_GRAPH_WRAPPER_H
marci@556
     4
marci@556
     5
///\ingroup gwrappers
marci@556
     6
///\file
marci@556
     7
///\brief Several graph wrappers.
marci@556
     8
///
marci@556
     9
///This file contains several useful graph wrapper functions.
marci@556
    10
///
marci@556
    11
///\author Marton Makai
marci@556
    12
marci@556
    13
#include <hugo/invalid.h>
marci@556
    14
//#include <iter_map.h>
marci@556
    15
marci@556
    16
namespace hugo {
marci@556
    17
marci@556
    18
  // Graph wrappers
marci@556
    19
marci@556
    20
  /// \addtogroup gwrappers
marci@556
    21
  /// A main parts of HUGOlib are the different graph structures, 
marci@556
    22
  /// generic graph algorithms, graph concepts which couple these, and 
marci@556
    23
  /// graph wrappers. While the previous ones are more or less clear, the 
marci@556
    24
  /// latter notion needs further explanation.
marci@556
    25
  /// Graph wrappers are graph classes which serve for considering graph 
marci@556
    26
  /// structures in different ways. A short example makes the notion much 
marci@556
    27
  /// clearer. 
marci@556
    28
  /// Suppose that we have an instance \c g of a directed graph
marci@556
    29
  /// type say \c ListGraph and an algorithm 
marci@556
    30
  /// \code template<typename Graph> int algorithm(const Graph&); \endcode 
marci@556
    31
  /// is needed to run on the reversely oriented graph. 
marci@556
    32
  /// It may be expensive (in time or in memory usage) to copy 
marci@556
    33
  /// \c g with the reverse orientation. 
marci@556
    34
  /// Thus, a wrapper class
marci@556
    35
  /// \code template<typename Graph> class RevGraphWrapper; \endcode is used. 
marci@556
    36
  /// The code looks as follows
marci@556
    37
  /// \code
marci@556
    38
  /// ListGraph g;
marci@556
    39
  /// RevGraphWrapper<ListGraph> rgw(g);
marci@556
    40
  /// int result=algorithm(rgw);
marci@556
    41
  /// \endcode
marci@556
    42
  /// After running the algorithm, the original graph \c g 
marci@556
    43
  /// remains untouched. Thus the graph wrapper used above is to consider the 
marci@556
    44
  /// original graph with reverse orientation. 
marci@556
    45
  /// This techniques gives rise to an elegant code, and 
marci@556
    46
  /// based on stable graph wrappers, complex algorithms can be 
marci@556
    47
  /// implemented easily. 
marci@556
    48
  /// In flow, circulation and bipartite matching problems, the residual 
marci@556
    49
  /// graph is of particular importance. Combining a wrapper implementing 
marci@556
    50
  /// this, shortest path algorithms and minimum mean cycle algorithms, 
marci@556
    51
  /// a range of weighted and cardinality optimization algorithms can be 
marci@556
    52
  /// obtained. For lack of space, for other examples, 
marci@556
    53
  /// the interested user is referred to the detailed documentation of graph 
marci@556
    54
  /// wrappers. 
marci@556
    55
  /// The behavior of graph wrappers can be very different. Some of them keep 
marci@556
    56
  /// capabilities of the original graph while in other cases this would be 
marci@556
    57
  /// meaningless. This means that the concepts that they are a model of depend 
marci@556
    58
  /// on the graph wrapper, and the wrapped graph(s). 
marci@556
    59
  /// If an edge of \c rgw is deleted, this is carried out by 
marci@556
    60
  /// deleting the corresponding edge of \c g. But for a residual 
marci@556
    61
  /// graph, this operation has no sense. 
marci@556
    62
  /// Let we stand one more example here to simplify your work. 
marci@556
    63
  /// wrapper class
marci@556
    64
  /// \code template<typename Graph> class RevGraphWrapper; \endcode 
marci@556
    65
  /// has constructor 
marci@556
    66
  /// <tt> RevGraphWrapper(Graph& _g)</tt>. 
marci@556
    67
  /// This means that in a situation, 
marci@556
    68
  /// when a <tt> const ListGraph& </tt> reference to a graph is given, 
marci@556
    69
  /// then it have to be instantiated with <tt>Graph=const ListGraph</tt>.
marci@556
    70
  /// \code
marci@556
    71
  /// int algorithm1(const ListGraph& g) {
marci@556
    72
  ///   RevGraphWrapper<const ListGraph> rgw(g);
marci@556
    73
  ///   return algorithm2(rgw);
marci@556
    74
  /// }
marci@556
    75
  /// \endcode
marci@556
    76
marci@556
    77
  /// \addtogroup gwrappers
marci@556
    78
  /// @{
marci@556
    79
marci@556
    80
  ///Base type for the Graph Wrappers
marci@556
    81
marci@556
    82
  ///This is the base type for the Graph Wrappers.
marci@556
    83
  ///\todo Some more docs... 
marci@556
    84
  ///
marci@556
    85
  ///\author Marton Makai
marci@556
    86
 
marci@556
    87
  template<typename Graph>
marci@556
    88
  class GraphWrapper {
marci@556
    89
  protected:
marci@556
    90
    Graph* graph;
marci@556
    91
    GraphWrapper() : graph(0) { }
marci@556
    92
    void setGraph(Graph& _graph) { graph=&_graph; }
marci@556
    93
marci@556
    94
  public:
marci@556
    95
    typedef Graph BaseGraph;
marci@556
    96
    typedef Graph ParentGraph;
marci@556
    97
marci@556
    98
    GraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@556
    99
//     Graph& getGraph() const { return *graph; }
marci@556
   100
 
marci@556
   101
//    typedef typename Graph::Node Node;
marci@556
   102
    class Node : public Graph::Node {
marci@556
   103
      friend class GraphWrapper<Graph>;
marci@556
   104
    public:
marci@556
   105
      Node() { }
marci@556
   106
      Node(const typename Graph::Node& _n) : Graph::Node(_n) { }
marci@556
   107
      Node(const Invalid& i) : Graph::Node(i) { }
marci@556
   108
    };
marci@556
   109
    class NodeIt { 
marci@556
   110
      friend class GraphWrapper<Graph>;
marci@556
   111
      typename Graph::NodeIt n;
marci@556
   112
     public:
marci@556
   113
      NodeIt() { }
marci@556
   114
      NodeIt(const typename Graph::NodeIt& _n) : n(_n) { }
marci@556
   115
      NodeIt(const Invalid& i) : n(i) { }
marci@556
   116
      NodeIt(const GraphWrapper<Graph>& _G) : n(*(_G.graph)) { }
marci@556
   117
      operator Node() const { return Node(typename Graph::Node(n)); }
marci@556
   118
    };
marci@556
   119
//    typedef typename Graph::Edge Edge;
marci@556
   120
    class Edge : public Graph::Edge {
marci@556
   121
      friend class GraphWrapper<Graph>;
marci@556
   122
    public:
marci@556
   123
      Edge() { }
marci@556
   124
      Edge(const typename Graph::Edge& _e) : Graph::Edge(_e) { }
marci@556
   125
      Edge(const Invalid& i) : Graph::Edge(i) { }
marci@556
   126
    };
marci@556
   127
    class OutEdgeIt { 
marci@556
   128
      friend class GraphWrapper<Graph>;
marci@556
   129
      typename Graph::OutEdgeIt e;
marci@556
   130
    public:
marci@556
   131
      OutEdgeIt() { }
marci@556
   132
      OutEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
marci@556
   133
      OutEdgeIt(const Invalid& i) : e(i) { }
marci@556
   134
      OutEdgeIt(const GraphWrapper<Graph>& _G, const Node& _n) : 
marci@556
   135
	e(*(_G.graph), typename Graph::Node(_n)) { }
marci@556
   136
      operator Edge() const { return Edge(typename Graph::Edge(e)); }
marci@556
   137
    };
marci@556
   138
    class InEdgeIt { 
marci@556
   139
      friend class GraphWrapper<Graph>;
marci@556
   140
      typename Graph::InEdgeIt e;
marci@556
   141
    public:
marci@556
   142
      InEdgeIt() { }
marci@556
   143
      InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
marci@556
   144
      InEdgeIt(const Invalid& i) : e(i) { }
marci@556
   145
      InEdgeIt(const GraphWrapper<Graph>& _G, const Node& _n) : 
marci@556
   146
	e(*(_G.graph), typename Graph::Node(_n)) { }
marci@556
   147
      operator Edge() const { return Edge(typename Graph::Edge(e)); }
marci@556
   148
    };
marci@556
   149
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@556
   150
    class EdgeIt { 
marci@556
   151
      friend class GraphWrapper<Graph>;
marci@556
   152
      typename Graph::EdgeIt e;
marci@556
   153
    public:
marci@556
   154
      EdgeIt() { }
marci@556
   155
      EdgeIt(const typename Graph::EdgeIt& _e) : e(_e) { }
marci@556
   156
      EdgeIt(const Invalid& i) : e(i) { }
marci@556
   157
      EdgeIt(const GraphWrapper<Graph>& _G) : e(*(_G.graph)) { }
marci@556
   158
      operator Edge() const { return Edge(typename Graph::Edge(e)); }
marci@556
   159
    };
marci@556
   160
   
marci@556
   161
    NodeIt& first(NodeIt& i) const { 
marci@556
   162
      i=NodeIt(*this); return i;
marci@556
   163
    }
marci@556
   164
    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
marci@556
   165
      i=OutEdgeIt(*this, p); return i;
marci@556
   166
    }
marci@556
   167
    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
marci@556
   168
      i=InEdgeIt(*this, p); return i;
marci@556
   169
    }
marci@556
   170
    EdgeIt& first(EdgeIt& i) const { 
marci@556
   171
      i=EdgeIt(*this); return i;
marci@556
   172
    }
marci@556
   173
marci@556
   174
    NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; }
marci@556
   175
    OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i.e); return i; }
marci@556
   176
    InEdgeIt& next(InEdgeIt& i) const { graph->next(i.e); return i; }
marci@556
   177
    EdgeIt& next(EdgeIt& i) const { graph->next(i.e); return i; }    
marci@556
   178
marci@556
   179
    Node tail(const Edge& e) const { 
marci@556
   180
      return Node(graph->tail(static_cast<typename Graph::Edge>(e))); }
marci@556
   181
    Node head(const Edge& e) const { 
marci@556
   182
      return Node(graph->head(static_cast<typename Graph::Edge>(e))); }
marci@556
   183
marci@556
   184
    bool valid(const Node& n) const { 
marci@556
   185
      return graph->valid(static_cast<typename Graph::Node>(n)); }
marci@556
   186
    bool valid(const Edge& e) const { 
marci@556
   187
      return graph->valid(static_cast<typename Graph::Edge>(e)); }
marci@556
   188
marci@556
   189
    int nodeNum() const { return graph->nodeNum(); }
marci@556
   190
    int edgeNum() const { return graph->edgeNum(); }
marci@556
   191
  
marci@556
   192
    Node aNode(const OutEdgeIt& e) const { return Node(graph->aNode(e.e)); }
marci@556
   193
    Node aNode(const InEdgeIt& e) const { return Node(graph->aNode(e.e)); }
marci@556
   194
    Node bNode(const OutEdgeIt& e) const { return Node(graph->bNode(e.e)); }
marci@556
   195
    Node bNode(const InEdgeIt& e) const { return Node(graph->bNode(e.e)); }
marci@556
   196
  
marci@556
   197
    Node addNode() const { return Node(graph->addNode()); }
marci@556
   198
    Edge addEdge(const Node& tail, const Node& head) const { 
marci@556
   199
      return Edge(graph->addEdge(tail, head)); }
marci@556
   200
marci@556
   201
    void erase(const Node& i) const { graph->erase(i); }
marci@556
   202
    void erase(const Edge& i) const { graph->erase(i); }
marci@556
   203
  
marci@556
   204
    void clear() const { graph->clear(); }
marci@556
   205
    
marci@556
   206
    template<typename T> class NodeMap : public Graph::template NodeMap<T> { 
marci@556
   207
      typedef typename Graph::template NodeMap<T> Parent;
marci@556
   208
    public:
marci@556
   209
      NodeMap(const GraphWrapper<Graph>& _G) :  Parent(*(_G.graph)) { }
marci@556
   210
      NodeMap(const GraphWrapper<Graph>& _G, T a) : Parent(*(_G.graph), a) { }
marci@556
   211
    };
marci@556
   212
marci@556
   213
    template<typename T> class EdgeMap : public Graph::template EdgeMap<T> { 
marci@556
   214
      typedef typename Graph::template EdgeMap<T> Parent;
marci@556
   215
    public:
marci@556
   216
      EdgeMap(const GraphWrapper<Graph>& _G) : Parent(*(_G.graph)) { }
marci@556
   217
      EdgeMap(const GraphWrapper<Graph>& _G, T a) : Parent(*(_G.graph), a) { }
marci@556
   218
    };
marci@556
   219
  };
marci@556
   220
marci@569
   221
marci@569
   222
marci@556
   223
  /// A graph wrapper which reverses the orientation of the edges.
marci@556
   224
marci@556
   225
  /// A graph wrapper which reverses the orientation of the edges.
marci@556
   226
  ///
marci@556
   227
  ///\author Marton Makai
marci@556
   228
  template<typename Graph>
marci@556
   229
  class RevGraphWrapper : public GraphWrapper<Graph> {
marci@556
   230
  protected:
marci@556
   231
    RevGraphWrapper() : GraphWrapper<Graph>(0) { }
marci@556
   232
  public:
marci@556
   233
    RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
marci@556
   234
marci@556
   235
    typedef typename GraphWrapper<Graph>::Node Node;
marci@556
   236
    typedef typename GraphWrapper<Graph>::Edge Edge;
marci@556
   237
    //If Graph::OutEdgeIt is not defined
marci@556
   238
    //and we do not want to use RevGraphWrapper::InEdgeIt,
marci@556
   239
    //the typdef techinque does not work.
marci@556
   240
    //Unfortunately all the typedefs are instantiated in templates.
marci@556
   241
    //typedef typename GraphWrapper<Graph>::OutEdgeIt InEdgeIt;
marci@556
   242
    //typedef typename GraphWrapper<Graph>::InEdgeIt OutEdgeIt;
marci@556
   243
marci@556
   244
    class OutEdgeIt { 
marci@556
   245
      friend class GraphWrapper<Graph>;
marci@556
   246
      friend class RevGraphWrapper<Graph>;
marci@556
   247
      typename Graph::InEdgeIt e;
marci@556
   248
    public:
marci@556
   249
      OutEdgeIt() { }
marci@556
   250
      OutEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
marci@556
   251
      OutEdgeIt(const Invalid& i) : e(i) { }
marci@556
   252
      OutEdgeIt(const RevGraphWrapper<Graph>& _G, const Node& _n) : 
marci@556
   253
	e(*(_G.graph), typename Graph::Node(_n)) { }
marci@556
   254
      operator Edge() const { return Edge(typename Graph::Edge(e)); }
marci@556
   255
    };
marci@556
   256
    class InEdgeIt { 
marci@556
   257
      friend class GraphWrapper<Graph>;
marci@556
   258
      friend class RevGraphWrapper<Graph>;
marci@556
   259
      typename Graph::OutEdgeIt e;
marci@556
   260
    public:
marci@556
   261
      InEdgeIt() { }
marci@556
   262
      InEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
marci@556
   263
      InEdgeIt(const Invalid& i) : e(i) { }
marci@556
   264
      InEdgeIt(const RevGraphWrapper<Graph>& _G, const Node& _n) : 
marci@556
   265
	e(*(_G.graph), typename Graph::Node(_n)) { }
marci@556
   266
      operator Edge() const { return Edge(typename Graph::Edge(e)); }
marci@556
   267
    };
marci@556
   268
marci@556
   269
    using GraphWrapper<Graph>::first;
marci@556
   270
    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
marci@556
   271
      i=OutEdgeIt(*this, p); return i;
marci@556
   272
    }
marci@556
   273
    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
marci@556
   274
      i=InEdgeIt(*this, p); return i;
marci@556
   275
    }
marci@556
   276
marci@556
   277
    using GraphWrapper<Graph>::next;
marci@556
   278
    OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; }
marci@556
   279
    InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; }
marci@556
   280
marci@556
   281
    Node aNode(const OutEdgeIt& e) const { 
marci@556
   282
      return Node(this->graph->aNode(e.e)); }
marci@556
   283
    Node aNode(const InEdgeIt& e) const { 
marci@556
   284
      return Node(this->graph->aNode(e.e)); }
marci@556
   285
    Node bNode(const OutEdgeIt& e) const { 
marci@556
   286
      return Node(this->graph->bNode(e.e)); }
marci@556
   287
    Node bNode(const InEdgeIt& e) const { 
marci@556
   288
      return Node(this->graph->bNode(e.e)); }
marci@556
   289
marci@556
   290
    Node tail(const Edge& e) const { 
marci@556
   291
      return GraphWrapper<Graph>::head(e); }
marci@556
   292
    Node head(const Edge& e) const { 
marci@556
   293
      return GraphWrapper<Graph>::tail(e); }
marci@556
   294
marci@556
   295
  };
marci@556
   296
marci@569
   297
marci@569
   298
marci@556
   299
  /// Wrapper for hiding nodes and edges from a graph.
marci@556
   300
  
marci@556
   301
  /// This wrapper shows a graph with filtered node-set and 
marci@556
   302
  /// edge-set. The quick brown fox iterator jumps over 
marci@556
   303
  /// the lazy dog nodes or edges if the values for them are false 
marci@556
   304
  /// in the bool maps. 
marci@556
   305
  ///
marci@556
   306
  ///\author Marton Makai
marci@556
   307
  template<typename Graph, typename NodeFilterMap, 
marci@556
   308
	   typename EdgeFilterMap>
marci@556
   309
  class SubGraphWrapper : public GraphWrapper<Graph> {
marci@556
   310
  protected:
marci@556
   311
    NodeFilterMap* node_filter_map;
marci@556
   312
    EdgeFilterMap* edge_filter_map;
marci@556
   313
marci@556
   314
    SubGraphWrapper() : GraphWrapper<Graph>(0), 
marci@556
   315
			node_filter_map(0), edge_filter_map(0) { }
marci@556
   316
    void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
marci@556
   317
      node_filter_map=&_node_filter_map;
marci@556
   318
    }
marci@556
   319
    void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
marci@556
   320
      edge_filter_map=&_edge_filter_map;
marci@556
   321
    }
marci@556
   322
    
marci@556
   323
  public:
marci@556
   324
marci@556
   325
    SubGraphWrapper(Graph& _graph, NodeFilterMap& _node_filter_map, 
marci@556
   326
		    EdgeFilterMap& _edge_filter_map) : 
marci@556
   327
      GraphWrapper<Graph>(_graph), node_filter_map(&_node_filter_map), 
marci@556
   328
      edge_filter_map(&_edge_filter_map) { }  
marci@556
   329
marci@556
   330
    typedef typename GraphWrapper<Graph>::Node Node;
marci@556
   331
    class NodeIt { 
marci@556
   332
      friend class GraphWrapper<Graph>;
marci@556
   333
      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
marci@556
   334
      typename Graph::NodeIt n;
marci@556
   335
     public:
marci@556
   336
      NodeIt() { }
marci@556
   337
      NodeIt(const typename Graph::NodeIt& _n) : n(_n) { }
marci@556
   338
      NodeIt(const Invalid& i) : n(i) { }
marci@556
   339
      NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G) : 
marci@556
   340
	n(*(_G.graph)) { 
marci@556
   341
	while (_G.graph->valid(n) && !(*(_G.node_filter_map))[n]) 
marci@556
   342
	  _G.graph->next(n);
marci@556
   343
      }
marci@556
   344
      operator Node() const { return Node(typename Graph::Node(n)); }
marci@556
   345
    };
marci@556
   346
    typedef typename GraphWrapper<Graph>::Edge Edge;
marci@556
   347
    class OutEdgeIt { 
marci@556
   348
      friend class GraphWrapper<Graph>;
marci@556
   349
      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
marci@556
   350
      typename Graph::OutEdgeIt e;
marci@556
   351
    public:
marci@556
   352
      OutEdgeIt() { }
marci@556
   353
      OutEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
marci@556
   354
      OutEdgeIt(const Invalid& i) : e(i) { }
marci@556
   355
      OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G, 
marci@556
   356
		const Node& _n) : 
marci@556
   357
	e(*(_G.graph), typename Graph::Node(_n)) { 
marci@556
   358
      	while (_G.graph->valid(e) && !(*(_G.edge_filter_map))[e]) 
marci@556
   359
	  _G.graph->next(e);
marci@556
   360
      }
marci@556
   361
      operator Edge() const { return Edge(typename Graph::Edge(e)); }
marci@556
   362
    };
marci@556
   363
    class InEdgeIt { 
marci@556
   364
      friend class GraphWrapper<Graph>;
marci@556
   365
      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
marci@556
   366
      typename Graph::InEdgeIt e;
marci@556
   367
    public:
marci@556
   368
      InEdgeIt() { }
marci@556
   369
      InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
marci@556
   370
      InEdgeIt(const Invalid& i) : e(i) { }
marci@556
   371
      InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G, 
marci@556
   372
	       const Node& _n) : 
marci@556
   373
	e(*(_G.graph), typename Graph::Node(_n)) { 
marci@556
   374
      	while (_G.graph->valid(e) && !(*(_G.edge_filter_map))[e]) 
marci@556
   375
	  _G.graph->next(e);
marci@556
   376
      }
marci@556
   377
      operator Edge() const { return Edge(typename Graph::Edge(e)); }
marci@556
   378
    };
marci@556
   379
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@556
   380
    class EdgeIt { 
marci@556
   381
      friend class GraphWrapper<Graph>;
marci@556
   382
      friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
marci@556
   383
      typename Graph::EdgeIt e;
marci@556
   384
    public:
marci@556
   385
      EdgeIt() { }
marci@556
   386
      EdgeIt(const typename Graph::EdgeIt& _e) : e(_e) { }
marci@556
   387
      EdgeIt(const Invalid& i) : e(i) { }
marci@556
   388
      EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G) : 
marci@556
   389
	e(*(_G.graph)) { 
marci@556
   390
      	while (_G.graph->valid(e) && !(*(_G.edge_filter_map))[e]) 
marci@556
   391
	  _G.graph->next(e);
marci@556
   392
      }
marci@556
   393
      operator Edge() const { return Edge(typename Graph::Edge(e)); }
marci@556
   394
    };
marci@556
   395
marci@556
   396
    NodeIt& first(NodeIt& i) const { 
marci@556
   397
      i=NodeIt(*this); return i;
marci@556
   398
    }
marci@556
   399
    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
marci@556
   400
      i=OutEdgeIt(*this, p); return i;
marci@556
   401
    }
marci@556
   402
    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
marci@556
   403
      i=InEdgeIt(*this, p); return i;
marci@556
   404
    }
marci@556
   405
    EdgeIt& first(EdgeIt& i) const { 
marci@556
   406
      i=EdgeIt(*this); return i;
marci@556
   407
    }
marci@556
   408
    
marci@556
   409
    NodeIt& next(NodeIt& i) const {
marci@556
   410
      this->graph->next(i.n); 
marci@556
   411
      while (this->graph->valid(i) && !(*node_filter_map)[i.n]) { 
marci@556
   412
	this->graph->next(i.n); }
marci@556
   413
      return i;
marci@556
   414
    }
marci@556
   415
    OutEdgeIt& next(OutEdgeIt& i) const {
marci@556
   416
      this->graph->next(i.e); 
marci@556
   417
      while (this->graph->valid(i) && !(*edge_filter_map)[i.e]) { 
marci@556
   418
	this->graph->next(i.e); }
marci@556
   419
      return i;
marci@556
   420
    }
marci@556
   421
    InEdgeIt& next(InEdgeIt& i) const {
marci@556
   422
      this->graph->next(i.e); 
marci@556
   423
      while (this->graph->valid(i) && !(*edge_filter_map)[i.e]) { 
marci@556
   424
	this->graph->next(i.e); }
marci@556
   425
      return i;
marci@556
   426
    }
marci@556
   427
    EdgeIt& next(EdgeIt& i) const {
marci@556
   428
      this->graph->next(i.e); 
marci@556
   429
      while (this->graph->valid(i) && !(*edge_filter_map)[i.e]) { 
marci@556
   430
	this->graph->next(i.e); }
marci@556
   431
      return i;
marci@556
   432
    }
marci@556
   433
marci@556
   434
    Node aNode(const OutEdgeIt& e) const { 
marci@556
   435
      return Node(this->graph->aNode(e.e)); }
marci@556
   436
    Node aNode(const InEdgeIt& e) const { 
marci@556
   437
      return Node(this->graph->aNode(e.e)); }
marci@556
   438
    Node bNode(const OutEdgeIt& e) const { 
marci@556
   439
      return Node(this->graph->bNode(e.e)); }
marci@556
   440
    Node bNode(const InEdgeIt& e) const { 
marci@556
   441
      return Node(this->graph->bNode(e.e)); }
marci@556
   442
marci@561
   443
    /// This function hides \c n in the graph, i.e. the iteration 
marci@561
   444
    /// jumps over it. This is done by simply setting the value of \c n  
marci@561
   445
    /// to be false in the corresponding node-map.
marci@556
   446
    void hide(const Node& n) const { node_filter_map->set(n, false); }
marci@561
   447
marci@561
   448
    /// This function hides \c e in the graph, i.e. the iteration 
marci@561
   449
    /// jumps over it. This is done by simply setting the value of \c e  
marci@561
   450
    /// to be false in the corresponding edge-map.
marci@556
   451
    void hide(const Edge& e) const { edge_filter_map->set(e, false); }
marci@556
   452
marci@561
   453
    /// The value of \c n is set to be true in the node-map which stores 
marci@561
   454
    /// hide information. If \c n was hidden previuosly, then it is shown 
marci@561
   455
    /// again
marci@561
   456
     void unHide(const Node& n) const { node_filter_map->set(n, true); }
marci@561
   457
marci@561
   458
    /// The value of \c e is set to be true in the edge-map which stores 
marci@561
   459
    /// hide information. If \c e was hidden previuosly, then it is shown 
marci@561
   460
    /// again
marci@556
   461
    void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
marci@556
   462
marci@561
   463
    /// Returns true if \c n is hidden.
marci@561
   464
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
marci@561
   465
marci@561
   466
    /// Returns true if \c n is hidden.
marci@561
   467
    bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
marci@593
   468
alpar@594
   469
    /// This is a linear time operation and works only if 
marci@593
   470
    /// NodeIt is defined.
marci@593
   471
    int nodeNum() const { 
marci@593
   472
      int i=0;
marci@593
   473
      NodeIt n;
marci@593
   474
      for (this->first(n); this->valid(n); this->next(n)) ++i;
marci@593
   475
      return i; 
marci@593
   476
    }
marci@593
   477
marci@593
   478
    /// This is a linear time operation and works only if 
marci@593
   479
    /// EdgeIt is defined.
marci@593
   480
    int edgeNum() const { 
marci@593
   481
      int i=0;
marci@593
   482
      EdgeIt e;
marci@593
   483
      for (this->first(e); this->valid(e); this->next(e)) ++i;
marci@593
   484
      return i; 
marci@593
   485
    }
marci@593
   486
marci@556
   487
  };
marci@556
   488
marci@569
   489
marci@569
   490
marci@556
   491
  /// A wrapper for forgetting the orientation of a graph.
marci@556
   492
marci@556
   493
  /// A wrapper for getting an undirected graph by forgetting
marci@556
   494
  /// the orientation of a directed one.
alpar@589
   495
  ///
alpar@589
   496
  ///\author Marton Makai
marci@556
   497
  template<typename Graph>
marci@556
   498
  class UndirGraphWrapper : public GraphWrapper<Graph> {
marci@556
   499
  protected:
marci@556
   500
    UndirGraphWrapper() : GraphWrapper<Graph>() { }
marci@556
   501
    
marci@556
   502
  public:
marci@556
   503
    typedef typename GraphWrapper<Graph>::Node Node;
marci@556
   504
    typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
marci@556
   505
    typedef typename GraphWrapper<Graph>::Edge Edge;
marci@556
   506
    typedef typename GraphWrapper<Graph>::EdgeIt EdgeIt;
marci@556
   507
marci@556
   508
    UndirGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
marci@556
   509
marci@556
   510
    class OutEdgeIt {
marci@556
   511
      friend class UndirGraphWrapper<Graph>;
marci@556
   512
      bool out_or_in; //true iff out
marci@556
   513
      typename Graph::OutEdgeIt out;
marci@556
   514
      typename Graph::InEdgeIt in;
marci@556
   515
    public:
marci@556
   516
      OutEdgeIt() { }
marci@556
   517
      OutEdgeIt(const Invalid& i) : Edge(i) { }
marci@556
   518
      OutEdgeIt(const UndirGraphWrapper<Graph>& _G, const Node& _n) {
marci@556
   519
	out_or_in=true; _G.graph->first(out, _n);
marci@556
   520
	if (!(_G.graph->valid(out))) { out_or_in=false; _G.graph->first(in, _n);	}
marci@556
   521
      } 
marci@556
   522
      operator Edge() const { 
marci@556
   523
	if (out_or_in) return Edge(out); else return Edge(in); 
marci@556
   524
      }
marci@556
   525
    };
marci@556
   526
marci@556
   527
//FIXME InEdgeIt
marci@556
   528
    typedef OutEdgeIt InEdgeIt; 
marci@556
   529
marci@556
   530
    using GraphWrapper<Graph>::first;
marci@556
   531
//     NodeIt& first(NodeIt& i) const { 
marci@556
   532
//       i=NodeIt(*this); return i;
marci@556
   533
//     }
marci@556
   534
    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
marci@556
   535
      i=OutEdgeIt(*this, p); return i;
marci@556
   536
    }
marci@556
   537
//FIXME
marci@556
   538
//     InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
marci@556
   539
//       i=InEdgeIt(*this, p); return i;
marci@556
   540
//     }
marci@556
   541
//     EdgeIt& first(EdgeIt& i) const { 
marci@556
   542
//       i=EdgeIt(*this); return i;
marci@556
   543
//     }
marci@556
   544
marci@556
   545
    using GraphWrapper<Graph>::next;
marci@556
   546
//     NodeIt& next(NodeIt& n) const {
marci@556
   547
//       GraphWrapper<Graph>::next(n);
marci@556
   548
//       return n;
marci@556
   549
//     }
marci@556
   550
    OutEdgeIt& next(OutEdgeIt& e) const {
marci@556
   551
      if (e.out_or_in) {
marci@556
   552
	typename Graph::Node n=this->graph->tail(e.out);
marci@556
   553
	this->graph->next(e.out);
marci@556
   554
	if (!this->graph->valid(e.out)) { 
marci@556
   555
	  e.out_or_in=false; this->graph->first(e.in, n); }
marci@556
   556
      } else {
marci@556
   557
	this->graph->next(e.in);
marci@556
   558
      }
marci@556
   559
      return e;
marci@556
   560
    }
marci@556
   561
    //FIXME InEdgeIt
marci@556
   562
//     EdgeIt& next(EdgeIt& e) const {
marci@556
   563
//       GraphWrapper<Graph>::next(n);
marci@556
   564
// //      graph->next(e.e);
marci@556
   565
//       return e;
marci@556
   566
//     }
marci@556
   567
marci@556
   568
    Node aNode(const OutEdgeIt& e) const { 
marci@556
   569
      if (e.out_or_in) return this->graph->tail(e); else 
marci@556
   570
	return this->graph->head(e); }
marci@556
   571
    Node bNode(const OutEdgeIt& e) const { 
marci@556
   572
      if (e.out_or_in) return this->graph->head(e); else 
marci@556
   573
	return this->graph->tail(e); }
marci@556
   574
  };
marci@556
   575
  
marci@556
   576
marci@556
   577
marci@556
   578
  /// An undirected graph template
marci@556
   579
  template<typename Graph>
marci@556
   580
  class UndirGraph : public UndirGraphWrapper<Graph> {
marci@556
   581
    typedef UndirGraphWrapper<Graph> Parent;
marci@556
   582
  protected:
marci@556
   583
    Graph gr;
marci@556
   584
  public:
marci@556
   585
    UndirGraph() : UndirGraphWrapper<Graph>() { 
marci@556
   586
      Parent::setGraph(gr); 
marci@556
   587
    }
marci@556
   588
  };
marci@556
   589
marci@569
   590
marci@576
   591
  /// A wrapper for composing bidirected graph from a directed one. 
marci@576
   592
  /// experimental, for fezso's sake.
marci@569
   593
marci@569
   594
  /// A wrapper for composing bidirected graph from a directed one. 
marci@569
   595
  /// experimental, for fezso's sake.
marci@569
   596
  template<typename Graph>
marci@569
   597
  class BidirGraphWrapper : public GraphWrapper<Graph> {
marci@569
   598
  protected:
marci@569
   599
    //const CapacityMap* capacity;
marci@569
   600
    //FlowMap* flow;
marci@569
   601
marci@569
   602
    BidirGraphWrapper() : GraphWrapper<Graph>()/*, 
marci@569
   603
						 capacity(0), flow(0)*/ { }
marci@569
   604
//     void setCapacityMap(const CapacityMap& _capacity) {
marci@569
   605
//       capacity=&_capacity;
marci@569
   606
//     }
marci@569
   607
//     void setFlowMap(FlowMap& _flow) {
marci@569
   608
//       flow=&_flow;
marci@569
   609
//     }
marci@569
   610
marci@569
   611
  public:
marci@569
   612
marci@569
   613
    BidirGraphWrapper(Graph& _graph/*, const CapacityMap& _capacity, 
marci@569
   614
				     FlowMap& _flow*/) : 
marci@569
   615
      GraphWrapper<Graph>(_graph)/*, capacity(&_capacity), flow(&_flow)*/ { }
marci@569
   616
marci@569
   617
    class Edge; 
marci@569
   618
    class OutEdgeIt; 
marci@569
   619
    friend class Edge; 
marci@569
   620
    friend class OutEdgeIt; 
marci@569
   621
marci@569
   622
    typedef typename GraphWrapper<Graph>::Node Node;
marci@569
   623
    typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
marci@569
   624
    class Edge : public Graph::Edge {
marci@569
   625
      friend class BidirGraphWrapper<Graph>;
marci@569
   626
    protected:
marci@569
   627
      bool backward; //true, iff backward
marci@569
   628
//      typename Graph::Edge e;
marci@569
   629
    public:
marci@569
   630
      Edge() { }
marci@569
   631
      Edge(const typename Graph::Edge& _e, bool _backward) : 
marci@569
   632
	Graph::Edge(_e), backward(_backward) { }
marci@569
   633
      Edge(const Invalid& i) : Graph::Edge(i), backward(true) { }
marci@569
   634
//the unique invalid iterator
marci@569
   635
      friend bool operator==(const Edge& u, const Edge& v) { 
marci@569
   636
	return (v.backward==u.backward && 
marci@569
   637
		static_cast<typename Graph::Edge>(u)==
marci@569
   638
		static_cast<typename Graph::Edge>(v));
marci@569
   639
      } 
marci@569
   640
      friend bool operator!=(const Edge& u, const Edge& v) { 
marci@569
   641
	return (v.backward!=u.backward || 
marci@569
   642
		static_cast<typename Graph::Edge>(u)!=
marci@569
   643
		static_cast<typename Graph::Edge>(v));
marci@569
   644
      } 
marci@569
   645
    };
marci@569
   646
marci@569
   647
    class OutEdgeIt {
marci@569
   648
      friend class BidirGraphWrapper<Graph>;
marci@569
   649
    protected:
marci@569
   650
      typename Graph::OutEdgeIt out;
marci@569
   651
      typename Graph::InEdgeIt in;
marci@569
   652
      bool backward;
marci@569
   653
    public:
marci@569
   654
      OutEdgeIt() { }
marci@569
   655
      //FIXME
marci@569
   656
//      OutEdgeIt(const Edge& e) : Edge(e) { }
marci@569
   657
      OutEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
marci@569
   658
//the unique invalid iterator
marci@569
   659
      OutEdgeIt(const BidirGraphWrapper<Graph>& _G, Node v) { 
marci@569
   660
	backward=false;
marci@569
   661
	_G.graph->first(out, v);
marci@569
   662
	while(_G.graph->valid(out) && !_G.enabled(*this)) { _G.graph->next(out); }
marci@569
   663
	if (!_G.graph->valid(out)) {
marci@569
   664
	  backward=true;
marci@569
   665
	  _G.graph->first(in, v);
marci@569
   666
	  while(_G.graph->valid(in) && !_G.enabled(*this)) { _G.graph->next(in); }
marci@569
   667
	}
marci@569
   668
      }
marci@569
   669
      operator Edge() const { 
marci@569
   670
//	Edge e;
marci@569
   671
//	e.forward=this->forward;
marci@569
   672
//	if (this->forward) e=out; else e=in;
marci@569
   673
//	return e;
marci@569
   674
	if (this->backward) 
marci@569
   675
	  return Edge(in, this->backward); 
marci@569
   676
	else 
marci@569
   677
	  return Edge(out, this->backward);
marci@569
   678
      }
marci@569
   679
    };
marci@569
   680
marci@569
   681
    class InEdgeIt {
marci@569
   682
      friend class BidirGraphWrapper<Graph>;
marci@569
   683
    protected:
marci@569
   684
      typename Graph::OutEdgeIt out;
marci@569
   685
      typename Graph::InEdgeIt in;
marci@569
   686
      bool backward;
marci@569
   687
    public:
marci@569
   688
      InEdgeIt() { }
marci@569
   689
      //FIXME
marci@569
   690
//      OutEdgeIt(const Edge& e) : Edge(e) { }
marci@569
   691
      InEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
marci@569
   692
//the unique invalid iterator
marci@569
   693
      InEdgeIt(const BidirGraphWrapper<Graph>& _G, Node v) { 
marci@569
   694
	backward=false;
marci@569
   695
	_G.graph->first(in, v);
marci@569
   696
	while(_G.graph->valid(in) && !_G.enabled(*this)) { _G.graph->next(in); }
marci@569
   697
	if (!_G.graph->valid(in)) {
marci@569
   698
	  backward=true;
marci@569
   699
	  _G.graph->first(out, v);
marci@569
   700
	  while(_G.graph->valid(out) && !_G.enabled(*this)) { _G.graph->next(out); }
marci@569
   701
	}
marci@569
   702
      }
marci@569
   703
      operator Edge() const { 
marci@569
   704
//	Edge e;
marci@569
   705
//	e.forward=this->forward;
marci@569
   706
//	if (this->forward) e=out; else e=in;
marci@569
   707
//	return e;
marci@569
   708
	if (this->backward) 
marci@569
   709
	  return Edge(out, this->backward); 
marci@569
   710
	else 
marci@569
   711
	  return Edge(in, this->backward);
marci@569
   712
      }
marci@569
   713
    };
marci@569
   714
marci@569
   715
    class EdgeIt {
marci@569
   716
      friend class BidirGraphWrapper<Graph>;
marci@569
   717
    protected:
marci@569
   718
      typename Graph::EdgeIt e;
marci@569
   719
      bool backward;
marci@569
   720
    public:
marci@569
   721
      EdgeIt() { }
marci@569
   722
      EdgeIt(const Invalid& i) : e(i), backward(true) { }
marci@569
   723
      EdgeIt(const BidirGraphWrapper<Graph>& _G) { 
marci@569
   724
	backward=false;
marci@569
   725
	_G.graph->first(e);
marci@569
   726
	while (_G.graph->valid(e) && !_G.enabled(*this)) _G.graph->next(e);
marci@569
   727
	if (!_G.graph->valid(e)) {
marci@569
   728
	  backward=true;
marci@569
   729
	  _G.graph->first(e);
marci@569
   730
	  while (_G.graph->valid(e) && !_G.enabled(*this)) _G.graph->next(e);
marci@569
   731
	}
marci@569
   732
      }
marci@569
   733
      operator Edge() const { 
marci@569
   734
	return Edge(e, this->backward);
marci@569
   735
      }
marci@569
   736
    };
marci@569
   737
marci@569
   738
    using GraphWrapper<Graph>::first;
marci@569
   739
//     NodeIt& first(NodeIt& i) const { 
marci@569
   740
//       i=NodeIt(*this); return i;
marci@569
   741
//     }
marci@569
   742
    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
marci@569
   743
      i=OutEdgeIt(*this, p); return i;
marci@569
   744
    }
marci@569
   745
//    FIXME not tested
marci@569
   746
    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
marci@569
   747
      i=InEdgeIt(*this, p); return i;
marci@569
   748
    }
marci@569
   749
    EdgeIt& first(EdgeIt& i) const { 
marci@569
   750
      i=EdgeIt(*this); return i;
marci@569
   751
    }
marci@556
   752
  
marci@569
   753
    using GraphWrapper<Graph>::next;
marci@569
   754
//    NodeIt& next(NodeIt& n) const { GraphWrapper<Graph>::next(n); return n; }
marci@569
   755
    OutEdgeIt& next(OutEdgeIt& e) const { 
marci@569
   756
      if (!e.backward) {
marci@569
   757
	Node v=this->graph->aNode(e.out);
marci@569
   758
	this->graph->next(e.out);
marci@569
   759
	while(this->graph->valid(e.out) && !enabled(e)) { 
marci@569
   760
	  this->graph->next(e.out); }
marci@569
   761
	if (!this->graph->valid(e.out)) {
marci@569
   762
	  e.backward=true;
marci@569
   763
	  this->graph->first(e.in, v); 
marci@569
   764
	  while(this->graph->valid(e.in) && !enabled(e)) { 
marci@569
   765
	    this->graph->next(e.in); }
marci@569
   766
	}
marci@569
   767
      } else {
marci@569
   768
	this->graph->next(e.in);
marci@569
   769
	while(this->graph->valid(e.in) && !enabled(e)) { 
marci@569
   770
	  this->graph->next(e.in); } 
marci@569
   771
      }
marci@569
   772
      return e;
marci@569
   773
    }
marci@569
   774
//     FIXME Not tested
marci@569
   775
    InEdgeIt& next(InEdgeIt& e) const { 
marci@569
   776
      if (!e.backward) {
marci@569
   777
	Node v=this->graph->aNode(e.in);
marci@569
   778
	this->graph->next(e.in);
marci@569
   779
	while(this->graph->valid(e.in) && !enabled(e)) { 
marci@569
   780
	  this->graph->next(e.in); }
marci@569
   781
	if (!this->graph->valid(e.in)) {
marci@569
   782
	  e.backward=true;
marci@569
   783
	  this->graph->first(e.out, v); 
marci@569
   784
	  while(this->graph->valid(e.out) && !enabled(e)) { 
marci@569
   785
	    this->graph->next(e.out); }
marci@569
   786
	}
marci@569
   787
      } else {
marci@569
   788
	this->graph->next(e.out);
marci@569
   789
	while(this->graph->valid(e.out) && !enabled(e)) { 
marci@569
   790
	  this->graph->next(e.out); } 
marci@569
   791
      }
marci@569
   792
      return e;
marci@569
   793
    }
marci@569
   794
    EdgeIt& next(EdgeIt& e) const {
marci@569
   795
      if (!e.backward) {
marci@569
   796
	this->graph->next(e.e);
marci@569
   797
	while(this->graph->valid(e.e) && !enabled(e)) { 
marci@569
   798
	  this->graph->next(e.e); }
marci@569
   799
	if (!this->graph->valid(e.e)) {
marci@569
   800
	  e.backward=true;
marci@569
   801
	  this->graph->first(e.e); 
marci@569
   802
	  while(this->graph->valid(e.e) && !enabled(e)) { 
marci@569
   803
	    this->graph->next(e.e); }
marci@569
   804
	}
marci@569
   805
      } else {
marci@569
   806
	this->graph->next(e.e);
marci@569
   807
	while(this->graph->valid(e.e) && !enabled(e)) { 
marci@569
   808
	  this->graph->next(e.e); } 
marci@569
   809
      }
marci@569
   810
      return e;
marci@569
   811
    }
marci@569
   812
marci@569
   813
    Node tail(Edge e) const { 
marci@569
   814
      return ((!e.backward) ? this->graph->tail(e) : this->graph->head(e)); }
marci@569
   815
    Node head(Edge e) const { 
marci@569
   816
      return ((!e.backward) ? this->graph->head(e) : this->graph->tail(e)); }
marci@569
   817
marci@569
   818
    Node aNode(OutEdgeIt e) const { 
marci@569
   819
      return ((!e.backward) ? this->graph->aNode(e.out) : 
marci@569
   820
	      this->graph->aNode(e.in)); }
marci@569
   821
    Node bNode(OutEdgeIt e) const { 
marci@569
   822
      return ((!e.backward) ? this->graph->bNode(e.out) : 
marci@569
   823
	      this->graph->bNode(e.in)); }
marci@569
   824
marci@569
   825
    Node aNode(InEdgeIt e) const { 
marci@569
   826
      return ((!e.backward) ? this->graph->aNode(e.in) : 
marci@569
   827
	      this->graph->aNode(e.out)); }
marci@569
   828
    Node bNode(InEdgeIt e) const { 
marci@569
   829
      return ((!e.backward) ? this->graph->bNode(e.in) : 
marci@569
   830
	      this->graph->bNode(e.out)); }
marci@569
   831
marci@572
   832
    /// Gives back the opposite edge.
marci@572
   833
    Edge opposite(const Edge& e) const { 
marci@572
   834
      Edge f=e;
marci@572
   835
      f.backward=!f.backward;
marci@572
   836
      return f;
marci@572
   837
    }
marci@572
   838
marci@569
   839
//    int nodeNum() const { return graph->nodeNum(); }
marci@569
   840
    //FIXME
marci@569
   841
    void edgeNum() const { }
marci@569
   842
    //int edgeNum() const { return graph->edgeNum(); }
marci@569
   843
marci@569
   844
marci@569
   845
//    int id(Node v) const { return graph->id(v); }
marci@569
   846
marci@569
   847
    bool valid(Node n) const { return GraphWrapper<Graph>::valid(n); }
marci@569
   848
    bool valid(Edge e) const { 
marci@569
   849
      return this->graph->valid(e);
marci@569
   850
	//return e.forward ? graph->valid(e.out) : graph->valid(e.in); 
marci@569
   851
    }
marci@569
   852
marci@569
   853
    bool forward(const Edge& e) const { return !e.backward; }
marci@569
   854
    bool backward(const Edge& e) const { return e.backward; }
marci@569
   855
marci@569
   856
//     void augment(const Edge& e, Number a) const {
marci@569
   857
//       if (!e.backward)  
marci@569
   858
// // 	flow->set(e.out, flow->get(e.out)+a);
marci@569
   859
// 	flow->set(e, (*flow)[e]+a);
marci@569
   860
//       else  
marci@569
   861
// // 	flow->set(e.in, flow->get(e.in)-a);
marci@569
   862
// 	flow->set(e, (*flow)[e]-a);
marci@569
   863
//     }
marci@569
   864
marci@569
   865
    bool enabled(const Edge& e) const { 
marci@569
   866
      if (!e.backward) 
marci@569
   867
//	return (capacity->get(e.out)-flow->get(e.out)); 
marci@569
   868
	//return ((*capacity)[e]-(*flow)[e]);
marci@569
   869
	return true;
marci@569
   870
      else 
marci@569
   871
//	return (flow->get(e.in)); 
marci@569
   872
	//return ((*flow)[e]); 
marci@569
   873
	return true;
marci@569
   874
    }
marci@569
   875
marci@569
   876
//     Number enabled(typename Graph::OutEdgeIt out) const { 
marci@569
   877
// //      return (capacity->get(out)-flow->get(out)); 
marci@569
   878
//       return ((*capacity)[out]-(*flow)[out]); 
marci@569
   879
//     }
marci@569
   880
    
marci@569
   881
//     Number enabled(typename Graph::InEdgeIt in) const { 
marci@569
   882
// //      return (flow->get(in)); 
marci@569
   883
//       return ((*flow)[in]); 
marci@569
   884
//     }
marci@569
   885
marci@569
   886
    template <typename T>
marci@569
   887
    class EdgeMap {
marci@569
   888
      typename Graph::template EdgeMap<T> forward_map, backward_map; 
marci@569
   889
    public:
marci@569
   890
      EdgeMap(const BidirGraphWrapper<Graph>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
marci@569
   891
      EdgeMap(const BidirGraphWrapper<Graph>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
marci@569
   892
      void set(Edge e, T a) { 
marci@569
   893
	if (!e.backward) 
marci@569
   894
	  forward_map.set(e.out, a); 
marci@569
   895
	else 
marci@569
   896
	  backward_map.set(e.in, a); 
marci@569
   897
      }
marci@569
   898
      T operator[](Edge e) const { 
marci@569
   899
	if (!e.backward) 
marci@569
   900
	  return forward_map[e.out]; 
marci@569
   901
	else 
marci@569
   902
	  return backward_map[e.in]; 
marci@569
   903
      }
marci@569
   904
//       T get(Edge e) const { 
marci@569
   905
// 	if (e.out_or_in) 
marci@569
   906
// 	  return forward_map.get(e.out); 
marci@569
   907
// 	else 
marci@569
   908
// 	  return backward_map.get(e.in); 
marci@569
   909
//       }
marci@569
   910
    };
marci@569
   911
  };
marci@569
   912
marci@569
   913
marci@556
   914
marci@556
   915
  /// A wrapper for composing the residual graph for directed flow and circulation problems.
marci@556
   916
marci@556
   917
  /// A wrapper for composing the residual graph for directed flow and circulation problems.
marci@556
   918
  template<typename Graph, typename Number, 
marci@556
   919
	   typename CapacityMap, typename FlowMap>
marci@556
   920
  class ResGraphWrapper : public GraphWrapper<Graph> {
marci@556
   921
  protected:
marci@556
   922
    const CapacityMap* capacity;
marci@556
   923
    FlowMap* flow;
marci@556
   924
marci@556
   925
    ResGraphWrapper() : GraphWrapper<Graph>(0), 
marci@556
   926
			capacity(0), flow(0) { }
marci@560
   927
    void setCapacityMap(const CapacityMap& _capacity) {
marci@560
   928
      capacity=&_capacity;
marci@556
   929
    }
marci@556
   930
    void setFlowMap(FlowMap& _flow) {
marci@556
   931
      flow=&_flow;
marci@556
   932
    }
marci@556
   933
marci@556
   934
  public:
marci@556
   935
marci@556
   936
    ResGraphWrapper(Graph& _graph, const CapacityMap& _capacity, 
marci@556
   937
		    FlowMap& _flow) : 
marci@556
   938
      GraphWrapper<Graph>(_graph), capacity(&_capacity), flow(&_flow) { }
marci@556
   939
marci@556
   940
    class Edge; 
marci@556
   941
    class OutEdgeIt; 
marci@556
   942
    friend class Edge; 
marci@556
   943
    friend class OutEdgeIt; 
marci@556
   944
marci@556
   945
    typedef typename GraphWrapper<Graph>::Node Node;
marci@556
   946
    typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
marci@556
   947
    class Edge : public Graph::Edge {
marci@556
   948
      friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
marci@556
   949
    protected:
marci@565
   950
      bool backward; //true, iff backward
marci@556
   951
//      typename Graph::Edge e;
marci@556
   952
    public:
marci@556
   953
      Edge() { }
marci@565
   954
      Edge(const typename Graph::Edge& _e, bool _backward) : 
marci@565
   955
	Graph::Edge(_e), backward(_backward) { }
marci@565
   956
      Edge(const Invalid& i) : Graph::Edge(i), backward(true) { }
marci@556
   957
//the unique invalid iterator
marci@556
   958
      friend bool operator==(const Edge& u, const Edge& v) { 
marci@565
   959
	return (v.backward==u.backward && 
marci@556
   960
		static_cast<typename Graph::Edge>(u)==
marci@556
   961
		static_cast<typename Graph::Edge>(v));
marci@556
   962
      } 
marci@556
   963
      friend bool operator!=(const Edge& u, const Edge& v) { 
marci@565
   964
	return (v.backward!=u.backward || 
marci@556
   965
		static_cast<typename Graph::Edge>(u)!=
marci@556
   966
		static_cast<typename Graph::Edge>(v));
marci@556
   967
      } 
marci@556
   968
    };
marci@556
   969
marci@556
   970
    class OutEdgeIt {
marci@556
   971
      friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
marci@556
   972
    protected:
marci@556
   973
      typename Graph::OutEdgeIt out;
marci@556
   974
      typename Graph::InEdgeIt in;
marci@565
   975
      bool backward;
marci@556
   976
    public:
marci@556
   977
      OutEdgeIt() { }
marci@556
   978
      //FIXME
marci@556
   979
//      OutEdgeIt(const Edge& e) : Edge(e) { }
marci@565
   980
      OutEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
marci@556
   981
//the unique invalid iterator
marci@569
   982
      OutEdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G, Node v) { 
marci@565
   983
	backward=false;
marci@569
   984
	_G.graph->first(out, v);
marci@569
   985
	while( _G.graph->valid(out) && !(_G.resCap(*this)>0) ) { _G.graph->next(out); }
marci@569
   986
	if (!_G.graph->valid(out)) {
marci@565
   987
	  backward=true;
marci@569
   988
	  _G.graph->first(in, v);
marci@569
   989
	  while( _G.graph->valid(in) && !(_G.resCap(*this)>0) ) { _G.graph->next(in); }
marci@556
   990
	}
marci@556
   991
      }
marci@556
   992
      operator Edge() const { 
marci@556
   993
//	Edge e;
marci@556
   994
//	e.forward=this->forward;
marci@556
   995
//	if (this->forward) e=out; else e=in;
marci@556
   996
//	return e;
marci@565
   997
	if (this->backward) 
marci@565
   998
	  return Edge(in, this->backward); 
marci@556
   999
	else 
marci@565
  1000
	  return Edge(out, this->backward);
marci@556
  1001
      }
marci@556
  1002
    };
marci@556
  1003
marci@556
  1004
    class InEdgeIt {
marci@556
  1005
      friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
marci@556
  1006
    protected:
marci@556
  1007
      typename Graph::OutEdgeIt out;
marci@556
  1008
      typename Graph::InEdgeIt in;
marci@565
  1009
      bool backward;
marci@556
  1010
    public:
marci@556
  1011
      InEdgeIt() { }
marci@556
  1012
      //FIXME
marci@556
  1013
//      OutEdgeIt(const Edge& e) : Edge(e) { }
marci@565
  1014
      InEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
marci@556
  1015
//the unique invalid iterator
marci@569
  1016
      InEdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G, Node v) { 
marci@565
  1017
	backward=false;
marci@569
  1018
	_G.graph->first(in, v);
marci@569
  1019
	while( _G.graph->valid(in) && !(_G.resCap(*this)>0) ) { _G.graph->next(in); }
marci@569
  1020
	if (!_G.graph->valid(in)) {
marci@565
  1021
	  backward=true;
marci@569
  1022
	  _G.graph->first(out, v);
marci@569
  1023
	  while( _G.graph->valid(out) && !(_G.resCap(*this)>0) ) { _G.graph->next(out); }
marci@556
  1024
	}
marci@556
  1025
      }
marci@556
  1026
      operator Edge() const { 
marci@556
  1027
//	Edge e;
marci@556
  1028
//	e.forward=this->forward;
marci@556
  1029
//	if (this->forward) e=out; else e=in;
marci@556
  1030
//	return e;
marci@565
  1031
	if (this->backward) 
marci@565
  1032
	  return Edge(out, this->backward); 
marci@556
  1033
	else 
marci@565
  1034
	  return Edge(in, this->backward);
marci@556
  1035
      }
marci@556
  1036
    };
marci@556
  1037
marci@556
  1038
    class EdgeIt {
marci@556
  1039
      friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
marci@556
  1040
    protected:
marci@556
  1041
      typename Graph::EdgeIt e;
marci@565
  1042
      bool backward;
marci@556
  1043
    public:
marci@556
  1044
      EdgeIt() { }
marci@565
  1045
      EdgeIt(const Invalid& i) : e(i), backward(true) { }
marci@569
  1046
      EdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G) { 
marci@565
  1047
	backward=false;
marci@569
  1048
	_G.graph->first(e);
marci@569
  1049
	while (_G.graph->valid(e) && !(_G.resCap(*this)>0)) _G.graph->next(e);
marci@569
  1050
	if (!_G.graph->valid(e)) {
marci@565
  1051
	  backward=true;
marci@569
  1052
	  _G.graph->first(e);
marci@569
  1053
	  while (_G.graph->valid(e) && !(_G.resCap(*this)>0)) _G.graph->next(e);
marci@556
  1054
	}
marci@556
  1055
      }
marci@556
  1056
      operator Edge() const { 
marci@565
  1057
	return Edge(e, this->backward);
marci@556
  1058
      }
marci@556
  1059
    };
marci@556
  1060
marci@556
  1061
    using GraphWrapper<Graph>::first;
marci@556
  1062
//     NodeIt& first(NodeIt& i) const { 
marci@556
  1063
//       i=NodeIt(*this); return i;
marci@556
  1064
//     }
marci@556
  1065
    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
marci@556
  1066
      i=OutEdgeIt(*this, p); return i;
marci@556
  1067
    }
marci@556
  1068
//    FIXME not tested
marci@556
  1069
    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
marci@556
  1070
      i=InEdgeIt(*this, p); return i;
marci@556
  1071
    }
marci@556
  1072
    EdgeIt& first(EdgeIt& i) const { 
marci@556
  1073
      i=EdgeIt(*this); return i;
marci@556
  1074
    }
marci@556
  1075
  
marci@556
  1076
    using GraphWrapper<Graph>::next;
marci@556
  1077
//    NodeIt& next(NodeIt& n) const { GraphWrapper<Graph>::next(n); return n; }
marci@556
  1078
    OutEdgeIt& next(OutEdgeIt& e) const { 
marci@565
  1079
      if (!e.backward) {
marci@556
  1080
	Node v=this->graph->aNode(e.out);
marci@556
  1081
	this->graph->next(e.out);
marci@556
  1082
	while( this->graph->valid(e.out) && !(resCap(e)>0) ) { 
marci@556
  1083
	  this->graph->next(e.out); }
marci@556
  1084
	if (!this->graph->valid(e.out)) {
marci@565
  1085
	  e.backward=true;
marci@556
  1086
	  this->graph->first(e.in, v); 
marci@556
  1087
	  while( this->graph->valid(e.in) && !(resCap(e)>0) ) { 
marci@556
  1088
	    this->graph->next(e.in); }
marci@556
  1089
	}
marci@556
  1090
      } else {
marci@556
  1091
	this->graph->next(e.in);
marci@556
  1092
	while( this->graph->valid(e.in) && !(resCap(e)>0) ) { 
marci@556
  1093
	  this->graph->next(e.in); } 
marci@556
  1094
      }
marci@556
  1095
      return e;
marci@556
  1096
    }
marci@556
  1097
//     FIXME Not tested
marci@556
  1098
    InEdgeIt& next(InEdgeIt& e) const { 
marci@565
  1099
      if (!e.backward) {
marci@556
  1100
	Node v=this->graph->aNode(e.in);
marci@556
  1101
	this->graph->next(e.in);
marci@556
  1102
	while( this->graph->valid(e.in) && !(resCap(e)>0) ) { 
marci@556
  1103
	  this->graph->next(e.in); }
marci@556
  1104
	if (!this->graph->valid(e.in)) {
marci@565
  1105
	  e.backward=true;
marci@556
  1106
	  this->graph->first(e.out, v); 
marci@556
  1107
	  while( this->graph->valid(e.out) && !(resCap(e)>0) ) { 
marci@556
  1108
	    this->graph->next(e.out); }
marci@556
  1109
	}
marci@556
  1110
      } else {
marci@556
  1111
	this->graph->next(e.out);
marci@556
  1112
	while( this->graph->valid(e.out) && !(resCap(e)>0) ) { 
marci@556
  1113
	  this->graph->next(e.out); } 
marci@556
  1114
      }
marci@556
  1115
      return e;
marci@556
  1116
    }
marci@556
  1117
    EdgeIt& next(EdgeIt& e) const {
marci@565
  1118
      if (!e.backward) {
marci@556
  1119
	this->graph->next(e.e);
marci@556
  1120
	while( this->graph->valid(e.e) && !(resCap(e)>0) ) { 
marci@556
  1121
	  this->graph->next(e.e); }
marci@556
  1122
	if (!this->graph->valid(e.e)) {
marci@565
  1123
	  e.backward=true;
marci@556
  1124
	  this->graph->first(e.e); 
marci@556
  1125
	  while( this->graph->valid(e.e) && !(resCap(e)>0) ) { 
marci@556
  1126
	    this->graph->next(e.e); }
marci@556
  1127
	}
marci@556
  1128
      } else {
marci@556
  1129
	this->graph->next(e.e);
marci@556
  1130
	while( this->graph->valid(e.e) && !(resCap(e)>0) ) { 
marci@556
  1131
	  this->graph->next(e.e); } 
marci@556
  1132
      }
marci@556
  1133
      return e;
marci@556
  1134
    }
marci@556
  1135
marci@556
  1136
    Node tail(Edge e) const { 
marci@565
  1137
      return ((!e.backward) ? this->graph->tail(e) : this->graph->head(e)); }
marci@556
  1138
    Node head(Edge e) const { 
marci@565
  1139
      return ((!e.backward) ? this->graph->head(e) : this->graph->tail(e)); }
marci@556
  1140
marci@556
  1141
    Node aNode(OutEdgeIt e) const { 
marci@565
  1142
      return ((!e.backward) ? this->graph->aNode(e.out) : 
marci@556
  1143
	      this->graph->aNode(e.in)); }
marci@556
  1144
    Node bNode(OutEdgeIt e) const { 
marci@565
  1145
      return ((!e.backward) ? this->graph->bNode(e.out) : 
marci@556
  1146
	      this->graph->bNode(e.in)); }
marci@556
  1147
marci@556
  1148
    Node aNode(InEdgeIt e) const { 
marci@565
  1149
      return ((!e.backward) ? this->graph->aNode(e.in) : 
marci@556
  1150
	      this->graph->aNode(e.out)); }
marci@556
  1151
    Node bNode(InEdgeIt e) const { 
marci@565
  1152
      return ((!e.backward) ? this->graph->bNode(e.in) : 
marci@556
  1153
	      this->graph->bNode(e.out)); }
marci@556
  1154
marci@556
  1155
//    int nodeNum() const { return graph->nodeNum(); }
marci@556
  1156
    //FIXME
marci@556
  1157
    void edgeNum() const { }
marci@556
  1158
    //int edgeNum() const { return graph->edgeNum(); }
marci@556
  1159
marci@556
  1160
marci@556
  1161
//    int id(Node v) const { return graph->id(v); }
marci@556
  1162
marci@556
  1163
    bool valid(Node n) const { return GraphWrapper<Graph>::valid(n); }
marci@556
  1164
    bool valid(Edge e) const { 
marci@556
  1165
      return this->graph->valid(e);
marci@556
  1166
	//return e.forward ? graph->valid(e.out) : graph->valid(e.in); 
marci@556
  1167
    }
marci@556
  1168
marci@565
  1169
    bool forward(const Edge& e) const { return !e.backward; }
marci@565
  1170
    bool backward(const Edge& e) const { return e.backward; }
marci@556
  1171
marci@556
  1172
    void augment(const Edge& e, Number a) const {
marci@565
  1173
      if (!e.backward)  
marci@556
  1174
// 	flow->set(e.out, flow->get(e.out)+a);
marci@556
  1175
	flow->set(e, (*flow)[e]+a);
marci@556
  1176
      else  
marci@556
  1177
// 	flow->set(e.in, flow->get(e.in)-a);
marci@556
  1178
	flow->set(e, (*flow)[e]-a);
marci@556
  1179
    }
marci@556
  1180
marci@556
  1181
    Number resCap(const Edge& e) const { 
marci@565
  1182
      if (!e.backward) 
marci@556
  1183
//	return (capacity->get(e.out)-flow->get(e.out)); 
marci@556
  1184
	return ((*capacity)[e]-(*flow)[e]); 
marci@556
  1185
      else 
marci@556
  1186
//	return (flow->get(e.in)); 
marci@556
  1187
	return ((*flow)[e]); 
marci@556
  1188
    }
marci@556
  1189
marci@556
  1190
//     Number resCap(typename Graph::OutEdgeIt out) const { 
marci@556
  1191
// //      return (capacity->get(out)-flow->get(out)); 
marci@556
  1192
//       return ((*capacity)[out]-(*flow)[out]); 
marci@556
  1193
//     }
marci@556
  1194
    
marci@556
  1195
//     Number resCap(typename Graph::InEdgeIt in) const { 
marci@556
  1196
// //      return (flow->get(in)); 
marci@556
  1197
//       return ((*flow)[in]); 
marci@556
  1198
//     }
marci@556
  1199
marci@556
  1200
    template <typename T>
marci@556
  1201
    class EdgeMap {
marci@556
  1202
      typename Graph::template EdgeMap<T> forward_map, backward_map; 
marci@556
  1203
    public:
marci@556
  1204
      EdgeMap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
marci@556
  1205
      EdgeMap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
marci@556
  1206
      void set(Edge e, T a) { 
marci@565
  1207
	if (!e.backward) 
marci@556
  1208
	  forward_map.set(e.out, a); 
marci@556
  1209
	else 
marci@556
  1210
	  backward_map.set(e.in, a); 
marci@556
  1211
      }
marci@556
  1212
      T operator[](Edge e) const { 
marci@565
  1213
	if (!e.backward) 
marci@556
  1214
	  return forward_map[e.out]; 
marci@556
  1215
	else 
marci@556
  1216
	  return backward_map[e.in]; 
marci@556
  1217
      }
marci@556
  1218
//       T get(Edge e) const { 
marci@556
  1219
// 	if (e.out_or_in) 
marci@556
  1220
// 	  return forward_map.get(e.out); 
marci@556
  1221
// 	else 
marci@556
  1222
// 	  return backward_map.get(e.in); 
marci@556
  1223
//       }
marci@556
  1224
    };
marci@556
  1225
  };
marci@556
  1226
marci@569
  1227
marci@569
  1228
marci@556
  1229
  /// ErasingFirstGraphWrapper for blocking flows.
marci@556
  1230
marci@556
  1231
  /// ErasingFirstGraphWrapper for blocking flows.
marci@556
  1232
  ///
marci@556
  1233
  ///\author Marton Makai
marci@556
  1234
  template<typename Graph, typename FirstOutEdgesMap>
marci@556
  1235
  class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
marci@556
  1236
  protected:
marci@556
  1237
    FirstOutEdgesMap* first_out_edges;
marci@556
  1238
  public:
marci@556
  1239
    ErasingFirstGraphWrapper(Graph& _graph, 
marci@556
  1240
			     FirstOutEdgesMap& _first_out_edges) : 
marci@556
  1241
      GraphWrapper<Graph>(_graph), first_out_edges(&_first_out_edges) { }  
marci@556
  1242
marci@556
  1243
    typedef typename GraphWrapper<Graph>::Node Node;
marci@556
  1244
//     class NodeIt { 
marci@556
  1245
//       friend class GraphWrapper<Graph>;
marci@556
  1246
//       friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
marci@556
  1247
//       typename Graph::NodeIt n;
marci@556
  1248
//      public:
marci@556
  1249
//       NodeIt() { }
marci@556
  1250
//       NodeIt(const typename Graph::NodeIt& _n) : n(_n) { }
marci@556
  1251
//       NodeIt(const Invalid& i) : n(i) { }
marci@556
  1252
//       NodeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G) : 
marci@556
  1253
// 	n(*(_G.graph)) { }
marci@556
  1254
//       operator Node() const { return Node(typename Graph::Node(n)); }
marci@556
  1255
//     };
marci@556
  1256
    typedef typename GraphWrapper<Graph>::Edge Edge;
marci@556
  1257
    class OutEdgeIt { 
marci@556
  1258
      friend class GraphWrapper<Graph>;
marci@556
  1259
      friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
marci@556
  1260
//      typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
marci@556
  1261
      typename Graph::OutEdgeIt e;
marci@556
  1262
    public:
marci@556
  1263
      OutEdgeIt() { }
marci@556
  1264
      OutEdgeIt(const typename Graph::OutEdgeIt& _e) : e(_e) { }
marci@556
  1265
      OutEdgeIt(const Invalid& i) : e(i) { }
marci@556
  1266
      OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G, 
marci@556
  1267
		const Node& _n) : 
marci@556
  1268
	e((*_G.first_out_edges)[_n]) { }
marci@556
  1269
      operator Edge() const { return Edge(typename Graph::Edge(e)); }
marci@556
  1270
    };
marci@556
  1271
    class InEdgeIt { 
marci@556
  1272
      friend class GraphWrapper<Graph>;
marci@556
  1273
      friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
marci@556
  1274
//      typedef typename Graph::InEdgeIt GraphInEdgeIt;
marci@556
  1275
      typename Graph::InEdgeIt e;
marci@556
  1276
    public:
marci@556
  1277
      InEdgeIt() { }
marci@556
  1278
      InEdgeIt(const typename Graph::InEdgeIt& _e) : e(_e) { }
marci@556
  1279
      InEdgeIt(const Invalid& i) : e(i) { }
marci@556
  1280
      InEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G, 
marci@556
  1281
	       const Node& _n) : 
marci@556
  1282
	e(*(_G.graph), typename Graph::Node(_n)) { }
marci@556
  1283
      operator Edge() const { return Edge(typename Graph::Edge(e)); }
marci@556
  1284
    };
marci@556
  1285
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@556
  1286
    class EdgeIt { 
marci@556
  1287
      friend class GraphWrapper<Graph>;
marci@556
  1288
      friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
marci@556
  1289
//      typedef typename Graph::EdgeIt GraphEdgeIt;
marci@556
  1290
      typename Graph::EdgeIt e;
marci@556
  1291
    public:
marci@556
  1292
      EdgeIt() { }
marci@556
  1293
      EdgeIt(const typename Graph::EdgeIt& _e) : e(_e) { }
marci@556
  1294
      EdgeIt(const Invalid& i) : e(i) { }
marci@556
  1295
      EdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G) : 
marci@556
  1296
	e(*(_G.graph)) { }
marci@556
  1297
      operator Edge() const { return Edge(typename Graph::Edge(e)); }
marci@556
  1298
    };
marci@556
  1299
marci@556
  1300
    using GraphWrapper<Graph>::first;
marci@556
  1301
//     NodeIt& first(NodeIt& i) const { 
marci@556
  1302
//       i=NodeIt(*this); return i;
marci@556
  1303
//     }
marci@556
  1304
    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
marci@556
  1305
      i=OutEdgeIt(*this, p); return i;
marci@556
  1306
    }
marci@556
  1307
    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
marci@556
  1308
      i=InEdgeIt(*this, p); return i;
marci@556
  1309
    }
marci@556
  1310
    EdgeIt& first(EdgeIt& i) const { 
marci@556
  1311
      i=EdgeIt(*this); return i;
marci@556
  1312
    }
marci@556
  1313
marci@556
  1314
    using GraphWrapper<Graph>::next;
marci@556
  1315
//    NodeIt& next(NodeIt& i) const { graph->next(i.n); return i; }
marci@556
  1316
    OutEdgeIt& next(OutEdgeIt& i) const { this->graph->next(i.e); return i; }
marci@556
  1317
    InEdgeIt& next(InEdgeIt& i) const { this->graph->next(i.e); return i; }
marci@556
  1318
    EdgeIt& next(EdgeIt& i) const { this->graph->next(i.e); return i; }    
marci@556
  1319
    
marci@556
  1320
    Node aNode(const OutEdgeIt& e) const { 
marci@556
  1321
      return Node(this->graph->aNode(e.e)); }
marci@556
  1322
    Node aNode(const InEdgeIt& e) const { 
marci@556
  1323
      return Node(this->graph->aNode(e.e)); }
marci@556
  1324
    Node bNode(const OutEdgeIt& e) const { 
marci@556
  1325
      return Node(this->graph->bNode(e.e)); }
marci@556
  1326
    Node bNode(const InEdgeIt& e) const { 
marci@556
  1327
      return Node(this->graph->bNode(e.e)); }
marci@556
  1328
marci@556
  1329
    void erase(const OutEdgeIt& e) const {
marci@556
  1330
      OutEdgeIt f=e;
marci@556
  1331
      this->next(f);
marci@556
  1332
      first_out_edges->set(this->tail(e), f.e);
marci@556
  1333
    }
marci@556
  1334
  };
marci@556
  1335
marci@556
  1336
  ///@}
marci@556
  1337
marci@556
  1338
} //namespace hugo
marci@556
  1339
marci@556
  1340
#endif //HUGO_GRAPH_WRAPPER_H
marci@556
  1341