lemon/adaptors.h
author Peter Kovacs <kpeter@inf.elte.hu>
Fri, 09 Jan 2009 12:54:27 +0100
changeset 451 fbd6e04acf44
parent 450 14bb8812b8af
child 452 aea2dc0518ce
permissions -rw-r--r--
Various doc improvements for graph adaptors (#67)

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