src/work/marci/graph_wrapper.h
author alpar
Wed, 24 Mar 2004 13:06:06 +0000
changeset 242 b255f25ad394
parent 238 ad3bdd78f4f6
child 259 509ba9f136d2
permissions -rw-r--r--
DocFixes
marci@174
     1
// -*- c++ -*-
marci@76
     2
#ifndef GRAPH_WRAPPER_H
marci@76
     3
#define GRAPH_WRAPPER_H
marci@76
     4
marci@174
     5
#include <invalid.h>
marci@174
     6
alpar@105
     7
namespace hugo {
marci@76
     8
marci@76
     9
  template<typename Graph>
marci@76
    10
  class TrivGraphWrapper {
marci@199
    11
  protected:
marci@76
    12
    Graph* graph;
marci@76
    13
  
marci@76
    14
  public:
marci@76
    15
    typedef Graph BaseGraph;
marci@76
    16
marci@174
    17
    typedef typename Graph::Node Node;
marci@76
    18
    typedef typename Graph::NodeIt NodeIt;
marci@76
    19
marci@174
    20
    typedef typename Graph::Edge Edge;
marci@76
    21
    typedef typename Graph::OutEdgeIt OutEdgeIt;
marci@76
    22
    typedef typename Graph::InEdgeIt InEdgeIt;
marci@155
    23
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@174
    24
    typedef typename Graph::EdgeIt EdgeIt;
marci@168
    25
marci@168
    26
    //TrivGraphWrapper() : graph(0) { }
marci@168
    27
    TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@168
    28
marci@168
    29
    void setGraph(Graph& _graph) { graph = &_graph; }
marci@168
    30
    Graph& getGraph() const { return (*graph); }
marci@76
    31
    
marci@212
    32
    template<typename I> I& first(I& i) const { return graph->first(i); }
marci@212
    33
    template<typename I, typename P> I& first(I& i, const P& p) const { 
marci@212
    34
      return graph->first(i, p); }
marci@155
    35
    
marci@155
    36
    template<typename I> I getNext(const I& i) const { 
marci@155
    37
      return graph->getNext(i); }
marci@155
    38
    template<typename I> I& next(I &i) const { return graph->next(i); }    
marci@76
    39
marci@76
    40
    template< typename It > It first() const { 
marci@212
    41
      It e; first(e); return e; }
marci@76
    42
marci@174
    43
    template< typename It > It first(const Node& v) const { 
marci@212
    44
      It e; first(e, v); return e; }
marci@76
    45
marci@174
    46
    Node head(const Edge& e) const { return graph->head(e); }
marci@174
    47
    Node tail(const Edge& e) const { return graph->tail(e); }
marci@155
    48
marci@155
    49
    template<typename I> bool valid(const I& i) const 
marci@155
    50
      { return graph->valid(i); }
marci@155
    51
  
marci@155
    52
    //template<typename I> void setInvalid(const I &i);
marci@155
    53
    //{ return graph->setInvalid(i); }
marci@155
    54
marci@155
    55
    int nodeNum() const { return graph->nodeNum(); }
marci@155
    56
    int edgeNum() const { return graph->edgeNum(); }
marci@76
    57
  
marci@174
    58
    template<typename I> Node aNode(const I& e) const { 
marci@76
    59
      return graph->aNode(e); }
marci@174
    60
    template<typename I> Node bNode(const I& e) const { 
marci@76
    61
      return graph->bNode(e); }
marci@76
    62
  
marci@174
    63
    Node addNode() const { return graph->addNode(); }
marci@174
    64
    Edge addEdge(const Node& tail, const Node& head) const { 
marci@76
    65
      return graph->addEdge(tail, head); }
marci@76
    66
  
marci@76
    67
    template<typename I> void erase(const I& i) const { graph->erase(i); }
marci@76
    68
  
marci@76
    69
    void clear() const { graph->clear(); }
marci@155
    70
    
marci@76
    71
    template<typename T> class NodeMap : public Graph::NodeMap<T> { 
marci@76
    72
    public:
marci@155
    73
      NodeMap(const TrivGraphWrapper<Graph>& _G) : 
marci@158
    74
	Graph::NodeMap<T>(_G.getGraph()) { }
marci@155
    75
      NodeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
marci@158
    76
	Graph::NodeMap<T>(_G.getGraph(), a) { }
marci@76
    77
    };
marci@168
    78
marci@155
    79
    template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
marci@155
    80
    public:
marci@155
    81
      EdgeMap(const TrivGraphWrapper<Graph>& _G) : 
marci@158
    82
	Graph::EdgeMap<T>(_G.getGraph()) { }
marci@155
    83
      EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
marci@158
    84
	Graph::EdgeMap<T>(_G.getGraph(), a) { }
marci@155
    85
    };
marci@76
    86
  };
marci@76
    87
marci@212
    88
  template<typename GraphWrapper>
marci@212
    89
  class GraphWrapperSkeleton {
marci@212
    90
  protected:
marci@212
    91
    GraphWrapper gw;
marci@212
    92
  
marci@212
    93
  public:
marci@212
    94
    typedef typename GraphWrapper::BaseGraph BaseGraph;
marci@212
    95
marci@212
    96
    typedef typename GraphWrapper::Node Node;
marci@212
    97
    typedef typename GraphWrapper::NodeIt NodeIt;
marci@212
    98
marci@212
    99
    typedef typename GraphWrapper::Edge Edge;
marci@212
   100
    typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
marci@212
   101
    typedef typename GraphWrapper::InEdgeIt InEdgeIt;
marci@212
   102
    //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
marci@212
   103
    typedef typename GraphWrapper::EdgeIt EdgeIt;
marci@212
   104
marci@212
   105
    //GraphWrapperSkeleton() : gw() { }
marci@230
   106
    GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
marci@212
   107
marci@212
   108
    void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
marci@212
   109
    BaseGraph& getGraph() const { return gw.getGraph(); }
marci@212
   110
    
marci@212
   111
    template<typename I> I& first(I& i) const { return gw.first(i); }
marci@212
   112
    template<typename I, typename P> I& first(I& i, const P& p) const { 
marci@212
   113
      return gw.first(i, p); }
marci@212
   114
    
marci@212
   115
    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
marci@212
   116
    template<typename I> I& next(I &i) const { return gw.next(i); }    
marci@212
   117
marci@212
   118
    template< typename It > It first() const { 
marci@212
   119
      It e; this->first(e); return e; }
marci@212
   120
marci@212
   121
    template< typename It > It first(const Node& v) const { 
marci@212
   122
      It e; this->first(e, v); return e; }
marci@212
   123
marci@212
   124
    Node head(const Edge& e) const { return gw.head(e); }
marci@212
   125
    Node tail(const Edge& e) const { return gw.tail(e); }
marci@212
   126
marci@212
   127
    template<typename I> bool valid(const I& i) const { return gw.valid(i); }
marci@212
   128
  
marci@212
   129
    //template<typename I> void setInvalid(const I &i);
marci@212
   130
    //{ return graph->setInvalid(i); }
marci@212
   131
marci@212
   132
    int nodeNum() const { return gw.nodeNum(); }
marci@212
   133
    int edgeNum() const { return gw.edgeNum(); }
marci@212
   134
  
marci@212
   135
    template<typename I> Node aNode(const I& e) const { return gw.aNode(e); }
marci@212
   136
    template<typename I> Node bNode(const I& e) const { return gw.bNode(e); }
marci@212
   137
  
marci@212
   138
    Node addNode() const { return gw.addNode(); }
marci@212
   139
    Edge addEdge(const Node& tail, const Node& head) const { 
marci@212
   140
      return gw.addEdge(tail, head); }
marci@212
   141
  
marci@212
   142
    template<typename I> void erase(const I& i) const { gw.erase(i); }
marci@212
   143
  
marci@212
   144
    void clear() const { gw.clear(); }
marci@212
   145
    
marci@212
   146
    template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 
marci@212
   147
    public:
marci@212
   148
      NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
marci@212
   149
	GraphWrapper::NodeMap<T>(_G.gw) { }
marci@212
   150
      NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) : 
marci@212
   151
	GraphWrapper::NodeMap<T>(_G.gw, a) { }
marci@212
   152
    };
marci@212
   153
marci@212
   154
    template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> { 
marci@212
   155
    public:
marci@212
   156
      EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
marci@212
   157
	GraphWrapper::EdgeMap<T>(_G.gw) { }
marci@212
   158
      EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) : 
marci@212
   159
	GraphWrapper::EdgeMap<T>(_G.gw, a) { }
marci@212
   160
    };
marci@212
   161
  };
marci@212
   162
marci@230
   163
//   template<typename Graph>
marci@230
   164
//   class RevGraphWrapper
marci@230
   165
//   {
marci@230
   166
//   protected:
marci@230
   167
//     Graph* graph;
marci@230
   168
  
marci@230
   169
//   public:
marci@230
   170
//     typedef Graph BaseGraph;
marci@230
   171
marci@230
   172
//     typedef typename Graph::Node Node;    
marci@230
   173
//     typedef typename Graph::NodeIt NodeIt;
marci@230
   174
  
marci@230
   175
//     typedef typename Graph::Edge Edge;
marci@230
   176
//     typedef typename Graph::OutEdgeIt InEdgeIt;
marci@230
   177
