lemon/adaptors.h
author Akos Ladanyi <ladanyi@tmit.bme.hu>
Mon, 27 Apr 2009 18:05:04 +0100
changeset 684 4faa0c763906
parent 626 d11bf7998905
child 703 cb38ccedd2c1
permissions -rw-r--r--
Add GLPK_ROOT_DIR variable to FindGLPK (#277)
deba@432
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@430
     2
 *
deba@432
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@430
     4
 *
alpar@477
     5
 * Copyright (C) 2003-2009
deba@430
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@430
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@430
     8
 *
deba@430
     9
 * Permission to use, modify and distribute this software is granted
deba@430
    10
 * provided that this copyright notice appears in all copies. For
deba@430
    11
 * precise terms see the accompanying LICENSE file.
deba@430
    12
 *
deba@430
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@430
    14
 * express or implied, and with no claim as to its suitability for any
deba@430
    15
 * purpose.
deba@430
    16
 *
deba@430
    17
 */
deba@430
    18
deba@432
    19
#ifndef LEMON_ADAPTORS_H
deba@432
    20
#define LEMON_ADAPTORS_H
deba@432
    21
deba@432
    22
/// \ingroup graph_adaptors
deba@432
    23
/// \file
kpeter@474
    24
/// \brief Adaptor classes for digraphs and graphs
deba@430
    25
///
deba@432
    26
/// This file contains several useful adaptors for digraphs and graphs.
deba@430
    27
deba@430
    28
#include <lemon/core.h>
deba@430
    29
#include <lemon/maps.h>
deba@430
    30
#include <lemon/bits/variant.h>
deba@430
    31
deba@430
    32
#include <lemon/bits/graph_adaptor_extender.h>
deba@566
    33
#include <lemon/bits/map_extender.h>
deba@430
    34
#include <lemon/tolerance.h>
deba@430
    35
deba@430
    36
#include <algorithm>
deba@430
    37
deba@430
    38
namespace lemon {
deba@430
    39
deba@559
    40
#ifdef _MSC_VER
deba@559
    41
#define LEMON_SCOPE_FIX(OUTER, NESTED) OUTER::NESTED
deba@559
    42
#else
deba@559
    43
#define LEMON_SCOPE_FIX(OUTER, NESTED) typename OUTER::template NESTED
deba@559
    44
#endif
deba@559
    45
deba@559
    46
  template<typename DGR>
deba@430
    47
  class DigraphAdaptorBase {
deba@430
    48
  public:
deba@559
    49
    typedef DGR Digraph;
deba@430
    50
    typedef DigraphAdaptorBase Adaptor;
deba@430
    51
deba@430
    52
  protected:
deba@559
    53
    DGR* _digraph;
deba@430
    54
    DigraphAdaptorBase() : _digraph(0) { }
deba@559
    55
    void initialize(DGR& digraph) { _digraph = &digraph; }
deba@430
    56
deba@430
    57
  public:
deba@559
    58
    DigraphAdaptorBase(DGR& digraph) : _digraph(&digraph) { }
deba@559
    59
deba@559
    60
    typedef typename DGR::Node Node;
deba@559
    61
    typedef typename DGR::Arc Arc;
deba@432
    62
deba@430
    63
    void first(Node& i) const { _digraph->first(i); }
deba@430
    64
    void first(Arc& i) const { _digraph->first(i); }
deba@430
    65
    void firstIn(Arc& i, const Node& n) const { _digraph->firstIn(i, n); }
deba@430
    66
    void firstOut(Arc& i, const Node& n ) const { _digraph->firstOut(i, n); }
deba@430
    67
deba@430
    68
    void next(Node& i) const { _digraph->next(i); }
deba@430
    69
    void next(Arc& i) const { _digraph->next(i); }
deba@430
    70
    void nextIn(Arc& i) const { _digraph->nextIn(i); }
deba@430
    71
    void nextOut(Arc& i) const { _digraph->nextOut(i); }
deba@430
    72
deba@430
    73
    Node source(const Arc& a) const { return _digraph->source(a); }
deba@430
    74
    Node target(const Arc& a) const { return _digraph->target(a); }
deba@430
    75
deba@559
    76
    typedef NodeNumTagIndicator<DGR> NodeNumTag;
deba@430
    77
    int nodeNum() const { return _digraph->nodeNum(); }
deba@432
    78
deba@559
    79
    typedef ArcNumTagIndicator<DGR> ArcNumTag;
deba@430
    80
    int arcNum() const { return _digraph->arcNum(); }
deba@430
    81
deba@559
    82
    typedef FindArcTagIndicator<DGR> FindArcTag;
kpeter@471
    83
    Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) const {
deba@430
    84
      return _digraph->findArc(u, v, prev);
deba@430
    85
    }
deba@432
    86
deba@430
    87
    Node addNode() { return _digraph->addNode(); }
deba@430
    88
    Arc addArc(const Node& u, const Node& v) { return _digraph->addArc(u, v); }
deba@430
    89
kpeter@471
    90
    void erase(const Node& n) { _digraph->erase(n); }
kpeter@471
    91
    void erase(const Arc& a) { _digraph->erase(a); }
kpeter@471
    92
kpeter@471
    93
    void clear() { _digraph->clear(); }
deba@432
    94
deba@430
    95
    int id(const Node& n) const { return _digraph->id(n); }
deba@430
    96
    int id(const Arc& a) const { return _digraph->id(a); }
deba@430
    97
deba@430
    98
    Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
deba@430
    99
    Arc arcFromId(int ix) const { return _digraph->arcFromId(ix); }
deba@430
   100
deba@430
   101
    int maxNodeId() const { return _digraph->maxNodeId(); }
deba@430
   102
    int maxArcId() const { return _digraph->maxArcId(); }
deba@430
   103
deba@559
   104
    typedef typename ItemSetTraits<DGR, Node>::ItemNotifier NodeNotifier;
deba@432
   105
    NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
deba@430
   106
deba@559
   107
    typedef typename ItemSetTraits<DGR, Arc>::ItemNotifier ArcNotifier;
deba@432
   108
    ArcNotifier& notifier(Arc) const { return _digraph->notifier(Arc()); }
deba@432
   109
deba@559
   110
    template <typename V>
deba@559
   111
    class NodeMap : public DGR::template NodeMap<V> {
kpeter@664
   112
      typedef typename DGR::template NodeMap<V> Parent;
kpeter@664
   113
deba@430
   114
    public:
deba@432
   115
      explicit NodeMap(const Adaptor& adaptor)
deba@432
   116
        : Parent(*adaptor._digraph) {}
deba@559
   117
      NodeMap(const Adaptor& adaptor, const V& value)
deba@432
   118
        : Parent(*adaptor._digraph, value) { }
deba@430
   119
deba@430
   120
    private:
deba@430
   121
      NodeMap& operator=(const NodeMap& cmap) {
deba@430
   122
        return operator=<NodeMap>(cmap);
deba@430
   123
      }
deba@430
   124
deba@430
   125
      template <typename CMap>
deba@430
   126
      NodeMap& operator=(const CMap& cmap) {
deba@430
   127
        Parent::operator=(cmap);
deba@430
   128
        return *this;
deba@430
   129
      }
deba@432
   130
deba@430
   131
    };
deba@430
   132
deba@559
   133
    template <typename V>
deba@559
   134
    class ArcMap : public DGR::template ArcMap<V> {
kpeter@664
   135
      typedef typename DGR::template ArcMap<V> Parent;
kpeter@664
   136
deba@430
   137
    public:
deba@559
   138
      explicit ArcMap(const DigraphAdaptorBase<DGR>& adaptor)
deba@432
   139
        : Parent(*adaptor._digraph) {}
deba@559
   140
      ArcMap(const DigraphAdaptorBase<DGR>& adaptor, const V& value)
deba@432
   141
        : Parent(*adaptor._digraph, value) {}
deba@430
   142
deba@430
   143
    private:
deba@430
   144
      ArcMap& operator=(const ArcMap& cmap) {
deba@430
   145
        return operator=<ArcMap>(cmap);
deba@430
   146
      }
deba@430
   147
deba@430
   148
      template <typename CMap>
deba@430
   149
      ArcMap& operator=(const CMap& cmap) {
deba@430
   150
        Parent::operator=(cmap);
deba@430
   151
        return *this;
deba@430
   152
      }
deba@430
   153
deba@430
   154
    };
deba@430
   155
deba@430
   156
  };
deba@430
   157
deba@559
   158
  template<typename GR>
deba@432
   159
  class GraphAdaptorBase {
deba@432
   160
  public:
deba@559
   161
    typedef GR Graph;
deba@432
   162
deba@432
   163
  protected:
deba@559
   164
    GR* _graph;
deba@432
   165
deba@432
   166
    GraphAdaptorBase() : _graph(0) {}
deba@432
   167
deba@559
   168
    void initialize(GR& graph) { _graph = &graph; }
deba@432
   169
deba@432
   170
  public:
deba@559
   171
    GraphAdaptorBase(GR& graph) : _graph(&graph) {}
deba@559
   172
deba@559
   173
    typedef typename GR::Node Node;
deba@559
   174
    typedef typename GR::Arc Arc;
deba@559
   175
    typedef typename GR::Edge Edge;
deba@432
   176
deba@432
   177
    void first(Node& i) const { _graph->first(i); }
deba@432
   178
    void first(Arc& i) const { _graph->first(i); }
deba@432
   179
    void first(Edge& i) const { _graph->first(i); }
deba@432
   180
    void firstIn(Arc& i, const Node& n) const { _graph->firstIn(i, n); }
deba@432
   181
    void firstOut(Arc& i, const Node& n ) const { _graph->firstOut(i, n); }
deba@432
   182
    void firstInc(Edge &i, bool &d, const Node &n) const {
deba@432
   183
      _graph->firstInc(i, d, n);
deba@432
   184
    }
deba@432
   185
deba@432
   186
    void next(Node& i) const { _graph->next(i); }
deba@432
   187
    void next(Arc& i) const { _graph->next(i); }
deba@432
   188
    void next(Edge& i) const { _graph->next(i); }
deba@432
   189
    void nextIn(Arc& i) const { _graph->nextIn(i); }
deba@432
   190
    void nextOut(Arc& i) const { _graph->nextOut(i); }
deba@432
   191
    void nextInc(Edge &i, bool &d) const { _graph->nextInc(i, d); }
deba@432
   192
deba@432
   193
    Node u(const Edge& e) const { return _graph->u(e); }
deba@432
   194
    Node v(const Edge& e) const { return _graph->v(e); }
deba@432
   195
deba@432
   196
    Node source(const Arc& a) const { return _graph->source(a); }
deba@432
   197
    Node target(const Arc& a) const { return _graph->target(a); }
deba@432
   198
deba@432
   199
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
deba@432
   200
    int nodeNum() const { return _graph->nodeNum(); }
deba@432
   201
kpeter@469
   202
    typedef ArcNumTagIndicator<Graph> ArcNumTag;
kpeter@469
   203
    int arcNum() const { return _graph->arcNum(); }
kpeter@469
   204
deba@432
   205
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
deba@432
   206
    int edgeNum() const { return _graph->edgeNum(); }
deba@432
   207
kpeter@469
   208
    typedef FindArcTagIndicator<Graph> FindArcTag;
kpeter@471
   209
    Arc findArc(const Node& u, const Node& v,
kpeter@471
   210
                const Arc& prev = INVALID) const {
deba@432
   211
      return _graph->findArc(u, v, prev);
deba@432
   212
    }
kpeter@469
   213
kpeter@469
   214
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
kpeter@471
   215
    Edge findEdge(const Node& u, const Node& v,
kpeter@471
   216
                  const Edge& prev = INVALID) const {
deba@432
   217
      return _graph->findEdge(u, v, prev);
deba@432
   218
    }
deba@432
   219
deba@432
   220
    Node addNode() { return _graph->addNode(); }
deba@432
   221
    Edge addEdge(const Node& u, const Node& v) { return _graph->addEdge(u, v); }
deba@432
   222
deba@432
   223
    void erase(const Node& i) { _graph->erase(i); }
deba@432
   224
    void erase(const Edge& i) { _graph->erase(i); }
deba@432
   225
deba@432
   226
    void clear() { _graph->clear(); }
deba@432
   227
deba@432
   228
    bool direction(const Arc& a) const { return _graph->direction(a); }
deba@432
   229
    Arc direct(const Edge& e, bool d) const { return _graph->direct(e, d); }
deba@432
   230
deba@432
   231
    int id(const Node& v) const { return _graph->id(v); }
deba@432
   232
    int id(const Arc& a) const { return _graph->id(a); }
deba@432
   233
    int id(const Edge& e) const { return _graph->id(e); }
deba@432
   234
deba@432
   235
    Node nodeFromId(int ix) const { return _graph->nodeFromId(ix); }
deba@432
   236
    Arc arcFromId(int ix) const { return _graph->arcFromId(ix); }
deba@432
   237
    Edge edgeFromId(int ix) const { return _graph->edgeFromId(ix); }
deba@432
   238
deba@432
   239
    int maxNodeId() const { return _graph->maxNodeId(); }
deba@432
   240
    int maxArcId() const { return _graph->maxArcId(); }
deba@432
   241
    int maxEdgeId() const { return _graph->maxEdgeId(); }
deba@432
   242
deba@559
   243
    typedef typename ItemSetTraits<GR, Node>::ItemNotifier NodeNotifier;
deba@432
   244
    NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
deba@432
   245
deba@559
   246
    typedef typename ItemSetTraits<GR, Arc>::ItemNotifier ArcNotifier;
deba@432
   247
    ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
deba@432
   248
deba@559
   249
    typedef typename ItemSetTraits<GR, Edge>::ItemNotifier EdgeNotifier;
deba@432
   250
    EdgeNotifier& notifier(Edge) const { return _graph->notifier(Edge()); }
deba@432
   251
deba@559
   252
    template <typename V>
deba@559
   253
    class NodeMap : public GR::template NodeMap<V> {
kpeter@664
   254
      typedef typename GR::template NodeMap<V> Parent;
kpeter@664
   255
deba@432
   256
    public:
deba@559
   257
      explicit NodeMap(const GraphAdaptorBase<GR>& adapter)
deba@432
   258
        : Parent(*adapter._graph) {}
deba@559
   259
      NodeMap(const GraphAdaptorBase<GR>& adapter, const V& value)
deba@432
   260
        : Parent(*adapter._graph, value) {}
deba@432
   261
deba@432
   262
    private:
deba@432
   263
      NodeMap& operator=(const NodeMap& cmap) {
deba@432
   264
        return operator=<NodeMap>(cmap);
deba@432
   265
      }
deba@432
   266
deba@432
   267
      template <typename CMap>
deba@432
   268
      NodeMap& operator=(const CMap& cmap) {
deba@432
   269
        Parent::operator=(cmap);
deba@432
   270
        return *this;
deba@432
   271
      }
deba@432
   272
deba@432
   273
    };
deba@432
   274
deba@559
   275
    template <typename V>
deba@559
   276
    class ArcMap : public GR::template ArcMap<V> {
kpeter@664
   277
      typedef typename GR::template ArcMap<V> Parent;
kpeter@664
   278
deba@432
   279
    public:
deba@559
   280
      explicit ArcMap(const GraphAdaptorBase<GR>& adapter)
deba@432
   281
        : Parent(*adapter._graph) {}
deba@559
   282
      ArcMap(const GraphAdaptorBase<GR>& adapter, const V& value)
deba@432
   283
        : Parent(*adapter._graph, value) {}
deba@432
   284
deba@432
   285
    private:
deba@432
   286
      ArcMap& operator=(const ArcMap& cmap) {
deba@432
   287
        return operator=<ArcMap>(cmap);
deba@432
   288
      }
deba@432
   289
deba@432
   290
      template <typename CMap>
deba@432
   291
      ArcMap& operator=(const CMap& cmap) {
deba@432
   292
        Parent::operator=(cmap);
deba@432
   293
        return *this;
deba@432
   294
      }
deba@432
   295
    };
deba@432
   296
deba@559
   297
    template <typename V>
deba@559
   298
    class EdgeMap : public GR::template EdgeMap<V> {
kpeter@664
   299
      typedef typename GR::template EdgeMap<V> Parent;
kpeter@664
   300
deba@432
   301
    public:
deba@559
   302
      explicit EdgeMap(const GraphAdaptorBase<GR>& adapter)
deba@432
   303
        : Parent(*adapter._graph) {}
deba@559
   304
      EdgeMap(const GraphAdaptorBase<GR>& adapter, const V& value)
deba@432
   305
        : Parent(*adapter._graph, value) {}
deba@432
   306
deba@432
   307
    private:
deba@432
   308
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@432
   309
        return operator=<EdgeMap>(cmap);
deba@432
   310
      }
deba@432
   311
deba@432
   312
      template <typename CMap>
deba@432
   313
      EdgeMap& operator=(const CMap& cmap) {
deba@432
   314
        Parent::operator=(cmap);
deba@432
   315
        return *this;
deba@432
   316
      }
deba@432
   317
    };
deba@432
   318
deba@432
   319
  };
deba@430
   320
deba@559
   321
  template <typename DGR>
deba@559
   322
  class ReverseDigraphBase : public DigraphAdaptorBase<DGR> {
kpeter@664
   323
    typedef DigraphAdaptorBase<DGR> Parent;
deba@430
   324
  public:
deba@559
   325
    typedef DGR Digraph;
deba@430
   326
  protected:
deba@432
   327
    ReverseDigraphBase() : Parent() { }
deba@430
   328
  public:
deba@430
   329
    typedef typename Parent::Node Node;
deba@430
   330
    typedef typename Parent::Arc Arc;
deba@430
   331
deba@430
   332
    void firstIn(Arc& a, const Node& n) const { Parent::firstOut(a, n); }
deba@430
   333
    void firstOut(Arc& a, const Node& n ) const { Parent::firstIn(a, n); }
deba@430
   334
deba@430
   335
    void nextIn(Arc& a) const { Parent::nextOut(a); }
deba@430
   336
    void nextOut(Arc& a) const { Parent::nextIn(a); }
deba@430
   337
deba@430
   338
    Node source(const Arc& a) const { return Parent::target(a); }
deba@430
   339
    Node target(const Arc& a) const { return Parent::source(a); }
deba@430
   340
deba@432
   341
    Arc addArc(const Node& u, const Node& v) { return Parent::addArc(v, u); }
deba@432
   342
deba@559
   343
    typedef FindArcTagIndicator<DGR> FindArcTag;
deba@432
   344
    Arc findArc(const Node& u, const Node& v,
kpeter@471
   345
                const Arc& prev = INVALID) const {
deba@430
   346
      return Parent::findArc(v, u, prev);
deba@430
   347
    }
deba@430
   348
deba@430
   349
  };
deba@432
   350
deba@432
   351
  /// \ingroup graph_adaptors
deba@430
   352
  ///
kpeter@474
   353
  /// \brief Adaptor class for reversing the orientation of the arcs in
kpeter@474
   354
  /// a digraph.
deba@430
   355
  ///
kpeter@474
   356
  /// ReverseDigraph can be used for reversing the arcs in a digraph.
kpeter@474
   357
  /// It conforms to the \ref concepts::Digraph "Digraph" concept.
deba@430
   358
  ///
kpeter@474
   359
  /// The adapted digraph can also be modified through this adaptor
kpeter@476
   360
  /// by adding or removing nodes or arcs, unless the \c GR template
kpeter@474
   361
  /// parameter is set to be \c const.
kpeter@474
   362
  ///
deba@559
   363
  /// \tparam DGR The type of the adapted digraph.
kpeter@474
   364
  /// It must conform to the \ref concepts::Digraph "Digraph" concept.
kpeter@474
   365
  /// It can also be specified to be \c const.
kpeter@474
   366
  ///
kpeter@474
   367
  /// \note The \c Node and \c Arc types of this adaptor and the adapted
kpeter@474
   368
  /// digraph are convertible to each other.
deba@559
   369
  template<typename DGR>
kpeter@476
   370
#ifdef DOXYGEN
kpeter@476
   371
  class ReverseDigraph {
kpeter@476
   372
#else
deba@432
   373
  class ReverseDigraph :
deba@559
   374
    public DigraphAdaptorExtender<ReverseDigraphBase<DGR> > {
kpeter@476
   375
#endif
kpeter@664
   376
    typedef DigraphAdaptorExtender<ReverseDigraphBase<DGR> > Parent;
deba@430
   377
  public:
kpeter@476
   378
    /// The type of the adapted digraph.
deba@559
   379
    typedef DGR Digraph;
deba@430
   380
  protected:
deba@432
   381
    ReverseDigraph() { }
deba@430
   382
  public:
deba@431
   383
deba@431
   384
    /// \brief Constructor
deba@431
   385
    ///
kpeter@474
   386
    /// Creates a reverse digraph adaptor for the given digraph.
deba@559
   387
    explicit ReverseDigraph(DGR& digraph) {
deba@559
   388
      Parent::initialize(digraph);
deba@430
   389
    }
deba@430
   390
  };
deba@430
   391
kpeter@474
   392
  /// \brief Returns a read-only ReverseDigraph adaptor
deba@430
   393
  ///
kpeter@474
   394
  /// This function just returns a read-only \ref ReverseDigraph adaptor.
kpeter@474
   395
  /// \ingroup graph_adaptors
kpeter@474
   396
  /// \relates ReverseDigraph
deba@559
   397
  template<typename DGR>
deba@559
   398
  ReverseDigraph<const DGR> reverseDigraph(const DGR& digraph) {
deba@559
   399
    return ReverseDigraph<const DGR>(digraph);
deba@430
   400
  }
deba@430
   401
kpeter@474
   402
deba@559
   403
  template <typename DGR, typename NF, typename AF, bool ch = true>
deba@559
   404
  class SubDigraphBase : public DigraphAdaptorBase<DGR> {
kpeter@664
   405
    typedef DigraphAdaptorBase<DGR> Parent;
deba@430
   406
  public:
deba@559
   407
    typedef DGR Digraph;
deba@559
   408
    typedef NF NodeFilterMap;
deba@559
   409
    typedef AF ArcFilterMap;
deba@430
   410
deba@432
   411
    typedef SubDigraphBase Adaptor;
deba@430
   412
  protected:
deba@559
   413
    NF* _node_filter;
deba@559
   414
    AF* _arc_filter;
deba@432
   415
    SubDigraphBase()
deba@430
   416
      : Parent(), _node_filter(0), _arc_filter(0) { }
deba@430
   417
deba@559
   418
    void initialize(DGR& digraph, NF& node_filter, AF& arc_filter) {
deba@559
   419
      Parent::initialize(digraph);
deba@430
   420
      _node_filter = &node_filter;
deba@559
   421
      _arc_filter = &arc_filter;      
deba@430
   422
    }
deba@430
   423
deba@430
   424
  public:
deba@430
   425
deba@430
   426
    typedef typename Parent::Node Node;
deba@430
   427
    typedef typename Parent::Arc Arc;
deba@430
   428
deba@432
   429
    void first(Node& i) const {
deba@432
   430
      Parent::first(i);
deba@432
   431
      while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
deba@430
   432
    }
deba@430
   433
deba@432
   434
    void first(Arc& i) const {
deba@432
   435
      Parent::first(i);
deba@432
   436
      while (i != INVALID && (!(*_arc_filter)[i]
deba@432
   437
                              || !(*_node_filter)[Parent::source(i)]
deba@432
   438
                              || !(*_node_filter)[Parent::target(i)]))
deba@432
   439
        Parent::next(i);
deba@430
   440
    }
deba@430
   441
deba@432
   442
    void firstIn(Arc& i, const Node& n) const {
deba@432
   443
      Parent::firstIn(i, n);
deba@432
   444
      while (i != INVALID && (!(*_arc_filter)[i]
deba@432
   445
                              || !(*_node_filter)[Parent::source(i)]))
deba@432
   446
        Parent::nextIn(i);
deba@430
   447
    }
deba@430
   448
deba@432
   449
    void firstOut(Arc& i, const Node& n) const {
deba@432
   450
      Parent::firstOut(i, n);
deba@432
   451
      while (i != INVALID && (!(*_arc_filter)[i]
deba@432
   452
                              || !(*_node_filter)[Parent::target(i)]))
deba@432
   453
        Parent::nextOut(i);
deba@430
   454
    }
deba@430
   455
deba@432
   456
    void next(Node& i) const {
deba@432
   457
      Parent::next(i);
deba@432
   458
      while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
deba@430
   459
    }
deba@430
   460
deba@432
   461
    void next(Arc& i) const {
deba@432
   462
      Parent::next(i);
deba@432
   463
      while (i != INVALID && (!(*_arc_filter)[i]
deba@432
   464
                              || !(*_node_filter)[Parent::source(i)]
deba@432
   465
                              || !(*_node_filter)[Parent::target(i)]))
deba@432
   466
        Parent::next(i);
deba@430
   467
    }
deba@430
   468
deba@432
   469
    void nextIn(Arc& i) const {
deba@432
   470
      Parent::nextIn(i);
deba@432
   471
      while (i != INVALID && (!(*_arc_filter)[i]
deba@432
   472
                              || !(*_node_filter)[Parent::source(i)]))
deba@432
   473
        Parent::nextIn(i);
deba@430
   474
    }
deba@430
   475
deba@432
   476
    void nextOut(Arc& i) const {
deba@432
   477
      Parent::nextOut(i);
deba@432
   478
      while (i != INVALID && (!(*_arc_filter)[i]
deba@432
   479
                              || !(*_node_filter)[Parent::target(i)]))
deba@432
   480
        Parent::nextOut(i);
deba@430
   481
    }
deba@430
   482
kpeter@475
   483
    void status(const Node& n, bool v) const { _node_filter->set(n, v); }
kpeter@475
   484
    void status(const Arc& a, bool v) const { _arc_filter->set(a, v); }
kpeter@475
   485
kpeter@475
   486
    bool status(const Node& n) const { return (*_node_filter)[n]; }
kpeter@475
   487
    bool status(const Arc& a) const { return (*_arc_filter)[a]; }
deba@430
   488
deba@430
   489
    typedef False NodeNumTag;
kpeter@469
   490
    typedef False ArcNumTag;
kpeter@469
   491
deba@559
   492
    typedef FindArcTagIndicator<DGR> FindArcTag;
deba@432
   493
    Arc findArc(const Node& source, const Node& target,
kpeter@471
   494
                const Arc& prev = INVALID) const {
deba@430
   495
      if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
deba@430
   496
        return INVALID;
deba@430
   497
      }
deba@430
   498
      Arc arc = Parent::findArc(source, target, prev);
deba@430
   499
      while (arc != INVALID && !(*_arc_filter)[arc]) {
deba@430
   500
        arc = Parent::findArc(source, target, arc);
deba@430
   501
      }
deba@430
   502
      return arc;
deba@430
   503
    }
deba@430
   504
deba@559
   505
  public:
deba@559
   506
deba@559
   507
    template <typename V>
deba@559
   508
    class NodeMap 
deba@559
   509
      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>, 
deba@559
   510
	      LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> {
kpeter@664
   511
      typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
kpeter@664
   512
	LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent;
kpeter@664
   513
deba@430
   514
    public:
deba@559
   515
      typedef V Value;
deba@559
   516
deba@559
   517
      NodeMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor)
deba@559
   518
        : Parent(adaptor) {}
deba@559
   519
      NodeMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor, const V& value)
