lemon/graph_adaptor.h
author klao
Thu, 16 Mar 2006 13:52:12 +0000
changeset 2009 de287863cc98
parent 1993 2115143eceea
child 2031 080d51024ac5
permissions -rw-r--r--
rethrow fix
alpar@906
     1
/* -*- C++ -*-
alpar@906
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@906
     8
 *
alpar@906
     9
 * Permission to use, modify and distribute this software is granted
alpar@906
    10
 * provided that this copyright notice appears in all copies. For
alpar@906
    11
 * precise terms see the accompanying LICENSE file.
alpar@906
    12
 *
alpar@906
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    14
 * express or implied, and with no claim as to its suitability for any
alpar@906
    15
 * purpose.
alpar@906
    16
 *
alpar@906
    17
 */
alpar@906
    18
alpar@1401
    19
#ifndef LEMON_GRAPH_ADAPTOR_H
alpar@1401
    20
#define LEMON_GRAPH_ADAPTOR_H
marci@556
    21
alpar@1401
    22
///\ingroup graph_adaptors
marci@556
    23
///\file
alpar@1401
    24
///\brief Several graph adaptors.
marci@556
    25
///
alpar@1401
    26
///This file contains several useful graph adaptor functions.
marci@556
    27
///
marci@556
    28
///\author Marton Makai
marci@556
    29
deba@1993
    30
#include <lemon/bits/invalid.h>
alpar@921
    31
#include <lemon/maps.h>
deba@1979
    32
deba@1999
    33
#include <lemon/bits/base_extender.h>
deba@1979
    34
#include <lemon/bits/graph_adaptor_extender.h>
deba@1791
    35
#include <lemon/bits/graph_extender.h>
deba@1979
    36
alpar@774
    37
#include <iostream>
marci@556
    38
alpar@921
    39
namespace lemon {
marci@556
    40
klao@1951
    41
  ///\brief Base type for the Graph Adaptors
klao@1951
    42
  ///\ingroup graph_adaptors
klao@1951
    43
  ///
klao@1951
    44
  ///Base type for the Graph Adaptors
klao@1951
    45
  ///
klao@1951
    46
  ///\warning Graph adaptors are in even
klao@1951
    47
  ///more experimental state than the other
klao@1951
    48
  ///parts of the lib. Use them at you own risk.
klao@1951
    49
  ///
klao@1951
    50
  ///This is the base type for most of LEMON graph adaptors. 
klao@1951
    51
  ///This class implements a trivial graph adaptor i.e. it only wraps the 
klao@1951
    52
  ///functions and types of the graph. The purpose of this class is to 
klao@1951
    53
  ///make easier implementing graph adaptors. E.g. if an adaptor is 
klao@1951
    54
  ///considered which differs from the wrapped graph only in some of its 
klao@1951
    55
  ///functions or types, then it can be derived from GraphAdaptor,
klao@1951
    56
  ///and only the 
klao@1951
    57
  ///differences should be implemented.
klao@1951
    58
  ///
klao@1951
    59
  ///author Marton Makai 
marci@970
    60
  template<typename _Graph>
alpar@1401
    61
  class GraphAdaptorBase {
marci@970
    62
  public:
marci@970
    63
    typedef _Graph Graph;
marci@970
    64
    typedef Graph ParentGraph;
marci@970
    65
marci@556
    66
  protected:
marci@556
    67
    Graph* graph;
alpar@1401
    68
    GraphAdaptorBase() : graph(0) { }
marci@556
    69
    void setGraph(Graph& _graph) { graph=&_graph; }
marci@556
    70
marci@556
    71
  public:
alpar@1401
    72
    GraphAdaptorBase(Graph& _graph) : graph(&_graph) { }
marci@556
    73
 
alpar@774
    74
    typedef typename Graph::Node Node;
alpar@774
    75
    typedef typename Graph::Edge Edge;
marci@556
    76
   
marci@970
    77
    void first(Node& i) const { graph->first(i); }
marci@970
    78
    void first(Edge& i) const { graph->first(i); }
marci@970
    79
    void firstIn(Edge& i, const Node& n) const { graph->firstIn(i, n); }
marci@970
    80
    void firstOut(Edge& i, const Node& n ) const { graph->firstOut(i, n); }
marci@556
    81
marci@970
    82
    void next(Node& i) const { graph->next(i); }
marci@970
    83
    void next(Edge& i) const { graph->next(i); }
marci@970
    84
    void nextIn(Edge& i) const { graph->nextIn(i); }
marci@970
    85
    void nextOut(Edge& i) const { graph->nextOut(i); }
marci@970
    86
alpar@986
    87
    Node source(const Edge& e) const { return graph->source(e); }
alpar@986
    88
    Node target(const Edge& e) const { return graph->target(e); }
marci@556
    89
deba@1697
    90
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
marci@556
    91
    int nodeNum() const { return graph->nodeNum(); }
deba@1697
    92
    
deba@1697
    93
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
marci@556
    94
    int edgeNum() const { return graph->edgeNum(); }
deba@1697
    95
deba@1697
    96
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1697
    97
    Edge findEdge(const Node& source, const Node& target, 
deba@1697
    98
		  const Edge& prev = INVALID) {
deba@1697
    99
      return graph->findEdge(source, target, prev);
deba@1697
   100
    }
marci@556
   101
  
deba@1697
   102
    Node addNode() const { 
deba@1697
   103
      return Node(graph->addNode()); 
deba@1697
   104
    }
deba@1697
   105
alpar@986
   106
    Edge addEdge(const Node& source, const Node& target) const { 
deba@1697
   107
      return Edge(graph->addEdge(source, target)); 
deba@1697
   108
    }
marci@556
   109
marci@556
   110
    void erase(const Node& i) const { graph->erase(i); }
marci@556
   111
    void erase(const Edge& i) const { graph->erase(i); }
marci@556
   112
  
marci@556
   113
    void clear() const { graph->clear(); }
marci@556
   114
    
marci@739
   115
    int id(const Node& v) const { return graph->id(v); }
marci@739
   116
    int id(const Edge& e) const { return graph->id(e); }
deba@1991
   117
deba@1991
   118
    int maxNodeId() const {
deba@1991
   119
      return graph->maxNodeId();
deba@1991
   120
    }
deba@1991
   121
deba@1991
   122
    int maxEdgeId() const {
deba@1991
   123
      return graph->maxEdgeId();
deba@1991
   124
    }
deba@1991
   125
deba@1991
   126
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
deba@1991
   127
deba@1991
   128
    NodeNotifier& getNotifier(Node) const {
deba@1991
   129
      return graph->getNotifier(Node());
deba@1991
   130
    } 
deba@1991
   131
deba@1991
   132
    typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
deba@1991
   133
deba@1991
   134
    EdgeNotifier& getNotifier(Edge) const {
deba@1991
   135
      return graph->getNotifier(Edge());
deba@1991
   136
    } 
marci@650
   137
    
marci@970
   138
    template <typename _Value>
marci@970
   139
    class NodeMap : public _Graph::template NodeMap<_Value> {
marci@970
   140
    public:
marci@970
   141
      typedef typename _Graph::template NodeMap<_Value> Parent;
deba@1991
   142
      explicit NodeMap(const GraphAdaptorBase<_Graph>& ga) 
deba@1991
   143
	: Parent(*ga.graph) { }
deba@1991
   144
      NodeMap(const GraphAdaptorBase<_Graph>& ga, const _Value& value)
deba@1991
   145
	: Parent(*ga.graph, value) { }
marci@970
   146
    };
marci@556
   147
marci@970
   148
    template <typename _Value>
marci@970
   149
    class EdgeMap : public _Graph::template EdgeMap<_Value> {
marci@970
   150
    public:
marci@970
   151
      typedef typename _Graph::template EdgeMap<_Value> Parent;
deba@1991
   152
      explicit EdgeMap(const GraphAdaptorBase<_Graph>& ga) 
deba@1991
   153
	: Parent(*ga.graph) { }
deba@1991
   154
      EdgeMap(const GraphAdaptorBase<_Graph>& ga, const _Value& value)
deba@1991
   155
	: Parent(*ga.graph, value) { }
marci@970
   156
    };
deba@877
   157
marci@556
   158
  };
marci@556
   159
marci@970
   160
  template <typename _Graph>
alpar@1401
   161
  class GraphAdaptor :
deba@1979
   162
    public GraphAdaptorExtender<GraphAdaptorBase<_Graph> > { 
marci@970
   163
  public:
marci@970
   164
    typedef _Graph Graph;
deba@1979
   165
    typedef GraphAdaptorExtender<GraphAdaptorBase<_Graph> > Parent;
marci@970
   166
  protected:
alpar@1401
   167
    GraphAdaptor() : Parent() { }
marci@569
   168
marci@970
   169
  public:
deba@1755
   170
    explicit GraphAdaptor(Graph& _graph) { setGraph(_graph); }
marci@970
   171
  };
marci@569
   172
deba@1991
   173
  /// \brief Just gives back a graph adaptor
deba@1991
   174
  ///
deba@1991
   175
  /// Just gives back a graph adaptor which 
deba@1991
   176
  /// should be provide original graph
deba@1991
   177
  template<typename Graph>
deba@1991
   178
  GraphAdaptor<const Graph>
deba@1991
   179
  graphAdaptor(const Graph& graph) {
deba@1991
   180
    return GraphAdaptor<const Graph>(graph);
deba@1991
   181
  }
deba@1991
   182
deba@1991
   183
marci@997
   184
  template <typename _Graph>
alpar@1401
   185
  class RevGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
marci@997
   186
  public:
marci@997
   187
    typedef _Graph Graph;
alpar@1401
   188
    typedef GraphAdaptorBase<_Graph> Parent;
marci@997
   189
  protected:
alpar@1401
   190
    RevGraphAdaptorBase() : Parent() { }
marci@997
   191
  public:
marci@997
   192
    typedef typename Parent::Node Node;
marci@997
   193
    typedef typename Parent::Edge Edge;
marci@997
   194
marci@997
   195
    void firstIn(Edge& i, const Node& n) const { Parent::firstOut(i, n); }
marci@997
   196
    void firstOut(Edge& i, const Node& n ) const { Parent::firstIn(i, n); }
marci@997
   197
marci@997
   198
    void nextIn(Edge& i) const { Parent::nextOut(i); }
marci@997
   199
    void nextOut(Edge& i) const { Parent::nextIn(i); }
marci@997
   200
marci@997
   201
    Node source(const Edge& e) const { return Parent::target(e); }
marci@997
   202
    Node target(const Edge& e) const { return Parent::source(e); }
deba@1991
   203
deba@1991
   204
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1991
   205
    Edge findEdge(const Node& source, const Node& target, 
deba@1991
   206
		  const Edge& prev = INVALID) {
deba@1991
   207
      return Parent::findEdge(target, source, prev);
deba@1991
   208
    }
deba@1991
   209
marci@997
   210
  };
marci@997
   211
    
marci@997
   212
alpar@1949
   213
  ///\brief A graph adaptor which reverses the orientation of the edges.
alpar@1949
   214
  ///\ingroup graph_adaptors
alpar@1949
   215
  ///
alpar@1949
   216
  ///\warning Graph adaptors are in even more experimental 
alpar@1949
   217
  ///state than the other
alpar@879
   218
  ///parts of the lib. Use them at you own risk.
alpar@879
   219
  ///
alpar@1949
   220
  /// If \c g is defined as
alpar@1946
   221
  ///\code
marci@923
   222
  /// ListGraph g;
alpar@1946
   223
  ///\endcode
alpar@1949
   224
  /// then
alpar@1946
   225
  ///\code
deba@1991
   226
  /// RevGraphAdaptor<ListGraph> ga(g);
alpar@1946
   227
  ///\endcode
alpar@1949
   228
  ///implements the graph obtained from \c g by 
alpar@1949
   229
  /// reversing the orientation of its edges.
alpar@1946
   230
marci@997
   231
  template<typename _Graph>
alpar@1401
   232
  class RevGraphAdaptor : 
deba@1979
   233
    public GraphAdaptorExtender<RevGraphAdaptorBase<_Graph> > {
marci@650
   234
  public:
marci@997
   235
    typedef _Graph Graph;
deba@1979
   236
    typedef GraphAdaptorExtender<
alpar@1401
   237
      RevGraphAdaptorBase<_Graph> > Parent;
marci@556
   238
  protected:
alpar@1401
   239
    RevGraphAdaptor() { }
marci@556
   240
  public:
deba@1755
   241
    explicit RevGraphAdaptor(_Graph& _graph) { setGraph(_graph); }
marci@997
   242
  };
