lemon/graph_adaptor.h
author deba
Fri, 29 Sep 2006 11:26:29 +0000
changeset 2224 f973894da54e
parent 2111 ea1fa1bc3f6d
child 2251 37fa5f83251e
permissions -rw-r--r--
Moving the file into correct group
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
deba@2037
    22
///\ingroup graph_adaptors
deba@2037
    23
///\file
deba@2037
    24
///\brief Several graph adaptors.
marci@556
    25
///
deba@2037
    26
///This file contains several useful graph adaptor functions.
marci@556
    27
///
deba@2037
    28
///\author Marton Makai and Balazs Dezso
marci@556
    29
deba@1993
    30
#include <lemon/bits/invalid.h>
deba@2177
    31
#include <lemon/bits/variant.h>
alpar@921
    32
#include <lemon/maps.h>
deba@1979
    33
deba@1999
    34
#include <lemon/bits/base_extender.h>
deba@1979
    35
#include <lemon/bits/graph_adaptor_extender.h>
deba@1791
    36
#include <lemon/bits/graph_extender.h>
deba@1979
    37
deba@2034
    38
#include <lemon/tolerance.h>
deba@2034
    39
deba@2079
    40
#include <algorithm>
marci@556
    41
alpar@921
    42
namespace lemon {
marci@556
    43
klao@1951
    44
  ///\brief Base type for the Graph Adaptors
klao@1951
    45
  ///
klao@1951
    46
  ///Base type for the Graph Adaptors
klao@1951
    47
  ///
klao@1951
    48
  ///This is the base type for most of LEMON graph adaptors. 
klao@1951
    49
  ///This class implements a trivial graph adaptor i.e. it only wraps the 
klao@1951
    50
  ///functions and types of the graph. The purpose of this class is to 
klao@1951
    51
  ///make easier implementing graph adaptors. E.g. if an adaptor is 
klao@1951
    52
  ///considered which differs from the wrapped graph only in some of its 
klao@1951
    53
  ///functions or types, then it can be derived from GraphAdaptor,
klao@1951
    54
  ///and only the 
klao@1951
    55
  ///differences should be implemented.
klao@1951
    56
  ///
klao@1951
    57
  ///author Marton Makai 
marci@970
    58
  template<typename _Graph>
alpar@1401
    59
  class GraphAdaptorBase {
marci@970
    60
  public:
marci@970
    61
    typedef _Graph Graph;
deba@2031
    62
    typedef GraphAdaptorBase Adaptor;
marci@970
    63
    typedef Graph ParentGraph;
marci@970
    64
marci@556
    65
  protected:
marci@556
    66
    Graph* graph;
alpar@1401
    67
    GraphAdaptorBase() : graph(0) { }
marci@556
    68
    void setGraph(Graph& _graph) { graph=&_graph; }
marci@556
    69
marci@556
    70
  public:
alpar@1401
    71
    GraphAdaptorBase(Graph& _graph) : graph(&_graph) { }
deba@2034
    72
alpar@774
    73
    typedef typename Graph::Node Node;
alpar@774
    74
    typedef typename Graph::Edge Edge;
marci@556
    75
   
marci@970
    76
    void first(Node& i) const { graph->first(i); }
marci@970
    77
    void first(Edge& i) const { graph->first(i); }
marci@970
    78
    void firstIn(Edge& i, const Node& n) const { graph->firstIn(i, n); }
marci@970
    79
    void firstOut(Edge& i, const Node& n ) const { graph->firstOut(i, n); }
marci@556
    80
marci@970
    81
    void next(Node& i) const { graph->next(i); }
marci@970
    82
    void next(Edge& i) const { graph->next(i); }
marci@970
    83
    void nextIn(Edge& i) const { graph->nextIn(i); }
marci@970
    84
    void nextOut(Edge& i) const { graph->nextOut(i); }
marci@970
    85
alpar@986
    86
    Node source(const Edge& e) const { return graph->source(e); }
alpar@986
    87
    Node target(const Edge& e) const { return graph->target(e); }
marci@556
    88
deba@1697
    89
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
marci@556
    90
    int nodeNum() const { return graph->nodeNum(); }
deba@1697
    91
    
deba@1697
    92
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
marci@556
    93
    int edgeNum() const { return graph->edgeNum(); }
deba@1697
    94
deba@1697
    95
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1697
    96
    Edge findEdge(const Node& source, const Node& target, 
deba@1697
    97
		  const Edge& prev = INVALID) {
deba@1697
    98
      return graph->findEdge(source, target, prev);
deba@1697
    99
    }
marci@556
   100
  
deba@1697
   101
    Node addNode() const { 
deba@1697
   102
      return Node(graph->addNode()); 
deba@1697
   103
    }
deba@1697
   104
alpar@986
   105
    Edge addEdge(const Node& source, const Node& target) const { 
deba@1697
   106
      return Edge(graph->addEdge(source, target)); 
deba@1697
   107
    }
marci@556
   108
marci@556
   109
    void erase(const Node& i) const { graph->erase(i); }
marci@556
   110
    void erase(const Edge& i) const { graph->erase(i); }
marci@556
   111
  
marci@556
   112
    void clear() const { graph->clear(); }
marci@556
   113
    
marci@739
   114
    int id(const Node& v) const { return graph->id(v); }
marci@739
   115
    int id(const Edge& e) const { return graph->id(e); }
deba@1991
   116
deba@2031
   117
    Node fromNodeId(int id) const {
deba@2031
   118
      return graph->fromNodeId(id);
deba@2031
   119
    }
deba@2031
   120
deba@2031
   121
    Edge fromEdgeId(int id) const {
deba@2031
   122
      return graph->fromEdgeId(id);
deba@2031
   123
    }
deba@2031
   124
deba@1991
   125
    int maxNodeId() const {
deba@1991
   126
      return graph->maxNodeId();
deba@1991
   127
    }
deba@1991
   128
deba@1991
   129
    int maxEdgeId() const {
deba@1991
   130
      return graph->maxEdgeId();
deba@1991
   131
    }
deba@1991
   132
deba@1991
   133
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
deba@1991
   134
deba@1991
   135
    NodeNotifier& getNotifier(Node) const {
deba@1991
   136
      return graph->getNotifier(Node());
deba@1991
   137
    } 
deba@1991
   138
deba@1991
   139
    typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
deba@1991
   140
deba@1991
   141
    EdgeNotifier& getNotifier(Edge) const {
deba@1991
   142
      return graph->getNotifier(Edge());
deba@1991
   143
    } 
marci@650
   144
    
marci@970
   145
    template <typename _Value>
deba@2031
   146
    class NodeMap : public Graph::template NodeMap<_Value> {
marci@970
   147
    public:
deba@2031
   148
deba@2031
   149
      typedef typename Graph::template NodeMap<_Value> Parent;
deba@2031
   150
deba@2031
   151
      explicit NodeMap(const Adaptor& ga) 
deba@2031
   152
	: Parent(*ga.graph) {}
deba@2031
   153
deba@2031
   154
      NodeMap(const Adaptor& ga, const _Value& value)
deba@1991
   155
	: Parent(*ga.graph, value) { }
deba@2031
   156
deba@2031
   157
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
   158
        return operator=<NodeMap>(cmap);
deba@2031
   159
      }
deba@2031
   160
deba@2031
   161
      template <typename CMap>
deba@2031
   162
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   163
        Parent::operator=(cmap);
deba@2031
   164
        return *this;
deba@2031
   165
      }
deba@2031
   166
      
marci@970
   167
    };
marci@556
   168
marci@970
   169
    template <typename _Value>
deba@2031
   170
    class EdgeMap : public Graph::template EdgeMap<_Value> {
marci@970
   171
    public:
deba@2031
   172
      
deba@2031
   173
      typedef typename Graph::template EdgeMap<_Value> Parent;
deba@2031
   174
      
deba@2031
   175
      explicit EdgeMap(const Adaptor& ga) 
deba@2031
   176
	: Parent(*ga.graph) {}
deba@2031
   177
deba@2031
   178
      EdgeMap(const Adaptor& ga, const _Value& value)
deba@2031
   179
	: Parent(*ga.graph, value) {}
deba@2031
   180
deba@2031
   181
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
   182
        return operator=<EdgeMap>(cmap);
deba@2031
   183
      }
deba@2031
   184
deba@2031
   185
      template <typename CMap>
deba@2031
   186
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   187
        Parent::operator=(cmap);
deba@2031
   188
        return *this;
deba@2031
   189
      }
deba@2031
   190
marci@970
   191
    };
deba@877
   192
marci@556
   193
  };
marci@556
   194
deba@2081
   195
  ///\ingroup graph_adaptors
deba@2081
   196
  ///
deba@2081
   197
  ///\brief Trivial Graph Adaptor
deba@2081
   198
  /// 
deba@2081
   199
  /// This class is an adaptor which does not change the adapted graph.
deba@2081
   200
  /// It can be used only to test the graph adaptors.
marci@970
   201
  template <typename _Graph>
alpar@1401
   202
  class GraphAdaptor :
deba@1979
   203
    public GraphAdaptorExtender<GraphAdaptorBase<_Graph> > { 
marci@970
   204
  public:
marci@970
   205
    typedef _Graph Graph;
deba@1979
   206
    typedef GraphAdaptorExtender<GraphAdaptorBase<_Graph> > Parent;
marci@970
   207
  protected:
alpar@1401
   208
    GraphAdaptor() : Parent() { }
marci@569
   209
marci@970
   210
  public:
deba@1755
   211
    explicit GraphAdaptor(Graph& _graph) { setGraph(_graph); }
marci@970
   212
  };
marci@569
   213
deba@1991
   214
  /// \brief Just gives back a graph adaptor
deba@1991
   215
  ///
deba@1991
   216
  /// Just gives back a graph adaptor which 
deba@1991
   217
  /// should be provide original graph
deba@1991
   218
  template<typename Graph>
deba@1991
   219
  GraphAdaptor<const Graph>
deba@1991
   220
  graphAdaptor(const Graph& graph) {
deba@1991
   221
    return GraphAdaptor<const Graph>(graph);
deba@1991
   222
  }
deba@1991
   223
deba@1991
   224
marci@997
   225
  template <typename _Graph>
alpar@1401
   226
  class RevGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
marci@997
   227
  public:
marci@997
   228
    typedef _Graph Graph;
alpar@1401
   229
    typedef GraphAdaptorBase<_Graph> Parent;
marci@997
   230
  protected:
alpar@1401
   231
    RevGraphAdaptorBase() : Parent() { }
marci@997
   232
  public:
marci@997
   233
    typedef typename Parent::Node Node;
marci@997
   234
    typedef typename Parent::Edge Edge;
marci@997
   235
marci@997
   236
    void firstIn(Edge& i, const Node& n) const { Parent::firstOut(i, n); }
marci@997
   237
    void firstOut(Edge& i, const Node& n ) const { Parent::firstIn(i, n); }
marci@997
   238
marci@997
   239
    void nextIn(Edge& i) const { Parent::nextOut(i); }
marci@997
   240
    void nextOut(Edge& i) const { Parent::nextIn(i); }
marci@997
   241
marci@997
   242
    Node source(const Edge& e) const { return Parent::target(e); }
marci@997
   243
    Node target(const Edge& e) const { return Parent::source(e); }
deba@1991
   244
deba@1991
   245
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1991
   246
    Edge findEdge(const Node& source, const Node& target, 
deba@1991
   247
		  const Edge& prev = INVALID) {
deba@1991
   248
      return Parent::findEdge(target, source, prev);
deba@1991
   249
    }
deba@1991
   250
marci@997
   251
  };
marci@997
   252
    
marci@997
   253
deba@2081
   254
  ///\ingroup graph_adaptors
deba@2081
   255
  ///
alpar@1949
   256
  ///\brief A graph adaptor which reverses the orientation of the edges.
alpar@1949
   257
  ///
alpar@1949
   258
  /// If \c g is defined as
alpar@1946
   259
  ///\code
marci@923
   260
  /// ListGraph g;
alpar@1946
   261
  ///\endcode
alpar@1949
   262
  /// then
alpar@1946
   263
  ///\code
deba@1991
   264
  /// RevGraphAdaptor<ListGraph> ga(g);
alpar@1946
   265
  ///\endcode
deba@2079
   266
  /// implements the graph obtained from \c g by 
alpar@1949
   267
  /// reversing the orientation of its edges.
deba@2084
   268
  ///
deba@2084
   269
  /// A good example of using RevGraphAdaptor is to decide that the
deba@2084
   270
  /// directed graph is wheter strongly connected or not. If from one
deba@2084
   271
  /// node each node is reachable and from each node is reachable this
deba@2084
   272
  /// node then and just then the graph is strongly connected. Instead of
deba@2084
   273
  /// this condition we use a little bit different. From one node each node
deba@2084
   274
  /// ahould be reachable in the graph and in the reversed graph. Now this
deba@2084
   275
  /// condition can be checked with the Dfs algorithm class and the
deba@2084
   276
  /// RevGraphAdaptor algorithm class.
deba@2084
   277
  ///
deba@2084
   278
  /// And look at the code:
deba@2084
   279
  ///
deba@2084
   280
  ///\code
deba@2084
   281
  /// bool stronglyConnected(const Graph& graph) {
deba@2084
   282
  ///   if (NodeIt(graph) == INVALID) return true;
deba@2084
   283
  ///   Dfs<Graph> dfs(graph);
deba@2084
   284
  ///   dfs.run(NodeIt(graph));
deba@2084
   285
  ///   for (NodeIt it(graph); it != INVALID; ++it) {
deba@2084
   286
  ///     if (!dfs.reached(it)) {
deba@2084
   287
  ///       return false;
deba@2084
   288
  ///     }
deba@2084
   289
  ///   }
deba@2084
   290
  ///   typedef RevGraphAdaptor<const Graph> RGraph;
deba@2084
   291
  ///   RGraph rgraph(graph);
deba@2084
   292
  ///   DfsVisit<RGraph> rdfs(rgraph);
deba@2084
   293
  ///   rdfs.run(NodeIt(graph));
deba@2084
   294
  ///   for (NodeIt it(graph); it != INVALID; ++it) {
deba@2084
   295
  ///     if (!rdfs.reached(it)) {
deba@2084
   296
  ///       return false;
deba@2084
   297
  ///     }
deba@2084
   298
  ///   }
deba@2084
   299
  ///   return true;
deba@2084
   300
  /// }
deba@2084
   301
  ///\endcode
marci@997
   302
  template<typename _Graph>
alpar@1401
   303
  class RevGraphAdaptor : 
deba@1979
   304
    public GraphAdaptorExtender<RevGraphAdaptorBase<_Graph> > {
marci@650
   305
  public:
marci@997
   306
    typedef _Graph Graph;
deba@1979
   307
    typedef GraphAdaptorExtender<
alpar@1401
   308
      RevGraphAdaptorBase<_Graph> > Parent;
marci@556
   309
  protected:
alpar@1401
   310
    RevGraphAdaptor() { }
marci@556
   311
  public:
deba@1755
   312
    explicit RevGraphAdaptor(_Graph& _graph) { setGraph(_graph); }
marci@997
   313
  };
marci@556
   314
deba@1991
   315
  /// \brief Just gives back a reverse graph adaptor
deba@1991
   316
  ///
deba@1991
   317
  /// Just gives back a reverse graph adaptor
deba@1991
   318
  template<typename Graph>
deba@1991
   319
  RevGraphAdaptor<const Graph>
deba@1991
   320
  revGraphAdaptor(const Graph& graph) {
deba@1991
   321
    return RevGraphAdaptor<const Graph>(graph);
deba@1991
   322
  }
deba@1991
   323
deba@1681
   324
  template <typename _Graph, typename NodeFilterMap, 
deba@1681
   325
	    typename EdgeFilterMap, bool checked = true>
alpar@1401
   326
  class SubGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
marci@992
   327
  public:
marci@992
   328
    typedef _Graph Graph;
deba@2031
   329
    typedef SubGraphAdaptorBase Adaptor;
alpar@1401
   330
    typedef GraphAdaptorBase<_Graph> Parent;
marci@992
   331
  protected:
marci@992
   332
    NodeFilterMap* node_filter_map;
marci@992
   333
    EdgeFilterMap* edge_filter_map;
alpar@1401
   334
    SubGraphAdaptorBase() : Parent(), 
marci@992
   335
			    node_filter_map(0), edge_filter_map(0) { }
marci@775
   336
marci@992
   337
    void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
marci@992
   338
      node_filter_map=&_node_filter_map;
marci@992
   339
    }
marci@992
   340
    void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
marci@992
   341
      edge_filter_map=&_edge_filter_map;
marci@992
   342
    }
marci@992
   343
marci@992
   344
  public:
marci@992
   345
marci@992
   346
    typedef typename Parent::Node Node;
marci@992
   347
    typedef typename Parent::Edge Edge;
marci@992
   348
marci@992
   349
    void first(Node& i) const { 
marci@992
   350
      Parent::first(i); 
marci@992
   351
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
marci@992
   352
    }
deba@1681
   353
