lemon/ugraph_adaptor.h
author deba
Mon, 03 Apr 2006 16:05:26 +0000
changeset 2033 7bf1f64962c2
parent 1993 2115143eceea
child 2037 32e4bebee616
permissions -rw-r--r--
Small corrections
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
  /// \ingroup graph_adaptors
deba@1979
    42
  ///
deba@1979
    43
  /// \brief Base type for the Graph Adaptors
deba@1979
    44
  ///
deba@1979
    45
  /// This is the base type for most of LEMON graph adaptors. 
deba@1979
    46
  /// This class implements a trivial graph adaptor i.e. it only wraps the 
deba@1979
    47
  /// functions and types of the graph. The purpose of this class is to 
deba@1979
    48
  /// make easier implementing graph adaptors. E.g. if an adaptor is 
deba@1979
    49
  /// considered which differs from the wrapped graph only in some of its 
deba@1979
    50
  /// functions or types, then it can be derived from GraphAdaptor, and only 
deba@1979
    51
  /// the differences should be implemented.
deba@1979
    52
  ///
deba@1979
    53
  /// \author Balazs Dezso 
deba@1979
    54
  template<typename _UGraph>
deba@1979
    55
  class UGraphAdaptorBase {
deba@1979
    56
  public:
deba@1979
    57
    typedef _UGraph Graph;
deba@1979
    58
    typedef Graph ParentGraph;
deba@1979
    59
deba@1979
    60
  protected:
deba@1979
    61
    Graph* graph;
deba@1979
    62
deba@1979
    63
    UGraphAdaptorBase() : graph(0) {}
deba@1979
    64
deba@1979
    65
    void setGraph(Graph& _graph) { graph=&_graph; }
deba@1979
    66
deba@1979
    67
    Graph& getGraph() { return *graph; }
deba@1979
    68
    const Graph& getGraph() const { return *graph; }
deba@1979
    69
deba@1979
    70
  public:
deba@1979
    71
    UGraphAdaptorBase(Graph& _graph) : graph(&_graph) {}
deba@1979
    72
 
deba@1979
    73
    typedef typename Graph::Node Node;
deba@1979
    74
    typedef typename Graph::Edge Edge;
deba@1979
    75
    typedef typename Graph::UEdge UEdge;
deba@1979
    76
   
deba@1979
    77
    void first(Node& i) const { graph->first(i); }
deba@1979
    78
    void first(Edge& i) const { graph->first(i); }
deba@1979
    79
    void first(UEdge& i) const { graph->first(i); }
deba@1979
    80
    void firstIn(Edge& i, const Node& n) const { graph->firstIn(i, n); }
deba@1979
    81
    void firstOut(Edge& i, const Node& n ) const { graph->firstOut(i, n); }
deba@1979
    82
    void firstInc(UEdge &i, bool &d, const Node &n) const {
deba@1979
    83
      graph->firstInc(i, d, n);
deba@1979
    84
    }
deba@1979
    85
deba@1979
    86
    void next(Node& i) const { graph->next(i); }
deba@1979
    87
    void next(Edge& i) const { graph->next(i); }
deba@1979
    88
    void next(UEdge& i) const { graph->next(i); }
deba@1979
    89
    void nextIn(Edge& i) const { graph->nextIn(i); }
deba@1979
    90
    void nextOut(Edge& i) const { graph->nextOut(i); }
deba@1979
    91
    void nextInc(UEdge &i, bool &d) const { graph->nextInc(i, d); }
deba@1979
    92
deba@1979
    93
    Node source(const UEdge& e) const { return graph->source(e); }
deba@1979
    94
    Node target(const UEdge& e) const { return graph->target(e); }
deba@1979
    95
deba@1979
    96
    Node source(const Edge& e) const { return graph->source(e); }
deba@1979
    97
    Node target(const Edge& e) const { return graph->target(e); }
deba@1979
    98
deba@1979
    99
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
deba@1979
   100
    int nodeNum() const { return graph->nodeNum(); }
deba@1979
   101
    
deba@1979
   102
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
deba@1979
   103
    int edgeNum() const { return graph->edgeNum(); }
deba@2031
   104
    int uEdgeNum() const { return graph->uEdgeNum(); }
deba@1979
   105
deba@1979
   106
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1979
   107
    Edge findEdge(const Node& source, const Node& target, 
deba@1979
   108
		  const Edge& prev = INVALID) {
deba@1979
   109
      return graph->findEdge(source, target, prev);
deba@1979
   110
    }
deba@1979
   111
    UEdge findUEdge(const Node& source, const Node& target, 
deba@1979
   112
                    const UEdge& prev = INVALID) {
deba@1979
   113
      return graph->findUEdge(source, target, prev);
deba@1979
   114
    }
deba@1979
   115
  
deba@1979
   116
    Node addNode() const { return graph->addNode(); }
deba@1979
   117
    UEdge addEdge(const Node& source, const Node& target) const { 
deba@1979
   118
      return graph->addEdge(source, target); 
deba@1979
   119
    }
deba@1979
   120
deba@1979
   121
    void erase(const Node& i) const { graph->erase(i); }
deba@2031
   122
    void erase(const UEdge& i) const { graph->erase(i); }
deba@1979
   123
  
deba@1979
   124
    void clear() const { graph->clear(); }
deba@1979
   125
    
deba@2031
   126
    bool direction(const Edge& e) const { return graph->direction(e); }
deba@2031
   127
    Edge direct(const UEdge& e, bool d) const { return graph->direct(e, d); }
deba@2031
   128
deba@1979
   129
    int id(const Node& v) const { return graph->id(v); }
deba@2031
   130
    int id(const Edge& e) const { return graph->id(e); }
deba@1979
   131
    int id(const UEdge& e) const { return graph->id(e); }
deba@1979
   132
deba@2031
   133
    Node fromNodeId(int id) const {
deba@2031
   134
      return graph->fromNodeId(id);
deba@2031
   135
    }
deba@2031
   136
deba@2031
   137
    Edge fromEdgeId(int id) const {
deba@2031
   138
      return graph->fromEdgeId(id);
deba@2031
   139
    }
deba@2031
   140
deba@2031
   141
    UEdge fromUEdgeId(int id) const {
deba@2031
   142
      return graph->fromUEdgeId(id);
deba@2031
   143
    }
deba@1991
   144
deba@1991
   145
    int maxNodeId() const {
deba@1991
   146
      return graph->maxNodeId();
deba@1979
   147
    }
deba@1979
   148
deba@1991
   149
    int maxEdgeId() const {
deba@1991
   150
      return graph->maxEdgeId();
deba@1979
   151
    }
deba@1979
   152
deba@1991
   153
    int maxUEdgeId() const {
deba@1991
   154
      return graph->maxEdgeId();
deba@1979
   155
    }
deba@1979
   156
deba@1991
   157
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
deba@1991
   158
deba@1991
   159
    NodeNotifier& getNotifier(Node) const {
deba@1991
   160
      return graph->getNotifier(Node());
deba@1991
   161
    } 
deba@1991
   162
deba@1991
   163
    typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
deba@1991
   164
deba@1991
   165
    EdgeNotifier& getNotifier(Edge) const {
deba@1991
   166
      return graph->getNotifier(Edge());
deba@1991
   167
    } 
deba@1991
   168
deba@1991
   169
    typedef typename ItemSetTraits<Graph, UEdge>::ItemNotifier UEdgeNotifier;
deba@1991
   170
deba@1991
   171
    UEdgeNotifier& getNotifier(UEdge) const {
deba@1991
   172
      return graph->getNotifier(UEdge());
deba@1991
   173
    } 
deba@1979
   174
deba@1979
   175
    template <typename _Value>
deba@1979
   176
    class NodeMap : public Graph::template NodeMap<_Value> {
deba@1979
   177
    public:
deba@1979
   178
      typedef typename Graph::template NodeMap<_Value> Parent;
deba@1979
   179
      explicit NodeMap(const UGraphAdaptorBase<Graph>& ga) 
deba@1979
   180
	: Parent(*ga.graph) {}
deba@1979
   181
      NodeMap(const UGraphAdaptorBase<Graph>& ga, const _Value& value)
deba@1979
   182
	: Parent(*ga.graph, value) {}
deba@1979
   183
deba@1979
   184
      NodeMap& operator=(const NodeMap& cmap) {
deba@1979
   185
	return operator=<NodeMap>(cmap);
deba@1979
   186
      }
deba@1979
   187
deba@1979
   188
      template <typename CMap>
deba@1979
   189
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   190
        Parent::operator=(cmap);
deba@2031
   191
        return *this;
deba@1979
   192
      }
deba@2031
   193
deba@1979
   194
    };
