src/work/marci/graph_wrapper.h
author klao
Thu, 11 Mar 2004 19:19:52 +0000
changeset 171 ec3d3596e3c9
parent 158 4f54d89fa9d2
child 174 44700ed9ffaa
permissions -rw-r--r--
hurokeles bug
marci@76
     1
// -*-mode: c++; -*-
marci@76
     2
#ifndef GRAPH_WRAPPER_H
marci@76
     3
#define GRAPH_WRAPPER_H
marci@76
     4
alpar@105
     5
namespace hugo {
marci@76
     6
marci@76
     7
  template<typename Graph>
marci@76
     8
  class TrivGraphWrapper {
marci@76
     9
    Graph* graph;
marci@76
    10
  
marci@76
    11
  public:
marci@76
    12
    typedef Graph BaseGraph;
marci@76
    13
marci@76
    14
    typedef typename Graph::NodeIt NodeIt;
marci@76
    15
    typedef typename Graph::EachNodeIt EachNodeIt;
marci@76
    16
marci@155
    17
    typedef typename Graph::EdgeIt EdgeIt;
marci@76
    18
    typedef typename Graph::OutEdgeIt OutEdgeIt;
marci@76
    19
    typedef typename Graph::InEdgeIt InEdgeIt;
marci@155
    20
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@76
    21
    typedef typename Graph::EachEdgeIt EachEdgeIt;
marci@168
    22
marci@168
    23
    //TrivGraphWrapper() : graph(0) { }
marci@168
    24
    TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@168
    25
marci@168
    26
    void setGraph(Graph& _graph) { graph = &_graph; }
marci@168
    27
    Graph& getGraph() const { return (*graph); }
marci@76
    28
    
marci@76
    29
    template<typename I> I& getFirst(I& i) const { return graph->getFirst(i); }
marci@76
    30
    template<typename I, typename P> I& getFirst(I& i, const P& p) const { 
marci@76
    31
      return graph->getFirst(i, p); }
marci@155
    32
    
marci@155
    33
    template<typename I> I getNext(const I& i) const { 
marci@155
    34
      return graph->getNext(i); }
marci@155
    35
    template<typename I> I& next(I &i) const { return graph->next(i); }    
marci@76
    36
marci@76
    37
    template< typename It > It first() const { 
marci@76
    38
      It e; getFirst(e); return e; }
marci@76
    39
marci@155
    40
    template< typename It > It first(const NodeIt& v) const { 
marci@76
    41
      It e; getFirst(e, v); return e; }
marci@76
    42
marci@76
    43
    NodeIt head(const EdgeIt& e) const { return graph->head(e); }
marci@76
    44
    NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
marci@155
    45
marci@155
    46
    template<typename I> bool valid(const I& i) const 
marci@155
    47
      { return graph->valid(i); }
marci@155
    48
  
marci@155
    49
    //template<typename I> void setInvalid(const I &i);
marci@155
    50
    //{ return graph->setInvalid(i); }
marci@155
    51
marci@155
    52
    int nodeNum() const { return graph->nodeNum(); }
marci@155
    53
    int edgeNum() const { return graph->edgeNum(); }
marci@76
    54
  
marci@76
    55
    template<typename I> NodeIt aNode(const I& e) const { 
marci@76
    56
      return graph->aNode(e); }
marci@76
    57
    template<typename I> NodeIt bNode(const I& e) const { 
marci@76
    58
      return graph->bNode(e); }
marci@76
    59
  
marci@76
    60
    NodeIt addNode() const { return graph->addNode(); }
marci@76
    61
    EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) const { 
marci@76
    62
      return graph->addEdge(tail, head); }
marci@76
    63
  
marci@76
    64
    template<typename I> void erase(const I& i) const { graph->erase(i); }
marci@76
    65
  
marci@76
    66
    void clear() const { graph->clear(); }
marci@155
    67
    
marci@76
    68
    template<typename T> class NodeMap : public Graph::NodeMap<T> { 
marci@76
    69
    public:
marci@155
    70
      NodeMap(const TrivGraphWrapper<Graph>& _G) : 
marci@158
    71
	Graph::NodeMap<T>(_G.getGraph()) { }
marci@155
    72
      NodeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
marci@158
    73
	Graph::NodeMap<T>(_G.getGraph(), a) { }
marci@76
    74
    };
marci@168
    75
marci@155
    76
    template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
marci@155
    77
    public:
marci@155
    78
      EdgeMap(const TrivGraphWrapper<Graph>& _G) : 
marci@158
    79
	Graph::EdgeMap<T>(_G.getGraph()) { }
marci@155
    80
      EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
marci@158
    81
	Graph::EdgeMap<T>(_G.getGraph(), a) { }
marci@155
    82
    };
marci@76
    83
  };
marci@76
    84
marci@76
    85
  template<typename Graph>
marci@76
    86
  class RevGraphWrapper
marci@76
    87
  {
marci@76
    88
    Graph* graph;
marci@76
    89
  
marci@76
    90
  public:
marci@76
    91
    typedef Graph BaseGraph;
marci@76
    92
marci@155
    93
    typedef typename Graph::NodeIt NodeIt;    
marci@76
    94
    typedef typename Graph::EachNodeIt EachNodeIt;
marci@76
    95
  
marci@155
    96
    typedef typename Graph::EdgeIt EdgeIt;
marci@76
    97
    typedef typename Graph::OutEdgeIt InEdgeIt;
marci@76
    98
    typedef typename Graph::InEdgeIt OutEdgeIt;
marci@155
    99
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@76
   100
    typedef typename Graph::EachEdgeIt EachEdgeIt;
marci@168
   101
marci@168
   102
    //RevGraphWrapper() : graph(0) { }
marci@168
   103
    RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@168
   104
marci@168
   105
    void setGraph(Graph& _graph) { graph = &_graph; }
marci@168
   106
    Graph& getGraph() const { return (*graph); }
marci@76
   107
    
marci@76
   108
    template<typename I> I& getFirst(I& i) const { return graph->getFirst(i); }
marci@76
   109
    template<typename I, typename P> I& getFirst(I& i, const P& p) const { 
marci@76
   110
      return graph->getFirst(i, p); }
marci@155
   111
marci@155
   112
    template<typename I> I getNext(const I& i) const { 
marci@155
   113
      return graph->getNext(i); }
marci@155
   114
    template<typename I> I& next(I &i) const { return graph->next(i); }    
marci@76
   115
marci@76
   116
    template< typename It > It first() const { 
marci@76
   117
      It e; getFirst(e); return e; }
marci@76
   118
marci@155
   119
    template< typename It > It first(const NodeIt& v) const { 
marci@76
   120
      It e; getFirst(e, v); return e; }
marci@76
   121
marci@76
   122
    NodeIt head(const EdgeIt& e) const { return graph->tail(e); }
marci@76
   123
    NodeIt tail(const EdgeIt& e) const { return graph->head(e); }
marci@76
   124
  
marci@155
   125
    template<typename I> bool valid(const I& i) const 
marci@155
   126
      { return graph->valid(i); }
marci@155
   127
  
marci@155
   128
    //template<typename I> void setInvalid(const I &i);
marci@155
   129
    //{ return graph->setInvalid(i); }
marci@155
   130
  
marci@76
   131
    template<typename I> NodeIt aNode(const I& e) const { 
marci@76
   132
      return graph->aNode(e); }
marci@76
   133
    template<typename I> NodeIt bNode(const I& e) const { 
marci@76
   134
      return graph->bNode(e); }
marci@155
   135
marci@155
   136
    NodeIt addNode() const { return graph->addNode(); }
marci@155
   137
    EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) const { 
marci@76
   138
      return graph->addEdge(tail, head); }
