lemon/ugraph_adaptor.h
author alpar
Tue, 17 Oct 2006 11:01:35 +0000
changeset 2250 b8fbffd35445
parent 2087 67258b5a057b
child 2381 0248790c66ea
permissions -rw-r--r--
Compilation warning resolved.
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
 *
deba@1979
     5
 * Copyright (C) 2003-2006
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@1979
   102
    Edge findEdge(const Node& source, const Node& target, 
deba@1979
   103
		  const Edge& prev = INVALID) {
deba@1979
   104
      return graph->findEdge(source, target, prev);
deba@1979
   105
    }
deba@1979
   106
    UEdge findUEdge(const Node& source, const Node& target, 
deba@1979
   107
                    const UEdge& prev = INVALID) {
deba@1979
   108
      return graph->findUEdge(source, target, prev);
deba@1979
   109
    }
deba@1979
   110
  
deba@1979
   111
    Node addNode() const { return graph->addNode(); }
deba@1979
   112
    UEdge addEdge(const Node& source, const Node& target) const { 
deba@1979
   113
      return graph->addEdge(source, target); 
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@2031
   128
    Node fromNodeId(int id) const {
deba@2031
   129
      return graph->fromNodeId(id);
deba@2031
   130
    }
deba@2031
   131
deba@2031
   132
    Edge fromEdgeId(int id) const {
deba@2031
   133
      return graph->fromEdgeId(id);
deba@2031
   134
    }
deba@2031
   135
deba@2031
   136
    UEdge fromUEdgeId(int id) const {
deba@2031
   137
      return graph->fromUEdgeId(id);
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@1991
   154
    NodeNotifier& getNotifier(Node) const {
deba@1991
   155
      return graph->getNotifier(Node());
deba@1991
   156
    } 
deba@1991
   157
deba@1991
   158
    typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
deba@1991
   159
deba@1991
   160
    EdgeNotifier& getNotifier(Edge) const {
deba@1991
   161
      return graph->getNotifier(Edge());
deba@1991
   162
    } 
deba@1991
   163
deba@1991
   164
    typedef typename ItemSetTraits<Graph, UEdge>::ItemNotifier UEdgeNotifier;
deba@1991
   165
deba@1991
   166
    UEdgeNotifier& getNotifier(UEdge) const {
deba@1991
   167
      return graph->getNotifier(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@1979
   314
            || !(*node_filter_map)[Parent::target(i)])) Parent::nextInc(i, d); 
deba@1979
   315
    }
deba@1979
   316
deba@1979
   317
    void next(Node& i) const { 
deba@1979
   318
      Parent::next(i); 
deba@1979
   319
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1979
   320
    }
deba@1979
   321
deba@1979
   322
    void next(Edge& i) const { 
deba@1979
   323
      Parent::next(i); 
deba@1979
   324
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   325
	     || !(*node_filter_map)[Parent::source(i)]
deba@1979
   326
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1979
   327
    }
deba@1979
   328
deba@1979
   329
    void next(UEdge& i) const { 
deba@1979
   330
      Parent::next(i); 
deba@1979
   331
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   332
	     || !(*node_filter_map)[Parent::source(i)]
deba@1979
   333
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1979
   334
    }
deba@1979
   335
deba@1979
   336
    void nextIn(Edge& i) const { 
deba@1979
   337
      Parent::nextIn(i); 
deba@1979
   338
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   339
	     || !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i); 
deba@1979
   340
    }
deba@1979
   341
deba@1979
   342
    void nextOut(Edge& i) const { 
deba@1979
   343
      Parent::nextOut(i); 
deba@1979
   344
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   345
	     || !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i); 
deba@1979
   346
    }
deba@1979
   347
deba@1979
   348
    void nextInc(UEdge& i, bool& d) const { 
deba@1979
   349
      Parent::nextInc(i, d); 
deba@1979
   350
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   351
            || !(*node_filter_map)[Parent::source(i)])) Parent::nextInc(i, d); 
deba@1979
   352
    }
deba@1979
   353
deba@2084
   354
    /// \brief Hide the given node in the graph.
deba@2084
   355
    ///
deba@1979
   356
    /// This function hides \c n in the graph, i.e. the iteration 
deba@1979
   357
    /// jumps over it. This is done by simply setting the value of \c n  
deba@1979
   358
    /// to be false in the corresponding node-map.
deba@1979
   359
    void hide(const Node& n) const { node_filter_map->set(n, false); }
deba@1979
   360
deba@2084
   361
    /// \brief Hide the given undirected edge in the graph.
deba@2084
   362
    ///
deba@1979
   363
    /// This function hides \c e in the graph, i.e. the iteration 
deba@1979
   364
    /// jumps over it. This is done by simply setting the value of \c e  
deba@2084
   365
    /// to be false in the corresponding uedge-map.
deba@1979
   366
    void hide(const UEdge& e) const { uedge_filter_map->set(e, false); }
deba@1979
   367
deba@2084
   368
    /// \brief Unhide the given node in the graph.
deba@2084
   369
    ///
deba@1979
   370
    /// The value of \c n is set to be true in the node-map which stores 
deba@1979
   371
    /// hide information. If \c n was hidden previuosly, then it is shown 
deba@1979
   372
    /// again
deba@1979
   373
     void unHide(const Node& n) const { node_filter_map->set(n, true); }
deba@1979
   374
deba@2084
   375
    /// \brief Hide the given undirected edge in the graph.
deba@2084
   376
    ///
deba@2084
   377
    /// The value of \c e is set to be true in the uedge-map which stores 
deba@1979
   378
    /// hide information. If \c e was hidden previuosly, then it is shown 
deba@1979
   379
    /// again
deba@1979
   380
    void unHide(const UEdge& e) const { uedge_filter_map->set(e, true); }
deba@1979
   381
deba@2084
   382
    /// \brief Returns true if \c n is hidden.
deba@2084
   383
    ///
deba@1979
   384
    /// Returns true if \c n is hidden.
deba@1979
   385
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
deba@1979
   386
deba@2084
   387
    /// \brief Returns true if \c e is hidden.