//     typedef typename Graph::InEdgeIt OutEdgeIt;
marci@230
   178
//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@230
   179
//     typedef typename Graph::EdgeIt EdgeIt;
marci@230
   180
marci@230
   181
//     //RevGraphWrapper() : graph(0) { }
marci@230
   182
//     RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@230
   183
marci@230
   184
//     void setGraph(Graph& _graph) { graph = &_graph; }
marci@230
   185
//     Graph& getGraph() const { return (*graph); }
marci@230
   186
    
marci@230
   187
//     template<typename I> I& first(I& i) const { return graph->first(i); }
marci@230
   188
//     template<typename I, typename P> I& first(I& i, const P& p) const { 
marci@230
   189
//       return graph->first(i, p); }
marci@230
   190
marci@230
   191
//     template<typename I> I getNext(const I& i) const { 
marci@230
   192
//       return graph->getNext(i); }
marci@230
   193
//     template<typename I> I& next(I &i) const { return graph->next(i); }    
marci@230
   194
marci@230
   195
//     template< typename It > It first() const { 
marci@230
   196
//       It e; first(e); return e; }
marci@230
   197
marci@230
   198
//     template< typename It > It first(const Node& v) const { 
marci@230
   199
//       It e; first(e, v); return e; }
marci@230
   200
marci@230
   201
//     Node head(const Edge& e) const { return graph->tail(e); }
marci@230
   202
//     Node tail(const Edge& e) const { return graph->head(e); }
marci@230
   203
  
marci@230
   204
//     template<typename I> bool valid(const I& i) const 
marci@230
   205
//       { return graph->valid(i); }
marci@230
   206
  
marci@230
   207
//     //template<typename I> void setInvalid(const I &i);
marci@230
   208
//     //{ return graph->setInvalid(i); }
marci@230
   209
  
marci@230
   210
//     template<typename I> Node aNode(const I& e) const { 
marci@230
   211
//       return graph->aNode(e); }
marci@230
   212
//     template<typename I> Node bNode(const I& e) const { 
marci@230
   213
//       return graph->bNode(e); }
marci@230
   214
marci@230
   215
//     Node addNode() const { return graph->addNode(); }
marci@230
   216
//     Edge addEdge(const Node& tail, const Node& head) const { 
marci@230
   217
//       return graph->addEdge(tail, head); }
marci@230
   218
  
marci@230
   219
//     int nodeNum() const { return graph->nodeNum(); }
marci@230
   220
//     int edgeNum() const { return graph->edgeNum(); }
marci@230
   221
  
marci@230
   222
//     template<typename I> void erase(const I& i) const { graph->erase(i); }
marci@230
   223
  
marci@230
   224
//     void clear() const { graph->clear(); }
marci@230
   225
marci@230
   226
//     template<typename T> class NodeMap : public Graph::NodeMap<T> { 
marci@230
   227
//     public:
marci@230
   228
//       NodeMap(const RevGraphWrapper<Graph>& _G) : 
marci@230
   229
// 	Graph::NodeMap<T>(_G.getGraph()) { }
marci@230
   230
//       NodeMap(const RevGraphWrapper<Graph>& _G, T a) : 
marci@230
   231
// 	Graph::NodeMap<T>(_G.getGraph(), a) { }
marci@230
   232
//     };
marci@230
   233
marci@230
   234
//     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
marci@230
   235
//     public:
marci@230
   236
//       EdgeMap(const RevGraphWrapper<Graph>& _G) : 
marci@230
   237
// 	Graph::EdgeMap<T>(_G.getGraph()) { }
marci@230
   238
//       EdgeMap(const RevGraphWrapper<Graph>& _G, T a) : 
marci@230
   239
// 	Graph::EdgeMap<T>(_G.getGraph(), a) { }
marci@230
   240
//     };
marci@230
   241
//   };
marci@230
   242
marci@235
   243
//   template<typename /*Graph*/GraphWrapper
marci@235
   244
//   /*=typename GraphWrapperSkeleton< TrivGraphWrapper<Graph>*/ >
marci@235
   245
//   class RevGraphWrapper : 
marci@235
   246
//     public GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/ {
marci@235
   247
//   protected:
marci@235
   248
//     //Graph* graph;
marci@230
   249
    
marci@235
   250
//   public:
marci@235
   251
//     //typedef Graph BaseGraph;
marci@235
   252
marci@235
   253
//     //typedef typename Graph::Node Node;    
marci@235
   254
//     //typedef typename Graph::NodeIt NodeIt;
marci@235
   255
  
marci@235
   256
//     //typedef typename Graph::Edge Edge;
marci@235
   257
//     typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::OutEdgeIt InEdgeIt;
marci@235
   258
//     typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::InEdgeIt OutEdgeIt;
marci@235
   259
//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@235
   260
//     //typedef typename Graph::EdgeIt EdgeIt;
marci@235
   261
marci@235
   262
//     //RevGraphWrapper() : graph(0) { }
marci@235
   263
//     RevGraphWrapper(GraphWrapper _gw/*BaseGraph& _graph*/) : GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/(_gw/*TrivGraphWrapper<Graph>(_graph)*/) { }
marci@235
   264
    
marci@235
   265
//     //void setGraph(Graph& _graph) { graph = &_graph; }
marci@235
   266
//     //Graph& getGraph() const { return (*graph); }
marci@235
   267
    
marci@235
   268
//     //template<typename I> I& first(I& i) const { return graph->first(i); }
marci@235
   269
//     //template<typename I, typename P> I& first(I& i, const P& p) const { 
marci@235
   270
//     //  return graph->first(i, p); }
marci@235
   271
marci@235
   272
//     //template<typename I> I getNext(const I& i) const { 
marci@235
   273
//     //  return graph->getNext(i); }
marci@235
   274
//     //template<typename I> I& next(I &i) const { return graph->next(i); }    
marci@235
   275
marci@235
   276
//     //template< typename It > It first() const { 
marci@235
   277
//     //  It e; first(e); return e; }
marci@235
   278
marci@235
   279
//     //template< typename It > It first(const Node& v) const { 
marci@235
   280
//     //  It e; first(e, v); return e; }
marci@235
   281
marci@235
   282
//     //Node head(const Edge& e) const { return graph->tail(e); }
marci@235
   283
//     //Node tail(const Edge& e) const { return graph->head(e); }
marci@235
   284
  
marci@235
   285
//     //template<typename I> bool valid(const I& i) const 
marci@235
   286
//     //  { return graph->valid(i); }
marci@235
   287
  
marci@235
   288
//     //template<typename I> void setInvalid(const I &i);
marci@235
   289
//     //{ return graph->setInvalid(i); }
marci@235
   290
  
marci@235
   291
//     //template<typename I> Node aNode(const I& e) const { 
marci@235
   292
//     //  return graph->aNode(e); }
marci@235
   293
//     //template<typename I> Node bNode(const I& e) const { 
marci@235
   294
//     //  return graph->bNode(e); }
marci@235
   295
marci@235
   296
//     //Node addNode() const { return graph->addNode(); }
marci@235
   297
//     //Edge addEdge(const Node& tail, const Node& head) const { 
marci@235
   298
//     //  return graph->addEdge(tail, head); }
marci@235
   299
  
marci@235
   300
//     //int nodeNum() const { return graph->nodeNum(); }
marci@235
   301
//     //int edgeNum() const { return graph->edgeNum(); }
marci@235
   302
  
marci@235
   303
//     //template<typename I> void erase(const I& i) const { graph->erase(i); }
marci@235
   304
  
marci@235
   305
//     //void clear() const { graph->clear(); }
marci@235
   306
marci@235
   307
//     template<typename T> class NodeMap : 
marci@235
   308
//       public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T> 
marci@235
   309
//     { 
marci@235
   310
//     public:
marci@235
   311
//       NodeMap(const RevGraphWrapper<GraphWrapper>& _gw) : 
marci@235
   312
// 	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw) { }
marci@235
   313
//       NodeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) : 
marci@235
   314
// 	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw, a) { }
marci@235
   315
//     };
marci@235
   316
    
marci@235
   317
//     template<typename T> class EdgeMap : 
marci@235
   318
//       public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T> { 
marci@235
   319
//     public:
marci@235
   320
//       EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw) : 
marci@235
   321
// 	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw) { }
marci@235
   322
//       EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) : 
marci@235
   323
// 	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw, a) { }
marci@235
   324
//     };
marci@235
   325
//   };
marci@235
   326
marci@235
   327
marci@235
   328
  template<typename GraphWrapper>
marci@235
   329
  class RevGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
marci@230
   330
  public:
marci@237
   331
    typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
marci@237
   332
    typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
marci@235
   333
    typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt InEdgeIt;
marci@235
   334
    typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt OutEdgeIt;
marci@237
   335
marci@238
   336
    RevGraphWrapper(GraphWrapper _gw) : 
marci@238
   337
      GraphWrapperSkeleton<GraphWrapper>(_gw) { }  
marci@238
   338
marci@237
   339
    Node head(const Edge& e) const 
marci@237
   340
      { return GraphWrapperSkeleton<GraphWrapper>::tail(e); }
marci@237
   341
    Node tail(const Edge& e) const 
marci@237
   342
      { return GraphWrapperSkeleton<GraphWrapper>::head(e); }
marci@76
   343
  };
marci@76
   344
marci@155
   345