marci@76
   139
  
marci@155
   140
    int nodeNum() const { return graph->nodeNum(); }
marci@155
   141
    int edgeNum() const { return graph->edgeNum(); }
marci@76
   142
  
marci@155
   143
    template<typename I> void erase(const I& i) const { graph->erase(i); }
marci@76
   144
  
marci@155
   145
    void clear() const { graph->clear(); }
marci@155
   146
marci@155
   147
    template<typename T> class NodeMap : public Graph::NodeMap<T> { 
marci@155
   148
    public:
marci@155
   149
      NodeMap(const RevGraphWrapper<Graph>& _G) : 
marci@158
   150
	Graph::NodeMap<T>(_G.getGraph()) { }
marci@155
   151
      NodeMap(const RevGraphWrapper<Graph>& _G, T a) : 
marci@158
   152
	Graph::NodeMap<T>(_G.getGraph(), a) { }
marci@155
   153
    };
marci@168
   154
marci@155
   155
    template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
marci@155
   156
    public:
marci@155
   157
      EdgeMap(const RevGraphWrapper<Graph>& _G) : 
marci@158
   158
	Graph::EdgeMap<T>(_G.getGraph()) { }
marci@155
   159
      EdgeMap(const RevGraphWrapper<Graph>& _G, T a) : 
marci@158
   160
	Graph::EdgeMap<T>(_G.getGraph(), a) { }
marci@155
   161
    };
marci@76
   162
  };
marci@76
   163
marci@155
   164
marci@158
   165
  template<typename Graph>
marci@158
   166
  class UndirGraphWrapper {
marci@158
   167
    Graph* graph;
marci@158
   168
  
marci@158
   169
  public:
marci@158
   170
    typedef Graph BaseGraph;
marci@158
   171
marci@158
   172
    typedef typename Graph::NodeIt NodeIt;
marci@158
   173
    typedef typename Graph::EachNodeIt EachNodeIt;
marci@158
   174
marci@158
   175
    //typedef typename Graph::EdgeIt EdgeIt;
marci@158
   176
    //typedef typename Graph::OutEdgeIt OutEdgeIt;
marci@158
   177
    //typedef typename Graph::InEdgeIt InEdgeIt;
marci@158
   178
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@158
   179
    //typedef typename Graph::EachEdgeIt EachEdgeIt;
marci@158
   180
marci@158
   181
    //private:
marci@158
   182
    typedef typename Graph::EdgeIt GraphEdgeIt;
marci@158
   183
    typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
marci@158
   184
    typedef typename Graph::InEdgeIt GraphInEdgeIt;
marci@158
   185
    //public:
marci@158
   186
marci@168
   187
    //UndirGraphWrapper() : graph(0) { }
marci@168
   188
    UndirGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@168
   189
marci@168
   190
    void setGraph(Graph& _graph) { graph = &_graph; }
marci@168
   191
    Graph& getGraph() const { return (*graph); }
marci@168
   192
  
marci@158
   193
    class EdgeIt {
marci@158
   194
      friend class UndirGraphWrapper<Graph>;
marci@158
   195
      bool out_or_in; //true iff out
marci@158
   196
      GraphOutEdgeIt out;
marci@158
   197
      GraphInEdgeIt in;
marci@158
   198
    public:
marci@158
   199
      EdgeIt() : out_or_in(true), out(), in() { }
marci@158
   200
      operator GraphEdgeIt() const {
marci@158
   201
	if (out_or_in) return(out); else return(in);
marci@158
   202
      }
marci@158
   203
    };
marci@158
   204
marci@158
   205
    class OutEdgeIt : public EdgeIt {
marci@158
   206
      friend class UndirGraphWrapper<Graph>;
marci@158
   207
    public:
marci@158
   208
      OutEdgeIt() : EdgeIt() { }
marci@158
   209
      OutEdgeIt(const UndirGraphWrapper& _G, const NodeIt& n) : EdgeIt() { 
marci@158
   210
	_G.graph->getFirst(out, n);
marci@158
   211
	if (!(_G.graph->valid(out))) {
marci@158
   212
	  out_or_in=false;
marci@158
   213
	  _G.graph->getFirst(in, n);
marci@158
   214
	}
marci@158
   215
      }
marci@158
   216
    };
marci@158
   217
marci@158
   218
    OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt& n) const {
marci@158
   219
      e.out_or_in=true;
marci@158
   220
      graph->getFirst(e.out, n);
marci@158
   221
      if (!(graph->valid(e.out))) {
marci@158
   222
	e.out_or_in=false;
marci@158
   223
	graph->getFirst(e.in, n);
marci@158
   224
      }
marci@158
   225
      return e;
marci@158
   226
    }
marci@158
   227
marci@158
   228
    OutEdgeIt& next(OutEdgeIt& e) const {
marci@158
   229
      if (e.out_or_in) {
marci@158
   230
	NodeIt n=graph->tail(e.out);
marci@158
   231
	graph->next(e.out);
marci@158
   232
	if (!graph->valid(e.out)) {
marci@158
   233
	  e.out_or_in=false;
marci@158
   234
	  graph->getFirst(e.in, n);
marci@158
   235
	}
marci@158
   236
      } else {
marci@158
   237
	graph->next(e.in);
marci@158
   238
      }
marci@158
   239
      return e;
marci@158
   240
    }
marci@158
   241
marci@158
   242
    NodeIt aNode(const OutEdgeIt& e) const { 
marci@158
   243
      if (e.out_or_in) return graph->tail(e); else return graph->head(e); }
marci@158
   244
    NodeIt bNode(const OutEdgeIt& e) const { 
marci@158
   245
      if (e.out_or_in) return graph->head(e); else return graph->tail(e); }
marci@158
   246
marci@158
   247
    typedef OutEdgeIt InEdgeIt; 
marci@158
   248
marci@158
   249
    template<typename I> I& getFirst(I& i) const { return graph->getFirst(i); }
marci@158
   250
//     template<typename I, typename P> I& getFirst(I& i, const P& p) const { 
marci@158
   251
//       return graph->getFirst(i, p); }
marci@158
   252
    
marci@158
   253
    template<typename I> I getNext(const I& i) const { 
marci@158
   254
      return graph->getNext(i); }