deba@1979
   388
    ///
deba@2084
   389
    /// Returns true if \c e is hidden.
deba@1979
   390
    bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; }
deba@1979
   391
deba@1979
   392
    typedef False NodeNumTag;
deba@1979
   393
    typedef False EdgeNumTag;
deba@1991
   394
deba@1991
   395
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1991
   396
    Edge findEdge(const Node& source, const Node& target, 
deba@1991
   397
		  const Edge& prev = INVALID) {
deba@1991
   398
      if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
deba@1991
   399
        return INVALID;
deba@1991
   400
      }
deba@1991
   401
      Edge edge = Parent::findEdge(source, target, prev);
deba@1991
   402
      while (edge != INVALID && !(*uedge_filter_map)[edge]) {
deba@1991
   403
        edge = Parent::findEdge(source, target, edge);
deba@1991
   404
      }
deba@1991
   405
      return edge;
deba@1991
   406
    }
deba@1991
   407
    UEdge findUEdge(const Node& source, const Node& target, 
deba@1991
   408
		  const UEdge& prev = INVALID) {
deba@1991
   409
      if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
deba@1991
   410
        return INVALID;
deba@1991
   411
      }
deba@1991
   412
      UEdge uedge = Parent::findUEdge(source, target, prev);
deba@1991
   413
      while (uedge != INVALID && !(*uedge_filter_map)[uedge]) {
deba@1991
   414
        uedge = Parent::findUEdge(source, target, uedge);
deba@1991
   415
      }
deba@1991
   416
      return uedge;
deba@1991
   417
    }
deba@2031
   418
deba@2031
   419
    template <typename _Value>
deba@2031
   420
    class NodeMap 
deba@2031
   421
      : public SubMapExtender<Adaptor, 
deba@2031
   422
                              typename Parent::template NodeMap<_Value> > 
deba@2031
   423
    {
deba@2031
   424
    public:
deba@2031
   425
      typedef Adaptor Graph;
deba@2031
   426
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   427
                             template NodeMap<_Value> > Parent;
deba@2031
   428
    
deba@2031
   429
      NodeMap(const Graph& graph) 
deba@2031
   430
	: Parent(graph) {}
deba@2031
   431
      NodeMap(const Graph& graph, const _Value& value) 
deba@2031
   432
	: Parent(graph, value) {}
deba@2031
   433
    
deba@2031
   434
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
   435
	return operator=<NodeMap>(cmap);
deba@2031
   436
      }
deba@2031
   437
    
deba@2031
   438
      template <typename CMap>
deba@2031
   439
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   440
        Parent::operator=(cmap);
deba@2031
   441
	return *this;
deba@2031
   442
      }
deba@2031
   443
    };
deba@2031
   444
deba@2031
   445
    template <typename _Value>
deba@2031
   446
    class EdgeMap 
deba@2031
   447
      : public SubMapExtender<Adaptor, 
deba@2031
   448
                              typename Parent::template EdgeMap<_Value> > 
deba@2031
   449
    {
deba@2031
   450
    public:
deba@2031
   451
      typedef Adaptor Graph;
deba@2031
   452
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   453
                             template EdgeMap<_Value> > Parent;
deba@2031
   454
    
deba@2031
   455
      EdgeMap(const Graph& graph) 
deba@2031
   456
	: Parent(graph) {}
deba@2031
   457
      EdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   458
	: Parent(graph, value) {}
deba@2031
   459
    
deba@2031
   460
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
   461
	return operator=<EdgeMap>(cmap);
deba@2031
   462
      }
deba@2031
   463
    
deba@2031
   464
      template <typename CMap>
deba@2031
   465
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   466
        Parent::operator=(cmap);
deba@2031
   467
	return *this;
deba@2031
   468
      }
deba@2031
   469
    };
deba@2031
   470
deba@2031
   471
    template <typename _Value>
deba@2031
   472
    class UEdgeMap 
deba@2031
   473
      : public SubMapExtender<Adaptor, 
deba@2031
   474
                              typename Parent::template UEdgeMap<_Value> > 
deba@2031
   475
    {
deba@2031
   476
    public:
deba@2031
   477
      typedef Adaptor Graph;
deba@2031
   478
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   479
                             template UEdgeMap<_Value> > Parent;
deba@2031
   480
    
deba@2031
   481
      UEdgeMap(const Graph& graph) 
deba@2031
   482
	: Parent(graph) {}
deba@2031
   483
      UEdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   484
	: Parent(graph, value) {}
deba@2031
   485
    
deba@2031
   486
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@2031
   487
	return operator=<UEdgeMap>(cmap);
deba@2031
   488
      }
deba@2031
   489
    
deba@2031
   490
      template <typename CMap>
deba@2031
   491
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
   492
        Parent::operator=(cmap);
deba@2031
   493
	return *this;
deba@2031
   494
      }
deba@2031
   495
    };
deba@2031
   496
deba@1979
   497
  };
deba@1979
   498
deba@1979
   499
  template <typename _UGraph, typename NodeFilterMap, typename UEdgeFilterMap>
deba@1979
   500
  class SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, false> 
deba@1979
   501
    : public UGraphAdaptorBase<_UGraph> {
deba@1979
   502
  public:
deba@1979
   503
    typedef _UGraph Graph;
deba@2031
   504
    typedef SubUGraphAdaptorBase Adaptor;
deba@1979
   505
    typedef UGraphAdaptorBase<_UGraph> Parent;
deba@1979
   506
  protected:
deba@1979
   507
    NodeFilterMap* node_filter_map;
deba@1979
   508
    UEdgeFilterMap* uedge_filter_map;
deba@1979
   509
    SubUGraphAdaptorBase() : Parent(), 
deba@1979
   510
			    node_filter_map(0), uedge_filter_map(0) { }
deba@1979
   511
deba@1979
   512
    void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
deba@1979
   513
      node_filter_map=&_node_filter_map;
deba@1979
   514
    }
deba@1979
   515
    void setUEdgeFilterMap(UEdgeFilterMap& _uedge_filter_map) {
deba@1979
   516
      uedge_filter_map=&_uedge_filter_map;
deba@1979
   517
    }
