lemon/ugraph_adaptor.h
author deba
Tue, 18 Apr 2006 07:01:55 +0000
changeset 2058 0b1fc1566fdb
parent 2037 32e4bebee616
child 2069 d55adbe1fc78
permissions -rw-r--r--
Refinements in bipartite matching algorithms
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
  public:
deba@1979
    68
    UGraphAdaptorBase(Graph& _graph) : graph(&_graph) {}
deba@1979
    69
 
deba@1979
    70
    typedef typename Graph::Node Node;
deba@1979
    71
    typedef typename Graph::Edge Edge;
deba@1979
    72
    typedef typename Graph::UEdge UEdge;
deba@1979
    73
   
deba@1979
    74
    void first(Node& i) const { graph->first(i); }
deba@1979
    75
    void first(Edge& i) const { graph->first(i); }
deba@1979
    76
    void first(UEdge& i) const { graph->first(i); }
deba@1979
    77
    void firstIn(Edge& i, const Node& n) const { graph->firstIn(i, n); }
deba@1979
    78
    void firstOut(Edge& i, const Node& n ) const { graph->firstOut(i, n); }
deba@1979
    79
    void firstInc(UEdge &i, bool &d, const Node &n) const {
deba@1979
    80
      graph->firstInc(i, d, n);
deba@1979
    81
    }
deba@1979
    82
deba@1979
    83
    void next(Node& i) const { graph->next(i); }
deba@1979
    84
    void next(Edge& i) const { graph->next(i); }
deba@1979
    85
    void next(UEdge& i) const { graph->next(i); }
deba@1979
    86
    void nextIn(Edge& i) const { graph->nextIn(i); }
deba@1979
    87
    void nextOut(Edge& i) const { graph->nextOut(i); }
deba@1979
    88
    void nextInc(UEdge &i, bool &d) const { graph->nextInc(i, d); }
deba@1979
    89
deba@1979
    90
    Node source(const UEdge& e) const { return graph->source(e); }
deba@1979
    91
    Node target(const UEdge& e) const { return graph->target(e); }
deba@1979
    92
deba@1979
    93
    Node source(const Edge& e) const { return graph->source(e); }
deba@1979
    94
    Node target(const Edge& e) const { return graph->target(e); }
deba@1979
    95
deba@1979
    96
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
deba@1979
    97
    int nodeNum() const { return graph->nodeNum(); }
deba@1979
    98
    
deba@1979
    99
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
deba@1979
   100
    int edgeNum() const { return graph->edgeNum(); }
deba@2031
   101
    int uEdgeNum() const { return graph->uEdgeNum(); }
deba@1979
   102
deba@1979
   103
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1979
   104
    Edge findEdge(const Node& source, const Node& target, 
deba@1979
   105
		  const Edge& prev = INVALID) {
deba@1979
   106
      return graph->findEdge(source, target, prev);
deba@1979
   107
    }
deba@1979
   108
    UEdge findUEdge(const Node& source, const Node& target, 
deba@1979
   109
                    const UEdge& prev = INVALID) {
deba@1979
   110
      return graph->findUEdge(source, target, prev);
deba@1979
   111
    }
deba@1979
   112
  
deba@1979
   113
    Node addNode() const { return graph->addNode(); }
deba@1979
   114
    UEdge addEdge(const Node& source, const Node& target) const { 
deba@1979
   115
      return graph->addEdge(source, target); 
deba@1979
   116
    }
deba@1979
   117
deba@1979
   118
    void erase(const Node& i) const { graph->erase(i); }
deba@2031
   119
    void erase(const UEdge& i) const { graph->erase(i); }
deba@1979
   120
  
deba@1979
   121
    void clear() const { graph->clear(); }
deba@1979
   122
    
deba@2031
   123
    bool direction(const Edge& e) const { return graph->direction(e); }
deba@2031
   124
    Edge direct(const UEdge& e, bool d) const { return graph->direct(e, d); }
deba@2031
   125
deba@1979
   126
    int id(const Node& v) const { return graph->id(v); }
deba@2031
   127
    int id(const Edge& e) const { return graph->id(e); }
deba@1979
   128
    int id(const UEdge& e) const { return graph->id(e); }
deba@1979
   129
deba@2031
   130
    Node fromNodeId(int id) const {
deba@2031
   131
      return graph->fromNodeId(id);
deba@2031
   132
    }
deba@2031
   133
deba@2031
   134
    Edge fromEdgeId(int id) const {
deba@2031
   135
      return graph->fromEdgeId(id);
deba@2031
   136
    }
deba@2031
   137
deba@2031
   138
    UEdge fromUEdgeId(int id) const {
deba@2031
   139
      return graph->fromUEdgeId(id);
deba@2031
   140
    }
deba@1991
   141
deba@1991
   142
    int maxNodeId() const {
deba@1991
   143
      return graph->maxNodeId();
deba@1979
   144
    }
deba@1979
   145
deba@1991
   146
    int maxEdgeId() const {
deba@1991
   147
      return graph->maxEdgeId();
deba@1979
   148
    }
deba@1979
   149
deba@1991
   150
    int maxUEdgeId() const {
deba@1991
   151
      return graph->maxEdgeId();
deba@1979
   152
    }
deba@1979
   153
deba@1991
   154
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
deba@1991
   155
deba@1991
   156
    NodeNotifier& getNotifier(Node) const {
deba@1991
   157
      return graph->getNotifier(Node());
deba@1991
   158
    } 
deba@1991
   159
deba@1991
   160
    typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
deba@1991
   161
deba@1991
   162
    EdgeNotifier& getNotifier(Edge) const {
deba@1991
   163
      return graph->getNotifier(Edge());
deba@1991
   164
    } 
deba@1991
   165
deba@1991
   166
    typedef typename ItemSetTraits<Graph, UEdge>::ItemNotifier UEdgeNotifier;
deba@1991
   167
deba@1991
   168
    UEdgeNotifier& getNotifier(UEdge) const {
deba@1991
   169
      return graph->getNotifier(UEdge());
deba@1991
   170
    } 
deba@1979
   171
deba@1979
   172
    template <typename _Value>
deba@1979
   173
    class NodeMap : public Graph::template NodeMap<_Value> {
deba@1979
   174
    public:
deba@1979
   175
      typedef typename Graph::template NodeMap<_Value> Parent;
deba@1979
   176
      explicit NodeMap(const UGraphAdaptorBase<Graph>& ga) 
deba@1979
   177
	: Parent(*ga.graph) {}
deba@1979
   178
      NodeMap(const UGraphAdaptorBase<Graph>& ga, const _Value& value)
deba@1979
   179
	: Parent(*ga.graph, value) {}
deba@1979
   180
deba@1979
   181
      NodeMap& operator=(const NodeMap& cmap) {
deba@1979
   182
	return operator=<NodeMap>(cmap);
deba@1979
   183
      }
deba@1979
   184
deba@1979
   185
      template <typename CMap>
deba@1979
   186
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   187
        Parent::operator=(cmap);
deba@2031
   188
        return *this;
deba@1979
   189
      }