deba@1979
   195
deba@1979
   196
    template <typename _Value>
deba@1979
   197
    class EdgeMap : public Graph::template EdgeMap<_Value> {
deba@1979
   198
    public:
deba@1979
   199
      typedef typename Graph::template EdgeMap<_Value> Parent;
deba@1979
   200
      explicit EdgeMap(const UGraphAdaptorBase<Graph>& ga) 
deba@1979
   201
	: Parent(*ga.graph) {}
deba@1979
   202
      EdgeMap(const UGraphAdaptorBase<Graph>& ga, const _Value& value)
deba@1979
   203
	: Parent(*ga.graph, value) {}
deba@1979
   204
deba@1979
   205
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@1979
   206
	return operator=<EdgeMap>(cmap);
deba@1979
   207
      }
deba@1979
   208
deba@1979
   209
      template <typename CMap>
deba@1979
   210
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   211
        Parent::operator=(cmap);
deba@1979
   212
	return *this;
deba@1979
   213
      }
deba@1979
   214
    };
deba@1979
   215
deba@1979
   216
    template <typename _Value>
deba@1979
   217
    class UEdgeMap : public Graph::template UEdgeMap<_Value> {
deba@1979
   218
    public:
deba@1979
   219
      typedef typename Graph::template UEdgeMap<_Value> Parent;
deba@1979
   220
      explicit UEdgeMap(const UGraphAdaptorBase<Graph>& ga) 
deba@1979
   221
	: Parent(*ga.graph) {}
deba@1979
   222
      UEdgeMap(const UGraphAdaptorBase<Graph>& ga, const _Value& value)
deba@1979
   223
	: Parent(*ga.graph, value) {}
deba@1979
   224
deba@1979
   225
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@1979
   226
	return operator=<UEdgeMap>(cmap);
deba@1979
   227
      }