deba@1681
   354
    void first(Edge& i) const { 
deba@1681
   355
      Parent::first(i); 
deba@1681
   356
      while (i!=INVALID && (!(*edge_filter_map)[i] 
deba@1681
   357
	     || !(*node_filter_map)[Parent::source(i)]
deba@1681
   358
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1681
   359
    }
deba@1681
   360
deba@1681
   361
    void firstIn(Edge& i, const Node& n) const { 
deba@1681
   362
      Parent::firstIn(i, n); 
deba@1681
   363
      while (i!=INVALID && (!(*edge_filter_map)[i] 
deba@1681
   364
	     || !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i); 
deba@1681
   365
    }
deba@1681
   366
deba@1681
   367
    void firstOut(Edge& i, const Node& n) const { 
deba@1681
   368
      Parent::firstOut(i, n); 
deba@1681
   369
      while (i!=INVALID && (!(*edge_filter_map)[i] 
deba@1681
   370
	     || !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i); 
deba@1681
   371
    }
deba@1681
   372
deba@1681
   373
    void next(Node& i) const { 
deba@1681
   374
      Parent::next(i); 
deba@1681
   375
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1681
   376
    }
deba@1681
   377
deba@1681
   378
    void next(Edge& i) const { 
deba@1681
   379
      Parent::next(i); 
deba@1681
   380
      while (i!=INVALID && (!(*edge_filter_map)[i] 
deba@1681
   381
	     || !(*node_filter_map)[Parent::source(i)]
deba@1681
   382
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1681
   383
    }
deba@1681
   384
deba@1681
   385
    void nextIn(Edge& i) const { 
deba@1681
   386
      Parent::nextIn(i); 
deba@1681
   387
      while (i!=INVALID && (!(*edge_filter_map)[i] 
deba@1681
   388
	     || !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i); 
deba@1681
   389
    }
deba@1681
   390
deba@1681
   391
    void nextOut(Edge& i) const { 
deba@1681
   392
      Parent::nextOut(i); 
deba@1681
   393
      while (i!=INVALID && (!(*edge_filter_map)[i] 
deba@1681
   394
	     || !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i); 
deba@1681
   395
    }
deba@1681
   396
klao@1951
   397
    ///\e
alpar@1949
   398
klao@1951
   399
    /// This function hides \c n in the graph, i.e. the iteration 
klao@1951
   400
    /// jumps over it. This is done by simply setting the value of \c n  
klao@1951
   401
    /// to be false in the corresponding node-map.
deba@1681
   402
    void hide(const Node& n) const { node_filter_map->set(n, false); }
deba@1681
   403
klao@1951
   404
    ///\e
alpar@1949
   405
klao@1951
   406
    /// This function hides \c e in the graph, i.e. the iteration 
klao@1951
   407
    /// jumps over it. This is done by simply setting the value of \c e  
klao@1951
   408
    /// to be false in the corresponding edge-map.
deba@1681
   409
    void hide(const Edge& e) const { edge_filter_map->set(e, false); }
deba@1681
   410
klao@1951
   411
    ///\e
alpar@1949
   412
klao@1951
   413
    /// The value of \c n is set to be true in the node-map which stores 
klao@1951
   414
    /// hide information. If \c n was hidden previuosly, then it is shown 
klao@1951
   415
    /// again
deba@1681
   416
     void unHide(const Node& n) const { node_filter_map->set(n, true); }
deba@1681
   417
klao@1951
   418
    ///\e
alpar@1949
   419
klao@1951
   420
    /// The value of \c e is set to be true in the edge-map which stores 
klao@1951
   421
    /// hide information. If \c e was hidden previuosly, then it is shown 
klao@1951
   422
    /// again
deba@1681
   423
    void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
deba@1681
   424
klao@1951
   425
    /// Returns true if \c n is hidden.
alpar@1949
   426
    
klao@1951
   427
    ///\e
klao@1951
   428
    ///
deba@1681
   429
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
deba@1681
   430
klao@1951
   431
    /// Returns true if \c n is hidden.
alpar@1949
   432
    
klao@1951
   433
    ///\e
klao@1951
   434
    ///
deba@1681
   435
    bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
deba@1681
   436
deba@1697
   437
    typedef False NodeNumTag;
deba@1697
   438
    typedef False EdgeNumTag;
deba@1991
   439
deba@1991
   440
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1991
   441
    Edge findEdge(const Node& source, const Node& target, 
deba@1991
   442
		  const Edge& prev = INVALID) {
deba@1991
   443
      if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
deba@1991
   444
        return INVALID;
deba@1991
   445
      }
deba@1991
   446
      Edge edge = Parent::findEdge(source, target, prev);
deba@1991
   447
      while (edge != INVALID && !(*edge_filter_map)[edge]) {
deba@1991
   448
        edge = Parent::findEdge(source, target, edge);
deba@1991
   449
      }
deba@1991
   450
      return edge;
deba@1991
   451
    }
deba@2031
   452
deba@2031
   453
    template <typename _Value>
deba@2031
   454
    class NodeMap 
deba@2031
   455
      : public SubMapExtender<Adaptor, 
deba@2031
   456
                              typename Parent::template NodeMap<_Value> > 
deba@2031
   457
    {
deba@2031
   458
    public:
deba@2031
   459
      typedef Adaptor Graph;
deba@2031
   460
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   461
                             template NodeMap<_Value> > Parent;
deba@2031
   462
    
deba@2031
   463
      NodeMap(const Graph& graph) 
deba@2031
   464
	: Parent(graph) {}
deba@2031
   465
      NodeMap(const Graph& graph, const _Value& value) 
deba@2031
   466
	: Parent(graph, value) {}
deba@2031
   467
    
deba@2031
   468
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
   469
	return operator=<NodeMap>(cmap);
deba@2031
   470
      }
deba@2031
   471
    
deba@2031
   472
      template <typename CMap>
deba@2031
   473
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   474
        Parent::operator=(cmap);
deba@2031
   475
	return *this;
deba@2031
   476
      }
deba@2031
   477
    };
deba@2031
   478
deba@2031
   479
    template <typename _Value>
deba@2031
   480
    class EdgeMap 
deba@2031
   481
      : public SubMapExtender<Adaptor, 
deba@2031
   482
                              typename Parent::template EdgeMap<_Value> > 
deba@2031
   483
    {
deba@2031
   484
    public:
deba@2031
   485
      typedef Adaptor Graph;
deba@2031
   486
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   487
                             template EdgeMap<_Value> > Parent;
deba@2031
   488
    
deba@2031
   489
      EdgeMap(const Graph& graph) 
deba@2031
   490
	: Parent(graph) {}
deba@2031
   491
      EdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   492
	: Parent(graph, value) {}
deba@2031
   493
    
deba@2031
   494
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
   495
	return operator=<EdgeMap>(cmap);
deba@2031
   496
      }
deba@2031
   497
    
deba@2031
   498
      template <typename CMap>
deba@2031
   499
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   500
        Parent::operator=(cmap);
deba@2031
   501
	return *this;
deba@2031
   502
      }
deba@2031
   503
    };
deba@2031
   504
deba@1681
   505
  };
deba@1681
   506
deba@1681
   507
  template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1681
   508
  class SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap, false> 
deba@1681
   509
    : public GraphAdaptorBase<_Graph> {
deba@1681
   510
  public:
deba@1681
   511
    typedef _Graph Graph;
deba@2031
   512
    typedef SubGraphAdaptorBase Adaptor;
deba@1681
   513
    typedef GraphAdaptorBase<_Graph> Parent;
deba@1681
   514
  protected:
deba@1681
   515
    NodeFilterMap* node_filter_map;
deba@1681
   516
    EdgeFilterMap* edge_filter_map;
deba@1681
   517
    SubGraphAdaptorBase() : Parent(), 
deba@1681
   518
			    node_filter_map(0), edge_filter_map(0) { }
deba@1681
   519
deba@1681
   520
    void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
deba@1681
   521
      node_filter_map=&_node_filter_map;
deba@1681
   522
    }
deba@1681
   523
    void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
deba@1681
   524
      edge_filter_map=&_edge_filter_map;
deba@1681
   525
    }
deba@1681
   526
deba@1681
   527
  public:
deba@1681
   528
deba@1681
   529
    typedef typename Parent::Node Node;
deba@1681
   530
    typedef typename Parent::Edge Edge;
deba@1681
   531
deba@1681
   532
    void first(Node& i) const { 
deba@1681
   533
      Parent::first(i); 
deba@1681
   534
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1681
   535
    }
deba@1681
   536
marci@992
   537
    void first(Edge& i) const { 
marci@992
   538
      Parent::first(i); 
marci@992
   539
      while (i!=INVALID && !(*edge_filter_map)[i]) Parent::next(i); 
marci@992
   540
    }
deba@1681
   541
marci@992
   542
    void firstIn(Edge& i, const Node& n) const { 
marci@992
   543
      Parent::firstIn(i, n); 
marci@992
   544
      while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextIn(i); 
marci@992
   545
    }
deba@1681
   546
marci@992
   547
    void firstOut(Edge& i, const Node& n) const { 
marci@992
   548
      Parent::firstOut(i, n); 
marci@992
   549
      while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextOut(i); 
marci@992
   550
    }
marci@992
   551
marci@992
   552
    void next(Node& i) const { 
marci@992
   553
      Parent::next(i); 
marci@992
   554
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
marci@992
   555
    }
marci@992
   556
    void next(Edge& i) const { 
marci@992
   557
      Parent::next(i); 
marci@992
   558
      while (i!=INVALID && !(*edge_filter_map)[i]) Parent::next(i); 
marci@992
   559
    }
marci@992
   560
    void nextIn(Edge& i) const { 
marci@992
   561
      Parent::nextIn(i); 
marci@992
   562
      while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextIn(i); 
marci@992
   563
    }
deba@1681
   564
marci@992
   565
    void nextOut(Edge& i) const { 
marci@992
   566
      Parent::nextOut(i); 
marci@992
   567
      while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextOut(i); 
marci@992
   568
    }
marci@992
   569
klao@1951
   570
    ///\e
alpar@1949
   571
klao@1951
   572
    /// This function hides \c n in the graph, i.e. the iteration 
klao@1951
   573
    /// jumps over it. This is done by simply setting the value of \c n  
klao@1951
   574
    /// to be false in the corresponding node-map.
marci@992
   575
    void hide(const Node& n) const { node_filter_map->set(n, false); }
marci@992
   576
klao@1951
   577
    ///\e
alpar@1949
   578
klao@1951
   579
    /// This function hides \c e in the graph, i.e. the iteration 
klao@1951
   580
    /// jumps over it. This is done by simply setting the value of \c e  
klao@1951
   581
    /// to be false in the corresponding edge-map.
marci@992
   582
    void hide(const Edge& e) const { edge_filter_map->set(e, false); }
marci@992
   583
klao@1951
   584
    ///\e
alpar@1949
   585
klao@1951
   586
    /// The value of \c n is set to be true in the node-map which stores 
klao@1951
   587
    /// hide information. If \c n was hidden previuosly, then it is shown 
klao@1951
   588
    /// again
marci@992
   589
     void unHide(const Node& n) const { node_filter_map->set(n, true); }
marci@992
   590
klao@1951
   591
    ///\e
alpar@1949
   592
klao@1951
   593
    /// The value of \c e is set to be true in the edge-map which stores 
klao@1951
   594
    /// hide information. If \c e was hidden previuosly, then it is shown 
klao@1951
   595
    /// again
marci@992
   596
    void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
marci@992
   597
klao@1951
   598
    /// Returns true if \c n is hidden.
alpar@1949
   599
    
klao@1951
   600
    ///\e
klao@1951
   601
    ///
marci@992
   602
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
marci@992
   603
klao@1951
   604
    /// Returns true if \c n is hidden.
alpar@1949
   605
    
klao@1951
   606
    ///\e
klao@1951
   607
    ///
marci@992
   608
    bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
marci@992
   609
deba@1697
   610
    typedef False NodeNumTag;
deba@1697
   611
    typedef False EdgeNumTag;
deba@1991
   612
deba@1991
   613
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1991
   614
    Edge findEdge(const Node& source, const Node& target, 
deba@1991
   615
		  const Edge& prev = INVALID) {
deba@1991
   616
      if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
deba@1991
   617
        return INVALID;
deba@1991
   618
      }
deba@1991
   619
      Edge edge = Parent::findEdge(source, target, prev);
deba@1991
   620
      while (edge != INVALID && !(*edge_filter_map)[edge]) {
deba@1991
   621
        edge = Parent::findEdge(source, target, edge);
deba@1991
   622
      }
deba@1991
   623
      return edge;
deba@1991
   624
    }
deba@2031
   625
deba@2031
   626
    template <typename _Value>
deba@2031
   627
    class NodeMap 
deba@2031
   628
      : public SubMapExtender<Adaptor, 
deba@2031
   629
                              typename Parent::template NodeMap<_Value> > 
deba@2031
   630
    {
deba@2031
   631
    public:
deba@2031
   632
      typedef Adaptor Graph;
deba@2031
   633
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   634
                             template NodeMap<_Value> > Parent;
deba@2031
   635
    
deba@2031
   636
      NodeMap(const Graph& graph) 
deba@2031
   637
	: Parent(graph) {}
deba@2031
   638
      NodeMap(const Graph& graph, const _Value& value) 
deba@2031
   639
	: Parent(graph, value) {}
deba@2031
   640
    
deba@2031
   641
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
   642
	return operator=<NodeMap>(cmap);
deba@2031
   643
      }
deba@2031
   644
    
deba@2031
   645
      template <typename CMap>
deba@2031
   646
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   647
        Parent::operator=(cmap);
deba@2031
   648
	return *this;
deba@2031
   649
      }
deba@2031
   650
    };
deba@2031
   651
deba@2031
   652
    template <typename _Value>
deba@2031
   653
    class EdgeMap 
deba@2031
   654
      : public SubMapExtender<Adaptor, 
deba@2031
   655
                              typename Parent::template EdgeMap<_Value> > 
deba@2031
   656
    {
deba@2031
   657
    public:
deba@2031
   658
      typedef Adaptor Graph;
deba@2031
   659
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   660
                             template EdgeMap<_Value> > Parent;
deba@2031
   661
    
deba@2031
   662
      EdgeMap(const Graph& graph) 
deba@2031
   663
	: Parent(graph) {}
deba@2031
   664
      EdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   665
	: Parent(graph, value) {}
deba@2031
   666
    
deba@2031
   667
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
   668
	return operator=<EdgeMap>(cmap);
deba@2031
   669
      }
deba@2031
   670
    
deba@2031
   671
      template <typename CMap>
deba@2031
   672
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   673
        Parent::operator=(cmap);
deba@2031
   674
	return *this;
deba@2031
   675
      }
deba@2031
   676
    };
deba@2031
   677
marci@992
   678
  };
marci@775
   679
deba@2081
   680
  /// \ingroup graph_adaptors
deba@2081
   681
  ///
klao@1951
   682
  /// \brief A graph adaptor for hiding nodes and edges from a graph.
klao@1951
   683
  /// 
klao@1951
   684
  /// SubGraphAdaptor shows the graph with filtered node-set and 
klao@1951
   685
  /// edge-set. If the \c checked parameter is true then it filters the edgeset
klao@1951
   686
  /// to do not get invalid edges without source or target.
klao@1952
   687
  /// Let \f$ G=(V, A) \f$ be a directed graph
klao@1951
   688
  /// and suppose that the graph instance \c g of type ListGraph
klao@1952
   689
  /// implements \f$ G \f$.
klao@1952
   690
  /// Let moreover \f$ b_V \f$ and \f$ b_A \f$ be bool-valued functions resp.
klao@1951
   691
  /// on the node-set and edge-set.
klao@1951
   692
  /// SubGraphAdaptor<...>::NodeIt iterates 
klao@1952
   693
  /// on the node-set \f$ \{v\in V : b_V(v)=true\} \f$ and 
klao@1951
   694
  /// SubGraphAdaptor<...>::EdgeIt iterates 
klao@1952
   695
  /// on the edge-set \f$ \{e\in A : b_A(e)=true\} \f$. Similarly, 
klao@1951
   696
  /// SubGraphAdaptor<...>::OutEdgeIt and
klao@1951
   697
  /// SubGraphAdaptor<...>::InEdgeIt iterates 
klao@1951
   698
  /// only on edges leaving and entering a specific node which have true value.
klao@1951
   699
  /// 
klao@1951
   700
  /// If the \c checked template parameter is false then we have to note that 
klao@1951
   701
  /// the node-iterator cares only the filter on the node-set, and the 
klao@1951
   702
  /// edge-iterator cares only the filter on the edge-set.
klao@1951
   703
  /// This way the edge-map
klao@1951
   704
  /// should filter all edges which's source or target is filtered by the 
klao@1951
   705
  /// node-filter.
alpar@1957
   706
  ///\code
klao@1951
   707
  /// typedef ListGraph Graph;
klao@1951
   708
  /// Graph g;
klao@1951
   709
  /// typedef Graph::Node Node;
klao@1951
   710
  /// typedef Graph::Edge Edge;
klao@1951
   711
  /// Node u=g.addNode(); //node of id 0
klao@1951
   712
  /// Node v=g.addNode(); //node of id 1
klao@1951
   713
  /// Node e=g.addEdge(u, v); //edge of id 0
klao@1951
   714
  /// Node f=g.addEdge(v, u); //edge of id 1
klao@1951
   715
  /// Graph::NodeMap<bool> nm(g, true);
klao@1951
   716
  /// nm.set(u, false);
klao@1951
   717
  /// Graph::EdgeMap<bool> em(g, true);
klao@1951
   718
  /// em.set(e, false);
deba@1991
   719
  /// typedef SubGraphAdaptor<Graph, Graph::NodeMap<bool>, Graph::EdgeMap<bool> > SubGA;
deba@1991
   720
  /// SubGA ga(g, nm, em);
deba@1991
   721
  /// for (SubGA::NodeIt n(ga); n!=INVALID; ++n) std::cout << g.id(n) << std::endl;
klao@1951
   722
  /// std::cout << ":-)" << std::endl;
deba@1991
   723
  /// for (SubGA::EdgeIt e(ga); e!=INVALID; ++e) std::cout << g.id(e) << std::endl;
alpar@1957
   724
  ///\endcode
klao@1951
   725
  /// The output of the above code is the following.
alpar@1957
   726
  ///\code
klao@1951
   727
  /// 1
klao@1951
   728
  /// :-)
klao@1951
   729
  /// 1
alpar@1957
   730
  ///\endcode
deba@1991
   731
  /// Note that \c n is of type \c SubGA::NodeIt, but it can be converted to
klao@1951
   732
  /// \c Graph::Node that is why \c g.id(n) can be applied.
klao@1951
   733
  /// 
klao@1951
   734
  /// For other examples see also the documentation of NodeSubGraphAdaptor and 
klao@1951
   735
  /// EdgeSubGraphAdaptor.
klao@1951
   736
  /// 
klao@1951
   737
  /// \author Marton Makai
marci@1242
   738
marci@992
   739
  template<typename _Graph, typename NodeFilterMap, 