deba@1979
   518
deba@1979
   519
  public:
deba@1979
   520
deba@1979
   521
    typedef typename Parent::Node Node;
deba@1979
   522
    typedef typename Parent::Edge Edge;
deba@1979
   523
    typedef typename Parent::UEdge UEdge;
deba@1979
   524
deba@1979
   525
    void first(Node& i) const { 
deba@1979
   526
      Parent::first(i); 
deba@1979
   527
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1979
   528
    }
deba@1979
   529
deba@1979
   530
    void first(Edge& i) const { 
deba@1979
   531
      Parent::first(i); 
deba@1979
   532
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i); 
deba@1979
   533
    }
deba@1979
   534
deba@1979
   535
    void first(UEdge& i) const { 
deba@1979
   536
      Parent::first(i); 
deba@1979
   537
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i); 
deba@1979
   538
    }
deba@1979
   539
deba@1979
   540
    void firstIn(Edge& i, const Node& n) const { 
deba@1979
   541
      Parent::firstIn(i, n); 
deba@1979
   542
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextIn(i); 
deba@1979
   543
    }
deba@1979
   544
deba@1979
   545
    void firstOut(Edge& i, const Node& n) const { 
deba@1979
   546
      Parent::firstOut(i, n); 
deba@1979
   547
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextOut(i); 
deba@1979
   548
    }
deba@1979
   549
deba@1979
   550
    void firstInc(UEdge& i, bool& d, const Node& n) const { 
deba@1979
   551
      Parent::firstInc(i, d, n); 
deba@1979
   552
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextInc(i, d); 
deba@1979
   553
    }
deba@1979
   554
deba@1979
   555
    void next(Node& i) const { 
deba@1979
   556
      Parent::next(i); 
deba@1979
   557
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1979
   558
    }
deba@1979
   559
    void next(Edge& i) const { 
deba@1979
   560
      Parent::next(i); 
deba@1979
   561
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i); 
deba@1979
   562
    }
deba@1979
   563
    void next(UEdge& i) const { 
deba@1979
   564
      Parent::next(i); 
deba@1979
   565
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i); 
deba@1979
   566
    }
deba@1979
   567
    void nextIn(Edge& i) const { 
deba@1979
   568
      Parent::nextIn(i); 
deba@1979
   569
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextIn(i); 
deba@1979
   570
    }
deba@1979
   571
deba@1979
   572
    void nextOut(Edge& i) const { 
deba@1979
   573
      Parent::nextOut(i); 
deba@1979
   574
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextOut(i); 
deba@1979
   575
    }
deba@1979
   576
    void nextInc(UEdge& i, bool& d) const { 
deba@1979
   577
      Parent::nextInc(i, d); 
deba@1979
   578
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextInc(i, d); 
deba@1979
   579
    }
deba@1979
   580
deba@2084
   581
    /// \brief Hide the given node in the graph.
deba@2084
   582
    ///
deba@1979
   583
    /// This function hides \c n in the graph, i.e. the iteration 
deba@1979
   584
    /// jumps over it. This is done by simply setting the value of \c n  
deba@1979
   585
    /// to be false in the corresponding node-map.
deba@1979
   586
    void hide(const Node& n) const { node_filter_map->set(n, false); }
deba@1979
   587
deba@2084
   588
    /// \brief Hide the given undirected edge in the graph.
deba@2084
   589
    ///
deba@1979
   590
    /// This function hides \c e in the graph, i.e. the iteration 
deba@1979
   591
    /// jumps over it. This is done by simply setting the value of \c e  
deba@2084
   592
    /// to be false in the corresponding uedge-map.
deba@1979
   593
    void hide(const UEdge& e) const { uedge_filter_map->set(e, false); }
deba@1979
   594
deba@2084
   595
    /// \brief Unhide the given node in the graph.
deba@2084
   596
    ///
deba@1979
   597
    /// The value of \c n is set to be true in the node-map which stores 
deba@1979
   598
    /// hide information. If \c n was hidden previuosly, then it is shown 
deba@1979
   599
    /// again
deba@1979
   600
     void unHide(const Node& n) const { node_filter_map->set(n, true); }
deba@1979
   601
deba@2084
   602
    /// \brief Hide the given undirected edge in the graph.
deba@2084
   603
    ///
deba@2084
   604
    /// The value of \c e is set to be true in the uedge-map which stores 
deba@1979
   605
    /// hide information. If \c e was hidden previuosly, then it is shown 
deba@1979
   606
    /// again
deba@1979
   607
    void unHide(const UEdge& e) const { uedge_filter_map->set(e, true); }
deba@1979
   608
deba@2084
   609
    /// \brief Returns true if \c n is hidden.
deba@2084
   610
    ///
deba@1979
   611
    /// Returns true if \c n is hidden.
deba@1979
   612
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
deba@1979
   613
deba@2084
   614
    /// \brief Returns true if \c e is hidden.
deba@1979
   615
    ///
deba@2084
   616
    /// Returns true if \c e is hidden.
deba@1979
   617
    bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; }
deba@1979
   618
deba@1979
   619
    typedef False NodeNumTag;
deba@1979
   620
    typedef False EdgeNumTag;
deba@1991
   621
deba@1991
   622
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1991
   623
    Edge findEdge(const Node& source, const Node& target, 
deba@1991
   624
		  const Edge& prev = INVALID) {
deba@1991
   625
      Edge edge = Parent::findEdge(source, target, prev);
deba@1991
   626
      while (edge != INVALID && !(*uedge_filter_map)[edge]) {
deba@1991
   627
        edge = Parent::findEdge(source, target, edge);
deba@1991
   628
      }
deba@1991
   629
      return edge;
deba@1991
   630
    }