deba@2031
   190
deba@1979
   191
    };
deba@1979
   192
deba@1979
   193
    template <typename _Value>
deba@1979
   194
    class EdgeMap : public Graph::template EdgeMap<_Value> {
deba@1979
   195
    public:
deba@1979
   196
      typedef typename Graph::template EdgeMap<_Value> Parent;
deba@1979
   197
      explicit EdgeMap(const UGraphAdaptorBase<Graph>& ga) 
deba@1979
   198
	: Parent(*ga.graph) {}
deba@1979
   199
      EdgeMap(const UGraphAdaptorBase<Graph>& ga, const _Value& value)
deba@1979
   200
	: Parent(*ga.graph, value) {}
deba@1979
   201
deba@1979
   202
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@1979
   203
	return operator=<EdgeMap>(cmap);
deba@1979
   204
      }
deba@1979
   205
deba@1979
   206
      template <typename CMap>
deba@1979
   207
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   208
        Parent::operator=(cmap);
deba@1979
   209
	return *this;
deba@1979
   210
      }
deba@1979
   211
    };
deba@1979
   212
deba@1979
   213
    template <typename _Value>
deba@1979
   214
    class UEdgeMap : public Graph::template UEdgeMap<_Value> {
deba@1979
   215
    public:
deba@1979
   216
      typedef typename Graph::template UEdgeMap<_Value> Parent;
deba@1979
   217
      explicit UEdgeMap(const UGraphAdaptorBase<Graph>& ga) 
deba@1979
   218
	: Parent(*ga.graph) {}
deba@1979
   219
      UEdgeMap(const UGraphAdaptorBase<Graph>& ga, const _Value& value)
deba@1979
   220
	: Parent(*ga.graph, value) {}
deba@1979
   221
deba@1979
   222
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@1979
   223
	return operator=<UEdgeMap>(cmap);
deba@1979
   224
      }
deba@1979
   225
deba@1979
   226
      template <typename CMap>
deba@1979
   227
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
   228
        Parent::operator=(cmap);
deba@2031
   229
        return *this;
deba@1979
   230
      }
deba@1979
   231
    };
deba@1979
   232
deba@1979
   233
  };
deba@1979
   234
deba@1979
   235
  /// \ingroup graph_adaptors
deba@1979
   236
  template <typename _UGraph>
deba@1979
   237
  class UGraphAdaptor 
deba@1979
   238
    : public UGraphAdaptorExtender< UGraphAdaptorBase<_UGraph> > { 
deba@1979
   239
  public:
deba@1979
   240
    typedef _UGraph Graph;
deba@1979
   241
    typedef UGraphAdaptorExtender<UGraphAdaptorBase<_UGraph> > Parent;
deba@1979
   242
  protected:
deba@1979
   243
    UGraphAdaptor() : Parent() {}
deba@1979
   244
deba@1979
   245
  public:
deba@1979
   246
    explicit UGraphAdaptor(Graph& _graph) { setGraph(_graph); }
deba@1979
   247
  };
deba@1979
   248
deba@1979
   249
  template <typename _UGraph, typename NodeFilterMap, 
deba@1979
   250
	    typename UEdgeFilterMap, bool checked = true>
deba@1979
   251
  class SubUGraphAdaptorBase : public UGraphAdaptorBase<_UGraph> {
deba@1979
   252
  public:
deba@1979
   253
    typedef _UGraph Graph;
deba@2031
   254
    typedef SubUGraphAdaptorBase Adaptor;
deba@1979
   255
    typedef UGraphAdaptorBase<_UGraph> Parent;
deba@1979
   256
  protected:
deba@1979
   257
deba@1979
   258
    NodeFilterMap* node_filter_map;
deba@1979
   259
    UEdgeFilterMap* uedge_filter_map;
deba@1979
   260
deba@1979
   261
    SubUGraphAdaptorBase() 
deba@1979
   262
      : Parent(), node_filter_map(0), uedge_filter_map(0) { }
deba@1979
   263
deba@1979
   264
    void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
deba@1979
   265
      node_filter_map=&_node_filter_map;
deba@1979
   266
    }
deba@1979
   267
    void setUEdgeFilterMap(UEdgeFilterMap& _uedge_filter_map) {
deba@1979
   268
      uedge_filter_map=&_uedge_filter_map;
deba@1979
   269
    }
deba@1979
   270
deba@1979
   271
  public:
deba@1979
   272
deba@1979
   273
    typedef typename Parent::Node Node;
deba@1979
   274
    typedef typename Parent::Edge Edge;
deba@1979
   275
    typedef typename Parent::UEdge UEdge;
deba@1979
   276
deba@1979
   277
    void first(Node& i) const { 
deba@1979
   278
      Parent::first(i); 
deba@1979
   279
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1979
   280
    }
deba@1979
   281
deba@1979
   282
    void first(Edge& i) const { 
deba@1979
   283
      Parent::first(i); 
deba@1979
   284
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   285
	     || !(*node_filter_map)[Parent::source(i)]
deba@1979
   286
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1979
   287
    }
deba@1979
   288
deba@1979
   289
    void first(UEdge& i) const { 
deba@1979
   290
      Parent::first(i); 
deba@1979
   291
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   292
	     || !(*node_filter_map)[Parent::source(i)]
deba@1979
   293
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1979
   294
    }
deba@1979
   295
deba@1979
   296
    void firstIn(Edge& i, const Node& n) const { 
deba@1979
   297
      Parent::firstIn(i, n); 
deba@1979
   298
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   299
	     || !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i); 
deba@1979
   300
    }
deba@1979
   301
deba@1979
   302
    void firstOut(Edge& i, const Node& n) const { 
deba@1979
   303
      Parent::firstOut(i, n); 
deba@1979
   304
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   305
	     || !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i); 
deba@1979
   306
    }
deba@1979
   307
deba@1979
   308
    void firstInc(UEdge& i, bool& d, const Node& n) const { 
deba@1979
   309
      Parent::firstInc(i, d, n); 
deba@1979
   310
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   311
            || !(*node_filter_map)[Parent::target(i)])) Parent::nextInc(i, d); 
deba@1979
   312
    }
deba@1979
   313
deba@1979
   314
    void next(Node& i) const { 
deba@1979
   315
      Parent::next(i); 
deba@1979
   316
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1979
   317
    }
deba@1979
   318
deba@1979
   319
    void next(Edge& i) const { 
deba@1979
   320
      Parent::next(i); 
deba@1979
   321
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   322
	     || !(*node_filter_map)[Parent::source(i)]
deba@1979
   323
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1979
   324
    }
deba@1979
   325