marci@238
   346
//   template<typename GraphWrapper>
marci@236
   347
//   class UndirGraphWrapper {
marci@236
   348
//   protected:
marci@238
   349
//     //Graph* graph;
marci@238
   350
//     GraphWrapper gw;
marci@238
   351
marci@236
   352
//   public:
marci@238
   353
//     typedef GraphWrapper BaseGraph;
marci@236
   354
marci@238
   355
//     typedef typename GraphWrapper::Node Node;
marci@238
   356
//     typedef typename GraphWrapper::NodeIt NodeIt;
marci@236
   357
marci@236
   358
//     //typedef typename Graph::Edge Edge;
marci@236
   359
//     //typedef typename Graph::OutEdgeIt OutEdgeIt;
marci@236
   360
//     //typedef typename Graph::InEdgeIt InEdgeIt;
marci@236
   361
//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@236
   362
//     //typedef typename Graph::EdgeIt EdgeIt;
marci@236
   363
marci@236
   364
//     //private:
marci@238
   365
//     typedef typename GraphWrapper::Edge GraphEdge;
marci@238
   366
//     typedef typename GraphWrapper::OutEdgeIt GraphOutEdgeIt;
marci@238
   367
//     typedef typename GraphWrapper::InEdgeIt GraphInEdgeIt;
marci@236
   368
//     //public:
marci@236
   369
marci@236
   370
//     //UndirGraphWrapper() : graph(0) { }
marci@238
   371
//     UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
marci@236
   372
marci@238
   373
//     //void setGraph(Graph& _graph) { graph = &_graph; }
marci@238
   374
//     //Graph& getGraph() const { return (*graph); }
marci@236
   375
  
marci@236
   376
//     class Edge {
marci@238
   377
//       friend class UndirGraphWrapper<GraphWrapper>;
marci@236
   378
//       bool out_or_in; //true iff out
marci@236
   379
//       GraphOutEdgeIt out;
marci@236
   380
//       GraphInEdgeIt in;
marci@236
   381
//     public:
marci@236
   382
//       Edge() : out_or_in(), out(), in() { }
marci@236
   383
//       Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
marci@236
   384
//       operator GraphEdge() const {
marci@236
   385
// 	if (out_or_in) return(out); else return(in);
marci@236
   386
//       }
marci@236
   387
//       friend bool operator==(const Edge& u, const Edge& v) { 
marci@236
   388
// 	if (v.out_or_in) 
marci@236
   389
// 	  return (u.out_or_in && u.out==v.out);
marci@236
   390
// 	else
marci@236
   391
// 	  return (!u.out_or_in && u.in==v.in);
marci@236
   392
//       } 
marci@236
   393
//       friend bool operator!=(const Edge& u, const Edge& v) { 
marci@236
   394
// 	if (v.out_or_in) 
marci@236
   395
// 	  return (!u.out_or_in || u.out!=v.out);
marci@236
   396
// 	else
marci@236
   397
// 	  return (u.out_or_in || u.in!=v.in);
marci@236
   398
//       } 
marci@236
   399
//     };
marci@236
   400
marci@236
   401
//     class OutEdgeIt : public Edge {
marci@238
   402
//       friend class UndirGraphWrapper<GraphWrapper>;
marci@236
   403
//     public:
marci@236
   404
//       OutEdgeIt() : Edge() { }
marci@236
   405
//       OutEdgeIt(const Invalid& i) : Edge(i) { }
marci@238
   406
//       OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n) 
marci@238
   407
// 	: Edge() { 
marci@236
   408
// 	out_or_in=true;
marci@238
   409
// 	_G.gw.first(out, n);
marci@238
   410
// 	if (!(_G.gw.valid(out))) {
marci@236
   411
// 	  out_or_in=false;
marci@238
   412
// 	  _G.gw.first(in, n);
marci@236
   413
// 	}
marci@236
   414
//       }
marci@236
   415
//     };
marci@236
   416
marci@236
   417
//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
marci@236
   418
//       e.out_or_in=true;
marci@238
   419
//       gw.first(e.out, n);
marci@238
   420
//       if (!(gw.valid(e.out))) {
marci@236
   421
// 	e.out_or_in=false;
marci@238
   422
// 	gw.first(e.in, n);
marci@236
   423
//       }
marci@236
   424
//       return e;
marci@236
   425
//     }
marci@236
   426
marci@236
   427
//     OutEdgeIt& next(OutEdgeIt& e) const {
marci@236
   428
//       if (e.out_or_in) {
marci@238
   429
// 	Node n=gw.tail(e.out);
marci@238
   430
// 	gw.next(e.out);
marci@238
   431
// 	if (!gw.valid(e.out)) {
marci@236
   432
// 	  e.out_or_in=false;
marci@238
   433
// 	  gw.first(e.in, n);
marci@236
   434
// 	}
marci@236
   435
//       } else {
marci@238
   436
// 	gw.next(e.in);
marci@236
   437
//       }
marci@236
   438
//       return e;
marci@236
   439
//     }
marci@236
   440
marci@236
   441
//     Node aNode(const OutEdgeIt& e) const { 
marci@238
   442
//       if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
marci@236
   443
//     Node bNode(const OutEdgeIt& e) const { 
marci@238
   444
//       if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
marci@236
   445
marci@236
   446
//     typedef OutEdgeIt InEdgeIt; 
marci@236
   447
marci@238
   448
//     template<typename I> I& first(I& i) const { return gw.first(i); }
marci@236
   449
// //     template<typename I, typename P> I& first(I& i, const P& p) const { 
marci@236
   450
// //       return graph->first(i, p); }
marci@236
   451
    
marci@236
   452
//     template<typename I> I getNext(const I& i) const { 
marci@238
   453
//       return gw.getNext(i); }
marci@238
   454
//     template<typename I> I& next(I &i) const { return gw.next(i); }    
marci@236
   455
marci@236
   456
//     template< typename It > It first() const { 
marci@236
   457
//       It e; first(e); return e; }
marci@236
   458
marci@236
   459
//     template< typename It > It first(const Node& v) const { 
marci@236
   460
//       It e; first(e, v); return e; }
marci@236
   461
marci@238
   462
//     Node head(const Edge& e) const { return gw.head(e); }
marci@238
   463
//     Node tail(const Edge& e) const { return gw.tail(e); }
marci@236
   464
marci@236
   465
//     template<typename I> bool valid(const I& i) const 
marci@238
   466
//       { return gw.valid(i); }
marci@236
   467
  
marci@236
   468
//     //template<typename I> void setInvalid(const I &i);
marci@236
   469
//     //{ return graph->setInvalid(i); }
marci@236
   470
marci@238
   471
//     int nodeNum() const { return gw.nodeNum(); }
marci@238
   472
//     int edgeNum() const { return gw.edgeNum(); }
marci@236
   473
  
marci@236
   474
// //     template<typename I> Node aNode(const I& e) const { 
marci@236
   475
// //       return graph->aNode(e); }
marci@236
   476
// //     template<typename I> Node bNode(const I& e) const { 
marci@236
   477
// //       return graph->bNode(e); }
marci@236
   478
  
marci@238
   479
//     Node addNode() const { return gw.addNode(); }
marci@236
   480
// // FIXME: ez igy nem jo, mert nem
marci@236
   481
// //    Edge addEdge(const Node& tail, const Node& head) const { 
marci@236
   482
// //      return graph->addEdge(tail, head); }
marci@236
   483
  
marci@238
   484
//     template<typename I> void erase(const I& i) const { gw.erase(i); }
marci@236
   485
  
marci@238
   486
//     void clear() const { gw.clear(); }
marci@236
   487
    
marci@238
   488
//     template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 
marci@236
   489
//     public:
marci@238
   490
//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 
marci@238
   491
// 	GraphWrapper::NodeMap<T>(_G.gw) { }
marci@238
   492
//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 
marci@238
   493
// 	GraphWrapper::NodeMap<T>(_G.gw, a) { }
marci@236
   494
//     };
marci@236
   495
marci@238
   496
//     template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> { 
marci@236
   497
//     public:
marci@238
   498
//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 
marci@238
   499
// 	GraphWrapper::EdgeMap<T>(_G.gw) { }
marci@238
   500
//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 
marci@238
   501
// 	GraphWrapper::EdgeMap<T>(_G.gw, a) { }
marci@236
   502
//     };
marci@236
   503
//   };
marci@236
   504
marci@236
   505
marci@236
   506
  template<typename GraphWrapper>
marci@238
   507
  class UndirGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
marci@199
   508
  protected:
marci@238
   509
//    GraphWrapper gw;
marci@236
   510
marci@158
   511
  public:
marci@238
   512
    //typedef GraphWrapper BaseGraph;
marci@158
   513
marci@238
   514
    typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
marci@238
   515
    typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
marci@158
   516
marci@158
   517
    //private:
marci@238
   518
    typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge GraphEdge;
marci@238
   519
    typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt GraphOutEdgeIt;
marci@238
   520
    typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt GraphInEdgeIt;
marci@158
   521
    //public:
marci@158
   522
marci@168
   523
    //UndirGraphWrapper() : graph(0) { }
marci@238
   524
    UndirGraphWrapper(GraphWrapper _gw) : 
marci@238
   525
      GraphWrapperSkeleton<GraphWrapper>(_gw) { }  