deba@1681
   740
	   typename EdgeFilterMap, bool checked = true>
alpar@1401
   741
  class SubGraphAdaptor : 
deba@1979
   742
    public GraphAdaptorExtender<
deba@1681
   743
    SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap, checked> > {
marci@650
   744
  public:
marci@992
   745
    typedef _Graph Graph;
deba@2031
   746
    typedef GraphAdaptorExtender< SubGraphAdaptorBase<_Graph, NodeFilterMap, 
deba@2031
   747
                                                      EdgeFilterMap, checked> >
deba@2031
   748
    Parent;
deba@2031
   749
marci@556
   750
  protected:
alpar@1401
   751
    SubGraphAdaptor() { }
marci@992
   752
  public:
deba@2031
   753
alpar@1401
   754
    SubGraphAdaptor(_Graph& _graph, NodeFilterMap& _node_filter_map, 
marci@992
   755
		    EdgeFilterMap& _edge_filter_map) { 
marci@992
   756
      setGraph(_graph);
marci@992
   757
      setNodeFilterMap(_node_filter_map);
marci@992
   758
      setEdgeFilterMap(_edge_filter_map);
marci@992
   759
    }
deba@2031
   760
marci@992
   761
  };
marci@556
   762
deba@1991
   763
  /// \brief Just gives back a sub graph adaptor
deba@1991
   764
  ///
deba@1991
   765
  /// Just gives back a sub graph adaptor
deba@1991
   766
  template<typename Graph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1991
   767
  SubGraphAdaptor<const Graph, NodeFilterMap, EdgeFilterMap>
deba@1991
   768
  subGraphAdaptor(const Graph& graph, 
deba@1991
   769
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1991
   770
    return SubGraphAdaptor<const Graph, NodeFilterMap, EdgeFilterMap>
deba@1991
   771
      (graph, nfm, efm);
deba@1991
   772
  }
deba@1991
   773
deba@1991
   774
  template<typename Graph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1991
   775
  SubGraphAdaptor<const Graph, const NodeFilterMap, EdgeFilterMap>
deba@1991
   776
  subGraphAdaptor(const Graph& graph, 
deba@1991
   777
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1991
   778
    return SubGraphAdaptor<const Graph, const NodeFilterMap, EdgeFilterMap>
deba@1991
   779
      (graph, nfm, efm);
deba@1991
   780
  }
deba@1991
   781
deba@1991
   782
  template<typename Graph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1991
   783
  SubGraphAdaptor<const Graph, NodeFilterMap, const EdgeFilterMap>
deba@1991
   784
  subGraphAdaptor(const Graph& graph, 
deba@1991
   785
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1991
   786
    return SubGraphAdaptor<const Graph, NodeFilterMap, const EdgeFilterMap>
deba@1991
   787
      (graph, nfm, efm);
deba@1991
   788
  }
deba@1991
   789
deba@1991
   790
  template<typename Graph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1991
   791
  SubGraphAdaptor<const Graph, const NodeFilterMap, const EdgeFilterMap>
deba@1991
   792
  subGraphAdaptor(const Graph& graph, 
deba@1991
   793
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1991
   794
    return SubGraphAdaptor<const Graph, const NodeFilterMap, 
deba@1991
   795
      const EdgeFilterMap>(graph, nfm, efm);
deba@1991
   796
  }
deba@1991
   797
marci@556
   798
marci@569
   799
deba@2081
   800
  ///\ingroup graph_adaptors
deba@2081
   801
  ///
klao@1951
   802
  ///\brief An adaptor for hiding nodes from a graph.
klao@1951
   803
  ///
klao@1951
   804
  ///An adaptor for hiding nodes from a graph.
klao@1951
   805
  ///This adaptor specializes SubGraphAdaptor in the way that only
klao@1951
   806
  ///the node-set 
klao@1951
   807
  ///can be filtered. In usual case the checked parameter is true, we get the
klao@1951
   808
  ///induced subgraph. But if the checked parameter is false then we can only
klao@1951
   809
  ///filter only isolated nodes.
klao@1951
   810
  ///\author Marton Makai
deba@1681
   811
  template<typename Graph, typename NodeFilterMap, bool checked = true>
alpar@1401
   812
  class NodeSubGraphAdaptor : 
alpar@1401
   813
    public SubGraphAdaptor<Graph, NodeFilterMap, 
deba@1681
   814
			   ConstMap<typename Graph::Edge,bool>, checked> {
marci@933
   815
  public:
deba@2031
   816
alpar@1401
   817
    typedef SubGraphAdaptor<Graph, NodeFilterMap, 
deba@2031
   818
			    ConstMap<typename Graph::Edge,bool>, checked > 
deba@2031
   819
    Parent;
deba@2031
   820
marci@933
   821
  protected:
marci@933
   822
    ConstMap<typename Graph::Edge, bool> const_true_map;
deba@1991
   823
deba@1991
   824
    NodeSubGraphAdaptor() : const_true_map(true) {
deba@1991
   825
      Parent::setEdgeFilterMap(const_true_map);
deba@1991
   826
    }
deba@1991
   827
marci@933
   828
  public:
deba@2031
   829
alpar@1401
   830
    NodeSubGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map) : 
marci@933
   831
      Parent(), const_true_map(true) { 
marci@933
   832
      Parent::setGraph(_graph);
marci@933
   833
      Parent::setNodeFilterMap(_node_filter_map);
marci@933
   834
      Parent::setEdgeFilterMap(const_true_map);
marci@933
   835
    }
deba@2031
   836
marci@933
   837
  };
marci@933
   838
marci@933
   839
deba@1991
   840
  /// \brief Just gives back a node sub graph adaptor
deba@1991
   841
  ///
deba@1991
   842
  /// Just gives back a node sub graph adaptor
deba@1991
   843
  template<typename Graph, typename NodeFilterMap>
deba@1991
   844
  NodeSubGraphAdaptor<const Graph, NodeFilterMap>
deba@1991
   845
  nodeSubGraphAdaptor(const Graph& graph, NodeFilterMap& nfm) {
deba@1991
   846
    return NodeSubGraphAdaptor<const Graph, NodeFilterMap>(graph, nfm);
deba@1991
   847
  }
deba@1991
   848
deba@1991
   849
  template<typename Graph, typename NodeFilterMap>
deba@1991
   850
  NodeSubGraphAdaptor<const Graph, const NodeFilterMap>
deba@1991
   851
  nodeSubGraphAdaptor(const Graph& graph, const NodeFilterMap& nfm) {
deba@1991
   852
    return NodeSubGraphAdaptor<const Graph, const NodeFilterMap>(graph, nfm);
deba@1991
   853
  }
deba@1991
   854
deba@2081
   855
  ///\ingroup graph_adaptors
deba@2081
   856
  ///
klao@1951
   857
  ///\brief An adaptor for hiding edges from a graph.
klao@1951
   858
  ///
klao@1951
   859
  ///An adaptor for hiding edges from a graph.
klao@1951
   860
  ///This adaptor specializes SubGraphAdaptor in the way that
klao@1951
   861
  ///only the edge-set 
klao@1951
   862
  ///can be filtered. The usefulness of this adaptor is demonstrated in the 
klao@1951
   863
  ///problem of searching a maximum number of edge-disjoint shortest paths 
klao@1951
   864
  ///between 
klao@1951
   865
  ///two nodes \c s and \c t. Shortest here means being shortest w.r.t. 
klao@1951
   866
  ///non-negative edge-lengths. Note that 
klao@1951
   867
  ///the comprehension of the presented solution 
klao@1951
   868
  ///need's some elementary knowledge from combinatorial optimization. 
klao@1951
   869
  ///
klao@1951
   870
  ///If a single shortest path is to be 
klao@1951
   871
  ///searched between \c s and \c t, then this can be done easily by 
klao@1951
   872
  ///applying the Dijkstra algorithm. What happens, if a maximum number of 
klao@1951
   873
  ///edge-disjoint shortest paths is to be computed. It can be proved that an 
klao@1951
   874
  ///edge can be in a shortest path if and only
klao@1951
   875
  ///if it is tight with respect to 
klao@1951
   876
  ///the potential function computed by Dijkstra.
klao@1951
   877
  ///Moreover, any path containing 
klao@1951
   878
  ///only such edges is a shortest one.
klao@1951
   879
  ///Thus we have to compute a maximum number 
klao@1951
   880
  ///of edge-disjoint paths between \c s and \c t in
klao@1951
   881
  ///the graph which has edge-set 
klao@1951
   882
  ///all the tight edges. The computation will be demonstrated
klao@1951
   883
  ///on the following 
klao@1951
   884
  ///graph, which is read from the dimacs file \c sub_graph_adaptor_demo.dim. 
klao@1951
   885
  ///The full source code is available in \ref sub_graph_adaptor_demo.cc. 
klao@1951
   886
  ///If you are interested in more demo programs, you can use 
klao@1951
   887
  ///\ref dim_to_dot.cc to generate .dot files from dimacs files. 
klao@1951
   888
  ///The .dot file of the following figure was generated by  
klao@1951
   889
  ///the demo program \ref dim_to_dot.cc.
klao@1951
   890
  ///
klao@1951
   891
  ///\dot
klao@1951
   892
  ///digraph lemon_dot_example {
klao@1951
   893
  ///node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
klao@1951
   894
  ///n0 [ label="0 (s)" ];
klao@1951
   895
  ///n1 [ label="1" ];
klao@1951
   896
  ///n2 [ label="2" ];
klao@1951
   897
  ///n3 [ label="3" ];
klao@1951
   898
  ///n4 [ label="4" ];
klao@1951
   899
  ///n5 [ label="5" ];
klao@1951
   900
  ///n6 [ label="6 (t)" ];
klao@1951
   901
  ///edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
klao@1951
   902
  ///n5 ->  n6 [ label="9, length:4" ];
klao@1951
   903
  ///n4 ->  n6 [ label="8, length:2" ];
klao@1951
   904
  ///n3 ->  n5 [ label="7, length:1" ];
klao@1951
   905
  ///n2 ->  n5 [ label="6, length:3" ];
klao@1951
   906
  ///n2 ->  n6 [ label="5, length:5" ];
klao@1951
   907
  ///n2 ->  n4 [ label="4, length:2" ];
klao@1951
   908
  ///n1 ->  n4 [ label="3, length:3" ];
klao@1951
   909
  ///n0 ->  n3 [ label="2, length:1" ];
klao@1951
   910
  ///n0 ->  n2 [ label="1, length:2" ];
klao@1951
   911
  ///n0 ->  n1 [ label="0, length:3" ];
klao@1951
   912
  ///}
klao@1951
   913
  ///\enddot
klao@1951
   914
  ///
klao@1951
   915
  ///\code
klao@1951
   916
  ///Graph g;
klao@1951
   917
  ///Node s, t;
klao@1951
   918
  ///LengthMap length(g);
klao@1951
   919
  ///
klao@1951
   920
  ///readDimacs(std::cin, g, length, s, t);
klao@1951
   921
  ///
klao@1951
   922
  ///cout << "edges with lengths (of form id, source--length->target): " << endl;
klao@1951
   923
  ///for(EdgeIt e(g); e!=INVALID; ++e) 
klao@1951
   924
  ///  cout << g.id(e) << ", " << g.id(g.source(e)) << "--" 
klao@1951
   925
  ///       << length[e] << "->" << g.id(g.target(e)) << endl;
klao@1951
   926
  ///
klao@1951
   927
  ///cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
klao@1951
   928
  ///\endcode
klao@1951
   929
  ///Next, the potential function is computed with Dijkstra.
klao@1951
   930
  ///\code
klao@1951
   931
  ///typedef Dijkstra<Graph, LengthMap> Dijkstra;
klao@1951
   932
  ///Dijkstra dijkstra(g, length);
klao@1951
   933
  ///dijkstra.run(s);
klao@1951
   934
  ///\endcode
klao@1951
   935
  ///Next, we consrtruct a map which filters the edge-set to the tight edges.
klao@1951
   936
  ///\code
klao@1951
   937
  ///typedef TightEdgeFilterMap<Graph, const Dijkstra::DistMap, LengthMap> 
klao@1951
   938
  ///  TightEdgeFilter;
klao@1951
   939
  ///TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length);
klao@1951
   940
  ///
deba@1991
   941
  ///typedef EdgeSubGraphAdaptor<Graph, TightEdgeFilter> SubGA;
deba@1991
   942
  ///SubGA ga(g, tight_edge_filter);
klao@1951
   943
  ///\endcode
klao@1951
   944
  ///Then, the maximum nimber of edge-disjoint \c s-\c t paths are computed 
klao@1951
   945
  ///with a max flow algorithm Preflow.
klao@1951
   946
  ///\code
klao@1951
   947
  ///ConstMap<Edge, int> const_1_map(1);
klao@1951
   948
  ///Graph::EdgeMap<int> flow(g, 0);
klao@1951
   949
  ///
deba@1991
   950
  ///Preflow<SubGA, int, ConstMap<Edge, int>, Graph::EdgeMap<int> > 
deba@1991
   951
  ///  preflow(ga, s, t, const_1_map, flow);
klao@1951
   952
  ///preflow.run();
klao@1951
   953
  ///\endcode
klao@1951
   954
  ///Last, the output is:
klao@1951
   955
  ///\code  
klao@1951
   956
  ///cout << "maximum number of edge-disjoint shortest path: " 
klao@1951
   957
  ///     << preflow.flowValue() << endl;
klao@1951
   958
  ///cout << "edges of the maximum number of edge-disjoint shortest s-t paths: " 
klao@1951
   959
  ///     << endl;
klao@1951
   960
  ///for(EdgeIt e(g); e!=INVALID; ++e) 
klao@1951
   961
  ///  if (flow[e])
klao@1951
   962
  ///    cout << " " << g.id(g.source(e)) << "--"
klao@1951
   963
  ///         << length[e] << "->" << g.id(g.target(e)) << endl;
klao@1951
   964
  ///\endcode
klao@1951
   965
  ///The program has the following (expected :-)) output:
klao@1951
   966
  ///\code
klao@1951
   967
  ///edges with lengths (of form id, source--length->target):
klao@1951
   968
  /// 9, 5--4->6
klao@1951
   969
  /// 8, 4--2->6
klao@1951
   970
  /// 7, 3--1->5
klao@1951
   971
  /// 6, 2--3->5
klao@1951
   972
  /// 5, 2--5->6
klao@1951
   973
  /// 4, 2--2->4
klao@1951
   974
  /// 3, 1--3->4
klao@1951
   975
  /// 2, 0--1->3
klao@1951
   976
  /// 1, 0--2->2
klao@1951
   977
  /// 0, 0--3->1
klao@1951
   978
  ///s: 0 t: 6
klao@1951
   979
  ///maximum number of edge-disjoint shortest path: 2
klao@1951
   980
  ///edges of the maximum number of edge-disjoint shortest s-t paths:
klao@1951
   981
  /// 9, 5--4->6
klao@1951
   982
  /// 8, 4--2->6
klao@1951
   983
  /// 7, 3--1->5
klao@1951
   984
  /// 4, 2--2->4
klao@1951
   985
  /// 2, 0--1->3
klao@1951
   986
  /// 1, 0--2->2
klao@1951
   987
  ///\endcode
klao@1951
   988
  ///
klao@1951
   989
  ///\author Marton Makai
marci@932
   990
  template<typename Graph, typename EdgeFilterMap>
alpar@1401
   991
  class EdgeSubGraphAdaptor : 
alpar@1401
   992
    public SubGraphAdaptor<Graph, ConstMap<typename Graph::Node,bool>, 
deba@1681
   993
			   EdgeFilterMap, false> {
marci@932
   994
  public:
alpar@1401
   995
    typedef SubGraphAdaptor<Graph, ConstMap<typename Graph::Node,bool>, 
deba@1685
   996
			    EdgeFilterMap, false> Parent;
marci@932
   997
  protected:
marci@932
   998
    ConstMap<typename Graph::Node, bool> const_true_map;
deba@1991
   999
deba@1991
  1000
    EdgeSubGraphAdaptor() : const_true_map(true) {
deba@1991
  1001
      Parent::setNodeFilterMap(const_true_map);
deba@1991
  1002
    }
deba@1991
  1003
marci@932
  1004
  public:
deba@2031
  1005
alpar@1401
  1006
    EdgeSubGraphAdaptor(Graph& _graph, EdgeFilterMap& _edge_filter_map) : 
marci@932
  1007
      Parent(), const_true_map(true) { 
marci@932
  1008
      Parent::setGraph(_graph);
marci@932
  1009
      Parent::setNodeFilterMap(const_true_map);
marci@932
  1010
      Parent::setEdgeFilterMap(_edge_filter_map);
marci@932
  1011
    }
deba@2031
  1012
marci@932
  1013
  };
marci@932
  1014
deba@1991
  1015
  /// \brief Just gives back an edge sub graph adaptor
deba@1991
  1016
  ///
deba@1991
  1017
  /// Just gives back an edge sub graph adaptor
deba@1991
  1018
  template<typename Graph, typename EdgeFilterMap>
deba@1991
  1019
  EdgeSubGraphAdaptor<const Graph, EdgeFilterMap>
deba@1991
  1020
  edgeSubGraphAdaptor(const Graph& graph, EdgeFilterMap& efm) {
deba@1991
  1021
    return EdgeSubGraphAdaptor<const Graph, EdgeFilterMap>(graph, efm);
deba@1991
  1022
  }
deba@1991
  1023
deba@1991
  1024
  template<typename Graph, typename EdgeFilterMap>
deba@1991
  1025
  EdgeSubGraphAdaptor<const Graph, const EdgeFilterMap>
deba@1991
  1026
  edgeSubGraphAdaptor(const Graph& graph, const EdgeFilterMap& efm) {
deba@1991
  1027
    return EdgeSubGraphAdaptor<const Graph, const EdgeFilterMap>(graph, efm);
deba@1991
  1028
  }
deba@1991
  1029
deba@2079
  1030
  template <typename _Graph>
deba@1980
  1031
  class UndirGraphAdaptorBase : 
