lemon/ugraph_adaptor.h
author hegyi
Tue, 08 Apr 2008 11:39:40 +0000
changeset 2602 1c7790d9e025
parent 2422 77ed2b97abbd
child 2617 5222a3c470ed
permissions -rw-r--r--
Rel.07 NEWS - 3. round
deba@1979
     1
/* -*- C++ -*-
deba@1979
     2
 *
deba@1979
     3
 * This file is a part of LEMON, a generic C++ optimization library
deba@1979
     4
 *
alpar@2553
     5
 * Copyright (C) 2003-2008
deba@1979
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@1979
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@1979
     8
 *
deba@1979
     9
 * Permission to use, modify and distribute this software is granted
deba@1979
    10
 * provided that this copyright notice appears in all copies. For
deba@1979
    11
 * precise terms see the accompanying LICENSE file.
deba@1979
    12
 *
deba@1979
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@1979
    14
 * express or implied, and with no claim as to its suitability for any
deba@1979
    15
 * purpose.
deba@1979
    16
 *
deba@1979
    17
 */
deba@1979
    18
deba@1979
    19
#ifndef LEMON_UGRAPH_ADAPTOR_H
deba@1979
    20
#define LEMON_UGRAPH_ADAPTOR_H
deba@1979
    21
deba@1979
    22
///\ingroup graph_adaptors
deba@1979
    23
///\file
deba@1979
    24
///\brief Several graph adaptors.
deba@1979
    25
///
deba@1979
    26
///This file contains several useful ugraph adaptor functions.
deba@1979
    27
///
deba@1979
    28
///\author Balazs Dezso
deba@1979
    29
deba@1993
    30
#include <lemon/bits/invalid.h>
deba@1979
    31
#include <lemon/maps.h>
deba@1979
    32
deba@1979
    33
#include <lemon/bits/graph_adaptor_extender.h>
deba@1979
    34
deba@1993
    35
#include <lemon/bits/traits.h>
deba@1979
    36
deba@1979
    37
#include <iostream>
deba@1979
    38
deba@1979
    39
namespace lemon {
deba@1979
    40
deba@1979
    41
  /// \brief Base type for the Graph Adaptors
deba@1979
    42
  ///
deba@1979
    43
  /// This is the base type for most of LEMON graph adaptors. 
deba@1979
    44
  /// This class implements a trivial graph adaptor i.e. it only wraps the 
deba@1979
    45
  /// functions and types of the graph. The purpose of this class is to 
deba@1979
    46
  /// make easier implementing graph adaptors. E.g. if an adaptor is 
deba@1979
    47
  /// considered which differs from the wrapped graph only in some of its 
deba@1979
    48
  /// functions or types, then it can be derived from GraphAdaptor, and only 
deba@1979
    49
  /// the differences should be implemented.
deba@1979
    50
  ///
deba@1979
    51
  /// \author Balazs Dezso 
deba@1979
    52
  template<typename _UGraph>
deba@1979
    53
  class UGraphAdaptorBase {
deba@1979
    54
  public:
deba@1979
    55
    typedef _UGraph Graph;
deba@1979
    56
    typedef Graph ParentGraph;
deba@1979
    57
deba@1979
    58
  protected:
deba@1979
    59
    Graph* graph;
deba@1979
    60
deba@1979
    61
    UGraphAdaptorBase() : graph(0) {}
deba@1979
    62
deba@1979
    63
    void setGraph(Graph& _graph) { graph=&_graph; }
deba@1979
    64
deba@1979
    65
  public:
deba@1979
    66
    UGraphAdaptorBase(Graph& _graph) : graph(&_graph) {}
deba@1979
    67
 
deba@1979
    68
    typedef typename Graph::Node Node;
deba@1979
    69
    typedef typename Graph::Edge Edge;
deba@1979
    70
    typedef typename Graph::UEdge UEdge;
deba@1979
    71
   
deba@1979
    72
    void first(Node& i) const { graph->first(i); }
deba@1979
    73
    void first(Edge& i) const { graph->first(i); }
deba@1979
    74
    void first(UEdge& i) const { graph->first(i); }
deba@1979
    75
    void firstIn(Edge& i, const Node& n) const { graph->firstIn(i, n); }
deba@1979
    76
    void firstOut(Edge& i, const Node& n ) const { graph->firstOut(i, n); }
deba@1979
    77
    void firstInc(UEdge &i, bool &d, const Node &n) const {
deba@1979
    78
      graph->firstInc(i, d, n);
deba@1979
    79
    }
deba@1979
    80
deba@1979
    81
    void next(Node& i) const { graph->next(i); }
deba@1979
    82
    void next(Edge& i) const { graph->next(i); }
deba@1979
    83
    void next(UEdge& i) const { graph->next(i); }
deba@1979
    84
    void nextIn(Edge& i) const { graph->nextIn(i); }
deba@1979
    85
    void nextOut(Edge& i) const { graph->nextOut(i); }
deba@1979
    86
    void nextInc(UEdge &i, bool &d) const { graph->nextInc(i, d); }
deba@1979
    87
deba@1979
    88
    Node source(const UEdge& e) const { return graph->source(e); }
deba@1979
    89
    Node target(const UEdge& e) const { return graph->target(e); }
deba@1979
    90
deba@1979
    91
    Node source(const Edge& e) const { return graph->source(e); }
deba@1979
    92
    Node target(const Edge& e) const { return graph->target(e); }
deba@1979
    93
deba@1979
    94
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
deba@1979
    95
    int nodeNum() const { return graph->nodeNum(); }
deba@1979
    96
    
deba@1979
    97
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
deba@1979
    98
    int edgeNum() const { return graph->edgeNum(); }
deba@2031
    99
    int uEdgeNum() const { return graph->uEdgeNum(); }
deba@1979
   100
deba@1979
   101
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@2386
   102
    Edge findEdge(const Node& u, const Node& v, 
deba@1979
   103
		  const Edge& prev = INVALID) {
deba@2386
   104
      return graph->findEdge(u, v, prev);
deba@1979
   105
    }
deba@2386
   106
    UEdge findUEdge(const Node& u, const Node& v, 
deba@1979
   107
                    const UEdge& prev = INVALID) {
deba@2386
   108
      return graph->findUEdge(u, v, prev);
deba@1979
   109
    }
deba@1979
   110
  
deba@1979
   111
    Node addNode() const { return graph->addNode(); }
deba@2386
   112
    UEdge addEdge(const Node& u, const Node& v) const { 
deba@2386
   113
      return graph->addEdge(u, v); 
deba@1979
   114
    }
deba@1979
   115
deba@1979
   116
    void erase(const Node& i) const { graph->erase(i); }
deba@2031
   117
    void erase(const UEdge& i) const { graph->erase(i); }
deba@1979
   118
  
deba@1979
   119
    void clear() const { graph->clear(); }
deba@1979
   120
    
deba@2031
   121
    bool direction(const Edge& e) const { return graph->direction(e); }
deba@2031
   122
    Edge direct(const UEdge& e, bool d) const { return graph->direct(e, d); }
deba@2031
   123
deba@1979
   124
    int id(const Node& v) const { return graph->id(v); }
deba@2031
   125
    int id(const Edge& e) const { return graph->id(e); }
deba@1979
   126
    int id(const UEdge& e) const { return graph->id(e); }
deba@1979
   127
deba@2386
   128
    Node fromNodeId(int ix) const {
deba@2386
   129
      return graph->fromNodeId(ix);
deba@2031
   130
    }
deba@2031
   131
deba@2386
   132
    Edge fromEdgeId(int ix) const {
deba@2386
   133
      return graph->fromEdgeId(ix);
deba@2031
   134
    }
deba@2031
   135
deba@2386
   136
    UEdge fromUEdgeId(int ix) const {
deba@2386
   137
      return graph->fromUEdgeId(ix);
deba@2031
   138
    }
deba@1991
   139
deba@1991
   140
    int maxNodeId() const {
deba@1991
   141
      return graph->maxNodeId();
deba@1979
   142
    }
deba@1979
   143
deba@1991
   144
    int maxEdgeId() const {
deba@1991
   145
      return graph->maxEdgeId();
deba@1979
   146
    }
deba@1979
   147
deba@1991
   148
    int maxUEdgeId() const {
deba@1991
   149
      return graph->maxEdgeId();
deba@1979
   150
    }
deba@1979
   151
deba@1991
   152
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
deba@1991
   153
deba@2381
   154
    NodeNotifier& notifier(Node) const {
deba@2381
   155
      return graph->notifier(Node());
deba@1991
   156
    } 
deba@1991
   157
deba@1991
   158
    typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
deba@1991
   159
deba@2381
   160
    EdgeNotifier& notifier(Edge) const {
deba@2381
   161
      return graph->notifier(Edge());
deba@1991
   162
    } 
deba@1991
   163
deba@1991
   164
    typedef typename ItemSetTraits<Graph, UEdge>::ItemNotifier UEdgeNotifier;
deba@1991
   165
deba@2381
   166
    UEdgeNotifier& notifier(UEdge) const {
deba@2381
   167
      return graph->notifier(UEdge());
deba@1991
   168
    } 
deba@1979
   169
deba@1979
   170
    template <typename _Value>
deba@1979
   171
    class NodeMap : public Graph::template NodeMap<_Value> {
deba@1979
   172
    public:
deba@1979
   173
      typedef typename Graph::template NodeMap<_Value> Parent;
deba@1979
   174
      explicit NodeMap(const UGraphAdaptorBase<Graph>& ga) 
deba@1979
   175
	: Parent(*ga.graph) {}
deba@1979
   176
      NodeMap(const UGraphAdaptorBase<Graph>& ga, const _Value& value)
deba@1979
   177
	: Parent(*ga.graph, value) {}
deba@1979
   178
deba@1979
   179
      NodeMap& operator=(const NodeMap& cmap) {
deba@1979
   180
	return operator=<NodeMap>(cmap);
deba@1979
   181
      }
deba@1979
   182
deba@1979
   183
      template <typename CMap>
deba@1979
   184
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   185
        Parent::operator=(cmap);
deba@2031
   186
        return *this;
deba@1979
   187
      }
deba@2031
   188
deba@1979
   189
    };
deba@1979
   190
deba@1979
   191
    template <typename _Value>
deba@1979
   192
    class EdgeMap : public Graph::template EdgeMap<_Value> {
deba@1979
   193
    public:
deba@1979
   194
      typedef typename Graph::template EdgeMap<_Value> Parent;
deba@1979
   195
      explicit EdgeMap(const UGraphAdaptorBase<Graph>& ga) 
deba@1979
   196
	: Parent(*ga.graph) {}
deba@1979
   197
      EdgeMap(const UGraphAdaptorBase<Graph>& ga, const _Value& value)
deba@1979
   198
	: Parent(*ga.graph, value) {}
deba@1979
   199
deba@1979
   200
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@1979
   201
	return operator=<EdgeMap>(cmap);
deba@1979
   202
      }
deba@1979
   203
deba@1979
   204
      template <typename CMap>
deba@1979
   205
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   206
        Parent::operator=(cmap);
deba@1979
   207
	return *this;
deba@1979
   208
      }