deba@1991
   631
    UEdge findUEdge(const Node& source, const Node& target, 
deba@1991
   632
		  const UEdge& prev = INVALID) {
deba@1991
   633
      UEdge uedge = Parent::findUEdge(source, target, prev);
deba@1991
   634
      while (uedge != INVALID && !(*uedge_filter_map)[uedge]) {
deba@1991
   635
        uedge = Parent::findUEdge(source, target, uedge);
deba@1991
   636
      }
deba@1991
   637
      return uedge;
deba@1991
   638
    }
deba@2031
   639
deba@2031
   640
    template <typename _Value>
deba@2031
   641
    class NodeMap 
deba@2031
   642
      : public SubMapExtender<Adaptor, 
deba@2031
   643
                              typename Parent::template NodeMap<_Value> > 
deba@2031
   644
    {
deba@2031
   645
    public:
deba@2031
   646
      typedef Adaptor Graph;
deba@2031
   647
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   648
                             template NodeMap<_Value> > Parent;
deba@2031
   649
    
deba@2031
   650
      NodeMap(const Graph& graph) 
deba@2031
   651
	: Parent(graph) {}
deba@2031
   652
      NodeMap(const Graph& graph, const _Value& value) 
deba@2031
   653
	: Parent(graph, value) {}
deba@2031
   654
    
deba@2031
   655
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
   656
	return operator=<NodeMap>(cmap);
deba@2031
   657
      }
deba@2031
   658
    
deba@2031
   659
      template <typename CMap>
deba@2031
   660
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   661
        Parent::operator=(cmap);
deba@2031
   662
	return *this;
deba@2031
   663
      }
deba@2031
   664
    };
deba@2031
   665
deba@2031
   666
    template <typename _Value>
deba@2031
   667
    class EdgeMap 
deba@2031
   668
      : public SubMapExtender<Adaptor, 
deba@2031
   669
                              typename Parent::template EdgeMap<_Value> > 
deba@2031
   670
    {
deba@2031
   671
    public:
deba@2031
   672
      typedef Adaptor Graph;
deba@2031
   673
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   674
                             template EdgeMap<_Value> > Parent;
deba@2031
   675
    
deba@2031
   676
      EdgeMap(const Graph& graph) 
deba@2031
   677
	: Parent(graph) {}
deba@2031
   678
      EdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   679
	: Parent(graph, value) {}
deba@2031
   680
    
deba@2031
   681
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
   682
	return operator=<EdgeMap>(cmap);
deba@2031
   683
      }
deba@2031
   684
    
deba@2031
   685
      template <typename CMap>
deba@2031
   686
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   687
        Parent::operator=(cmap);
deba@2031
   688
	return *this;
deba@2031
   689
      }
deba@2031
   690
    };
deba@2031
   691
deba@2031
   692
    template <typename _Value>
deba@2031
   693
    class UEdgeMap 
deba@2031
   694
      : public SubMapExtender<Adaptor, 
deba@2031
   695
                              typename Parent::template UEdgeMap<_Value> > 
deba@2031
   696
    {
deba@2031
   697
    public:
deba@2031
   698
      typedef Adaptor Graph;
deba@2031
   699
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   700
                             template UEdgeMap<_Value> > Parent;
deba@2031
   701
    
deba@2031
   702
      UEdgeMap(const Graph& graph) 
deba@2031
   703
	: Parent(graph) {}
deba@2031
   704
      UEdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   705
	: Parent(graph, value) {}
deba@2031
   706
    
deba@2031
   707
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@2031
   708
	return operator=<UEdgeMap>(cmap);
deba@2031
   709
      }
deba@2031
   710
    
deba@2031
   711
      template <typename CMap>
deba@2031
   712
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
   713
        Parent::operator=(cmap);
deba@2031
   714
	return *this;
deba@2031
   715
      }
deba@2031
   716
    };
deba@1979
   717
  };
deba@1979
   718
deba@1979
   719
  /// \ingroup graph_adaptors
deba@1979
   720
  ///
deba@1979
   721
  /// \brief A graph adaptor for hiding nodes and edges from an undirected 
deba@1979
   722
  /// graph.
deba@1979
   723
  /// 
deba@1979
   724
  /// SubUGraphAdaptor shows the undirected graph with filtered node-set and 
deba@1979
   725
  /// edge-set. If the \c checked parameter is true then it filters the edgeset
deba@1979
   726
  /// to do not get invalid edges without source or target.
deba@1979
   727
  /// 
deba@1979
   728
  /// If the \c checked template parameter is false then we have to note that 
deba@1979
   729
  /// the node-iterator cares only the filter on the node-set, and the 
deba@1979
   730
  /// edge-iterator cares only the filter on the edge-set.
deba@1979
   731
  /// This way the edge-map
deba@1979
   732
  /// should filter all edges which's source or target is filtered by the 
deba@1979
   733
  /// node-filter.
deba@1979
   734
  ///
deba@1979
   735
  template<typename _UGraph, typename NodeFilterMap, 
deba@1979
   736
	   typename UEdgeFilterMap, bool checked = true>
deba@1979
   737
  class SubUGraphAdaptor : 
deba@1979
   738
    public UGraphAdaptorExtender<
deba@1979
   739
    SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, checked> > {
deba@1979
   740
  public:
deba@1979
   741
    typedef _UGraph Graph;
deba@1979
   742
    typedef UGraphAdaptorExtender<
deba@1979
   743
      SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap> > Parent;
deba@1979
   744
  protected:
deba@1979
   745
    SubUGraphAdaptor() { }
deba@1979
   746
  public:
deba@1979
   747
    SubUGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map, 
deba@1979
   748
		    UEdgeFilterMap& _uedge_filter_map) { 
deba@1979
   749
      setGraph(_graph);
deba@1979
   750
      setNodeFilterMap(_node_filter_map);
deba@1979
   751
      setUEdgeFilterMap(_uedge_filter_map);
deba@1979
   752
    }
deba@1979
   753
  };
deba@1979
   754
deba@1980
   755
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   756
  SubUGraphAdaptor<const UGraph, NodeFilterMap, EdgeFilterMap>
deba@1980
   757
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   758
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   759
    return SubUGraphAdaptor<const UGraph, NodeFilterMap, EdgeFilterMap>
deba@1980
   760
      (graph, nfm, efm);