deba@1979
   326
    void next(UEdge& i) const { 
deba@1979
   327
      Parent::next(i); 
deba@1979
   328
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   329
	     || !(*node_filter_map)[Parent::source(i)]
deba@1979
   330
	     || !(*node_filter_map)[Parent::target(i)])) Parent::next(i); 
deba@1979
   331
    }
deba@1979
   332
deba@1979
   333
    void nextIn(Edge& i) const { 
deba@1979
   334
      Parent::nextIn(i); 
deba@1979
   335
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   336
	     || !(*node_filter_map)[Parent::source(i)])) Parent::nextIn(i); 
deba@1979
   337
    }
deba@1979
   338
deba@1979
   339
    void nextOut(Edge& i) const { 
deba@1979
   340
      Parent::nextOut(i); 
deba@1979
   341
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   342
	     || !(*node_filter_map)[Parent::target(i)])) Parent::nextOut(i); 
deba@1979
   343
    }
deba@1979
   344
deba@1979
   345
    void nextInc(UEdge& i, bool& d) const { 
deba@1979
   346
      Parent::nextInc(i, d); 
deba@1979
   347
      while (i!=INVALID && (!(*uedge_filter_map)[i] 
deba@1979
   348
            || !(*node_filter_map)[Parent::source(i)])) Parent::nextInc(i, d); 
deba@1979
   349
    }
deba@1979
   350
deba@1979
   351
    ///\e
deba@1979
   352
deba@1979
   353
    /// This function hides \c n in the graph, i.e. the iteration 
deba@1979
   354
    /// jumps over it. This is done by simply setting the value of \c n  
deba@1979
   355
    /// to be false in the corresponding node-map.
deba@1979
   356
    void hide(const Node& n) const { node_filter_map->set(n, false); }
deba@1979
   357
deba@1979
   358
    ///\e
deba@1979
   359
deba@1979
   360
    /// This function hides \c e in the graph, i.e. the iteration 
deba@1979
   361
    /// jumps over it. This is done by simply setting the value of \c e  
deba@1979
   362
    /// to be false in the corresponding edge-map.
deba@1979
   363
    void hide(const UEdge& e) const { uedge_filter_map->set(e, false); }
deba@1979
   364
deba@1979
   365
    ///\e
deba@1979
   366
deba@1979
   367
    /// The value of \c n is set to be true in the node-map which stores 
deba@1979
   368
    /// hide information. If \c n was hidden previuosly, then it is shown 
deba@1979
   369
    /// again
deba@1979
   370
     void unHide(const Node& n) const { node_filter_map->set(n, true); }
deba@1979
   371
deba@1979
   372
    ///\e
deba@1979
   373
deba@1979
   374
    /// The value of \c e is set to be true in the edge-map which stores 
deba@1979
   375
    /// hide information. If \c e was hidden previuosly, then it is shown 
deba@1979
   376
    /// again
deba@1979
   377
    void unHide(const UEdge& e) const { uedge_filter_map->set(e, true); }
deba@1979
   378
deba@1979
   379
    /// Returns true if \c n is hidden.
deba@1979
   380
    
deba@1979
   381
    ///\e
deba@1979
   382
    ///
deba@1979
   383
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
deba@1979
   384
deba@1979
   385
    /// Returns true if \c n is hidden.
deba@1979
   386
    
deba@1979
   387
    ///\e
deba@1979
   388
    ///
deba@1979
   389
    bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; }
deba@1979
   390
deba@1979
   391
    typedef False NodeNumTag;
deba@1979
   392
    typedef False EdgeNumTag;
deba@1991
   393
deba@1991
   394
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1991
   395
    Edge findEdge(const Node& source, const Node& target, 
deba@1991
   396
		  const Edge& prev = INVALID) {
deba@1991
   397
      if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
deba@1991
   398
        return INVALID;
deba@1991
   399
      }
deba@1991
   400
      Edge edge = Parent::findEdge(source, target, prev);
deba@1991
   401
      while (edge != INVALID && !(*uedge_filter_map)[edge]) {
deba@1991
   402
        edge = Parent::findEdge(source, target, edge);
deba@1991
   403
      }
deba@1991
   404
      return edge;
deba@1991
   405
    }
deba@1991
   406
    UEdge findUEdge(const Node& source, const Node& target, 
deba@1991
   407
		  const UEdge& prev = INVALID) {
deba@1991
   408
      if (!(*node_filter_map)[source] || !(*node_filter_map)[target]) {
deba@1991
   409
        return INVALID;
deba@1991
   410
      }
deba@1991
   411
      UEdge uedge = Parent::findUEdge(source, target, prev);
deba@1991
   412
      while (uedge != INVALID && !(*uedge_filter_map)[uedge]) {
deba@1991
   413
        uedge = Parent::findUEdge(source, target, uedge);
deba@1991
   414
      }
deba@1991
   415
      return uedge;
deba@1991
   416
    }
deba@2031
   417
deba@2031
   418
    template <typename _Value>
deba@2031
   419
    class NodeMap 
deba@2031
   420
      : public SubMapExtender<Adaptor, 
deba@2031
   421
                              typename Parent::template NodeMap<_Value> > 
deba@2031
   422
    {
deba@2031
   423
    public:
deba@2031
   424
      typedef Adaptor Graph;
deba@2031
   425
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   426
                             template NodeMap<_Value> > Parent;
deba@2031
   427
    
deba@2031
   428
      NodeMap(const Graph& graph) 
deba@2031
   429
	: Parent(graph) {}
deba@2031
   430
      NodeMap(const Graph& graph, const _Value& value) 
deba@2031
   431
	: Parent(graph, value) {}
deba@2031
   432
    
deba@2031
   433
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
   434
	return operator=<NodeMap>(cmap);
deba@2031
   435
      }
deba@2031
   436
    
deba@2031
   437
      template <typename CMap>
deba@2031
   438
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   439
        Parent::operator=(cmap);
deba@2031
   440
	return *this;
deba@2031
   441
      }
deba@2031
   442
    };
deba@2031
   443
deba@2031
   444
    template <typename _Value>
deba@2031
   445
    class EdgeMap 
deba@2031
   446
      : public SubMapExtender<Adaptor, 
deba@2031
   447
                              typename Parent::template EdgeMap<_Value> > 
deba@2031
   448
    {
deba@2031
   449
    public:
deba@2031
   450
      typedef Adaptor Graph;
deba@2031
   451
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   452
                             template EdgeMap<_Value> > Parent;
deba@2031
   453
    
deba@2031
   454
      EdgeMap(const Graph& graph) 
deba@2031
   455
	: Parent(graph) {}
deba@2031
   456
      EdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   457
	: Parent(graph, value) {}
deba@2031
   458
    
deba@2031
   459
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
   460
	return operator=<EdgeMap>(cmap);
deba@2031
   461
      }
deba@2031
   462
    
deba@2031
   463
      template <typename CMap>
deba@2031
   464
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   465
        Parent::operator=(cmap);
deba@2031
   466
	return *this;