deba@1979
   228
deba@1979
   229
      template <typename CMap>
deba@1979
   230
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
   231
        Parent::operator=(cmap);
deba@2031
   232
        return *this;
deba@1979
   233
      }
deba@1979
   234
    };
deba@1979
   235
deba@1979
   236
  };
deba@1979
   237
deba@1979
   238
  /// \ingroup 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@1979
   354
    ///\e
deba@1979
   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@1979
   361
    ///\e
deba@1979
   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@1979
   365
    /// to be false in the corresponding edge-map.
deba@1979
   366
    void hide(const UEdge& e) const { uedge_filter_map->set(e, false); }
deba@1979
   367
deba@1979
   368
    ///\e
deba@1979
   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@1979
   375
    ///\e
deba@1979
   376
deba@1979
   377
    /// The value of \c e is set to be true in the edge-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@1979
   382
    /// Returns true if \c n is hidden.
deba@1979
   383
    
deba@1979
   384
    ///\e
deba@1979
   385
    ///
deba@1979
   386
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
deba@1979
   387
deba@1979
   388
    /// Returns true if \c n is hidden.
deba@1979
   389
    
deba@1979
   390
    ///\e
deba@1979
   391
    ///
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@1991
   398
    Edge findEdge(const Node& source, const Node& target, 
deba@1991
   399
		  const Edge& prev = INVALID) {
deba@1991
   400
      if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
deba@1991
   401
        return INVALID;
deba@1991
   402
      }
deba@1991
   403
      Edge edge = Parent::findEdge(source, target, prev);
deba@1991
   404
      while (edge != INVALID && !(*uedge_filter_map)[edge]) {
deba@1991
   405
        edge = Parent::findEdge(source, target, edge);
deba@1991
   406
      }
deba@1991
   407
      return edge;
deba@1991
   408
    }
deba@1991
   409
    UEdge findUEdge(const Node& source, const Node& target, 
deba@1991
   410
		  const UEdge& prev = INVALID) {
deba@1991
   411
      if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
deba@1991
   412
        return INVALID;
deba@1991
   413
      }
deba@1991
   414
      UEdge uedge = Parent::findUEdge(source, target, prev);
deba@1991
   415
      while (uedge != INVALID && !(*uedge_filter_map)[uedge]) {
deba@1991
   416
        uedge = Parent::findUEdge(source, target, 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@2031
   431
      NodeMap(const Graph& graph) 
deba@2031
   432
	: Parent(graph) {}
deba@2031
   433
      NodeMap(const Graph& graph, const _Value& value) 
deba@2031
   434
	: Parent(graph, value) {}
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@2031
   457
      EdgeMap(const Graph& graph) 
deba@2031
   458
	: Parent(graph) {}
deba@2031
   459
      EdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   460
	: Parent(graph, value) {}
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@2031
   483
      UEdgeMap(const Graph& graph) 
deba@2031
   484
	: Parent(graph) {}
deba@2031
   485
      UEdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   486
	: Parent(graph, value) {}
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@1979
   583
    ///\e
deba@1979
   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@1979
   590
    ///\e
deba@1979
   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@1979
   594
    /// to be false in the corresponding edge-map.
deba@1979
   595
    void hide(const UEdge& e) const { uedge_filter_map->set(e, false); }
deba@1979
   596
deba@1979
   597
    ///\e
deba@1979
   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@1979
   604
    ///\e
deba@1979
   605
deba@1979
   606
    /// The value of \c e is set to be true in the edge-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@1979
   611
    /// Returns true if \c n is hidden.
deba@1979
   612
    
deba@1979
   613
    ///\e
deba@1979
   614
    ///
deba@1979
   615
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
deba@1979
   616
deba@1979
   617
    /// Returns true if \c n is hidden.
deba@1979
   618
    
deba@1979
   619
    ///\e
deba@1979
   620
    ///
deba@1979
   621
    bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; }
deba@1979
   622
deba@1979
   623
    typedef False NodeNumTag;
deba@1979
   624
    typedef False EdgeNumTag;
deba@1991
   625
deba@1991
   626
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1991
   627
    Edge findEdge(const Node& source, const Node& target, 
deba@1991
   628
		  const Edge& prev = INVALID) {
deba@1991
   629
      Edge edge = Parent::findEdge(source, target, prev);
deba@1991
   630
      while (edge != INVALID && !(*uedge_filter_map)[edge]) {
deba@1991
   631
        edge = Parent::findEdge(source, target, edge);
deba@1991
   632
      }
deba@1991
   633
      return edge;
deba@1991
   634
    }
deba@1991
   635
    UEdge findUEdge(const Node& source, const Node& target, 
deba@1991
   636
		  const UEdge& prev = INVALID) {
deba@1991
   637
      UEdge uedge = Parent::findUEdge(source, target, prev);
deba@1991
   638
      while (uedge != INVALID && !(*uedge_filter_map)[uedge]) {
deba@1991
   639
        uedge = Parent::findUEdge(source, target, uedge);
deba@1991
   640
      }
deba@1991
   641
      return uedge;
deba@1991
   642
    }
deba@2031
   643
deba@2031
   644
    template <typename _Value>
deba@2031
   645
    class NodeMap 
deba@2031
   646
      : public SubMapExtender<Adaptor, 
deba@2031
   647
                              typename Parent::template NodeMap<_Value> > 
deba@2031
   648
    {
deba@2031
   649
    public:
deba@2031
   650
      typedef Adaptor Graph;
deba@2031
   651
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   652
                             template NodeMap<_Value> > Parent;
deba@2031
   653
    
deba@2031
   654
      NodeMap(const Graph& graph) 
deba@2031
   655
	: Parent(graph) {}
deba@2031
   656
      NodeMap(const Graph& graph, const _Value& value) 
deba@2031
   657
	: Parent(graph, value) {}
deba@2031
   658
    
deba@2031
   659
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
   660
	return operator=<NodeMap>(cmap);
deba@2031
   661
      }
deba@2031
   662
    
deba@2031
   663
      template <typename CMap>
deba@2031
   664
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   665
        Parent::operator=(cmap);
deba@2031
   666
	return *this;
deba@2031
   667
      }
