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