deba@2031
   467
      }
deba@2031
   468
    };
deba@2031
   469
deba@2031
   470
    template <typename _Value>
deba@2031
   471
    class UEdgeMap 
deba@2031
   472
      : public SubMapExtender<Adaptor, 
deba@2031
   473
                              typename Parent::template UEdgeMap<_Value> > 
deba@2031
   474
    {
deba@2031
   475
    public:
deba@2031
   476
      typedef Adaptor Graph;
deba@2031
   477
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   478
                             template UEdgeMap<_Value> > Parent;
deba@2031
   479
    
deba@2031
   480
      UEdgeMap(const Graph& graph) 
deba@2031
   481
	: Parent(graph) {}
deba@2031
   482
      UEdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   483
	: Parent(graph, value) {}
deba@2031
   484
    
deba@2031
   485
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@2031
   486
	return operator=<UEdgeMap>(cmap);
deba@2031
   487
      }
deba@2031
   488
    
deba@2031
   489
      template <typename CMap>
deba@2031
   490
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
   491
        Parent::operator=(cmap);
deba@2031
   492
	return *this;
deba@2031
   493
      }
deba@2031
   494
    };
deba@2031
   495
deba@1979
   496
  };
deba@1979
   497
deba@1979
   498
  template <typename _UGraph, typename NodeFilterMap, typename UEdgeFilterMap>
deba@1979
   499
  class SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, false> 
deba@1979
   500
    : public UGraphAdaptorBase<_UGraph> {
deba@1979
   501
  public:
deba@1979
   502
    typedef _UGraph Graph;
deba@2031
   503
    typedef SubUGraphAdaptorBase Adaptor;
deba@1979
   504
    typedef UGraphAdaptorBase<_UGraph> Parent;
deba@1979
   505
  protected:
deba@1979
   506
    NodeFilterMap* node_filter_map;
deba@1979
   507
    UEdgeFilterMap* uedge_filter_map;
deba@1979
   508
    SubUGraphAdaptorBase() : Parent(), 
deba@1979
   509
			    node_filter_map(0), uedge_filter_map(0) { }
deba@1979
   510
deba@1979
   511
    void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
deba@1979
   512
      node_filter_map=&_node_filter_map;
deba@1979
   513
    }
deba@1979
   514
    void setUEdgeFilterMap(UEdgeFilterMap& _uedge_filter_map) {
deba@1979
   515
      uedge_filter_map=&_uedge_filter_map;
deba@1979
   516
    }
deba@1979
   517
deba@1979
   518
  public:
deba@1979
   519
deba@1979
   520
    typedef typename Parent::Node Node;
deba@1979
   521
    typedef typename Parent::Edge Edge;
deba@1979
   522
    typedef typename Parent::UEdge UEdge;
deba@1979
   523
deba@1979
   524
    void first(Node& i) const { 
deba@1979
   525
      Parent::first(i); 
deba@1979
   526
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1979
   527
    }
deba@1979
   528
deba@1979
   529
    void first(Edge& i) const { 
deba@1979
   530
      Parent::first(i); 
deba@1979
   531
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i); 
deba@1979
   532
    }
deba@1979
   533
deba@1979
   534
    void first(UEdge& i) const { 
deba@1979
   535
      Parent::first(i); 
deba@1979
   536
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i); 
deba@1979
   537
    }
deba@1979
   538
deba@1979
   539
    void firstIn(Edge& i, const Node& n) const { 
deba@1979
   540
      Parent::firstIn(i, n); 
deba@1979
   541
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextIn(i); 
deba@1979
   542
    }
deba@1979
   543
deba@1979
   544
    void firstOut(Edge& i, const Node& n) const { 
deba@1979
   545
      Parent::firstOut(i, n); 
deba@1979
   546
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextOut(i); 
deba@1979
   547
    }
deba@1979
   548
deba@1979
   549
    void firstInc(UEdge& i, bool& d, const Node& n) const { 
deba@1979
   550
      Parent::firstInc(i, d, n); 
deba@1979
   551
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextInc(i, d); 
deba@1979
   552
    }
deba@1979
   553
deba@1979
   554
    void next(Node& i) const { 
deba@1979
   555
      Parent::next(i); 
deba@1979
   556
      while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
deba@1979
   557
    }
deba@1979
   558
    void next(Edge& i) const { 
deba@1979
   559
      Parent::next(i); 
deba@1979
   560
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i); 
deba@1979
   561
    }
deba@1979
   562
    void next(UEdge& i) const { 
deba@1979
   563
      Parent::next(i); 
deba@1979
   564
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::next(i); 
deba@1979
   565
    }
deba@1979
   566
    void nextIn(Edge& i) const { 
deba@1979
   567
      Parent::nextIn(i); 
deba@1979
   568
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextIn(i); 
deba@1979
   569
    }
deba@1979
   570
deba@1979
   571
    void nextOut(Edge& i) const { 
deba@1979
   572
      Parent::nextOut(i); 
deba@1979
   573
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextOut(i); 
deba@1979
   574
    }
deba@1979
   575
    void nextInc(UEdge& i, bool& d) const { 
deba@1979
   576
      Parent::nextInc(i, d); 
deba@1979
   577
      while (i!=INVALID && !(*uedge_filter_map)[i]) Parent::nextInc(i, d); 
deba@1979
   578
    }
deba@1979
   579
deba@1979
   580
    ///\e
deba@1979
   581
deba@1979
   582
    /// This function hides \c n in the graph, i.e. the iteration 
deba@1979
   583
    /// jumps over it. This is done by simply setting the value of \c n  
deba@1979
   584
    /// to be false in the corresponding node-map.
deba@1979
   585
    void hide(const Node& n) const { node_filter_map->set(n, false); }
deba@1979
   586
deba@1979
   587
    ///\e
deba@1979
   588
deba@1979
   589
    /// This function hides \c e in the graph, i.e. the iteration 
deba@1979
   590
    /// jumps over it. This is done by simply setting the value of \c e  
deba@1979
   591
    /// to be false in the corresponding edge-map.
deba@1979
   592
    void hide(const UEdge& e) const { uedge_filter_map->set(e, false); }
deba@1979
   593
deba@1979
   594
    ///\e
deba@1979
   595
deba@1979
   596
    /// The value of \c n is set to be true in the node-map which stores 
deba@1979
   597
    /// hide information. If \c n was hidden previuosly, then it is shown 
deba@1979
   598
    /// again
deba@1979
   599
     void unHide(const Node& n) const { node_filter_map->set(n, true); }
deba@1979
   600
deba@1979
   601
    ///\e
deba@1979
   602
deba@1979
   603
    /// The value of \c e is set to be true in the edge-map which stores 
deba@1979
   604
    /// hide information. If \c e was hidden previuosly, then it is shown 
deba@1979
   605
    /// again
deba@1979
   606
    void unHide(const UEdge& e) const { uedge_filter_map->set(e, true); }