deba@1979
   209
    };
deba@1979
   210
deba@1979
   211
    template <typename _Value>
deba@1979
   212
    class UEdgeMap : public Graph::template UEdgeMap<_Value> {
deba@1979
   213
    public:
deba@1979
   214
      typedef typename Graph::template UEdgeMap<_Value> Parent;
deba@1979
   215
      explicit UEdgeMap(const UGraphAdaptorBase<Graph>& ga) 
deba@1979
   216
	: Parent(*ga.graph) {}
deba@1979
   217
      UEdgeMap(const UGraphAdaptorBase<Graph>& ga, const _Value& value)
deba@1979
   218
	: Parent(*ga.graph, value) {}
deba@1979
   219
deba@1979
   220
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@1979
   221
	return operator=<UEdgeMap>(cmap);
deba@1979
   222
      }
deba@1979
   223
deba@1979
   224
      template <typename CMap>
deba@1979
   225
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
   226
        Parent::operator=(cmap);
deba@2031
   227
        return *this;
deba@1979
   228
      }
deba@1979
   229
    };
deba@1979
   230
deba@1979
   231
  };
deba@1979
   232
deba@1979
   233
  /// \ingroup graph_adaptors
deba@2084
   234
  ///
deba@2084
   235
  /// \brief Trivial undirected graph adaptor
deba@2084
   236
  ///
deba@2084
   237
  /// This class is an adaptor which does not change the adapted undirected
deba@2084
   238
  /// graph. It can be used only to test the undirected graph adaptors.
deba@1979
   239
  template <typename _UGraph>
deba@1979
   240
  class UGraphAdaptor 
deba@1979
   241
    : public UGraphAdaptorExtender< UGraphAdaptorBase<_UGraph> > { 
deba@1979
   242
  public:
deba@1979
   243
    typedef _UGraph Graph;
deba@1979
   244
    typedef UGraphAdaptorExtender<UGraphAdaptorBase<_UGraph> > Parent;
deba@1979
   245
  protected:
deba@1979
   246
    UGraphAdaptor() : Parent() {}
deba@1979
   247
deba@1979
   248
  public:
deba@1979
   249
    explicit UGraphAdaptor(Graph& _graph) { setGraph(_graph); }
deba@1979
   250
  };
deba@1979
   251
deba@1979
   252
  template <typename _UGraph, typename NodeFilterMap, 
deba@1979
   253
	    typename UEdgeFilterMap, bool checked = true>
deba@1979
   254
  class SubUGraphAdaptorBase : public UGraphAdaptorBase<_UGraph> {
deba@1979
   255
  public:
deba@1979
   256
    typedef _UGraph Graph;
deba@2031
   257
    typedef SubUGraphAdaptorBase Adaptor;
deba@1979
   258
    typedef UGraphAdaptorBase<_UGraph> Parent;
deba@1979
   259
  protected:
deba@1979
   260
deba@1979
   261
    NodeFilterMap* node_filter_map;
deba@1979
   262
    UEdgeFilterMap* uedge_filter_map;
deba@1979
   263
deba@1979
   264
    SubUGraphAdaptorBase() 
deba@1979
   265
      : Parent(), node_filter_map(0), uedge_filter_map(0) { }
deba@1979
   266
deba@1979
   267
    void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
deba@1979
   268
      node_filter_map=&_node_filter_map;
deba@1979
   269
    }
deba@1979
   270
    void setUEdgeFilterMap(UEdgeFilterMap& _uedge_filter_map) {
deba@1979
   271
      uedge_filter_map=&_uedge_filter_map;
deba@1979
   272
    }
deba@1979
   273
deba@1979
   274
  public:
deba@1979
   275
deba@1979
   276
    typedef typename Parent::Node Node;
deba@1979
   277
    typedef typename Parent::Edge Edge;
deba@1979
   278
    typedef typename Parent::UEdge UEdge;
deba@1979
   279
deba@1979
   280
    void first(Node& i) const { 
deba@1979
   281
      Parent::first(i); 
deba@1979
   282
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1979
   283
    }
deba@1979
   284
deba@1979
   285
    void first(Edge& i) const { 
deba@1979
   286
      Parent::first(i); 
deba@1979
   287
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   288
	     || !(*node_filter_map)[Parent::source(i)]
deba@1979
   289
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1979
   290
    }
deba@1979
   291
deba@1979
   292
    void first(UEdge& i) const { 
deba@1979
   293
      Parent::first(i); 
deba@1979
   294
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   295
	     || !(*node_filter_map)[Parent::source(i)]
deba@1979
   296
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1979
   297
    }
