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