deba@2031
   668
    };
deba@2031
   669
deba@2031
   670
    template <typename _Value>
deba@2031
   671
    class EdgeMap 
deba@2031
   672
      : public SubMapExtender<Adaptor, 
deba@2031
   673
                              typename Parent::template EdgeMap<_Value> > 
deba@2031
   674
    {
deba@2031
   675
    public:
deba@2031
   676
      typedef Adaptor Graph;
deba@2031
   677
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   678
                             template EdgeMap<_Value> > Parent;
deba@2031
   679
    
deba@2031
   680
      EdgeMap(const Graph& graph) 
deba@2031
   681
	: Parent(graph) {}
deba@2031
   682
      EdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   683
	: Parent(graph, value) {}
deba@2031
   684
    
deba@2031
   685
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
   686
	return operator=<EdgeMap>(cmap);
deba@2031
   687
      }
deba@2031
   688
    
deba@2031
   689
      template <typename CMap>
deba@2031
   690
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   691
        Parent::operator=(cmap);
deba@2031
   692
	return *this;
deba@2031
   693
      }
deba@2031
   694
    };
deba@2031
   695
deba@2031
   696
    template <typename _Value>
deba@2031
   697
    class UEdgeMap 
deba@2031
   698
      : public SubMapExtender<Adaptor, 
deba@2031
   699
                              typename Parent::template UEdgeMap<_Value> > 
deba@2031
   700
    {
deba@2031
   701
    public:
deba@2031
   702
      typedef Adaptor Graph;
deba@2031
   703
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   704
                             template UEdgeMap<_Value> > Parent;
deba@2031
   705
    
deba@2031
   706
      UEdgeMap(const Graph& graph) 
deba@2031
   707
	: Parent(graph) {}
deba@2031
   708
      UEdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   709
	: Parent(graph, value) {}
deba@2031
   710
    
deba@2031
   711
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@2031
   712
	return operator=<UEdgeMap>(cmap);
deba@2031
   713
      }
deba@2031
   714
    
deba@2031
   715
      template <typename CMap>
deba@2031
   716
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
   717
        Parent::operator=(cmap);
deba@2031
   718
	return *this;
deba@2031
   719
      }
deba@2031
   720
    };
deba@1979
   721
  };
deba@1979
   722
deba@1979
   723
  /// \ingroup graph_adaptors
deba@1979
   724
  ///
deba@1979
   725
  /// \brief A graph adaptor for hiding nodes and edges from an undirected 
deba@1979
   726
  /// graph.
deba@1979
   727
  /// 
deba@1979
   728
  /// SubUGraphAdaptor shows the undirected graph with filtered node-set and 
deba@1979
   729
  /// edge-set. If the \c checked parameter is true then it filters the edgeset
deba@1979
   730
  /// to do not get invalid edges without source or target.
deba@1979
   731
  /// 
deba@1979
   732
  /// If the \c checked template parameter is false then we have to note that 
deba@1979
   733
  /// the node-iterator cares only the filter on the node-set, and the 
deba@1979
   734
  /// edge-iterator cares only the filter on the edge-set.
deba@1979
   735
  /// This way the edge-map
deba@1979
   736
  /// should filter all edges which's source or target is filtered by the 
deba@1979
   737
  /// node-filter.
deba@1979
   738
  ///