deba@559
   520
        : Parent(adaptor, value) {}
deba@432
   521
deba@430
   522
    private:
deba@430
   523
      NodeMap& operator=(const NodeMap& cmap) {
deba@432
   524
        return operator=<NodeMap>(cmap);
deba@430
   525
      }
deba@432
   526
deba@430
   527
      template <typename CMap>
deba@430
   528
      NodeMap& operator=(const CMap& cmap) {
deba@559
   529
        Parent::operator=(cmap);
deba@432
   530
        return *this;
deba@430
   531
      }
deba@430
   532
    };
deba@430
   533
deba@559
   534
    template <typename V>
deba@559
   535
    class ArcMap 
deba@559
   536
      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
deba@559
   537
	      LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
kpeter@664
   538
      typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
kpeter@664
   539
        LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent;
kpeter@664
   540
deba@430
   541
    public:
deba@559
   542
      typedef V Value;
deba@559
   543
deba@559
   544
      ArcMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor)
deba@559
   545
        : Parent(adaptor) {}
deba@559
   546
      ArcMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor, const V& value)
deba@559
   547
        : Parent(adaptor, value) {}
deba@432
   548
deba@430
   549
    private:
deba@430
   550
      ArcMap& operator=(const ArcMap& cmap) {
deba@432
   551
        return operator=<ArcMap>(cmap);
deba@430
   552
      }
deba@432
   553
deba@430
   554
      template <typename CMap>
deba@430
   555
      ArcMap& operator=(const CMap& cmap) {
deba@559
   556
        Parent::operator=(cmap);
deba@432
   557
        return *this;
deba@430
   558
      }
deba@430
   559
    };
deba@430
   560
deba@430
   561
  };
deba@430
   562
deba@559
   563
  template <typename DGR, typename NF, typename AF>
deba@559
   564
  class SubDigraphBase<DGR, NF, AF, false>
deba@559
   565
    : public DigraphAdaptorBase<DGR> {
kpeter@664
   566
    typedef DigraphAdaptorBase<DGR> Parent;
deba@430
   567
  public:
deba@559
   568
    typedef DGR Digraph;
deba@559
   569
    typedef NF NodeFilterMap;
deba@559
   570
    typedef AF ArcFilterMap;
deba@430
   571
deba@432
   572
    typedef SubDigraphBase Adaptor;
deba@430
   573
  protected:
deba@559
   574
    NF* _node_filter;
deba@559
   575
    AF* _arc_filter;
deba@432
   576
    SubDigraphBase()
deba@430
   577
      : Parent(), _node_filter(0), _arc_filter(0) { }
deba@430
   578
deba@559
   579
    void initialize(DGR& digraph, NF& node_filter, AF& arc_filter) {
deba@559
   580
      Parent::initialize(digraph);
deba@430
   581
      _node_filter = &node_filter;
deba@559
   582
      _arc_filter = &arc_filter;      
deba@430
   583
    }
deba@430
   584
deba@430
   585
  public:
deba@430
   586
deba@430
   587
    typedef typename Parent::Node Node;
deba@430
   588
    typedef typename Parent::Arc Arc;
deba@430
   589
deba@432
   590
    void first(Node& i) const {
deba@432
   591
      Parent::first(i);
deba@432
   592
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
deba@430
   593
    }
deba@430
   594
deba@432
   595
    void first(Arc& i) const {
deba@432
   596
      Parent::first(i);
deba@432
   597
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
deba@430
   598
    }
deba@430
   599
deba@432
   600
    void firstIn(Arc& i, const Node& n) const {
deba@432
   601
      Parent::firstIn(i, n);
deba@432
   602
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
deba@430
   603
    }
deba@430
   604
deba@432
   605
    void firstOut(Arc& i, const Node& n) const {
deba@432
   606
      Parent::firstOut(i, n);
deba@432
   607
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
deba@430
   608
    }
deba@430
   609
deba@432
   610
    void next(Node& i) const {
deba@432
   611
      Parent::next(i);
deba@432
   612
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
deba@430
   613
    }
deba@432
   614
    void next(Arc& i) const {
deba@432
   615
      Parent::next(i);
deba@432
   616
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
deba@430
   617
    }
deba@432
   618
    void nextIn(Arc& i) const {
deba@432
   619
      Parent::nextIn(i);
deba@432
   620
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
deba@430
   621
    }
deba@430
   622
deba@432
   623
    void nextOut(Arc& i) const {
deba@432
   624
      Parent::nextOut(i);
deba@432
   625
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
deba@430
   626
    }
deba@430
   627
kpeter@475
   628
    void status(const Node& n, bool v) const { _node_filter->set(n, v); }
kpeter@475
   629
    void status(const Arc& a, bool v) const { _arc_filter->set(a, v); }
kpeter@475
   630
kpeter@475
   631
    bool status(const Node& n) const { return (*_node_filter)[n]; }
kpeter@475
   632
    bool status(const Arc& a) const { return (*_arc_filter)[a]; }
deba@430
   633
deba@430
   634
    typedef False NodeNumTag;
kpeter@469
   635
    typedef False ArcNumTag;
kpeter@469
   636
deba@559
   637
    typedef FindArcTagIndicator<DGR> FindArcTag;
deba@432
   638
    Arc findArc(const Node& source, const Node& target,
kpeter@471
   639
                const Arc& prev = INVALID) const {
deba@430
   640
      if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
deba@430
   641
        return INVALID;
deba@430
   642
      }
deba@430
   643
      Arc arc = Parent::findArc(source, target, prev);
deba@430
   644
      while (arc != INVALID && !(*_arc_filter)[arc]) {
deba@430
   645
        arc = Parent::findArc(source, target, arc);
deba@430
   646
      }
deba@430
   647
      return arc;
deba@430
   648
    }
deba@430
   649
deba@559
   650
    template <typename V>
deba@559
   651
    class NodeMap 
deba@559
   652
      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
deba@559
   653
          LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> {
kpeter@664
   654
      typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>, 
kpeter@664
   655
        LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent;
kpeter@664
   656
deba@430
   657
    public:
deba@559
   658
      typedef V Value;
deba@559
   659
deba@559
   660
      NodeMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor)
deba@559
   661
        : Parent(adaptor) {}
deba@559
   662
      NodeMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor, const V& value)
deba@559
   663
        : Parent(adaptor, value) {}
deba@432
   664
deba@430
   665
    private:
deba@430
   666
      NodeMap& operator=(const NodeMap& cmap) {
deba@432
   667
        return operator=<NodeMap>(cmap);
deba@430
   668
      }
deba@432
   669
deba@430
   670
      template <typename CMap>
deba@430
   671
      NodeMap& operator=(const CMap& cmap) {
deba@559
   672
        Parent::operator=(cmap);
deba@432
   673
        return *this;
deba@430
   674
      }
deba@430
   675
    };
deba@430
   676
deba@559
   677
    template <typename V>
deba@559
   678
    class ArcMap 
deba@559
   679
      : public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
deba@559
   680
          LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
kpeter@664
   681
      typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
kpeter@664
   682
        LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent;
kpeter@664
   683
deba@430
   684
    public:
deba@559
   685
      typedef V Value;
deba@559
   686
deba@559
   687
      ArcMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor)
deba@559
   688
        : Parent(adaptor) {}
deba@559
   689
      ArcMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor, const V& value)
deba@559
   690
        : Parent(adaptor, value) {}
deba@432
   691
deba@430
   692
    private:
deba@430
   693
      ArcMap& operator=(const ArcMap& cmap) {
deba@432
   694
        return operator=<ArcMap>(cmap);
deba@430
   695
      }
deba@432
   696
deba@430
   697
      template <typename CMap>
deba@430
   698
      ArcMap& operator=(const CMap& cmap) {
deba@559
   699
        Parent::operator=(cmap);
deba@432
   700
        return *this;
deba@430
   701
      }
deba@430
   702
    };
deba@430
   703
deba@430
   704
  };
deba@430
   705
deba@430
   706
  /// \ingroup graph_adaptors
deba@430
   707
  ///
kpeter@474
   708
  /// \brief Adaptor class for hiding nodes and arcs in a digraph
deba@432
   709
  ///
kpeter@474
   710
  /// SubDigraph can be used for hiding nodes and arcs in a digraph.
kpeter@474
   711
  /// A \c bool node map and a \c bool arc map must be specified, which
kpeter@474
   712
  /// define the filters for nodes and arcs.
kpeter@474
   713
  /// Only the nodes and arcs with \c true filter value are
kpeter@476
   714
  /// shown in the subdigraph. The arcs that are incident to hidden
kpeter@476
   715
  /// nodes are also filtered out.
kpeter@476
   716
  /// This adaptor conforms to the \ref concepts::Digraph "Digraph" concept.
deba@432
   717
  ///
kpeter@474
   718
  /// The adapted digraph can also be modified through this adaptor
kpeter@476
   719
  /// by adding or removing nodes or arcs, unless the \c GR template
kpeter@474
   720
  /// parameter is set to be \c const.
kpeter@474
   721
  ///
deba@559
   722
  /// \tparam DGR The type of the adapted digraph.
kpeter@474
   723
  /// It must conform to the \ref concepts::Digraph "Digraph" concept.
kpeter@474
   724
  /// It can also be specified to be \c const.
kpeter@476
   725
  /// \tparam NF The type of the node filter map.
kpeter@476
   726
  /// It must be a \c bool (or convertible) node map of the
kpeter@476
   727
  /// adapted digraph. The default type is
deba@559
   728
  /// \ref concepts::Digraph::NodeMap "DGR::NodeMap<bool>".
kpeter@476
   729
  /// \tparam AF The type of the arc filter map.
kpeter@476
   730
  /// It must be \c bool (or convertible) arc map of the
kpeter@476
   731
  /// adapted digraph. The default type is
deba@559
   732
  /// \ref concepts::Digraph::ArcMap "DGR::ArcMap<bool>".
kpeter@474
   733
  ///
kpeter@474
   734
  /// \note The \c Node and \c Arc types of this adaptor and the adapted
kpeter@474
   735
  /// digraph are convertible to each other.
deba@432
   736
  ///
deba@432
   737
  /// \see FilterNodes
deba@432
   738
  /// \see FilterArcs
kpeter@474
   739
#ifdef DOXYGEN
deba@559
   740
  template<typename DGR, typename NF, typename AF>
kpeter@476
   741
  class SubDigraph {
kpeter@474
   742
#else
deba@559
   743
  template<typename DGR,
deba@559
   744
           typename NF = typename DGR::template NodeMap<bool>,
deba@559
   745
           typename AF = typename DGR::template ArcMap<bool> >
kpeter@476
   746
  class SubDigraph :
deba@559
   747
    public DigraphAdaptorExtender<SubDigraphBase<DGR, NF, AF, true> > {
kpeter@474
   748
#endif
deba@430
   749
  public:
kpeter@474
   750
    /// The type of the adapted digraph.
deba@559
   751
    typedef DGR Digraph;
kpeter@474
   752
    /// The type of the node filter map.
kpeter@476
   753
    typedef NF NodeFilterMap;
kpeter@474
   754
    /// The type of the arc filter map.
kpeter@476
   755
    typedef AF ArcFilterMap;
kpeter@476
   756
deba@559
   757
    typedef DigraphAdaptorExtender<SubDigraphBase<DGR, NF, AF, true> >
kpeter@476
   758
      Parent;
deba@430
   759
deba@431
   760
    typedef typename Parent::Node Node;
deba@431
   761
    typedef typename Parent::Arc Arc;
deba@431
   762
deba@430
   763
  protected:
deba@432
   764
    SubDigraph() { }
deba@430
   765
  public:
deba@430
   766
deba@431
   767
    /// \brief Constructor
deba@431
   768
    ///
kpeter@474
   769
    /// Creates a subdigraph for the given digraph with the
kpeter@474
   770
    /// given node and arc filter maps.
deba@559
   771
    SubDigraph(DGR& digraph, NF& node_filter, AF& arc_filter) {
deba@559
   772
      Parent::initialize(digraph, node_filter, arc_filter);
deba@430
   773
    }
deba@430
   774
kpeter@475
   775
    /// \brief Sets the status of the given node
deba@431
   776
    ///
kpeter@475
   777
    /// This function sets the status of the given node.
kpeter@474
   778
    /// It is done by simply setting the assigned value of \c n
kpeter@475
   779
    /// to \c v in the node filter map.
kpeter@475
   780
    void status(const Node& n, bool v) const { Parent::status(n, v); }
kpeter@475
   781
kpeter@475
   782
    /// \brief Sets the status of the given arc
deba@431
   783
    ///
kpeter@475
   784
    /// This function sets the status of the given arc.
kpeter@474
   785
    /// It is done by simply setting the assigned value of \c a
kpeter@475
   786
    /// to \c v in the arc filter map.
kpeter@475
   787
    void status(const Arc& a, bool v) const { Parent::status(a, v); }
kpeter@475
   788
kpeter@475
   789
    /// \brief Returns the status of the given node
deba@431
   790
    ///
kpeter@475
   791
    /// This function returns the status of the given node.
kpeter@475
   792
    /// It is \c true if the given node is enabled (i.e. not hidden).
kpeter@475
   793
    bool status(const Node& n) const { return Parent::status(n); }
kpeter@475
   794
kpeter@475
   795
    /// \brief Returns the status of the given arc
deba@431
   796
    ///
kpeter@475
   797
    /// This function returns the status of the given arc.
kpeter@475
   798
    /// It is \c true if the given arc is enabled (i.e. not hidden).
kpeter@475
   799
    bool status(const Arc& a) const { return Parent::status(a); }
kpeter@475
   800
kpeter@475
   801
    /// \brief Disables the given node
deba@431
   802
    ///
kpeter@475
   803
    /// This function disables the given node in the subdigraph,
kpeter@475
   804
    /// so the iteration jumps over it.
kpeter@475
   805
    /// It is the same as \ref status() "status(n, false)".
kpeter@475
   806
    void disable(const Node& n) const { Parent::status(n, false); }
kpeter@475
   807
kpeter@475
   808
    /// \brief Disables the given arc
deba@431
   809
    ///
kpeter@475
   810
    /// This function disables the given arc in the subdigraph,
kpeter@475
   811
    /// so the iteration jumps over it.
kpeter@475
   812
    /// It is the same as \ref status() "status(a, false)".
kpeter@475
   813
    void disable(const Arc& a) const { Parent::status(a, false); }
kpeter@475
   814
kpeter@475
   815
    /// \brief Enables the given node
kpeter@475
   816
    ///
kpeter@475
   817
    /// This function enables the given node in the subdigraph.
kpeter@475
   818
    /// It is the same as \ref status() "status(n, true)".
kpeter@475
   819
    void enable(const Node& n) const { Parent::status(n, true); }
kpeter@475
   820
kpeter@475
   821
    /// \brief Enables the given arc
kpeter@475
   822
    ///
kpeter@475
   823
    /// This function enables the given arc in the subdigraph.
kpeter@475
   824
    /// It is the same as \ref status() "status(a, true)".
kpeter@475
   825
    void enable(const Arc& a) const { Parent::status(a, true); }
deba@431
   826
deba@430
   827
  };
deba@430
   828
kpeter@474
   829
  /// \brief Returns a read-only SubDigraph adaptor
deba@430
   830
  ///
kpeter@474
   831
  /// This function just returns a read-only \ref SubDigraph adaptor.
kpeter@474
   832
  /// \ingroup graph_adaptors
kpeter@474
   833
  /// \relates SubDigraph
deba@559
   834
  template<typename DGR, typename NF, typename AF>
deba@559
   835
  SubDigraph<const DGR, NF, AF>
deba@559
   836
  subDigraph(const DGR& digraph,
deba@559
   837
             NF& node_filter, AF& arc_filter) {
deba@559
   838
    return SubDigraph<const DGR, NF, AF>
deba@559
   839
      (digraph, node_filter, arc_filter);
deba@430
   840
  }
deba@430
   841
deba@559
   842
  template<typename DGR, typename NF, typename AF>
deba@559
   843
  SubDigraph<const DGR, const NF, AF>
deba@559
   844
  subDigraph(const DGR& digraph,
deba@559
   845
             const NF& node_filter, AF& arc_filter) {
deba@559
   846
    return SubDigraph<const DGR, const NF, AF>
deba@559
   847
      (digraph, node_filter, arc_filter);
deba@430
   848
  }
deba@430
   849
deba@559
   850
  template<typename DGR, typename NF, typename AF>
deba@559
   851
  SubDigraph<const DGR, NF, const AF>
deba@559
   852
  subDigraph(const DGR& digraph,
deba@559
   853
             NF& node_filter, const AF& arc_filter) {
deba@559
   854
    return SubDigraph<const DGR, NF, const AF>
deba@559
   855
      (digraph, node_filter, arc_filter);
deba@430
   856
  }
deba@430
   857
deba@559
   858
  template<typename DGR, typename NF, typename AF>
deba@559
   859
  SubDigraph<const DGR, const NF, const AF>
deba@559
   860
  subDigraph(const DGR& digraph,
deba@559
   861
             const NF& node_filter, const AF& arc_filter) {
deba@559
   862
    return SubDigraph<const DGR, const NF, const AF>
deba@559
   863
      (digraph, node_filter, arc_filter);
deba@430
   864
  }
deba@430
   865
deba@430
   866
deba@559
   867
  template <typename GR, typename NF, typename EF, bool ch = true>
deba@559
   868
  class SubGraphBase : public GraphAdaptorBase<GR> {
kpeter@664
   869
    typedef GraphAdaptorBase<GR> Parent;
deba@432
   870
  public:
deba@559
   871
    typedef GR Graph;
deba@559
   872
    typedef NF NodeFilterMap;
deba@559
   873
    typedef EF EdgeFilterMap;
kpeter@472
   874
deba@432
   875
    typedef SubGraphBase Adaptor;
deba@432
   876
  protected:
deba@432
   877
deba@559
   878
    NF* _node_filter;
deba@559
   879
    EF* _edge_filter;
deba@432
   880
deba@432
   881
    SubGraphBase()
deba@559
   882
      : Parent(), _node_filter(0), _edge_filter(0) { }
deba@559
   883
deba@559
   884
    void initialize(GR& graph, NF& node_filter, EF& edge_filter) {
deba@559
   885
      Parent::initialize(graph);
deba@559
   886
      _node_filter = &node_filter;
deba@559
   887
      _edge_filter = &edge_filter;
deba@432
   888
    }
deba@432
   889
deba@432
   890
  public:
deba@432
   891
deba@432
   892
    typedef typename Parent::Node Node;
deba@432
   893
    typedef typename Parent::Arc Arc;
deba@432
   894
    typedef typename Parent::Edge Edge;
deba@432
   895
deba@432
   896
    void first(Node& i) const {
deba@432
   897
      Parent::first(i);
deba@559
   898
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
deba@432
   899
    }
deba@432
   900
deba@432
   901
    void first(Arc& i) const {
deba@432
   902
      Parent::first(i);
deba@559
   903
      while (i!=INVALID && (!(*_edge_filter)[i]
deba@559
   904
                            || !(*_node_filter)[Parent::source(i)]
deba@559
   905
                            || !(*_node_filter)[Parent::target(i)]))
deba@432
   906
        Parent::next(i);
deba@432
   907
    }
deba@432
   908
deba@432
   909
    void first(Edge& i) const {
deba@432
   910
      Parent::first(i);
deba@559
   911
      while (i!=INVALID && (!(*_edge_filter)[i]
deba@559
   912
                            || !(*_node_filter)[Parent::u(i)]
deba@559
   913
                            || !(*_node_filter)[Parent::v(i)]))
deba@432
   914
        Parent::next(i);
deba@432
   915
    }
deba@432
   916
deba@432
   917
    void firstIn(Arc& i, const Node& n) const {
deba@432
   918
      Parent::firstIn(i, n);
deba@559
   919
      while (i!=INVALID && (!(*_edge_filter)[i]
deba@559
   920
                            || !(*_node_filter)[Parent::source(i)]))
deba@432
   921
        Parent::nextIn(i);
deba@432
   922
    }
deba@432
   923
deba@432
   924
    void firstOut(Arc& i, const Node& n) const {
deba@432
   925
      Parent::firstOut(i, n);
deba@559
   926
      while (i!=INVALID && (!(*_edge_filter)[i]
deba@559
   927
                            || !(*_node_filter)[Parent::target(i)]))
deba@432
   928
        Parent::nextOut(i);
deba@432
   929
    }
deba@432
   930
deba@432
   931
    void firstInc(Edge& i, bool& d, const Node& n) const {
deba@432
   932
      Parent::firstInc(i, d, n);
deba@559
   933
      while (i!=INVALID && (!(*_edge_filter)[i]
deba@559
   934
                            || !(*_node_filter)[Parent::u(i)]
deba@559
   935
                            || !(*_node_filter)[Parent::v(i)]))
deba@432
   936
        Parent::nextInc(i, d);
deba@432
   937
    }
deba@432
   938
deba@432
   939
    void next(Node& i) const {
deba@432
   940
      Parent::next(i);
deba@559
   941
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
deba@432
   942
    }
deba@432
   943
deba@432
   944
    void next(Arc& i) const {
deba@432
   945
      Parent::next(i);
deba@559
   946
      while (i!=INVALID && (!(*_edge_filter)[i]
deba@559
   947
                            || !(*_node_filter)[Parent::source(i)]
deba@559
   948
                            || !(*_node_filter)[Parent::target(i)]))
deba@432
   949
        Parent::next(i);
deba@432
   950
    }
deba@432
   951
deba@432
   952
    void next(Edge& i) const {
deba@432
   953
      Parent::next(i);
deba@559
   954
      while (i!=INVALID && (!(*_edge_filter)[i]
deba@559
   955
                            || !(*_node_filter)[Parent::u(i)]
deba@559
   956
                            || !(*_node_filter)[Parent::v(i)]))
deba@432
   957
        Parent::next(i);
deba@432
   958
    }
deba@432
   959
deba@432
   960
    void nextIn(Arc& i) const {
deba@432
   961
      Parent::nextIn(i);
deba@559
   962
      while (i!=INVALID && (!(*_edge_filter)[i]
deba@559
   963
                            || !(*_node_filter)[Parent::source(i)]))
deba@432
   964
        Parent::nextIn(i);
deba@432
   965
    }
deba@432
   966
deba@432
   967
    void nextOut(Arc& i) const {
deba@432
   968
      Parent::nextOut(i);
deba@559
   969
      while (i!=INVALID && (!(*_edge_filter)[i]
deba@559
   970
                            || !(*_node_filter)[Parent::target(i)]))
deba@432
   971
        Parent::nextOut(i);
deba@432
   972
    }
deba@432
   973
deba@432
   974
    void nextInc(Edge& i, bool& d) const {
deba@432
   975
      Parent::nextInc(i, d);
deba@559
   976
      while (i!=INVALID && (!(*_edge_filter)[i]
deba@559
   977
                            || !(*_node_filter)[Parent::u(i)]
deba@559
   978
                            || !(*_node_filter)[Parent::v(i)]))
deba@432
   979
        Parent::nextInc(i, d);
deba@432
   980
    }
deba@432
   981
deba@559
   982
    void status(const Node& n, bool v) const { _node_filter->set(n, v); }
deba@559
   983
    void status(const Edge& e, bool v) const { _edge_filter->set(e, v); }
deba@559
   984
deba@559
   985
    bool status(const Node& n) const { return (*_node_filter)[n]; }
deba@559
   986
    bool status(const Edge& e) const { return (*_edge_filter)[e]; }
deba@432
   987
deba@432
   988
    typedef False NodeNumTag;
kpeter@469
   989
    typedef False ArcNumTag;
deba@432
   990
    typedef False EdgeNumTag;
deba@432
   991
kpeter@469
   992
    typedef FindArcTagIndicator<Graph> FindArcTag;
deba@432
   993
    Arc findArc(const Node& u, const Node& v,
kpeter@471
   994
                const Arc& prev = INVALID) const {
deba@559
   995
      if (!(*_node_filter)[u] || !(*_node_filter)[v]) {
deba@432
   996
        return INVALID;
deba@432
   997
      }
deba@432
   998
      Arc arc = Parent::findArc(u, v, prev);
deba@559
   999
      while (arc != INVALID && !(*_edge_filter)[arc]) {
deba@432
  1000
        arc = Parent::findArc(u, v, arc);
deba@432
  1001
      }
deba@432
  1002
      return arc;
deba@432
  1003
    }
kpeter@469
  1004
kpeter@469
  1005
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@432
  1006
    Edge findEdge(const Node& u, const Node& v,
kpeter@471
  1007
                  const Edge& prev = INVALID) const {
deba@559
  1008
      if (!(*_node_filter)[u] || !(*_node_filter)[v]) {
deba@432
  1009
        return INVALID;
deba@432
  1010
      }
deba@432
  1011
      Edge edge = Parent::findEdge(u, v, prev);
deba@559
  1012
      while (edge != INVALID && !(*_edge_filter)[edge]) {
deba@432
  1013
        edge = Parent::findEdge(u, v, edge);
deba@432
  1014
      }
deba@432
  1015
      return edge;
deba@432
  1016
    }
deba@432
  1017
deba@559
  1018
    template <typename V>
deba@559
  1019
    class NodeMap 
deba@559
  1020
      : public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
deba@559
  1021
          LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> {
kpeter@664
  1022
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 
kpeter@664
  1023
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent;
kpeter@664
  1024
deba@432
  1025
    public:
deba@559
  1026
      typedef V Value;
deba@559
  1027
deba@559
  1028
      NodeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor)
deba@559
  1029
        : Parent(adaptor) {}
deba@559
  1030
      NodeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor, const V& value)
deba@559
  1031
        : Parent(adaptor, value) {}
deba@432
  1032
deba@432
  1033
    private:
deba@432
  1034
      NodeMap& operator=(const NodeMap& cmap) {
deba@432
  1035
        return operator=<NodeMap>(cmap);
deba@432
  1036
      }
deba@432
  1037
deba@432
  1038
      template <typename CMap>
deba@432
  1039
      NodeMap& operator=(const CMap& cmap) {
deba@559
  1040
        Parent::operator=(cmap);
deba@432
  1041
        return *this;
deba@432
  1042
      }
deba@432
  1043
    };