deba@1979
   607
deba@1979
   608
    /// Returns true if \c n is hidden.
deba@1979
   609
    
deba@1979
   610
    ///\e
deba@1979
   611
    ///
deba@1979
   612
    bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
deba@1979
   613
deba@1979
   614
    /// Returns true if \c n is hidden.
deba@1979
   615
    
deba@1979
   616
    ///\e
deba@1979
   617
    ///
deba@1979
   618
    bool hidden(const UEdge& e) const { return !(*uedge_filter_map)[e]; }
deba@1979
   619
deba@1979
   620
    typedef False NodeNumTag;
deba@1979
   621
    typedef False EdgeNumTag;
deba@1991
   622
deba@1991
   623
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1991
   624
    Edge findEdge(const Node& source, const Node& target, 
deba@1991
   625
		  const Edge& prev = INVALID) {
deba@1991
   626
      Edge edge = Parent::findEdge(source, target, prev);
deba@1991
   627
      while (edge != INVALID && !(*uedge_filter_map)[edge]) {
deba@1991
   628
        edge = Parent::findEdge(source, target, edge);
deba@1991
   629
      }
deba@1991
   630
      return edge;
deba@1991
   631
    }
deba@1991
   632
    UEdge findUEdge(const Node& source, const Node& target, 
deba@1991
   633
		  const UEdge& prev = INVALID) {
deba@1991
   634
      UEdge uedge = Parent::findUEdge(source, target, prev);
deba@1991
   635
      while (uedge != INVALID && !(*uedge_filter_map)[uedge]) {
deba@1991
   636
        uedge = Parent::findUEdge(source, target, uedge);
deba@1991
   637
      }
deba@1991
   638
      return uedge;
deba@1991
   639
    }
deba@2031
   640
deba@2031
   641
    template <typename _Value>
deba@2031
   642
    class NodeMap 
deba@2031
   643
      : public SubMapExtender<Adaptor, 
deba@2031
   644
                              typename Parent::template NodeMap<_Value> > 
deba@2031
   645
    {
deba@2031
   646
    public:
deba@2031
   647
      typedef Adaptor Graph;
deba@2031
   648
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   649
                             template NodeMap<_Value> > Parent;
deba@2031
   650
    
deba@2031
   651
      NodeMap(const Graph& graph) 
deba@2031
   652
	: Parent(graph) {}
deba@2031
   653
      NodeMap(const Graph& graph, const _Value& value) 
deba@2031
   654
	: Parent(graph, value) {}
deba@2031
   655
    
deba@2031
   656
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
   657
	return operator=<NodeMap>(cmap);
deba@2031
   658
      }
deba@2031
   659
    
deba@2031
   660
      template <typename CMap>
deba@2031
   661
      NodeMap& operator=(const CMap& cmap) {
deba@2031
   662
        Parent::operator=(cmap);
deba@2031
   663
	return *this;
deba@2031
   664
      }
deba@2031
   665
    };
deba@2031
   666
deba@2031
   667
    template <typename _Value>
deba@2031
   668
    class EdgeMap 
deba@2031
   669
      : public SubMapExtender<Adaptor, 
deba@2031
   670
                              typename Parent::template EdgeMap<_Value> > 
deba@2031
   671
    {
deba@2031
   672
    public:
deba@2031
   673
      typedef Adaptor Graph;
deba@2031
   674
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   675
                             template EdgeMap<_Value> > Parent;
deba@2031
   676
    
deba@2031
   677
      EdgeMap(const Graph& graph) 
deba@2031
   678
	: Parent(graph) {}
deba@2031
   679
      EdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   680
	: Parent(graph, value) {}
deba@2031
   681
    
deba@2031
   682
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
   683
	return operator=<EdgeMap>(cmap);
deba@2031
   684
      }
deba@2031
   685
    
deba@2031
   686
      template <typename CMap>
deba@2031
   687
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
   688
        Parent::operator=(cmap);
deba@2031
   689
	return *this;
deba@2031
   690
      }
deba@2031
   691
    };
deba@2031
   692
deba@2031
   693
    template <typename _Value>
deba@2031
   694
    class UEdgeMap 
deba@2031
   695
      : public SubMapExtender<Adaptor, 
deba@2031
   696
                              typename Parent::template UEdgeMap<_Value> > 
deba@2031
   697
    {
deba@2031
   698
    public:
deba@2031
   699
      typedef Adaptor Graph;
deba@2031
   700
      typedef SubMapExtender<Adaptor, typename Parent::
deba@2031
   701
                             template UEdgeMap<_Value> > Parent;
deba@2031
   702
    
deba@2031
   703
      UEdgeMap(const Graph& graph) 
deba@2031
   704
	: Parent(graph) {}
deba@2031
   705
      UEdgeMap(const Graph& graph, const _Value& value) 
deba@2031
   706
	: Parent(graph, value) {}
deba@2031
   707
    
deba@2031
   708
      UEdgeMap& operator=(const UEdgeMap& cmap) {
deba@2031
   709
	return operator=<UEdgeMap>(cmap);
deba@2031
   710
      }
deba@2031
   711
    
deba@2031
   712
      template <typename CMap>
deba@2031
   713
      UEdgeMap& operator=(const CMap& cmap) {
deba@2031
   714
        Parent::operator=(cmap);
deba@2031
   715
	return *this;
deba@2031
   716
      }
deba@2031
   717
    };
deba@1979
   718
  };
deba@1979
   719
deba@1979
   720
  /// \ingroup graph_adaptors
deba@1979
   721
  ///
deba@1979
   722
  /// \brief A graph adaptor for hiding nodes and edges from an undirected 
deba@1979
   723
  /// graph.
deba@1979
   724
  /// 
deba@1979
   725
  /// SubUGraphAdaptor shows the undirected graph with filtered node-set and 
deba@1979
   726
  /// edge-set. If the \c checked parameter is true then it filters the edgeset
deba@1979
   727
  /// to do not get invalid edges without source or target.
deba@1979
   728
  /// 
deba@1979
   729
  /// If the \c checked template parameter is false then we have to note that 
deba@1979
   730
  /// the node-iterator cares only the filter on the node-set, and the 
deba@1979
   731
  /// edge-iterator cares only the filter on the edge-set.
deba@1979
   732
  /// This way the edge-map
deba@1979
   733
  /// should filter all edges which's source or target is filtered by the 
deba@1979
   734
  /// node-filter.
deba@1979
   735
  ///
deba@1979
   736
  /// Note that \c n is of type \c SubGA::NodeIt, but it can be converted to
deba@1979
   737
  /// \c Graph::Node that is why \c g.id(n) can be applied.
deba@1979
   738
  /// 
deba@1979
   739
  template<typename _UGraph, typename NodeFilterMap, 
deba@1979
   740
	   typename UEdgeFilterMap, bool checked = true>