deba@2079
  1032
    public UndirGraphExtender<GraphAdaptorBase<_Graph> > {
marci@1383
  1033
  public:
marci@1383
  1034
    typedef _Graph Graph;
deba@2031
  1035
    typedef UndirGraphAdaptorBase Adaptor;
deba@2079
  1036
    typedef UndirGraphExtender<GraphAdaptorBase<_Graph> > Parent;
deba@1991
  1037
marci@1383
  1038
  protected:
deba@1991
  1039
deba@1991
  1040
    UndirGraphAdaptorBase() : Parent() {}
deba@1991
  1041
marci@1383
  1042
  public:
deba@1991
  1043
klao@1909
  1044
    typedef typename Parent::UEdge UEdge;
marci@1383
  1045
    typedef typename Parent::Edge Edge;
deba@1991
  1046
deba@2031
  1047
  private:
marci@1383
  1048
    
deba@1991
  1049
    template <typename _Value>
deba@2031
  1050
    class EdgeMapBase {
deba@1991
  1051
    private:
deba@1991
  1052
      
deba@1991
  1053
      typedef typename _Graph::template EdgeMap<_Value> MapImpl;
deba@1991
  1054
      
marci@1383
  1055
    public:
deba@1991
  1056
deba@1991
  1057
      typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
deba@1991
  1058
deba@1991
  1059
      typedef _Value Value;
marci@1383
  1060
      typedef Edge Key;
marci@1383
  1061
      
deba@2031
  1062
      EdgeMapBase(const Adaptor& adaptor) :
deba@2031
  1063
	forward_map(*adaptor.graph), backward_map(*adaptor.graph) {}
marci@569
  1064
deba@2031
  1065
      EdgeMapBase(const Adaptor& adaptor, const Value& v) 
deba@2031
  1066
        : forward_map(*adaptor.graph, v), backward_map(*adaptor.graph, v) {}
marci@1383
  1067
      
deba@1991
  1068
      void set(const Edge& e, const Value& a) { 
deba@1991
  1069
	if (Parent::direction(e)) {
marci@1383
  1070
	  forward_map.set(e, a); 
deba@1991
  1071
        } else { 
deba@1991
  1072
	  backward_map.set(e, a);
deba@1991
  1073
        } 
marci@1383
  1074
      }
marci@556
  1075
deba@1991
  1076
      typename MapTraits<MapImpl>::ConstReturnValue operator[](Edge e) const { 
deba@1991
  1077
	if (Parent::direction(e)) {
marci@1383
  1078
	  return forward_map[e]; 
deba@1991
  1079
	} else { 
marci@1383
  1080
	  return backward_map[e]; 
deba@1991
  1081
        }
marci@556
  1082
      }
deba@1991
  1083
deba@1991
  1084
      typename MapTraits<MapImpl>::ReturnValue operator[](Edge e) { 
deba@1991
  1085
	if (Parent::direction(e)) {
deba@1991
  1086
	  return forward_map[e]; 
deba@1991
  1087
	} else { 
deba@1991
  1088
	  return backward_map[e]; 
deba@1991
  1089
        }
deba@1991
  1090
      }
deba@1991
  1091
deba@1991
  1092
    protected:
deba@1991
  1093
deba@1991
  1094
      MapImpl forward_map, backward_map; 
deba@1991
  1095
marci@556
  1096
    };
deba@2031
  1097
deba@2031
  1098
  public:
deba@2031
  1099
deba@2031
  1100
    template <typename _Value>
deba@2031
  1101
    class EdgeMap 
deba@2031
  1102
      : public SubMapExtender<Adaptor, EdgeMapBase<_Value> > 
deba@2031
  1103
    {
deba@2031
  1104
    public:
deba@2031
  1105
      typedef Adaptor Graph;
deba@2031
  1106
      typedef SubMapExtender<Adaptor, EdgeMapBase<_Value> > Parent;
deba@2031
  1107
    
deba@2031
  1108
      EdgeMap(const Graph& graph) 
deba@2031
  1109
	: Parent(graph) {}
deba@2031
  1110
      EdgeMap(const Graph& graph, const _Value& value) 
deba@2031
  1111
	: Parent(graph, value) {}
deba@2031
  1112
    
deba@2031
  1113
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
  1114
	return operator=<EdgeMap>(cmap);
deba@2031
  1115
      }
deba@2031
  1116
    
deba@2031
  1117
      template <typename CMap>
deba@2031
  1118
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
  1119
        Parent::operator=(cmap);
deba@2031
  1120
	return *this;
deba@2031
  1121
      }
deba@2031
  1122
    };
marci@1383
  1123
        
deba@1991
  1124
    template <typename _Value>
deba@2031
  1125
    class UEdgeMap : public Graph::template EdgeMap<_Value> {
marci@1383
  1126
    public:
deba@2031
  1127
      
deba@2031
  1128
      typedef typename Graph::template EdgeMap<_Value> Parent;
deba@2031
  1129
      
deba@2031
  1130
      explicit UEdgeMap(const Adaptor& ga) 
deba@2031
  1131
	: Parent(*ga.graph) {}
deba@1991
  1132
deba@2031
  1133
      UEdgeMap(const Adaptor& ga, const _Value& value)
deba@2031
  1134
	: Parent(*ga.graph, value) {}
deba@1991
  1135
deba@2031
  1136
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@2031
  1137
        return operator=<UEdgeMap>(cmap);
deba@2031
  1138
      }
deba@1991
  1139
deba@2031
  1140
      template <typename CMap>
deba@2031
  1141
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
  1142
        Parent::operator=(cmap);
deba@2031
  1143
        return *this;
deba@2031
  1144
      }
deba@2031
  1145
deba@1991
  1146
    };
deba@1991
  1147
      
deba@1991
  1148
  };
marci@556
  1149
deba@2079
  1150
  template <typename _Graph, typename Enable = void>
deba@2079
  1151
  class AlterableUndirGraphAdaptor 
deba@2079
  1152
    : public UGraphAdaptorExtender<UndirGraphAdaptorBase<_Graph> > {
deba@2079
  1153
  public:
deba@2079
  1154
    typedef UGraphAdaptorExtender<UndirGraphAdaptorBase<_Graph> > Parent;
deba@2079
  1155
    
deba@2079
  1156
  protected:
deba@2079
  1157
deba@2079
  1158
    AlterableUndirGraphAdaptor() : Parent() {}
deba@2079
  1159
deba@1991
  1160
  public:
deba@1991
  1161
deba@2079
  1162
    typedef typename Parent::EdgeNotifier UEdgeNotifier;
deba@2079
  1163
    typedef InvalidType EdgeNotifier;
deba@2079
  1164
deba@2079
  1165
  };
deba@2079
  1166
deba@2079
  1167
  template <typename _Graph>
deba@2079
  1168
  class AlterableUndirGraphAdaptor<
deba@2079
  1169
    _Graph, 
deba@2079
  1170
    typename enable_if<typename _Graph::EdgeNotifier::Notifier>::type > 
deba@2079
  1171
    : public UGraphAdaptorExtender<UndirGraphAdaptorBase<_Graph> > {
deba@2079
  1172
  public:
deba@2079
  1173
deba@2079
  1174
    typedef UGraphAdaptorExtender<UndirGraphAdaptorBase<_Graph> > Parent;
deba@1991
  1175
    typedef _Graph Graph;
deba@2079
  1176
    typedef typename _Graph::Edge GraphEdge;
deba@2079
  1177
    
deba@1991
  1178
  protected:
deba@1991
  1179
deba@2079
  1180
    AlterableUndirGraphAdaptor() 
deba@2079
  1181
      : Parent(), edge_notifier(*this), edge_notifier_proxy(*this) {}
deba@1991
  1182
deba@1991
  1183
    void setGraph(_Graph& graph) {
deba@1991
  1184
      Parent::setGraph(graph);
deba@2079
  1185
      edge_notifier_proxy.setNotifier(graph.getNotifier(GraphEdge()));
deba@1991
  1186
    }
deba@1991
  1187
deba@1991
  1188
  public:
deba@1991
  1189
deba@2079
  1190
    ~AlterableUndirGraphAdaptor() {
deba@1999
  1191
      edge_notifier.clear();
deba@1999
  1192
    }
deba@1999
  1193
deba@1991
  1194
    typedef typename Parent::UEdge UEdge;
deba@1991
  1195
    typedef typename Parent::Edge Edge;
deba@1991
  1196
deba@1991
  1197
    typedef typename Parent::EdgeNotifier UEdgeNotifier;
deba@1991
  1198
deba@1991
  1199
    using Parent::getNotifier;
deba@1991
  1200
deba@2079
  1201
    typedef AlterationNotifier<AlterableUndirGraphAdaptor, 
deba@2079
  1202
                               Edge> EdgeNotifier;
deba@1991
  1203
    EdgeNotifier& getNotifier(Edge) const { return edge_notifier; }
deba@1991
  1204
deba@1991
  1205
  protected:
deba@1991
  1206
deba@2079
  1207
    class NotifierProxy : public Graph::EdgeNotifier::ObserverBase {
deba@1991
  1208
    public:
deba@1991
  1209
deba@2079
  1210
      typedef typename Graph::EdgeNotifier::ObserverBase Parent;
deba@2079
  1211
      typedef AlterableUndirGraphAdaptor AdaptorBase;
marci@1383
  1212
      
deba@2079
  1213
      NotifierProxy(const AdaptorBase& _adaptor)
deba@2079
  1214
        : Parent(), adaptor(&_adaptor) {
marci@1383
  1215
      }
marci@556
  1216
deba@1991
  1217
      virtual ~NotifierProxy() {
deba@1991
  1218
        if (Parent::attached()) {
deba@1991
  1219
          Parent::detach();
deba@1991
  1220
        }
marci@1383
  1221
      }
deba@1991
  1222
deba@2079
  1223
      void setNotifier(typename Graph::EdgeNotifier& notifier) {
deba@2079
  1224
        Parent::attach(notifier);
deba@1991
  1225
      }
deba@1991
  1226
deba@1991
  1227
      
deba@1991
  1228
    protected:
deba@1991
  1229
deba@2079
  1230
      virtual void add(const GraphEdge& ge) {
deba@1991
  1231
        std::vector<Edge> edges;
deba@2079
  1232
        edges.push_back(AdaptorBase::Parent::direct(ge, true));
deba@2079
  1233
        edges.push_back(AdaptorBase::Parent::direct(ge, false));
deba@2079
  1234
        adaptor->getNotifier(Edge()).add(edges);
deba@1991
  1235
      }
deba@2079
  1236
      virtual void add(const std::vector<GraphEdge>& ge) {
deba@1991
  1237
        std::vector<Edge> edges;
deba@2079
  1238
        for (int i = 0; i < (int)ge.size(); ++i) { 
deba@2079
  1239
          edges.push_back(AdaptorBase::Parent::direct(ge[i], true));
deba@2079
  1240
          edges.push_back(AdaptorBase::Parent::direct(ge[i], false));
deba@1991
  1241
        }
deba@2079
  1242
        adaptor->getNotifier(Edge()).add(edges);
deba@1991
  1243
      }
deba@2079
  1244
      virtual void erase(const GraphEdge& ge) {
deba@1991
  1245
        std::vector<Edge> edges;
deba@2079
  1246
        edges.push_back(AdaptorBase::Parent::direct(ge, true));
deba@2079
  1247
        edges.push_back(AdaptorBase::Parent::direct(ge, false));
deba@2079
  1248
        adaptor->getNotifier(Edge()).erase(edges);
deba@1991
  1249
      }
deba@2079
  1250
      virtual void erase(const std::vector<GraphEdge>& ge) {
deba@1991
  1251
        std::vector<Edge> edges;
deba@2079
  1252
        for (int i = 0; i < (int)ge.size(); ++i) { 
deba@2079
  1253
          edges.push_back(AdaptorBase::Parent::direct(ge[i], true));
deba@2079
  1254
          edges.push_back(AdaptorBase::Parent::direct(ge[i], false));
deba@1991
  1255
        }
deba@2079
  1256
        adaptor->getNotifier(Edge()).erase(edges);
deba@1991
  1257
      }
deba@1991
  1258
      virtual void build() {
deba@2079
  1259
        adaptor->getNotifier(Edge()).build();
deba@1991
  1260
      }
deba@1991
  1261
      virtual void clear() {
deba@2079
  1262
        adaptor->getNotifier(Edge()).clear();
deba@1991
  1263
      }
deba@1991
  1264
deba@2079
  1265
      const AdaptorBase* adaptor;
deba@1991
  1266
    };
deba@1991
  1267
deba@1991
  1268
deba@1991
  1269
    mutable EdgeNotifier edge_notifier;
deba@1991
  1270
    NotifierProxy edge_notifier_proxy;
deba@1991
  1271
marci@1383
  1272
  };
marci@1383
  1273
deba@2079
  1274
deba@2081
  1275
  ///\ingroup graph_adaptors
deba@2081
  1276
  ///
deba@2079
  1277
  /// \brief An undirected graph is made from a directed graph by an adaptor
klao@1951
  1278
  ///
klao@1951
  1279
  /// Undocumented, untested!!!
klao@1951
  1280
  /// If somebody knows nice demo application, let's polulate it.
klao@1951
  1281
  /// 
klao@1951
  1282
  /// \author Marton Makai
marci@1383
  1283
  template<typename _Graph>
deba@2079
  1284
  class UndirGraphAdaptor : public AlterableUndirGraphAdaptor<_Graph> {
marci@1383
  1285
  public:
marci@1383
  1286
    typedef _Graph Graph;
deba@2079
  1287
    typedef AlterableUndirGraphAdaptor<_Graph> Parent;
marci@1383
  1288
  protected:
deba@1980
  1289
    UndirGraphAdaptor() { }
marci@1383
  1290
  public:
deba@1980
  1291
    UndirGraphAdaptor(_Graph& _graph) { 
marci@1383
  1292
      setGraph(_graph);
marci@556
  1293
    }
marci@556
  1294
deba@1991
  1295
    template <typename _ForwardMap, typename _BackwardMap>
deba@1991
  1296
    class CombinedEdgeMap {
deba@1991
  1297
    public:
deba@1991
  1298
      
deba@1991
  1299
      typedef _ForwardMap ForwardMap;
deba@1991
  1300
      typedef _BackwardMap BackwardMap;
marci@992
  1301
deba@1991
  1302
      typedef typename MapTraits<ForwardMap>::ReferenceMapTag ReferenceMapTag;
marci@992
  1303
deba@1991
  1304
      typedef typename ForwardMap::Value Value;
deba@1991
  1305
      typedef typename Parent::Edge Key;
deba@1991
  1306
      
deba@1991
  1307
      CombinedEdgeMap() : forward_map(0), backward_map(0) {}
marci@992
  1308
deba@1991
  1309
      CombinedEdgeMap(ForwardMap& _forward_map, BackwardMap& _backward_map) 
deba@1991
  1310
        : forward_map(&_forward_map), backward_map(&_backward_map) {}
marci@992
  1311
      
deba@1991
  1312
      void set(const Key& e, const Value& a) { 
deba@1991
  1313
	if (Parent::direction(e)) {
deba@1991
  1314
	  forward_map->set(e, a); 
deba@1991
  1315
        } else { 
deba@1991
  1316
	  backward_map->set(e, a);
deba@1991
  1317
        } 
marci@992
  1318
      }
marci@992
  1319
deba@1991
  1320
      typename MapTraits<ForwardMap>::ConstReturnValue 
deba@1991
  1321
      operator[](const Key& e) const { 
deba@1991
  1322
	if (Parent::direction(e)) {
deba@1991
  1323
	  return (*forward_map)[e]; 
deba@1991
  1324
	} else { 
deba@1991
  1325
	  return (*backward_map)[e]; 
deba@1991
  1326
        }
marci@992
  1327
      }
marci@992
  1328
deba@1991
  1329
      typename MapTraits<ForwardMap>::ReturnValue 
deba@1991
  1330
      operator[](const Key& e) { 
deba@1991
  1331
	if (Parent::direction(e)) {
deba@1991
  1332
	  return (*forward_map)[e]; 
deba@1991
  1333
	} else { 
deba@1991
  1334
	  return (*backward_map)[e]; 
deba@1991
  1335
        }
marci@992
  1336
      }
deba@1991
  1337
deba@1991
  1338
      void setForwardMap(ForwardMap& _forward_map) {
deba@1991
  1339
        forward_map = &_forward_map;
deba@1991
  1340
      }
deba@1991
  1341
deba@1991
  1342
      void setBackwardMap(BackwardMap& _backward_map) {
deba@1991
  1343
        backward_map = &_backward_map;
deba@1991
  1344
      }
deba@1991
  1345
deba@1991
  1346
    protected:
deba@1991
  1347
deba@1991
  1348
      ForwardMap* forward_map;
deba@1991
  1349
      BackwardMap* backward_map; 
deba@1991
  1350
marci@992
  1351
    };
marci@992
  1352
marci@992
  1353
  };
marci@569
  1354
deba@1991
  1355
  /// \brief Just gives back an undir graph adaptor
klao@1951
  1356
  ///
deba@1991
  1357
  /// Just gives back an undir graph adaptor
marci@650
  1358
  template<typename Graph>
deba@1991
  1359
  UndirGraphAdaptor<const Graph>
deba@1991
  1360
  undirGraphAdaptor(const Graph& graph) {
deba@1991
  1361
    return UndirGraphAdaptor<const Graph>(graph);
deba@1991
  1362
  }
marci@650
  1363
deba@2034
  1364
  template<typename Graph, typename Number,  
deba@2034
  1365
           typename CapacityMap, typename FlowMap, 
deba@2034
  1366
           typename Tolerance = Tolerance<Number> >