deba@1979
   739
  /// Note that \c n is of type \c SubGA::NodeIt, but it can be converted to
deba@1979
   740
  /// \c Graph::Node that is why \c g.id(n) can be applied.
deba@1979
   741
  /// 
deba@1979
   742
  template<typename _UGraph, typename NodeFilterMap, 
deba@1979
   743
	   typename UEdgeFilterMap, bool checked = true>
deba@1979
   744
  class SubUGraphAdaptor : 
deba@1979
   745
    public UGraphAdaptorExtender<
deba@1979
   746
    SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, checked> > {
deba@1979
   747
  public:
deba@1979
   748
    typedef _UGraph Graph;
deba@1979
   749
    typedef UGraphAdaptorExtender<
deba@1979
   750
      SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap> > Parent;
deba@1979
   751
  protected:
deba@1979
   752
    SubUGraphAdaptor() { }
deba@1979
   753
  public:
deba@1979
   754
    SubUGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map, 
deba@1979
   755
		    UEdgeFilterMap& _uedge_filter_map) { 
deba@1979
   756
      setGraph(_graph);
deba@1979
   757
      setNodeFilterMap(_node_filter_map);
deba@1979
   758
      setUEdgeFilterMap(_uedge_filter_map);
deba@1979
   759
    }
deba@1979
   760
  };
deba@1979
   761
deba@1980
   762
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   763
  SubUGraphAdaptor<const UGraph, NodeFilterMap, EdgeFilterMap>
deba@1980
   764
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   765
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   766
    return SubUGraphAdaptor<const UGraph, NodeFilterMap, EdgeFilterMap>
deba@1980
   767
      (graph, nfm, efm);
deba@1980
   768
  }
deba@1980
   769
deba@1980
   770
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   771
  SubUGraphAdaptor<const UGraph, const NodeFilterMap, EdgeFilterMap>
deba@1980
   772
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   773
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   774
    return SubUGraphAdaptor<const UGraph, const NodeFilterMap, EdgeFilterMap>
deba@1980
   775
      (graph, nfm, efm);
deba@1980
   776
  }
deba@1980
   777
deba@1980
   778
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   779
  SubUGraphAdaptor<const UGraph, NodeFilterMap, const EdgeFilterMap>
deba@1980
   780
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   781
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   782
    return SubUGraphAdaptor<const UGraph, NodeFilterMap, const EdgeFilterMap>
deba@1980
   783
      (graph, nfm, efm);
deba@1980
   784
  }
deba@1980
   785
deba@1980
   786
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   787
  SubUGraphAdaptor<const UGraph, const NodeFilterMap, const EdgeFilterMap>
deba@1980
   788
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   789
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   790
    return SubUGraphAdaptor<const UGraph, const NodeFilterMap, 
deba@1980
   791
      const EdgeFilterMap>(graph, nfm, efm);
deba@1980
   792
  }
deba@1980
   793
deba@1979
   794
  /// \ingroup graph_adaptors
deba@1979
   795
  ///
deba@1980
   796
  /// \brief An adaptor for hiding nodes from an undirected graph.
deba@1979
   797
  ///
deba@1979
   798
  /// An adaptor for hiding nodes from an undirected graph.
deba@1979
   799
  /// This adaptor specializes SubUGraphAdaptor in the way that only
deba@1979
   800
  /// the node-set 
deba@1979
   801
  /// can be filtered. In usual case the checked parameter is true, we get the
deba@1979
   802
  /// induced subgraph. But if the checked parameter is false then we can only
deba@1979
   803
  /// filter only isolated nodes.
deba@1979
   804
  template<typename _UGraph, typename NodeFilterMap, bool checked = true>
deba@1979
   805
  class NodeSubUGraphAdaptor : 
deba@1979
   806
    public SubUGraphAdaptor<_UGraph, NodeFilterMap, 
deba@1979
   807
                            ConstMap<typename _UGraph::UEdge, bool>, checked> {
deba@1979
   808
  public:
deba@1979
   809
    typedef SubUGraphAdaptor<_UGraph, NodeFilterMap, 
deba@1979
   810
                             ConstMap<typename _UGraph::UEdge, bool> > Parent;
deba@1979
   811
    typedef _UGraph Graph;
deba@1979
   812
  protected:
deba@1985
   813
    ConstMap<typename _UGraph::UEdge, bool> const_true_map;
deba@1991
   814
deba@1991
   815
    NodeSubUGraphAdaptor() : const_true_map(true) {
deba@1991
   816
      Parent::setUEdgeFilterMap(const_true_map);
deba@1991
   817
    }
deba@1991
   818
deba@1979
   819
  public:
deba@1979
   820
    NodeSubUGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map) : 
deba@1979
   821
      Parent(), const_true_map(true) { 
deba@1979
   822
      Parent::setGraph(_graph);
deba@1979
   823
      Parent::setNodeFilterMap(_node_filter_map);
deba@1979
   824
      Parent::setUEdgeFilterMap(const_true_map);
deba@1979
   825
    }
deba@1979
   826
  };