deba@1980
   761
  }
deba@1980
   762
deba@1980
   763
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   764
  SubUGraphAdaptor<const UGraph, const NodeFilterMap, EdgeFilterMap>
deba@1980
   765
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   766
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   767
    return SubUGraphAdaptor<const UGraph, const NodeFilterMap, EdgeFilterMap>
deba@1980
   768
      (graph, nfm, efm);
deba@1980
   769
  }
deba@1980
   770
deba@1980
   771
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   772
  SubUGraphAdaptor<const UGraph, NodeFilterMap, const EdgeFilterMap>
deba@1980
   773
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   774
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   775
    return SubUGraphAdaptor<const UGraph, NodeFilterMap, const EdgeFilterMap>
deba@1980
   776
      (graph, nfm, efm);
deba@1980
   777
  }
deba@1980
   778
deba@1980
   779
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   780
  SubUGraphAdaptor<const UGraph, const NodeFilterMap, const EdgeFilterMap>
deba@1980
   781
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   782
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   783
    return SubUGraphAdaptor<const UGraph, const NodeFilterMap, 
deba@1980
   784
      const EdgeFilterMap>(graph, nfm, efm);
deba@1980
   785
  }
deba@1980
   786
deba@1979
   787
  /// \ingroup graph_adaptors
deba@1979
   788
  ///
deba@1980
   789
  /// \brief An adaptor for hiding nodes from an undirected graph.
deba@1979
   790
  ///
deba@1979
   791
  /// An adaptor for hiding nodes from an undirected graph.
deba@1979
   792
  /// This adaptor specializes SubUGraphAdaptor in the way that only
deba@1979
   793
  /// the node-set 
deba@1979
   794
  /// can be filtered. In usual case the checked parameter is true, we get the
deba@1979
   795
  /// induced subgraph. But if the checked parameter is false then we can only
deba@1979
   796
  /// filter only isolated nodes.
deba@1979
   797
  template<typename _UGraph, typename NodeFilterMap, bool checked = true>
deba@1979
   798
  class NodeSubUGraphAdaptor : 
deba@1979
   799
    public SubUGraphAdaptor<_UGraph, NodeFilterMap, 
deba@1979
   800
                            ConstMap<typename _UGraph::UEdge, bool>, checked> {
deba@1979
   801
  public:
deba@1979
   802
    typedef SubUGraphAdaptor<_UGraph, NodeFilterMap, 
deba@1979
   803
                             ConstMap<typename _UGraph::UEdge, bool> > Parent;
deba@1979
   804
    typedef _UGraph Graph;
deba@1979
   805
  protected:
deba@1985
   806
    ConstMap<typename _UGraph::UEdge, bool> const_true_map;
deba@1991
   807
deba@1991
   808
    NodeSubUGraphAdaptor() : const_true_map(true) {
deba@1991
   809
      Parent::setUEdgeFilterMap(const_true_map);
deba@1991
   810
    }
deba@1991
   811
deba@1979
   812
  public:
deba@1979
   813
    NodeSubUGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map) : 
deba@1979
   814
      Parent(), const_true_map(true) { 
deba@1979
   815
      Parent::setGraph(_graph);
deba@1979
   816
      Parent::setNodeFilterMap(_node_filter_map);
deba@1979
   817
      Parent::setUEdgeFilterMap(const_true_map);
deba@1979
   818
    }
deba@1979
   819
  };
deba@1979
   820
deba@1979
   821
  template<typename UGraph, typename NodeFilterMap>
deba@1979
   822
  NodeSubUGraphAdaptor<const UGraph, NodeFilterMap>
deba@1979
   823
  nodeSubUGraphAdaptor(const UGraph& graph, NodeFilterMap& nfm) {
deba@1979
   824
    return NodeSubUGraphAdaptor<const UGraph, NodeFilterMap>(graph, nfm);
deba@1979
   825
  }
deba@1979
   826
deba@1979
   827
  template<typename UGraph, typename NodeFilterMap>
deba@1979
   828
  NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap>
deba@1979
   829
  nodeSubUGraphAdaptor(const UGraph& graph, const NodeFilterMap& nfm) {
deba@1979
   830
    return NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap>(graph, nfm);
deba@1979
   831
  }
deba@1979
   832
deba@2042
   833
  /// \ingroup graph_adaptors
deba@2042
   834
  ///
deba@1979
   835
  /// \brief An adaptor for hiding undirected edges from an undirected graph.
deba@1979
   836
  ///
deba@1979
   837
  /// \warning Graph adaptors are in even more experimental state
deba@1979
   838
  /// than the other parts of the lib. Use them at you own risk.
deba@1979
   839
  ///
deba@1979
   840
  /// An adaptor for hiding undirected edges from an undirected graph.
deba@1979
   841
  /// This adaptor specializes SubUGraphAdaptor in the way that
deba@1979
   842
  /// only the edge-set 
deba@1979
   843
  /// can be filtered.
deba@1979
   844
  template<typename _UGraph, typename UEdgeFilterMap>
deba@1979
   845
  class EdgeSubUGraphAdaptor : 
deba@1979
   846
    public SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>, 
deba@1979
   847
                            UEdgeFilterMap, false> {
deba@1979
   848
  public:
deba@1979
   849
    typedef SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>, 
deba@1979
   850
                             UEdgeFilterMap, false> Parent;
deba@1979
   851
    typedef _UGraph Graph;
deba@1979
   852
  protected:
deba@1979
   853
    ConstMap<typename Graph::Node, bool> const_true_map;
deba@1991
   854
deba@1991
   855
    EdgeSubUGraphAdaptor() : const_true_map(true) {
deba@1991
   856
      Parent::setNodeFilterMap(const_true_map);
deba@1991
   857
    }
deba@1991
   858
deba@1979
   859
  public:
deba@2031
   860
deba@1979
   861
    EdgeSubUGraphAdaptor(Graph& _graph, UEdgeFilterMap& _uedge_filter_map) : 
deba@1979
   862
      Parent(), const_true_map(true) { 
deba@1979
   863
      Parent::setGraph(_graph);
deba@1979
   864
      Parent::setNodeFilterMap(const_true_map);
deba@1979
   865
      Parent::setUEdgeFilterMap(_uedge_filter_map);
deba@1979
   866
    }
deba@2031
   867
deba@1979
   868
  };