marci@158
   255
    template<typename I> I& next(I &i) const { return graph->next(i); }    
marci@158
   256
marci@158
   257
    template< typename It > It first() const { 
marci@158
   258
      It e; getFirst(e); return e; }
marci@158
   259
marci@158
   260
    template< typename It > It first(const NodeIt& v) const { 
marci@158
   261
      It e; getFirst(e, v); return e; }
marci@158
   262
marci@158
   263
    NodeIt head(const EdgeIt& e) const { return graph->head(e); }
marci@158
   264
    NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
marci@158
   265
marci@158
   266
    template<typename I> bool valid(const I& i) const 
marci@158
   267
      { return graph->valid(i); }
marci@158
   268
  
marci@158
   269
    //template<typename I> void setInvalid(const I &i);
marci@158
   270
    //{ return graph->setInvalid(i); }
marci@158
   271
marci@158
   272
    int nodeNum() const { return graph->nodeNum(); }
marci@158
   273
    int edgeNum() const { return graph->edgeNum(); }
marci@158
   274
  
marci@158
   275
//     template<typename I> NodeIt aNode(const I& e) const { 
marci@158
   276
//       return graph->aNode(e); }
marci@158
   277
//     template<typename I> NodeIt bNode(const I& e) const { 
marci@158
   278
//       return graph->bNode(e); }
marci@158
   279
  
marci@158
   280
    NodeIt addNode() const { return graph->addNode(); }
marci@158
   281
    EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) const { 
marci@158
   282
      return graph->addEdge(tail, head); }
marci@158
   283
  
marci@158
   284
    template<typename I> void erase(const I& i) const { graph->erase(i); }
marci@158
   285
  
marci@158
   286
    void clear() const { graph->clear(); }
marci@158
   287
    
marci@158
   288
    template<typename T> class NodeMap : public Graph::NodeMap<T> { 
marci@158
   289
    public:
marci@158
   290
      NodeMap(const UndirGraphWrapper<Graph>& _G) : 
marci@158
   291
	Graph::NodeMap<T>(_G.getGraph()) { }
marci@158
   292
      NodeMap(const UndirGraphWrapper<Graph>& _G, T a) : 
marci@158
   293
	Graph::NodeMap<T>(_G.getGraph(), a) { }
marci@158
   294
    };
marci@168
   295
marci@158
   296
    template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
marci@158
   297
    public:
marci@158
   298
      EdgeMap(const UndirGraphWrapper<Graph>& _G) : 
marci@158
   299
	Graph::EdgeMap<T>(_G.getGraph()) { }
marci@158
   300
      EdgeMap(const UndirGraphWrapper<Graph>& _G, T a) : 
marci@158
   301
	Graph::EdgeMap<T>(_G.getGraph(), a) { }
marci@158
   302
    };
marci@158
   303
  };
marci@158
   304
marci@158
   305
marci@158
   306
marci@155
   307
//   template<typename Graph>
marci@155
   308
//   class SymGraphWrapper
marci@155
   309
//   {
marci@155
   310
//     Graph* graph;
marci@76
   311
  
marci@155
   312
//   public:
marci@155
   313
//     typedef Graph BaseGraph;
marci@155
   314
marci@155
   315
//     typedef typename Graph::NodeIt NodeIt;
marci@155
   316
//     typedef typename Graph::EdgeIt EdgeIt;
marci@155
   317
  
marci@155
   318
//     typedef typename Graph::EachNodeIt EachNodeIt;
marci@155
   319
    
marci@155
   320
//     //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
marci@155
   321
//     //iranyitatlant, ami van
marci@155
   322
//     //mert csak 1 dolgot lehet be typedef-elni
marci@155
   323
//     typedef typename Graph::OutEdgeIt SymEdgeIt;
marci@155
   324
//     //typedef typename Graph::InEdgeIt SymEdgeIt;
marci@155
   325
//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@155
   326
//     typedef typename Graph::EachEdgeIt EachEdgeIt;
marci@155
   327
marci@155
   328
//     int nodeNum() const { return graph->nodeNum(); }
marci@155
   329
//     int edgeNum() const { return graph->edgeNum(); }
marci@155
   330
    
marci@155
   331
//     template<typename I> I& getFirst(I& i) const { return graph->getFirst(i); }
marci@155
   332
//     template<typename I, typename P> I& getFirst(I& i, const P& p) const { 
marci@155
   333
//       return graph->getFirst(i, p); }
marci@155
   334
//     //template<typename I> I next(const I i); { return graph->goNext(i); }
marci@155
   335
//     //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
marci@155
   336
marci@155
   337
//     template< typename It > It first() const { 
marci@155
   338
//       It e; getFirst(e); return e; }
marci@155
   339
marci@155
   340
//     template< typename It > It first(NodeIt v) const { 
marci@155
   341
//       It e; getFirst(e, v); return e; }
marci@155
   342
marci@155
   343
//     NodeIt head(const EdgeIt& e) const { return graph->head(e); }
marci@155
   344
//     NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
marci@155
   345
  
marci@155
   346
//     template<typename I> NodeIt aNode(const I& e) const { 
marci@155
   347
//       return graph->aNode(e); }
marci@155
   348
//     template<typename I> NodeIt bNode(const I& e) const { 
marci@155
   349
//       return graph->bNode(e); }
marci@155
   350
  
marci@155
   351
//     //template<typename I> bool valid(const I i);
marci@155
   352
//     //{ return graph->valid(i); }
marci@155
   353
  
marci@155
   354
//     //template<typename I> void setInvalid(const I &i);
marci@155
   355
//     //{ return graph->setInvalid(i); }
marci@155
   356
  
marci@155
   357
//     NodeIt addNode() { return graph->addNode(); }
marci@155
   358
//     EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) { 
marci@155
   359
//       return graph->addEdge(tail, head); }
marci@155
   360
  
marci@155
   361
//     template<typename I> void erase(const I& i) { graph->erase(i); }
marci@155
   362
  
marci@155
   363
//     void clear() { graph->clear(); }
marci@155
   364
  
marci@155
   365
//     template<typename T> class NodeMap : public Graph::NodeMap<T> { };
marci@155
   366
//     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
marci@155
   367
  
marci@155
   368
//     void setGraph(Graph& _graph) { graph = &_graph; }
marci@155
   369
//     Graph& getGraph() { return (*graph); }
marci@155
   370
marci@155
   371
//     //SymGraphWrapper() : graph(0) { }
marci@155
   372
//     SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@155
   373
//   };
marci@155
   374
marci@155
   375
marci@155
   376
  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