marci@238
   526
marci@238
   527
    //UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
marci@168
   528
marci@236
   529
    //void setGraph(Graph& _graph) { graph = &_graph; }
marci@236
   530
    //Graph& getGraph() const { return (*graph); }
marci@168
   531
  
marci@174
   532
    class Edge {
marci@236
   533
      friend class UndirGraphWrapper<GraphWrapper>;
marci@158
   534
      bool out_or_in; //true iff out
marci@158
   535
      GraphOutEdgeIt out;
marci@158
   536
      GraphInEdgeIt in;
marci@158
   537
    public:
marci@174
   538
      Edge() : out_or_in(), out(), in() { }
marci@174
   539
      Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
marci@174
   540
      operator GraphEdge() const {
marci@158
   541
	if (out_or_in) return(out); else return(in);
marci@158
   542
      }
marci@239
   543
//FIXME
marci@239
   544
//2 edges are equal if they "refer" to the same physical edge 
marci@239
   545
//is it good?
marci@174
   546
      friend bool operator==(const Edge& u, const Edge& v) { 
marci@174
   547
	if (v.out_or_in) 
marci@239
   548
	  if (u.out_or_in) return (u.out==v.out); else return (u.out==v.in);
marci@239
   549
	//return (u.out_or_in && u.out==v.out);
marci@174
   550
	else
marci@239
   551
	  if (u.out_or_in) return (u.out==v.in); else return (u.in==v.in);
marci@239
   552
	//return (!u.out_or_in && u.in==v.in);
marci@174
   553
      } 
marci@174
   554
      friend bool operator!=(const Edge& u, const Edge& v) { 
marci@174
   555
	if (v.out_or_in) 
marci@239
   556
	  if (u.out_or_in) return (u.out!=v.out); else return (u.out!=v.in);
marci@239
   557
	//return (!u.out_or_in || u.out!=v.out);
marci@174
   558
	else
marci@239
   559
	  if (u.out_or_in) return (u.out!=v.in); else return (u.in!=v.in);
marci@239
   560
	//return (u.out_or_in || u.in!=v.in);
marci@174
   561
      } 
marci@158
   562
    };
marci@158
   563
marci@174
   564
    class OutEdgeIt : public Edge {
marci@236
   565
      friend class UndirGraphWrapper<GraphWrapper>;
marci@158
   566
    public:
marci@174
   567
      OutEdgeIt() : Edge() { }
marci@174
   568
      OutEdgeIt(const Invalid& i) : Edge(i) { }
marci@236
   569
      OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n) 
marci@236
   570
	: Edge() { 
marci@239
   571
	out_or_in=true; _G.gw.first(out, n);
marci@239
   572
	if (!(_G.gw.valid(out))) { out_or_in=false; _G.gw.first(in, n);	}
marci@158
   573
      }
marci@158
   574
    };
marci@158
   575
marci@238
   576
    typedef OutEdgeIt InEdgeIt; 
marci@238
   577
marci@238
   578
    class EdgeIt : public Edge {
marci@238
   579
      friend class UndirGraphWrapper<GraphWrapper>;
marci@238
   580
    protected:
marci@238
   581
      NodeIt v;
marci@238
   582
    public:
marci@238
   583
      EdgeIt() : Edge() { }
marci@238
   584
      EdgeIt(const Invalid& i) : Edge(i) { }
marci@238
   585
      EdgeIt(const UndirGraphWrapper<GraphWrapper>& _G) 
marci@238
   586
	: Edge() { 
marci@238
   587
	out_or_in=true;
marci@238
   588
	//Node v;
marci@238
   589
	_G.first(v);
marci@238
   590
	if (_G.valid(v)) _G.gw.first(out); else out=INVALID;
marci@238
   591
	while (_G.valid(v) && !_G.gw.valid(out)) { 
marci@238
   592
	  _G.gw.next(v); 
marci@238
   593
	  if (_G.valid(v)) _G.gw.first(out); 
marci@238
   594
	}
marci@238
   595
      }
marci@238
   596
    };
marci@238
   597
marci@212
   598
    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
marci@239
   599
      e.out_or_in=true; gw.first(e.out, n);
marci@239
   600
      if (!(gw.valid(e.out))) { e.out_or_in=false; gw.first(e.in, n); }
marci@158
   601
      return e;
marci@158
   602
    }
marci@158
   603
marci@238
   604
    EdgeIt& first(EdgeIt& e) const {
marci@238
   605
      e.out_or_in=true;
marci@238
   606
      //NodeIt v;
marci@238
   607
      first(e.v);
marci@238
   608
      if (valid(e.v)) gw.first(e.out, e.v); else e.out=INVALID;
marci@238
   609
      while (valid(e.v) && !gw.valid(e.out)) { 
marci@238
   610
	gw.next(e.v); 
marci@238
   611
	if (valid(e.v)) gw.first(e.out, e.v); 
marci@238
   612
      }
marci@238
   613
      return e;
marci@238
   614
    }
marci@238
   615
marci@238
   616
    template<typename I> I& first(I& i) const { return gw.first(i); }
marci@238
   617
    template<typename I, typename P> I& first(I& i, const P& p) const { 
marci@238
   618
      return graph->first(i, p); }
marci@238
   619
marci@158
   620
    OutEdgeIt& next(OutEdgeIt& e) const {
marci@158
   621
      if (e.out_or_in) {
marci@236
   622
	Node n=gw.tail(e.out);
marci@236
   623
	gw.next(e.out);
marci@239
   624
	if (!gw.valid(e.out)) { e.out_or_in=false; gw.first(e.in, n); }
marci@158
   625
      } else {
marci@236
   626
	gw.next(e.in);
marci@158
   627
      }
marci@158
   628
      return e;
marci@158
   629
    }
marci@158
   630
marci@238
   631
    EdgeIt& next(EdgeIt& e) const {
marci@238
   632
      //NodeIt v=tail(e);
marci@238
   633
      gw.next(e.out);
marci@238
   634
      while (valid(e.v) && !gw.valid(e.out)) { 
marci@238
   635
	next(e.v); 
marci@238
   636
	if (valid(e.v)) gw.first(e.out, e.v); 
marci@238
   637
      }
marci@238
   638
      return e;
marci@238
   639
    }
marci@158
   640
marci@238
   641
    template<typename I> I& next(I &i) const { return gw.next(i); }    
marci@239
   642
    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
marci@158
   643
marci@158
   644
    template< typename It > It first() const { 
marci@212
   645
      It e; first(e); return e; }
marci@158
   646
marci@174
   647
    template< typename It > It first(const Node& v) const { 
marci@212
   648
      It e; first(e, v); return e; }
marci@158
   649
marci@238
   650
//    Node head(const Edge& e) const { return gw.head(e); }
marci@238
   651
//    Node tail(const Edge& e) const { return gw.tail(e); }
marci@158
   652
marci@238
   653
//    template<typename I> bool valid(const I& i) const 
marci@238
   654
//      { return gw.valid(i); }
marci@158
   655
  
marci@238
   656
//    int nodeNum() const { return gw.nodeNum(); }
marci@238
   657
//    int edgeNum() const { return gw.edgeNum(); }
marci@158
   658
  
marci@174
   659
//     template<typename I> Node aNode(const I& e) const { 
marci@158
   660
//       return graph->aNode(e); }
marci@174
   661
//     template<typename I> Node bNode(const I& e) const { 
marci@158
   662
//       return graph->bNode(e); }
marci@238
   663