deba@1979
   741
  class SubUGraphAdaptor : 
deba@1979
   742
    public UGraphAdaptorExtender<
deba@1979
   743
    SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, checked> > {
deba@1979
   744
  public:
deba@1979
   745
    typedef _UGraph Graph;
deba@1979
   746
    typedef UGraphAdaptorExtender<
deba@1979
   747
      SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap> > Parent;
deba@1979
   748
  protected:
deba@1979
   749
    SubUGraphAdaptor() { }
deba@1979
   750
  public:
deba@1979
   751
    SubUGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map, 
deba@1979
   752
		    UEdgeFilterMap& _uedge_filter_map) { 
deba@1979
   753
      setGraph(_graph);
deba@1979
   754
      setNodeFilterMap(_node_filter_map);
deba@1979
   755
      setUEdgeFilterMap(_uedge_filter_map);
deba@1979
   756
    }
deba@1979
   757
  };
deba@1979
   758
deba@1980
   759
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   760
  SubUGraphAdaptor<const UGraph, NodeFilterMap, EdgeFilterMap>
deba@1980
   761
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   762
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   763
    return SubUGraphAdaptor<const UGraph, NodeFilterMap, EdgeFilterMap>
deba@1980
   764
      (graph, nfm, efm);
deba@1980
   765
  }
deba@1980
   766
deba@1980
   767
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   768
  SubUGraphAdaptor<const UGraph, const NodeFilterMap, EdgeFilterMap>
deba@1980
   769
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   770
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   771
    return SubUGraphAdaptor<const UGraph, const NodeFilterMap, EdgeFilterMap>
deba@1980
   772
      (graph, nfm, efm);
deba@1980
   773
  }
deba@1980
   774
deba@1980
   775
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   776
  SubUGraphAdaptor<const UGraph, NodeFilterMap, const EdgeFilterMap>
deba@1980
   777
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   778
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   779
    return SubUGraphAdaptor<const UGraph, NodeFilterMap, const EdgeFilterMap>
deba@1980
   780
      (graph, nfm, efm);
deba@1980
   781
  }
deba@1980
   782
deba@1980
   783
  template<typename UGraph, typename NodeFilterMap, typename EdgeFilterMap>
deba@1980
   784
  SubUGraphAdaptor<const UGraph, const NodeFilterMap, const EdgeFilterMap>
deba@1980
   785
  subUGraphAdaptor(const UGraph& graph, 
deba@1980
   786
                   NodeFilterMap& nfm, EdgeFilterMap& efm) {
deba@1980
   787
    return SubUGraphAdaptor<const UGraph, const NodeFilterMap, 
deba@1980
   788
      const EdgeFilterMap>(graph, nfm, efm);
deba@1980
   789
  }
deba@1980
   790
deba@1979
   791
  /// \ingroup graph_adaptors
deba@1979
   792
  ///
deba@1980
   793
  /// \brief An adaptor for hiding nodes from an undirected graph.
deba@1979
   794
  ///
deba@1979
   795
  /// An adaptor for hiding nodes from an undirected graph.
deba@1979
   796
  /// This adaptor specializes SubUGraphAdaptor in the way that only
deba@1979
   797
  /// the node-set 
deba@1979
   798
  /// can be filtered. In usual case the checked parameter is true, we get the
deba@1979
   799
  /// induced subgraph. But if the checked parameter is false then we can only
deba@1979
   800
  /// filter only isolated nodes.
deba@1979
   801
  template<typename _UGraph, typename NodeFilterMap, bool checked = true>
deba@1979
   802
  class NodeSubUGraphAdaptor : 
deba@1979
   803
    public SubUGraphAdaptor<_UGraph, NodeFilterMap, 
deba@1979
   804
                            ConstMap<typename _UGraph::UEdge, bool>, checked> {
deba@1979
   805
  public:
deba@1979
   806
    typedef SubUGraphAdaptor<_UGraph, NodeFilterMap, 
deba@1979
   807
                             ConstMap<typename _UGraph::UEdge, bool> > Parent;
deba@1979
   808
    typedef _UGraph Graph;
deba@1979
   809
  protected:
deba@1985
   810
    ConstMap<typename _UGraph::UEdge, bool> const_true_map;
deba@1991
   811
deba@1991
   812
    NodeSubUGraphAdaptor() : const_true_map(true) {
deba@1991
   813
      Parent::setUEdgeFilterMap(const_true_map);
deba@1991
   814
    }
deba@1991
   815
deba@1979
   816
  public:
deba@1979
   817
    NodeSubUGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map) : 
deba@1979
   818
      Parent(), const_true_map(true) { 
deba@1979
   819
      Parent::setGraph(_graph);
deba@1979
   820
      Parent::setNodeFilterMap(_node_filter_map);
deba@1979
   821
      Parent::setUEdgeFilterMap(const_true_map);
deba@1979
   822
    }
deba@1979
   823
  };
deba@1979
   824
deba@1979
   825
  template<typename UGraph, typename NodeFilterMap>
deba@1979
   826
  NodeSubUGraphAdaptor<const UGraph, NodeFilterMap>
deba@1979
   827
  nodeSubUGraphAdaptor(const UGraph& graph, NodeFilterMap& nfm) {
deba@1979
   828
    return NodeSubUGraphAdaptor<const UGraph, NodeFilterMap>(graph, nfm);
deba@1979
   829
  }
deba@1979
   830
deba@1979
   831
  template<typename UGraph, typename NodeFilterMap>
deba@1979
   832
  NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap>
deba@1979
   833
  nodeSubUGraphAdaptor(const UGraph& graph, const NodeFilterMap& nfm) {
deba@1979
   834
    return NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap>(graph, nfm);
deba@1979
   835
  }
deba@1979
   836
deba@2042
   837
  /// \ingroup graph_adaptors
deba@2042
   838
  ///
deba@1979
   839
  /// \brief An adaptor for hiding undirected edges from an undirected graph.
deba@1979
   840
  ///
deba@1979
   841
  /// \warning Graph adaptors are in even more experimental state
deba@1979
   842
  /// than the other parts of the lib. Use them at you own risk.
deba@1979
   843
  ///
deba@1979
   844
  /// An adaptor for hiding undirected edges from an undirected graph.
deba@1979
   845
  /// This adaptor specializes SubUGraphAdaptor in the way that
deba@1979
   846
  /// only the edge-set 
deba@1979
   847
  /// can be filtered.
deba@1979
   848
  template<typename _UGraph, typename UEdgeFilterMap>
deba@1979
   849
  class EdgeSubUGraphAdaptor : 
deba@1979
   850
    public SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>, 