deba@1979
   827
deba@1979
   828
  template<typename UGraph, typename NodeFilterMap>
deba@1979
   829
  NodeSubUGraphAdaptor<const UGraph, NodeFilterMap>
deba@1979
   830
  nodeSubUGraphAdaptor(const UGraph& graph, NodeFilterMap& nfm) {
deba@1979
   831
    return NodeSubUGraphAdaptor<const UGraph, NodeFilterMap>(graph, nfm);
deba@1979
   832
  }
deba@1979
   833
deba@1979
   834
  template<typename UGraph, typename NodeFilterMap>
deba@1979
   835
  NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap>
deba@1979
   836
  nodeSubUGraphAdaptor(const UGraph& graph, const NodeFilterMap& nfm) {
deba@1979
   837
    return NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap>(graph, nfm);
deba@1979
   838
  }
deba@1979
   839
deba@1979
   840
  /// \brief An adaptor for hiding undirected edges from an undirected graph.
deba@1979
   841
  ///
deba@1979
   842
  /// \warning Graph adaptors are in even more experimental state
deba@1979
   843
  /// than the other parts of the lib. Use them at you own risk.
deba@1979
   844
  ///
deba@1979
   845
  /// An adaptor for hiding undirected edges from an undirected graph.
deba@1979
   846
  /// This adaptor specializes SubUGraphAdaptor in the way that
deba@1979
   847
  /// only the edge-set 
deba@1979
   848
  /// can be filtered.
deba@1979
   849
  template<typename _UGraph, typename UEdgeFilterMap>
deba@1979
   850
  class EdgeSubUGraphAdaptor : 
deba@1979
   851
    public SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>, 
deba@1979
   852
                            UEdgeFilterMap, false> {
deba@1979
   853
  public:
deba@1979
   854
    typedef SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>, 
deba@1979
   855
                             UEdgeFilterMap, false> Parent;
deba@1979
   856
    typedef _UGraph Graph;
deba@1979
   857
  protected:
deba@1979
   858
    ConstMap<typename Graph::Node, bool> const_true_map;
deba@1991
   859
deba@1991
   860
    EdgeSubUGraphAdaptor() : const_true_map(true) {
deba@1991
   861
      Parent::setNodeFilterMap(const_true_map);
deba@1991
   862
    }
deba@1991
   863
deba@1979
   864
  public:
deba@2031
   865
deba@1979
   866
    EdgeSubUGraphAdaptor(Graph& _graph, UEdgeFilterMap& _uedge_filter_map) : 
deba@1979
   867
      Parent(), const_true_map(true) { 
deba@1979
   868
      Parent::setGraph(_graph);
deba@1979
   869
      Parent::setNodeFilterMap(const_true_map);
deba@1979
   870
      Parent::setUEdgeFilterMap(_uedge_filter_map);
deba@1979
   871
    }
deba@2031
   872
deba@1979
   873
  };
deba@1979
   874
deba@1979
   875
  template<typename UGraph, typename EdgeFilterMap>
deba@1979
   876
  EdgeSubUGraphAdaptor<const UGraph, EdgeFilterMap>
deba@1979
   877
  edgeSubUGraphAdaptor(const UGraph& graph, EdgeFilterMap& efm) {
deba@1979
   878
    return EdgeSubUGraphAdaptor<const UGraph, EdgeFilterMap>(graph, efm);
deba@1979
   879
  }
deba@1979
   880
deba@1979
   881
  template<typename UGraph, typename EdgeFilterMap>
deba@1979
   882
  EdgeSubUGraphAdaptor<const UGraph, const EdgeFilterMap>
deba@1979
   883
  edgeSubUGraphAdaptor(const UGraph& graph, const EdgeFilterMap& efm) {
deba@1979
   884
    return EdgeSubUGraphAdaptor<const UGraph, const EdgeFilterMap>(graph, efm);
deba@1979
   885
  }
deba@1979
   886
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@1991
   897
    void reverseEdge(const Edge& edge) {
deba@1991
   898
      direction->set(edge, !(*direction)[edge]);
deba@1991
   899
    }
deba@1991
   900
deba@1979
   901
    void first(Node& i) const { graph->first(i); }
deba@1979
   902
    void first(Edge& i) const { graph->first(i); }
deba@1979
   903
    void firstIn(Edge& i, const Node& n) const {
deba@1979
   904
      bool d;
deba@1979
   905
      graph->firstInc(i, d, n);
deba@1979
   906
      while (i != INVALID && d == (*direction)[i]) graph->nextInc(i, d);
deba@1979
   907
    }
deba@1979
   908
    void firstOut(Edge& i, const Node& n ) const { 
deba@1979
   909
      bool d;
deba@1979
   910
      graph->firstInc(i, d, n);
deba@1979
   911
      while (i != INVALID && d != (*direction)[i]) graph->nextInc(i, d);
deba@1979
   912
    }
deba@1979
   913
deba@1979
   914
    void next(Node& i) const { graph->next(i); }
deba@1979
   915
    void next(Edge& i) const { graph->next(i); }