deba@432
  1044
deba@559
  1045
    template <typename V>
deba@559
  1046
    class ArcMap 
deba@559
  1047
      : public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
deba@559
  1048
          LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> {
kpeter@664
  1049
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 
kpeter@664
  1050
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent;
kpeter@664
  1051
deba@432
  1052
    public:
deba@559
  1053
      typedef V Value;
deba@559
  1054
deba@559
  1055
      ArcMap(const SubGraphBase<GR, NF, EF, ch>& adaptor)
deba@559
  1056
        : Parent(adaptor) {}
deba@559
  1057
      ArcMap(const SubGraphBase<GR, NF, EF, ch>& adaptor, const V& value)
deba@559
  1058
        : Parent(adaptor, value) {}
deba@432
  1059
deba@432
  1060
    private:
deba@432
  1061
      ArcMap& operator=(const ArcMap& cmap) {
deba@432
  1062
        return operator=<ArcMap>(cmap);
deba@432
  1063
      }
deba@432
  1064
deba@432
  1065
      template <typename CMap>
deba@432
  1066
      ArcMap& operator=(const CMap& cmap) {
deba@559
  1067
        Parent::operator=(cmap);
deba@432
  1068
        return *this;
deba@432
  1069
      }
deba@432
  1070
    };
deba@432
  1071
deba@559
  1072
    template <typename V>
deba@559
  1073
    class EdgeMap 
deba@559
  1074
      : public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
deba@559
  1075
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> {
kpeter@664
  1076
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>, 
kpeter@664
  1077
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent;
kpeter@664
  1078
deba@432
  1079
    public:
deba@559
  1080
      typedef V Value;
deba@559
  1081
deba@559
  1082
      EdgeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor)
deba@559
  1083
        : Parent(adaptor) {}
deba@559
  1084
deba@559
  1085
      EdgeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor, const V& value)
deba@559
  1086
        : Parent(adaptor, value) {}
deba@432
  1087
deba@432
  1088
    private:
deba@432
  1089
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@432
  1090
        return operator=<EdgeMap>(cmap);
deba@432
  1091
      }
deba@432
  1092
deba@432
  1093
      template <typename CMap>
deba@432
  1094
      EdgeMap& operator=(const CMap& cmap) {
deba@559
  1095
        Parent::operator=(cmap);
deba@432
  1096
        return *this;
deba@432
  1097
      }
deba@432
  1098
    };
deba@432
  1099
deba@432
  1100
  };
deba@432
  1101
deba@559
  1102
  template <typename GR, typename NF, typename EF>
deba@559
  1103
  class SubGraphBase<GR, NF, EF, false>
deba@559
  1104
    : public GraphAdaptorBase<GR> {
kpeter@664
  1105
    typedef GraphAdaptorBase<GR> Parent;
deba@432
  1106
  public:
deba@559
  1107
    typedef GR Graph;
deba@559
  1108
    typedef NF NodeFilterMap;
deba@559
  1109
    typedef EF EdgeFilterMap;
kpeter@472
  1110
deba@432
  1111
    typedef SubGraphBase Adaptor;
deba@432
  1112
  protected:
deba@559
  1113
    NF* _node_filter;
deba@559
  1114
    EF* _edge_filter;
deba@559
  1115
    SubGraphBase() 
deba@559
  1116
	  : Parent(), _node_filter(0), _edge_filter(0) { }
deba@559
  1117
deba@559
  1118
    void initialize(GR& graph, NF& node_filter, EF& edge_filter) {
deba@559
  1119
      Parent::initialize(graph);
deba@559
  1120
      _node_filter = &node_filter;
deba@559
  1121
      _edge_filter = &edge_filter;
deba@432
  1122
    }
deba@432
  1123
deba@432
  1124
  public:
deba@432
  1125
deba@432
  1126
    typedef typename Parent::Node Node;
deba@432
  1127
    typedef typename Parent::Arc Arc;
deba@432
  1128
    typedef typename Parent::Edge Edge;
deba@432
  1129
deba@432
  1130
    void first(Node& i) const {
deba@432
  1131
      Parent::first(i);
deba@559
  1132
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
deba@432
  1133
    }
deba@432
  1134
deba@432
  1135
    void first(Arc& i) const {
deba@432
  1136
      Parent::first(i);
deba@559
  1137
      while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
deba@432
  1138
    }
deba@432
  1139
deba@432
  1140
    void first(Edge& i) const {
deba@432
  1141
      Parent::first(i);
deba@559
  1142
      while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
deba@432
  1143
    }
deba@432
  1144
deba@432
  1145
    void firstIn(Arc& i, const Node& n) const {
deba@432
  1146
      Parent::firstIn(i, n);
deba@559
  1147
      while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextIn(i);
deba@432
  1148
    }
deba@432
  1149
deba@432
  1150
    void firstOut(Arc& i, const Node& n) const {
deba@432
  1151
      Parent::firstOut(i, n);
deba@559
  1152
      while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextOut(i);
deba@432
  1153
    }
deba@432
  1154
deba@432
  1155
    void firstInc(Edge& i, bool& d, const Node& n) const {
deba@432
  1156
      Parent::firstInc(i, d, n);
deba@559
  1157
      while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextInc(i, d);
deba@432
  1158
    }
deba@432
  1159
deba@432
  1160
    void next(Node& i) const {
deba@432
  1161
      Parent::next(i);
deba@559
  1162
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
deba@432
  1163
    }
deba@432
  1164
    void next(Arc& i) const {
deba@432
  1165
      Parent::next(i);
deba@559
  1166
      while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
deba@432
  1167
    }
deba@432
  1168
    void next(Edge& i) const {
deba@432
  1169
      Parent::next(i);
deba@559
  1170
      while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
deba@432
  1171
    }
deba@432
  1172
    void nextIn(Arc& i) const {
deba@432
  1173
      Parent::nextIn(i);
deba@559
  1174
      while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextIn(i);
deba@432
  1175
    }
deba@432
  1176
deba@432
  1177
    void nextOut(Arc& i) const {
deba@432
  1178
      Parent::nextOut(i);
deba@559
  1179
      while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextOut(i);
deba@432
  1180
    }
deba@432
  1181
    void nextInc(Edge& i, bool& d) const {
deba@432
  1182
      Parent::nextInc(i, d);
deba@559
  1183
      while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextInc(i, d);
deba@432
  1184
    }
deba@432
  1185
deba@559
  1186
    void status(const Node& n, bool v) const { _node_filter->set(n, v); }
deba@559
  1187
    void status(const Edge& e, bool v) const { _edge_filter->set(e, v); }
deba@559
  1188
deba@559
  1189
    bool status(const Node& n) const { return (*_node_filter)[n]; }
deba@559
  1190
    bool status(const Edge& e) const { return (*_edge_filter)[e]; }
deba@432
  1191
deba@432
  1192
    typedef False NodeNumTag;
kpeter@469
  1193
    typedef False ArcNumTag;
deba@432
  1194
    typedef False EdgeNumTag;
deba@432
  1195
kpeter@469
  1196
    typedef FindArcTagIndicator<Graph> FindArcTag;
deba@432
  1197
    Arc findArc(const Node& u, const Node& v,
kpeter@471
  1198
                const Arc& prev = INVALID) const {
deba@432
  1199
      Arc arc = Parent::findArc(u, v, prev);
deba@559
  1200
      while (arc != INVALID && !(*_edge_filter)[arc]) {
deba@432
  1201
        arc = Parent::findArc(u, v, arc);
deba@432
  1202
      }
deba@432
  1203
      return arc;
deba@432
  1204
    }
kpeter@469
  1205
kpeter@469
  1206
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@432
  1207
    Edge findEdge(const Node& u, const Node& v,
kpeter@471
  1208
                  const Edge& prev = INVALID) const {
deba@432
  1209
      Edge edge = Parent::findEdge(u, v, prev);
deba@559
  1210
      while (edge != INVALID && !(*_edge_filter)[edge]) {
deba@432
  1211
        edge = Parent::findEdge(u, v, edge);
deba@432
  1212
      }
deba@432
  1213
      return edge;
deba@432
  1214
    }
deba@432
  1215
deba@559
  1216
    template <typename V>
deba@559
  1217
    class NodeMap 
deba@559
  1218
      : public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
deba@559
  1219
          LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> {
kpeter@664
  1220
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 
kpeter@664
  1221
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent;
kpeter@664
  1222
deba@432
  1223
    public:
deba@559
  1224
      typedef V Value;
deba@559
  1225
deba@559
  1226
      NodeMap(const SubGraphBase<GR, NF, EF, false>& adaptor)
deba@559
  1227
        : Parent(adaptor) {}
deba@559
  1228
      NodeMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value)
deba@559
  1229
        : Parent(adaptor, value) {}
deba@432
  1230
deba@432
  1231
    private:
deba@432
  1232
      NodeMap& operator=(const NodeMap& cmap) {
deba@432
  1233
        return operator=<NodeMap>(cmap);
deba@432
  1234
      }
deba@432
  1235
deba@432
  1236
      template <typename CMap>
deba@432
  1237
      NodeMap& operator=(const CMap& cmap) {
deba@559
  1238
        Parent::operator=(cmap);
deba@432
  1239
        return *this;
deba@432
  1240
      }
deba@432
  1241
    };
deba@432
  1242
deba@559
  1243
    template <typename V>
deba@559
  1244
    class ArcMap 
deba@559
  1245
      : public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
deba@559
  1246
          LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> {
kpeter@664
  1247
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 
kpeter@664
  1248
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent;
kpeter@664
  1249
deba@432
  1250
    public:
deba@559
  1251
      typedef V Value;
deba@559
  1252
deba@559
  1253
      ArcMap(const SubGraphBase<GR, NF, EF, false>& adaptor)
deba@559
  1254
        : Parent(adaptor) {}
deba@559
  1255
      ArcMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value)
deba@559
  1256
        : Parent(adaptor, value) {}
deba@432
  1257
deba@432
  1258
    private:
deba@432
  1259
      ArcMap& operator=(const ArcMap& cmap) {
deba@432
  1260
        return operator=<ArcMap>(cmap);
deba@432
  1261
      }
deba@432
  1262
deba@432
  1263
      template <typename CMap>
deba@432
  1264
      ArcMap& operator=(const CMap& cmap) {
deba@559
  1265
        Parent::operator=(cmap);
deba@432
  1266
        return *this;
deba@432
  1267
      }
deba@432
  1268
    };
deba@432
  1269
deba@559
  1270
    template <typename V>
deba@559
  1271
    class EdgeMap 
deba@559
  1272
      : public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
deba@559
  1273
        LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> {
kpeter@664
  1274
      typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>, 
kpeter@664
  1275
	LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent;
kpeter@664
  1276
deba@432
  1277
    public:
deba@559
  1278
      typedef V Value;
deba@559
  1279
deba@559
  1280
      EdgeMap(const SubGraphBase<GR, NF, EF, false>& adaptor)
deba@559
  1281
        : Parent(adaptor) {}
deba@559
  1282
deba@559
  1283
      EdgeMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value)
deba@559
  1284
        : Parent(adaptor, value) {}
deba@432
  1285
deba@432
  1286
    private:
deba@432
  1287
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@432
  1288
        return operator=<EdgeMap>(cmap);
deba@432
  1289
      }
deba@432
  1290
deba@432
  1291
      template <typename CMap>
deba@432
  1292
      EdgeMap& operator=(const CMap& cmap) {
deba@559
  1293
        Parent::operator=(cmap);
deba@432
  1294
        return *this;
deba@432
  1295
      }
deba@432
  1296
    };
deba@432
  1297
deba@432
  1298
  };
deba@432
  1299
deba@432
  1300
  /// \ingroup graph_adaptors
deba@430
  1301
  ///
kpeter@474
  1302
  /// \brief Adaptor class for hiding nodes and edges in an undirected
kpeter@474
  1303
  /// graph.
deba@430
  1304
  ///
kpeter@474
  1305
  /// SubGraph can be used for hiding nodes and edges in a graph.
kpeter@474
  1306
  /// A \c bool node map and a \c bool edge map must be specified, which
kpeter@474
  1307
  /// define the filters for nodes and edges.
kpeter@474
  1308
  /// Only the nodes and edges with \c true filter value are
kpeter@476
  1309
  /// shown in the subgraph. The edges that are incident to hidden
kpeter@476
  1310
  /// nodes are also filtered out.
kpeter@476
  1311
  /// This adaptor conforms to the \ref concepts::Graph "Graph" concept.
deba@432
  1312
  ///
kpeter@474
  1313
  /// The adapted graph can also be modified through this adaptor
kpeter@476
  1314
  /// by adding or removing nodes or edges, unless the \c GR template
kpeter@474
  1315
  /// parameter is set to be \c const.
kpeter@474
  1316
  ///
kpeter@476
  1317
  /// \tparam GR The type of the adapted graph.
kpeter@474
  1318
  /// It must conform to the \ref concepts::Graph "Graph" concept.
kpeter@474
  1319
  /// It can also be specified to be \c const.
kpeter@476
  1320
  /// \tparam NF The type of the node filter map.
kpeter@476
  1321
  /// It must be a \c bool (or convertible) node map of the
kpeter@476
  1322
  /// adapted graph. The default type is
kpeter@476
  1323
  /// \ref concepts::Graph::NodeMap "GR::NodeMap<bool>".
kpeter@476
  1324
  /// \tparam EF The type of the edge filter map.
kpeter@476
  1325
  /// It must be a \c bool (or convertible) edge map of the
kpeter@476
  1326
  /// adapted graph. The default type is
kpeter@476
  1327
  /// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>".
kpeter@474
  1328
  ///
kpeter@474
  1329
  /// \note The \c Node, \c Edge and \c Arc types of this adaptor and the
kpeter@474
  1330
  /// adapted graph are convertible to each other.
deba@432
  1331
  ///
deba@432
  1332
  /// \see FilterNodes
deba@432
  1333
  /// \see FilterEdges
kpeter@474
  1334
#ifdef DOXYGEN
kpeter@476
  1335
  template<typename GR, typename NF, typename EF>