marci@155
   377
  class ResGraphWrapper {
marci@76
   378
  public:
marci@76
   379
    typedef Graph BaseGraph;
marci@155
   380
    typedef typename Graph::NodeIt NodeIt;
marci@155
   381
    typedef typename Graph::EachNodeIt EachNodeIt;
marci@155
   382
  private:
marci@155
   383
    typedef typename Graph::OutEdgeIt OldOutEdgeIt;
marci@155
   384
    typedef typename Graph::InEdgeIt OldInEdgeIt;
marci@155
   385
    const Graph* G;
marci@155
   386
    FlowMap* flow;
marci@155
   387
    const CapacityMap* capacity;
marci@155
   388
  public:
marci@168
   389
marci@155
   390
    ResGraphWrapper(const Graph& _G, FlowMap& _flow, 
marci@155
   391
	     const CapacityMap& _capacity) : 
marci@155
   392
      G(&_G), flow(&_flow), capacity(&_capacity) { }
marci@155
   393
//     ResGraphWrapper(const ResGraphWrapper& res_graph_wrapper) : 
marci@155
   394
//       G(res_graph_wrapper.G), flow(res_graph_wrapper.flow), capacity(res_graph_wrapper.capacity) { }
marci@168
   395
marci@168
   396
    void setGraph(const Graph& _graph) { graph = &_graph; }
marci@168
   397
    const Graph& getGraph() const { return (*G); }
marci@168
   398
marci@155
   399
    class EdgeIt; 
marci@155
   400
    class OutEdgeIt; 
marci@155
   401
    friend class EdgeIt; 
marci@155
   402
    friend class OutEdgeIt; 
marci@76
   403
marci@155
   404
    class EdgeIt {
marci@155
   405
      friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
marci@155
   406
    protected:
marci@168
   407
      bool out_or_in; //true, iff out
marci@155
   408
      OldOutEdgeIt out;
marci@155
   409
      OldInEdgeIt in;
marci@155
   410
    public:
marci@155
   411
      EdgeIt() : out_or_in(true) { } 
marci@168
   412
//       bool valid() const { 
marci@168
   413
// 	return out_or_in && out.valid() || in.valid(); }
marci@155
   414
    };
marci@155
   415
marci@155
   416
marci@155
   417
    class OutEdgeIt : public EdgeIt {
marci@155
   418
      friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
marci@155
   419
    public:
marci@155
   420
      OutEdgeIt() { }
marci@168
   421
      //FIXME
marci@168
   422
      OutEdgeIt(const EdgeIt& e) : EdgeIt(e) { }
marci@155
   423
    private:
marci@168
   424
      OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, NodeIt v) : EdgeIt() { 
marci@168
   425
	resG.G->getFirst(out, v);
marci@168
   426
	while( out.valid() && !(resG.free(out)>0) ) { ++out; }
marci@155
   427
	if (!out.valid()) {
marci@155
   428
	  out_or_in=0;
marci@168
   429
	  resG.G->getFirst(in, v);
marci@168
   430
	  while( in.valid() && !(resG.free(in)>0) ) { ++in; }
marci@155
   431
	}
marci@155
   432
      }
marci@168
   433
//     public:
marci@168
   434
//       OutEdgeIt& operator++() { 
marci@168
   435
// 	if (out_or_in) {
marci@168
   436
// 	  NodeIt v=/*resG->*/G->aNode(out);
marci@168
   437
// 	  ++out;
marci@168
   438
// 	  while( out.valid() && !(EdgeIt::free()>0) ) { ++out; }
marci@168
   439
// 	  if (!out.valid()) {
marci@168
   440
// 	    out_or_in=0;
marci@168
   441
// 	    G->getFirst(in, v); 
marci@168
   442
// 	    while( in.valid() && !(EdgeIt::free()>0) ) { ++in; }
marci@168
   443
// 	  }
marci@168
   444
// 	} else {
marci@168
   445
// 	  ++in;
marci@168
   446
// 	  while( in.valid() && !(EdgeIt::free()>0) ) { ++in; } 
marci@168
   447
// 	}
marci@168
   448
// 	return *this; 
marci@168
   449
//       }
marci@155
   450
    };
marci@155
   451
marci@155
   452
    class EachEdgeIt : public EdgeIt {
marci@155
   453
      friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
marci@155
   454
      typename Graph::EachNodeIt v;
marci@155
   455
    public:
marci@155
   456
      EachEdgeIt() { }
marci@155
   457
      //EachEdgeIt(const EachEdgeIt& e) : EdgeIt(e), v(e.v) { }
marci@168
   458
      EachEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG) : EdgeIt() { 
marci@168
   459
	resG.G->getFirst(v);
marci@168
   460
	if (v.valid()) resG.G->getFirst(out, v); else out=OldOutEdgeIt();
marci@168
   461
	while (out.valid() && !(resG.free(out)>0) ) { ++out; }
marci@155
   462
	while (v.valid() && !out.valid()) { 
marci@155
   463
	  ++v; 
marci@168
   464
	  if (v.valid()) resG.G->getFirst(out, v); 
marci@168
   465
	  while (out.valid() && !(resG.free(out)>0) ) { ++out; }
marci@155
   466
	}
marci@155
   467
	if (!out.valid()) {
marci@155
   468
	  out_or_in=0;
marci@168
   469
	  resG.G->getFirst(v);
marci@168
   470
	  if (v.valid()) resG.G->getFirst(in, v); else in=OldInEdgeIt();
marci@168
   471
	  while (in.valid() && !(resG.free(in)>0) ) { ++in; }
marci@155
   472
	  while (v.valid() && !in.valid()) { 
marci@155
   473
	    ++v; 
marci@168
   474
	    if (v.valid()) resG.G->getFirst(in, v); 
marci@168
   475
	    while (in.valid() && !(resG.free(in)>0) ) { ++in; }
marci@155
   476
	  }
marci@155
   477
	}
marci@155
   478
      }
marci@168
   479
//       EachEdgeIt& operator++() { 
marci@168
   480
// 	if (out_or_in) {
marci@168
   481
// 	  ++out;
marci@168
   482
// 	  while (out.valid() && !(EdgeIt::free()>0) ) { ++out; }
marci@168
   483
// 	  while (v.valid() && !out.valid()) { 
marci@168
   484
// 	    ++v; 
marci@168
   485
// 	    if (v.valid()) G->getFirst(out, v); 
marci@168
   486
// 	    while (out.valid() && !(EdgeIt::free()>0) ) { ++out; }
marci@168
   487
// 	  }
marci@168
   488
// 	  if (!out.valid()) {
marci@168
   489
// 	    out_or_in=0;
marci@168
   490
// 	    G->getFirst(v);
marci@168
   491
// 	    if (v.valid()) G->getFirst(in, v); else in=OldInEdgeIt();
marci@168
   492
// 	    while (in.valid() && !(EdgeIt::free()>0) ) { ++in; }
marci@168
   493
// 	    while (v.valid() && !in.valid()) { 
marci@168
   494
// 	      ++v; 
marci@168
   495
// 	      if (v.valid()) G->getFirst(in, v); 
marci@168
   496
// 	      while (in.valid() && !(EdgeIt::free()>0) ) { ++in; }
marci@168
   497