marci@238
   664
    Node aNode(const OutEdgeIt& e) const { 
marci@238
   665
      if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
marci@238
   666
    Node bNode(const OutEdgeIt& e) const { 
marci@238
   667
      if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
marci@158
   668
  
marci@238
   669
//    Node addNode() const { return gw.addNode(); }
marci@238
   670
marci@231
   671
// FIXME: ez igy nem jo, mert nem
marci@231
   672
//    Edge addEdge(const Node& tail, const Node& head) const { 
marci@231
   673
//      return graph->addEdge(tail, head); }
marci@158
   674
  
marci@238
   675
//    template<typename I> void erase(const I& i) const { gw.erase(i); }
marci@158
   676
  
marci@238
   677
//    void clear() const { gw.clear(); }
marci@158
   678
    
marci@238
   679
//     template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 
marci@238
   680
//     public:
marci@238
   681
//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 
marci@238
   682
// 	GraphWrapper::NodeMap<T>(_G.gw) { }
marci@238
   683
//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 
marci@238
   684
// 	GraphWrapper::NodeMap<T>(_G.gw, a) { }
marci@238
   685
//     };
marci@168
   686
marci@238
   687
//     template<typename T> class EdgeMap : 
marci@238
   688
//       public GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T> { 
marci@238
   689
//     public:
marci@238
   690
//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 
marci@238
   691
// 	GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T>(_G.gw) { }
marci@238
   692
//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 
marci@238
   693
// 	GraphWrapper::EdgeMap<T>(_G.gw, a) { }
marci@238
   694
//     };
marci@238
   695
   };
marci@158
   696
marci@158
   697
marci@158
   698
marci@236
   699
marci@236
   700
marci@155
   701
//   template<typename Graph>
marci@155
   702
//   class SymGraphWrapper
marci@155
   703
//   {
marci@155
   704
//     Graph* graph;
marci@76
   705
  
marci@155
   706
//   public:
marci@155
   707
//     typedef Graph BaseGraph;
marci@155
   708
marci@174
   709
//     typedef typename Graph::Node Node;
marci@174
   710
//     typedef typename Graph::Edge Edge;
marci@174
   711
  
marci@155
   712
//     typedef typename Graph::NodeIt NodeIt;
marci@155
   713
    
marci@155
   714
//     //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
marci@155
   715
//     //iranyitatlant, ami van
marci@155
   716
//     //mert csak 1 dolgot lehet be typedef-elni
marci@155
   717
//     typedef typename Graph::OutEdgeIt SymEdgeIt;
marci@155
   718
//     //typedef typename Graph::InEdgeIt SymEdgeIt;
marci@155
   719
//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@174
   720
//     typedef typename Graph::EdgeIt EdgeIt;
marci@155
   721
marci@155
   722
//     int nodeNum() const { return graph->nodeNum(); }
marci@155
   723
//     int edgeNum() const { return graph->edgeNum(); }
marci@155
   724
    
marci@212
   725
//     template<typename I> I& first(I& i) const { return graph->first(i); }
marci@212
   726
//     template<typename I, typename P> I& first(I& i, const P& p) const { 
marci@212
   727
//       return graph->first(i, p); }
marci@155
   728
//     //template<typename I> I next(const I i); { return graph->goNext(i); }
marci@155
   729
//     //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
marci@155
   730
marci@155
   731
//     template< typename It > It first() const { 
marci@212
   732
//       It e; first(e); return e; }
marci@155
   733
marci@174
   734
//     template< typename It > It first(Node v) const { 
marci@212
   735
//       It e; first(e, v); return e; }
marci@155
   736
marci@174
   737
//     Node head(const Edge& e) const { return graph->head(e); }
marci@174
   738
//     Node tail(const Edge& e) const { return graph->tail(e); }
marci@155
   739
  
marci@174
   740
//     template<typename I> Node aNode(const I& e) const { 
marci@155
   741
//       return graph->aNode(e); }
marci@174
   742
//     template<typename I> Node bNode(const I& e) const { 
marci@155
   743
//       return graph->bNode(e); }
marci@155
   744
  
marci@155
   745
//     //template<typename I> bool valid(const I i);
marci@155
   746
//     //{ return graph->valid(i); }
marci@155
   747
  
marci@155
   748
//     //template<typename I> void setInvalid(const I &i);
marci@155
   749
//     //{ return graph->setInvalid(i); }
marci@155
   750
  
marci@174
   751
//     Node addNode() { return graph->addNode(); }
marci@174
   752
//     Edge addEdge(const Node& tail, const Node& head) { 
marci@155
   753
//       return graph->addEdge(tail, head); }
marci@155
   754
  
marci@155
   755
//     template<typename I> void erase(const I& i) { graph->erase(i); }
marci@155
   756
  
marci@155
   757
//     void clear() { graph->clear(); }
marci@155
   758
  
marci@155
   759
//     template<typename T> class NodeMap : public Graph::NodeMap<T> { };
marci@155
   760
//     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
marci@155
   761
  
marci@155
   762
//     void setGraph(Graph& _graph) { graph = &_graph; }
marci@155
   763
//     Graph& getGraph() { return (*graph); }
marci@155
   764
marci@155
   765
//     //SymGraphWrapper() : graph(0) { }
marci@155
   766
//     SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@155
   767
//   };
marci@155
   768
marci@155
   769
marci@155
   770
  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
marci@155
   771
  class ResGraphWrapper {
marci@76
   772
  public:
marci@76
   773
    typedef Graph BaseGraph;
marci@174
   774
    typedef typename Graph::Node Node;
marci@155
   775
    typedef typename Graph::NodeIt NodeIt;
marci@155
   776
  private:
marci@155
   777
    typedef typename Graph::OutEdgeIt OldOutEdgeIt;
marci@155
   778
    typedef typename Graph::InEdgeIt OldInEdgeIt;
marci@199
   779
  protected:
marci@174
   780
    const Graph* graph;
marci@155
   781
    FlowMap* flow;
marci@155
   782
    const CapacityMap* capacity;
marci@155
   783
  public:
marci@168
   784
marci@155
   785
    ResGraphWrapper(const Graph& _G, FlowMap& _flow, 
marci@155
   786
	     const CapacityMap& _capacity) : 
marci@174
   787
      graph(&_G), flow(&_flow), capacity(&_capacity) { }
marci@168
   788
marci@168
   789
    void setGraph(const Graph& _graph) { graph = &_graph; }
marci@174
   790
    const Graph& getGraph() const { return (*graph); }
marci@168
   791
marci@174
   792
    class Edge; 
marci@155
   793
    class OutEdgeIt; 
marci@174
   794
    friend class Edge; 
marci@155
   795
    friend class OutEdgeIt; 
marci@76
   796
marci@174
   797
    class Edge {
marci@155
   798
      friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
marci@155
   799
    protected:
marci@168
   800
      bool out_or_in; //true, iff out
marci@155
   801
      OldOutEdgeIt out;
marci@155
   802
      OldInEdgeIt in;
marci@155
   803
    public:
marci@174
   804
      Edge() : out_or_in(true) { } 
marci@174
   805
      Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
marci@168
   806
//       bool valid() const { 
marci@168
   807
// 	return out_or_in && out.valid() || in.valid(); }
marci@174
   808
      friend bool operator==(const Edge& u, const Edge& v) { 
marci@174
   809
	if (v.out_or_in) 
marci@174
   810
	  return (u.out_or_in && u.out==v.out);
marci@174
   811
	else
marci@174
   812
	  return (!u.out_or_in && u.in==v.in);
marci@174
   813
      } 
marci@174
   814
      friend bool operator!=(const Edge& u, const Edge& v) { 
marci@174
   815
	if (v.out_or_in) 
marci@174
   816
	  return (!u.out_or_in || u.out!=v.out);
marci@174
   817
	else
marci@174
   818
	  return (u.out_or_in || u.in!=v.in);
marci@174
   819
      } 
marci@155
   820
    };
marci@155
   821
marci@155
   822
marci@174
   823
    class OutEdgeIt : public Edge {
marci@155
   824
      friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
marci@155
   825
    public:
marci@155
   826
      OutEdgeIt() { }
marci@168
   827
      //FIXME
marci@174
   828
      OutEdgeIt(const Edge& e) : Edge(e) { }
marci@174
   829
      OutEdgeIt(const Invalid& i) : Edge(i) { }
marci@155
   830
    private:
marci@174
   831
      OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() { 
marci@212
   832
	resG.graph->first(out, v);
marci@174
   833
	while( resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
marci@174
   834
	if (!resG.graph->valid(out)) {
marci@155
   835
	  out_or_in=0;
marci@212
   836
	  resG.graph->first(in, v);
marci@174
   837
	  while( resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
marci@155
   838
	}
marci@155
   839
      }
marci@168
   840
//     public:
marci@168
   841
//       OutEdgeIt& operator++() { 
marci@168
   842
// 	if (out_or_in) {
marci@174
   843
// 	  Node v=/*resG->*/G->aNode(out);
marci@168
   844
// 	  ++out;
marci@174
   845
// 	  while( out.valid() && !(Edge::free()>0) ) { ++out; }
marci@168
   846
// 	  if (!out.valid()) {
marci@168
   847
// 	    out_or_in=0;
marci@212
   848
// 	    G->first(in, v); 
marci@174
   849
// 	    while( in.valid() && !(Edge::free()>0) ) { ++in; }
marci@168
   850
// 	  }
marci@168
   851
// 	} else {
marci@168
   852
// 	  ++in;
marci@174
   853
// 	  while( in.valid() && !(Edge::free()>0) ) { ++in; } 
marci@168
   854
// 	}
marci@168
   855
// 	return *this; 
marci@168
   856
//       }
marci@155
   857
    };
marci@155
   858
marci@174
   859
    class EdgeIt : public Edge {
marci@155
   860
      friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
marci@174
   861
      typename Graph::NodeIt v;
marci@155
   862
    public:
marci@174
   863
      EdgeIt() { }
marci@174
   864
      //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }
marci@174
   865
      EdgeIt(const Invalid& i) : Edge(i) { }
marci@174
   866
      EdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG) : Edge() { 
marci@212
   867
	resG.graph->first(v);
marci@212
   868
	if (resG.graph->valid(v)) resG.graph->first(out, v); else out=OldOutEdgeIt(INVALID);
marci@174
   869
	while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
marci@174
   870
	while (resG.graph->valid(v) && !resG.graph->valid(out)) { 
marci@174
   871
	  resG.graph->next(v); 
marci@212
   872
	  if (resG.graph->valid(v)) resG.graph->first(out, v); 
marci@174
   873
	  while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
marci@155
   874
	}
marci@174
   875
	if (!resG.graph->valid(out)) {
marci@155
   876
	  out_or_in=0;
marci@212
   877
	  resG.graph->first(v);
marci@212
   878
	  if (resG.graph->valid(v)) resG.graph->first(in, v); else in=OldInEdgeIt(INVALID);
marci@174
   879
	  while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
marci@174
   880
	  while (resG.graph->valid(v) && !resG.graph->valid(in)) { 
marci@174
   881
	    resG.graph->next(v); 
marci@212
   882
	    if (resG.graph->valid(v)) resG.graph->first(in, v); 
marci@174
   883
	    while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
marci@155
   884
	  }
marci@155
   885
	}
marci@155
   886
      }
marci@174
   887
//       EdgeIt& operator++() { 
marci@168
   888
// 	if (out_or_in) {
marci@168
   889
// 	  ++out;
marci@174
   890
// 	  while (out.valid() && !(Edge::free()>0) ) { ++out; }
marci@168
   891
// 	  while (v.valid() && !out.valid()) { 
marci@168
   892
// 	    ++v; 
marci@212
   893
// 	    if (v.valid()) G->first(out, v); 
marci@174
   894
// 	    while (out.valid() && !(Edge::free()>0) ) { ++out; }
marci@168
   895
// 	  }
marci@168
   896
// 	  if (!out.valid()) {
marci@168
   897
// 	    out_or_in=0;
marci@212
   898
// 	    G->first(v);
marci@212
   899
// 	    if (v.valid()) G->first(in, v); else in=OldInEdgeIt();
marci@174
   900
// 	    while (in.valid() && !(Edge::free()>0) ) { ++in; }
marci@168
   901
// 	    while (v.valid() && !in.valid()) { 
marci@168
   902
// 	      ++v; 
marci@212
   903
// 	      if (v.valid()) G->first(in, v); 
marci@174
   904
// 	      while (in.valid() && !(Edge::free()>0) ) { ++in; }
marci@168
   905
// 	    }  
marci@168
   906
// 	  }
marci@168
   907
// 	} else {
marci@168
   908
// 	  ++in;
marci@174
   909
// 	  while (in.valid() && !(Edge::free()>0) ) { ++in; }
marci@168
   910
// 	  while (v.valid() && !in.valid()) { 
marci@168
   911
// 	    ++v; 
marci@212
   912
// 	    if (v.valid()) G->first(in, v); 
marci@174
   913
// 	    while (in.valid() && !(Edge::free()>0) ) { ++in; }
marci@168
   914
// 	  }
marci@168
   915
// 	}
marci@168
   916
// 	return *this;
marci@168
   917
//       }
marci@155
   918
    };
marci@155
   919
marci@212
   920
    NodeIt& first(NodeIt& v) const { return graph->first(v); }
marci@212
   921
    OutEdgeIt& first(OutEdgeIt& e, Node v) const { 
marci@168
   922
      e=OutEdgeIt(*this, v); 
marci@174
   923
      return e;
marci@155
   924
    }
marci@212
   925
    EdgeIt& first(EdgeIt& e) const { 
marci@174
   926
      e=EdgeIt(*this); 
marci@174
   927
      return e;
marci@155
   928
    }
marci@155
   929
   
marci@174
   930
    NodeIt& next(NodeIt& n) const { return graph->next(n); }
marci@155
   931
marci@155
   932
    OutEdgeIt& next(OutEdgeIt& e) const { 
marci@155
   933
      if (e.out_or_in) {
marci@174
   934
	Node v=graph->aNode(e.out);
marci@174
   935
	graph->next(e.out);
marci@174
   936
	while( graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
marci@174
   937
	if (!graph->valid(e.out)) {
marci@155
   938
	  e.out_or_in=0;
marci@212
   939
	  graph->first(e.in, v); 
marci@174
   940
	  while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
marci@155
   941
	}
marci@155
   942
      } else {
marci@174
   943
	graph->next(e.in);
marci@174
   944
	while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } 
marci@155
   945
      }
marci@155
   946
      return e;
marci@155
   947
    }
marci@155
   948
marci@174
   949
    EdgeIt& next(EdgeIt& e) const { 
marci@155
   950
      if (e.out_or_in) {
marci@174
   951
	graph->next(e.out);
marci@174
   952
	while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
marci@174
   953
	  while (graph->valid(e.v) && !graph->valid(e.out)) { 
marci@174
   954
	    graph->next(e.v); 
marci@212
   955
	    if (graph->valid(e.v)) graph->first(e.out, e.v); 
marci@174
   956
	    while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
marci@155
   957
	  }
marci@174
   958
	  if (!graph->valid(e.out)) {
marci@155
   959
	    e.out_or_in=0;
marci@212
   960
	    graph->first(e.v);
marci@212
   961
	    if (graph->valid(e.v)) graph->first(e.in, e.v); else e.in=OldInEdgeIt(INVALID);
marci@174
   962
	    while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
marci@174
   963
	    while (graph->valid(e.v) && !graph->valid(e.in)) { 
marci@174
   964
	      graph->next(e.v); 
marci@212
   965
	      if (graph->valid(e.v)) graph->first(e.in, e.v); 
marci@174
   966
	      while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
marci@155
   967
	    }  
marci@155
   968
	  }
marci@155
   969
	} else {
marci@174
   970
	  graph->next(e.in);
marci@174
   971
	  while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
marci@174
   972
	  while (graph->valid(e.v) && !graph->valid(e.in)) { 
marci@174
   973
	    graph->next(e.v); 
marci@212
   974
	    if (graph->valid(e.v)) graph->first(e.in, e.v); 
marci@174
   975
	    while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
marci@155
   976
	  }
marci@155
   977
	}
marci@155
   978
	return e;
marci@155
   979
      }
marci@76
   980
    
marci@76
   981
marci@155
   982
    template< typename It >
marci@155
   983
    It first() const { 
marci@155
   984
      It e;
marci@212
   985
      first(e);
marci@155
   986
      return e; 
marci@155
   987
    }
marci@76
   988
marci@155
   989
    template< typename It >
marci@174
   990
    It first(Node v) const { 
marci@155
   991
      It e;
marci@212
   992
      first(e, v);
marci@155
   993
      return e; 
marci@155
   994
    }
marci@76
   995
marci@174
   996
    Node tail(Edge e) const { 
marci@174
   997
      return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
marci@174
   998
    Node head(Edge e) const { 
marci@174
   999
      return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); }
marci@76
  1000
marci@174
  1001
    Node aNode(OutEdgeIt e) const { 
marci@174
  1002
      return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
marci@174
  1003
    Node bNode(OutEdgeIt e) const { 
marci@174
  1004
      return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); }
marci@76
  1005
marci@174
  1006
    int id(Node v) const { return graph->id(v); }
marci@155
  1007
marci@174
  1008
    bool valid(Node n) const { return graph->valid(n); }
marci@174
  1009
    bool valid(Edge e) const { 
marci@174
  1010
      return e.out_or_in ? graph->valid(e.out) : graph->valid(e.in); }
marci@155
  1011
marci@174
  1012
    void augment(const Edge& e, Number a) const {
marci@168
  1013
      if (e.out_or_in)  
marci@168
  1014
	flow->set(e.out, flow->get(e.out)+a);
marci@168
  1015
      else  
marci@168
  1016
	flow->set(e.in, flow->get(e.in)-a);
marci@168
  1017
    }
marci@168
  1018
marci@174
  1019
    Number free(const Edge& e) const { 
marci@168
  1020
      if (e.out_or_in) 
marci@168
  1021
	return (capacity->get(e.out)-flow->get(e.out)); 
marci@168
  1022
      else 
marci@168
  1023
	return (flow->get(e.in)); 
marci@168
  1024
    }
marci@168
  1025
marci@168
  1026
    Number free(OldOutEdgeIt out) const { 
marci@168
  1027
      return (capacity->get(out)-flow->get(out)); 
marci@168
  1028
    }
marci@168
  1029
    
marci@168
  1030
    Number free(OldInEdgeIt in) const { 
marci@168
  1031
      return (flow->get(in)); 
marci@168
  1032
    }
marci@168
  1033
marci@155
  1034
    template<typename T> class NodeMap : public Graph::NodeMap<T> { 
marci@155
  1035
    public:
marci@155
  1036
      NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) 
marci@158
  1037
	: Graph::NodeMap<T>(_G.getGraph()) { }
marci@155
  1038
      NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, 
marci@158
  1039
	      T a) : Graph::NodeMap<T>(_G.getGraph(), a) { }
marci@155
  1040
    };
marci@155
  1041
marci@155
  1042
//     template <typename T>
marci@155
  1043
//     class NodeMap {
marci@155
  1044
//       typename Graph::NodeMap<T> node_map; 
marci@155
  1045
//     public:
marci@174
  1046
//       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.graph)) { }
marci@174
  1047
//       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.graph), a) { }
marci@174
  1048
//       void set(Node nit, T a) { node_map.set(nit, a); }
marci@174
  1049
//       T get(Node nit) const { return node_map.get(nit); }
marci@155
  1050
//     };
marci@155
  1051
marci@155
  1052
    template <typename T>
marci@155
  1053
    class EdgeMap {
marci@155
  1054
      typename Graph::EdgeMap<T> forward_map, backward_map; 
marci@155
  1055
    public:
marci@158
  1056
      EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.getGraph()), backward_map(_G.getGraph()) { }
marci@158
  1057
      EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.getGraph(), a), backward_map(_G.getGraph(), a) { }