marci@658
  1367
  class ResForwardFilter {
marci@650
  1368
    const CapacityMap* capacity;
marci@650
  1369
    const FlowMap* flow;
deba@2034
  1370
    Tolerance tolerance;
marci@650
  1371
  public:
deba@1991
  1372
    typedef typename Graph::Edge Key;
deba@1991
  1373
    typedef bool Value;
deba@1991
  1374
deba@2034
  1375
    ResForwardFilter(const CapacityMap& _capacity, const FlowMap& _flow,
deba@2034
  1376
                     const Tolerance& _tolerance = Tolerance()) 
deba@2034
  1377
      : capacity(&_capacity), flow(&_flow), tolerance(_tolerance) { }
deba@2034
  1378
deba@2034
  1379
    ResForwardFilter(const Tolerance& _tolerance) 
deba@2034
  1380
      : capacity(0), flow(0), tolerance(_tolerance)  { }
deba@2034
  1381
deba@1991
  1382
    void setCapacity(const CapacityMap& _capacity) { capacity = &_capacity; }
deba@1991
  1383
    void setFlow(const FlowMap& _flow) { flow = &_flow; }
deba@2034
  1384
marci@650
  1385
    bool operator[](const typename Graph::Edge& e) const {
deba@2034
  1386
      return tolerance.less((*flow)[e], (*capacity)[e]);
marci@650
  1387
    }
marci@650
  1388
  };
marci@650
  1389
marci@650
  1390
  template<typename Graph, typename Number,
deba@2034
  1391
	   typename CapacityMap, typename FlowMap,
deba@2034
  1392
           typename Tolerance = Tolerance<Number> >
marci@658
  1393
  class ResBackwardFilter {
marci@650
  1394
    const CapacityMap* capacity;
marci@650
  1395
    const FlowMap* flow;
deba@2034
  1396
    Tolerance tolerance;
marci@650
  1397
  public:
deba@1991
  1398
    typedef typename Graph::Edge Key;
deba@1991
  1399
    typedef bool Value;
deba@1991
  1400
deba@2034
  1401
    ResBackwardFilter(const CapacityMap& _capacity, const FlowMap& _flow,
deba@2034
  1402
                      const Tolerance& _tolerance = Tolerance())
deba@2034
  1403
      : capacity(&_capacity), flow(&_flow), tolerance(_tolerance) { }
deba@2034
  1404
    ResBackwardFilter(const Tolerance& _tolerance = Tolerance())
deba@2034
  1405
      : capacity(0), flow(0), tolerance(_tolerance) { }
deba@1991
  1406
    void setCapacity(const CapacityMap& _capacity) { capacity = &_capacity; }
deba@1991
  1407
    void setFlow(const FlowMap& _flow) { flow = &_flow; }
marci@650
  1408
    bool operator[](const typename Graph::Edge& e) const {
deba@2034
  1409
      return tolerance.less(0, Number((*flow)[e]));
marci@650
  1410
    }
marci@650
  1411
  };
marci@650
  1412
marci@653
  1413
  
deba@2081
  1414
  ///\ingroup graph_adaptors
deba@2081
  1415
  ///
klao@1951
  1416
  ///\brief An adaptor for composing the residual
klao@1951
  1417
  ///graph for directed flow and circulation problems.
deba@2037
  1418
  ///
deba@2042
  1419
  ///An adaptor for composing the residual graph for directed flow and
deba@2042
  1420
  ///circulation problems.  Let \f$ G=(V, A) \f$ be a directed graph
deba@2042
  1421
  ///and let \f$ F \f$ be a number type. Let moreover \f$ f,c:A\to F \f$,
deba@2042
  1422
  ///be functions on the edge-set.
deba@2042
  1423
  ///
deba@2042
  1424
  ///In the appications of ResGraphAdaptor, \f$ f \f$ usually stands
deba@2042
  1425
  ///for a flow and \f$ c \f$ for a capacity function.  Suppose that a
deba@2042
  1426
  ///graph instange \c g of type \c ListGraph implements \f$ G \f$.
deba@2042
  1427
  ///
deba@2042
  1428
  ///\code 
deba@2042
  1429
  ///  ListGraph g;
deba@2042
  1430
  ///\endcode 
deba@2042
  1431
  ///
deba@2042
  1432
  ///Then RevGraphAdaptor implements the graph structure with node-set
deba@2042
  1433
  /// \f$ V \f$ and edge-set \f$ A_{forward}\cup A_{backward} \f$,
deba@2042
  1434
  ///where \f$ A_{forward}=\{uv : uv\in A, f(uv)<c(uv)\} \f$ and 
deba@2042
  1435
  /// \f$ A_{backward}=\{vu : uv\in A, f(uv)>0\} \f$, i.e. the so called
deba@2042
  1436
  ///residual graph.  When we take the union 
deba@2042
  1437
  /// \f$ A_{forward}\cup A_{backward} \f$, multilicities are counted, i.e. 
deba@2042
  1438
  ///if an edge is in both \f$ A_{forward} \f$ and \f$ A_{backward} \f$, 
deba@2042
  1439
  ///then in the adaptor it appears twice. The following code shows how 
deba@2042
  1440
  ///such an instance can be constructed.
deba@2042
  1441
  ///
deba@2042
  1442
  ///\code 
deba@2042
  1443
  ///  typedef ListGraph Graph; 
deba@2042
  1444
  ///  Graph::EdgeMap<int> f(g);
deba@2042
  1445
  ///  Graph::EdgeMap<int> c(g); 
deba@2042
  1446
  ///  ResGraphAdaptor<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > ga(g); 
deba@2042
  1447
  ///\endcode
deba@2042
  1448
  ///\author Marton Makai
deba@2042
  1449
  ///
marci@650
  1450
  template<typename Graph, typename Number, 
deba@2034
  1451
	   typename CapacityMap, typename FlowMap,
deba@2034
  1452
           typename Tolerance = Tolerance<Number> >
alpar@1401
  1453
  class ResGraphAdaptor : 
deba@1991
  1454
    public EdgeSubGraphAdaptor< 
deba@2034
  1455
    UndirGraphAdaptor<const Graph>, 
deba@2034
  1456
    typename UndirGraphAdaptor<const Graph>::template CombinedEdgeMap<
deba@2034
  1457
    ResForwardFilter<const Graph, Number, CapacityMap, FlowMap>,  
deba@2034
  1458
    ResBackwardFilter<const Graph, Number, CapacityMap, FlowMap> > > {
marci@650
  1459
  public:
deba@1991
  1460
deba@2034
  1461
    typedef UndirGraphAdaptor<const Graph> UGraph;
deba@1991
  1462
deba@2034
  1463
    typedef ResForwardFilter<const Graph, Number, CapacityMap, FlowMap> 
deba@1991
  1464
    ForwardFilter;
deba@1991
  1465
deba@2034
  1466
    typedef ResBackwardFilter<const Graph, Number, CapacityMap, FlowMap> 
deba@1991
  1467
    BackwardFilter;
deba@1991
  1468
deba@1991
  1469
    typedef typename UGraph::
deba@1991
  1470
    template CombinedEdgeMap<ForwardFilter, BackwardFilter>
deba@1991
  1471
    EdgeFilter;
deba@1991
  1472
deba@1991
  1473
    typedef EdgeSubGraphAdaptor<UGraph, EdgeFilter> Parent;
deba@1991
  1474
marci@650
  1475
  protected:
deba@1991
  1476
marci@650
  1477
    const CapacityMap* capacity;
marci@650
  1478
    FlowMap* flow;
deba@1991
  1479
deba@1991
  1480
    UGraph ugraph;
deba@1991
  1481
    ForwardFilter forward_filter;
deba@1991
  1482
    BackwardFilter backward_filter;
deba@1991
  1483
    EdgeFilter edge_filter;
deba@1991
  1484
marci@658
  1485
    void setCapacityMap(const CapacityMap& _capacity) {
marci@658
  1486
      capacity=&_capacity;
marci@658
  1487
      forward_filter.setCapacity(_capacity);
marci@658
  1488
      backward_filter.setCapacity(_capacity);
marci@658
  1489
    }
deba@1991
  1490
marci@658
  1491
    void setFlowMap(FlowMap& _flow) {
marci@658
  1492
      flow=&_flow;
marci@658
  1493
      forward_filter.setFlow(_flow);
marci@658
  1494
      backward_filter.setFlow(_flow);
marci@658
  1495
    }
deba@1991
  1496
marci@650
  1497
  public:
deba@1991
  1498
deba@2034
  1499
    /// \brief Constructor of the residual graph.
deba@2034
  1500
    ///
deba@2034
  1501
    /// Constructor of the residual graph. The parameters are the graph type,
deba@2034
  1502
    /// the flow map, the capacity map and a tolerance object.
deba@2034
  1503
    ResGraphAdaptor(const Graph& _graph, const CapacityMap& _capacity, 
deba@2034
  1504
                    FlowMap& _flow, const Tolerance& _tolerance = Tolerance()) 
deba@2034
  1505
      : Parent(), capacity(&_capacity), flow(&_flow), ugraph(_graph),
deba@2034
  1506
        forward_filter(_capacity, _flow, _tolerance), 
deba@2034
  1507
        backward_filter(_capacity, _flow, _tolerance),
deba@2034
  1508
        edge_filter(forward_filter, backward_filter)
deba@2034
  1509
    {
deba@1991
  1510
      Parent::setGraph(ugraph);
deba@1991
  1511
      Parent::setEdgeFilterMap(edge_filter);
marci@650
  1512
    }
marci@650
  1513
marci@660
  1514
    typedef typename Parent::Edge Edge;
marci@660
  1515
deba@2034
  1516
    /// \brief Gives back the residual capacity of the edge.
deba@2034
  1517
    ///
deba@2034
  1518
    /// Gives back the residual capacity of the edge.
deba@2034
  1519
    Number rescap(const Edge& edge) const {
deba@2034
  1520
      if (UGraph::direction(edge)) {
deba@2034
  1521
        return (*capacity)[edge]-(*flow)[edge]; 
deba@2034
  1522
      } else {
deba@2034
  1523
        return (*flow)[edge];
deba@2034
  1524
      }
deba@2034
  1525
    } 
deba@2034
  1526
deba@2034
  1527
    /// \brief Augment on the given edge in the residual graph.
deba@2034
  1528
    ///
deba@2034
  1529
    /// Augment on the given edge in the residual graph. It increase
deba@2034
  1530
    /// or decrease the flow on the original edge depend on the direction
deba@2034
  1531
    /// of the residual edge.
marci@660
  1532
    void augment(const Edge& e, Number a) const {
deba@1991
  1533
      if (UGraph::direction(e)) {
deba@2034
  1534
        flow->set(e, (*flow)[e] + a);
deba@1991
  1535
      } else {  
deba@2034
  1536
        flow->set(e, (*flow)[e] - a);
deba@1991
  1537
      }
marci@650
  1538
    }
marci@650
  1539
deba@2034
  1540
    /// \brief Returns the direction of the edge.
deba@2034
  1541
    ///
deba@2034
  1542
    /// Returns true when the edge is same oriented as the original edge.
deba@1991
  1543
    static bool forward(const Edge& e) {
deba@1991
  1544
      return UGraph::direction(e);
deba@1991
  1545
    }
deba@1991
  1546
deba@2034
  1547
    /// \brief Returns the direction of the edge.
deba@2034
  1548
    ///
deba@2034
  1549
    /// Returns true when the edge is opposite oriented as the original edge.
deba@1991
  1550
    static bool backward(const Edge& e) {
deba@1991
  1551
      return !UGraph::direction(e);
deba@1991
  1552
    }
deba@1991
  1553
deba@2034
  1554
    /// \brief Gives back the forward oriented residual edge.
deba@2034
  1555
    ///
deba@2034
  1556
    /// Gives back the forward oriented residual edge.
deba@1991
  1557
    static Edge forward(const typename Graph::Edge& e) {
deba@1991
  1558
      return UGraph::direct(e, true);
deba@1991
  1559
    }
deba@1991
  1560
deba@2034
  1561
    /// \brief Gives back the backward oriented residual edge.
deba@2034
  1562
    ///
deba@2034
  1563
    /// Gives back the backward oriented residual edge.
deba@1991
  1564
    static Edge backward(const typename Graph::Edge& e) {
deba@1991
  1565
      return UGraph::direct(e, false);
deba@1991
  1566
    }
deba@1991
  1567
klao@1951
  1568
    /// \brief Residual capacity map.
klao@1951
  1569
    ///
klao@1951
  1570
    /// In generic residual graphs the residual capacity can be obtained 
klao@1951
  1571
    /// as a map. 
marci@660
  1572
    class ResCap {
marci@660
  1573
    protected:
deba@1991
  1574
      const ResGraphAdaptor* res_graph;
marci@660
  1575
    public:
alpar@987
  1576
      typedef Number Value;
alpar@987
  1577
      typedef Edge Key;
deba@1991
  1578
      ResCap(const ResGraphAdaptor& _res_graph) 
deba@1991
  1579
        : res_graph(&_res_graph) {}
deba@1991
  1580
      
deba@2034
  1581
      Number operator[](const Edge& e) const {
deba@2034
  1582
        return res_graph->rescap(e);
marci@660
  1583
      }
deba@1991
  1584
      
marci@660
  1585
    };
marci@660
  1586
marci@650
  1587
  };
marci@650
  1588
marci@650
  1589
marci@998
  1590
marci@998
  1591
  template <typename _Graph, typename FirstOutEdgesMap>
alpar@1401
  1592
  class ErasingFirstGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
marci@998
  1593
  public:
marci@998
  1594
    typedef _Graph Graph;
alpar@1401
  1595
    typedef GraphAdaptorBase<_Graph> Parent;
marci@998
  1596
  protected:
marci@998
  1597
    FirstOutEdgesMap* first_out_edges;
alpar@1401
  1598
    ErasingFirstGraphAdaptorBase() : Parent(), 
marci@998
  1599
				     first_out_edges(0) { }
marci@998
  1600
marci@998
  1601
    void setFirstOutEdgesMap(FirstOutEdgesMap& _first_out_edges) {
marci@998
  1602
      first_out_edges=&_first_out_edges;
marci@998
  1603
    }
marci@998
  1604
marci@998
  1605
  public:
marci@998
  1606
marci@998
  1607
    typedef typename Parent::Node Node;
marci@998
  1608
    typedef typename Parent::Edge Edge;
marci@998
  1609
marci@998
  1610
    void firstOut(Edge& i, const Node& n) const { 
marci@998
  1611
      i=(*first_out_edges)[n];
marci@998
  1612
    }
marci@998
  1613
marci@998
  1614
    void erase(const Edge& e) const {
marci@998
  1615
      Node n=source(e);
marci@998
  1616
      Edge f=e;
marci@998
  1617
      Parent::nextOut(f);
marci@998
  1618
      first_out_edges->set(n, f);
marci@998
  1619
    }    
marci@998
  1620
  };
marci@998
  1621
marci@998
  1622
deba@2081
  1623
  ///\ingroup graph_adaptors
deba@2081
  1624
  ///
klao@1951
  1625
  ///\brief For blocking flows.
klao@1951
  1626
  ///
klao@1951
  1627
  ///This graph adaptor is used for on-the-fly 
klao@1951
  1628
  ///Dinits blocking flow computations.
klao@1951
  1629
  ///For each node, an out-edge is stored which is used when the 
klao@1951
  1630
  ///\code
klao@1951
  1631
  ///OutEdgeIt& first(OutEdgeIt&, const Node&)
klao@1951
  1632
  ///\endcode
klao@1951
  1633
  ///is called. 
klao@1951
  1634
  ///
klao@1951
  1635
  ///\author Marton Makai
klao@1951
  1636
  ///
marci@998
  1637
  template <typename _Graph, typename FirstOutEdgesMap>
alpar@1401
  1638
  class ErasingFirstGraphAdaptor : 
deba@1979
  1639
    public GraphAdaptorExtender<
alpar@1401
  1640
    ErasingFirstGraphAdaptorBase<_Graph, FirstOutEdgesMap> > {
marci@650
  1641
  public:
marci@998
  1642
    typedef _Graph Graph;
deba@1979
  1643
    typedef GraphAdaptorExtender<
alpar@1401
  1644
      ErasingFirstGraphAdaptorBase<_Graph, FirstOutEdgesMap> > Parent;
alpar@1401
  1645
    ErasingFirstGraphAdaptor(Graph& _graph, 
marci@998
  1646
			     FirstOutEdgesMap& _first_out_edges) { 
marci@998
  1647
      setGraph(_graph);
marci@998
  1648
      setFirstOutEdgesMap(_first_out_edges);
marci@998
  1649
    } 
marci@1019
  1650
marci@998
  1651
  };
marci@556
  1652
deba@2079
  1653
  /// \brief Base class for split graph adaptor
deba@2079
  1654
  ///
deba@2079
  1655
  /// Base class of split graph adaptor. In most case you do not need to
deba@2079
  1656
  /// use it directly but the documented member functions of this class can 
deba@2079
  1657
  /// be used with the SplitGraphAdaptor class.
deba@2079
  1658
  /// \sa SplitGraphAdaptor
deba@2079
  1659
  template <typename _Graph>
deba@2079
  1660
  class SplitGraphAdaptorBase 