deba@1979
   851
                            UEdgeFilterMap, false> {
deba@1979
   852
  public:
deba@1979
   853
    typedef SubUGraphAdaptor<_UGraph, ConstMap<typename _UGraph::Node,bool>, 
deba@1979
   854
                             UEdgeFilterMap, false> Parent;
deba@1979
   855
    typedef _UGraph Graph;
deba@1979
   856
  protected:
deba@1979
   857
    ConstMap<typename Graph::Node, bool> const_true_map;
deba@1991
   858
deba@1991
   859
    EdgeSubUGraphAdaptor() : const_true_map(true) {
deba@1991
   860
      Parent::setNodeFilterMap(const_true_map);
deba@1991
   861
    }
deba@1991
   862
deba@1979
   863
  public:
deba@2031
   864
deba@1979
   865
    EdgeSubUGraphAdaptor(Graph& _graph, UEdgeFilterMap& _uedge_filter_map) : 
deba@1979
   866
      Parent(), const_true_map(true) { 
deba@1979
   867
      Parent::setGraph(_graph);
deba@1979
   868
      Parent::setNodeFilterMap(const_true_map);
deba@1979
   869
      Parent::setUEdgeFilterMap(_uedge_filter_map);
deba@1979
   870
    }
deba@2031
   871
deba@1979
   872
  };
deba@1979
   873
deba@1979
   874
  template<typename UGraph, typename EdgeFilterMap>
deba@1979
   875
  EdgeSubUGraphAdaptor<const UGraph, EdgeFilterMap>
deba@1979
   876
  edgeSubUGraphAdaptor(const UGraph& graph, EdgeFilterMap& efm) {
deba@1979
   877
    return EdgeSubUGraphAdaptor<const UGraph, EdgeFilterMap>(graph, efm);
deba@1979
   878
  }
deba@1979
   879
deba@1979
   880
  template<typename UGraph, typename EdgeFilterMap>
deba@1979
   881
  EdgeSubUGraphAdaptor<const UGraph, const EdgeFilterMap>
deba@1979
   882
  edgeSubUGraphAdaptor(const UGraph& graph, const EdgeFilterMap& efm) {
deba@1979
   883
    return EdgeSubUGraphAdaptor<const UGraph, const EdgeFilterMap>(graph, efm);
deba@1979
   884
  }
deba@1979
   885
deba@1979
   886
  template <typename _UGraph, typename _DirectionMap>
deba@1980
   887
  class DirUGraphAdaptorBase {
deba@1979
   888
  public:
deba@1979
   889
    
deba@1979
   890
    typedef _UGraph Graph;
deba@1979
   891
    typedef _DirectionMap DirectionMap;
deba@1979
   892
deba@1979
   893
    typedef typename _UGraph::Node Node;
deba@1979
   894
    typedef typename _UGraph::UEdge Edge;
deba@1979
   895
   
deba@1991
   896
    void reverseEdge(const Edge& edge) {
deba@1991
   897
      direction->set(edge, !(*direction)[edge]);
deba@1991
   898
    }
deba@1991
   899
deba@1979
   900
    void first(Node& i) const { graph->first(i); }
deba@1979
   901
    void first(Edge& i) const { graph->first(i); }
deba@1979
   902
    void firstIn(Edge& i, const Node& n) const {
deba@1979
   903
      bool d;
deba@1979
   904
      graph->firstInc(i, d, n);
deba@1979
   905
      while (i != INVALID && d == (*direction)[i]) graph->nextInc(i, d);
deba@1979
   906
    }
deba@1979
   907
    void firstOut(Edge& i, const Node& n ) const { 
deba@1979
   908
      bool d;
deba@1979
   909
      graph->firstInc(i, d, n);
deba@1979
   910
      while (i != INVALID && d != (*direction)[i]) graph->nextInc(i, d);
deba@1979
   911
    }
deba@1979
   912
deba@1979
   913
    void next(Node& i) const { graph->next(i); }
deba@1979
   914
    void next(Edge& i) const { graph->next(i); }
deba@1979
   915
    void nextIn(Edge& i) const {
deba@1979
   916
      bool d = !(*direction)[i];
deba@1979
   917
      graph->nextInc(i, d);
deba@1979
   918
      while (i != INVALID && d == (*direction)[i]) graph->nextInc(i, d);
deba@1979
   919
    }
deba@1979
   920
    void nextOut(Edge& i) const {
deba@1979
   921
      bool d = (*direction)[i];
deba@1979
   922
      graph->nextInc(i, d);
deba@1979
   923
      while (i != INVALID && d != (*direction)[i]) graph->nextInc(i, d);
deba@1979
   924
    }
deba@1979
   925
deba@1979
   926
    Node source(const Edge& e) const { 
deba@1979
   927
      return (*direction)[e] ? graph->source(e) : graph->target(e); 
deba@1979
   928
    }
deba@1979
   929
    Node target(const Edge& e) const { 
deba@1979
   930
      return (*direction)[e] ? graph->target(e) : graph->source(e); 
deba@1979
   931
    }
deba@1979
   932
deba@1979
   933
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
deba@1979
   934
    int nodeNum() const { return graph->nodeNum(); }
deba@1979
   935
    
deba@1979
   936
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
deba@1979
   937
    int edgeNum() const { return graph->uEdgeNum(); }
deba@1979
   938
deba@1979
   939
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@1979
   940
    Edge findEdge(const Node& source, const Node& target, 
deba@1979
   941
		  const Edge& prev = INVALID) {
deba@1979
   942
      Edge edge = prev;
deba@1979
   943
      bool d = edge == INVALID ? true : (*direction)[edge];
deba@1979
   944
      if (d) {
deba@1979
   945
        edge = graph->findUEdge(source, target, edge);
deba@1979
   946
        while (edge != INVALID && !(*direction)[edge]) {
deba@1979
   947
          graph->findUEdge(source, target, edge);
deba@1979
   948
        }
deba@1979
   949
        if (edge != INVALID) return edge;
deba@1979
   950
      }
deba@1979
   951
      graph->findUEdge(target, source, edge);
deba@1979
   952
      while (edge != INVALID && (*direction)[edge]) {
deba@1979
   953
        graph->findUEdge(source, target, edge);
deba@1979
   954
      }
deba@1979
   955
      return edge;
deba@1979
   956
    }
deba@1979
   957
  
deba@1979
   958
    Node addNode() const { 
deba@1979
   959
      return Node(graph->addNode()); 
deba@1979
   960
    }
deba@1979
   961
deba@1979
   962
    Edge addEdge(const Node& source, const Node& target) const {
deba@1979
   963
      Edge edge = graph->addEdge(source, target);
deba@1979
   964
      (*direction)[edge] = graph->source(edge) == source;
deba@1979
   965
      return edge; 
deba@1979
   966
    }
deba@1979
   967
deba@1979
   968
    void erase(const Node& i) const { graph->erase(i); }
deba@1979
   969
    void erase(const Edge& i) const { graph->erase(i); }
deba@1979
   970
  
deba@1979
   971
    void clear() const { graph->clear(); }
deba@1979
   972
    
deba@1979
   973
    int id(const Node& v) const { return graph->id(v); }
deba@1979
   974
    int id(const Edge& e) const { return graph->id(e); }
deba@1979
   975
deba@1991
   976
    int maxNodeId() const {
deba@1991
   977
      return graph->maxNodeId();
deba@1979
   978
    }
deba@1979
   979
deba@1991
   980
    int maxEdgeId() const {
deba@1991
   981
      return graph->maxEdgeId();
deba@1991
   982
    }
deba@1991
   983
deba@1991
   984
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
deba@1991
   985
deba@1991
   986
    NodeNotifier& getNotifier(Node) const {
deba@1991
   987
      return graph->getNotifier(Node());
deba@1991
   988
    } 
deba@1991
   989
deba@1991
   990
    typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
deba@1991
   991
deba@1991
   992
    EdgeNotifier& getNotifier(Edge) const {
deba@1991
   993
      return graph->getNotifier(Edge());
deba@1991
   994
    } 
deba@1991
   995
deba@1979
   996
    template <typename _Value>
deba@1979
   997
    class NodeMap : public _UGraph::template NodeMap<_Value> {
deba@1979
   998
    public:
deba@2031
   999
deba@1979
  1000
      typedef typename _UGraph::template NodeMap<_Value> Parent;
deba@2031
  1001
deba@1980
  1002
      explicit NodeMap(const DirUGraphAdaptorBase& ga) 
deba@2031
  1003
	: Parent(*ga.graph) {}
deba@2031
  1004
deba@1980
  1005
      NodeMap(const DirUGraphAdaptorBase& ga, const _Value& value)
deba@2031
  1006
	: Parent(*ga.graph, value) {}
deba@2031
  1007
deba@2031
  1008
      NodeMap& operator=(const NodeMap& cmap) {
deba@2031
  1009
        return operator=<NodeMap>(cmap);
deba@2031
  1010
      }
deba@2031
  1011
deba@2031
  1012
      template <typename CMap>
deba@2031
  1013
      NodeMap& operator=(const CMap& cmap) {
deba@2031
  1014
        Parent::operator=(cmap);
deba@2031
  1015
        return *this;
deba@2031
  1016
      }
deba@2031
  1017
deba@1979
  1018
    };
deba@1979
  1019
deba@1979
  1020
    template <typename _Value>
deba@1979
  1021
    class EdgeMap : public _UGraph::template UEdgeMap<_Value> {
deba@1979
  1022
    public:
deba@2031
  1023
deba@1980
  1024
      typedef typename _UGraph::template UEdgeMap<_Value> Parent;
deba@2031
  1025
deba@1980
  1026
      explicit EdgeMap(const DirUGraphAdaptorBase& ga) 
deba@1979
  1027
	: Parent(*ga.graph) { }
deba@2031
  1028
deba@1980
  1029
      EdgeMap(const DirUGraphAdaptorBase& ga, const _Value& value)
deba@1979
  1030
	: Parent(*ga.graph, value) { }
deba@2031
  1031
deba@2031
  1032
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@2031
  1033
        return operator=<EdgeMap>(cmap);
deba@2031
  1034
      }
deba@2031
  1035
deba@2031
  1036
      template <typename CMap>
deba@2031
  1037
      EdgeMap& operator=(const CMap& cmap) {
deba@2031
  1038
        Parent::operator=(cmap);
deba@2031
  1039
        return *this;
deba@2031
  1040
      }
deba@1979
  1041
    };