marci@174
  1058
      void set(Edge e, T a) { 
marci@155
  1059
	if (e.out_or_in) 
marci@155
  1060
	  forward_map.set(e.out, a); 
marci@155
  1061
	else 
marci@155
  1062
	  backward_map.set(e.in, a); 
marci@155
  1063
      }
marci@174
  1064
      T get(Edge e) { 
marci@155
  1065
	if (e.out_or_in) 
marci@155
  1066
	  return forward_map.get(e.out); 
marci@155
  1067
	else 
marci@155
  1068
	  return backward_map.get(e.in); 
marci@155
  1069
      }
marci@155
  1070
    };
marci@168
  1071
  };
marci@168
  1072
marci@168
  1073
  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
marci@168
  1074
  class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
marci@168
  1075
  protected:
marci@168
  1076
    ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
marci@168
  1077
    //ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
marci@168
  1078
  public:
marci@168
  1079
    ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow, 
marci@168
  1080
			   const CapacityMap& _capacity) : 
marci@168
  1081
      ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), 
marci@168
  1082
      first_out_edges(*this) /*, dist(*this)*/ { 
marci@174
  1083
      for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) {
marci@168
  1084
	OutEdgeIt e;
marci@212
  1085
	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
marci@168
  1086
	first_out_edges.set(n, e);
marci@168
  1087
      }