deba@1979
   916
    void nextIn(Edge& i) const {
deba@1979
   917
      bool d = !(*direction)[i];
deba@1979
   918
      graph->nextInc(i, d);
deba@1979
   919
      while (i != INVALID && d == (*direction)[i]) graph->nextInc(i, d);
deba@1979
   920
    }
deba@1979
   921
    void nextOut(Edge& i) const {
deba@1979
   922
      bool d = (*direction)[i];
deba@1979
   923
      graph->nextInc(i, d);
deba@1979
   924
      while (i != INVALID && d != (*direction)[i]) graph->nextInc(i, d);
deba@1979
   925
    }
deba@1979
   926
deba@1979
   927
    Node source(const Edge& e) const { 
deba@1979
   928
      return (*direction)[e] ? graph->source(e) : graph->target(e); 
deba@1979
   929
    }
deba@1979
   930
    Node target(const Edge& e) const { 
deba@1979
   931
      return (*direction)[e] ? graph->target(e) : graph->source(e); 
deba@1979
   932
    }
deba@1979
   933
deba@1979
   934
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
deba@1979
   935
    int nodeNum() const { return graph->nodeNum(); }
deba@1979
   936
    
deba@1979
   937
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
deba@1979
   938
    int edgeNum() const { return graph->uEdgeNum(); }
deba@1979
   939
deba@1979
   940
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1979
   941
    Edge findEdge(const Node& source, const Node& target, 
deba@1979
   942
		  const Edge& prev = INVALID) {
deba@1979
   943
      Edge edge = prev;
deba@1979
   944
      bool d = edge == INVALID ? true : (*direction)[edge];
deba@1979
   945
      if (d) {
deba@1979
   946
        edge = graph->findUEdge(source, target, edge);
deba@1979
   947
        while (edge != INVALID && !(*direction)[edge]) {
deba@1979
   948
          graph->findUEdge(source, target, edge);
deba@1979
   949
        }
deba@1979
   950
        if (edge != INVALID) return edge;
deba@1979
   951
      }
deba@1979
   952
      graph->findUEdge(target, source, edge);
deba@1979
   953
      while (edge != INVALID && (*direction)[edge]) {
deba@1979
   954
        graph->findUEdge(source, target, edge);
deba@1979
   955
      }
deba@1979
   956
      return edge;
deba@1979
   957
    }
deba@1979
   958
  
deba@1979
   959
    Node addNode() const { 
deba@1979
   960
      return Node(graph->addNode()); 
deba@1979
   961
    }
deba@1979
   962
deba@1979
   963
    Edge addEdge(const Node& source, const Node& target) const {
deba@1979
   964
      Edge edge = graph->addEdge(source, target);
deba@1979
   965
      (*direction)[edge] = graph->source(edge) == source;
deba@1979
   966
      return edge; 
deba@1979
   967
    }
deba@1979
   968
deba@1979
   969
    void erase(const Node& i) const { graph->erase(i); }
deba@1979
   970
    void erase(const Edge& i) const { graph->erase(i); }
deba@1979
   971
  
deba@1979
   972
    void clear() const { graph->clear(); }
deba@1979
   973
    
deba@1979
   974
    int id(const Node& v) const { return graph->id(v); }
deba@1979
   975
    int id(const Edge& e) const { return graph->id(e); }
deba@1979
   976
deba@1991
   977
    int maxNodeId() const {
deba@1991
   978
      return graph->maxNodeId();
deba@1979
   979
    }
deba@1979
   980
deba@1991
   981
    int maxEdgeId() const {
deba@1991
   982
      return graph->maxEdgeId();
deba@1991
   983
    }
deba@1991
   984
deba@1991
   985
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
deba@1991
   986
deba@1991
   987
    NodeNotifier& getNotifier(Node) const {
deba@1991
   988
      return graph->getNotifier(Node());
deba@1991
   989
    } 
deba@1991
   990
deba@1991
   991
    typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
deba@1991
   992
deba@1991
   993
    EdgeNotifier& getNotifier(Edge) const {
deba@1991
   994
      return graph->getNotifier(Edge());
deba@1991
   995
    } 
deba@1991
   996
deba@1979
   997
    template <typename _Value>
deba@1979
   998
    class NodeMap : public _UGraph::template NodeMap<_Value> {
deba@1979
   999
    public:
deba@2031
  1000
deba@1979
  1001
      typedef typename _UGraph::template NodeMap<_Value> Parent;
deba@2031
  1002
deba@1980
  1003
      explicit NodeMap(const DirUGraphAdaptorBase& ga) 
deba@2031
  1004
	: Parent(*ga.graph) {}
deba@2031
  1005
deba@1980
  1006
      NodeMap(const DirUGraphAdaptorBase& ga, const _Value& value)
deba@2031
  1007
	: Parent(*ga.graph, value) {}
deba@2031
  1008
deba@2031
  1009
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
  1010
        return operator=<NodeMap>(cmap);
deba@2031
  1011
      }
deba@2031
  1012