deba@1979
   298
deba@1979
   299
    void firstIn(Edge& i, const Node& n) const { 
deba@1979
   300
      Parent::firstIn(i, n); 
deba@1979
   301
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   302
	     || !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i); 
deba@1979
   303
    }
deba@1979
   304
deba@1979
   305
    void firstOut(Edge& i, const Node& n) const { 
deba@1979
   306
      Parent::firstOut(i, n); 
deba@1979
   307
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   308
	     || !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i); 
deba@1979
   309
    }
deba@1979
   310
deba@1979
   311
    void firstInc(UEdge& i, bool& d, const Node& n) const { 
deba@1979
   312
      Parent::firstInc(i, d, n); 
deba@1979
   313
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@2381
   314
            || !(*node_filter_map)[Parent::source(i)]
deba@1979
   315
            || !(*node_filter_map)[Parent::target(i)])) Parent::nextInc(i, d); 
deba@1979
   316
    }
deba@1979
   317
deba@1979
   318
    void next(Node& i) const { 
deba@1979
   319
      Parent::next(i); 
deba@1979
   320
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1979
   321
    }
deba@1979
   322
deba@1979
   323
    void next(Edge& i) const { 
deba@1979
   324
      Parent::next(i); 
deba@1979
   325
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   326
	     || !(*node_filter_map)[Parent::source(i)]
deba@1979
   327
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1979
   328
    }
deba@1979
   329
deba@1979
   330
    void next(UEdge& i) const { 
deba@1979
   331
      Parent::next(i); 
deba@1979
   332
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   333
	     || !(*node_filter_map)[Parent::source(i)]
deba@1979
   334
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1979
   335
    }
deba@1979
   336
deba@1979
   337
    void nextIn(Edge& i) const { 
deba@1979
   338
      Parent::nextIn(i); 
deba@1979
   339
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   340
	     || !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i); 
deba@1979
   341
    }
deba@1979
   342
deba@1979
   343
    void nextOut(Edge& i) const { 
deba@1979
   344
      Parent::nextOut(i); 
deba@1979
   345
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   346
	     || !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i); 
deba@1979
   347
    }
deba@1979
   348
deba@1979
   349
    void nextInc(UEdge& i, bool& d) const { 
deba@1979
   350
      Parent::nextInc(i, d); 
deba@2381
   351
      while (i!=INVALID && (!(*uedge_filter_map)[i]
deba@2381
   352
            || !(*node_filter_map)[Parent::source(i)]
deba@2381
   353
            || !(*node_filter_map)[Parent::target(i)])) Parent::nextInc(i, d); 
deba@1979
   354
    }
deba@1979
   355
deba@2084
   356
    /// \brief Hide the given node in the graph.
deba@2084
   357
    ///
deba@1979
   358
    /// This function hides \c n in the graph, i.e. the iteration 
deba@1979
   359
    /// jumps over it. This is done by simply setting the value of \c n  
deba@1979
   360
    /// to be false in the corresponding node-map.
deba@1979
   361
    void hide(const Node& n) const { node_filter_map->set(n, false); }
deba@1979
   362
deba@2084
   363
    /// \brief Hide the given undirected edge in the graph.
deba@2084
   364
    ///
deba@1979
   365
    /// This function hides \c e in the graph, i.e. the iteration 
deba@1979
   366
    /// jumps over it. This is done by simply setting the value of \c e  
deba@2084
   367
    /// to be false in the corresponding uedge-map.
deba@1979
   368
    void hide(const UEdge& e) const { uedge_filter_map->set(e, false); }
deba@1979
   369
deba@2084
   370
    /// \brief Unhide the given node in the graph.
deba@2084
   371
    ///
deba@1979
   372
    /// The value of \c n is set to be true in the node-map which stores 
deba@1979
   373
    /// hide information. If \c n was hidden previuosly, then it is shown 
deba@1979
   374
    /// again
deba@1979
   375
     void unHide(const Node& n) const { node_filter_map->set(n, true); }
deba@1979
   376
deba@2084
   377
    /// \brief Hide the given undirected edge in the graph.
deba@2084
   378
    ///
deba@2084
   379
    /// The value of \c e is set to be true in the uedge-map which stores 
deba@1979
   380
    /// hide information. If \c e was hidden previuosly, then it is shown 
deba@1979
   381
    /// again
deba@1979
   382
    void unHide(const UEdge& e) const { uedge_filter_map->set(e, true); }
deba@1979
   383
deba@2084
   384
    /// \brief Returns true if \c n is hidden.
deba@2084
   385
    ///
deba@1979
   386
    /// Returns true if \c n is hidden.
deba@1979
   387
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
deba@1979
   388
deba@2084
   389
    /// \brief Returns true if \c e is hidden.
deba@1979
   390
    ///
deba@2084
   391
    /// Returns true if \c e is hidden.
deba@1979
   392
    bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; }
deba@1979
   393
deba@1979
   394
    typedef False NodeNumTag;
deba@1979
   395
    typedef False EdgeNumTag;
deba@1991
   396
deba@1991
   397
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@2386
   398
    Edge findEdge(const Node& u, const Node& v, 
deba@1991
   399
		  const Edge& prev = INVALID) {
deba@2386
   400
      if (!(*node_filter_map)[u] || !(*node_filter_map)[v]) {
deba@1991
   401
        return INVALID;
deba@1991
   402
      }
deba@2386
   403
      Edge edge = Parent::findEdge(u, v, prev);
deba@1991
   404
      while (edge != INVALID && !(*uedge_filter_map)[edge]) {
deba@2386
   405
        edge = Parent::findEdge(u, v, edge);
deba@1991
   406
      }
deba@1991
   407
      return edge;
deba@1991
   408
    }
deba@2386
   409
    UEdge findUEdge(const Node& u, const Node& v, 
deba@1991
   410
		  const UEdge& prev = INVALID) {
deba@2386
   411
      if (!(*node_filter_map)[u] || !(*node_filter_map)[v]) {
deba@1991
   412
        return INVALID;
deba@1991
   413
      }
deba@2386
   414
      UEdge uedge = Parent::findUEdge(u, v, prev);
deba@1991
   415
      while (uedge != INVALID && !(*uedge_filter_map)[uedge]) {
deba@2386
   416
        uedge = Parent::findUEdge(u, v, uedge);
deba@1991
   417
      }
deba@1991
   418
      return uedge;
deba@1991
   419
    }
deba@2031
   420
deba@2031
   421
    template <typename _Value>
deba@2031
   422
    class NodeMap 
deba@2031
   423
      : public SubMapExtender<Adaptor, 
deba@2031
   424
                              typename Parent::template NodeMap<_Value> > 
deba@2031
   425
    {
deba@2031
   426
    public:
deba@2031
   427
      typedef Adaptor Graph;
deba@2031
   428
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   429
                             template NodeMap<_Value> > Parent;
deba@2031
   430
    
deba@2386
   431
      NodeMap(const Graph& g) 
deba@2386
   432
	: Parent(g) {}
deba@2386
   433
      NodeMap(const Graph& g, const _Value& v) 
deba@2386
   434
	: Parent(g, v) {}
deba@2031
   435
    
deba@2031
   436
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
   437
	return operator=<NodeMap>(cmap);
deba@2031
   438
      }
deba@2031
   439
    
deba@2031
   440
      template <typename CMap>
deba@2031
   441
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   442
        Parent::operator=(cmap);
deba@2031
   443
	return *this;
deba@2031
   444
      }
deba@2031
   445
    };
deba@2031
   446
deba@2031
   447
    template <typename _Value>
deba@2031
   448
    class EdgeMap 
deba@2031
   449
      : public SubMapExtender<Adaptor, 
deba@2031
   450
                              typename Parent::template EdgeMap<_Value> > 
