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