deba@2079
  1661
    : public GraphAdaptorBase<const _Graph> {
deba@2079
  1662
  public:
deba@1697
  1663
deba@2079
  1664
    typedef _Graph Graph;
deba@2079
  1665
deba@2079
  1666
    typedef GraphAdaptorBase<const _Graph> Parent;
deba@2079
  1667
deba@2079
  1668
    typedef typename Graph::Node GraphNode;
deba@2079
  1669
    typedef typename Graph::Edge GraphEdge;
deba@2079
  1670
deba@2079
  1671
    class Node;
deba@2079
  1672
    class Edge;
deba@2079
  1673
deba@2079
  1674
    template <typename T> class NodeMap;
deba@2079
  1675
    template <typename T> class EdgeMap;
deba@1697
  1676
    
deba@1697
  1677
deba@2079
  1678
    class Node : public GraphNode {
deba@2079
  1679
      friend class SplitGraphAdaptorBase;
deba@2079
  1680
      template <typename T> friend class NodeMap;
deba@2079
  1681
    private:
deba@1697
  1682
deba@2079
  1683
      bool in_node;
deba@2079
  1684
      Node(GraphNode _node, bool _in_node)
deba@2079
  1685
	: GraphNode(_node), in_node(_in_node) {}
deba@1697
  1686
      
deba@2079
  1687
    public:
deba@1697
  1688
deba@2079
  1689
      Node() {}
deba@2079
  1690
      Node(Invalid) : GraphNode(INVALID), in_node(true) {}
deba@2079
  1691
deba@2079
  1692
      bool operator==(const Node& node) const {
deba@2079
  1693
	return GraphNode::operator==(node) && in_node == node.in_node;
deba@2079
  1694
      }
deba@1697
  1695
      
deba@2079
  1696
      bool operator!=(const Node& node) const {
deba@2079
  1697
	return !(*this == node);
deba@2079
  1698
      }
deba@1697
  1699
      
deba@2079
  1700
      bool operator<(const Node& node) const {
deba@2079
  1701
	return GraphNode::operator<(node) || 
deba@2079
  1702
	  (GraphNode::operator==(node) && in_node < node.in_node);
deba@2079
  1703
      }
deba@2079
  1704
    };
deba@1697
  1705
deba@2079
  1706
    class Edge {
deba@2079
  1707
      friend class SplitGraphAdaptorBase;
deba@2079
  1708
      template <typename T> friend class EdgeMap;
deba@2079
  1709
    private:
deba@2079
  1710
      typedef BiVariant<GraphEdge, GraphNode> EdgeImpl;
deba@1697
  1711
deba@2079
  1712
      explicit Edge(const GraphEdge& edge) : item(edge) {}
deba@2079
  1713
      explicit Edge(const GraphNode& node) : item(node) {}
deba@2079
  1714
      
deba@2079
  1715
      EdgeImpl item;
deba@1697
  1716
deba@2079
  1717
    public:
deba@2079
  1718
      Edge() {}
deba@2079
  1719
      Edge(Invalid) : item(GraphEdge(INVALID)) {}
deba@2079
  1720
deba@2079
  1721
      bool operator==(const Edge& edge) const {
deba@2079
  1722
        if (item.firstState()) {
deba@2079
  1723
          if (edge.item.firstState()) {
deba@2079
  1724
            return item.first() == edge.item.first();
deba@2079
  1725
          }
deba@2079
  1726
        } else {
deba@2079
  1727
          if (edge.item.secondState()) {
deba@2079
  1728
            return item.second() == edge.item.second();
deba@2079
  1729
          }
deba@2079
  1730
        }
deba@2079
  1731
        return false;
deba@2079
  1732
      }
deba@1697
  1733
      
deba@2079
  1734
      bool operator!=(const Edge& edge) const {
deba@2079
  1735
	return !(*this == edge);
deba@2079
  1736
      }
deba@1697
  1737
      
deba@2079
  1738
      bool operator<(const Edge& edge) const {
deba@2079
  1739
        if (item.firstState()) {
deba@2079
  1740
          if (edge.item.firstState()) {
deba@2079
  1741
            return item.first() < edge.item.first();
deba@2079
  1742
          }
deba@2079
  1743
          return false;
deba@2079
  1744
        } else {
deba@2079
  1745
          if (edge.item.secondState()) {
deba@2079
  1746
            return item.second() < edge.item.second();
deba@2079
  1747
          }
deba@2079
  1748
          return true;
deba@2079
  1749
        }
deba@2079
  1750
      }
deba@1697
  1751
deba@2079
  1752
      operator GraphEdge() const { return item.first(); }
deba@2079
  1753
      operator GraphNode() const { return item.second(); }
deba@1697
  1754
deba@2079
  1755
    };
deba@1697
  1756
deba@2079
  1757
    void first(Node& node) const {
deba@2079
  1758
      Parent::first(node);
deba@2079
  1759
      node.in_node = true;
deba@2079
  1760
    }
deba@1697
  1761
deba@2079
  1762
    void next(Node& node) const {
deba@2079
  1763
      if (node.in_node) {
deba@2079
  1764
	node.in_node = false;
deba@2079
  1765
      } else {
deba@2079
  1766
	node.in_node = true;
deba@2079
  1767
	Parent::next(node);
deba@2079
  1768
      }
deba@2079
  1769
    }
deba@1697
  1770
deba@2079
  1771
    void first(Edge& edge) const {
deba@2079
  1772
      edge.item.setSecond();
deba@2079
  1773
      Parent::first(edge.item.second());
deba@2079
  1774
      if (edge.item.second() == INVALID) {
deba@2079
  1775
        edge.item.setFirst();
deba@2079
  1776
	Parent::first(edge.item.first());
deba@2079
  1777
      }
deba@2079
  1778
    }
deba@1697
  1779
deba@2079
  1780
    void next(Edge& edge) const {
deba@2079
  1781
      if (edge.item.secondState()) {
deba@2079
  1782
	Parent::next(edge.item.second());
deba@2079
  1783
        if (edge.item.second() == INVALID) {
deba@2079
  1784
          edge.item.setFirst();
deba@2079
  1785
          Parent::first(edge.item.first());
deba@2079
  1786
        }
deba@2079
  1787
      } else {
deba@2079
  1788
	Parent::next(edge.item.first());
deba@2079
  1789
      }      
deba@2079
  1790
    }
deba@1697
  1791
deba@2079
  1792
    void firstOut(Edge& edge, const Node& node) const {
deba@2079
  1793
      if (node.in_node) {
deba@2079
  1794
        edge.item.setSecond(node);
deba@2079
  1795
      } else {
deba@2079
  1796
        edge.item.setFirst();
deba@2079
  1797
	Parent::firstOut(edge.item.first(), node);
deba@2079
  1798
      }
deba@2079
  1799
    }
deba@1697
  1800
deba@2079
  1801
    void nextOut(Edge& edge) const {
deba@2079
  1802
      if (!edge.item.firstState()) {
deba@2079
  1803
	edge.item.setFirst(INVALID);
deba@2079
  1804
      } else {
deba@2079
  1805
	Parent::nextOut(edge.item.first());
deba@2079
  1806
      }      
deba@2079
  1807
    }
deba@1697
  1808
deba@2079
  1809
    void firstIn(Edge& edge, const Node& node) const {
deba@2079
  1810
      if (!node.in_node) {
deba@2079
  1811
        edge.item.setSecond(node);        
deba@2079
  1812
      } else {
deba@2079
  1813
        edge.item.setFirst();
deba@2079
  1814
	Parent::firstIn(edge.item.first(), node);
deba@2079
  1815
      }
deba@2079
  1816
    }
deba@1697
  1817
deba@2079
  1818
    void nextIn(Edge& edge) const {
deba@2079
  1819
      if (!edge.item.firstState()) {
deba@2079
  1820
	edge.item.setFirst(INVALID);
deba@2079
  1821
      } else {
deba@2079
  1822
	Parent::nextIn(edge.item.first());
deba@2079
  1823
      }
deba@2079
  1824
    }
deba@1697
  1825
deba@2079
  1826
    Node source(const Edge& edge) const {
deba@2079
  1827
      if (edge.item.firstState()) {
deba@2079
  1828
	return Node(Parent::source(edge.item.first()), false);
deba@2079
  1829
      } else {
deba@2079
  1830
	return Node(edge.item.second(), true);
deba@2079
  1831
      }
deba@2079
  1832
    }
deba@1697
  1833
deba@2079
  1834
    Node target(const Edge& edge) const {
deba@2079
  1835
      if (edge.item.firstState()) {
deba@2079
  1836
	return Node(Parent::target(edge.item.first()), true);
deba@2079
  1837
      } else {
deba@2079
  1838
	return Node(edge.item.second(), false);
deba@2079
  1839
      }
deba@2079
  1840
    }
deba@1697
  1841
deba@2079
  1842
    int id(const Node& node) const {
deba@2079
  1843
      return (Parent::id(node) << 1) | (node.in_node ? 0 : 1);
deba@2079
  1844
    }
deba@2079
  1845
    Node nodeFromId(int id) const {
deba@2079
  1846
      return Node(Parent::nodeFromId(id >> 1), (id & 1) == 0);
deba@2079
  1847
    }
deba@2079
  1848
    int maxNodeId() const {
deba@2079
  1849
      return 2 * Parent::maxNodeId() + 1;
deba@2079
  1850
    }
deba@1697
  1851
deba@2079
  1852
    int id(const Edge& edge) const {
deba@2079
  1853
      if (edge.item.firstState()) {
deba@2079
  1854
        return Parent::id(edge.item.first()) << 1;
deba@2079
  1855
      } else {
deba@2079
  1856
        return (Parent::id(edge.item.second()) << 1) | 1;
deba@2079
  1857
      }
deba@2079
  1858
    }
deba@2079
  1859
    Edge edgeFromId(int id) const {
deba@2079
  1860
      if ((id & 1) == 0) {
deba@2079
  1861
        return Edge(Parent::edgeFromId(id >> 1));
deba@2079
  1862
      } else {
deba@2079
  1863
        return Edge(Parent::nodeFromId(id >> 1));
deba@2079
  1864
      }
deba@2079
  1865
    }
deba@2079
  1866
    int maxEdgeId() const {
deba@2079
  1867
      return std::max(Parent::maxNodeId() << 1, 
deba@2079
  1868
                      (Parent::maxEdgeId() << 1) | 1);
deba@2079
  1869
    }
deba@1697
  1870
deba@2079
  1871
    /// \brief Returns true when the node is in-node.
deba@2079
  1872
    ///
deba@2079
  1873
    /// Returns true when the node is in-node.
deba@2079
  1874
    static bool inNode(const Node& node) {
deba@2079
  1875
      return node.in_node;
deba@2079
  1876
    }
deba@1697
  1877
deba@2079
  1878
    /// \brief Returns true when the node is out-node.
deba@2079
  1879
    ///
deba@2079
  1880
    /// Returns true when the node is out-node.
deba@2079
  1881
    static bool outNode(const Node& node) {
deba@2079
  1882
      return !node.in_node;
deba@2079
  1883
    }
deba@1697
  1884
deba@2079
  1885
    /// \brief Returns true when the edge is edge in the original graph.
deba@2079
  1886
    ///
deba@2079
  1887
    /// Returns true when the edge is edge in the original graph.
deba@2079
  1888
    static bool origEdge(const Edge& edge) {
deba@2079
  1889
      return edge.item.firstState();
deba@2079
  1890
    }
deba@1697
  1891
deba@2079
  1892
    /// \brief Returns true when the edge binds an in-node and an out-node.
deba@2079
  1893
    ///
deba@2079
  1894
    /// Returns true when the edge binds an in-node and an out-node.
deba@2079
  1895
    static bool bindEdge(const Edge& edge) {
deba@2079
  1896
      return edge.item.secondState();
deba@2079
  1897
    }
deba@1697
  1898
deba@2079
  1899
    /// \brief Gives back the in-node created from the \c node.
deba@2079
  1900
    ///
deba@2079
  1901
    /// Gives back the in-node created from the \c node.
deba@2079
  1902
    static Node inNode(const GraphNode& node) {
deba@2079
  1903
      return Node(node, true);
deba@2079
  1904
    }
deba@2079
  1905
deba@2079
  1906
    /// \brief Gives back the out-node created from the \c node.
deba@2079
  1907
    ///
deba@2079
  1908
    /// Gives back the out-node created from the \c node.
deba@2079
  1909
    static Node outNode(const GraphNode& node) {
deba@2079
  1910
      return Node(node, false);
deba@2079
  1911
    }
deba@2079
  1912
deba@2079
  1913
    /// \brief Gives back the edge binds the two part of the node.
deba@2079
  1914
    /// 
deba@2079
  1915
    /// Gives back the edge binds the two part of the node.
deba@2079
  1916
    static Edge edge(const GraphNode& node) {
deba@2079
  1917
      return Edge(node);
deba@2079
  1918
    }
deba@2079
  1919
deba@2079
  1920
    /// \brief Gives back the edge of the original edge.
deba@2079
  1921
    /// 
deba@2079
  1922
    /// Gives back the edge of the original edge.
deba@2079
  1923
    static Edge edge(const GraphEdge& edge) {
deba@2079
  1924
      return Edge(edge);
deba@2079
  1925
    }
deba@2079
  1926
deba@2079
  1927
    typedef True NodeNumTag;
deba@2079
  1928
deba@2079
  1929
    int nodeNum() const {
deba@2079
  1930
      return  2 * countNodes(*Parent::graph);
deba@2079
  1931
    }
deba@2079
  1932
deba@2079
  1933
    typedef True EdgeNumTag;
deba@1697
  1934
    
deba@2079
  1935
    int edgeNum() const {
deba@2079
  1936
      return countEdges(*Parent::graph) + countNodes(*Parent::graph);
deba@2079
  1937
    }
deba@1697
  1938
deba@2079
  1939
    typedef True FindEdgeTag;
deba@2079
  1940
deba@2079
  1941
    Edge findEdge(const Node& source, const Node& target, 
deba@2079
  1942
		  const Edge& prev = INVALID) const {
deba@2079
  1943
      if (inNode(source)) {
deba@2079
  1944
        if (outNode(target)) {
deba@2079
  1945
          if ((GraphNode&)source == (GraphNode&)target && prev == INVALID) {
deba@2079
  1946
            return Edge(source);
deba@2079
  1947
          }
deba@2079
  1948
        }
deba@2079
  1949
      } else {
deba@2079
  1950
        if (inNode(target)) {
deba@2079
  1951
          return Edge(findEdge(*Parent::graph, source, target, prev));
deba@2079
  1952
        }
deba@2079
  1953
      }
deba@2079
  1954
      return INVALID;
deba@2079
  1955
    }
deba@1697
  1956
    
deba@2079
  1957
    template <typename T>
deba@2079
  1958
    class NodeMap : public MapBase<Node, T> {
deba@2079
  1959
      typedef typename Parent::template NodeMap<T> NodeImpl;
deba@2079
  1960
    public:
deba@2079
  1961
      NodeMap(const SplitGraphAdaptorBase& _graph) 
deba@2079
  1962
	: inNodeMap(_graph), outNodeMap(_graph) {}
deba@2079
  1963
      NodeMap(const SplitGraphAdaptorBase& _graph, const T& t) 
deba@2079
  1964
	: inNodeMap(_graph, t), outNodeMap(_graph, t) {}
deba@1697
  1965
      
deba@2079
  1966
      void set(const Node& key, const T& val) {
deba@2079
  1967
	if (SplitGraphAdaptorBase::inNode(key)) { inNodeMap.set(key, val); }
deba@2079
  1968
	else {outNodeMap.set(key, val); }
deba@2079
  1969
      }
deba@1697
  1970
      
deba@2079
  1971
      typename MapTraits<NodeImpl>::ReturnValue 
deba@2079
  1972
      operator[](const Node& key) {
deba@2079
  1973
	if (SplitGraphAdaptorBase::inNode(key)) { return inNodeMap[key]; }
deba@2079
  1974
	else { return outNodeMap[key]; }
deba@2079
  1975
      }
deba@1697
  1976
deba@2079
  1977
      typename MapTraits<NodeImpl>::ConstReturnValue
deba@2079
  1978
      operator[](const Node& key) const {
deba@2079
  1979
	if (SplitGraphAdaptorBase::inNode(key)) { return inNodeMap[key]; }
deba@2079
  1980
	else { return outNodeMap[key]; }
deba@2079
  1981
      }
deba@1697
  1982
deba@2079
  1983
    private:
deba@2079
  1984
      NodeImpl inNodeMap, outNodeMap;
deba@2079
  1985
    };
deba@1697
  1986
deba@2079
  1987
    template <typename T>
deba@2079
  1988
    class EdgeMap : public MapBase<Edge, T> {
deba@2079
  1989
      typedef typename Parent::template EdgeMap<T> EdgeMapImpl;
deba@2079
  1990
      typedef typename Parent::template NodeMap<T> NodeMapImpl;
deba@2079
  1991
    public:
deba@2079
  1992
deba@2079
  1993
      EdgeMap(const SplitGraphAdaptorBase& _graph) 
deba@2079
  1994
	: edge_map(_graph), node_map(_graph) {}
deba@2079
  1995
      EdgeMap(const SplitGraphAdaptorBase& _graph, const T& t) 
deba@2079
  1996
	: edge_map(_graph, t), node_map(_graph, t) {}
deba@1697
  1997
      
deba@2079
  1998
      void set(const Edge& key, const T& val) {
deba@2079
  1999
	if (SplitGraphAdaptorBase::origEdge(key)) { 
deba@2079
  2000
          edge_map.set(key.item.first(), val); 
deba@2079
  2001
        } else {
deba@2079
  2002
          node_map.set(key.item.second(), val); 
deba@2079
  2003
        }
deba@2079
  2004
      }
deba@1697
  2005
      
deba@2079
  2006
      typename MapTraits<EdgeMapImpl>::ReturnValue
deba@2079
  2007
      operator[](const Edge& key) {
deba@2079
  2008
	if (SplitGraphAdaptorBase::origEdge(key)) { 
deba@2079
  2009
          return edge_map[key.item.first()];
deba@2079
  2010
        } else {
deba@2079
  2011
          return node_map[key.item.second()];
deba@2079
  2012
        }
deba@2079
  2013
      }
deba@1697
  2014
deba@2079
  2015
      typename MapTraits<EdgeMapImpl>::ConstReturnValue
deba@2079
  2016
      operator[](const Edge& key) const {
deba@2079
  2017
	if (SplitGraphAdaptorBase::origEdge(key)) { 
deba@2079
  2018
          return edge_map[key.item.first()];
deba@2079
  2019
        } else {
deba@2079
  2020
          return node_map[key.item.second()];
deba@2079
  2021
        }
deba@2079
  2022
      }
deba@1697
  2023
deba@2079
  2024
    private:
deba@2079
  2025
      typename Parent::template EdgeMap<T> edge_map;
deba@2079
  2026
      typename Parent::template NodeMap<T> node_map;
deba@2079
  2027
    };
deba@1697
  2028
deba@1697
  2029
deba@2079
  2030
  };
deba@1697
  2031
deba@2079
  2032
  template <typename _Graph, typename NodeEnable = void, 