marci@556
   243
deba@1991
   244
  /// \brief Just gives back a reverse graph adaptor
deba@1991
   245
  ///
deba@1991
   246
  /// Just gives back a reverse graph adaptor
deba@1991
   247
  template<typename Graph>
deba@1991
   248
  RevGraphAdaptor<const Graph>
deba@1991
   249
  revGraphAdaptor(const Graph& graph) {
deba@1991
   250
    return RevGraphAdaptor<const Graph>(graph);
deba@1991
   251
  }
deba@1991
   252
deba@1681
   253
  template <typename _Graph, typename NodeFilterMap, 
deba@1681
   254
	    typename EdgeFilterMap, bool checked = true>
alpar@1401
   255
  class SubGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
marci@992
   256
  public:
marci@992
   257
    typedef _Graph Graph;
alpar@1401
   258
    typedef GraphAdaptorBase<_Graph> Parent;
marci@992
   259
  protected:
marci@992
   260
    NodeFilterMap* node_filter_map;
marci@992
   261
    EdgeFilterMap* edge_filter_map;
alpar@1401
   262
    SubGraphAdaptorBase() : Parent(), 
marci@992
   263
			    node_filter_map(0), edge_filter_map(0) { }
marci@775
   264
marci@992
   265
    void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
marci@992
   266
      node_filter_map=&_node_filter_map;
marci@992
   267
    }
marci@992
   268
    void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
marci@992
   269
      edge_filter_map=&_edge_filter_map;
marci@992
   270
    }
marci@992
   271
marci@992
   272
  public:
marci@992
   273
marci@992
   274
    typedef typename Parent::Node Node;
marci@992
   275
    typedef typename Parent::Edge Edge;
marci@992
   276
marci@992
   277
    void first(Node& i) const { 
marci@992
   278
      Parent::first(i); 
marci@992
   279
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
marci@992
   280
    }
deba@1681
   281