deba@2031
  1013
      template <typename CMap>
deba@2031
  1014
      NodeMap& operator=(const CMap& cmap) {
deba@2031
  1015
        Parent::operator=(cmap);
deba@2031
  1016
        return *this;
deba@2031
  1017
      }
deba@2031
  1018
deba@1979
  1019
    };
deba@1979
  1020
deba@1979
  1021
    template <typename _Value>
deba@1979
  1022
    class EdgeMap : public _UGraph::template UEdgeMap<_Value> {
deba@1979
  1023
    public:
deba@2031
  1024
deba@1980
  1025
      typedef typename _UGraph::template UEdgeMap<_Value> Parent;
deba@2031
  1026
deba@1980
  1027
      explicit EdgeMap(const DirUGraphAdaptorBase& ga) 
deba@1979
  1028
	: Parent(*ga.graph) { }
deba@2031
  1029
deba@1980
  1030
      EdgeMap(const DirUGraphAdaptorBase& ga, const _Value& value)
deba@1979
  1031
	: Parent(*ga.graph, value) { }
deba@2031
  1032
deba@2031
  1033
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
  1034
        return operator=<EdgeMap>(cmap);
deba@2031
  1035
      }
deba@2031
  1036
deba@2031
  1037
      template <typename CMap>
deba@2031
  1038
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
  1039
        Parent::operator=(cmap);
deba@2031
  1040
        return *this;
deba@2031
  1041
      }
deba@1979
  1042
    };
deba@1979
  1043
deba@1979
  1044
    
deba@1979
  1045
deba@1979
  1046
  protected:
deba@1979
  1047
    Graph* graph;
deba@1979
  1048
    DirectionMap* direction;
deba@1979
  1049
deba@1979
  1050
    void setDirectionMap(DirectionMap& _direction) {
deba@1979
  1051
      direction = &_direction;
deba@1979
  1052
    }
deba@1979
  1053
deba@1979
  1054
    void setGraph(Graph& _graph) {
deba@1979
  1055
      graph = &_graph;
deba@1979
  1056
    }
deba@1979
  1057
deba@1979
  1058
  };
deba@1979
  1059
deba@1979
  1060
deba@1980
  1061
  /// \ingroup graph_adaptors
deba@1991
  1062
  ///
deba@1991
  1063
  /// \brief A directed graph is made from an undirected graph by an adaptor
deba@1980
  1064
  ///
deba@1980
  1065
  /// This adaptor gives a direction for each uedge in the undirected graph.
deba@1980
  1066
  /// The direction of the edges stored in the DirectionMap. This map is
deba@1980
  1067
  /// a bool map on the undirected edges. If the uedge is mapped to true
deba@1980
  1068
  /// then the direction of the directed edge will be the same as the
deba@1980
  1069
  /// default direction of the uedge. The edges can be easily reverted
deba@1980
  1070
  /// by the reverseEdge member in the adaptor.  
deba@1980
  1071
  template<typename _Graph, 
deba@1980
  1072
           typename DirectionMap = typename _Graph::template UEdgeMap<bool> > 
deba@1980
  1073
  class DirUGraphAdaptor : 
deba@1979
  1074
    public GraphAdaptorExtender<
deba@1980
  1075
    DirUGraphAdaptorBase<_Graph, DirectionMap> > {
deba@1979
  1076
  public:
deba@1979
  1077
    typedef _Graph Graph;
deba@1979
  1078
    typedef GraphAdaptorExtender<
deba@1980
  1079
      DirUGraphAdaptorBase<_Graph, DirectionMap> > Parent;
deba@1979
  1080
  protected:
deba@1980
  1081
    DirUGraphAdaptor() { }
deba@1979
  1082
  public:
deba@1980
  1083
    DirUGraphAdaptor(_Graph& _graph, DirectionMap& _direction_map) { 
deba@1979
  1084
      setGraph(_graph);
deba@1979
  1085
      setDirectionMap(_direction_map);
deba@1979
  1086
    }
deba@1979
  1087
  };
deba@1979
  1088
deba@1979
  1089
  template<typename UGraph, typename DirectionMap>
deba@1980
  1090
  DirUGraphAdaptor<const UGraph, DirectionMap>
deba@1980
  1091
  dirUGraphAdaptor(const UGraph& graph, DirectionMap& dm) {
deba@1980
  1092
    return DirUGraphAdaptor<const UGraph, DirectionMap>(graph, dm);
deba@1979
  1093
  }
deba@1979
  1094
deba@1979
  1095
  template<typename UGraph, typename DirectionMap>
deba@1980
  1096
  DirUGraphAdaptor<const UGraph, const DirectionMap>
deba@1980
  1097
  dirUGraphAdaptor(const UGraph& graph, const DirectionMap& dm) {
deba@1980
  1098
    return DirUGraphAdaptor<const UGraph, const DirectionMap>(graph, dm);
deba@1979
  1099
  }
deba@1979
  1100
deba@1979
  1101
}
deba@1979
  1102
deba@1979
  1103
#endif