deba@2031
   451
    {
deba@2031
   452
    public:
deba@2031
   453
      typedef Adaptor Graph;
deba@2031
   454
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   455
                             template EdgeMap<_Value> > Parent;
deba@2031
   456
    
deba@2386
   457
      EdgeMap(const Graph& g) 
deba@2386
   458
	: Parent(g) {}
deba@2386
   459
      EdgeMap(const Graph& g, const _Value& v) 
deba@2386
   460
	: Parent(g, v) {}
deba@2031
   461
    
deba@2031
   462
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
   463
	return operator=<EdgeMap>(cmap);
deba@2031
   464
      }
deba@2031
   465
    
deba@2031
   466
      template <typename CMap>
deba@2031
   467
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   468
        Parent::operator=(cmap);
deba@2031
   469
	return *this;
deba@2031
   470
      }
deba@2031
   471
    };
deba@2031
   472
deba@2031
   473
    template <typename _Value>
deba@2031
   474
    class UEdgeMap 
deba@2031
   475
      : public SubMapExtender<Adaptor, 
deba@2031
   476
                              typename Parent::template UEdgeMap<_Value> > 
deba@2031
   477
    {
deba@2031
   478
    public:
deba@2031
   479
      typedef Adaptor Graph;
deba@2031
   480
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   481
                             template UEdgeMap<_Value> > Parent;
deba@2031
   482
    
deba@2386
   483
      UEdgeMap(const Graph& g) 
deba@2386
   484
	: Parent(g) {}
deba@2386
   485
      UEdgeMap(const Graph& g, const _Value& v) 
deba@2386
   486
	: Parent(g, v) {}
deba@2031
   487
    
deba@2031
   488
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@2031
   489
	return operator=<UEdgeMap>(cmap);
deba@2031
   490
      }
deba@2031
   491
    
deba@2031
   492
      template <typename CMap>
deba@2031
   493
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
   494
        Parent::operator=(cmap);
deba@2031
   495
	return *this;
deba@2031
   496
      }
deba@2031
   497
    };
deba@2031
   498
deba@1979
   499
  };
deba@1979
   500
deba@1979
   501
  template <typename _UGraph, typename NodeFilterMap, typename UEdgeFilterMap>
deba@1979
   502
  class SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, false> 
deba@1979
   503
    : public UGraphAdaptorBase<_UGraph> {
deba@1979
   504
  public:
deba@1979
   505
    typedef _UGraph Graph;
deba@2031
   506
    typedef SubUGraphAdaptorBase Adaptor;
deba@1979
   507
    typedef UGraphAdaptorBase<_UGraph> Parent;
deba@1979
   508
  protected:
deba@1979
   509
    NodeFilterMap* node_filter_map;
deba@1979
   510
    UEdgeFilterMap* uedge_filter_map;
deba@1979
   511
    SubUGraphAdaptorBase() : Parent(), 
deba@1979
   512
			    node_filter_map(0), uedge_filter_map(0) { }
deba@1979
   513
deba@1979
   514
    void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
deba@1979
   515
      node_filter_map=&_node_filter_map;
deba@1979
   516
    }
deba@1979
   517
    void setUEdgeFilterMap(UEdgeFilterMap& _uedge_filter_map) {
deba@1979
   518
      uedge_filter_map=&_uedge_filter_map;
deba@1979
   519
    }
deba@1979
   520
deba@1979
   521
  public:
deba@1979
   522
deba@1979
   523
    typedef typename Parent::Node Node;
deba@1979
   524
    typedef typename Parent::Edge Edge;
deba@1979
   525
    typedef typename Parent::UEdge UEdge;
deba@1979
   526
deba@1979
   527
    void first(Node& i) const { 
deba@1979
   528
      Parent::first(i); 
deba@1979
   529
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1979
   530
    }
deba@1979
   531
deba@1979
   532
    void first(Edge& i) const { 
deba@1979
   533
      Parent::first(i); 
deba@1979
   534
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i); 
deba@1979
   535
    }
deba@1979
   536
deba@1979
   537
    void first(UEdge& i) const { 
deba@1979
   538
      Parent::first(i); 
deba@1979
   539
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i); 
deba@1979
   540
    }
deba@1979
   541
deba@1979
   542
    void firstIn(Edge& i, const Node& n) const { 
deba@1979
   543
      Parent::firstIn(i, n); 
deba@1979
   544
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextIn(i); 
deba@1979
   545
    }
deba@1979
   546
deba@1979
   547
    void firstOut(Edge& i, const Node& n) const { 
deba@1979
   548
      Parent::firstOut(i, n); 
deba@1979
   549
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextOut(i); 
deba@1979
   550
    }
deba@1979
   551
deba@1979
   552
    void firstInc(UEdge& i, bool& d, const Node& n) const { 
deba@1979
   553
      Parent::firstInc(i, d, n); 
deba@1979
   554
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextInc(i, d); 
deba@1979
   555
    }
deba@1979
   556
deba@1979
   557
    void next(Node& i) const { 
deba@1979
   558
      Parent::next(i); 
deba@1979
   559
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1979
   560
    }
deba@1979
   561
    void next(Edge& i) const { 
deba@1979
   562
      Parent::next(i); 
deba@1979
   563
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i); 
deba@1979
   564
    }
deba@1979
   565
    void next(UEdge& i) const { 
deba@1979
   566
      Parent::next(i); 
deba@1979
   567
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i); 
deba@1979
   568
    }
deba@1979
   569
    void nextIn(Edge& i) const { 
deba@1979
   570
      Parent::nextIn(i); 
deba@1979
   571
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextIn(i); 
deba@1979
   572
    }
deba@1979
   573
deba@1979
   574
    void nextOut(Edge& i) const { 
deba@1979
   575
      Parent::nextOut(i); 
deba@1979
   576
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextOut(i); 
deba@1979
   577
    }
deba@1979
   578
    void nextInc(UEdge& i, bool& d) const { 
deba@1979
   579
      Parent::nextInc(i, d); 
deba@1979
   580
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextInc(i, d); 
deba@1979
   581
    }
deba@1979
   582
deba@2084
   583
    /// \brief Hide the given node in the graph.
deba@2084
   584
    ///
deba@1979
   585
    /// This function hides \c n in the graph, i.e. the iteration 
deba@1979
   586
    /// jumps over it. This is done by simply setting the value of \c n  
deba@1979
   587
    /// to be false in the corresponding node-map.
deba@1979
   588
    void hide(const Node& n) const { node_filter_map->set(n, false); }
deba@1979
   589
deba@2084
   590
    /// \brief Hide the given undirected edge in the graph.
deba@2084
   591
    ///
deba@1979
   592
    /// This function hides \c e in the graph, i.e. the iteration 
deba@1979
   593
    /// jumps over it. This is done by simply setting the value of \c e  
deba@2084
   594
    /// to be false in the corresponding uedge-map.
deba@1979
   595
    void hide(const UEdge& e) const { uedge_filter_map->set(e, false); }
deba@1979
   596
deba@2084
   597
    /// \brief Unhide the given node in the graph.
deba@2084
   598
    ///
deba@1979
   599
    /// The value of \c n is set to be true in the node-map which stores 
deba@1979
   600
    /// hide information. If \c n was hidden previuosly, then it is shown 
deba@1979
   601
    /// again
deba@1979
   602
     void unHide(const Node& n) const { node_filter_map->set(n, true); }
deba@1979
   603
deba@2084
   604
    /// \brief Hide the given undirected edge in the graph.
deba@2084
   605
    ///
deba@2084
   606
    /// The value of \c e is set to be true in the uedge-map which stores 
deba@1979
   607
    /// hide information. If \c e was hidden previuosly, then it is shown 
deba@1979
   608
    /// again
deba@1979
   609
    void unHide(const UEdge& e) const { uedge_filter_map->set(e, true); }
deba@1979
   610
deba@2084
   611
    /// \brief Returns true if \c n is hidden.