kpeter@476
  1336
  class SubGraph {
kpeter@474
  1337
#else
kpeter@476
  1338
  template<typename GR,
kpeter@476
  1339
           typename NF = typename GR::template NodeMap<bool>,
kpeter@476
  1340
           typename EF = typename GR::template EdgeMap<bool> >
kpeter@476
  1341
  class SubGraph :
kpeter@476
  1342
    public GraphAdaptorExtender<SubGraphBase<GR, NF, EF, true> > {
kpeter@474
  1343
#endif
deba@430
  1344
  public:
kpeter@474
  1345
    /// The type of the adapted graph.
kpeter@476
  1346
    typedef GR Graph;
kpeter@474
  1347
    /// The type of the node filter map.
kpeter@476
  1348
    typedef NF NodeFilterMap;
kpeter@474
  1349
    /// The type of the edge filter map.
kpeter@476
  1350
    typedef EF EdgeFilterMap;
kpeter@476
  1351
deba@559
  1352
    typedef GraphAdaptorExtender<SubGraphBase<GR, NF, EF, true> >
kpeter@476
  1353
      Parent;
deba@430
  1354
deba@431
  1355
    typedef typename Parent::Node Node;
deba@432
  1356
    typedef typename Parent::Edge Edge;
deba@431
  1357
deba@430
  1358
  protected:
deba@432
  1359
    SubGraph() { }
deba@430
  1360
  public:
deba@430
  1361
deba@431
  1362
    /// \brief Constructor
deba@431
  1363
    ///
kpeter@474
  1364
    /// Creates a subgraph for the given graph with the given node
kpeter@474
  1365
    /// and edge filter maps.
deba@559
  1366
    SubGraph(GR& graph, NF& node_filter, EF& edge_filter) {
deba@559
  1367
      initialize(graph, node_filter, edge_filter);
deba@430
  1368
    }
deba@430
  1369
kpeter@475
  1370
    /// \brief Sets the status of the given node
deba@431
  1371
    ///
kpeter@475
  1372
    /// This function sets the status of the given node.
kpeter@474
  1373
    /// It is done by simply setting the assigned value of \c n
kpeter@475
  1374
    /// to \c v in the node filter map.
kpeter@475
  1375
    void status(const Node& n, bool v) const { Parent::status(n, v); }
kpeter@475
  1376
kpeter@475
  1377
    /// \brief Sets the status of the given edge
deba@432
  1378
    ///
kpeter@475
  1379
    /// This function sets the status of the given edge.
kpeter@474
  1380
    /// It is done by simply setting the assigned value of \c e
kpeter@475
  1381
    /// to \c v in the edge filter map.
kpeter@475
  1382
    void status(const Edge& e, bool v) const { Parent::status(e, v); }
kpeter@475
  1383
kpeter@475
  1384
    /// \brief Returns the status of the given node
deba@431
  1385
    ///
kpeter@475
  1386
    /// This function returns the status of the given node.
kpeter@475
  1387
    /// It is \c true if the given node is enabled (i.e. not hidden).
kpeter@475
  1388
    bool status(const Node& n) const { return Parent::status(n); }
kpeter@475
  1389
kpeter@475
  1390
    /// \brief Returns the status of the given edge
deba@432
  1391
    ///
kpeter@475
  1392
    /// This function returns the status of the given edge.
kpeter@475
  1393
    /// It is \c true if the given edge is enabled (i.e. not hidden).
kpeter@475
  1394
    bool status(const Edge& e) const { return Parent::status(e); }
kpeter@475
  1395
kpeter@475
  1396
    /// \brief Disables the given node
deba@431
  1397
    ///
kpeter@475
  1398
    /// This function disables the given node in the subdigraph,
kpeter@475
  1399
    /// so the iteration jumps over it.
kpeter@475
  1400
    /// It is the same as \ref status() "status(n, false)".
kpeter@475
  1401
    void disable(const Node& n) const { Parent::status(n, false); }
kpeter@475
  1402
kpeter@475
  1403
    /// \brief Disables the given edge
deba@431
  1404
    ///
kpeter@475
  1405
    /// This function disables the given edge in the subgraph,
kpeter@475
  1406
    /// so the iteration jumps over it.
kpeter@475
  1407
    /// It is the same as \ref status() "status(e, false)".
kpeter@475
  1408
    void disable(const Edge& e) const { Parent::status(e, false); }
kpeter@475
  1409
kpeter@475
  1410
    /// \brief Enables the given node
kpeter@475
  1411
    ///
kpeter@475
  1412
    /// This function enables the given node in the subdigraph.
kpeter@475
  1413
    /// It is the same as \ref status() "status(n, true)".
kpeter@475
  1414
    void enable(const Node& n) const { Parent::status(n, true); }
kpeter@475
  1415
kpeter@475
  1416
    /// \brief Enables the given edge
kpeter@475
  1417
    ///
kpeter@475
  1418
    /// This function enables the given edge in the subgraph.
kpeter@475
  1419
    /// It is the same as \ref status() "status(e, true)".
kpeter@475
  1420
    void enable(const Edge& e) const { Parent::status(e, true); }
kpeter@475
  1421
deba@430
  1422
  };
deba@430
  1423
kpeter@474
  1424
  /// \brief Returns a read-only SubGraph adaptor
deba@430
  1425
  ///
kpeter@474
  1426
  /// This function just returns a read-only \ref SubGraph adaptor.
kpeter@474
  1427
  /// \ingroup graph_adaptors
kpeter@474
  1428
  /// \relates SubGraph
kpeter@476
  1429
  template<typename GR, typename NF, typename EF>
kpeter@476
  1430
  SubGraph<const GR, NF, EF>
deba@559
  1431
  subGraph(const GR& graph, NF& node_filter, EF& edge_filter) {
kpeter@476
  1432
    return SubGraph<const GR, NF, EF>
deba@559
  1433
      (graph, node_filter, edge_filter);
deba@432
  1434
  }
deba@432
  1435
kpeter@476
  1436
  template<typename GR, typename NF, typename EF>
kpeter@476
  1437
  SubGraph<const GR, const NF, EF>
deba@559
  1438
  subGraph(const GR& graph, const NF& node_filter, EF& edge_filter) {
kpeter@476
  1439
    return SubGraph<const GR, const NF, EF>
deba@559
  1440
      (graph, node_filter, edge_filter);
deba@432
  1441
  }
deba@432
  1442
kpeter@476
  1443
  template<typename GR, typename NF, typename EF>
kpeter@476
  1444
  SubGraph<const GR, NF, const EF>
deba@559
  1445
  subGraph(const GR& graph, NF& node_filter, const EF& edge_filter) {
kpeter@476
  1446
    return SubGraph<const GR, NF, const EF>
deba@559
  1447
      (graph, node_filter, edge_filter);
deba@432
  1448
  }
deba@432
  1449
kpeter@476
  1450
  template<typename GR, typename NF, typename EF>
kpeter@476
  1451
  SubGraph<const GR, const NF, const EF>
deba@559
  1452
  subGraph(const GR& graph, const NF& node_filter, const EF& edge_filter) {
kpeter@476
  1453
    return SubGraph<const GR, const NF, const EF>
deba@559
  1454
      (graph, node_filter, edge_filter);
deba@432
  1455
  }
deba@432
  1456
kpeter@474
  1457
deba@432
  1458
  /// \ingroup graph_adaptors
deba@432
  1459
  ///
kpeter@474
  1460
  /// \brief Adaptor class for hiding nodes in a digraph or a graph.
deba@432
  1461
  ///
kpeter@474
  1462
  /// FilterNodes adaptor can be used for hiding nodes in a digraph or a
kpeter@474
  1463
  /// graph. A \c bool node map must be specified, which defines the filter
kpeter@474
  1464
  /// for the nodes. Only the nodes with \c true filter value and the
kpeter@474
  1465
  /// arcs/edges incident to nodes both with \c true filter value are shown
kpeter@474
  1466
  /// in the subgraph. This adaptor conforms to the \ref concepts::Digraph
kpeter@474
  1467
  /// "Digraph" concept or the \ref concepts::Graph "Graph" concept
kpeter@476
  1468
  /// depending on the \c GR template parameter.
deba@432
  1469
  ///
kpeter@474
  1470
  /// The adapted (di)graph can also be modified through this adaptor
kpeter@476
  1471
  /// by adding or removing nodes or arcs/edges, unless the \c GR template
kpeter@474
  1472
  /// parameter is set to be \c const.
kpeter@474
  1473
  ///
kpeter@476
  1474
  /// \tparam GR The type of the adapted digraph or graph.
kpeter@474
  1475
  /// It must conform to the \ref concepts::Digraph "Digraph" concept
kpeter@474
  1476
  /// or the \ref concepts::Graph "Graph" concept.
kpeter@474
  1477
  /// It can also be specified to be \c const.
kpeter@476
  1478
  /// \tparam NF The type of the node filter map.
kpeter@476
  1479
  /// It must be a \c bool (or convertible) node map of the
kpeter@476
  1480
  /// adapted (di)graph. The default type is
kpeter@476
  1481
  /// \ref concepts::Graph::NodeMap "GR::NodeMap<bool>".
kpeter@474
  1482
  ///
kpeter@474
  1483
  /// \note The \c Node and <tt>Arc/Edge</tt> types of this adaptor and the
kpeter@474
  1484
  /// adapted (di)graph are convertible to each other.
deba@432
  1485
#ifdef DOXYGEN
kpeter@476
  1486
  template<typename GR, typename NF>
kpeter@476
  1487
  class FilterNodes {
deba@432
  1488
#else
kpeter@476
  1489
  template<typename GR,
kpeter@476
  1490
           typename NF = typename GR::template NodeMap<bool>,
deba@432
  1491
           typename Enable = void>
kpeter@476
  1492
  class FilterNodes :
kpeter@476
  1493
    public DigraphAdaptorExtender<
deba@559
  1494
      SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >,
deba@559
  1495
                     true> > {
deba@432
  1496
#endif
kpeter@476
  1497
    typedef DigraphAdaptorExtender<
deba@559
  1498
      SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >, 
deba@559
  1499
                     true> > Parent;
deba@432
  1500
kpeter@664
  1501
  public:
kpeter@664
  1502
kpeter@664
  1503
    typedef GR Digraph;
kpeter@664
  1504
    typedef NF NodeFilterMap;
kpeter@664
  1505
deba@432
  1506
    typedef typename Parent::Node Node;
deba@432
  1507
deba@432
  1508
  protected:
deba@559
  1509
    ConstMap<typename Digraph::Arc, Const<bool, true> > const_true_map;
deba@559
  1510
deba@559
  1511
    FilterNodes() : const_true_map() {}
deba@432
  1512
deba@432
  1513
  public:
deba@432
  1514
deba@432
  1515
    /// \brief Constructor
deba@432
  1516
    ///
kpeter@474
  1517
    /// Creates a subgraph for the given digraph or graph with the
deba@432
  1518
    /// given node filter map.
deba@559
  1519
    FilterNodes(GR& graph, NF& node_filter) 
deba@559
  1520
      : Parent(), const_true_map()
kpeter@476
  1521
    {
deba@559
  1522
      Parent::initialize(graph, node_filter, const_true_map);
deba@432
  1523
    }
deba@432
  1524
kpeter@475
  1525
    /// \brief Sets the status of the given node
deba@432
  1526
    ///
kpeter@475
  1527
    /// This function sets the status of the given node.
kpeter@474
  1528
    /// It is done by simply setting the assigned value of \c n
kpeter@475
  1529
    /// to \c v in the node filter map.
kpeter@475
  1530
    void status(const Node& n, bool v) const { Parent::status(n, v); }
kpeter@475
  1531
kpeter@475
  1532
    /// \brief Returns the status of the given node
deba@432
  1533
    ///
kpeter@475
  1534
    /// This function returns the status of the given node.
kpeter@475
  1535
    /// It is \c true if the given node is enabled (i.e. not hidden).
kpeter@475
  1536
    bool status(const Node& n) const { return Parent::status(n); }
kpeter@475
  1537
kpeter@475
  1538
    /// \brief Disables the given node
deba@432
  1539
    ///
kpeter@475
  1540
    /// This function disables the given node, so the iteration
kpeter@475
  1541
    /// jumps over it.
kpeter@475
  1542
    /// It is the same as \ref status() "status(n, false)".
kpeter@475
  1543
    void disable(const Node& n) const { Parent::status(n, false); }
kpeter@475
  1544
kpeter@475
  1545
    /// \brief Enables the given node
kpeter@475
  1546
    ///
kpeter@475
  1547
    /// This function enables the given node.
kpeter@475
  1548
    /// It is the same as \ref status() "status(n, true)".
kpeter@475
  1549
    void enable(const Node& n) const { Parent::status(n, true); }
deba@432
  1550
deba@432
  1551
  };
deba@432
  1552
kpeter@476
  1553
  template<typename GR, typename NF>
kpeter@476
  1554
  class FilterNodes<GR, NF,
kpeter@476
  1555
                    typename enable_if<UndirectedTagIndicator<GR> >::type> :
kpeter@476
  1556
    public GraphAdaptorExtender<
deba@559
  1557
      SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, 
deba@559
  1558
                   true> > {
kpeter@476
  1559
kpeter@476
  1560
    typedef GraphAdaptorExtender<
deba@559
  1561
      SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >, 
deba@559
  1562
                   true> > Parent;
deba@432
  1563
kpeter@664
  1564
  public:
kpeter@664
  1565
kpeter@664
  1566
    typedef GR Graph;
kpeter@664
  1567
    typedef NF NodeFilterMap;
kpeter@664
  1568
deba@432
  1569
    typedef typename Parent::Node Node;
kpeter@664
  1570
deba@432
  1571
  protected:
deba@559
  1572
    ConstMap<typename GR::Edge, Const<bool, true> > const_true_map;
deba@559
  1573
deba@559
  1574
    FilterNodes() : const_true_map() {}
deba@432
  1575
deba@432
  1576
  public:
deba@432
  1577
deba@559
  1578
    FilterNodes(GR& graph, NodeFilterMap& node_filter) :
deba@559
  1579
      Parent(), const_true_map() {
deba@559
  1580
      Parent::initialize(graph, node_filter, const_true_map);
deba@432
  1581
    }
deba@432
  1582
kpeter@475
  1583
    void status(const Node& n, bool v) const { Parent::status(n, v); }
kpeter@475
  1584
    bool status(const Node& n) const { return Parent::status(n); }
kpeter@475
  1585
    void disable(const Node& n) const { Parent::status(n, false); }
kpeter@475
  1586
    void enable(const Node& n) const { Parent::status(n, true); }
deba@432
  1587
deba@432
  1588
  };
deba@432
  1589
deba@432
  1590
kpeter@474
  1591
  /// \brief Returns a read-only FilterNodes adaptor
deba@432
  1592
  ///
kpeter@474
  1593
  /// This function just returns a read-only \ref FilterNodes adaptor.
kpeter@474
  1594
  /// \ingroup graph_adaptors
kpeter@474
  1595
  /// \relates FilterNodes
kpeter@476
  1596
  template<typename GR, typename NF>
kpeter@476
  1597
  FilterNodes<const GR, NF>
deba@559
  1598
  filterNodes(const GR& graph, NF& node_filter) {
deba@559
  1599
    return FilterNodes<const GR, NF>(graph, node_filter);
deba@430
  1600
  }
deba@430
  1601
kpeter@476
  1602
  template<typename GR, typename NF>
kpeter@476
  1603
  FilterNodes<const GR, const NF>
deba@559
  1604
  filterNodes(const GR& graph, const NF& node_filter) {
deba@559
  1605
    return FilterNodes<const GR, const NF>(graph, node_filter);
deba@430
  1606
  }
deba@430
  1607
deba@432
  1608
  /// \ingroup graph_adaptors
deba@430
  1609
  ///
kpeter@474
  1610
  /// \brief Adaptor class for hiding arcs in a digraph.
deba@430
  1611
  ///
kpeter@474
  1612
  /// FilterArcs adaptor can be used for hiding arcs in a digraph.
kpeter@474
  1613
  /// A \c bool arc map must be specified, which defines the filter for
kpeter@474
  1614
  /// the arcs. Only the arcs with \c true filter value are shown in the
kpeter@474
  1615
  /// subdigraph. This adaptor conforms to the \ref concepts::Digraph
kpeter@474
  1616
  /// "Digraph" concept.
deba@430
  1617
  ///
kpeter@474
  1618
  /// The adapted digraph can also be modified through this adaptor
kpeter@476
  1619
  /// by adding or removing nodes or arcs, unless the \c GR template
kpeter@474
  1620
  /// parameter is set to be \c const.
kpeter@474
  1621
  ///
deba@559
  1622
  /// \tparam DGR The type of the adapted digraph.
kpeter@474
  1623
  /// It must conform to the \ref concepts::Digraph "Digraph" concept.
kpeter@474
  1624
  /// It can also be specified to be \c const.
kpeter@476
  1625
  /// \tparam AF The type of the arc filter map.
kpeter@476
  1626
  /// It must be a \c bool (or convertible) arc map of the
kpeter@476
  1627
  /// adapted digraph. The default type is
deba@559
  1628
  /// \ref concepts::Digraph::ArcMap "DGR::ArcMap<bool>".
kpeter@474
  1629
  ///
kpeter@474
  1630
  /// \note The \c Node and \c Arc types of this adaptor and the adapted
kpeter@474
  1631
  /// digraph are convertible to each other.
kpeter@474
  1632
#ifdef DOXYGEN
deba@559
  1633
  template<typename DGR,
kpeter@476
  1634
           typename AF>
kpeter@476
  1635
  class FilterArcs {
kpeter@474
  1636
#else
deba@559
  1637
  template<typename DGR,
deba@559
  1638
           typename AF = typename DGR::template ArcMap<bool> >
kpeter@476
  1639
  class FilterArcs :
kpeter@476
  1640
    public DigraphAdaptorExtender<
deba@559
  1641
      SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >,
deba@559
  1642
                     AF, false> > {
kpeter@474
  1643
#endif
kpeter@664
  1644
    typedef DigraphAdaptorExtender<
kpeter@664
  1645
      SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >, 
kpeter@664
  1646
                     AF, false> > Parent;
kpeter@664
  1647
deba@430
  1648
  public:
kpeter@664
  1649
kpeter@476
  1650
    /// The type of the adapted digraph.
deba@559
  1651
    typedef DGR Digraph;
kpeter@476
  1652
    /// The type of the arc filter map.
kpeter@476
  1653
    typedef AF ArcFilterMap;
kpeter@476
  1654
deba@431
  1655
    typedef typename Parent::Arc Arc;
deba@431
  1656
deba@430
  1657
  protected:
deba@559
  1658
    ConstMap<typename DGR::Node, Const<bool, true> > const_true_map;
deba@559
  1659
deba@559
  1660
    FilterArcs() : const_true_map() {}
deba@430
  1661
deba@430
  1662
  public:
deba@430
  1663
deba@431
  1664
    /// \brief Constructor
deba@431
  1665
    ///
kpeter@474
  1666
    /// Creates a subdigraph for the given digraph with the given arc
kpeter@474
  1667
    /// filter map.
deba@559
  1668
    FilterArcs(DGR& digraph, ArcFilterMap& arc_filter)
deba@559
  1669
      : Parent(), const_true_map() {
deba@559
  1670
      Parent::initialize(digraph, const_true_map, arc_filter);
deba@430
  1671
    }
deba@430
  1672
kpeter@475
  1673
    /// \brief Sets the status of the given arc
deba@431
  1674
    ///
kpeter@475
  1675
    /// This function sets the status of the given arc.
kpeter@474
  1676
    /// It is done by simply setting the assigned value of \c a
kpeter@475
  1677
    /// to \c v in the arc filter map.
kpeter@475
  1678
    void status(const Arc& a, bool v) const { Parent::status(a, v); }
kpeter@475
  1679
kpeter@475
  1680
    /// \brief Returns the status of the given arc
deba@431
  1681
    ///
kpeter@475
  1682
    /// This function returns the status of the given arc.
kpeter@475
  1683
    /// It is \c true if the given arc is enabled (i.e. not hidden).
kpeter@475
  1684
    bool status(const Arc& a) const { return Parent::status(a); }
kpeter@475
  1685
kpeter@475
  1686
    /// \brief Disables the given arc
deba@431
  1687
    ///
kpeter@475
  1688
    /// This function disables the given arc in the subdigraph,
kpeter@475
  1689
    /// so the iteration jumps over it.
kpeter@475
  1690
    /// It is the same as \ref status() "status(a, false)".
kpeter@475
  1691
    void disable(const Arc& a) const { Parent::status(a, false); }
kpeter@475
  1692
kpeter@475
  1693
    /// \brief Enables the given arc
kpeter@475
  1694
    ///
kpeter@475
  1695
    /// This function enables the given arc in the subdigraph.
kpeter@475
  1696
    /// It is the same as \ref status() "status(a, true)".
kpeter@475
  1697
    void enable(const Arc& a) const { Parent::status(a, true); }
deba@431
  1698
deba@430
  1699
  };
deba@430
  1700
kpeter@474
  1701
  /// \brief Returns a read-only FilterArcs adaptor
deba@430
  1702
  ///
kpeter@474
  1703
  /// This function just returns a read-only \ref FilterArcs adaptor.
kpeter@474
  1704
  /// \ingroup graph_adaptors
kpeter@474
  1705
  /// \relates FilterArcs
deba@559
  1706
  template<typename DGR, typename AF>
deba@559
  1707
  FilterArcs<const DGR, AF>
deba@559
  1708
  filterArcs(const DGR& digraph, AF& arc_filter) {
deba@559
  1709
    return FilterArcs<const DGR, AF>(digraph, arc_filter);
deba@430
  1710
  }
deba@430
  1711
deba@559
  1712
  template<typename DGR, typename AF>
deba@559
  1713
  FilterArcs<const DGR, const AF>
deba@559
  1714
  filterArcs(const DGR& digraph, const AF& arc_filter) {
deba@559
  1715
    return FilterArcs<const DGR, const AF>(digraph, arc_filter);
deba@430
  1716
  }
deba@430
  1717
deba@432
  1718
  /// \ingroup graph_adaptors
deba@432
  1719
  ///
kpeter@474
  1720
  /// \brief Adaptor class for hiding edges in a graph.
deba@432
  1721
  ///
kpeter@474
  1722
  /// FilterEdges adaptor can be used for hiding edges in a graph.
kpeter@474
  1723
  /// A \c bool edge map must be specified, which defines the filter for
kpeter@474
  1724
  /// the edges. Only the edges with \c true filter value are shown in the
kpeter@474
  1725
  /// subgraph. This adaptor conforms to the \ref concepts::Graph
kpeter@474
  1726
  /// "Graph" concept.
deba@432
  1727
  ///
kpeter@474
  1728
  /// The adapted graph can also be modified through this adaptor
kpeter@476
  1729
  /// by adding or removing nodes or edges, unless the \c GR template
kpeter@474
  1730
  /// parameter is set to be \c const.
kpeter@474
  1731
  ///
kpeter@476
  1732
  /// \tparam GR The type of the adapted graph.
kpeter@474
  1733
  /// It must conform to the \ref concepts::Graph "Graph" concept.
kpeter@474
  1734
  /// It can also be specified to be \c const.
kpeter@476
  1735
  /// \tparam EF The type of the edge filter map.
kpeter@476
  1736
  /// It must be a \c bool (or convertible) edge map of the
kpeter@476
  1737
  /// adapted graph. The default type is
kpeter@476
  1738
  /// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>".
kpeter@474
  1739
  ///
kpeter@474
  1740
  /// \note The \c Node, \c Edge and \c Arc types of this adaptor and the
kpeter@474
  1741
  /// adapted graph are convertible to each other.
kpeter@474
  1742
#ifdef DOXYGEN
kpeter@476
  1743
  template<typename GR,
kpeter@476
  1744
           typename EF>
kpeter@476
  1745
  class FilterEdges {
kpeter@474
  1746
#else
kpeter@476
  1747
  template<typename GR,
kpeter@476
  1748
           typename EF = typename GR::template EdgeMap<bool> >
kpeter@476
  1749
  class FilterEdges :
kpeter@476
  1750
    public GraphAdaptorExtender<
deba@559
  1751
      SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >, 
deba@559
  1752
                   EF, false> > {
kpeter@474
  1753
#endif
kpeter@664
  1754
    typedef GraphAdaptorExtender<
kpeter@664
  1755
      SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >, 
kpeter@664
  1756
                   EF, false> > Parent;
kpeter@664
  1757
deba@432
  1758
  public:
kpeter@664
  1759
kpeter@476
  1760
    /// The type of the adapted graph.
kpeter@476
  1761
    typedef GR Graph;
kpeter@476
  1762
    /// The type of the edge filter map.
kpeter@476
  1763
    typedef EF EdgeFilterMap;
kpeter@476
  1764
deba@432
  1765
    typedef typename Parent::Edge Edge;
kpeter@476
  1766
deba@432
  1767
  protected:
deba@559
  1768
    ConstMap<typename GR::Node, Const<bool, true> > const_true_map;
deba@432
  1769
deba@432
  1770
    FilterEdges() : const_true_map(true) {
deba@432
  1771
      Parent::setNodeFilterMap(const_true_map);
deba@432
  1772
    }
deba@432
  1773
deba@432
  1774
  public:
deba@432
  1775
deba@432
  1776
    /// \brief Constructor
deba@432
  1777
    ///
kpeter@474
  1778
    /// Creates a subgraph for the given graph with the given edge
kpeter@474
  1779
    /// filter map.
deba@559
  1780
    FilterEdges(GR& graph, EF& edge_filter) 
deba@559
  1781
      : Parent(), const_true_map() {
deba@559
  1782
      Parent::initialize(graph, const_true_map, edge_filter);
deba@432
  1783
    }
deba@432
  1784
kpeter@475
  1785
    /// \brief Sets the status of the given edge
deba@432
  1786
    ///
kpeter@475
  1787
    /// This function sets the status of the given edge.
kpeter@474
  1788
    /// It is done by simply setting the assigned value of \c e
kpeter@475
  1789
    /// to \c v in the edge filter map.
kpeter@475
  1790
    void status(const Edge& e, bool v) const { Parent::status(e, v); }
kpeter@475
  1791
kpeter@475
  1792
    /// \brief Returns the status of the given edge
deba@432
  1793
    ///
kpeter@475
  1794
    /// This function returns the status of the given edge.
kpeter@475
  1795
    /// It is \c true if the given edge is enabled (i.e. not hidden).
kpeter@475
  1796
    bool status(const Edge& e) const { return Parent::status(e); }
kpeter@475
  1797
kpeter@475
  1798
    /// \brief Disables the given edge
deba@432
  1799
    ///
kpeter@475
  1800
    /// This function disables the given edge in the subgraph,
kpeter@475
  1801
    /// so the iteration jumps over it.
kpeter@475
  1802
    /// It is the same as \ref status() "status(e, false)".
kpeter@475
  1803
    void disable(const Edge& e) const { Parent::status(e, false); }
kpeter@475
  1804
kpeter@475
  1805
    /// \brief Enables the given edge
kpeter@475
  1806
    ///
kpeter@475
  1807
    /// This function enables the given edge in the subgraph.
kpeter@475
  1808
    /// It is the same as \ref status() "status(e, true)".
kpeter@475
  1809
    void enable(const Edge& e) const { Parent::status(e, true); }
deba@432
  1810
deba@432
  1811
  };
deba@432
  1812
kpeter@474
  1813
  /// \brief Returns a read-only FilterEdges adaptor
deba@432
  1814
  ///
kpeter@474
  1815
  /// This function just returns a read-only \ref FilterEdges adaptor.
kpeter@474
  1816
  /// \ingroup graph_adaptors
kpeter@474
  1817
  /// \relates FilterEdges
kpeter@476
  1818
  template<typename GR, typename EF>
kpeter@476
  1819
  FilterEdges<const GR, EF>
deba@559
  1820
  filterEdges(const GR& graph, EF& edge_filter) {
deba@559
  1821
    return FilterEdges<const GR, EF>(graph, edge_filter);
deba@432
  1822
  }
deba@432
  1823
kpeter@476
  1824
  template<typename GR, typename EF>
kpeter@476
  1825
  FilterEdges<const GR, const EF>
deba@559
  1826
  filterEdges(const GR& graph, const EF& edge_filter) {
deba@559
  1827
    return FilterEdges<const GR, const EF>(graph, edge_filter);
deba@432
  1828
  }
deba@432
  1829
kpeter@474
  1830
deba@559
  1831
  template <typename DGR>
deba@432
  1832
  class UndirectorBase {
deba@430
  1833
  public:
deba@559
  1834
    typedef DGR Digraph;
deba@432
  1835
    typedef UndirectorBase Adaptor;
deba@430
  1836
deba@430
  1837
    typedef True UndirectedTag;
deba@430
  1838
deba@430
  1839
    typedef typename Digraph::Arc Edge;
deba@430
  1840
    typedef typename Digraph::Node Node;
deba@430
  1841
deba@430
  1842
    class Arc : public Edge {
deba@432
  1843
      friend class UndirectorBase;
deba@430
  1844
    protected:
deba@430
  1845
      bool _forward;
deba@430
  1846
deba@430
  1847
      Arc(const Edge& edge, bool forward) :
deba@430
  1848
        Edge(edge), _forward(forward) {}
deba@430
  1849
deba@430
  1850
    public:
deba@430
  1851
      Arc() {}
deba@430
  1852
deba@430
  1853
      Arc(Invalid) : Edge(INVALID), _forward(true) {}
deba@430
  1854
deba@430
  1855
      bool operator==(const Arc &other) const {
deba@432
  1856
        return _forward == other._forward &&
deba@432
  1857
          static_cast<const Edge&>(*this) == static_cast<const Edge&>(other);
deba@430
  1858
      }
deba@430
  1859
      bool operator!=(const Arc &other) const {
deba@432
  1860
        return _forward != other._forward ||
deba@432
  1861
          static_cast<const Edge&>(*this) != static_cast<const Edge&>(other);
deba@430
  1862
      }
deba@430
  1863
      bool operator<(const Arc &other) const {
deba@432
  1864
        return _forward < other._forward ||
deba@432
  1865
          (_forward == other._forward &&
deba@432
  1866
           static_cast<const Edge&>(*this) < static_cast<const Edge&>(other));
deba@430
  1867
      }
deba@430
  1868
    };
deba@430
  1869
deba@430
  1870
    void first(Node& n) const {
deba@430
  1871
      _digraph->first(n);
deba@430
  1872
    }
deba@430
  1873
deba@430
  1874
    void next(Node& n) const {
deba@430
  1875
      _digraph->next(n);
deba@430
  1876
    }
deba@430
  1877
deba@430
  1878
    void first(Arc& a) const {
deba@430
  1879
      _digraph->first(a);
deba@430
  1880
      a._forward = true;
deba@430
  1881
    }
deba@430
  1882
deba@430
  1883
    void next(Arc& a) const {
deba@430
  1884
      if (a._forward) {
deba@432
  1885
        a._forward = false;
deba@430
  1886
      } else {
deba@432
  1887
        _digraph->next(a);
deba@432
  1888
        a._forward = true;
deba@430
  1889
      }
deba@430
  1890
    }
deba@430
  1891
deba@430
  1892
    void first(Edge& e) const {
deba@430
  1893
      _digraph->first(e);
deba@430
  1894
    }
deba@430
  1895
deba@430
  1896
    void next(Edge& e) const {
deba@430
  1897
      _digraph->next(e);
deba@430
  1898
    }
deba@430
  1899
deba@430
  1900
    void firstOut(Arc& a, const Node& n) const {
deba@430
  1901
      _digraph->firstIn(a, n);
deba@430
  1902
      if( static_cast<const Edge&>(a) != INVALID ) {
deba@432
  1903
        a._forward = false;
deba@430
  1904
      } else {
deba@432
  1905
        _digraph->firstOut(a, n);
deba@432
  1906
        a._forward = true;
deba@430
  1907
      }
deba@430
  1908
    }
deba@430
  1909
    void nextOut(Arc &a) const {
deba@430
  1910
      if (!a._forward) {
deba@432
  1911
        Node n = _digraph->target(a);
deba@432
  1912
        _digraph->nextIn(a);
deba@432
  1913
        if (static_cast<const Edge&>(a) == INVALID ) {
deba@432
  1914
          _digraph->firstOut(a, n);
deba@432
  1915
          a._forward = true;
deba@432
  1916
        }
deba@430
  1917
      }
deba@430
  1918
      else {
deba@432
  1919
        _digraph->nextOut(a);
deba@430
  1920
      }
deba@430
  1921
    }
deba@430
  1922
deba@430
  1923
    void firstIn(Arc &a, const Node &n) const {
deba@430
  1924
      _digraph->firstOut(a, n);
deba@430
  1925
      if (static_cast<const Edge&>(a) != INVALID ) {
deba@432
  1926
        a._forward = false;
deba@430
  1927
      } else {
deba@432
  1928
        _digraph->firstIn(a, n);
deba@432
  1929
        a._forward = true;
deba@430
  1930
      }
deba@430
  1931
    }
deba@430
  1932
    void nextIn(Arc &a) const {
deba@430
  1933
      if (!a._forward) {
deba@432
  1934
        Node n = _digraph->source(a);
deba@432
  1935
        _digraph->nextOut(a);
deba@432
  1936
        if( static_cast<const Edge&>(a) == INVALID ) {
deba@432
  1937
          _digraph->firstIn(a, n);
deba@432
  1938
          a._forward = true;
deba@432
  1939
        }
deba@430
  1940
      }
deba@430
  1941
      else {
deba@432
  1942
        _digraph->nextIn(a);
deba@430
  1943
      }
deba@430
  1944
    }
deba@430
  1945
deba@430
  1946
    void firstInc(Edge &e, bool &d, const Node &n) const {
deba@430
  1947
      d = true;
deba@430
  1948
      _digraph->firstOut(e, n);
deba@430
  1949
      if (e != INVALID) return;
deba@430
  1950
      d = false;
deba@430
  1951
      _digraph->firstIn(e, n);
deba@430
  1952
    }
deba@430
  1953
deba@430
  1954
    void nextInc(Edge &e, bool &d) const {
deba@430
  1955
      if (d) {
deba@432
  1956
        Node s = _digraph->source(e);
deba@432
  1957
        _digraph->nextOut(e);
deba@432
  1958
        if (e != INVALID) return;
deba@432
  1959
        d = false;
deba@432
  1960
        _digraph->firstIn(e, s);
deba@430
  1961
      } else {
deba@432
  1962
        _digraph->nextIn(e);
deba@430
  1963
      }
deba@430
  1964
    }
deba@430
  1965
deba@430
  1966
    Node u(const Edge& e) const {
deba@430
  1967
      return _digraph->source(e);
deba@430
  1968
    }
deba@430
  1969
deba@430
  1970
    Node v(const Edge& e) const {
deba@430
  1971
      return _digraph->target(e);
deba@430
  1972
    }
deba@430
  1973
deba@430
  1974
    Node source(const Arc &a) const {
deba@430
  1975
      return a._forward ? _digraph->source(a) : _digraph->target(a);
deba@430
  1976
    }
deba@430
  1977
deba@430
  1978
    Node target(const Arc &a) const {
deba@430
  1979
      return a._forward ? _digraph->target(a) : _digraph->source(a);
deba@430
  1980
    }
deba@430
  1981
deba@430
  1982
    static Arc direct(const Edge &e, bool d) {
deba@430
  1983
      return Arc(e, d);
deba@430
  1984
    }
deba@430
  1985
    Arc direct(const Edge &e, const Node& n) const {
deba@430
  1986
      return Arc(e, _digraph->source(e) == n);
deba@430
  1987
    }
deba@430
  1988
deba@430
  1989
    static bool direction(const Arc &a) { return a._forward; }
deba@430
  1990
deba@430
  1991
    Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
deba@430
  1992
    Arc arcFromId(int ix) const {
deba@430
  1993
      return direct(_digraph->arcFromId(ix >> 1), bool(ix & 1));
deba@430
  1994
    }
deba@430
  1995
    Edge edgeFromId(int ix) const { return _digraph->arcFromId(ix); }
deba@430
  1996
deba@430
  1997
    int id(const Node &n) const { return _digraph->id(n); }
deba@430
  1998
    int id(const Arc &a) const {
deba@430
  1999
      return  (_digraph->id(a) << 1) | (a._forward ? 1 : 0);
deba@430
  2000
    }
deba@430
  2001
    int id(const Edge &e) const { return _digraph->id(e); }
deba@430
  2002
deba@430
  2003
    int maxNodeId() const { return _digraph->maxNodeId(); }
deba@430
  2004
    int maxArcId() const { return (_digraph->maxArcId() << 1) | 1; }
deba@430
  2005
    int maxEdgeId() const { return _digraph->maxArcId(); }
deba@430
  2006
deba@430
  2007
    Node addNode() { return _digraph->addNode(); }
deba@432
  2008
    Edge addEdge(const Node& u, const Node& v) {
deba@432
  2009
      return _digraph->addArc(u, v);
deba@430
  2010
    }
deba@430
  2011
deba@430
  2012
    void erase(const Node& i) { _digraph->erase(i); }
deba@430
  2013
    void erase(const Edge& i) { _digraph->erase(i); }
deba@432
  2014
deba@430
  2015
    void clear() { _digraph->clear(); }
deba@430
  2016
deba@430
  2017
    typedef NodeNumTagIndicator<Digraph> NodeNumTag;
kpeter@472
  2018
    int nodeNum() const { return _digraph->nodeNum(); }
kpeter@469
  2019
kpeter@469
  2020
    typedef ArcNumTagIndicator<Digraph> ArcNumTag;
deba@430
  2021
    int arcNum() const { return 2 * _digraph->arcNum(); }
kpeter@469
  2022
kpeter@469
  2023
    typedef ArcNumTag EdgeNumTag;
deba@430
  2024
    int edgeNum() const { return _digraph->arcNum(); }
deba@430
  2025
kpeter@469
  2026
    typedef FindArcTagIndicator<Digraph> FindArcTag;
deba@430
  2027
    Arc findArc(Node s, Node t, Arc p = INVALID) const {
deba@430
  2028
      if (p == INVALID) {
deba@432
  2029
        Edge arc = _digraph->findArc(s, t);
deba@432
  2030
        if (arc != INVALID) return direct(arc, true);
deba@432
  2031
        arc = _digraph->findArc(t, s);
deba@432
  2032
        if (arc != INVALID) return direct(arc, false);
deba@430
  2033
      } else if (direction(p)) {
deba@432
  2034
        Edge arc = _digraph->findArc(s, t, p);
deba@432
  2035
        if (arc != INVALID) return direct(arc, true);
deba@432
  2036
        arc = _digraph->findArc(t, s);
deba@432
  2037
        if (arc != INVALID) return direct(arc, false);
deba@430
  2038
      } else {
deba@432
  2039
        Edge arc = _digraph->findArc(t, s, p);
deba@432
  2040
        if (arc != INVALID) return direct(arc, false);
deba@430
  2041
      }
deba@430
  2042
      return INVALID;
deba@430
  2043
    }
deba@430
  2044
kpeter@469
  2045
    typedef FindArcTag FindEdgeTag;
deba@430
  2046
    Edge findEdge(Node s, Node t, Edge p = INVALID) const {
deba@430
  2047
      if (s != t) {
deba@430
  2048
        if (p == INVALID) {
deba@430
  2049
          Edge arc = _digraph->findArc(s, t);
deba@430
  2050
          if (arc != INVALID) return arc;
deba@430
  2051
          arc = _digraph->findArc(t, s);
deba@430
  2052
          if (arc != INVALID) return arc;
kpeter@472
  2053
        } else if (_digraph->source(p) == s) {
deba@430
  2054
          Edge arc = _digraph->findArc(s, t, p);
deba@430
  2055
          if (arc != INVALID) return arc;
deba@430
  2056
          arc = _digraph->findArc(t, s);
deba@432
  2057
          if (arc != INVALID) return arc;
deba@430
  2058
        } else {
deba@430
  2059
          Edge arc = _digraph->findArc(t, s, p);
deba@432
  2060
          if (arc != INVALID) return arc;
deba@430
  2061
        }
deba@430
  2062
      } else {
deba@430
  2063
        return _digraph->findArc(s, t, p);
deba@430
  2064
      }
deba@430
  2065
      return INVALID;
deba@430
  2066
    }
deba@430
  2067
deba@430
  2068
  private:
deba@432
  2069
deba@559
  2070
    template <typename V>
deba@430
  2071
    class ArcMapBase {
deba@430
  2072
    private:
deba@432
  2073
deba@559
  2074
      typedef typename DGR::template ArcMap<V> MapImpl;
deba@432
  2075
deba@430
  2076
    public:
deba@430
  2077
deba@430
  2078
      typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
deba@430
  2079
deba@559
  2080
      typedef V Value;
deba@430
  2081
      typedef Arc Key;
kpeter@472
  2082
      typedef typename MapTraits<MapImpl>::ConstReturnValue ConstReturnValue;
kpeter@472
  2083
      typedef typename MapTraits<MapImpl>::ReturnValue ReturnValue;
kpeter@472
  2084
      typedef typename MapTraits<MapImpl>::ConstReturnValue ConstReference;
kpeter@472
  2085
      typedef typename MapTraits<MapImpl>::ReturnValue Reference;
deba@432
  2086
deba@559
  2087
      ArcMapBase(const UndirectorBase<DGR>& adaptor) :
deba@432
  2088
        _forward(*adaptor._digraph), _backward(*adaptor._digraph) {}
deba@432
  2089
deba@559
  2090
      ArcMapBase(const UndirectorBase<DGR>& adaptor, const V& value)
deba@559
  2091
        : _forward(*adaptor._digraph, value), 
deba@559
  2092
          _backward(*adaptor._digraph, value) {}
deba@559
  2093
deba@559
  2094
      void set(const Arc& a, const V& value) {
deba@432
  2095
        if (direction(a)) {
deba@559
  2096
          _forward.set(a, value);
deba@432
  2097
        } else {
deba@559
  2098
          _backward.set(a, value);
deba@430
  2099
        }
deba@430
  2100
      }
deba@430
  2101
kpeter@472
  2102
      ConstReturnValue operator[](const Arc& a) const {
deba@432
  2103
        if (direction(a)) {
deba@432
  2104
          return _forward[a];
deba@432
  2105
        } else {
deba@432
  2106
          return _backward[a];
deba@430
  2107
        }
deba@430
  2108
      }
deba@430
  2109
kpeter@472
  2110
      ReturnValue operator[](const Arc& a) {
deba@432
  2111
        if (direction(a)) {
deba@432
  2112
          return _forward[a];
deba@432
  2113
        } else {
deba@432
  2114
          return _backward[a];
deba@432
  2115
        }
deba@432
  2116
      }
deba@432
  2117
deba@430
  2118
    protected:
deba@430
  2119
deba@432
  2120
      MapImpl _forward, _backward;
deba@430
  2121
deba@430
  2122
    };
deba@430
  2123
deba@430
  2124
  public:
deba@430
  2125
deba@559
  2126
    template <typename V>
deba@559
  2127
    class NodeMap : public DGR::template NodeMap<V> {
kpeter@664
  2128
      typedef typename DGR::template NodeMap<V> Parent;
kpeter@664
  2129
deba@430
  2130
    public:
deba@559
  2131
      typedef V Value;
deba@559
  2132
deba@559
  2133
      explicit NodeMap(const UndirectorBase<DGR>& adaptor)
deba@432
  2134
        : Parent(*adaptor._digraph) {}
deba@430
  2135
deba@559
  2136
      NodeMap(const UndirectorBase<DGR>& adaptor, const V& value)
deba@432
  2137
        : Parent(*adaptor._digraph, value) { }
deba@430
  2138
deba@430
  2139
    private:
deba@430
  2140
      NodeMap& operator=(const NodeMap& cmap) {
deba@430
  2141
        return operator=<NodeMap>(cmap);
deba@430
  2142
      }
deba@430
  2143
deba@430
  2144
      template <typename CMap>
deba@430
  2145
      NodeMap& operator=(const CMap& cmap) {
deba@430
  2146
        Parent::operator=(cmap);
deba@430
  2147
        return *this;
deba@430
  2148
      }
deba@432
  2149
deba@430
  2150
    };
deba@430
  2151
deba@559
  2152
    template <typename V>
deba@432
  2153
    class ArcMap
kpeter@664
  2154
      : public SubMapExtender<UndirectorBase<DGR>, ArcMapBase<V> > {
kpeter@664
  2155
      typedef SubMapExtender<UndirectorBase<DGR>, ArcMapBase<V> > Parent;
kpeter@664
  2156
deba@430
  2157
    public:
deba@559
  2158
      typedef V Value;
deba@559
  2159
deba@559
  2160
      explicit ArcMap(const UndirectorBase<DGR>& adaptor)
deba@432
  2161
        : Parent(adaptor) {}
deba@432
  2162
deba@559
  2163
      ArcMap(const UndirectorBase<DGR>& adaptor, const V& value)
deba@432
  2164
        : Parent(adaptor, value) {}
deba@432
  2165
deba@430
  2166
    private:
deba@430
  2167
      ArcMap& operator=(const ArcMap& cmap) {
deba@432
  2168
        return operator=<ArcMap>(cmap);
deba@430
  2169
      }
deba@432
  2170
deba@430
  2171
      template <typename CMap>
deba@430
  2172
      ArcMap& operator=(const CMap& cmap) {
deba@430
  2173
        Parent::operator=(cmap);
deba@432
  2174
        return *this;
deba@430
  2175
      }
deba@430
  2176
    };
deba@432
  2177
deba@559
  2178
    template <typename V>
deba@559
  2179
    class EdgeMap : public Digraph::template ArcMap<V> {
kpeter@664
  2180
      typedef typename Digraph::template ArcMap<V> Parent;
kpeter@664
  2181
deba@430
  2182
    public:
deba@559
  2183
      typedef V Value;
deba@559
  2184
deba@559
  2185
      explicit EdgeMap(const UndirectorBase<DGR>& adaptor)
deba@432
  2186
        : Parent(*adaptor._digraph) {}
deba@430
  2187
deba@559
  2188
      EdgeMap(const UndirectorBase<DGR>& adaptor, const V& value)
deba@432
  2189
        : Parent(*adaptor._digraph, value) {}
deba@430
  2190
deba@430
  2191
    private:
deba@430
  2192
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@430
  2193
        return operator=<EdgeMap>(cmap);
deba@430
  2194
      }
deba@430
  2195
deba@430
  2196
      template <typename CMap>
deba@430
  2197
      EdgeMap& operator=(const CMap& cmap) {
deba@430
  2198
        Parent::operator=(cmap);
deba@430
  2199
        return *this;
deba@430
  2200
      }
deba@430
  2201
deba@430
  2202
    };
deba@430
  2203
deba@559
  2204
    typedef typename ItemSetTraits<DGR, Node>::ItemNotifier NodeNotifier;
deba@432
  2205
    NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
deba@430
  2206
deba@559
  2207
    typedef typename ItemSetTraits<DGR, Edge>::ItemNotifier EdgeNotifier;
kpeter@472
  2208
    EdgeNotifier& notifier(Edge) const { return _digraph->notifier(Edge()); }
kpeter@626
  2209
    
kpeter@626
  2210
    typedef EdgeNotifier ArcNotifier;
kpeter@626
  2211
    ArcNotifier& notifier(Arc) const { return _digraph->notifier(Edge()); }
kpeter@472
  2212
deba@430
  2213
  protected:
deba@430
  2214
deba@432
  2215
    UndirectorBase() : _digraph(0) {}
deba@430
  2216
deba@559
  2217
    DGR* _digraph;
deba@559
  2218
deba@559
  2219
    void initialize(DGR& digraph) {
deba@430
  2220
      _digraph = &digraph;
deba@430
  2221
    }
deba@432
  2222
deba@430
  2223
  };
deba@430
  2224
deba@432
  2225
  /// \ingroup graph_adaptors
deba@430
  2226
  ///
kpeter@474
  2227
  /// \brief Adaptor class for viewing a digraph as an undirected graph.
deba@430
  2228
  ///
kpeter@474
  2229
  /// Undirector adaptor can be used for viewing a digraph as an undirected
kpeter@474
  2230
  /// graph. All arcs of the underlying digraph are showed in the
kpeter@474
  2231
  /// adaptor as an edge (and also as a pair of arcs, of course).
kpeter@474
  2232
  /// This adaptor conforms to the \ref concepts::Graph "Graph" concept.
deba@430
  2233
  ///
kpeter@474
  2234
  /// The adapted digraph can also be modified through this adaptor
kpeter@476
  2235
  /// by adding or removing nodes or edges, unless the \c GR template
kpeter@474
  2236
  /// parameter is set to be \c const.
kpeter@474
  2237
  ///
deba@559
  2238
  /// \tparam DGR The type of the adapted digraph.
kpeter@474
  2239
  /// It must conform to the \ref concepts::Digraph "Digraph" concept.
kpeter@474
  2240
  /// It can also be specified to be \c const.
kpeter@474
  2241
  ///
kpeter@474
  2242
  /// \note The \c Node type of this adaptor and the adapted digraph are
kpeter@474
  2243
  /// convertible to each other, moreover the \c Edge type of the adaptor
kpeter@474
  2244
  /// and the \c Arc type of the adapted digraph are also convertible to
kpeter@474
  2245
  /// each other.
kpeter@474
  2246
  /// (Thus the \c Arc type of the adaptor is convertible to the \c Arc type
kpeter@474
  2247
  /// of the adapted digraph.)
deba@559
  2248
  template<typename DGR>
kpeter@476
  2249
#ifdef DOXYGEN
kpeter@476
  2250
  class Undirector {
kpeter@476
  2251
#else
kpeter@476
  2252
  class Undirector :
deba@559
  2253
    public GraphAdaptorExtender<UndirectorBase<DGR> > {
kpeter@476
  2254
#endif
kpeter@664
  2255
    typedef GraphAdaptorExtender<UndirectorBase<DGR> > Parent;
deba@430
  2256
  public:
kpeter@476
  2257
    /// The type of the adapted digraph.
deba@559
  2258
    typedef DGR Digraph;
deba@430
  2259
  protected:
deba@432
  2260
    Undirector() { }
deba@430
  2261
  public:
deba@430
  2262
deba@430
  2263
    /// \brief Constructor
deba@430
  2264
    ///
kpeter@474
  2265
    /// Creates an undirected graph from the given digraph.
deba@559
  2266
    Undirector(DGR& digraph) {
deba@559
  2267
      initialize(digraph);
deba@430
  2268
    }
deba@430
  2269
kpeter@474
  2270
    /// \brief Arc map combined from two original arc maps
deba@430
  2271
    ///
kpeter@474
  2272
    /// This map adaptor class adapts two arc maps of the underlying
kpeter@474
  2273
    /// digraph to get an arc map of the undirected graph.
kpeter@606
  2274
    /// Its value type is inherited from the first arc map type (\c FW).
kpeter@606
  2275
    /// \tparam FW The type of the "foward" arc map.
kpeter@606
  2276
    /// \tparam BK The type of the "backward" arc map.
kpeter@606
  2277
    template <typename FW, typename BK>
deba@430
  2278
    class CombinedArcMap {
deba@430
  2279
    public:
deba@432
  2280
kpeter@474
  2281
      /// The key type of the map
kpeter@474
  2282
      typedef typename Parent::Arc Key;
kpeter@474
  2283
      /// The value type of the map
kpeter@606
  2284
      typedef typename FW::Value Value;
kpeter@606
  2285
kpeter@606
  2286
      typedef typename MapTraits<FW>::ReferenceMapTag ReferenceMapTag;
kpeter@606
  2287
kpeter@606
  2288
      typedef typename MapTraits<FW>::ReturnValue ReturnValue;
kpeter@606
  2289
      typedef typename MapTraits<FW>::ConstReturnValue ConstReturnValue;
kpeter@606
  2290
      typedef typename MapTraits<FW>::ReturnValue Reference;
kpeter@606
  2291
      typedef typename MapTraits<FW>::ConstReturnValue ConstReference;
kpeter@472
  2292
deba@432
  2293
      /// Constructor
kpeter@606
  2294
      CombinedArcMap(FW& forward, BK& backward)
deba@430
  2295
        : _forward(&forward), _backward(&backward) {}
deba@432
  2296
kpeter@474
  2297
      /// Sets the value associated with the given key.
deba@432
  2298
      void set(const Key& e, const Value& a) {
deba@432
  2299
        if (Parent::direction(e)) {
deba@432
  2300
          _forward->set(e, a);
deba@432
  2301
        } else {
deba@432
  2302
          _backward->set(e, a);
deba@432
  2303
        }
deba@430
  2304
      }
deba@430
  2305
kpeter@474
  2306
      /// Returns the value associated with the given key.
kpeter@472
  2307
      ConstReturnValue operator[](const Key& e) const {
deba@432
  2308
        if (Parent::direction(e)) {
deba@432
  2309
          return (*_forward)[e];
deba@432
  2310
        } else {
deba@432
  2311
          return (*_backward)[e];
deba@430
  2312
        }
deba@430
  2313
      }
deba@430
  2314
kpeter@474
  2315
      /// Returns a reference to the value associated with the given key.
kpeter@472
  2316
      ReturnValue operator[](const Key& e) {
deba@432
  2317
        if (Parent::direction(e)) {
deba@432
  2318
          return (*_forward)[e];
deba@432
  2319
        } else {
deba@432
  2320
          return (*_backward)[e];
deba@430
  2321
        }
deba@430
  2322
      }
deba@430
  2323
deba@432
  2324
    protected:
deba@432
  2325
kpeter@606
  2326
      FW* _forward;
kpeter@606
  2327
      BK* _backward;
deba@432
  2328
deba@432
  2329
    };
deba@432
  2330
kpeter@474
  2331
    /// \brief Returns a combined arc map
deba@432
  2332
    ///
kpeter@474
  2333
    /// This function just returns a combined arc map.
kpeter@606
  2334
    template <typename FW, typename BK>
kpeter@606
  2335
    static CombinedArcMap<FW, BK>
kpeter@606
  2336
    combinedArcMap(FW& forward, BK& backward) {
kpeter@606
  2337
      return CombinedArcMap<FW, BK>(forward, backward);
deba@432
  2338
    }
deba@432
  2339
kpeter@606
  2340
    template <typename FW, typename BK>
kpeter@606
  2341
    static CombinedArcMap<const FW, BK>
kpeter@606
  2342
    combinedArcMap(const FW& forward, BK& backward) {
kpeter@606
  2343
      return CombinedArcMap<const FW, BK>(forward, backward);
deba@432
  2344
    }
deba@432
  2345
kpeter@606
  2346
    template <typename FW, typename BK>
kpeter@606
  2347
    static CombinedArcMap<FW, const BK>
kpeter@606
  2348
    combinedArcMap(FW& forward, const BK& backward) {
kpeter@606
  2349
      return CombinedArcMap<FW, const BK>(forward, backward);
deba@432
  2350
    }
deba@432
  2351
kpeter@606
  2352
    template <typename FW, typename BK>
kpeter@606
  2353
    static CombinedArcMap<const FW, const BK>
kpeter@606
  2354
    combinedArcMap(const FW& forward, const BK& backward) {
kpeter@606
  2355
      return CombinedArcMap<const FW, const BK>(forward, backward);
deba@432
  2356
    }
deba@432
  2357
deba@432
  2358
  };
deba@432
  2359
kpeter@474
  2360
  /// \brief Returns a read-only Undirector adaptor
deba@432
  2361
  ///
kpeter@474
  2362
  /// This function just returns a read-only \ref Undirector adaptor.
kpeter@474
  2363
  /// \ingroup graph_adaptors
kpeter@474
  2364
  /// \relates Undirector
deba@559
  2365
  template<typename DGR>
deba@559
  2366
  Undirector<const DGR> undirector(const DGR& digraph) {
deba@559
  2367
    return Undirector<const DGR>(digraph);
deba@432
  2368
  }
deba@432
  2369
kpeter@474
  2370
deba@559
  2371
  template <typename GR, typename DM>
deba@432
  2372
  class OrienterBase {
deba@432
  2373
  public:
deba@432
  2374
deba@559
  2375
    typedef GR Graph;
deba@559
  2376
    typedef DM DirectionMap;
deba@559
  2377
deba@559
  2378
    typedef typename GR::Node Node;
deba@559
  2379
    typedef typename GR::Edge Arc;
deba@432
  2380
deba@432
  2381
    void reverseArc(const Arc& arc) {
deba@432
  2382
      _direction->set(arc, !(*_direction)[arc]);
deba@432
  2383
    }
deba@432
  2384
deba@432
  2385
    void first(Node& i) const { _graph->first(i); }
deba@432
  2386
    void first(Arc& i) const { _graph->first(i); }
deba@432
  2387
    void firstIn(Arc& i, const Node& n) const {
kpeter@470
  2388
      bool d = true;
deba@432
  2389
      _graph->firstInc(i, d, n);
deba@432
  2390
      while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
deba@432
  2391
    }
deba@432
  2392
    void firstOut(Arc& i, const Node& n ) const {
kpeter@470
  2393
      bool d = true;
deba@432
  2394
      _graph->firstInc(i, d, n);
deba@432
  2395
      while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
deba@432
  2396
    }
deba@432
  2397
deba@432
  2398
    void next(Node& i) const { _graph->next(i); }
deba@432
  2399
    void next(Arc& i) const { _graph->next(i); }
deba@432
  2400
    void nextIn(Arc& i) const {
deba@432
  2401
      bool d = !(*_direction)[i];
deba@432
  2402
      _graph->nextInc(i, d);
deba@432
  2403
      while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
deba@432
  2404
    }
deba@432
  2405
    void nextOut(Arc& i) const {
deba@432
  2406
      bool d = (*_direction)[i];
deba@432
  2407
      _graph->nextInc(i, d);
deba@432
  2408
      while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
deba@432
  2409
    }
deba@432
  2410
deba@432
  2411
    Node source(const Arc& e) const {
deba@432
  2412
      return (*_direction)[e] ? _graph->u(e) : _graph->v(e);
deba@432
  2413
    }
deba@432
  2414
    Node target(const Arc& e) const {
deba@432
  2415
      return (*_direction)[e] ? _graph->v(e) : _graph->u(e);
deba@432
  2416
    }
deba@432
  2417
deba@432
  2418
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
deba@432
  2419
    int nodeNum() const { return _graph->nodeNum(); }
deba@432
  2420
kpeter@469
  2421
    typedef EdgeNumTagIndicator<Graph> ArcNumTag;
deba@432
  2422
    int arcNum() const { return _graph->edgeNum(); }
deba@432
  2423
kpeter@469
  2424
    typedef FindEdgeTagIndicator<Graph> FindArcTag;
deba@432
  2425
    Arc findArc(const Node& u, const Node& v,
kpeter@471
  2426
                const Arc& prev = INVALID) const {
kpeter@472
  2427
      Arc arc = _graph->findEdge(u, v, prev);
kpeter@472
  2428
      while (arc != INVALID && source(arc) != u) {
deba@432
  2429
        arc = _graph->findEdge(u, v, arc);
deba@430
  2430
      }
deba@432
  2431
      return arc;
deba@432
  2432
    }
deba@432
  2433
deba@432
  2434
    Node addNode() {
deba@432
  2435
      return Node(_graph->addNode());
deba@432
  2436
    }
deba@432
  2437
deba@432
  2438
    Arc addArc(const Node& u, const Node& v) {
kpeter@472
  2439
      Arc arc = _graph->addEdge(u, v);
kpeter@472
  2440
      _direction->set(arc, _graph->u(arc) == u);
deba@432
  2441
      return arc;
deba@432
  2442
    }
deba@432
  2443
deba@432
  2444
    void erase(const Node& i) { _graph->erase(i); }
deba@432
  2445
    void erase(const Arc& i) { _graph->erase(i); }
deba@432
  2446
deba@432
  2447
    void clear() { _graph->clear(); }
deba@432
  2448
deba@432
  2449
    int id(const Node& v) const { return _graph->id(v); }
deba@432
  2450
    int id(const Arc& e) const { return _graph->id(e); }
deba@432
  2451
deba@432
  2452
    Node nodeFromId(int idx) const { return _graph->nodeFromId(idx); }
deba@432
  2453
    Arc arcFromId(int idx) const { return _graph->edgeFromId(idx); }
deba@432
  2454
deba@432
  2455
    int maxNodeId() const { return _graph->maxNodeId(); }
deba@432
  2456
    int maxArcId() const { return _graph->maxEdgeId(); }
deba@432
  2457
deba@559
  2458
    typedef typename ItemSetTraits<GR, Node>::ItemNotifier NodeNotifier;
deba@432
  2459
    NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
deba@432
  2460
deba@559
  2461
    typedef typename ItemSetTraits<GR, Arc>::ItemNotifier ArcNotifier;
deba@432
  2462
    ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
deba@432
  2463
deba@559
  2464
    template <typename V>
deba@559
  2465
    class NodeMap : public GR::template NodeMap<V> {
kpeter@664
  2466
      typedef typename GR::template NodeMap<V> Parent;
kpeter@664
  2467
deba@432
  2468
    public:
deba@432
  2469
deba@559
  2470
      explicit NodeMap(const OrienterBase<GR, DM>& adapter)
deba@432
  2471
        : Parent(*adapter._graph) {}
deba@432
  2472
deba@559
  2473
      NodeMap(const OrienterBase<GR, DM>& adapter, const V& value)
deba@432
  2474
        : Parent(*adapter._graph, value) {}
deba@432
  2475
deba@432
  2476
    private:
deba@432
  2477
      NodeMap& operator=(const NodeMap& cmap) {
deba@432
  2478
        return operator=<NodeMap>(cmap);
deba@432
  2479
      }
deba@432
  2480
deba@432
  2481
      template <typename CMap>
deba@432
  2482
      NodeMap& operator=(const CMap& cmap) {
deba@432
  2483
        Parent::operator=(cmap);
deba@432
  2484
        return *this;
deba@432
  2485
      }
deba@430
  2486
deba@430
  2487
    };
deba@430
  2488
deba@559
  2489
    template <typename V>
deba@559
  2490
    class ArcMap : public GR::template EdgeMap<V> {
kpeter@664
  2491
      typedef typename Graph::template EdgeMap<V> Parent;
kpeter@664
  2492
deba@432
  2493
    public:
deba@432
  2494
deba@559
  2495
      explicit ArcMap(const OrienterBase<GR, DM>& adapter)
deba@432
  2496
        : Parent(*adapter._graph) { }
deba@432
  2497
deba@559
  2498
      ArcMap(const OrienterBase<GR, DM>& adapter, const V& value)
deba@432
  2499
        : Parent(*adapter._graph, value) { }
deba@432
  2500
deba@432
  2501
    private:
deba@432
  2502
      ArcMap& operator=(const ArcMap& cmap) {
deba@432
  2503
        return operator=<ArcMap>(cmap);
deba@432
  2504
      }
deba@432
  2505
deba@432
  2506
      template <typename CMap>
deba@432
  2507
      ArcMap& operator=(const CMap& cmap) {
deba@432
  2508
        Parent::operator=(cmap);
deba@432
  2509
        return *this;
deba@432
  2510
      }
deba@432
  2511
    };
deba@432
  2512
deba@432
  2513
deba@432
  2514
deba@432
  2515
  protected:
deba@432
  2516
    Graph* _graph;
deba@559
  2517
    DM* _direction;
deba@559
  2518
deba@559
  2519
    void initialize(GR& graph, DM& direction) {
deba@559
  2520
      _graph = &graph;
deba@432
  2521
      _direction = &direction;
deba@432
  2522
    }
deba@432
  2523
deba@430
  2524
  };
deba@430
  2525
deba@432
  2526
  /// \ingroup graph_adaptors
deba@430
  2527
  ///
kpeter@474
  2528
  /// \brief Adaptor class for orienting the edges of a graph to get a digraph
deba@432
  2529
  ///
kpeter@474
  2530
  /// Orienter adaptor can be used for orienting the edges of a graph to
kpeter@474
  2531
  /// get a digraph. A \c bool edge map of the underlying graph must be
kpeter@474
  2532
  /// specified, which define the direction of the arcs in the adaptor.
kpeter@474
  2533
  /// The arcs can be easily reversed by the \c reverseArc() member function
kpeter@474
  2534
  /// of the adaptor.
kpeter@474
  2535
  /// This class conforms to the \ref concepts::Digraph "Digraph" concept.
deba@432
  2536
  ///
kpeter@474
  2537
  /// The adapted graph can also be modified through this adaptor
kpeter@476
  2538
  /// by adding or removing nodes or arcs, unless the \c GR template
kpeter@474
  2539
  /// parameter is set to be \c const.
deba@432
  2540
  ///
kpeter@476
  2541
  /// \tparam GR The type of the adapted graph.
kpeter@474
  2542
  /// It must conform to the \ref concepts::Graph "Graph" concept.
kpeter@474
  2543
  /// It can also be specified to be \c const.
kpeter@476
  2544
  /// \tparam DM The type of the direction map.
kpeter@476
  2545
  /// It must be a \c bool (or convertible) edge map of the
kpeter@476
  2546
  /// adapted graph. The default type is
kpeter@476
  2547
  /// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>".
kpeter@474
  2548
  ///
kpeter@474
  2549
  /// \note The \c Node type of this adaptor and the adapted graph are
kpeter@474
  2550
  /// convertible to each other, moreover the \c Arc type of the adaptor
kpeter@474
  2551
  /// and the \c Edge type of the adapted graph are also convertible to
kpeter@474
  2552
  /// each other.
kpeter@474
  2553
#ifdef DOXYGEN
kpeter@476
  2554
  template<typename GR,
kpeter@476
  2555
           typename DM>
kpeter@476
  2556
  class Orienter {
kpeter@474
  2557
#else
kpeter@476
  2558
  template<typename GR,
kpeter@476
  2559
           typename DM = typename GR::template EdgeMap<bool> >
kpeter@476
  2560
  class Orienter :
kpeter@476
  2561
    public DigraphAdaptorExtender<OrienterBase<GR, DM> > {
kpeter@474
  2562
#endif
kpeter@664
  2563
    typedef DigraphAdaptorExtender<OrienterBase<GR, DM> > Parent;
deba@432
  2564
  public:
kpeter@474
  2565
kpeter@474
  2566
    /// The type of the adapted graph.
kpeter@476
  2567
    typedef GR Graph;
kpeter@474
  2568
    /// The type of the direction edge map.
kpeter@476
  2569
    typedef DM DirectionMap;
kpeter@476
  2570
deba@432
  2571
    typedef typename Parent::Arc Arc;
kpeter@664
  2572
deba@432
  2573
  protected:
deba@432
  2574
    Orienter() { }
kpeter@664
  2575
deba@432
  2576
  public:
deba@432
  2577
kpeter@474
  2578
    /// \brief Constructor
deba@432
  2579
    ///
kpeter@474
  2580
    /// Constructor of the adaptor.
deba@559
  2581
    Orienter(GR& graph, DM& direction) {
deba@559
  2582
      Parent::initialize(graph, direction);
deba@432
  2583
    }
deba@432
  2584
kpeter@474
  2585
    /// \brief Reverses the given arc
deba@432
  2586
    ///
kpeter@474
  2587
    /// This function reverses the given arc.
kpeter@474
  2588
    /// It is done by simply negate the assigned value of \c a
kpeter@474
  2589
    /// in the direction map.
deba@432
  2590
    void reverseArc(const Arc& a) {
deba@432
  2591
      Parent::reverseArc(a);
deba@432
  2592
    }
deba@432
  2593
  };
deba@432
  2594
kpeter@474
  2595
  /// \brief Returns a read-only Orienter adaptor
deba@432
  2596
  ///
kpeter@474
  2597
  /// This function just returns a read-only \ref Orienter adaptor.
kpeter@474
  2598
  /// \ingroup graph_adaptors
kpeter@474
  2599
  /// \relates Orienter
kpeter@476
  2600
  template<typename GR, typename DM>
kpeter@476
  2601
  Orienter<const GR, DM>
deba@559
  2602
  orienter(const GR& graph, DM& direction) {
deba@559
  2603
    return Orienter<const GR, DM>(graph, direction);
deba@430
  2604
  }
deba@430
  2605
kpeter@476
  2606
  template<typename GR, typename DM>
kpeter@476
  2607
  Orienter<const GR, const DM>
deba@559
  2608
  orienter(const GR& graph, const DM& direction) {
deba@559
  2609
    return Orienter<const GR, const DM>(graph, direction);
deba@432
  2610
  }
deba@432
  2611
deba@432
  2612
  namespace _adaptor_bits {
deba@432
  2613
deba@559
  2614
    template <typename DGR, typename CM, typename FM, typename TL>
deba@432
  2615
    class ResForwardFilter {
deba@432
  2616
    public:
deba@432
  2617
deba@559
  2618
      typedef typename DGR::Arc Key;
deba@432
  2619
      typedef bool Value;
deba@432
  2620
deba@432
  2621
    private:
deba@432
  2622
deba@559
  2623
      const CM* _capacity;
deba@559
  2624
      const FM* _flow;
deba@559
  2625
      TL _tolerance;
deba@559
  2626
deba@432
  2627
    public:
deba@432
  2628
deba@559
  2629
      ResForwardFilter(const CM& capacity, const FM& flow,
deba@559
  2630
                       const TL& tolerance = TL())
deba@432
  2631
        : _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
deba@432
  2632
deba@559
  2633
      bool operator[](const typename DGR::Arc& a) const {
deba@432
  2634
        return _tolerance.positive((*_capacity)[a] - (*_flow)[a]);
deba@432
  2635
      }
deba@432
  2636
    };
deba@432
  2637
deba@559
  2638
    template<typename DGR,typename CM, typename FM, typename TL>
deba@432
  2639
    class ResBackwardFilter {
deba@432
  2640
    public:
deba@432
  2641
deba@559
  2642
      typedef typename DGR::Arc Key;
deba@432
  2643
      typedef bool Value;
deba@432
  2644
deba@432
  2645
    private:
deba@432
  2646
deba@559
  2647
      const CM* _capacity;
deba@559
  2648
      const FM* _flow;
deba@559
  2649
      TL _tolerance;
deba@432
  2650
deba@432
  2651
    public:
deba@432
  2652
deba@559
  2653
      ResBackwardFilter(const CM& capacity, const FM& flow,
deba@559
  2654
                        const TL& tolerance = TL())
deba@432
  2655
        : _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
deba@432
  2656
deba@559
  2657
      bool operator[](const typename DGR::Arc& a) const {
deba@432
  2658
        return _tolerance.positive((*_flow)[a]);
deba@432
  2659
      }
deba@432
  2660
    };
deba@432
  2661
deba@432
  2662
  }
deba@432
  2663
deba@432
  2664
  /// \ingroup graph_adaptors
deba@432
  2665
  ///
kpeter@474
  2666
  /// \brief Adaptor class for composing the residual digraph for directed
deba@432
  2667
  /// flow and circulation problems.
deba@432
  2668
  ///
kpeter@487
  2669
  /// ResidualDigraph can be used for composing the \e residual digraph
kpeter@487
  2670
  /// for directed flow and circulation problems. Let \f$ G=(V, A) \f$
kpeter@487
  2671
  /// be a directed graph and let \f$ F \f$ be a number type.
kpeter@487
  2672
  /// Let \f$ flow, cap: A\to F \f$ be functions on the arcs.
kpeter@474
  2673
  /// This adaptor implements a digraph structure with node set \f$ V \f$
kpeter@474
  2674
  /// and arc set \f$ A_{forward}\cup A_{backward} \f$,
kpeter@474
  2675
  /// where \f$ A_{forward}=\{uv : uv\in A, flow(uv)<cap(uv)\} \f$ and
kpeter@474
  2676
  /// \f$ A_{backward}=\{vu : uv\in A, flow(uv)>0\} \f$, i.e. the so
kpeter@474
  2677
  /// called residual digraph.
kpeter@474
  2678
  /// When the union \f$ A_{forward}\cup A_{backward} \f$ is taken,
kpeter@474
  2679
  /// multiplicities are counted, i.e. the adaptor has exactly
kpeter@474
  2680
  /// \f$ |A_{forward}| + |A_{backward}|\f$ arcs (it may have parallel
kpeter@474
  2681
  /// arcs).
kpeter@474
  2682
  /// This class conforms to the \ref concepts::Digraph "Digraph" concept.
deba@432
  2683
  ///
deba@559
  2684
  /// \tparam DGR The type of the adapted digraph.
kpeter@474
  2685
  /// It must conform to the \ref concepts::Digraph "Digraph" concept.
kpeter@474
  2686
  /// It is implicitly \c const.
kpeter@476
  2687
  /// \tparam CM The type of the capacity map.
kpeter@476
  2688
  /// It must be an arc map of some numerical type, which defines
kpeter@474
  2689
  /// the capacities in the flow problem. It is implicitly \c const.
kpeter@476
  2690
  /// The default type is
kpeter@476
  2691
  /// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
kpeter@476
  2692
  /// \tparam FM The type of the flow map.
kpeter@476
  2693
  /// It must be an arc map of some numerical type, which defines
kpeter@476
  2694
  /// the flow values in the flow problem. The default type is \c CM.
kpeter@476
  2695
  /// \tparam TL The tolerance type for handling inexact computation.
kpeter@474
  2696
  /// The default tolerance type depends on the value type of the
kpeter@474
  2697
  /// capacity map.
deba@432
  2698
  ///
kpeter@474
  2699
  /// \note This adaptor is implemented using Undirector and FilterArcs
kpeter@474
  2700
  /// adaptors.
kpeter@474
  2701
  ///
kpeter@474
  2702
  /// \note The \c Node type of this adaptor and the adapted digraph are
kpeter@474
  2703
  /// convertible to each other, moreover the \c Arc type of the adaptor
kpeter@474
  2704
  /// is convertible to the \c Arc type of the adapted digraph.
kpeter@474
  2705
#ifdef DOXYGEN
deba@559
  2706
  template<typename DGR, typename CM, typename FM, typename TL>
kpeter@487
  2707
  class ResidualDigraph
kpeter@474
  2708
#else
deba@559
  2709
  template<typename DGR,
deba@559
  2710
           typename CM = typename DGR::template ArcMap<int>,
kpeter@476
  2711
           typename FM = CM,
kpeter@476
  2712
           typename TL = Tolerance<typename CM::Value> >
deba@559
  2713
  class ResidualDigraph 
deba@559
  2714
    : public SubDigraph<
deba@559
  2715
        Undirector<const DGR>,
deba@559
  2716
        ConstMap<typename DGR::Node, Const<bool, true> >,
deba@559
  2717
        typename Undirector<const DGR>::template CombinedArcMap<
deba@559
  2718
          _adaptor_bits::ResForwardFilter<const DGR, CM, FM, TL>,
deba@559
  2719
          _adaptor_bits::ResBackwardFilter<const DGR, CM, FM, TL> > >
kpeter@474
  2720
#endif
deba@432
  2721
  {
deba@430
  2722
  public:
deba@430
  2723
kpeter@474
  2724
    /// The type of the underlying digraph.
deba@559
  2725
    typedef DGR Digraph;
kpeter@474
  2726
    /// The type of the capacity map.
kpeter@476
  2727
    typedef CM CapacityMap;
kpeter@474
  2728
    /// The type of the flow map.
kpeter@476
  2729
    typedef FM FlowMap;
kpeter@476
  2730
    /// The tolerance type.
kpeter@476
  2731
    typedef TL Tolerance;
deba@430
  2732
deba@430
  2733
    typedef typename CapacityMap::Value Value;
kpeter@487
  2734
    typedef ResidualDigraph Adaptor;
deba@430
  2735
deba@430
  2736
  protected:
deba@430
  2737
deba@432
  2738
    typedef Undirector<const Digraph> Undirected;
deba@432
  2739
deba@559
  2740
    typedef ConstMap<typename DGR::Node, Const<bool, true> > NodeFilter;
deba@559
  2741
deba@559
  2742
    typedef _adaptor_bits::ResForwardFilter<const DGR, CM,
deba@559
  2743
                                            FM, TL> ForwardFilter;
deba@559
  2744
deba@559
  2745
    typedef _adaptor_bits::ResBackwardFilter<const DGR, CM,
deba@559
  2746
                                             FM, TL> BackwardFilter;
deba@432
  2747
deba@432
  2748
    typedef typename Undirected::
kpeter@476
  2749
      template CombinedArcMap<ForwardFilter, BackwardFilter> ArcFilter;
deba@430
  2750
deba@559
  2751
    typedef SubDigraph<Undirected, NodeFilter, ArcFilter> Parent;
deba@430
  2752
deba@430
  2753
    const CapacityMap* _capacity;
deba@430
  2754
    FlowMap* _flow;
deba@430
  2755
deba@432
  2756
    Undirected _graph;
deba@559
  2757
    NodeFilter _node_filter;
deba@430
  2758
    ForwardFilter _forward_filter;
deba@430
  2759
    BackwardFilter _backward_filter;
deba@430
  2760
    ArcFilter _arc_filter;
deba@430
  2761
deba@430
  2762
  public:
deba@430
  2763
kpeter@474
  2764
    /// \brief Constructor
deba@430
  2765
    ///
kpeter@474
  2766
    /// Constructor of the residual digraph adaptor. The parameters are the
kpeter@474
  2767
    /// digraph, the capacity map, the flow map, and a tolerance object.
deba@559
  2768
    ResidualDigraph(const DGR& digraph, const CM& capacity,
deba@559
  2769
                    FM& flow, const TL& tolerance = Tolerance())
deba@559
  2770
      : Parent(), _capacity(&capacity), _flow(&flow), 
deba@559
  2771
        _graph(digraph), _node_filter(),
deba@432
  2772
        _forward_filter(capacity, flow, tolerance),
deba@430
  2773
        _backward_filter(capacity, flow, tolerance),
deba@430
  2774
        _arc_filter(_forward_filter, _backward_filter)
deba@430
  2775
    {
deba@559
  2776
      Parent::initialize(_graph, _node_filter, _arc_filter);
deba@430
  2777
    }
deba@430
  2778
deba@430
  2779
    typedef typename Parent::Arc Arc;
deba@430
  2780
kpeter@474
  2781
    /// \brief Returns the residual capacity of the given arc.
deba@430
  2782
    ///
kpeter@474
  2783
    /// Returns the residual capacity of the given arc.
deba@432
  2784
    Value residualCapacity(const Arc& a) const {
deba@432
  2785
      if (Undirected::direction(a)) {
deba@432
  2786
        return (*_capacity)[a] - (*_flow)[a];
deba@430
  2787
      } else {
deba@432
  2788
        return (*_flow)[a];
deba@430
  2789
      }
deba@432
  2790
    }
deba@432
  2791
kpeter@475
  2792
    /// \brief Augments on the given arc in the residual digraph.
deba@430
  2793
    ///
kpeter@475
  2794
    /// Augments on the given arc in the residual digraph. It increases
kpeter@474
  2795
    /// or decreases the flow value on the original arc according to the
kpeter@474
  2796
    /// direction of the residual arc.
deba@432
  2797
    void augment(const Arc& a, const Value& v) const {
deba@432
  2798
      if (Undirected::direction(a)) {
deba@432
  2799
        _flow->set(a, (*_flow)[a] + v);
deba@432
  2800
      } else {
deba@432
  2801
        _flow->set(a, (*_flow)[a] - v);
deba@430
  2802
      }
deba@430
  2803
    }
deba@430
  2804
kpeter@474
  2805
    /// \brief Returns \c true if the given residual arc is a forward arc.
deba@430
  2806
    ///
kpeter@474
  2807
    /// Returns \c true if the given residual arc has the same orientation
kpeter@474
  2808
    /// as the original arc, i.e. it is a so called forward arc.
deba@432
  2809
    static bool forward(const Arc& a) {
deba@432
  2810
      return Undirected::direction(a);
deba@430
  2811
    }
deba@430
  2812
kpeter@474
  2813
    /// \brief Returns \c true if the given residual arc is a backward arc.
deba@430
  2814
    ///
kpeter@474
  2815
    /// Returns \c true if the given residual arc has the opposite orientation
kpeter@474
  2816
    /// than the original arc, i.e. it is a so called backward arc.
deba@432
  2817
    static bool backward(const Arc& a) {
deba@432
  2818
      return !Undirected::direction(a);
deba@430
  2819
    }
deba@430
  2820
kpeter@474
  2821
    /// \brief Returns the forward oriented residual arc.
deba@430
  2822
    ///
kpeter@474
  2823
    /// Returns the forward oriented residual arc related to the given
kpeter@474
  2824
    /// arc of the underlying digraph.
deba@432
  2825
    static Arc forward(const typename Digraph::Arc& a) {
deba@432
  2826
      return Undirected::direct(a, true);
deba@430
  2827
    }
deba@430
  2828
kpeter@474
  2829
    /// \brief Returns the backward oriented residual arc.
deba@430
  2830
    ///
kpeter@474
  2831
    /// Returns the backward oriented residual arc related to the given
kpeter@474
  2832
    /// arc of the underlying digraph.
deba@432
  2833
    static Arc backward(const typename Digraph::Arc& a) {
deba@432
  2834
      return Undirected::direct(a, false);
deba@430
  2835
    }
deba@430
  2836
deba@430
  2837
    /// \brief Residual capacity map.
deba@430
  2838
    ///
kpeter@474
  2839
    /// This map adaptor class can be used for obtaining the residual
kpeter@474
  2840
    /// capacities as an arc map of the residual digraph.
kpeter@474
  2841
    /// Its value type is inherited from the capacity map.
deba@432
  2842
    class ResidualCapacity {
deba@430
  2843
    protected:
deba@430
  2844
      const Adaptor* _adaptor;
deba@430
  2845
    public:
kpeter@474
  2846
      /// The key type of the map
deba@430
  2847
      typedef Arc Key;
kpeter@474
  2848
      /// The value type of the map
kpeter@476
  2849
      typedef typename CapacityMap::Value Value;
deba@430
  2850
deba@432
  2851
      /// Constructor
deba@559
  2852
      ResidualCapacity(const ResidualDigraph<DGR, CM, FM, TL>& adaptor) 
deba@559
  2853
        : _adaptor(&adaptor) {}
deba@432
  2854
kpeter@474
  2855
      /// Returns the value associated with the given residual arc
deba@432
  2856
      Value operator[](const Arc& a) const {
deba@432
  2857
        return _adaptor->residualCapacity(a);
deba@430
  2858
      }
deba@432
  2859
deba@430
  2860
    };
deba@430
  2861
kpeter@473
  2862
    /// \brief Returns a residual capacity map
kpeter@473
  2863
    ///
kpeter@473
  2864
    /// This function just returns a residual capacity map.
kpeter@473
  2865
    ResidualCapacity residualCapacity() const {
kpeter@473
  2866
      return ResidualCapacity(*this);
kpeter@473
  2867
    }
kpeter@473
  2868
deba@430
  2869
  };
deba@430
  2870
kpeter@473
  2871
  /// \brief Returns a (read-only) Residual adaptor
kpeter@473
  2872
  ///
deba@559
  2873
  /// This function just returns a (read-only) \ref ResidualDigraph adaptor.
kpeter@473
  2874
  /// \ingroup graph_adaptors
deba@559
  2875
  /// \relates ResidualDigraph
deba@559
  2876
    template<typename DGR, typename CM, typename FM>
deba@559
  2877
  ResidualDigraph<DGR, CM, FM>
deba@559
  2878
  residualDigraph(const DGR& digraph, const CM& capacity_map, FM& flow_map) {
deba@559
  2879
    return ResidualDigraph<DGR, CM, FM> (digraph, capacity_map, flow_map);
kpeter@473
  2880
  }
kpeter@473
  2881
kpeter@473
  2882
deba@559
  2883
  template <typename DGR>
deba@432
  2884
  class SplitNodesBase {
kpeter@664
  2885
    typedef DigraphAdaptorBase<const DGR> Parent;
kpeter@664
  2886
deba@430
  2887
  public:
deba@430
  2888
deba@559
  2889
    typedef DGR Digraph;
deba@432
  2890
    typedef SplitNodesBase Adaptor;
deba@430
  2891
deba@559
  2892
    typedef typename DGR::Node DigraphNode;
deba@559
  2893
    typedef typename DGR::Arc DigraphArc;
deba@430
  2894
deba@430
  2895
    class Node;
deba@430
  2896
    class Arc;
deba@430
  2897
deba@430
  2898
  private:
deba@430
  2899
deba@430
  2900
    template <typename T> class NodeMapBase;
deba@430
  2901
    template <typename T> class ArcMapBase;
deba@430
  2902
deba@430
  2903
  public:
deba@432
  2904
deba@430
  2905
    class Node : public DigraphNode {
deba@432
  2906
      friend class SplitNodesBase;
deba@430
  2907
      template <typename T> friend class NodeMapBase;
deba@430
  2908
    private:
deba@430
  2909
deba@430
  2910
      bool _in;
deba@430
  2911
      Node(DigraphNode node, bool in)
deba@432
  2912
        : DigraphNode(node), _in(in) {}
deba@432
  2913
deba@430
  2914
    public:
deba@430
  2915
deba@430
  2916
      Node() {}
deba@430
  2917
      Node(Invalid) : DigraphNode(INVALID), _in(true) {}
deba@430
  2918
deba@430
  2919
      bool operator==(const Node& node) const {
deba@432
  2920
        return DigraphNode::operator==(node) && _in == node._in;
deba@430
  2921
      }
deba@432
  2922
deba@430
  2923
      bool operator!=(const Node& node) const {
deba@432
  2924
        return !(*this == node);
deba@430
  2925
      }
deba@432
  2926
deba@430
  2927
      bool operator<(const Node& node) const {
deba@432
  2928
        return DigraphNode::operator<(node) ||
deba@432
  2929
          (DigraphNode::operator==(node) && _in < node._in);
deba@430
  2930
      }
deba@430
  2931
    };
deba@430
  2932
deba@430
  2933
    class Arc {
deba@432
  2934
      friend class SplitNodesBase;
deba@430
  2935
      template <typename T> friend class ArcMapBase;
deba@430
  2936
    private:
deba@430
  2937
      typedef BiVariant<DigraphArc, DigraphNode> ArcImpl;
deba@430
  2938
deba@430
  2939
      explicit Arc(const DigraphArc& arc) : _item(arc) {}
deba@430
  2940
      explicit Arc(const DigraphNode& node) : _item(node) {}
deba@432
  2941
deba@430
  2942
      ArcImpl _item;
deba@430
  2943
deba@430
  2944
    public:
deba@430
  2945
      Arc() {}
deba@430
  2946
      Arc(Invalid) : _item(DigraphArc(INVALID)) {}
deba@430
  2947
deba@430
  2948
      bool operator==(const Arc& arc) const {
deba@430
  2949
        if (_item.firstState()) {
deba@430
  2950
          if (arc._item.firstState()) {
deba@430
  2951
            return _item.first() == arc._item.first();
deba@430
  2952
          }
deba@430
  2953
        } else {
deba@430
  2954
          if (arc._item.secondState()) {
deba@430
  2955
            return _item.second() == arc._item.second();
deba@430
  2956
          }
deba@430
  2957
        }
deba@430
  2958
        return false;
deba@430
  2959
      }
deba@432
  2960
deba@430
  2961
      bool operator!=(const Arc& arc) const {
deba@432
  2962
        return !(*this == arc);
deba@430
  2963
      }
deba@432
  2964
deba@430
  2965
      bool operator<(const Arc& arc) const {
deba@430
  2966
        if (_item.firstState()) {
deba@430
  2967
          if (arc._item.firstState()) {
deba@430
  2968
            return _item.first() < arc._item.first();
deba@430
  2969
          }
deba@430
  2970
          return false;
deba@430
  2971
        } else {
deba@430
  2972
          if (arc._item.secondState()) {
deba@430
  2973
            return _item.second() < arc._item.second();
deba@430
  2974
          }
deba@430
  2975
          return true;
deba@430
  2976
        }
deba@430
  2977
      }
deba@430
  2978
deba@430
  2979
      operator DigraphArc() const { return _item.first(); }
deba@430
  2980
      operator DigraphNode() const { return _item.second(); }
deba@430
  2981
deba@430
  2982
    };
deba@430
  2983
deba@430
  2984
    void first(Node& n) const {
deba@430
  2985
      _digraph->first(n);
deba@430
  2986
      n._in = true;
deba@430
  2987
    }
deba@430
  2988
deba@430
  2989
    void next(Node& n) const {
deba@430
  2990
      if (n._in) {
deba@432
  2991
        n._in = false;
deba@430
  2992
      } else {
deba@432
  2993
        n._in = true;
deba@432
  2994
        _digraph->next(n);
deba@430
  2995
      }
deba@430
  2996
    }
deba@430
  2997
deba@430
  2998
    void first(Arc& e) const {
deba@430
  2999
      e._item.setSecond();
deba@430
  3000
      _digraph->first(e._item.second());
deba@430
  3001
      if (e._item.second() == INVALID) {
deba@430
  3002
        e._item.setFirst();
deba@432
  3003
        _digraph->first(e._item.first());
deba@430
  3004
      }
deba@430
  3005
    }
deba@430
  3006
deba@430
  3007
    void next(Arc& e) const {
deba@430
  3008
      if (e._item.secondState()) {
deba@432
  3009
        _digraph->next(e._item.second());
deba@430
  3010
        if (e._item.second() == INVALID) {
deba@430
  3011
          e._item.setFirst();
deba@430
  3012
          _digraph->first(e._item.first());
deba@430
  3013
        }
deba@430
  3014
      } else {
deba@432
  3015
        _digraph->next(e._item.first());
deba@432
  3016
      }
deba@430
  3017
    }
deba@430
  3018
deba@430
  3019
    void firstOut(Arc& e, const Node& n) const {
deba@430
  3020
      if (n._in) {
deba@430
  3021
        e._item.setSecond(n);
deba@430
  3022
      } else {
deba@430
  3023
        e._item.setFirst();
deba@432
  3024
        _digraph->firstOut(e._item.first(), n);
deba@430
  3025
      }
deba@430
  3026
    }
deba@430
  3027
deba@430
  3028
    void nextOut(Arc& e) const {
deba@430
  3029
      if (!e._item.firstState()) {
deba@432
  3030
        e._item.setFirst(INVALID);
deba@430
  3031
      } else {
deba@432
  3032
        _digraph->nextOut(e._item.first());
deba@432
  3033
      }
deba@430
  3034
    }
deba@430
  3035
deba@430
  3036
    void firstIn(Arc& e, const Node& n) const {
deba@430
  3037
      if (!n._in) {
deba@432
  3038
        e._item.setSecond(n);
deba@430
  3039
      } else {
deba@430
  3040
        e._item.setFirst();
deba@432
  3041
        _digraph->firstIn(e._item.first(), n);
deba@430
  3042
      }
deba@430
  3043
    }
deba@430
  3044
deba@430
  3045
    void nextIn(Arc& e) const {
deba@430
  3046
      if (!e._item.firstState()) {
deba@432
  3047
        e._item.setFirst(INVALID);
deba@430
  3048
      } else {
deba@432
  3049
        _digraph->nextIn(e._item.first());
deba@430
  3050
      }
deba@430
  3051
    }
deba@430
  3052
deba@430
  3053
    Node source(const Arc& e) const {
deba@430
  3054
      if (e._item.firstState()) {
deba@432
  3055
        return Node(_digraph->source(e._item.first()), false);
deba@430
  3056
      } else {
deba@432
  3057
        return Node(e._item.second(), true);
deba@430
  3058
      }
deba@430
  3059
    }
deba@430
  3060
deba@430
  3061
    Node target(const Arc& e) const {
deba@430
  3062
      if (e._item.firstState()) {
deba@432
  3063
        return Node(_digraph->target(e._item.first()), true);
deba@430
  3064
      } else {
deba@432
  3065
        return Node(e._item.second(), false);
deba@430
  3066
      }
deba@430
  3067
    }
deba@430
  3068
deba@430
  3069
    int id(const Node& n) const {
deba@430
  3070
      return (_digraph->id(n) << 1) | (n._in ? 0 : 1);
deba@430
  3071
    }
deba@430
  3072
    Node nodeFromId(int ix) const {
deba@430
  3073
      return Node(_digraph->nodeFromId(ix >> 1), (ix & 1) == 0);
deba@430
  3074
    }
deba@430
  3075
    int maxNodeId() const {
deba@430
  3076
      return 2 * _digraph->maxNodeId() + 1;
deba@430
  3077
    }
deba@430
  3078
deba@430
  3079
    int id(const Arc& e) const {
deba@430
  3080
      if (e._item.firstState()) {
deba@430
  3081
        return _digraph->id(e._item.first()) << 1;
deba@430
  3082
      } else {
deba@430
  3083
        return (_digraph->id(e._item.second()) << 1) | 1;
deba@430
  3084
      }
deba@430
  3085
    }
deba@430
  3086
    Arc arcFromId(int ix) const {
deba@430
  3087
      if ((ix & 1) == 0) {
deba@430
  3088
        return Arc(_digraph->arcFromId(ix >> 1));
deba@430
  3089
      } else {
deba@430
  3090
        return Arc(_digraph->nodeFromId(ix >> 1));
deba@430
  3091
      }
deba@430
  3092
    }
deba@430
  3093
    int maxArcId() const {
deba@432
  3094
      return std::max(_digraph->maxNodeId() << 1,
deba@430
  3095
                      (_digraph->maxArcId() << 1) | 1);
deba@430
  3096
    }
deba@430
  3097
deba@430
  3098
    static bool inNode(const Node& n) {
deba@430
  3099
      return n._in;
deba@430
  3100
    }
deba@430
  3101
deba@430
  3102
    static bool outNode(const Node& n) {
deba@430
  3103
      return !n._in;
deba@430
  3104
    }
deba@430
  3105
deba@430
  3106
    static bool origArc(const Arc& e) {
deba@430
  3107
      return e._item.firstState();
deba@430
  3108
    }
deba@430
  3109
deba@430
  3110
    static bool bindArc(const Arc& e) {
deba@430
  3111
      return e._item.secondState();
deba@430
  3112
    }
deba@430
  3113
deba@430
  3114
    static Node inNode(const DigraphNode& n) {
deba@430
  3115
      return Node(n, true);
deba@430
  3116
    }
deba@430
  3117
deba@430
  3118
    static Node outNode(const DigraphNode& n) {
deba@430
  3119
      return Node(n, false);
deba@430
  3120
    }
deba@430
  3121
deba@430
  3122
    static Arc arc(const DigraphNode& n) {
deba@430
  3123
      return Arc(n);
deba@430
  3124
    }
deba@430
  3125
deba@430
  3126
    static Arc arc(const DigraphArc& e) {
deba@430
  3127
      return Arc(e);
deba@430
  3128
    }
deba@430
  3129
deba@430
  3130
    typedef True NodeNumTag;
deba@430
  3131
    int nodeNum() const {
deba@430
  3132
      return  2 * countNodes(*_digraph);
deba@430
  3133
    }
deba@430
  3134
kpeter@469
  3135
    typedef True ArcNumTag;
deba@430
  3136
    int arcNum() const {
deba@430
  3137
      return countArcs(*_digraph) + countNodes(*_digraph);
deba@430
  3138
    }
deba@430
  3139
kpeter@469
  3140
    typedef True FindArcTag;
deba@432
  3141
    Arc findArc(const Node& u, const Node& v,
deba@432
  3142
                const Arc& prev = INVALID) const {
kpeter@472
  3143
      if (inNode(u) && outNode(v)) {
kpeter@472
  3144
        if (static_cast<const DigraphNode&>(u) ==
kpeter@472
  3145
            static_cast<const DigraphNode&>(v) && prev == INVALID) {
kpeter@472
  3146
          return Arc(u);
deba@430
  3147
        }
kpeter@472
  3148
      }
kpeter@472
  3149
      else if (outNode(u) && inNode(v)) {
kpeter@472
  3150
        return Arc(::lemon::findArc(*_digraph, u, v, prev));
deba@430
  3151
      }
deba@430
  3152
      return INVALID;
deba@430
  3153
    }
deba@430
  3154
deba@430
  3155
  private:
deba@432
  3156
deba@559
  3157
    template <typename V>
deba@432
  3158
    class NodeMapBase
deba@559
  3159
      : public MapTraits<typename Parent::template NodeMap<V> > {
deba@559
  3160
      typedef typename Parent::template NodeMap<V> NodeImpl;
deba@430
  3161
    public:
deba@430
  3162
      typedef Node Key;
deba@559
  3163
      typedef V Value;
kpeter@472
  3164
      typedef typename MapTraits<NodeImpl>::ReferenceMapTag ReferenceMapTag;
kpeter@472
  3165
      typedef typename MapTraits<NodeImpl>::ReturnValue ReturnValue;
kpeter@472
  3166
      typedef typename MapTraits<NodeImpl>::ConstReturnValue ConstReturnValue;
kpeter@472
  3167
      typedef typename MapTraits<NodeImpl>::ReturnValue Reference;
kpeter@472
  3168
      typedef typename MapTraits<NodeImpl>::ConstReturnValue ConstReference;
deba@432
  3169
deba@559
  3170
      NodeMapBase(const SplitNodesBase<DGR>& adaptor)
deba@432
  3171
        : _in_map(*adaptor._digraph), _out_map(*adaptor._digraph) {}
deba@559
  3172
      NodeMapBase(const SplitNodesBase<DGR>& adaptor, const V& value)
deba@432
  3173
        : _in_map(*adaptor._digraph, value),
deba@432
  3174
          _out_map(*adaptor._digraph, value) {}
deba@430
  3175
deba@559
  3176
      void set(const Node& key, const V& val) {
deba@559
  3177
        if (SplitNodesBase<DGR>::inNode(key)) { _in_map.set(key, val); }
deba@432
  3178
        else {_out_map.set(key, val); }
deba@430
  3179
      }
deba@432
  3180
kpeter@472
  3181
      ReturnValue operator[](const Node& key) {
deba@559
  3182
        if (SplitNodesBase<DGR>::inNode(key)) { return _in_map[key]; }
deba@432
  3183
        else { return _out_map[key]; }
deba@430
  3184
      }
deba@430
  3185
kpeter@472
  3186
      ConstReturnValue operator[](const Node& key) const {
deba@432
  3187
        if (Adaptor::inNode(key)) { return _in_map[key]; }
deba@432
  3188
        else { return _out_map[key]; }
deba@430
  3189
      }
deba@430
  3190
deba@430
  3191
    private:
deba@430
  3192
      NodeImpl _in_map, _out_map;
deba@430
  3193
    };
deba@430
  3194
deba@559
  3195
    template <typename V>
deba@432
  3196
    class ArcMapBase
deba@559
  3197
      : public MapTraits<typename Parent::template ArcMap<V> > {
deba@559
  3198
      typedef typename Parent::template ArcMap<V> ArcImpl;
deba@559
  3199
      typedef typename Parent::template NodeMap<V> NodeImpl;
deba@430
  3200
    public:
deba@430
  3201
      typedef Arc Key;
deba@559
  3202
      typedef V Value;
kpeter@472
  3203
      typedef typename MapTraits<ArcImpl>::ReferenceMapTag ReferenceMapTag;
kpeter@472
  3204
      typedef typename MapTraits<ArcImpl>::ReturnValue ReturnValue;
kpeter@472
  3205
      typedef typename MapTraits<ArcImpl>::ConstReturnValue ConstReturnValue;
kpeter@472
  3206
      typedef typename MapTraits<ArcImpl>::ReturnValue Reference;
kpeter@472
  3207
      typedef typename MapTraits<ArcImpl>::ConstReturnValue ConstReference;
deba@430
  3208
deba@559
  3209
      ArcMapBase(const SplitNodesBase<DGR>& adaptor)
deba@432
  3210
        : _arc_map(*adaptor._digraph), _node_map(*adaptor._digraph) {}
deba@559
  3211
      ArcMapBase(const SplitNodesBase<DGR>& adaptor, const V& value)
deba@432
  3212
        : _arc_map(*adaptor._digraph, value),
deba@432
  3213
          _node_map(*adaptor._digraph, value) {}
deba@430
  3214
deba@559
  3215
      void set(const Arc& key, const V& val) {
deba@559
  3216
        if (SplitNodesBase<DGR>::origArc(key)) {
kpeter@563
  3217
          _arc_map.set(static_cast<const DigraphArc&>(key), val);
deba@430
  3218
        } else {
kpeter@563
  3219
          _node_map.set(static_cast<const DigraphNode&>(key), val);
deba@430
  3220
        }
deba@430
  3221
      }
deba@432
  3222
kpeter@472
  3223
      ReturnValue operator[](const Arc& key) {
deba@559
  3224
        if (SplitNodesBase<DGR>::origArc(key)) {
kpeter@563
  3225
          return _arc_map[static_cast<const DigraphArc&>(key)];
deba@430
  3226
        } else {
kpeter@563
  3227
          return _node_map[static_cast<const DigraphNode&>(key)];
deba@430
  3228
        }
deba@430
  3229
      }
deba@430
  3230
kpeter@472
  3231
      ConstReturnValue operator[](const Arc& key) const {
deba@559
  3232
        if (SplitNodesBase<DGR>::origArc(key)) {
kpeter@563
  3233
          return _arc_map[static_cast<const DigraphArc&>(key)];
deba@430
  3234
        } else {
kpeter@563
  3235
          return _node_map[static_cast<const DigraphNode&>(key)];
deba@430
  3236
        }
deba@430
  3237
      }
deba@430
  3238
deba@430
  3239
    private:
deba@430
  3240
      ArcImpl _arc_map;
deba@430
  3241
      NodeImpl _node_map;
deba@430
  3242
    };
deba@430
  3243
deba@430
  3244
  public:
deba@430
  3245
deba@559
  3246
    template <typename V>
deba@432
  3247
    class NodeMap
kpeter@664
  3248
      : public SubMapExtender<SplitNodesBase<DGR>, NodeMapBase<V> > {
kpeter@664
  3249
      typedef SubMapExtender<SplitNodesBase<DGR>, NodeMapBase<V> > Parent;
kpeter@664
  3250
deba@430
  3251
    public:
deba@559
  3252
      typedef V Value;
deba@559
  3253
deba@559
  3254
      NodeMap(const SplitNodesBase<DGR>& adaptor)
deba@432
  3255
        : Parent(adaptor) {}
deba@432
  3256
deba@559
  3257
      NodeMap(const SplitNodesBase<DGR>& adaptor, const V& value)
deba@432
  3258
        : Parent(adaptor, value) {}
deba@432
  3259
deba@430
  3260
    private:
deba@430
  3261
      NodeMap& operator=(const NodeMap& cmap) {
deba@432
  3262
        return operator=<NodeMap>(cmap);
deba@430
  3263
      }
deba@432
  3264
deba@430
  3265
      template <typename CMap>
deba@430
  3266
      NodeMap& operator=(const CMap& cmap) {
deba@430
  3267
        Parent::operator=(cmap);
deba@432
  3268
        return *this;
deba@430
  3269
      }
deba@430
  3270
    };
deba@430
  3271
deba@559
  3272
    template <typename V>
deba@432
  3273
    class ArcMap
kpeter@664
  3274
      : public SubMapExtender<SplitNodesBase<DGR>, ArcMapBase<V> > {
kpeter@664
  3275
      typedef SubMapExtender<SplitNodesBase<DGR>, ArcMapBase<V> > Parent;
kpeter@664
  3276
deba@430
  3277
    public:
deba@559
  3278
      typedef V Value;
deba@559
  3279
deba@559
  3280
      ArcMap(const SplitNodesBase<DGR>& adaptor)
deba@432
  3281
        : Parent(adaptor) {}
deba@432
  3282
deba@559
  3283
      ArcMap(const SplitNodesBase<DGR>& adaptor, const V& value)
deba@432
  3284
        : Parent(adaptor, value) {}
deba@432
  3285
deba@430
  3286
    private:
deba@430
  3287
      ArcMap& operator=(const ArcMap& cmap) {
deba@432
  3288
        return operator=<ArcMap>(cmap);
deba@430
  3289
      }
deba@432
  3290
deba@430
  3291
      template <typename CMap>
deba@430
  3292
      ArcMap& operator=(const CMap& cmap) {
deba@430
  3293
        Parent::operator=(cmap);
deba@432
  3294
        return *this;
deba@430
  3295
      }
deba@430
  3296
    };
deba@430
  3297
deba@430
  3298
  protected:
deba@430
  3299
deba@432
  3300
    SplitNodesBase() : _digraph(0) {}
deba@430
  3301
deba@559
  3302
    DGR* _digraph;
deba@559
  3303
deba@559
  3304
    void initialize(Digraph& digraph) {
deba@430
  3305
      _digraph = &digraph;
deba@430
  3306
    }
deba@432
  3307
deba@430
  3308
  };
deba@430
  3309
deba@430
  3310
  /// \ingroup graph_adaptors
deba@430
  3311
  ///
kpeter@474
  3312
  /// \brief Adaptor class for splitting the nodes of a digraph.
deba@432
  3313
  ///
kpeter@474
  3314
  /// SplitNodes adaptor can be used for splitting each node into an
kpeter@474
  3315
  /// \e in-node and an \e out-node in a digraph. Formaly, the adaptor
kpeter@474
  3316
  /// replaces each node \f$ u \f$ in the digraph with two nodes,
kpeter@474
  3317
  /// namely node \f$ u_{in} \f$ and node \f$ u_{out} \f$.
kpeter@474
  3318
  /// If there is a \f$ (v, u) \f$ arc in the original digraph, then the
kpeter@474
  3319
  /// new target of the arc will be \f$ u_{in} \f$ and similarly the
kpeter@474
  3320
  /// source of each original \f$ (u, v) \f$ arc will be \f$ u_{out} \f$.
kpeter@474
  3321
  /// The adaptor adds an additional \e bind \e arc from \f$ u_{in} \f$
kpeter@474
  3322
  /// to \f$ u_{out} \f$ for each node \f$ u \f$ of the original digraph.
deba@430
  3323
  ///
kpeter@474
  3324
  /// The aim of this class is running an algorithm with respect to node
kpeter@474
  3325
  /// costs or capacities if the algorithm considers only arc costs or
kpeter@474
  3326
  /// capacities directly.
kpeter@474
  3327
  /// In this case you can use \c SplitNodes adaptor, and set the node
kpeter@474
  3328
  /// costs/capacities of the original digraph to the \e bind \e arcs
kpeter@474
  3329
  /// in the adaptor.
deba@430
  3330
  ///
deba@559
  3331
  /// \tparam DGR The type of the adapted digraph.
kpeter@474
  3332
  /// It must conform to the \ref concepts::Digraph "Digraph" concept.
kpeter@474
  3333
  /// It is implicitly \c const.
kpeter@474
  3334
  ///
kpeter@474
  3335
  /// \note The \c Node type of this adaptor is converible to the \c Node
kpeter@474
  3336
  /// type of the adapted digraph.
deba@559
  3337
  template <typename DGR>
kpeter@476
  3338
#ifdef DOXYGEN
kpeter@476
  3339
  class SplitNodes {
kpeter@476
  3340
#else
deba@432
  3341
  class SplitNodes
deba@559
  3342
    : public DigraphAdaptorExtender<SplitNodesBase<const DGR> > {
kpeter@476
  3343
#endif
kpeter@664
  3344
    typedef DigraphAdaptorExtender<SplitNodesBase<const DGR> > Parent;
kpeter@664
  3345
deba@430
  3346
  public:
deba@559
  3347
    typedef DGR Digraph;
deba@559
  3348
deba@559
  3349
    typedef typename DGR::Node DigraphNode;
deba@559
  3350
    typedef typename DGR::Arc DigraphArc;
deba@431
  3351
deba@430
  3352
    typedef typename Parent::Node Node;
deba@430
  3353
    typedef typename Parent::Arc Arc;
deba@430
  3354
kpeter@474
  3355
    /// \brief Constructor
deba@430
  3356
    ///
deba@430
  3357
    /// Constructor of the adaptor.
deba@559
  3358
    SplitNodes(const DGR& g) {
deba@559
  3359
      Parent::initialize(g);
deba@430
  3360
    }
deba@430
  3361
kpeter@474
  3362
    /// \brief Returns \c true if the given node is an in-node.
deba@431
  3363
    ///
kpeter@474
  3364
    /// Returns \c true if the given node is an in-node.
deba@431
  3365
    static bool inNode(const Node& n) {
deba@431
  3366
      return Parent::inNode(n);
deba@431
  3367
    }
deba@431
  3368
kpeter@474
  3369
    /// \brief Returns \c true if the given node is an out-node.
deba@431
  3370
    ///
kpeter@474
  3371
    /// Returns \c true if the given node is an out-node.
deba@431
  3372
    static bool outNode(const Node& n) {
deba@431
  3373
      return Parent::outNode(n);
deba@431
  3374
    }
deba@431
  3375
kpeter@474
  3376
    /// \brief Returns \c true if the given arc is an original arc.
deba@431
  3377
    ///
kpeter@474
  3378
    /// Returns \c true if the given arc is one of the arcs in the
kpeter@474
  3379
    /// original digraph.
deba@431
  3380
    static bool origArc(const Arc& a) {
deba@431
  3381
      return Parent::origArc(a);
deba@431
  3382
    }
deba@431
  3383
kpeter@474
  3384
    /// \brief Returns \c true if the given arc is a bind arc.
deba@431
  3385
    ///
kpeter@474
  3386
    /// Returns \c true if the given arc is a bind arc, i.e. it connects
kpeter@474
  3387
    /// an in-node and an out-node.
deba@431
  3388
    static bool bindArc(const Arc& a) {
deba@431
  3389
      return Parent::bindArc(a);
deba@431
  3390
    }
deba@431
  3391
kpeter@474
  3392
    /// \brief Returns the in-node created from the given original node.
deba@431
  3393
    ///
kpeter@474
  3394
    /// Returns the in-node created from the given original node.
deba@431
  3395
    static Node inNode(const DigraphNode& n) {
deba@431
  3396
      return Parent::inNode(n);
deba@431
  3397
    }
deba@431
  3398
kpeter@474
  3399
    /// \brief Returns the out-node created from the given original node.
deba@431
  3400
    ///
kpeter@474
  3401
    /// Returns the out-node created from the given original node.
deba@431
  3402
    static Node outNode(const DigraphNode& n) {
deba@431
  3403
      return Parent::outNode(n);
deba@431
  3404
    }
deba@431
  3405
kpeter@474
  3406
    /// \brief Returns the bind arc that corresponds to the given
kpeter@474
  3407
    /// original node.
deba@432
  3408
    ///
kpeter@474
  3409
    /// Returns the bind arc in the adaptor that corresponds to the given
kpeter@474
  3410
    /// original node, i.e. the arc connecting the in-node and out-node
kpeter@474
  3411
    /// of \c n.
deba@431
  3412
    static Arc arc(const DigraphNode& n) {
deba@431
  3413
      return Parent::arc(n);
deba@431
  3414
    }
deba@431
  3415
kpeter@474
  3416
    /// \brief Returns the arc that corresponds to the given original arc.
deba@432
  3417
    ///
kpeter@474
  3418
    /// Returns the arc in the adaptor that corresponds to the given
kpeter@474
  3419
    /// original arc.
deba@431
  3420
    static Arc arc(const DigraphArc& a) {
deba@431
  3421
      return Parent::arc(a);
deba@431
  3422
    }
deba@431
  3423
kpeter@474
  3424
    /// \brief Node map combined from two original node maps
deba@430
  3425
    ///
kpeter@474
  3426
    /// This map adaptor class adapts two node maps of the original digraph
kpeter@474
  3427
    /// to get a node map of the split digraph.
kpeter@606
  3428
    /// Its value type is inherited from the first node map type (\c IN).
kpeter@606
  3429
    /// \tparam IN The type of the node map for the in-nodes. 
kpeter@606
  3430
    /// \tparam OUT The type of the node map for the out-nodes.
kpeter@606
  3431
    template <typename IN, typename OUT>
deba@430
  3432
    class CombinedNodeMap {
deba@430
  3433
    public:
deba@430
  3434
kpeter@474
  3435
      /// The key type of the map
deba@430
  3436
      typedef Node Key;
kpeter@474
  3437
      /// The value type of the map
kpeter@606
  3438
      typedef typename IN::Value Value;
kpeter@606
  3439
kpeter@606
  3440
      typedef typename MapTraits<IN>::ReferenceMapTag ReferenceMapTag;
kpeter@606
  3441
      typedef typename MapTraits<IN>::ReturnValue ReturnValue;
kpeter@606
  3442
      typedef typename MapTraits<IN>::ConstReturnValue ConstReturnValue;
kpeter@606
  3443
      typedef typename MapTraits<IN>::ReturnValue Reference;
kpeter@606
  3444
      typedef typename MapTraits<IN>::ConstReturnValue ConstReference;
kpeter@472
  3445
kpeter@474
  3446
      /// Constructor
kpeter@606
  3447
      CombinedNodeMap(IN& in_map, OUT& out_map)
deba@432
  3448
        : _in_map(in_map), _out_map(out_map) {}
deba@430
  3449
kpeter@474
  3450
      /// Returns the value associated with the given key.
kpeter@474
  3451
      Value operator[](const Key& key) const {
deba@559
  3452
        if (SplitNodesBase<const DGR>::inNode(key)) {
kpeter@474
  3453
          return _in_map[key];
kpeter@474
  3454
        } else {
kpeter@474
  3455
          return _out_map[key];
kpeter@474
  3456
        }
kpeter@474
  3457
      }
kpeter@474
  3458
kpeter@474
  3459
      /// Returns a reference to the value associated with the given key.
deba@430
  3460
      Value& operator[](const Key& key) {
deba@559
  3461
        if (SplitNodesBase<const DGR>::inNode(key)) {
deba@432
  3462
          return _in_map[key];
deba@432
  3463
        } else {
deba@432
  3464
          return _out_map[key];
deba@432
  3465
        }
deba@430
  3466
      }
deba@430
  3467
kpeter@474
  3468
      /// Sets the value associated with the given key.
deba@430
  3469
      void set(const Key& key, const Value& value) {
deba@559
  3470
        if (SplitNodesBase<const DGR>::inNode(key)) {
deba@432
  3471
          _in_map.set(key, value);
deba@432
  3472
        } else {
deba@432
  3473
          _out_map.set(key, value);
deba@432
  3474
        }
deba@430
  3475
      }
deba@432
  3476
deba@430
  3477
    private:
deba@432
  3478
kpeter@606
  3479
      IN& _in_map;
kpeter@606
  3480
      OUT& _out_map;
deba@432
  3481
deba@430
  3482
    };
deba@430
  3483
deba@430
  3484
kpeter@474
  3485
    /// \brief Returns a combined node map
deba@432
  3486
    ///
kpeter@474
  3487
    /// This function just returns a combined node map.
kpeter@606
  3488
    template <typename IN, typename OUT>
kpeter@606
  3489
    static CombinedNodeMap<IN, OUT>
kpeter@606
  3490
    combinedNodeMap(IN& in_map, OUT& out_map) {
kpeter@606
  3491
      return CombinedNodeMap<IN, OUT>(in_map, out_map);
deba@430
  3492
    }
deba@430
  3493
kpeter@606
  3494
    template <typename IN, typename OUT>
kpeter@606
  3495
    static CombinedNodeMap<const IN, OUT>
kpeter@606
  3496
    combinedNodeMap(const IN& in_map, OUT& out_map) {
kpeter@606
  3497
      return CombinedNodeMap<const IN, OUT>(in_map, out_map);
deba@430
  3498
    }
deba@430
  3499
kpeter@606
  3500
    template <typename IN, typename OUT>
kpeter@606
  3501
    static CombinedNodeMap<IN, const OUT>
kpeter@606
  3502
    combinedNodeMap(IN& in_map, const OUT& out_map) {
kpeter@606
  3503
      return CombinedNodeMap<IN, const OUT>(in_map, out_map);
deba@430
  3504
    }
deba@430
  3505
kpeter@606
  3506
    template <typename IN, typename OUT>
kpeter@606
  3507
    static CombinedNodeMap<const IN, const OUT>
kpeter@606
  3508
    combinedNodeMap(const IN& in_map, const OUT& out_map) {
kpeter@606
  3509
      return CombinedNodeMap<const IN, const OUT>(in_map, out_map);
deba@430
  3510
    }
deba@430
  3511
kpeter@474
  3512
    /// \brief Arc map combined from an arc map and a node map of the
kpeter@474
  3513
    /// original digraph.
deba@430
  3514
    ///
kpeter@474
  3515
    /// This map adaptor class adapts an arc map and a node map of the
kpeter@474
  3516
    /// original digraph to get an arc map of the split digraph.
kpeter@606
  3517
    /// Its value type is inherited from the original arc map type (\c AM).
kpeter@606
  3518
    /// \tparam AM The type of the arc map.
kpeter@606
  3519
    /// \tparam NM the type of the node map.
kpeter@606
  3520
    template <typename AM, typename NM>
deba@430
  3521
    class CombinedArcMap {
deba@430
  3522
    public:
deba@432
  3523
kpeter@474
  3524
      /// The key type of the map
deba@430
  3525
      typedef Arc Key;
kpeter@474
  3526
      /// The value type of the map
kpeter@606
  3527
      typedef typename AM::Value Value;
kpeter@606
  3528
kpeter@606
  3529
      typedef typename MapTraits<AM>::ReferenceMapTag ReferenceMapTag;
kpeter@606
  3530
      typedef typename MapTraits<AM>::ReturnValue ReturnValue;
kpeter@606
  3531
      typedef typename MapTraits<AM>::ConstReturnValue ConstReturnValue;
kpeter@606
  3532
      typedef typename MapTraits<AM>::ReturnValue Reference;
kpeter@606
  3533
      typedef typename MapTraits<AM>::ConstReturnValue ConstReference;
kpeter@472
  3534
kpeter@474
  3535
      /// Constructor
kpeter@606
  3536
      CombinedArcMap(AM& arc_map, NM& node_map)
deba@432
  3537
        : _arc_map(arc_map), _node_map(node_map) {}
deba@430
  3538
kpeter@474
  3539
      /// Returns the value associated with the given key.
kpeter@474
  3540
      Value operator[](const Key& arc) const {
deba@559
  3541
        if (SplitNodesBase<const DGR>::origArc(arc)) {
kpeter@474
  3542
          return _arc_map[arc];
kpeter@474
  3543
        } else {
kpeter@474
  3544
          return _node_map[arc];
kpeter@474
  3545
        }
kpeter@474
  3546
      }
kpeter@474
  3547
kpeter@474
  3548
      /// Returns a reference to the value associated with the given key.
kpeter@474
  3549
      Value& operator[](const Key& arc) {
deba@559
  3550
        if (SplitNodesBase<const DGR>::origArc(arc)) {
kpeter@474
  3551
          return _arc_map[arc];
kpeter@474
  3552
        } else {
kpeter@474
  3553
          return _node_map[arc];
kpeter@474
  3554
        }
kpeter@474
  3555
      }
kpeter@474
  3556
kpeter@474
  3557
      /// Sets the value associated with the given key.
deba@430
  3558
      void set(const Arc& arc, const Value& val) {
deba@559
  3559
        if (SplitNodesBase<const DGR>::origArc(arc)) {
deba@432
  3560
          _arc_map.set(arc, val);
deba@432
  3561
        } else {
deba@432
  3562
          _node_map.set(arc, val);
deba@432
  3563
        }
deba@430
  3564
      }
deba@430
  3565
deba@430
  3566
    private:
kpeter@606
  3567
kpeter@606
  3568
      AM& _arc_map;
kpeter@606
  3569
      NM& _node_map;
kpeter@606
  3570
deba@430
  3571
    };
deba@432
  3572
kpeter@474
  3573
    /// \brief Returns a combined arc map
deba@432
  3574
    ///
kpeter@474
  3575
    /// This function just returns a combined arc map.
kpeter@476
  3576
    template <typename ArcMap, typename NodeMap>
kpeter@476
  3577
    static CombinedArcMap<ArcMap, NodeMap>
kpeter@476
  3578
    combinedArcMap(ArcMap& arc_map, NodeMap& node_map) {
kpeter@476
  3579
      return CombinedArcMap<ArcMap, NodeMap>(arc_map, node_map);
deba@430
  3580
    }
deba@430
  3581
kpeter@476
  3582
    template <typename ArcMap, typename NodeMap>
kpeter@476
  3583
    static CombinedArcMap<const ArcMap, NodeMap>
kpeter@476
  3584
    combinedArcMap(const ArcMap& arc_map, NodeMap& node_map) {
kpeter@476
  3585
      return CombinedArcMap<const ArcMap, NodeMap>(arc_map, node_map);
deba@430
  3586
    }
deba@430
  3587
kpeter@476
  3588
    template <typename ArcMap, typename NodeMap>
kpeter@476
  3589
    static CombinedArcMap<ArcMap, const NodeMap>
kpeter@476
  3590
    combinedArcMap(ArcMap& arc_map, const NodeMap& node_map) {
kpeter@476
  3591
      return CombinedArcMap<ArcMap, const NodeMap>(arc_map, node_map);
deba@430
  3592
    }
deba@430
  3593
kpeter@476
  3594
    template <typename ArcMap, typename NodeMap>
kpeter@476
  3595
    static CombinedArcMap<const ArcMap, const NodeMap>
kpeter@476
  3596
    combinedArcMap(const ArcMap& arc_map, const NodeMap& node_map) {
kpeter@476
  3597
      return CombinedArcMap<const ArcMap, const NodeMap>(arc_map, node_map);
deba@430
  3598
    }
deba@430
  3599
deba@430
  3600
  };
deba@430
  3601
kpeter@474
  3602
  /// \brief Returns a (read-only) SplitNodes adaptor
deba@430
  3603
  ///
kpeter@474
  3604
  /// This function just returns a (read-only) \ref SplitNodes adaptor.
kpeter@474
  3605
  /// \ingroup graph_adaptors
kpeter@474
  3606
  /// \relates SplitNodes
deba@559
  3607
  template<typename DGR>
deba@559
  3608
  SplitNodes<DGR>
deba@559
  3609
  splitNodes(const DGR& digraph) {
deba@559
  3610
    return SplitNodes<DGR>(digraph);
deba@430
  3611
  }
deba@430
  3612
deba@559
  3613
#undef LEMON_SCOPE_FIX
deba@559
  3614
deba@430
  3615
} //namespace lemon
deba@430
  3616
deba@432
  3617
#endif //LEMON_ADAPTORS_H