// 	    }  
marci@168
   498
// 	  }
marci@168
   499
// 	} else {
marci@168
   500
// 	  ++in;
marci@168
   501
// 	  while (in.valid() && !(EdgeIt::free()>0) ) { ++in; }
marci@168
   502
// 	  while (v.valid() && !in.valid()) { 
marci@168
   503
// 	    ++v; 
marci@168
   504
// 	    if (v.valid()) G->getFirst(in, v); 
marci@168
   505
// 	    while (in.valid() && !(EdgeIt::free()>0) ) { ++in; }
marci@168
   506
// 	  }
marci@168
   507
// 	}
marci@168
   508
// 	return *this;
marci@168
   509
//       }
marci@155
   510
    };
marci@155
   511
marci@168
   512
    EachNodeIt& getFirst(EachNodeIt& v) const { G->getFirst(v); }
marci@168
   513
    OutEdgeIt& getFirst(OutEdgeIt& e, NodeIt v) const { 
marci@168
   514
      e=OutEdgeIt(*this, v); 
marci@155
   515
    }
marci@168
   516
    EachEdgeIt& getFirst(EachEdgeIt& e) const { 
marci@168
   517
      e=EachEdgeIt(*this); 
marci@155
   518
    }
marci@155
   519
   
marci@155
   520
    EachNodeIt& next(EachNodeIt& n) const { return G->next(n); }
marci@155
   521
marci@155
   522
    OutEdgeIt& next(OutEdgeIt& e) const { 
marci@155
   523
      if (e.out_or_in) {
marci@155
   524
	NodeIt v=G->aNode(e.out);
marci@155
   525
	++(e.out);
marci@168
   526
	while( G->valid(e.out) && !(free(e.out)>0) ) { ++(e.out); }
marci@155
   527
	if (!G->valid(e.out)) {
marci@155
   528
	  e.out_or_in=0;
marci@168
   529
	  G->getFirst(e.in, v); 
marci@168
   530
	  while( G->valid(e.in) && !(free(e.in)>0) ) { ++(e.in); }
marci@155
   531
	}
marci@155
   532
      } else {
marci@155
   533
	++(e.in);
marci@168
   534
	while( G->valid(e.in) && !(free(e.in)>0) ) { ++(e.in); } 
marci@155
   535
      }
marci@155
   536
      return e;
marci@155
   537
    }
marci@155
   538
marci@155
   539
    EachEdgeIt& next(EachEdgeIt& e) const { 
marci@155
   540
      if (e.out_or_in) {
marci@155
   541
	++(e.out);
marci@168
   542
	while (G->valid(e.out) && !(free(e.out)>0) ) { ++(e.out); }
marci@155
   543
	  while (G->valid(e.v) && !G->valid(e.out)) { 
marci@155
   544
	    ++(e.v); 
marci@155
   545
	    if (G->valid(e.v)) G->getFirst(e.out, e.v); 
marci@168
   546
	    while (G->valid(e.out) && !(free(e.out)>0) ) { ++(e.out); }
marci@155
   547
	  }
marci@155
   548
	  if (!G->valid(e.out)) {
marci@155
   549
	    e.out_or_in=0;
marci@155
   550
	    G->getFirst(e.v);
marci@155
   551
	    if (G->valid(e.v)) G->getFirst(e.in, e.v); else e.in=OldInEdgeIt();
marci@168
   552
	    while (G->valid(e.in) && !(free(e.in)>0) ) { ++(e.in); }
marci@155
   553
	    while (G->valid(e.v) && !G->valid(e.in)) { 
marci@155
   554
	      ++(e.v); 
marci@155
   555
	      if (G->valid(e.v)) G->getFirst(e.in, e.v); 
marci@168
   556
	      while (G->valid(e.in) && !(free(e.in)>0) ) { ++(e.in); }
marci@155
   557
	    }  
marci@155
   558
	  }
marci@155
   559
	} else {
marci@155
   560
	  ++(e.in);
marci@168
   561
	  while (G->valid(e.in) && !(free(e.in)>0) ) { ++(e.in); }
marci@155
   562
	  while (G->valid(e.v) && !G->valid(e.in)) { 
marci@155
   563
	    ++(e.v); 
marci@155
   564
	    if (G->valid(e.v)) G->getFirst(e.in, e.v); 
marci@168
   565
	    while (G->valid(e.in) && !(free(e.in)>0) ) { ++(e.in); }
marci@155
   566
	  }
marci@155
   567
	}
marci@155
   568
	return e;
marci@155
   569
      }
marci@76
   570
    
marci@76
   571
marci@155
   572
    template< typename It >
marci@155
   573
    It first() const { 
marci@155
   574
      It e;
marci@155
   575
      getFirst(e);
marci@155
   576
      return e; 
marci@155
   577
    }
marci@76
   578
marci@155
   579
    template< typename It >
marci@155
   580
    It first(NodeIt v) const { 
marci@155
   581
      It e;
marci@155
   582
      getFirst(e, v);
marci@155
   583
      return e; 
marci@155
   584
    }
marci@76
   585
marci@155
   586
    NodeIt tail(EdgeIt e) const { 
marci@155
   587
      return ((e.out_or_in) ? G->aNode(e.out) : G->aNode(e.in)); }
marci@155
   588
    NodeIt head(EdgeIt e) const { 
marci@155
   589
      return ((e.out_or_in) ? G->bNode(e.out) : G->bNode(e.in)); }
marci@76
   590
marci@155
   591
    NodeIt aNode(OutEdgeIt e) const { 
marci@155
   592
      return ((e.out_or_in) ? G->aNode(e.out) : G->aNode(e.in)); }
marci@155
   593
    NodeIt bNode(OutEdgeIt e) const { 
marci@155
   594
      return ((e.out_or_in) ? G->bNode(e.out) : G->bNode(e.in)); }
marci@76
   595
marci@155
   596
    int id(NodeIt v) const { return G->id(v); }
marci@155
   597
marci@155
   598
    bool valid(NodeIt n) const { return G->valid(n); }
marci@155
   599
    bool valid(EdgeIt e) const { 
marci@155
   600
      return e.out_or_in ? G->valid(e.out) : G->valid(e.in); }
marci@155
   601
marci@168
   602
    void augment(const EdgeIt& e, Number a) const {
marci@168
   603
      if (e.out_or_in)  
marci@168
   604
	flow->set(e.out, flow->get(e.out)+a);
marci@168
   605
      else  
marci@168
   606
	flow->set(e.in, flow->get(e.in)-a);
marci@168
   607
    }
marci@168
   608
marci@168
   609
    Number free(const EdgeIt& e) const { 
marci@168
   610
      if (e.out_or_in) 
marci@168
   611
	return (capacity->get(e.out)-flow->get(e.out)); 
marci@168
   612
      else 
marci@168
   613
	return (flow->get(e.in)); 
marci@168
   614
    }
marci@168
   615