deba@2079
  2033
            typename EdgeEnable = void>
deba@2079
  2034
  class AlterableSplitGraphAdaptor 
deba@2079
  2035
    : public GraphAdaptorExtender<SplitGraphAdaptorBase<_Graph> > {
deba@2079
  2036
  public:
deba@1697
  2037
deba@2079
  2038
    typedef GraphAdaptorExtender<SplitGraphAdaptorBase<_Graph> > Parent;
deba@2079
  2039
    typedef _Graph Graph;
deba@1697
  2040
deba@2079
  2041
    typedef typename Graph::Node GraphNode;
deba@2079
  2042
    typedef typename Graph::Node GraphEdge;
deba@1697
  2043
deba@2079
  2044
  protected:
deba@2079
  2045
deba@2079
  2046
    AlterableSplitGraphAdaptor() : Parent() {}
deba@2079
  2047
deba@2079
  2048
  public:
deba@2079
  2049
    
deba@2079
  2050
    typedef InvalidType NodeNotifier;
deba@2079
  2051
    typedef InvalidType EdgeNotifier;
deba@2079
  2052
deba@2079
  2053
  };
deba@2079
  2054
deba@2079
  2055
  template <typename _Graph, typename EdgeEnable>
deba@2079
  2056
  class AlterableSplitGraphAdaptor<
deba@2079
  2057
    _Graph,
deba@2079
  2058
    typename enable_if<typename _Graph::NodeNotifier::Notifier>::type,
deba@2079
  2059
    EdgeEnable> 
deba@2079
  2060
      : public GraphAdaptorExtender<SplitGraphAdaptorBase<_Graph> > {
deba@2079
  2061
  public:
deba@2079
  2062
deba@2079
  2063
    typedef GraphAdaptorExtender<SplitGraphAdaptorBase<_Graph> > Parent;
deba@2079
  2064
    typedef _Graph Graph;
deba@2079
  2065
deba@2079
  2066
    typedef typename Graph::Node GraphNode;
deba@2079
  2067
    typedef typename Graph::Edge GraphEdge;
deba@2079
  2068
deba@2079
  2069
    typedef typename Parent::Node Node;
deba@2079
  2070
    typedef typename Parent::Edge Edge;
deba@2079
  2071
 
deba@2079
  2072
  protected:
deba@2079
  2073
deba@2079
  2074
    AlterableSplitGraphAdaptor() 
deba@2079
  2075
      : Parent(), node_notifier(*this), node_notifier_proxy(*this) {}
deba@2079
  2076
deba@2079
  2077
    void setGraph(_Graph& graph) {
deba@2079
  2078
      Parent::setGraph(graph);
deba@2079
  2079
      node_notifier_proxy.setNotifier(graph.getNotifier(GraphNode()));
deba@2079
  2080
    }
deba@2079
  2081
deba@2079
  2082
  public:
deba@2079
  2083
deba@2079
  2084
    ~AlterableSplitGraphAdaptor() {
deba@2079
  2085
      node_notifier.clear();
deba@2079
  2086
    }
deba@2079
  2087
deba@2079
  2088
    typedef AlterationNotifier<AlterableSplitGraphAdaptor, Node> NodeNotifier;
deba@2079
  2089
    typedef InvalidType EdgeNotifier;
deba@2079
  2090
deba@2079
  2091
    NodeNotifier& getNotifier(Node) const { return node_notifier; }
deba@2079
  2092
deba@2079
  2093
  protected:
deba@2079
  2094
deba@2079
  2095
    class NodeNotifierProxy : public Graph::NodeNotifier::ObserverBase {
deba@2079
  2096
    public:
deba@2079
  2097
deba@2079
  2098
      typedef typename Graph::NodeNotifier::ObserverBase Parent;
deba@2079
  2099
      typedef AlterableSplitGraphAdaptor AdaptorBase;
deba@1697
  2100
      
deba@2079
  2101
      NodeNotifierProxy(const AdaptorBase& _adaptor)
deba@2079
  2102
        : Parent(), adaptor(&_adaptor) {
deba@2079
  2103
      }
deba@2079
  2104
deba@2079
  2105
      virtual ~NodeNotifierProxy() {
deba@2079
  2106
        if (Parent::attached()) {
deba@2079
  2107
          Parent::detach();
deba@2079
  2108
        }
deba@2079
  2109
      }
deba@2079
  2110
deba@2079
  2111
      void setNotifier(typename Graph::NodeNotifier& graph_notifier) {
deba@2079
  2112
        Parent::attach(graph_notifier);
deba@2079
  2113
      }
deba@2079
  2114
deba@1697
  2115
      
deba@2079
  2116
    protected:
deba@2079
  2117
deba@2079
  2118
      virtual void add(const GraphNode& gn) {
deba@2079
  2119
        std::vector<Node> nodes;
deba@2079
  2120
        nodes.push_back(AdaptorBase::Parent::inNode(gn));
deba@2079
  2121
        nodes.push_back(AdaptorBase::Parent::outNode(gn));
deba@2079
  2122
        adaptor->getNotifier(Node()).add(nodes);
deba@2079
  2123
      }
deba@2079
  2124
deba@2079
  2125
      virtual void add(const std::vector<GraphNode>& gn) {
deba@2079
  2126
        std::vector<Node> nodes;
deba@2079
  2127
        for (int i = 0; i < (int)gn.size(); ++i) {
deba@2079
  2128
          nodes.push_back(AdaptorBase::Parent::inNode(gn[i]));
deba@2079
  2129
          nodes.push_back(AdaptorBase::Parent::outNode(gn[i]));
deba@2079
  2130
        }
deba@2079
  2131
        adaptor->getNotifier(Node()).add(nodes);
deba@2079
  2132
      }
deba@2079
  2133
deba@2079
  2134
      virtual void erase(const GraphNode& gn) {
deba@2079
  2135
        std::vector<Node> nodes;
deba@2079
  2136
        nodes.push_back(AdaptorBase::Parent::inNode(gn));
deba@2079
  2137
        nodes.push_back(AdaptorBase::Parent::outNode(gn));
deba@2079
  2138
        adaptor->getNotifier(Node()).erase(nodes);
deba@2079
  2139
      }
deba@2079
  2140
deba@2079
  2141
      virtual void erase(const std::vector<GraphNode>& gn) {
deba@2079
  2142
        std::vector<Node> nodes;
deba@2079
  2143
        for (int i = 0; i < (int)gn.size(); ++i) {
deba@2079
  2144
          nodes.push_back(AdaptorBase::Parent::inNode(gn[i]));
deba@2079
  2145
          nodes.push_back(AdaptorBase::Parent::outNode(gn[i]));
deba@2079
  2146
        }
deba@2079
  2147
        adaptor->getNotifier(Node()).erase(nodes);
deba@2079
  2148
      }
deba@2079
  2149
      virtual void build() {
deba@2079
  2150
        adaptor->getNotifier(Node()).build();
deba@2079
  2151
      }
deba@2079
  2152
      virtual void clear() {
deba@2079
  2153
        adaptor->getNotifier(Node()).clear();
deba@2079
  2154
      }
deba@2079
  2155
deba@2079
  2156
      const AdaptorBase* adaptor;
deba@2079
  2157
    };
deba@2079
  2158
deba@2079
  2159
deba@2079
  2160
    mutable NodeNotifier node_notifier;
deba@2079
  2161
deba@2079
  2162
    NodeNotifierProxy node_notifier_proxy;
deba@2079
  2163
deba@2079
  2164
  };
deba@2079
  2165
deba@2079
  2166
  template <typename _Graph>
deba@2079
  2167
  class AlterableSplitGraphAdaptor<
deba@2079
  2168
    _Graph,
deba@2079
  2169
    typename enable_if<typename _Graph::NodeNotifier::Notifier>::type,
deba@2079
  2170
    typename enable_if<typename _Graph::EdgeNotifier::Notifier>::type> 
deba@2079
  2171
      : public GraphAdaptorExtender<SplitGraphAdaptorBase<_Graph> > {
deba@2079
  2172
  public:
deba@2079
  2173
deba@2079
  2174
    typedef GraphAdaptorExtender<SplitGraphAdaptorBase<_Graph> > Parent;
deba@2079
  2175
    typedef _Graph Graph;
deba@2079
  2176
deba@2079
  2177
    typedef typename Graph::Node GraphNode;
deba@2079
  2178
    typedef typename Graph::Edge GraphEdge;
deba@2079
  2179
deba@2079
  2180
    typedef typename Parent::Node Node;
deba@2079
  2181
    typedef typename Parent::Edge Edge;
deba@2079
  2182
 
deba@2079
  2183
  protected:
deba@2079
  2184
    
deba@2079
  2185
    AlterableSplitGraphAdaptor() 
deba@2079
  2186
      : Parent(), node_notifier(*this), edge_notifier(*this), 
deba@2079
  2187
        node_notifier_proxy(*this), edge_notifier_proxy(*this) {}
deba@2079
  2188
    
deba@2079
  2189
    void setGraph(_Graph& graph) {
deba@2079
  2190
      Parent::setGraph(graph);
deba@2079
  2191
      node_notifier_proxy.setNotifier(graph.getNotifier(GraphNode()));
deba@2079
  2192
      edge_notifier_proxy.setNotifier(graph.getNotifier(GraphEdge()));
deba@2079
  2193
    }
deba@2079
  2194
deba@2079
  2195
  public:
deba@2079
  2196
deba@2079
  2197
    ~AlterableSplitGraphAdaptor() {
deba@2079
  2198
      node_notifier.clear();
deba@2079
  2199
      edge_notifier.clear();
deba@2079
  2200
    }
deba@2079
  2201
deba@2079
  2202
    typedef AlterationNotifier<AlterableSplitGraphAdaptor, Node> NodeNotifier;
deba@2079
  2203
    typedef AlterationNotifier<AlterableSplitGraphAdaptor, Edge> EdgeNotifier;
deba@2079
  2204
deba@2079
  2205
    NodeNotifier& getNotifier(Node) const { return node_notifier; }
deba@2079
  2206
    EdgeNotifier& getNotifier(Edge) const { return edge_notifier; }
deba@2079
  2207
deba@2079
  2208
  protected:
deba@2079
  2209
deba@2079
  2210
    class NodeNotifierProxy : public Graph::NodeNotifier::ObserverBase {
deba@2079
  2211
    public:
deba@1697
  2212
      
deba@2079
  2213
      typedef typename Graph::NodeNotifier::ObserverBase Parent;
deba@2079
  2214
      typedef AlterableSplitGraphAdaptor AdaptorBase;
deba@2079
  2215
      
deba@2079
  2216
      NodeNotifierProxy(const AdaptorBase& _adaptor)
deba@2079
  2217
        : Parent(), adaptor(&_adaptor) {
deba@2079
  2218
      }
deba@1697
  2219
deba@2079
  2220
      virtual ~NodeNotifierProxy() {
deba@2079
  2221
        if (Parent::attached()) {
deba@2079
  2222
          Parent::detach();
deba@2079
  2223
        }
deba@2079
  2224
      }
deba@1697
  2225
deba@2079
  2226
      void setNotifier(typename Graph::NodeNotifier& graph_notifier) {
deba@2079
  2227
        Parent::attach(graph_notifier);
deba@2079
  2228
      }
deba@1697
  2229
deba@2079
  2230
      
deba@2079
  2231
    protected:
deba@1697
  2232
deba@2079
  2233
      virtual void add(const GraphNode& gn) {
deba@2079
  2234
        std::vector<Node> nodes;
deba@2079
  2235
        nodes.push_back(AdaptorBase::Parent::inNode(gn));
deba@2079
  2236
        nodes.push_back(AdaptorBase::Parent::outNode(gn));
deba@2079
  2237
        adaptor->getNotifier(Node()).add(nodes);
deba@2079
  2238
        adaptor->getNotifier(Edge()).add(AdaptorBase::Parent::edge(gn));
deba@2079
  2239
      }
deba@2079
  2240
      virtual void add(const std::vector<GraphNode>& gn) {
deba@2079
  2241
        std::vector<Node> nodes;
deba@2079
  2242
        std::vector<Edge> edges;
deba@2079
  2243
        for (int i = 0; i < (int)gn.size(); ++i) {
deba@2079
  2244
          edges.push_back(AdaptorBase::Parent::edge(gn[i]));
deba@2079
  2245
          nodes.push_back(AdaptorBase::Parent::inNode(gn[i]));
deba@2079
  2246
          nodes.push_back(AdaptorBase::Parent::outNode(gn[i]));
deba@2079
  2247
        }
deba@2079
  2248
        adaptor->getNotifier(Node()).add(nodes);
deba@2079
  2249
        adaptor->getNotifier(Edge()).add(edges);
deba@2079
  2250
      }
deba@2079
  2251
      virtual void erase(const GraphNode& gn) {
deba@2079
  2252
        adaptor->getNotifier(Edge()).erase(AdaptorBase::Parent::edge(gn));
deba@2079
  2253
        std::vector<Node> nodes;
deba@2079
  2254
        nodes.push_back(AdaptorBase::Parent::inNode(gn));
deba@2079
  2255
        nodes.push_back(AdaptorBase::Parent::outNode(gn));
deba@2079
  2256
        adaptor->getNotifier(Node()).erase(nodes);
deba@2079
  2257
      }
deba@2079
  2258
      virtual void erase(const std::vector<GraphNode>& gn) {
deba@2079
  2259
        std::vector<Node> nodes;
deba@2079
  2260
        std::vector<Edge> edges;
deba@2079
  2261
        for (int i = 0; i < (int)gn.size(); ++i) {
deba@2079
  2262
          edges.push_back(AdaptorBase::Parent::edge(gn[i]));
deba@2079
  2263
          nodes.push_back(AdaptorBase::Parent::inNode(gn[i]));
deba@2079
  2264
          nodes.push_back(AdaptorBase::Parent::outNode(gn[i]));
deba@2079
  2265
        }
deba@2079
  2266
        adaptor->getNotifier(Edge()).erase(edges);
deba@2079
  2267
        adaptor->getNotifier(Node()).erase(nodes);
deba@2079
  2268
      }
deba@2079
  2269
      virtual void build() {
deba@2079
  2270
        std::vector<Edge> edges;
deba@2079
  2271
        const typename Parent::Notifier* notifier = Parent::getNotifier();
deba@2079
  2272
        GraphNode it;
deba@2079
  2273
        for (notifier->first(it); it != INVALID; notifier->next(it)) {
deba@2079
  2274
          edges.push_back(AdaptorBase::Parent::edge(it));
deba@2079
  2275
        }
deba@2079
  2276
        adaptor->getNotifier(Node()).build();
deba@2079
  2277
        adaptor->getNotifier(Edge()).add(edges);        
deba@2079
  2278
      }
deba@2079
  2279
      virtual void clear() {
deba@2079
  2280
        std::vector<Edge> edges;
deba@2079
  2281
        const typename Parent::Notifier* notifier = Parent::getNotifier();
deba@2079
  2282
        GraphNode it;
deba@2079
  2283
        for (notifier->first(it); it != INVALID; notifier->next(it)) {
deba@2079
  2284
          edges.push_back(AdaptorBase::Parent::edge(it));
deba@2079
  2285
        }
deba@2079
  2286
        adaptor->getNotifier(Edge()).erase(edges);        
deba@2079
  2287
        adaptor->getNotifier(Node()).clear();
deba@2079
  2288
      }
deba@1697
  2289
deba@2079
  2290
      const AdaptorBase* adaptor;
deba@2079
  2291
    };
deba@1697
  2292
deba@2079
  2293
    class EdgeNotifierProxy : public Graph::EdgeNotifier::ObserverBase {
deba@2079
  2294
    public:
deba@2079
  2295
deba@2079
  2296
      typedef typename Graph::EdgeNotifier::ObserverBase Parent;
deba@2079
  2297
      typedef AlterableSplitGraphAdaptor AdaptorBase;
deba@1697
  2298
      
deba@2079
  2299
      EdgeNotifierProxy(const AdaptorBase& _adaptor)
deba@2079
  2300
        : Parent(), adaptor(&_adaptor) {
deba@2079
  2301
      }
deba@1697
  2302
deba@2079
  2303
      virtual ~EdgeNotifierProxy() {
deba@2079
  2304
        if (Parent::attached()) {
deba@2079
  2305
          Parent::detach();
deba@2079
  2306
        }
deba@2079
  2307
      }
deba@1697
  2308
deba@2079
  2309
      void setNotifier(typename Graph::EdgeNotifier& graph_notifier) {
deba@2079
  2310
        Parent::attach(graph_notifier);
deba@2079
  2311
      }
deba@1697
  2312
deba@2079
  2313
      
deba@2079
  2314
    protected:
deba@1697
  2315
deba@2079
  2316
      virtual void add(const GraphEdge& ge) {
deba@2079
  2317
        adaptor->getNotifier(Edge()).add(AdaptorBase::edge(ge));
deba@2079
  2318
      }
deba@2079
  2319
      virtual void add(const std::vector<GraphEdge>& ge) {
deba@2079
  2320
        std::vector<Edge> edges;
deba@2079
  2321
        for (int i = 0; i < (int)ge.size(); ++i) {
deba@2079
  2322
          edges.push_back(AdaptorBase::edge(ge[i]));
deba@2079
  2323
        }
deba@2079
  2324
        adaptor->getNotifier(Edge()).add(edges);
deba@2079
  2325
      }
deba@2079
  2326
      virtual void erase(const GraphEdge& ge) {
deba@2079
  2327
        adaptor->getNotifier(Edge()).erase(AdaptorBase::edge(ge));
deba@2079
  2328
      }
deba@2079
  2329
      virtual void erase(const std::vector<GraphEdge>& ge) {
deba@2079
  2330
        std::vector<Edge> edges;
deba@2079
  2331
        for (int i = 0; i < (int)ge.size(); ++i) {
deba@2079
  2332
          edges.push_back(AdaptorBase::edge(ge[i]));
deba@2079
  2333
        }
deba@2079
  2334
        adaptor->getNotifier(Edge()).erase(edges);
deba@2079
  2335
      }
deba@2079
  2336
      virtual void build() {
deba@2079
  2337
        std::vector<Edge> edges;
deba@2079
  2338
        const typename Parent::Notifier* notifier = Parent::getNotifier();
deba@2079
  2339
        GraphEdge it;
deba@2079
  2340
        for (notifier->first(it); it != INVALID; notifier->next(it)) {
deba@2079
  2341
          edges.push_back(AdaptorBase::Parent::edge(it));
deba@2079
  2342
        }
deba@2079
  2343
        adaptor->getNotifier(Edge()).add(edges);
deba@2079
  2344
      }
deba@2079
  2345
      virtual void clear() {
deba@2079
  2346
        std::vector<Edge> edges;
deba@2079
  2347
        const typename Parent::Notifier* notifier = Parent::getNotifier();
deba@2079
  2348
        GraphEdge it;
deba@2079
  2349
        for (notifier->first(it); it != INVALID; notifier->next(it)) {
deba@2079
  2350
          edges.push_back(AdaptorBase::Parent::edge(it));
deba@2079
  2351
        }
deba@2079
  2352
        adaptor->getNotifier(Edge()).erase(edges);
deba@2079
  2353
      }
deba@1697
  2354
deba@2079
  2355
      const AdaptorBase* adaptor;
deba@2079
  2356
    };
deba@2079
  2357
deba@2079
  2358
deba@2079
  2359
    mutable NodeNotifier node_notifier;
deba@2079
  2360
    mutable EdgeNotifier edge_notifier;
deba@2079
  2361
deba@2079
  2362
    NodeNotifierProxy node_notifier_proxy;
deba@2079
  2363
    EdgeNotifierProxy edge_notifier_proxy;
deba@2079
  2364
deba@2079
  2365
  };