deba@2084
   612
    ///
deba@1979
   613
    /// Returns true if \c n is hidden.
deba@1979
   614
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
deba@1979
   615
deba@2084
   616
    /// \brief Returns true if \c e is hidden.
deba@1979
   617
    ///
deba@2084
   618
    /// Returns true if \c e is hidden.
deba@1979
   619
    bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; }
deba@1979
   620
deba@1979
   621
    typedef False NodeNumTag;
deba@1979
   622
    typedef False EdgeNumTag;
deba@1991
   623
deba@1991
   624
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@2386
   625
    Edge findEdge(const Node& u, const Node& v, 
deba@1991
   626
		  const Edge& prev = INVALID) {
deba@2386
   627
      Edge edge = Parent::findEdge(u, v, prev);
deba@1991
   628
      while (edge != INVALID && !(*uedge_filter_map)[edge]) {
deba@2386
   629
        edge = Parent::findEdge(u, v, edge);
deba@1991
   630
      }
deba@1991
   631
      return edge;
deba@1991
   632
    }
deba@2386
   633
    UEdge findUEdge(const Node& u, const Node& v, 
deba@1991
   634
		  const UEdge& prev = INVALID) {
deba@2386
   635
      UEdge uedge = Parent::findUEdge(u, v, prev);
deba@1991
   636
      while (uedge != INVALID && !(*uedge_filter_map)[uedge]) {
deba@2386
   637
        uedge = Parent::findUEdge(u, v, uedge);
deba@1991
   638
      }
deba@1991
   639
      return uedge;
deba@1991
   640
    }
deba@2031
   641
deba@2031
   642
    template <typename _Value>
deba@2031
   643
    class NodeMap 
deba@2031
   644
      : public SubMapExtender<Adaptor, 
deba@2031
   645
                              typename Parent::template NodeMap<_Value> > 
deba@2031
   646
    {
deba@2031
   647
    public:
deba@2031
   648
      typedef Adaptor Graph;
deba@2031
   649
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   650
                             template NodeMap<_Value> > Parent;
deba@2031
   651
    
deba@2386
   652
      NodeMap(const Graph& g) 
deba@2386
   653
	: Parent(g) {}
deba@2386
   654
      NodeMap(const Graph& g, const _Value& v) 
deba@2386
   655
	: Parent(g, v) {}
deba@2031
   656
    
deba@2031
   657
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
   658
	return operator=<NodeMap>(cmap);
deba@2031
   659
      }
deba@2031
   660
    
deba@2031
   661
      template <typename CMap>
deba@2031
   662
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   663
        Parent::operator=(cmap);
deba@2031
   664
	return *this;
deba@2031
   665
      }
deba@2031
   666
    };
deba@2031
   667
deba@2031
   668
    template <typename _Value>
deba@2031
   669
    class EdgeMap 
deba@2031
   670
      : public SubMapExtender<Adaptor, 
deba@2031
   671
                              typename Parent::template EdgeMap<_Value> > 
deba@2031
   672
    {
deba@2031
   673
    public:
deba@2031
   674
      typedef Adaptor Graph;
deba@2031
   675
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   676
                             template EdgeMap<_Value> > Parent;
deba@2031
   677
    
deba@2386
   678
      EdgeMap(const Graph& g) 
deba@2386
   679
	: Parent(g) {}
deba@2386
   680
      EdgeMap(const Graph& g, const _Value& v) 
deba@2386
   681
	: Parent(g, v) {}
deba@2031
   682
    
deba@2031
   683
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
   684
	return operator=<EdgeMap>(cmap);
deba@2031
   685
      }
deba@2031
   686
    
deba@2031
   687
      template <typename CMap>
deba@2031
   688
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   689
        Parent::operator=(cmap);
deba@2031
   690
	return *this;
deba@2031
   691
      }
deba@2031
   692
    };
deba@2031
   693
deba@2031
   694
    template <typename _Value>
deba@2031
   695
    class UEdgeMap 
deba@2031
   696
      : public SubMapExtender<Adaptor, 
deba@2031
   697
                              typename Parent::template UEdgeMap<_Value> > 
deba@2031
   698
    {
deba@2031
   699
    public:
deba@2031
   700
      typedef Adaptor Graph;
deba@2031
   701
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   702
                             template UEdgeMap<_Value> > Parent;
deba@2031
   703
    
deba@2386
   704
      UEdgeMap(const Graph& g) 
deba@2386
   705
	: Parent(g) {}
deba@2386
   706
      UEdgeMap(const Graph& g, const _Value& v) 
deba@2386
   707
	: Parent(g, v) {}
deba@2031
   708
    
deba@2031
   709
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@2031
   710
	return operator=<UEdgeMap>(cmap);
deba@2031
   711
      }
deba@2031
   712
    
deba@2031
   713
      template <typename CMap>
deba@2031
   714
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
   715
        Parent::operator=(cmap);
deba@2031
   716
	return *this;
deba@2031
   717
      }
deba@2031
   718
    };
deba@1979
   719
  };
deba@1979
   720
deba@1979
   721
  /// \ingroup graph_adaptors
deba@1979
   722
  ///
deba@1979
   723
  /// \brief A graph adaptor for hiding nodes and edges from an undirected 
deba@1979
   724
  /// graph.
deba@1979
   725
  /// 
deba@1979
   726
  /// SubUGraphAdaptor shows the undirected graph with filtered node-set and 
deba@1979
   727
  /// edge-set. If the \c checked parameter is true then it filters the edgeset
deba@1979
   728
  /// to do not get invalid edges without source or target.
deba@1979
   729
  /// 
deba@1979
   730
  /// If the \c checked template parameter is false then we have to note that 
deba@1979
   731
  /// the node-iterator cares only the filter on the node-set, and the 
deba@1979
   732
  /// edge-iterator cares only the filter on the edge-set.
deba@1979
   733
  /// This way the edge-map
deba@1979
   734
  /// should filter all edges which's source or target is filtered by the 
deba@1979
   735
  /// node-filter.
deba@1979
   736
  ///
deba@1979
   737
  template<typename _UGraph, typename NodeFilterMap, 
deba@1979
   738
	   typename UEdgeFilterMap, bool checked = true>
deba@1979
   739
  class SubUGraphAdaptor : 
deba@1979
   740
    public UGraphAdaptorExtender<
deba@1979
   741
    SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, checked> > {
deba@1979
   742
  public:
deba@1979
   743
    typedef _UGraph Graph;
deba@1979
   744
    typedef UGraphAdaptorExtender<
deba@1979
   745
      SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap> > Parent;
deba@1979
   746
  protected:
deba@1979
   747
    SubUGraphAdaptor() { }
deba@1979
   748
  public:
deba@1979
   749
    SubUGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map, 
deba@1979
   750
		    UEdgeFilterMap& _uedge_filter_map) { 
deba@1979
   751
      setGraph(_graph);
deba@1979
   752
      setNodeFilterMap(_node_filter_map);
deba@1979
   753
      setUEdgeFilterMap(_uedge_filter_map);
deba@1979
   754
    }
deba@1979
   755
  };
deba@1979
   756
deba@1980
   757
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   758
  SubUGraphAdaptor<const UGraph, NodeFilterMap, EdgeFilterMap>
deba@1980
   759
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   760
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   761
    return SubUGraphAdaptor<const UGraph, NodeFilterMap, EdgeFilterMap>
deba@1980
   762
      (graph, nfm, efm);
deba@1980
   763
  }
deba@1980
   764
deba@1980
   765
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   766
  SubUGraphAdaptor<const UGraph, const NodeFilterMap, EdgeFilterMap>
deba@1980
   767
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   768
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   769
    return SubUGraphAdaptor<const UGraph, const NodeFilterMap, EdgeFilterMap>
deba@1980
   770
      (graph, nfm, efm);
deba@1980
   771
  }
deba@1980
   772