marci@168
  1088
    }
marci@168
  1089
marci@168
  1090
    //void setGraph(Graph& _graph) { graph = &_graph; }
marci@168
  1091
    //Graph& getGraph() const { return (*graph); }
marci@168
  1092
  
marci@168
  1093
    //TrivGraphWrapper() : graph(0) { }
marci@168
  1094
    //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@168
  1095
marci@168
  1096
    //typedef Graph BaseGraph;
marci@168
  1097
marci@174
  1098
    //typedef typename Graph::Node Node;
marci@168
  1099
    //typedef typename Graph::NodeIt NodeIt;
marci@168
  1100
marci@174
  1101
    //typedef typename Graph::Edge Edge;
marci@168
  1102
    //typedef typename Graph::OutEdgeIt OutEdgeIt;
marci@168
  1103
    //typedef typename Graph::InEdgeIt InEdgeIt;
marci@168
  1104
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@174
  1105
    //typedef typename Graph::EdgeIt EdgeIt;
marci@168
  1106
marci@174
  1107
    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
marci@168
  1108
    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
marci@168
  1109
marci@174
  1110
    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
marci@168
  1111
    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
marci@168
  1112
    //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
marci@168
  1113
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@174
  1114
    //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
marci@168
  1115
marci@212
  1116
    NodeIt& first(NodeIt& n) const { 
marci@212
  1117
      return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
marci@168
  1118
    }
marci@168
  1119
marci@212
  1120
    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { 
marci@168
  1121
      e=first_out_edges.get(n);
marci@168
  1122
      return e;
marci@168
  1123
    }
marci@168
  1124
    
marci@212
  1125
    //ROSSZ template<typename I> I& first(I& i) const { return first(i); }
marci@212
  1126
    //ROSSZ template<typename I, typename P> I& first(I& i, const P& p) const { 
marci@212
  1127
    //  return first(i, p); }
marci@168
  1128
    
marci@168
  1129
    //template<typename I> I getNext(const I& i) const { 
marci@168
  1130
    //  return graph->getNext(i); }
marci@168
  1131
    //template<typename I> I& next(I &i) const { return graph->next(i); }    
marci@168
  1132
marci@168
  1133
    template< typename It > It first() const { 
marci@212
  1134
      It e; first(e); return e; }
marci@168
  1135
marci@174
  1136
    template< typename It > It first(const Node& v) const { 
marci@212
  1137
      It e; first(e, v); return e; }
marci@168
  1138
marci@174
  1139
    //Node head(const Edge& e) const { return graph->head(e); }
marci@174
  1140
    //Node tail(const Edge& e) const { return graph->tail(e); }
marci@168
  1141
marci@168
  1142
    //template<typename I> bool valid(const I& i) const 
marci@168
  1143
    //  { return graph->valid(i); }
marci@168
  1144
  
marci@168
  1145
    //int nodeNum() const { return graph->nodeNum(); }
marci@168
  1146
    //int edgeNum() const { return graph->edgeNum(); }
marci@168
  1147
  
marci@174
  1148
    //template<typename I> Node aNode(const I& e) const { 
marci@168
  1149
    //  return graph->aNode(e); }
marci@174
  1150
    //template<typename I> Node bNode(const I& e) const { 
marci@168
  1151
    //  return graph->bNode(e); }
marci@168
  1152
  
marci@174
  1153
    //Node addNode() const { return graph->addNode(); }
marci@174
  1154
    //Edge addEdge(const Node& tail, const Node& head) const { 
marci@168
  1155
    //  return graph->addEdge(tail, head); }
marci@168
  1156
  
marci@168
  1157
    //void erase(const OutEdgeIt& e) {
marci@168
  1158
    //  first_out_edge(this->tail(e))=e;
marci@168
  1159
    //}
marci@174
  1160
    void erase(const Edge& e) {
marci@168
  1161
      OutEdgeIt f(e);
marci@168
  1162
      next(f);
marci@168
  1163
      first_out_edges.set(this->tail(e), f);
marci@168
  1164
    }
marci@168
  1165
    //template<typename I> void erase(const I& i) const { graph->erase(i); }
marci@168
  1166
  
marci@168
  1167
    //void clear() const { graph->clear(); }
marci@168
  1168
    
marci@168
  1169
    template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { 
marci@168
  1170
    public:
marci@168
  1171
      NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : 
marci@168
  1172
	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
marci@168
  1173
      NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : 
marci@168
  1174
	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
marci@168
  1175
    };
marci@168
  1176
marci@168
  1177
    template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { 
marci@168
  1178
    public:
marci@168
  1179
      EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : 
marci@168
  1180
	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
marci@168
  1181
      EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : 
marci@168
  1182
	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
marci@168
  1183
    };
marci@168
  1184
  };
marci@168
  1185
marci@168
  1186
  template<typename GraphWrapper> 
marci@168
  1187
  class FilterGraphWrapper {
marci@168
  1188
  };
marci@168
  1189
marci@168
  1190
  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
marci@168
  1191
  class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
marci@168
  1192
marci@168
  1193
    //Graph* graph;
marci@168
  1194
  
marci@168
  1195
  public:
marci@168
  1196
    //typedef Graph BaseGraph;
marci@168
  1197
marci@174
  1198
    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
marci@168
  1199
    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
marci@168
  1200
marci@174
  1201
    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
marci@168
  1202
    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
marci@168
  1203
    //typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
marci@168
  1204
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@174
  1205
    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
marci@168
  1206
marci@168
  1207
    //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
marci@168
  1208
    
marci@168
  1209
  public:
marci@168
  1210
    FilterGraphWrapper(const Graph& _G, FlowMap& _flow, 
marci@168
  1211
			   const CapacityMap& _capacity) : 
marci@199
  1212
      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, graph->nodeNum()) { 
marci@168
  1213
    }
marci@168
  1214
marci@212
  1215
    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
marci@212
  1216
      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
marci@199
  1217
      while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e)))) 
marci@168
  1218
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
marci@168
  1219
      return e;
marci@168
  1220
    }
marci@168
  1221
marci@174
  1222
    NodeIt& next(NodeIt& e) const {
marci@168
  1223
      return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
marci@168
  1224
    }
marci@168
  1225
marci@168
  1226
    OutEdgeIt& next(OutEdgeIt& e) const {
marci@168
  1227
      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
marci@199
  1228
      while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e)))) 
marci@168
  1229
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
marci@168
  1230
      return e;
marci@168
  1231
    }
marci@168
  1232
marci@212
  1233
    NodeIt& first(NodeIt& n) const {
marci@212
  1234
      return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
marci@168
  1235
    }
marci@168
  1236
marci@174
  1237
    void erase(const Edge& e) {
marci@168
  1238
      OutEdgeIt f(e);
marci@168
  1239
      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
marci@199
  1240
      while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f)))) 
marci@168
  1241
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
marci@168
  1242
      first_out_edges.set(this->tail(e), f);
marci@168
  1243
    }
marci@168
  1244
marci@168
  1245
    //TrivGraphWrapper() : graph(0) { }
marci@168
  1246
    //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@168
  1247
marci@168
  1248
    //void setGraph(Graph& _graph) { graph = &_graph; }
marci@168
  1249
    //Graph& getGraph() const { return (*graph); }
marci@168
  1250
    
marci@212
  1251
    //template<typename I> I& first(I& i) const { return graph->first(i); }
marci@212
  1252
    //template<typename I, typename P> I& first(I& i, const P& p) const { 
marci@212
  1253
    //  return graph->first(i, p); }
marci@168
  1254
    
marci@168
  1255
    //template<typename I> I getNext(const I& i) const { 
marci@168
  1256
    //  return graph->getNext(i); }
marci@168
  1257
    //template<typename I> I& next(I &i) const { return graph->next(i); }    
marci@168
  1258
marci@168
  1259
    template< typename It > It first() const { 
marci@212
  1260
      It e; first(e); return e; }
marci@168
  1261
marci@174
  1262
    template< typename It > It first(const Node& v) const { 
marci@212
  1263
      It e; first(e, v); return e; }
marci@168
  1264
marci@174
  1265
    //Node head(const Edge& e) const { return graph->head(e); }
marci@174
  1266
    //Node tail(const Edge& e) const { return graph->tail(e); }
marci@168
  1267
marci@168
  1268
    //template<typename I> bool valid(const I& i) const 
