deba@416: /* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@414:  *
deba@416:  * This file is a part of LEMON, a generic C++ optimization library.
deba@414:  *
deba@414:  * Copyright (C) 2003-2008
deba@414:  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@414:  * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@414:  *
deba@414:  * Permission to use, modify and distribute this software is granted
deba@414:  * provided that this copyright notice appears in all copies. For
deba@414:  * precise terms see the accompanying LICENSE file.
deba@414:  *
deba@414:  * This software is provided "AS IS" with no warranty of any kind,
deba@414:  * express or implied, and with no claim as to its suitability for any
deba@414:  * purpose.
deba@414:  *
deba@414:  */
deba@414: 
deba@416: #ifndef LEMON_ADAPTORS_H
deba@416: #define LEMON_ADAPTORS_H
deba@416: 
deba@416: /// \ingroup graph_adaptors
deba@416: /// \file
deba@416: /// \brief Several graph adaptors
deba@414: ///
deba@416: /// This file contains several useful adaptors for digraphs and graphs.
deba@414: 
deba@414: #include <lemon/core.h>
deba@414: #include <lemon/maps.h>
deba@414: #include <lemon/bits/variant.h>
deba@414: 
deba@414: #include <lemon/bits/graph_adaptor_extender.h>
deba@414: #include <lemon/tolerance.h>
deba@414: 
deba@414: #include <algorithm>
deba@414: 
deba@414: namespace lemon {
deba@414: 
deba@414:   template<typename _Digraph>
deba@414:   class DigraphAdaptorBase {
deba@414:   public:
deba@414:     typedef _Digraph Digraph;
deba@414:     typedef DigraphAdaptorBase Adaptor;
deba@414:     typedef Digraph ParentDigraph;
deba@414: 
deba@414:   protected:
deba@414:     Digraph* _digraph;
deba@414:     DigraphAdaptorBase() : _digraph(0) { }
deba@414:     void setDigraph(Digraph& digraph) { _digraph = &digraph; }
deba@414: 
deba@414:   public:
deba@414:     DigraphAdaptorBase(Digraph& digraph) : _digraph(&digraph) { }
deba@414: 
deba@414:     typedef typename Digraph::Node Node;
deba@414:     typedef typename Digraph::Arc Arc;
deba@416: 
deba@414:     void first(Node& i) const { _digraph->first(i); }
deba@414:     void first(Arc& i) const { _digraph->first(i); }
deba@414:     void firstIn(Arc& i, const Node& n) const { _digraph->firstIn(i, n); }
deba@414:     void firstOut(Arc& i, const Node& n ) const { _digraph->firstOut(i, n); }
deba@414: 
deba@414:     void next(Node& i) const { _digraph->next(i); }
deba@414:     void next(Arc& i) const { _digraph->next(i); }
deba@414:     void nextIn(Arc& i) const { _digraph->nextIn(i); }
deba@414:     void nextOut(Arc& i) const { _digraph->nextOut(i); }
deba@414: 
deba@414:     Node source(const Arc& a) const { return _digraph->source(a); }
deba@414:     Node target(const Arc& a) const { return _digraph->target(a); }
deba@414: 
deba@414:     typedef NodeNumTagIndicator<Digraph> NodeNumTag;
deba@414:     int nodeNum() const { return _digraph->nodeNum(); }
deba@416: 
deba@414:     typedef EdgeNumTagIndicator<Digraph> EdgeNumTag;
deba@414:     int arcNum() const { return _digraph->arcNum(); }
deba@414: 
deba@414:     typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
deba@414:     Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
deba@414:       return _digraph->findArc(u, v, prev);
deba@414:     }
deba@416: 
deba@414:     Node addNode() { return _digraph->addNode(); }
deba@414:     Arc addArc(const Node& u, const Node& v) { return _digraph->addArc(u, v); }
deba@414: 
deba@414:     void erase(const Node& n) const { _digraph->erase(n); }
deba@414:     void erase(const Arc& a) const { _digraph->erase(a); }
deba@416: 
deba@414:     void clear() const { _digraph->clear(); }
deba@416: 
deba@414:     int id(const Node& n) const { return _digraph->id(n); }
deba@414:     int id(const Arc& a) const { return _digraph->id(a); }
deba@414: 
deba@414:     Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
deba@414:     Arc arcFromId(int ix) const { return _digraph->arcFromId(ix); }
deba@414: 
deba@414:     int maxNodeId() const { return _digraph->maxNodeId(); }
deba@414:     int maxArcId() const { return _digraph->maxArcId(); }
deba@414: 
deba@414:     typedef typename ItemSetTraits<Digraph, Node>::ItemNotifier NodeNotifier;
deba@416:     NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
deba@414: 
deba@414:     typedef typename ItemSetTraits<Digraph, Arc>::ItemNotifier ArcNotifier;
deba@416:     ArcNotifier& notifier(Arc) const { return _digraph->notifier(Arc()); }
deba@416: 
deba@414:     template <typename _Value>
deba@414:     class NodeMap : public Digraph::template NodeMap<_Value> {
deba@414:     public:
deba@414: 
deba@414:       typedef typename Digraph::template NodeMap<_Value> Parent;
deba@414: 
deba@416:       explicit NodeMap(const Adaptor& adaptor)
deba@416:         : Parent(*adaptor._digraph) {}
deba@414: 
deba@414:       NodeMap(const Adaptor& adaptor, const _Value& value)
deba@416:         : Parent(*adaptor._digraph, value) { }
deba@414: 
deba@414:     private:
deba@414:       NodeMap& operator=(const NodeMap& cmap) {
deba@414:         return operator=<NodeMap>(cmap);
deba@414:       }
deba@414: 
deba@414:       template <typename CMap>
deba@414:       NodeMap& operator=(const CMap& cmap) {
deba@414:         Parent::operator=(cmap);
deba@414:         return *this;
deba@414:       }
deba@416: 
deba@414:     };
deba@414: 
deba@414:     template <typename _Value>
deba@414:     class ArcMap : public Digraph::template ArcMap<_Value> {
deba@414:     public:
deba@416: 
deba@414:       typedef typename Digraph::template ArcMap<_Value> Parent;
deba@416: 
deba@416:       explicit ArcMap(const Adaptor& adaptor)
deba@416:         : Parent(*adaptor._digraph) {}
deba@414: 
deba@414:       ArcMap(const Adaptor& adaptor, const _Value& value)
deba@416:         : Parent(*adaptor._digraph, value) {}
deba@414: 
deba@414:     private:
deba@414:       ArcMap& operator=(const ArcMap& cmap) {
deba@414:         return operator=<ArcMap>(cmap);
deba@414:       }
deba@414: 
deba@414:       template <typename CMap>
deba@414:       ArcMap& operator=(const CMap& cmap) {
deba@414:         Parent::operator=(cmap);
deba@414:         return *this;
deba@414:       }
deba@414: 
deba@414:     };
deba@414: 
deba@414:   };
deba@414: 
deba@416:   template<typename _Graph>
deba@416:   class GraphAdaptorBase {
deba@416:   public:
deba@416:     typedef _Graph Graph;
deba@416:     typedef Graph ParentGraph;
deba@416: 
deba@416:   protected:
deba@416:     Graph* _graph;
deba@416: 
deba@416:     GraphAdaptorBase() : _graph(0) {}
deba@416: 
deba@416:     void setGraph(Graph& graph) { _graph = &graph; }
deba@416: 
deba@416:   public:
deba@416:     GraphAdaptorBase(Graph& graph) : _graph(&graph) {}
deba@416: 
deba@416:     typedef typename Graph::Node Node;
deba@416:     typedef typename Graph::Arc Arc;
deba@416:     typedef typename Graph::Edge Edge;
deba@416: 
deba@416:     void first(Node& i) const { _graph->first(i); }
deba@416:     void first(Arc& i) const { _graph->first(i); }
deba@416:     void first(Edge& i) const { _graph->first(i); }
deba@416:     void firstIn(Arc& i, const Node& n) const { _graph->firstIn(i, n); }
deba@416:     void firstOut(Arc& i, const Node& n ) const { _graph->firstOut(i, n); }
deba@416:     void firstInc(Edge &i, bool &d, const Node &n) const {
deba@416:       _graph->firstInc(i, d, n);
deba@416:     }
deba@416: 
deba@416:     void next(Node& i) const { _graph->next(i); }
deba@416:     void next(Arc& i) const { _graph->next(i); }
deba@416:     void next(Edge& i) const { _graph->next(i); }
deba@416:     void nextIn(Arc& i) const { _graph->nextIn(i); }
deba@416:     void nextOut(Arc& i) const { _graph->nextOut(i); }
deba@416:     void nextInc(Edge &i, bool &d) const { _graph->nextInc(i, d); }
deba@416: 
deba@416:     Node u(const Edge& e) const { return _graph->u(e); }
deba@416:     Node v(const Edge& e) const { return _graph->v(e); }
deba@416: 
deba@416:     Node source(const Arc& a) const { return _graph->source(a); }
deba@416:     Node target(const Arc& a) const { return _graph->target(a); }
deba@416: 
deba@416:     typedef NodeNumTagIndicator<Graph> NodeNumTag;
deba@416:     int nodeNum() const { return _graph->nodeNum(); }
deba@416: 
deba@416:     typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
deba@416:     int arcNum() const { return _graph->arcNum(); }
deba@416:     int edgeNum() const { return _graph->edgeNum(); }
deba@416: 
deba@416:     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@416:     Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
deba@416:       return _graph->findArc(u, v, prev);
deba@416:     }
deba@416:     Edge findEdge(const Node& u, const Node& v, const Edge& prev = INVALID) {
deba@416:       return _graph->findEdge(u, v, prev);
deba@416:     }
deba@416: 
deba@416:     Node addNode() { return _graph->addNode(); }
deba@416:     Edge addEdge(const Node& u, const Node& v) { return _graph->addEdge(u, v); }
deba@416: 
deba@416:     void erase(const Node& i) { _graph->erase(i); }
deba@416:     void erase(const Edge& i) { _graph->erase(i); }
deba@416: 
deba@416:     void clear() { _graph->clear(); }
deba@416: 
deba@416:     bool direction(const Arc& a) const { return _graph->direction(a); }
deba@416:     Arc direct(const Edge& e, bool d) const { return _graph->direct(e, d); }
deba@416: 
deba@416:     int id(const Node& v) const { return _graph->id(v); }
deba@416:     int id(const Arc& a) const { return _graph->id(a); }
deba@416:     int id(const Edge& e) const { return _graph->id(e); }
deba@416: 
deba@416:     Node nodeFromId(int ix) const { return _graph->nodeFromId(ix); }
deba@416:     Arc arcFromId(int ix) const { return _graph->arcFromId(ix); }
deba@416:     Edge edgeFromId(int ix) const { return _graph->edgeFromId(ix); }
deba@416: 
deba@416:     int maxNodeId() const { return _graph->maxNodeId(); }
deba@416:     int maxArcId() const { return _graph->maxArcId(); }
deba@416:     int maxEdgeId() const { return _graph->maxEdgeId(); }
deba@416: 
deba@416:     typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
deba@416:     NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
deba@416: 
deba@416:     typedef typename ItemSetTraits<Graph, Arc>::ItemNotifier ArcNotifier;
deba@416:     ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
deba@416: 
deba@416:     typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
deba@416:     EdgeNotifier& notifier(Edge) const { return _graph->notifier(Edge()); }
deba@416: 
deba@416:     template <typename _Value>
deba@416:     class NodeMap : public Graph::template NodeMap<_Value> {
deba@416:     public:
deba@416:       typedef typename Graph::template NodeMap<_Value> Parent;
deba@416:       explicit NodeMap(const GraphAdaptorBase<Graph>& adapter)
deba@416:         : Parent(*adapter._graph) {}
deba@416:       NodeMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
deba@416:         : Parent(*adapter._graph, value) {}
deba@416: 
deba@416:     private:
deba@416:       NodeMap& operator=(const NodeMap& cmap) {
deba@416:         return operator=<NodeMap>(cmap);
deba@416:       }
deba@416: 
deba@416:       template <typename CMap>
deba@416:       NodeMap& operator=(const CMap& cmap) {
deba@416:         Parent::operator=(cmap);
deba@416:         return *this;
deba@416:       }
deba@416: 
deba@416:     };
deba@416: 
deba@416:     template <typename _Value>
deba@416:     class ArcMap : public Graph::template ArcMap<_Value> {
deba@416:     public:
deba@416:       typedef typename Graph::template ArcMap<_Value> Parent;
deba@416:       explicit ArcMap(const GraphAdaptorBase<Graph>& adapter)
deba@416:         : Parent(*adapter._graph) {}
deba@416:       ArcMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
deba@416:         : Parent(*adapter._graph, value) {}
deba@416: 
deba@416:     private:
deba@416:       ArcMap& operator=(const ArcMap& cmap) {
deba@416:         return operator=<ArcMap>(cmap);
deba@416:       }
deba@416: 
deba@416:       template <typename CMap>
deba@416:       ArcMap& operator=(const CMap& cmap) {
deba@416:         Parent::operator=(cmap);
deba@416:         return *this;
deba@416:       }
deba@416:     };
deba@416: 
deba@416:     template <typename _Value>
deba@416:     class EdgeMap : public Graph::template EdgeMap<_Value> {
deba@416:     public:
deba@416:       typedef typename Graph::template EdgeMap<_Value> Parent;
deba@416:       explicit EdgeMap(const GraphAdaptorBase<Graph>& adapter)
deba@416:         : Parent(*adapter._graph) {}
deba@416:       EdgeMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
deba@416:         : Parent(*adapter._graph, value) {}
deba@416: 
deba@416:     private:
deba@416:       EdgeMap& operator=(const EdgeMap& cmap) {
deba@416:         return operator=<EdgeMap>(cmap);
deba@416:       }
deba@416: 
deba@416:       template <typename CMap>
deba@416:       EdgeMap& operator=(const CMap& cmap) {
deba@416:         Parent::operator=(cmap);
deba@416:         return *this;
deba@416:       }
deba@416:     };
deba@416: 
deba@416:   };
deba@414: 
deba@414:   template <typename _Digraph>
deba@416:   class ReverseDigraphBase : public DigraphAdaptorBase<_Digraph> {
deba@414:   public:
deba@414:     typedef _Digraph Digraph;
deba@414:     typedef DigraphAdaptorBase<_Digraph> Parent;
deba@414:   protected:
deba@416:     ReverseDigraphBase() : Parent() { }
deba@414:   public:
deba@414:     typedef typename Parent::Node Node;
deba@414:     typedef typename Parent::Arc Arc;
deba@414: 
deba@414:     void firstIn(Arc& a, const Node& n) const { Parent::firstOut(a, n); }
deba@414:     void firstOut(Arc& a, const Node& n ) const { Parent::firstIn(a, n); }
deba@414: 
deba@414:     void nextIn(Arc& a) const { Parent::nextOut(a); }
deba@414:     void nextOut(Arc& a) const { Parent::nextIn(a); }
deba@414: 
deba@414:     Node source(const Arc& a) const { return Parent::target(a); }
deba@414:     Node target(const Arc& a) const { return Parent::source(a); }
deba@414: 
deba@416:     Arc addArc(const Node& u, const Node& v) { return Parent::addArc(v, u); }
deba@416: 
deba@414:     typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
deba@416:     Arc findArc(const Node& u, const Node& v,
deba@416:                 const Arc& prev = INVALID) {
deba@414:       return Parent::findArc(v, u, prev);
deba@414:     }
deba@414: 
deba@414:   };
deba@416: 
deba@416:   /// \ingroup graph_adaptors
deba@414:   ///
deba@416:   /// \brief A digraph adaptor which reverses the orientation of the arcs.
deba@414:   ///
deba@416:   /// ReverseDigraph reverses the arcs in the adapted digraph. The
deba@416:   /// SubDigraph is conform to the \ref concepts::Digraph
deba@416:   /// "Digraph concept".
deba@414:   ///
deba@416:   /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
deba@416:   /// "Digraph concept". The type can be specified to be const.
deba@414:   template<typename _Digraph>
deba@416:   class ReverseDigraph :
deba@416:     public DigraphAdaptorExtender<ReverseDigraphBase<_Digraph> > {
deba@414:   public:
deba@414:     typedef _Digraph Digraph;
deba@414:     typedef DigraphAdaptorExtender<
deba@416:       ReverseDigraphBase<_Digraph> > Parent;
deba@414:   protected:
deba@416:     ReverseDigraph() { }
deba@414:   public:
deba@415: 
deba@415:     /// \brief Constructor
deba@415:     ///
deba@416:     /// Creates a reverse digraph adaptor for the given digraph
deba@416:     explicit ReverseDigraph(Digraph& digraph) {
deba@416:       Parent::setDigraph(digraph);
deba@414:     }
deba@414:   };
deba@414: 
deba@414:   /// \brief Just gives back a reverse digraph adaptor
deba@414:   ///
deba@414:   /// Just gives back a reverse digraph adaptor
deba@414:   template<typename Digraph>
deba@416:   ReverseDigraph<const Digraph> reverseDigraph(const Digraph& digraph) {
deba@416:     return ReverseDigraph<const Digraph>(digraph);
deba@414:   }
deba@414: 
deba@416:   template <typename _Digraph, typename _NodeFilterMap,
deba@416:             typename _ArcFilterMap, bool _checked = true>
deba@416:   class SubDigraphBase : public DigraphAdaptorBase<_Digraph> {
deba@414:   public:
deba@414:     typedef _Digraph Digraph;
deba@414:     typedef _NodeFilterMap NodeFilterMap;
deba@414:     typedef _ArcFilterMap ArcFilterMap;
deba@414: 
deba@416:     typedef SubDigraphBase Adaptor;
deba@414:     typedef DigraphAdaptorBase<_Digraph> Parent;
deba@414:   protected:
deba@414:     NodeFilterMap* _node_filter;
deba@414:     ArcFilterMap* _arc_filter;
deba@416:     SubDigraphBase()
deba@414:       : Parent(), _node_filter(0), _arc_filter(0) { }
deba@414: 
deba@414:     void setNodeFilterMap(NodeFilterMap& node_filter) {
deba@414:       _node_filter = &node_filter;
deba@414:     }
deba@414:     void setArcFilterMap(ArcFilterMap& arc_filter) {
deba@414:       _arc_filter = &arc_filter;
deba@414:     }
deba@414: 
deba@414:   public:
deba@414: 
deba@414:     typedef typename Parent::Node Node;
deba@414:     typedef typename Parent::Arc Arc;
deba@414: 
deba@416:     void first(Node& i) const {
deba@416:       Parent::first(i);
deba@416:       while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
deba@414:     }
deba@414: 
deba@416:     void first(Arc& i) const {
deba@416:       Parent::first(i);
deba@416:       while (i != INVALID && (!(*_arc_filter)[i]
deba@416:                               || !(*_node_filter)[Parent::source(i)]
deba@416:                               || !(*_node_filter)[Parent::target(i)]))
deba@416:         Parent::next(i);
deba@414:     }
deba@414: 
deba@416:     void firstIn(Arc& i, const Node& n) const {
deba@416:       Parent::firstIn(i, n);
deba@416:       while (i != INVALID && (!(*_arc_filter)[i]
deba@416:                               || !(*_node_filter)[Parent::source(i)]))
deba@416:         Parent::nextIn(i);
deba@414:     }
deba@414: 
deba@416:     void firstOut(Arc& i, const Node& n) const {
deba@416:       Parent::firstOut(i, n);
deba@416:       while (i != INVALID && (!(*_arc_filter)[i]
deba@416:                               || !(*_node_filter)[Parent::target(i)]))
deba@416:         Parent::nextOut(i);
deba@414:     }
deba@414: 
deba@416:     void next(Node& i) const {
deba@416:       Parent::next(i);
deba@416:       while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
deba@414:     }
deba@414: 
deba@416:     void next(Arc& i) const {
deba@416:       Parent::next(i);
deba@416:       while (i != INVALID && (!(*_arc_filter)[i]
deba@416:                               || !(*_node_filter)[Parent::source(i)]
deba@416:                               || !(*_node_filter)[Parent::target(i)]))
deba@416:         Parent::next(i);
deba@414:     }
deba@414: 
deba@416:     void nextIn(Arc& i) const {
deba@416:       Parent::nextIn(i);
deba@416:       while (i != INVALID && (!(*_arc_filter)[i]
deba@416:                               || !(*_node_filter)[Parent::source(i)]))
deba@416:         Parent::nextIn(i);
deba@414:     }
deba@414: 
deba@416:     void nextOut(Arc& i) const {
deba@416:       Parent::nextOut(i);
deba@416:       while (i != INVALID && (!(*_arc_filter)[i]
deba@416:                               || !(*_node_filter)[Parent::target(i)]))
deba@416:         Parent::nextOut(i);
deba@414:     }
deba@414: 
deba@414:     void hide(const Node& n) const { _node_filter->set(n, false); }
deba@414:     void hide(const Arc& a) const { _arc_filter->set(a, false); }
deba@414: 
deba@415:     void unHide(const Node& n) const { _node_filter->set(n, true); }
deba@414:     void unHide(const Arc& a) const { _arc_filter->set(a, true); }
deba@414: 
deba@414:     bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
deba@414:     bool hidden(const Arc& a) const { return !(*_arc_filter)[a]; }
deba@414: 
deba@414:     typedef False NodeNumTag;
deba@414:     typedef False EdgeNumTag;
deba@414: 
deba@414:     typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
deba@416:     Arc findArc(const Node& source, const Node& target,
deba@416:                 const Arc& prev = INVALID) {
deba@414:       if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
deba@414:         return INVALID;
deba@414:       }
deba@414:       Arc arc = Parent::findArc(source, target, prev);
deba@414:       while (arc != INVALID && !(*_arc_filter)[arc]) {
deba@414:         arc = Parent::findArc(source, target, arc);
deba@414:       }
deba@414:       return arc;
deba@414:     }
deba@414: 
deba@414:     template <typename _Value>
deba@416:     class NodeMap : public SubMapExtender<Adaptor,
deba@416:       typename Parent::template NodeMap<_Value> > {
deba@414:     public:
deba@414:       typedef _Value Value;
deba@414:       typedef SubMapExtender<Adaptor, typename Parent::
deba@414:                              template NodeMap<Value> > MapParent;
deba@416: 
deba@416:       NodeMap(const Adaptor& adaptor)
deba@416:         : MapParent(adaptor) {}
deba@416:       NodeMap(const Adaptor& adaptor, const Value& value)
deba@416:         : MapParent(adaptor, value) {}
deba@416: 
deba@414:     private:
deba@414:       NodeMap& operator=(const NodeMap& cmap) {
deba@416:         return operator=<NodeMap>(cmap);
deba@414:       }
deba@416: 
deba@414:       template <typename CMap>
deba@414:       NodeMap& operator=(const CMap& cmap) {
deba@414:         MapParent::operator=(cmap);
deba@416:         return *this;
deba@414:       }
deba@414:     };
deba@414: 
deba@414:     template <typename _Value>
deba@416:     class ArcMap : public SubMapExtender<Adaptor,
deba@416:       typename Parent::template ArcMap<_Value> > {
deba@414:     public:
deba@414:       typedef _Value Value;
deba@414:       typedef SubMapExtender<Adaptor, typename Parent::
deba@414:                              template ArcMap<Value> > MapParent;
deba@416: 
deba@416:       ArcMap(const Adaptor& adaptor)
deba@416:         : MapParent(adaptor) {}
deba@416:       ArcMap(const Adaptor& adaptor, const Value& value)
deba@416:         : MapParent(adaptor, value) {}
deba@416: 
deba@414:     private:
deba@414:       ArcMap& operator=(const ArcMap& cmap) {
deba@416:         return operator=<ArcMap>(cmap);
deba@414:       }
deba@416: 
deba@414:       template <typename CMap>
deba@414:       ArcMap& operator=(const CMap& cmap) {
deba@414:         MapParent::operator=(cmap);
deba@416:         return *this;
deba@414:       }
deba@414:     };
deba@414: 
deba@414:   };
deba@414: 
deba@414:   template <typename _Digraph, typename _NodeFilterMap, typename _ArcFilterMap>
deba@416:   class SubDigraphBase<_Digraph, _NodeFilterMap, _ArcFilterMap, false>
deba@414:     : public DigraphAdaptorBase<_Digraph> {
deba@414:   public:
deba@414:     typedef _Digraph Digraph;
deba@414:     typedef _NodeFilterMap NodeFilterMap;
deba@414:     typedef _ArcFilterMap ArcFilterMap;
deba@414: 
deba@416:     typedef SubDigraphBase Adaptor;
deba@414:     typedef DigraphAdaptorBase<Digraph> Parent;
deba@414:   protected:
deba@414:     NodeFilterMap* _node_filter;
deba@414:     ArcFilterMap* _arc_filter;
deba@416:     SubDigraphBase()
deba@414:       : Parent(), _node_filter(0), _arc_filter(0) { }
deba@414: 
deba@414:     void setNodeFilterMap(NodeFilterMap& node_filter) {
deba@414:       _node_filter = &node_filter;
deba@414:     }
deba@414:     void setArcFilterMap(ArcFilterMap& arc_filter) {
deba@414:       _arc_filter = &arc_filter;
deba@414:     }
deba@414: 
deba@414:   public:
deba@414: 
deba@414:     typedef typename Parent::Node Node;
deba@414:     typedef typename Parent::Arc Arc;
deba@414: 
deba@416:     void first(Node& i) const {
deba@416:       Parent::first(i);
deba@416:       while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
deba@414:     }
deba@414: 
deba@416:     void first(Arc& i) const {
deba@416:       Parent::first(i);
deba@416:       while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
deba@414:     }
deba@414: 
deba@416:     void firstIn(Arc& i, const Node& n) const {
deba@416:       Parent::firstIn(i, n);
deba@416:       while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
deba@414:     }
deba@414: 
deba@416:     void firstOut(Arc& i, const Node& n) const {
deba@416:       Parent::firstOut(i, n);
deba@416:       while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
deba@414:     }
deba@414: 
deba@416:     void next(Node& i) const {
deba@416:       Parent::next(i);
deba@416:       while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
deba@414:     }
deba@416:     void next(Arc& i) const {
deba@416:       Parent::next(i);
deba@416:       while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
deba@414:     }
deba@416:     void nextIn(Arc& i) const {
deba@416:       Parent::nextIn(i);
deba@416:       while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
deba@414:     }
deba@414: 
deba@416:     void nextOut(Arc& i) const {
deba@416:       Parent::nextOut(i);
deba@416:       while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
deba@414:     }
deba@414: 
deba@414:     void hide(const Node& n) const { _node_filter->set(n, false); }
deba@414:     void hide(const Arc& e) const { _arc_filter->set(e, false); }
deba@414: 
deba@415:     void unHide(const Node& n) const { _node_filter->set(n, true); }
deba@414:     void unHide(const Arc& e) const { _arc_filter->set(e, true); }
deba@414: 
deba@414:     bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
deba@414:     bool hidden(const Arc& e) const { return !(*_arc_filter)[e]; }
deba@414: 
deba@414:     typedef False NodeNumTag;
deba@414:     typedef False EdgeNumTag;
deba@414: 
deba@414:     typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
deba@416:     Arc findArc(const Node& source, const Node& target,
deba@416:                 const Arc& prev = INVALID) {
deba@414:       if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
deba@414:         return INVALID;
deba@414:       }
deba@414:       Arc arc = Parent::findArc(source, target, prev);
deba@414:       while (arc != INVALID && !(*_arc_filter)[arc]) {
deba@414:         arc = Parent::findArc(source, target, arc);
deba@414:       }
deba@414:       return arc;
deba@414:     }
deba@414: 
deba@414:     template <typename _Value>
deba@416:     class NodeMap : public SubMapExtender<Adaptor,
deba@416:       typename Parent::template NodeMap<_Value> > {
deba@414:     public:
deba@414:       typedef _Value Value;
deba@414:       typedef SubMapExtender<Adaptor, typename Parent::
deba@414:                              template NodeMap<Value> > MapParent;
deba@416: 
deba@416:       NodeMap(const Adaptor& adaptor)
deba@416:         : MapParent(adaptor) {}
deba@416:       NodeMap(const Adaptor& adaptor, const Value& value)
deba@416:         : MapParent(adaptor, value) {}
deba@416: 
deba@414:     private:
deba@414:       NodeMap& operator=(const NodeMap& cmap) {
deba@416:         return operator=<NodeMap>(cmap);
deba@414:       }
deba@416: 
deba@414:       template <typename CMap>
deba@414:       NodeMap& operator=(const CMap& cmap) {
deba@414:         MapParent::operator=(cmap);
deba@416:         return *this;
deba@414:       }
deba@414:     };
deba@414: 
deba@414:     template <typename _Value>
deba@416:     class ArcMap : public SubMapExtender<Adaptor,
deba@416:       typename Parent::template ArcMap<_Value> > {
deba@414:     public:
deba@414:       typedef _Value Value;
deba@414:       typedef SubMapExtender<Adaptor, typename Parent::
deba@414:                              template ArcMap<Value> > MapParent;
deba@416: 
deba@416:       ArcMap(const Adaptor& adaptor)
deba@416:         : MapParent(adaptor) {}
deba@416:       ArcMap(const Adaptor& adaptor, const Value& value)
deba@416:         : MapParent(adaptor, value) {}
deba@416: 
deba@414:     private:
deba@414:       ArcMap& operator=(const ArcMap& cmap) {
deba@416:         return operator=<ArcMap>(cmap);
deba@414:       }
deba@416: 
deba@414:       template <typename CMap>
deba@414:       ArcMap& operator=(const CMap& cmap) {
deba@414:         MapParent::operator=(cmap);
deba@416:         return *this;
deba@414:       }
deba@414:     };
deba@414: 
deba@414:   };
deba@414: 
deba@414:   /// \ingroup graph_adaptors
deba@414:   ///
deba@416:   /// \brief An adaptor for hiding nodes and arcs in a digraph
deba@416:   ///
deba@416:   /// SubDigraph hides nodes and arcs in a digraph. A bool node map
deba@416:   /// and a bool arc map must be specified, which define the filters
deba@416:   /// for nodes and arcs. Just the nodes and arcs with true value are
deba@416:   /// shown in the subdigraph. The SubDigraph is conform to the \ref
deba@416:   /// concepts::Digraph "Digraph concept". If the \c _checked parameter
deba@416:   /// is true, then the arcs incident to filtered nodes are also
deba@416:   /// filtered out.
deba@416:   ///
deba@416:   /// \tparam _Digraph It must be conform to the \ref
deba@416:   /// concepts::Digraph "Digraph concept". The type can be specified
deba@416:   /// to const.
deba@416:   /// \tparam _NodeFilterMap A bool valued node map of the the adapted digraph.
deba@416:   /// \tparam _ArcFilterMap A bool valued arc map of the the adapted digraph.
deba@416:   /// \tparam _checked If the parameter is false then the arc filtering
deba@416:   /// is not checked with respect to node filter. Otherwise, each arc
deba@416:   /// is automatically filtered, which is incident to a filtered node.
deba@416:   ///
deba@416:   /// \see FilterNodes
deba@416:   /// \see FilterArcs
deba@416:   template<typename _Digraph,
deba@416:            typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
deba@416:            typename _ArcFilterMap = typename _Digraph::template ArcMap<bool>,
deba@416:            bool _checked = true>
deba@416:   class SubDigraph
deba@416:     : public DigraphAdaptorExtender<
deba@416:       SubDigraphBase<_Digraph, _NodeFilterMap, _ArcFilterMap, _checked> > {
deba@414:   public:
deba@414:     typedef _Digraph Digraph;
deba@414:     typedef _NodeFilterMap NodeFilterMap;
deba@414:     typedef _ArcFilterMap ArcFilterMap;
deba@414: 
deba@414:     typedef DigraphAdaptorExtender<
deba@416:       SubDigraphBase<Digraph, NodeFilterMap, ArcFilterMap, _checked> >
deba@414:     Parent;
deba@414: 
deba@415:     typedef typename Parent::Node Node;
deba@415:     typedef typename Parent::Arc Arc;
deba@415: 
deba@414:   protected:
deba@416:     SubDigraph() { }
deba@414:   public:
deba@414: 
deba@415:     /// \brief Constructor
deba@415:     ///
deba@416:     /// Creates a subdigraph for the given digraph with
deba@415:     /// given node and arc map filters.
deba@416:     SubDigraph(Digraph& digraph, NodeFilterMap& node_filter,
deba@416:                ArcFilterMap& arc_filter) {
deba@414:       setDigraph(digraph);
deba@414:       setNodeFilterMap(node_filter);
deba@414:       setArcFilterMap(arc_filter);
deba@414:     }
deba@414: 
deba@415:     /// \brief Hides the node of the graph
deba@415:     ///
deba@416:     /// This function hides \c n in the digraph, i.e. the iteration
deba@416:     /// jumps over it. This is done by simply setting the value of \c n
deba@415:     /// to be false in the corresponding node-map.
deba@415:     void hide(const Node& n) const { Parent::hide(n); }
deba@415: 
deba@415:     /// \brief Hides the arc of the graph
deba@415:     ///
deba@416:     /// This function hides \c a in the digraph, i.e. the iteration
deba@415:     /// jumps over it. This is done by simply setting the value of \c a
deba@415:     /// to be false in the corresponding arc-map.
deba@415:     void hide(const Arc& a) const { Parent::hide(a); }
deba@415: 
deba@415:     /// \brief Unhides the node of the graph
deba@415:     ///
deba@416:     /// The value of \c n is set to be true in the node-map which stores
deba@416:     /// hide information. If \c n was hidden previuosly, then it is shown
deba@415:     /// again
deba@415:     void unHide(const Node& n) const { Parent::unHide(n); }
deba@415: 
deba@415:     /// \brief Unhides the arc of the graph
deba@415:     ///
deba@416:     /// The value of \c a is set to be true in the arc-map which stores
deba@416:     /// hide information. If \c a was hidden previuosly, then it is shown
deba@415:     /// again
deba@415:     void unHide(const Arc& a) const { Parent::unHide(a); }
deba@415: 
deba@415:     /// \brief Returns true if \c n is hidden.
deba@415:     ///
deba@415:     /// Returns true if \c n is hidden.
deba@415:     ///
deba@415:     bool hidden(const Node& n) const { return Parent::hidden(n); }
deba@415: 
deba@415:     /// \brief Returns true if \c a is hidden.
deba@415:     ///
deba@415:     /// Returns true if \c a is hidden.
deba@415:     ///
deba@415:     bool hidden(const Arc& a) const { return Parent::hidden(a); }
deba@415: 
deba@414:   };
deba@414: 
deba@416:   /// \brief Just gives back a subdigraph
deba@414:   ///
deba@416:   /// Just gives back a subdigraph
deba@414:   template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
deba@416:   SubDigraph<const Digraph, NodeFilterMap, ArcFilterMap>
deba@416:   subDigraph(const Digraph& digraph, NodeFilterMap& nfm, ArcFilterMap& afm) {
deba@416:     return SubDigraph<const Digraph, NodeFilterMap, ArcFilterMap>
deba@414:       (digraph, nfm, afm);
deba@414:   }
deba@414: 
deba@414:   template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
deba@416:   SubDigraph<const Digraph, const NodeFilterMap, ArcFilterMap>
deba@416:   subDigraph(const Digraph& digraph,
deba@416:              const NodeFilterMap& nfm, ArcFilterMap& afm) {
deba@416:     return SubDigraph<const Digraph, const NodeFilterMap, ArcFilterMap>
deba@414:       (digraph, nfm, afm);
deba@414:   }
deba@414: 
deba@414:   template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
deba@416:   SubDigraph<const Digraph, NodeFilterMap, const ArcFilterMap>
deba@416:   subDigraph(const Digraph& digraph,
deba@416:              NodeFilterMap& nfm, const ArcFilterMap& afm) {
deba@416:     return SubDigraph<const Digraph, NodeFilterMap, const ArcFilterMap>
deba@414:       (digraph, nfm, afm);
deba@414:   }
deba@414: 
deba@414:   template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
deba@416:   SubDigraph<const Digraph, const NodeFilterMap, const ArcFilterMap>
deba@416:   subDigraph(const Digraph& digraph,
deba@416:              const NodeFilterMap& nfm, const ArcFilterMap& afm) {
deba@416:     return SubDigraph<const Digraph, const NodeFilterMap,
deba@414:       const ArcFilterMap>(digraph, nfm, afm);
deba@414:   }
deba@414: 
deba@414: 
deba@416:   template <typename _Graph, typename NodeFilterMap,
deba@416:             typename EdgeFilterMap, bool _checked = true>
deba@416:   class SubGraphBase : public GraphAdaptorBase<_Graph> {
deba@416:   public:
deba@416:     typedef _Graph Graph;
deba@416:     typedef SubGraphBase Adaptor;
deba@416:     typedef GraphAdaptorBase<_Graph> Parent;
deba@416:   protected:
deba@416: 
deba@416:     NodeFilterMap* _node_filter_map;
deba@416:     EdgeFilterMap* _edge_filter_map;
deba@416: 
deba@416:     SubGraphBase()
deba@416:       : Parent(), _node_filter_map(0), _edge_filter_map(0) { }
deba@416: 
deba@416:     void setNodeFilterMap(NodeFilterMap& node_filter_map) {
deba@416:       _node_filter_map=&node_filter_map;
deba@416:     }
deba@416:     void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
deba@416:       _edge_filter_map=&edge_filter_map;
deba@416:     }
deba@416: 
deba@416:   public:
deba@416: 
deba@416:     typedef typename Parent::Node Node;
deba@416:     typedef typename Parent::Arc Arc;
deba@416:     typedef typename Parent::Edge Edge;
deba@416: 
deba@416:     void first(Node& i) const {
deba@416:       Parent::first(i);
deba@416:       while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
deba@416:     }
deba@416: 
deba@416:     void first(Arc& i) const {
deba@416:       Parent::first(i);
deba@416:       while (i!=INVALID && (!(*_edge_filter_map)[i]
deba@416:                             || !(*_node_filter_map)[Parent::source(i)]
deba@416:                             || !(*_node_filter_map)[Parent::target(i)]))
deba@416:         Parent::next(i);
deba@416:     }
deba@416: 
deba@416:     void first(Edge& i) const {
deba@416:       Parent::first(i);
deba@416:       while (i!=INVALID && (!(*_edge_filter_map)[i]
deba@416:                             || !(*_node_filter_map)[Parent::u(i)]
deba@416:                             || !(*_node_filter_map)[Parent::v(i)]))
deba@416:         Parent::next(i);
deba@416:     }
deba@416: 
deba@416:     void firstIn(Arc& i, const Node& n) const {
deba@416:       Parent::firstIn(i, n);
deba@416:       while (i!=INVALID && (!(*_edge_filter_map)[i]
deba@416:                             || !(*_node_filter_map)[Parent::source(i)]))
deba@416:         Parent::nextIn(i);
deba@416:     }
deba@416: 
deba@416:     void firstOut(Arc& i, const Node& n) const {
deba@416:       Parent::firstOut(i, n);
deba@416:       while (i!=INVALID && (!(*_edge_filter_map)[i]
deba@416:                             || !(*_node_filter_map)[Parent::target(i)]))
deba@416:         Parent::nextOut(i);
deba@416:     }
deba@416: 
deba@416:     void firstInc(Edge& i, bool& d, const Node& n) const {
deba@416:       Parent::firstInc(i, d, n);
deba@416:       while (i!=INVALID && (!(*_edge_filter_map)[i]
deba@416:                             || !(*_node_filter_map)[Parent::u(i)]
deba@416:                             || !(*_node_filter_map)[Parent::v(i)]))
deba@416:         Parent::nextInc(i, d);
deba@416:     }
deba@416: 
deba@416:     void next(Node& i) const {
deba@416:       Parent::next(i);
deba@416:       while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
deba@416:     }
deba@416: 
deba@416:     void next(Arc& i) const {
deba@416:       Parent::next(i);
deba@416:       while (i!=INVALID && (!(*_edge_filter_map)[i]
deba@416:                             || !(*_node_filter_map)[Parent::source(i)]
deba@416:                             || !(*_node_filter_map)[Parent::target(i)]))
deba@416:         Parent::next(i);
deba@416:     }
deba@416: 
deba@416:     void next(Edge& i) const {
deba@416:       Parent::next(i);
deba@416:       while (i!=INVALID && (!(*_edge_filter_map)[i]
deba@416:                             || !(*_node_filter_map)[Parent::u(i)]
deba@416:                             || !(*_node_filter_map)[Parent::v(i)]))
deba@416:         Parent::next(i);
deba@416:     }
deba@416: 
deba@416:     void nextIn(Arc& i) const {
deba@416:       Parent::nextIn(i);
deba@416:       while (i!=INVALID && (!(*_edge_filter_map)[i]
deba@416:                             || !(*_node_filter_map)[Parent::source(i)]))
deba@416:         Parent::nextIn(i);
deba@416:     }
deba@416: 
deba@416:     void nextOut(Arc& i) const {
deba@416:       Parent::nextOut(i);
deba@416:       while (i!=INVALID && (!(*_edge_filter_map)[i]
deba@416:                             || !(*_node_filter_map)[Parent::target(i)]))
deba@416:         Parent::nextOut(i);
deba@416:     }
deba@416: 
deba@416:     void nextInc(Edge& i, bool& d) const {
deba@416:       Parent::nextInc(i, d);
deba@416:       while (i!=INVALID && (!(*_edge_filter_map)[i]
deba@416:                             || !(*_node_filter_map)[Parent::u(i)]
deba@416:                             || !(*_node_filter_map)[Parent::v(i)]))
deba@416:         Parent::nextInc(i, d);
deba@416:     }
deba@416: 
deba@416:     void hide(const Node& n) const { _node_filter_map->set(n, false); }
deba@416:     void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
deba@416: 
deba@416:     void unHide(const Node& n) const { _node_filter_map->set(n, true); }
deba@416:     void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
deba@416: 
deba@416:     bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; }
deba@416:     bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
deba@416: 
deba@416:     typedef False NodeNumTag;
deba@416:     typedef False EdgeNumTag;
deba@416: 
deba@416:     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@416:     Arc findArc(const Node& u, const Node& v,
deba@416:                 const Arc& prev = INVALID) {
deba@416:       if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
deba@416:         return INVALID;
deba@416:       }
deba@416:       Arc arc = Parent::findArc(u, v, prev);
deba@416:       while (arc != INVALID && !(*_edge_filter_map)[arc]) {
deba@416:         arc = Parent::findArc(u, v, arc);
deba@416:       }
deba@416:       return arc;
deba@416:     }
deba@416:     Edge findEdge(const Node& u, const Node& v,
deba@416:                   const Edge& prev = INVALID) {
deba@416:       if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
deba@416:         return INVALID;
deba@416:       }
deba@416:       Edge edge = Parent::findEdge(u, v, prev);
deba@416:       while (edge != INVALID && !(*_edge_filter_map)[edge]) {
deba@416:         edge = Parent::findEdge(u, v, edge);
deba@416:       }
deba@416:       return edge;
deba@416:     }
deba@416: 
deba@416:     template <typename _Value>
deba@416:     class NodeMap : public SubMapExtender<Adaptor,
deba@416:       typename Parent::template NodeMap<_Value> > {
deba@416:     public:
deba@416:       typedef _Value Value;
deba@416:       typedef SubMapExtender<Adaptor, typename Parent::
deba@416:                              template NodeMap<Value> > MapParent;
deba@416: 
deba@416:       NodeMap(const Adaptor& adaptor)
deba@416:         : MapParent(adaptor) {}
deba@416:       NodeMap(const Adaptor& adaptor, const Value& value)
deba@416:         : MapParent(adaptor, value) {}
deba@416: 
deba@416:     private:
deba@416:       NodeMap& operator=(const NodeMap& cmap) {
deba@416:         return operator=<NodeMap>(cmap);
deba@416:       }
deba@416: 
deba@416:       template <typename CMap>
deba@416:       NodeMap& operator=(const CMap& cmap) {
deba@416:         MapParent::operator=(cmap);
deba@416:         return *this;
deba@416:       }
deba@416:     };
deba@416: 
deba@416:     template <typename _Value>
deba@416:     class ArcMap : public SubMapExtender<Adaptor,
deba@416:       typename Parent::template ArcMap<_Value> > {
deba@416:     public:
deba@416:       typedef _Value Value;
deba@416:       typedef SubMapExtender<Adaptor, typename Parent::
deba@416:                              template ArcMap<Value> > MapParent;
deba@416: 
deba@416:       ArcMap(const Adaptor& adaptor)
deba@416:         : MapParent(adaptor) {}
deba@416:       ArcMap(const Adaptor& adaptor, const Value& value)
deba@416:         : MapParent(adaptor, value) {}
deba@416: 
deba@416:     private:
deba@416:       ArcMap& operator=(const ArcMap& cmap) {
deba@416:         return operator=<ArcMap>(cmap);
deba@416:       }
deba@416: 
deba@416:       template <typename CMap>
deba@416:       ArcMap& operator=(const CMap& cmap) {
deba@416:         MapParent::operator=(cmap);
deba@416:         return *this;
deba@416:       }
deba@416:     };
deba@416: 
deba@416:     template <typename _Value>
deba@416:     class EdgeMap : public SubMapExtender<Adaptor,
deba@416:       typename Parent::template EdgeMap<_Value> > {
deba@416:     public:
deba@416:       typedef _Value Value;
deba@416:       typedef SubMapExtender<Adaptor, typename Parent::
deba@416:                              template EdgeMap<Value> > MapParent;
deba@416: 
deba@416:       EdgeMap(const Adaptor& adaptor)
deba@416:         : MapParent(adaptor) {}
deba@416: 
deba@416:       EdgeMap(const Adaptor& adaptor, const Value& value)
deba@416:         : MapParent(adaptor, value) {}
deba@416: 
deba@416:     private:
deba@416:       EdgeMap& operator=(const EdgeMap& cmap) {
deba@416:         return operator=<EdgeMap>(cmap);
deba@416:       }
deba@416: 
deba@416:       template <typename CMap>
deba@416:       EdgeMap& operator=(const CMap& cmap) {
deba@416:         MapParent::operator=(cmap);
deba@416:         return *this;
deba@416:       }
deba@416:     };
deba@416: 
deba@416:   };
deba@416: 
deba@416:   template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
deba@416:   class SubGraphBase<_Graph, NodeFilterMap, EdgeFilterMap, false>
deba@416:     : public GraphAdaptorBase<_Graph> {
deba@416:   public:
deba@416:     typedef _Graph Graph;
deba@416:     typedef SubGraphBase Adaptor;
deba@416:     typedef GraphAdaptorBase<_Graph> Parent;
deba@416:   protected:
deba@416:     NodeFilterMap* _node_filter_map;
deba@416:     EdgeFilterMap* _edge_filter_map;
deba@416:     SubGraphBase() : Parent(),
deba@416:                      _node_filter_map(0), _edge_filter_map(0) { }
deba@416: 
deba@416:     void setNodeFilterMap(NodeFilterMap& node_filter_map) {
deba@416:       _node_filter_map=&node_filter_map;
deba@416:     }
deba@416:     void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
deba@416:       _edge_filter_map=&edge_filter_map;
deba@416:     }
deba@416: 
deba@416:   public:
deba@416: 
deba@416:     typedef typename Parent::Node Node;
deba@416:     typedef typename Parent::Arc Arc;
deba@416:     typedef typename Parent::Edge Edge;
deba@416: 
deba@416:     void first(Node& i) const {
deba@416:       Parent::first(i);
deba@416:       while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
deba@416:     }
deba@416: 
deba@416:     void first(Arc& i) const {
deba@416:       Parent::first(i);
deba@416:       while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
deba@416:     }
deba@416: 
deba@416:     void first(Edge& i) const {
deba@416:       Parent::first(i);
deba@416:       while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
deba@416:     }
deba@416: 
deba@416:     void firstIn(Arc& i, const Node& n) const {
deba@416:       Parent::firstIn(i, n);
deba@416:       while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i);
deba@416:     }
deba@416: 
deba@416:     void firstOut(Arc& i, const Node& n) const {
deba@416:       Parent::firstOut(i, n);
deba@416:       while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i);
deba@416:     }
deba@416: 
deba@416:     void firstInc(Edge& i, bool& d, const Node& n) const {
deba@416:       Parent::firstInc(i, d, n);
deba@416:       while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d);
deba@416:     }
deba@416: 
deba@416:     void next(Node& i) const {
deba@416:       Parent::next(i);
deba@416:       while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
deba@416:     }
deba@416:     void next(Arc& i) const {
deba@416:       Parent::next(i);
deba@416:       while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
deba@416:     }
deba@416:     void next(Edge& i) const {
deba@416:       Parent::next(i);
deba@416:       while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
deba@416:     }
deba@416:     void nextIn(Arc& i) const {
deba@416:       Parent::nextIn(i);
deba@416:       while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i);
deba@416:     }
deba@416: 
deba@416:     void nextOut(Arc& i) const {
deba@416:       Parent::nextOut(i);
deba@416:       while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i);
deba@416:     }
deba@416:     void nextInc(Edge& i, bool& d) const {
deba@416:       Parent::nextInc(i, d);
deba@416:       while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d);
deba@416:     }
deba@416: 
deba@416:     void hide(const Node& n) const { _node_filter_map->set(n, false); }
deba@416:     void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
deba@416: 
deba@416:     void unHide(const Node& n) const { _node_filter_map->set(n, true); }
deba@416:     void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
deba@416: 
deba@416:     bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; }
deba@416:     bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
deba@416: 
deba@416:     typedef False NodeNumTag;
deba@416:     typedef False EdgeNumTag;
deba@416: 
deba@416:     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@416:     Arc findArc(const Node& u, const Node& v,
deba@416:                 const Arc& prev = INVALID) {
deba@416:       Arc arc = Parent::findArc(u, v, prev);
deba@416:       while (arc != INVALID && !(*_edge_filter_map)[arc]) {
deba@416:         arc = Parent::findArc(u, v, arc);
deba@416:       }
deba@416:       return arc;
deba@416:     }
deba@416:     Edge findEdge(const Node& u, const Node& v,
deba@416:                   const Edge& prev = INVALID) {
deba@416:       Edge edge = Parent::findEdge(u, v, prev);
deba@416:       while (edge != INVALID && !(*_edge_filter_map)[edge]) {
deba@416:         edge = Parent::findEdge(u, v, edge);
deba@416:       }
deba@416:       return edge;
deba@416:     }
deba@416: 
deba@416:     template <typename _Value>
deba@416:     class NodeMap : public SubMapExtender<Adaptor,
deba@416:       typename Parent::template NodeMap<_Value> > {
deba@416:     public:
deba@416:       typedef _Value Value;
deba@416:       typedef SubMapExtender<Adaptor, typename Parent::
deba@416:                              template NodeMap<Value> > MapParent;
deba@416: 
deba@416:       NodeMap(const Adaptor& adaptor)
deba@416:         : MapParent(adaptor) {}
deba@416:       NodeMap(const Adaptor& adaptor, const Value& value)
deba@416:         : MapParent(adaptor, value) {}
deba@416: 
deba@416:     private:
deba@416:       NodeMap& operator=(const NodeMap& cmap) {
deba@416:         return operator=<NodeMap>(cmap);
deba@416:       }
deba@416: 
deba@416:       template <typename CMap>
deba@416:       NodeMap& operator=(const CMap& cmap) {
deba@416:         MapParent::operator=(cmap);
deba@416:         return *this;
deba@416:       }
deba@416:     };
deba@416: 
deba@416:     template <typename _Value>
deba@416:     class ArcMap : public SubMapExtender<Adaptor,
deba@416:       typename Parent::template ArcMap<_Value> > {
deba@416:     public:
deba@416:       typedef _Value Value;
deba@416:       typedef SubMapExtender<Adaptor, typename Parent::
deba@416:                              template ArcMap<Value> > MapParent;
deba@416: 
deba@416:       ArcMap(const Adaptor& adaptor)
deba@416:         : MapParent(adaptor) {}
deba@416:       ArcMap(const Adaptor& adaptor, const Value& value)
deba@416:         : MapParent(adaptor, value) {}
deba@416: 
deba@416:     private:
deba@416:       ArcMap& operator=(const ArcMap& cmap) {
deba@416:         return operator=<ArcMap>(cmap);
deba@416:       }
deba@416: 
deba@416:       template <typename CMap>
deba@416:       ArcMap& operator=(const CMap& cmap) {
deba@416:         MapParent::operator=(cmap);
deba@416:         return *this;
deba@416:       }
deba@416:     };
deba@416: 
deba@416:     template <typename _Value>
deba@416:     class EdgeMap : public SubMapExtender<Adaptor,
deba@416:       typename Parent::template EdgeMap<_Value> > {
deba@416:     public:
deba@416:       typedef _Value Value;
deba@416:       typedef SubMapExtender<Adaptor, typename Parent::
deba@416:                              template EdgeMap<Value> > MapParent;
deba@416: 
deba@416:       EdgeMap(const Adaptor& adaptor)
deba@416:         : MapParent(adaptor) {}
deba@416: 
deba@416:       EdgeMap(const Adaptor& adaptor, const _Value& value)
deba@416:         : MapParent(adaptor, value) {}
deba@416: 
deba@416:     private:
deba@416:       EdgeMap& operator=(const EdgeMap& cmap) {
deba@416:         return operator=<EdgeMap>(cmap);
deba@416:       }
deba@416: 
deba@416:       template <typename CMap>
deba@416:       EdgeMap& operator=(const CMap& cmap) {
deba@416:         MapParent::operator=(cmap);
deba@416:         return *this;
deba@416:       }
deba@416:     };
deba@416: 
deba@416:   };
deba@416: 
deba@416:   /// \ingroup graph_adaptors
deba@414:   ///
deba@416:   /// \brief A graph adaptor for hiding nodes and edges in an
deba@416:   /// undirected graph.
deba@414:   ///
deba@416:   /// SubGraph hides nodes and edges in a graph. A bool node map and a
deba@416:   /// bool edge map must be specified, which define the filters for
deba@416:   /// nodes and edges. Just the nodes and edges with true value are
deba@416:   /// shown in the subgraph. The SubGraph is conform to the \ref
deba@416:   /// concepts::Graph "Graph concept". If the \c _checked parameter is
deba@416:   /// true, then the edges incident to filtered nodes are also
deba@416:   /// filtered out.
deba@416:   ///
deba@416:   /// \tparam _Graph It must be conform to the \ref
deba@416:   /// concepts::Graph "Graph concept". The type can be specified
deba@416:   /// to const.
deba@416:   /// \tparam _NodeFilterMap A bool valued node map of the the adapted graph.
deba@416:   /// \tparam _EdgeFilterMap A bool valued edge map of the the adapted graph.
deba@416:   /// \tparam _checked If the parameter is false then the edge filtering
deba@416:   /// is not checked with respect to node filter. Otherwise, each edge
deba@416:   /// is automatically filtered, which is incident to a filtered node.
deba@416:   ///
deba@416:   /// \see FilterNodes
deba@416:   /// \see FilterEdges
deba@416:   template<typename _Graph, typename NodeFilterMap,
deba@416:            typename EdgeFilterMap, bool _checked = true>
deba@416:   class SubGraph
deba@416:     : public GraphAdaptorExtender<
deba@416:       SubGraphBase<_Graph, NodeFilterMap, EdgeFilterMap, _checked> > {
deba@414:   public:
deba@416:     typedef _Graph Graph;
deba@416:     typedef GraphAdaptorExtender<
deba@416:       SubGraphBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent;
deba@414: 
deba@415:     typedef typename Parent::Node Node;
deba@416:     typedef typename Parent::Edge Edge;
deba@415: 
deba@414:   protected:
deba@416:     SubGraph() { }
deba@414:   public:
deba@414: 
deba@415:     /// \brief Constructor
deba@415:     ///
deba@416:     /// Creates a subgraph for the given graph with given node and
deba@416:     /// edge map filters.
deba@416:     SubGraph(Graph& _graph, NodeFilterMap& node_filter_map,
deba@416:              EdgeFilterMap& edge_filter_map) {
deba@416:       setGraph(_graph);
deba@416:       setNodeFilterMap(node_filter_map);
deba@416:       setEdgeFilterMap(edge_filter_map);
deba@414:     }
deba@414: 
deba@415:     /// \brief Hides the node of the graph
deba@415:     ///
deba@416:     /// This function hides \c n in the graph, i.e. the iteration
deba@416:     /// jumps over it. This is done by simply setting the value of \c n
deba@415:     /// to be false in the corresponding node-map.
deba@415:     void hide(const Node& n) const { Parent::hide(n); }
deba@415: 
deba@416:     /// \brief Hides the edge of the graph
deba@416:     ///
deba@416:     /// This function hides \c e in the graph, i.e. the iteration
deba@416:     /// jumps over it. This is done by simply setting the value of \c e
deba@416:     /// to be false in the corresponding edge-map.
deba@416:     void hide(const Edge& e) const { Parent::hide(e); }
deba@416: 
deba@415:     /// \brief Unhides the node of the graph
deba@415:     ///
deba@416:     /// The value of \c n is set to be true in the node-map which stores
deba@416:     /// hide information. If \c n was hidden previuosly, then it is shown
deba@415:     /// again
deba@415:     void unHide(const Node& n) const { Parent::unHide(n); }
deba@415: 
deba@416:     /// \brief Unhides the edge of the graph
deba@416:     ///
deba@416:     /// The value of \c e is set to be true in the edge-map which stores
deba@416:     /// hide information. If \c e was hidden previuosly, then it is shown
deba@416:     /// again
deba@416:     void unHide(const Edge& e) const { Parent::unHide(e); }
deba@416: 
deba@415:     /// \brief Returns true if \c n is hidden.
deba@415:     ///
deba@415:     /// Returns true if \c n is hidden.
deba@415:     ///
deba@415:     bool hidden(const Node& n) const { return Parent::hidden(n); }
deba@415: 
deba@416:     /// \brief Returns true if \c e is hidden.
deba@416:     ///
deba@416:     /// Returns true if \c e is hidden.
deba@416:     ///
deba@416:     bool hidden(const Edge& e) const { return Parent::hidden(e); }
deba@414:   };
deba@414: 
deba@416:   /// \brief Just gives back a subgraph
deba@414:   ///
deba@416:   /// Just gives back a subgraph
deba@416:   template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
deba@416:   SubGraph<const Graph, NodeFilterMap, ArcFilterMap>
deba@416:   subGraph(const Graph& graph, NodeFilterMap& nfm, ArcFilterMap& efm) {
deba@416:     return SubGraph<const Graph, NodeFilterMap, ArcFilterMap>(graph, nfm, efm);
deba@416:   }
deba@416: 
deba@416:   template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
deba@416:   SubGraph<const Graph, const NodeFilterMap, ArcFilterMap>
deba@416:   subGraph(const Graph& graph,
deba@416:            const NodeFilterMap& nfm, ArcFilterMap& efm) {
deba@416:     return SubGraph<const Graph, const NodeFilterMap, ArcFilterMap>
deba@416:       (graph, nfm, efm);
deba@416:   }
deba@416: 
deba@416:   template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
deba@416:   SubGraph<const Graph, NodeFilterMap, const ArcFilterMap>
deba@416:   subGraph(const Graph& graph,
deba@416:            NodeFilterMap& nfm, const ArcFilterMap& efm) {
deba@416:     return SubGraph<const Graph, NodeFilterMap, const ArcFilterMap>
deba@416:       (graph, nfm, efm);
deba@416:   }
deba@416: 
deba@416:   template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
deba@416:   SubGraph<const Graph, const NodeFilterMap, const ArcFilterMap>
deba@416:   subGraph(const Graph& graph,
deba@416:            const NodeFilterMap& nfm, const ArcFilterMap& efm) {
deba@416:     return SubGraph<const Graph, const NodeFilterMap, const ArcFilterMap>
deba@416:       (graph, nfm, efm);
deba@416:   }
deba@416: 
deba@416:   /// \ingroup graph_adaptors
deba@416:   ///
deba@416:   /// \brief An adaptor for hiding nodes from a digraph or a graph.
deba@416:   ///
deba@416:   /// FilterNodes adaptor hides nodes in a graph or a digraph. A bool
deba@416:   /// node map must be specified, which defines the filters for
deba@416:   /// nodes. Just the unfiltered nodes and the arcs or edges incident
deba@416:   /// to unfiltered nodes are shown in the subdigraph or subgraph. The
deba@416:   /// FilterNodes is conform to the \ref concepts::Digraph
deba@416:   /// "Digraph concept" or \ref concepts::Graph "Graph concept" depending
deba@416:   /// on the \c _Digraph template parameter. If the \c _checked
deba@416:   /// parameter is true, then the arc or edges incident to filtered nodes
deba@416:   /// are also filtered out.
deba@416:   ///
deba@416:   /// \tparam _Digraph It must be conform to the \ref
deba@416:   /// concepts::Digraph "Digraph concept" or \ref concepts::Graph
deba@416:   /// "Graph concept". The type can be specified to be const.
deba@416:   /// \tparam _NodeFilterMap A bool valued node map of the the adapted graph.
deba@416:   /// \tparam _checked If the parameter is false then the arc or edge
deba@416:   /// filtering is not checked with respect to node filter. In this
deba@416:   /// case just isolated nodes can be filtered out from the
deba@416:   /// graph.
deba@416: #ifdef DOXYGEN
deba@416:   template<typename _Digraph,
deba@416:            typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
deba@416:            bool _checked = true>
deba@416: #else
deba@416:   template<typename _Digraph,
deba@416:            typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
deba@416:            bool _checked = true,
deba@416:            typename Enable = void>
deba@416: #endif
deba@416:   class FilterNodes
deba@416:     : public SubDigraph<_Digraph, _NodeFilterMap,
deba@416:                         ConstMap<typename _Digraph::Arc, bool>, _checked> {
deba@416:   public:
deba@416: 
deba@416:     typedef _Digraph Digraph;
deba@416:     typedef _NodeFilterMap NodeFilterMap;
deba@416: 
deba@416:     typedef SubDigraph<Digraph, NodeFilterMap,
deba@416:                        ConstMap<typename Digraph::Arc, bool>, _checked>
deba@416:     Parent;
deba@416: 
deba@416:     typedef typename Parent::Node Node;
deba@416: 
deba@416:   protected:
deba@416:     ConstMap<typename Digraph::Arc, bool> const_true_map;
deba@416: 
deba@416:     FilterNodes() : const_true_map(true) {
deba@416:       Parent::setArcFilterMap(const_true_map);
deba@416:     }
deba@416: 
deba@416:   public:
deba@416: 
deba@416:     /// \brief Constructor
deba@416:     ///
deba@416:     /// Creates an adaptor for the given digraph or graph with
deba@416:     /// given node filter map.
deba@416:     FilterNodes(Digraph& _digraph, NodeFilterMap& node_filter) :
deba@416:       Parent(), const_true_map(true) {
deba@416:       Parent::setDigraph(_digraph);
deba@416:       Parent::setNodeFilterMap(node_filter);
deba@416:       Parent::setArcFilterMap(const_true_map);
deba@416:     }
deba@416: 
deba@416:     /// \brief Hides the node of the graph
deba@416:     ///
deba@416:     /// This function hides \c n in the digraph or graph, i.e. the iteration
deba@416:     /// jumps over it. This is done by simply setting the value of \c n
deba@416:     /// to be false in the corresponding node map.
deba@416:     void hide(const Node& n) const { Parent::hide(n); }
deba@416: 
deba@416:     /// \brief Unhides the node of the graph
deba@416:     ///
deba@416:     /// The value of \c n is set to be true in the node-map which stores
deba@416:     /// hide information. If \c n was hidden previuosly, then it is shown
deba@416:     /// again
deba@416:     void unHide(const Node& n) const { Parent::unHide(n); }
deba@416: 
deba@416:     /// \brief Returns true if \c n is hidden.
deba@416:     ///
deba@416:     /// Returns true if \c n is hidden.
deba@416:     ///
deba@416:     bool hidden(const Node& n) const { return Parent::hidden(n); }
deba@416: 
deba@416:   };
deba@416: 
deba@416:   template<typename _Graph, typename _NodeFilterMap, bool _checked>
deba@416:   class FilterNodes<_Graph, _NodeFilterMap, _checked,
deba@416:                     typename enable_if<UndirectedTagIndicator<_Graph> >::type>
deba@416:     : public SubGraph<_Graph, _NodeFilterMap,
deba@416:                       ConstMap<typename _Graph::Edge, bool>, _checked> {
deba@416:   public:
deba@416:     typedef _Graph Graph;
deba@416:     typedef _NodeFilterMap NodeFilterMap;
deba@416:     typedef SubGraph<Graph, NodeFilterMap,
deba@416:                      ConstMap<typename Graph::Edge, bool> > Parent;
deba@416: 
deba@416:     typedef typename Parent::Node Node;
deba@416:   protected:
deba@416:     ConstMap<typename Graph::Edge, bool> const_true_map;
deba@416: 
deba@416:     FilterNodes() : const_true_map(true) {
deba@416:       Parent::setEdgeFilterMap(const_true_map);
deba@416:     }
deba@416: 
deba@416:   public:
deba@416: 
deba@416:     FilterNodes(Graph& _graph, NodeFilterMap& node_filter_map) :
deba@416:       Parent(), const_true_map(true) {
deba@416:       Parent::setGraph(_graph);
deba@416:       Parent::setNodeFilterMap(node_filter_map);
deba@416:       Parent::setEdgeFilterMap(const_true_map);
deba@416:     }
deba@416: 
deba@416:     void hide(const Node& n) const { Parent::hide(n); }
deba@416:     void unHide(const Node& n) const { Parent::unHide(n); }
deba@416:     bool hidden(const Node& n) const { return Parent::hidden(n); }
deba@416: 
deba@416:   };
deba@416: 
deba@416: 
deba@416:   /// \brief Just gives back a FilterNodes adaptor
deba@416:   ///
deba@416:   /// Just gives back a FilterNodes adaptor
deba@414:   template<typename Digraph, typename NodeFilterMap>
deba@416:   FilterNodes<const Digraph, NodeFilterMap>
deba@416:   filterNodes(const Digraph& digraph, NodeFilterMap& nfm) {
deba@416:     return FilterNodes<const Digraph, NodeFilterMap>(digraph, nfm);
deba@414:   }
deba@414: 
deba@414:   template<typename Digraph, typename NodeFilterMap>
deba@416:   FilterNodes<const Digraph, const NodeFilterMap>
deba@416:   filterNodes(const Digraph& digraph, const NodeFilterMap& nfm) {
deba@416:     return FilterNodes<const Digraph, const NodeFilterMap>(digraph, nfm);
deba@414:   }
deba@414: 
deba@416:   /// \ingroup graph_adaptors
deba@414:   ///
deba@416:   /// \brief An adaptor for hiding arcs from a digraph.
deba@414:   ///
deba@416:   /// FilterArcs adaptor hides arcs in a digraph. A bool arc map must
deba@416:   /// be specified, which defines the filters for arcs. Just the
deba@416:   /// unfiltered arcs are shown in the subdigraph. The FilterArcs is
deba@416:   /// conform to the \ref concepts::Digraph "Digraph concept".
deba@414:   ///
deba@416:   /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
deba@416:   /// "Digraph concept". The type can be specified to be const.
deba@416:   /// \tparam _ArcFilterMap A bool valued arc map of the the adapted
deba@416:   /// graph.
deba@414:   template<typename _Digraph, typename _ArcFilterMap>
deba@416:   class FilterArcs :
deba@416:     public SubDigraph<_Digraph, ConstMap<typename _Digraph::Node, bool>,
deba@416:                       _ArcFilterMap, false> {
deba@414:   public:
deba@414:     typedef _Digraph Digraph;
deba@414:     typedef _ArcFilterMap ArcFilterMap;
deba@414: 
deba@416:     typedef SubDigraph<Digraph, ConstMap<typename Digraph::Node, bool>,
deba@416:                        ArcFilterMap, false> Parent;
deba@415: 
deba@415:     typedef typename Parent::Arc Arc;
deba@415: 
deba@414:   protected:
deba@414:     ConstMap<typename Digraph::Node, bool> const_true_map;
deba@414: 
deba@416:     FilterArcs() : const_true_map(true) {
deba@414:       Parent::setNodeFilterMap(const_true_map);
deba@414:     }
deba@414: 
deba@414:   public:
deba@414: 
deba@415:     /// \brief Constructor
deba@415:     ///
deba@416:     /// Creates a FilterArcs adaptor for the given graph with
deba@415:     /// given arc map filter.
deba@416:     FilterArcs(Digraph& digraph, ArcFilterMap& arc_filter)
deba@416:       : Parent(), const_true_map(true) {
deba@414:       Parent::setDigraph(digraph);
deba@414:       Parent::setNodeFilterMap(const_true_map);
deba@414:       Parent::setArcFilterMap(arc_filter);
deba@414:     }
deba@414: 
deba@415:     /// \brief Hides the arc of the graph
deba@415:     ///
deba@416:     /// This function hides \c a in the graph, i.e. the iteration
deba@415:     /// jumps over it. This is done by simply setting the value of \c a
deba@416:     /// to be false in the corresponding arc map.
deba@415:     void hide(const Arc& a) const { Parent::hide(a); }
deba@415: 
deba@415:     /// \brief Unhides the arc of the graph
deba@415:     ///
deba@416:     /// The value of \c a is set to be true in the arc-map which stores
deba@416:     /// hide information. If \c a was hidden previuosly, then it is shown
deba@415:     /// again
deba@415:     void unHide(const Arc& a) const { Parent::unHide(a); }
deba@415: 
deba@415:     /// \brief Returns true if \c a is hidden.
deba@415:     ///
deba@415:     /// Returns true if \c a is hidden.
deba@415:     ///
deba@415:     bool hidden(const Arc& a) const { return Parent::hidden(a); }
deba@415: 
deba@414:   };
deba@414: 
deba@416:   /// \brief Just gives back an FilterArcs adaptor
deba@414:   ///
deba@416:   /// Just gives back an FilterArcs adaptor
deba@414:   template<typename Digraph, typename ArcFilterMap>
deba@416:   FilterArcs<const Digraph, ArcFilterMap>
deba@416:   filterArcs(const Digraph& digraph, ArcFilterMap& afm) {
deba@416:     return FilterArcs<const Digraph, ArcFilterMap>(digraph, afm);
deba@414:   }
deba@414: 
deba@414:   template<typename Digraph, typename ArcFilterMap>
deba@416:   FilterArcs<const Digraph, const ArcFilterMap>
deba@416:   filterArcs(const Digraph& digraph, const ArcFilterMap& afm) {
deba@416:     return FilterArcs<const Digraph, const ArcFilterMap>(digraph, afm);
deba@414:   }
deba@414: 
deba@416:   /// \ingroup graph_adaptors
deba@416:   ///
deba@416:   /// \brief An adaptor for hiding edges from a graph.
deba@416:   ///
deba@416:   /// FilterEdges adaptor hides edges in a digraph. A bool edge map must
deba@416:   /// be specified, which defines the filters for edges. Just the
deba@416:   /// unfiltered edges are shown in the subdigraph. The FilterEdges is
deba@416:   /// conform to the \ref concepts::Graph "Graph concept".
deba@416:   ///
deba@416:   /// \tparam _Graph It must be conform to the \ref concepts::Graph
deba@416:   /// "Graph concept". The type can be specified to be const.
deba@416:   /// \tparam _EdgeFilterMap A bool valued edge map of the the adapted
deba@416:   /// graph.
deba@416:   template<typename _Graph, typename _EdgeFilterMap>
deba@416:   class FilterEdges :
deba@416:     public SubGraph<_Graph, ConstMap<typename _Graph::Node,bool>,
deba@416:                     _EdgeFilterMap, false> {
deba@416:   public:
deba@416:     typedef _Graph Graph;
deba@416:     typedef _EdgeFilterMap EdgeFilterMap;
deba@416:     typedef SubGraph<Graph, ConstMap<typename Graph::Node,bool>,
deba@416:                      EdgeFilterMap, false> Parent;
deba@416:     typedef typename Parent::Edge Edge;
deba@416:   protected:
deba@416:     ConstMap<typename Graph::Node, bool> const_true_map;
deba@416: 
deba@416:     FilterEdges() : const_true_map(true) {
deba@416:       Parent::setNodeFilterMap(const_true_map);
deba@416:     }
deba@416: 
deba@416:   public:
deba@416: 
deba@416:     /// \brief Constructor
deba@416:     ///
deba@416:     /// Creates a FilterEdges adaptor for the given graph with
deba@416:     /// given edge map filters.
deba@416:     FilterEdges(Graph& _graph, EdgeFilterMap& edge_filter_map) :
deba@416:       Parent(), const_true_map(true) {
deba@416:       Parent::setGraph(_graph);
deba@416:       Parent::setNodeFilterMap(const_true_map);
deba@416:       Parent::setEdgeFilterMap(edge_filter_map);
deba@416:     }
deba@416: 
deba@416:     /// \brief Hides the edge of the graph
deba@416:     ///
deba@416:     /// This function hides \c e in the graph, i.e. the iteration
deba@416:     /// jumps over it. This is done by simply setting the value of \c e
deba@416:     /// to be false in the corresponding edge-map.
deba@416:     void hide(const Edge& e) const { Parent::hide(e); }
deba@416: 
deba@416:     /// \brief Unhides the edge of the graph
deba@416:     ///
deba@416:     /// The value of \c e is set to be true in the edge-map which stores
deba@416:     /// hide information. If \c e was hidden previuosly, then it is shown
deba@416:     /// again
deba@416:     void unHide(const Edge& e) const { Parent::unHide(e); }
deba@416: 
deba@416:     /// \brief Returns true if \c e is hidden.
deba@416:     ///
deba@416:     /// Returns true if \c e is hidden.
deba@416:     ///
deba@416:     bool hidden(const Edge& e) const { return Parent::hidden(e); }
deba@416: 
deba@416:   };
deba@416: 
deba@416:   /// \brief Just gives back a FilterEdges adaptor
deba@416:   ///
deba@416:   /// Just gives back a FilterEdges adaptor
deba@416:   template<typename Graph, typename EdgeFilterMap>
deba@416:   FilterEdges<const Graph, EdgeFilterMap>
deba@416:   filterEdges(const Graph& graph, EdgeFilterMap& efm) {
deba@416:     return FilterEdges<const Graph, EdgeFilterMap>(graph, efm);
deba@416:   }
deba@416: 
deba@416:   template<typename Graph, typename EdgeFilterMap>
deba@416:   FilterEdges<const Graph, const EdgeFilterMap>
deba@416:   filterEdges(const Graph& graph, const EdgeFilterMap& efm) {
deba@416:     return FilterEdges<const Graph, const EdgeFilterMap>(graph, efm);
deba@416:   }
deba@416: 
deba@414:   template <typename _Digraph>
deba@416:   class UndirectorBase {
deba@414:   public:
deba@414:     typedef _Digraph Digraph;
deba@416:     typedef UndirectorBase Adaptor;
deba@414: 
deba@414:     typedef True UndirectedTag;
deba@414: 
deba@414:     typedef typename Digraph::Arc Edge;
deba@414:     typedef typename Digraph::Node Node;
deba@414: 
deba@414:     class Arc : public Edge {
deba@416:       friend class UndirectorBase;
deba@414:     protected:
deba@414:       bool _forward;
deba@414: 
deba@414:       Arc(const Edge& edge, bool forward) :
deba@414:         Edge(edge), _forward(forward) {}
deba@414: 
deba@414:     public:
deba@414:       Arc() {}
deba@414: 
deba@414:       Arc(Invalid) : Edge(INVALID), _forward(true) {}
deba@414: 
deba@414:       bool operator==(const Arc &other) const {
deba@416:         return _forward == other._forward &&
deba@416:           static_cast<const Edge&>(*this) == static_cast<const Edge&>(other);
deba@414:       }
deba@414:       bool operator!=(const Arc &other) const {
deba@416:         return _forward != other._forward ||
deba@416:           static_cast<const Edge&>(*this) != static_cast<const Edge&>(other);
deba@414:       }
deba@414:       bool operator<(const Arc &other) const {
deba@416:         return _forward < other._forward ||
deba@416:           (_forward == other._forward &&
deba@416:            static_cast<const Edge&>(*this) < static_cast<const Edge&>(other));
deba@414:       }
deba@414:     };
deba@414: 
deba@414: 
deba@414: 
deba@414:     void first(Node& n) const {
deba@414:       _digraph->first(n);
deba@414:     }
deba@414: 
deba@414:     void next(Node& n) const {
deba@414:       _digraph->next(n);
deba@414:     }
deba@414: 
deba@414:     void first(Arc& a) const {
deba@414:       _digraph->first(a);
deba@414:       a._forward = true;
deba@414:     }
deba@414: 
deba@414:     void next(Arc& a) const {
deba@414:       if (a._forward) {
deba@416:         a._forward = false;
deba@414:       } else {
deba@416:         _digraph->next(a);
deba@416:         a._forward = true;
deba@414:       }
deba@414:     }
deba@414: 
deba@414:     void first(Edge& e) const {
deba@414:       _digraph->first(e);
deba@414:     }
deba@414: 
deba@414:     void next(Edge& e) const {
deba@414:       _digraph->next(e);
deba@414:     }
deba@414: 
deba@414:     void firstOut(Arc& a, const Node& n) const {
deba@414:       _digraph->firstIn(a, n);
deba@414:       if( static_cast<const Edge&>(a) != INVALID ) {
deba@416:         a._forward = false;
deba@414:       } else {
deba@416:         _digraph->firstOut(a, n);
deba@416:         a._forward = true;
deba@414:       }
deba@414:     }
deba@414:     void nextOut(Arc &a) const {
deba@414:       if (!a._forward) {
deba@416:         Node n = _digraph->target(a);
deba@416:         _digraph->nextIn(a);
deba@416:         if (static_cast<const Edge&>(a) == INVALID ) {
deba@416:           _digraph->firstOut(a, n);
deba@416:           a._forward = true;
deba@416:         }
deba@414:       }
deba@414:       else {
deba@416:         _digraph->nextOut(a);
deba@414:       }
deba@414:     }
deba@414: 
deba@414:     void firstIn(Arc &a, const Node &n) const {
deba@414:       _digraph->firstOut(a, n);
deba@414:       if (static_cast<const Edge&>(a) != INVALID ) {
deba@416:         a._forward = false;
deba@414:       } else {
deba@416:         _digraph->firstIn(a, n);
deba@416:         a._forward = true;
deba@414:       }
deba@414:     }
deba@414:     void nextIn(Arc &a) const {
deba@414:       if (!a._forward) {
deba@416:         Node n = _digraph->source(a);
deba@416:         _digraph->nextOut(a);
deba@416:         if( static_cast<const Edge&>(a) == INVALID ) {
deba@416:           _digraph->firstIn(a, n);
deba@416:           a._forward = true;
deba@416:         }
deba@414:       }
deba@414:       else {
deba@416:         _digraph->nextIn(a);
deba@414:       }
deba@414:     }
deba@414: 
deba@414:     void firstInc(Edge &e, bool &d, const Node &n) const {
deba@414:       d = true;
deba@414:       _digraph->firstOut(e, n);
deba@414:       if (e != INVALID) return;
deba@414:       d = false;
deba@414:       _digraph->firstIn(e, n);
deba@414:     }
deba@414: 
deba@414:     void nextInc(Edge &e, bool &d) const {
deba@414:       if (d) {
deba@416:         Node s = _digraph->source(e);
deba@416:         _digraph->nextOut(e);
deba@416:         if (e != INVALID) return;
deba@416:         d = false;
deba@416:         _digraph->firstIn(e, s);
deba@414:       } else {
deba@416:         _digraph->nextIn(e);
deba@414:       }
deba@414:     }
deba@414: 
deba@414:     Node u(const Edge& e) const {
deba@414:       return _digraph->source(e);
deba@414:     }
deba@414: 
deba@414:     Node v(const Edge& e) const {
deba@414:       return _digraph->target(e);
deba@414:     }
deba@414: 
deba@414:     Node source(const Arc &a) const {
deba@414:       return a._forward ? _digraph->source(a) : _digraph->target(a);
deba@414:     }
deba@414: 
deba@414:     Node target(const Arc &a) const {
deba@414:       return a._forward ? _digraph->target(a) : _digraph->source(a);
deba@414:     }
deba@414: 
deba@414:     static Arc direct(const Edge &e, bool d) {
deba@414:       return Arc(e, d);
deba@414:     }
deba@414:     Arc direct(const Edge &e, const Node& n) const {
deba@414:       return Arc(e, _digraph->source(e) == n);
deba@414:     }
deba@414: 
deba@414:     static bool direction(const Arc &a) { return a._forward; }
deba@414: 
deba@414:     Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
deba@414:     Arc arcFromId(int ix) const {
deba@414:       return direct(_digraph->arcFromId(ix >> 1), bool(ix & 1));
deba@414:     }
deba@414:     Edge edgeFromId(int ix) const { return _digraph->arcFromId(ix); }
deba@414: 
deba@414:     int id(const Node &n) const { return _digraph->id(n); }
deba@414:     int id(const Arc &a) const {
deba@414:       return  (_digraph->id(a) << 1) | (a._forward ? 1 : 0);
deba@414:     }
deba@414:     int id(const Edge &e) const { return _digraph->id(e); }
deba@414: 
deba@414:     int maxNodeId() const { return _digraph->maxNodeId(); }
deba@414:     int maxArcId() const { return (_digraph->maxArcId() << 1) | 1; }
deba@414:     int maxEdgeId() const { return _digraph->maxArcId(); }
deba@414: 
deba@414:     Node addNode() { return _digraph->addNode(); }
deba@416:     Edge addEdge(const Node& u, const Node& v) {
deba@416:       return _digraph->addArc(u, v);
deba@414:     }
deba@414: 
deba@414:     void erase(const Node& i) { _digraph->erase(i); }
deba@414:     void erase(const Edge& i) { _digraph->erase(i); }
deba@416: 
deba@414:     void clear() { _digraph->clear(); }
deba@414: 
deba@414:     typedef NodeNumTagIndicator<Digraph> NodeNumTag;
deba@414:     int nodeNum() const { return 2 * _digraph->arcNum(); }
deba@414:     typedef EdgeNumTagIndicator<Digraph> EdgeNumTag;
deba@414:     int arcNum() const { return 2 * _digraph->arcNum(); }
deba@414:     int edgeNum() const { return _digraph->arcNum(); }
deba@414: 
deba@414:     typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
deba@414:     Arc findArc(Node s, Node t, Arc p = INVALID) const {
deba@414:       if (p == INVALID) {
deba@416:         Edge arc = _digraph->findArc(s, t);
deba@416:         if (arc != INVALID) return direct(arc, true);
deba@416:         arc = _digraph->findArc(t, s);
deba@416:         if (arc != INVALID) return direct(arc, false);
deba@414:       } else if (direction(p)) {
deba@416:         Edge arc = _digraph->findArc(s, t, p);
deba@416:         if (arc != INVALID) return direct(arc, true);
deba@416:         arc = _digraph->findArc(t, s);
deba@416:         if (arc != INVALID) return direct(arc, false);
deba@414:       } else {
deba@416:         Edge arc = _digraph->findArc(t, s, p);
deba@416:         if (arc != INVALID) return direct(arc, false);
deba@414:       }
deba@414:       return INVALID;
deba@414:     }
deba@414: 
deba@414:     Edge findEdge(Node s, Node t, Edge p = INVALID) const {
deba@414:       if (s != t) {
deba@414:         if (p == INVALID) {
deba@414:           Edge arc = _digraph->findArc(s, t);
deba@414:           if (arc != INVALID) return arc;
deba@414:           arc = _digraph->findArc(t, s);
deba@414:           if (arc != INVALID) return arc;
deba@414:         } else if (_digraph->s(p) == s) {
deba@414:           Edge arc = _digraph->findArc(s, t, p);
deba@414:           if (arc != INVALID) return arc;
deba@414:           arc = _digraph->findArc(t, s);
deba@416:           if (arc != INVALID) return arc;
deba@414:         } else {
deba@414:           Edge arc = _digraph->findArc(t, s, p);
deba@416:           if (arc != INVALID) return arc;
deba@414:         }
deba@414:       } else {
deba@414:         return _digraph->findArc(s, t, p);
deba@414:       }
deba@414:       return INVALID;
deba@414:     }
deba@414: 
deba@414:   private:
deba@416: 
deba@414:     template <typename _Value>
deba@414:     class ArcMapBase {
deba@414:     private:
deba@416: 
deba@414:       typedef typename Digraph::template ArcMap<_Value> MapImpl;
deba@416: 
deba@414:     public:
deba@414: 
deba@414:       typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
deba@414: 
deba@414:       typedef _Value Value;
deba@414:       typedef Arc Key;
deba@416: 
deba@414:       ArcMapBase(const Adaptor& adaptor) :
deba@416:         _forward(*adaptor._digraph), _backward(*adaptor._digraph) {}
deba@416: 
deba@416:       ArcMapBase(const Adaptor& adaptor, const Value& v)
deba@414:         : _forward(*adaptor._digraph, v), _backward(*adaptor._digraph, v) {}
deba@416: 
deba@416:       void set(const Arc& a, const Value& v) {
deba@416:         if (direction(a)) {
deba@416:           _forward.set(a, v);
deba@416:         } else {
deba@416:           _backward.set(a, v);
deba@414:         }
deba@414:       }
deba@414: 
deba@416:       typename MapTraits<MapImpl>::ConstReturnValue
deba@416:       operator[](const Arc& a) const {
deba@416:         if (direction(a)) {
deba@416:           return _forward[a];
deba@416:         } else {
deba@416:           return _backward[a];
deba@414:         }
deba@414:       }
deba@414: 
deba@416:       typename MapTraits<MapImpl>::ReturnValue
deba@416:       operator[](const Arc& a) {
deba@416:         if (direction(a)) {
deba@416:           return _forward[a];
deba@416:         } else {
deba@416:           return _backward[a];
deba@416:         }
deba@416:       }
deba@416: 
deba@414:     protected:
deba@414: 
deba@416:       MapImpl _forward, _backward;
deba@414: 
deba@414:     };
deba@414: 
deba@414:   public:
deba@414: 
deba@414:     template <typename _Value>
deba@414:     class NodeMap : public Digraph::template NodeMap<_Value> {
deba@414:     public:
deba@414: 
deba@414:       typedef _Value Value;
deba@414:       typedef typename Digraph::template NodeMap<Value> Parent;
deba@414: 
deba@416:       explicit NodeMap(const Adaptor& adaptor)
deba@416:         : Parent(*adaptor._digraph) {}
deba@414: 
deba@414:       NodeMap(const Adaptor& adaptor, const _Value& value)
deba@416:         : Parent(*adaptor._digraph, value) { }
deba@414: 
deba@414:     private:
deba@414:       NodeMap& operator=(const NodeMap& cmap) {
deba@414:         return operator=<NodeMap>(cmap);
deba@414:       }
deba@414: 
deba@414:       template <typename CMap>
deba@414:       NodeMap& operator=(const CMap& cmap) {
deba@414:         Parent::operator=(cmap);
deba@414:         return *this;
deba@414:       }
deba@416: 
deba@414:     };
deba@414: 
deba@414:     template <typename _Value>
deba@416:     class ArcMap
deba@416:       : public SubMapExtender<Adaptor, ArcMapBase<_Value> >
deba@414:     {
deba@414:     public:
deba@414:       typedef _Value Value;
deba@414:       typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
deba@416: 
deba@416:       ArcMap(const Adaptor& adaptor)
deba@416:         : Parent(adaptor) {}
deba@416: 
deba@416:       ArcMap(const Adaptor& adaptor, const Value& value)
deba@416:         : Parent(adaptor, value) {}
deba@416: 
deba@414:     private:
deba@414:       ArcMap& operator=(const ArcMap& cmap) {
deba@416:         return operator=<ArcMap>(cmap);
deba@414:       }
deba@416: 
deba@414:       template <typename CMap>
deba@414:       ArcMap& operator=(const CMap& cmap) {
deba@414:         Parent::operator=(cmap);
deba@416:         return *this;
deba@414:       }
deba@414:     };
deba@416: 
deba@414:     template <typename _Value>
deba@414:     class EdgeMap : public Digraph::template ArcMap<_Value> {
deba@414:     public:
deba@416: 
deba@414:       typedef _Value Value;
deba@414:       typedef typename Digraph::template ArcMap<Value> Parent;
deba@416: 
deba@416:       explicit EdgeMap(const Adaptor& adaptor)
deba@416:         : Parent(*adaptor._digraph) {}
deba@414: 
deba@414:       EdgeMap(const Adaptor& adaptor, const Value& value)
deba@416:         : Parent(*adaptor._digraph, value) {}
deba@414: 
deba@414:     private:
deba@414:       EdgeMap& operator=(const EdgeMap& cmap) {
deba@414:         return operator=<EdgeMap>(cmap);
deba@414:       }
deba@414: 
deba@414:       template <typename CMap>
deba@414:       EdgeMap& operator=(const CMap& cmap) {
deba@414:         Parent::operator=(cmap);
deba@414:         return *this;
deba@414:       }
deba@414: 
deba@414:     };
deba@414: 
deba@414:     typedef typename ItemSetTraits<Digraph, Node>::ItemNotifier NodeNotifier;
deba@416:     NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
deba@414: 
deba@414:   protected:
deba@414: 
deba@416:     UndirectorBase() : _digraph(0) {}
deba@414: 
deba@414:     Digraph* _digraph;
deba@414: 
deba@414:     void setDigraph(Digraph& digraph) {
deba@414:       _digraph = &digraph;
deba@414:     }
deba@416: 
deba@414:   };
deba@414: 
deba@416:   /// \ingroup graph_adaptors
deba@414:   ///
deba@416:   /// \brief Undirect the graph
deba@414:   ///
deba@414:   /// This adaptor makes an undirected graph from a directed
deba@416:   /// graph. All arcs of the underlying digraph will be showed in the
deba@416:   /// adaptor as an edge. The Orienter adaptor is conform to the \ref
deba@416:   /// concepts::Graph "Graph concept".
deba@414:   ///
deba@416:   /// \tparam _Digraph It must be conform to the \ref
deba@416:   /// concepts::Digraph "Digraph concept". The type can be specified
deba@416:   /// to const.
deba@414:   template<typename _Digraph>
deba@416:   class Undirector
deba@416:     : public GraphAdaptorExtender<UndirectorBase<_Digraph> > {
deba@414:   public:
deba@414:     typedef _Digraph Digraph;
deba@416:     typedef GraphAdaptorExtender<UndirectorBase<Digraph> > Parent;
deba@414:   protected:
deba@416:     Undirector() { }
deba@414:   public:
deba@414: 
deba@414:     /// \brief Constructor
deba@414:     ///
deba@416:     /// Creates a undirected graph from the given digraph
deba@416:     Undirector(_Digraph& digraph) {
deba@416:       setDigraph(digraph);
deba@414:     }
deba@414: 
deba@414:     /// \brief ArcMap combined from two original ArcMap
deba@414:     ///
deba@414:     /// This class adapts two original digraph ArcMap to
deba@416:     /// get an arc map on the undirected graph.
deba@414:     template <typename _ForwardMap, typename _BackwardMap>
deba@414:     class CombinedArcMap {
deba@414:     public:
deba@416: 
deba@414:       typedef _ForwardMap ForwardMap;
deba@414:       typedef _BackwardMap BackwardMap;
deba@414: 
deba@414:       typedef typename MapTraits<ForwardMap>::ReferenceMapTag ReferenceMapTag;
deba@414: 
deba@414:       typedef typename ForwardMap::Value Value;
deba@414:       typedef typename Parent::Arc Key;
deba@414: 
deba@416:       /// \brief Constructor
deba@414:       ///
deba@416:       /// Constructor
deba@416:       CombinedArcMap(ForwardMap& forward, BackwardMap& backward)
deba@414:         : _forward(&forward), _backward(&backward) {}
deba@416: 
deba@414: 
deba@414:       /// \brief Sets the value associated with a key.
deba@414:       ///
deba@414:       /// Sets the value associated with a key.
deba@416:       void set(const Key& e, const Value& a) {
deba@416:         if (Parent::direction(e)) {
deba@416:           _forward->set(e, a);
deba@416:         } else {
deba@416:           _backward->set(e, a);
deba@416:         }
deba@414:       }
deba@414: 
deba@414:       /// \brief Returns the value associated with a key.
deba@414:       ///
deba@414:       /// Returns the value associated with a key.
deba@416:       typename MapTraits<ForwardMap>::ConstReturnValue
deba@416:       operator[](const Key& e) const {
deba@416:         if (Parent::direction(e)) {
deba@416:           return (*_forward)[e];
deba@416:         } else {
deba@416:           return (*_backward)[e];
deba@414:         }
deba@414:       }
deba@414: 
deba@414:       /// \brief Returns the value associated with a key.
deba@414:       ///
deba@414:       /// Returns the value associated with a key.
deba@416:       typename MapTraits<ForwardMap>::ReturnValue
deba@416:       operator[](const Key& e) {
deba@416:         if (Parent::direction(e)) {
deba@416:           return (*_forward)[e];
deba@416:         } else {
deba@416:           return (*_backward)[e];
deba@414:         }
deba@414:       }
deba@414: 
deba@416:     protected:
deba@416: 
deba@416:       ForwardMap* _forward;
deba@416:       BackwardMap* _backward;
deba@416: 
deba@416:     };
deba@416: 
deba@416:     /// \brief Just gives back a combined arc map
deba@416:     ///
deba@416:     /// Just gives back a combined arc map
deba@416:     template <typename ForwardMap, typename BackwardMap>
deba@416:     static CombinedArcMap<ForwardMap, BackwardMap>
deba@416:     combinedArcMap(ForwardMap& forward, BackwardMap& backward) {
deba@416:       return CombinedArcMap<ForwardMap, BackwardMap>(forward, backward);
deba@416:     }
deba@416: 
deba@416:     template <typename ForwardMap, typename BackwardMap>
deba@416:     static CombinedArcMap<const ForwardMap, BackwardMap>
deba@416:     combinedArcMap(const ForwardMap& forward, BackwardMap& backward) {
deba@416:       return CombinedArcMap<const ForwardMap,
deba@416:         BackwardMap>(forward, backward);
deba@416:     }
deba@416: 
deba@416:     template <typename ForwardMap, typename BackwardMap>
deba@416:     static CombinedArcMap<ForwardMap, const BackwardMap>
deba@416:     combinedArcMap(ForwardMap& forward, const BackwardMap& backward) {
deba@416:       return CombinedArcMap<ForwardMap,
deba@416:         const BackwardMap>(forward, backward);
deba@416:     }
deba@416: 
deba@416:     template <typename ForwardMap, typename BackwardMap>
deba@416:     static CombinedArcMap<const ForwardMap, const BackwardMap>
deba@416:     combinedArcMap(const ForwardMap& forward, const BackwardMap& backward) {
deba@416:       return CombinedArcMap<const ForwardMap,
deba@416:         const BackwardMap>(forward, backward);
deba@416:     }
deba@416: 
deba@416:   };
deba@416: 
deba@416:   /// \brief Just gives back an undirected view of the given digraph
deba@416:   ///
deba@416:   /// Just gives back an undirected view of the given digraph
deba@416:   template<typename Digraph>
deba@416:   Undirector<const Digraph>
deba@416:   undirector(const Digraph& digraph) {
deba@416:     return Undirector<const Digraph>(digraph);
deba@416:   }
deba@416: 
deba@416:   template <typename _Graph, typename _DirectionMap>
deba@416:   class OrienterBase {
deba@416:   public:
deba@416: 
deba@416:     typedef _Graph Graph;
deba@416:     typedef _DirectionMap DirectionMap;
deba@416: 
deba@416:     typedef typename Graph::Node Node;
deba@416:     typedef typename Graph::Edge Arc;
deba@416: 
deba@416:     void reverseArc(const Arc& arc) {
deba@416:       _direction->set(arc, !(*_direction)[arc]);
deba@416:     }
deba@416: 
deba@416:     void first(Node& i) const { _graph->first(i); }
deba@416:     void first(Arc& i) const { _graph->first(i); }
deba@416:     void firstIn(Arc& i, const Node& n) const {
deba@416:       bool d;
deba@416:       _graph->firstInc(i, d, n);
deba@416:       while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
deba@416:     }
deba@416:     void firstOut(Arc& i, const Node& n ) const {
deba@416:       bool d;
deba@416:       _graph->firstInc(i, d, n);
deba@416:       while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
deba@416:     }
deba@416: 
deba@416:     void next(Node& i) const { _graph->next(i); }
deba@416:     void next(Arc& i) const { _graph->next(i); }
deba@416:     void nextIn(Arc& i) const {
deba@416:       bool d = !(*_direction)[i];
deba@416:       _graph->nextInc(i, d);
deba@416:       while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
deba@416:     }
deba@416:     void nextOut(Arc& i) const {
deba@416:       bool d = (*_direction)[i];
deba@416:       _graph->nextInc(i, d);
deba@416:       while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
deba@416:     }
deba@416: 
deba@416:     Node source(const Arc& e) const {
deba@416:       return (*_direction)[e] ? _graph->u(e) : _graph->v(e);
deba@416:     }
deba@416:     Node target(const Arc& e) const {
deba@416:       return (*_direction)[e] ? _graph->v(e) : _graph->u(e);
deba@416:     }
deba@416: 
deba@416:     typedef NodeNumTagIndicator<Graph> NodeNumTag;
deba@416:     int nodeNum() const { return _graph->nodeNum(); }
deba@416: 
deba@416:     typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
deba@416:     int arcNum() const { return _graph->edgeNum(); }
deba@416: 
deba@416:     typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
deba@416:     Arc findArc(const Node& u, const Node& v,
deba@416:                 const Arc& prev = INVALID) {
deba@416:       Arc arc = prev;
deba@416:       bool d = arc == INVALID ? true : (*_direction)[arc];
deba@416:       if (d) {
deba@416:         arc = _graph->findEdge(u, v, arc);
deba@416:         while (arc != INVALID && !(*_direction)[arc]) {
deba@416:           _graph->findEdge(u, v, arc);
deba@416:         }
deba@416:         if (arc != INVALID) return arc;
deba@414:       }
deba@416:       _graph->findEdge(v, u, arc);
deba@416:       while (arc != INVALID && (*_direction)[arc]) {
deba@416:         _graph->findEdge(u, v, arc);
deba@414:       }
deba@416:       return arc;
deba@416:     }
deba@416: 
deba@416:     Node addNode() {
deba@416:       return Node(_graph->addNode());
deba@416:     }
deba@416: 
deba@416:     Arc addArc(const Node& u, const Node& v) {
deba@416:       Arc arc = _graph->addArc(u, v);
deba@416:       _direction->set(arc, _graph->source(arc) == u);
deba@416:       return arc;
deba@416:     }
deba@416: 
deba@416:     void erase(const Node& i) { _graph->erase(i); }
deba@416:     void erase(const Arc& i) { _graph->erase(i); }
deba@416: 
deba@416:     void clear() { _graph->clear(); }
deba@416: 
deba@416:     int id(const Node& v) const { return _graph->id(v); }
deba@416:     int id(const Arc& e) const { return _graph->id(e); }
deba@416: 
deba@416:     Node nodeFromId(int idx) const { return _graph->nodeFromId(idx); }
deba@416:     Arc arcFromId(int idx) const { return _graph->edgeFromId(idx); }
deba@416: 
deba@416:     int maxNodeId() const { return _graph->maxNodeId(); }
deba@416:     int maxArcId() const { return _graph->maxEdgeId(); }
deba@416: 
deba@416:     typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
deba@416:     NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
deba@416: 
deba@416:     typedef typename ItemSetTraits<Graph, Arc>::ItemNotifier ArcNotifier;
deba@416:     ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
deba@416: 
deba@416:     template <typename _Value>
deba@416:     class NodeMap : public _Graph::template NodeMap<_Value> {
deba@416:     public:
deba@416: 
deba@416:       typedef typename _Graph::template NodeMap<_Value> Parent;
deba@416: 
deba@416:       explicit NodeMap(const OrienterBase& adapter)
deba@416:         : Parent(*adapter._graph) {}
deba@416: 
deba@416:       NodeMap(const OrienterBase& adapter, const _Value& value)
deba@416:         : Parent(*adapter._graph, value) {}
deba@416: 
deba@416:     private:
deba@416:       NodeMap& operator=(const NodeMap& cmap) {
deba@416:         return operator=<NodeMap>(cmap);
deba@416:       }
deba@416: 
deba@416:       template <typename CMap>
deba@416:       NodeMap& operator=(const CMap& cmap) {
deba@416:         Parent::operator=(cmap);
deba@416:         return *this;
deba@416:       }
deba@414: 
deba@414:     };
deba@414: 
deba@416:     template <typename _Value>
deba@416:     class ArcMap : public _Graph::template EdgeMap<_Value> {
deba@416:     public:
deba@416: 
deba@416:       typedef typename Graph::template EdgeMap<_Value> Parent;
deba@416: 
deba@416:       explicit ArcMap(const OrienterBase& adapter)
deba@416:         : Parent(*adapter._graph) { }
deba@416: 
deba@416:       ArcMap(const OrienterBase& adapter, const _Value& value)
deba@416:         : Parent(*adapter._graph, value) { }
deba@416: 
deba@416:     private:
deba@416:       ArcMap& operator=(const ArcMap& cmap) {
deba@416:         return operator=<ArcMap>(cmap);
deba@416:       }
deba@416: 
deba@416:       template <typename CMap>
deba@416:       ArcMap& operator=(const CMap& cmap) {
deba@416:         Parent::operator=(cmap);
deba@416:         return *this;
deba@416:       }
deba@416:     };
deba@416: 
deba@416: 
deba@416: 
deba@416:   protected:
deba@416:     Graph* _graph;
deba@416:     DirectionMap* _direction;
deba@416: 
deba@416:     void setDirectionMap(DirectionMap& direction) {
deba@416:       _direction = &direction;
deba@416:     }
deba@416: 
deba@416:     void setGraph(Graph& graph) {
deba@416:       _graph = &graph;
deba@416:     }
deba@416: 
deba@414:   };
deba@414: 
deba@416:   /// \ingroup graph_adaptors
deba@414:   ///
deba@416:   /// \brief Orients the edges of the graph to get a digraph
deba@416:   ///
deba@416:   /// This adaptor orients each edge in the undirected graph. The
deba@416:   /// direction of the arcs stored in an edge node map.  The arcs can
deba@416:   /// be easily reverted by the \c reverseArc() member function in the
deba@416:   /// adaptor. The Orienter adaptor is conform to the \ref
deba@416:   /// concepts::Digraph "Digraph concept".
deba@416:   ///
deba@416:   /// \tparam _Graph It must be conform to the \ref concepts::Graph
deba@416:   /// "Graph concept". The type can be specified to be const.
deba@416:   /// \tparam _DirectionMap A bool valued edge map of the the adapted
deba@416:   /// graph.
deba@416:   ///
deba@416:   /// \sa orienter
deba@416:   template<typename _Graph,
deba@416:            typename DirectionMap = typename _Graph::template EdgeMap<bool> >
deba@416:   class Orienter :
deba@416:     public DigraphAdaptorExtender<OrienterBase<_Graph, DirectionMap> > {
deba@416:   public:
deba@416:     typedef _Graph Graph;
deba@416:     typedef DigraphAdaptorExtender<
deba@416:       OrienterBase<_Graph, DirectionMap> > Parent;
deba@416:     typedef typename Parent::Arc Arc;
deba@416:   protected:
deba@416:     Orienter() { }
deba@416:   public:
deba@416: 
deba@416:     /// \brief Constructor of the adaptor
deba@416:     ///
deba@416:     /// Constructor of the adaptor
deba@416:     Orienter(Graph& graph, DirectionMap& direction) {
deba@416:       setGraph(graph);
deba@416:       setDirectionMap(direction);
deba@416:     }
deba@416: 
deba@416:     /// \brief Reverse arc
deba@416:     ///
deba@416:     /// It reverse the given arc. It simply negate the direction in the map.
deba@416:     void reverseArc(const Arc& a) {
deba@416:       Parent::reverseArc(a);
deba@416:     }
deba@416:   };
deba@416: 
deba@416:   /// \brief Just gives back a Orienter
deba@416:   ///
deba@416:   /// Just gives back a Orienter
deba@416:   template<typename Graph, typename DirectionMap>
deba@416:   Orienter<const Graph, DirectionMap>
deba@416:   orienter(const Graph& graph, DirectionMap& dm) {
deba@416:     return Orienter<const Graph, DirectionMap>(graph, dm);
deba@414:   }
deba@414: 
deba@416:   template<typename Graph, typename DirectionMap>
deba@416:   Orienter<const Graph, const DirectionMap>
deba@416:   orienter(const Graph& graph, const DirectionMap& dm) {
deba@416:     return Orienter<const Graph, const DirectionMap>(graph, dm);
deba@416:   }
deba@416: 
deba@416:   namespace _adaptor_bits {
deba@416: 
deba@416:     template<typename _Digraph,
deba@416:              typename _CapacityMap = typename _Digraph::template ArcMap<int>,
deba@416:              typename _FlowMap = _CapacityMap,
deba@416:              typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
deba@416:     class ResForwardFilter {
deba@416:     public:
deba@416: 
deba@416:       typedef _Digraph Digraph;
deba@416:       typedef _CapacityMap CapacityMap;
deba@416:       typedef _FlowMap FlowMap;
deba@416:       typedef _Tolerance Tolerance;
deba@416: 
deba@416:       typedef typename Digraph::Arc Key;
deba@416:       typedef bool Value;
deba@416: 
deba@416:     private:
deba@416: 
deba@416:       const CapacityMap* _capacity;
deba@416:       const FlowMap* _flow;
deba@416:       Tolerance _tolerance;
deba@416:     public:
deba@416: 
deba@416:       ResForwardFilter(const CapacityMap& capacity, const FlowMap& flow,
deba@416:                        const Tolerance& tolerance = Tolerance())
deba@416:         : _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
deba@416: 
deba@416:       bool operator[](const typename Digraph::Arc& a) const {
deba@416:         return _tolerance.positive((*_capacity)[a] - (*_flow)[a]);
deba@416:       }
deba@416:     };
deba@416: 
deba@416:     template<typename _Digraph,
deba@416:              typename _CapacityMap = typename _Digraph::template ArcMap<int>,
deba@416:              typename _FlowMap = _CapacityMap,
deba@416:              typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
deba@416:     class ResBackwardFilter {
deba@416:     public:
deba@416: 
deba@416:       typedef _Digraph Digraph;
deba@416:       typedef _CapacityMap CapacityMap;
deba@416:       typedef _FlowMap FlowMap;
deba@416:       typedef _Tolerance Tolerance;
deba@416: 
deba@416:       typedef typename Digraph::Arc Key;
deba@416:       typedef bool Value;
deba@416: 
deba@416:     private:
deba@416: 
deba@416:       const CapacityMap* _capacity;
deba@416:       const FlowMap* _flow;
deba@416:       Tolerance _tolerance;
deba@416: 
deba@416:     public:
deba@416: 
deba@416:       ResBackwardFilter(const CapacityMap& capacity, const FlowMap& flow,
deba@416:                         const Tolerance& tolerance = Tolerance())
deba@416:         : _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
deba@416: 
deba@416:       bool operator[](const typename Digraph::Arc& a) const {
deba@416:         return _tolerance.positive((*_flow)[a]);
deba@416:       }
deba@416:     };
deba@416: 
deba@416:   }
deba@416: 
deba@416:   /// \ingroup graph_adaptors
deba@416:   ///
deba@416:   /// \brief An adaptor for composing the residual graph for directed
deba@416:   /// flow and circulation problems.
deba@416:   ///
deba@416:   /// An adaptor for composing the residual graph for directed flow and
deba@416:   /// circulation problems.  Let \f$ G=(V, A) \f$ be a directed graph
deba@416:   /// and let \f$ F \f$ be a number type. Let moreover \f$ f,c:A\to F \f$,
deba@416:   /// be functions on the arc-set.
deba@416:   ///
deba@416:   /// Then Residual implements the digraph structure with
deba@416:   /// node-set \f$ V \f$ and arc-set \f$ A_{forward}\cup A_{backward} \f$,
deba@416:   /// where \f$ A_{forward}=\{uv : uv\in A, f(uv)<c(uv)\} \f$ and
deba@416:   /// \f$ A_{backward}=\{vu : uv\in A, f(uv)>0\} \f$, i.e. the so
deba@416:   /// called residual graph.  When we take the union
deba@416:   /// \f$ A_{forward}\cup A_{backward} \f$, multiplicities are counted,
deba@416:   /// i.e.  if an arc is in both \f$ A_{forward} \f$ and
deba@416:   /// \f$ A_{backward} \f$, then in the adaptor it appears in both
deba@416:   /// orientation.
deba@416:   ///
deba@416:   /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
deba@416:   /// "Digraph concept". The type is implicitly const.
deba@416:   /// \tparam _CapacityMap An arc map of some numeric type, it defines
deba@416:   /// the capacities in the flow problem. The map is implicitly const.
deba@416:   /// \tparam _FlowMap An arc map of some numeric type, it defines
deba@416:   /// the capacities in the flow problem.
deba@416:   /// \tparam _Tolerance Handler for inexact computation.
deba@416:   template<typename _Digraph,
deba@416:            typename _CapacityMap = typename _Digraph::template ArcMap<int>,
deba@416:            typename _FlowMap = _CapacityMap,
deba@414:            typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
deba@416:   class Residual :
deba@416:     public FilterArcs<
deba@416:     Undirector<const _Digraph>,
deba@416:     typename Undirector<const _Digraph>::template CombinedArcMap<
deba@416:       _adaptor_bits::ResForwardFilter<const _Digraph, _CapacityMap,
deba@416:                                       _FlowMap, _Tolerance>,
deba@416:       _adaptor_bits::ResBackwardFilter<const _Digraph, _CapacityMap,
deba@416:                                        _FlowMap, _Tolerance> > >
deba@416:   {
deba@414:   public:
deba@414: 
deba@414:     typedef _Digraph Digraph;
deba@414:     typedef _CapacityMap CapacityMap;
deba@414:     typedef _FlowMap FlowMap;
deba@414:     typedef _Tolerance Tolerance;
deba@414: 
deba@414:     typedef typename CapacityMap::Value Value;
deba@416:     typedef Residual Adaptor;
deba@414: 
deba@414:   protected:
deba@414: 
deba@416:     typedef Undirector<const Digraph> Undirected;
deba@416: 
deba@416:     typedef _adaptor_bits::ResForwardFilter<const Digraph, CapacityMap,
deba@416:                                             FlowMap, Tolerance> ForwardFilter;
deba@416: 
deba@416:     typedef _adaptor_bits::ResBackwardFilter<const Digraph, CapacityMap,
deba@416:                                              FlowMap, Tolerance> BackwardFilter;
deba@416: 
deba@416:     typedef typename Undirected::
deba@414:     template CombinedArcMap<ForwardFilter, BackwardFilter> ArcFilter;
deba@414: 
deba@416:     typedef FilterArcs<Undirected, ArcFilter> Parent;
deba@414: 
deba@414:     const CapacityMap* _capacity;
deba@414:     FlowMap* _flow;
deba@414: 
deba@416:     Undirected _graph;
deba@414:     ForwardFilter _forward_filter;
deba@414:     BackwardFilter _backward_filter;
deba@414:     ArcFilter _arc_filter;
deba@414: 
deba@414:   public:
deba@414: 
deba@414:     /// \brief Constructor of the residual digraph.
deba@414:     ///
deba@416:     /// Constructor of the residual graph. The parameters are the digraph,
deba@414:     /// the flow map, the capacity map and a tolerance object.
deba@416:     Residual(const Digraph& digraph, const CapacityMap& capacity,
deba@416:              FlowMap& flow, const Tolerance& tolerance = Tolerance())
deba@414:       : Parent(), _capacity(&capacity), _flow(&flow), _graph(digraph),
deba@416:         _forward_filter(capacity, flow, tolerance),
deba@414:         _backward_filter(capacity, flow, tolerance),
deba@414:         _arc_filter(_forward_filter, _backward_filter)
deba@414:     {
deba@414:       Parent::setDigraph(_graph);
deba@414:       Parent::setArcFilterMap(_arc_filter);
deba@414:     }
deba@414: 
deba@414:     typedef typename Parent::Arc Arc;
deba@414: 
deba@414:     /// \brief Gives back the residual capacity of the arc.
deba@414:     ///
deba@414:     /// Gives back the residual capacity of the arc.
deba@416:     Value residualCapacity(const Arc& a) const {
deba@416:       if (Undirected::direction(a)) {
deba@416:         return (*_capacity)[a] - (*_flow)[a];
deba@414:       } else {
deba@416:         return (*_flow)[a];
deba@414:       }
deba@416:     }
deba@416: 
deba@416:     /// \brief Augment on the given arc in the residual graph.
deba@414:     ///
deba@416:     /// Augment on the given arc in the residual graph. It increase
deba@414:     /// or decrease the flow on the original arc depend on the direction
deba@414:     /// of the residual arc.
deba@416:     void augment(const Arc& a, const Value& v) const {
deba@416:       if (Undirected::direction(a)) {
deba@416:         _flow->set(a, (*_flow)[a] + v);
deba@416:       } else {
deba@416:         _flow->set(a, (*_flow)[a] - v);
deba@414:       }
deba@414:     }
deba@414: 
deba@414:     /// \brief Returns the direction of the arc.
deba@414:     ///
deba@414:     /// Returns true when the arc is same oriented as the original arc.
deba@416:     static bool forward(const Arc& a) {
deba@416:       return Undirected::direction(a);
deba@414:     }
deba@414: 
deba@414:     /// \brief Returns the direction of the arc.
deba@414:     ///
deba@414:     /// Returns true when the arc is opposite oriented as the original arc.
deba@416:     static bool backward(const Arc& a) {
deba@416:       return !Undirected::direction(a);
deba@414:     }
deba@414: 
deba@414:     /// \brief Gives back the forward oriented residual arc.
deba@414:     ///
deba@414:     /// Gives back the forward oriented residual arc.
deba@416:     static Arc forward(const typename Digraph::Arc& a) {
deba@416:       return Undirected::direct(a, true);
deba@414:     }
deba@414: 
deba@414:     /// \brief Gives back the backward oriented residual arc.
deba@414:     ///
deba@414:     /// Gives back the backward oriented residual arc.
deba@416:     static Arc backward(const typename Digraph::Arc& a) {
deba@416:       return Undirected::direct(a, false);
deba@414:     }
deba@414: 
deba@414:     /// \brief Residual capacity map.
deba@414:     ///
deba@416:     /// In generic residual graph the residual capacity can be obtained
deba@416:     /// as a map.
deba@416:     class ResidualCapacity {
deba@414:     protected:
deba@414:       const Adaptor* _adaptor;
deba@414:     public:
deba@416:       /// The Key type
deba@414:       typedef Arc Key;
deba@416:       /// The Value type
deba@414:       typedef typename _CapacityMap::Value Value;
deba@414: 
deba@416:       /// Constructor
deba@416:       ResidualCapacity(const Adaptor& adaptor) : _adaptor(&adaptor) {}
deba@416: 
deba@416:       /// \e
deba@416:       Value operator[](const Arc& a) const {
deba@416:         return _adaptor->residualCapacity(a);
deba@414:       }
deba@416: 
deba@414:     };
deba@414: 
deba@414:   };
deba@414: 
deba@414:   template <typename _Digraph>
deba@416:   class SplitNodesBase {
deba@414:   public:
deba@414: 
deba@414:     typedef _Digraph Digraph;
deba@414:     typedef DigraphAdaptorBase<const _Digraph> Parent;
deba@416:     typedef SplitNodesBase Adaptor;
deba@414: 
deba@414:     typedef typename Digraph::Node DigraphNode;
deba@414:     typedef typename Digraph::Arc DigraphArc;
deba@414: 
deba@414:     class Node;
deba@414:     class Arc;
deba@414: 
deba@414:   private:
deba@414: 
deba@414:     template <typename T> class NodeMapBase;
deba@414:     template <typename T> class ArcMapBase;
deba@414: 
deba@414:   public:
deba@416: 
deba@414:     class Node : public DigraphNode {
deba@416:       friend class SplitNodesBase;
deba@414:       template <typename T> friend class NodeMapBase;
deba@414:     private:
deba@414: 
deba@414:       bool _in;
deba@414:       Node(DigraphNode node, bool in)
deba@416:         : DigraphNode(node), _in(in) {}
deba@416: 
deba@414:     public:
deba@414: 
deba@414:       Node() {}
deba@414:       Node(Invalid) : DigraphNode(INVALID), _in(true) {}
deba@414: 
deba@414:       bool operator==(const Node& node) const {
deba@416:         return DigraphNode::operator==(node) && _in == node._in;
deba@414:       }
deba@416: 
deba@414:       bool operator!=(const Node& node) const {
deba@416:         return !(*this == node);
deba@414:       }
deba@416: 
deba@414:       bool operator<(const Node& node) const {
deba@416:         return DigraphNode::operator<(node) ||
deba@416:           (DigraphNode::operator==(node) && _in < node._in);
deba@414:       }
deba@414:     };
deba@414: 
deba@414:     class Arc {
deba@416:       friend class SplitNodesBase;
deba@414:       template <typename T> friend class ArcMapBase;
deba@414:     private:
deba@414:       typedef BiVariant<DigraphArc, DigraphNode> ArcImpl;
deba@414: 
deba@414:       explicit Arc(const DigraphArc& arc) : _item(arc) {}
deba@414:       explicit Arc(const DigraphNode& node) : _item(node) {}
deba@416: 
deba@414:       ArcImpl _item;
deba@414: 
deba@414:     public:
deba@414:       Arc() {}
deba@414:       Arc(Invalid) : _item(DigraphArc(INVALID)) {}
deba@414: 
deba@414:       bool operator==(const Arc& arc) const {
deba@414:         if (_item.firstState()) {
deba@414:           if (arc._item.firstState()) {
deba@414:             return _item.first() == arc._item.first();
deba@414:           }
deba@414:         } else {
deba@414:           if (arc._item.secondState()) {
deba@414:             return _item.second() == arc._item.second();
deba@414:           }
deba@414:         }
deba@414:         return false;
deba@414:       }
deba@416: 
deba@414:       bool operator!=(const Arc& arc) const {
deba@416:         return !(*this == arc);
deba@414:       }
deba@416: 
deba@414:       bool operator<(const Arc& arc) const {
deba@414:         if (_item.firstState()) {
deba@414:           if (arc._item.firstState()) {
deba@414:             return _item.first() < arc._item.first();
deba@414:           }
deba@414:           return false;
deba@414:         } else {
deba@414:           if (arc._item.secondState()) {
deba@414:             return _item.second() < arc._item.second();
deba@414:           }
deba@414:           return true;
deba@414:         }
deba@414:       }
deba@414: 
deba@414:       operator DigraphArc() const { return _item.first(); }
deba@414:       operator DigraphNode() const { return _item.second(); }
deba@414: 
deba@414:     };
deba@414: 
deba@414:     void first(Node& n) const {
deba@414:       _digraph->first(n);
deba@414:       n._in = true;
deba@414:     }
deba@414: 
deba@414:     void next(Node& n) const {
deba@414:       if (n._in) {
deba@416:         n._in = false;
deba@414:       } else {
deba@416:         n._in = true;
deba@416:         _digraph->next(n);
deba@414:       }
deba@414:     }
deba@414: 
deba@414:     void first(Arc& e) const {
deba@414:       e._item.setSecond();
deba@414:       _digraph->first(e._item.second());
deba@414:       if (e._item.second() == INVALID) {
deba@414:         e._item.setFirst();
deba@416:         _digraph->first(e._item.first());
deba@414:       }
deba@414:     }
deba@414: 
deba@414:     void next(Arc& e) const {
deba@414:       if (e._item.secondState()) {
deba@416:         _digraph->next(e._item.second());
deba@414:         if (e._item.second() == INVALID) {
deba@414:           e._item.setFirst();
deba@414:           _digraph->first(e._item.first());
deba@414:         }
deba@414:       } else {
deba@416:         _digraph->next(e._item.first());
deba@416:       }
deba@414:     }
deba@414: 
deba@414:     void firstOut(Arc& e, const Node& n) const {
deba@414:       if (n._in) {
deba@414:         e._item.setSecond(n);
deba@414:       } else {
deba@414:         e._item.setFirst();
deba@416:         _digraph->firstOut(e._item.first(), n);
deba@414:       }
deba@414:     }
deba@414: 
deba@414:     void nextOut(Arc& e) const {
deba@414:       if (!e._item.firstState()) {
deba@416:         e._item.setFirst(INVALID);
deba@414:       } else {
deba@416:         _digraph->nextOut(e._item.first());
deba@416:       }
deba@414:     }
deba@414: 
deba@414:     void firstIn(Arc& e, const Node& n) const {
deba@414:       if (!n._in) {
deba@416:         e._item.setSecond(n);
deba@414:       } else {
deba@414:         e._item.setFirst();
deba@416:         _digraph->firstIn(e._item.first(), n);
deba@414:       }
deba@414:     }
deba@414: 
deba@414:     void nextIn(Arc& e) const {
deba@414:       if (!e._item.firstState()) {
deba@416:         e._item.setFirst(INVALID);
deba@414:       } else {
deba@416:         _digraph->nextIn(e._item.first());
deba@414:       }
deba@414:     }
deba@414: 
deba@414:     Node source(const Arc& e) const {
deba@414:       if (e._item.firstState()) {
deba@416:         return Node(_digraph->source(e._item.first()), false);
deba@414:       } else {
deba@416:         return Node(e._item.second(), true);
deba@414:       }
deba@414:     }
deba@414: 
deba@414:     Node target(const Arc& e) const {
deba@414:       if (e._item.firstState()) {
deba@416:         return Node(_digraph->target(e._item.first()), true);
deba@414:       } else {
deba@416:         return Node(e._item.second(), false);
deba@414:       }
deba@414:     }
deba@414: 
deba@414:     int id(const Node& n) const {
deba@414:       return (_digraph->id(n) << 1) | (n._in ? 0 : 1);
deba@414:     }
deba@414:     Node nodeFromId(int ix) const {
deba@414:       return Node(_digraph->nodeFromId(ix >> 1), (ix & 1) == 0);
deba@414:     }
deba@414:     int maxNodeId() const {
deba@414:       return 2 * _digraph->maxNodeId() + 1;
deba@414:     }
deba@414: 
deba@414:     int id(const Arc& e) const {
deba@414:       if (e._item.firstState()) {
deba@414:         return _digraph->id(e._item.first()) << 1;
deba@414:       } else {
deba@414:         return (_digraph->id(e._item.second()) << 1) | 1;
deba@414:       }
deba@414:     }
deba@414:     Arc arcFromId(int ix) const {
deba@414:       if ((ix & 1) == 0) {
deba@414:         return Arc(_digraph->arcFromId(ix >> 1));
deba@414:       } else {
deba@414:         return Arc(_digraph->nodeFromId(ix >> 1));
deba@414:       }
deba@414:     }
deba@414:     int maxArcId() const {
deba@416:       return std::max(_digraph->maxNodeId() << 1,
deba@414:                       (_digraph->maxArcId() << 1) | 1);
deba@414:     }
deba@414: 
deba@414:     static bool inNode(const Node& n) {
deba@414:       return n._in;
deba@414:     }
deba@414: 
deba@414:     static bool outNode(const Node& n) {
deba@414:       return !n._in;
deba@414:     }
deba@414: 
deba@414:     static bool origArc(const Arc& e) {
deba@414:       return e._item.firstState();
deba@414:     }
deba@414: 
deba@414:     static bool bindArc(const Arc& e) {
deba@414:       return e._item.secondState();
deba@414:     }
deba@414: 
deba@414:     static Node inNode(const DigraphNode& n) {
deba@414:       return Node(n, true);
deba@414:     }
deba@414: 
deba@414:     static Node outNode(const DigraphNode& n) {
deba@414:       return Node(n, false);
deba@414:     }
deba@414: 
deba@414:     static Arc arc(const DigraphNode& n) {
deba@414:       return Arc(n);
deba@414:     }
deba@414: 
deba@414:     static Arc arc(const DigraphArc& e) {
deba@414:       return Arc(e);
deba@414:     }
deba@414: 
deba@414:     typedef True NodeNumTag;
deba@414: 
deba@414:     int nodeNum() const {
deba@414:       return  2 * countNodes(*_digraph);
deba@414:     }
deba@414: 
deba@414:     typedef True EdgeNumTag;
deba@414:     int arcNum() const {
deba@414:       return countArcs(*_digraph) + countNodes(*_digraph);
deba@414:     }
deba@414: 
deba@414:     typedef True FindEdgeTag;
deba@416:     Arc findArc(const Node& u, const Node& v,
deba@416:                 const Arc& prev = INVALID) const {
deba@414:       if (inNode(u)) {
deba@414:         if (outNode(v)) {
deba@416:           if (static_cast<const DigraphNode&>(u) ==
deba@414:               static_cast<const DigraphNode&>(v) && prev == INVALID) {
deba@414:             return Arc(u);
deba@414:           }
deba@414:         }
deba@414:       } else {
deba@414:         if (inNode(v)) {
deba@414:           return Arc(::lemon::findArc(*_digraph, u, v, prev));
deba@414:         }
deba@414:       }
deba@414:       return INVALID;
deba@414:     }
deba@414: 
deba@414:   private:
deba@416: 
deba@414:     template <typename _Value>
deba@416:     class NodeMapBase
deba@414:       : public MapTraits<typename Parent::template NodeMap<_Value> > {
deba@414:       typedef typename Parent::template NodeMap<_Value> NodeImpl;
deba@414:     public:
deba@414:       typedef Node Key;
deba@414:       typedef _Value Value;
deba@416: 
deba@416:       NodeMapBase(const Adaptor& adaptor)
deba@416:         : _in_map(*adaptor._digraph), _out_map(*adaptor._digraph) {}
deba@416:       NodeMapBase(const Adaptor& adaptor, const Value& value)
deba@416:         : _in_map(*adaptor._digraph, value),
deba@416:           _out_map(*adaptor._digraph, value) {}
deba@414: 
deba@414:       void set(const Node& key, const Value& val) {
deba@416:         if (Adaptor::inNode(key)) { _in_map.set(key, val); }
deba@416:         else {_out_map.set(key, val); }
deba@414:       }
deba@416: 
deba@416:       typename MapTraits<NodeImpl>::ReturnValue
deba@414:       operator[](const Node& key) {
deba@416:         if (Adaptor::inNode(key)) { return _in_map[key]; }
deba@416:         else { return _out_map[key]; }
deba@414:       }
deba@414: 
deba@414:       typename MapTraits<NodeImpl>::ConstReturnValue
deba@414:       operator[](const Node& key) const {
deba@416:         if (Adaptor::inNode(key)) { return _in_map[key]; }
deba@416:         else { return _out_map[key]; }
deba@414:       }
deba@414: 
deba@414:     private:
deba@414:       NodeImpl _in_map, _out_map;
deba@414:     };
deba@414: 
deba@414:     template <typename _Value>
deba@416:     class ArcMapBase
deba@414:       : public MapTraits<typename Parent::template ArcMap<_Value> > {
deba@414:       typedef typename Parent::template ArcMap<_Value> ArcImpl;
deba@414:       typedef typename Parent::template NodeMap<_Value> NodeImpl;
deba@414:     public:
deba@414:       typedef Arc Key;
deba@414:       typedef _Value Value;
deba@414: 
deba@416:       ArcMapBase(const Adaptor& adaptor)
deba@416:         : _arc_map(*adaptor._digraph), _node_map(*adaptor._digraph) {}
deba@416:       ArcMapBase(const Adaptor& adaptor, const Value& value)
deba@416:         : _arc_map(*adaptor._digraph, value),
deba@416:           _node_map(*adaptor._digraph, value) {}
deba@414: 
deba@414:       void set(const Arc& key, const Value& val) {
deba@416:         if (Adaptor::origArc(key)) {
deba@416:           _arc_map.set(key._item.first(), val);
deba@414:         } else {
deba@416:           _node_map.set(key._item.second(), val);
deba@414:         }
deba@414:       }
deba@416: 
deba@414:       typename MapTraits<ArcImpl>::ReturnValue
deba@414:       operator[](const Arc& key) {
deba@416:         if (Adaptor::origArc(key)) {
deba@414:           return _arc_map[key._item.first()];
deba@414:         } else {
deba@414:           return _node_map[key._item.second()];
deba@414:         }
deba@414:       }
deba@414: 
deba@414:       typename MapTraits<ArcImpl>::ConstReturnValue
deba@414:       operator[](const Arc& key) const {
deba@416:         if (Adaptor::origArc(key)) {
deba@414:           return _arc_map[key._item.first()];
deba@414:         } else {
deba@414:           return _node_map[key._item.second()];
deba@414:         }
deba@414:       }
deba@414: 
deba@414:     private:
deba@414:       ArcImpl _arc_map;
deba@414:       NodeImpl _node_map;
deba@414:     };
deba@414: 
deba@414:   public:
deba@414: 
deba@414:     template <typename _Value>
deba@416:     class NodeMap
deba@416:       : public SubMapExtender<Adaptor, NodeMapBase<_Value> >
deba@414:     {
deba@414:     public:
deba@414:       typedef _Value Value;
deba@414:       typedef SubMapExtender<Adaptor, NodeMapBase<Value> > Parent;
deba@416: 
deba@416:       NodeMap(const Adaptor& adaptor)
deba@416:         : Parent(adaptor) {}
deba@416: 
deba@416:       NodeMap(const Adaptor& adaptor, const Value& value)
deba@416:         : Parent(adaptor, value) {}
deba@416: 
deba@414:     private:
deba@414:       NodeMap& operator=(const NodeMap& cmap) {
deba@416:         return operator=<NodeMap>(cmap);
deba@414:       }
deba@416: 
deba@414:       template <typename CMap>
deba@414:       NodeMap& operator=(const CMap& cmap) {
deba@414:         Parent::operator=(cmap);
deba@416:         return *this;
deba@414:       }
deba@414:     };
deba@414: 
deba@414:     template <typename _Value>
deba@416:     class ArcMap
deba@416:       : public SubMapExtender<Adaptor, ArcMapBase<_Value> >
deba@414:     {
deba@414:     public:
deba@414:       typedef _Value Value;
deba@414:       typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
deba@416: 
deba@416:       ArcMap(const Adaptor& adaptor)
deba@416:         : Parent(adaptor) {}
deba@416: 
deba@416:       ArcMap(const Adaptor& adaptor, const Value& value)
deba@416:         : Parent(adaptor, value) {}
deba@416: 
deba@414:     private:
deba@414:       ArcMap& operator=(const ArcMap& cmap) {
deba@416:         return operator=<ArcMap>(cmap);
deba@414:       }
deba@416: 
deba@414:       template <typename CMap>
deba@414:       ArcMap& operator=(const CMap& cmap) {
deba@414:         Parent::operator=(cmap);
deba@416:         return *this;
deba@414:       }
deba@414:     };
deba@414: 
deba@414:   protected:
deba@414: 
deba@416:     SplitNodesBase() : _digraph(0) {}
deba@414: 
deba@414:     Digraph* _digraph;
deba@414: 
deba@414:     void setDigraph(Digraph& digraph) {
deba@414:       _digraph = &digraph;
deba@414:     }
deba@416: 
deba@414:   };
deba@414: 
deba@414:   /// \ingroup graph_adaptors
deba@414:   ///
deba@416:   /// \brief Split the nodes of a directed graph
deba@416:   ///
deba@416:   /// The SplitNodes adaptor splits each node into an in-node and an
deba@416:   /// out-node. Formaly, the adaptor replaces each \f$ u \f$ node in
deba@416:   /// the digraph with two nodes(namely node \f$ u_{in} \f$ and node
deba@416:   /// \f$ u_{out} \f$). If there is a \f$ (v, u) \f$ arc in the
deba@416:   /// original digraph the new target of the arc will be \f$ u_{in} \f$
deba@416:   /// and similarly the source of the original \f$ (u, v) \f$ arc
deba@416:   /// will be \f$ u_{out} \f$.  The adaptor will add for each node in
deba@416:   /// the original digraph an additional arc which connects
deba@414:   /// \f$ (u_{in}, u_{out}) \f$.
deba@414:   ///
deba@416:   /// The aim of this class is to run algorithm with node costs if the
deba@414:   /// algorithm can use directly just arc costs. In this case we should use
deba@416:   /// a \c SplitNodes and set the node cost of the graph to the
deba@416:   /// bind arc in the adapted graph.
deba@414:   ///
deba@416:   /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
deba@416:   /// "Digraph concept". The type can be specified to be const.
deba@414:   template <typename _Digraph>
deba@416:   class SplitNodes
deba@416:     : public DigraphAdaptorExtender<SplitNodesBase<_Digraph> > {
deba@414:   public:
deba@414:     typedef _Digraph Digraph;
deba@416:     typedef DigraphAdaptorExtender<SplitNodesBase<Digraph> > Parent;
deba@414: 
deba@415:     typedef typename Digraph::Node DigraphNode;
deba@415:     typedef typename Digraph::Arc DigraphArc;
deba@415: 
deba@414:     typedef typename Parent::Node Node;
deba@414:     typedef typename Parent::Arc Arc;
deba@414: 
deba@414:     /// \brief Constructor of the adaptor.
deba@414:     ///
deba@414:     /// Constructor of the adaptor.
deba@416:     SplitNodes(Digraph& g) {
deba@414:       Parent::setDigraph(g);
deba@414:     }
deba@414: 
deba@415:     /// \brief Returns true when the node is in-node.
deba@415:     ///
deba@415:     /// Returns true when the node is in-node.
deba@415:     static bool inNode(const Node& n) {
deba@415:       return Parent::inNode(n);
deba@415:     }
deba@415: 
deba@415:     /// \brief Returns true when the node is out-node.
deba@415:     ///
deba@415:     /// Returns true when the node is out-node.
deba@415:     static bool outNode(const Node& n) {
deba@415:       return Parent::outNode(n);
deba@415:     }
deba@415: 
deba@415:     /// \brief Returns true when the arc is arc in the original digraph.
deba@415:     ///
deba@415:     /// Returns true when the arc is arc in the original digraph.
deba@415:     static bool origArc(const Arc& a) {
deba@415:       return Parent::origArc(a);
deba@415:     }
deba@415: 
deba@415:     /// \brief Returns true when the arc binds an in-node and an out-node.
deba@415:     ///
deba@415:     /// Returns true when the arc binds an in-node and an out-node.
deba@415:     static bool bindArc(const Arc& a) {
deba@415:       return Parent::bindArc(a);
deba@415:     }
deba@415: 
deba@415:     /// \brief Gives back the in-node created from the \c node.
deba@415:     ///
deba@415:     /// Gives back the in-node created from the \c node.
deba@415:     static Node inNode(const DigraphNode& n) {
deba@415:       return Parent::inNode(n);
deba@415:     }
deba@415: 
deba@415:     /// \brief Gives back the out-node created from the \c node.
deba@415:     ///
deba@415:     /// Gives back the out-node created from the \c node.
deba@415:     static Node outNode(const DigraphNode& n) {
deba@415:       return Parent::outNode(n);
deba@415:     }
deba@415: 
deba@415:     /// \brief Gives back the arc binds the two part of the node.
deba@416:     ///
deba@415:     /// Gives back the arc binds the two part of the node.
deba@415:     static Arc arc(const DigraphNode& n) {
deba@415:       return Parent::arc(n);
deba@415:     }
deba@415: 
deba@415:     /// \brief Gives back the arc of the original arc.
deba@416:     ///
deba@415:     /// Gives back the arc of the original arc.
deba@415:     static Arc arc(const DigraphArc& a) {
deba@415:       return Parent::arc(a);
deba@415:     }
deba@415: 
deba@414:     /// \brief NodeMap combined from two original NodeMap
deba@414:     ///
deba@414:     /// This class adapt two of the original digraph NodeMap to
deba@414:     /// get a node map on the adapted digraph.
deba@414:     template <typename InNodeMap, typename OutNodeMap>
deba@414:     class CombinedNodeMap {
deba@414:     public:
deba@414: 
deba@414:       typedef Node Key;
deba@414:       typedef typename InNodeMap::Value Value;
deba@414: 
deba@414:       /// \brief Constructor
deba@414:       ///
deba@414:       /// Constructor.
deba@416:       CombinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map)
deba@416:         : _in_map(in_map), _out_map(out_map) {}
deba@414: 
deba@414:       /// \brief The subscript operator.
deba@414:       ///
deba@414:       /// The subscript operator.
deba@414:       Value& operator[](const Key& key) {
deba@416:         if (Parent::inNode(key)) {
deba@416:           return _in_map[key];
deba@416:         } else {
deba@416:           return _out_map[key];
deba@416:         }
deba@414:       }
deba@414: 
deba@414:       /// \brief The const subscript operator.
deba@414:       ///
deba@414:       /// The const subscript operator.
deba@414:       Value operator[](const Key& key) const {
deba@416:         if (Parent::inNode(key)) {
deba@416:           return _in_map[key];
deba@416:         } else {
deba@416:           return _out_map[key];
deba@416:         }
deba@414:       }
deba@414: 
deba@414:       /// \brief The setter function of the map.
deba@416:       ///
deba@414:       /// The setter function of the map.
deba@414:       void set(const Key& key, const Value& value) {
deba@416:         if (Parent::inNode(key)) {
deba@416:           _in_map.set(key, value);
deba@416:         } else {
deba@416:           _out_map.set(key, value);
deba@416:         }
deba@414:       }
deba@416: 
deba@414:     private:
deba@416: 
deba@414:       InNodeMap& _in_map;
deba@414:       OutNodeMap& _out_map;
deba@416: 
deba@414:     };
deba@414: 
deba@414: 
deba@416:     /// \brief Just gives back a combined node map
deba@416:     ///
deba@416:     /// Just gives back a combined node map
deba@414:     template <typename InNodeMap, typename OutNodeMap>
deba@416:     static CombinedNodeMap<InNodeMap, OutNodeMap>
deba@414:     combinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) {
deba@414:       return CombinedNodeMap<InNodeMap, OutNodeMap>(in_map, out_map);
deba@414:     }
deba@414: 
deba@414:     template <typename InNodeMap, typename OutNodeMap>
deba@416:     static CombinedNodeMap<const InNodeMap, OutNodeMap>
deba@414:     combinedNodeMap(const InNodeMap& in_map, OutNodeMap& out_map) {
deba@414:       return CombinedNodeMap<const InNodeMap, OutNodeMap>(in_map, out_map);
deba@414:     }
deba@414: 
deba@414:     template <typename InNodeMap, typename OutNodeMap>
deba@416:     static CombinedNodeMap<InNodeMap, const OutNodeMap>
deba@414:     combinedNodeMap(InNodeMap& in_map, const OutNodeMap& out_map) {
deba@414:       return CombinedNodeMap<InNodeMap, const OutNodeMap>(in_map, out_map);
deba@414:     }
deba@414: 
deba@414:     template <typename InNodeMap, typename OutNodeMap>
deba@416:     static CombinedNodeMap<const InNodeMap, const OutNodeMap>
deba@414:     combinedNodeMap(const InNodeMap& in_map, const OutNodeMap& out_map) {
deba@416:       return CombinedNodeMap<const InNodeMap,
deba@414:         const OutNodeMap>(in_map, out_map);
deba@414:     }
deba@414: 
deba@416:     /// \brief ArcMap combined from an original ArcMap and a NodeMap
deba@414:     ///
deba@416:     /// This class adapt an original ArcMap and a NodeMap to get an
deba@416:     /// arc map on the adapted digraph
deba@414:     template <typename DigraphArcMap, typename DigraphNodeMap>
deba@414:     class CombinedArcMap {
deba@414:     public:
deba@416: 
deba@414:       typedef Arc Key;
deba@414:       typedef typename DigraphArcMap::Value Value;
deba@416: 
deba@414:       /// \brief Constructor
deba@414:       ///
deba@414:       /// Constructor.
deba@416:       CombinedArcMap(DigraphArcMap& arc_map, DigraphNodeMap& node_map)
deba@416:         : _arc_map(arc_map), _node_map(node_map) {}
deba@414: 
deba@414:       /// \brief The subscript operator.
deba@414:       ///
deba@414:       /// The subscript operator.
deba@414:       void set(const Arc& arc, const Value& val) {
deba@416:         if (Parent::origArc(arc)) {
deba@416:           _arc_map.set(arc, val);
deba@416:         } else {
deba@416:           _node_map.set(arc, val);
deba@416:         }
deba@414:       }
deba@414: 
deba@414:       /// \brief The const subscript operator.
deba@414:       ///
deba@414:       /// The const subscript operator.
deba@414:       Value operator[](const Key& arc) const {
deba@416:         if (Parent::origArc(arc)) {
deba@416:           return _arc_map[arc];
deba@416:         } else {
deba@416:           return _node_map[arc];
deba@416:         }
deba@416:       }
deba@414: 
deba@414:       /// \brief The const subscript operator.
deba@414:       ///
deba@414:       /// The const subscript operator.
deba@414:       Value& operator[](const Key& arc) {
deba@416:         if (Parent::origArc(arc)) {
deba@416:           return _arc_map[arc];
deba@416:         } else {
deba@416:           return _node_map[arc];
deba@416:         }
deba@416:       }
deba@416: 
deba@414:     private:
deba@414:       DigraphArcMap& _arc_map;
deba@414:       DigraphNodeMap& _node_map;
deba@414:     };
deba@416: 
deba@416:     /// \brief Just gives back a combined arc map
deba@416:     ///
deba@416:     /// Just gives back a combined arc map
deba@414:     template <typename DigraphArcMap, typename DigraphNodeMap>
deba@416:     static CombinedArcMap<DigraphArcMap, DigraphNodeMap>
deba@414:     combinedArcMap(DigraphArcMap& arc_map, DigraphNodeMap& node_map) {
deba@414:       return CombinedArcMap<DigraphArcMap, DigraphNodeMap>(arc_map, node_map);
deba@414:     }
deba@414: 
deba@414:     template <typename DigraphArcMap, typename DigraphNodeMap>
deba@416:     static CombinedArcMap<const DigraphArcMap, DigraphNodeMap>
deba@414:     combinedArcMap(const DigraphArcMap& arc_map, DigraphNodeMap& node_map) {
deba@416:       return CombinedArcMap<const DigraphArcMap,
deba@414:         DigraphNodeMap>(arc_map, node_map);
deba@414:     }
deba@414: 
deba@414:     template <typename DigraphArcMap, typename DigraphNodeMap>
deba@416:     static CombinedArcMap<DigraphArcMap, const DigraphNodeMap>
deba@414:     combinedArcMap(DigraphArcMap& arc_map, const DigraphNodeMap& node_map) {
deba@416:       return CombinedArcMap<DigraphArcMap,
deba@414:         const DigraphNodeMap>(arc_map, node_map);
deba@414:     }
deba@414: 
deba@414:     template <typename DigraphArcMap, typename DigraphNodeMap>
deba@416:     static CombinedArcMap<const DigraphArcMap, const DigraphNodeMap>
deba@416:     combinedArcMap(const DigraphArcMap& arc_map,
deba@416:                    const DigraphNodeMap& node_map) {
deba@416:       return CombinedArcMap<const DigraphArcMap,
deba@414:         const DigraphNodeMap>(arc_map, node_map);
deba@414:     }
deba@414: 
deba@414:   };
deba@414: 
deba@416:   /// \brief Just gives back a node splitter
deba@414:   ///
deba@416:   /// Just gives back a node splitter
deba@414:   template<typename Digraph>
deba@416:   SplitNodes<Digraph>
deba@416:   splitNodes(const Digraph& digraph) {
deba@416:     return SplitNodes<Digraph>(digraph);
deba@414:   }
deba@414: 
deba@414: 
deba@414: } //namespace lemon
deba@414: 
deba@416: #endif //LEMON_ADAPTORS_H