1.1 --- a/doc/groups.dox Sun Nov 30 19:00:30 2008 +0100
1.2 +++ b/doc/groups.dox Sun Nov 30 19:18:32 2008 +0100
1.3 @@ -60,6 +60,79 @@
1.4 */
1.5
1.6 /**
1.7 +@defgroup graph_adaptors Adaptor Classes for graphs
1.8 +@ingroup graphs
1.9 +\brief This group contains several adaptor classes for digraphs and graphs
1.10 +
1.11 +The main parts of LEMON are the different graph structures, generic
1.12 +graph algorithms, graph concepts which couple these, and graph
1.13 +adaptors. While the previous notions are more or less clear, the
1.14 +latter one needs further explanation. Graph adaptors are graph classes
1.15 +which serve for considering graph structures in different ways.
1.16 +
1.17 +A short example makes this much clearer. Suppose that we have an
1.18 +instance \c g of a directed graph type say ListDigraph and an algorithm
1.19 +\code
1.20 +template <typename Digraph>
1.21 +int algorithm(const Digraph&);
1.22 +\endcode
1.23 +is needed to run on the reverse oriented graph. It may be expensive
1.24 +(in time or in memory usage) to copy \c g with the reversed
1.25 +arcs. In this case, an adaptor class is used, which (according
1.26 +to LEMON digraph concepts) works as a digraph. The adaptor uses the
1.27 +original digraph structure and digraph operations when methods of the
1.28 +reversed oriented graph are called. This means that the adaptor have
1.29 +minor memory usage, and do not perform sophisticated algorithmic
1.30 +actions. The purpose of it is to give a tool for the cases when a
1.31 +graph have to be used in a specific alteration. If this alteration is
1.32 +obtained by a usual construction like filtering the arc-set or
1.33 +considering a new orientation, then an adaptor is worthwhile to use.
1.34 +To come back to the reverse oriented graph, in this situation
1.35 +\code
1.36 +template<typename Digraph> class ReverseDigraph;
1.37 +\endcode
1.38 +template class can be used. The code looks as follows
1.39 +\code
1.40 +ListDigraph g;
1.41 +ReverseDigraph<ListGraph> rg(g);
1.42 +int result = algorithm(rg);
1.43 +\endcode
1.44 +After running the algorithm, the original graph \c g is untouched.
1.45 +This techniques gives rise to an elegant code, and based on stable
1.46 +graph adaptors, complex algorithms can be implemented easily.
1.47 +
1.48 +In flow, circulation and bipartite matching problems, the residual
1.49 +graph is of particular importance. Combining an adaptor implementing
1.50 +this, shortest path algorithms and minimum mean cycle algorithms,
1.51 +a range of weighted and cardinality optimization algorithms can be
1.52 +obtained. For other examples, the interested user is referred to the
1.53 +detailed documentation of particular adaptors.
1.54 +
1.55 +The behavior of graph adaptors can be very different. Some of them keep
1.56 +capabilities of the original graph while in other cases this would be
1.57 +meaningless. This means that the concepts that they are models of depend
1.58 +on the graph adaptor, and the wrapped graph(s).
1.59 +If an arc of \c rg is deleted, this is carried out by deleting the
1.60 +corresponding arc of \c g, thus the adaptor modifies the original graph.
1.61 +
1.62 +But for a residual graph, this operation has no sense.
1.63 +Let us stand one more example here to simplify your work.
1.64 +RevGraphAdaptor has constructor
1.65 +\code
1.66 +ReverseDigraph(Digraph& digraph);
1.67 +\endcode
1.68 +This means that in a situation, when a <tt>const ListDigraph&</tt>
1.69 +reference to a graph is given, then it have to be instantiated with
1.70 +<tt>Digraph=const ListDigraph</tt>.
1.71 +\code
1.72 +int algorithm1(const ListDigraph& g) {
1.73 + RevGraphAdaptor<const ListDigraph> rg(g);
1.74 + return algorithm2(rg);
1.75 +}
1.76 +\endcode
1.77 +*/
1.78 +
1.79 +/**
1.80 @defgroup semi_adaptors Semi-Adaptor Classes for Graphs
1.81 @ingroup graphs
1.82 \brief Graph types between real graphs and graph adaptors.
2.1 --- a/lemon/Makefile.am Sun Nov 30 19:00:30 2008 +0100
2.2 +++ b/lemon/Makefile.am Sun Nov 30 19:18:32 2008 +0100
2.3 @@ -16,6 +16,7 @@
2.4 #lemon_libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS) $(SOPLEX_LIBS)
2.5
2.6 lemon_HEADERS += \
2.7 + lemon/adaptors.h \
2.8 lemon/arg_parser.h \
2.9 lemon/assert.h \
2.10 lemon/bfs.h \
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/lemon/adaptors.h Sun Nov 30 19:18:32 2008 +0100
3.3 @@ -0,0 +1,3347 @@
3.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
3.5 + *
3.6 + * This file is a part of LEMON, a generic C++ optimization library.
3.7 + *
3.8 + * Copyright (C) 2003-2008
3.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
3.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
3.11 + *
3.12 + * Permission to use, modify and distribute this software is granted
3.13 + * provided that this copyright notice appears in all copies. For
3.14 + * precise terms see the accompanying LICENSE file.
3.15 + *
3.16 + * This software is provided "AS IS" with no warranty of any kind,
3.17 + * express or implied, and with no claim as to its suitability for any
3.18 + * purpose.
3.19 + *
3.20 + */
3.21 +
3.22 +#ifndef LEMON_ADAPTORS_H
3.23 +#define LEMON_ADAPTORS_H
3.24 +
3.25 +/// \ingroup graph_adaptors
3.26 +/// \file
3.27 +/// \brief Several graph adaptors
3.28 +///
3.29 +/// This file contains several useful adaptors for digraphs and graphs.
3.30 +
3.31 +#include <lemon/core.h>
3.32 +#include <lemon/maps.h>
3.33 +#include <lemon/bits/variant.h>
3.34 +
3.35 +#include <lemon/bits/graph_adaptor_extender.h>
3.36 +#include <lemon/tolerance.h>
3.37 +
3.38 +#include <algorithm>
3.39 +
3.40 +namespace lemon {
3.41 +
3.42 + template<typename _Digraph>
3.43 + class DigraphAdaptorBase {
3.44 + public:
3.45 + typedef _Digraph Digraph;
3.46 + typedef DigraphAdaptorBase Adaptor;
3.47 + typedef Digraph ParentDigraph;
3.48 +
3.49 + protected:
3.50 + Digraph* _digraph;
3.51 + DigraphAdaptorBase() : _digraph(0) { }
3.52 + void setDigraph(Digraph& digraph) { _digraph = &digraph; }
3.53 +
3.54 + public:
3.55 + DigraphAdaptorBase(Digraph& digraph) : _digraph(&digraph) { }
3.56 +
3.57 + typedef typename Digraph::Node Node;
3.58 + typedef typename Digraph::Arc Arc;
3.59 +
3.60 + void first(Node& i) const { _digraph->first(i); }
3.61 + void first(Arc& i) const { _digraph->first(i); }
3.62 + void firstIn(Arc& i, const Node& n) const { _digraph->firstIn(i, n); }
3.63 + void firstOut(Arc& i, const Node& n ) const { _digraph->firstOut(i, n); }
3.64 +
3.65 + void next(Node& i) const { _digraph->next(i); }
3.66 + void next(Arc& i) const { _digraph->next(i); }
3.67 + void nextIn(Arc& i) const { _digraph->nextIn(i); }
3.68 + void nextOut(Arc& i) const { _digraph->nextOut(i); }
3.69 +
3.70 + Node source(const Arc& a) const { return _digraph->source(a); }
3.71 + Node target(const Arc& a) const { return _digraph->target(a); }
3.72 +
3.73 + typedef NodeNumTagIndicator<Digraph> NodeNumTag;
3.74 + int nodeNum() const { return _digraph->nodeNum(); }
3.75 +
3.76 + typedef EdgeNumTagIndicator<Digraph> EdgeNumTag;
3.77 + int arcNum() const { return _digraph->arcNum(); }
3.78 +
3.79 + typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
3.80 + Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
3.81 + return _digraph->findArc(u, v, prev);
3.82 + }
3.83 +
3.84 + Node addNode() { return _digraph->addNode(); }
3.85 + Arc addArc(const Node& u, const Node& v) { return _digraph->addArc(u, v); }
3.86 +
3.87 + void erase(const Node& n) const { _digraph->erase(n); }
3.88 + void erase(const Arc& a) const { _digraph->erase(a); }
3.89 +
3.90 + void clear() const { _digraph->clear(); }
3.91 +
3.92 + int id(const Node& n) const { return _digraph->id(n); }
3.93 + int id(const Arc& a) const { return _digraph->id(a); }
3.94 +
3.95 + Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
3.96 + Arc arcFromId(int ix) const { return _digraph->arcFromId(ix); }
3.97 +
3.98 + int maxNodeId() const { return _digraph->maxNodeId(); }
3.99 + int maxArcId() const { return _digraph->maxArcId(); }
3.100 +
3.101 + typedef typename ItemSetTraits<Digraph, Node>::ItemNotifier NodeNotifier;
3.102 + NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
3.103 +
3.104 + typedef typename ItemSetTraits<Digraph, Arc>::ItemNotifier ArcNotifier;
3.105 + ArcNotifier& notifier(Arc) const { return _digraph->notifier(Arc()); }
3.106 +
3.107 + template <typename _Value>
3.108 + class NodeMap : public Digraph::template NodeMap<_Value> {
3.109 + public:
3.110 +
3.111 + typedef typename Digraph::template NodeMap<_Value> Parent;
3.112 +
3.113 + explicit NodeMap(const Adaptor& adaptor)
3.114 + : Parent(*adaptor._digraph) {}
3.115 +
3.116 + NodeMap(const Adaptor& adaptor, const _Value& value)
3.117 + : Parent(*adaptor._digraph, value) { }
3.118 +
3.119 + private:
3.120 + NodeMap& operator=(const NodeMap& cmap) {
3.121 + return operator=<NodeMap>(cmap);
3.122 + }
3.123 +
3.124 + template <typename CMap>
3.125 + NodeMap& operator=(const CMap& cmap) {
3.126 + Parent::operator=(cmap);
3.127 + return *this;
3.128 + }
3.129 +
3.130 + };
3.131 +
3.132 + template <typename _Value>
3.133 + class ArcMap : public Digraph::template ArcMap<_Value> {
3.134 + public:
3.135 +
3.136 + typedef typename Digraph::template ArcMap<_Value> Parent;
3.137 +
3.138 + explicit ArcMap(const Adaptor& adaptor)
3.139 + : Parent(*adaptor._digraph) {}
3.140 +
3.141 + ArcMap(const Adaptor& adaptor, const _Value& value)
3.142 + : Parent(*adaptor._digraph, value) {}
3.143 +
3.144 + private:
3.145 + ArcMap& operator=(const ArcMap& cmap) {
3.146 + return operator=<ArcMap>(cmap);
3.147 + }
3.148 +
3.149 + template <typename CMap>
3.150 + ArcMap& operator=(const CMap& cmap) {
3.151 + Parent::operator=(cmap);
3.152 + return *this;
3.153 + }
3.154 +
3.155 + };
3.156 +
3.157 + };
3.158 +
3.159 + template<typename _Graph>
3.160 + class GraphAdaptorBase {
3.161 + public:
3.162 + typedef _Graph Graph;
3.163 + typedef Graph ParentGraph;
3.164 +
3.165 + protected:
3.166 + Graph* _graph;
3.167 +
3.168 + GraphAdaptorBase() : _graph(0) {}
3.169 +
3.170 + void setGraph(Graph& graph) { _graph = &graph; }
3.171 +
3.172 + public:
3.173 + GraphAdaptorBase(Graph& graph) : _graph(&graph) {}
3.174 +
3.175 + typedef typename Graph::Node Node;
3.176 + typedef typename Graph::Arc Arc;
3.177 + typedef typename Graph::Edge Edge;
3.178 +
3.179 + void first(Node& i) const { _graph->first(i); }
3.180 + void first(Arc& i) const { _graph->first(i); }
3.181 + void first(Edge& i) const { _graph->first(i); }
3.182 + void firstIn(Arc& i, const Node& n) const { _graph->firstIn(i, n); }
3.183 + void firstOut(Arc& i, const Node& n ) const { _graph->firstOut(i, n); }
3.184 + void firstInc(Edge &i, bool &d, const Node &n) const {
3.185 + _graph->firstInc(i, d, n);
3.186 + }
3.187 +
3.188 + void next(Node& i) const { _graph->next(i); }
3.189 + void next(Arc& i) const { _graph->next(i); }
3.190 + void next(Edge& i) const { _graph->next(i); }
3.191 + void nextIn(Arc& i) const { _graph->nextIn(i); }
3.192 + void nextOut(Arc& i) const { _graph->nextOut(i); }
3.193 + void nextInc(Edge &i, bool &d) const { _graph->nextInc(i, d); }
3.194 +
3.195 + Node u(const Edge& e) const { return _graph->u(e); }
3.196 + Node v(const Edge& e) const { return _graph->v(e); }
3.197 +
3.198 + Node source(const Arc& a) const { return _graph->source(a); }
3.199 + Node target(const Arc& a) const { return _graph->target(a); }
3.200 +
3.201 + typedef NodeNumTagIndicator<Graph> NodeNumTag;
3.202 + int nodeNum() const { return _graph->nodeNum(); }
3.203 +
3.204 + typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
3.205 + int arcNum() const { return _graph->arcNum(); }
3.206 + int edgeNum() const { return _graph->edgeNum(); }
3.207 +
3.208 + typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
3.209 + Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
3.210 + return _graph->findArc(u, v, prev);
3.211 + }
3.212 + Edge findEdge(const Node& u, const Node& v, const Edge& prev = INVALID) {
3.213 + return _graph->findEdge(u, v, prev);
3.214 + }
3.215 +
3.216 + Node addNode() { return _graph->addNode(); }
3.217 + Edge addEdge(const Node& u, const Node& v) { return _graph->addEdge(u, v); }
3.218 +
3.219 + void erase(const Node& i) { _graph->erase(i); }
3.220 + void erase(const Edge& i) { _graph->erase(i); }
3.221 +
3.222 + void clear() { _graph->clear(); }
3.223 +
3.224 + bool direction(const Arc& a) const { return _graph->direction(a); }
3.225 + Arc direct(const Edge& e, bool d) const { return _graph->direct(e, d); }
3.226 +
3.227 + int id(const Node& v) const { return _graph->id(v); }
3.228 + int id(const Arc& a) const { return _graph->id(a); }
3.229 + int id(const Edge& e) const { return _graph->id(e); }
3.230 +
3.231 + Node nodeFromId(int ix) const { return _graph->nodeFromId(ix); }
3.232 + Arc arcFromId(int ix) const { return _graph->arcFromId(ix); }
3.233 + Edge edgeFromId(int ix) const { return _graph->edgeFromId(ix); }
3.234 +
3.235 + int maxNodeId() const { return _graph->maxNodeId(); }
3.236 + int maxArcId() const { return _graph->maxArcId(); }
3.237 + int maxEdgeId() const { return _graph->maxEdgeId(); }
3.238 +
3.239 + typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
3.240 + NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
3.241 +
3.242 + typedef typename ItemSetTraits<Graph, Arc>::ItemNotifier ArcNotifier;
3.243 + ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
3.244 +
3.245 + typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
3.246 + EdgeNotifier& notifier(Edge) const { return _graph->notifier(Edge()); }
3.247 +
3.248 + template <typename _Value>
3.249 + class NodeMap : public Graph::template NodeMap<_Value> {
3.250 + public:
3.251 + typedef typename Graph::template NodeMap<_Value> Parent;
3.252 + explicit NodeMap(const GraphAdaptorBase<Graph>& adapter)
3.253 + : Parent(*adapter._graph) {}
3.254 + NodeMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
3.255 + : Parent(*adapter._graph, value) {}
3.256 +
3.257 + private:
3.258 + NodeMap& operator=(const NodeMap& cmap) {
3.259 + return operator=<NodeMap>(cmap);
3.260 + }
3.261 +
3.262 + template <typename CMap>
3.263 + NodeMap& operator=(const CMap& cmap) {
3.264 + Parent::operator=(cmap);
3.265 + return *this;
3.266 + }
3.267 +
3.268 + };
3.269 +
3.270 + template <typename _Value>
3.271 + class ArcMap : public Graph::template ArcMap<_Value> {
3.272 + public:
3.273 + typedef typename Graph::template ArcMap<_Value> Parent;
3.274 + explicit ArcMap(const GraphAdaptorBase<Graph>& adapter)
3.275 + : Parent(*adapter._graph) {}
3.276 + ArcMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
3.277 + : Parent(*adapter._graph, value) {}
3.278 +
3.279 + private:
3.280 + ArcMap& operator=(const ArcMap& cmap) {
3.281 + return operator=<ArcMap>(cmap);
3.282 + }
3.283 +
3.284 + template <typename CMap>
3.285 + ArcMap& operator=(const CMap& cmap) {
3.286 + Parent::operator=(cmap);
3.287 + return *this;
3.288 + }
3.289 + };
3.290 +
3.291 + template <typename _Value>
3.292 + class EdgeMap : public Graph::template EdgeMap<_Value> {
3.293 + public:
3.294 + typedef typename Graph::template EdgeMap<_Value> Parent;
3.295 + explicit EdgeMap(const GraphAdaptorBase<Graph>& adapter)
3.296 + : Parent(*adapter._graph) {}
3.297 + EdgeMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
3.298 + : Parent(*adapter._graph, value) {}
3.299 +
3.300 + private:
3.301 + EdgeMap& operator=(const EdgeMap& cmap) {
3.302 + return operator=<EdgeMap>(cmap);
3.303 + }
3.304 +
3.305 + template <typename CMap>
3.306 + EdgeMap& operator=(const CMap& cmap) {
3.307 + Parent::operator=(cmap);
3.308 + return *this;
3.309 + }
3.310 + };
3.311 +
3.312 + };
3.313 +
3.314 + template <typename _Digraph>
3.315 + class ReverseDigraphBase : public DigraphAdaptorBase<_Digraph> {
3.316 + public:
3.317 + typedef _Digraph Digraph;
3.318 + typedef DigraphAdaptorBase<_Digraph> Parent;
3.319 + protected:
3.320 + ReverseDigraphBase() : Parent() { }
3.321 + public:
3.322 + typedef typename Parent::Node Node;
3.323 + typedef typename Parent::Arc Arc;
3.324 +
3.325 + void firstIn(Arc& a, const Node& n) const { Parent::firstOut(a, n); }
3.326 + void firstOut(Arc& a, const Node& n ) const { Parent::firstIn(a, n); }
3.327 +
3.328 + void nextIn(Arc& a) const { Parent::nextOut(a); }
3.329 + void nextOut(Arc& a) const { Parent::nextIn(a); }
3.330 +
3.331 + Node source(const Arc& a) const { return Parent::target(a); }
3.332 + Node target(const Arc& a) const { return Parent::source(a); }
3.333 +
3.334 + Arc addArc(const Node& u, const Node& v) { return Parent::addArc(v, u); }
3.335 +
3.336 + typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
3.337 + Arc findArc(const Node& u, const Node& v,
3.338 + const Arc& prev = INVALID) {
3.339 + return Parent::findArc(v, u, prev);
3.340 + }
3.341 +
3.342 + };
3.343 +
3.344 + /// \ingroup graph_adaptors
3.345 + ///
3.346 + /// \brief A digraph adaptor which reverses the orientation of the arcs.
3.347 + ///
3.348 + /// ReverseDigraph reverses the arcs in the adapted digraph. The
3.349 + /// SubDigraph is conform to the \ref concepts::Digraph
3.350 + /// "Digraph concept".
3.351 + ///
3.352 + /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
3.353 + /// "Digraph concept". The type can be specified to be const.
3.354 + template<typename _Digraph>
3.355 + class ReverseDigraph :
3.356 + public DigraphAdaptorExtender<ReverseDigraphBase<_Digraph> > {
3.357 + public:
3.358 + typedef _Digraph Digraph;
3.359 + typedef DigraphAdaptorExtender<
3.360 + ReverseDigraphBase<_Digraph> > Parent;
3.361 + protected:
3.362 + ReverseDigraph() { }
3.363 + public:
3.364 +
3.365 + /// \brief Constructor
3.366 + ///
3.367 + /// Creates a reverse digraph adaptor for the given digraph
3.368 + explicit ReverseDigraph(Digraph& digraph) {
3.369 + Parent::setDigraph(digraph);
3.370 + }
3.371 + };
3.372 +
3.373 + /// \brief Just gives back a reverse digraph adaptor
3.374 + ///
3.375 + /// Just gives back a reverse digraph adaptor
3.376 + template<typename Digraph>
3.377 + ReverseDigraph<const Digraph> reverseDigraph(const Digraph& digraph) {
3.378 + return ReverseDigraph<const Digraph>(digraph);
3.379 + }
3.380 +
3.381 + template <typename _Digraph, typename _NodeFilterMap,
3.382 + typename _ArcFilterMap, bool _checked = true>
3.383 + class SubDigraphBase : public DigraphAdaptorBase<_Digraph> {
3.384 + public:
3.385 + typedef _Digraph Digraph;
3.386 + typedef _NodeFilterMap NodeFilterMap;
3.387 + typedef _ArcFilterMap ArcFilterMap;
3.388 +
3.389 + typedef SubDigraphBase Adaptor;
3.390 + typedef DigraphAdaptorBase<_Digraph> Parent;
3.391 + protected:
3.392 + NodeFilterMap* _node_filter;
3.393 + ArcFilterMap* _arc_filter;
3.394 + SubDigraphBase()
3.395 + : Parent(), _node_filter(0), _arc_filter(0) { }
3.396 +
3.397 + void setNodeFilterMap(NodeFilterMap& node_filter) {
3.398 + _node_filter = &node_filter;
3.399 + }
3.400 + void setArcFilterMap(ArcFilterMap& arc_filter) {
3.401 + _arc_filter = &arc_filter;
3.402 + }
3.403 +
3.404 + public:
3.405 +
3.406 + typedef typename Parent::Node Node;
3.407 + typedef typename Parent::Arc Arc;
3.408 +
3.409 + void first(Node& i) const {
3.410 + Parent::first(i);
3.411 + while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
3.412 + }
3.413 +
3.414 + void first(Arc& i) const {
3.415 + Parent::first(i);
3.416 + while (i != INVALID && (!(*_arc_filter)[i]
3.417 + || !(*_node_filter)[Parent::source(i)]
3.418 + || !(*_node_filter)[Parent::target(i)]))
3.419 + Parent::next(i);
3.420 + }
3.421 +
3.422 + void firstIn(Arc& i, const Node& n) const {
3.423 + Parent::firstIn(i, n);
3.424 + while (i != INVALID && (!(*_arc_filter)[i]
3.425 + || !(*_node_filter)[Parent::source(i)]))
3.426 + Parent::nextIn(i);
3.427 + }
3.428 +
3.429 + void firstOut(Arc& i, const Node& n) const {
3.430 + Parent::firstOut(i, n);
3.431 + while (i != INVALID && (!(*_arc_filter)[i]
3.432 + || !(*_node_filter)[Parent::target(i)]))
3.433 + Parent::nextOut(i);
3.434 + }
3.435 +
3.436 + void next(Node& i) const {
3.437 + Parent::next(i);
3.438 + while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
3.439 + }
3.440 +
3.441 + void next(Arc& i) const {
3.442 + Parent::next(i);
3.443 + while (i != INVALID && (!(*_arc_filter)[i]
3.444 + || !(*_node_filter)[Parent::source(i)]
3.445 + || !(*_node_filter)[Parent::target(i)]))
3.446 + Parent::next(i);
3.447 + }
3.448 +
3.449 + void nextIn(Arc& i) const {
3.450 + Parent::nextIn(i);
3.451 + while (i != INVALID && (!(*_arc_filter)[i]
3.452 + || !(*_node_filter)[Parent::source(i)]))
3.453 + Parent::nextIn(i);
3.454 + }
3.455 +
3.456 + void nextOut(Arc& i) const {
3.457 + Parent::nextOut(i);
3.458 + while (i != INVALID && (!(*_arc_filter)[i]
3.459 + || !(*_node_filter)[Parent::target(i)]))
3.460 + Parent::nextOut(i);
3.461 + }
3.462 +
3.463 + void hide(const Node& n) const { _node_filter->set(n, false); }
3.464 + void hide(const Arc& a) const { _arc_filter->set(a, false); }
3.465 +
3.466 + void unHide(const Node& n) const { _node_filter->set(n, true); }
3.467 + void unHide(const Arc& a) const { _arc_filter->set(a, true); }
3.468 +
3.469 + bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
3.470 + bool hidden(const Arc& a) const { return !(*_arc_filter)[a]; }
3.471 +
3.472 + typedef False NodeNumTag;
3.473 + typedef False EdgeNumTag;
3.474 +
3.475 + typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
3.476 + Arc findArc(const Node& source, const Node& target,
3.477 + const Arc& prev = INVALID) {
3.478 + if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
3.479 + return INVALID;
3.480 + }
3.481 + Arc arc = Parent::findArc(source, target, prev);
3.482 + while (arc != INVALID && !(*_arc_filter)[arc]) {
3.483 + arc = Parent::findArc(source, target, arc);
3.484 + }
3.485 + return arc;
3.486 + }
3.487 +
3.488 + template <typename _Value>
3.489 + class NodeMap : public SubMapExtender<Adaptor,
3.490 + typename Parent::template NodeMap<_Value> > {
3.491 + public:
3.492 + typedef _Value Value;
3.493 + typedef SubMapExtender<Adaptor, typename Parent::
3.494 + template NodeMap<Value> > MapParent;
3.495 +
3.496 + NodeMap(const Adaptor& adaptor)
3.497 + : MapParent(adaptor) {}
3.498 + NodeMap(const Adaptor& adaptor, const Value& value)
3.499 + : MapParent(adaptor, value) {}
3.500 +
3.501 + private:
3.502 + NodeMap& operator=(const NodeMap& cmap) {
3.503 + return operator=<NodeMap>(cmap);
3.504 + }
3.505 +
3.506 + template <typename CMap>
3.507 + NodeMap& operator=(const CMap& cmap) {
3.508 + MapParent::operator=(cmap);
3.509 + return *this;
3.510 + }
3.511 + };
3.512 +
3.513 + template <typename _Value>
3.514 + class ArcMap : public SubMapExtender<Adaptor,
3.515 + typename Parent::template ArcMap<_Value> > {
3.516 + public:
3.517 + typedef _Value Value;
3.518 + typedef SubMapExtender<Adaptor, typename Parent::
3.519 + template ArcMap<Value> > MapParent;
3.520 +
3.521 + ArcMap(const Adaptor& adaptor)
3.522 + : MapParent(adaptor) {}
3.523 + ArcMap(const Adaptor& adaptor, const Value& value)
3.524 + : MapParent(adaptor, value) {}
3.525 +
3.526 + private:
3.527 + ArcMap& operator=(const ArcMap& cmap) {
3.528 + return operator=<ArcMap>(cmap);
3.529 + }
3.530 +
3.531 + template <typename CMap>
3.532 + ArcMap& operator=(const CMap& cmap) {
3.533 + MapParent::operator=(cmap);
3.534 + return *this;
3.535 + }
3.536 + };
3.537 +
3.538 + };
3.539 +
3.540 + template <typename _Digraph, typename _NodeFilterMap, typename _ArcFilterMap>
3.541 + class SubDigraphBase<_Digraph, _NodeFilterMap, _ArcFilterMap, false>
3.542 + : public DigraphAdaptorBase<_Digraph> {
3.543 + public:
3.544 + typedef _Digraph Digraph;
3.545 + typedef _NodeFilterMap NodeFilterMap;
3.546 + typedef _ArcFilterMap ArcFilterMap;
3.547 +
3.548 + typedef SubDigraphBase Adaptor;
3.549 + typedef DigraphAdaptorBase<Digraph> Parent;
3.550 + protected:
3.551 + NodeFilterMap* _node_filter;
3.552 + ArcFilterMap* _arc_filter;
3.553 + SubDigraphBase()
3.554 + : Parent(), _node_filter(0), _arc_filter(0) { }
3.555 +
3.556 + void setNodeFilterMap(NodeFilterMap& node_filter) {
3.557 + _node_filter = &node_filter;
3.558 + }
3.559 + void setArcFilterMap(ArcFilterMap& arc_filter) {
3.560 + _arc_filter = &arc_filter;
3.561 + }
3.562 +
3.563 + public:
3.564 +
3.565 + typedef typename Parent::Node Node;
3.566 + typedef typename Parent::Arc Arc;
3.567 +
3.568 + void first(Node& i) const {
3.569 + Parent::first(i);
3.570 + while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
3.571 + }
3.572 +
3.573 + void first(Arc& i) const {
3.574 + Parent::first(i);
3.575 + while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
3.576 + }
3.577 +
3.578 + void firstIn(Arc& i, const Node& n) const {
3.579 + Parent::firstIn(i, n);
3.580 + while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
3.581 + }
3.582 +
3.583 + void firstOut(Arc& i, const Node& n) const {
3.584 + Parent::firstOut(i, n);
3.585 + while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
3.586 + }
3.587 +
3.588 + void next(Node& i) const {
3.589 + Parent::next(i);
3.590 + while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
3.591 + }
3.592 + void next(Arc& i) const {
3.593 + Parent::next(i);
3.594 + while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
3.595 + }
3.596 + void nextIn(Arc& i) const {
3.597 + Parent::nextIn(i);
3.598 + while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
3.599 + }
3.600 +
3.601 + void nextOut(Arc& i) const {
3.602 + Parent::nextOut(i);
3.603 + while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
3.604 + }
3.605 +
3.606 + void hide(const Node& n) const { _node_filter->set(n, false); }
3.607 + void hide(const Arc& e) const { _arc_filter->set(e, false); }
3.608 +
3.609 + void unHide(const Node& n) const { _node_filter->set(n, true); }
3.610 + void unHide(const Arc& e) const { _arc_filter->set(e, true); }
3.611 +
3.612 + bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
3.613 + bool hidden(const Arc& e) const { return !(*_arc_filter)[e]; }
3.614 +
3.615 + typedef False NodeNumTag;
3.616 + typedef False EdgeNumTag;
3.617 +
3.618 + typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
3.619 + Arc findArc(const Node& source, const Node& target,
3.620 + const Arc& prev = INVALID) {
3.621 + if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
3.622 + return INVALID;
3.623 + }
3.624 + Arc arc = Parent::findArc(source, target, prev);
3.625 + while (arc != INVALID && !(*_arc_filter)[arc]) {
3.626 + arc = Parent::findArc(source, target, arc);
3.627 + }
3.628 + return arc;
3.629 + }
3.630 +
3.631 + template <typename _Value>
3.632 + class NodeMap : public SubMapExtender<Adaptor,
3.633 + typename Parent::template NodeMap<_Value> > {
3.634 + public:
3.635 + typedef _Value Value;
3.636 + typedef SubMapExtender<Adaptor, typename Parent::
3.637 + template NodeMap<Value> > MapParent;
3.638 +
3.639 + NodeMap(const Adaptor& adaptor)
3.640 + : MapParent(adaptor) {}
3.641 + NodeMap(const Adaptor& adaptor, const Value& value)
3.642 + : MapParent(adaptor, value) {}
3.643 +
3.644 + private:
3.645 + NodeMap& operator=(const NodeMap& cmap) {
3.646 + return operator=<NodeMap>(cmap);
3.647 + }
3.648 +
3.649 + template <typename CMap>
3.650 + NodeMap& operator=(const CMap& cmap) {
3.651 + MapParent::operator=(cmap);
3.652 + return *this;
3.653 + }
3.654 + };
3.655 +
3.656 + template <typename _Value>
3.657 + class ArcMap : public SubMapExtender<Adaptor,
3.658 + typename Parent::template ArcMap<_Value> > {
3.659 + public:
3.660 + typedef _Value Value;
3.661 + typedef SubMapExtender<Adaptor, typename Parent::
3.662 + template ArcMap<Value> > MapParent;
3.663 +
3.664 + ArcMap(const Adaptor& adaptor)
3.665 + : MapParent(adaptor) {}
3.666 + ArcMap(const Adaptor& adaptor, const Value& value)
3.667 + : MapParent(adaptor, value) {}
3.668 +
3.669 + private:
3.670 + ArcMap& operator=(const ArcMap& cmap) {
3.671 + return operator=<ArcMap>(cmap);
3.672 + }
3.673 +
3.674 + template <typename CMap>
3.675 + ArcMap& operator=(const CMap& cmap) {
3.676 + MapParent::operator=(cmap);
3.677 + return *this;
3.678 + }
3.679 + };
3.680 +
3.681 + };
3.682 +
3.683 + /// \ingroup graph_adaptors
3.684 + ///
3.685 + /// \brief An adaptor for hiding nodes and arcs in a digraph
3.686 + ///
3.687 + /// SubDigraph hides nodes and arcs in a digraph. A bool node map
3.688 + /// and a bool arc map must be specified, which define the filters
3.689 + /// for nodes and arcs. Just the nodes and arcs with true value are
3.690 + /// shown in the subdigraph. The SubDigraph is conform to the \ref
3.691 + /// concepts::Digraph "Digraph concept". If the \c _checked parameter
3.692 + /// is true, then the arcs incident to filtered nodes are also
3.693 + /// filtered out.
3.694 + ///
3.695 + /// \tparam _Digraph It must be conform to the \ref
3.696 + /// concepts::Digraph "Digraph concept". The type can be specified
3.697 + /// to const.
3.698 + /// \tparam _NodeFilterMap A bool valued node map of the the adapted digraph.
3.699 + /// \tparam _ArcFilterMap A bool valued arc map of the the adapted digraph.
3.700 + /// \tparam _checked If the parameter is false then the arc filtering
3.701 + /// is not checked with respect to node filter. Otherwise, each arc
3.702 + /// is automatically filtered, which is incident to a filtered node.
3.703 + ///
3.704 + /// \see FilterNodes
3.705 + /// \see FilterArcs
3.706 + template<typename _Digraph,
3.707 + typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
3.708 + typename _ArcFilterMap = typename _Digraph::template ArcMap<bool>,
3.709 + bool _checked = true>
3.710 + class SubDigraph
3.711 + : public DigraphAdaptorExtender<
3.712 + SubDigraphBase<_Digraph, _NodeFilterMap, _ArcFilterMap, _checked> > {
3.713 + public:
3.714 + typedef _Digraph Digraph;
3.715 + typedef _NodeFilterMap NodeFilterMap;
3.716 + typedef _ArcFilterMap ArcFilterMap;
3.717 +
3.718 + typedef DigraphAdaptorExtender<
3.719 + SubDigraphBase<Digraph, NodeFilterMap, ArcFilterMap, _checked> >
3.720 + Parent;
3.721 +
3.722 + typedef typename Parent::Node Node;
3.723 + typedef typename Parent::Arc Arc;
3.724 +
3.725 + protected:
3.726 + SubDigraph() { }
3.727 + public:
3.728 +
3.729 + /// \brief Constructor
3.730 + ///
3.731 + /// Creates a subdigraph for the given digraph with
3.732 + /// given node and arc map filters.
3.733 + SubDigraph(Digraph& digraph, NodeFilterMap& node_filter,
3.734 + ArcFilterMap& arc_filter) {
3.735 + setDigraph(digraph);
3.736 + setNodeFilterMap(node_filter);
3.737 + setArcFilterMap(arc_filter);
3.738 + }
3.739 +
3.740 + /// \brief Hides the node of the graph
3.741 + ///
3.742 + /// This function hides \c n in the digraph, i.e. the iteration
3.743 + /// jumps over it. This is done by simply setting the value of \c n
3.744 + /// to be false in the corresponding node-map.
3.745 + void hide(const Node& n) const { Parent::hide(n); }
3.746 +
3.747 + /// \brief Hides the arc of the graph
3.748 + ///
3.749 + /// This function hides \c a in the digraph, i.e. the iteration
3.750 + /// jumps over it. This is done by simply setting the value of \c a
3.751 + /// to be false in the corresponding arc-map.
3.752 + void hide(const Arc& a) const { Parent::hide(a); }
3.753 +
3.754 + /// \brief Unhides the node of the graph
3.755 + ///
3.756 + /// The value of \c n is set to be true in the node-map which stores
3.757 + /// hide information. If \c n was hidden previuosly, then it is shown
3.758 + /// again
3.759 + void unHide(const Node& n) const { Parent::unHide(n); }
3.760 +
3.761 + /// \brief Unhides the arc of the graph
3.762 + ///
3.763 + /// The value of \c a is set to be true in the arc-map which stores
3.764 + /// hide information. If \c a was hidden previuosly, then it is shown
3.765 + /// again
3.766 + void unHide(const Arc& a) const { Parent::unHide(a); }
3.767 +
3.768 + /// \brief Returns true if \c n is hidden.
3.769 + ///
3.770 + /// Returns true if \c n is hidden.
3.771 + ///
3.772 + bool hidden(const Node& n) const { return Parent::hidden(n); }
3.773 +
3.774 + /// \brief Returns true if \c a is hidden.
3.775 + ///
3.776 + /// Returns true if \c a is hidden.
3.777 + ///
3.778 + bool hidden(const Arc& a) const { return Parent::hidden(a); }
3.779 +
3.780 + };
3.781 +
3.782 + /// \brief Just gives back a subdigraph
3.783 + ///
3.784 + /// Just gives back a subdigraph
3.785 + template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
3.786 + SubDigraph<const Digraph, NodeFilterMap, ArcFilterMap>
3.787 + subDigraph(const Digraph& digraph, NodeFilterMap& nfm, ArcFilterMap& afm) {
3.788 + return SubDigraph<const Digraph, NodeFilterMap, ArcFilterMap>
3.789 + (digraph, nfm, afm);
3.790 + }
3.791 +
3.792 + template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
3.793 + SubDigraph<const Digraph, const NodeFilterMap, ArcFilterMap>
3.794 + subDigraph(const Digraph& digraph,
3.795 + const NodeFilterMap& nfm, ArcFilterMap& afm) {
3.796 + return SubDigraph<const Digraph, const NodeFilterMap, ArcFilterMap>
3.797 + (digraph, nfm, afm);
3.798 + }
3.799 +
3.800 + template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
3.801 + SubDigraph<const Digraph, NodeFilterMap, const ArcFilterMap>
3.802 + subDigraph(const Digraph& digraph,
3.803 + NodeFilterMap& nfm, const ArcFilterMap& afm) {
3.804 + return SubDigraph<const Digraph, NodeFilterMap, const ArcFilterMap>
3.805 + (digraph, nfm, afm);
3.806 + }
3.807 +
3.808 + template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
3.809 + SubDigraph<const Digraph, const NodeFilterMap, const ArcFilterMap>
3.810 + subDigraph(const Digraph& digraph,
3.811 + const NodeFilterMap& nfm, const ArcFilterMap& afm) {
3.812 + return SubDigraph<const Digraph, const NodeFilterMap,
3.813 + const ArcFilterMap>(digraph, nfm, afm);
3.814 + }
3.815 +
3.816 +
3.817 + template <typename _Graph, typename NodeFilterMap,
3.818 + typename EdgeFilterMap, bool _checked = true>
3.819 + class SubGraphBase : public GraphAdaptorBase<_Graph> {
3.820 + public:
3.821 + typedef _Graph Graph;
3.822 + typedef SubGraphBase Adaptor;
3.823 + typedef GraphAdaptorBase<_Graph> Parent;
3.824 + protected:
3.825 +
3.826 + NodeFilterMap* _node_filter_map;
3.827 + EdgeFilterMap* _edge_filter_map;
3.828 +
3.829 + SubGraphBase()
3.830 + : Parent(), _node_filter_map(0), _edge_filter_map(0) { }
3.831 +
3.832 + void setNodeFilterMap(NodeFilterMap& node_filter_map) {
3.833 + _node_filter_map=&node_filter_map;
3.834 + }
3.835 + void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
3.836 + _edge_filter_map=&edge_filter_map;
3.837 + }
3.838 +
3.839 + public:
3.840 +
3.841 + typedef typename Parent::Node Node;
3.842 + typedef typename Parent::Arc Arc;
3.843 + typedef typename Parent::Edge Edge;
3.844 +
3.845 + void first(Node& i) const {
3.846 + Parent::first(i);
3.847 + while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
3.848 + }
3.849 +
3.850 + void first(Arc& i) const {
3.851 + Parent::first(i);
3.852 + while (i!=INVALID && (!(*_edge_filter_map)[i]
3.853 + || !(*_node_filter_map)[Parent::source(i)]
3.854 + || !(*_node_filter_map)[Parent::target(i)]))
3.855 + Parent::next(i);
3.856 + }
3.857 +
3.858 + void first(Edge& i) const {
3.859 + Parent::first(i);
3.860 + while (i!=INVALID && (!(*_edge_filter_map)[i]
3.861 + || !(*_node_filter_map)[Parent::u(i)]
3.862 + || !(*_node_filter_map)[Parent::v(i)]))
3.863 + Parent::next(i);
3.864 + }
3.865 +
3.866 + void firstIn(Arc& i, const Node& n) const {
3.867 + Parent::firstIn(i, n);
3.868 + while (i!=INVALID && (!(*_edge_filter_map)[i]
3.869 + || !(*_node_filter_map)[Parent::source(i)]))
3.870 + Parent::nextIn(i);
3.871 + }
3.872 +
3.873 + void firstOut(Arc& i, const Node& n) const {
3.874 + Parent::firstOut(i, n);
3.875 + while (i!=INVALID && (!(*_edge_filter_map)[i]
3.876 + || !(*_node_filter_map)[Parent::target(i)]))
3.877 + Parent::nextOut(i);
3.878 + }
3.879 +
3.880 + void firstInc(Edge& i, bool& d, const Node& n) const {
3.881 + Parent::firstInc(i, d, n);
3.882 + while (i!=INVALID && (!(*_edge_filter_map)[i]
3.883 + || !(*_node_filter_map)[Parent::u(i)]
3.884 + || !(*_node_filter_map)[Parent::v(i)]))
3.885 + Parent::nextInc(i, d);
3.886 + }
3.887 +
3.888 + void next(Node& i) const {
3.889 + Parent::next(i);
3.890 + while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
3.891 + }
3.892 +
3.893 + void next(Arc& i) const {
3.894 + Parent::next(i);
3.895 + while (i!=INVALID && (!(*_edge_filter_map)[i]
3.896 + || !(*_node_filter_map)[Parent::source(i)]
3.897 + || !(*_node_filter_map)[Parent::target(i)]))
3.898 + Parent::next(i);
3.899 + }
3.900 +
3.901 + void next(Edge& i) const {
3.902 + Parent::next(i);
3.903 + while (i!=INVALID && (!(*_edge_filter_map)[i]
3.904 + || !(*_node_filter_map)[Parent::u(i)]
3.905 + || !(*_node_filter_map)[Parent::v(i)]))
3.906 + Parent::next(i);
3.907 + }
3.908 +
3.909 + void nextIn(Arc& i) const {
3.910 + Parent::nextIn(i);
3.911 + while (i!=INVALID && (!(*_edge_filter_map)[i]
3.912 + || !(*_node_filter_map)[Parent::source(i)]))
3.913 + Parent::nextIn(i);
3.914 + }
3.915 +
3.916 + void nextOut(Arc& i) const {
3.917 + Parent::nextOut(i);
3.918 + while (i!=INVALID && (!(*_edge_filter_map)[i]
3.919 + || !(*_node_filter_map)[Parent::target(i)]))
3.920 + Parent::nextOut(i);
3.921 + }
3.922 +
3.923 + void nextInc(Edge& i, bool& d) const {
3.924 + Parent::nextInc(i, d);
3.925 + while (i!=INVALID && (!(*_edge_filter_map)[i]
3.926 + || !(*_node_filter_map)[Parent::u(i)]
3.927 + || !(*_node_filter_map)[Parent::v(i)]))
3.928 + Parent::nextInc(i, d);
3.929 + }
3.930 +
3.931 + void hide(const Node& n) const { _node_filter_map->set(n, false); }
3.932 + void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
3.933 +
3.934 + void unHide(const Node& n) const { _node_filter_map->set(n, true); }
3.935 + void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
3.936 +
3.937 + bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; }
3.938 + bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
3.939 +
3.940 + typedef False NodeNumTag;
3.941 + typedef False EdgeNumTag;
3.942 +
3.943 + typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
3.944 + Arc findArc(const Node& u, const Node& v,
3.945 + const Arc& prev = INVALID) {
3.946 + if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
3.947 + return INVALID;
3.948 + }
3.949 + Arc arc = Parent::findArc(u, v, prev);
3.950 + while (arc != INVALID && !(*_edge_filter_map)[arc]) {
3.951 + arc = Parent::findArc(u, v, arc);
3.952 + }
3.953 + return arc;
3.954 + }
3.955 + Edge findEdge(const Node& u, const Node& v,
3.956 + const Edge& prev = INVALID) {
3.957 + if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
3.958 + return INVALID;
3.959 + }
3.960 + Edge edge = Parent::findEdge(u, v, prev);
3.961 + while (edge != INVALID && !(*_edge_filter_map)[edge]) {
3.962 + edge = Parent::findEdge(u, v, edge);
3.963 + }
3.964 + return edge;
3.965 + }
3.966 +
3.967 + template <typename _Value>
3.968 + class NodeMap : public SubMapExtender<Adaptor,
3.969 + typename Parent::template NodeMap<_Value> > {
3.970 + public:
3.971 + typedef _Value Value;
3.972 + typedef SubMapExtender<Adaptor, typename Parent::
3.973 + template NodeMap<Value> > MapParent;
3.974 +
3.975 + NodeMap(const Adaptor& adaptor)
3.976 + : MapParent(adaptor) {}
3.977 + NodeMap(const Adaptor& adaptor, const Value& value)
3.978 + : MapParent(adaptor, value) {}
3.979 +
3.980 + private:
3.981 + NodeMap& operator=(const NodeMap& cmap) {
3.982 + return operator=<NodeMap>(cmap);
3.983 + }
3.984 +
3.985 + template <typename CMap>
3.986 + NodeMap& operator=(const CMap& cmap) {
3.987 + MapParent::operator=(cmap);
3.988 + return *this;
3.989 + }
3.990 + };
3.991 +
3.992 + template <typename _Value>
3.993 + class ArcMap : public SubMapExtender<Adaptor,
3.994 + typename Parent::template ArcMap<_Value> > {
3.995 + public:
3.996 + typedef _Value Value;
3.997 + typedef SubMapExtender<Adaptor, typename Parent::
3.998 + template ArcMap<Value> > MapParent;
3.999 +
3.1000 + ArcMap(const Adaptor& adaptor)
3.1001 + : MapParent(adaptor) {}
3.1002 + ArcMap(const Adaptor& adaptor, const Value& value)
3.1003 + : MapParent(adaptor, value) {}
3.1004 +
3.1005 + private:
3.1006 + ArcMap& operator=(const ArcMap& cmap) {
3.1007 + return operator=<ArcMap>(cmap);
3.1008 + }
3.1009 +
3.1010 + template <typename CMap>
3.1011 + ArcMap& operator=(const CMap& cmap) {
3.1012 + MapParent::operator=(cmap);
3.1013 + return *this;
3.1014 + }
3.1015 + };
3.1016 +
3.1017 + template <typename _Value>
3.1018 + class EdgeMap : public SubMapExtender<Adaptor,
3.1019 + typename Parent::template EdgeMap<_Value> > {
3.1020 + public:
3.1021 + typedef _Value Value;
3.1022 + typedef SubMapExtender<Adaptor, typename Parent::
3.1023 + template EdgeMap<Value> > MapParent;
3.1024 +
3.1025 + EdgeMap(const Adaptor& adaptor)
3.1026 + : MapParent(adaptor) {}
3.1027 +
3.1028 + EdgeMap(const Adaptor& adaptor, const Value& value)
3.1029 + : MapParent(adaptor, value) {}
3.1030 +
3.1031 + private:
3.1032 + EdgeMap& operator=(const EdgeMap& cmap) {
3.1033 + return operator=<EdgeMap>(cmap);
3.1034 + }
3.1035 +
3.1036 + template <typename CMap>
3.1037 + EdgeMap& operator=(const CMap& cmap) {
3.1038 + MapParent::operator=(cmap);
3.1039 + return *this;
3.1040 + }
3.1041 + };
3.1042 +
3.1043 + };
3.1044 +
3.1045 + template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
3.1046 + class SubGraphBase<_Graph, NodeFilterMap, EdgeFilterMap, false>
3.1047 + : public GraphAdaptorBase<_Graph> {
3.1048 + public:
3.1049 + typedef _Graph Graph;
3.1050 + typedef SubGraphBase Adaptor;
3.1051 + typedef GraphAdaptorBase<_Graph> Parent;
3.1052 + protected:
3.1053 + NodeFilterMap* _node_filter_map;
3.1054 + EdgeFilterMap* _edge_filter_map;
3.1055 + SubGraphBase() : Parent(),
3.1056 + _node_filter_map(0), _edge_filter_map(0) { }
3.1057 +
3.1058 + void setNodeFilterMap(NodeFilterMap& node_filter_map) {
3.1059 + _node_filter_map=&node_filter_map;
3.1060 + }
3.1061 + void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
3.1062 + _edge_filter_map=&edge_filter_map;
3.1063 + }
3.1064 +
3.1065 + public:
3.1066 +
3.1067 + typedef typename Parent::Node Node;
3.1068 + typedef typename Parent::Arc Arc;
3.1069 + typedef typename Parent::Edge Edge;
3.1070 +
3.1071 + void first(Node& i) const {
3.1072 + Parent::first(i);
3.1073 + while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
3.1074 + }
3.1075 +
3.1076 + void first(Arc& i) const {
3.1077 + Parent::first(i);
3.1078 + while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
3.1079 + }
3.1080 +
3.1081 + void first(Edge& i) const {
3.1082 + Parent::first(i);
3.1083 + while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
3.1084 + }
3.1085 +
3.1086 + void firstIn(Arc& i, const Node& n) const {
3.1087 + Parent::firstIn(i, n);
3.1088 + while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i);
3.1089 + }
3.1090 +
3.1091 + void firstOut(Arc& i, const Node& n) const {
3.1092 + Parent::firstOut(i, n);
3.1093 + while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i);
3.1094 + }
3.1095 +
3.1096 + void firstInc(Edge& i, bool& d, const Node& n) const {
3.1097 + Parent::firstInc(i, d, n);
3.1098 + while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d);
3.1099 + }
3.1100 +
3.1101 + void next(Node& i) const {
3.1102 + Parent::next(i);
3.1103 + while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
3.1104 + }
3.1105 + void next(Arc& i) const {
3.1106 + Parent::next(i);
3.1107 + while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
3.1108 + }
3.1109 + void next(Edge& i) const {
3.1110 + Parent::next(i);
3.1111 + while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
3.1112 + }
3.1113 + void nextIn(Arc& i) const {
3.1114 + Parent::nextIn(i);
3.1115 + while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i);
3.1116 + }
3.1117 +
3.1118 + void nextOut(Arc& i) const {
3.1119 + Parent::nextOut(i);
3.1120 + while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i);
3.1121 + }
3.1122 + void nextInc(Edge& i, bool& d) const {
3.1123 + Parent::nextInc(i, d);
3.1124 + while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d);
3.1125 + }
3.1126 +
3.1127 + void hide(const Node& n) const { _node_filter_map->set(n, false); }
3.1128 + void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
3.1129 +
3.1130 + void unHide(const Node& n) const { _node_filter_map->set(n, true); }
3.1131 + void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
3.1132 +
3.1133 + bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; }
3.1134 + bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
3.1135 +
3.1136 + typedef False NodeNumTag;
3.1137 + typedef False EdgeNumTag;
3.1138 +
3.1139 + typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
3.1140 + Arc findArc(const Node& u, const Node& v,
3.1141 + const Arc& prev = INVALID) {
3.1142 + Arc arc = Parent::findArc(u, v, prev);
3.1143 + while (arc != INVALID && !(*_edge_filter_map)[arc]) {
3.1144 + arc = Parent::findArc(u, v, arc);
3.1145 + }
3.1146 + return arc;
3.1147 + }
3.1148 + Edge findEdge(const Node& u, const Node& v,
3.1149 + const Edge& prev = INVALID) {
3.1150 + Edge edge = Parent::findEdge(u, v, prev);
3.1151 + while (edge != INVALID && !(*_edge_filter_map)[edge]) {
3.1152 + edge = Parent::findEdge(u, v, edge);
3.1153 + }
3.1154 + return edge;
3.1155 + }
3.1156 +
3.1157 + template <typename _Value>
3.1158 + class NodeMap : public SubMapExtender<Adaptor,
3.1159 + typename Parent::template NodeMap<_Value> > {
3.1160 + public:
3.1161 + typedef _Value Value;
3.1162 + typedef SubMapExtender<Adaptor, typename Parent::
3.1163 + template NodeMap<Value> > MapParent;
3.1164 +
3.1165 + NodeMap(const Adaptor& adaptor)
3.1166 + : MapParent(adaptor) {}
3.1167 + NodeMap(const Adaptor& adaptor, const Value& value)
3.1168 + : MapParent(adaptor, value) {}
3.1169 +
3.1170 + private:
3.1171 + NodeMap& operator=(const NodeMap& cmap) {
3.1172 + return operator=<NodeMap>(cmap);
3.1173 + }
3.1174 +
3.1175 + template <typename CMap>
3.1176 + NodeMap& operator=(const CMap& cmap) {
3.1177 + MapParent::operator=(cmap);
3.1178 + return *this;
3.1179 + }
3.1180 + };
3.1181 +
3.1182 + template <typename _Value>
3.1183 + class ArcMap : public SubMapExtender<Adaptor,
3.1184 + typename Parent::template ArcMap<_Value> > {
3.1185 + public:
3.1186 + typedef _Value Value;
3.1187 + typedef SubMapExtender<Adaptor, typename Parent::
3.1188 + template ArcMap<Value> > MapParent;
3.1189 +
3.1190 + ArcMap(const Adaptor& adaptor)
3.1191 + : MapParent(adaptor) {}
3.1192 + ArcMap(const Adaptor& adaptor, const Value& value)
3.1193 + : MapParent(adaptor, value) {}
3.1194 +
3.1195 + private:
3.1196 + ArcMap& operator=(const ArcMap& cmap) {
3.1197 + return operator=<ArcMap>(cmap);
3.1198 + }
3.1199 +
3.1200 + template <typename CMap>
3.1201 + ArcMap& operator=(const CMap& cmap) {
3.1202 + MapParent::operator=(cmap);
3.1203 + return *this;
3.1204 + }
3.1205 + };
3.1206 +
3.1207 + template <typename _Value>
3.1208 + class EdgeMap : public SubMapExtender<Adaptor,
3.1209 + typename Parent::template EdgeMap<_Value> > {
3.1210 + public:
3.1211 + typedef _Value Value;
3.1212 + typedef SubMapExtender<Adaptor, typename Parent::
3.1213 + template EdgeMap<Value> > MapParent;
3.1214 +
3.1215 + EdgeMap(const Adaptor& adaptor)
3.1216 + : MapParent(adaptor) {}
3.1217 +
3.1218 + EdgeMap(const Adaptor& adaptor, const _Value& value)
3.1219 + : MapParent(adaptor, value) {}
3.1220 +
3.1221 + private:
3.1222 + EdgeMap& operator=(const EdgeMap& cmap) {
3.1223 + return operator=<EdgeMap>(cmap);
3.1224 + }
3.1225 +
3.1226 + template <typename CMap>
3.1227 + EdgeMap& operator=(const CMap& cmap) {
3.1228 + MapParent::operator=(cmap);
3.1229 + return *this;
3.1230 + }
3.1231 + };
3.1232 +
3.1233 + };
3.1234 +
3.1235 + /// \ingroup graph_adaptors
3.1236 + ///
3.1237 + /// \brief A graph adaptor for hiding nodes and edges in an
3.1238 + /// undirected graph.
3.1239 + ///
3.1240 + /// SubGraph hides nodes and edges in a graph. A bool node map and a
3.1241 + /// bool edge map must be specified, which define the filters for
3.1242 + /// nodes and edges. Just the nodes and edges with true value are
3.1243 + /// shown in the subgraph. The SubGraph is conform to the \ref
3.1244 + /// concepts::Graph "Graph concept". If the \c _checked parameter is
3.1245 + /// true, then the edges incident to filtered nodes are also
3.1246 + /// filtered out.
3.1247 + ///
3.1248 + /// \tparam _Graph It must be conform to the \ref
3.1249 + /// concepts::Graph "Graph concept". The type can be specified
3.1250 + /// to const.
3.1251 + /// \tparam _NodeFilterMap A bool valued node map of the the adapted graph.
3.1252 + /// \tparam _EdgeFilterMap A bool valued edge map of the the adapted graph.
3.1253 + /// \tparam _checked If the parameter is false then the edge filtering
3.1254 + /// is not checked with respect to node filter. Otherwise, each edge
3.1255 + /// is automatically filtered, which is incident to a filtered node.
3.1256 + ///
3.1257 + /// \see FilterNodes
3.1258 + /// \see FilterEdges
3.1259 + template<typename _Graph, typename NodeFilterMap,
3.1260 + typename EdgeFilterMap, bool _checked = true>
3.1261 + class SubGraph
3.1262 + : public GraphAdaptorExtender<
3.1263 + SubGraphBase<_Graph, NodeFilterMap, EdgeFilterMap, _checked> > {
3.1264 + public:
3.1265 + typedef _Graph Graph;
3.1266 + typedef GraphAdaptorExtender<
3.1267 + SubGraphBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent;
3.1268 +
3.1269 + typedef typename Parent::Node Node;
3.1270 + typedef typename Parent::Edge Edge;
3.1271 +
3.1272 + protected:
3.1273 + SubGraph() { }
3.1274 + public:
3.1275 +
3.1276 + /// \brief Constructor
3.1277 + ///
3.1278 + /// Creates a subgraph for the given graph with given node and
3.1279 + /// edge map filters.
3.1280 + SubGraph(Graph& _graph, NodeFilterMap& node_filter_map,
3.1281 + EdgeFilterMap& edge_filter_map) {
3.1282 + setGraph(_graph);
3.1283 + setNodeFilterMap(node_filter_map);
3.1284 + setEdgeFilterMap(edge_filter_map);
3.1285 + }
3.1286 +
3.1287 + /// \brief Hides the node of the graph
3.1288 + ///
3.1289 + /// This function hides \c n in the graph, i.e. the iteration
3.1290 + /// jumps over it. This is done by simply setting the value of \c n
3.1291 + /// to be false in the corresponding node-map.
3.1292 + void hide(const Node& n) const { Parent::hide(n); }
3.1293 +
3.1294 + /// \brief Hides the edge of the graph
3.1295 + ///
3.1296 + /// This function hides \c e in the graph, i.e. the iteration
3.1297 + /// jumps over it. This is done by simply setting the value of \c e
3.1298 + /// to be false in the corresponding edge-map.
3.1299 + void hide(const Edge& e) const { Parent::hide(e); }
3.1300 +
3.1301 + /// \brief Unhides the node of the graph
3.1302 + ///
3.1303 + /// The value of \c n is set to be true in the node-map which stores
3.1304 + /// hide information. If \c n was hidden previuosly, then it is shown
3.1305 + /// again
3.1306 + void unHide(const Node& n) const { Parent::unHide(n); }
3.1307 +
3.1308 + /// \brief Unhides the edge of the graph
3.1309 + ///
3.1310 + /// The value of \c e is set to be true in the edge-map which stores
3.1311 + /// hide information. If \c e was hidden previuosly, then it is shown
3.1312 + /// again
3.1313 + void unHide(const Edge& e) const { Parent::unHide(e); }
3.1314 +
3.1315 + /// \brief Returns true if \c n is hidden.
3.1316 + ///
3.1317 + /// Returns true if \c n is hidden.
3.1318 + ///
3.1319 + bool hidden(const Node& n) const { return Parent::hidden(n); }
3.1320 +
3.1321 + /// \brief Returns true if \c e is hidden.
3.1322 + ///
3.1323 + /// Returns true if \c e is hidden.
3.1324 + ///
3.1325 + bool hidden(const Edge& e) const { return Parent::hidden(e); }
3.1326 + };
3.1327 +
3.1328 + /// \brief Just gives back a subgraph
3.1329 + ///
3.1330 + /// Just gives back a subgraph
3.1331 + template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
3.1332 + SubGraph<const Graph, NodeFilterMap, ArcFilterMap>
3.1333 + subGraph(const Graph& graph, NodeFilterMap& nfm, ArcFilterMap& efm) {
3.1334 + return SubGraph<const Graph, NodeFilterMap, ArcFilterMap>(graph, nfm, efm);
3.1335 + }
3.1336 +
3.1337 + template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
3.1338 + SubGraph<const Graph, const NodeFilterMap, ArcFilterMap>
3.1339 + subGraph(const Graph& graph,
3.1340 + const NodeFilterMap& nfm, ArcFilterMap& efm) {
3.1341 + return SubGraph<const Graph, const NodeFilterMap, ArcFilterMap>
3.1342 + (graph, nfm, efm);
3.1343 + }
3.1344 +
3.1345 + template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
3.1346 + SubGraph<const Graph, NodeFilterMap, const ArcFilterMap>
3.1347 + subGraph(const Graph& graph,
3.1348 + NodeFilterMap& nfm, const ArcFilterMap& efm) {
3.1349 + return SubGraph<const Graph, NodeFilterMap, const ArcFilterMap>
3.1350 + (graph, nfm, efm);
3.1351 + }
3.1352 +
3.1353 + template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
3.1354 + SubGraph<const Graph, const NodeFilterMap, const ArcFilterMap>
3.1355 + subGraph(const Graph& graph,
3.1356 + const NodeFilterMap& nfm, const ArcFilterMap& efm) {
3.1357 + return SubGraph<const Graph, const NodeFilterMap, const ArcFilterMap>
3.1358 + (graph, nfm, efm);
3.1359 + }
3.1360 +
3.1361 + /// \ingroup graph_adaptors
3.1362 + ///
3.1363 + /// \brief An adaptor for hiding nodes from a digraph or a graph.
3.1364 + ///
3.1365 + /// FilterNodes adaptor hides nodes in a graph or a digraph. A bool
3.1366 + /// node map must be specified, which defines the filters for
3.1367 + /// nodes. Just the unfiltered nodes and the arcs or edges incident
3.1368 + /// to unfiltered nodes are shown in the subdigraph or subgraph. The
3.1369 + /// FilterNodes is conform to the \ref concepts::Digraph
3.1370 + /// "Digraph concept" or \ref concepts::Graph "Graph concept" depending
3.1371 + /// on the \c _Digraph template parameter. If the \c _checked
3.1372 + /// parameter is true, then the arc or edges incident to filtered nodes
3.1373 + /// are also filtered out.
3.1374 + ///
3.1375 + /// \tparam _Digraph It must be conform to the \ref
3.1376 + /// concepts::Digraph "Digraph concept" or \ref concepts::Graph
3.1377 + /// "Graph concept". The type can be specified to be const.
3.1378 + /// \tparam _NodeFilterMap A bool valued node map of the the adapted graph.
3.1379 + /// \tparam _checked If the parameter is false then the arc or edge
3.1380 + /// filtering is not checked with respect to node filter. In this
3.1381 + /// case just isolated nodes can be filtered out from the
3.1382 + /// graph.
3.1383 +#ifdef DOXYGEN
3.1384 + template<typename _Digraph,
3.1385 + typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
3.1386 + bool _checked = true>
3.1387 +#else
3.1388 + template<typename _Digraph,
3.1389 + typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
3.1390 + bool _checked = true,
3.1391 + typename Enable = void>
3.1392 +#endif
3.1393 + class FilterNodes
3.1394 + : public SubDigraph<_Digraph, _NodeFilterMap,
3.1395 + ConstMap<typename _Digraph::Arc, bool>, _checked> {
3.1396 + public:
3.1397 +
3.1398 + typedef _Digraph Digraph;
3.1399 + typedef _NodeFilterMap NodeFilterMap;
3.1400 +
3.1401 + typedef SubDigraph<Digraph, NodeFilterMap,
3.1402 + ConstMap<typename Digraph::Arc, bool>, _checked>
3.1403 + Parent;
3.1404 +
3.1405 + typedef typename Parent::Node Node;
3.1406 +
3.1407 + protected:
3.1408 + ConstMap<typename Digraph::Arc, bool> const_true_map;
3.1409 +
3.1410 + FilterNodes() : const_true_map(true) {
3.1411 + Parent::setArcFilterMap(const_true_map);
3.1412 + }
3.1413 +
3.1414 + public:
3.1415 +
3.1416 + /// \brief Constructor
3.1417 + ///
3.1418 + /// Creates an adaptor for the given digraph or graph with
3.1419 + /// given node filter map.
3.1420 + FilterNodes(Digraph& _digraph, NodeFilterMap& node_filter) :
3.1421 + Parent(), const_true_map(true) {
3.1422 + Parent::setDigraph(_digraph);
3.1423 + Parent::setNodeFilterMap(node_filter);
3.1424 + Parent::setArcFilterMap(const_true_map);
3.1425 + }
3.1426 +
3.1427 + /// \brief Hides the node of the graph
3.1428 + ///
3.1429 + /// This function hides \c n in the digraph or graph, i.e. the iteration
3.1430 + /// jumps over it. This is done by simply setting the value of \c n
3.1431 + /// to be false in the corresponding node map.
3.1432 + void hide(const Node& n) const { Parent::hide(n); }
3.1433 +
3.1434 + /// \brief Unhides the node of the graph
3.1435 + ///
3.1436 + /// The value of \c n is set to be true in the node-map which stores
3.1437 + /// hide information. If \c n was hidden previuosly, then it is shown
3.1438 + /// again
3.1439 + void unHide(const Node& n) const { Parent::unHide(n); }
3.1440 +
3.1441 + /// \brief Returns true if \c n is hidden.
3.1442 + ///
3.1443 + /// Returns true if \c n is hidden.
3.1444 + ///
3.1445 + bool hidden(const Node& n) const { return Parent::hidden(n); }
3.1446 +
3.1447 + };
3.1448 +
3.1449 + template<typename _Graph, typename _NodeFilterMap, bool _checked>
3.1450 + class FilterNodes<_Graph, _NodeFilterMap, _checked,
3.1451 + typename enable_if<UndirectedTagIndicator<_Graph> >::type>
3.1452 + : public SubGraph<_Graph, _NodeFilterMap,
3.1453 + ConstMap<typename _Graph::Edge, bool>, _checked> {
3.1454 + public:
3.1455 + typedef _Graph Graph;
3.1456 + typedef _NodeFilterMap NodeFilterMap;
3.1457 + typedef SubGraph<Graph, NodeFilterMap,
3.1458 + ConstMap<typename Graph::Edge, bool> > Parent;
3.1459 +
3.1460 + typedef typename Parent::Node Node;
3.1461 + protected:
3.1462 + ConstMap<typename Graph::Edge, bool> const_true_map;
3.1463 +
3.1464 + FilterNodes() : const_true_map(true) {
3.1465 + Parent::setEdgeFilterMap(const_true_map);
3.1466 + }
3.1467 +
3.1468 + public:
3.1469 +
3.1470 + FilterNodes(Graph& _graph, NodeFilterMap& node_filter_map) :
3.1471 + Parent(), const_true_map(true) {
3.1472 + Parent::setGraph(_graph);
3.1473 + Parent::setNodeFilterMap(node_filter_map);
3.1474 + Parent::setEdgeFilterMap(const_true_map);
3.1475 + }
3.1476 +
3.1477 + void hide(const Node& n) const { Parent::hide(n); }
3.1478 + void unHide(const Node& n) const { Parent::unHide(n); }
3.1479 + bool hidden(const Node& n) const { return Parent::hidden(n); }
3.1480 +
3.1481 + };
3.1482 +
3.1483 +
3.1484 + /// \brief Just gives back a FilterNodes adaptor
3.1485 + ///
3.1486 + /// Just gives back a FilterNodes adaptor
3.1487 + template<typename Digraph, typename NodeFilterMap>
3.1488 + FilterNodes<const Digraph, NodeFilterMap>
3.1489 + filterNodes(const Digraph& digraph, NodeFilterMap& nfm) {
3.1490 + return FilterNodes<const Digraph, NodeFilterMap>(digraph, nfm);
3.1491 + }
3.1492 +
3.1493 + template<typename Digraph, typename NodeFilterMap>
3.1494 + FilterNodes<const Digraph, const NodeFilterMap>
3.1495 + filterNodes(const Digraph& digraph, const NodeFilterMap& nfm) {
3.1496 + return FilterNodes<const Digraph, const NodeFilterMap>(digraph, nfm);
3.1497 + }
3.1498 +
3.1499 + /// \ingroup graph_adaptors
3.1500 + ///
3.1501 + /// \brief An adaptor for hiding arcs from a digraph.
3.1502 + ///
3.1503 + /// FilterArcs adaptor hides arcs in a digraph. A bool arc map must
3.1504 + /// be specified, which defines the filters for arcs. Just the
3.1505 + /// unfiltered arcs are shown in the subdigraph. The FilterArcs is
3.1506 + /// conform to the \ref concepts::Digraph "Digraph concept".
3.1507 + ///
3.1508 + /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
3.1509 + /// "Digraph concept". The type can be specified to be const.
3.1510 + /// \tparam _ArcFilterMap A bool valued arc map of the the adapted
3.1511 + /// graph.
3.1512 + template<typename _Digraph, typename _ArcFilterMap>
3.1513 + class FilterArcs :
3.1514 + public SubDigraph<_Digraph, ConstMap<typename _Digraph::Node, bool>,
3.1515 + _ArcFilterMap, false> {
3.1516 + public:
3.1517 + typedef _Digraph Digraph;
3.1518 + typedef _ArcFilterMap ArcFilterMap;
3.1519 +
3.1520 + typedef SubDigraph<Digraph, ConstMap<typename Digraph::Node, bool>,
3.1521 + ArcFilterMap, false> Parent;
3.1522 +
3.1523 + typedef typename Parent::Arc Arc;
3.1524 +
3.1525 + protected:
3.1526 + ConstMap<typename Digraph::Node, bool> const_true_map;
3.1527 +
3.1528 + FilterArcs() : const_true_map(true) {
3.1529 + Parent::setNodeFilterMap(const_true_map);
3.1530 + }
3.1531 +
3.1532 + public:
3.1533 +
3.1534 + /// \brief Constructor
3.1535 + ///
3.1536 + /// Creates a FilterArcs adaptor for the given graph with
3.1537 + /// given arc map filter.
3.1538 + FilterArcs(Digraph& digraph, ArcFilterMap& arc_filter)
3.1539 + : Parent(), const_true_map(true) {
3.1540 + Parent::setDigraph(digraph);
3.1541 + Parent::setNodeFilterMap(const_true_map);
3.1542 + Parent::setArcFilterMap(arc_filter);
3.1543 + }
3.1544 +
3.1545 + /// \brief Hides the arc of the graph
3.1546 + ///
3.1547 + /// This function hides \c a in the graph, i.e. the iteration
3.1548 + /// jumps over it. This is done by simply setting the value of \c a
3.1549 + /// to be false in the corresponding arc map.
3.1550 + void hide(const Arc& a) const { Parent::hide(a); }
3.1551 +
3.1552 + /// \brief Unhides the arc of the graph
3.1553 + ///
3.1554 + /// The value of \c a is set to be true in the arc-map which stores
3.1555 + /// hide information. If \c a was hidden previuosly, then it is shown
3.1556 + /// again
3.1557 + void unHide(const Arc& a) const { Parent::unHide(a); }
3.1558 +
3.1559 + /// \brief Returns true if \c a is hidden.
3.1560 + ///
3.1561 + /// Returns true if \c a is hidden.
3.1562 + ///
3.1563 + bool hidden(const Arc& a) const { return Parent::hidden(a); }
3.1564 +
3.1565 + };
3.1566 +
3.1567 + /// \brief Just gives back an FilterArcs adaptor
3.1568 + ///
3.1569 + /// Just gives back an FilterArcs adaptor
3.1570 + template<typename Digraph, typename ArcFilterMap>
3.1571 + FilterArcs<const Digraph, ArcFilterMap>
3.1572 + filterArcs(const Digraph& digraph, ArcFilterMap& afm) {
3.1573 + return FilterArcs<const Digraph, ArcFilterMap>(digraph, afm);
3.1574 + }
3.1575 +
3.1576 + template<typename Digraph, typename ArcFilterMap>
3.1577 + FilterArcs<const Digraph, const ArcFilterMap>
3.1578 + filterArcs(const Digraph& digraph, const ArcFilterMap& afm) {
3.1579 + return FilterArcs<const Digraph, const ArcFilterMap>(digraph, afm);
3.1580 + }
3.1581 +
3.1582 + /// \ingroup graph_adaptors
3.1583 + ///
3.1584 + /// \brief An adaptor for hiding edges from a graph.
3.1585 + ///
3.1586 + /// FilterEdges adaptor hides edges in a digraph. A bool edge map must
3.1587 + /// be specified, which defines the filters for edges. Just the
3.1588 + /// unfiltered edges are shown in the subdigraph. The FilterEdges is
3.1589 + /// conform to the \ref concepts::Graph "Graph concept".
3.1590 + ///
3.1591 + /// \tparam _Graph It must be conform to the \ref concepts::Graph
3.1592 + /// "Graph concept". The type can be specified to be const.
3.1593 + /// \tparam _EdgeFilterMap A bool valued edge map of the the adapted
3.1594 + /// graph.
3.1595 + template<typename _Graph, typename _EdgeFilterMap>
3.1596 + class FilterEdges :
3.1597 + public SubGraph<_Graph, ConstMap<typename _Graph::Node,bool>,
3.1598 + _EdgeFilterMap, false> {
3.1599 + public:
3.1600 + typedef _Graph Graph;
3.1601 + typedef _EdgeFilterMap EdgeFilterMap;
3.1602 + typedef SubGraph<Graph, ConstMap<typename Graph::Node,bool>,
3.1603 + EdgeFilterMap, false> Parent;
3.1604 + typedef typename Parent::Edge Edge;
3.1605 + protected:
3.1606 + ConstMap<typename Graph::Node, bool> const_true_map;
3.1607 +
3.1608 + FilterEdges() : const_true_map(true) {
3.1609 + Parent::setNodeFilterMap(const_true_map);
3.1610 + }
3.1611 +
3.1612 + public:
3.1613 +
3.1614 + /// \brief Constructor
3.1615 + ///
3.1616 + /// Creates a FilterEdges adaptor for the given graph with
3.1617 + /// given edge map filters.
3.1618 + FilterEdges(Graph& _graph, EdgeFilterMap& edge_filter_map) :
3.1619 + Parent(), const_true_map(true) {
3.1620 + Parent::setGraph(_graph);
3.1621 + Parent::setNodeFilterMap(const_true_map);
3.1622 + Parent::setEdgeFilterMap(edge_filter_map);
3.1623 + }
3.1624 +
3.1625 + /// \brief Hides the edge of the graph
3.1626 + ///
3.1627 + /// This function hides \c e in the graph, i.e. the iteration
3.1628 + /// jumps over it. This is done by simply setting the value of \c e
3.1629 + /// to be false in the corresponding edge-map.
3.1630 + void hide(const Edge& e) const { Parent::hide(e); }
3.1631 +
3.1632 + /// \brief Unhides the edge of the graph
3.1633 + ///
3.1634 + /// The value of \c e is set to be true in the edge-map which stores
3.1635 + /// hide information. If \c e was hidden previuosly, then it is shown
3.1636 + /// again
3.1637 + void unHide(const Edge& e) const { Parent::unHide(e); }
3.1638 +
3.1639 + /// \brief Returns true if \c e is hidden.
3.1640 + ///
3.1641 + /// Returns true if \c e is hidden.
3.1642 + ///
3.1643 + bool hidden(const Edge& e) const { return Parent::hidden(e); }
3.1644 +
3.1645 + };
3.1646 +
3.1647 + /// \brief Just gives back a FilterEdges adaptor
3.1648 + ///
3.1649 + /// Just gives back a FilterEdges adaptor
3.1650 + template<typename Graph, typename EdgeFilterMap>
3.1651 + FilterEdges<const Graph, EdgeFilterMap>
3.1652 + filterEdges(const Graph& graph, EdgeFilterMap& efm) {
3.1653 + return FilterEdges<const Graph, EdgeFilterMap>(graph, efm);
3.1654 + }
3.1655 +
3.1656 + template<typename Graph, typename EdgeFilterMap>
3.1657 + FilterEdges<const Graph, const EdgeFilterMap>
3.1658 + filterEdges(const Graph& graph, const EdgeFilterMap& efm) {
3.1659 + return FilterEdges<const Graph, const EdgeFilterMap>(graph, efm);
3.1660 + }
3.1661 +
3.1662 + template <typename _Digraph>
3.1663 + class UndirectorBase {
3.1664 + public:
3.1665 + typedef _Digraph Digraph;
3.1666 + typedef UndirectorBase Adaptor;
3.1667 +
3.1668 + typedef True UndirectedTag;
3.1669 +
3.1670 + typedef typename Digraph::Arc Edge;
3.1671 + typedef typename Digraph::Node Node;
3.1672 +
3.1673 + class Arc : public Edge {
3.1674 + friend class UndirectorBase;
3.1675 + protected:
3.1676 + bool _forward;
3.1677 +
3.1678 + Arc(const Edge& edge, bool forward) :
3.1679 + Edge(edge), _forward(forward) {}
3.1680 +
3.1681 + public:
3.1682 + Arc() {}
3.1683 +
3.1684 + Arc(Invalid) : Edge(INVALID), _forward(true) {}
3.1685 +
3.1686 + bool operator==(const Arc &other) const {
3.1687 + return _forward == other._forward &&
3.1688 + static_cast<const Edge&>(*this) == static_cast<const Edge&>(other);
3.1689 + }
3.1690 + bool operator!=(const Arc &other) const {
3.1691 + return _forward != other._forward ||
3.1692 + static_cast<const Edge&>(*this) != static_cast<const Edge&>(other);
3.1693 + }
3.1694 + bool operator<(const Arc &other) const {
3.1695 + return _forward < other._forward ||
3.1696 + (_forward == other._forward &&
3.1697 + static_cast<const Edge&>(*this) < static_cast<const Edge&>(other));
3.1698 + }
3.1699 + };
3.1700 +
3.1701 +
3.1702 +
3.1703 + void first(Node& n) const {
3.1704 + _digraph->first(n);
3.1705 + }
3.1706 +
3.1707 + void next(Node& n) const {
3.1708 + _digraph->next(n);
3.1709 + }
3.1710 +
3.1711 + void first(Arc& a) const {
3.1712 + _digraph->first(a);
3.1713 + a._forward = true;
3.1714 + }
3.1715 +
3.1716 + void next(Arc& a) const {
3.1717 + if (a._forward) {
3.1718 + a._forward = false;
3.1719 + } else {
3.1720 + _digraph->next(a);
3.1721 + a._forward = true;
3.1722 + }
3.1723 + }
3.1724 +
3.1725 + void first(Edge& e) const {
3.1726 + _digraph->first(e);
3.1727 + }
3.1728 +
3.1729 + void next(Edge& e) const {
3.1730 + _digraph->next(e);
3.1731 + }
3.1732 +
3.1733 + void firstOut(Arc& a, const Node& n) const {
3.1734 + _digraph->firstIn(a, n);
3.1735 + if( static_cast<const Edge&>(a) != INVALID ) {
3.1736 + a._forward = false;
3.1737 + } else {
3.1738 + _digraph->firstOut(a, n);
3.1739 + a._forward = true;
3.1740 + }
3.1741 + }
3.1742 + void nextOut(Arc &a) const {
3.1743 + if (!a._forward) {
3.1744 + Node n = _digraph->target(a);
3.1745 + _digraph->nextIn(a);
3.1746 + if (static_cast<const Edge&>(a) == INVALID ) {
3.1747 + _digraph->firstOut(a, n);
3.1748 + a._forward = true;
3.1749 + }
3.1750 + }
3.1751 + else {
3.1752 + _digraph->nextOut(a);
3.1753 + }
3.1754 + }
3.1755 +
3.1756 + void firstIn(Arc &a, const Node &n) const {
3.1757 + _digraph->firstOut(a, n);
3.1758 + if (static_cast<const Edge&>(a) != INVALID ) {
3.1759 + a._forward = false;
3.1760 + } else {
3.1761 + _digraph->firstIn(a, n);
3.1762 + a._forward = true;
3.1763 + }
3.1764 + }
3.1765 + void nextIn(Arc &a) const {
3.1766 + if (!a._forward) {
3.1767 + Node n = _digraph->source(a);
3.1768 + _digraph->nextOut(a);
3.1769 + if( static_cast<const Edge&>(a) == INVALID ) {
3.1770 + _digraph->firstIn(a, n);
3.1771 + a._forward = true;
3.1772 + }
3.1773 + }
3.1774 + else {
3.1775 + _digraph->nextIn(a);
3.1776 + }
3.1777 + }
3.1778 +
3.1779 + void firstInc(Edge &e, bool &d, const Node &n) const {
3.1780 + d = true;
3.1781 + _digraph->firstOut(e, n);
3.1782 + if (e != INVALID) return;
3.1783 + d = false;
3.1784 + _digraph->firstIn(e, n);
3.1785 + }
3.1786 +
3.1787 + void nextInc(Edge &e, bool &d) const {
3.1788 + if (d) {
3.1789 + Node s = _digraph->source(e);
3.1790 + _digraph->nextOut(e);
3.1791 + if (e != INVALID) return;
3.1792 + d = false;
3.1793 + _digraph->firstIn(e, s);
3.1794 + } else {
3.1795 + _digraph->nextIn(e);
3.1796 + }
3.1797 + }
3.1798 +
3.1799 + Node u(const Edge& e) const {
3.1800 + return _digraph->source(e);
3.1801 + }
3.1802 +
3.1803 + Node v(const Edge& e) const {
3.1804 + return _digraph->target(e);
3.1805 + }
3.1806 +
3.1807 + Node source(const Arc &a) const {
3.1808 + return a._forward ? _digraph->source(a) : _digraph->target(a);
3.1809 + }
3.1810 +
3.1811 + Node target(const Arc &a) const {
3.1812 + return a._forward ? _digraph->target(a) : _digraph->source(a);
3.1813 + }
3.1814 +
3.1815 + static Arc direct(const Edge &e, bool d) {
3.1816 + return Arc(e, d);
3.1817 + }
3.1818 + Arc direct(const Edge &e, const Node& n) const {
3.1819 + return Arc(e, _digraph->source(e) == n);
3.1820 + }
3.1821 +
3.1822 + static bool direction(const Arc &a) { return a._forward; }
3.1823 +
3.1824 + Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
3.1825 + Arc arcFromId(int ix) const {
3.1826 + return direct(_digraph->arcFromId(ix >> 1), bool(ix & 1));
3.1827 + }
3.1828 + Edge edgeFromId(int ix) const { return _digraph->arcFromId(ix); }
3.1829 +
3.1830 + int id(const Node &n) const { return _digraph->id(n); }
3.1831 + int id(const Arc &a) const {
3.1832 + return (_digraph->id(a) << 1) | (a._forward ? 1 : 0);
3.1833 + }
3.1834 + int id(const Edge &e) const { return _digraph->id(e); }
3.1835 +
3.1836 + int maxNodeId() const { return _digraph->maxNodeId(); }
3.1837 + int maxArcId() const { return (_digraph->maxArcId() << 1) | 1; }
3.1838 + int maxEdgeId() const { return _digraph->maxArcId(); }
3.1839 +
3.1840 + Node addNode() { return _digraph->addNode(); }
3.1841 + Edge addEdge(const Node& u, const Node& v) {
3.1842 + return _digraph->addArc(u, v);
3.1843 + }
3.1844 +
3.1845 + void erase(const Node& i) { _digraph->erase(i); }
3.1846 + void erase(const Edge& i) { _digraph->erase(i); }
3.1847 +
3.1848 + void clear() { _digraph->clear(); }
3.1849 +
3.1850 + typedef NodeNumTagIndicator<Digraph> NodeNumTag;
3.1851 + int nodeNum() const { return 2 * _digraph->arcNum(); }
3.1852 + typedef EdgeNumTagIndicator<Digraph> EdgeNumTag;
3.1853 + int arcNum() const { return 2 * _digraph->arcNum(); }
3.1854 + int edgeNum() const { return _digraph->arcNum(); }
3.1855 +
3.1856 + typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
3.1857 + Arc findArc(Node s, Node t, Arc p = INVALID) const {
3.1858 + if (p == INVALID) {
3.1859 + Edge arc = _digraph->findArc(s, t);
3.1860 + if (arc != INVALID) return direct(arc, true);
3.1861 + arc = _digraph->findArc(t, s);
3.1862 + if (arc != INVALID) return direct(arc, false);
3.1863 + } else if (direction(p)) {
3.1864 + Edge arc = _digraph->findArc(s, t, p);
3.1865 + if (arc != INVALID) return direct(arc, true);
3.1866 + arc = _digraph->findArc(t, s);
3.1867 + if (arc != INVALID) return direct(arc, false);
3.1868 + } else {
3.1869 + Edge arc = _digraph->findArc(t, s, p);
3.1870 + if (arc != INVALID) return direct(arc, false);
3.1871 + }
3.1872 + return INVALID;
3.1873 + }
3.1874 +
3.1875 + Edge findEdge(Node s, Node t, Edge p = INVALID) const {
3.1876 + if (s != t) {
3.1877 + if (p == INVALID) {
3.1878 + Edge arc = _digraph->findArc(s, t);
3.1879 + if (arc != INVALID) return arc;
3.1880 + arc = _digraph->findArc(t, s);
3.1881 + if (arc != INVALID) return arc;
3.1882 + } else if (_digraph->s(p) == s) {
3.1883 + Edge arc = _digraph->findArc(s, t, p);
3.1884 + if (arc != INVALID) return arc;
3.1885 + arc = _digraph->findArc(t, s);
3.1886 + if (arc != INVALID) return arc;
3.1887 + } else {
3.1888 + Edge arc = _digraph->findArc(t, s, p);
3.1889 + if (arc != INVALID) return arc;
3.1890 + }
3.1891 + } else {
3.1892 + return _digraph->findArc(s, t, p);
3.1893 + }
3.1894 + return INVALID;
3.1895 + }
3.1896 +
3.1897 + private:
3.1898 +
3.1899 + template <typename _Value>
3.1900 + class ArcMapBase {
3.1901 + private:
3.1902 +
3.1903 + typedef typename Digraph::template ArcMap<_Value> MapImpl;
3.1904 +
3.1905 + public:
3.1906 +
3.1907 + typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
3.1908 +
3.1909 + typedef _Value Value;
3.1910 + typedef Arc Key;
3.1911 +
3.1912 + ArcMapBase(const Adaptor& adaptor) :
3.1913 + _forward(*adaptor._digraph), _backward(*adaptor._digraph) {}
3.1914 +
3.1915 + ArcMapBase(const Adaptor& adaptor, const Value& v)
3.1916 + : _forward(*adaptor._digraph, v), _backward(*adaptor._digraph, v) {}
3.1917 +
3.1918 + void set(const Arc& a, const Value& v) {
3.1919 + if (direction(a)) {
3.1920 + _forward.set(a, v);
3.1921 + } else {
3.1922 + _backward.set(a, v);
3.1923 + }
3.1924 + }
3.1925 +
3.1926 + typename MapTraits<MapImpl>::ConstReturnValue
3.1927 + operator[](const Arc& a) const {
3.1928 + if (direction(a)) {
3.1929 + return _forward[a];
3.1930 + } else {
3.1931 + return _backward[a];
3.1932 + }
3.1933 + }
3.1934 +
3.1935 + typename MapTraits<MapImpl>::ReturnValue
3.1936 + operator[](const Arc& a) {
3.1937 + if (direction(a)) {
3.1938 + return _forward[a];
3.1939 + } else {
3.1940 + return _backward[a];
3.1941 + }
3.1942 + }
3.1943 +
3.1944 + protected:
3.1945 +
3.1946 + MapImpl _forward, _backward;
3.1947 +
3.1948 + };
3.1949 +
3.1950 + public:
3.1951 +
3.1952 + template <typename _Value>
3.1953 + class NodeMap : public Digraph::template NodeMap<_Value> {
3.1954 + public:
3.1955 +
3.1956 + typedef _Value Value;
3.1957 + typedef typename Digraph::template NodeMap<Value> Parent;
3.1958 +
3.1959 + explicit NodeMap(const Adaptor& adaptor)
3.1960 + : Parent(*adaptor._digraph) {}
3.1961 +
3.1962 + NodeMap(const Adaptor& adaptor, const _Value& value)
3.1963 + : Parent(*adaptor._digraph, value) { }
3.1964 +
3.1965 + private:
3.1966 + NodeMap& operator=(const NodeMap& cmap) {
3.1967 + return operator=<NodeMap>(cmap);
3.1968 + }
3.1969 +
3.1970 + template <typename CMap>
3.1971 + NodeMap& operator=(const CMap& cmap) {
3.1972 + Parent::operator=(cmap);
3.1973 + return *this;
3.1974 + }
3.1975 +
3.1976 + };
3.1977 +
3.1978 + template <typename _Value>
3.1979 + class ArcMap
3.1980 + : public SubMapExtender<Adaptor, ArcMapBase<_Value> >
3.1981 + {
3.1982 + public:
3.1983 + typedef _Value Value;
3.1984 + typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
3.1985 +
3.1986 + ArcMap(const Adaptor& adaptor)
3.1987 + : Parent(adaptor) {}
3.1988 +
3.1989 + ArcMap(const Adaptor& adaptor, const Value& value)
3.1990 + : Parent(adaptor, value) {}
3.1991 +
3.1992 + private:
3.1993 + ArcMap& operator=(const ArcMap& cmap) {
3.1994 + return operator=<ArcMap>(cmap);
3.1995 + }
3.1996 +
3.1997 + template <typename CMap>
3.1998 + ArcMap& operator=(const CMap& cmap) {
3.1999 + Parent::operator=(cmap);
3.2000 + return *this;
3.2001 + }
3.2002 + };
3.2003 +
3.2004 + template <typename _Value>
3.2005 + class EdgeMap : public Digraph::template ArcMap<_Value> {
3.2006 + public:
3.2007 +
3.2008 + typedef _Value Value;
3.2009 + typedef typename Digraph::template ArcMap<Value> Parent;
3.2010 +
3.2011 + explicit EdgeMap(const Adaptor& adaptor)
3.2012 + : Parent(*adaptor._digraph) {}
3.2013 +
3.2014 + EdgeMap(const Adaptor& adaptor, const Value& value)
3.2015 + : Parent(*adaptor._digraph, value) {}
3.2016 +
3.2017 + private:
3.2018 + EdgeMap& operator=(const EdgeMap& cmap) {
3.2019 + return operator=<EdgeMap>(cmap);
3.2020 + }
3.2021 +
3.2022 + template <typename CMap>
3.2023 + EdgeMap& operator=(const CMap& cmap) {
3.2024 + Parent::operator=(cmap);
3.2025 + return *this;
3.2026 + }
3.2027 +
3.2028 + };
3.2029 +
3.2030 + typedef typename ItemSetTraits<Digraph, Node>::ItemNotifier NodeNotifier;
3.2031 + NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
3.2032 +
3.2033 + protected:
3.2034 +
3.2035 + UndirectorBase() : _digraph(0) {}
3.2036 +
3.2037 + Digraph* _digraph;
3.2038 +
3.2039 + void setDigraph(Digraph& digraph) {
3.2040 + _digraph = &digraph;
3.2041 + }
3.2042 +
3.2043 + };
3.2044 +
3.2045 + /// \ingroup graph_adaptors
3.2046 + ///
3.2047 + /// \brief Undirect the graph
3.2048 + ///
3.2049 + /// This adaptor makes an undirected graph from a directed
3.2050 + /// graph. All arcs of the underlying digraph will be showed in the
3.2051 + /// adaptor as an edge. The Orienter adaptor is conform to the \ref
3.2052 + /// concepts::Graph "Graph concept".
3.2053 + ///
3.2054 + /// \tparam _Digraph It must be conform to the \ref
3.2055 + /// concepts::Digraph "Digraph concept". The type can be specified
3.2056 + /// to const.
3.2057 + template<typename _Digraph>
3.2058 + class Undirector
3.2059 + : public GraphAdaptorExtender<UndirectorBase<_Digraph> > {
3.2060 + public:
3.2061 + typedef _Digraph Digraph;
3.2062 + typedef GraphAdaptorExtender<UndirectorBase<Digraph> > Parent;
3.2063 + protected:
3.2064 + Undirector() { }
3.2065 + public:
3.2066 +
3.2067 + /// \brief Constructor
3.2068 + ///
3.2069 + /// Creates a undirected graph from the given digraph
3.2070 + Undirector(_Digraph& digraph) {
3.2071 + setDigraph(digraph);
3.2072 + }
3.2073 +
3.2074 + /// \brief ArcMap combined from two original ArcMap
3.2075 + ///
3.2076 + /// This class adapts two original digraph ArcMap to
3.2077 + /// get an arc map on the undirected graph.
3.2078 + template <typename _ForwardMap, typename _BackwardMap>
3.2079 + class CombinedArcMap {
3.2080 + public:
3.2081 +
3.2082 + typedef _ForwardMap ForwardMap;
3.2083 + typedef _BackwardMap BackwardMap;
3.2084 +
3.2085 + typedef typename MapTraits<ForwardMap>::ReferenceMapTag ReferenceMapTag;
3.2086 +
3.2087 + typedef typename ForwardMap::Value Value;
3.2088 + typedef typename Parent::Arc Key;
3.2089 +
3.2090 + /// \brief Constructor
3.2091 + ///
3.2092 + /// Constructor
3.2093 + CombinedArcMap(ForwardMap& forward, BackwardMap& backward)
3.2094 + : _forward(&forward), _backward(&backward) {}
3.2095 +
3.2096 +
3.2097 + /// \brief Sets the value associated with a key.
3.2098 + ///
3.2099 + /// Sets the value associated with a key.
3.2100 + void set(const Key& e, const Value& a) {
3.2101 + if (Parent::direction(e)) {
3.2102 + _forward->set(e, a);
3.2103 + } else {
3.2104 + _backward->set(e, a);
3.2105 + }
3.2106 + }
3.2107 +
3.2108 + /// \brief Returns the value associated with a key.
3.2109 + ///
3.2110 + /// Returns the value associated with a key.
3.2111 + typename MapTraits<ForwardMap>::ConstReturnValue
3.2112 + operator[](const Key& e) const {
3.2113 + if (Parent::direction(e)) {
3.2114 + return (*_forward)[e];
3.2115 + } else {
3.2116 + return (*_backward)[e];
3.2117 + }
3.2118 + }
3.2119 +
3.2120 + /// \brief Returns the value associated with a key.
3.2121 + ///
3.2122 + /// Returns the value associated with a key.
3.2123 + typename MapTraits<ForwardMap>::ReturnValue
3.2124 + operator[](const Key& e) {
3.2125 + if (Parent::direction(e)) {
3.2126 + return (*_forward)[e];
3.2127 + } else {
3.2128 + return (*_backward)[e];
3.2129 + }
3.2130 + }
3.2131 +
3.2132 + protected:
3.2133 +
3.2134 + ForwardMap* _forward;
3.2135 + BackwardMap* _backward;
3.2136 +
3.2137 + };
3.2138 +
3.2139 + /// \brief Just gives back a combined arc map
3.2140 + ///
3.2141 + /// Just gives back a combined arc map
3.2142 + template <typename ForwardMap, typename BackwardMap>
3.2143 + static CombinedArcMap<ForwardMap, BackwardMap>
3.2144 + combinedArcMap(ForwardMap& forward, BackwardMap& backward) {
3.2145 + return CombinedArcMap<ForwardMap, BackwardMap>(forward, backward);
3.2146 + }
3.2147 +
3.2148 + template <typename ForwardMap, typename BackwardMap>
3.2149 + static CombinedArcMap<const ForwardMap, BackwardMap>
3.2150 + combinedArcMap(const ForwardMap& forward, BackwardMap& backward) {
3.2151 + return CombinedArcMap<const ForwardMap,
3.2152 + BackwardMap>(forward, backward);
3.2153 + }
3.2154 +
3.2155 + template <typename ForwardMap, typename BackwardMap>
3.2156 + static CombinedArcMap<ForwardMap, const BackwardMap>
3.2157 + combinedArcMap(ForwardMap& forward, const BackwardMap& backward) {
3.2158 + return CombinedArcMap<ForwardMap,
3.2159 + const BackwardMap>(forward, backward);
3.2160 + }
3.2161 +
3.2162 + template <typename ForwardMap, typename BackwardMap>
3.2163 + static CombinedArcMap<const ForwardMap, const BackwardMap>
3.2164 + combinedArcMap(const ForwardMap& forward, const BackwardMap& backward) {
3.2165 + return CombinedArcMap<const ForwardMap,
3.2166 + const BackwardMap>(forward, backward);
3.2167 + }
3.2168 +
3.2169 + };
3.2170 +
3.2171 + /// \brief Just gives back an undirected view of the given digraph
3.2172 + ///
3.2173 + /// Just gives back an undirected view of the given digraph
3.2174 + template<typename Digraph>
3.2175 + Undirector<const Digraph>
3.2176 + undirector(const Digraph& digraph) {
3.2177 + return Undirector<const Digraph>(digraph);
3.2178 + }
3.2179 +
3.2180 + template <typename _Graph, typename _DirectionMap>
3.2181 + class OrienterBase {
3.2182 + public:
3.2183 +
3.2184 + typedef _Graph Graph;
3.2185 + typedef _DirectionMap DirectionMap;
3.2186 +
3.2187 + typedef typename Graph::Node Node;
3.2188 + typedef typename Graph::Edge Arc;
3.2189 +
3.2190 + void reverseArc(const Arc& arc) {
3.2191 + _direction->set(arc, !(*_direction)[arc]);
3.2192 + }
3.2193 +
3.2194 + void first(Node& i) const { _graph->first(i); }
3.2195 + void first(Arc& i) const { _graph->first(i); }
3.2196 + void firstIn(Arc& i, const Node& n) const {
3.2197 + bool d;
3.2198 + _graph->firstInc(i, d, n);
3.2199 + while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
3.2200 + }
3.2201 + void firstOut(Arc& i, const Node& n ) const {
3.2202 + bool d;
3.2203 + _graph->firstInc(i, d, n);
3.2204 + while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
3.2205 + }
3.2206 +
3.2207 + void next(Node& i) const { _graph->next(i); }
3.2208 + void next(Arc& i) const { _graph->next(i); }
3.2209 + void nextIn(Arc& i) const {
3.2210 + bool d = !(*_direction)[i];
3.2211 + _graph->nextInc(i, d);
3.2212 + while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
3.2213 + }
3.2214 + void nextOut(Arc& i) const {
3.2215 + bool d = (*_direction)[i];
3.2216 + _graph->nextInc(i, d);
3.2217 + while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
3.2218 + }
3.2219 +
3.2220 + Node source(const Arc& e) const {
3.2221 + return (*_direction)[e] ? _graph->u(e) : _graph->v(e);
3.2222 + }
3.2223 + Node target(const Arc& e) const {
3.2224 + return (*_direction)[e] ? _graph->v(e) : _graph->u(e);
3.2225 + }
3.2226 +
3.2227 + typedef NodeNumTagIndicator<Graph> NodeNumTag;
3.2228 + int nodeNum() const { return _graph->nodeNum(); }
3.2229 +
3.2230 + typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
3.2231 + int arcNum() const { return _graph->edgeNum(); }
3.2232 +
3.2233 + typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
3.2234 + Arc findArc(const Node& u, const Node& v,
3.2235 + const Arc& prev = INVALID) {
3.2236 + Arc arc = prev;
3.2237 + bool d = arc == INVALID ? true : (*_direction)[arc];
3.2238 + if (d) {
3.2239 + arc = _graph->findEdge(u, v, arc);
3.2240 + while (arc != INVALID && !(*_direction)[arc]) {
3.2241 + _graph->findEdge(u, v, arc);
3.2242 + }
3.2243 + if (arc != INVALID) return arc;
3.2244 + }
3.2245 + _graph->findEdge(v, u, arc);
3.2246 + while (arc != INVALID && (*_direction)[arc]) {
3.2247 + _graph->findEdge(u, v, arc);
3.2248 + }
3.2249 + return arc;
3.2250 + }
3.2251 +
3.2252 + Node addNode() {
3.2253 + return Node(_graph->addNode());
3.2254 + }
3.2255 +
3.2256 + Arc addArc(const Node& u, const Node& v) {
3.2257 + Arc arc = _graph->addArc(u, v);
3.2258 + _direction->set(arc, _graph->source(arc) == u);
3.2259 + return arc;
3.2260 + }
3.2261 +
3.2262 + void erase(const Node& i) { _graph->erase(i); }
3.2263 + void erase(const Arc& i) { _graph->erase(i); }
3.2264 +
3.2265 + void clear() { _graph->clear(); }
3.2266 +
3.2267 + int id(const Node& v) const { return _graph->id(v); }
3.2268 + int id(const Arc& e) const { return _graph->id(e); }
3.2269 +
3.2270 + Node nodeFromId(int idx) const { return _graph->nodeFromId(idx); }
3.2271 + Arc arcFromId(int idx) const { return _graph->edgeFromId(idx); }
3.2272 +
3.2273 + int maxNodeId() const { return _graph->maxNodeId(); }
3.2274 + int maxArcId() const { return _graph->maxEdgeId(); }
3.2275 +
3.2276 + typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
3.2277 + NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
3.2278 +
3.2279 + typedef typename ItemSetTraits<Graph, Arc>::ItemNotifier ArcNotifier;
3.2280 + ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
3.2281 +
3.2282 + template <typename _Value>
3.2283 + class NodeMap : public _Graph::template NodeMap<_Value> {
3.2284 + public:
3.2285 +
3.2286 + typedef typename _Graph::template NodeMap<_Value> Parent;
3.2287 +
3.2288 + explicit NodeMap(const OrienterBase& adapter)
3.2289 + : Parent(*adapter._graph) {}
3.2290 +
3.2291 + NodeMap(const OrienterBase& adapter, const _Value& value)
3.2292 + : Parent(*adapter._graph, value) {}
3.2293 +
3.2294 + private:
3.2295 + NodeMap& operator=(const NodeMap& cmap) {
3.2296 + return operator=<NodeMap>(cmap);
3.2297 + }
3.2298 +
3.2299 + template <typename CMap>
3.2300 + NodeMap& operator=(const CMap& cmap) {
3.2301 + Parent::operator=(cmap);
3.2302 + return *this;
3.2303 + }
3.2304 +
3.2305 + };
3.2306 +
3.2307 + template <typename _Value>
3.2308 + class ArcMap : public _Graph::template EdgeMap<_Value> {
3.2309 + public:
3.2310 +
3.2311 + typedef typename Graph::template EdgeMap<_Value> Parent;
3.2312 +
3.2313 + explicit ArcMap(const OrienterBase& adapter)
3.2314 + : Parent(*adapter._graph) { }
3.2315 +
3.2316 + ArcMap(const OrienterBase& adapter, const _Value& value)
3.2317 + : Parent(*adapter._graph, value) { }
3.2318 +
3.2319 + private:
3.2320 + ArcMap& operator=(const ArcMap& cmap) {
3.2321 + return operator=<ArcMap>(cmap);
3.2322 + }
3.2323 +
3.2324 + template <typename CMap>
3.2325 + ArcMap& operator=(const CMap& cmap) {
3.2326 + Parent::operator=(cmap);
3.2327 + return *this;
3.2328 + }
3.2329 + };
3.2330 +
3.2331 +
3.2332 +
3.2333 + protected:
3.2334 + Graph* _graph;
3.2335 + DirectionMap* _direction;
3.2336 +
3.2337 + void setDirectionMap(DirectionMap& direction) {
3.2338 + _direction = &direction;
3.2339 + }
3.2340 +
3.2341 + void setGraph(Graph& graph) {
3.2342 + _graph = &graph;
3.2343 + }
3.2344 +
3.2345 + };
3.2346 +
3.2347 + /// \ingroup graph_adaptors
3.2348 + ///
3.2349 + /// \brief Orients the edges of the graph to get a digraph
3.2350 + ///
3.2351 + /// This adaptor orients each edge in the undirected graph. The
3.2352 + /// direction of the arcs stored in an edge node map. The arcs can
3.2353 + /// be easily reverted by the \c reverseArc() member function in the
3.2354 + /// adaptor. The Orienter adaptor is conform to the \ref
3.2355 + /// concepts::Digraph "Digraph concept".
3.2356 + ///
3.2357 + /// \tparam _Graph It must be conform to the \ref concepts::Graph
3.2358 + /// "Graph concept". The type can be specified to be const.
3.2359 + /// \tparam _DirectionMap A bool valued edge map of the the adapted
3.2360 + /// graph.
3.2361 + ///
3.2362 + /// \sa orienter
3.2363 + template<typename _Graph,
3.2364 + typename DirectionMap = typename _Graph::template EdgeMap<bool> >
3.2365 + class Orienter :
3.2366 + public DigraphAdaptorExtender<OrienterBase<_Graph, DirectionMap> > {
3.2367 + public:
3.2368 + typedef _Graph Graph;
3.2369 + typedef DigraphAdaptorExtender<
3.2370 + OrienterBase<_Graph, DirectionMap> > Parent;
3.2371 + typedef typename Parent::Arc Arc;
3.2372 + protected:
3.2373 + Orienter() { }
3.2374 + public:
3.2375 +
3.2376 + /// \brief Constructor of the adaptor
3.2377 + ///
3.2378 + /// Constructor of the adaptor
3.2379 + Orienter(Graph& graph, DirectionMap& direction) {
3.2380 + setGraph(graph);
3.2381 + setDirectionMap(direction);
3.2382 + }
3.2383 +
3.2384 + /// \brief Reverse arc
3.2385 + ///
3.2386 + /// It reverse the given arc. It simply negate the direction in the map.
3.2387 + void reverseArc(const Arc& a) {
3.2388 + Parent::reverseArc(a);
3.2389 + }
3.2390 + };
3.2391 +
3.2392 + /// \brief Just gives back a Orienter
3.2393 + ///
3.2394 + /// Just gives back a Orienter
3.2395 + template<typename Graph, typename DirectionMap>
3.2396 + Orienter<const Graph, DirectionMap>
3.2397 + orienter(const Graph& graph, DirectionMap& dm) {
3.2398 + return Orienter<const Graph, DirectionMap>(graph, dm);
3.2399 + }
3.2400 +
3.2401 + template<typename Graph, typename DirectionMap>
3.2402 + Orienter<const Graph, const DirectionMap>
3.2403 + orienter(const Graph& graph, const DirectionMap& dm) {
3.2404 + return Orienter<const Graph, const DirectionMap>(graph, dm);
3.2405 + }
3.2406 +
3.2407 + namespace _adaptor_bits {
3.2408 +
3.2409 + template<typename _Digraph,
3.2410 + typename _CapacityMap = typename _Digraph::template ArcMap<int>,
3.2411 + typename _FlowMap = _CapacityMap,
3.2412 + typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
3.2413 + class ResForwardFilter {
3.2414 + public:
3.2415 +
3.2416 + typedef _Digraph Digraph;
3.2417 + typedef _CapacityMap CapacityMap;
3.2418 + typedef _FlowMap FlowMap;
3.2419 + typedef _Tolerance Tolerance;
3.2420 +
3.2421 + typedef typename Digraph::Arc Key;
3.2422 + typedef bool Value;
3.2423 +
3.2424 + private:
3.2425 +
3.2426 + const CapacityMap* _capacity;
3.2427 + const FlowMap* _flow;
3.2428 + Tolerance _tolerance;
3.2429 + public:
3.2430 +
3.2431 + ResForwardFilter(const CapacityMap& capacity, const FlowMap& flow,
3.2432 + const Tolerance& tolerance = Tolerance())
3.2433 + : _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
3.2434 +
3.2435 + bool operator[](const typename Digraph::Arc& a) const {
3.2436 + return _tolerance.positive((*_capacity)[a] - (*_flow)[a]);
3.2437 + }
3.2438 + };
3.2439 +
3.2440 + template<typename _Digraph,
3.2441 + typename _CapacityMap = typename _Digraph::template ArcMap<int>,
3.2442 + typename _FlowMap = _CapacityMap,
3.2443 + typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
3.2444 + class ResBackwardFilter {
3.2445 + public:
3.2446 +
3.2447 + typedef _Digraph Digraph;
3.2448 + typedef _CapacityMap CapacityMap;
3.2449 + typedef _FlowMap FlowMap;
3.2450 + typedef _Tolerance Tolerance;
3.2451 +
3.2452 + typedef typename Digraph::Arc Key;
3.2453 + typedef bool Value;
3.2454 +
3.2455 + private:
3.2456 +
3.2457 + const CapacityMap* _capacity;
3.2458 + const FlowMap* _flow;
3.2459 + Tolerance _tolerance;
3.2460 +
3.2461 + public:
3.2462 +
3.2463 + ResBackwardFilter(const CapacityMap& capacity, const FlowMap& flow,
3.2464 + const Tolerance& tolerance = Tolerance())
3.2465 + : _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
3.2466 +
3.2467 + bool operator[](const typename Digraph::Arc& a) const {
3.2468 + return _tolerance.positive((*_flow)[a]);
3.2469 + }
3.2470 + };
3.2471 +
3.2472 + }
3.2473 +
3.2474 + /// \ingroup graph_adaptors
3.2475 + ///
3.2476 + /// \brief An adaptor for composing the residual graph for directed
3.2477 + /// flow and circulation problems.
3.2478 + ///
3.2479 + /// An adaptor for composing the residual graph for directed flow and
3.2480 + /// circulation problems. Let \f$ G=(V, A) \f$ be a directed graph
3.2481 + /// and let \f$ F \f$ be a number type. Let moreover \f$ f,c:A\to F \f$,
3.2482 + /// be functions on the arc-set.
3.2483 + ///
3.2484 + /// Then Residual implements the digraph structure with
3.2485 + /// node-set \f$ V \f$ and arc-set \f$ A_{forward}\cup A_{backward} \f$,
3.2486 + /// where \f$ A_{forward}=\{uv : uv\in A, f(uv)<c(uv)\} \f$ and
3.2487 + /// \f$ A_{backward}=\{vu : uv\in A, f(uv)>0\} \f$, i.e. the so
3.2488 + /// called residual graph. When we take the union
3.2489 + /// \f$ A_{forward}\cup A_{backward} \f$, multiplicities are counted,
3.2490 + /// i.e. if an arc is in both \f$ A_{forward} \f$ and
3.2491 + /// \f$ A_{backward} \f$, then in the adaptor it appears in both
3.2492 + /// orientation.
3.2493 + ///
3.2494 + /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
3.2495 + /// "Digraph concept". The type is implicitly const.
3.2496 + /// \tparam _CapacityMap An arc map of some numeric type, it defines
3.2497 + /// the capacities in the flow problem. The map is implicitly const.
3.2498 + /// \tparam _FlowMap An arc map of some numeric type, it defines
3.2499 + /// the capacities in the flow problem.
3.2500 + /// \tparam _Tolerance Handler for inexact computation.
3.2501 + template<typename _Digraph,
3.2502 + typename _CapacityMap = typename _Digraph::template ArcMap<int>,
3.2503 + typename _FlowMap = _CapacityMap,
3.2504 + typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
3.2505 + class Residual :
3.2506 + public FilterArcs<
3.2507 + Undirector<const _Digraph>,
3.2508 + typename Undirector<const _Digraph>::template CombinedArcMap<
3.2509 + _adaptor_bits::ResForwardFilter<const _Digraph, _CapacityMap,
3.2510 + _FlowMap, _Tolerance>,
3.2511 + _adaptor_bits::ResBackwardFilter<const _Digraph, _CapacityMap,
3.2512 + _FlowMap, _Tolerance> > >
3.2513 + {
3.2514 + public:
3.2515 +
3.2516 + typedef _Digraph Digraph;
3.2517 + typedef _CapacityMap CapacityMap;
3.2518 + typedef _FlowMap FlowMap;
3.2519 + typedef _Tolerance Tolerance;
3.2520 +
3.2521 + typedef typename CapacityMap::Value Value;
3.2522 + typedef Residual Adaptor;
3.2523 +
3.2524 + protected:
3.2525 +
3.2526 + typedef Undirector<const Digraph> Undirected;
3.2527 +
3.2528 + typedef _adaptor_bits::ResForwardFilter<const Digraph, CapacityMap,
3.2529 + FlowMap, Tolerance> ForwardFilter;
3.2530 +
3.2531 + typedef _adaptor_bits::ResBackwardFilter<const Digraph, CapacityMap,
3.2532 + FlowMap, Tolerance> BackwardFilter;
3.2533 +
3.2534 + typedef typename Undirected::
3.2535 + template CombinedArcMap<ForwardFilter, BackwardFilter> ArcFilter;
3.2536 +
3.2537 + typedef FilterArcs<Undirected, ArcFilter> Parent;
3.2538 +
3.2539 + const CapacityMap* _capacity;
3.2540 + FlowMap* _flow;
3.2541 +
3.2542 + Undirected _graph;
3.2543 + ForwardFilter _forward_filter;
3.2544 + BackwardFilter _backward_filter;
3.2545 + ArcFilter _arc_filter;
3.2546 +
3.2547 + public:
3.2548 +
3.2549 + /// \brief Constructor of the residual digraph.
3.2550 + ///
3.2551 + /// Constructor of the residual graph. The parameters are the digraph,
3.2552 + /// the flow map, the capacity map and a tolerance object.
3.2553 + Residual(const Digraph& digraph, const CapacityMap& capacity,
3.2554 + FlowMap& flow, const Tolerance& tolerance = Tolerance())
3.2555 + : Parent(), _capacity(&capacity), _flow(&flow), _graph(digraph),
3.2556 + _forward_filter(capacity, flow, tolerance),
3.2557 + _backward_filter(capacity, flow, tolerance),
3.2558 + _arc_filter(_forward_filter, _backward_filter)
3.2559 + {
3.2560 + Parent::setDigraph(_graph);
3.2561 + Parent::setArcFilterMap(_arc_filter);
3.2562 + }
3.2563 +
3.2564 + typedef typename Parent::Arc Arc;
3.2565 +
3.2566 + /// \brief Gives back the residual capacity of the arc.
3.2567 + ///
3.2568 + /// Gives back the residual capacity of the arc.
3.2569 + Value residualCapacity(const Arc& a) const {
3.2570 + if (Undirected::direction(a)) {
3.2571 + return (*_capacity)[a] - (*_flow)[a];
3.2572 + } else {
3.2573 + return (*_flow)[a];
3.2574 + }
3.2575 + }
3.2576 +
3.2577 + /// \brief Augment on the given arc in the residual graph.
3.2578 + ///
3.2579 + /// Augment on the given arc in the residual graph. It increase
3.2580 + /// or decrease the flow on the original arc depend on the direction
3.2581 + /// of the residual arc.
3.2582 + void augment(const Arc& a, const Value& v) const {
3.2583 + if (Undirected::direction(a)) {
3.2584 + _flow->set(a, (*_flow)[a] + v);
3.2585 + } else {
3.2586 + _flow->set(a, (*_flow)[a] - v);
3.2587 + }
3.2588 + }
3.2589 +
3.2590 + /// \brief Returns the direction of the arc.
3.2591 + ///
3.2592 + /// Returns true when the arc is same oriented as the original arc.
3.2593 + static bool forward(const Arc& a) {
3.2594 + return Undirected::direction(a);
3.2595 + }
3.2596 +
3.2597 + /// \brief Returns the direction of the arc.
3.2598 + ///
3.2599 + /// Returns true when the arc is opposite oriented as the original arc.
3.2600 + static bool backward(const Arc& a) {
3.2601 + return !Undirected::direction(a);
3.2602 + }
3.2603 +
3.2604 + /// \brief Gives back the forward oriented residual arc.
3.2605 + ///
3.2606 + /// Gives back the forward oriented residual arc.
3.2607 + static Arc forward(const typename Digraph::Arc& a) {
3.2608 + return Undirected::direct(a, true);
3.2609 + }
3.2610 +
3.2611 + /// \brief Gives back the backward oriented residual arc.
3.2612 + ///
3.2613 + /// Gives back the backward oriented residual arc.
3.2614 + static Arc backward(const typename Digraph::Arc& a) {
3.2615 + return Undirected::direct(a, false);
3.2616 + }
3.2617 +
3.2618 + /// \brief Residual capacity map.
3.2619 + ///
3.2620 + /// In generic residual graph the residual capacity can be obtained
3.2621 + /// as a map.
3.2622 + class ResidualCapacity {
3.2623 + protected:
3.2624 + const Adaptor* _adaptor;
3.2625 + public:
3.2626 + /// The Key type
3.2627 + typedef Arc Key;
3.2628 + /// The Value type
3.2629 + typedef typename _CapacityMap::Value Value;
3.2630 +
3.2631 + /// Constructor
3.2632 + ResidualCapacity(const Adaptor& adaptor) : _adaptor(&adaptor) {}
3.2633 +
3.2634 + /// \e
3.2635 + Value operator[](const Arc& a) const {
3.2636 + return _adaptor->residualCapacity(a);
3.2637 + }
3.2638 +
3.2639 + };
3.2640 +
3.2641 + };
3.2642 +
3.2643 + template <typename _Digraph>
3.2644 + class SplitNodesBase {
3.2645 + public:
3.2646 +
3.2647 + typedef _Digraph Digraph;
3.2648 + typedef DigraphAdaptorBase<const _Digraph> Parent;
3.2649 + typedef SplitNodesBase Adaptor;
3.2650 +
3.2651 + typedef typename Digraph::Node DigraphNode;
3.2652 + typedef typename Digraph::Arc DigraphArc;
3.2653 +
3.2654 + class Node;
3.2655 + class Arc;
3.2656 +
3.2657 + private:
3.2658 +
3.2659 + template <typename T> class NodeMapBase;
3.2660 + template <typename T> class ArcMapBase;
3.2661 +
3.2662 + public:
3.2663 +
3.2664 + class Node : public DigraphNode {
3.2665 + friend class SplitNodesBase;
3.2666 + template <typename T> friend class NodeMapBase;
3.2667 + private:
3.2668 +
3.2669 + bool _in;
3.2670 + Node(DigraphNode node, bool in)
3.2671 + : DigraphNode(node), _in(in) {}
3.2672 +
3.2673 + public:
3.2674 +
3.2675 + Node() {}
3.2676 + Node(Invalid) : DigraphNode(INVALID), _in(true) {}
3.2677 +
3.2678 + bool operator==(const Node& node) const {
3.2679 + return DigraphNode::operator==(node) && _in == node._in;
3.2680 + }
3.2681 +
3.2682 + bool operator!=(const Node& node) const {
3.2683 + return !(*this == node);
3.2684 + }
3.2685 +
3.2686 + bool operator<(const Node& node) const {
3.2687 + return DigraphNode::operator<(node) ||
3.2688 + (DigraphNode::operator==(node) && _in < node._in);
3.2689 + }
3.2690 + };
3.2691 +
3.2692 + class Arc {
3.2693 + friend class SplitNodesBase;
3.2694 + template <typename T> friend class ArcMapBase;
3.2695 + private:
3.2696 + typedef BiVariant<DigraphArc, DigraphNode> ArcImpl;
3.2697 +
3.2698 + explicit Arc(const DigraphArc& arc) : _item(arc) {}
3.2699 + explicit Arc(const DigraphNode& node) : _item(node) {}
3.2700 +
3.2701 + ArcImpl _item;
3.2702 +
3.2703 + public:
3.2704 + Arc() {}
3.2705 + Arc(Invalid) : _item(DigraphArc(INVALID)) {}
3.2706 +
3.2707 + bool operator==(const Arc& arc) const {
3.2708 + if (_item.firstState()) {
3.2709 + if (arc._item.firstState()) {
3.2710 + return _item.first() == arc._item.first();
3.2711 + }
3.2712 + } else {
3.2713 + if (arc._item.secondState()) {
3.2714 + return _item.second() == arc._item.second();
3.2715 + }
3.2716 + }
3.2717 + return false;
3.2718 + }
3.2719 +
3.2720 + bool operator!=(const Arc& arc) const {
3.2721 + return !(*this == arc);
3.2722 + }
3.2723 +
3.2724 + bool operator<(const Arc& arc) const {
3.2725 + if (_item.firstState()) {
3.2726 + if (arc._item.firstState()) {
3.2727 + return _item.first() < arc._item.first();
3.2728 + }
3.2729 + return false;
3.2730 + } else {
3.2731 + if (arc._item.secondState()) {
3.2732 + return _item.second() < arc._item.second();
3.2733 + }
3.2734 + return true;
3.2735 + }
3.2736 + }
3.2737 +
3.2738 + operator DigraphArc() const { return _item.first(); }
3.2739 + operator DigraphNode() const { return _item.second(); }
3.2740 +
3.2741 + };
3.2742 +
3.2743 + void first(Node& n) const {
3.2744 + _digraph->first(n);
3.2745 + n._in = true;
3.2746 + }
3.2747 +
3.2748 + void next(Node& n) const {
3.2749 + if (n._in) {
3.2750 + n._in = false;
3.2751 + } else {
3.2752 + n._in = true;
3.2753 + _digraph->next(n);
3.2754 + }
3.2755 + }
3.2756 +
3.2757 + void first(Arc& e) const {
3.2758 + e._item.setSecond();
3.2759 + _digraph->first(e._item.second());
3.2760 + if (e._item.second() == INVALID) {
3.2761 + e._item.setFirst();
3.2762 + _digraph->first(e._item.first());
3.2763 + }
3.2764 + }
3.2765 +
3.2766 + void next(Arc& e) const {
3.2767 + if (e._item.secondState()) {
3.2768 + _digraph->next(e._item.second());
3.2769 + if (e._item.second() == INVALID) {
3.2770 + e._item.setFirst();
3.2771 + _digraph->first(e._item.first());
3.2772 + }
3.2773 + } else {
3.2774 + _digraph->next(e._item.first());
3.2775 + }
3.2776 + }
3.2777 +
3.2778 + void firstOut(Arc& e, const Node& n) const {
3.2779 + if (n._in) {
3.2780 + e._item.setSecond(n);
3.2781 + } else {
3.2782 + e._item.setFirst();
3.2783 + _digraph->firstOut(e._item.first(), n);
3.2784 + }
3.2785 + }
3.2786 +
3.2787 + void nextOut(Arc& e) const {
3.2788 + if (!e._item.firstState()) {
3.2789 + e._item.setFirst(INVALID);
3.2790 + } else {
3.2791 + _digraph->nextOut(e._item.first());
3.2792 + }
3.2793 + }
3.2794 +
3.2795 + void firstIn(Arc& e, const Node& n) const {
3.2796 + if (!n._in) {
3.2797 + e._item.setSecond(n);
3.2798 + } else {
3.2799 + e._item.setFirst();
3.2800 + _digraph->firstIn(e._item.first(), n);
3.2801 + }
3.2802 + }
3.2803 +
3.2804 + void nextIn(Arc& e) const {
3.2805 + if (!e._item.firstState()) {
3.2806 + e._item.setFirst(INVALID);
3.2807 + } else {
3.2808 + _digraph->nextIn(e._item.first());
3.2809 + }
3.2810 + }
3.2811 +
3.2812 + Node source(const Arc& e) const {
3.2813 + if (e._item.firstState()) {
3.2814 + return Node(_digraph->source(e._item.first()), false);
3.2815 + } else {
3.2816 + return Node(e._item.second(), true);
3.2817 + }
3.2818 + }
3.2819 +
3.2820 + Node target(const Arc& e) const {
3.2821 + if (e._item.firstState()) {
3.2822 + return Node(_digraph->target(e._item.first()), true);
3.2823 + } else {
3.2824 + return Node(e._item.second(), false);
3.2825 + }
3.2826 + }
3.2827 +
3.2828 + int id(const Node& n) const {
3.2829 + return (_digraph->id(n) << 1) | (n._in ? 0 : 1);
3.2830 + }
3.2831 + Node nodeFromId(int ix) const {
3.2832 + return Node(_digraph->nodeFromId(ix >> 1), (ix & 1) == 0);
3.2833 + }
3.2834 + int maxNodeId() const {
3.2835 + return 2 * _digraph->maxNodeId() + 1;
3.2836 + }
3.2837 +
3.2838 + int id(const Arc& e) const {
3.2839 + if (e._item.firstState()) {
3.2840 + return _digraph->id(e._item.first()) << 1;
3.2841 + } else {
3.2842 + return (_digraph->id(e._item.second()) << 1) | 1;
3.2843 + }
3.2844 + }
3.2845 + Arc arcFromId(int ix) const {
3.2846 + if ((ix & 1) == 0) {
3.2847 + return Arc(_digraph->arcFromId(ix >> 1));
3.2848 + } else {
3.2849 + return Arc(_digraph->nodeFromId(ix >> 1));
3.2850 + }
3.2851 + }
3.2852 + int maxArcId() const {
3.2853 + return std::max(_digraph->maxNodeId() << 1,
3.2854 + (_digraph->maxArcId() << 1) | 1);
3.2855 + }
3.2856 +
3.2857 + static bool inNode(const Node& n) {
3.2858 + return n._in;
3.2859 + }
3.2860 +
3.2861 + static bool outNode(const Node& n) {
3.2862 + return !n._in;
3.2863 + }
3.2864 +
3.2865 + static bool origArc(const Arc& e) {
3.2866 + return e._item.firstState();
3.2867 + }
3.2868 +
3.2869 + static bool bindArc(const Arc& e) {
3.2870 + return e._item.secondState();
3.2871 + }
3.2872 +
3.2873 + static Node inNode(const DigraphNode& n) {
3.2874 + return Node(n, true);
3.2875 + }
3.2876 +
3.2877 + static Node outNode(const DigraphNode& n) {
3.2878 + return Node(n, false);
3.2879 + }
3.2880 +
3.2881 + static Arc arc(const DigraphNode& n) {
3.2882 + return Arc(n);
3.2883 + }
3.2884 +
3.2885 + static Arc arc(const DigraphArc& e) {
3.2886 + return Arc(e);
3.2887 + }
3.2888 +
3.2889 + typedef True NodeNumTag;
3.2890 +
3.2891 + int nodeNum() const {
3.2892 + return 2 * countNodes(*_digraph);
3.2893 + }
3.2894 +
3.2895 + typedef True EdgeNumTag;
3.2896 + int arcNum() const {
3.2897 + return countArcs(*_digraph) + countNodes(*_digraph);
3.2898 + }
3.2899 +
3.2900 + typedef True FindEdgeTag;
3.2901 + Arc findArc(const Node& u, const Node& v,
3.2902 + const Arc& prev = INVALID) const {
3.2903 + if (inNode(u)) {
3.2904 + if (outNode(v)) {
3.2905 + if (static_cast<const DigraphNode&>(u) ==
3.2906 + static_cast<const DigraphNode&>(v) && prev == INVALID) {
3.2907 + return Arc(u);
3.2908 + }
3.2909 + }
3.2910 + } else {
3.2911 + if (inNode(v)) {
3.2912 + return Arc(::lemon::findArc(*_digraph, u, v, prev));
3.2913 + }
3.2914 + }
3.2915 + return INVALID;
3.2916 + }
3.2917 +
3.2918 + private:
3.2919 +
3.2920 + template <typename _Value>
3.2921 + class NodeMapBase
3.2922 + : public MapTraits<typename Parent::template NodeMap<_Value> > {
3.2923 + typedef typename Parent::template NodeMap<_Value> NodeImpl;
3.2924 + public:
3.2925 + typedef Node Key;
3.2926 + typedef _Value Value;
3.2927 +
3.2928 + NodeMapBase(const Adaptor& adaptor)
3.2929 + : _in_map(*adaptor._digraph), _out_map(*adaptor._digraph) {}
3.2930 + NodeMapBase(const Adaptor& adaptor, const Value& value)
3.2931 + : _in_map(*adaptor._digraph, value),
3.2932 + _out_map(*adaptor._digraph, value) {}
3.2933 +
3.2934 + void set(const Node& key, const Value& val) {
3.2935 + if (Adaptor::inNode(key)) { _in_map.set(key, val); }
3.2936 + else {_out_map.set(key, val); }
3.2937 + }
3.2938 +
3.2939 + typename MapTraits<NodeImpl>::ReturnValue
3.2940 + operator[](const Node& key) {
3.2941 + if (Adaptor::inNode(key)) { return _in_map[key]; }
3.2942 + else { return _out_map[key]; }
3.2943 + }
3.2944 +
3.2945 + typename MapTraits<NodeImpl>::ConstReturnValue
3.2946 + operator[](const Node& key) const {
3.2947 + if (Adaptor::inNode(key)) { return _in_map[key]; }
3.2948 + else { return _out_map[key]; }
3.2949 + }
3.2950 +
3.2951 + private:
3.2952 + NodeImpl _in_map, _out_map;
3.2953 + };
3.2954 +
3.2955 + template <typename _Value>
3.2956 + class ArcMapBase
3.2957 + : public MapTraits<typename Parent::template ArcMap<_Value> > {
3.2958 + typedef typename Parent::template ArcMap<_Value> ArcImpl;
3.2959 + typedef typename Parent::template NodeMap<_Value> NodeImpl;
3.2960 + public:
3.2961 + typedef Arc Key;
3.2962 + typedef _Value Value;
3.2963 +
3.2964 + ArcMapBase(const Adaptor& adaptor)
3.2965 + : _arc_map(*adaptor._digraph), _node_map(*adaptor._digraph) {}
3.2966 + ArcMapBase(const Adaptor& adaptor, const Value& value)
3.2967 + : _arc_map(*adaptor._digraph, value),
3.2968 + _node_map(*adaptor._digraph, value) {}
3.2969 +
3.2970 + void set(const Arc& key, const Value& val) {
3.2971 + if (Adaptor::origArc(key)) {
3.2972 + _arc_map.set(key._item.first(), val);
3.2973 + } else {
3.2974 + _node_map.set(key._item.second(), val);
3.2975 + }
3.2976 + }
3.2977 +
3.2978 + typename MapTraits<ArcImpl>::ReturnValue
3.2979 + operator[](const Arc& key) {
3.2980 + if (Adaptor::origArc(key)) {
3.2981 + return _arc_map[key._item.first()];
3.2982 + } else {
3.2983 + return _node_map[key._item.second()];
3.2984 + }
3.2985 + }
3.2986 +
3.2987 + typename MapTraits<ArcImpl>::ConstReturnValue
3.2988 + operator[](const Arc& key) const {
3.2989 + if (Adaptor::origArc(key)) {
3.2990 + return _arc_map[key._item.first()];
3.2991 + } else {
3.2992 + return _node_map[key._item.second()];
3.2993 + }
3.2994 + }
3.2995 +
3.2996 + private:
3.2997 + ArcImpl _arc_map;
3.2998 + NodeImpl _node_map;
3.2999 + };
3.3000 +
3.3001 + public:
3.3002 +
3.3003 + template <typename _Value>
3.3004 + class NodeMap
3.3005 + : public SubMapExtender<Adaptor, NodeMapBase<_Value> >
3.3006 + {
3.3007 + public:
3.3008 + typedef _Value Value;
3.3009 + typedef SubMapExtender<Adaptor, NodeMapBase<Value> > Parent;
3.3010 +
3.3011 + NodeMap(const Adaptor& adaptor)
3.3012 + : Parent(adaptor) {}
3.3013 +
3.3014 + NodeMap(const Adaptor& adaptor, const Value& value)
3.3015 + : Parent(adaptor, value) {}
3.3016 +
3.3017 + private:
3.3018 + NodeMap& operator=(const NodeMap& cmap) {
3.3019 + return operator=<NodeMap>(cmap);
3.3020 + }
3.3021 +
3.3022 + template <typename CMap>
3.3023 + NodeMap& operator=(const CMap& cmap) {
3.3024 + Parent::operator=(cmap);
3.3025 + return *this;
3.3026 + }
3.3027 + };
3.3028 +
3.3029 + template <typename _Value>
3.3030 + class ArcMap
3.3031 + : public SubMapExtender<Adaptor, ArcMapBase<_Value> >
3.3032 + {
3.3033 + public:
3.3034 + typedef _Value Value;
3.3035 + typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
3.3036 +
3.3037 + ArcMap(const Adaptor& adaptor)
3.3038 + : Parent(adaptor) {}
3.3039 +
3.3040 + ArcMap(const Adaptor& adaptor, const Value& value)
3.3041 + : Parent(adaptor, value) {}
3.3042 +
3.3043 + private:
3.3044 + ArcMap& operator=(const ArcMap& cmap) {
3.3045 + return operator=<ArcMap>(cmap);
3.3046 + }
3.3047 +
3.3048 + template <typename CMap>
3.3049 + ArcMap& operator=(const CMap& cmap) {
3.3050 + Parent::operator=(cmap);
3.3051 + return *this;
3.3052 + }
3.3053 + };
3.3054 +
3.3055 + protected:
3.3056 +
3.3057 + SplitNodesBase() : _digraph(0) {}
3.3058 +
3.3059 + Digraph* _digraph;
3.3060 +
3.3061 + void setDigraph(Digraph& digraph) {
3.3062 + _digraph = &digraph;
3.3063 + }
3.3064 +
3.3065 + };
3.3066 +
3.3067 + /// \ingroup graph_adaptors
3.3068 + ///
3.3069 + /// \brief Split the nodes of a directed graph
3.3070 + ///
3.3071 + /// The SplitNodes adaptor splits each node into an in-node and an
3.3072 + /// out-node. Formaly, the adaptor replaces each \f$ u \f$ node in
3.3073 + /// the digraph with two nodes(namely node \f$ u_{in} \f$ and node
3.3074 + /// \f$ u_{out} \f$). If there is a \f$ (v, u) \f$ arc in the
3.3075 + /// original digraph the new target of the arc will be \f$ u_{in} \f$
3.3076 + /// and similarly the source of the original \f$ (u, v) \f$ arc
3.3077 + /// will be \f$ u_{out} \f$. The adaptor will add for each node in
3.3078 + /// the original digraph an additional arc which connects
3.3079 + /// \f$ (u_{in}, u_{out}) \f$.
3.3080 + ///
3.3081 + /// The aim of this class is to run algorithm with node costs if the
3.3082 + /// algorithm can use directly just arc costs. In this case we should use
3.3083 + /// a \c SplitNodes and set the node cost of the graph to the
3.3084 + /// bind arc in the adapted graph.
3.3085 + ///
3.3086 + /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
3.3087 + /// "Digraph concept". The type can be specified to be const.
3.3088 + template <typename _Digraph>
3.3089 + class SplitNodes
3.3090 + : public DigraphAdaptorExtender<SplitNodesBase<_Digraph> > {
3.3091 + public:
3.3092 + typedef _Digraph Digraph;
3.3093 + typedef DigraphAdaptorExtender<SplitNodesBase<Digraph> > Parent;
3.3094 +
3.3095 + typedef typename Digraph::Node DigraphNode;
3.3096 + typedef typename Digraph::Arc DigraphArc;
3.3097 +
3.3098 + typedef typename Parent::Node Node;
3.3099 + typedef typename Parent::Arc Arc;
3.3100 +
3.3101 + /// \brief Constructor of the adaptor.
3.3102 + ///
3.3103 + /// Constructor of the adaptor.
3.3104 + SplitNodes(Digraph& g) {
3.3105 + Parent::setDigraph(g);
3.3106 + }
3.3107 +
3.3108 + /// \brief Returns true when the node is in-node.
3.3109 + ///
3.3110 + /// Returns true when the node is in-node.
3.3111 + static bool inNode(const Node& n) {
3.3112 + return Parent::inNode(n);
3.3113 + }
3.3114 +
3.3115 + /// \brief Returns true when the node is out-node.
3.3116 + ///
3.3117 + /// Returns true when the node is out-node.
3.3118 + static bool outNode(const Node& n) {
3.3119 + return Parent::outNode(n);
3.3120 + }
3.3121 +
3.3122 + /// \brief Returns true when the arc is arc in the original digraph.
3.3123 + ///
3.3124 + /// Returns true when the arc is arc in the original digraph.
3.3125 + static bool origArc(const Arc& a) {
3.3126 + return Parent::origArc(a);
3.3127 + }
3.3128 +
3.3129 + /// \brief Returns true when the arc binds an in-node and an out-node.
3.3130 + ///
3.3131 + /// Returns true when the arc binds an in-node and an out-node.
3.3132 + static bool bindArc(const Arc& a) {
3.3133 + return Parent::bindArc(a);
3.3134 + }
3.3135 +
3.3136 + /// \brief Gives back the in-node created from the \c node.
3.3137 + ///
3.3138 + /// Gives back the in-node created from the \c node.
3.3139 + static Node inNode(const DigraphNode& n) {
3.3140 + return Parent::inNode(n);
3.3141 + }
3.3142 +
3.3143 + /// \brief Gives back the out-node created from the \c node.
3.3144 + ///
3.3145 + /// Gives back the out-node created from the \c node.
3.3146 + static Node outNode(const DigraphNode& n) {
3.3147 + return Parent::outNode(n);
3.3148 + }
3.3149 +
3.3150 + /// \brief Gives back the arc binds the two part of the node.
3.3151 + ///
3.3152 + /// Gives back the arc binds the two part of the node.
3.3153 + static Arc arc(const DigraphNode& n) {
3.3154 + return Parent::arc(n);
3.3155 + }
3.3156 +
3.3157 + /// \brief Gives back the arc of the original arc.
3.3158 + ///
3.3159 + /// Gives back the arc of the original arc.
3.3160 + static Arc arc(const DigraphArc& a) {
3.3161 + return Parent::arc(a);
3.3162 + }
3.3163 +
3.3164 + /// \brief NodeMap combined from two original NodeMap
3.3165 + ///
3.3166 + /// This class adapt two of the original digraph NodeMap to
3.3167 + /// get a node map on the adapted digraph.
3.3168 + template <typename InNodeMap, typename OutNodeMap>
3.3169 + class CombinedNodeMap {
3.3170 + public:
3.3171 +
3.3172 + typedef Node Key;
3.3173 + typedef typename InNodeMap::Value Value;
3.3174 +
3.3175 + /// \brief Constructor
3.3176 + ///
3.3177 + /// Constructor.
3.3178 + CombinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map)
3.3179 + : _in_map(in_map), _out_map(out_map) {}
3.3180 +
3.3181 + /// \brief The subscript operator.
3.3182 + ///
3.3183 + /// The subscript operator.
3.3184 + Value& operator[](const Key& key) {
3.3185 + if (Parent::inNode(key)) {
3.3186 + return _in_map[key];
3.3187 + } else {
3.3188 + return _out_map[key];
3.3189 + }
3.3190 + }
3.3191 +
3.3192 + /// \brief The const subscript operator.
3.3193 + ///
3.3194 + /// The const subscript operator.
3.3195 + Value operator[](const Key& key) const {
3.3196 + if (Parent::inNode(key)) {
3.3197 + return _in_map[key];
3.3198 + } else {
3.3199 + return _out_map[key];
3.3200 + }
3.3201 + }
3.3202 +
3.3203 + /// \brief The setter function of the map.
3.3204 + ///
3.3205 + /// The setter function of the map.
3.3206 + void set(const Key& key, const Value& value) {
3.3207 + if (Parent::inNode(key)) {
3.3208 + _in_map.set(key, value);
3.3209 + } else {
3.3210 + _out_map.set(key, value);
3.3211 + }
3.3212 + }
3.3213 +
3.3214 + private:
3.3215 +
3.3216 + InNodeMap& _in_map;
3.3217 + OutNodeMap& _out_map;
3.3218 +
3.3219 + };
3.3220 +
3.3221 +
3.3222 + /// \brief Just gives back a combined node map
3.3223 + ///
3.3224 + /// Just gives back a combined node map
3.3225 + template <typename InNodeMap, typename OutNodeMap>
3.3226 + static CombinedNodeMap<InNodeMap, OutNodeMap>
3.3227 + combinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) {
3.3228 + return CombinedNodeMap<InNodeMap, OutNodeMap>(in_map, out_map);
3.3229 + }
3.3230 +
3.3231 + template <typename InNodeMap, typename OutNodeMap>
3.3232 + static CombinedNodeMap<const InNodeMap, OutNodeMap>
3.3233 + combinedNodeMap(const InNodeMap& in_map, OutNodeMap& out_map) {
3.3234 + return CombinedNodeMap<const InNodeMap, OutNodeMap>(in_map, out_map);
3.3235 + }
3.3236 +
3.3237 + template <typename InNodeMap, typename OutNodeMap>
3.3238 + static CombinedNodeMap<InNodeMap, const OutNodeMap>
3.3239 + combinedNodeMap(InNodeMap& in_map, const OutNodeMap& out_map) {
3.3240 + return CombinedNodeMap<InNodeMap, const OutNodeMap>(in_map, out_map);
3.3241 + }
3.3242 +
3.3243 + template <typename InNodeMap, typename OutNodeMap>
3.3244 + static CombinedNodeMap<const InNodeMap, const OutNodeMap>
3.3245 + combinedNodeMap(const InNodeMap& in_map, const OutNodeMap& out_map) {
3.3246 + return CombinedNodeMap<const InNodeMap,
3.3247 + const OutNodeMap>(in_map, out_map);
3.3248 + }
3.3249 +
3.3250 + /// \brief ArcMap combined from an original ArcMap and a NodeMap
3.3251 + ///
3.3252 + /// This class adapt an original ArcMap and a NodeMap to get an
3.3253 + /// arc map on the adapted digraph
3.3254 + template <typename DigraphArcMap, typename DigraphNodeMap>
3.3255 + class CombinedArcMap {
3.3256 + public:
3.3257 +
3.3258 + typedef Arc Key;
3.3259 + typedef typename DigraphArcMap::Value Value;
3.3260 +
3.3261 + /// \brief Constructor
3.3262 + ///
3.3263 + /// Constructor.
3.3264 + CombinedArcMap(DigraphArcMap& arc_map, DigraphNodeMap& node_map)
3.3265 + : _arc_map(arc_map), _node_map(node_map) {}
3.3266 +
3.3267 + /// \brief The subscript operator.
3.3268 + ///
3.3269 + /// The subscript operator.
3.3270 + void set(const Arc& arc, const Value& val) {
3.3271 + if (Parent::origArc(arc)) {
3.3272 + _arc_map.set(arc, val);
3.3273 + } else {
3.3274 + _node_map.set(arc, val);
3.3275 + }
3.3276 + }
3.3277 +
3.3278 + /// \brief The const subscript operator.
3.3279 + ///
3.3280 + /// The const subscript operator.
3.3281 + Value operator[](const Key& arc) const {
3.3282 + if (Parent::origArc(arc)) {
3.3283 + return _arc_map[arc];
3.3284 + } else {
3.3285 + return _node_map[arc];
3.3286 + }
3.3287 + }
3.3288 +
3.3289 + /// \brief The const subscript operator.
3.3290 + ///
3.3291 + /// The const subscript operator.
3.3292 + Value& operator[](const Key& arc) {
3.3293 + if (Parent::origArc(arc)) {
3.3294 + return _arc_map[arc];
3.3295 + } else {
3.3296 + return _node_map[arc];
3.3297 + }
3.3298 + }
3.3299 +
3.3300 + private:
3.3301 + DigraphArcMap& _arc_map;
3.3302 + DigraphNodeMap& _node_map;
3.3303 + };
3.3304 +
3.3305 + /// \brief Just gives back a combined arc map
3.3306 + ///
3.3307 + /// Just gives back a combined arc map
3.3308 + template <typename DigraphArcMap, typename DigraphNodeMap>
3.3309 + static CombinedArcMap<DigraphArcMap, DigraphNodeMap>
3.3310 + combinedArcMap(DigraphArcMap& arc_map, DigraphNodeMap& node_map) {
3.3311 + return CombinedArcMap<DigraphArcMap, DigraphNodeMap>(arc_map, node_map);
3.3312 + }
3.3313 +
3.3314 + template <typename DigraphArcMap, typename DigraphNodeMap>
3.3315 + static CombinedArcMap<const DigraphArcMap, DigraphNodeMap>
3.3316 + combinedArcMap(const DigraphArcMap& arc_map, DigraphNodeMap& node_map) {
3.3317 + return CombinedArcMap<const DigraphArcMap,
3.3318 + DigraphNodeMap>(arc_map, node_map);
3.3319 + }
3.3320 +
3.3321 + template <typename DigraphArcMap, typename DigraphNodeMap>
3.3322 + static CombinedArcMap<DigraphArcMap, const DigraphNodeMap>
3.3323 + combinedArcMap(DigraphArcMap& arc_map, const DigraphNodeMap& node_map) {
3.3324 + return CombinedArcMap<DigraphArcMap,
3.3325 + const DigraphNodeMap>(arc_map, node_map);
3.3326 + }
3.3327 +
3.3328 + template <typename DigraphArcMap, typename DigraphNodeMap>
3.3329 + static CombinedArcMap<const DigraphArcMap, const DigraphNodeMap>
3.3330 + combinedArcMap(const DigraphArcMap& arc_map,
3.3331 + const DigraphNodeMap& node_map) {
3.3332 + return CombinedArcMap<const DigraphArcMap,
3.3333 + const DigraphNodeMap>(arc_map, node_map);
3.3334 + }
3.3335 +
3.3336 + };
3.3337 +
3.3338 + /// \brief Just gives back a node splitter
3.3339 + ///
3.3340 + /// Just gives back a node splitter
3.3341 + template<typename Digraph>
3.3342 + SplitNodes<Digraph>
3.3343 + splitNodes(const Digraph& digraph) {
3.3344 + return SplitNodes<Digraph>(digraph);
3.3345 + }
3.3346 +
3.3347 +
3.3348 +} //namespace lemon
3.3349 +
3.3350 +#endif //LEMON_ADAPTORS_H
4.1 --- a/lemon/bits/graph_adaptor_extender.h Sun Nov 30 19:00:30 2008 +0100
4.2 +++ b/lemon/bits/graph_adaptor_extender.h Sun Nov 30 19:18:32 2008 +0100
4.3 @@ -1,6 +1,6 @@
4.4 -/* -*- C++ -*-
4.5 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
4.6 *
4.7 - * This file is a part of LEMON, a generic C++ optimization library
4.8 + * This file is a part of LEMON, a generic C++ optimization library.
4.9 *
4.10 * Copyright (C) 2003-2008
4.11 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
4.12 @@ -24,15 +24,8 @@
4.13
4.14 #include <lemon/bits/default_map.h>
4.15
4.16 -
4.17 -///\ingroup digraphbits
4.18 -///\file
4.19 -///\brief Extenders for the digraph adaptor types
4.20 namespace lemon {
4.21
4.22 - /// \ingroup digraphbits
4.23 - ///
4.24 - /// \brief Extender for the DigraphAdaptors
4.25 template <typename _Digraph>
4.26 class DigraphAdaptorExtender : public _Digraph {
4.27 public:
4.28 @@ -64,14 +57,14 @@
4.29
4.30 Node oppositeNode(const Node &n, const Arc &e) const {
4.31 if (n == Parent::source(e))
4.32 - return Parent::target(e);
4.33 + return Parent::target(e);
4.34 else if(n==Parent::target(e))
4.35 - return Parent::source(e);
4.36 + return Parent::source(e);
4.37 else
4.38 - return INVALID;
4.39 + return INVALID;
4.40 }
4.41
4.42 - class NodeIt : public Node {
4.43 + class NodeIt : public Node {
4.44 const Adaptor* _adaptor;
4.45 public:
4.46
4.47 @@ -80,21 +73,21 @@
4.48 NodeIt(Invalid i) : Node(i) { }
4.49
4.50 explicit NodeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
4.51 - _adaptor->first(static_cast<Node&>(*this));
4.52 + _adaptor->first(static_cast<Node&>(*this));
4.53 }
4.54
4.55 - NodeIt(const Adaptor& adaptor, const Node& node)
4.56 - : Node(node), _adaptor(&adaptor) {}
4.57 + NodeIt(const Adaptor& adaptor, const Node& node)
4.58 + : Node(node), _adaptor(&adaptor) {}
4.59
4.60 - NodeIt& operator++() {
4.61 - _adaptor->next(*this);
4.62 - return *this;
4.63 + NodeIt& operator++() {
4.64 + _adaptor->next(*this);
4.65 + return *this;
4.66 }
4.67
4.68 };
4.69
4.70
4.71 - class ArcIt : public Arc {
4.72 + class ArcIt : public Arc {
4.73 const Adaptor* _adaptor;
4.74 public:
4.75
4.76 @@ -103,21 +96,21 @@
4.77 ArcIt(Invalid i) : Arc(i) { }
4.78
4.79 explicit ArcIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
4.80 - _adaptor->first(static_cast<Arc&>(*this));
4.81 + _adaptor->first(static_cast<Arc&>(*this));
4.82 }
4.83
4.84 - ArcIt(const Adaptor& adaptor, const Arc& e) :
4.85 - Arc(e), _adaptor(&adaptor) { }
4.86 + ArcIt(const Adaptor& adaptor, const Arc& e) :
4.87 + Arc(e), _adaptor(&adaptor) { }
4.88
4.89 - ArcIt& operator++() {
4.90 - _adaptor->next(*this);
4.91 - return *this;
4.92 + ArcIt& operator++() {
4.93 + _adaptor->next(*this);
4.94 + return *this;
4.95 }
4.96
4.97 };
4.98
4.99
4.100 - class OutArcIt : public Arc {
4.101 + class OutArcIt : public Arc {
4.102 const Adaptor* _adaptor;
4.103 public:
4.104
4.105 @@ -125,23 +118,23 @@
4.106
4.107 OutArcIt(Invalid i) : Arc(i) { }
4.108
4.109 - OutArcIt(const Adaptor& adaptor, const Node& node)
4.110 - : _adaptor(&adaptor) {
4.111 - _adaptor->firstOut(*this, node);
4.112 + OutArcIt(const Adaptor& adaptor, const Node& node)
4.113 + : _adaptor(&adaptor) {
4.114 + _adaptor->firstOut(*this, node);
4.115 }
4.116
4.117 - OutArcIt(const Adaptor& adaptor, const Arc& arc)
4.118 - : Arc(arc), _adaptor(&adaptor) {}
4.119 + OutArcIt(const Adaptor& adaptor, const Arc& arc)
4.120 + : Arc(arc), _adaptor(&adaptor) {}
4.121
4.122 - OutArcIt& operator++() {
4.123 - _adaptor->nextOut(*this);
4.124 - return *this;
4.125 + OutArcIt& operator++() {
4.126 + _adaptor->nextOut(*this);
4.127 + return *this;
4.128 }
4.129
4.130 };
4.131
4.132
4.133 - class InArcIt : public Arc {
4.134 + class InArcIt : public Arc {
4.135 const Adaptor* _adaptor;
4.136 public:
4.137
4.138 @@ -149,45 +142,31 @@
4.139
4.140 InArcIt(Invalid i) : Arc(i) { }
4.141
4.142 - InArcIt(const Adaptor& adaptor, const Node& node)
4.143 - : _adaptor(&adaptor) {
4.144 - _adaptor->firstIn(*this, node);
4.145 + InArcIt(const Adaptor& adaptor, const Node& node)
4.146 + : _adaptor(&adaptor) {
4.147 + _adaptor->firstIn(*this, node);
4.148 }
4.149
4.150 - InArcIt(const Adaptor& adaptor, const Arc& arc) :
4.151 - Arc(arc), _adaptor(&adaptor) {}
4.152 + InArcIt(const Adaptor& adaptor, const Arc& arc) :
4.153 + Arc(arc), _adaptor(&adaptor) {}
4.154
4.155 - InArcIt& operator++() {
4.156 - _adaptor->nextIn(*this);
4.157 - return *this;
4.158 + InArcIt& operator++() {
4.159 + _adaptor->nextIn(*this);
4.160 + return *this;
4.161 }
4.162
4.163 };
4.164
4.165 - /// \brief Base node of the iterator
4.166 - ///
4.167 - /// Returns the base node (ie. the source in this case) of the iterator
4.168 Node baseNode(const OutArcIt &e) const {
4.169 return Parent::source(e);
4.170 }
4.171 - /// \brief Running node of the iterator
4.172 - ///
4.173 - /// Returns the running node (ie. the target in this case) of the
4.174 - /// iterator
4.175 Node runningNode(const OutArcIt &e) const {
4.176 return Parent::target(e);
4.177 }
4.178
4.179 - /// \brief Base node of the iterator
4.180 - ///
4.181 - /// Returns the base node (ie. the target in this case) of the iterator
4.182 Node baseNode(const InArcIt &e) const {
4.183 return Parent::target(e);
4.184 }
4.185 - /// \brief Running node of the iterator
4.186 - ///
4.187 - /// Returns the running node (ie. the source in this case) of the
4.188 - /// iterator
4.189 Node runningNode(const InArcIt &e) const {
4.190 return Parent::source(e);
4.191 }
4.192 @@ -198,10 +177,10 @@
4.193 /// \ingroup digraphbits
4.194 ///
4.195 /// \brief Extender for the GraphAdaptors
4.196 - template <typename _Graph>
4.197 + template <typename _Graph>
4.198 class GraphAdaptorExtender : public _Graph {
4.199 public:
4.200 -
4.201 +
4.202 typedef _Graph Parent;
4.203 typedef _Graph Graph;
4.204 typedef GraphAdaptorExtender Adaptor;
4.205 @@ -210,7 +189,7 @@
4.206 typedef typename Parent::Arc Arc;
4.207 typedef typename Parent::Edge Edge;
4.208
4.209 - // Graph extension
4.210 + // Graph extension
4.211
4.212 int maxId(Node) const {
4.213 return Parent::maxNodeId();
4.214 @@ -238,11 +217,11 @@
4.215
4.216 Node oppositeNode(const Node &n, const Edge &e) const {
4.217 if( n == Parent::u(e))
4.218 - return Parent::v(e);
4.219 + return Parent::v(e);
4.220 else if( n == Parent::v(e))
4.221 - return Parent::u(e);
4.222 + return Parent::u(e);
4.223 else
4.224 - return INVALID;
4.225 + return INVALID;
4.226 }
4.227
4.228 Arc oppositeArc(const Arc &a) const {
4.229 @@ -255,7 +234,7 @@
4.230 }
4.231
4.232
4.233 - class NodeIt : public Node {
4.234 + class NodeIt : public Node {
4.235 const Adaptor* _adaptor;
4.236 public:
4.237
4.238 @@ -264,21 +243,21 @@
4.239 NodeIt(Invalid i) : Node(i) { }
4.240
4.241 explicit NodeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
4.242 - _adaptor->first(static_cast<Node&>(*this));
4.243 + _adaptor->first(static_cast<Node&>(*this));
4.244 }
4.245
4.246 - NodeIt(const Adaptor& adaptor, const Node& node)
4.247 - : Node(node), _adaptor(&adaptor) {}
4.248 + NodeIt(const Adaptor& adaptor, const Node& node)
4.249 + : Node(node), _adaptor(&adaptor) {}
4.250
4.251 - NodeIt& operator++() {
4.252 - _adaptor->next(*this);
4.253 - return *this;
4.254 + NodeIt& operator++() {
4.255 + _adaptor->next(*this);
4.256 + return *this;
4.257 }
4.258
4.259 };
4.260
4.261
4.262 - class ArcIt : public Arc {
4.263 + class ArcIt : public Arc {
4.264 const Adaptor* _adaptor;
4.265 public:
4.266
4.267 @@ -287,21 +266,21 @@
4.268 ArcIt(Invalid i) : Arc(i) { }
4.269
4.270 explicit ArcIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
4.271 - _adaptor->first(static_cast<Arc&>(*this));
4.272 + _adaptor->first(static_cast<Arc&>(*this));
4.273 }
4.274
4.275 - ArcIt(const Adaptor& adaptor, const Arc& e) :
4.276 - Arc(e), _adaptor(&adaptor) { }
4.277 + ArcIt(const Adaptor& adaptor, const Arc& e) :
4.278 + Arc(e), _adaptor(&adaptor) { }
4.279
4.280 - ArcIt& operator++() {
4.281 - _adaptor->next(*this);
4.282 - return *this;
4.283 + ArcIt& operator++() {
4.284 + _adaptor->next(*this);
4.285 + return *this;
4.286 }
4.287
4.288 };
4.289
4.290
4.291 - class OutArcIt : public Arc {
4.292 + class OutArcIt : public Arc {
4.293 const Adaptor* _adaptor;
4.294 public:
4.295
4.296 @@ -309,23 +288,23 @@
4.297
4.298 OutArcIt(Invalid i) : Arc(i) { }
4.299
4.300 - OutArcIt(const Adaptor& adaptor, const Node& node)
4.301 - : _adaptor(&adaptor) {
4.302 - _adaptor->firstOut(*this, node);
4.303 + OutArcIt(const Adaptor& adaptor, const Node& node)
4.304 + : _adaptor(&adaptor) {
4.305 + _adaptor->firstOut(*this, node);
4.306 }
4.307
4.308 - OutArcIt(const Adaptor& adaptor, const Arc& arc)
4.309 - : Arc(arc), _adaptor(&adaptor) {}
4.310 + OutArcIt(const Adaptor& adaptor, const Arc& arc)
4.311 + : Arc(arc), _adaptor(&adaptor) {}
4.312
4.313 - OutArcIt& operator++() {
4.314 - _adaptor->nextOut(*this);
4.315 - return *this;
4.316 + OutArcIt& operator++() {
4.317 + _adaptor->nextOut(*this);
4.318 + return *this;
4.319 }
4.320
4.321 };
4.322
4.323
4.324 - class InArcIt : public Arc {
4.325 + class InArcIt : public Arc {
4.326 const Adaptor* _adaptor;
4.327 public:
4.328
4.329 @@ -333,22 +312,22 @@
4.330
4.331 InArcIt(Invalid i) : Arc(i) { }
4.332
4.333 - InArcIt(const Adaptor& adaptor, const Node& node)
4.334 - : _adaptor(&adaptor) {
4.335 - _adaptor->firstIn(*this, node);
4.336 + InArcIt(const Adaptor& adaptor, const Node& node)
4.337 + : _adaptor(&adaptor) {
4.338 + _adaptor->firstIn(*this, node);
4.339 }
4.340
4.341 - InArcIt(const Adaptor& adaptor, const Arc& arc) :
4.342 - Arc(arc), _adaptor(&adaptor) {}
4.343 + InArcIt(const Adaptor& adaptor, const Arc& arc) :
4.344 + Arc(arc), _adaptor(&adaptor) {}
4.345
4.346 - InArcIt& operator++() {
4.347 - _adaptor->nextIn(*this);
4.348 - return *this;
4.349 + InArcIt& operator++() {
4.350 + _adaptor->nextIn(*this);
4.351 + return *this;
4.352 }
4.353
4.354 };
4.355
4.356 - class EdgeIt : public Parent::Edge {
4.357 + class EdgeIt : public Parent::Edge {
4.358 const Adaptor* _adaptor;
4.359 public:
4.360
4.361 @@ -357,20 +336,20 @@
4.362 EdgeIt(Invalid i) : Edge(i) { }
4.363
4.364 explicit EdgeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
4.365 - _adaptor->first(static_cast<Edge&>(*this));
4.366 + _adaptor->first(static_cast<Edge&>(*this));
4.367 }
4.368
4.369 - EdgeIt(const Adaptor& adaptor, const Edge& e) :
4.370 - Edge(e), _adaptor(&adaptor) { }
4.371 + EdgeIt(const Adaptor& adaptor, const Edge& e) :
4.372 + Edge(e), _adaptor(&adaptor) { }
4.373
4.374 - EdgeIt& operator++() {
4.375 - _adaptor->next(*this);
4.376 - return *this;
4.377 + EdgeIt& operator++() {
4.378 + _adaptor->next(*this);
4.379 + return *this;
4.380 }
4.381
4.382 };
4.383
4.384 - class IncEdgeIt : public Edge {
4.385 + class IncEdgeIt : public Edge {
4.386 friend class GraphAdaptorExtender;
4.387 const Adaptor* _adaptor;
4.388 bool direction;
4.389 @@ -381,57 +360,37 @@
4.390 IncEdgeIt(Invalid i) : Edge(i), direction(false) { }
4.391
4.392 IncEdgeIt(const Adaptor& adaptor, const Node &n) : _adaptor(&adaptor) {
4.393 - _adaptor->firstInc(static_cast<Edge&>(*this), direction, n);
4.394 + _adaptor->firstInc(static_cast<Edge&>(*this), direction, n);
4.395 }
4.396
4.397 IncEdgeIt(const Adaptor& adaptor, const Edge &e, const Node &n)
4.398 - : _adaptor(&adaptor), Edge(e) {
4.399 - direction = (_adaptor->u(e) == n);
4.400 + : _adaptor(&adaptor), Edge(e) {
4.401 + direction = (_adaptor->u(e) == n);
4.402 }
4.403
4.404 IncEdgeIt& operator++() {
4.405 - _adaptor->nextInc(*this, direction);
4.406 - return *this;
4.407 + _adaptor->nextInc(*this, direction);
4.408 + return *this;
4.409 }
4.410 };
4.411
4.412 - /// \brief Base node of the iterator
4.413 - ///
4.414 - /// Returns the base node (ie. the source in this case) of the iterator
4.415 Node baseNode(const OutArcIt &a) const {
4.416 return Parent::source(a);
4.417 }
4.418 - /// \brief Running node of the iterator
4.419 - ///
4.420 - /// Returns the running node (ie. the target in this case) of the
4.421 - /// iterator
4.422 Node runningNode(const OutArcIt &a) const {
4.423 return Parent::target(a);
4.424 }
4.425
4.426 - /// \brief Base node of the iterator
4.427 - ///
4.428 - /// Returns the base node (ie. the target in this case) of the iterator
4.429 Node baseNode(const InArcIt &a) const {
4.430 return Parent::target(a);
4.431 }
4.432 - /// \brief Running node of the iterator
4.433 - ///
4.434 - /// Returns the running node (ie. the source in this case) of the
4.435 - /// iterator
4.436 Node runningNode(const InArcIt &a) const {
4.437 return Parent::source(a);
4.438 }
4.439
4.440 - /// Base node of the iterator
4.441 - ///
4.442 - /// Returns the base node of the iterator
4.443 Node baseNode(const IncEdgeIt &e) const {
4.444 return e.direction ? Parent::u(e) : Parent::v(e);
4.445 }
4.446 - /// Running node of the iterator
4.447 - ///
4.448 - /// Returns the running node of the iterator
4.449 Node runningNode(const IncEdgeIt &e) const {
4.450 return e.direction ? Parent::v(e) : Parent::u(e);
4.451 }
5.1 --- a/lemon/bits/variant.h Sun Nov 30 19:00:30 2008 +0100
5.2 +++ b/lemon/bits/variant.h Sun Nov 30 19:18:32 2008 +0100
5.3 @@ -1,6 +1,6 @@
5.4 -/* -*- C++ -*-
5.5 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
5.6 *
5.7 - * This file is a part of LEMON, a generic C++ optimization library
5.8 + * This file is a part of LEMON, a generic C++ optimization library.
5.9 *
5.10 * Copyright (C) 2003-2008
5.11 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5.12 @@ -27,7 +27,7 @@
5.13 namespace lemon {
5.14
5.15 namespace _variant_bits {
5.16 -
5.17 +
5.18 template <int left, int right>
5.19 struct CTMax {
5.20 static const int value = left < right ? right : left;
5.21 @@ -86,9 +86,9 @@
5.22 BiVariant(const BiVariant& bivariant) {
5.23 flag = bivariant.flag;
5.24 if (flag) {
5.25 - new(reinterpret_cast<First*>(data)) First(bivariant.first());
5.26 + new(reinterpret_cast<First*>(data)) First(bivariant.first());
5.27 } else {
5.28 - new(reinterpret_cast<Second*>(data)) Second(bivariant.second());
5.29 + new(reinterpret_cast<Second*>(data)) Second(bivariant.second());
5.30 }
5.31 }
5.32
5.33 @@ -106,7 +106,7 @@
5.34 BiVariant& setFirst() {
5.35 destroy();
5.36 flag = true;
5.37 - new(reinterpret_cast<First*>(data)) First();
5.38 + new(reinterpret_cast<First*>(data)) First();
5.39 return *this;
5.40 }
5.41
5.42 @@ -117,7 +117,7 @@
5.43 BiVariant& setFirst(const First& f) {
5.44 destroy();
5.45 flag = true;
5.46 - new(reinterpret_cast<First*>(data)) First(f);
5.47 + new(reinterpret_cast<First*>(data)) First(f);
5.48 return *this;
5.49 }
5.50
5.51 @@ -128,7 +128,7 @@
5.52 BiVariant& setSecond() {
5.53 destroy();
5.54 flag = false;
5.55 - new(reinterpret_cast<Second*>(data)) Second();
5.56 + new(reinterpret_cast<Second*>(data)) Second();
5.57 return *this;
5.58 }
5.59
5.60 @@ -139,7 +139,7 @@
5.61 BiVariant& setSecond(const Second& s) {
5.62 destroy();
5.63 flag = false;
5.64 - new(reinterpret_cast<Second*>(data)) Second(s);
5.65 + new(reinterpret_cast<Second*>(data)) Second(s);
5.66 return *this;
5.67 }
5.68
5.69 @@ -159,9 +159,9 @@
5.70 destroy();
5.71 flag = bivariant.flag;
5.72 if (flag) {
5.73 - new(reinterpret_cast<First*>(data)) First(bivariant.first());
5.74 + new(reinterpret_cast<First*>(data)) First(bivariant.first());
5.75 } else {
5.76 - new(reinterpret_cast<Second*>(data)) Second(bivariant.second());
5.77 + new(reinterpret_cast<Second*>(data)) Second(bivariant.second());
5.78 }
5.79 return *this;
5.80 }
5.81 @@ -231,13 +231,13 @@
5.82 reinterpret_cast<Second*>(data)->~Second();
5.83 }
5.84 }
5.85 -
5.86 +
5.87 char data[_variant_bits::CTMax<sizeof(First), sizeof(Second)>::value];
5.88 bool flag;
5.89 };
5.90
5.91 namespace _variant_bits {
5.92 -
5.93 +
5.94 template <int _idx, typename _TypeMap>
5.95 struct Memory {
5.96
5.97 @@ -276,14 +276,14 @@
5.98
5.99 template <int _idx, typename _TypeMap>
5.100 struct Size {
5.101 - static const int value =
5.102 - CTMax<sizeof(typename _TypeMap::template Map<_idx>::Type),
5.103 + static const int value =
5.104 + CTMax<sizeof(typename _TypeMap::template Map<_idx>::Type),
5.105 Size<_idx - 1, _TypeMap>::value>::value;
5.106 };
5.107
5.108 template <typename _TypeMap>
5.109 struct Size<0, _TypeMap> {
5.110 - static const int value =
5.111 + static const int value =
5.112 sizeof(typename _TypeMap::template Map<0>::Type);
5.113 };
5.114
5.115 @@ -301,7 +301,7 @@
5.116 /// \param _num The number of the types which can be stored in the
5.117 /// variant type.
5.118 /// \param _TypeMap This class describes the types of the Variant. The
5.119 - /// _TypeMap::Map<index>::Type should be a valid type for each index
5.120 + /// _TypeMap::Map<index>::Type should be a valid type for each index
5.121 /// in the range {0, 1, ..., _num - 1}. The \c VariantTypeMap is helper
5.122 /// class to define such type mappings up to 10 types.
5.123 ///
5.124 @@ -337,7 +337,7 @@
5.125 /// with 0 index.
5.126 Variant() {
5.127 flag = 0;
5.128 - new(reinterpret_cast<typename TypeMap::template Map<0>::Type*>(data))
5.129 + new(reinterpret_cast<typename TypeMap::template Map<0>::Type*>(data))
5.130 typename TypeMap::template Map<0>::Type();
5.131 }
5.132
5.133 @@ -378,7 +378,7 @@
5.134 Variant& set() {
5.135 _variant_bits::Memory<num - 1, TypeMap>::destroy(flag, data);
5.136 flag = _idx;
5.137 - new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data))
5.138 + new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data))
5.139 typename TypeMap::template Map<_idx>::Type();
5.140 return *this;
5.141 }
5.142 @@ -391,7 +391,7 @@
5.143 Variant& set(const typename _TypeMap::template Map<_idx>::Type& init) {
5.144 _variant_bits::Memory<num - 1, TypeMap>::destroy(flag, data);
5.145 flag = _idx;
5.146 - new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data))
5.147 + new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data))
5.148 typename TypeMap::template Map<_idx>::Type(init);
5.149 return *this;
5.150 }
5.151 @@ -403,7 +403,7 @@
5.152 const typename TypeMap::template Map<_idx>::Type& get() const {
5.153 LEMON_DEBUG(_idx == flag, "Variant wrong index");
5.154 return *reinterpret_cast<const typename TypeMap::
5.155 - template Map<_idx>::Type*>(data);
5.156 + template Map<_idx>::Type*>(data);
5.157 }
5.158
5.159 /// \brief Gets the current value of the type with \c _idx index.
5.160 @@ -413,7 +413,7 @@
5.161 typename _TypeMap::template Map<_idx>::Type& get() {
5.162 LEMON_DEBUG(_idx == flag, "Variant wrong index");
5.163 return *reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>
5.164 - (data);
5.165 + (data);
5.166 }
5.167
5.168 /// \brief Returns the current state of the variant.
5.169 @@ -424,7 +424,7 @@
5.170 }
5.171
5.172 private:
5.173 -
5.174 +
5.175 char data[_variant_bits::Size<num - 1, TypeMap>::value];
5.176 int flag;
5.177 };
5.178 @@ -442,14 +442,14 @@
5.179 };
5.180
5.181 struct List {};
5.182 -
5.183 +
5.184 template <typename _Type, typename _List>
5.185 struct Insert {
5.186 typedef _List Next;
5.187 typedef _Type Type;
5.188 };
5.189
5.190 - template <int _idx, typename _T0, typename _T1, typename _T2,
5.191 + template <int _idx, typename _T0, typename _T1, typename _T2,
5.192 typename _T3, typename _T5, typename _T4, typename _T6,
5.193 typename _T7, typename _T8, typename _T9>
5.194 struct Mapper {
5.195 @@ -466,7 +466,7 @@
5.196 typedef Insert<_T0, L1> L0;
5.197 typedef typename Get<_idx, L0>::Type Type;
5.198 };
5.199 -
5.200 +
5.201 }
5.202
5.203 /// \brief Helper class for Variant
5.204 @@ -475,7 +475,7 @@
5.205 /// converts the template parameters to be mappable by integer.
5.206 /// \see Variant
5.207 template <
5.208 - typename _T0,
5.209 + typename _T0,
5.210 typename _T1 = void, typename _T2 = void, typename _T3 = void,
5.211 typename _T5 = void, typename _T4 = void, typename _T6 = void,
5.212 typename _T7 = void, typename _T8 = void, typename _T9 = void>
5.213 @@ -487,7 +487,7 @@
5.214 Type;
5.215 };
5.216 };
5.217 -
5.218 +
5.219 }
5.220
5.221
6.1 --- a/lemon/digraph_adaptor.h Sun Nov 30 19:00:30 2008 +0100
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,2547 +0,0 @@
6.4 -/* -*- C++ -*-
6.5 - *
6.6 - * This file is a part of LEMON, a generic C++ optimization library
6.7 - *
6.8 - * Copyright (C) 2003-2008
6.9 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
6.10 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
6.11 - *
6.12 - * Permission to use, modify and distribute this software is granted
6.13 - * provided that this copyright notice appears in all copies. For
6.14 - * precise terms see the accompanying LICENSE file.
6.15 - *
6.16 - * This software is provided "AS IS" with no warranty of any kind,
6.17 - * express or implied, and with no claim as to its suitability for any
6.18 - * purpose.
6.19 - *
6.20 - */
6.21 -
6.22 -#ifndef LEMON_DIGRAPH_ADAPTOR_H
6.23 -#define LEMON_DIGRAPH_ADAPTOR_H
6.24 -
6.25 -///\ingroup graph_adaptors
6.26 -///\file
6.27 -///\brief Several digraph adaptors.
6.28 -///
6.29 -///This file contains several useful digraph adaptor classes.
6.30 -
6.31 -#include <lemon/core.h>
6.32 -#include <lemon/maps.h>
6.33 -#include <lemon/bits/variant.h>
6.34 -
6.35 -#include <lemon/bits/base_extender.h>
6.36 -#include <lemon/bits/graph_adaptor_extender.h>
6.37 -#include <lemon/bits/graph_extender.h>
6.38 -#include <lemon/tolerance.h>
6.39 -
6.40 -#include <algorithm>
6.41 -
6.42 -namespace lemon {
6.43 -
6.44 - template<typename _Digraph>
6.45 - class DigraphAdaptorBase {
6.46 - public:
6.47 - typedef _Digraph Digraph;
6.48 - typedef DigraphAdaptorBase Adaptor;
6.49 - typedef Digraph ParentDigraph;
6.50 -
6.51 - protected:
6.52 - Digraph* _digraph;
6.53 - DigraphAdaptorBase() : _digraph(0) { }
6.54 - void setDigraph(Digraph& digraph) { _digraph = &digraph; }
6.55 -
6.56 - public:
6.57 - DigraphAdaptorBase(Digraph& digraph) : _digraph(&digraph) { }
6.58 -
6.59 - typedef typename Digraph::Node Node;
6.60 - typedef typename Digraph::Arc Arc;
6.61 -
6.62 - void first(Node& i) const { _digraph->first(i); }
6.63 - void first(Arc& i) const { _digraph->first(i); }
6.64 - void firstIn(Arc& i, const Node& n) const { _digraph->firstIn(i, n); }
6.65 - void firstOut(Arc& i, const Node& n ) const { _digraph->firstOut(i, n); }
6.66 -
6.67 - void next(Node& i) const { _digraph->next(i); }
6.68 - void next(Arc& i) const { _digraph->next(i); }
6.69 - void nextIn(Arc& i) const { _digraph->nextIn(i); }
6.70 - void nextOut(Arc& i) const { _digraph->nextOut(i); }
6.71 -
6.72 - Node source(const Arc& a) const { return _digraph->source(a); }
6.73 - Node target(const Arc& a) const { return _digraph->target(a); }
6.74 -
6.75 - typedef NodeNumTagIndicator<Digraph> NodeNumTag;
6.76 - int nodeNum() const { return _digraph->nodeNum(); }
6.77 -
6.78 - typedef EdgeNumTagIndicator<Digraph> EdgeNumTag;
6.79 - int arcNum() const { return _digraph->arcNum(); }
6.80 -
6.81 - typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
6.82 - Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
6.83 - return _digraph->findArc(u, v, prev);
6.84 - }
6.85 -
6.86 - Node addNode() { return _digraph->addNode(); }
6.87 - Arc addArc(const Node& u, const Node& v) { return _digraph->addArc(u, v); }
6.88 -
6.89 - void erase(const Node& n) const { _digraph->erase(n); }
6.90 - void erase(const Arc& a) const { _digraph->erase(a); }
6.91 -
6.92 - void clear() const { _digraph->clear(); }
6.93 -
6.94 - int id(const Node& n) const { return _digraph->id(n); }
6.95 - int id(const Arc& a) const { return _digraph->id(a); }
6.96 -
6.97 - Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
6.98 - Arc arcFromId(int ix) const { return _digraph->arcFromId(ix); }
6.99 -
6.100 - int maxNodeId() const { return _digraph->maxNodeId(); }
6.101 - int maxArcId() const { return _digraph->maxArcId(); }
6.102 -
6.103 - typedef typename ItemSetTraits<Digraph, Node>::ItemNotifier NodeNotifier;
6.104 - NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
6.105 -
6.106 - typedef typename ItemSetTraits<Digraph, Arc>::ItemNotifier ArcNotifier;
6.107 - ArcNotifier& notifier(Arc) const { return _digraph->notifier(Arc()); }
6.108 -
6.109 - template <typename _Value>
6.110 - class NodeMap : public Digraph::template NodeMap<_Value> {
6.111 - public:
6.112 -
6.113 - typedef typename Digraph::template NodeMap<_Value> Parent;
6.114 -
6.115 - explicit NodeMap(const Adaptor& adaptor)
6.116 - : Parent(*adaptor._digraph) {}
6.117 -
6.118 - NodeMap(const Adaptor& adaptor, const _Value& value)
6.119 - : Parent(*adaptor._digraph, value) { }
6.120 -
6.121 - private:
6.122 - NodeMap& operator=(const NodeMap& cmap) {
6.123 - return operator=<NodeMap>(cmap);
6.124 - }
6.125 -
6.126 - template <typename CMap>
6.127 - NodeMap& operator=(const CMap& cmap) {
6.128 - Parent::operator=(cmap);
6.129 - return *this;
6.130 - }
6.131 -
6.132 - };
6.133 -
6.134 - template <typename _Value>
6.135 - class ArcMap : public Digraph::template ArcMap<_Value> {
6.136 - public:
6.137 -
6.138 - typedef typename Digraph::template ArcMap<_Value> Parent;
6.139 -
6.140 - explicit ArcMap(const Adaptor& adaptor)
6.141 - : Parent(*adaptor._digraph) {}
6.142 -
6.143 - ArcMap(const Adaptor& adaptor, const _Value& value)
6.144 - : Parent(*adaptor._digraph, value) {}
6.145 -
6.146 - private:
6.147 - ArcMap& operator=(const ArcMap& cmap) {
6.148 - return operator=<ArcMap>(cmap);
6.149 - }
6.150 -
6.151 - template <typename CMap>
6.152 - ArcMap& operator=(const CMap& cmap) {
6.153 - Parent::operator=(cmap);
6.154 - return *this;
6.155 - }
6.156 -
6.157 - };
6.158 -
6.159 - };
6.160 -
6.161 -
6.162 - template <typename _Digraph>
6.163 - class RevDigraphAdaptorBase : public DigraphAdaptorBase<_Digraph> {
6.164 - public:
6.165 - typedef _Digraph Digraph;
6.166 - typedef DigraphAdaptorBase<_Digraph> Parent;
6.167 - protected:
6.168 - RevDigraphAdaptorBase() : Parent() { }
6.169 - public:
6.170 - typedef typename Parent::Node Node;
6.171 - typedef typename Parent::Arc Arc;
6.172 -
6.173 - void firstIn(Arc& a, const Node& n) const { Parent::firstOut(a, n); }
6.174 - void firstOut(Arc& a, const Node& n ) const { Parent::firstIn(a, n); }
6.175 -
6.176 - void nextIn(Arc& a) const { Parent::nextOut(a); }
6.177 - void nextOut(Arc& a) const { Parent::nextIn(a); }
6.178 -
6.179 - Node source(const Arc& a) const { return Parent::target(a); }
6.180 - Node target(const Arc& a) const { return Parent::source(a); }
6.181 -
6.182 - typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
6.183 - Arc findArc(const Node& u, const Node& v,
6.184 - const Arc& prev = INVALID) {
6.185 - return Parent::findArc(v, u, prev);
6.186 - }
6.187 -
6.188 - };
6.189 -
6.190 -
6.191 - ///\ingroup graph_adaptors
6.192 - ///
6.193 - ///\brief A digraph adaptor which reverses the orientation of the arcs.
6.194 - ///
6.195 - /// If \c g is defined as
6.196 - ///\code
6.197 - /// ListDigraph dg;
6.198 - ///\endcode
6.199 - /// then
6.200 - ///\code
6.201 - /// RevDigraphAdaptor<ListDigraph> dga(dg);
6.202 - ///\endcode
6.203 - /// implements the digraph obtained from \c dg by
6.204 - /// reversing the orientation of its arcs.
6.205 - ///
6.206 - /// A good example of using RevDigraphAdaptor is to decide whether
6.207 - /// the directed graph is strongly connected or not. The digraph is
6.208 - /// strongly connected iff each node is reachable from one node and
6.209 - /// this node is reachable from the others. Instead of this
6.210 - /// condition we use a slightly different, from one node each node
6.211 - /// is reachable both in the digraph and the reversed digraph. Now
6.212 - /// this condition can be checked with the Dfs algorithm and the
6.213 - /// RevDigraphAdaptor class.
6.214 - ///
6.215 - /// The implementation:
6.216 - ///\code
6.217 - /// bool stronglyConnected(const Digraph& digraph) {
6.218 - /// if (NodeIt(digraph) == INVALID) return true;
6.219 - /// Dfs<Digraph> dfs(digraph);
6.220 - /// dfs.run(NodeIt(digraph));
6.221 - /// for (NodeIt it(digraph); it != INVALID; ++it) {
6.222 - /// if (!dfs.reached(it)) {
6.223 - /// return false;
6.224 - /// }
6.225 - /// }
6.226 - /// typedef RevDigraphAdaptor<const Digraph> RDigraph;
6.227 - /// RDigraph rdigraph(digraph);
6.228 - /// DfsVisit<RDigraph> rdfs(rdigraph);
6.229 - /// rdfs.run(NodeIt(digraph));
6.230 - /// for (NodeIt it(digraph); it != INVALID; ++it) {
6.231 - /// if (!rdfs.reached(it)) {
6.232 - /// return false;
6.233 - /// }
6.234 - /// }
6.235 - /// return true;
6.236 - /// }
6.237 - ///\endcode
6.238 - template<typename _Digraph>
6.239 - class RevDigraphAdaptor :
6.240 - public DigraphAdaptorExtender<RevDigraphAdaptorBase<_Digraph> > {
6.241 - public:
6.242 - typedef _Digraph Digraph;
6.243 - typedef DigraphAdaptorExtender<
6.244 - RevDigraphAdaptorBase<_Digraph> > Parent;
6.245 - protected:
6.246 - RevDigraphAdaptor() { }
6.247 - public:
6.248 -
6.249 - /// \brief Constructor
6.250 - ///
6.251 - /// Creates a reverse graph adaptor for the given digraph
6.252 - explicit RevDigraphAdaptor(Digraph& digraph) {
6.253 - Parent::setDigraph(digraph);
6.254 - }
6.255 - };
6.256 -
6.257 - /// \brief Just gives back a reverse digraph adaptor
6.258 - ///
6.259 - /// Just gives back a reverse digraph adaptor
6.260 - template<typename Digraph>
6.261 - RevDigraphAdaptor<const Digraph>
6.262 - revDigraphAdaptor(const Digraph& digraph) {
6.263 - return RevDigraphAdaptor<const Digraph>(digraph);
6.264 - }
6.265 -
6.266 - template <typename _Digraph, typename _NodeFilterMap,
6.267 - typename _ArcFilterMap, bool checked = true>
6.268 - class SubDigraphAdaptorBase : public DigraphAdaptorBase<_Digraph> {
6.269 - public:
6.270 - typedef _Digraph Digraph;
6.271 - typedef _NodeFilterMap NodeFilterMap;
6.272 - typedef _ArcFilterMap ArcFilterMap;
6.273 -
6.274 - typedef SubDigraphAdaptorBase Adaptor;
6.275 - typedef DigraphAdaptorBase<_Digraph> Parent;
6.276 - protected:
6.277 - NodeFilterMap* _node_filter;
6.278 - ArcFilterMap* _arc_filter;
6.279 - SubDigraphAdaptorBase()
6.280 - : Parent(), _node_filter(0), _arc_filter(0) { }
6.281 -
6.282 - void setNodeFilterMap(NodeFilterMap& node_filter) {
6.283 - _node_filter = &node_filter;
6.284 - }
6.285 - void setArcFilterMap(ArcFilterMap& arc_filter) {
6.286 - _arc_filter = &arc_filter;
6.287 - }
6.288 -
6.289 - public:
6.290 -
6.291 - typedef typename Parent::Node Node;
6.292 - typedef typename Parent::Arc Arc;
6.293 -
6.294 - void first(Node& i) const {
6.295 - Parent::first(i);
6.296 - while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
6.297 - }
6.298 -
6.299 - void first(Arc& i) const {
6.300 - Parent::first(i);
6.301 - while (i != INVALID && (!(*_arc_filter)[i]
6.302 - || !(*_node_filter)[Parent::source(i)]
6.303 - || !(*_node_filter)[Parent::target(i)])) Parent::next(i);
6.304 - }
6.305 -
6.306 - void firstIn(Arc& i, const Node& n) const {
6.307 - Parent::firstIn(i, n);
6.308 - while (i != INVALID && (!(*_arc_filter)[i]
6.309 - || !(*_node_filter)[Parent::source(i)])) Parent::nextIn(i);
6.310 - }
6.311 -
6.312 - void firstOut(Arc& i, const Node& n) const {
6.313 - Parent::firstOut(i, n);
6.314 - while (i != INVALID && (!(*_arc_filter)[i]
6.315 - || !(*_node_filter)[Parent::target(i)])) Parent::nextOut(i);
6.316 - }
6.317 -
6.318 - void next(Node& i) const {
6.319 - Parent::next(i);
6.320 - while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
6.321 - }
6.322 -
6.323 - void next(Arc& i) const {
6.324 - Parent::next(i);
6.325 - while (i != INVALID && (!(*_arc_filter)[i]
6.326 - || !(*_node_filter)[Parent::source(i)]
6.327 - || !(*_node_filter)[Parent::target(i)])) Parent::next(i);
6.328 - }
6.329 -
6.330 - void nextIn(Arc& i) const {
6.331 - Parent::nextIn(i);
6.332 - while (i != INVALID && (!(*_arc_filter)[i]
6.333 - || !(*_node_filter)[Parent::source(i)])) Parent::nextIn(i);
6.334 - }
6.335 -
6.336 - void nextOut(Arc& i) const {
6.337 - Parent::nextOut(i);
6.338 - while (i != INVALID && (!(*_arc_filter)[i]
6.339 - || !(*_node_filter)[Parent::target(i)])) Parent::nextOut(i);
6.340 - }
6.341 -
6.342 - void hide(const Node& n) const { _node_filter->set(n, false); }
6.343 - void hide(const Arc& a) const { _arc_filter->set(a, false); }
6.344 -
6.345 - void unHide(const Node& n) const { _node_filter->set(n, true); }
6.346 - void unHide(const Arc& a) const { _arc_filter->set(a, true); }
6.347 -
6.348 - bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
6.349 - bool hidden(const Arc& a) const { return !(*_arc_filter)[a]; }
6.350 -
6.351 - typedef False NodeNumTag;
6.352 - typedef False EdgeNumTag;
6.353 -
6.354 - typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
6.355 - Arc findArc(const Node& source, const Node& target,
6.356 - const Arc& prev = INVALID) {
6.357 - if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
6.358 - return INVALID;
6.359 - }
6.360 - Arc arc = Parent::findArc(source, target, prev);
6.361 - while (arc != INVALID && !(*_arc_filter)[arc]) {
6.362 - arc = Parent::findArc(source, target, arc);
6.363 - }
6.364 - return arc;
6.365 - }
6.366 -
6.367 - template <typename _Value>
6.368 - class NodeMap : public SubMapExtender<Adaptor,
6.369 - typename Parent::template NodeMap<_Value> > {
6.370 - public:
6.371 - typedef _Value Value;
6.372 - typedef SubMapExtender<Adaptor, typename Parent::
6.373 - template NodeMap<Value> > MapParent;
6.374 -
6.375 - NodeMap(const Adaptor& adaptor)
6.376 - : MapParent(adaptor) {}
6.377 - NodeMap(const Adaptor& adaptor, const Value& value)
6.378 - : MapParent(adaptor, value) {}
6.379 -
6.380 - private:
6.381 - NodeMap& operator=(const NodeMap& cmap) {
6.382 - return operator=<NodeMap>(cmap);
6.383 - }
6.384 -
6.385 - template <typename CMap>
6.386 - NodeMap& operator=(const CMap& cmap) {
6.387 - MapParent::operator=(cmap);
6.388 - return *this;
6.389 - }
6.390 - };
6.391 -
6.392 - template <typename _Value>
6.393 - class ArcMap : public SubMapExtender<Adaptor,
6.394 - typename Parent::template ArcMap<_Value> > {
6.395 - public:
6.396 - typedef _Value Value;
6.397 - typedef SubMapExtender<Adaptor, typename Parent::
6.398 - template ArcMap<Value> > MapParent;
6.399 -
6.400 - ArcMap(const Adaptor& adaptor)
6.401 - : MapParent(adaptor) {}
6.402 - ArcMap(const Adaptor& adaptor, const Value& value)
6.403 - : MapParent(adaptor, value) {}
6.404 -
6.405 - private:
6.406 - ArcMap& operator=(const ArcMap& cmap) {
6.407 - return operator=<ArcMap>(cmap);
6.408 - }
6.409 -
6.410 - template <typename CMap>
6.411 - ArcMap& operator=(const CMap& cmap) {
6.412 - MapParent::operator=(cmap);
6.413 - return *this;
6.414 - }
6.415 - };
6.416 -
6.417 - };
6.418 -
6.419 - template <typename _Digraph, typename _NodeFilterMap, typename _ArcFilterMap>
6.420 - class SubDigraphAdaptorBase<_Digraph, _NodeFilterMap, _ArcFilterMap, false>
6.421 - : public DigraphAdaptorBase<_Digraph> {
6.422 - public:
6.423 - typedef _Digraph Digraph;
6.424 - typedef _NodeFilterMap NodeFilterMap;
6.425 - typedef _ArcFilterMap ArcFilterMap;
6.426 -
6.427 - typedef SubDigraphAdaptorBase Adaptor;
6.428 - typedef DigraphAdaptorBase<Digraph> Parent;
6.429 - protected:
6.430 - NodeFilterMap* _node_filter;
6.431 - ArcFilterMap* _arc_filter;
6.432 - SubDigraphAdaptorBase()
6.433 - : Parent(), _node_filter(0), _arc_filter(0) { }
6.434 -
6.435 - void setNodeFilterMap(NodeFilterMap& node_filter) {
6.436 - _node_filter = &node_filter;
6.437 - }
6.438 - void setArcFilterMap(ArcFilterMap& arc_filter) {
6.439 - _arc_filter = &arc_filter;
6.440 - }
6.441 -
6.442 - public:
6.443 -
6.444 - typedef typename Parent::Node Node;
6.445 - typedef typename Parent::Arc Arc;
6.446 -
6.447 - void first(Node& i) const {
6.448 - Parent::first(i);
6.449 - while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
6.450 - }
6.451 -
6.452 - void first(Arc& i) const {
6.453 - Parent::first(i);
6.454 - while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
6.455 - }
6.456 -
6.457 - void firstIn(Arc& i, const Node& n) const {
6.458 - Parent::firstIn(i, n);
6.459 - while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
6.460 - }
6.461 -
6.462 - void firstOut(Arc& i, const Node& n) const {
6.463 - Parent::firstOut(i, n);
6.464 - while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
6.465 - }
6.466 -
6.467 - void next(Node& i) const {
6.468 - Parent::next(i);
6.469 - while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
6.470 - }
6.471 - void next(Arc& i) const {
6.472 - Parent::next(i);
6.473 - while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
6.474 - }
6.475 - void nextIn(Arc& i) const {
6.476 - Parent::nextIn(i);
6.477 - while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
6.478 - }
6.479 -
6.480 - void nextOut(Arc& i) const {
6.481 - Parent::nextOut(i);
6.482 - while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
6.483 - }
6.484 -
6.485 - void hide(const Node& n) const { _node_filter->set(n, false); }
6.486 - void hide(const Arc& e) const { _arc_filter->set(e, false); }
6.487 -
6.488 - void unHide(const Node& n) const { _node_filter->set(n, true); }
6.489 - void unHide(const Arc& e) const { _arc_filter->set(e, true); }
6.490 -
6.491 - bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
6.492 - bool hidden(const Arc& e) const { return !(*_arc_filter)[e]; }
6.493 -
6.494 - typedef False NodeNumTag;
6.495 - typedef False EdgeNumTag;
6.496 -
6.497 - typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
6.498 - Arc findArc(const Node& source, const Node& target,
6.499 - const Arc& prev = INVALID) {
6.500 - if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
6.501 - return INVALID;
6.502 - }
6.503 - Arc arc = Parent::findArc(source, target, prev);
6.504 - while (arc != INVALID && !(*_arc_filter)[arc]) {
6.505 - arc = Parent::findArc(source, target, arc);
6.506 - }
6.507 - return arc;
6.508 - }
6.509 -
6.510 - template <typename _Value>
6.511 - class NodeMap : public SubMapExtender<Adaptor,
6.512 - typename Parent::template NodeMap<_Value> > {
6.513 - public:
6.514 - typedef _Value Value;
6.515 - typedef SubMapExtender<Adaptor, typename Parent::
6.516 - template NodeMap<Value> > MapParent;
6.517 -
6.518 - NodeMap(const Adaptor& adaptor)
6.519 - : MapParent(adaptor) {}
6.520 - NodeMap(const Adaptor& adaptor, const Value& value)
6.521 - : MapParent(adaptor, value) {}
6.522 -
6.523 - private:
6.524 - NodeMap& operator=(const NodeMap& cmap) {
6.525 - return operator=<NodeMap>(cmap);
6.526 - }
6.527 -
6.528 - template <typename CMap>
6.529 - NodeMap& operator=(const CMap& cmap) {
6.530 - MapParent::operator=(cmap);
6.531 - return *this;
6.532 - }
6.533 - };
6.534 -
6.535 - template <typename _Value>
6.536 - class ArcMap : public SubMapExtender<Adaptor,
6.537 - typename Parent::template ArcMap<_Value> > {
6.538 - public:
6.539 - typedef _Value Value;
6.540 - typedef SubMapExtender<Adaptor, typename Parent::
6.541 - template ArcMap<Value> > MapParent;
6.542 -
6.543 - ArcMap(const Adaptor& adaptor)
6.544 - : MapParent(adaptor) {}
6.545 - ArcMap(const Adaptor& adaptor, const Value& value)
6.546 - : MapParent(adaptor, value) {}
6.547 -
6.548 - private:
6.549 - ArcMap& operator=(const ArcMap& cmap) {
6.550 - return operator=<ArcMap>(cmap);
6.551 - }
6.552 -
6.553 - template <typename CMap>
6.554 - ArcMap& operator=(const CMap& cmap) {
6.555 - MapParent::operator=(cmap);
6.556 - return *this;
6.557 - }
6.558 - };
6.559 -
6.560 - };
6.561 -
6.562 - /// \ingroup graph_adaptors
6.563 - ///
6.564 - /// \brief A digraph adaptor for hiding nodes and arcs from a digraph.
6.565 - ///
6.566 - /// SubDigraphAdaptor shows the digraph with filtered node-set and
6.567 - /// arc-set. If the \c checked parameter is true then it filters the arc-set
6.568 - /// respect to the source and target.
6.569 - ///
6.570 - /// If the \c checked template parameter is false then the
6.571 - /// node-iterator cares only the filter on the node-set, and the
6.572 - /// arc-iterator cares only the filter on the arc-set. Therefore
6.573 - /// the arc-map have to filter all arcs which's source or target is
6.574 - /// filtered by the node-filter.
6.575 - ///\code
6.576 - /// typedef ListDigraph Digraph;
6.577 - /// DIGRAPH_TYPEDEFS(Digraph);
6.578 - /// Digraph g;
6.579 - /// Node u=g.addNode(); //node of id 0
6.580 - /// Node v=g.addNode(); //node of id 1
6.581 - /// Arc a=g.addArc(u, v); //arc of id 0
6.582 - /// Arc f=g.addArc(v, u); //arc of id 1
6.583 - /// BoolNodeMap nm(g, true);
6.584 - /// nm.set(u, false);
6.585 - /// BoolArcMap am(g, true);
6.586 - /// am.set(a, false);
6.587 - /// typedef SubDigraphAdaptor<Digraph, BoolNodeMap, BoolArcMap> SubDGA;
6.588 - /// SubDGA ga(g, nm, am);
6.589 - /// for (SubDGA::NodeIt n(ga); n!=INVALID; ++n)
6.590 - /// std::cout << g.id(n) << std::endl;
6.591 - /// for (SubDGA::ArcIt a(ga); a!=INVALID; ++a)
6.592 - /// std::cout << g.id(a) << std::endl;
6.593 - ///\endcode
6.594 - /// The output of the above code is the following.
6.595 - ///\code
6.596 - /// 1
6.597 - /// 1
6.598 - ///\endcode
6.599 - /// Note that \c n is of type \c SubDGA::NodeIt, but it can be converted to
6.600 - /// \c Digraph::Node that is why \c g.id(n) can be applied.
6.601 - ///
6.602 - /// For other examples see also the documentation of
6.603 - /// NodeSubDigraphAdaptor and ArcSubDigraphAdaptor.
6.604 - template<typename _Digraph,
6.605 - typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
6.606 - typename _ArcFilterMap = typename _Digraph::template ArcMap<bool>,
6.607 - bool checked = true>
6.608 - class SubDigraphAdaptor :
6.609 - public DigraphAdaptorExtender<
6.610 - SubDigraphAdaptorBase<_Digraph, _NodeFilterMap, _ArcFilterMap, checked> > {
6.611 - public:
6.612 - typedef _Digraph Digraph;
6.613 - typedef _NodeFilterMap NodeFilterMap;
6.614 - typedef _ArcFilterMap ArcFilterMap;
6.615 -
6.616 - typedef DigraphAdaptorExtender<
6.617 - SubDigraphAdaptorBase<Digraph, NodeFilterMap, ArcFilterMap, checked> >
6.618 - Parent;
6.619 -
6.620 - typedef typename Parent::Node Node;
6.621 - typedef typename Parent::Arc Arc;
6.622 -
6.623 - protected:
6.624 - SubDigraphAdaptor() { }
6.625 - public:
6.626 -
6.627 - /// \brief Constructor
6.628 - ///
6.629 - /// Creates a sub-digraph-adaptor for the given digraph with
6.630 - /// given node and arc map filters.
6.631 - SubDigraphAdaptor(Digraph& digraph, NodeFilterMap& node_filter,
6.632 - ArcFilterMap& arc_filter) {
6.633 - setDigraph(digraph);
6.634 - setNodeFilterMap(node_filter);
6.635 - setArcFilterMap(arc_filter);
6.636 - }
6.637 -
6.638 - /// \brief Hides the node of the graph
6.639 - ///
6.640 - /// This function hides \c n in the digraph, i.e. the iteration
6.641 - /// jumps over it. This is done by simply setting the value of \c n
6.642 - /// to be false in the corresponding node-map.
6.643 - void hide(const Node& n) const { Parent::hide(n); }
6.644 -
6.645 - /// \brief Hides the arc of the graph
6.646 - ///
6.647 - /// This function hides \c a in the digraph, i.e. the iteration
6.648 - /// jumps over it. This is done by simply setting the value of \c a
6.649 - /// to be false in the corresponding arc-map.
6.650 - void hide(const Arc& a) const { Parent::hide(a); }
6.651 -
6.652 - /// \brief Unhides the node of the graph
6.653 - ///
6.654 - /// The value of \c n is set to be true in the node-map which stores
6.655 - /// hide information. If \c n was hidden previuosly, then it is shown
6.656 - /// again
6.657 - void unHide(const Node& n) const { Parent::unHide(n); }
6.658 -
6.659 - /// \brief Unhides the arc of the graph
6.660 - ///
6.661 - /// The value of \c a is set to be true in the arc-map which stores
6.662 - /// hide information. If \c a was hidden previuosly, then it is shown
6.663 - /// again
6.664 - void unHide(const Arc& a) const { Parent::unHide(a); }
6.665 -
6.666 - /// \brief Returns true if \c n is hidden.
6.667 - ///
6.668 - /// Returns true if \c n is hidden.
6.669 - ///
6.670 - bool hidden(const Node& n) const { return Parent::hidden(n); }
6.671 -
6.672 - /// \brief Returns true if \c a is hidden.
6.673 - ///
6.674 - /// Returns true if \c a is hidden.
6.675 - ///
6.676 - bool hidden(const Arc& a) const { return Parent::hidden(a); }
6.677 -
6.678 - };
6.679 -
6.680 - /// \brief Just gives back a sub-digraph-adaptor
6.681 - ///
6.682 - /// Just gives back a sub-digraph-adaptor
6.683 - template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
6.684 - SubDigraphAdaptor<const Digraph, NodeFilterMap, ArcFilterMap>
6.685 - subDigraphAdaptor(const Digraph& digraph,
6.686 - NodeFilterMap& nfm, ArcFilterMap& afm) {
6.687 - return SubDigraphAdaptor<const Digraph, NodeFilterMap, ArcFilterMap>
6.688 - (digraph, nfm, afm);
6.689 - }
6.690 -
6.691 - template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
6.692 - SubDigraphAdaptor<const Digraph, const NodeFilterMap, ArcFilterMap>
6.693 - subDigraphAdaptor(const Digraph& digraph,
6.694 - NodeFilterMap& nfm, ArcFilterMap& afm) {
6.695 - return SubDigraphAdaptor<const Digraph, const NodeFilterMap, ArcFilterMap>
6.696 - (digraph, nfm, afm);
6.697 - }
6.698 -
6.699 - template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
6.700 - SubDigraphAdaptor<const Digraph, NodeFilterMap, const ArcFilterMap>
6.701 - subDigraphAdaptor(const Digraph& digraph,
6.702 - NodeFilterMap& nfm, ArcFilterMap& afm) {
6.703 - return SubDigraphAdaptor<const Digraph, NodeFilterMap, const ArcFilterMap>
6.704 - (digraph, nfm, afm);
6.705 - }
6.706 -
6.707 - template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
6.708 - SubDigraphAdaptor<const Digraph, const NodeFilterMap, const ArcFilterMap>
6.709 - subDigraphAdaptor(const Digraph& digraph,
6.710 - NodeFilterMap& nfm, ArcFilterMap& afm) {
6.711 - return SubDigraphAdaptor<const Digraph, const NodeFilterMap,
6.712 - const ArcFilterMap>(digraph, nfm, afm);
6.713 -
6.714 - }
6.715 -
6.716 -
6.717 -
6.718 - ///\ingroup graph_adaptors
6.719 - ///
6.720 - ///\brief An adaptor for hiding nodes from a digraph.
6.721 - ///
6.722 - ///An adaptor for hiding nodes from a digraph. This adaptor
6.723 - ///specializes SubDigraphAdaptor in the way that only the node-set
6.724 - ///can be filtered. In usual case the checked parameter is true, we
6.725 - ///get the induced subgraph. But if the checked parameter is false
6.726 - ///then we can filter only isolated nodes.
6.727 - template<typename _Digraph,
6.728 - typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
6.729 - bool checked = true>
6.730 - class NodeSubDigraphAdaptor :
6.731 - public SubDigraphAdaptor<_Digraph, _NodeFilterMap,
6.732 - ConstMap<typename _Digraph::Arc, bool>, checked> {
6.733 - public:
6.734 -
6.735 - typedef _Digraph Digraph;
6.736 - typedef _NodeFilterMap NodeFilterMap;
6.737 -
6.738 - typedef SubDigraphAdaptor<Digraph, NodeFilterMap,
6.739 - ConstMap<typename Digraph::Arc, bool>, checked>
6.740 - Parent;
6.741 -
6.742 - typedef typename Parent::Node Node;
6.743 -
6.744 - protected:
6.745 - ConstMap<typename Digraph::Arc, bool> const_true_map;
6.746 -
6.747 - NodeSubDigraphAdaptor() : const_true_map(true) {
6.748 - Parent::setArcFilterMap(const_true_map);
6.749 - }
6.750 -
6.751 - public:
6.752 -
6.753 - /// \brief Constructor
6.754 - ///
6.755 - /// Creates a node-sub-digraph-adaptor for the given digraph with
6.756 - /// given node map filter.
6.757 - NodeSubDigraphAdaptor(Digraph& _digraph, NodeFilterMap& node_filter) :
6.758 - Parent(), const_true_map(true) {
6.759 - Parent::setDigraph(_digraph);
6.760 - Parent::setNodeFilterMap(node_filter);
6.761 - Parent::setArcFilterMap(const_true_map);
6.762 - }
6.763 -
6.764 - /// \brief Hides the node of the graph
6.765 - ///
6.766 - /// This function hides \c n in the digraph, i.e. the iteration
6.767 - /// jumps over it. This is done by simply setting the value of \c n
6.768 - /// to be false in the corresponding node-map.
6.769 - void hide(const Node& n) const { Parent::hide(n); }
6.770 -
6.771 - /// \brief Unhides the node of the graph
6.772 - ///
6.773 - /// The value of \c n is set to be true in the node-map which stores
6.774 - /// hide information. If \c n was hidden previuosly, then it is shown
6.775 - /// again
6.776 - void unHide(const Node& n) const { Parent::unHide(n); }
6.777 -
6.778 - /// \brief Returns true if \c n is hidden.
6.779 - ///
6.780 - /// Returns true if \c n is hidden.
6.781 - ///
6.782 - bool hidden(const Node& n) const { return Parent::hidden(n); }
6.783 -
6.784 - };
6.785 -
6.786 -
6.787 - /// \brief Just gives back a node-sub-digraph adaptor
6.788 - ///
6.789 - /// Just gives back a node-sub-digraph adaptor
6.790 - template<typename Digraph, typename NodeFilterMap>
6.791 - NodeSubDigraphAdaptor<const Digraph, NodeFilterMap>
6.792 - nodeSubDigraphAdaptor(const Digraph& digraph, NodeFilterMap& nfm) {
6.793 - return NodeSubDigraphAdaptor<const Digraph, NodeFilterMap>(digraph, nfm);
6.794 - }
6.795 -
6.796 - template<typename Digraph, typename NodeFilterMap>
6.797 - NodeSubDigraphAdaptor<const Digraph, const NodeFilterMap>
6.798 - nodeSubDigraphAdaptor(const Digraph& digraph, const NodeFilterMap& nfm) {
6.799 - return NodeSubDigraphAdaptor<const Digraph, const NodeFilterMap>
6.800 - (digraph, nfm);
6.801 - }
6.802 -
6.803 - ///\ingroup graph_adaptors
6.804 - ///
6.805 - ///\brief An adaptor for hiding arcs from a digraph.
6.806 - ///
6.807 - ///An adaptor for hiding arcs from a digraph. This adaptor
6.808 - ///specializes SubDigraphAdaptor in the way that only the arc-set
6.809 - ///can be filtered. The usefulness of this adaptor is demonstrated
6.810 - ///in the problem of searching a maximum number of arc-disjoint
6.811 - ///shortest paths between two nodes \c s and \c t. Shortest here
6.812 - ///means being shortest with respect to non-negative
6.813 - ///arc-lengths. Note that the comprehension of the presented
6.814 - ///solution need's some elementary knowledge from combinatorial
6.815 - ///optimization.
6.816 - ///
6.817 - ///If a single shortest path is to be searched between \c s and \c
6.818 - ///t, then this can be done easily by applying the Dijkstra
6.819 - ///algorithm. What happens, if a maximum number of arc-disjoint
6.820 - ///shortest paths is to be computed. It can be proved that an arc
6.821 - ///can be in a shortest path if and only if it is tight with respect
6.822 - ///to the potential function computed by Dijkstra. Moreover, any
6.823 - ///path containing only such arcs is a shortest one. Thus we have
6.824 - ///to compute a maximum number of arc-disjoint paths between \c s
6.825 - ///and \c t in the digraph which has arc-set all the tight arcs. The
6.826 - ///computation will be demonstrated on the following digraph, which
6.827 - ///is read from the dimacs file \c sub_digraph_adaptor_demo.dim.
6.828 - ///The full source code is available in \ref
6.829 - ///sub_digraph_adaptor_demo.cc. If you are interested in more demo
6.830 - ///programs, you can use \ref dim_to_dot.cc to generate .dot files
6.831 - ///from dimacs files. The .dot file of the following figure was
6.832 - ///generated by the demo program \ref dim_to_dot.cc.
6.833 - ///
6.834 - ///\dot
6.835 - ///digraph lemon_dot_example {
6.836 - ///node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
6.837 - ///n0 [ label="0 (s)" ];
6.838 - ///n1 [ label="1" ];
6.839 - ///n2 [ label="2" ];
6.840 - ///n3 [ label="3" ];
6.841 - ///n4 [ label="4" ];
6.842 - ///n5 [ label="5" ];
6.843 - ///n6 [ label="6 (t)" ];
6.844 - ///arc [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
6.845 - ///n5 -> n6 [ label="9, length:4" ];
6.846 - ///n4 -> n6 [ label="8, length:2" ];
6.847 - ///n3 -> n5 [ label="7, length:1" ];
6.848 - ///n2 -> n5 [ label="6, length:3" ];
6.849 - ///n2 -> n6 [ label="5, length:5" ];
6.850 - ///n2 -> n4 [ label="4, length:2" ];
6.851 - ///n1 -> n4 [ label="3, length:3" ];
6.852 - ///n0 -> n3 [ label="2, length:1" ];
6.853 - ///n0 -> n2 [ label="1, length:2" ];
6.854 - ///n0 -> n1 [ label="0, length:3" ];
6.855 - ///}
6.856 - ///\enddot
6.857 - ///
6.858 - ///\code
6.859 - ///Digraph g;
6.860 - ///Node s, t;
6.861 - ///LengthMap length(g);
6.862 - ///
6.863 - ///readDimacs(std::cin, g, length, s, t);
6.864 - ///
6.865 - ///cout << "arcs with lengths (of form id, source--length->target): " << endl;
6.866 - ///for(ArcIt e(g); e!=INVALID; ++e)
6.867 - /// cout << g.id(e) << ", " << g.id(g.source(e)) << "--"
6.868 - /// << length[e] << "->" << g.id(g.target(e)) << endl;
6.869 - ///
6.870 - ///cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
6.871 - ///\endcode
6.872 - ///Next, the potential function is computed with Dijkstra.
6.873 - ///\code
6.874 - ///typedef Dijkstra<Digraph, LengthMap> Dijkstra;
6.875 - ///Dijkstra dijkstra(g, length);
6.876 - ///dijkstra.run(s);
6.877 - ///\endcode
6.878 - ///Next, we consrtruct a map which filters the arc-set to the tight arcs.
6.879 - ///\code
6.880 - ///typedef TightArcFilterMap<Digraph, const Dijkstra::DistMap, LengthMap>
6.881 - /// TightArcFilter;
6.882 - ///TightArcFilter tight_arc_filter(g, dijkstra.distMap(), length);
6.883 - ///
6.884 - ///typedef ArcSubDigraphAdaptor<Digraph, TightArcFilter> SubGA;
6.885 - ///SubGA ga(g, tight_arc_filter);
6.886 - ///\endcode
6.887 - ///Then, the maximum nimber of arc-disjoint \c s-\c t paths are computed
6.888 - ///with a max flow algorithm Preflow.
6.889 - ///\code
6.890 - ///ConstMap<Arc, int> const_1_map(1);
6.891 - ///Digraph::ArcMap<int> flow(g, 0);
6.892 - ///
6.893 - ///Preflow<SubGA, ConstMap<Arc, int>, Digraph::ArcMap<int> >
6.894 - /// preflow(ga, const_1_map, s, t);
6.895 - ///preflow.run();
6.896 - ///\endcode
6.897 - ///Last, the output is:
6.898 - ///\code
6.899 - ///cout << "maximum number of arc-disjoint shortest path: "
6.900 - /// << preflow.flowValue() << endl;
6.901 - ///cout << "arcs of the maximum number of arc-disjoint shortest s-t paths: "
6.902 - /// << endl;
6.903 - ///for(ArcIt e(g); e!=INVALID; ++e)
6.904 - /// if (preflow.flow(e))
6.905 - /// cout << " " << g.id(g.source(e)) << "--"
6.906 - /// << length[e] << "->" << g.id(g.target(e)) << endl;
6.907 - ///\endcode
6.908 - ///The program has the following (expected :-)) output:
6.909 - ///\code
6.910 - ///arcs with lengths (of form id, source--length->target):
6.911 - /// 9, 5--4->6
6.912 - /// 8, 4--2->6
6.913 - /// 7, 3--1->5
6.914 - /// 6, 2--3->5
6.915 - /// 5, 2--5->6
6.916 - /// 4, 2--2->4
6.917 - /// 3, 1--3->4
6.918 - /// 2, 0--1->3
6.919 - /// 1, 0--2->2
6.920 - /// 0, 0--3->1
6.921 - ///s: 0 t: 6
6.922 - ///maximum number of arc-disjoint shortest path: 2
6.923 - ///arcs of the maximum number of arc-disjoint shortest s-t paths:
6.924 - /// 9, 5--4->6
6.925 - /// 8, 4--2->6
6.926 - /// 7, 3--1->5
6.927 - /// 4, 2--2->4
6.928 - /// 2, 0--1->3
6.929 - /// 1, 0--2->2
6.930 - ///\endcode
6.931 - template<typename _Digraph, typename _ArcFilterMap>
6.932 - class ArcSubDigraphAdaptor :
6.933 - public SubDigraphAdaptor<_Digraph, ConstMap<typename _Digraph::Node, bool>,
6.934 - _ArcFilterMap, false> {
6.935 - public:
6.936 - typedef _Digraph Digraph;
6.937 - typedef _ArcFilterMap ArcFilterMap;
6.938 -
6.939 - typedef SubDigraphAdaptor<Digraph, ConstMap<typename Digraph::Node, bool>,
6.940 - ArcFilterMap, false> Parent;
6.941 -
6.942 - typedef typename Parent::Arc Arc;
6.943 -
6.944 - protected:
6.945 - ConstMap<typename Digraph::Node, bool> const_true_map;
6.946 -
6.947 - ArcSubDigraphAdaptor() : const_true_map(true) {
6.948 - Parent::setNodeFilterMap(const_true_map);
6.949 - }
6.950 -
6.951 - public:
6.952 -
6.953 - /// \brief Constructor
6.954 - ///
6.955 - /// Creates a arc-sub-digraph-adaptor for the given digraph with
6.956 - /// given arc map filter.
6.957 - ArcSubDigraphAdaptor(Digraph& digraph, ArcFilterMap& arc_filter)
6.958 - : Parent(), const_true_map(true) {
6.959 - Parent::setDigraph(digraph);
6.960 - Parent::setNodeFilterMap(const_true_map);
6.961 - Parent::setArcFilterMap(arc_filter);
6.962 - }
6.963 -
6.964 - /// \brief Hides the arc of the graph
6.965 - ///
6.966 - /// This function hides \c a in the digraph, i.e. the iteration
6.967 - /// jumps over it. This is done by simply setting the value of \c a
6.968 - /// to be false in the corresponding arc-map.
6.969 - void hide(const Arc& a) const { Parent::hide(a); }
6.970 -
6.971 - /// \brief Unhides the arc of the graph
6.972 - ///
6.973 - /// The value of \c a is set to be true in the arc-map which stores
6.974 - /// hide information. If \c a was hidden previuosly, then it is shown
6.975 - /// again
6.976 - void unHide(const Arc& a) const { Parent::unHide(a); }
6.977 -
6.978 - /// \brief Returns true if \c a is hidden.
6.979 - ///
6.980 - /// Returns true if \c a is hidden.
6.981 - ///
6.982 - bool hidden(const Arc& a) const { return Parent::hidden(a); }
6.983 -
6.984 - };
6.985 -
6.986 - /// \brief Just gives back an arc-sub-digraph adaptor
6.987 - ///
6.988 - /// Just gives back an arc-sub-digraph adaptor
6.989 - template<typename Digraph, typename ArcFilterMap>
6.990 - ArcSubDigraphAdaptor<const Digraph, ArcFilterMap>
6.991 - arcSubDigraphAdaptor(const Digraph& digraph, ArcFilterMap& afm) {
6.992 - return ArcSubDigraphAdaptor<const Digraph, ArcFilterMap>(digraph, afm);
6.993 - }
6.994 -
6.995 - template<typename Digraph, typename ArcFilterMap>
6.996 - ArcSubDigraphAdaptor<const Digraph, const ArcFilterMap>
6.997 - arcSubDigraphAdaptor(const Digraph& digraph, const ArcFilterMap& afm) {
6.998 - return ArcSubDigraphAdaptor<const Digraph, const ArcFilterMap>
6.999 - (digraph, afm);
6.1000 - }
6.1001 -
6.1002 - template <typename _Digraph>
6.1003 - class UndirDigraphAdaptorBase {
6.1004 - public:
6.1005 - typedef _Digraph Digraph;
6.1006 - typedef UndirDigraphAdaptorBase Adaptor;
6.1007 -
6.1008 - typedef True UndirectedTag;
6.1009 -
6.1010 - typedef typename Digraph::Arc Edge;
6.1011 - typedef typename Digraph::Node Node;
6.1012 -
6.1013 - class Arc : public Edge {
6.1014 - friend class UndirDigraphAdaptorBase;
6.1015 - protected:
6.1016 - bool _forward;
6.1017 -
6.1018 - Arc(const Edge& edge, bool forward) :
6.1019 - Edge(edge), _forward(forward) {}
6.1020 -
6.1021 - public:
6.1022 - Arc() {}
6.1023 -
6.1024 - Arc(Invalid) : Edge(INVALID), _forward(true) {}
6.1025 -
6.1026 - bool operator==(const Arc &other) const {
6.1027 - return _forward == other._forward &&
6.1028 - static_cast<const Edge&>(*this) == static_cast<const Edge&>(other);
6.1029 - }
6.1030 - bool operator!=(const Arc &other) const {
6.1031 - return _forward != other._forward ||
6.1032 - static_cast<const Edge&>(*this) != static_cast<const Edge&>(other);
6.1033 - }
6.1034 - bool operator<(const Arc &other) const {
6.1035 - return _forward < other._forward ||
6.1036 - (_forward == other._forward &&
6.1037 - static_cast<const Edge&>(*this) < static_cast<const Edge&>(other));
6.1038 - }
6.1039 - };
6.1040 -
6.1041 -
6.1042 -
6.1043 - void first(Node& n) const {
6.1044 - _digraph->first(n);
6.1045 - }
6.1046 -
6.1047 - void next(Node& n) const {
6.1048 - _digraph->next(n);
6.1049 - }
6.1050 -
6.1051 - void first(Arc& a) const {
6.1052 - _digraph->first(a);
6.1053 - a._forward = true;
6.1054 - }
6.1055 -
6.1056 - void next(Arc& a) const {
6.1057 - if (a._forward) {
6.1058 - a._forward = false;
6.1059 - } else {
6.1060 - _digraph->next(a);
6.1061 - a._forward = true;
6.1062 - }
6.1063 - }
6.1064 -
6.1065 - void first(Edge& e) const {
6.1066 - _digraph->first(e);
6.1067 - }
6.1068 -
6.1069 - void next(Edge& e) const {
6.1070 - _digraph->next(e);
6.1071 - }
6.1072 -
6.1073 - void firstOut(Arc& a, const Node& n) const {
6.1074 - _digraph->firstIn(a, n);
6.1075 - if( static_cast<const Edge&>(a) != INVALID ) {
6.1076 - a._forward = false;
6.1077 - } else {
6.1078 - _digraph->firstOut(a, n);
6.1079 - a._forward = true;
6.1080 - }
6.1081 - }
6.1082 - void nextOut(Arc &a) const {
6.1083 - if (!a._forward) {
6.1084 - Node n = _digraph->target(a);
6.1085 - _digraph->nextIn(a);
6.1086 - if (static_cast<const Edge&>(a) == INVALID ) {
6.1087 - _digraph->firstOut(a, n);
6.1088 - a._forward = true;
6.1089 - }
6.1090 - }
6.1091 - else {
6.1092 - _digraph->nextOut(a);
6.1093 - }
6.1094 - }
6.1095 -
6.1096 - void firstIn(Arc &a, const Node &n) const {
6.1097 - _digraph->firstOut(a, n);
6.1098 - if (static_cast<const Edge&>(a) != INVALID ) {
6.1099 - a._forward = false;
6.1100 - } else {
6.1101 - _digraph->firstIn(a, n);
6.1102 - a._forward = true;
6.1103 - }
6.1104 - }
6.1105 - void nextIn(Arc &a) const {
6.1106 - if (!a._forward) {
6.1107 - Node n = _digraph->source(a);
6.1108 - _digraph->nextOut(a);
6.1109 - if( static_cast<const Edge&>(a) == INVALID ) {
6.1110 - _digraph->firstIn(a, n);
6.1111 - a._forward = true;
6.1112 - }
6.1113 - }
6.1114 - else {
6.1115 - _digraph->nextIn(a);
6.1116 - }
6.1117 - }
6.1118 -
6.1119 - void firstInc(Edge &e, bool &d, const Node &n) const {
6.1120 - d = true;
6.1121 - _digraph->firstOut(e, n);
6.1122 - if (e != INVALID) return;
6.1123 - d = false;
6.1124 - _digraph->firstIn(e, n);
6.1125 - }
6.1126 -
6.1127 - void nextInc(Edge &e, bool &d) const {
6.1128 - if (d) {
6.1129 - Node s = _digraph->source(e);
6.1130 - _digraph->nextOut(e);
6.1131 - if (e != INVALID) return;
6.1132 - d = false;
6.1133 - _digraph->firstIn(e, s);
6.1134 - } else {
6.1135 - _digraph->nextIn(e);
6.1136 - }
6.1137 - }
6.1138 -
6.1139 - Node u(const Edge& e) const {
6.1140 - return _digraph->source(e);
6.1141 - }
6.1142 -
6.1143 - Node v(const Edge& e) const {
6.1144 - return _digraph->target(e);
6.1145 - }
6.1146 -
6.1147 - Node source(const Arc &a) const {
6.1148 - return a._forward ? _digraph->source(a) : _digraph->target(a);
6.1149 - }
6.1150 -
6.1151 - Node target(const Arc &a) const {
6.1152 - return a._forward ? _digraph->target(a) : _digraph->source(a);
6.1153 - }
6.1154 -
6.1155 - static Arc direct(const Edge &e, bool d) {
6.1156 - return Arc(e, d);
6.1157 - }
6.1158 - Arc direct(const Edge &e, const Node& n) const {
6.1159 - return Arc(e, _digraph->source(e) == n);
6.1160 - }
6.1161 -
6.1162 - static bool direction(const Arc &a) { return a._forward; }
6.1163 -
6.1164 - Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
6.1165 - Arc arcFromId(int ix) const {
6.1166 - return direct(_digraph->arcFromId(ix >> 1), bool(ix & 1));
6.1167 - }
6.1168 - Edge edgeFromId(int ix) const { return _digraph->arcFromId(ix); }
6.1169 -
6.1170 - int id(const Node &n) const { return _digraph->id(n); }
6.1171 - int id(const Arc &a) const {
6.1172 - return (_digraph->id(a) << 1) | (a._forward ? 1 : 0);
6.1173 - }
6.1174 - int id(const Edge &e) const { return _digraph->id(e); }
6.1175 -
6.1176 - int maxNodeId() const { return _digraph->maxNodeId(); }
6.1177 - int maxArcId() const { return (_digraph->maxArcId() << 1) | 1; }
6.1178 - int maxEdgeId() const { return _digraph->maxArcId(); }
6.1179 -
6.1180 - Node addNode() { return _digraph->addNode(); }
6.1181 - Edge addEdge(const Node& u, const Node& v) {
6.1182 - return _digraph->addArc(u, v);
6.1183 - }
6.1184 -
6.1185 - void erase(const Node& i) { _digraph->erase(i); }
6.1186 - void erase(const Edge& i) { _digraph->erase(i); }
6.1187 -
6.1188 - void clear() { _digraph->clear(); }
6.1189 -
6.1190 - typedef NodeNumTagIndicator<Digraph> NodeNumTag;
6.1191 - int nodeNum() const { return 2 * _digraph->arcNum(); }
6.1192 - typedef EdgeNumTagIndicator<Digraph> EdgeNumTag;
6.1193 - int arcNum() const { return 2 * _digraph->arcNum(); }
6.1194 - int edgeNum() const { return _digraph->arcNum(); }
6.1195 -
6.1196 - typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
6.1197 - Arc findArc(Node s, Node t, Arc p = INVALID) const {
6.1198 - if (p == INVALID) {
6.1199 - Edge arc = _digraph->findArc(s, t);
6.1200 - if (arc != INVALID) return direct(arc, true);
6.1201 - arc = _digraph->findArc(t, s);
6.1202 - if (arc != INVALID) return direct(arc, false);
6.1203 - } else if (direction(p)) {
6.1204 - Edge arc = _digraph->findArc(s, t, p);
6.1205 - if (arc != INVALID) return direct(arc, true);
6.1206 - arc = _digraph->findArc(t, s);
6.1207 - if (arc != INVALID) return direct(arc, false);
6.1208 - } else {
6.1209 - Edge arc = _digraph->findArc(t, s, p);
6.1210 - if (arc != INVALID) return direct(arc, false);
6.1211 - }
6.1212 - return INVALID;
6.1213 - }
6.1214 -
6.1215 - Edge findEdge(Node s, Node t, Edge p = INVALID) const {
6.1216 - if (s != t) {
6.1217 - if (p == INVALID) {
6.1218 - Edge arc = _digraph->findArc(s, t);
6.1219 - if (arc != INVALID) return arc;
6.1220 - arc = _digraph->findArc(t, s);
6.1221 - if (arc != INVALID) return arc;
6.1222 - } else if (_digraph->s(p) == s) {
6.1223 - Edge arc = _digraph->findArc(s, t, p);
6.1224 - if (arc != INVALID) return arc;
6.1225 - arc = _digraph->findArc(t, s);
6.1226 - if (arc != INVALID) return arc;
6.1227 - } else {
6.1228 - Edge arc = _digraph->findArc(t, s, p);
6.1229 - if (arc != INVALID) return arc;
6.1230 - }
6.1231 - } else {
6.1232 - return _digraph->findArc(s, t, p);
6.1233 - }
6.1234 - return INVALID;
6.1235 - }
6.1236 -
6.1237 - private:
6.1238 -
6.1239 - template <typename _Value>
6.1240 - class ArcMapBase {
6.1241 - private:
6.1242 -
6.1243 - typedef typename Digraph::template ArcMap<_Value> MapImpl;
6.1244 -
6.1245 - public:
6.1246 -
6.1247 - typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
6.1248 -
6.1249 - typedef _Value Value;
6.1250 - typedef Arc Key;
6.1251 -
6.1252 - ArcMapBase(const Adaptor& adaptor) :
6.1253 - _forward(*adaptor._digraph), _backward(*adaptor._digraph) {}
6.1254 -
6.1255 - ArcMapBase(const Adaptor& adaptor, const Value& v)
6.1256 - : _forward(*adaptor._digraph, v), _backward(*adaptor._digraph, v) {}
6.1257 -
6.1258 - void set(const Arc& a, const Value& v) {
6.1259 - if (direction(a)) {
6.1260 - _forward.set(a, v);
6.1261 - } else {
6.1262 - _backward.set(a, v);
6.1263 - }
6.1264 - }
6.1265 -
6.1266 - typename MapTraits<MapImpl>::ConstReturnValue
6.1267 - operator[](const Arc& a) const {
6.1268 - if (direction(a)) {
6.1269 - return _forward[a];
6.1270 - } else {
6.1271 - return _backward[a];
6.1272 - }
6.1273 - }
6.1274 -
6.1275 - typename MapTraits<MapImpl>::ReturnValue
6.1276 - operator[](const Arc& a) {
6.1277 - if (direction(a)) {
6.1278 - return _forward[a];
6.1279 - } else {
6.1280 - return _backward[a];
6.1281 - }
6.1282 - }
6.1283 -
6.1284 - protected:
6.1285 -
6.1286 - MapImpl _forward, _backward;
6.1287 -
6.1288 - };
6.1289 -
6.1290 - public:
6.1291 -
6.1292 - template <typename _Value>
6.1293 - class NodeMap : public Digraph::template NodeMap<_Value> {
6.1294 - public:
6.1295 -
6.1296 - typedef _Value Value;
6.1297 - typedef typename Digraph::template NodeMap<Value> Parent;
6.1298 -
6.1299 - explicit NodeMap(const Adaptor& adaptor)
6.1300 - : Parent(*adaptor._digraph) {}
6.1301 -
6.1302 - NodeMap(const Adaptor& adaptor, const _Value& value)
6.1303 - : Parent(*adaptor._digraph, value) { }
6.1304 -
6.1305 - private:
6.1306 - NodeMap& operator=(const NodeMap& cmap) {
6.1307 - return operator=<NodeMap>(cmap);
6.1308 - }
6.1309 -
6.1310 - template <typename CMap>
6.1311 - NodeMap& operator=(const CMap& cmap) {
6.1312 - Parent::operator=(cmap);
6.1313 - return *this;
6.1314 - }
6.1315 -
6.1316 - };
6.1317 -
6.1318 - template <typename _Value>
6.1319 - class ArcMap
6.1320 - : public SubMapExtender<Adaptor, ArcMapBase<_Value> >
6.1321 - {
6.1322 - public:
6.1323 - typedef _Value Value;
6.1324 - typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
6.1325 -
6.1326 - ArcMap(const Adaptor& adaptor)
6.1327 - : Parent(adaptor) {}
6.1328 -
6.1329 - ArcMap(const Adaptor& adaptor, const Value& value)
6.1330 - : Parent(adaptor, value) {}
6.1331 -
6.1332 - private:
6.1333 - ArcMap& operator=(const ArcMap& cmap) {
6.1334 - return operator=<ArcMap>(cmap);
6.1335 - }
6.1336 -
6.1337 - template <typename CMap>
6.1338 - ArcMap& operator=(const CMap& cmap) {
6.1339 - Parent::operator=(cmap);
6.1340 - return *this;
6.1341 - }
6.1342 - };
6.1343 -
6.1344 - template <typename _Value>
6.1345 - class EdgeMap : public Digraph::template ArcMap<_Value> {
6.1346 - public:
6.1347 -
6.1348 - typedef _Value Value;
6.1349 - typedef typename Digraph::template ArcMap<Value> Parent;
6.1350 -
6.1351 - explicit EdgeMap(const Adaptor& adaptor)
6.1352 - : Parent(*adaptor._digraph) {}
6.1353 -
6.1354 - EdgeMap(const Adaptor& adaptor, const Value& value)
6.1355 - : Parent(*adaptor._digraph, value) {}
6.1356 -
6.1357 - private:
6.1358 - EdgeMap& operator=(const EdgeMap& cmap) {
6.1359 - return operator=<EdgeMap>(cmap);
6.1360 - }
6.1361 -
6.1362 - template <typename CMap>
6.1363 - EdgeMap& operator=(const CMap& cmap) {
6.1364 - Parent::operator=(cmap);
6.1365 - return *this;
6.1366 - }
6.1367 -
6.1368 - };
6.1369 -
6.1370 - typedef typename ItemSetTraits<Digraph, Node>::ItemNotifier NodeNotifier;
6.1371 - NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
6.1372 -
6.1373 - protected:
6.1374 -
6.1375 - UndirDigraphAdaptorBase() : _digraph(0) {}
6.1376 -
6.1377 - Digraph* _digraph;
6.1378 -
6.1379 - void setDigraph(Digraph& digraph) {
6.1380 - _digraph = &digraph;
6.1381 - }
6.1382 -
6.1383 - };
6.1384 -
6.1385 - ///\ingroup graph_adaptors
6.1386 - ///
6.1387 - /// \brief A graph is made from a directed digraph by an adaptor
6.1388 - ///
6.1389 - /// This adaptor makes an undirected graph from a directed
6.1390 - /// graph. All arc of the underlying digraph will be showed in the
6.1391 - /// adaptor as an edge. Let's see an informal example about using
6.1392 - /// this adaptor.
6.1393 - ///
6.1394 - /// There is a network of the streets of a town. Of course there are
6.1395 - /// some one-way street in the town hence the network is a directed
6.1396 - /// one. There is a crazy driver who go oppositely in the one-way
6.1397 - /// street without moral sense. Of course he can pass this streets
6.1398 - /// slower than the regular way, in fact his speed is half of the
6.1399 - /// normal speed. How long should he drive to get from a source
6.1400 - /// point to the target? Let see the example code which calculate it:
6.1401 - ///
6.1402 - /// \todo BadCode, SimpleMap does no exists
6.1403 - ///\code
6.1404 - /// typedef UndirDigraphAdaptor<Digraph> Graph;
6.1405 - /// Graph graph(digraph);
6.1406 - ///
6.1407 - /// typedef SimpleMap<LengthMap> FLengthMap;
6.1408 - /// FLengthMap flength(length);
6.1409 - ///
6.1410 - /// typedef ScaleMap<LengthMap> RLengthMap;
6.1411 - /// RLengthMap rlength(length, 2.0);
6.1412 - ///
6.1413 - /// typedef Graph::CombinedArcMap<FLengthMap, RLengthMap > ULengthMap;
6.1414 - /// ULengthMap ulength(flength, rlength);
6.1415 - ///
6.1416 - /// Dijkstra<Graph, ULengthMap> dijkstra(graph, ulength);
6.1417 - /// std::cout << "Driving time : " << dijkstra.run(src, trg) << std::endl;
6.1418 - ///\endcode
6.1419 - ///
6.1420 - /// The combined arc map makes the length map for the undirected
6.1421 - /// graph. It is created from a forward and reverse map. The forward
6.1422 - /// map is created from the original length map with a SimpleMap
6.1423 - /// adaptor which just makes a read-write map from the reference map
6.1424 - /// i.e. it forgets that it can be return reference to values. The
6.1425 - /// reverse map is just the scaled original map with the ScaleMap
6.1426 - /// adaptor. The combination solves that passing the reverse way
6.1427 - /// takes double time than the original. To get the driving time we
6.1428 - /// run the dijkstra algorithm on the graph.
6.1429 - template<typename _Digraph>
6.1430 - class UndirDigraphAdaptor
6.1431 - : public GraphAdaptorExtender<UndirDigraphAdaptorBase<_Digraph> > {
6.1432 - public:
6.1433 - typedef _Digraph Digraph;
6.1434 - typedef GraphAdaptorExtender<UndirDigraphAdaptorBase<Digraph> > Parent;
6.1435 - protected:
6.1436 - UndirDigraphAdaptor() { }
6.1437 - public:
6.1438 -
6.1439 - /// \brief Constructor
6.1440 - ///
6.1441 - /// Constructor
6.1442 - UndirDigraphAdaptor(_Digraph& _digraph) {
6.1443 - setDigraph(_digraph);
6.1444 - }
6.1445 -
6.1446 - /// \brief ArcMap combined from two original ArcMap
6.1447 - ///
6.1448 - /// This class adapts two original digraph ArcMap to
6.1449 - /// get an arc map on the adaptor.
6.1450 - template <typename _ForwardMap, typename _BackwardMap>
6.1451 - class CombinedArcMap {
6.1452 - public:
6.1453 -
6.1454 - typedef _ForwardMap ForwardMap;
6.1455 - typedef _BackwardMap BackwardMap;
6.1456 -
6.1457 - typedef typename MapTraits<ForwardMap>::ReferenceMapTag ReferenceMapTag;
6.1458 -
6.1459 - typedef typename ForwardMap::Value Value;
6.1460 - typedef typename Parent::Arc Key;
6.1461 -
6.1462 - /// \brief Constructor
6.1463 - ///
6.1464 - /// Constructor
6.1465 - CombinedArcMap() : _forward(0), _backward(0) {}
6.1466 -
6.1467 - /// \brief Constructor
6.1468 - ///
6.1469 - /// Constructor
6.1470 - CombinedArcMap(ForwardMap& forward, BackwardMap& backward)
6.1471 - : _forward(&forward), _backward(&backward) {}
6.1472 -
6.1473 -
6.1474 - /// \brief Sets the value associated with a key.
6.1475 - ///
6.1476 - /// Sets the value associated with a key.
6.1477 - void set(const Key& e, const Value& a) {
6.1478 - if (Parent::direction(e)) {
6.1479 - _forward->set(e, a);
6.1480 - } else {
6.1481 - _backward->set(e, a);
6.1482 - }
6.1483 - }
6.1484 -
6.1485 - /// \brief Returns the value associated with a key.
6.1486 - ///
6.1487 - /// Returns the value associated with a key.
6.1488 - typename MapTraits<ForwardMap>::ConstReturnValue
6.1489 - operator[](const Key& e) const {
6.1490 - if (Parent::direction(e)) {
6.1491 - return (*_forward)[e];
6.1492 - } else {
6.1493 - return (*_backward)[e];
6.1494 - }
6.1495 - }
6.1496 -
6.1497 - /// \brief Returns the value associated with a key.
6.1498 - ///
6.1499 - /// Returns the value associated with a key.
6.1500 - typename MapTraits<ForwardMap>::ReturnValue
6.1501 - operator[](const Key& e) {
6.1502 - if (Parent::direction(e)) {
6.1503 - return (*_forward)[e];
6.1504 - } else {
6.1505 - return (*_backward)[e];
6.1506 - }
6.1507 - }
6.1508 -
6.1509 - /// \brief Sets the forward map
6.1510 - ///
6.1511 - /// Sets the forward map
6.1512 - void setForwardMap(ForwardMap& forward) {
6.1513 - _forward = &forward;
6.1514 - }
6.1515 -
6.1516 - /// \brief Sets the backward map
6.1517 - ///
6.1518 - /// Sets the backward map
6.1519 - void setBackwardMap(BackwardMap& backward) {
6.1520 - _backward = &backward;
6.1521 - }
6.1522 -
6.1523 - protected:
6.1524 -
6.1525 - ForwardMap* _forward;
6.1526 - BackwardMap* _backward;
6.1527 -
6.1528 - };
6.1529 -
6.1530 - };
6.1531 -
6.1532 - /// \brief Just gives back an undir digraph adaptor
6.1533 - ///
6.1534 - /// Just gives back an undir digraph adaptor
6.1535 - template<typename Digraph>
6.1536 - UndirDigraphAdaptor<const Digraph>
6.1537 - undirDigraphAdaptor(const Digraph& digraph) {
6.1538 - return UndirDigraphAdaptor<const Digraph>(digraph);
6.1539 - }
6.1540 -
6.1541 - template<typename _Digraph,
6.1542 - typename _CapacityMap = typename _Digraph::template ArcMap<int>,
6.1543 - typename _FlowMap = _CapacityMap,
6.1544 - typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
6.1545 - class ResForwardFilter {
6.1546 - public:
6.1547 -
6.1548 - typedef _Digraph Digraph;
6.1549 - typedef _CapacityMap CapacityMap;
6.1550 - typedef _FlowMap FlowMap;
6.1551 - typedef _Tolerance Tolerance;
6.1552 -
6.1553 - typedef typename Digraph::Arc Key;
6.1554 - typedef bool Value;
6.1555 -
6.1556 - private:
6.1557 -
6.1558 - const CapacityMap* _capacity;
6.1559 - const FlowMap* _flow;
6.1560 - Tolerance _tolerance;
6.1561 - public:
6.1562 -
6.1563 - ResForwardFilter(const CapacityMap& capacity, const FlowMap& flow,
6.1564 - const Tolerance& tolerance = Tolerance())
6.1565 - : _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
6.1566 -
6.1567 - ResForwardFilter(const Tolerance& tolerance = Tolerance())
6.1568 - : _capacity(0), _flow(0), _tolerance(tolerance) { }
6.1569 -
6.1570 - void setCapacity(const CapacityMap& capacity) { _capacity = &capacity; }
6.1571 - void setFlow(const FlowMap& flow) { _flow = &flow; }
6.1572 -
6.1573 - bool operator[](const typename Digraph::Arc& a) const {
6.1574 - return _tolerance.positive((*_capacity)[a] - (*_flow)[a]);
6.1575 - }
6.1576 - };
6.1577 -
6.1578 - template<typename _Digraph,
6.1579 - typename _CapacityMap = typename _Digraph::template ArcMap<int>,
6.1580 - typename _FlowMap = _CapacityMap,
6.1581 - typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
6.1582 - class ResBackwardFilter {
6.1583 - public:
6.1584 -
6.1585 - typedef _Digraph Digraph;
6.1586 - typedef _CapacityMap CapacityMap;
6.1587 - typedef _FlowMap FlowMap;
6.1588 - typedef _Tolerance Tolerance;
6.1589 -
6.1590 - typedef typename Digraph::Arc Key;
6.1591 - typedef bool Value;
6.1592 -
6.1593 - private:
6.1594 -
6.1595 - const CapacityMap* _capacity;
6.1596 - const FlowMap* _flow;
6.1597 - Tolerance _tolerance;
6.1598 -
6.1599 - public:
6.1600 -
6.1601 - ResBackwardFilter(const CapacityMap& capacity, const FlowMap& flow,
6.1602 - const Tolerance& tolerance = Tolerance())
6.1603 - : _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
6.1604 - ResBackwardFilter(const Tolerance& tolerance = Tolerance())
6.1605 - : _capacity(0), _flow(0), _tolerance(tolerance) { }
6.1606 -
6.1607 - void setCapacity(const CapacityMap& capacity) { _capacity = &capacity; }
6.1608 - void setFlow(const FlowMap& flow) { _flow = &flow; }
6.1609 -
6.1610 - bool operator[](const typename Digraph::Arc& a) const {
6.1611 - return _tolerance.positive((*_flow)[a]);
6.1612 - }
6.1613 - };
6.1614 -
6.1615 -
6.1616 - ///\ingroup graph_adaptors
6.1617 - ///
6.1618 - ///\brief An adaptor for composing the residual graph for directed
6.1619 - ///flow and circulation problems.
6.1620 - ///
6.1621 - ///An adaptor for composing the residual graph for directed flow and
6.1622 - ///circulation problems. Let \f$ G=(V, A) \f$ be a directed digraph
6.1623 - ///and let \f$ F \f$ be a number type. Let moreover \f$ f,c:A\to F
6.1624 - ///\f$, be functions on the arc-set.
6.1625 - ///
6.1626 - ///In the appications of ResDigraphAdaptor, \f$ f \f$ usually stands
6.1627 - ///for a flow and \f$ c \f$ for a capacity function. Suppose that a
6.1628 - ///graph instance \c g of type \c ListDigraph implements \f$ G \f$.
6.1629 - ///
6.1630 - ///\code
6.1631 - /// ListDigraph g;
6.1632 - ///\endcode
6.1633 - ///
6.1634 - ///Then ResDigraphAdaptor implements the digraph structure with
6.1635 - /// node-set \f$ V \f$ and arc-set \f$ A_{forward}\cup A_{backward}
6.1636 - /// \f$, where \f$ A_{forward}=\{uv : uv\in A, f(uv)<c(uv)\} \f$ and
6.1637 - /// \f$ A_{backward}=\{vu : uv\in A, f(uv)>0\} \f$, i.e. the so
6.1638 - /// called residual graph. When we take the union \f$
6.1639 - /// A_{forward}\cup A_{backward} \f$, multilicities are counted,
6.1640 - /// i.e. if an arc is in both \f$ A_{forward} \f$ and \f$
6.1641 - /// A_{backward} \f$, then in the adaptor it appears twice. The
6.1642 - /// following code shows how such an instance can be constructed.
6.1643 - ///
6.1644 - ///\code
6.1645 - /// typedef ListDigraph Digraph;
6.1646 - /// IntArcMap f(g), c(g);
6.1647 - /// ResDigraphAdaptor<Digraph, int, IntArcMap, IntArcMap> ga(g);
6.1648 - ///\endcode
6.1649 - template<typename _Digraph,
6.1650 - typename _CapacityMap = typename _Digraph::template ArcMap<int>,
6.1651 - typename _FlowMap = _CapacityMap,
6.1652 - typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
6.1653 - class ResDigraphAdaptor :
6.1654 - public ArcSubDigraphAdaptor<
6.1655 - UndirDigraphAdaptor<const _Digraph>,
6.1656 - typename UndirDigraphAdaptor<const _Digraph>::template CombinedArcMap<
6.1657 - ResForwardFilter<const _Digraph, _CapacityMap, _FlowMap>,
6.1658 - ResBackwardFilter<const _Digraph, _CapacityMap, _FlowMap> > > {
6.1659 - public:
6.1660 -
6.1661 - typedef _Digraph Digraph;
6.1662 - typedef _CapacityMap CapacityMap;
6.1663 - typedef _FlowMap FlowMap;
6.1664 - typedef _Tolerance Tolerance;
6.1665 -
6.1666 - typedef typename CapacityMap::Value Value;
6.1667 - typedef ResDigraphAdaptor Adaptor;
6.1668 -
6.1669 - protected:
6.1670 -
6.1671 - typedef UndirDigraphAdaptor<const Digraph> UndirDigraph;
6.1672 -
6.1673 - typedef ResForwardFilter<const Digraph, CapacityMap, FlowMap>
6.1674 - ForwardFilter;
6.1675 -
6.1676 - typedef ResBackwardFilter<const Digraph, CapacityMap, FlowMap>
6.1677 - BackwardFilter;
6.1678 -
6.1679 - typedef typename UndirDigraph::
6.1680 - template CombinedArcMap<ForwardFilter, BackwardFilter> ArcFilter;
6.1681 -
6.1682 - typedef ArcSubDigraphAdaptor<UndirDigraph, ArcFilter> Parent;
6.1683 -
6.1684 - const CapacityMap* _capacity;
6.1685 - FlowMap* _flow;
6.1686 -
6.1687 - UndirDigraph _graph;
6.1688 - ForwardFilter _forward_filter;
6.1689 - BackwardFilter _backward_filter;
6.1690 - ArcFilter _arc_filter;
6.1691 -
6.1692 - void setCapacityMap(const CapacityMap& capacity) {
6.1693 - _capacity = &capacity;
6.1694 - _forward_filter.setCapacity(capacity);
6.1695 - _backward_filter.setCapacity(capacity);
6.1696 - }
6.1697 -
6.1698 - void setFlowMap(FlowMap& flow) {
6.1699 - _flow = &flow;
6.1700 - _forward_filter.setFlow(flow);
6.1701 - _backward_filter.setFlow(flow);
6.1702 - }
6.1703 -
6.1704 - public:
6.1705 -
6.1706 - /// \brief Constructor of the residual digraph.
6.1707 - ///
6.1708 - /// Constructor of the residual graph. The parameters are the digraph type,
6.1709 - /// the flow map, the capacity map and a tolerance object.
6.1710 - ResDigraphAdaptor(const Digraph& digraph, const CapacityMap& capacity,
6.1711 - FlowMap& flow, const Tolerance& tolerance = Tolerance())
6.1712 - : Parent(), _capacity(&capacity), _flow(&flow), _graph(digraph),
6.1713 - _forward_filter(capacity, flow, tolerance),
6.1714 - _backward_filter(capacity, flow, tolerance),
6.1715 - _arc_filter(_forward_filter, _backward_filter)
6.1716 - {
6.1717 - Parent::setDigraph(_graph);
6.1718 - Parent::setArcFilterMap(_arc_filter);
6.1719 - }
6.1720 -
6.1721 - typedef typename Parent::Arc Arc;
6.1722 -
6.1723 - /// \brief Gives back the residual capacity of the arc.
6.1724 - ///
6.1725 - /// Gives back the residual capacity of the arc.
6.1726 - Value rescap(const Arc& arc) const {
6.1727 - if (UndirDigraph::direction(arc)) {
6.1728 - return (*_capacity)[arc] - (*_flow)[arc];
6.1729 - } else {
6.1730 - return (*_flow)[arc];
6.1731 - }
6.1732 - }
6.1733 -
6.1734 - /// \brief Augment on the given arc in the residual digraph.
6.1735 - ///
6.1736 - /// Augment on the given arc in the residual digraph. It increase
6.1737 - /// or decrease the flow on the original arc depend on the direction
6.1738 - /// of the residual arc.
6.1739 - void augment(const Arc& e, const Value& a) const {
6.1740 - if (UndirDigraph::direction(e)) {
6.1741 - _flow->set(e, (*_flow)[e] + a);
6.1742 - } else {
6.1743 - _flow->set(e, (*_flow)[e] - a);
6.1744 - }
6.1745 - }
6.1746 -
6.1747 - /// \brief Returns the direction of the arc.
6.1748 - ///
6.1749 - /// Returns true when the arc is same oriented as the original arc.
6.1750 - static bool forward(const Arc& e) {
6.1751 - return UndirDigraph::direction(e);
6.1752 - }
6.1753 -
6.1754 - /// \brief Returns the direction of the arc.
6.1755 - ///
6.1756 - /// Returns true when the arc is opposite oriented as the original arc.
6.1757 - static bool backward(const Arc& e) {
6.1758 - return !UndirDigraph::direction(e);
6.1759 - }
6.1760 -
6.1761 - /// \brief Gives back the forward oriented residual arc.
6.1762 - ///
6.1763 - /// Gives back the forward oriented residual arc.
6.1764 - static Arc forward(const typename Digraph::Arc& e) {
6.1765 - return UndirDigraph::direct(e, true);
6.1766 - }
6.1767 -
6.1768 - /// \brief Gives back the backward oriented residual arc.
6.1769 - ///
6.1770 - /// Gives back the backward oriented residual arc.
6.1771 - static Arc backward(const typename Digraph::Arc& e) {
6.1772 - return UndirDigraph::direct(e, false);
6.1773 - }
6.1774 -
6.1775 - /// \brief Residual capacity map.
6.1776 - ///
6.1777 - /// In generic residual digraphs the residual capacity can be obtained
6.1778 - /// as a map.
6.1779 - class ResCap {
6.1780 - protected:
6.1781 - const Adaptor* _adaptor;
6.1782 - public:
6.1783 - typedef Arc Key;
6.1784 - typedef typename _CapacityMap::Value Value;
6.1785 -
6.1786 - ResCap(const Adaptor& adaptor) : _adaptor(&adaptor) {}
6.1787 -
6.1788 - Value operator[](const Arc& e) const {
6.1789 - return _adaptor->rescap(e);
6.1790 - }
6.1791 -
6.1792 - };
6.1793 -
6.1794 - };
6.1795 -
6.1796 - template <typename _Digraph>
6.1797 - class SplitDigraphAdaptorBase {
6.1798 - public:
6.1799 -
6.1800 - typedef _Digraph Digraph;
6.1801 - typedef DigraphAdaptorBase<const _Digraph> Parent;
6.1802 - typedef SplitDigraphAdaptorBase Adaptor;
6.1803 -
6.1804 - typedef typename Digraph::Node DigraphNode;
6.1805 - typedef typename Digraph::Arc DigraphArc;
6.1806 -
6.1807 - class Node;
6.1808 - class Arc;
6.1809 -
6.1810 - private:
6.1811 -
6.1812 - template <typename T> class NodeMapBase;
6.1813 - template <typename T> class ArcMapBase;
6.1814 -
6.1815 - public:
6.1816 -
6.1817 - class Node : public DigraphNode {
6.1818 - friend class SplitDigraphAdaptorBase;
6.1819 - template <typename T> friend class NodeMapBase;
6.1820 - private:
6.1821 -
6.1822 - bool _in;
6.1823 - Node(DigraphNode node, bool in)
6.1824 - : DigraphNode(node), _in(in) {}
6.1825 -
6.1826 - public:
6.1827 -
6.1828 - Node() {}
6.1829 - Node(Invalid) : DigraphNode(INVALID), _in(true) {}
6.1830 -
6.1831 - bool operator==(const Node& node) const {
6.1832 - return DigraphNode::operator==(node) && _in == node._in;
6.1833 - }
6.1834 -
6.1835 - bool operator!=(const Node& node) const {
6.1836 - return !(*this == node);
6.1837 - }
6.1838 -
6.1839 - bool operator<(const Node& node) const {
6.1840 - return DigraphNode::operator<(node) ||
6.1841 - (DigraphNode::operator==(node) && _in < node._in);
6.1842 - }
6.1843 - };
6.1844 -
6.1845 - class Arc {
6.1846 - friend class SplitDigraphAdaptorBase;
6.1847 - template <typename T> friend class ArcMapBase;
6.1848 - private:
6.1849 - typedef BiVariant<DigraphArc, DigraphNode> ArcImpl;
6.1850 -
6.1851 - explicit Arc(const DigraphArc& arc) : _item(arc) {}
6.1852 - explicit Arc(const DigraphNode& node) : _item(node) {}
6.1853 -
6.1854 - ArcImpl _item;
6.1855 -
6.1856 - public:
6.1857 - Arc() {}
6.1858 - Arc(Invalid) : _item(DigraphArc(INVALID)) {}
6.1859 -
6.1860 - bool operator==(const Arc& arc) const {
6.1861 - if (_item.firstState()) {
6.1862 - if (arc._item.firstState()) {
6.1863 - return _item.first() == arc._item.first();
6.1864 - }
6.1865 - } else {
6.1866 - if (arc._item.secondState()) {
6.1867 - return _item.second() == arc._item.second();
6.1868 - }
6.1869 - }
6.1870 - return false;
6.1871 - }
6.1872 -
6.1873 - bool operator!=(const Arc& arc) const {
6.1874 - return !(*this == arc);
6.1875 - }
6.1876 -
6.1877 - bool operator<(const Arc& arc) const {
6.1878 - if (_item.firstState()) {
6.1879 - if (arc._item.firstState()) {
6.1880 - return _item.first() < arc._item.first();
6.1881 - }
6.1882 - return false;
6.1883 - } else {
6.1884 - if (arc._item.secondState()) {
6.1885 - return _item.second() < arc._item.second();
6.1886 - }
6.1887 - return true;
6.1888 - }
6.1889 - }
6.1890 -
6.1891 - operator DigraphArc() const { return _item.first(); }
6.1892 - operator DigraphNode() const { return _item.second(); }
6.1893 -
6.1894 - };
6.1895 -
6.1896 - void first(Node& n) const {
6.1897 - _digraph->first(n);
6.1898 - n._in = true;
6.1899 - }
6.1900 -
6.1901 - void next(Node& n) const {
6.1902 - if (n._in) {
6.1903 - n._in = false;
6.1904 - } else {
6.1905 - n._in = true;
6.1906 - _digraph->next(n);
6.1907 - }
6.1908 - }
6.1909 -
6.1910 - void first(Arc& e) const {
6.1911 - e._item.setSecond();
6.1912 - _digraph->first(e._item.second());
6.1913 - if (e._item.second() == INVALID) {
6.1914 - e._item.setFirst();
6.1915 - _digraph->first(e._item.first());
6.1916 - }
6.1917 - }
6.1918 -
6.1919 - void next(Arc& e) const {
6.1920 - if (e._item.secondState()) {
6.1921 - _digraph->next(e._item.second());
6.1922 - if (e._item.second() == INVALID) {
6.1923 - e._item.setFirst();
6.1924 - _digraph->first(e._item.first());
6.1925 - }
6.1926 - } else {
6.1927 - _digraph->next(e._item.first());
6.1928 - }
6.1929 - }
6.1930 -
6.1931 - void firstOut(Arc& e, const Node& n) const {
6.1932 - if (n._in) {
6.1933 - e._item.setSecond(n);
6.1934 - } else {
6.1935 - e._item.setFirst();
6.1936 - _digraph->firstOut(e._item.first(), n);
6.1937 - }
6.1938 - }
6.1939 -
6.1940 - void nextOut(Arc& e) const {
6.1941 - if (!e._item.firstState()) {
6.1942 - e._item.setFirst(INVALID);
6.1943 - } else {
6.1944 - _digraph->nextOut(e._item.first());
6.1945 - }
6.1946 - }
6.1947 -
6.1948 - void firstIn(Arc& e, const Node& n) const {
6.1949 - if (!n._in) {
6.1950 - e._item.setSecond(n);
6.1951 - } else {
6.1952 - e._item.setFirst();
6.1953 - _digraph->firstIn(e._item.first(), n);
6.1954 - }
6.1955 - }
6.1956 -
6.1957 - void nextIn(Arc& e) const {
6.1958 - if (!e._item.firstState()) {
6.1959 - e._item.setFirst(INVALID);
6.1960 - } else {
6.1961 - _digraph->nextIn(e._item.first());
6.1962 - }
6.1963 - }
6.1964 -
6.1965 - Node source(const Arc& e) const {
6.1966 - if (e._item.firstState()) {
6.1967 - return Node(_digraph->source(e._item.first()), false);
6.1968 - } else {
6.1969 - return Node(e._item.second(), true);
6.1970 - }
6.1971 - }
6.1972 -
6.1973 - Node target(const Arc& e) const {
6.1974 - if (e._item.firstState()) {
6.1975 - return Node(_digraph->target(e._item.first()), true);
6.1976 - } else {
6.1977 - return Node(e._item.second(), false);
6.1978 - }
6.1979 - }
6.1980 -
6.1981 - int id(const Node& n) const {
6.1982 - return (_digraph->id(n) << 1) | (n._in ? 0 : 1);
6.1983 - }
6.1984 - Node nodeFromId(int ix) const {
6.1985 - return Node(_digraph->nodeFromId(ix >> 1), (ix & 1) == 0);
6.1986 - }
6.1987 - int maxNodeId() const {
6.1988 - return 2 * _digraph->maxNodeId() + 1;
6.1989 - }
6.1990 -
6.1991 - int id(const Arc& e) const {
6.1992 - if (e._item.firstState()) {
6.1993 - return _digraph->id(e._item.first()) << 1;
6.1994 - } else {
6.1995 - return (_digraph->id(e._item.second()) << 1) | 1;
6.1996 - }
6.1997 - }
6.1998 - Arc arcFromId(int ix) const {
6.1999 - if ((ix & 1) == 0) {
6.2000 - return Arc(_digraph->arcFromId(ix >> 1));
6.2001 - } else {
6.2002 - return Arc(_digraph->nodeFromId(ix >> 1));
6.2003 - }
6.2004 - }
6.2005 - int maxArcId() const {
6.2006 - return std::max(_digraph->maxNodeId() << 1,
6.2007 - (_digraph->maxArcId() << 1) | 1);
6.2008 - }
6.2009 -
6.2010 - static bool inNode(const Node& n) {
6.2011 - return n._in;
6.2012 - }
6.2013 -
6.2014 - static bool outNode(const Node& n) {
6.2015 - return !n._in;
6.2016 - }
6.2017 -
6.2018 - static bool origArc(const Arc& e) {
6.2019 - return e._item.firstState();
6.2020 - }
6.2021 -
6.2022 - static bool bindArc(const Arc& e) {
6.2023 - return e._item.secondState();
6.2024 - }
6.2025 -
6.2026 - static Node inNode(const DigraphNode& n) {
6.2027 - return Node(n, true);
6.2028 - }
6.2029 -
6.2030 - static Node outNode(const DigraphNode& n) {
6.2031 - return Node(n, false);
6.2032 - }
6.2033 -
6.2034 - static Arc arc(const DigraphNode& n) {
6.2035 - return Arc(n);
6.2036 - }
6.2037 -
6.2038 - static Arc arc(const DigraphArc& e) {
6.2039 - return Arc(e);
6.2040 - }
6.2041 -
6.2042 - typedef True NodeNumTag;
6.2043 -
6.2044 - int nodeNum() const {
6.2045 - return 2 * countNodes(*_digraph);
6.2046 - }
6.2047 -
6.2048 - typedef True EdgeNumTag;
6.2049 - int arcNum() const {
6.2050 - return countArcs(*_digraph) + countNodes(*_digraph);
6.2051 - }
6.2052 -
6.2053 - typedef True FindEdgeTag;
6.2054 - Arc findArc(const Node& u, const Node& v,
6.2055 - const Arc& prev = INVALID) const {
6.2056 - if (inNode(u)) {
6.2057 - if (outNode(v)) {
6.2058 - if (static_cast<const DigraphNode&>(u) ==
6.2059 - static_cast<const DigraphNode&>(v) && prev == INVALID) {
6.2060 - return Arc(u);
6.2061 - }
6.2062 - }
6.2063 - } else {
6.2064 - if (inNode(v)) {
6.2065 - return Arc(::lemon::findArc(*_digraph, u, v, prev));
6.2066 - }
6.2067 - }
6.2068 - return INVALID;
6.2069 - }
6.2070 -
6.2071 - private:
6.2072 -
6.2073 - template <typename _Value>
6.2074 - class NodeMapBase
6.2075 - : public MapTraits<typename Parent::template NodeMap<_Value> > {
6.2076 - typedef typename Parent::template NodeMap<_Value> NodeImpl;
6.2077 - public:
6.2078 - typedef Node Key;
6.2079 - typedef _Value Value;
6.2080 -
6.2081 - NodeMapBase(const Adaptor& adaptor)
6.2082 - : _in_map(*adaptor._digraph), _out_map(*adaptor._digraph) {}
6.2083 - NodeMapBase(const Adaptor& adaptor, const Value& value)
6.2084 - : _in_map(*adaptor._digraph, value),
6.2085 - _out_map(*adaptor._digraph, value) {}
6.2086 -
6.2087 - void set(const Node& key, const Value& val) {
6.2088 - if (Adaptor::inNode(key)) { _in_map.set(key, val); }
6.2089 - else {_out_map.set(key, val); }
6.2090 - }
6.2091 -
6.2092 - typename MapTraits<NodeImpl>::ReturnValue
6.2093 - operator[](const Node& key) {
6.2094 - if (Adaptor::inNode(key)) { return _in_map[key]; }
6.2095 - else { return _out_map[key]; }
6.2096 - }
6.2097 -
6.2098 - typename MapTraits<NodeImpl>::ConstReturnValue
6.2099 - operator[](const Node& key) const {
6.2100 - if (Adaptor::inNode(key)) { return _in_map[key]; }
6.2101 - else { return _out_map[key]; }
6.2102 - }
6.2103 -
6.2104 - private:
6.2105 - NodeImpl _in_map, _out_map;
6.2106 - };
6.2107 -
6.2108 - template <typename _Value>
6.2109 - class ArcMapBase
6.2110 - : public MapTraits<typename Parent::template ArcMap<_Value> > {
6.2111 - typedef typename Parent::template ArcMap<_Value> ArcImpl;
6.2112 - typedef typename Parent::template NodeMap<_Value> NodeImpl;
6.2113 - public:
6.2114 - typedef Arc Key;
6.2115 - typedef _Value Value;
6.2116 -
6.2117 - ArcMapBase(const Adaptor& adaptor)
6.2118 - : _arc_map(*adaptor._digraph), _node_map(*adaptor._digraph) {}
6.2119 - ArcMapBase(const Adaptor& adaptor, const Value& value)
6.2120 - : _arc_map(*adaptor._digraph, value),
6.2121 - _node_map(*adaptor._digraph, value) {}
6.2122 -
6.2123 - void set(const Arc& key, const Value& val) {
6.2124 - if (Adaptor::origArc(key)) {
6.2125 - _arc_map.set(key._item.first(), val);
6.2126 - } else {
6.2127 - _node_map.set(key._item.second(), val);
6.2128 - }
6.2129 - }
6.2130 -
6.2131 - typename MapTraits<ArcImpl>::ReturnValue
6.2132 - operator[](const Arc& key) {
6.2133 - if (Adaptor::origArc(key)) {
6.2134 - return _arc_map[key._item.first()];
6.2135 - } else {
6.2136 - return _node_map[key._item.second()];
6.2137 - }
6.2138 - }
6.2139 -
6.2140 - typename MapTraits<ArcImpl>::ConstReturnValue
6.2141 - operator[](const Arc& key) const {
6.2142 - if (Adaptor::origArc(key)) {
6.2143 - return _arc_map[key._item.first()];
6.2144 - } else {
6.2145 - return _node_map[key._item.second()];
6.2146 - }
6.2147 - }
6.2148 -
6.2149 - private:
6.2150 - ArcImpl _arc_map;
6.2151 - NodeImpl _node_map;
6.2152 - };
6.2153 -
6.2154 - public:
6.2155 -
6.2156 - template <typename _Value>
6.2157 - class NodeMap
6.2158 - : public SubMapExtender<Adaptor, NodeMapBase<_Value> >
6.2159 - {
6.2160 - public:
6.2161 - typedef _Value Value;
6.2162 - typedef SubMapExtender<Adaptor, NodeMapBase<Value> > Parent;
6.2163 -
6.2164 - NodeMap(const Adaptor& adaptor)
6.2165 - : Parent(adaptor) {}
6.2166 -
6.2167 - NodeMap(const Adaptor& adaptor, const Value& value)
6.2168 - : Parent(adaptor, value) {}
6.2169 -
6.2170 - private:
6.2171 - NodeMap& operator=(const NodeMap& cmap) {
6.2172 - return operator=<NodeMap>(cmap);
6.2173 - }
6.2174 -
6.2175 - template <typename CMap>
6.2176 - NodeMap& operator=(const CMap& cmap) {
6.2177 - Parent::operator=(cmap);
6.2178 - return *this;
6.2179 - }
6.2180 - };
6.2181 -
6.2182 - template <typename _Value>
6.2183 - class ArcMap
6.2184 - : public SubMapExtender<Adaptor, ArcMapBase<_Value> >
6.2185 - {
6.2186 - public:
6.2187 - typedef _Value Value;
6.2188 - typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
6.2189 -
6.2190 - ArcMap(const Adaptor& adaptor)
6.2191 - : Parent(adaptor) {}
6.2192 -
6.2193 - ArcMap(const Adaptor& adaptor, const Value& value)
6.2194 - : Parent(adaptor, value) {}
6.2195 -
6.2196 - private:
6.2197 - ArcMap& operator=(const ArcMap& cmap) {
6.2198 - return operator=<ArcMap>(cmap);
6.2199 - }
6.2200 -
6.2201 - template <typename CMap>
6.2202 - ArcMap& operator=(const CMap& cmap) {
6.2203 - Parent::operator=(cmap);
6.2204 - return *this;
6.2205 - }
6.2206 - };
6.2207 -
6.2208 - protected:
6.2209 -
6.2210 - SplitDigraphAdaptorBase() : _digraph(0) {}
6.2211 -
6.2212 - Digraph* _digraph;
6.2213 -
6.2214 - void setDigraph(Digraph& digraph) {
6.2215 - _digraph = &digraph;
6.2216 - }
6.2217 -
6.2218 - };
6.2219 -
6.2220 - /// \ingroup graph_adaptors
6.2221 - ///
6.2222 - /// \brief Split digraph adaptor class
6.2223 - ///
6.2224 - /// This is an digraph adaptor which splits all node into an in-node
6.2225 - /// and an out-node. Formaly, the adaptor replaces each \f$ u \f$
6.2226 - /// node in the digraph with two node, \f$ u_{in} \f$ node and
6.2227 - /// \f$ u_{out} \f$ node. If there is an \f$ (v, u) \f$ arc in the
6.2228 - /// original digraph the new target of the arc will be \f$ u_{in} \f$ and
6.2229 - /// similarly the source of the original \f$ (u, v) \f$ arc will be
6.2230 - /// \f$ u_{out} \f$. The adaptor will add for each node in the
6.2231 - /// original digraph an additional arc which will connect
6.2232 - /// \f$ (u_{in}, u_{out}) \f$.
6.2233 - ///
6.2234 - /// The aim of this class is to run algorithm with node costs if the
6.2235 - /// algorithm can use directly just arc costs. In this case we should use
6.2236 - /// a \c SplitDigraphAdaptor and set the node cost of the digraph to the
6.2237 - /// bind arc in the adapted digraph.
6.2238 - ///
6.2239 - /// For example a maximum flow algorithm can compute how many arc
6.2240 - /// disjoint paths are in the digraph. But we would like to know how
6.2241 - /// many node disjoint paths are in the digraph. First we have to
6.2242 - /// adapt the digraph with the \c SplitDigraphAdaptor. Then run the flow
6.2243 - /// algorithm on the adapted digraph. The bottleneck of the flow will
6.2244 - /// be the bind arcs which bounds the flow with the count of the
6.2245 - /// node disjoint paths.
6.2246 - ///
6.2247 - ///\code
6.2248 - ///
6.2249 - /// typedef SplitDigraphAdaptor<SmartDigraph> SDigraph;
6.2250 - ///
6.2251 - /// SDigraph sdigraph(digraph);
6.2252 - ///
6.2253 - /// typedef ConstMap<SDigraph::Arc, int> SCapacity;
6.2254 - /// SCapacity scapacity(1);
6.2255 - ///
6.2256 - /// SDigraph::ArcMap<int> sflow(sdigraph);
6.2257 - ///
6.2258 - /// Preflow<SDigraph, SCapacity>
6.2259 - /// spreflow(sdigraph, scapacity,
6.2260 - /// SDigraph::outNode(source), SDigraph::inNode(target));
6.2261 - ///
6.2262 - /// spreflow.run();
6.2263 - ///
6.2264 - ///\endcode
6.2265 - ///
6.2266 - /// The result of the mamixum flow on the original digraph
6.2267 - /// shows the next figure:
6.2268 - ///
6.2269 - /// \image html arc_disjoint.png
6.2270 - /// \image latex arc_disjoint.eps "Arc disjoint paths" width=\textwidth
6.2271 - ///
6.2272 - /// And the maximum flow on the adapted digraph:
6.2273 - ///
6.2274 - /// \image html node_disjoint.png
6.2275 - /// \image latex node_disjoint.eps "Node disjoint paths" width=\textwidth
6.2276 - ///
6.2277 - /// The second solution contains just 3 disjoint paths while the first 4.
6.2278 - /// The full code can be found in the \ref disjoint_paths_demo.cc demo file.
6.2279 - ///
6.2280 - /// This digraph adaptor is fully conform to the
6.2281 - /// \ref concepts::Digraph "Digraph" concept and
6.2282 - /// contains some additional member functions and types. The
6.2283 - /// documentation of some member functions may be found just in the
6.2284 - /// SplitDigraphAdaptorBase class.
6.2285 - ///
6.2286 - /// \sa SplitDigraphAdaptorBase
6.2287 - template <typename _Digraph>
6.2288 - class SplitDigraphAdaptor
6.2289 - : public DigraphAdaptorExtender<SplitDigraphAdaptorBase<_Digraph> > {
6.2290 - public:
6.2291 - typedef _Digraph Digraph;
6.2292 - typedef DigraphAdaptorExtender<SplitDigraphAdaptorBase<Digraph> > Parent;
6.2293 -
6.2294 - typedef typename Digraph::Node DigraphNode;
6.2295 - typedef typename Digraph::Arc DigraphArc;
6.2296 -
6.2297 - typedef typename Parent::Node Node;
6.2298 - typedef typename Parent::Arc Arc;
6.2299 -
6.2300 - /// \brief Constructor of the adaptor.
6.2301 - ///
6.2302 - /// Constructor of the adaptor.
6.2303 - SplitDigraphAdaptor(Digraph& g) {
6.2304 - Parent::setDigraph(g);
6.2305 - }
6.2306 -
6.2307 - /// \brief Returns true when the node is in-node.
6.2308 - ///
6.2309 - /// Returns true when the node is in-node.
6.2310 - static bool inNode(const Node& n) {
6.2311 - return Parent::inNode(n);
6.2312 - }
6.2313 -
6.2314 - /// \brief Returns true when the node is out-node.
6.2315 - ///
6.2316 - /// Returns true when the node is out-node.
6.2317 - static bool outNode(const Node& n) {
6.2318 - return Parent::outNode(n);
6.2319 - }
6.2320 -
6.2321 - /// \brief Returns true when the arc is arc in the original digraph.
6.2322 - ///
6.2323 - /// Returns true when the arc is arc in the original digraph.
6.2324 - static bool origArc(const Arc& a) {
6.2325 - return Parent::origArc(a);
6.2326 - }
6.2327 -
6.2328 - /// \brief Returns true when the arc binds an in-node and an out-node.
6.2329 - ///
6.2330 - /// Returns true when the arc binds an in-node and an out-node.
6.2331 - static bool bindArc(const Arc& a) {
6.2332 - return Parent::bindArc(a);
6.2333 - }
6.2334 -
6.2335 - /// \brief Gives back the in-node created from the \c node.
6.2336 - ///
6.2337 - /// Gives back the in-node created from the \c node.
6.2338 - static Node inNode(const DigraphNode& n) {
6.2339 - return Parent::inNode(n);
6.2340 - }
6.2341 -
6.2342 - /// \brief Gives back the out-node created from the \c node.
6.2343 - ///
6.2344 - /// Gives back the out-node created from the \c node.
6.2345 - static Node outNode(const DigraphNode& n) {
6.2346 - return Parent::outNode(n);
6.2347 - }
6.2348 -
6.2349 - /// \brief Gives back the arc binds the two part of the node.
6.2350 - ///
6.2351 - /// Gives back the arc binds the two part of the node.
6.2352 - static Arc arc(const DigraphNode& n) {
6.2353 - return Parent::arc(n);
6.2354 - }
6.2355 -
6.2356 - /// \brief Gives back the arc of the original arc.
6.2357 - ///
6.2358 - /// Gives back the arc of the original arc.
6.2359 - static Arc arc(const DigraphArc& a) {
6.2360 - return Parent::arc(a);
6.2361 - }
6.2362 -
6.2363 - /// \brief NodeMap combined from two original NodeMap
6.2364 - ///
6.2365 - /// This class adapt two of the original digraph NodeMap to
6.2366 - /// get a node map on the adapted digraph.
6.2367 - template <typename InNodeMap, typename OutNodeMap>
6.2368 - class CombinedNodeMap {
6.2369 - public:
6.2370 -
6.2371 - typedef Node Key;
6.2372 - typedef typename InNodeMap::Value Value;
6.2373 -
6.2374 - /// \brief Constructor
6.2375 - ///
6.2376 - /// Constructor.
6.2377 - CombinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map)
6.2378 - : _in_map(in_map), _out_map(out_map) {}
6.2379 -
6.2380 - /// \brief The subscript operator.
6.2381 - ///
6.2382 - /// The subscript operator.
6.2383 - Value& operator[](const Key& key) {
6.2384 - if (Parent::inNode(key)) {
6.2385 - return _in_map[key];
6.2386 - } else {
6.2387 - return _out_map[key];
6.2388 - }
6.2389 - }
6.2390 -
6.2391 - /// \brief The const subscript operator.
6.2392 - ///
6.2393 - /// The const subscript operator.
6.2394 - Value operator[](const Key& key) const {
6.2395 - if (Parent::inNode(key)) {
6.2396 - return _in_map[key];
6.2397 - } else {
6.2398 - return _out_map[key];
6.2399 - }
6.2400 - }
6.2401 -
6.2402 - /// \brief The setter function of the map.
6.2403 - ///
6.2404 - /// The setter function of the map.
6.2405 - void set(const Key& key, const Value& value) {
6.2406 - if (Parent::inNode(key)) {
6.2407 - _in_map.set(key, value);
6.2408 - } else {
6.2409 - _out_map.set(key, value);
6.2410 - }
6.2411 - }
6.2412 -
6.2413 - private:
6.2414 -
6.2415 - InNodeMap& _in_map;
6.2416 - OutNodeMap& _out_map;
6.2417 -
6.2418 - };
6.2419 -
6.2420 -
6.2421 - /// \brief Just gives back a combined node map.
6.2422 - ///
6.2423 - /// Just gives back a combined node map.
6.2424 - template <typename InNodeMap, typename OutNodeMap>
6.2425 - static CombinedNodeMap<InNodeMap, OutNodeMap>
6.2426 - combinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) {
6.2427 - return CombinedNodeMap<InNodeMap, OutNodeMap>(in_map, out_map);
6.2428 - }
6.2429 -
6.2430 - template <typename InNodeMap, typename OutNodeMap>
6.2431 - static CombinedNodeMap<const InNodeMap, OutNodeMap>
6.2432 - combinedNodeMap(const InNodeMap& in_map, OutNodeMap& out_map) {
6.2433 - return CombinedNodeMap<const InNodeMap, OutNodeMap>(in_map, out_map);
6.2434 - }
6.2435 -
6.2436 - template <typename InNodeMap, typename OutNodeMap>
6.2437 - static CombinedNodeMap<InNodeMap, const OutNodeMap>
6.2438 - combinedNodeMap(InNodeMap& in_map, const OutNodeMap& out_map) {
6.2439 - return CombinedNodeMap<InNodeMap, const OutNodeMap>(in_map, out_map);
6.2440 - }
6.2441 -
6.2442 - template <typename InNodeMap, typename OutNodeMap>
6.2443 - static CombinedNodeMap<const InNodeMap, const OutNodeMap>
6.2444 - combinedNodeMap(const InNodeMap& in_map, const OutNodeMap& out_map) {
6.2445 - return CombinedNodeMap<const InNodeMap,
6.2446 - const OutNodeMap>(in_map, out_map);
6.2447 - }
6.2448 -
6.2449 - /// \brief ArcMap combined from an original ArcMap and NodeMap
6.2450 - ///
6.2451 - /// This class adapt an original digraph ArcMap and NodeMap to
6.2452 - /// get an arc map on the adapted digraph.
6.2453 - template <typename DigraphArcMap, typename DigraphNodeMap>
6.2454 - class CombinedArcMap {
6.2455 - public:
6.2456 -
6.2457 - typedef Arc Key;
6.2458 - typedef typename DigraphArcMap::Value Value;
6.2459 -
6.2460 - /// \brief Constructor
6.2461 - ///
6.2462 - /// Constructor.
6.2463 - CombinedArcMap(DigraphArcMap& arc_map, DigraphNodeMap& node_map)
6.2464 - : _arc_map(arc_map), _node_map(node_map) {}
6.2465 -
6.2466 - /// \brief The subscript operator.
6.2467 - ///
6.2468 - /// The subscript operator.
6.2469 - void set(const Arc& arc, const Value& val) {
6.2470 - if (Parent::origArc(arc)) {
6.2471 - _arc_map.set(arc, val);
6.2472 - } else {
6.2473 - _node_map.set(arc, val);
6.2474 - }
6.2475 - }
6.2476 -
6.2477 - /// \brief The const subscript operator.
6.2478 - ///
6.2479 - /// The const subscript operator.
6.2480 - Value operator[](const Key& arc) const {
6.2481 - if (Parent::origArc(arc)) {
6.2482 - return _arc_map[arc];
6.2483 - } else {
6.2484 - return _node_map[arc];
6.2485 - }
6.2486 - }
6.2487 -
6.2488 - /// \brief The const subscript operator.
6.2489 - ///
6.2490 - /// The const subscript operator.
6.2491 - Value& operator[](const Key& arc) {
6.2492 - if (Parent::origArc(arc)) {
6.2493 - return _arc_map[arc];
6.2494 - } else {
6.2495 - return _node_map[arc];
6.2496 - }
6.2497 - }
6.2498 -
6.2499 - private:
6.2500 - DigraphArcMap& _arc_map;
6.2501 - DigraphNodeMap& _node_map;
6.2502 - };
6.2503 -
6.2504 - /// \brief Just gives back a combined arc map.
6.2505 - ///
6.2506 - /// Just gives back a combined arc map.
6.2507 - template <typename DigraphArcMap, typename DigraphNodeMap>
6.2508 - static CombinedArcMap<DigraphArcMap, DigraphNodeMap>
6.2509 - combinedArcMap(DigraphArcMap& arc_map, DigraphNodeMap& node_map) {
6.2510 - return CombinedArcMap<DigraphArcMap, DigraphNodeMap>(arc_map, node_map);
6.2511 - }
6.2512 -
6.2513 - template <typename DigraphArcMap, typename DigraphNodeMap>
6.2514 - static CombinedArcMap<const DigraphArcMap, DigraphNodeMap>
6.2515 - combinedArcMap(const DigraphArcMap& arc_map, DigraphNodeMap& node_map) {
6.2516 - return CombinedArcMap<const DigraphArcMap,
6.2517 - DigraphNodeMap>(arc_map, node_map);
6.2518 - }
6.2519 -
6.2520 - template <typename DigraphArcMap, typename DigraphNodeMap>
6.2521 - static CombinedArcMap<DigraphArcMap, const DigraphNodeMap>
6.2522 - combinedArcMap(DigraphArcMap& arc_map, const DigraphNodeMap& node_map) {
6.2523 - return CombinedArcMap<DigraphArcMap,
6.2524 - const DigraphNodeMap>(arc_map, node_map);
6.2525 - }
6.2526 -
6.2527 - template <typename DigraphArcMap, typename DigraphNodeMap>
6.2528 - static CombinedArcMap<const DigraphArcMap, const DigraphNodeMap>
6.2529 - combinedArcMap(const DigraphArcMap& arc_map,
6.2530 - const DigraphNodeMap& node_map) {
6.2531 - return CombinedArcMap<const DigraphArcMap,
6.2532 - const DigraphNodeMap>(arc_map, node_map);
6.2533 - }
6.2534 -
6.2535 - };
6.2536 -
6.2537 - /// \brief Just gives back a split digraph adaptor
6.2538 - ///
6.2539 - /// Just gives back a split digraph adaptor
6.2540 - template<typename Digraph>
6.2541 - SplitDigraphAdaptor<Digraph>
6.2542 - splitDigraphAdaptor(const Digraph& digraph) {
6.2543 - return SplitDigraphAdaptor<Digraph>(digraph);
6.2544 - }
6.2545 -
6.2546 -
6.2547 -} //namespace lemon
6.2548 -
6.2549 -#endif //LEMON_DIGRAPH_ADAPTOR_H
6.2550 -
7.1 --- a/lemon/graph_adaptor.h Sun Nov 30 19:00:30 2008 +0100
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,1164 +0,0 @@
7.4 -/* -*- C++ -*-
7.5 - *
7.6 - * This file is a part of LEMON, a generic C++ optimization library
7.7 - *
7.8 - * Copyright (C) 2003-2008
7.9 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7.10 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
7.11 - *
7.12 - * Permission to use, modify and distribute this software is granted
7.13 - * provided that this copyright notice appears in all copies. For
7.14 - * precise terms see the accompanying LICENSE file.
7.15 - *
7.16 - * This software is provided "AS IS" with no warranty of any kind,
7.17 - * express or implied, and with no claim as to its suitability for any
7.18 - * purpose.
7.19 - *
7.20 - */
7.21 -
7.22 -#ifndef LEMON_GRAPH_ADAPTOR_H
7.23 -#define LEMON_GRAPH_ADAPTOR_H
7.24 -
7.25 -///\ingroup graph_adaptors
7.26 -///\file
7.27 -///\brief Several graph adaptors.
7.28 -///
7.29 -///This file contains several useful undirected graph adaptor classes.
7.30 -
7.31 -#include <lemon/core.h>
7.32 -#include <lemon/maps.h>
7.33 -#include <lemon/bits/graph_adaptor_extender.h>
7.34 -
7.35 -namespace lemon {
7.36 -
7.37 - template<typename _Graph>
7.38 - class GraphAdaptorBase {
7.39 - public:
7.40 - typedef _Graph Graph;
7.41 - typedef Graph ParentGraph;
7.42 -
7.43 - protected:
7.44 - Graph* _graph;
7.45 -
7.46 - GraphAdaptorBase() : _graph(0) {}
7.47 -
7.48 - void setGraph(Graph& graph) { _graph = &graph; }
7.49 -
7.50 - public:
7.51 - GraphAdaptorBase(Graph& graph) : _graph(&graph) {}
7.52 -
7.53 - typedef typename Graph::Node Node;
7.54 - typedef typename Graph::Arc Arc;
7.55 - typedef typename Graph::Edge Edge;
7.56 -
7.57 - void first(Node& i) const { _graph->first(i); }
7.58 - void first(Arc& i) const { _graph->first(i); }
7.59 - void first(Edge& i) const { _graph->first(i); }
7.60 - void firstIn(Arc& i, const Node& n) const { _graph->firstIn(i, n); }
7.61 - void firstOut(Arc& i, const Node& n ) const { _graph->firstOut(i, n); }
7.62 - void firstInc(Edge &i, bool &d, const Node &n) const {
7.63 - _graph->firstInc(i, d, n);
7.64 - }
7.65 -
7.66 - void next(Node& i) const { _graph->next(i); }
7.67 - void next(Arc& i) const { _graph->next(i); }
7.68 - void next(Edge& i) const { _graph->next(i); }
7.69 - void nextIn(Arc& i) const { _graph->nextIn(i); }
7.70 - void nextOut(Arc& i) const { _graph->nextOut(i); }
7.71 - void nextInc(Edge &i, bool &d) const { _graph->nextInc(i, d); }
7.72 -
7.73 - Node u(const Edge& e) const { return _graph->u(e); }
7.74 - Node v(const Edge& e) const { return _graph->v(e); }
7.75 -
7.76 - Node source(const Arc& a) const { return _graph->source(a); }
7.77 - Node target(const Arc& a) const { return _graph->target(a); }
7.78 -
7.79 - typedef NodeNumTagIndicator<Graph> NodeNumTag;
7.80 - int nodeNum() const { return _graph->nodeNum(); }
7.81 -
7.82 - typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
7.83 - int arcNum() const { return _graph->arcNum(); }
7.84 - int edgeNum() const { return _graph->edgeNum(); }
7.85 -
7.86 - typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
7.87 - Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
7.88 - return _graph->findArc(u, v, prev);
7.89 - }
7.90 - Edge findEdge(const Node& u, const Node& v, const Edge& prev = INVALID) {
7.91 - return _graph->findEdge(u, v, prev);
7.92 - }
7.93 -
7.94 - Node addNode() { return _graph->addNode(); }
7.95 - Edge addEdge(const Node& u, const Node& v) { return _graph->addEdge(u, v); }
7.96 -
7.97 - void erase(const Node& i) { _graph->erase(i); }
7.98 - void erase(const Edge& i) { _graph->erase(i); }
7.99 -
7.100 - void clear() { _graph->clear(); }
7.101 -
7.102 - bool direction(const Arc& a) const { return _graph->direction(a); }
7.103 - Arc direct(const Edge& e, bool d) const { return _graph->direct(e, d); }
7.104 -
7.105 - int id(const Node& v) const { return _graph->id(v); }
7.106 - int id(const Arc& a) const { return _graph->id(a); }
7.107 - int id(const Edge& e) const { return _graph->id(e); }
7.108 -
7.109 - Node nodeFromId(int ix) const { return _graph->nodeFromId(ix); }
7.110 - Arc arcFromId(int ix) const { return _graph->arcFromId(ix); }
7.111 - Edge edgeFromId(int ix) const { return _graph->edgeFromId(ix); }
7.112 -
7.113 - int maxNodeId() const { return _graph->maxNodeId(); }
7.114 - int maxArcId() const { return _graph->maxArcId(); }
7.115 - int maxEdgeId() const { return _graph->maxEdgeId(); }
7.116 -
7.117 - typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
7.118 - NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
7.119 -
7.120 - typedef typename ItemSetTraits<Graph, Arc>::ItemNotifier ArcNotifier;
7.121 - ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
7.122 -
7.123 - typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
7.124 - EdgeNotifier& notifier(Edge) const { return _graph->notifier(Edge()); }
7.125 -
7.126 - template <typename _Value>
7.127 - class NodeMap : public Graph::template NodeMap<_Value> {
7.128 - public:
7.129 - typedef typename Graph::template NodeMap<_Value> Parent;
7.130 - explicit NodeMap(const GraphAdaptorBase<Graph>& adapter)
7.131 - : Parent(*adapter._graph) {}
7.132 - NodeMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
7.133 - : Parent(*adapter._graph, value) {}
7.134 -
7.135 - private:
7.136 - NodeMap& operator=(const NodeMap& cmap) {
7.137 - return operator=<NodeMap>(cmap);
7.138 - }
7.139 -
7.140 - template <typename CMap>
7.141 - NodeMap& operator=(const CMap& cmap) {
7.142 - Parent::operator=(cmap);
7.143 - return *this;
7.144 - }
7.145 -
7.146 - };
7.147 -
7.148 - template <typename _Value>
7.149 - class ArcMap : public Graph::template ArcMap<_Value> {
7.150 - public:
7.151 - typedef typename Graph::template ArcMap<_Value> Parent;
7.152 - explicit ArcMap(const GraphAdaptorBase<Graph>& adapter)
7.153 - : Parent(*adapter._graph) {}
7.154 - ArcMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
7.155 - : Parent(*adapter._graph, value) {}
7.156 -
7.157 - private:
7.158 - ArcMap& operator=(const ArcMap& cmap) {
7.159 - return operator=<ArcMap>(cmap);
7.160 - }
7.161 -
7.162 - template <typename CMap>
7.163 - ArcMap& operator=(const CMap& cmap) {
7.164 - Parent::operator=(cmap);
7.165 - return *this;
7.166 - }
7.167 - };
7.168 -
7.169 - template <typename _Value>
7.170 - class EdgeMap : public Graph::template EdgeMap<_Value> {
7.171 - public:
7.172 - typedef typename Graph::template EdgeMap<_Value> Parent;
7.173 - explicit EdgeMap(const GraphAdaptorBase<Graph>& adapter)
7.174 - : Parent(*adapter._graph) {}
7.175 - EdgeMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
7.176 - : Parent(*adapter._graph, value) {}
7.177 -
7.178 - private:
7.179 - EdgeMap& operator=(const EdgeMap& cmap) {
7.180 - return operator=<EdgeMap>(cmap);
7.181 - }
7.182 -
7.183 - template <typename CMap>
7.184 - EdgeMap& operator=(const CMap& cmap) {
7.185 - Parent::operator=(cmap);
7.186 - return *this;
7.187 - }
7.188 - };
7.189 -
7.190 - };
7.191 -
7.192 - template <typename _Graph, typename NodeFilterMap,
7.193 - typename EdgeFilterMap, bool checked = true>
7.194 - class SubGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
7.195 - public:
7.196 - typedef _Graph Graph;
7.197 - typedef SubGraphAdaptorBase Adaptor;
7.198 - typedef GraphAdaptorBase<_Graph> Parent;
7.199 - protected:
7.200 -
7.201 - NodeFilterMap* _node_filter_map;
7.202 - EdgeFilterMap* _edge_filter_map;
7.203 -
7.204 - SubGraphAdaptorBase()
7.205 - : Parent(), _node_filter_map(0), _edge_filter_map(0) { }
7.206 -
7.207 - void setNodeFilterMap(NodeFilterMap& node_filter_map) {
7.208 - _node_filter_map=&node_filter_map;
7.209 - }
7.210 - void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
7.211 - _edge_filter_map=&edge_filter_map;
7.212 - }
7.213 -
7.214 - public:
7.215 -
7.216 - typedef typename Parent::Node Node;
7.217 - typedef typename Parent::Arc Arc;
7.218 - typedef typename Parent::Edge Edge;
7.219 -
7.220 - void first(Node& i) const {
7.221 - Parent::first(i);
7.222 - while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
7.223 - }
7.224 -
7.225 - void first(Arc& i) const {
7.226 - Parent::first(i);
7.227 - while (i!=INVALID && (!(*_edge_filter_map)[i]
7.228 - || !(*_node_filter_map)[Parent::source(i)]
7.229 - || !(*_node_filter_map)[Parent::target(i)])) Parent::next(i);
7.230 - }
7.231 -
7.232 - void first(Edge& i) const {
7.233 - Parent::first(i);
7.234 - while (i!=INVALID && (!(*_edge_filter_map)[i]
7.235 - || !(*_node_filter_map)[Parent::u(i)]
7.236 - || !(*_node_filter_map)[Parent::v(i)])) Parent::next(i);
7.237 - }
7.238 -
7.239 - void firstIn(Arc& i, const Node& n) const {
7.240 - Parent::firstIn(i, n);
7.241 - while (i!=INVALID && (!(*_edge_filter_map)[i]
7.242 - || !(*_node_filter_map)[Parent::source(i)])) Parent::nextIn(i);
7.243 - }
7.244 -
7.245 - void firstOut(Arc& i, const Node& n) const {
7.246 - Parent::firstOut(i, n);
7.247 - while (i!=INVALID && (!(*_edge_filter_map)[i]
7.248 - || !(*_node_filter_map)[Parent::target(i)])) Parent::nextOut(i);
7.249 - }
7.250 -
7.251 - void firstInc(Edge& i, bool& d, const Node& n) const {
7.252 - Parent::firstInc(i, d, n);
7.253 - while (i!=INVALID && (!(*_edge_filter_map)[i]
7.254 - || !(*_node_filter_map)[Parent::u(i)]
7.255 - || !(*_node_filter_map)[Parent::v(i)])) Parent::nextInc(i, d);
7.256 - }
7.257 -
7.258 - void next(Node& i) const {
7.259 - Parent::next(i);
7.260 - while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
7.261 - }
7.262 -
7.263 - void next(Arc& i) const {
7.264 - Parent::next(i);
7.265 - while (i!=INVALID && (!(*_edge_filter_map)[i]
7.266 - || !(*_node_filter_map)[Parent::source(i)]
7.267 - || !(*_node_filter_map)[Parent::target(i)])) Parent::next(i);
7.268 - }
7.269 -
7.270 - void next(Edge& i) const {
7.271 - Parent::next(i);
7.272 - while (i!=INVALID && (!(*_edge_filter_map)[i]
7.273 - || !(*_node_filter_map)[Parent::u(i)]
7.274 - || !(*_node_filter_map)[Parent::v(i)])) Parent::next(i);
7.275 - }
7.276 -
7.277 - void nextIn(Arc& i) const {
7.278 - Parent::nextIn(i);
7.279 - while (i!=INVALID && (!(*_edge_filter_map)[i]
7.280 - || !(*_node_filter_map)[Parent::source(i)])) Parent::nextIn(i);
7.281 - }
7.282 -
7.283 - void nextOut(Arc& i) const {
7.284 - Parent::nextOut(i);
7.285 - while (i!=INVALID && (!(*_edge_filter_map)[i]
7.286 - || !(*_node_filter_map)[Parent::target(i)])) Parent::nextOut(i);
7.287 - }
7.288 -
7.289 - void nextInc(Edge& i, bool& d) const {
7.290 - Parent::nextInc(i, d);
7.291 - while (i!=INVALID && (!(*_edge_filter_map)[i]
7.292 - || !(*_node_filter_map)[Parent::u(i)]
7.293 - || !(*_node_filter_map)[Parent::v(i)])) Parent::nextInc(i, d);
7.294 - }
7.295 -
7.296 - void hide(const Node& n) const { _node_filter_map->set(n, false); }
7.297 - void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
7.298 -
7.299 - void unHide(const Node& n) const { _node_filter_map->set(n, true); }
7.300 - void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
7.301 -
7.302 - bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; }
7.303 - bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
7.304 -
7.305 - typedef False NodeNumTag;
7.306 - typedef False EdgeNumTag;
7.307 -
7.308 - typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
7.309 - Arc findArc(const Node& u, const Node& v,
7.310 - const Arc& prev = INVALID) {
7.311 - if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
7.312 - return INVALID;
7.313 - }
7.314 - Arc arc = Parent::findArc(u, v, prev);
7.315 - while (arc != INVALID && !(*_edge_filter_map)[arc]) {
7.316 - arc = Parent::findArc(u, v, arc);
7.317 - }
7.318 - return arc;
7.319 - }
7.320 - Edge findEdge(const Node& u, const Node& v,
7.321 - const Edge& prev = INVALID) {
7.322 - if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
7.323 - return INVALID;
7.324 - }
7.325 - Edge edge = Parent::findEdge(u, v, prev);
7.326 - while (edge != INVALID && !(*_edge_filter_map)[edge]) {
7.327 - edge = Parent::findEdge(u, v, edge);
7.328 - }
7.329 - return edge;
7.330 - }
7.331 -
7.332 - template <typename _Value>
7.333 - class NodeMap : public SubMapExtender<Adaptor,
7.334 - typename Parent::template NodeMap<_Value> > {
7.335 - public:
7.336 - typedef _Value Value;
7.337 - typedef SubMapExtender<Adaptor, typename Parent::
7.338 - template NodeMap<Value> > MapParent;
7.339 -
7.340 - NodeMap(const Adaptor& adaptor)
7.341 - : MapParent(adaptor) {}
7.342 - NodeMap(const Adaptor& adaptor, const Value& value)
7.343 - : MapParent(adaptor, value) {}
7.344 -
7.345 - private:
7.346 - NodeMap& operator=(const NodeMap& cmap) {
7.347 - return operator=<NodeMap>(cmap);
7.348 - }
7.349 -
7.350 - template <typename CMap>
7.351 - NodeMap& operator=(const CMap& cmap) {
7.352 - MapParent::operator=(cmap);
7.353 - return *this;
7.354 - }
7.355 - };
7.356 -
7.357 - template <typename _Value>
7.358 - class ArcMap : public SubMapExtender<Adaptor,
7.359 - typename Parent::template ArcMap<_Value> > {
7.360 - public:
7.361 - typedef _Value Value;
7.362 - typedef SubMapExtender<Adaptor, typename Parent::
7.363 - template ArcMap<Value> > MapParent;
7.364 -
7.365 - ArcMap(const Adaptor& adaptor)
7.366 - : MapParent(adaptor) {}
7.367 - ArcMap(const Adaptor& adaptor, const Value& value)
7.368 - : MapParent(adaptor, value) {}
7.369 -
7.370 - private:
7.371 - ArcMap& operator=(const ArcMap& cmap) {
7.372 - return operator=<ArcMap>(cmap);
7.373 - }
7.374 -
7.375 - template <typename CMap>
7.376 - ArcMap& operator=(const CMap& cmap) {
7.377 - MapParent::operator=(cmap);
7.378 - return *this;
7.379 - }
7.380 - };
7.381 -
7.382 - template <typename _Value>
7.383 - class EdgeMap : public SubMapExtender<Adaptor,
7.384 - typename Parent::template EdgeMap<_Value> > {
7.385 - public:
7.386 - typedef _Value Value;
7.387 - typedef SubMapExtender<Adaptor, typename Parent::
7.388 - template EdgeMap<Value> > MapParent;
7.389 -
7.390 - EdgeMap(const Adaptor& adaptor)
7.391 - : MapParent(adaptor) {}
7.392 -
7.393 - EdgeMap(const Adaptor& adaptor, const Value& value)
7.394 - : MapParent(adaptor, value) {}
7.395 -
7.396 - private:
7.397 - EdgeMap& operator=(const EdgeMap& cmap) {
7.398 - return operator=<EdgeMap>(cmap);
7.399 - }
7.400 -
7.401 - template <typename CMap>
7.402 - EdgeMap& operator=(const CMap& cmap) {
7.403 - MapParent::operator=(cmap);
7.404 - return *this;
7.405 - }
7.406 - };
7.407 -
7.408 - };
7.409 -
7.410 - template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
7.411 - class SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap, false>
7.412 - : public GraphAdaptorBase<_Graph> {
7.413 - public:
7.414 - typedef _Graph Graph;
7.415 - typedef SubGraphAdaptorBase Adaptor;
7.416 - typedef GraphAdaptorBase<_Graph> Parent;
7.417 - protected:
7.418 - NodeFilterMap* _node_filter_map;
7.419 - EdgeFilterMap* _edge_filter_map;
7.420 - SubGraphAdaptorBase() : Parent(),
7.421 - _node_filter_map(0), _edge_filter_map(0) { }
7.422 -
7.423 - void setNodeFilterMap(NodeFilterMap& node_filter_map) {
7.424 - _node_filter_map=&node_filter_map;
7.425 - }
7.426 - void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
7.427 - _edge_filter_map=&edge_filter_map;
7.428 - }
7.429 -
7.430 - public:
7.431 -
7.432 - typedef typename Parent::Node Node;
7.433 - typedef typename Parent::Arc Arc;
7.434 - typedef typename Parent::Edge Edge;
7.435 -
7.436 - void first(Node& i) const {
7.437 - Parent::first(i);
7.438 - while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
7.439 - }
7.440 -
7.441 - void first(Arc& i) const {
7.442 - Parent::first(i);
7.443 - while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
7.444 - }
7.445 -
7.446 - void first(Edge& i) const {
7.447 - Parent::first(i);
7.448 - while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
7.449 - }
7.450 -
7.451 - void firstIn(Arc& i, const Node& n) const {
7.452 - Parent::firstIn(i, n);
7.453 - while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i);
7.454 - }
7.455 -
7.456 - void firstOut(Arc& i, const Node& n) const {
7.457 - Parent::firstOut(i, n);
7.458 - while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i);
7.459 - }
7.460 -
7.461 - void firstInc(Edge& i, bool& d, const Node& n) const {
7.462 - Parent::firstInc(i, d, n);
7.463 - while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d);
7.464 - }
7.465 -
7.466 - void next(Node& i) const {
7.467 - Parent::next(i);
7.468 - while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
7.469 - }
7.470 - void next(Arc& i) const {
7.471 - Parent::next(i);
7.472 - while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
7.473 - }
7.474 - void next(Edge& i) const {
7.475 - Parent::next(i);
7.476 - while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
7.477 - }
7.478 - void nextIn(Arc& i) const {
7.479 - Parent::nextIn(i);
7.480 - while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i);
7.481 - }
7.482 -
7.483 - void nextOut(Arc& i) const {
7.484 - Parent::nextOut(i);
7.485 - while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i);
7.486 - }
7.487 - void nextInc(Edge& i, bool& d) const {
7.488 - Parent::nextInc(i, d);
7.489 - while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d);
7.490 - }
7.491 -
7.492 - void hide(const Node& n) const { _node_filter_map->set(n, false); }
7.493 - void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
7.494 -
7.495 - void unHide(const Node& n) const { _node_filter_map->set(n, true); }
7.496 - void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
7.497 -
7.498 - bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; }
7.499 - bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
7.500 -
7.501 - typedef False NodeNumTag;
7.502 - typedef False EdgeNumTag;
7.503 -
7.504 - typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
7.505 - Arc findArc(const Node& u, const Node& v,
7.506 - const Arc& prev = INVALID) {
7.507 - Arc arc = Parent::findArc(u, v, prev);
7.508 - while (arc != INVALID && !(*_edge_filter_map)[arc]) {
7.509 - arc = Parent::findArc(u, v, arc);
7.510 - }
7.511 - return arc;
7.512 - }
7.513 - Edge findEdge(const Node& u, const Node& v,
7.514 - const Edge& prev = INVALID) {
7.515 - Edge edge = Parent::findEdge(u, v, prev);
7.516 - while (edge != INVALID && !(*_edge_filter_map)[edge]) {
7.517 - edge = Parent::findEdge(u, v, edge);
7.518 - }
7.519 - return edge;
7.520 - }
7.521 -
7.522 - template <typename _Value>
7.523 - class NodeMap : public SubMapExtender<Adaptor,
7.524 - typename Parent::template NodeMap<_Value> > {
7.525 - public:
7.526 - typedef _Value Value;
7.527 - typedef SubMapExtender<Adaptor, typename Parent::
7.528 - template NodeMap<Value> > MapParent;
7.529 -
7.530 - NodeMap(const Adaptor& adaptor)
7.531 - : MapParent(adaptor) {}
7.532 - NodeMap(const Adaptor& adaptor, const Value& value)
7.533 - : MapParent(adaptor, value) {}
7.534 -
7.535 - private:
7.536 - NodeMap& operator=(const NodeMap& cmap) {
7.537 - return operator=<NodeMap>(cmap);
7.538 - }
7.539 -
7.540 - template <typename CMap>
7.541 - NodeMap& operator=(const CMap& cmap) {
7.542 - MapParent::operator=(cmap);
7.543 - return *this;
7.544 - }
7.545 - };
7.546 -
7.547 - template <typename _Value>
7.548 - class ArcMap : public SubMapExtender<Adaptor,
7.549 - typename Parent::template ArcMap<_Value> > {
7.550 - public:
7.551 - typedef _Value Value;
7.552 - typedef SubMapExtender<Adaptor, typename Parent::
7.553 - template ArcMap<Value> > MapParent;
7.554 -
7.555 - ArcMap(const Adaptor& adaptor)
7.556 - : MapParent(adaptor) {}
7.557 - ArcMap(const Adaptor& adaptor, const Value& value)
7.558 - : MapParent(adaptor, value) {}
7.559 -
7.560 - private:
7.561 - ArcMap& operator=(const ArcMap& cmap) {
7.562 - return operator=<ArcMap>(cmap);
7.563 - }
7.564 -
7.565 - template <typename CMap>
7.566 - ArcMap& operator=(const CMap& cmap) {
7.567 - MapParent::operator=(cmap);
7.568 - return *this;
7.569 - }
7.570 - };
7.571 -
7.572 - template <typename _Value>
7.573 - class EdgeMap : public SubMapExtender<Adaptor,
7.574 - typename Parent::template EdgeMap<_Value> > {
7.575 - public:
7.576 - typedef _Value Value;
7.577 - typedef SubMapExtender<Adaptor, typename Parent::
7.578 - template EdgeMap<Value> > MapParent;
7.579 -
7.580 - EdgeMap(const Adaptor& adaptor)
7.581 - : MapParent(adaptor) {}
7.582 -
7.583 - EdgeMap(const Adaptor& adaptor, const _Value& value)
7.584 - : MapParent(adaptor, value) {}
7.585 -
7.586 - private:
7.587 - EdgeMap& operator=(const EdgeMap& cmap) {
7.588 - return operator=<EdgeMap>(cmap);
7.589 - }
7.590 -
7.591 - template <typename CMap>
7.592 - EdgeMap& operator=(const CMap& cmap) {
7.593 - MapParent::operator=(cmap);
7.594 - return *this;
7.595 - }
7.596 - };
7.597 -
7.598 - };
7.599 -
7.600 - /// \ingroup graph_adaptors
7.601 - ///
7.602 - /// \brief A graph adaptor for hiding nodes and edges from an
7.603 - /// undirected graph.
7.604 - ///
7.605 - /// SubGraphAdaptor shows the graph with filtered node-set and
7.606 - /// edge-set. If the \c checked parameter is true then it filters
7.607 - /// the edge-set to do not get invalid edges which incident node is
7.608 - /// filtered.
7.609 - ///
7.610 - /// If the \c checked template parameter is false then we have to
7.611 - /// note that the node-iterator cares only the filter on the
7.612 - /// node-set, and the edge-iterator cares only the filter on the
7.613 - /// edge-set. This way the edge-map should filter all arcs which
7.614 - /// has filtered end node.
7.615 - template<typename _Graph, typename NodeFilterMap,
7.616 - typename EdgeFilterMap, bool checked = true>
7.617 - class SubGraphAdaptor :
7.618 - public GraphAdaptorExtender<
7.619 - SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap, checked> > {
7.620 - public:
7.621 - typedef _Graph Graph;
7.622 - typedef GraphAdaptorExtender<
7.623 - SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent;
7.624 -
7.625 - typedef typename Parent::Node Node;
7.626 - typedef typename Parent::Edge Edge;
7.627 -
7.628 - protected:
7.629 - SubGraphAdaptor() { }
7.630 - public:
7.631 -
7.632 - /// \brief Constructor
7.633 - ///
7.634 - /// Creates a sub-graph-adaptor for the given graph with
7.635 - /// given node and edge map filters.
7.636 - SubGraphAdaptor(Graph& _graph, NodeFilterMap& node_filter_map,
7.637 - EdgeFilterMap& edge_filter_map) {
7.638 - setGraph(_graph);
7.639 - setNodeFilterMap(node_filter_map);
7.640 - setEdgeFilterMap(edge_filter_map);
7.641 - }
7.642 -
7.643 - /// \brief Hides the node of the graph
7.644 - ///
7.645 - /// This function hides \c n in the digraph, i.e. the iteration
7.646 - /// jumps over it. This is done by simply setting the value of \c n
7.647 - /// to be false in the corresponding node-map.
7.648 - void hide(const Node& n) const { Parent::hide(n); }
7.649 -
7.650 - /// \brief Hides the edge of the graph
7.651 - ///
7.652 - /// This function hides \c e in the digraph, i.e. the iteration
7.653 - /// jumps over it. This is done by simply setting the value of \c e
7.654 - /// to be false in the corresponding edge-map.
7.655 - void hide(const Edge& e) const { Parent::hide(e); }
7.656 -
7.657 - /// \brief Unhides the node of the graph
7.658 - ///
7.659 - /// The value of \c n is set to be true in the node-map which stores
7.660 - /// hide information. If \c n was hidden previuosly, then it is shown
7.661 - /// again
7.662 - void unHide(const Node& n) const { Parent::unHide(n); }
7.663 -
7.664 - /// \brief Unhides the edge of the graph
7.665 - ///
7.666 - /// The value of \c e is set to be true in the edge-map which stores
7.667 - /// hide information. If \c e was hidden previuosly, then it is shown
7.668 - /// again
7.669 - void unHide(const Edge& e) const { Parent::unHide(e); }
7.670 -
7.671 - /// \brief Returns true if \c n is hidden.
7.672 - ///
7.673 - /// Returns true if \c n is hidden.
7.674 - ///
7.675 - bool hidden(const Node& n) const { return Parent::hidden(n); }
7.676 -
7.677 - /// \brief Returns true if \c e is hidden.
7.678 - ///
7.679 - /// Returns true if \c e is hidden.
7.680 - ///
7.681 - bool hidden(const Edge& e) const { return Parent::hidden(e); }
7.682 - };
7.683 -
7.684 - /// \brief Just gives back a sub-graph adaptor
7.685 - ///
7.686 - /// Just gives back a sub-graph adaptor
7.687 - template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
7.688 - SubGraphAdaptor<const Graph, NodeFilterMap, ArcFilterMap>
7.689 - subGraphAdaptor(const Graph& graph,
7.690 - NodeFilterMap& nfm, ArcFilterMap& efm) {
7.691 - return SubGraphAdaptor<const Graph, NodeFilterMap, ArcFilterMap>
7.692 - (graph, nfm, efm);
7.693 - }
7.694 -
7.695 - template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
7.696 - SubGraphAdaptor<const Graph, const NodeFilterMap, ArcFilterMap>
7.697 - subGraphAdaptor(const Graph& graph,
7.698 - NodeFilterMap& nfm, ArcFilterMap& efm) {
7.699 - return SubGraphAdaptor<const Graph, const NodeFilterMap, ArcFilterMap>
7.700 - (graph, nfm, efm);
7.701 - }
7.702 -
7.703 - template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
7.704 - SubGraphAdaptor<const Graph, NodeFilterMap, const ArcFilterMap>
7.705 - subGraphAdaptor(const Graph& graph,
7.706 - NodeFilterMap& nfm, ArcFilterMap& efm) {
7.707 - return SubGraphAdaptor<const Graph, NodeFilterMap, const ArcFilterMap>
7.708 - (graph, nfm, efm);
7.709 - }
7.710 -
7.711 - template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
7.712 - SubGraphAdaptor<const Graph, const NodeFilterMap, const ArcFilterMap>
7.713 - subGraphAdaptor(const Graph& graph,
7.714 - NodeFilterMap& nfm, ArcFilterMap& efm) {
7.715 - return SubGraphAdaptor<const Graph, const NodeFilterMap,
7.716 - const ArcFilterMap>(graph, nfm, efm);
7.717 - }
7.718 -
7.719 - /// \ingroup graph_adaptors
7.720 - ///
7.721 - /// \brief An adaptor for hiding nodes from an graph.
7.722 - ///
7.723 - /// An adaptor for hiding nodes from an graph. This
7.724 - /// adaptor specializes SubGraphAdaptor in the way that only the
7.725 - /// node-set can be filtered. In usual case the checked parameter is
7.726 - /// true, we get the induced subgraph. But if the checked parameter
7.727 - /// is false then we can filter only isolated nodes.
7.728 - template<typename _Graph, typename _NodeFilterMap, bool checked = true>
7.729 - class NodeSubGraphAdaptor :
7.730 - public SubGraphAdaptor<_Graph, _NodeFilterMap,
7.731 - ConstMap<typename _Graph::Edge, bool>, checked> {
7.732 - public:
7.733 - typedef _Graph Graph;
7.734 - typedef _NodeFilterMap NodeFilterMap;
7.735 - typedef SubGraphAdaptor<Graph, NodeFilterMap,
7.736 - ConstMap<typename Graph::Edge, bool> > Parent;
7.737 -
7.738 - typedef typename Parent::Node Node;
7.739 - protected:
7.740 - ConstMap<typename Graph::Edge, bool> const_true_map;
7.741 -
7.742 - NodeSubGraphAdaptor() : const_true_map(true) {
7.743 - Parent::setEdgeFilterMap(const_true_map);
7.744 - }
7.745 -
7.746 - public:
7.747 -
7.748 - /// \brief Constructor
7.749 - ///
7.750 - /// Creates a node-sub-graph-adaptor for the given graph with
7.751 - /// given node map filters.
7.752 - NodeSubGraphAdaptor(Graph& _graph, NodeFilterMap& node_filter_map) :
7.753 - Parent(), const_true_map(true) {
7.754 - Parent::setGraph(_graph);
7.755 - Parent::setNodeFilterMap(node_filter_map);
7.756 - Parent::setEdgeFilterMap(const_true_map);
7.757 - }
7.758 -
7.759 - /// \brief Hides the node of the graph
7.760 - ///
7.761 - /// This function hides \c n in the digraph, i.e. the iteration
7.762 - /// jumps over it. This is done by simply setting the value of \c n
7.763 - /// to be false in the corresponding node-map.
7.764 - void hide(const Node& n) const { Parent::hide(n); }
7.765 -
7.766 - /// \brief Unhides the node of the graph
7.767 - ///
7.768 - /// The value of \c n is set to be true in the node-map which stores
7.769 - /// hide information. If \c n was hidden previuosly, then it is shown
7.770 - /// again
7.771 - void unHide(const Node& n) const { Parent::unHide(n); }
7.772 -
7.773 - /// \brief Returns true if \c n is hidden.
7.774 - ///
7.775 - /// Returns true if \c n is hidden.
7.776 - ///
7.777 - bool hidden(const Node& n) const { return Parent::hidden(n); }
7.778 -
7.779 - };
7.780 -
7.781 - /// \brief Just gives back a node-sub-graph adaptor
7.782 - ///
7.783 - /// Just gives back a node-sub-graph adaptor
7.784 - template<typename Graph, typename NodeFilterMap>
7.785 - NodeSubGraphAdaptor<const Graph, NodeFilterMap>
7.786 - nodeSubGraphAdaptor(const Graph& graph, NodeFilterMap& nfm) {
7.787 - return NodeSubGraphAdaptor<const Graph, NodeFilterMap>(graph, nfm);
7.788 - }
7.789 -
7.790 - template<typename Graph, typename NodeFilterMap>
7.791 - NodeSubGraphAdaptor<const Graph, const NodeFilterMap>
7.792 - nodeSubGraphAdaptor(const Graph& graph, const NodeFilterMap& nfm) {
7.793 - return NodeSubGraphAdaptor<const Graph, const NodeFilterMap>(graph, nfm);
7.794 - }
7.795 -
7.796 - /// \ingroup graph_adaptors
7.797 - ///
7.798 - /// \brief An adaptor for hiding edges from an graph.
7.799 - ///
7.800 - /// \warning Graph adaptors are in even more experimental state
7.801 - /// than the other parts of the lib. Use them at you own risk.
7.802 - ///
7.803 - /// An adaptor for hiding edges from an graph.
7.804 - /// This adaptor specializes SubGraphAdaptor in the way that
7.805 - /// only the arc-set
7.806 - /// can be filtered.
7.807 - template<typename _Graph, typename _EdgeFilterMap>
7.808 - class EdgeSubGraphAdaptor :
7.809 - public SubGraphAdaptor<_Graph, ConstMap<typename _Graph::Node,bool>,
7.810 - _EdgeFilterMap, false> {
7.811 - public:
7.812 - typedef _Graph Graph;
7.813 - typedef _EdgeFilterMap EdgeFilterMap;
7.814 - typedef SubGraphAdaptor<Graph, ConstMap<typename Graph::Node,bool>,
7.815 - EdgeFilterMap, false> Parent;
7.816 - typedef typename Parent::Edge Edge;
7.817 - protected:
7.818 - ConstMap<typename Graph::Node, bool> const_true_map;
7.819 -
7.820 - EdgeSubGraphAdaptor() : const_true_map(true) {
7.821 - Parent::setNodeFilterMap(const_true_map);
7.822 - }
7.823 -
7.824 - public:
7.825 -
7.826 - /// \brief Constructor
7.827 - ///
7.828 - /// Creates a edge-sub-graph-adaptor for the given graph with
7.829 - /// given node map filters.
7.830 - EdgeSubGraphAdaptor(Graph& _graph, EdgeFilterMap& edge_filter_map) :
7.831 - Parent(), const_true_map(true) {
7.832 - Parent::setGraph(_graph);
7.833 - Parent::setNodeFilterMap(const_true_map);
7.834 - Parent::setEdgeFilterMap(edge_filter_map);
7.835 - }
7.836 -
7.837 - /// \brief Hides the edge of the graph
7.838 - ///
7.839 - /// This function hides \c e in the digraph, i.e. the iteration
7.840 - /// jumps over it. This is done by simply setting the value of \c e
7.841 - /// to be false in the corresponding edge-map.
7.842 - void hide(const Edge& e) const { Parent::hide(e); }
7.843 -
7.844 - /// \brief Unhides the edge of the graph
7.845 - ///
7.846 - /// The value of \c e is set to be true in the edge-map which stores
7.847 - /// hide information. If \c e was hidden previuosly, then it is shown
7.848 - /// again
7.849 - void unHide(const Edge& e) const { Parent::unHide(e); }
7.850 -
7.851 - /// \brief Returns true if \c e is hidden.
7.852 - ///
7.853 - /// Returns true if \c e is hidden.
7.854 - ///
7.855 - bool hidden(const Edge& e) const { return Parent::hidden(e); }
7.856 -
7.857 - };
7.858 -
7.859 - /// \brief Just gives back an edge-sub-graph adaptor
7.860 - ///
7.861 - /// Just gives back an edge-sub-graph adaptor
7.862 - template<typename Graph, typename EdgeFilterMap>
7.863 - EdgeSubGraphAdaptor<const Graph, EdgeFilterMap>
7.864 - edgeSubGraphAdaptor(const Graph& graph, EdgeFilterMap& efm) {
7.865 - return EdgeSubGraphAdaptor<const Graph, EdgeFilterMap>(graph, efm);
7.866 - }
7.867 -
7.868 - template<typename Graph, typename EdgeFilterMap>
7.869 - EdgeSubGraphAdaptor<const Graph, const EdgeFilterMap>
7.870 - edgeSubGraphAdaptor(const Graph& graph, const EdgeFilterMap& efm) {
7.871 - return EdgeSubGraphAdaptor<const Graph, const EdgeFilterMap>(graph, efm);
7.872 - }
7.873 -
7.874 - template <typename _Graph, typename _DirectionMap>
7.875 - class DirGraphAdaptorBase {
7.876 - public:
7.877 -
7.878 - typedef _Graph Graph;
7.879 - typedef _DirectionMap DirectionMap;
7.880 -
7.881 - typedef typename Graph::Node Node;
7.882 - typedef typename Graph::Edge Arc;
7.883 -
7.884 - /// \brief Reverse arc
7.885 - ///
7.886 - /// It reverse the given arc. It simply negate the direction in the map.
7.887 - void reverseArc(const Arc& arc) {
7.888 - _direction->set(arc, !(*_direction)[arc]);
7.889 - }
7.890 -
7.891 - void first(Node& i) const { _graph->first(i); }
7.892 - void first(Arc& i) const { _graph->first(i); }
7.893 - void firstIn(Arc& i, const Node& n) const {
7.894 - bool d;
7.895 - _graph->firstInc(i, d, n);
7.896 - while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
7.897 - }
7.898 - void firstOut(Arc& i, const Node& n ) const {
7.899 - bool d;
7.900 - _graph->firstInc(i, d, n);
7.901 - while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
7.902 - }
7.903 -
7.904 - void next(Node& i) const { _graph->next(i); }
7.905 - void next(Arc& i) const { _graph->next(i); }
7.906 - void nextIn(Arc& i) const {
7.907 - bool d = !(*_direction)[i];
7.908 - _graph->nextInc(i, d);
7.909 - while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
7.910 - }
7.911 - void nextOut(Arc& i) const {
7.912 - bool d = (*_direction)[i];
7.913 - _graph->nextInc(i, d);
7.914 - while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
7.915 - }
7.916 -
7.917 - Node source(const Arc& e) const {
7.918 - return (*_direction)[e] ? _graph->u(e) : _graph->v(e);
7.919 - }
7.920 - Node target(const Arc& e) const {
7.921 - return (*_direction)[e] ? _graph->v(e) : _graph->u(e);
7.922 - }
7.923 -
7.924 - typedef NodeNumTagIndicator<Graph> NodeNumTag;
7.925 - int nodeNum() const { return _graph->nodeNum(); }
7.926 -
7.927 - typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
7.928 - int arcNum() const { return _graph->edgeNum(); }
7.929 -
7.930 - typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
7.931 - Arc findArc(const Node& u, const Node& v,
7.932 - const Arc& prev = INVALID) {
7.933 - Arc arc = prev;
7.934 - bool d = arc == INVALID ? true : (*_direction)[arc];
7.935 - if (d) {
7.936 - arc = _graph->findEdge(u, v, arc);
7.937 - while (arc != INVALID && !(*_direction)[arc]) {
7.938 - _graph->findEdge(u, v, arc);
7.939 - }
7.940 - if (arc != INVALID) return arc;
7.941 - }
7.942 - _graph->findEdge(v, u, arc);
7.943 - while (arc != INVALID && (*_direction)[arc]) {
7.944 - _graph->findEdge(u, v, arc);
7.945 - }
7.946 - return arc;
7.947 - }
7.948 -
7.949 - Node addNode() {
7.950 - return Node(_graph->addNode());
7.951 - }
7.952 -
7.953 - Arc addArc(const Node& u, const Node& v) {
7.954 - Arc arc = _graph->addArc(u, v);
7.955 - _direction->set(arc, _graph->source(arc) == u);
7.956 - return arc;
7.957 - }
7.958 -
7.959 - void erase(const Node& i) { _graph->erase(i); }
7.960 - void erase(const Arc& i) { _graph->erase(i); }
7.961 -
7.962 - void clear() { _graph->clear(); }
7.963 -
7.964 - int id(const Node& v) const { return _graph->id(v); }
7.965 - int id(const Arc& e) const { return _graph->id(e); }
7.966 -
7.967 - Node nodeFromId(int idx) const { return _graph->nodeFromId(idx); }
7.968 - Arc arcFromId(int idx) const { return _graph->edgeFromId(idx); }
7.969 -
7.970 - int maxNodeId() const { return _graph->maxNodeId(); }
7.971 - int maxArcId() const { return _graph->maxEdgeId(); }
7.972 -
7.973 - typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
7.974 - NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
7.975 -
7.976 - typedef typename ItemSetTraits<Graph, Arc>::ItemNotifier ArcNotifier;
7.977 - ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
7.978 -
7.979 - template <typename _Value>
7.980 - class NodeMap : public _Graph::template NodeMap<_Value> {
7.981 - public:
7.982 -
7.983 - typedef typename _Graph::template NodeMap<_Value> Parent;
7.984 -
7.985 - explicit NodeMap(const DirGraphAdaptorBase& adapter)
7.986 - : Parent(*adapter._graph) {}
7.987 -
7.988 - NodeMap(const DirGraphAdaptorBase& adapter, const _Value& value)
7.989 - : Parent(*adapter._graph, value) {}
7.990 -
7.991 - private:
7.992 - NodeMap& operator=(const NodeMap& cmap) {
7.993 - return operator=<NodeMap>(cmap);
7.994 - }
7.995 -
7.996 - template <typename CMap>
7.997 - NodeMap& operator=(const CMap& cmap) {
7.998 - Parent::operator=(cmap);
7.999 - return *this;
7.1000 - }
7.1001 -
7.1002 - };
7.1003 -
7.1004 - template <typename _Value>
7.1005 - class ArcMap : public _Graph::template EdgeMap<_Value> {
7.1006 - public:
7.1007 -
7.1008 - typedef typename Graph::template EdgeMap<_Value> Parent;
7.1009 -
7.1010 - explicit ArcMap(const DirGraphAdaptorBase& adapter)
7.1011 - : Parent(*adapter._graph) { }
7.1012 -
7.1013 - ArcMap(const DirGraphAdaptorBase& adapter, const _Value& value)
7.1014 - : Parent(*adapter._graph, value) { }
7.1015 -
7.1016 - private:
7.1017 - ArcMap& operator=(const ArcMap& cmap) {
7.1018 - return operator=<ArcMap>(cmap);
7.1019 - }
7.1020 -
7.1021 - template <typename CMap>
7.1022 - ArcMap& operator=(const CMap& cmap) {
7.1023 - Parent::operator=(cmap);
7.1024 - return *this;
7.1025 - }
7.1026 - };
7.1027 -
7.1028 -
7.1029 -
7.1030 - protected:
7.1031 - Graph* _graph;
7.1032 - DirectionMap* _direction;
7.1033 -
7.1034 - void setDirectionMap(DirectionMap& direction) {
7.1035 - _direction = &direction;
7.1036 - }
7.1037 -
7.1038 - void setGraph(Graph& graph) {
7.1039 - _graph = &graph;
7.1040 - }
7.1041 -
7.1042 - };
7.1043 -
7.1044 -
7.1045 - /// \ingroup graph_adaptors
7.1046 - ///
7.1047 - /// \brief A directed graph is made from an graph by an adaptor
7.1048 - ///
7.1049 - /// This adaptor gives a direction for each edge in the undirected
7.1050 - /// graph. The direction of the arcs stored in the
7.1051 - /// DirectionMap. This map is a bool map on the edges. If
7.1052 - /// the edge is mapped to true then the direction of the directed
7.1053 - /// arc will be the same as the default direction of the edge. The
7.1054 - /// arcs can be easily reverted by the \ref
7.1055 - /// DirGraphAdaptorBase::reverseArc "reverseArc()" member in the
7.1056 - /// adaptor.
7.1057 - ///
7.1058 - /// It can be used to solve orientation problems on directed graphs.
7.1059 - /// For example how can we orient an graph to get the minimum
7.1060 - /// number of strongly connected components. If we orient the arcs with
7.1061 - /// the dfs algorithm out from the source then we will get such an
7.1062 - /// orientation.
7.1063 - ///
7.1064 - /// We use the \ref DfsVisitor "visitor" interface of the
7.1065 - /// \ref DfsVisit "dfs" algorithm:
7.1066 - ///\code
7.1067 - /// template <typename DirMap>
7.1068 - /// class OrientVisitor : public DfsVisitor<Graph> {
7.1069 - /// public:
7.1070 - ///
7.1071 - /// OrientVisitor(const Graph& graph, DirMap& dirMap)
7.1072 - /// : _graph(graph), _dirMap(dirMap), _processed(graph, false) {}
7.1073 - ///
7.1074 - /// void discover(const Arc& arc) {
7.1075 - /// _processed.set(arc, true);
7.1076 - /// _dirMap.set(arc, _graph.direction(arc));
7.1077 - /// }
7.1078 - ///
7.1079 - /// void examine(const Arc& arc) {
7.1080 - /// if (_processed[arc]) return;
7.1081 - /// _processed.set(arc, true);
7.1082 - /// _dirMap.set(arc, _graph.direction(arc));
7.1083 - /// }
7.1084 - ///
7.1085 - /// private:
7.1086 - /// const Graph& _graph;
7.1087 - /// DirMap& _dirMap;
7.1088 - /// Graph::EdgeMap<bool> _processed;
7.1089 - /// };
7.1090 - ///\endcode
7.1091 - ///
7.1092 - /// And now we can use the orientation:
7.1093 - ///\code
7.1094 - /// Graph::EdgeMap<bool> dmap(graph);
7.1095 - ///
7.1096 - /// typedef OrientVisitor<Graph::EdgeMap<bool> > Visitor;
7.1097 - /// Visitor visitor(graph, dmap);
7.1098 - ///
7.1099 - /// DfsVisit<Graph, Visitor> dfs(graph, visitor);
7.1100 - ///
7.1101 - /// dfs.run();
7.1102 - ///
7.1103 - /// typedef DirGraphAdaptor<Graph> DGraph;
7.1104 - /// DGraph dgraph(graph, dmap);
7.1105 - ///
7.1106 - /// LEMON_ASSERT(countStronglyConnectedComponents(dgraph) ==
7.1107 - /// countBiArcConnectedComponents(graph), "Wrong Orientation");
7.1108 - ///\endcode
7.1109 - ///
7.1110 - /// The number of the bi-connected components is a lower bound for
7.1111 - /// the number of the strongly connected components in the directed
7.1112 - /// graph because if we contract the bi-connected components to
7.1113 - /// nodes we will get a tree therefore we cannot orient arcs in
7.1114 - /// both direction between bi-connected components. In the other way
7.1115 - /// the algorithm will orient one component to be strongly
7.1116 - /// connected. The two relations proof that the assertion will
7.1117 - /// be always true and the found solution is optimal.
7.1118 - ///
7.1119 - /// \sa DirGraphAdaptorBase
7.1120 - /// \sa dirGraphAdaptor
7.1121 - template<typename _Graph,
7.1122 - typename DirectionMap = typename _Graph::template EdgeMap<bool> >
7.1123 - class DirGraphAdaptor :
7.1124 - public DigraphAdaptorExtender<DirGraphAdaptorBase<_Graph, DirectionMap> > {
7.1125 - public:
7.1126 - typedef _Graph Graph;
7.1127 - typedef DigraphAdaptorExtender<
7.1128 - DirGraphAdaptorBase<_Graph, DirectionMap> > Parent;
7.1129 - typedef typename Parent::Arc Arc;
7.1130 - protected:
7.1131 - DirGraphAdaptor() { }
7.1132 - public:
7.1133 -
7.1134 - /// \brief Constructor of the adaptor
7.1135 - ///
7.1136 - /// Constructor of the adaptor
7.1137 - DirGraphAdaptor(Graph& graph, DirectionMap& direction) {
7.1138 - setGraph(graph);
7.1139 - setDirectionMap(direction);
7.1140 - }
7.1141 -
7.1142 - /// \brief Reverse arc
7.1143 - ///
7.1144 - /// It reverse the given arc. It simply negate the direction in the map.
7.1145 - void reverseArc(const Arc& a) {
7.1146 - Parent::reverseArc(a);
7.1147 - }
7.1148 - };
7.1149 -
7.1150 - /// \brief Just gives back a DirGraphAdaptor
7.1151 - ///
7.1152 - /// Just gives back a DirGraphAdaptor
7.1153 - template<typename Graph, typename DirectionMap>
7.1154 - DirGraphAdaptor<const Graph, DirectionMap>
7.1155 - dirGraphAdaptor(const Graph& graph, DirectionMap& dm) {
7.1156 - return DirGraphAdaptor<const Graph, DirectionMap>(graph, dm);
7.1157 - }
7.1158 -
7.1159 - template<typename Graph, typename DirectionMap>
7.1160 - DirGraphAdaptor<const Graph, const DirectionMap>
7.1161 - dirGraphAdaptor(const Graph& graph, const DirectionMap& dm) {
7.1162 - return DirGraphAdaptor<const Graph, const DirectionMap>(graph, dm);
7.1163 - }
7.1164 -
7.1165 -}
7.1166 -
7.1167 -#endif
8.1 --- a/test/graph_adaptor_test.cc Sun Nov 30 19:00:30 2008 +0100
8.2 +++ b/test/graph_adaptor_test.cc Sun Nov 30 19:18:32 2008 +0100
8.3 @@ -1,6 +1,6 @@
8.4 -/* -*- C++ -*-
8.5 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
8.6 *
8.7 - * This file is a part of LEMON, a generic C++ optimization library
8.8 + * This file is a part of LEMON, a generic C++ optimization library.
8.9 *
8.10 * Copyright (C) 2003-2008
8.11 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
8.12 @@ -25,8 +25,7 @@
8.13 #include<lemon/concepts/digraph.h>
8.14 #include<lemon/concepts/graph.h>
8.15
8.16 -#include<lemon/digraph_adaptor.h>
8.17 -#include<lemon/graph_adaptor.h>
8.18 +#include<lemon/adaptors.h>
8.19
8.20 #include <limits>
8.21 #include <lemon/bfs.h>
8.22 @@ -37,11 +36,11 @@
8.23
8.24 using namespace lemon;
8.25
8.26 -void checkRevDigraphAdaptor() {
8.27 - checkConcept<concepts::Digraph, RevDigraphAdaptor<concepts::Digraph> >();
8.28 +void checkReverseDigraph() {
8.29 + checkConcept<concepts::Digraph, ReverseDigraph<concepts::Digraph> >();
8.30
8.31 typedef ListDigraph Digraph;
8.32 - typedef RevDigraphAdaptor<Digraph> Adaptor;
8.33 + typedef ReverseDigraph<Digraph> Adaptor;
8.34
8.35 Digraph digraph;
8.36 Adaptor adaptor(digraph);
8.37 @@ -53,7 +52,7 @@
8.38 Digraph::Arc a1 = digraph.addArc(n1, n2);
8.39 Digraph::Arc a2 = digraph.addArc(n1, n3);
8.40 Digraph::Arc a3 = digraph.addArc(n2, n3);
8.41 -
8.42 +
8.43 checkGraphNodeList(adaptor, 3);
8.44 checkGraphArcList(adaptor, 3);
8.45 checkGraphConArcList(adaptor, 3);
8.46 @@ -78,16 +77,16 @@
8.47 }
8.48 }
8.49
8.50 -void checkSubDigraphAdaptor() {
8.51 - checkConcept<concepts::Digraph,
8.52 - SubDigraphAdaptor<concepts::Digraph,
8.53 +void checkSubDigraph() {
8.54 + checkConcept<concepts::Digraph,
8.55 + SubDigraph<concepts::Digraph,
8.56 concepts::Digraph::NodeMap<bool>,
8.57 concepts::Digraph::ArcMap<bool> > >();
8.58
8.59 typedef ListDigraph Digraph;
8.60 typedef Digraph::NodeMap<bool> NodeFilter;
8.61 typedef Digraph::ArcMap<bool> ArcFilter;
8.62 - typedef SubDigraphAdaptor<Digraph, NodeFilter, ArcFilter> Adaptor;
8.63 + typedef SubDigraph<Digraph, NodeFilter, ArcFilter> Adaptor;
8.64
8.65 Digraph digraph;
8.66 NodeFilter node_filter(digraph);
8.67 @@ -123,7 +122,7 @@
8.68 checkGraphNodeMap(adaptor);
8.69 checkGraphArcMap(adaptor);
8.70
8.71 - arc_filter[a2] = false;
8.72 + arc_filter[a2] = false;
8.73
8.74 checkGraphNodeList(adaptor, 3);
8.75 checkGraphArcList(adaptor, 2);
8.76 @@ -143,7 +142,7 @@
8.77 checkGraphNodeMap(adaptor);
8.78 checkGraphArcMap(adaptor);
8.79
8.80 - node_filter[n1] = false;
8.81 + node_filter[n1] = false;
8.82
8.83 checkGraphNodeList(adaptor, 2);
8.84 checkGraphArcList(adaptor, 1);
8.85 @@ -175,14 +174,14 @@
8.86 checkGraphArcMap(adaptor);
8.87 }
8.88
8.89 -void checkNodeSubDigraphAdaptor() {
8.90 - checkConcept<concepts::Digraph,
8.91 - NodeSubDigraphAdaptor<concepts::Digraph,
8.92 +void checkFilterNodes1() {
8.93 + checkConcept<concepts::Digraph,
8.94 + FilterNodes<concepts::Digraph,
8.95 concepts::Digraph::NodeMap<bool> > >();
8.96
8.97 typedef ListDigraph Digraph;
8.98 typedef Digraph::NodeMap<bool> NodeFilter;
8.99 - typedef NodeSubDigraphAdaptor<Digraph, NodeFilter> Adaptor;
8.100 + typedef FilterNodes<Digraph, NodeFilter> Adaptor;
8.101
8.102 Digraph digraph;
8.103 NodeFilter node_filter(digraph);
8.104 @@ -216,7 +215,7 @@
8.105 checkGraphNodeMap(adaptor);
8.106 checkGraphArcMap(adaptor);
8.107
8.108 - node_filter[n1] = false;
8.109 + node_filter[n1] = false;
8.110
8.111 checkGraphNodeList(adaptor, 2);
8.112 checkGraphArcList(adaptor, 1);
8.113 @@ -247,14 +246,14 @@
8.114 checkGraphArcMap(adaptor);
8.115 }
8.116
8.117 -void checkArcSubDigraphAdaptor() {
8.118 - checkConcept<concepts::Digraph,
8.119 - ArcSubDigraphAdaptor<concepts::Digraph,
8.120 +void checkFilterArcs() {
8.121 + checkConcept<concepts::Digraph,
8.122 + FilterArcs<concepts::Digraph,
8.123 concepts::Digraph::ArcMap<bool> > >();
8.124
8.125 typedef ListDigraph Digraph;
8.126 typedef Digraph::ArcMap<bool> ArcFilter;
8.127 - typedef ArcSubDigraphAdaptor<Digraph, ArcFilter> Adaptor;
8.128 + typedef FilterArcs<Digraph, ArcFilter> Adaptor;
8.129
8.130 Digraph digraph;
8.131 ArcFilter arc_filter(digraph);
8.132 @@ -288,7 +287,7 @@
8.133 checkGraphNodeMap(adaptor);
8.134 checkGraphArcMap(adaptor);
8.135
8.136 - arc_filter[a2] = false;
8.137 + arc_filter[a2] = false;
8.138
8.139 checkGraphNodeList(adaptor, 3);
8.140 checkGraphArcList(adaptor, 2);
8.141 @@ -321,11 +320,11 @@
8.142 checkGraphArcMap(adaptor);
8.143 }
8.144
8.145 -void checkUndirDigraphAdaptor() {
8.146 - checkConcept<concepts::Graph, UndirDigraphAdaptor<concepts::Digraph> >();
8.147 +void checkUndirector() {
8.148 + checkConcept<concepts::Graph, Undirector<concepts::Digraph> >();
8.149
8.150 typedef ListDigraph Digraph;
8.151 - typedef UndirDigraphAdaptor<Digraph> Adaptor;
8.152 + typedef Undirector<Digraph> Adaptor;
8.153
8.154 Digraph digraph;
8.155 Adaptor adaptor(digraph);
8.156 @@ -337,7 +336,7 @@
8.157 Digraph::Arc a1 = digraph.addArc(n1, n2);
8.158 Digraph::Arc a2 = digraph.addArc(n1, n3);
8.159 Digraph::Arc a3 = digraph.addArc(n2, n3);
8.160 -
8.161 +
8.162 checkGraphNodeList(adaptor, 3);
8.163 checkGraphArcList(adaptor, 6);
8.164 checkGraphEdgeList(adaptor, 3);
8.165 @@ -371,15 +370,15 @@
8.166
8.167 }
8.168
8.169 -void checkResDigraphAdaptor() {
8.170 - checkConcept<concepts::Digraph,
8.171 - ResDigraphAdaptor<concepts::Digraph,
8.172 - concepts::Digraph::ArcMap<int>,
8.173 +void checkResidual() {
8.174 + checkConcept<concepts::Digraph,
8.175 + Residual<concepts::Digraph,
8.176 + concepts::Digraph::ArcMap<int>,
8.177 concepts::Digraph::ArcMap<int> > >();
8.178
8.179 typedef ListDigraph Digraph;
8.180 typedef Digraph::ArcMap<int> IntArcMap;
8.181 - typedef ResDigraphAdaptor<Digraph, IntArcMap> Adaptor;
8.182 + typedef Residual<Digraph, IntArcMap> Adaptor;
8.183
8.184 Digraph digraph;
8.185 IntArcMap capacity(digraph), flow(digraph);
8.186 @@ -407,7 +406,7 @@
8.187 for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
8.188 flow[a] = 0;
8.189 }
8.190 -
8.191 +
8.192 checkGraphNodeList(adaptor, 4);
8.193 checkGraphArcList(adaptor, 6);
8.194 checkGraphConArcList(adaptor, 6);
8.195 @@ -425,7 +424,7 @@
8.196 for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
8.197 flow[a] = capacity[a] / 2;
8.198 }
8.199 -
8.200 +
8.201 checkGraphNodeList(adaptor, 4);
8.202 checkGraphArcList(adaptor, 12);
8.203 checkGraphConArcList(adaptor, 12);
8.204 @@ -449,7 +448,7 @@
8.205 for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
8.206 flow[a] = capacity[a];
8.207 }
8.208 -
8.209 +
8.210 checkGraphNodeList(adaptor, 4);
8.211 checkGraphArcList(adaptor, 6);
8.212 checkGraphConArcList(adaptor, 6);
8.213 @@ -470,17 +469,18 @@
8.214
8.215 int flow_value = 0;
8.216 while (true) {
8.217 -
8.218 +
8.219 Bfs<Adaptor> bfs(adaptor);
8.220 bfs.run(n1, n4);
8.221 -
8.222 +
8.223 if (!bfs.reached(n4)) break;
8.224
8.225 Path<Adaptor> p = bfs.path(n4);
8.226 -
8.227 +
8.228 int min = std::numeric_limits<int>::max();
8.229 for (Path<Adaptor>::ArcIt a(p); a != INVALID; ++a) {
8.230 - if (adaptor.rescap(a) < min) min = adaptor.rescap(a);
8.231 + if (adaptor.residualCapacity(a) < min)
8.232 + min = adaptor.residualCapacity(a);
8.233 }
8.234
8.235 for (Path<Adaptor>::ArcIt a(p); a != INVALID; ++a) {
8.236 @@ -493,11 +493,11 @@
8.237
8.238 }
8.239
8.240 -void checkSplitDigraphAdaptor() {
8.241 - checkConcept<concepts::Digraph, SplitDigraphAdaptor<concepts::Digraph> >();
8.242 +void checkSplitNodes() {
8.243 + checkConcept<concepts::Digraph, SplitNodes<concepts::Digraph> >();
8.244
8.245 typedef ListDigraph Digraph;
8.246 - typedef SplitDigraphAdaptor<Digraph> Adaptor;
8.247 + typedef SplitNodes<Digraph> Adaptor;
8.248
8.249 Digraph digraph;
8.250 Adaptor adaptor(digraph);
8.251 @@ -509,7 +509,7 @@
8.252 Digraph::Arc a1 = digraph.addArc(n1, n2);
8.253 Digraph::Arc a2 = digraph.addArc(n1, n3);
8.254 Digraph::Arc a3 = digraph.addArc(n2, n3);
8.255 -
8.256 +
8.257 checkGraphNodeList(adaptor, 6);
8.258 checkGraphArcList(adaptor, 6);
8.259 checkGraphConArcList(adaptor, 6);
8.260 @@ -530,17 +530,17 @@
8.261
8.262 checkNodeIds(adaptor);
8.263 checkArcIds(adaptor);
8.264 -
8.265 +
8.266 checkGraphNodeMap(adaptor);
8.267 checkGraphArcMap(adaptor);
8.268
8.269 for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
8.270 if (adaptor.origArc(a)) {
8.271 Digraph::Arc oa = a;
8.272 - check(adaptor.source(a) == adaptor.outNode(digraph.source(oa)),
8.273 - "Wrong split");
8.274 - check(adaptor.target(a) == adaptor.inNode(digraph.target(oa)),
8.275 - "Wrong split");
8.276 + check(adaptor.source(a) == adaptor.outNode(digraph.source(oa)),
8.277 + "Wrong split");
8.278 + check(adaptor.target(a) == adaptor.inNode(digraph.target(oa)),
8.279 + "Wrong split");
8.280 } else {
8.281 Digraph::Node on = a;
8.282 check(adaptor.source(a) == adaptor.inNode(on), "Wrong split");
8.283 @@ -549,16 +549,16 @@
8.284 }
8.285 }
8.286
8.287 -void checkSubGraphAdaptor() {
8.288 - checkConcept<concepts::Graph,
8.289 - SubGraphAdaptor<concepts::Graph,
8.290 +void checkSubGraph() {
8.291 + checkConcept<concepts::Graph,
8.292 + SubGraph<concepts::Graph,
8.293 concepts::Graph::NodeMap<bool>,
8.294 concepts::Graph::EdgeMap<bool> > >();
8.295
8.296 typedef ListGraph Graph;
8.297 typedef Graph::NodeMap<bool> NodeFilter;
8.298 typedef Graph::EdgeMap<bool> EdgeFilter;
8.299 - typedef SubGraphAdaptor<Graph, NodeFilter, EdgeFilter> Adaptor;
8.300 + typedef SubGraph<Graph, NodeFilter, EdgeFilter> Adaptor;
8.301
8.302 Graph graph;
8.303 NodeFilter node_filter(graph);
8.304 @@ -607,7 +607,7 @@
8.305 checkGraphArcMap(adaptor);
8.306 checkGraphEdgeMap(adaptor);
8.307
8.308 - edge_filter[e2] = false;
8.309 + edge_filter[e2] = false;
8.310
8.311 checkGraphNodeList(adaptor, 4);
8.312 checkGraphArcList(adaptor, 6);
8.313 @@ -638,7 +638,7 @@
8.314 checkGraphArcMap(adaptor);
8.315 checkGraphEdgeMap(adaptor);
8.316
8.317 - node_filter[n1] = false;
8.318 + node_filter[n1] = false;
8.319
8.320 checkGraphNodeList(adaptor, 3);
8.321 checkGraphArcList(adaptor, 4);
8.322 @@ -684,14 +684,14 @@
8.323 checkGraphEdgeMap(adaptor);
8.324 }
8.325
8.326 -void checkNodeSubGraphAdaptor() {
8.327 - checkConcept<concepts::Graph,
8.328 - NodeSubGraphAdaptor<concepts::Graph,
8.329 +void checkFilterNodes2() {
8.330 + checkConcept<concepts::Graph,
8.331 + FilterNodes<concepts::Graph,
8.332 concepts::Graph::NodeMap<bool> > >();
8.333
8.334 typedef ListGraph Graph;
8.335 typedef Graph::NodeMap<bool> NodeFilter;
8.336 - typedef NodeSubGraphAdaptor<Graph, NodeFilter> Adaptor;
8.337 + typedef FilterNodes<Graph, NodeFilter> Adaptor;
8.338
8.339 Graph graph;
8.340 NodeFilter node_filter(graph);
8.341 @@ -738,7 +738,7 @@
8.342 checkGraphArcMap(adaptor);
8.343 checkGraphEdgeMap(adaptor);
8.344
8.345 - node_filter[n1] = false;
8.346 + node_filter[n1] = false;
8.347
8.348 checkGraphNodeList(adaptor, 3);
8.349 checkGraphArcList(adaptor, 4);
8.350 @@ -783,14 +783,14 @@
8.351 checkGraphEdgeMap(adaptor);
8.352 }
8.353
8.354 -void checkEdgeSubGraphAdaptor() {
8.355 - checkConcept<concepts::Graph,
8.356 - EdgeSubGraphAdaptor<concepts::Graph,
8.357 +void checkFilterEdges() {
8.358 + checkConcept<concepts::Graph,
8.359 + FilterEdges<concepts::Graph,
8.360 concepts::Graph::EdgeMap<bool> > >();
8.361
8.362 typedef ListGraph Graph;
8.363 typedef Graph::EdgeMap<bool> EdgeFilter;
8.364 - typedef EdgeSubGraphAdaptor<Graph, EdgeFilter> Adaptor;
8.365 + typedef FilterEdges<Graph, EdgeFilter> Adaptor;
8.366
8.367 Graph graph;
8.368 EdgeFilter edge_filter(graph);
8.369 @@ -837,7 +837,7 @@
8.370 checkGraphArcMap(adaptor);
8.371 checkGraphEdgeMap(adaptor);
8.372
8.373 - edge_filter[e2] = false;
8.374 + edge_filter[e2] = false;
8.375
8.376 checkGraphNodeList(adaptor, 4);
8.377 checkGraphArcList(adaptor, 6);
8.378 @@ -885,13 +885,13 @@
8.379 checkGraphEdgeMap(adaptor);
8.380 }
8.381
8.382 -void checkDirGraphAdaptor() {
8.383 - checkConcept<concepts::Digraph,
8.384 - DirGraphAdaptor<concepts::Graph, concepts::Graph::EdgeMap<bool> > >();
8.385 +void checkOrienter() {
8.386 + checkConcept<concepts::Digraph,
8.387 + Orienter<concepts::Graph, concepts::Graph::EdgeMap<bool> > >();
8.388
8.389 typedef ListGraph Graph;
8.390 typedef ListGraph::EdgeMap<bool> DirMap;
8.391 - typedef DirGraphAdaptor<Graph> Adaptor;
8.392 + typedef Orienter<Graph> Adaptor;
8.393
8.394 Graph graph;
8.395 DirMap dir(graph, true);
8.396 @@ -904,16 +904,16 @@
8.397 Graph::Edge e1 = graph.addEdge(n1, n2);
8.398 Graph::Edge e2 = graph.addEdge(n1, n3);
8.399 Graph::Edge e3 = graph.addEdge(n2, n3);
8.400 -
8.401 +
8.402 checkGraphNodeList(adaptor, 3);
8.403 checkGraphArcList(adaptor, 3);
8.404 checkGraphConArcList(adaptor, 3);
8.405 -
8.406 +
8.407 {
8.408 dir[e1] = true;
8.409 Adaptor::Node u = adaptor.source(e1);
8.410 Adaptor::Node v = adaptor.target(e1);
8.411 -
8.412 +
8.413 dir[e1] = false;
8.414 check (u == adaptor.target(e1), "Wrong dir");
8.415 check (v == adaptor.source(e1), "Wrong dir");
8.416 @@ -926,7 +926,7 @@
8.417 dir[e2] = true;
8.418 Adaptor::Node u = adaptor.source(e2);
8.419 Adaptor::Node v = adaptor.target(e2);
8.420 -
8.421 +
8.422 dir[e2] = false;
8.423 check (u == adaptor.target(e2), "Wrong dir");
8.424 check (v == adaptor.source(e2), "Wrong dir");
8.425 @@ -939,7 +939,7 @@
8.426 dir[e3] = true;
8.427 Adaptor::Node u = adaptor.source(e3);
8.428 Adaptor::Node v = adaptor.target(e3);
8.429 -
8.430 +
8.431 dir[e3] = false;
8.432 check (u == adaptor.target(e3), "Wrong dir");
8.433 check (v == adaptor.source(e3), "Wrong dir");
8.434 @@ -967,18 +967,18 @@
8.435
8.436 int main(int, const char **) {
8.437
8.438 - checkRevDigraphAdaptor();
8.439 - checkSubDigraphAdaptor();
8.440 - checkNodeSubDigraphAdaptor();
8.441 - checkArcSubDigraphAdaptor();
8.442 - checkUndirDigraphAdaptor();
8.443 - checkResDigraphAdaptor();
8.444 - checkSplitDigraphAdaptor();
8.445 + checkReverseDigraph();
8.446 + checkSubDigraph();
8.447 + checkFilterNodes1();
8.448 + checkFilterArcs();
8.449 + checkUndirector();
8.450 + checkResidual();
8.451 + checkSplitNodes();
8.452
8.453 - checkSubGraphAdaptor();
8.454 - checkNodeSubGraphAdaptor();
8.455 - checkEdgeSubGraphAdaptor();
8.456 - checkDirGraphAdaptor();
8.457 + checkSubGraph();
8.458 + checkFilterNodes2();
8.459 + checkFilterEdges();
8.460 + checkOrienter();
8.461
8.462 return 0;
8.463 }