marci@168
  1269
    //  { return graph->valid(i); }
marci@168
  1270
  
marci@168
  1271
    //template<typename I> void setInvalid(const I &i);
marci@168
  1272
    //{ return graph->setInvalid(i); }
marci@168
  1273
marci@168
  1274
    //int nodeNum() const { return graph->nodeNum(); }
marci@168
  1275
    //int edgeNum() const { return graph->edgeNum(); }
marci@168
  1276
  
marci@174
  1277
    //template<typename I> Node aNode(const I& e) const { 
marci@168
  1278
    //  return graph->aNode(e); }
marci@174
  1279
    //template<typename I> Node bNode(const I& e) const { 
marci@168
  1280
    //  return graph->bNode(e); }
marci@168
  1281
  
marci@174
  1282
    //Node addNode() const { return graph->addNode(); }
marci@174
  1283
    //Edge addEdge(const Node& tail, const Node& head) const { 
marci@168
  1284
    //  return graph->addEdge(tail, head); }
marci@168
  1285
  
marci@168
  1286
    //template<typename I> void erase(const I& i) const { graph->erase(i); }
marci@168
  1287
  
marci@168
  1288
    //void clear() const { graph->clear(); }
marci@168
  1289
    
marci@168
  1290
    template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { 
marci@168
  1291
    public:
marci@168
  1292
      NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) : 
marci@168
  1293
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
marci@168
  1294
      NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) : 
marci@168
  1295
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
marci@168
  1296
    };
marci@168
  1297
marci@168
  1298
    template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { 
marci@168
  1299
    public:
marci@168
  1300
      EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) : 
marci@168
  1301
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
marci@168
  1302
      EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) : 
marci@168
  1303
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
marci@168
  1304
    };
marci@168
  1305
marci@168
  1306
  public:
marci@168
  1307
    ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
marci@155
  1308
marci@76
  1309
  };
marci@76
  1310
marci@76
  1311
marci@148
  1312
marci@148
  1313
// // FIXME: comparison should be made better!!!
marci@148
  1314
//   template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
marci@148
  1315
//   class ResGraphWrapper
marci@148
  1316
//   {
marci@148
  1317
//     Graph* graph;
marci@76
  1318
  
marci@148
  1319
//   public:
marci@148
  1320
//     typedef Graph BaseGraph;
marci@76
  1321
marci@174
  1322
//     typedef typename Graph::Node Node;
marci@174
  1323
//     typedef typename Graph::Edge Edge;
marci@174
  1324
  
marci@148
  1325
//     typedef typename Graph::NodeIt NodeIt;
marci@76
  1326
   
marci@148
  1327
//     class OutEdgeIt {
marci@148
  1328
//     public:
marci@174
  1329
//       //Graph::Node n;
marci@148
  1330
//       bool out_or_in;
marci@148
  1331
//       typename Graph::OutEdgeIt o;
marci@148
  1332
//       typename Graph::InEdgeIt i;   
marci@148
  1333
//     };
marci@148
  1334
//     class InEdgeIt {
marci@148
  1335
//     public:
marci@174
  1336
//       //Graph::Node n;
marci@148
  1337
//       bool out_or_in;
marci@148
  1338
//       typename Graph::OutEdgeIt o;
marci@148
  1339
//       typename Graph::InEdgeIt i;   
marci@148
  1340
//     };
marci@148
  1341
//     typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@174
  1342
//     typedef typename Graph::EdgeIt EdgeIt;
marci@76
  1343
marci@148
  1344
//     int nodeNum() const { return graph->nodeNum(); }
marci@148
  1345
//     int edgeNum() const { return graph->edgeNum(); }
marci@76
  1346
marci@212
  1347
//     Node& first(Node& n) const { return graph->first(n); }
marci@76
  1348
marci@174
  1349
//     // Edge and SymEdge  is missing!!!!
marci@174
  1350
//     // Edge <-> In/OutEdgeIt conversion is missing!!!!
marci@76
  1351
marci@148
  1352
//     //FIXME
marci@212
  1353
//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const 
marci@148
  1354
//       {
marci@148
  1355
// 	e.n=n;
marci@212
  1356
// 	graph->first(e.o,n);
marci@148
  1357
// 	while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
marci@148
  1358
// 	  graph->goNext(e.o);
marci@148
  1359
// 	if(!graph->valid(e.o)) {
marci@212
  1360
// 	  graph->first(e.i,n);
marci@148
  1361
// 	  while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
marci@148
  1362
// 	    graph->goNext(e.i);
marci@148
  1363
// 	}
marci@148
  1364
// 	return e;
marci@148
  1365
//       }
marci@148
  1366
// /*
marci@148
  1367
//   OutEdgeIt &goNext(OutEdgeIt &e)
marci@148
  1368
//   {
marci@148
  1369
//   if(graph->valid(e.o)) {
marci@148
  1370
//   while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
marci@148
  1371
//   graph->goNext(e.o);
marci@148
  1372
//   if(graph->valid(e.o)) return e;
marci@212
  1373
//   else graph->first(e.i,e.n);
marci@148
  1374
//   }
marci@148
  1375
//   else {
marci@148
  1376
//   while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
marci@148
  1377
//   graph->goNext(e.i);
marci@148
  1378
//   return e;
marci@148
  1379
//   }
marci@148
  1380
//   }
marci@148
  1381
//   OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
marci@148
  1382
// */
marci@148
  1383
//     //bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);}
marci@76
  1384
marci@148
  1385
//     //FIXME
marci@212
  1386
//     InEdgeIt& first(InEdgeIt& e, const Node& n) const 
marci@148
  1387
//       {
marci@148
  1388
// 	e.n=n;
marci@212
  1389
// 	graph->first(e.i,n);
marci@148
  1390
// 	while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
marci@148
  1391
// 	  graph->goNext(e.i);
marci@148
  1392
// 	if(!graph->valid(e.i)) {
marci@212
  1393
// 	  graph->first(e.o,n);
marci@148
  1394
// 	  while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
marci@148
  1395
// 	    graph->goNext(e.o);
marci@148
  1396
// 	}
marci@148
  1397
// 	return e;
marci@148
  1398
//       }
marci@148
  1399
// /*
marci@148
  1400
//   InEdgeIt &goNext(InEdgeIt &e)
marci@148
  1401
//   {
marci@148
  1402
//   if(graph->valid(e.i)) {
marci@148
  1403
//   while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
marci@148
  1404
//   graph->goNext(e.i);
marci@148
  1405
//   if(graph->valid(e.i)) return e;
marci@212
  1406
//   else graph->first(e.o,e.n);
marci@148
  1407
//   }
marci@148
  1408
//   else {
marci@148
  1409
//   while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
marci@148
  1410
//   graph->goNext(e.o);
marci@148
  1411
//   return e;
marci@148
  1412
//   }
marci@148
  1413
//   }
marci@148
  1414
//   InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
marci@148
  1415
// */
marci@148
  1416
//     //bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);}
marci@76
  1417
marci@148
  1418
//     //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
marci@148
  1419
//     //template<typename I> I next(const I i); { return graph->goNext(i); }
marci@76
  1420
marci@148
  1421
//     template< typename It > It first() const { 
marci@212
  1422
//       It e; first(e); return e; }
marci@76
  1423
marci@174
  1424
//     template< typename It > It first(Node v) const { 
marci@212
  1425
//       It e; first(e, v); return e; }
marci@76
  1426
marci@174
  1427
//     Node head(const Edge& e) const { return graph->head(e); }
marci@174
  1428
//     Node tail(const Edge& e) const { return graph->tail(e); }
marci@76
  1429
  
marci@174
  1430
//     template<typename I> Node aNode(const I& e) const { 
marci@148
  1431
//       return graph->aNode(e); }
marci@174
  1432
//     template<typename I> Node bNode(const I& e) const { 
marci@148
  1433
//       return graph->bNode(e); }
marci@76
  1434
  
marci@148
  1435
//     //template<typename I> bool valid(const I i);
marci@148
  1436
//     //{ return graph->valid(i); }
marci@76
  1437
  
marci@148
  1438
//     //template<typename I> void setInvalid(const I &i);
marci@148
  1439
//     //{ return graph->setInvalid(i); }
marci@76
  1440
  
marci@174
  1441
//     Node addNode() { return graph->addNode(); }
marci@174
  1442
//     Edge addEdge(const Node& tail, const Node& head) { 
marci@148
  1443
//       return graph->addEdge(tail, head); }
marci@76
  1444
  
marci@148
  1445
//     template<typename I> void erase(const I& i) { graph->erase(i); }
marci@76
  1446
  
marci@148
  1447
//     void clear() { graph->clear(); }
marci@76
  1448
  
marci@148
  1449
//     template<typename S> class NodeMap : public Graph::NodeMap<S> { };
marci@148
  1450
//     template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
marci@76
  1451
  
marci@148
  1452
//     void setGraph(Graph& _graph) { graph = &_graph; }
marci@148
  1453
//     Graph& getGraph() { return (*graph); }
marci@76
  1454
marci@148
  1455
//     //ResGraphWrapper() : graph(0) { }
marci@148
  1456
//     ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@148
  1457
//   };
marci@76
  1458
alpar@105
  1459
} //namespace hugo
marci@76
  1460
marci@76
  1461
#endif //GRAPH_WRAPPER_H
marci@76
  1462