marci@168
   616
    Number free(OldOutEdgeIt out) const { 
marci@168
   617
      return (capacity->get(out)-flow->get(out)); 
marci@168
   618
    }
marci@168
   619
    
marci@168
   620
    Number free(OldInEdgeIt in) const { 
marci@168
   621
      return (flow->get(in)); 
marci@168
   622
    }
marci@168
   623
marci@155
   624
    template<typename T> class NodeMap : public Graph::NodeMap<T> { 
marci@155
   625
    public:
marci@155
   626
      NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) 
marci@158
   627
	: Graph::NodeMap<T>(_G.getGraph()) { }
marci@155
   628
      NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, 
marci@158
   629
	      T a) : Graph::NodeMap<T>(_G.getGraph(), a) { }
marci@155
   630
    };
marci@155
   631
marci@155
   632
//     template <typename T>
marci@155
   633
//     class NodeMap {
marci@155
   634
//       typename Graph::NodeMap<T> node_map; 
marci@155
   635
//     public:
marci@155
   636
//       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.G)) { }
marci@155
   637
//       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.G), a) { }
marci@155
   638
//       void set(NodeIt nit, T a) { node_map.set(nit, a); }
marci@155
   639
//       T get(NodeIt nit) const { return node_map.get(nit); }
marci@155
   640
//     };
marci@155
   641
marci@155
   642
    template <typename T>
marci@155
   643
    class EdgeMap {
marci@155
   644
      typename Graph::EdgeMap<T> forward_map, backward_map; 
marci@155
   645
    public:
marci@158
   646
      EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.getGraph()), backward_map(_G.getGraph()) { }
marci@158
   647
      EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.getGraph(), a), backward_map(_G.getGraph(), a) { }
marci@155
   648
      void set(EdgeIt e, T a) { 
marci@155
   649
	if (e.out_or_in) 
marci@155
   650
	  forward_map.set(e.out, a); 
marci@155
   651
	else 
marci@155
   652
	  backward_map.set(e.in, a); 
marci@155
   653
      }
marci@155
   654
      T get(EdgeIt e) { 
marci@155
   655
	if (e.out_or_in) 
marci@155
   656
	  return forward_map.get(e.out); 
marci@155
   657
	else 
marci@155
   658
	  return backward_map.get(e.in); 
marci@155
   659
      }
marci@155
   660
    };
marci@168
   661
  };
marci@168
   662
marci@168
   663
  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
marci@168
   664
  class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
marci@168
   665
  protected:
marci@168
   666
    ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
marci@168
   667
    //ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
marci@168
   668
  public:
marci@168
   669
    ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow, 
marci@168
   670
			   const CapacityMap& _capacity) : 
marci@168
   671
      ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), 
marci@168
   672
      first_out_edges(*this) /*, dist(*this)*/ { 
marci@168
   673
      for(EachNodeIt n=this->template first<EachNodeIt>(); this->valid(n); this->next(n)) {
marci@168
   674
	OutEdgeIt e;
marci@168
   675
	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::getFirst(e, n);
marci@168
   676
	first_out_edges.set(n, e);
marci@168
   677
      }
marci@168
   678
    }
marci@168
   679
marci@168
   680
    //void setGraph(Graph& _graph) { graph = &_graph; }
marci@168
   681
    //Graph& getGraph() const { return (*graph); }
marci@168
   682
  
marci@168
   683
    //TrivGraphWrapper() : graph(0) { }
marci@168
   684
    //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@168
   685
marci@168
   686
    //typedef Graph BaseGraph;
marci@168
   687
marci@168
   688
    //typedef typename Graph::NodeIt NodeIt;
marci@168
   689
    //typedef typename Graph::EachNodeIt EachNodeIt;
marci@168
   690
marci@168
   691
    //typedef typename Graph::EdgeIt EdgeIt;
marci@168
   692
    //typedef typename Graph::OutEdgeIt OutEdgeIt;
marci@168
   693
    //typedef typename Graph::InEdgeIt InEdgeIt;
marci@168
   694
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@168
   695
    //typedef typename Graph::EachEdgeIt EachEdgeIt;
marci@168
   696
marci@168
   697
    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
marci@168
   698
    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EachNodeIt EachNodeIt;
marci@168
   699
marci@168
   700
    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
marci@168
   701
    typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
marci@168
   702
    //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
marci@168
   703
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@168
   704
    //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EachEdgeIt EachEdgeIt;
marci@168
   705
marci@168
   706
    EachNodeIt& getFirst(EachNodeIt& n) const { 
marci@168
   707
      return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::getFirst(n);
marci@168
   708
    }
marci@168
   709
marci@168
   710
    OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt& n) const { 
marci@168
   711
      e=first_out_edges.get(n);
marci@168
   712
      return e;
marci@168
   713
    }
marci@168
   714
    
marci@168
   715
    //ROSSZ template<typename I> I& getFirst(I& i) const { return getFirst(i); }
marci@168
   716
    //ROSSZ template<typename I, typename P> I& getFirst(I& i, const P& p) const { 
marci@168
   717
    //  return getFirst(i, p); }
marci@168
   718
    
marci@168
   719
    //template<typename I> I getNext(const I& i) const { 
marci@168
   720
    //  return graph->getNext(i); }
marci@168
   721
    //template<typename I> I& next(I &i) const { return graph->next(i); }    
marci@168
   722
marci@168
   723
    template< typename It > It first() const { 
marci@168
   724
      It e; getFirst(e); return e; }
marci@168
   725
marci@168
   726
    template< typename It > It first(const NodeIt& v) const { 
marci@168
   727
      It e; getFirst(e, v); return e; }
marci@168
   728
marci@168
   729
    //NodeIt head(const EdgeIt& e) const { return graph->head(e); }
marci@168
   730
    //NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
marci@168
   731
marci@168
   732
    //template<typename I> bool valid(const I& i) const 
marci@168
   733
    //  { return graph->valid(i); }
marci@168
   734
  
marci@168
   735
    //int nodeNum() const { return graph->nodeNum(); }
marci@168
   736
    //int edgeNum() const { return graph->edgeNum(); }
marci@168
   737
  
marci@168
   738
    //template<typename I> NodeIt aNode(const I& e) const { 
marci@168
   739
    //  return graph->aNode(e); }
marci@168
   740
    //template<typename I> NodeIt bNode(const I& e) const { 
marci@168
   741
    //  return graph->bNode(e); }
marci@168
   742
  
marci@168
   743
    //NodeIt addNode() const { return graph->addNode(); }
marci@168
   744
    //EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) const { 
marci@168
   745
    //  return graph->addEdge(tail, head); }
marci@168
   746
  
marci@168
   747
    //void erase(const OutEdgeIt& e) {
marci@168
   748
    //  first_out_edge(this->tail(e))=e;
marci@168
   749
    //}
marci@168
   750
    void erase(const EdgeIt& e) {
marci@168
   751
      OutEdgeIt f(e);
marci@168
   752
      next(f);
marci@168
   753
      first_out_edges.set(this->tail(e), f);
marci@168
   754
    }