deba@1979
   869
deba@1979
   870
  template<typename UGraph, typename EdgeFilterMap>
deba@1979
   871
  EdgeSubUGraphAdaptor<const UGraph, EdgeFilterMap>
deba@1979
   872
  edgeSubUGraphAdaptor(const UGraph& graph, EdgeFilterMap& efm) {
deba@1979
   873
    return EdgeSubUGraphAdaptor<const UGraph, EdgeFilterMap>(graph, efm);
deba@1979
   874
  }
deba@1979
   875
deba@1979
   876
  template<typename UGraph, typename EdgeFilterMap>
deba@1979
   877
  EdgeSubUGraphAdaptor<const UGraph, const EdgeFilterMap>
deba@1979
   878
  edgeSubUGraphAdaptor(const UGraph& graph, const EdgeFilterMap& efm) {
deba@1979
   879
    return EdgeSubUGraphAdaptor<const UGraph, const EdgeFilterMap>(graph, efm);
deba@1979
   880
  }
deba@1979
   881
deba@2087
   882
  /// \brief Base of direct undirected graph adaptor
deba@2087
   883
  ///
deba@2087
   884
  /// Base class of the direct undirected graph adaptor. All public member
deba@2087
   885
  /// of this class can be used with the DirUGraphAdaptor too.
deba@2087
   886
  /// \sa DirUGraphAdaptor
deba@1979
   887
  template <typename _UGraph, typename _DirectionMap>
deba@1980
   888
  class DirUGraphAdaptorBase {
deba@1979
   889
  public:
deba@1979
   890
    
deba@1979
   891
    typedef _UGraph Graph;
deba@1979
   892
    typedef _DirectionMap DirectionMap;
deba@1979
   893
deba@1979
   894
    typedef typename _UGraph::Node Node;
deba@1979
   895
    typedef typename _UGraph::UEdge Edge;
deba@1979
   896
   
deba@2087
   897
    /// \brief Reverse edge
deba@2087
   898
    /// 
deba@2087
   899
    /// It reverse the given edge. It simply negate the direction in the map.
deba@1991
   900
    void reverseEdge(const Edge& edge) {
deba@1991
   901
      direction->set(edge, !(*direction)[edge]);
deba@1991
   902
    }
deba@1991
   903
deba@1979
   904
    void first(Node& i) const { graph->first(i); }
deba@1979
   905
    void first(Edge& i) const { graph->first(i); }
deba@1979
   906
    void firstIn(Edge& i, const Node& n) const {
deba@1979
   907
      bool d;
deba@1979
   908
      graph->firstInc(i, d, n);
deba@1979
   909
      while (i != INVALID && d == (*direction)[i]) graph->nextInc(i, d);
deba@1979
   910
    }
deba@1979
   911
    void firstOut(Edge& i, const Node& n ) const { 
deba@1979
   912
      bool d;
deba@1979
   913
      graph->firstInc(i, d, n);
deba@1979
   914
      while (i != INVALID && d != (*direction)[i]) graph->nextInc(i, d);
deba@1979
   915
    }
deba@1979
   916
deba@1979
   917
    void next(Node& i) const { graph->next(i); }
deba@1979
   918
    void next(Edge& i) const { graph->next(i); }
deba@1979
   919
    void nextIn(Edge& i) const {
deba@1979
   920
      bool d = !(*direction)[i];
deba@1979
   921
      graph->nextInc(i, d);
deba@1979
   922
      while (i != INVALID && d == (*direction)[i]) graph->nextInc(i, d);
deba@1979
   923
    }
deba@1979
   924
    void nextOut(Edge& i) const {
deba@1979
   925
      bool d = (*direction)[i];
deba@1979
   926
      graph->nextInc(i, d);
deba@1979
   927
      while (i != INVALID && d != (*direction)[i]) graph->nextInc(i, d);
deba@1979
   928
    }
deba@1979
   929
deba@1979
   930
    Node source(const Edge& e) const { 
deba@1979
   931
      return (*direction)[e] ? graph->source(e) : graph->target(e); 
deba@1979
   932
    }
deba@1979
   933
    Node target(const Edge& e) const { 
deba@1979
   934
      return (*direction)[e] ? graph->target(e) : graph->source(e); 
deba@1979
   935
    }
deba@1979
   936
deba@1979
   937
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
deba@1979
   938
    int nodeNum() const { return graph->nodeNum(); }
deba@1979
   939
    
deba@1979
   940
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
deba@1979
   941
    int edgeNum() const { return graph->uEdgeNum(); }
deba@1979
   942
deba@1979
   943
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1979
   944
    Edge findEdge(const Node& source, const Node& target, 
deba@1979
   945
		  const Edge& prev = INVALID) {
deba@1979
   946
      Edge edge = prev;
deba@1979
   947
      bool d = edge == INVALID ? true : (*direction)[edge];
deba@1979
   948
      if (d) {
deba@1979
   949
        edge = graph->findUEdge(source, target, edge);
deba@1979
   950
        while (edge != INVALID && !(*direction)[edge]) {
deba@1979
   951
          graph->findUEdge(source, target, edge);
deba@1979
   952
        }
deba@1979
   953
        if (edge != INVALID) return edge;
deba@1979
   954
      }
deba@1979
   955
      graph->findUEdge(target, source, edge);
deba@1979
   956
      while (edge != INVALID && (*direction)[edge]) {
deba@1979
   957
        graph->findUEdge(source, target, edge);
deba@1979
   958
      }
deba@1979
   959
      return edge;
deba@1979
   960
    }
deba@1979
   961
  
deba@1979
   962
    Node addNode() const { 
deba@1979
   963
      return Node(graph->addNode()); 
deba@1979
   964
    }
deba@1979
   965
deba@1979
   966
    Edge addEdge(const Node& source, const Node& target) const {
deba@1979
   967
      Edge edge = graph->addEdge(source, target);
deba@2069
   968
      direction->set(edge, graph->source(edge) == source);
deba@1979
   969
      return edge; 
deba@1979
   970
    }
deba@1979
   971
deba@1979
   972
    void erase(const Node& i) const { graph->erase(i); }
deba@1979
   973
    void erase(const Edge& i) const { graph->erase(i); }
deba@1979
   974
  
deba@1979
   975
    void clear() const { graph->clear(); }
deba@1979
   976
    
deba@1979
   977
    int id(const Node& v) const { return graph->id(v); }
deba@1979
   978
    int id(const Edge& e) const { return graph->id(e); }
deba@1979
   979
deba@1991
   980
    int maxNodeId() const {
deba@1991
   981
      return graph->maxNodeId();
deba@1979
   982
    }
deba@1979
   983
deba@1991
   984
    int maxEdgeId() const {
deba@1991
   985
      return graph->maxEdgeId();
deba@1991
   986
    }
deba@1991
   987
deba@1991
   988
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
deba@1991
   989
deba@1991
   990
    NodeNotifier& getNotifier(Node) const {
deba@1991
   991
      return graph->getNotifier(Node());
deba@1991
   992
    } 
deba@1991
   993
deba@1991
   994
    typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
deba@1991
   995
deba@1991
   996
    EdgeNotifier& getNotifier(Edge) const {
deba@1991
   997
      return graph->getNotifier(Edge());
deba@1991
   998
    } 
deba@1991
   999
deba@1979
  1000
    template <typename _Value>
deba@1979
  1001
    class NodeMap : public _UGraph::template NodeMap<_Value> {
deba@1979
  1002
    public:
deba@2031
  1003
deba@1979
  1004
      typedef typename _UGraph::template NodeMap<_Value> Parent;
deba@2031
  1005
deba@1980
  1006
      explicit NodeMap(const DirUGraphAdaptorBase& ga) 
deba@2031
  1007
	: Parent(*ga.graph) {}
deba@2031
  1008
deba@1980
  1009
      NodeMap(const DirUGraphAdaptorBase& ga, const _Value& value)
deba@2031
  1010
	: Parent(*ga.graph, value) {}
deba@2031
  1011
deba@2031
  1012
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
  1013
        return operator=<NodeMap>(cmap);
deba@2031
  1014
      }
deba@2031
  1015
deba@2031
  1016
      template <typename CMap>
deba@2031
  1017
      NodeMap& operator=(const CMap& cmap) {
deba@2031
  1018
        Parent::operator=(cmap);
deba@2031
  1019
        return *this;
deba@2031
  1020
      }
deba@2031
  1021
deba@1979
  1022
    };
