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