marci@168
   755
    //template<typename I> void erase(const I& i) const { graph->erase(i); }
marci@168
   756
  
marci@168
   757
    //void clear() const { graph->clear(); }
marci@168
   758
    
marci@168
   759
    template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { 
marci@168
   760
    public:
marci@168
   761
      NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : 
marci@168
   762
	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
marci@168
   763
      NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : 
marci@168
   764
	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
marci@168
   765
    };
marci@168
   766
marci@168
   767
    template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { 
marci@168
   768
    public:
marci@168
   769
      EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : 
marci@168
   770
	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
marci@168
   771
      EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : 
marci@168
   772
	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
marci@168
   773
    };
marci@168
   774
  };
marci@168
   775
marci@168
   776
  template<typename GraphWrapper> 
marci@168
   777
  class FilterGraphWrapper {
marci@168
   778
  };
marci@168
   779
marci@168
   780
  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
marci@168
   781
  class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
marci@168
   782
marci@168
   783
    //Graph* graph;
marci@168
   784
  
marci@168
   785
  public:
marci@168
   786
    //typedef Graph BaseGraph;
marci@168
   787
marci@168
   788
    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
marci@168
   789
    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EachNodeIt EachNodeIt;
marci@168
   790
marci@168
   791
    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
marci@168
   792
    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
marci@168
   793
    //typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
marci@168
   794
    //typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@168
   795
    typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EachEdgeIt EachEdgeIt;
marci@168
   796
marci@168
   797
    //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
marci@168
   798
    
marci@168
   799
  public:
marci@168
   800
    FilterGraphWrapper(const Graph& _G, FlowMap& _flow, 
marci@168
   801
			   const CapacityMap& _capacity) : 
marci@168
   802
      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this) { 
marci@168
   803
    }
marci@168
   804
marci@168
   805
    OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt& n) const {
marci@168
   806
      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::getFirst(e, n);
marci@168
   807
      while (valid(e) && (dist.get(tail(e))+1!=dist.get(head(e)))) 
marci@168
   808
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
marci@168
   809
      return e;
marci@168
   810
    }
marci@168
   811
marci@168
   812
    EachNodeIt& next(EachNodeIt& e) const {
marci@168
   813
      return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
marci@168
   814
    }
marci@168
   815
marci@168
   816
    OutEdgeIt& next(OutEdgeIt& e) const {
marci@168
   817
      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
marci@168
   818
      while (valid(e) && (dist.get(tail(e))+1!=dist.get(head(e)))) 
marci@168
   819
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
marci@168
   820
      return e;
marci@168
   821
    }
marci@168
   822
marci@168
   823
    EachNodeIt& getFirst(EachNodeIt& n) const {
marci@168
   824
      return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::getFirst(n);
marci@168
   825
    }
marci@168
   826
marci@168
   827
    void erase(const EdgeIt& e) {
marci@168
   828
      OutEdgeIt f(e);
marci@168
   829
      ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
marci@168
   830
      while (valid(f) && (dist.get(tail(f))+1!=dist.get(head(f)))) 
marci@168
   831
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
marci@168
   832
      first_out_edges.set(this->tail(e), f);
marci@168
   833
    }
marci@168
   834
marci@168
   835
    //TrivGraphWrapper() : graph(0) { }
marci@168
   836
    //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@168
   837
marci@168
   838
    //void setGraph(Graph& _graph) { graph = &_graph; }
marci@168
   839
    //Graph& getGraph() const { return (*graph); }
marci@168
   840
    
marci@168
   841
    //template<typename I> I& getFirst(I& i) const { return graph->getFirst(i); }
marci@168
   842
    //template<typename I, typename P> I& getFirst(I& i, const P& p) const { 
marci@168
   843
    //  return graph->getFirst(i, p); }
marci@168
   844
    
marci@168
   845
    //template<typename I> I getNext(const I& i) const { 
marci@168
   846
    //  return graph->getNext(i); }
marci@168
   847
    //template<typename I> I& next(I &i) const { return graph->next(i); }    
marci@168
   848
marci@168
   849
    template< typename It > It first() const { 
marci@168
   850
      It e; getFirst(e); return e; }
marci@168
   851
marci@168
   852
    template< typename It > It first(const NodeIt& v) const { 
marci@168
   853
      It e; getFirst(e, v); return e; }
marci@168
   854
marci@168
   855
    //NodeIt head(const EdgeIt& e) const { return graph->head(e); }
marci@168
   856
    //NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
marci@168
   857
marci@168
   858
    //template<typename I> bool valid(const I& i) const 
marci@168
   859
    //  { return graph->valid(i); }
marci@168
   860
  
marci@168
   861
    //template<typename I> void setInvalid(const I &i);
marci@168
   862
    //{ return graph->setInvalid(i); }
marci@168
   863
marci@168
   864
    //int nodeNum() const { return graph->nodeNum(); }
marci@168
   865
    //int edgeNum() const { return graph->edgeNum(); }
marci@168
   866
  
marci@168
   867
    //template<typename I> NodeIt aNode(const I& e) const { 
marci@168
   868
    //  return graph->aNode(e); }
marci@168
   869
    //template<typename I> NodeIt bNode(const I& e) const { 
marci@168
   870
    //  return graph->bNode(e); }
marci@168
   871
  
marci@168
   872
    //NodeIt addNode() const { return graph->addNode(); }
marci@168
   873
    //EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) const { 
marci@168
   874
    //  return graph->addEdge(tail, head); }
marci@168
   875
  
marci@168
   876
    //template<typename I> void erase(const I& i) const { graph->erase(i); }
marci@168
   877
  
marci@168
   878
    //void clear() const { graph->clear(); }
marci@168
   879
    
marci@168
   880
    template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { 
marci@168
   881
    public:
marci@168
   882
      NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) : 
marci@168
   883
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
marci@168
   884
      NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) : 
marci@168
   885
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
marci@168
   886
    };
marci@168
   887
marci@168
   888
    template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { 
marci@168
   889
    public:
marci@168
   890
      EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) : 
marci@168
   891
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
marci@168
   892
      EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) : 
marci@168
   893
	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
marci@168
   894
    };
marci@168
   895
marci@168
   896
  public:
marci@168
   897
    ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
marci@155
   898
marci@76
   899
  };
marci@76
   900
marci@76
   901
marci@148
   902
marci@148
   903
// // FIXME: comparison should be made better!!!
marci@148
   904
//   template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
marci@148
   905
//   class ResGraphWrapper
marci@148
   906
//   {
marci@148
   907
//     Graph* graph;
marci@76
   908
  
marci@148
   909
//   public:
marci@148
   910
//     typedef Graph BaseGraph;
marci@76
   911
marci@148
   912
//     typedef typename Graph::NodeIt NodeIt;
marci@148
   913
//     typedef typename Graph::EdgeIt EdgeIt;
marci@76
   914
  