deba@1979
  1023
deba@1979
  1024
    template <typename _Value>
deba@1979
  1025
    class EdgeMap : public _UGraph::template UEdgeMap<_Value> {
deba@1979
  1026
    public:
deba@2031
  1027
deba@1980
  1028
      typedef typename _UGraph::template UEdgeMap<_Value> Parent;
deba@2031
  1029
deba@1980
  1030
      explicit EdgeMap(const DirUGraphAdaptorBase& ga) 
deba@1979
  1031
	: Parent(*ga.graph) { }
deba@2031
  1032
deba@1980
  1033
      EdgeMap(const DirUGraphAdaptorBase& ga, const _Value& value)
deba@1979
  1034
	: Parent(*ga.graph, value) { }
deba@2031
  1035
deba@2031
  1036
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
  1037
        return operator=<EdgeMap>(cmap);
deba@2031
  1038
      }
deba@2031
  1039
deba@2031
  1040
      template <typename CMap>
deba@2031
  1041
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
  1042
        Parent::operator=(cmap);
deba@2031
  1043
        return *this;
deba@2031
  1044
      }
deba@1979
  1045
    };
deba@1979
  1046
deba@1979
  1047
    
deba@1979
  1048
deba@1979
  1049
  protected:
deba@1979
  1050
    Graph* graph;
deba@1979
  1051
    DirectionMap* direction;
deba@1979
  1052
deba@1979
  1053
    void setDirectionMap(DirectionMap& _direction) {
deba@1979
  1054
      direction = &_direction;
deba@1979
  1055
    }
deba@1979
  1056
deba@1979
  1057
    void setGraph(Graph& _graph) {
deba@1979
  1058
      graph = &_graph;
deba@1979
  1059
    }
deba@1979
  1060
deba@1979
  1061
  };
deba@1979
  1062
deba@1979
  1063
deba@1980
  1064
  /// \ingroup graph_adaptors
deba@1991
  1065
  ///
deba@1991
  1066
  /// \brief A directed graph is made from an undirected graph by an adaptor
deba@1980
  1067
  ///
deba@2087
  1068
  /// This adaptor gives a direction for each uedge in the undirected
deba@2087
  1069
  /// graph. The direction of the edges stored in the
deba@2087
  1070
  /// DirectionMap. This map is a bool map on the undirected edges. If
deba@2087
  1071
  /// the uedge is mapped to true then the direction of the directed
deba@2087
  1072
  /// edge will be the same as the default direction of the uedge. The
deba@2087
  1073
  /// edges can be easily reverted by the \ref
deba@2087
  1074
  /// DirUGraphAdaptorBase::reverseEdge "reverseEdge()" member in the
deba@2087
  1075
  /// adaptor.
deba@2087
  1076
  ///
deba@2087
  1077
  /// It can be used to solve orientation problems on directed graphs.
deba@2087
  1078
  /// By example how can we orient an undirected graph to get the minimum
deba@2087
  1079
  /// number of strongly connected components. If we orient the edges with
deba@2087
  1080
  /// the dfs algorithm out from the source then we will get such an 
deba@2087
  1081
  /// orientation. 
deba@2087
  1082
  ///
deba@2087
  1083
  /// We use the \ref DfsVisitor "visitor" interface of the 
deba@2087
  1084
  /// \ref DfsVisit "dfs" algorithm:
deba@2087
  1085
  ///\code