deba@1979
  1042
deba@1979
  1043
    
deba@1979
  1044
deba@1979
  1045
  protected:
deba@1979
  1046
    Graph* graph;
deba@1979
  1047
    DirectionMap* direction;
deba@1979
  1048
deba@1979
  1049
    void setDirectionMap(DirectionMap& _direction) {
deba@1979
  1050
      direction = &_direction;
deba@1979
  1051
    }
deba@1979
  1052
deba@1979
  1053
    void setGraph(Graph& _graph) {
deba@1979
  1054
      graph = &_graph;
deba@1979
  1055
    }
deba@1979
  1056
deba@1979
  1057
  };
deba@1979
  1058
deba@1979
  1059
deba@1980
  1060
  /// \ingroup graph_adaptors
deba@1991
  1061
  ///
deba@1991
  1062
  /// \brief A directed graph is made from an undirected graph by an adaptor
deba@1980
  1063
  ///
deba@1980
  1064
  /// This adaptor gives a direction for each uedge in the undirected graph.
deba@1980
  1065
  /// The direction of the edges stored in the DirectionMap. This map is
deba@1980
  1066
  /// a bool map on the undirected edges. If the uedge is mapped to true
deba@1980
  1067
  /// then the direction of the directed edge will be the same as the
deba@1980
  1068
  /// default direction of the uedge. The edges can be easily reverted
deba@1980
  1069
  /// by the reverseEdge member in the adaptor.  
deba@1980
  1070
  template<typename _Graph, 
deba@1980
  1071
           typename DirectionMap = typename _Graph::template UEdgeMap<bool> > 
deba@1980
  1072
  class DirUGraphAdaptor : 
deba@1979
  1073
    public GraphAdaptorExtender<
deba@1980
  1074
    DirUGraphAdaptorBase<_Graph, DirectionMap> > {
deba@1979
  1075
  public:
deba@1979
  1076
    typedef _Graph Graph;
deba@1979
  1077
    typedef GraphAdaptorExtender<
deba@1980
  1078
      DirUGraphAdaptorBase<_Graph, DirectionMap> > Parent;
deba@1979
  1079
  protected:
deba@1980
  1080
    DirUGraphAdaptor() { }
deba@1979
  1081
  public:
deba@1980
  1082
    DirUGraphAdaptor(_Graph& _graph, DirectionMap& _direction_map) { 
deba@1979
  1083
      setGraph(_graph);
deba@1979
  1084
      setDirectionMap(_direction_map);
deba@1979
  1085
    }
deba@1979
  1086
  };
deba@1979
  1087
deba@1979
  1088
  template<typename UGraph, typename DirectionMap>
deba@1980
  1089
  DirUGraphAdaptor<const UGraph, DirectionMap>
deba@1980
  1090
  dirUGraphAdaptor(const UGraph& graph, DirectionMap& dm) {
deba@1980
  1091
    return DirUGraphAdaptor<const UGraph, DirectionMap>(graph, dm);
deba@1979
  1092
  }
deba@1979
  1093
deba@1979
  1094
  template<typename UGraph, typename DirectionMap>
deba@1980
  1095
  DirUGraphAdaptor<const UGraph, const DirectionMap>
deba@1980
  1096
  dirUGraphAdaptor(const UGraph& graph, const DirectionMap& dm) {
deba@1980
  1097
    return DirUGraphAdaptor<const UGraph, const DirectionMap>(graph, dm);
deba@1979
  1098
  }
deba@1979
  1099
deba@1979
  1100
}
deba@1979
  1101
deba@1979
  1102
#endif