deba@2079
  2366
deba@2079
  2367
  /// \ingroup graph_adaptors
deba@2079
  2368
  ///
deba@2081
  2369
  /// \brief Split graph adaptor class
deba@2079
  2370
  /// 
deba@2079
  2371
  /// This is an graph adaptor which splits all node into an in-node
deba@2079
  2372
  /// and an out-node. Formaly, the adaptor replaces each \f$ u \f$
deba@2079
  2373
  /// node in the graph with two node, \f$ u_{in} \f$ node and 
deba@2079
  2374
  /// \f$ u_{out} \f$ node. If there is an \f$ (v, u) \f$ edge in the 
deba@2079
  2375
  /// original graph the new target of the edge will be \f$ u_{in} \f$ and
deba@2079
  2376
  /// similarly the source of the original \f$ (u, v) \f$ edge will be
deba@2079
  2377
  /// \f$ u_{out} \f$.  The adaptor will add for each node in the 
deba@2079
  2378
  /// original graph an additional edge which will connect 
deba@2079
  2379
  /// \f$ (u_{in}, u_{out}) \f$.
deba@2079
  2380
  ///
deba@2079
  2381
  /// The aim of this class is to run algorithm with node costs if the 
deba@2079
  2382
  /// algorithm can use directly just edge costs. In this case we should use
deba@2079
  2383
  /// a \c SplitGraphAdaptor and set the node cost of the graph to the
deba@2079
  2384
  /// bind edge in the adapted graph.
deba@2079
  2385
  /// 
deba@2079
  2386
  /// By example a maximum flow algoritm can compute how many edge
deba@2079
  2387
  /// disjoint paths are in the graph. But we would like to know how
deba@2079
  2388
  /// many node disjoint paths are in the graph. First we have to
deba@2079
  2389
  /// adapt the graph with the \c SplitGraphAdaptor. Then run the flow
deba@2079
  2390
  /// algorithm on the adapted graph. The bottleneck of the flow will
deba@2079
  2391
  /// be the bind edges which bounds the flow with the count of the
deba@2079
  2392
  /// node disjoint paths.
deba@2079
  2393
  ///
deba@2079
  2394
  ///\code
deba@2079
  2395
  ///
deba@2079
  2396
  /// typedef SplitGraphAdaptor<SmartGraph> SGraph;
deba@2079
  2397
  ///
deba@2079
  2398
  /// SGraph sgraph(graph);
deba@2079
  2399
  ///
deba@2079
  2400
  /// typedef ConstMap<SGraph::Edge, int> SCapacity;
deba@2079
  2401
  /// SCapacity scapacity(1);
deba@2079
  2402
  ///
deba@2079
  2403
  /// SGraph::EdgeMap<int> sflow(sgraph);
deba@2079
  2404
  ///
deba@2079
  2405
  /// Preflow<SGraph, int, SCapacity> 
deba@2079
  2406
  ///   spreflow(sgraph, SGraph::outNode(source),SGraph::inNode(target),  
deba@2079
  2407
  ///            scapacity, sflow);
deba@2079
  2408
  ///                                            
deba@2079
  2409
  /// spreflow.run();
deba@2079
  2410
  ///
deba@2079
  2411
  ///\endcode
deba@2079
  2412
  ///
deba@2079
  2413
  /// The result of the mamixum flow on the original graph
deba@2079
  2414
  /// shows the next figure:
deba@2079
  2415
  ///
deba@2079
  2416
  /// \image html edge_disjoint.png
deba@2079
  2417
  /// \image latex edge_disjoint.eps "Edge disjoint paths" width=\textwidth
deba@2079
  2418
  /// 
deba@2079
  2419
  /// And the maximum flow on the adapted graph:
deba@2079
  2420
  ///
deba@2079
  2421
  /// \image html node_disjoint.png
deba@2079
  2422
  /// \image latex node_disjoint.eps "Node disjoint paths" width=\textwidth
deba@2079
  2423
  ///
deba@2079
  2424
  /// The second solution contains just 3 disjoint paths while the first 4.
deba@2084
  2425
  /// The full code can be found in the \ref disjoint_paths_demo.cc demo file.
deba@2079
  2426
  ///
deba@2079
  2427
  /// This graph adaptor is fully conform to the 
deba@2111
  2428
  /// \ref concept::Graph "Graph" concept and
deba@2079
  2429
  /// contains some additional member functions and types. The 
deba@2079
  2430
  /// documentation of some member functions may be found just in the
deba@2079
  2431
  /// SplitGraphAdaptorBase class.
deba@2079
  2432
  ///
deba@2079
  2433
  /// \sa SplitGraphAdaptorBase
deba@2079
  2434
  template <typename _Graph>
deba@2079
  2435
  class SplitGraphAdaptor : public AlterableSplitGraphAdaptor<_Graph> {
deba@2079
  2436
  public:
deba@2079
  2437
    typedef AlterableSplitGraphAdaptor<_Graph> Parent;
deba@2079
  2438
deba@2079
  2439
    typedef typename Parent::Node Node;
deba@2079
  2440
    typedef typename Parent::Edge Edge;
deba@2079
  2441
deba@2079
  2442
    /// \brief Constructor of the adaptor.
deba@2079
  2443
    ///
deba@2079
  2444
    /// Constructor of the adaptor.
deba@2079
  2445
    SplitGraphAdaptor(_Graph& graph) {
deba@2079
  2446
      Parent::setGraph(graph);
deba@2079
  2447
    }
deba@2079
  2448
deba@2079
  2449
    /// \brief NodeMap combined from two original NodeMap
deba@2079
  2450
    ///
deba@2079
  2451
    /// This class adapt two of the original graph NodeMap to
deba@2079
  2452
    /// get a node map on the adapted graph.
deba@2079
  2453
    template <typename InNodeMap, typename OutNodeMap>
deba@2079
  2454
    class CombinedNodeMap {
deba@2079
  2455
    public:
deba@2079
  2456
deba@2079
  2457
      typedef Node Key;
deba@2079
  2458
      typedef typename InNodeMap::Value Value;
deba@2079
  2459
deba@2079
  2460
      /// \brief Constructor
deba@2079
  2461
      ///
deba@2079
  2462
      /// Constructor.
deba@2079
  2463
      CombinedNodeMap(InNodeMap& _inNodeMap, OutNodeMap& _outNodeMap) 
deba@2079
  2464
	: inNodeMap(_inNodeMap), outNodeMap(_outNodeMap) {}
deba@2079
  2465
deba@2079
  2466
      /// \brief The subscript operator.
deba@2079
  2467
      ///
deba@2079
  2468
      /// The subscript operator.
deba@2079
  2469
      Value& operator[](const Key& key) {
deba@2079
  2470
	if (Parent::inNode(key)) {
deba@2079
  2471
	  return inNodeMap[key];
deba@2079
  2472
	} else {
deba@2079
  2473
	  return outNodeMap[key];
deba@2079
  2474
	}
deba@2079
  2475
      }
deba@2079
  2476
deba@2079
  2477
      /// \brief The const subscript operator.
deba@2079
  2478
      ///
deba@2079
  2479
      /// The const subscript operator.
deba@2079
  2480
      Value operator[](const Key& key) const {
deba@2079
  2481
	if (Parent::inNode(key)) {
deba@2079
  2482
	  return inNodeMap[key];
deba@2079
  2483
	} else {
deba@2079
  2484
	  return outNodeMap[key];
deba@2079
  2485
	}
deba@2079
  2486
      }
deba@2079
  2487
deba@2079
  2488
      /// \brief The setter function of the map.
deba@2079
  2489
      /// 
deba@2079
  2490
      /// The setter function of the map.
deba@2079
  2491
      void set(const Key& key, const Value& value) {
deba@2079
  2492
	if (Parent::inNode(key)) {
deba@2079
  2493
	  inNodeMap.set(key, value);
deba@2079
  2494
	} else {
deba@2079
  2495
	  outNodeMap.set(key, value);
deba@2079
  2496
	}
deba@2079
  2497
      }
deba@2079
  2498
      
deba@2079
  2499
    private:
deba@2079
  2500
      
deba@2079
  2501
      InNodeMap& inNodeMap;
deba@2079
  2502
      OutNodeMap& outNodeMap;
deba@2079
  2503
      
deba@2079
  2504
    };
deba@2079
  2505
deba@2079
  2506
deba@2079
  2507
    /// \brief Just gives back a combined node map.
deba@2079
  2508
    /// 
deba@2079
  2509
    /// Just gives back a combined node map.
deba@2079
  2510
    template <typename InNodeMap, typename OutNodeMap>
deba@2079
  2511
    static CombinedNodeMap<InNodeMap, OutNodeMap> 
deba@2079
  2512
    combinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) {
deba@2079
  2513
      return CombinedNodeMap<InNodeMap, OutNodeMap>(in_map, out_map);
deba@2079
  2514
    }
deba@2079
  2515
deba@2079
  2516
    template <typename InNodeMap, typename OutNodeMap>
deba@2079
  2517
    static CombinedNodeMap<const InNodeMap, OutNodeMap> 
deba@2079
  2518
    combinedNodeMap(const InNodeMap& in_map, OutNodeMap& out_map) {
deba@2079
  2519
      return CombinedNodeMap<const InNodeMap, OutNodeMap>(in_map, out_map);
deba@2079
  2520
    }
deba@2079
  2521
deba@2079
  2522
    template <typename InNodeMap, typename OutNodeMap>
deba@2079
  2523
    static CombinedNodeMap<InNodeMap, const OutNodeMap> 
deba@2079
  2524
    combinedNodeMap(InNodeMap& in_map, const OutNodeMap& out_map) {
deba@2079
  2525
      return CombinedNodeMap<InNodeMap, const OutNodeMap>(in_map, out_map);
deba@2079
  2526
    }
deba@2079
  2527
deba@2079
  2528
    template <typename InNodeMap, typename OutNodeMap>
deba@2079
  2529
    static CombinedNodeMap<const InNodeMap, const OutNodeMap> 
deba@2079
  2530
    combinedNodeMap(const InNodeMap& in_map, const OutNodeMap& out_map) {
deba@2079
  2531
      return CombinedNodeMap<const InNodeMap, 
deba@2079
  2532
        const OutNodeMap>(in_map, out_map);
deba@2079
  2533
    }
deba@2079
  2534
deba@2079
  2535
    /// \brief EdgeMap combined from an original EdgeMap and NodeMap
deba@2079
  2536
    ///
deba@2079
  2537
    /// This class adapt an original graph EdgeMap and NodeMap to
deba@2079
  2538
    /// get an edge map on the adapted graph.
deba@2079
  2539
    template <typename GraphEdgeMap, typename GraphNodeMap>
deba@2079
  2540
    class CombinedEdgeMap 
deba@2079
  2541
      : public MapBase<Edge, typename GraphEdgeMap::Value> {
deba@2079
  2542
    public:
deba@2079
  2543
      typedef MapBase<Edge, typename GraphEdgeMap::Value> Parent;
deba@2079
  2544
deba@2079
  2545
      typedef typename Parent::Key Key;
deba@2079
  2546
      typedef typename Parent::Value Value;
deba@2079
  2547
deba@2079
  2548
      /// \brief Constructor
deba@2079
  2549
      ///
deba@2079
  2550
      /// Constructor.
deba@2079
  2551
      CombinedEdgeMap(GraphEdgeMap& _edge_map, GraphNodeMap& _node_map) 
deba@2079
  2552
	: edge_map(_edge_map), node_map(_node_map) {}
deba@2079
  2553
deba@2079
  2554
      /// \brief The subscript operator.
deba@2079
  2555
      ///
deba@2079
  2556
      /// The subscript operator.
deba@2079
  2557
      void set(const Edge& edge, const Value& val) {
deba@2079
  2558
	if (Parent::origEdge(edge)) {
deba@2079
  2559
	  edge_map.set(edge, val);
deba@2079
  2560
	} else {
deba@2079
  2561
	  node_map.set(edge, val);
deba@2079
  2562
	}
deba@2079
  2563
      }
deba@2079
  2564
deba@2079
  2565
      /// \brief The const subscript operator.
deba@2079
  2566
      ///
deba@2079
  2567
      /// The const subscript operator.
deba@2079
  2568
      Value operator[](const Key& edge) const {
deba@2079
  2569
	if (Parent::origEdge(edge)) {
deba@2079
  2570
	  return edge_map[edge];
deba@2079
  2571
	} else {
deba@2079
  2572
	  return node_map[edge];
deba@2079
  2573
	}
deba@2079
  2574
      }      
deba@2079
  2575
deba@2079
  2576
      /// \brief The const subscript operator.
deba@2079
  2577
      ///
deba@2079
  2578
      /// The const subscript operator.
deba@2079
  2579
      Value& operator[](const Key& edge) {
deba@2079
  2580
	if (Parent::origEdge(edge)) {
deba@2079
  2581
	  return edge_map[edge];
deba@2079
  2582
	} else {
deba@2079
  2583
	  return node_map[edge];
deba@2079
  2584
	}
deba@2079
  2585
      }      
deba@2079
  2586
      
deba@2079
  2587
    private:
deba@2079
  2588
      GraphEdgeMap& edge_map;
deba@2079
  2589
      GraphNodeMap& node_map;
deba@2079
  2590
    };
deba@2079
  2591
                    
deba@2079
  2592
    /// \brief Just gives back a combined edge map.
deba@2079
  2593
    /// 
deba@2079
  2594
    /// Just gives back a combined edge map.
deba@2079
  2595
    template <typename GraphEdgeMap, typename GraphNodeMap>
deba@2079
  2596
    static CombinedEdgeMap<GraphEdgeMap, GraphNodeMap> 
deba@2079
  2597
    combinedEdgeMap(GraphEdgeMap& edge_map, GraphNodeMap& node_map) {
deba@2079
  2598
      return CombinedEdgeMap<GraphEdgeMap, GraphNodeMap>(edge_map, node_map);
deba@2079
  2599
    }
deba@2079
  2600
deba@2079
  2601
    template <typename GraphEdgeMap, typename GraphNodeMap>
deba@2079
  2602
    static CombinedEdgeMap<const GraphEdgeMap, GraphNodeMap> 
deba@2079
  2603
    combinedEdgeMap(const GraphEdgeMap& edge_map, GraphNodeMap& node_map) {
deba@2079
  2604
      return CombinedEdgeMap<const GraphEdgeMap, 
deba@2079
  2605
        GraphNodeMap>(edge_map, node_map);
deba@2079
  2606
    }
deba@2079
  2607
deba@2079
  2608
    template <typename GraphEdgeMap, typename GraphNodeMap>
deba@2079
  2609
    static CombinedEdgeMap<GraphEdgeMap, const GraphNodeMap> 
deba@2079
  2610
    combinedEdgeMap(GraphEdgeMap& edge_map, const GraphNodeMap& node_map) {
deba@2079
  2611
      return CombinedEdgeMap<GraphEdgeMap, 
deba@2079
  2612
        const GraphNodeMap>(edge_map, node_map);
deba@2079
  2613
    }
deba@2079
  2614
deba@2079
  2615
    template <typename GraphEdgeMap, typename GraphNodeMap>
deba@2079
  2616
    static CombinedEdgeMap<const GraphEdgeMap, const GraphNodeMap> 
deba@2079
  2617
    combinedEdgeMap(const GraphEdgeMap& edge_map, 
deba@2079
  2618
                    const GraphNodeMap& node_map) {
deba@2079
  2619
      return CombinedEdgeMap<const GraphEdgeMap, 
deba@2079
  2620
        const GraphNodeMap>(edge_map, node_map);
deba@2079
  2621
    }
deba@2079
  2622
deba@2079
  2623
  };
deba@2079
  2624
deba@2084
  2625
  /// \brief Just gives back a split graph adaptor
deba@2084
  2626
  ///
deba@2084
  2627
  /// Just gives back a split graph adaptor
deba@2084
  2628
  template<typename Graph>
deba@2084
  2629
  SplitGraphAdaptor<Graph>
deba@2084
  2630
  splitGraphAdaptor(const Graph& graph) {
deba@2084
  2631
    return SplitGraphAdaptor<Graph>(graph);
deba@2084
  2632
  }
deba@2084
  2633
deba@1697
  2634
alpar@921
  2635
} //namespace lemon
marci@556
  2636
alpar@1401
  2637
#endif //LEMON_GRAPH_ADAPTOR_H
marci@556
  2638