deba@1980
   773
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   774
  SubUGraphAdaptor<const UGraph, NodeFilterMap, const EdgeFilterMap>
deba@1980
   775
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   776
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   777
    return SubUGraphAdaptor<const UGraph, NodeFilterMap, const EdgeFilterMap>
deba@1980
   778
      (graph, nfm, efm);
deba@1980
   779
  }
deba@1980
   780
deba@1980
   781
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   782
  SubUGraphAdaptor<const UGraph, const NodeFilterMap, const EdgeFilterMap>
deba@1980
   783
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   784
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   785
    return SubUGraphAdaptor<const UGraph, const NodeFilterMap, 
deba@1980
   786
      const EdgeFilterMap>(graph, nfm, efm);
deba@1980
   787
  }
deba@1980
   788
deba@1979
   789
  /// \ingroup graph_adaptors
deba@1979
   790
  ///
deba@1980
   791
  /// \brief An adaptor for hiding nodes from an undirected graph.
deba@1979
   792
  ///
deba@2422
   793
  /// An adaptor for hiding nodes from an undirected graph.  This
deba@2422
   794
  /// adaptor specializes SubUGraphAdaptor in the way that only the
deba@2422
   795
  /// node-set can be filtered. In usual case the checked parameter is
deba@2422
   796
  /// true, we get the induced subgraph. But if the checked parameter
deba@2422
   797
  /// is false then we can filter only isolated nodes.
deba@1979
   798
  template<typename _UGraph, typename NodeFilterMap, bool checked = true>
deba@1979
   799
  class NodeSubUGraphAdaptor : 
deba@1979
   800
    public SubUGraphAdaptor<_UGraph, NodeFilterMap, 
deba@1979
   801
                            ConstMap<typename _UGraph::UEdge, bool>, checked> {
deba@1979
   802
  public:
deba@1979
   803
    typedef SubUGraphAdaptor<_UGraph, NodeFilterMap, 
deba@1979
   804
                             ConstMap<typename _UGraph::UEdge, bool> > Parent;
deba@1979
   805
    typedef _UGraph Graph;
deba@1979
   806
  protected:
deba@1985
   807
    ConstMap<typename _UGraph::UEdge, bool> const_true_map;
deba@1991
   808
deba@1991
   809
    NodeSubUGraphAdaptor() : const_true_map(true) {
deba@1991
   810
      Parent::setUEdgeFilterMap(const_true_map);
deba@1991
   811
    }
deba@1991
   812
deba@1979
   813
  public:
deba@1979
   814
    NodeSubUGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map) : 
deba@1979
   815
      Parent(), const_true_map(true) { 
deba@1979
   816
      Parent::setGraph(_graph);
deba@1979
   817
      Parent::setNodeFilterMap(_node_filter_map);
deba@1979
   818
      Parent::setUEdgeFilterMap(const_true_map);
deba@1979
   819
    }
deba@1979
   820
  };
deba@1979
   821
deba@1979
   822
  template<typename UGraph, typename NodeFilterMap>
deba@1979
   823
  NodeSubUGraphAdaptor<const UGraph, NodeFilterMap>
deba@1979
   824
  nodeSubUGraphAdaptor(const UGraph& graph, NodeFilterMap& nfm) {
deba@1979
   825
    return NodeSubUGraphAdaptor<const UGraph, NodeFilterMap>(graph, nfm);
deba@1979
   826
  }
deba@1979
   827
deba@1979
   828
  template<typename UGraph, typename NodeFilterMap>
deba@1979
   829
  NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap>
deba@1979
   830
  nodeSubUGraphAdaptor(const UGraph& graph, const NodeFilterMap& nfm) {
deba@1979
   831
    return NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap>(graph, nfm);
deba@1979
   832
  }
deba@1979
   833
deba@2042
   834
  /// \ingroup graph_adaptors
deba@2042
   835
  ///
deba@1979
   836
  /// \brief An adaptor for hiding undirected edges from an undirected graph.
deba@1979
   837
  ///
deba@1979
   838
  /// \warning Graph adaptors are in even more experimental state
deba@1979
   839
  /// than the other parts of the lib. Use them at you own risk.
deba@1979
   840
  ///
deba@1979
   841
  /// An adaptor for hiding undirected edges from an undirected graph.
deba@1979
   842
  /// This adaptor specializes SubUGraphAdaptor in the way that
deba@1979
   843
  /// only the edge-set 
deba@1979
   844
  /// can be filtered.
deba@1979
   845
  template<typename _UGraph, typename UEdgeFilterMap>
deba@1979
   846
  class EdgeSubUGraphAdaptor : 
deba@1979
   847
    public SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>, 
deba@1979
   848
                            UEdgeFilterMap, false> {
deba@1979
   849
  public:
deba@1979
   850
    typedef SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>, 
deba@1979
   851
                             UEdgeFilterMap, false> Parent;
deba@1979
   852
    typedef _UGraph Graph;
deba@1979
   853
  protected:
deba@1979
   854
    ConstMap<typename Graph::Node, bool> const_true_map;
deba@1991
   855
deba@1991
   856
    EdgeSubUGraphAdaptor() : const_true_map(true) {
deba@1991
   857
      Parent::setNodeFilterMap(const_true_map);
deba@1991
   858
    }
deba@1991
   859
deba@1979
   860
  public:
deba@2031
   861
deba@1979
   862
    EdgeSubUGraphAdaptor(Graph& _graph, UEdgeFilterMap& _uedge_filter_map) : 
deba@1979
   863
      Parent(), const_true_map(true) { 
deba@1979
   864
      Parent::setGraph(_graph);
deba@1979
   865
      Parent::setNodeFilterMap(const_true_map);
deba@1979
   866
      Parent::setUEdgeFilterMap(_uedge_filter_map);
deba@1979
   867
    }
deba@2031
   868
deba@1979
   869
  };
deba@1979
   870
deba@1979
   871
  template<typename UGraph, typename EdgeFilterMap>
deba@1979
   872
  EdgeSubUGraphAdaptor<const UGraph, EdgeFilterMap>
deba@1979
   873
  edgeSubUGraphAdaptor(const UGraph& graph, EdgeFilterMap& efm) {
deba@1979
   874
    return EdgeSubUGraphAdaptor<const UGraph, EdgeFilterMap>(graph, efm);
deba@1979
   875
  }
deba@1979
   876
deba@1979
   877
  template<typename UGraph, typename EdgeFilterMap>
deba@1979
   878
  EdgeSubUGraphAdaptor<const UGraph, const EdgeFilterMap>
deba@1979
   879
  edgeSubUGraphAdaptor(const UGraph& graph, const EdgeFilterMap& efm) {
deba@1979
   880
    return EdgeSubUGraphAdaptor<const UGraph, const EdgeFilterMap>(graph, efm);
deba@1979
   881
  }
deba@1979
   882
deba@2087
   883
  /// \brief Base of direct undirected graph adaptor
deba@2087
   884
  ///
deba@2087
   885
  /// Base class of the direct undirected graph adaptor. All public member
deba@2087
   886
  /// of this class can be used with the DirUGraphAdaptor too.
deba@2087
   887
  /// \sa DirUGraphAdaptor
deba@1979
   888
  template <typename _UGraph, typename _DirectionMap>