deba@1681
   282
    void first(Edge& i) const { 
deba@1681
   283
      Parent::first(i); 
deba@1681
   284
      while (i!=INVALID && (!(*edge_filter_map)[i] 
deba@1681
   285
	     || !(*node_filter_map)[Parent::source(i)]
deba@1681
   286
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1681
   287
    }
deba@1681
   288
deba@1681
   289
    void firstIn(Edge& i, const Node& n) const { 
deba@1681
   290
      Parent::firstIn(i, n); 
deba@1681
   291
      while (i!=INVALID && (!(*edge_filter_map)[i] 
deba@1681
   292
	     || !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i); 
deba@1681
   293
    }
deba@1681
   294
deba@1681
   295
    void firstOut(Edge& i, const Node& n) const { 
deba@1681
   296
      Parent::firstOut(i, n); 
deba@1681
   297
      while (i!=INVALID && (!(*edge_filter_map)[i] 
deba@1681
   298
	     || !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i); 
deba@1681
   299
    }
deba@1681
   300
deba@1681
   301
    void next(Node& i) const { 
deba@1681
   302
      Parent::next(i); 
deba@1681
   303
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1681
   304
    }
deba@1681
   305
deba@1681
   306
    void next(Edge& i) const { 
deba@1681
   307
      Parent::next(i); 
deba@1681
   308
      while (i!=INVALID && (!(*edge_filter_map)[i] 
deba@1681
   309
	     || !(*node_filter_map)[Parent::source(i)]
deba@1681
   310
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1681
   311
    }
deba@1681
   312
deba@1681
   313
    void nextIn(Edge& i) const { 
deba@1681
   314
      Parent::nextIn(i); 
deba@1681
   315
      while (i!=INVALID && (!(*edge_filter_map)[i] 
deba@1681
   316
	     || !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i); 
deba@1681
   317
    }
deba@1681
   318
deba@1681
   319
    void nextOut(Edge& i) const { 
deba@1681
   320
      Parent::nextOut(i); 
deba@1681
   321
      while (i!=INVALID && (!(*edge_filter_map)[i] 
deba@1681
   322
	     || !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i); 
deba@1681
   323
    }
deba@1681
   324
klao@1951
   325
    ///\e
alpar@1949
   326
klao@1951
   327
    /// This function hides \c n in the graph, i.e. the iteration 
klao@1951
   328
    /// jumps over it. This is done by simply setting the value of \c n  
klao@1951
   329
    /// to be false in the corresponding node-map.
deba@1681
   330
    void hide(const Node& n) const { node_filter_map->set(n, false); }
deba@1681
   331
klao@1951
   332
    ///\e
alpar@1949
   333
klao@1951
   334
    /// This function hides \c e in the graph, i.e. the iteration 
klao@1951
   335
    /// jumps over it. This is done by simply setting the value of \c e  
klao@1951
   336
    /// to be false in the corresponding edge-map.
deba@1681
   337
    void hide(const Edge& e) const { edge_filter_map->set(e, false); }
deba@1681
   338
klao@1951
   339
    ///\e
alpar@1949
   340
klao@1951
   341
    /// The value of \c n is set to be true in the node-map which stores 
klao@1951
   342
    /// hide information. If \c n was hidden previuosly, then it is shown 
klao@1951
   343
    /// again
deba@1681
   344
     void unHide(const Node& n) const { node_filter_map->set(n, true); }
deba@1681
   345
klao@1951
   346
    ///\e
alpar@1949
   347
klao@1951
   348
    /// The value of \c e is set to be true in the edge-map which stores 
klao@1951
   349
    /// hide information. If \c e was hidden previuosly, then it is shown 
klao@1951
   350
    /// again
deba@1681
   351
    void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
deba@1681
   352
klao@1951
   353
    /// Returns true if \c n is hidden.
alpar@1949
   354
    
klao@1951
   355
    ///\e
klao@1951
   356
    ///
deba@1681
   357
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
deba@1681
   358
klao@1951
   359
    /// Returns true if \c n is hidden.
alpar@1949
   360
    
klao@1951
   361
    ///\e
klao@1951
   362
    ///
deba@1681
   363
    bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
deba@1681
   364
deba@1697
   365
    typedef False NodeNumTag;
deba@1697
   366
    typedef False EdgeNumTag;
deba@1991
   367
deba@1991
   368
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1991
   369
    Edge findEdge(const Node& source, const Node& target, 
deba@1991
   370
		  const Edge& prev = INVALID) {
deba@1991
   371
      if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
deba@1991
   372
        return INVALID;
deba@1991
   373
      }
deba@1991
   374
      Edge edge = Parent::findEdge(source, target, prev);
deba@1991
   375
      while (edge != INVALID && !(*edge_filter_map)[edge]) {
deba@1991
   376
        edge = Parent::findEdge(source, target, edge);
deba@1991
   377
      }
deba@1991
   378
      return edge;
deba@1991
   379
    }
deba@1681
   380
  };
deba@1681
   381
deba@1681
   382
  template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1681
   383
  class SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap, false> 
deba@1681
   384
    : public GraphAdaptorBase<_Graph> {
deba@1681
   385
  public:
deba@1681
   386
    typedef _Graph Graph;
deba@1681
   387
    typedef GraphAdaptorBase<_Graph> Parent;
deba@1681
   388
  protected:
deba@1681
   389
    NodeFilterMap* node_filter_map;
deba@1681
   390
    EdgeFilterMap* edge_filter_map;
deba@1681
   391
    SubGraphAdaptorBase() : Parent(), 
deba@1681
   392
			    node_filter_map(0), edge_filter_map(0) { }
deba@1681
   393
deba@1681
   394
    void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
deba@1681
   395
      node_filter_map=&_node_filter_map;
deba@1681
   396
    }
deba@1681
   397
    void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
deba@1681
   398
      edge_filter_map=&_edge_filter_map;
deba@1681
   399
    }
deba@1681
   400
deba@1681
   401
  public:
deba@1681
   402
deba@1681
   403
    typedef typename Parent::Node Node;
deba@1681
   404
    typedef typename Parent::Edge Edge;
deba@1681
   405
deba@1681
   406
    void first(Node& i) const { 
deba@1681
   407
      Parent::first(i); 
deba@1681
   408
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1681
   409
    }
deba@1681
   410
marci@992
   411
    void first(Edge& i) const { 
marci@992
   412
      Parent::first(i); 
marci@992
   413
      while (i!=INVALID && !(*edge_filter_map)[i]) Parent::next(i); 
marci@992
   414
    }
deba@1681
   415
marci@992
   416
    void firstIn(Edge& i, const Node& n) const { 
marci@992
   417
      Parent::firstIn(i, n); 
marci@992
   418
      while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextIn(i); 
marci@992
   419
    }
deba@1681
   420
marci@992
   421
    void firstOut(Edge& i, const Node& n) const { 
marci@992
   422
      Parent::firstOut(i, n); 
marci@992
   423
      while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextOut(i); 
marci@992
   424
    }
marci@992
   425
marci@992
   426
    void next(Node& i) const { 
marci@992
   427
      Parent::next(i); 
marci@992
   428
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
marci@992
   429
    }
marci@992
   430
    void next(Edge& i) const { 
marci@992
   431
      Parent::next(i); 
marci@992
   432
      while (i!=INVALID && !(*edge_filter_map)[i]) Parent::next(i); 
marci@992
   433
    }
marci@992
   434
    void nextIn(Edge& i) const { 
marci@992
   435
      Parent::nextIn(i); 
marci@992
   436
      while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextIn(i); 
marci@992
   437
    }
deba@1681
   438
marci@992
   439
    void nextOut(Edge& i) const { 
marci@992
   440
      Parent::nextOut(i); 
marci@992
   441
      while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextOut(i); 
marci@992
   442
    }
marci@992
   443
klao@1951
   444
    ///\e
alpar@1949
   445
klao@1951
   446
    /// This function hides \c n in the graph, i.e. the iteration 
klao@1951
   447
    /// jumps over it. This is done by simply setting the value of \c n  
klao@1951
   448
    /// to be false in the corresponding node-map.
marci@992
   449
    void hide(const Node& n) const { node_filter_map->set(n, false); }
marci@992
   450
klao@1951
   451
    ///\e
alpar@1949
   452
klao@1951
   453
    /// This function hides \c e in the graph, i.e. the iteration 
klao@1951
   454
    /// jumps over it. This is done by simply setting the value of \c e  
klao@1951
   455
    /// to be false in the corresponding edge-map.
marci@992
   456
    void hide(const Edge& e) const { edge_filter_map->set(e, false); }
marci@992
   457
klao@1951
   458
    ///\e
alpar@1949
   459
klao@1951
   460
    /// The value of \c n is set to be true in the node-map which stores 
klao@1951
   461
    /// hide information. If \c n was hidden previuosly, then it is shown 
klao@1951
   462
    /// again
marci@992
   463
     void unHide(const Node& n) const { node_filter_map->set(n, true); }
marci@992
   464
klao@1951
   465
    ///\e
alpar@1949
   466
klao@1951
   467
    /// The value of \c e is set to be true in the edge-map which stores 
klao@1951
   468
    /// hide information. If \c e was hidden previuosly, then it is shown 
klao@1951
   469
    /// again
marci@992
   470
    void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
marci@992
   471
klao@1951
   472
    /// Returns true if \c n is hidden.
alpar@1949
   473
    
klao@1951
   474
    ///\e
klao@1951
   475
    ///
marci@992
   476
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
marci@992
   477
klao@1951
   478
    /// Returns true if \c n is hidden.
alpar@1949
   479
    
klao@1951
   480
    ///\e
klao@1951
   481
    ///
marci@992
   482
    bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
marci@992
   483
deba@1697
   484
    typedef False NodeNumTag;
deba@1697
   485
    typedef False EdgeNumTag;
deba@1991
   486
deba@1991
   487
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1991
   488
    Edge findEdge(const Node& source, const Node& target, 
deba@1991
   489
		  const Edge& prev = INVALID) {
deba@1991
   490
      if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
deba@1991
   491
        return INVALID;
deba@1991
   492
      }
deba@1991
   493
      Edge edge = Parent::findEdge(source, target, prev);
deba@1991
   494
      while (edge != INVALID && !(*edge_filter_map)[edge]) {
deba@1991
   495
        edge = Parent::findEdge(source, target, edge);
deba@1991
   496
      }
deba@1991
   497
      return edge;
deba@1991
   498
    }
marci@992
   499
  };
marci@775
   500
klao@1951
   501
  /// \brief A graph adaptor for hiding nodes and edges from a graph.
klao@1951
   502
  /// \ingroup graph_adaptors
klao@1951
   503
  /// 
klao@1951
   504
  /// \warning Graph adaptors are in even more experimental state than the
klao@1951
   505
  /// other parts of the lib. Use them at you own risk.
klao@1951
   506
  /// 
klao@1951
   507
  /// SubGraphAdaptor shows the graph with filtered node-set and 
klao@1951
   508
  /// edge-set. If the \c checked parameter is true then it filters the edgeset
klao@1951
   509
  /// to do not get invalid edges without source or target.
klao@1952
   510
  /// Let \f$ G=(V, A) \f$ be a directed graph
klao@1951
   511
  /// and suppose that the graph instance \c g of type ListGraph
klao@1952
   512
  /// implements \f$ G \f$.
klao@1952
   513
  /// Let moreover \f$ b_V \f$ and \f$ b_A \f$ be bool-valued functions resp.
klao@1951
   514
  /// on the node-set and edge-set.
klao@1951
   515
  /// SubGraphAdaptor<...>::NodeIt iterates 
klao@1952
   516
  /// on the node-set \f$ \{v\in V : b_V(v)=true\} \f$ and 
klao@1951
   517
  /// SubGraphAdaptor<...>::EdgeIt iterates 
klao@1952
   518
  /// on the edge-set \f$ \{e\in A : b_A(e)=true\} \f$. Similarly, 
klao@1951
   519
  /// SubGraphAdaptor<...>::OutEdgeIt and
klao@1951
   520
  /// SubGraphAdaptor<...>::InEdgeIt iterates 
klao@1951
   521
  /// only on edges leaving and entering a specific node which have true value.
klao@1951
   522
  /// 
klao@1951
   523
  /// If the \c checked template parameter is false then we have to note that 
klao@1951
   524
  /// the node-iterator cares only the filter on the node-set, and the 
klao@1951
   525
  /// edge-iterator cares only the filter on the edge-set.
klao@1951
   526
  /// This way the edge-map
klao@1951
   527
  /// should filter all edges which's source or target is filtered by the 
klao@1951
   528
  /// node-filter.
alpar@1957
   529
  ///\code
klao@1951
   530
  /// typedef ListGraph Graph;
klao@1951
   531
  /// Graph g;
klao@1951
   532
  /// typedef Graph::Node Node;
klao@1951
   533
  /// typedef Graph::Edge Edge;
klao@1951
   534
  /// Node u=g.addNode(); //node of id 0
klao@1951
   535
  /// Node v=g.addNode(); //node of id 1
klao@1951
   536
  /// Node e=g.addEdge(u, v); //edge of id 0
klao@1951
   537
  /// Node f=g.addEdge(v, u); //edge of id 1
klao@1951
   538
  /// Graph::NodeMap<bool> nm(g, true);
klao@1951
   539
  /// nm.set(u, false);
klao@1951
   540
  /// Graph::EdgeMap<bool> em(g, true);
klao@1951
   541
  /// em.set(e, false);
deba@1991
   542
  /// typedef SubGraphAdaptor<Graph, Graph::NodeMap<bool>, Graph::EdgeMap<bool> > SubGA;
deba@1991
   543
  /// SubGA ga(g, nm, em);
deba@1991
   544
  /// for (SubGA::NodeIt n(ga); n!=INVALID; ++n) std::cout << g.id(n) << std::endl;
klao@1951
   545
  /// std::cout << ":-)" << std::endl;
deba@1991
   546
  /// for (SubGA::EdgeIt e(ga); e!=INVALID; ++e) std::cout << g.id(e) << std::endl;
alpar@1957
   547
  ///\endcode
klao@1951
   548
  /// The output of the above code is the following.
alpar@1957
   549
  ///\code
klao@1951
   550
  /// 1
klao@1951
   551
  /// :-)
klao@1951
   552
  /// 1
alpar@1957
   553
  ///\endcode
deba@1991
   554
  /// Note that \c n is of type \c SubGA::NodeIt, but it can be converted to
klao@1951
   555
  /// \c Graph::Node that is why \c g.id(n) can be applied.
klao@1951
   556
  /// 
klao@1951
   557
  /// For other examples see also the documentation of NodeSubGraphAdaptor and 
klao@1951
   558
  /// EdgeSubGraphAdaptor.
klao@1951
   559
  /// 
klao@1951
   560
  /// \author Marton Makai
marci@1242
   561
marci@992
   562
  template<typename _Graph, typename NodeFilterMap, 
deba@1681
   563
	   typename EdgeFilterMap, bool checked = true>
alpar@1401
   564
  class SubGraphAdaptor : 
deba@1979
   565
    public GraphAdaptorExtender<
deba@1681
   566
    SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap, checked> > {
marci@650
   567
  public:
marci@992
   568
    typedef _Graph Graph;
deba@1979
   569
    typedef GraphAdaptorExtender<
alpar@1401
   570
      SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent;
marci@556
   571
  protected:
alpar@1401
   572
    SubGraphAdaptor() { }
marci@992
   573
  public:
alpar@1401
   574
    SubGraphAdaptor(_Graph& _graph, NodeFilterMap& _node_filter_map, 
marci@992
   575
		    EdgeFilterMap& _edge_filter_map) { 
marci@992
   576
      setGraph(_graph);
marci@992
   577
      setNodeFilterMap(_node_filter_map);
marci@992
   578
      setEdgeFilterMap(_edge_filter_map);
marci@992
   579
    }
marci@992
   580
  };
marci@556
   581
deba@1991
   582
  /// \brief Just gives back a sub graph adaptor
deba@1991
   583
  ///
deba@1991
   584
  /// Just gives back a sub graph adaptor
deba@1991
   585
  template<typename Graph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1991
   586
  SubGraphAdaptor<const Graph, NodeFilterMap, EdgeFilterMap>
deba@1991
   587
  subGraphAdaptor(const Graph& graph, 
deba@1991
   588
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1991
   589
    return SubGraphAdaptor<const Graph, NodeFilterMap, EdgeFilterMap>
deba@1991
   590
      (graph, nfm, efm);
deba@1991
   591
  }
deba@1991
   592
deba@1991
   593
  template<typename Graph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1991
   594
  SubGraphAdaptor<const Graph, const NodeFilterMap, EdgeFilterMap>
deba@1991
   595
  subGraphAdaptor(const Graph& graph, 
deba@1991
   596
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1991
   597
    return SubGraphAdaptor<const Graph, const NodeFilterMap, EdgeFilterMap>
deba@1991
   598
      (graph, nfm, efm);
deba@1991
   599
  }
deba@1991
   600
deba@1991
   601
  template<typename Graph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1991
   602
  SubGraphAdaptor<const Graph, NodeFilterMap, const EdgeFilterMap>
deba@1991
   603
  subGraphAdaptor(const Graph& graph, 
deba@1991
   604
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1991
   605
    return SubGraphAdaptor<const Graph, NodeFilterMap, const EdgeFilterMap>
deba@1991
   606
      (graph, nfm, efm);
deba@1991
   607
  }
deba@1991
   608
deba@1991
   609
  template<typename Graph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1991
   610
  SubGraphAdaptor<const Graph, const NodeFilterMap, const EdgeFilterMap>
deba@1991
   611
  subGraphAdaptor(const Graph& graph, 
deba@1991
   612
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1991
   613
    return SubGraphAdaptor<const Graph, const NodeFilterMap, 
deba@1991
   614
      const EdgeFilterMap>(graph, nfm, efm);
deba@1991
   615
  }
deba@1991
   616
marci@556
   617
marci@569
   618
klao@1951
   619
  ///\brief An adaptor for hiding nodes from a graph.
klao@1951
   620
  ///\ingroup graph_adaptors
klao@1951
   621
  ///
klao@1951
   622
  ///\warning Graph adaptors are in even more experimental state
klao@1951
   623
  ///than the other
klao@1951
   624
  ///parts of the lib. Use them at you own risk.
klao@1951
   625
  ///
klao@1951
   626
  ///An adaptor for hiding nodes from a graph.
klao@1951
   627
  ///This adaptor specializes SubGraphAdaptor in the way that only
klao@1951
   628
  ///the node-set 
klao@1951
   629
  ///can be filtered. In usual case the checked parameter is true, we get the
klao@1951
   630
  ///induced subgraph. But if the checked parameter is false then we can only
klao@1951
   631
  ///filter only isolated nodes.
klao@1951
   632
  ///\author Marton Makai
deba@1681
   633
  template<typename Graph, typename NodeFilterMap, bool checked = true>
alpar@1401
   634
  class NodeSubGraphAdaptor : 
alpar@1401
   635
    public SubGraphAdaptor<Graph, NodeFilterMap, 
deba@1681
   636
			   ConstMap<typename Graph::Edge,bool>, checked> {
marci@933
   637
  public:
alpar@1401
   638
    typedef SubGraphAdaptor<Graph, NodeFilterMap, 
marci@933
   639
			    ConstMap<typename Graph::Edge,bool> > Parent;
marci@933
   640
  protected:
marci@933
   641
    ConstMap<typename Graph::Edge, bool> const_true_map;
deba@1991
   642
deba@1991
   643
    NodeSubGraphAdaptor() : const_true_map(true) {
deba@1991
   644
      Parent::setEdgeFilterMap(const_true_map);
deba@1991
   645
    }
deba@1991
   646
marci@933
   647
  public:
alpar@1401
   648
    NodeSubGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map) : 
marci@933
   649
      Parent(), const_true_map(true) { 
marci@933
   650
      Parent::setGraph(_graph);
marci@933
   651
      Parent::setNodeFilterMap(_node_filter_map);
marci@933
   652
      Parent::setEdgeFilterMap(const_true_map);
marci@933
   653
    }
marci@933
   654
  };
marci@933
   655
marci@933
   656
deba@1991
   657
  /// \brief Just gives back a node sub graph adaptor
deba@1991
   658
  ///
deba@1991
   659
  /// Just gives back a node sub graph adaptor
deba@1991
   660
  template<typename Graph, typename NodeFilterMap>
deba@1991
   661
  NodeSubGraphAdaptor<const Graph, NodeFilterMap>
deba@1991
   662
  nodeSubGraphAdaptor(const Graph& graph, NodeFilterMap& nfm) {
deba@1991
   663
    return NodeSubGraphAdaptor<const Graph, NodeFilterMap>(graph, nfm);
deba@1991
   664
  }
deba@1991
   665
deba@1991
   666
  template<typename Graph, typename NodeFilterMap>
deba@1991
   667
  NodeSubGraphAdaptor<const Graph, const NodeFilterMap>
deba@1991
   668
  nodeSubGraphAdaptor(const Graph& graph, const NodeFilterMap& nfm) {
deba@1991
   669
    return NodeSubGraphAdaptor<const Graph, const NodeFilterMap>(graph, nfm);
deba@1991
   670
  }
deba@1991
   671
klao@1951
   672
  ///\brief An adaptor for hiding edges from a graph.
klao@1951
   673
  ///
klao@1951
   674
  ///\warning Graph adaptors are in even more experimental state
klao@1951
   675
  ///than the other parts of the lib. Use them at you own risk.
klao@1951
   676
  ///
klao@1951
   677
  ///An adaptor for hiding edges from a graph.
klao@1951
   678
  ///This adaptor specializes SubGraphAdaptor in the way that
klao@1951
   679
  ///only the edge-set 
klao@1951
   680
  ///can be filtered. The usefulness of this adaptor is demonstrated in the 
klao@1951
   681
  ///problem of searching a maximum number of edge-disjoint shortest paths 
klao@1951
   682
  ///between 
klao@1951
   683
  ///two nodes \c s and \c t. Shortest here means being shortest w.r.t. 
klao@1951
   684
  ///non-negative edge-lengths. Note that 
klao@1951
   685
  ///the comprehension of the presented solution 
klao@1951
   686
  ///need's some elementary knowledge from combinatorial optimization. 
klao@1951
   687
  ///
klao@1951
   688
  ///If a single shortest path is to be 
klao@1951
   689
  ///searched between \c s and \c t, then this can be done easily by 
klao@1951
   690
  ///applying the Dijkstra algorithm. What happens, if a maximum number of 
klao@1951
   691
  ///edge-disjoint shortest paths is to be computed. It can be proved that an 
klao@1951
   692
  ///edge can be in a shortest path if and only
klao@1951
   693
  ///if it is tight with respect to 
klao@1951
   694
  ///the potential function computed by Dijkstra.
klao@1951
   695
  ///Moreover, any path containing 
klao@1951
   696
  ///only such edges is a shortest one.
klao@1951
   697
  ///Thus we have to compute a maximum number 
klao@1951
   698
  ///of edge-disjoint paths between \c s and \c t in
klao@1951
   699
  ///the graph which has edge-set 
klao@1951
   700
  ///all the tight edges. The computation will be demonstrated
klao@1951
   701
  ///on the following 
klao@1951
   702
  ///graph, which is read from the dimacs file \c sub_graph_adaptor_demo.dim. 
klao@1951
   703
  ///The full source code is available in \ref sub_graph_adaptor_demo.cc. 
klao@1951
   704
  ///If you are interested in more demo programs, you can use 
klao@1951
   705
  ///\ref dim_to_dot.cc to generate .dot files from dimacs files. 
klao@1951
   706
  ///The .dot file of the following figure was generated by  
klao@1951
   707
  ///the demo program \ref dim_to_dot.cc.
klao@1951
   708
  ///
klao@1951
   709
  ///\dot
klao@1951
   710
  ///digraph lemon_dot_example {
klao@1951
   711
  ///node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
klao@1951
   712
  ///n0 [ label="0 (s)" ];
klao@1951
   713
  ///n1 [ label="1" ];
klao@1951
   714
  ///n2 [ label="2" ];
klao@1951
   715
  ///n3 [ label="3" ];
klao@1951
   716
  ///n4 [ label="4" ];
klao@1951
   717
  ///n5 [ label="5" ];
klao@1951
   718
  ///n6 [ label="6 (t)" ];
klao@1951
   719
  ///edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
klao@1951
   720
  ///n5 ->  n6 [ label="9, length:4" ];
klao@1951
   721
  ///n4 ->  n6 [ label="8, length:2" ];
klao@1951
   722
  ///n3 ->  n5 [ label="7, length:1" ];
klao@1951
   723
  ///n2 ->  n5 [ label="6, length:3" ];
klao@1951
   724
  ///n2 ->  n6 [ label="5, length:5" ];
klao@1951
   725
  ///n2 ->  n4 [ label="4, length:2" ];
klao@1951
   726
  ///n1 ->  n4 [ label="3, length:3" ];
klao@1951
   727
  ///n0 ->  n3 [ label="2, length:1" ];
klao@1951
   728
  ///n0 ->  n2 [ label="1, length:2" ];
klao@1951
   729
  ///n0 ->  n1 [ label="0, length:3" ];
klao@1951
   730
  ///}
klao@1951
   731
  ///\enddot
klao@1951
   732
  ///
klao@1951
   733
  ///\code
klao@1951
   734
  ///Graph g;
klao@1951
   735
  ///Node s, t;
klao@1951
   736
  ///LengthMap length(g);
klao@1951
   737
  ///
klao@1951
   738
  ///readDimacs(std::cin, g, length, s, t);
klao@1951
   739
  ///
klao@1951
   740
  ///cout << "edges with lengths (of form id, source--length->target): " << endl;
klao@1951
   741
  ///for(EdgeIt e(g); e!=INVALID; ++e) 
klao@1951
   742
  ///  cout << g.id(e) << ", " << g.id(g.source(e)) << "--" 
klao@1951
   743
  ///       << length[e] << "->" << g.id(g.target(e)) << endl;
klao@1951
   744
  ///
klao@1951
   745
  ///cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
klao@1951
   746
  ///\endcode
klao@1951
   747
  ///Next, the potential function is computed with Dijkstra.
klao@1951
   748
  ///\code
klao@1951
   749
  ///typedef Dijkstra<Graph, LengthMap> Dijkstra;
klao@1951
   750
  ///Dijkstra dijkstra(g, length);
klao@1951
   751
  ///dijkstra.run(s);
klao@1951
   752
  ///\endcode
klao@1951
   753
  ///Next, we consrtruct a map which filters the edge-set to the tight edges.
klao@1951
   754
  ///\code
klao@1951
   755
  ///typedef TightEdgeFilterMap<Graph, const Dijkstra::DistMap, LengthMap> 
klao@1951
   756
  ///  TightEdgeFilter;
klao@1951
   757
  ///TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length);
klao@1951
   758
  ///
deba@1991
   759
  ///typedef EdgeSubGraphAdaptor<Graph, TightEdgeFilter> SubGA;
deba@1991
   760
  ///SubGA ga(g, tight_edge_filter);
klao@1951
   761
  ///\endcode
klao@1951
   762
  ///Then, the maximum nimber of edge-disjoint \c s-\c t paths are computed 
klao@1951
   763
  ///with a max flow algorithm Preflow.
klao@1951
   764
  ///\code
klao@1951
   765
  ///ConstMap<Edge, int> const_1_map(1);
klao@1951
   766
  ///Graph::EdgeMap<int> flow(g, 0);
klao@1951
   767
  ///
deba@1991
   768
  ///Preflow<SubGA, int, ConstMap<Edge, int>, Graph::EdgeMap<int> > 
deba@1991
   769
  ///  preflow(ga, s, t, const_1_map, flow);
klao@1951
   770
  ///preflow.run();
klao@1951
   771
  ///\endcode
klao@1951
   772
  ///Last, the output is:
klao@1951
   773
  ///\code  
klao@1951
   774
  ///cout << "maximum number of edge-disjoint shortest path: " 
klao@1951
   775
  ///     << preflow.flowValue() << endl;
klao@1951
   776
  ///cout << "edges of the maximum number of edge-disjoint shortest s-t paths: " 
klao@1951
   777
  ///     << endl;
klao@1951
   778
  ///for(EdgeIt e(g); e!=INVALID; ++e) 
klao@1951
   779
  ///  if (flow[e])
klao@1951
   780
  ///    cout << " " << g.id(g.source(e)) << "--"
klao@1951
   781
  ///         << length[e] << "->" << g.id(g.target(e)) << endl;
klao@1951
   782
  ///\endcode
klao@1951
   783
  ///The program has the following (expected :-)) output:
klao@1951
   784
  ///\code
klao@1951
   785
  ///edges with lengths (of form id, source--length->target):
klao@1951
   786
  /// 9, 5--4->6
klao@1951
   787
  /// 8, 4--2->6
klao@1951
   788
  /// 7, 3--1->5
klao@1951
   789
  /// 6, 2--3->5
klao@1951
   790
  /// 5, 2--5->6
klao@1951
   791
  /// 4, 2--2->4
klao@1951
   792
  /// 3, 1--3->4
klao@1951
   793
  /// 2, 0--1->3
klao@1951
   794
  /// 1, 0--2->2
klao@1951
   795
  /// 0, 0--3->1
klao@1951
   796
  ///s: 0 t: 6
klao@1951
   797
  ///maximum number of edge-disjoint shortest path: 2
klao@1951
   798
  ///edges of the maximum number of edge-disjoint shortest s-t paths:
klao@1951
   799
  /// 9, 5--4->6
klao@1951
   800
  /// 8, 4--2->6
klao@1951
   801
  /// 7, 3--1->5
klao@1951
   802
  /// 4, 2--2->4
klao@1951
   803
  /// 2, 0--1->3
klao@1951
   804
  /// 1, 0--2->2
klao@1951
   805
  ///\endcode
klao@1951
   806
  ///
klao@1951
   807
  ///\author Marton Makai
marci@932
   808
  template<typename Graph, typename EdgeFilterMap>
alpar@1401
   809
  class EdgeSubGraphAdaptor : 
alpar@1401
   810
    public SubGraphAdaptor<Graph, ConstMap<typename Graph::Node,bool>, 
deba@1681
   811
			   EdgeFilterMap, false> {
marci@932
   812
  public:
alpar@1401
   813
    typedef SubGraphAdaptor<Graph, ConstMap<typename Graph::Node,bool>, 
deba@1685
   814
			    EdgeFilterMap, false> Parent;
marci@932
   815
  protected:
marci@932
   816
    ConstMap<typename Graph::Node, bool> const_true_map;
deba@1991
   817
deba@1991
   818
    EdgeSubGraphAdaptor() : const_true_map(true) {
deba@1991
   819
      Parent::setNodeFilterMap(const_true_map);
deba@1991
   820
    }
deba@1991
   821
marci@932
   822
  public:
alpar@1401
   823
    EdgeSubGraphAdaptor(Graph& _graph, EdgeFilterMap& _edge_filter_map) : 
marci@932
   824
      Parent(), const_true_map(true) { 
marci@932
   825
      Parent::setGraph(_graph);
marci@932
   826
      Parent::setNodeFilterMap(const_true_map);
marci@932
   827
      Parent::setEdgeFilterMap(_edge_filter_map);
marci@932
   828
    }
marci@932
   829
  };
marci@932
   830
deba@1991
   831
  /// \brief Just gives back an edge sub graph adaptor
deba@1991
   832
  ///
deba@1991
   833
  /// Just gives back an edge sub graph adaptor
deba@1991
   834
  template<typename Graph, typename EdgeFilterMap>
deba@1991
   835
  EdgeSubGraphAdaptor<const Graph, EdgeFilterMap>
deba@1991
   836
  edgeSubGraphAdaptor(const Graph& graph, EdgeFilterMap& efm) {
deba@1991
   837
    return EdgeSubGraphAdaptor<const Graph, EdgeFilterMap>(graph, efm);
deba@1991
   838
  }
deba@1991
   839
deba@1991
   840
  template<typename Graph, typename EdgeFilterMap>
deba@1991
   841
  EdgeSubGraphAdaptor<const Graph, const EdgeFilterMap>
deba@1991
   842
  edgeSubGraphAdaptor(const Graph& graph, const EdgeFilterMap& efm) {
deba@1991
   843
    return EdgeSubGraphAdaptor<const Graph, const EdgeFilterMap>(graph, efm);
deba@1991
   844
  }
deba@1991
   845
deba@1991
   846
  template <typename _Graph, typename Enable = void>
deba@1980
   847
  class UndirGraphAdaptorBase : 
deba@1979
   848
    public UGraphBaseExtender<GraphAdaptorBase<_Graph> > {
marci@1383
   849
  public:
marci@1383
   850
    typedef _Graph Graph;
deba@1979
   851
    typedef UGraphBaseExtender<GraphAdaptorBase<_Graph> > Parent;
deba@1991
   852
marci@1383
   853
  protected:
deba@1991
   854
deba@1991
   855
    UndirGraphAdaptorBase() : Parent() {}
deba@1991
   856
marci@1383
   857
  public:
deba@1991
   858
klao@1909
   859
    typedef typename Parent::UEdge UEdge;
marci@1383
   860
    typedef typename Parent::Edge Edge;
deba@1991
   861
marci@1383
   862
    
deba@1991
   863
    template <typename _Value>
marci@1383
   864
    class EdgeMap {
deba@1991
   865
    private:
deba@1991
   866
      
deba@1991
   867
      typedef typename _Graph::template EdgeMap<_Value> MapImpl;
deba@1991
   868
      
marci@1383
   869
    public:
deba@1991
   870
deba@1991
   871
      typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
deba@1991
   872
deba@1991
   873
      typedef _Value Value;
marci@1383
   874
      typedef Edge Key;
marci@1383
   875
      
deba@1991
   876
      EdgeMap(const UndirGraphAdaptorBase<_Graph>& _g) :
deba@1991
   877
	forward_map(*(_g.graph)), backward_map(*(_g.graph)) {}
marci@569
   878
deba@1991
   879
      EdgeMap(const UndirGraphAdaptorBase<_Graph>& _g, const Value& a) 
deba@1991
   880
        : forward_map(*(_g.graph), a), backward_map(*(_g.graph), a) {}
marci@1383
   881
      
deba@1991
   882
      void set(const Edge& e, const Value& a) { 
deba@1991
   883
	if (Parent::direction(e)) {
marci@1383
   884
	  forward_map.set(e, a); 
deba@1991
   885
        } else { 
deba@1991
   886
	  backward_map.set(e, a);
deba@1991
   887
        } 
marci@1383
   888
      }
marci@556
   889
deba@1991
   890
      typename MapTraits<MapImpl>::ConstReturnValue operator[](Edge e) const { 
deba@1991
   891
	if (Parent::direction(e)) {
marci@1383
   892
	  return forward_map[e]; 
deba@1991
   893
	} else { 
marci@1383
   894
	  return backward_map[e]; 
deba@1991
   895
        }
marci@556
   896
      }
deba@1991
   897
deba@1991
   898
      typename MapTraits<MapImpl>::ReturnValue operator[](Edge e) { 
deba@1991
   899
	if (Parent::direction(e)) {
deba@1991
   900
	  return forward_map[e]; 
deba@1991
   901
	} else { 
deba@1991
   902
	  return backward_map[e]; 
deba@1991
   903
        }
deba@1991
   904
      }
deba@1991
   905
deba@1991
   906
    protected:
deba@1991
   907
deba@1991
   908
      MapImpl forward_map, backward_map; 
deba@1991
   909
marci@556
   910
    };
marci@1383
   911
        
deba@1991
   912
    template <typename _Value>
deba@1991
   913
    class UEdgeMap : public _Graph::template EdgeMap<_Value> {
marci@1383
   914
    public:
deba@1991
   915
deba@1991
   916
      typedef typename _Graph::template EdgeMap<_Value> Parent; 
deba@1991
   917
deba@1991
   918
      UEdgeMap(const UndirGraphAdaptorBase<_Graph>& g) 
deba@1991
   919
        : Parent(*(g.graph)) {}
deba@1991
   920
deba@1991
   921
      UEdgeMap(const UndirGraphAdaptorBase<_Graph>& g, const _Value& a) 
deba@1991
   922
        : Parent(*(g.graph), a) {}
marci@1383
   923
      
deba@1991
   924
    };
deba@1991
   925
      
deba@1991
   926
  };
marci@556
   927
deba@1991
   928
  template <typename _Graph>
deba@1991
   929
  class UndirGraphAdaptorBase<
deba@1991
   930
    _Graph, typename enable_if<
deba@1991
   931
    typename _Graph::EdgeNotifier::Notifier>::type > 
deba@1991
   932
      : public UGraphBaseExtender<GraphAdaptorBase<_Graph> > {
deba@1991
   933
  public:
deba@1991
   934
deba@1991
   935
    typedef _Graph Graph;
deba@1991
   936
    typedef UGraphBaseExtender<GraphAdaptorBase<_Graph> > Parent;
deba@1991
   937
deba@1991
   938
  protected:
deba@1991
   939
deba@1991
   940
    UndirGraphAdaptorBase() 
deba@1999
   941
      : edge_notifier(*this), edge_notifier_proxy(edge_notifier) {}
deba@1991
   942
deba@1991
   943
    void setGraph(_Graph& graph) {
deba@1991
   944
      Parent::setGraph(graph);
deba@1991
   945
      edge_notifier_proxy.setUEdgeNotifier(graph.getNotifier(UEdge()));
deba@1991
   946
    }
deba@1991
   947
deba@1991
   948
  public:
deba@1991
   949
deba@1991
   950
    ~UndirGraphAdaptorBase() {
deba@1999
   951
      edge_notifier.clear();
deba@1999
   952
    }
deba@1999
   953
deba@1999
   954
    int maxId(typename Parent::Edge) const {
deba@1999
   955
      return Parent::maxEdgeId();
deba@1991
   956
    }
deba@1991
   957
deba@1991
   958
deba@1991
   959
    typedef typename Parent::UEdge UEdge;
deba@1991
   960
    typedef typename Parent::Edge Edge;
deba@1991
   961
deba@1991
   962
    typedef typename Parent::EdgeNotifier UEdgeNotifier;
deba@1991
   963
deba@1991
   964
    using Parent::getNotifier;
deba@1991
   965
deba@1999
   966
    typedef AlterationNotifier<UndirGraphAdaptorBase, Edge> EdgeNotifier;
deba@1991
   967
    EdgeNotifier& getNotifier(Edge) const { return edge_notifier; }
deba@1991
   968
deba@1991
   969
  protected:
deba@1991
   970
deba@1991
   971
    class NotifierProxy : public UEdgeNotifier::ObserverBase {
deba@1991
   972
    public:
deba@1991
   973
deba@1991
   974
      typedef typename UEdgeNotifier::ObserverBase Parent;
deba@1991
   975
      typedef UndirGraphAdaptorBase AdaptorBase;
marci@1383
   976
      
deba@1991
   977
      NotifierProxy(EdgeNotifier& _edge_notifier)
deba@1991
   978
        : Parent(), edge_notifier(_edge_notifier) {
marci@1383
   979
      }
marci@556
   980
deba@1991
   981
      virtual ~NotifierProxy() {
deba@1991
   982
        if (Parent::attached()) {
deba@1991
   983
          Parent::detach();
deba@1991
   984
        }
marci@1383
   985
      }
deba@1991
   986
deba@1991
   987
      void setUEdgeNotifier(UEdgeNotifier& _uedge_notifier) {
deba@1991
   988
        Parent::attach(_uedge_notifier);
deba@1991
   989
      }
deba@1991
   990
deba@1991
   991
      
deba@1991
   992
    protected:
deba@1991
   993
deba@1991
   994
      virtual void add(const UEdge& uedge) {
deba@1991
   995
        std::vector<Edge> edges;
deba@1991
   996
        edges.push_back(AdaptorBase::Parent::direct(uedge, true));
deba@1991
   997
        edges.push_back(AdaptorBase::Parent::direct(uedge, false));
deba@1991
   998
        edge_notifier.add(edges);
deba@1991
   999
      }
deba@1991
  1000
      virtual void add(const std::vector<UEdge>& uedges) {
deba@1991
  1001
        std::vector<Edge> edges;
deba@1991
  1002
        for (int i = 0; i < (int)uedges.size(); ++i) { 
deba@1991
  1003
          edges.push_back(AdaptorBase::Parent::direct(uedges[i], true));
deba@1991
  1004
          edges.push_back(AdaptorBase::Parent::direct(uedges[i], false));
deba@1991
  1005
        }
deba@1991
  1006
        edge_notifier.add(edges);
deba@1991
  1007
      }
deba@1991
  1008
      virtual void erase(const UEdge& uedge) {
deba@1991
  1009
        std::vector<Edge> edges;
deba@1991
  1010
        edges.push_back(AdaptorBase::Parent::direct(uedge, true));
deba@1991
  1011
        edges.push_back(AdaptorBase::Parent::direct(uedge, false));
deba@1991
  1012
        edge_notifier.erase(edges);
deba@1991
  1013
      }
deba@1991
  1014
      virtual void erase(const std::vector<UEdge>& uedges) {
deba@1991
  1015
        std::vector<Edge> edges;
deba@1991
  1016
        for (int i = 0; i < (int)uedges.size(); ++i) { 
deba@1991
  1017
          edges.push_back(AdaptorBase::Parent::direct(uedges[i], true));
deba@1991
  1018
          edges.push_back(AdaptorBase::Parent::direct(uedges[i], false));
deba@1991
  1019
        }
deba@1991
  1020
        edge_notifier.erase(edges);
deba@1991
  1021
      }
deba@1991
  1022
      virtual void build() {
deba@1991
  1023
        edge_notifier.build();
deba@1991
  1024
      }
deba@1991
  1025
      virtual void clear() {
deba@1991
  1026
        edge_notifier.clear();
deba@1991
  1027
      }
deba@1991
  1028
deba@1991
  1029
      EdgeNotifier& edge_notifier;
deba@1991
  1030
    };
deba@1991
  1031
deba@1991
  1032
deba@1991
  1033
    mutable EdgeNotifier edge_notifier;
deba@1991
  1034
    NotifierProxy edge_notifier_proxy;
deba@1991
  1035
deba@1991
  1036
  public:
deba@1991
  1037
    
deba@1991
  1038
    
deba@1991
  1039
    template <typename _Value>
deba@1991
  1040
    class EdgeMap {
deba@1991
  1041
    private:
deba@1991
  1042
      
deba@1991
  1043
      typedef typename _Graph::template EdgeMap<_Value> MapImpl;
deba@1991
  1044
      
deba@1991
  1045
    public:
deba@1991
  1046
deba@1991
  1047
      typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
deba@1991
  1048
deba@1991
  1049
      typedef _Value Value;
deba@1991
  1050
      typedef Edge Key;
deba@1991
  1051
      
deba@1991
  1052
      EdgeMap(const UndirGraphAdaptorBase<_Graph>& _g) :
deba@1991
  1053
	forward_map(*(_g.graph)), backward_map(*(_g.graph)) {}
deba@1991
  1054
deba@1991
  1055
      EdgeMap(const UndirGraphAdaptorBase<_Graph>& _g, const Value& a) 
deba@1991
  1056
        : forward_map(*(_g.graph), a), backward_map(*(_g.graph), a) {}
deba@1991
  1057
      
deba@1991
  1058
      void set(const Edge& e, const Value& a) { 
deba@1991
  1059
	if (Parent::direction(e)) {
deba@1991
  1060
	  forward_map.set(e, a); 
deba@1991
  1061
        } else { 
deba@1991
  1062
	  backward_map.set(e, a);
deba@1991
  1063
        } 
deba@1991
  1064
      }
deba@1991
  1065
deba@1991
  1066
      typename MapTraits<MapImpl>::ConstReturnValue 
deba@1991
  1067
      operator[](const Edge& e) const { 
deba@1991
  1068
	if (Parent::direction(e)) {
deba@1991
  1069
	  return forward_map[e]; 
deba@1991
  1070
	} else { 
deba@1991
  1071
	  return backward_map[e]; 
deba@1991
  1072
        }
deba@1991
  1073
      }
deba@1991
  1074
deba@1991
  1075
      typename MapTraits<MapImpl>::ReturnValue 
deba@1991
  1076
      operator[](const Edge& e) { 
deba@1991
  1077
	if (Parent::direction(e)) {
deba@1991
  1078
	  return forward_map[e]; 
deba@1991
  1079
	} else { 
deba@1991
  1080
	  return backward_map[e]; 
deba@1991
  1081
        }
deba@1991
  1082
      }
deba@1991
  1083
deba@1991
  1084
    protected:
deba@1991
  1085
deba@1991
  1086
      MapImpl forward_map, backward_map; 
deba@1991
  1087
deba@1991
  1088
    };
deba@1991
  1089
        
deba@1991
  1090
    template <typename _Value>
deba@1991
  1091
    class UEdgeMap : public _Graph::template EdgeMap<_Value> {
deba@1991
  1092
    public:
deba@1991
  1093
deba@1991
  1094
      typedef typename _Graph::template EdgeMap<_Value> Parent; 
deba@1991
  1095
deba@1991
  1096
      UEdgeMap(const UndirGraphAdaptorBase<_Graph>& g) 
deba@1991
  1097
        : Parent(*(g.graph)) {}
deba@1991
  1098
deba@1991
  1099
      UEdgeMap(const UndirGraphAdaptorBase<_Graph>& g, const _Value& a) 
deba@1991
  1100
        : Parent(*(g.graph), a) {}
deba@1991
  1101
      
marci@1383
  1102
    };
marci@1383
  1103
      
marci@1383
  1104
  };
marci@1383
  1105
klao@1951
  1106
  ///\brief An undirected graph is made from a directed graph by an adaptor
klao@1951
  1107
  ///\ingroup graph_adaptors
klao@1951
  1108
  ///
klao@1951
  1109
  /// Undocumented, untested!!!
klao@1951
  1110
  /// If somebody knows nice demo application, let's polulate it.
klao@1951
  1111
  /// 
klao@1951
  1112
  /// \author Marton Makai
marci@1383
  1113
  template<typename _Graph>
deba@1980
  1114
  class UndirGraphAdaptor : 
deba@1979
  1115
    public UGraphAdaptorExtender<
deba@1980
  1116
    UndirGraphAdaptorBase<_Graph> > {
marci@1383
  1117
  public:
marci@1383
  1118
    typedef _Graph Graph;
deba@1979
  1119
    typedef UGraphAdaptorExtender<
deba@1980
  1120
      UndirGraphAdaptorBase<_Graph> > Parent;
marci@1383
  1121
  protected:
deba@1980
  1122
    UndirGraphAdaptor() { }
marci@1383
  1123
  public:
deba@1980
  1124
    UndirGraphAdaptor(_Graph& _graph) { 
marci@1383
  1125
      setGraph(_graph);
marci@556
  1126
    }
marci@556
  1127
deba@1991
  1128
    template <typename _ForwardMap, typename _BackwardMap>
deba@1991
  1129
    class CombinedEdgeMap {
deba@1991
  1130
    public:
deba@1991
  1131
      
deba@1991
  1132
      typedef _ForwardMap ForwardMap;
deba@1991
  1133
      typedef _BackwardMap BackwardMap;
marci@992
  1134
deba@1991
  1135
      typedef typename MapTraits<ForwardMap>::ReferenceMapTag ReferenceMapTag;
marci@992
  1136
deba@1991
  1137
      typedef typename ForwardMap::Value Value;
deba@1991
  1138
      typedef typename Parent::Edge Key;
deba@1991
  1139
      
deba@1991
  1140
      CombinedEdgeMap() : forward_map(0), backward_map(0) {}
marci@992
  1141
deba@1991
  1142
      CombinedEdgeMap(ForwardMap& _forward_map, BackwardMap& _backward_map) 
deba@1991
  1143
        : forward_map(&_forward_map), backward_map(&_backward_map) {}
marci@992
  1144
      
deba@1991
  1145
      void set(const Key& e, const Value& a) { 
deba@1991
  1146
	if (Parent::direction(e)) {
deba@1991
  1147
	  forward_map->set(e, a); 
deba@1991
  1148
        } else { 
deba@1991
  1149
	  backward_map->set(e, a);
deba@1991
  1150
        } 
marci@992
  1151
      }
marci@992
  1152
deba@1991
  1153
      typename MapTraits<ForwardMap>::ConstReturnValue 
deba@1991
  1154
      operator[](const Key& e) const { 
deba@1991
  1155
	if (Parent::direction(e)) {
deba@1991
  1156
	  return (*forward_map)[e]; 
deba@1991
  1157
	} else { 
deba@1991
  1158
	  return (*backward_map)[e]; 
deba@1991
  1159
        }
marci@992
  1160
      }
marci@992
  1161
deba@1991
  1162
      typename MapTraits<ForwardMap>::ReturnValue 
deba@1991
  1163
      operator[](const Key& e) { 
deba@1991
  1164
	if (Parent::direction(e)) {
deba@1991
  1165
	  return (*forward_map)[e]; 
deba@1991
  1166
	} else { 
deba@1991
  1167
	  return (*backward_map)[e]; 
deba@1991
  1168
        }
marci@992
  1169
      }
deba@1991
  1170
deba@1991
  1171
      void setForwardMap(ForwardMap& _forward_map) {
deba@1991
  1172
        forward_map = &_forward_map;
deba@1991
  1173
      }
deba@1991
  1174
deba@1991
  1175
      void setBackwardMap(BackwardMap& _backward_map) {
deba@1991
  1176
        backward_map = &_backward_map;
deba@1991
  1177
      }
deba@1991
  1178
deba@1991
  1179
    protected:
deba@1991
  1180
deba@1991
  1181
      ForwardMap* forward_map;
deba@1991
  1182
      BackwardMap* backward_map; 
deba@1991
  1183
marci@992
  1184
    };
marci@992
  1185
marci@992
  1186
  };
marci@569
  1187
deba@1991
  1188
  /// \brief Just gives back an undir graph adaptor
klao@1951
  1189
  ///
deba@1991
  1190
  /// Just gives back an undir graph adaptor
marci@650
  1191
  template<typename Graph>
deba@1991
  1192
  UndirGraphAdaptor<const Graph>
deba@1991
  1193
  undirGraphAdaptor(const Graph& graph) {
deba@1991
  1194
    return UndirGraphAdaptor<const Graph>(graph);
deba@1991
  1195
  }
marci@650
  1196
marci@650
  1197
  template<typename Graph, typename Number,
marci@650
  1198
	   typename CapacityMap, typename FlowMap>
marci@658
  1199
  class ResForwardFilter {
marci@650
  1200
    const CapacityMap* capacity;
marci@650
  1201
    const FlowMap* flow;
marci@650
  1202
  public:
deba@1991
  1203
    typedef typename Graph::Edge Key;
deba@1991
  1204
    typedef bool Value;
deba@1991
  1205
deba@1991
  1206
    ResForwardFilter(const CapacityMap& _capacity, const FlowMap& _flow) 
deba@1991
  1207
      : capacity(&_capacity), flow(&_flow) { }
deba@1991
  1208
    ResForwardFilter() : capacity(0), flow(0) { }
deba@1991
  1209
    void setCapacity(const CapacityMap& _capacity) { capacity = &_capacity; }
deba@1991
  1210
    void setFlow(const FlowMap& _flow) { flow = &_flow; }
marci@650
  1211
    bool operator[](const typename Graph::Edge& e) const {
marci@738
  1212
      return (Number((*flow)[e]) < Number((*capacity)[e]));
marci@650
  1213
    }
marci@650
  1214
  };
marci@650
  1215
marci@650
  1216
  template<typename Graph, typename Number,
marci@650
  1217
	   typename CapacityMap, typename FlowMap>
marci@658
  1218
  class ResBackwardFilter {
marci@650
  1219
    const CapacityMap* capacity;
marci@650
  1220
    const FlowMap* flow;
marci@650
  1221
  public:
deba@1991
  1222
    typedef typename Graph::Edge Key;
deba@1991
  1223
    typedef bool Value;
deba@1991
  1224
deba@1991
  1225
    ResBackwardFilter(const CapacityMap& _capacity, const FlowMap& _flow) 
deba@1991
  1226
      : capacity(&_capacity), flow(&_flow) { }
deba@1991
  1227
    ResBackwardFilter() : capacity(0), flow(0) { }
deba@1991
  1228
    void setCapacity(const CapacityMap& _capacity) { capacity = &_capacity; }
deba@1991
  1229
    void setFlow(const FlowMap& _flow) { flow = &_flow; }
marci@650
  1230
    bool operator[](const typename Graph::Edge& e) const {
marci@738
  1231
      return (Number(0) < Number((*flow)[e]));
marci@650
  1232
    }
marci@650
  1233
  };
marci@650
  1234
marci@653
  1235
  
klao@1951
  1236
  ///\brief An adaptor for composing the residual
klao@1951
  1237
  ///graph for directed flow and circulation problems.
klao@1951
  1238
  ///\ingroup graph_adaptors
klao@1951
  1239
  ///
klao@1951
  1240
  ///An adaptor for composing the residual graph for
klao@1951
  1241
  ///directed flow and circulation problems. 
klao@1952
  1242
  ///Let \f$ G=(V, A) \f$ be a directed graph and let \f$ F \f$ be a 
klao@1951
  1243
  ///number type. Let moreover 
klao@1952
  1244
  ///\f$ f,c:A\to F \f$, be functions on the edge-set. 
klao@1952
  1245
  ///In the appications of ResGraphAdaptor, \f$ f \f$ usually stands for a flow 
klao@1952
  1246
  ///and \f$ c \f$ for a capacity function.   
klao@1951
  1247
  ///Suppose that a graph instange \c g of type 
klao@1952
  1248
  ///\c ListGraph implements \f$ G \f$.
klao@1951
  1249
  ///\code
klao@1951
  1250
  ///  ListGraph g;
klao@1951
  1251
  ///\endcode
klao@1951
  1252
  ///Then RevGraphAdaptor implements the graph structure with node-set 
klao@1952
  1253
  ///\f$ V \f$ and edge-set \f$ A_{forward}\cup A_{backward} \f$, where 
klao@1952
  1254
  ///\f$ A_{forward}=\{uv : uv\in A, f(uv)<c(uv)\} \f$ and 
klao@1952
  1255
  ///\f$ A_{backward}=\{vu : uv\in A, f(uv)>0\} \f$, 
klao@1951
  1256
  ///i.e. the so called residual graph. 
klao@1952
  1257
  ///When we take the union \f$ A_{forward}\cup A_{backward} \f$, 
klao@1951
  1258
  ///multilicities are counted, i.e. if an edge is in both 
klao@1952
  1259
  ///\f$ A_{forward} \f$ and \f$ A_{backward} \f$, then in the adaptor it 
klao@1951
  1260
  ///appears twice. 
klao@1951
  1261
  ///The following code shows how 
klao@1951
  1262
  ///such an instance can be constructed.
klao@1951
  1263
  ///\code
klao@1951
  1264
  ///typedef ListGraph Graph;
klao@1951
  1265
  ///Graph::EdgeMap<int> f(g);
klao@1951
  1266
  ///Graph::EdgeMap<int> c(g);
deba@1991
  1267
  ///ResGraphAdaptor<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > ga(g);
klao@1951
  1268
  ///\endcode
klao@1951
  1269
  ///\author Marton Makai
klao@1951
  1270
  ///
marci@650
  1271
  template<typename Graph, typename Number, 
marci@650
  1272
	   typename CapacityMap, typename FlowMap>
alpar@1401
  1273
  class ResGraphAdaptor : 
deba@1991
  1274
    public EdgeSubGraphAdaptor< 
deba@1991
  1275
    UndirGraphAdaptor<Graph>, 
deba@1991
  1276
    typename UndirGraphAdaptor<Graph>::template CombinedEdgeMap<
marci@658
  1277
    ResForwardFilter<Graph, Number, CapacityMap, FlowMap>,  
deba@1991
  1278
    ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> > > {
marci@650
  1279
  public:
deba@1991
  1280
deba@1991
  1281
    typedef UndirGraphAdaptor<Graph> UGraph;
deba@1991
  1282
deba@1991
  1283
    typedef ResForwardFilter<Graph, Number, CapacityMap, FlowMap> 
deba@1991
  1284
    ForwardFilter;
deba@1991
  1285
deba@1991
  1286
    typedef ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> 
deba@1991
  1287
    BackwardFilter;
deba@1991
  1288
deba@1991
  1289
    typedef typename UGraph::
deba@1991
  1290
    template CombinedEdgeMap<ForwardFilter, BackwardFilter>
deba@1991
  1291
    EdgeFilter;
deba@1991
  1292
deba@1991
  1293
    typedef EdgeSubGraphAdaptor<UGraph, EdgeFilter> Parent;
deba@1991
  1294
marci@650
  1295
  protected:
deba@1991
  1296
marci@650
  1297
    const CapacityMap* capacity;
marci@650
  1298
    FlowMap* flow;
deba@1991
  1299
deba@1991
  1300
    UGraph ugraph;
deba@1991
  1301
    ForwardFilter forward_filter;
deba@1991
  1302
    BackwardFilter backward_filter;
deba@1991
  1303
    EdgeFilter edge_filter;
deba@1991
  1304
marci@658
  1305
    void setCapacityMap(const CapacityMap& _capacity) {
marci@658
  1306
      capacity=&_capacity;
marci@658
  1307
      forward_filter.setCapacity(_capacity);
marci@658
  1308
      backward_filter.setCapacity(_capacity);
marci@658
  1309
    }
deba@1991
  1310
marci@658
  1311
    void setFlowMap(FlowMap& _flow) {
marci@658
  1312
      flow=&_flow;
marci@658
  1313
      forward_filter.setFlow(_flow);
marci@658
  1314
      backward_filter.setFlow(_flow);
marci@658
  1315
    }
deba@1991
  1316
marci@650
  1317
  public:
deba@1991
  1318
alpar@1401
  1319
    ResGraphAdaptor(Graph& _graph, const CapacityMap& _capacity, 
deba@1991
  1320
                    FlowMap& _flow) 
deba@1991
  1321
      : Parent(), capacity(&_capacity), flow(&_flow),
deba@1991
  1322
        ugraph(_graph),
deba@1991
  1323
        forward_filter(_capacity, _flow), 
deba@1991
  1324
        backward_filter(_capacity, _flow),
deba@1991
  1325
        edge_filter(forward_filter, backward_filter) {
deba@1991
  1326
      Parent::setGraph(ugraph);
deba@1991
  1327
      Parent::setEdgeFilterMap(edge_filter);
marci@650
  1328
    }
marci@650
  1329
marci@660
  1330
    typedef typename Parent::Edge Edge;
marci@660
  1331
marci@660
  1332
    void augment(const Edge& e, Number a) const {
deba@1991
  1333
      if (UGraph::direction(e)) {
marci@650
  1334
	flow->set(e, (*flow)[e]+a);
deba@1991
  1335
      } else {  
marci@650
  1336
	flow->set(e, (*flow)[e]-a);
deba@1991
  1337
      }
marci@650
  1338
    }
marci@650
  1339
deba@1991
  1340
    static bool forward(const Edge& e) {
deba@1991
  1341
      return UGraph::direction(e);
deba@1991
  1342
    }
deba@1991
  1343
deba@1991
  1344
    static bool backward(const Edge& e) {
deba@1991
  1345
      return !UGraph::direction(e);
deba@1991
  1346
    }
deba@1991
  1347
deba@1991
  1348
    static Edge forward(const typename Graph::Edge& e) {
deba@1991
  1349
      return UGraph::direct(e, true);
deba@1991
  1350
    }
deba@1991
  1351
deba@1991
  1352
    static Edge backward(const typename Graph::Edge& e) {
deba@1991
  1353
      return UGraph::direct(e, false);
deba@1991
  1354
    }
deba@1991
  1355
deba@1991
  1356
klao@1951
  1357
    /// \brief Residual capacity map.
klao@1951
  1358
    ///
klao@1951
  1359
    /// In generic residual graphs the residual capacity can be obtained 
klao@1951
  1360
    /// as a map. 
marci@660
  1361
    class ResCap {
marci@660
  1362
    protected:
deba@1991
  1363
      const ResGraphAdaptor* res_graph;
marci@660
  1364
    public:
alpar@987
  1365
      typedef Number Value;
alpar@987
  1366
      typedef Edge Key;
deba@1991
  1367
      ResCap(const ResGraphAdaptor& _res_graph) 
deba@1991
  1368
        : res_graph(&_res_graph) {}
deba@1991
  1369
      
marci@660
  1370
      Number operator[](const Edge& e) const { 
deba@1991
  1371
	if (ResGraphAdaptor::direction(e)) 
marci@660
  1372
	  return (*(res_graph->capacity))[e]-(*(res_graph->flow))[e]; 
marci@660
  1373
	else 
marci@660
  1374
	  return (*(res_graph->flow))[e]; 
marci@660
  1375
      }
deba@1991
  1376
      
marci@660
  1377
    };
marci@660
  1378
marci@650
  1379
  };
marci@650
  1380
marci@650
  1381
marci@998
  1382
marci@998
  1383
  template <typename _Graph, typename FirstOutEdgesMap>
alpar@1401
  1384
  class ErasingFirstGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
marci@998
  1385
  public:
marci@998
  1386
    typedef _Graph Graph;
alpar@1401
  1387
    typedef GraphAdaptorBase<_Graph> Parent;
marci@998
  1388
  protected:
marci@998
  1389
    FirstOutEdgesMap* first_out_edges;
alpar@1401
  1390
    ErasingFirstGraphAdaptorBase() : Parent(), 
marci@998
  1391
				     first_out_edges(0) { }
marci@998
  1392
marci@998
  1393
    void setFirstOutEdgesMap(FirstOutEdgesMap& _first_out_edges) {
marci@998
  1394
      first_out_edges=&_first_out_edges;
marci@998
  1395
    }
marci@998
  1396
marci@998
  1397
  public:
marci@998
  1398
marci@998
  1399
    typedef typename Parent::Node Node;
marci@998
  1400
    typedef typename Parent::Edge Edge;
marci@998
  1401
marci@998
  1402
    void firstOut(Edge& i, const Node& n) const { 
marci@998
  1403
      i=(*first_out_edges)[n];
marci@998
  1404
    }
marci@998
  1405
marci@998
  1406
    void erase(const Edge& e) const {
marci@998
  1407
      Node n=source(e);
marci@998
  1408
      Edge f=e;
marci@998
  1409
      Parent::nextOut(f);
marci@998
  1410
      first_out_edges->set(n, f);
marci@998
  1411
    }    
marci@998
  1412
  };
marci@998
  1413
marci@998
  1414
klao@1951
  1415
  ///\brief For blocking flows.
klao@1951
  1416
  ///\ingroup graph_adaptors
klao@1951
  1417
  ///
klao@1951
  1418
  ///\warning Graph adaptors are in even more
klao@1951
  1419
  ///experimental state than the other
klao@1951
  1420
  ///parts of the lib. Use them at you own risk.
klao@1951
  1421
  ///
klao@1951
  1422
  ///This graph adaptor is used for on-the-fly 
klao@1951
  1423
  ///Dinits blocking flow computations.
klao@1951
  1424
  ///For each node, an out-edge is stored which is used when the 
klao@1951
  1425
  ///\code
klao@1951
  1426
  ///OutEdgeIt& first(OutEdgeIt&, const Node&)
klao@1951
  1427
  ///\endcode
klao@1951
  1428
  ///is called. 
klao@1951
  1429
  ///
klao@1951
  1430
  ///\author Marton Makai
klao@1951
  1431
  ///
marci@998
  1432
  template <typename _Graph, typename FirstOutEdgesMap>
alpar@1401
  1433
  class ErasingFirstGraphAdaptor : 
deba@1979
  1434
    public GraphAdaptorExtender<
alpar@1401
  1435
    ErasingFirstGraphAdaptorBase<_Graph, FirstOutEdgesMap> > {
marci@650
  1436
  public:
marci@998
  1437
    typedef _Graph Graph;
deba@1979
  1438
    typedef GraphAdaptorExtender<
alpar@1401
  1439
      ErasingFirstGraphAdaptorBase<_Graph, FirstOutEdgesMap> > Parent;
alpar@1401
  1440
    ErasingFirstGraphAdaptor(Graph& _graph, 
marci@998
  1441
			     FirstOutEdgesMap& _first_out_edges) { 
marci@998
  1442
      setGraph(_graph);
marci@998
  1443
      setFirstOutEdgesMap(_first_out_edges);
marci@998
  1444
    } 
marci@1019
  1445
marci@998
  1446
  };
marci@556
  1447
deba@1989
  1448
//   template <typename _Graph>
deba@1989
  1449
//   class SplitGraphAdaptorBase 
deba@1989
  1450
//     : public GraphAdaptorBase<_Graph> {
deba@1989
  1451
//   public:
deba@1989
  1452
//     typedef GraphAdaptorBase<_Graph> Parent;
deba@1697
  1453
deba@1989
  1454
//     class Node;
deba@1989
  1455
//     class Edge;
deba@1989
  1456
//     template <typename T> class NodeMap;
deba@1989
  1457
//     template <typename T> class EdgeMap;
deba@1697
  1458
    
deba@1697
  1459
deba@1989
  1460
//     class Node : public Parent::Node {
deba@1989
  1461
//       friend class SplitGraphAdaptorBase;
deba@1989
  1462
//       template <typename T> friend class NodeMap;
deba@1989
  1463
//       typedef typename Parent::Node NodeParent;
deba@1989
  1464
//     private:
deba@1697
  1465
deba@1989
  1466
//       bool entry;
deba@1989
  1467
//       Node(typename Parent::Node _node, bool _entry)
deba@1989
  1468
// 	: Parent::Node(_node), entry(_entry) {}
deba@1697
  1469
      
deba@1989
  1470
//     public:
deba@1989
  1471
//       Node() {}
deba@1989
  1472
//       Node(Invalid) : NodeParent(INVALID), entry(true) {}
deba@1697
  1473
deba@1989
  1474
//       bool operator==(const Node& node) const {
deba@1989
  1475
// 	return NodeParent::operator==(node) && entry == node.entry;
deba@1989
  1476
//       }
deba@1697
  1477
      
deba@1989
  1478
//       bool operator!=(const Node& node) const {
deba@1989
  1479
// 	return !(*this == node);
deba@1989
  1480
//       }
deba@1697
  1481
      
deba@1989
  1482
//       bool operator<(const Node& node) const {
deba@1989
  1483
// 	return NodeParent::operator<(node) || 
deba@1989
  1484
// 	  (NodeParent::operator==(node) && entry < node.entry);
deba@1989
  1485
//       }
deba@1989
  1486
//     };
deba@1697
  1487
deba@1989
  1488
//     /// \todo May we want VARIANT/union type
deba@1989
  1489
//     class Edge : public Parent::Edge {
deba@1989
  1490
//       friend class SplitGraphAdaptorBase;
deba@1989
  1491
//       template <typename T> friend class EdgeMap;
deba@1989
  1492
//     private:
deba@1989
  1493
//       typedef typename Parent::Edge EdgeParent;
deba@1989
  1494
//       typedef typename Parent::Node NodeParent;
deba@1989
  1495
//       NodeParent bind;
deba@1697
  1496
deba@1989
  1497
//       Edge(const EdgeParent& edge, const NodeParent& node)
deba@1989
  1498
// 	: EdgeParent(edge), bind(node) {}
deba@1989
  1499
//     public:
deba@1989
  1500
//       Edge() {}
deba@1989
  1501
//       Edge(Invalid) : EdgeParent(INVALID), bind(INVALID) {}
deba@1697
  1502
deba@1989
  1503
//       bool operator==(const Edge& edge) const {
deba@1989
  1504
// 	return EdgeParent::operator==(edge) && bind == edge.bind;
deba@1989
  1505
//       }
deba@1697
  1506
      
deba@1989
  1507
//       bool operator!=(const Edge& edge) const {
deba@1989
  1508
// 	return !(*this == edge);
deba@1989
  1509
//       }
deba@1697
  1510
      
deba@1989
  1511
//       bool operator<(const Edge& edge) const {
deba@1989
  1512
// 	return EdgeParent::operator<(edge) || 
deba@1989
  1513
// 	  (EdgeParent::operator==(edge) && bind < edge.bind);
deba@1989
  1514
//       }
deba@1989
  1515
//     };
deba@1697
  1516
deba@1989
  1517
//     void first(Node& node) const {
deba@1989
  1518
//       Parent::first(node);
deba@1989
  1519
//       node.entry = true;
deba@1989
  1520
//     } 
deba@1697
  1521
deba@1989
  1522
//     void next(Node& node) const {
deba@1989
  1523
//       if (node.entry) {
deba@1989
  1524
// 	node.entry = false;
deba@1989
  1525
//       } else {
deba@1989
  1526
// 	node.entry = true;
deba@1989
  1527
// 	Parent::next(node);
deba@1989
  1528
//       }
deba@1989
  1529
//     }
deba@1697
  1530
deba@1989
  1531
//     void first(Edge& edge) const {
deba@1989
  1532
//       Parent::first(edge);
deba@1989
  1533
//       if ((typename Parent::Edge&)edge == INVALID) {
deba@1989
  1534
// 	Parent::first(edge.bind);
deba@1989
  1535
//       } else {
deba@1989
  1536
// 	edge.bind = INVALID;
deba@1989
  1537
//       }
deba@1989
  1538
//     }
deba@1697
  1539
deba@1989
  1540
//     void next(Edge& edge) const {
deba@1989
  1541
//       if ((typename Parent::Edge&)edge != INVALID) {
deba@1989
  1542
// 	Parent::next(edge);
deba@1989
  1543
// 	if ((typename Parent::Edge&)edge == INVALID) {
deba@1989
  1544
// 	  Parent::first(edge.bind);
deba@1989
  1545
// 	}
deba@1989
  1546
//       } else {
deba@1989
  1547
// 	Parent::next(edge.bind);
deba@1989
  1548
//       }      
deba@1989
  1549
//     }
deba@1697
  1550
deba@1989
  1551
//     void firstIn(Edge& edge, const Node& node) const {
deba@1989
  1552
//       if (node.entry) {
deba@1989
  1553
// 	Parent::firstIn(edge, node);
deba@1989
  1554
// 	edge.bind = INVALID;
deba@1989
  1555
//       } else {
deba@1989
  1556
// 	(typename Parent::Edge&)edge = INVALID;
deba@1989
  1557
// 	edge.bind = node;
deba@1989
  1558
//       }
deba@1989
  1559
//     }
deba@1697
  1560
deba@1989
  1561
//     void nextIn(Edge& edge) const {
deba@1989
  1562
//       if ((typename Parent::Edge&)edge != INVALID) {
deba@1989
  1563
// 	Parent::nextIn(edge);
deba@1989
  1564
//       } else {
deba@1989
  1565
// 	edge.bind = INVALID;
deba@1989
  1566
//       }      
deba@1989
  1567
//     }
deba@1697
  1568
deba@1989
  1569
//     void firstOut(Edge& edge, const Node& node) const {
deba@1989
  1570
//       if (!node.entry) {
deba@1989
  1571
// 	Parent::firstOut(edge, node);
deba@1989
  1572
// 	edge.bind = INVALID;
deba@1989
  1573
//       } else {
deba@1989
  1574
// 	(typename Parent::Edge&)edge = INVALID;
deba@1989
  1575
// 	edge.bind = node;
deba@1989
  1576
//       }
deba@1989
  1577
//     }
deba@1697
  1578
deba@1989
  1579
//     void nextOut(Edge& edge) const {
deba@1989
  1580
//       if ((typename Parent::Edge&)edge != INVALID) {
deba@1989
  1581
// 	Parent::nextOut(edge);
deba@1989
  1582
//       } else {
deba@1989
  1583
// 	edge.bind = INVALID;
deba@1989
  1584
//       }
deba@1989
  1585
//     }
deba@1697
  1586
deba@1989
  1587
//     Node source(const Edge& edge) const {
deba@1989
  1588
//       if ((typename Parent::Edge&)edge != INVALID) {
deba@1989
  1589
// 	return Node(Parent::source(edge), false);
deba@1989
  1590
//       } else {
deba@1989
  1591
// 	return Node(edge.bind, true);
deba@1989
  1592
//       }
deba@1989
  1593
//     }
deba@1697
  1594
deba@1989
  1595
//     Node target(const Edge& edge) const {
deba@1989
  1596
//       if ((typename Parent::Edge&)edge != INVALID) {
deba@1989
  1597
// 	return Node(Parent::target(edge), true);
deba@1989
  1598
//       } else {
deba@1989
  1599
// 	return Node(edge.bind, false);
deba@1989
  1600
//       }
deba@1989
  1601
//     }
deba@1697
  1602
deba@1989
  1603
//     static bool entryNode(const Node& node) {
deba@1989
  1604
//       return node.entry;
deba@1989
  1605
//     }
deba@1697
  1606
deba@1989
  1607
//     static bool exitNode(const Node& node) {
deba@1989
  1608
//       return !node.entry;
deba@1989
  1609
//     }
deba@1697
  1610
deba@1989
  1611
//     static Node getEntry(const typename Parent::Node& node) {
deba@1989
  1612
//       return Node(node, true);
deba@1989
  1613
//     }
deba@1697
  1614
deba@1989
  1615
//     static Node getExit(const typename Parent::Node& node) {
deba@1989
  1616
//       return Node(node, false);
deba@1989
  1617
//     }
deba@1697
  1618
deba@1989
  1619
//     static bool originalEdge(const Edge& edge) {
deba@1989
  1620
//       return (typename Parent::Edge&)edge != INVALID;
deba@1989
  1621
//     }
deba@1697
  1622
deba@1989
  1623
//     static bool bindingEdge(const Edge& edge) {
deba@1989
  1624
//       return edge.bind != INVALID;
deba@1989
  1625
//     }
deba@1697
  1626
deba@1989
  1627
//     static Node getBindedNode(const Edge& edge) {
deba@1989
  1628
//       return edge.bind;
deba@1989
  1629
//     }
deba@1697
  1630
deba@1989
  1631
//     int nodeNum() const {
deba@1989
  1632
//       return Parent::nodeNum() * 2;
deba@1989
  1633
//     }
deba@1697
  1634
deba@1989
  1635
//     typedef True EdgeNumTag;
deba@1697
  1636
    
deba@1989
  1637
//     int edgeNum() const {
deba@1989
  1638
//       return countEdges() + Parent::nodeNum();
deba@1989
  1639
//     }
deba@1697
  1640
deba@1989
  1641
//     Edge findEdge(const Node& source, const Node& target, 
deba@1989
  1642
// 		  const Edge& prev = INVALID) const {
deba@1989
  1643
//       if (exitNode(source) && entryNode(target)) {
deba@1989
  1644
// 	return Parent::findEdge(source, target, prev);
deba@1989
  1645
//       } else {
deba@1989
  1646
// 	if (prev == INVALID && entryNode(source) && exitNode(target) && 
deba@1989
  1647
// 	    (typename Parent::Node&)source == (typename Parent::Node&)target) {
deba@1989
  1648
// 	  return Edge(INVALID, source);
deba@1989
  1649
// 	} else {
deba@1989
  1650
// 	  return INVALID;
deba@1989
  1651
// 	}
deba@1989
  1652
//       }
deba@1989
  1653
//     }
deba@1697
  1654
    
deba@1989
  1655
//     template <typename T>
deba@1989
  1656
//     class NodeMap : public MapBase<Node, T> {
deba@1989
  1657
//       typedef typename Parent::template NodeMap<T> NodeImpl;
deba@1989
  1658
//     public:
deba@1989
  1659
//       NodeMap(const SplitGraphAdaptorBase& _graph) 
deba@1989
  1660
// 	: entry(_graph), exit(_graph) {}
deba@1989
  1661
//       NodeMap(const SplitGraphAdaptorBase& _graph, const T& t) 
deba@1989
  1662
// 	: entry(_graph, t), exit(_graph, t) {}
deba@1697
  1663
      
deba@1989
  1664
//       void set(const Node& key, const T& val) {
deba@1989
  1665
// 	if (key.entry) { entry.set(key, val); }
deba@1989
  1666
// 	else {exit.set(key, val); }
deba@1989
  1667
//       }
deba@1697
  1668
      
deba@1989
  1669
//       typename MapTraits<NodeImpl>::ReturnValue 
deba@1989
  1670
//       operator[](const Node& key) {
deba@1989
  1671
// 	if (key.entry) { return entry[key]; }
deba@1989
  1672
// 	else { return exit[key]; }
deba@1989
  1673
//       }
deba@1697
  1674
deba@1989
  1675
//       typename MapTraits<NodeImpl>::ConstReturnValue
deba@1989
  1676
//       operator[](const Node& key) const {
deba@1989
  1677
// 	if (key.entry) { return entry[key]; }
deba@1989
  1678
// 	else { return exit[key]; }
deba@1989
  1679
//       }
deba@1697
  1680
deba@1989
  1681
//     private:
deba@1989
  1682
//       NodeImpl entry, exit;
deba@1989
  1683
//     };
deba@1697
  1684
deba@1989
  1685
//     template <typename T>
deba@1989
  1686
//     class EdgeMap : public MapBase<Edge, T> {
deba@1989
  1687
//       typedef typename Parent::template NodeMap<T> NodeImpl;
deba@1989
  1688
//       typedef typename Parent::template EdgeMap<T> EdgeImpl;
deba@1989
  1689
//     public:
deba@1989
  1690
//       EdgeMap(const SplitGraphAdaptorBase& _graph) 
deba@1989
  1691
// 	: bind(_graph), orig(_graph) {}
deba@1989
  1692
//       EdgeMap(const SplitGraphAdaptorBase& _graph, const T& t) 
deba@1989
  1693
// 	: bind(_graph, t), orig(_graph, t) {}
deba@1697
  1694
      
deba@1989
  1695
//       void set(const Edge& key, const T& val) {
deba@1989
  1696
// 	if ((typename Parent::Edge&)key != INVALID) { orig.set(key, val); }
deba@1989
  1697
// 	else {bind.set(key.bind, val); }
deba@1989
  1698
//       }
deba@1697
  1699
      
deba@1989
  1700
//       typename MapTraits<EdgeImpl>::ReturnValue
deba@1989
  1701
//       operator[](const Edge& key) {
deba@1989
  1702
// 	if ((typename Parent::Edge&)key != INVALID) { return orig[key]; }
deba@1989
  1703
// 	else {return bind[key.bind]; }
deba@1989
  1704
//       }
deba@1697
  1705
deba@1989
  1706
//       typename MapTraits<EdgeImpl>::ConstReturnValue
deba@1989
  1707
//       operator[](const Edge& key) const {
deba@1989
  1708
// 	if ((typename Parent::Edge&)key != INVALID) { return orig[key]; }
deba@1989
  1709
// 	else {return bind[key.bind]; }
deba@1989
  1710
//       }
deba@1697
  1711
deba@1989
  1712
//     private:
deba@1989
  1713
//       typename Parent::template NodeMap<T> bind;
deba@1989
  1714
//       typename Parent::template EdgeMap<T> orig;
deba@1989
  1715
//     };
deba@1697
  1716
deba@1989
  1717
//     template <typename EntryMap, typename ExitMap>
deba@1989
  1718
//     class CombinedNodeMap : public MapBase<Node, typename EntryMap::Value> {
deba@1989
  1719
//     public:
deba@1989
  1720
//       typedef MapBase<Node, typename EntryMap::Value> Parent;
deba@1697
  1721
deba@1989
  1722
//       typedef typename Parent::Key Key;
deba@1989
  1723
//       typedef typename Parent::Value Value;
deba@1697
  1724
deba@1989
  1725
//       CombinedNodeMap(EntryMap& _entryMap, ExitMap& _exitMap) 
deba@1989
  1726
// 	: entryMap(_entryMap), exitMap(_exitMap) {}
deba@1697
  1727
deba@1989
  1728
//       Value& operator[](const Key& key) {
deba@1989
  1729
// 	if (key.entry) {
deba@1989
  1730
// 	  return entryMap[key];
deba@1989
  1731
// 	} else {
deba@1989
  1732
// 	  return exitMap[key];
deba@1989
  1733
// 	}
deba@1989
  1734
//       }
deba@1697
  1735
deba@1989
  1736
//       Value operator[](const Key& key) const {
deba@1989
  1737
// 	if (key.entry) {
deba@1989
  1738
// 	  return entryMap[key];
deba@1989
  1739
// 	} else {
deba@1989
  1740
// 	  return exitMap[key];
deba@1989
  1741
// 	}
deba@1989
  1742
//       }
deba@1697
  1743
deba@1989
  1744
//       void set(const Key& key, const Value& value) {
deba@1989
  1745
// 	if (key.entry) {
deba@1989
  1746
// 	  entryMap.set(key, value);
deba@1989
  1747
// 	} else {
deba@1989
  1748
// 	  exitMap.set(key, value);
deba@1989
  1749
// 	}
deba@1989
  1750
//       }
deba@1697
  1751
      
deba@1989
  1752
//     private:
deba@1697
  1753
      
deba@1989
  1754
//       EntryMap& entryMap;
deba@1989
  1755
//       ExitMap& exitMap;
deba@1697
  1756
      
deba@1989
  1757
//     };
deba@1697
  1758
deba@1989
  1759
//     template <typename EdgeMap, typename NodeMap>
deba@1989
  1760
//     class CombinedEdgeMap : public MapBase<Edge, typename EdgeMap::Value> {
deba@1989
  1761
//     public:
deba@1989
  1762
//       typedef MapBase<Edge, typename EdgeMap::Value> Parent;
deba@1697
  1763
deba@1989
  1764
//       typedef typename Parent::Key Key;
deba@1989
  1765
//       typedef typename Parent::Value Value;
deba@1697
  1766
deba@1989
  1767
//       CombinedEdgeMap(EdgeMap& _edgeMap, NodeMap& _nodeMap) 
deba@1989
  1768
// 	: edgeMap(_edgeMap), nodeMap(_nodeMap) {}
deba@1697
  1769
deba@1989
  1770
//       void set(const Edge& edge, const Value& val) {
deba@1989
  1771
// 	if (SplitGraphAdaptorBase::originalEdge(edge)) {
deba@1989
  1772
// 	  edgeMap.set(edge, val);
deba@1989
  1773
// 	} else {
deba@1989
  1774
// 	  nodeMap.set(SplitGraphAdaptorBase::bindedNode(edge), val);
deba@1989
  1775
// 	}
deba@1989
  1776
//       }
deba@1697
  1777
deba@1989
  1778
//       Value operator[](const Key& edge) const {
deba@1989
  1779
// 	if (SplitGraphAdaptorBase::originalEdge(edge)) {
deba@1989
  1780
// 	  return edgeMap[edge];
deba@1989
  1781
// 	} else {
deba@1989
  1782
// 	  return nodeMap[SplitGraphAdaptorBase::bindedNode(edge)];
deba@1989
  1783
// 	}
deba@1989
  1784
//       }      
deba@1697
  1785
deba@1989
  1786
//       Value& operator[](const Key& edge) {
deba@1989
  1787
// 	if (SplitGraphAdaptorBase::originalEdge(edge)) {
deba@1989
  1788
// 	  return edgeMap[edge];
deba@1989
  1789
// 	} else {
deba@1989
  1790
// 	  return nodeMap[SplitGraphAdaptorBase::bindedNode(edge)];
deba@1989
  1791
// 	}
deba@1989
  1792
//       }      
deba@1697
  1793
      
deba@1989
  1794
//     private:
deba@1989
  1795
//       EdgeMap& edgeMap;
deba@1989
  1796
//       NodeMap& nodeMap;
deba@1989
  1797
//     };
deba@1697
  1798
deba@1989
  1799
//   };
deba@1697
  1800
deba@1989
  1801
//   template <typename _Graph>
deba@1989
  1802
//   class SplitGraphAdaptor 
deba@1989
  1803
//     : public GraphAdaptorExtender<SplitGraphAdaptorBase<_Graph> > {
deba@1989
  1804
//   public:
deba@1989
  1805
//     typedef GraphAdaptorExtender<SplitGraphAdaptorBase<_Graph> > Parent;
deba@1697
  1806
deba@1989
  1807
//     SplitGraphAdaptor(_Graph& graph) {
deba@1989
  1808
//       Parent::setGraph(graph);
deba@1989
  1809
//     }
deba@1697
  1810
deba@1697
  1811
deba@1989
  1812
//   };
deba@1697
  1813
alpar@921
  1814
} //namespace lemon
marci@556
  1815
alpar@1401
  1816
#endif //LEMON_GRAPH_ADAPTOR_H
marci@556
  1817