deba@2087
  1086
  /// template <typename DirMap>
deba@2087
  1087
  /// class OrientVisitor : public DfsVisitor<UGraph> {
deba@2087
  1088
  /// public:
deba@2087
  1089
  ///
deba@2087
  1090
  ///   OrientVisitor(const UGraph& ugraph, DirMap& dirMap)
deba@2087
  1091
  ///     : _ugraph(ugraph), _dirMap(dirMap), _processed(ugraph, false) {}
deba@2087
  1092
  ///
deba@2087
  1093
  ///   void discover(const Edge& edge) {
deba@2087
  1094
  ///     _processed.set(edge, true);
deba@2087
  1095
  ///     _dirMap.set(edge, _ugraph.direction(edge));
deba@2087
  1096
  ///   }
deba@2087
  1097
  ///
deba@2087
  1098
  ///   void examine(const Edge& edge) {
deba@2087
  1099
  ///     if (_processed[edge]) return;
deba@2087
  1100
  ///     _processed.set(edge, true);
deba@2087
  1101
  ///     _dirMap.set(edge, _ugraph.direction(edge));
deba@2087
  1102
  ///   }  
deba@2087
  1103
  /// 
deba@2087
  1104
  /// private:
deba@2087
  1105
  ///   const UGraph& _ugraph;  
deba@2087
  1106
  ///   DirMap& _dirMap;
deba@2087
  1107
  ///   UGraph::UEdgeMap<bool> _processed;
deba@2087
  1108
  /// };
deba@2087
  1109
  ///\endcode
deba@2087
  1110
  ///
deba@2087
  1111
  /// And now we can use the orientation:
deba@2087
  1112
  ///\code
deba@2087
  1113
  /// UGraph::UEdgeMap<bool> dmap(ugraph);
deba@2087
  1114
  ///
deba@2087
  1115
  /// typedef OrientVisitor<UGraph::UEdgeMap<bool> > Visitor;
deba@2087
  1116
  /// Visitor visitor(ugraph, dmap);
deba@2087
  1117
  ///
deba@2087
  1118
  /// DfsVisit<UGraph, Visitor> dfs(ugraph, visitor);
deba@2087
  1119
  ///
deba@2087
  1120
  /// dfs.run();
deba@2087
  1121
  ///
deba@2087
  1122
  /// typedef DirUGraphAdaptor<UGraph> DGraph;
deba@2087
  1123
  /// DGraph dgraph(ugraph, dmap);
deba@2087
  1124
  ///
deba@2087
  1125
  /// LEMON_ASSERT(countStronglyConnectedComponents(dgraph) == 
deba@2087
  1126
  ///              countBiEdgeConnectedComponents(ugraph), "Wrong Orientation");
deba@2087
  1127
  ///\endcode
deba@2087
  1128
  ///
deba@2087
  1129
  /// The number of the bi-connected components is a lower bound for
deba@2087
  1130
  /// the number of the strongly connected components in the directed
deba@2087
  1131
  /// graph because if we contract the bi-connected components to
deba@2087
  1132
  /// nodes we will get a tree therefore we cannot orient edges in
deba@2087
  1133
  /// both direction between bi-connected components. In the other way
deba@2087
  1134
  /// the algorithm will orient one component to be strongly
deba@2087
  1135
  /// connected. The two relations proof that the assertion will
deba@2087
  1136
  /// be always true and the found solution is optimal.
deba@2087
  1137
  ///
deba@2087
  1138
  /// \sa DirUGraphAdaptorBase
deba@2087
  1139
  /// \sa dirUGraphAdaptor
deba@1980
  1140
  template<typename _Graph, 
deba@1980
  1141
           typename DirectionMap = typename _Graph::template UEdgeMap<bool> > 
deba@1980
  1142
  class DirUGraphAdaptor : 
deba@1979
  1143
    public GraphAdaptorExtender<
deba@1980
  1144
    DirUGraphAdaptorBase<_Graph, DirectionMap> > {
deba@1979
  1145
  public:
deba@1979
  1146
    typedef _Graph Graph;
deba@1979
  1147
    typedef GraphAdaptorExtender<
deba@1980
  1148
      DirUGraphAdaptorBase<_Graph, DirectionMap> > Parent;
deba@1979
  1149
  protected:
deba@1980
  1150
    DirUGraphAdaptor() { }
deba@1979
  1151
  public:
deba@2087
  1152
    
deba@2087
  1153
    /// \brief Constructor of the adaptor
deba@2087
  1154
    ///
deba@2087
  1155
    /// Constructor of the adaptor
deba@1980
  1156
    DirUGraphAdaptor(_Graph& _graph, DirectionMap& _direction_map) { 
deba@1979
  1157
      setGraph(_graph);
deba@1979
  1158
      setDirectionMap(_direction_map);
deba@1979
  1159
    }
deba@1979
  1160
  };
deba@1979
  1161
deba@2087
  1162
  /// \brief Just gives back a DirUGraphAdaptor
deba@2087
  1163
  ///
deba@2087
  1164
  /// Just gives back a DirUGraphAdaptor
deba@1979
  1165
  template<typename UGraph, typename DirectionMap>
deba@1980
  1166
  DirUGraphAdaptor<const UGraph, DirectionMap>
deba@1980
  1167
  dirUGraphAdaptor(const UGraph& graph, DirectionMap& dm) {
deba@1980
  1168
    return DirUGraphAdaptor<const UGraph, DirectionMap>(graph, dm);
deba@1979
  1169
  }
deba@1979
  1170
deba@1979
  1171
  template<typename UGraph, typename DirectionMap>
deba@1980
  1172
  DirUGraphAdaptor<const UGraph, const DirectionMap>
deba@1980
  1173
  dirUGraphAdaptor(const UGraph& graph, const DirectionMap& dm) {
deba@1980
  1174
    return DirUGraphAdaptor<const UGraph, const DirectionMap>(graph, dm);
deba@1979
  1175
  }
deba@1979
  1176
deba@1979
  1177
}
deba@1979
  1178
deba@1979
  1179
#endif