marci@148
   915
//     typedef typename Graph::EachNodeIt EachNodeIt;
marci@76
   916
   
marci@148
   917
//     class OutEdgeIt {
marci@148
   918
//     public:
marci@148
   919
//       //Graph::NodeIt n;
marci@148
   920
//       bool out_or_in;
marci@148
   921
//       typename Graph::OutEdgeIt o;
marci@148
   922
//       typename Graph::InEdgeIt i;   
marci@148
   923
//     };
marci@148
   924
//     class InEdgeIt {
marci@148
   925
//     public:
marci@148
   926
//       //Graph::NodeIt n;
marci@148
   927
//       bool out_or_in;
marci@148
   928
//       typename Graph::OutEdgeIt o;
marci@148
   929
//       typename Graph::InEdgeIt i;   
marci@148
   930
//     };
marci@148
   931
//     typedef typename Graph::SymEdgeIt SymEdgeIt;
marci@148
   932
//     typedef typename Graph::EachEdgeIt EachEdgeIt;
marci@76
   933
marci@148
   934
//     int nodeNum() const { return graph->nodeNum(); }
marci@148
   935
//     int edgeNum() const { return graph->edgeNum(); }
marci@76
   936
marci@148
   937
//     NodeIt& getFirst(NodeIt& n) const { return graph->getFirst(n); }
marci@76
   938
marci@148
   939
//     // EachEdge and SymEdge  is missing!!!!
marci@148
   940
//     // EdgeIt <-> In/OutEdgeIt conversion is missing!!!!
marci@76
   941
marci@148
   942
//     //FIXME
marci@148
   943
//     OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt& n) const 
marci@148
   944
//       {
marci@148
   945
// 	e.n=n;
marci@148
   946
// 	graph->getFirst(e.o,n);
marci@148
   947
// 	while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
marci@148
   948
// 	  graph->goNext(e.o);
marci@148
   949
// 	if(!graph->valid(e.o)) {
marci@148
   950
// 	  graph->getFirst(e.i,n);
marci@148
   951
// 	  while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
marci@148
   952
// 	    graph->goNext(e.i);
marci@148
   953
// 	}
marci@148
   954
// 	return e;
marci@148
   955
//       }
marci@148
   956
// /*
marci@148
   957
//   OutEdgeIt &goNext(OutEdgeIt &e)
marci@148
   958
//   {
marci@148
   959
//   if(graph->valid(e.o)) {
marci@148
   960
//   while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
marci@148
   961
//   graph->goNext(e.o);
marci@148
   962
//   if(graph->valid(e.o)) return e;
marci@148
   963
//   else graph->getFirst(e.i,e.n);
marci@148
   964
//   }
marci@148
   965
//   else {
marci@148
   966
//   while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
marci@148
   967
//   graph->goNext(e.i);
marci@148
   968
//   return e;
marci@148
   969
//   }
marci@148
   970
//   }
marci@148
   971
//   OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
marci@148
   972
// */
marci@148
   973
//     //bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);}
marci@76
   974
marci@148
   975
//     //FIXME
marci@148
   976
//     InEdgeIt& getFirst(InEdgeIt& e, const NodeIt& n) const 
marci@148
   977
//       {
marci@148
   978
// 	e.n=n;
marci@148
   979
// 	graph->getFirst(e.i,n);
marci@148
   980
// 	while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
marci@148
   981
// 	  graph->goNext(e.i);
marci@148
   982
// 	if(!graph->valid(e.i)) {
marci@148
   983
// 	  graph->getFirst(e.o,n);
marci@148
   984
// 	  while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
marci@148
   985
// 	    graph->goNext(e.o);
marci@148
   986
// 	}
marci@148
   987
// 	return e;
marci@148
   988
//       }
marci@148
   989
// /*
marci@148
   990
//   InEdgeIt &goNext(InEdgeIt &e)
marci@148
   991
//   {
marci@148
   992
//   if(graph->valid(e.i)) {
marci@148
   993
//   while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
marci@148
   994
//   graph->goNext(e.i);
marci@148
   995
//   if(graph->valid(e.i)) return e;
marci@148
   996
//   else graph->getFirst(e.o,e.n);
marci@148
   997
//   }
marci@148
   998
//   else {
marci@148
   999
//   while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
marci@148
  1000
//   graph->goNext(e.o);
marci@148
  1001
//   return e;
marci@148
  1002
//   }
marci@148
  1003
//   }
marci@148
  1004
//   InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
marci@148
  1005
// */
marci@148
  1006
//     //bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);}
marci@76
  1007
marci@148
  1008
//     //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
marci@148
  1009
//     //template<typename I> I next(const I i); { return graph->goNext(i); }
marci@76
  1010
marci@148
  1011
//     template< typename It > It first() const { 
marci@148
  1012
//       It e; getFirst(e); return e; }
marci@76
  1013
marci@148
  1014
//     template< typename It > It first(NodeIt v) const { 
marci@148
  1015
//       It e; getFirst(e, v); return e; }
marci@76
  1016
marci@148
  1017
//     NodeIt head(const EdgeIt& e) const { return graph->head(e); }
marci@148
  1018
//     NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
marci@76
  1019
  
marci@148
  1020
//     template<typename I> NodeIt aNode(const I& e) const { 
marci@148
  1021
//       return graph->aNode(e); }
marci@148
  1022
//     template<typename I> NodeIt bNode(const I& e) const { 
marci@148
  1023
//       return graph->bNode(e); }
marci@76
  1024
  
marci@148
  1025
//     //template<typename I> bool valid(const I i);
marci@148
  1026
//     //{ return graph->valid(i); }
marci@76
  1027
  
marci@148
  1028
//     //template<typename I> void setInvalid(const I &i);
marci@148
  1029
//     //{ return graph->setInvalid(i); }
marci@76
  1030
  
marci@148
  1031
//     NodeIt addNode() { return graph->addNode(); }
marci@148
  1032
//     EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) { 
marci@148
  1033
//       return graph->addEdge(tail, head); }
marci@76
  1034
  
marci@148
  1035
//     template<typename I> void erase(const I& i) { graph->erase(i); }
marci@76
  1036
  
marci@148
  1037
//     void clear() { graph->clear(); }
marci@76
  1038
  
marci@148
  1039
//     template<typename S> class NodeMap : public Graph::NodeMap<S> { };
marci@148
  1040
//     template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
marci@76
  1041
  
marci@148
  1042
//     void setGraph(Graph& _graph) { graph = &_graph; }
marci@148
  1043
//     Graph& getGraph() { return (*graph); }
marci@76
  1044
marci@148
  1045
//     //ResGraphWrapper() : graph(0) { }
marci@148
  1046
//     ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
marci@148
  1047
//   };
marci@76
  1048
alpar@105
  1049
} //namespace hugo
marci@76
  1050
marci@76
  1051
#endif //GRAPH_WRAPPER_H
marci@76
  1052