deba@1980
   889
  class DirUGraphAdaptorBase {
deba@1979
   890
  public:
deba@1979
   891
    
deba@1979
   892
    typedef _UGraph Graph;
deba@1979
   893
    typedef _DirectionMap DirectionMap;
deba@1979
   894
deba@1979
   895
    typedef typename _UGraph::Node Node;
deba@1979
   896
    typedef typename _UGraph::UEdge Edge;
deba@1979
   897
   
deba@2087
   898
    /// \brief Reverse edge
deba@2087
   899
    /// 
deba@2087
   900
    /// It reverse the given edge. It simply negate the direction in the map.
deba@1991
   901
    void reverseEdge(const Edge& edge) {
deba@1991
   902
      direction->set(edge, !(*direction)[edge]);
deba@1991
   903
    }
deba@1991
   904
deba@1979
   905
    void first(Node& i) const { graph->first(i); }
deba@1979
   906
    void first(Edge& i) const { graph->first(i); }
deba@1979
   907
    void firstIn(Edge& i, const Node& n) const {
deba@1979
   908
      bool d;
deba@1979
   909
      graph->firstInc(i, d, n);
deba@1979
   910
      while (i != INVALID && d == (*direction)[i]) graph->nextInc(i, d);
deba@1979
   911
    }
deba@1979
   912
    void firstOut(Edge& i, const Node& n ) const { 
deba@1979
   913
      bool d;
deba@1979
   914
      graph->firstInc(i, d, n);
deba@1979
   915
      while (i != INVALID && d != (*direction)[i]) graph->nextInc(i, d);
deba@1979
   916
    }
deba@1979
   917
deba@1979
   918
    void next(Node& i) const { graph->next(i); }
deba@1979
   919
    void next(Edge& i) const { graph->next(i); }
deba@1979
   920
    void nextIn(Edge& i) const {
deba@1979
   921
      bool d = !(*direction)[i];
deba@1979
   922
      graph->nextInc(i, d);
deba@1979
   923
      while (i != INVALID && d == (*direction)[i]) graph->nextInc(i, d);
deba@1979
   924
    }
deba@1979
   925
    void nextOut(Edge& i) const {
deba@1979
   926
      bool d = (*direction)[i];
deba@1979
   927
      graph->nextInc(i, d);
deba@1979
   928
      while (i != INVALID && d != (*direction)[i]) graph->nextInc(i, d);
deba@1979
   929
    }
deba@1979
   930
deba@1979
   931
    Node source(const Edge& e) const { 
deba@1979
   932
      return (*direction)[e] ? graph->source(e) : graph->target(e); 
deba@1979
   933
    }
deba@1979
   934
    Node target(const Edge& e) const { 
deba@1979
   935
      return (*direction)[e] ? graph->target(e) : graph->source(e); 
deba@1979
   936
    }
deba@1979
   937
deba@1979
   938
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
deba@1979
   939
    int nodeNum() const { return graph->nodeNum(); }
deba@1979
   940
    
deba@1979
   941
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
deba@1979
   942
    int edgeNum() const { return graph->uEdgeNum(); }
deba@1979
   943
deba@1979
   944
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@2386
   945
    Edge findEdge(const Node& u, const Node& v, 
deba@1979
   946
		  const Edge& prev = INVALID) {
deba@1979
   947
      Edge edge = prev;
deba@1979
   948
      bool d = edge == INVALID ? true : (*direction)[edge];
deba@1979
   949
      if (d) {
deba@2386
   950
        edge = graph->findUEdge(u, v, edge);
deba@1979
   951
        while (edge != INVALID && !(*direction)[edge]) {
deba@2386
   952
          graph->findUEdge(u, v, edge);
deba@1979
   953
        }
deba@1979
   954
        if (edge != INVALID) return edge;
deba@1979
   955
      }
deba@2386
   956
      graph->findUEdge(v, u, edge);
deba@1979
   957
      while (edge != INVALID && (*direction)[edge]) {
deba@2386
   958
        graph->findUEdge(u, v, edge);
deba@1979
   959
      }
deba@1979
   960
      return edge;
deba@1979
   961
    }
deba@1979
   962
  
deba@1979
   963
    Node addNode() const { 
deba@1979
   964
      return Node(graph->addNode()); 
deba@1979
   965
    }
deba@1979
   966
deba@2386
   967
    Edge addEdge(const Node& u, const Node& v) const {
deba@2386
   968
      Edge edge = graph->addEdge(u, v);
deba@2386
   969
      direction->set(edge, graph->source(edge) == u);
deba@1979
   970
      return edge; 
deba@1979
   971
    }
deba@1979
   972
deba@1979
   973
    void erase(const Node& i) const { graph->erase(i); }
deba@1979
   974
    void erase(const Edge& i) const { graph->erase(i); }
deba@1979
   975
  
deba@1979
   976
    void clear() const { graph->clear(); }
deba@1979
   977
    
deba@1979
   978
    int id(const Node& v) const { return graph->id(v); }
deba@1979
   979
    int id(const Edge& e) const { return graph->id(e); }
deba@1979
   980
deba@1991
   981
    int maxNodeId() const {
deba@1991
   982
      return graph->maxNodeId();
deba@1979
   983
    }
deba@1979
   984
deba@1991
   985
    int maxEdgeId() const {
deba@1991
   986
      return graph->maxEdgeId();
deba@1991
   987
    }
deba@1991
   988
deba@1991
   989
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
deba@1991
   990
deba@2381
   991
    NodeNotifier& notifier(Node) const {
deba@2381
   992
      return graph->notifier(Node());
deba@1991
   993
    } 
deba@1991
   994
deba@1991
   995
    typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
deba@1991
   996
deba@2381
   997
    EdgeNotifier& notifier(Edge) const {
deba@2381
   998
      return graph->notifier(Edge());
deba@1991
   999
    } 
deba@1991
  1000
deba@1979
  1001
    template <typename _Value>
deba@1979
  1002
    class NodeMap : public _UGraph::template NodeMap<_Value> {
deba@1979
  1003
    public:
deba@2031
  1004
deba@1979
  1005
      typedef typename _UGraph::template NodeMap<_Value> Parent;
deba@2031
  1006
deba@1980
  1007
      explicit NodeMap(const DirUGraphAdaptorBase& ga) 
deba@2031
  1008
	: Parent(*ga.graph) {}
deba@2031
  1009
deba@1980
  1010
      NodeMap(const DirUGraphAdaptorBase& ga, const _Value& value)
deba@2031
  1011
	: Parent(*ga.graph, value) {}
deba@2031
  1012
deba@2031
  1013
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
  1014
        return operator=<NodeMap>(cmap);
deba@2031
  1015
      }
deba@2031
  1016
deba@2031
  1017
      template <typename CMap>
deba@2031
  1018
      NodeMap& operator=(const CMap& cmap) {
deba@2031
  1019
        Parent::operator=(cmap);
deba@2031
  1020
        return *this;
deba@2031
  1021
      }
deba@2031
  1022
deba@1979
  1023
    };
deba@1979
  1024
deba@1979
  1025
    template <typename _Value>
deba@1979
  1026
    class EdgeMap : public _UGraph::template UEdgeMap<_Value> {
deba@1979
  1027
    public:
deba@2031
  1028
deba@1980
  1029
      typedef typename _UGraph::template UEdgeMap<_Value> Parent;
deba@2031
  1030
deba@1980
  1031
      explicit EdgeMap(const DirUGraphAdaptorBase& ga) 
deba@1979
  1032
	: Parent(*ga.graph) { }
deba@2031
  1033
deba@1980
  1034
      EdgeMap(const DirUGraphAdaptorBase& ga, const _Value& value)
deba@1979
  1035
	: Parent(*ga.graph, value) { }
deba@2031
  1036
deba@2031
  1037
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
  1038
        return operator=<EdgeMap>(cmap);
deba@2031
  1039
      }
deba@2031
  1040
deba@2031
  1041
      template <typename CMap>
deba@2031
  1042
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
  1043
        Parent::operator=(cmap);
deba@2031
  1044
        return *this;
deba@2031
  1045
      }
deba@1979
  1046
    };
deba@1979
  1047
deba@1979
  1048
    
deba@1979
  1049
deba@1979
  1050
  protected:
deba@1979
  1051
    Graph* graph;
deba@1979
  1052
    DirectionMap* direction;
deba@1979
  1053
deba@1979
  1054
    void setDirectionMap(DirectionMap& _direction) {
deba@1979
  1055
      direction = &_direction;
deba@1979
  1056
    }
deba@1979
  1057
deba@1979
  1058
    void setGraph(Graph& _graph) {
deba@1979
  1059
      graph = &_graph;
deba@1979
  1060
    }
deba@1979
  1061
deba@1979
  1062
  };
deba@1979
  1063
deba@1979
  1064
deba@1980
  1065
  /// \ingroup graph_adaptors
deba@1991
  1066
  ///
deba@1991
  1067
  /// \brief A directed graph is made from an undirected graph by an adaptor
deba@1980
  1068
  ///
deba@2087
  1069
  /// This adaptor gives a direction for each uedge in the undirected
deba@2087
  1070
  /// graph. The direction of the edges stored in the
deba@2087
  1071
  /// DirectionMap. This map is a bool map on the undirected edges. If
deba@2087
  1072
  /// the uedge is mapped to true then the direction of the directed
deba@2087
  1073
  /// edge will be the same as the default direction of the uedge. The
deba@2087
  1074
  /// edges can be easily reverted by the \ref
deba@2087
  1075
  /// DirUGraphAdaptorBase::reverseEdge "reverseEdge()" member in the
deba@2087
  1076
  /// adaptor.
deba@2087
  1077
  ///
deba@2087
  1078
  /// It can be used to solve orientation problems on directed graphs.
deba@2087
  1079
  /// By example how can we orient an undirected graph to get the minimum
deba@2087
  1080
  /// number of strongly connected components. If we orient the edges with
deba@2087
  1081
  /// the dfs algorithm out from the source then we will get such an 
deba@2087
  1082
  /// orientation. 
deba@2087
  1083
  ///
deba@2087
  1084
  /// We use the \ref DfsVisitor "visitor" interface of the 
deba@2087
  1085
  /// \ref DfsVisit "dfs" algorithm:
deba@2087
  1086
  ///\code
deba@2087
  1087
  /// template <typename DirMap>
deba@2087
  1088
  /// class OrientVisitor : public DfsVisitor<UGraph> {
deba@2087
  1089
  /// public:
deba@2087
  1090
  ///
deba@2087
  1091
  ///   OrientVisitor(const UGraph& ugraph, DirMap& dirMap)
deba@2087
  1092
  ///     : _ugraph(ugraph), _dirMap(dirMap), _processed(ugraph, false) {}
deba@2087
  1093
  ///
deba@2087
  1094
  ///   void discover(const Edge& edge) {
deba@2087
  1095
  ///     _processed.set(edge, true);
deba@2087
  1096
  ///     _dirMap.set(edge, _ugraph.direction(edge));
deba@2087
  1097
  ///   }
deba@2087
  1098
  ///
deba@2087
  1099
  ///   void examine(const Edge& edge) {
deba@2087
  1100
  ///     if (_processed[edge]) return;
deba@2087
  1101
  ///     _processed.set(edge, true);
deba@2087
  1102
  ///     _dirMap.set(edge, _ugraph.direction(edge));
deba@2087
  1103
  ///   }  
deba@2087
  1104
  /// 
deba@2087
  1105
  /// private:
deba@2087
  1106
  ///   const UGraph& _ugraph;  
deba@2087
  1107
  ///   DirMap& _dirMap;
deba@2087
  1108
  ///   UGraph::UEdgeMap<bool> _processed;
deba@2087
  1109
  /// };
deba@2087
  1110
  ///\endcode
deba@2087
  1111
  ///
deba@2087
  1112
  /// And now we can use the orientation:
deba@2087
  1113
  ///\code
deba@2087
  1114
  /// UGraph::UEdgeMap<bool> dmap(ugraph);
deba@2087
  1115
  ///
deba@2087
  1116
  /// typedef OrientVisitor<UGraph::UEdgeMap<bool> > Visitor;
deba@2087
  1117
  /// Visitor visitor(ugraph, dmap);
deba@2087
  1118
  ///
deba@2087
  1119
  /// DfsVisit<UGraph, Visitor> dfs(ugraph, visitor);
deba@2087
  1120
  ///
deba@2087
  1121
  /// dfs.run();
deba@2087
  1122
  ///
deba@2087
  1123
  /// typedef DirUGraphAdaptor<UGraph> DGraph;
deba@2087
  1124
  /// DGraph dgraph(ugraph, dmap);
deba@2087
  1125
  ///
deba@2087
  1126
  /// LEMON_ASSERT(countStronglyConnectedComponents(dgraph) == 
deba@2087
  1127
  ///              countBiEdgeConnectedComponents(ugraph), "Wrong Orientation");
deba@2087
  1128
  ///\endcode
deba@2087
  1129
  ///
deba@2087
  1130
  /// The number of the bi-connected components is a lower bound for
deba@2087
  1131
  /// the number of the strongly connected components in the directed
deba@2087
  1132
  /// graph because if we contract the bi-connected components to
deba@2087
  1133
  /// nodes we will get a tree therefore we cannot orient edges in
deba@2087
  1134
  /// both direction between bi-connected components. In the other way
deba@2087
  1135
  /// the algorithm will orient one component to be strongly
deba@2087
  1136
  /// connected. The two relations proof that the assertion will
deba@2087
  1137
  /// be always true and the found solution is optimal.
deba@2087
  1138
  ///
deba@2087
  1139
  /// \sa DirUGraphAdaptorBase
deba@2087
  1140
  /// \sa dirUGraphAdaptor
deba@1980
  1141
  template<typename _Graph, 
deba@1980
  1142
           typename DirectionMap = typename _Graph::template UEdgeMap<bool> > 
deba@1980
  1143
  class DirUGraphAdaptor : 
deba@1979
  1144
    public GraphAdaptorExtender<
deba@1980
  1145
    DirUGraphAdaptorBase<_Graph, DirectionMap> > {
deba@1979
  1146
  public:
deba@1979
  1147
    typedef _Graph Graph;
deba@1979
  1148
    typedef GraphAdaptorExtender<
deba@1980
  1149
      DirUGraphAdaptorBase<_Graph, DirectionMap> > Parent;
deba@1979
  1150
  protected:
deba@1980
  1151
    DirUGraphAdaptor() { }
deba@1979
  1152
  public:
deba@2087
  1153
    
deba@2087
  1154
    /// \brief Constructor of the adaptor
deba@2087
  1155
    ///
deba@2087
  1156
    /// Constructor of the adaptor
deba@1980
  1157
    DirUGraphAdaptor(_Graph& _graph, DirectionMap& _direction_map) { 
deba@1979
  1158
      setGraph(_graph);
deba@1979
  1159
      setDirectionMap(_direction_map);
deba@1979
  1160
    }
deba@1979
  1161
  };
deba@1979
  1162
deba@2087
  1163
  /// \brief Just gives back a DirUGraphAdaptor
deba@2087
  1164
  ///
deba@2087
  1165
  /// Just gives back a DirUGraphAdaptor
deba@1979
  1166
  template<typename UGraph, typename DirectionMap>
deba@1980
  1167
  DirUGraphAdaptor<const UGraph, DirectionMap>
deba@1980
  1168
  dirUGraphAdaptor(const UGraph& graph, DirectionMap& dm) {
deba@1980
  1169
    return DirUGraphAdaptor<const UGraph, DirectionMap>(graph, dm);
deba@1979
  1170
  }
deba@1979
  1171
deba@1979
  1172
  template<typename UGraph, typename DirectionMap>
deba@1980
  1173
  DirUGraphAdaptor<const UGraph, const DirectionMap>
deba@1980
  1174
  dirUGraphAdaptor(const UGraph& graph, const DirectionMap& dm) {
deba@1980
  1175
    return DirUGraphAdaptor<const UGraph, const DirectionMap>(graph, dm);
deba@1979
  1176
  }
deba@1979
  1177
deba@1979
  1178
}
deba@1979
  1179
deba@1979
  1180
#endif