deba@432
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
deba@430
|
2 |
*
|
deba@432
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
deba@430
|
4 |
*
|
alpar@477
|
5 |
* Copyright (C) 2003-2009
|
deba@430
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@430
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@430
|
8 |
*
|
deba@430
|
9 |
* Permission to use, modify and distribute this software is granted
|
deba@430
|
10 |
* provided that this copyright notice appears in all copies. For
|
deba@430
|
11 |
* precise terms see the accompanying LICENSE file.
|
deba@430
|
12 |
*
|
deba@430
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@430
|
14 |
* express or implied, and with no claim as to its suitability for any
|
deba@430
|
15 |
* purpose.
|
deba@430
|
16 |
*
|
deba@430
|
17 |
*/
|
deba@430
|
18 |
|
deba@432
|
19 |
#ifndef LEMON_ADAPTORS_H
|
deba@432
|
20 |
#define LEMON_ADAPTORS_H
|
deba@432
|
21 |
|
deba@432
|
22 |
/// \ingroup graph_adaptors
|
deba@432
|
23 |
/// \file
|
kpeter@474
|
24 |
/// \brief Adaptor classes for digraphs and graphs
|
deba@430
|
25 |
///
|
deba@432
|
26 |
/// This file contains several useful adaptors for digraphs and graphs.
|
deba@430
|
27 |
|
deba@430
|
28 |
#include <lemon/core.h>
|
deba@430
|
29 |
#include <lemon/maps.h>
|
deba@430
|
30 |
#include <lemon/bits/variant.h>
|
deba@430
|
31 |
|
deba@430
|
32 |
#include <lemon/bits/graph_adaptor_extender.h>
|
deba@566
|
33 |
#include <lemon/bits/map_extender.h>
|
deba@430
|
34 |
#include <lemon/tolerance.h>
|
deba@430
|
35 |
|
deba@430
|
36 |
#include <algorithm>
|
deba@430
|
37 |
|
deba@430
|
38 |
namespace lemon {
|
deba@430
|
39 |
|
deba@559
|
40 |
#ifdef _MSC_VER
|
deba@559
|
41 |
#define LEMON_SCOPE_FIX(OUTER, NESTED) OUTER::NESTED
|
deba@559
|
42 |
#else
|
deba@559
|
43 |
#define LEMON_SCOPE_FIX(OUTER, NESTED) typename OUTER::template NESTED
|
deba@559
|
44 |
#endif
|
deba@559
|
45 |
|
deba@559
|
46 |
template<typename DGR>
|
deba@430
|
47 |
class DigraphAdaptorBase {
|
deba@430
|
48 |
public:
|
deba@559
|
49 |
typedef DGR Digraph;
|
deba@430
|
50 |
typedef DigraphAdaptorBase Adaptor;
|
deba@430
|
51 |
|
deba@430
|
52 |
protected:
|
deba@559
|
53 |
DGR* _digraph;
|
deba@430
|
54 |
DigraphAdaptorBase() : _digraph(0) { }
|
deba@559
|
55 |
void initialize(DGR& digraph) { _digraph = &digraph; }
|
deba@430
|
56 |
|
deba@430
|
57 |
public:
|
deba@559
|
58 |
DigraphAdaptorBase(DGR& digraph) : _digraph(&digraph) { }
|
deba@559
|
59 |
|
deba@559
|
60 |
typedef typename DGR::Node Node;
|
deba@559
|
61 |
typedef typename DGR::Arc Arc;
|
deba@432
|
62 |
|
deba@430
|
63 |
void first(Node& i) const { _digraph->first(i); }
|
deba@430
|
64 |
void first(Arc& i) const { _digraph->first(i); }
|
deba@430
|
65 |
void firstIn(Arc& i, const Node& n) const { _digraph->firstIn(i, n); }
|
deba@430
|
66 |
void firstOut(Arc& i, const Node& n ) const { _digraph->firstOut(i, n); }
|
deba@430
|
67 |
|
deba@430
|
68 |
void next(Node& i) const { _digraph->next(i); }
|
deba@430
|
69 |
void next(Arc& i) const { _digraph->next(i); }
|
deba@430
|
70 |
void nextIn(Arc& i) const { _digraph->nextIn(i); }
|
deba@430
|
71 |
void nextOut(Arc& i) const { _digraph->nextOut(i); }
|
deba@430
|
72 |
|
deba@430
|
73 |
Node source(const Arc& a) const { return _digraph->source(a); }
|
deba@430
|
74 |
Node target(const Arc& a) const { return _digraph->target(a); }
|
deba@430
|
75 |
|
deba@559
|
76 |
typedef NodeNumTagIndicator<DGR> NodeNumTag;
|
deba@430
|
77 |
int nodeNum() const { return _digraph->nodeNum(); }
|
deba@432
|
78 |
|
deba@559
|
79 |
typedef ArcNumTagIndicator<DGR> ArcNumTag;
|
deba@430
|
80 |
int arcNum() const { return _digraph->arcNum(); }
|
deba@430
|
81 |
|
deba@559
|
82 |
typedef FindArcTagIndicator<DGR> FindArcTag;
|
kpeter@471
|
83 |
Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) const {
|
deba@430
|
84 |
return _digraph->findArc(u, v, prev);
|
deba@430
|
85 |
}
|
deba@432
|
86 |
|
deba@430
|
87 |
Node addNode() { return _digraph->addNode(); }
|
deba@430
|
88 |
Arc addArc(const Node& u, const Node& v) { return _digraph->addArc(u, v); }
|
deba@430
|
89 |
|
kpeter@471
|
90 |
void erase(const Node& n) { _digraph->erase(n); }
|
kpeter@471
|
91 |
void erase(const Arc& a) { _digraph->erase(a); }
|
kpeter@471
|
92 |
|
kpeter@471
|
93 |
void clear() { _digraph->clear(); }
|
deba@432
|
94 |
|
deba@430
|
95 |
int id(const Node& n) const { return _digraph->id(n); }
|
deba@430
|
96 |
int id(const Arc& a) const { return _digraph->id(a); }
|
deba@430
|
97 |
|
deba@430
|
98 |
Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
|
deba@430
|
99 |
Arc arcFromId(int ix) const { return _digraph->arcFromId(ix); }
|
deba@430
|
100 |
|
deba@430
|
101 |
int maxNodeId() const { return _digraph->maxNodeId(); }
|
deba@430
|
102 |
int maxArcId() const { return _digraph->maxArcId(); }
|
deba@430
|
103 |
|
deba@559
|
104 |
typedef typename ItemSetTraits<DGR, Node>::ItemNotifier NodeNotifier;
|
deba@432
|
105 |
NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
|
deba@430
|
106 |
|
deba@559
|
107 |
typedef typename ItemSetTraits<DGR, Arc>::ItemNotifier ArcNotifier;
|
deba@432
|
108 |
ArcNotifier& notifier(Arc) const { return _digraph->notifier(Arc()); }
|
deba@432
|
109 |
|
deba@559
|
110 |
template <typename V>
|
deba@559
|
111 |
class NodeMap : public DGR::template NodeMap<V> {
|
kpeter@664
|
112 |
typedef typename DGR::template NodeMap<V> Parent;
|
kpeter@664
|
113 |
|
deba@430
|
114 |
public:
|
deba@432
|
115 |
explicit NodeMap(const Adaptor& adaptor)
|
deba@432
|
116 |
: Parent(*adaptor._digraph) {}
|
deba@559
|
117 |
NodeMap(const Adaptor& adaptor, const V& value)
|
deba@432
|
118 |
: Parent(*adaptor._digraph, value) { }
|
deba@430
|
119 |
|
deba@430
|
120 |
private:
|
deba@430
|
121 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@430
|
122 |
return operator=<NodeMap>(cmap);
|
deba@430
|
123 |
}
|
deba@430
|
124 |
|
deba@430
|
125 |
template <typename CMap>
|
deba@430
|
126 |
NodeMap& operator=(const CMap& cmap) {
|
deba@430
|
127 |
Parent::operator=(cmap);
|
deba@430
|
128 |
return *this;
|
deba@430
|
129 |
}
|
deba@432
|
130 |
|
deba@430
|
131 |
};
|
deba@430
|
132 |
|
deba@559
|
133 |
template <typename V>
|
deba@559
|
134 |
class ArcMap : public DGR::template ArcMap<V> {
|
kpeter@664
|
135 |
typedef typename DGR::template ArcMap<V> Parent;
|
kpeter@664
|
136 |
|
deba@430
|
137 |
public:
|
deba@559
|
138 |
explicit ArcMap(const DigraphAdaptorBase<DGR>& adaptor)
|
deba@432
|
139 |
: Parent(*adaptor._digraph) {}
|
deba@559
|
140 |
ArcMap(const DigraphAdaptorBase<DGR>& adaptor, const V& value)
|
deba@432
|
141 |
: Parent(*adaptor._digraph, value) {}
|
deba@430
|
142 |
|
deba@430
|
143 |
private:
|
deba@430
|
144 |
ArcMap& operator=(const ArcMap& cmap) {
|
deba@430
|
145 |
return operator=<ArcMap>(cmap);
|
deba@430
|
146 |
}
|
deba@430
|
147 |
|
deba@430
|
148 |
template <typename CMap>
|
deba@430
|
149 |
ArcMap& operator=(const CMap& cmap) {
|
deba@430
|
150 |
Parent::operator=(cmap);
|
deba@430
|
151 |
return *this;
|
deba@430
|
152 |
}
|
deba@430
|
153 |
|
deba@430
|
154 |
};
|
deba@430
|
155 |
|
deba@430
|
156 |
};
|
deba@430
|
157 |
|
deba@559
|
158 |
template<typename GR>
|
deba@432
|
159 |
class GraphAdaptorBase {
|
deba@432
|
160 |
public:
|
deba@559
|
161 |
typedef GR Graph;
|
deba@432
|
162 |
|
deba@432
|
163 |
protected:
|
deba@559
|
164 |
GR* _graph;
|
deba@432
|
165 |
|
deba@432
|
166 |
GraphAdaptorBase() : _graph(0) {}
|
deba@432
|
167 |
|
deba@559
|
168 |
void initialize(GR& graph) { _graph = &graph; }
|
deba@432
|
169 |
|
deba@432
|
170 |
public:
|
deba@559
|
171 |
GraphAdaptorBase(GR& graph) : _graph(&graph) {}
|
deba@559
|
172 |
|
deba@559
|
173 |
typedef typename GR::Node Node;
|
deba@559
|
174 |
typedef typename GR::Arc Arc;
|
deba@559
|
175 |
typedef typename GR::Edge Edge;
|
deba@432
|
176 |
|
deba@432
|
177 |
void first(Node& i) const { _graph->first(i); }
|
deba@432
|
178 |
void first(Arc& i) const { _graph->first(i); }
|
deba@432
|
179 |
void first(Edge& i) const { _graph->first(i); }
|
deba@432
|
180 |
void firstIn(Arc& i, const Node& n) const { _graph->firstIn(i, n); }
|
deba@432
|
181 |
void firstOut(Arc& i, const Node& n ) const { _graph->firstOut(i, n); }
|
deba@432
|
182 |
void firstInc(Edge &i, bool &d, const Node &n) const {
|
deba@432
|
183 |
_graph->firstInc(i, d, n);
|
deba@432
|
184 |
}
|
deba@432
|
185 |
|
deba@432
|
186 |
void next(Node& i) const { _graph->next(i); }
|
deba@432
|
187 |
void next(Arc& i) const { _graph->next(i); }
|
deba@432
|
188 |
void next(Edge& i) const { _graph->next(i); }
|
deba@432
|
189 |
void nextIn(Arc& i) const { _graph->nextIn(i); }
|
deba@432
|
190 |
void nextOut(Arc& i) const { _graph->nextOut(i); }
|
deba@432
|
191 |
void nextInc(Edge &i, bool &d) const { _graph->nextInc(i, d); }
|
deba@432
|
192 |
|
deba@432
|
193 |
Node u(const Edge& e) const { return _graph->u(e); }
|
deba@432
|
194 |
Node v(const Edge& e) const { return _graph->v(e); }
|
deba@432
|
195 |
|
deba@432
|
196 |
Node source(const Arc& a) const { return _graph->source(a); }
|
deba@432
|
197 |
Node target(const Arc& a) const { return _graph->target(a); }
|
deba@432
|
198 |
|
deba@432
|
199 |
typedef NodeNumTagIndicator<Graph> NodeNumTag;
|
deba@432
|
200 |
int nodeNum() const { return _graph->nodeNum(); }
|
deba@432
|
201 |
|
kpeter@469
|
202 |
typedef ArcNumTagIndicator<Graph> ArcNumTag;
|
kpeter@469
|
203 |
int arcNum() const { return _graph->arcNum(); }
|
kpeter@469
|
204 |
|
deba@432
|
205 |
typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
|
deba@432
|
206 |
int edgeNum() const { return _graph->edgeNum(); }
|
deba@432
|
207 |
|
kpeter@469
|
208 |
typedef FindArcTagIndicator<Graph> FindArcTag;
|
kpeter@471
|
209 |
Arc findArc(const Node& u, const Node& v,
|
kpeter@471
|
210 |
const Arc& prev = INVALID) const {
|
deba@432
|
211 |
return _graph->findArc(u, v, prev);
|
deba@432
|
212 |
}
|
kpeter@469
|
213 |
|
kpeter@469
|
214 |
typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
|
kpeter@471
|
215 |
Edge findEdge(const Node& u, const Node& v,
|
kpeter@471
|
216 |
const Edge& prev = INVALID) const {
|
deba@432
|
217 |
return _graph->findEdge(u, v, prev);
|
deba@432
|
218 |
}
|
deba@432
|
219 |
|
deba@432
|
220 |
Node addNode() { return _graph->addNode(); }
|
deba@432
|
221 |
Edge addEdge(const Node& u, const Node& v) { return _graph->addEdge(u, v); }
|
deba@432
|
222 |
|
deba@432
|
223 |
void erase(const Node& i) { _graph->erase(i); }
|
deba@432
|
224 |
void erase(const Edge& i) { _graph->erase(i); }
|
deba@432
|
225 |
|
deba@432
|
226 |
void clear() { _graph->clear(); }
|
deba@432
|
227 |
|
deba@432
|
228 |
bool direction(const Arc& a) const { return _graph->direction(a); }
|
deba@432
|
229 |
Arc direct(const Edge& e, bool d) const { return _graph->direct(e, d); }
|
deba@432
|
230 |
|
deba@432
|
231 |
int id(const Node& v) const { return _graph->id(v); }
|
deba@432
|
232 |
int id(const Arc& a) const { return _graph->id(a); }
|
deba@432
|
233 |
int id(const Edge& e) const { return _graph->id(e); }
|
deba@432
|
234 |
|
deba@432
|
235 |
Node nodeFromId(int ix) const { return _graph->nodeFromId(ix); }
|
deba@432
|
236 |
Arc arcFromId(int ix) const { return _graph->arcFromId(ix); }
|
deba@432
|
237 |
Edge edgeFromId(int ix) const { return _graph->edgeFromId(ix); }
|
deba@432
|
238 |
|
deba@432
|
239 |
int maxNodeId() const { return _graph->maxNodeId(); }
|
deba@432
|
240 |
int maxArcId() const { return _graph->maxArcId(); }
|
deba@432
|
241 |
int maxEdgeId() const { return _graph->maxEdgeId(); }
|
deba@432
|
242 |
|
deba@559
|
243 |
typedef typename ItemSetTraits<GR, Node>::ItemNotifier NodeNotifier;
|
deba@432
|
244 |
NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
|
deba@432
|
245 |
|
deba@559
|
246 |
typedef typename ItemSetTraits<GR, Arc>::ItemNotifier ArcNotifier;
|
deba@432
|
247 |
ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
|
deba@432
|
248 |
|
deba@559
|
249 |
typedef typename ItemSetTraits<GR, Edge>::ItemNotifier EdgeNotifier;
|
deba@432
|
250 |
EdgeNotifier& notifier(Edge) const { return _graph->notifier(Edge()); }
|
deba@432
|
251 |
|
deba@559
|
252 |
template <typename V>
|
deba@559
|
253 |
class NodeMap : public GR::template NodeMap<V> {
|
kpeter@664
|
254 |
typedef typename GR::template NodeMap<V> Parent;
|
kpeter@664
|
255 |
|
deba@432
|
256 |
public:
|
deba@559
|
257 |
explicit NodeMap(const GraphAdaptorBase<GR>& adapter)
|
deba@432
|
258 |
: Parent(*adapter._graph) {}
|
deba@559
|
259 |
NodeMap(const GraphAdaptorBase<GR>& adapter, const V& value)
|
deba@432
|
260 |
: Parent(*adapter._graph, value) {}
|
deba@432
|
261 |
|
deba@432
|
262 |
private:
|
deba@432
|
263 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@432
|
264 |
return operator=<NodeMap>(cmap);
|
deba@432
|
265 |
}
|
deba@432
|
266 |
|
deba@432
|
267 |
template <typename CMap>
|
deba@432
|
268 |
NodeMap& operator=(const CMap& cmap) {
|
deba@432
|
269 |
Parent::operator=(cmap);
|
deba@432
|
270 |
return *this;
|
deba@432
|
271 |
}
|
deba@432
|
272 |
|
deba@432
|
273 |
};
|
deba@432
|
274 |
|
deba@559
|
275 |
template <typename V>
|
deba@559
|
276 |
class ArcMap : public GR::template ArcMap<V> {
|
kpeter@664
|
277 |
typedef typename GR::template ArcMap<V> Parent;
|
kpeter@664
|
278 |
|
deba@432
|
279 |
public:
|
deba@559
|
280 |
explicit ArcMap(const GraphAdaptorBase<GR>& adapter)
|
deba@432
|
281 |
: Parent(*adapter._graph) {}
|
deba@559
|
282 |
ArcMap(const GraphAdaptorBase<GR>& adapter, const V& value)
|
deba@432
|
283 |
: Parent(*adapter._graph, value) {}
|
deba@432
|
284 |
|
deba@432
|
285 |
private:
|
deba@432
|
286 |
ArcMap& operator=(const ArcMap& cmap) {
|
deba@432
|
287 |
return operator=<ArcMap>(cmap);
|
deba@432
|
288 |
}
|
deba@432
|
289 |
|
deba@432
|
290 |
template <typename CMap>
|
deba@432
|
291 |
ArcMap& operator=(const CMap& cmap) {
|
deba@432
|
292 |
Parent::operator=(cmap);
|
deba@432
|
293 |
return *this;
|
deba@432
|
294 |
}
|
deba@432
|
295 |
};
|
deba@432
|
296 |
|
deba@559
|
297 |
template <typename V>
|
deba@559
|
298 |
class EdgeMap : public GR::template EdgeMap<V> {
|
kpeter@664
|
299 |
typedef typename GR::template EdgeMap<V> Parent;
|
kpeter@664
|
300 |
|
deba@432
|
301 |
public:
|
deba@559
|
302 |
explicit EdgeMap(const GraphAdaptorBase<GR>& adapter)
|
deba@432
|
303 |
: Parent(*adapter._graph) {}
|
deba@559
|
304 |
EdgeMap(const GraphAdaptorBase<GR>& adapter, const V& value)
|
deba@432
|
305 |
: Parent(*adapter._graph, value) {}
|
deba@432
|
306 |
|
deba@432
|
307 |
private:
|
deba@432
|
308 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@432
|
309 |
return operator=<EdgeMap>(cmap);
|
deba@432
|
310 |
}
|
deba@432
|
311 |
|
deba@432
|
312 |
template <typename CMap>
|
deba@432
|
313 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@432
|
314 |
Parent::operator=(cmap);
|
deba@432
|
315 |
return *this;
|
deba@432
|
316 |
}
|
deba@432
|
317 |
};
|
deba@432
|
318 |
|
deba@432
|
319 |
};
|
deba@430
|
320 |
|
deba@559
|
321 |
template <typename DGR>
|
deba@559
|
322 |
class ReverseDigraphBase : public DigraphAdaptorBase<DGR> {
|
kpeter@664
|
323 |
typedef DigraphAdaptorBase<DGR> Parent;
|
deba@430
|
324 |
public:
|
deba@559
|
325 |
typedef DGR Digraph;
|
deba@430
|
326 |
protected:
|
deba@432
|
327 |
ReverseDigraphBase() : Parent() { }
|
deba@430
|
328 |
public:
|
deba@430
|
329 |
typedef typename Parent::Node Node;
|
deba@430
|
330 |
typedef typename Parent::Arc Arc;
|
deba@430
|
331 |
|
deba@430
|
332 |
void firstIn(Arc& a, const Node& n) const { Parent::firstOut(a, n); }
|
deba@430
|
333 |
void firstOut(Arc& a, const Node& n ) const { Parent::firstIn(a, n); }
|
deba@430
|
334 |
|
deba@430
|
335 |
void nextIn(Arc& a) const { Parent::nextOut(a); }
|
deba@430
|
336 |
void nextOut(Arc& a) const { Parent::nextIn(a); }
|
deba@430
|
337 |
|
deba@430
|
338 |
Node source(const Arc& a) const { return Parent::target(a); }
|
deba@430
|
339 |
Node target(const Arc& a) const { return Parent::source(a); }
|
deba@430
|
340 |
|
deba@432
|
341 |
Arc addArc(const Node& u, const Node& v) { return Parent::addArc(v, u); }
|
deba@432
|
342 |
|
deba@559
|
343 |
typedef FindArcTagIndicator<DGR> FindArcTag;
|
deba@432
|
344 |
Arc findArc(const Node& u, const Node& v,
|
kpeter@471
|
345 |
const Arc& prev = INVALID) const {
|
deba@430
|
346 |
return Parent::findArc(v, u, prev);
|
deba@430
|
347 |
}
|
deba@430
|
348 |
|
deba@430
|
349 |
};
|
deba@432
|
350 |
|
deba@432
|
351 |
/// \ingroup graph_adaptors
|
deba@430
|
352 |
///
|
kpeter@474
|
353 |
/// \brief Adaptor class for reversing the orientation of the arcs in
|
kpeter@474
|
354 |
/// a digraph.
|
deba@430
|
355 |
///
|
kpeter@474
|
356 |
/// ReverseDigraph can be used for reversing the arcs in a digraph.
|
kpeter@474
|
357 |
/// It conforms to the \ref concepts::Digraph "Digraph" concept.
|
deba@430
|
358 |
///
|
kpeter@474
|
359 |
/// The adapted digraph can also be modified through this adaptor
|
kpeter@476
|
360 |
/// by adding or removing nodes or arcs, unless the \c GR template
|
kpeter@474
|
361 |
/// parameter is set to be \c const.
|
kpeter@474
|
362 |
///
|
deba@559
|
363 |
/// \tparam DGR The type of the adapted digraph.
|
kpeter@474
|
364 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept.
|
kpeter@474
|
365 |
/// It can also be specified to be \c const.
|
kpeter@474
|
366 |
///
|
kpeter@474
|
367 |
/// \note The \c Node and \c Arc types of this adaptor and the adapted
|
kpeter@474
|
368 |
/// digraph are convertible to each other.
|
deba@559
|
369 |
template<typename DGR>
|
kpeter@476
|
370 |
#ifdef DOXYGEN
|
kpeter@476
|
371 |
class ReverseDigraph {
|
kpeter@476
|
372 |
#else
|
deba@432
|
373 |
class ReverseDigraph :
|
deba@559
|
374 |
public DigraphAdaptorExtender<ReverseDigraphBase<DGR> > {
|
kpeter@476
|
375 |
#endif
|
kpeter@664
|
376 |
typedef DigraphAdaptorExtender<ReverseDigraphBase<DGR> > Parent;
|
deba@430
|
377 |
public:
|
kpeter@476
|
378 |
/// The type of the adapted digraph.
|
deba@559
|
379 |
typedef DGR Digraph;
|
deba@430
|
380 |
protected:
|
deba@432
|
381 |
ReverseDigraph() { }
|
deba@430
|
382 |
public:
|
deba@431
|
383 |
|
deba@431
|
384 |
/// \brief Constructor
|
deba@431
|
385 |
///
|
kpeter@474
|
386 |
/// Creates a reverse digraph adaptor for the given digraph.
|
deba@559
|
387 |
explicit ReverseDigraph(DGR& digraph) {
|
deba@559
|
388 |
Parent::initialize(digraph);
|
deba@430
|
389 |
}
|
deba@430
|
390 |
};
|
deba@430
|
391 |
|
kpeter@474
|
392 |
/// \brief Returns a read-only ReverseDigraph adaptor
|
deba@430
|
393 |
///
|
kpeter@474
|
394 |
/// This function just returns a read-only \ref ReverseDigraph adaptor.
|
kpeter@474
|
395 |
/// \ingroup graph_adaptors
|
kpeter@474
|
396 |
/// \relates ReverseDigraph
|
deba@559
|
397 |
template<typename DGR>
|
deba@559
|
398 |
ReverseDigraph<const DGR> reverseDigraph(const DGR& digraph) {
|
deba@559
|
399 |
return ReverseDigraph<const DGR>(digraph);
|
deba@430
|
400 |
}
|
deba@430
|
401 |
|
kpeter@474
|
402 |
|
deba@559
|
403 |
template <typename DGR, typename NF, typename AF, bool ch = true>
|
deba@559
|
404 |
class SubDigraphBase : public DigraphAdaptorBase<DGR> {
|
kpeter@664
|
405 |
typedef DigraphAdaptorBase<DGR> Parent;
|
deba@430
|
406 |
public:
|
deba@559
|
407 |
typedef DGR Digraph;
|
deba@559
|
408 |
typedef NF NodeFilterMap;
|
deba@559
|
409 |
typedef AF ArcFilterMap;
|
deba@430
|
410 |
|
deba@432
|
411 |
typedef SubDigraphBase Adaptor;
|
deba@430
|
412 |
protected:
|
deba@559
|
413 |
NF* _node_filter;
|
deba@559
|
414 |
AF* _arc_filter;
|
deba@432
|
415 |
SubDigraphBase()
|
deba@430
|
416 |
: Parent(), _node_filter(0), _arc_filter(0) { }
|
deba@430
|
417 |
|
deba@559
|
418 |
void initialize(DGR& digraph, NF& node_filter, AF& arc_filter) {
|
deba@559
|
419 |
Parent::initialize(digraph);
|
deba@430
|
420 |
_node_filter = &node_filter;
|
deba@559
|
421 |
_arc_filter = &arc_filter;
|
deba@430
|
422 |
}
|
deba@430
|
423 |
|
deba@430
|
424 |
public:
|
deba@430
|
425 |
|
deba@430
|
426 |
typedef typename Parent::Node Node;
|
deba@430
|
427 |
typedef typename Parent::Arc Arc;
|
deba@430
|
428 |
|
deba@432
|
429 |
void first(Node& i) const {
|
deba@432
|
430 |
Parent::first(i);
|
deba@432
|
431 |
while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
|
deba@430
|
432 |
}
|
deba@430
|
433 |
|
deba@432
|
434 |
void first(Arc& i) const {
|
deba@432
|
435 |
Parent::first(i);
|
deba@432
|
436 |
while (i != INVALID && (!(*_arc_filter)[i]
|
deba@432
|
437 |
|| !(*_node_filter)[Parent::source(i)]
|
deba@432
|
438 |
|| !(*_node_filter)[Parent::target(i)]))
|
deba@432
|
439 |
Parent::next(i);
|
deba@430
|
440 |
}
|
deba@430
|
441 |
|
deba@432
|
442 |
void firstIn(Arc& i, const Node& n) const {
|
deba@432
|
443 |
Parent::firstIn(i, n);
|
deba@432
|
444 |
while (i != INVALID && (!(*_arc_filter)[i]
|
deba@432
|
445 |
|| !(*_node_filter)[Parent::source(i)]))
|
deba@432
|
446 |
Parent::nextIn(i);
|
deba@430
|
447 |
}
|
deba@430
|
448 |
|
deba@432
|
449 |
void firstOut(Arc& i, const Node& n) const {
|
deba@432
|
450 |
Parent::firstOut(i, n);
|
deba@432
|
451 |
while (i != INVALID && (!(*_arc_filter)[i]
|
deba@432
|
452 |
|| !(*_node_filter)[Parent::target(i)]))
|
deba@432
|
453 |
Parent::nextOut(i);
|
deba@430
|
454 |
}
|
deba@430
|
455 |
|
deba@432
|
456 |
void next(Node& i) const {
|
deba@432
|
457 |
Parent::next(i);
|
deba@432
|
458 |
while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
|
deba@430
|
459 |
}
|
deba@430
|
460 |
|
deba@432
|
461 |
void next(Arc& i) const {
|
deba@432
|
462 |
Parent::next(i);
|
deba@432
|
463 |
while (i != INVALID && (!(*_arc_filter)[i]
|
deba@432
|
464 |
|| !(*_node_filter)[Parent::source(i)]
|
deba@432
|
465 |
|| !(*_node_filter)[Parent::target(i)]))
|
deba@432
|
466 |
Parent::next(i);
|
deba@430
|
467 |
}
|
deba@430
|
468 |
|
deba@432
|
469 |
void nextIn(Arc& i) const {
|
deba@432
|
470 |
Parent::nextIn(i);
|
deba@432
|
471 |
while (i != INVALID && (!(*_arc_filter)[i]
|
deba@432
|
472 |
|| !(*_node_filter)[Parent::source(i)]))
|
deba@432
|
473 |
Parent::nextIn(i);
|
deba@430
|
474 |
}
|
deba@430
|
475 |
|
deba@432
|
476 |
void nextOut(Arc& i) const {
|
deba@432
|
477 |
Parent::nextOut(i);
|
deba@432
|
478 |
while (i != INVALID && (!(*_arc_filter)[i]
|
deba@432
|
479 |
|| !(*_node_filter)[Parent::target(i)]))
|
deba@432
|
480 |
Parent::nextOut(i);
|
deba@430
|
481 |
}
|
deba@430
|
482 |
|
kpeter@475
|
483 |
void status(const Node& n, bool v) const { _node_filter->set(n, v); }
|
kpeter@475
|
484 |
void status(const Arc& a, bool v) const { _arc_filter->set(a, v); }
|
kpeter@475
|
485 |
|
kpeter@475
|
486 |
bool status(const Node& n) const { return (*_node_filter)[n]; }
|
kpeter@475
|
487 |
bool status(const Arc& a) const { return (*_arc_filter)[a]; }
|
deba@430
|
488 |
|
deba@430
|
489 |
typedef False NodeNumTag;
|
kpeter@469
|
490 |
typedef False ArcNumTag;
|
kpeter@469
|
491 |
|
deba@559
|
492 |
typedef FindArcTagIndicator<DGR> FindArcTag;
|
deba@432
|
493 |
Arc findArc(const Node& source, const Node& target,
|
kpeter@471
|
494 |
const Arc& prev = INVALID) const {
|
deba@430
|
495 |
if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
|
deba@430
|
496 |
return INVALID;
|
deba@430
|
497 |
}
|
deba@430
|
498 |
Arc arc = Parent::findArc(source, target, prev);
|
deba@430
|
499 |
while (arc != INVALID && !(*_arc_filter)[arc]) {
|
deba@430
|
500 |
arc = Parent::findArc(source, target, arc);
|
deba@430
|
501 |
}
|
deba@430
|
502 |
return arc;
|
deba@430
|
503 |
}
|
deba@430
|
504 |
|
deba@559
|
505 |
public:
|
deba@559
|
506 |
|
deba@559
|
507 |
template <typename V>
|
deba@559
|
508 |
class NodeMap
|
deba@559
|
509 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
|
deba@559
|
510 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> {
|
kpeter@664
|
511 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
|
kpeter@664
|
512 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent;
|
kpeter@664
|
513 |
|
deba@430
|
514 |
public:
|
deba@559
|
515 |
typedef V Value;
|
deba@559
|
516 |
|
deba@559
|
517 |
NodeMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor)
|
deba@559
|
518 |
: Parent(adaptor) {}
|
deba@559
|
519 |
NodeMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor, const V& value)
|
deba@559
|
520 |
: Parent(adaptor, value) {}
|
deba@432
|
521 |
|
deba@430
|
522 |
private:
|
deba@430
|
523 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@432
|
524 |
return operator=<NodeMap>(cmap);
|
deba@430
|
525 |
}
|
deba@432
|
526 |
|
deba@430
|
527 |
template <typename CMap>
|
deba@430
|
528 |
NodeMap& operator=(const CMap& cmap) {
|
deba@559
|
529 |
Parent::operator=(cmap);
|
deba@432
|
530 |
return *this;
|
deba@430
|
531 |
}
|
deba@430
|
532 |
};
|
deba@430
|
533 |
|
deba@559
|
534 |
template <typename V>
|
deba@559
|
535 |
class ArcMap
|
deba@559
|
536 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
|
deba@559
|
537 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
|
kpeter@664
|
538 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, ch>,
|
kpeter@664
|
539 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent;
|
kpeter@664
|
540 |
|
deba@430
|
541 |
public:
|
deba@559
|
542 |
typedef V Value;
|
deba@559
|
543 |
|
deba@559
|
544 |
ArcMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor)
|
deba@559
|
545 |
: Parent(adaptor) {}
|
deba@559
|
546 |
ArcMap(const SubDigraphBase<DGR, NF, AF, ch>& adaptor, const V& value)
|
deba@559
|
547 |
: Parent(adaptor, value) {}
|
deba@432
|
548 |
|
deba@430
|
549 |
private:
|
deba@430
|
550 |
ArcMap& operator=(const ArcMap& cmap) {
|
deba@432
|
551 |
return operator=<ArcMap>(cmap);
|
deba@430
|
552 |
}
|
deba@432
|
553 |
|
deba@430
|
554 |
template <typename CMap>
|
deba@430
|
555 |
ArcMap& operator=(const CMap& cmap) {
|
deba@559
|
556 |
Parent::operator=(cmap);
|
deba@432
|
557 |
return *this;
|
deba@430
|
558 |
}
|
deba@430
|
559 |
};
|
deba@430
|
560 |
|
deba@430
|
561 |
};
|
deba@430
|
562 |
|
deba@559
|
563 |
template <typename DGR, typename NF, typename AF>
|
deba@559
|
564 |
class SubDigraphBase<DGR, NF, AF, false>
|
deba@559
|
565 |
: public DigraphAdaptorBase<DGR> {
|
kpeter@664
|
566 |
typedef DigraphAdaptorBase<DGR> Parent;
|
deba@430
|
567 |
public:
|
deba@559
|
568 |
typedef DGR Digraph;
|
deba@559
|
569 |
typedef NF NodeFilterMap;
|
deba@559
|
570 |
typedef AF ArcFilterMap;
|
deba@430
|
571 |
|
deba@432
|
572 |
typedef SubDigraphBase Adaptor;
|
deba@430
|
573 |
protected:
|
deba@559
|
574 |
NF* _node_filter;
|
deba@559
|
575 |
AF* _arc_filter;
|
deba@432
|
576 |
SubDigraphBase()
|
deba@430
|
577 |
: Parent(), _node_filter(0), _arc_filter(0) { }
|
deba@430
|
578 |
|
deba@559
|
579 |
void initialize(DGR& digraph, NF& node_filter, AF& arc_filter) {
|
deba@559
|
580 |
Parent::initialize(digraph);
|
deba@430
|
581 |
_node_filter = &node_filter;
|
deba@559
|
582 |
_arc_filter = &arc_filter;
|
deba@430
|
583 |
}
|
deba@430
|
584 |
|
deba@430
|
585 |
public:
|
deba@430
|
586 |
|
deba@430
|
587 |
typedef typename Parent::Node Node;
|
deba@430
|
588 |
typedef typename Parent::Arc Arc;
|
deba@430
|
589 |
|
deba@432
|
590 |
void first(Node& i) const {
|
deba@432
|
591 |
Parent::first(i);
|
deba@432
|
592 |
while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
|
deba@430
|
593 |
}
|
deba@430
|
594 |
|
deba@432
|
595 |
void first(Arc& i) const {
|
deba@432
|
596 |
Parent::first(i);
|
deba@432
|
597 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
|
deba@430
|
598 |
}
|
deba@430
|
599 |
|
deba@432
|
600 |
void firstIn(Arc& i, const Node& n) const {
|
deba@432
|
601 |
Parent::firstIn(i, n);
|
deba@432
|
602 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
|
deba@430
|
603 |
}
|
deba@430
|
604 |
|
deba@432
|
605 |
void firstOut(Arc& i, const Node& n) const {
|
deba@432
|
606 |
Parent::firstOut(i, n);
|
deba@432
|
607 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
|
deba@430
|
608 |
}
|
deba@430
|
609 |
|
deba@432
|
610 |
void next(Node& i) const {
|
deba@432
|
611 |
Parent::next(i);
|
deba@432
|
612 |
while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
|
deba@430
|
613 |
}
|
deba@432
|
614 |
void next(Arc& i) const {
|
deba@432
|
615 |
Parent::next(i);
|
deba@432
|
616 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
|
deba@430
|
617 |
}
|
deba@432
|
618 |
void nextIn(Arc& i) const {
|
deba@432
|
619 |
Parent::nextIn(i);
|
deba@432
|
620 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
|
deba@430
|
621 |
}
|
deba@430
|
622 |
|
deba@432
|
623 |
void nextOut(Arc& i) const {
|
deba@432
|
624 |
Parent::nextOut(i);
|
deba@432
|
625 |
while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
|
deba@430
|
626 |
}
|
deba@430
|
627 |
|
kpeter@475
|
628 |
void status(const Node& n, bool v) const { _node_filter->set(n, v); }
|
kpeter@475
|
629 |
void status(const Arc& a, bool v) const { _arc_filter->set(a, v); }
|
kpeter@475
|
630 |
|
kpeter@475
|
631 |
bool status(const Node& n) const { return (*_node_filter)[n]; }
|
kpeter@475
|
632 |
bool status(const Arc& a) const { return (*_arc_filter)[a]; }
|
deba@430
|
633 |
|
deba@430
|
634 |
typedef False NodeNumTag;
|
kpeter@469
|
635 |
typedef False ArcNumTag;
|
kpeter@469
|
636 |
|
deba@559
|
637 |
typedef FindArcTagIndicator<DGR> FindArcTag;
|
deba@432
|
638 |
Arc findArc(const Node& source, const Node& target,
|
kpeter@471
|
639 |
const Arc& prev = INVALID) const {
|
deba@430
|
640 |
if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
|
deba@430
|
641 |
return INVALID;
|
deba@430
|
642 |
}
|
deba@430
|
643 |
Arc arc = Parent::findArc(source, target, prev);
|
deba@430
|
644 |
while (arc != INVALID && !(*_arc_filter)[arc]) {
|
deba@430
|
645 |
arc = Parent::findArc(source, target, arc);
|
deba@430
|
646 |
}
|
deba@430
|
647 |
return arc;
|
deba@430
|
648 |
}
|
deba@430
|
649 |
|
deba@559
|
650 |
template <typename V>
|
deba@559
|
651 |
class NodeMap
|
deba@559
|
652 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
|
deba@559
|
653 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> {
|
kpeter@664
|
654 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
|
kpeter@664
|
655 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, NodeMap<V>)> Parent;
|
kpeter@664
|
656 |
|
deba@430
|
657 |
public:
|
deba@559
|
658 |
typedef V Value;
|
deba@559
|
659 |
|
deba@559
|
660 |
NodeMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor)
|
deba@559
|
661 |
: Parent(adaptor) {}
|
deba@559
|
662 |
NodeMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor, const V& value)
|
deba@559
|
663 |
: Parent(adaptor, value) {}
|
deba@432
|
664 |
|
deba@430
|
665 |
private:
|
deba@430
|
666 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@432
|
667 |
return operator=<NodeMap>(cmap);
|
deba@430
|
668 |
}
|
deba@432
|
669 |
|
deba@430
|
670 |
template <typename CMap>
|
deba@430
|
671 |
NodeMap& operator=(const CMap& cmap) {
|
deba@559
|
672 |
Parent::operator=(cmap);
|
deba@432
|
673 |
return *this;
|
deba@430
|
674 |
}
|
deba@430
|
675 |
};
|
deba@430
|
676 |
|
deba@559
|
677 |
template <typename V>
|
deba@559
|
678 |
class ArcMap
|
deba@559
|
679 |
: public SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
|
deba@559
|
680 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> {
|
kpeter@664
|
681 |
typedef SubMapExtender<SubDigraphBase<DGR, NF, AF, false>,
|
kpeter@664
|
682 |
LEMON_SCOPE_FIX(DigraphAdaptorBase<DGR>, ArcMap<V>)> Parent;
|
kpeter@664
|
683 |
|
deba@430
|
684 |
public:
|
deba@559
|
685 |
typedef V Value;
|
deba@559
|
686 |
|
deba@559
|
687 |
ArcMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor)
|
deba@559
|
688 |
: Parent(adaptor) {}
|
deba@559
|
689 |
ArcMap(const SubDigraphBase<DGR, NF, AF, false>& adaptor, const V& value)
|
deba@559
|
690 |
: Parent(adaptor, value) {}
|
deba@432
|
691 |
|
deba@430
|
692 |
private:
|
deba@430
|
693 |
ArcMap& operator=(const ArcMap& cmap) {
|
deba@432
|
694 |
return operator=<ArcMap>(cmap);
|
deba@430
|
695 |
}
|
deba@432
|
696 |
|
deba@430
|
697 |
template <typename CMap>
|
deba@430
|
698 |
ArcMap& operator=(const CMap& cmap) {
|
deba@559
|
699 |
Parent::operator=(cmap);
|
deba@432
|
700 |
return *this;
|
deba@430
|
701 |
}
|
deba@430
|
702 |
};
|
deba@430
|
703 |
|
deba@430
|
704 |
};
|
deba@430
|
705 |
|
deba@430
|
706 |
/// \ingroup graph_adaptors
|
deba@430
|
707 |
///
|
kpeter@474
|
708 |
/// \brief Adaptor class for hiding nodes and arcs in a digraph
|
deba@432
|
709 |
///
|
kpeter@474
|
710 |
/// SubDigraph can be used for hiding nodes and arcs in a digraph.
|
kpeter@474
|
711 |
/// A \c bool node map and a \c bool arc map must be specified, which
|
kpeter@474
|
712 |
/// define the filters for nodes and arcs.
|
kpeter@474
|
713 |
/// Only the nodes and arcs with \c true filter value are
|
kpeter@476
|
714 |
/// shown in the subdigraph. The arcs that are incident to hidden
|
kpeter@476
|
715 |
/// nodes are also filtered out.
|
kpeter@476
|
716 |
/// This adaptor conforms to the \ref concepts::Digraph "Digraph" concept.
|
deba@432
|
717 |
///
|
kpeter@474
|
718 |
/// The adapted digraph can also be modified through this adaptor
|
kpeter@476
|
719 |
/// by adding or removing nodes or arcs, unless the \c GR template
|
kpeter@474
|
720 |
/// parameter is set to be \c const.
|
kpeter@474
|
721 |
///
|
deba@559
|
722 |
/// \tparam DGR The type of the adapted digraph.
|
kpeter@474
|
723 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept.
|
kpeter@474
|
724 |
/// It can also be specified to be \c const.
|
kpeter@476
|
725 |
/// \tparam NF The type of the node filter map.
|
kpeter@476
|
726 |
/// It must be a \c bool (or convertible) node map of the
|
kpeter@476
|
727 |
/// adapted digraph. The default type is
|
deba@559
|
728 |
/// \ref concepts::Digraph::NodeMap "DGR::NodeMap<bool>".
|
kpeter@476
|
729 |
/// \tparam AF The type of the arc filter map.
|
kpeter@476
|
730 |
/// It must be \c bool (or convertible) arc map of the
|
kpeter@476
|
731 |
/// adapted digraph. The default type is
|
deba@559
|
732 |
/// \ref concepts::Digraph::ArcMap "DGR::ArcMap<bool>".
|
kpeter@474
|
733 |
///
|
kpeter@474
|
734 |
/// \note The \c Node and \c Arc types of this adaptor and the adapted
|
kpeter@474
|
735 |
/// digraph are convertible to each other.
|
deba@432
|
736 |
///
|
deba@432
|
737 |
/// \see FilterNodes
|
deba@432
|
738 |
/// \see FilterArcs
|
kpeter@474
|
739 |
#ifdef DOXYGEN
|
deba@559
|
740 |
template<typename DGR, typename NF, typename AF>
|
kpeter@476
|
741 |
class SubDigraph {
|
kpeter@474
|
742 |
#else
|
deba@559
|
743 |
template<typename DGR,
|
deba@559
|
744 |
typename NF = typename DGR::template NodeMap<bool>,
|
deba@559
|
745 |
typename AF = typename DGR::template ArcMap<bool> >
|
kpeter@476
|
746 |
class SubDigraph :
|
deba@559
|
747 |
public DigraphAdaptorExtender<SubDigraphBase<DGR, NF, AF, true> > {
|
kpeter@474
|
748 |
#endif
|
deba@430
|
749 |
public:
|
kpeter@474
|
750 |
/// The type of the adapted digraph.
|
deba@559
|
751 |
typedef DGR Digraph;
|
kpeter@474
|
752 |
/// The type of the node filter map.
|
kpeter@476
|
753 |
typedef NF NodeFilterMap;
|
kpeter@474
|
754 |
/// The type of the arc filter map.
|
kpeter@476
|
755 |
typedef AF ArcFilterMap;
|
kpeter@476
|
756 |
|
deba@559
|
757 |
typedef DigraphAdaptorExtender<SubDigraphBase<DGR, NF, AF, true> >
|
kpeter@476
|
758 |
Parent;
|
deba@430
|
759 |
|
deba@431
|
760 |
typedef typename Parent::Node Node;
|
deba@431
|
761 |
typedef typename Parent::Arc Arc;
|
deba@431
|
762 |
|
deba@430
|
763 |
protected:
|
deba@432
|
764 |
SubDigraph() { }
|
deba@430
|
765 |
public:
|
deba@430
|
766 |
|
deba@431
|
767 |
/// \brief Constructor
|
deba@431
|
768 |
///
|
kpeter@474
|
769 |
/// Creates a subdigraph for the given digraph with the
|
kpeter@474
|
770 |
/// given node and arc filter maps.
|
deba@559
|
771 |
SubDigraph(DGR& digraph, NF& node_filter, AF& arc_filter) {
|
deba@559
|
772 |
Parent::initialize(digraph, node_filter, arc_filter);
|
deba@430
|
773 |
}
|
deba@430
|
774 |
|
kpeter@475
|
775 |
/// \brief Sets the status of the given node
|
deba@431
|
776 |
///
|
kpeter@475
|
777 |
/// This function sets the status of the given node.
|
kpeter@474
|
778 |
/// It is done by simply setting the assigned value of \c n
|
kpeter@475
|
779 |
/// to \c v in the node filter map.
|
kpeter@475
|
780 |
void status(const Node& n, bool v) const { Parent::status(n, v); }
|
kpeter@475
|
781 |
|
kpeter@475
|
782 |
/// \brief Sets the status of the given arc
|
deba@431
|
783 |
///
|
kpeter@475
|
784 |
/// This function sets the status of the given arc.
|
kpeter@474
|
785 |
/// It is done by simply setting the assigned value of \c a
|
kpeter@475
|
786 |
/// to \c v in the arc filter map.
|
kpeter@475
|
787 |
void status(const Arc& a, bool v) const { Parent::status(a, v); }
|
kpeter@475
|
788 |
|
kpeter@475
|
789 |
/// \brief Returns the status of the given node
|
deba@431
|
790 |
///
|
kpeter@475
|
791 |
/// This function returns the status of the given node.
|
kpeter@475
|
792 |
/// It is \c true if the given node is enabled (i.e. not hidden).
|
kpeter@475
|
793 |
bool status(const Node& n) const { return Parent::status(n); }
|
kpeter@475
|
794 |
|
kpeter@475
|
795 |
/// \brief Returns the status of the given arc
|
deba@431
|
796 |
///
|
kpeter@475
|
797 |
/// This function returns the status of the given arc.
|
kpeter@475
|
798 |
/// It is \c true if the given arc is enabled (i.e. not hidden).
|
kpeter@475
|
799 |
bool status(const Arc& a) const { return Parent::status(a); }
|
kpeter@475
|
800 |
|
kpeter@475
|
801 |
/// \brief Disables the given node
|
deba@431
|
802 |
///
|
kpeter@475
|
803 |
/// This function disables the given node in the subdigraph,
|
kpeter@475
|
804 |
/// so the iteration jumps over it.
|
kpeter@475
|
805 |
/// It is the same as \ref status() "status(n, false)".
|
kpeter@475
|
806 |
void disable(const Node& n) const { Parent::status(n, false); }
|
kpeter@475
|
807 |
|
kpeter@475
|
808 |
/// \brief Disables the given arc
|
deba@431
|
809 |
///
|
kpeter@475
|
810 |
/// This function disables the given arc in the subdigraph,
|
kpeter@475
|
811 |
/// so the iteration jumps over it.
|
kpeter@475
|
812 |
/// It is the same as \ref status() "status(a, false)".
|
kpeter@475
|
813 |
void disable(const Arc& a) const { Parent::status(a, false); }
|
kpeter@475
|
814 |
|
kpeter@475
|
815 |
/// \brief Enables the given node
|
kpeter@475
|
816 |
///
|
kpeter@475
|
817 |
/// This function enables the given node in the subdigraph.
|
kpeter@475
|
818 |
/// It is the same as \ref status() "status(n, true)".
|
kpeter@475
|
819 |
void enable(const Node& n) const { Parent::status(n, true); }
|
kpeter@475
|
820 |
|
kpeter@475
|
821 |
/// \brief Enables the given arc
|
kpeter@475
|
822 |
///
|
kpeter@475
|
823 |
/// This function enables the given arc in the subdigraph.
|
kpeter@475
|
824 |
/// It is the same as \ref status() "status(a, true)".
|
kpeter@475
|
825 |
void enable(const Arc& a) const { Parent::status(a, true); }
|
deba@431
|
826 |
|
deba@430
|
827 |
};
|
deba@430
|
828 |
|
kpeter@474
|
829 |
/// \brief Returns a read-only SubDigraph adaptor
|
deba@430
|
830 |
///
|
kpeter@474
|
831 |
/// This function just returns a read-only \ref SubDigraph adaptor.
|
kpeter@474
|
832 |
/// \ingroup graph_adaptors
|
kpeter@474
|
833 |
/// \relates SubDigraph
|
deba@559
|
834 |
template<typename DGR, typename NF, typename AF>
|
deba@559
|
835 |
SubDigraph<const DGR, NF, AF>
|
deba@559
|
836 |
subDigraph(const DGR& digraph,
|
deba@559
|
837 |
NF& node_filter, AF& arc_filter) {
|
deba@559
|
838 |
return SubDigraph<const DGR, NF, AF>
|
deba@559
|
839 |
(digraph, node_filter, arc_filter);
|
deba@430
|
840 |
}
|
deba@430
|
841 |
|
deba@559
|
842 |
template<typename DGR, typename NF, typename AF>
|
deba@559
|
843 |
SubDigraph<const DGR, const NF, AF>
|
deba@559
|
844 |
subDigraph(const DGR& digraph,
|
deba@559
|
845 |
const NF& node_filter, AF& arc_filter) {
|
deba@559
|
846 |
return SubDigraph<const DGR, const NF, AF>
|
deba@559
|
847 |
(digraph, node_filter, arc_filter);
|
deba@430
|
848 |
}
|
deba@430
|
849 |
|
deba@559
|
850 |
template<typename DGR, typename NF, typename AF>
|
deba@559
|
851 |
SubDigraph<const DGR, NF, const AF>
|
deba@559
|
852 |
subDigraph(const DGR& digraph,
|
deba@559
|
853 |
NF& node_filter, const AF& arc_filter) {
|
deba@559
|
854 |
return SubDigraph<const DGR, NF, const AF>
|
deba@559
|
855 |
(digraph, node_filter, arc_filter);
|
deba@430
|
856 |
}
|
deba@430
|
857 |
|
deba@559
|
858 |
template<typename DGR, typename NF, typename AF>
|
deba@559
|
859 |
SubDigraph<const DGR, const NF, const AF>
|
deba@559
|
860 |
subDigraph(const DGR& digraph,
|
deba@559
|
861 |
const NF& node_filter, const AF& arc_filter) {
|
deba@559
|
862 |
return SubDigraph<const DGR, const NF, const AF>
|
deba@559
|
863 |
(digraph, node_filter, arc_filter);
|
deba@430
|
864 |
}
|
deba@430
|
865 |
|
deba@430
|
866 |
|
deba@559
|
867 |
template <typename GR, typename NF, typename EF, bool ch = true>
|
deba@559
|
868 |
class SubGraphBase : public GraphAdaptorBase<GR> {
|
kpeter@664
|
869 |
typedef GraphAdaptorBase<GR> Parent;
|
deba@432
|
870 |
public:
|
deba@559
|
871 |
typedef GR Graph;
|
deba@559
|
872 |
typedef NF NodeFilterMap;
|
deba@559
|
873 |
typedef EF EdgeFilterMap;
|
kpeter@472
|
874 |
|
deba@432
|
875 |
typedef SubGraphBase Adaptor;
|
deba@432
|
876 |
protected:
|
deba@432
|
877 |
|
deba@559
|
878 |
NF* _node_filter;
|
deba@559
|
879 |
EF* _edge_filter;
|
deba@432
|
880 |
|
deba@432
|
881 |
SubGraphBase()
|
deba@559
|
882 |
: Parent(), _node_filter(0), _edge_filter(0) { }
|
deba@559
|
883 |
|
deba@559
|
884 |
void initialize(GR& graph, NF& node_filter, EF& edge_filter) {
|
deba@559
|
885 |
Parent::initialize(graph);
|
deba@559
|
886 |
_node_filter = &node_filter;
|
deba@559
|
887 |
_edge_filter = &edge_filter;
|
deba@432
|
888 |
}
|
deba@432
|
889 |
|
deba@432
|
890 |
public:
|
deba@432
|
891 |
|
deba@432
|
892 |
typedef typename Parent::Node Node;
|
deba@432
|
893 |
typedef typename Parent::Arc Arc;
|
deba@432
|
894 |
typedef typename Parent::Edge Edge;
|
deba@432
|
895 |
|
deba@432
|
896 |
void first(Node& i) const {
|
deba@432
|
897 |
Parent::first(i);
|
deba@559
|
898 |
while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
|
deba@432
|
899 |
}
|
deba@432
|
900 |
|
deba@432
|
901 |
void first(Arc& i) const {
|
deba@432
|
902 |
Parent::first(i);
|
deba@559
|
903 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
deba@559
|
904 |
|| !(*_node_filter)[Parent::source(i)]
|
deba@559
|
905 |
|| !(*_node_filter)[Parent::target(i)]))
|
deba@432
|
906 |
Parent::next(i);
|
deba@432
|
907 |
}
|
deba@432
|
908 |
|
deba@432
|
909 |
void first(Edge& i) const {
|
deba@432
|
910 |
Parent::first(i);
|
deba@559
|
911 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
deba@559
|
912 |
|| !(*_node_filter)[Parent::u(i)]
|
deba@559
|
913 |
|| !(*_node_filter)[Parent::v(i)]))
|
deba@432
|
914 |
Parent::next(i);
|
deba@432
|
915 |
}
|
deba@432
|
916 |
|
deba@432
|
917 |
void firstIn(Arc& i, const Node& n) const {
|
deba@432
|
918 |
Parent::firstIn(i, n);
|
deba@559
|
919 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
deba@559
|
920 |
|| !(*_node_filter)[Parent::source(i)]))
|
deba@432
|
921 |
Parent::nextIn(i);
|
deba@432
|
922 |
}
|
deba@432
|
923 |
|
deba@432
|
924 |
void firstOut(Arc& i, const Node& n) const {
|
deba@432
|
925 |
Parent::firstOut(i, n);
|
deba@559
|
926 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
deba@559
|
927 |
|| !(*_node_filter)[Parent::target(i)]))
|
deba@432
|
928 |
Parent::nextOut(i);
|
deba@432
|
929 |
}
|
deba@432
|
930 |
|
deba@432
|
931 |
void firstInc(Edge& i, bool& d, const Node& n) const {
|
deba@432
|
932 |
Parent::firstInc(i, d, n);
|
deba@559
|
933 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
deba@559
|
934 |
|| !(*_node_filter)[Parent::u(i)]
|
deba@559
|
935 |
|| !(*_node_filter)[Parent::v(i)]))
|
deba@432
|
936 |
Parent::nextInc(i, d);
|
deba@432
|
937 |
}
|
deba@432
|
938 |
|
deba@432
|
939 |
void next(Node& i) const {
|
deba@432
|
940 |
Parent::next(i);
|
deba@559
|
941 |
while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
|
deba@432
|
942 |
}
|
deba@432
|
943 |
|
deba@432
|
944 |
void next(Arc& i) const {
|
deba@432
|
945 |
Parent::next(i);
|
deba@559
|
946 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
deba@559
|
947 |
|| !(*_node_filter)[Parent::source(i)]
|
deba@559
|
948 |
|| !(*_node_filter)[Parent::target(i)]))
|
deba@432
|
949 |
Parent::next(i);
|
deba@432
|
950 |
}
|
deba@432
|
951 |
|
deba@432
|
952 |
void next(Edge& i) const {
|
deba@432
|
953 |
Parent::next(i);
|
deba@559
|
954 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
deba@559
|
955 |
|| !(*_node_filter)[Parent::u(i)]
|
deba@559
|
956 |
|| !(*_node_filter)[Parent::v(i)]))
|
deba@432
|
957 |
Parent::next(i);
|
deba@432
|
958 |
}
|
deba@432
|
959 |
|
deba@432
|
960 |
void nextIn(Arc& i) const {
|
deba@432
|
961 |
Parent::nextIn(i);
|
deba@559
|
962 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
deba@559
|
963 |
|| !(*_node_filter)[Parent::source(i)]))
|
deba@432
|
964 |
Parent::nextIn(i);
|
deba@432
|
965 |
}
|
deba@432
|
966 |
|
deba@432
|
967 |
void nextOut(Arc& i) const {
|
deba@432
|
968 |
Parent::nextOut(i);
|
deba@559
|
969 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
deba@559
|
970 |
|| !(*_node_filter)[Parent::target(i)]))
|
deba@432
|
971 |
Parent::nextOut(i);
|
deba@432
|
972 |
}
|
deba@432
|
973 |
|
deba@432
|
974 |
void nextInc(Edge& i, bool& d) const {
|
deba@432
|
975 |
Parent::nextInc(i, d);
|
deba@559
|
976 |
while (i!=INVALID && (!(*_edge_filter)[i]
|
deba@559
|
977 |
|| !(*_node_filter)[Parent::u(i)]
|
deba@559
|
978 |
|| !(*_node_filter)[Parent::v(i)]))
|
deba@432
|
979 |
Parent::nextInc(i, d);
|
deba@432
|
980 |
}
|
deba@432
|
981 |
|
deba@559
|
982 |
void status(const Node& n, bool v) const { _node_filter->set(n, v); }
|
deba@559
|
983 |
void status(const Edge& e, bool v) const { _edge_filter->set(e, v); }
|
deba@559
|
984 |
|
deba@559
|
985 |
bool status(const Node& n) const { return (*_node_filter)[n]; }
|
deba@559
|
986 |
bool status(const Edge& e) const { return (*_edge_filter)[e]; }
|
deba@432
|
987 |
|
deba@432
|
988 |
typedef False NodeNumTag;
|
kpeter@469
|
989 |
typedef False ArcNumTag;
|
deba@432
|
990 |
typedef False EdgeNumTag;
|
deba@432
|
991 |
|
kpeter@469
|
992 |
typedef FindArcTagIndicator<Graph> FindArcTag;
|
deba@432
|
993 |
Arc findArc(const Node& u, const Node& v,
|
kpeter@471
|
994 |
const Arc& prev = INVALID) const {
|
deba@559
|
995 |
if (!(*_node_filter)[u] || !(*_node_filter)[v]) {
|
deba@432
|
996 |
return INVALID;
|
deba@432
|
997 |
}
|
deba@432
|
998 |
Arc arc = Parent::findArc(u, v, prev);
|
deba@559
|
999 |
while (arc != INVALID && !(*_edge_filter)[arc]) {
|
deba@432
|
1000 |
arc = Parent::findArc(u, v, arc);
|
deba@432
|
1001 |
}
|
deba@432
|
1002 |
return arc;
|
deba@432
|
1003 |
}
|
kpeter@469
|
1004 |
|
kpeter@469
|
1005 |
typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
|
deba@432
|
1006 |
Edge findEdge(const Node& u, const Node& v,
|
kpeter@471
|
1007 |
const Edge& prev = INVALID) const {
|
deba@559
|
1008 |
if (!(*_node_filter)[u] || !(*_node_filter)[v]) {
|
deba@432
|
1009 |
return INVALID;
|
deba@432
|
1010 |
}
|
deba@432
|
1011 |
Edge edge = Parent::findEdge(u, v, prev);
|
deba@559
|
1012 |
while (edge != INVALID && !(*_edge_filter)[edge]) {
|
deba@432
|
1013 |
edge = Parent::findEdge(u, v, edge);
|
deba@432
|
1014 |
}
|
deba@432
|
1015 |
return edge;
|
deba@432
|
1016 |
}
|
deba@432
|
1017 |
|
deba@559
|
1018 |
template <typename V>
|
deba@559
|
1019 |
class NodeMap
|
deba@559
|
1020 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
|
deba@559
|
1021 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> {
|
kpeter@664
|
1022 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
|
kpeter@664
|
1023 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent;
|
kpeter@664
|
1024 |
|
deba@432
|
1025 |
public:
|
deba@559
|
1026 |
typedef V Value;
|
deba@559
|
1027 |
|
deba@559
|
1028 |
NodeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor)
|
deba@559
|
1029 |
: Parent(adaptor) {}
|
deba@559
|
1030 |
NodeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor, const V& value)
|
deba@559
|
1031 |
: Parent(adaptor, value) {}
|
deba@432
|
1032 |
|
deba@432
|
1033 |
private:
|
deba@432
|
1034 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@432
|
1035 |
return operator=<NodeMap>(cmap);
|
deba@432
|
1036 |
}
|
deba@432
|
1037 |
|
deba@432
|
1038 |
template <typename CMap>
|
deba@432
|
1039 |
NodeMap& operator=(const CMap& cmap) {
|
deba@559
|
1040 |
Parent::operator=(cmap);
|
deba@432
|
1041 |
return *this;
|
deba@432
|
1042 |
}
|
deba@432
|
1043 |
};
|
deba@432
|
1044 |
|
deba@559
|
1045 |
template <typename V>
|
deba@559
|
1046 |
class ArcMap
|
deba@559
|
1047 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
|
deba@559
|
1048 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> {
|
kpeter@664
|
1049 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
|
kpeter@664
|
1050 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent;
|
kpeter@664
|
1051 |
|
deba@432
|
1052 |
public:
|
deba@559
|
1053 |
typedef V Value;
|
deba@559
|
1054 |
|
deba@559
|
1055 |
ArcMap(const SubGraphBase<GR, NF, EF, ch>& adaptor)
|
deba@559
|
1056 |
: Parent(adaptor) {}
|
deba@559
|
1057 |
ArcMap(const SubGraphBase<GR, NF, EF, ch>& adaptor, const V& value)
|
deba@559
|
1058 |
: Parent(adaptor, value) {}
|
deba@432
|
1059 |
|
deba@432
|
1060 |
private:
|
deba@432
|
1061 |
ArcMap& operator=(const ArcMap& cmap) {
|
deba@432
|
1062 |
return operator=<ArcMap>(cmap);
|
deba@432
|
1063 |
}
|
deba@432
|
1064 |
|
deba@432
|
1065 |
template <typename CMap>
|
deba@432
|
1066 |
ArcMap& operator=(const CMap& cmap) {
|
deba@559
|
1067 |
Parent::operator=(cmap);
|
deba@432
|
1068 |
return *this;
|
deba@432
|
1069 |
}
|
deba@432
|
1070 |
};
|
deba@432
|
1071 |
|
deba@559
|
1072 |
template <typename V>
|
deba@559
|
1073 |
class EdgeMap
|
deba@559
|
1074 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
|
deba@559
|
1075 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> {
|
kpeter@664
|
1076 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, ch>,
|
kpeter@664
|
1077 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent;
|
kpeter@664
|
1078 |
|
deba@432
|
1079 |
public:
|
deba@559
|
1080 |
typedef V Value;
|
deba@559
|
1081 |
|
deba@559
|
1082 |
EdgeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor)
|
deba@559
|
1083 |
: Parent(adaptor) {}
|
deba@559
|
1084 |
|
deba@559
|
1085 |
EdgeMap(const SubGraphBase<GR, NF, EF, ch>& adaptor, const V& value)
|
deba@559
|
1086 |
: Parent(adaptor, value) {}
|
deba@432
|
1087 |
|
deba@432
|
1088 |
private:
|
deba@432
|
1089 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@432
|
1090 |
return operator=<EdgeMap>(cmap);
|
deba@432
|
1091 |
}
|
deba@432
|
1092 |
|
deba@432
|
1093 |
template <typename CMap>
|
deba@432
|
1094 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@559
|
1095 |
Parent::operator=(cmap);
|
deba@432
|
1096 |
return *this;
|
deba@432
|
1097 |
}
|
deba@432
|
1098 |
};
|
deba@432
|
1099 |
|
deba@432
|
1100 |
};
|
deba@432
|
1101 |
|
deba@559
|
1102 |
template <typename GR, typename NF, typename EF>
|
deba@559
|
1103 |
class SubGraphBase<GR, NF, EF, false>
|
deba@559
|
1104 |
: public GraphAdaptorBase<GR> {
|
kpeter@664
|
1105 |
typedef GraphAdaptorBase<GR> Parent;
|
deba@432
|
1106 |
public:
|
deba@559
|
1107 |
typedef GR Graph;
|
deba@559
|
1108 |
typedef NF NodeFilterMap;
|
deba@559
|
1109 |
typedef EF EdgeFilterMap;
|
kpeter@472
|
1110 |
|
deba@432
|
1111 |
typedef SubGraphBase Adaptor;
|
deba@432
|
1112 |
protected:
|
deba@559
|
1113 |
NF* _node_filter;
|
deba@559
|
1114 |
EF* _edge_filter;
|
deba@559
|
1115 |
SubGraphBase()
|
deba@559
|
1116 |
: Parent(), _node_filter(0), _edge_filter(0) { }
|
deba@559
|
1117 |
|
deba@559
|
1118 |
void initialize(GR& graph, NF& node_filter, EF& edge_filter) {
|
deba@559
|
1119 |
Parent::initialize(graph);
|
deba@559
|
1120 |
_node_filter = &node_filter;
|
deba@559
|
1121 |
_edge_filter = &edge_filter;
|
deba@432
|
1122 |
}
|
deba@432
|
1123 |
|
deba@432
|
1124 |
public:
|
deba@432
|
1125 |
|
deba@432
|
1126 |
typedef typename Parent::Node Node;
|
deba@432
|
1127 |
typedef typename Parent::Arc Arc;
|
deba@432
|
1128 |
typedef typename Parent::Edge Edge;
|
deba@432
|
1129 |
|
deba@432
|
1130 |
void first(Node& i) const {
|
deba@432
|
1131 |
Parent::first(i);
|
deba@559
|
1132 |
while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
|
deba@432
|
1133 |
}
|
deba@432
|
1134 |
|
deba@432
|
1135 |
void first(Arc& i) const {
|
deba@432
|
1136 |
Parent::first(i);
|
deba@559
|
1137 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
|
deba@432
|
1138 |
}
|
deba@432
|
1139 |
|
deba@432
|
1140 |
void first(Edge& i) const {
|
deba@432
|
1141 |
Parent::first(i);
|
deba@559
|
1142 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
|
deba@432
|
1143 |
}
|
deba@432
|
1144 |
|
deba@432
|
1145 |
void firstIn(Arc& i, const Node& n) const {
|
deba@432
|
1146 |
Parent::firstIn(i, n);
|
deba@559
|
1147 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextIn(i);
|
deba@432
|
1148 |
}
|
deba@432
|
1149 |
|
deba@432
|
1150 |
void firstOut(Arc& i, const Node& n) const {
|
deba@432
|
1151 |
Parent::firstOut(i, n);
|
deba@559
|
1152 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextOut(i);
|
deba@432
|
1153 |
}
|
deba@432
|
1154 |
|
deba@432
|
1155 |
void firstInc(Edge& i, bool& d, const Node& n) const {
|
deba@432
|
1156 |
Parent::firstInc(i, d, n);
|
deba@559
|
1157 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextInc(i, d);
|
deba@432
|
1158 |
}
|
deba@432
|
1159 |
|
deba@432
|
1160 |
void next(Node& i) const {
|
deba@432
|
1161 |
Parent::next(i);
|
deba@559
|
1162 |
while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
|
deba@432
|
1163 |
}
|
deba@432
|
1164 |
void next(Arc& i) const {
|
deba@432
|
1165 |
Parent::next(i);
|
deba@559
|
1166 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
|
deba@432
|
1167 |
}
|
deba@432
|
1168 |
void next(Edge& i) const {
|
deba@432
|
1169 |
Parent::next(i);
|
deba@559
|
1170 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::next(i);
|
deba@432
|
1171 |
}
|
deba@432
|
1172 |
void nextIn(Arc& i) const {
|
deba@432
|
1173 |
Parent::nextIn(i);
|
deba@559
|
1174 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextIn(i);
|
deba@432
|
1175 |
}
|
deba@432
|
1176 |
|
deba@432
|
1177 |
void nextOut(Arc& i) const {
|
deba@432
|
1178 |
Parent::nextOut(i);
|
deba@559
|
1179 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextOut(i);
|
deba@432
|
1180 |
}
|
deba@432
|
1181 |
void nextInc(Edge& i, bool& d) const {
|
deba@432
|
1182 |
Parent::nextInc(i, d);
|
deba@559
|
1183 |
while (i!=INVALID && !(*_edge_filter)[i]) Parent::nextInc(i, d);
|
deba@432
|
1184 |
}
|
deba@432
|
1185 |
|
deba@559
|
1186 |
void status(const Node& n, bool v) const { _node_filter->set(n, v); }
|
deba@559
|
1187 |
void status(const Edge& e, bool v) const { _edge_filter->set(e, v); }
|
deba@559
|
1188 |
|
deba@559
|
1189 |
bool status(const Node& n) const { return (*_node_filter)[n]; }
|
deba@559
|
1190 |
bool status(const Edge& e) const { return (*_edge_filter)[e]; }
|
deba@432
|
1191 |
|
deba@432
|
1192 |
typedef False NodeNumTag;
|
kpeter@469
|
1193 |
typedef False ArcNumTag;
|
deba@432
|
1194 |
typedef False EdgeNumTag;
|
deba@432
|
1195 |
|
kpeter@469
|
1196 |
typedef FindArcTagIndicator<Graph> FindArcTag;
|
deba@432
|
1197 |
Arc findArc(const Node& u, const Node& v,
|
kpeter@471
|
1198 |
const Arc& prev = INVALID) const {
|
deba@432
|
1199 |
Arc arc = Parent::findArc(u, v, prev);
|
deba@559
|
1200 |
while (arc != INVALID && !(*_edge_filter)[arc]) {
|
deba@432
|
1201 |
arc = Parent::findArc(u, v, arc);
|
deba@432
|
1202 |
}
|
deba@432
|
1203 |
return arc;
|
deba@432
|
1204 |
}
|
kpeter@469
|
1205 |
|
kpeter@469
|
1206 |
typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
|
deba@432
|
1207 |
Edge findEdge(const Node& u, const Node& v,
|
kpeter@471
|
1208 |
const Edge& prev = INVALID) const {
|
deba@432
|
1209 |
Edge edge = Parent::findEdge(u, v, prev);
|
deba@559
|
1210 |
while (edge != INVALID && !(*_edge_filter)[edge]) {
|
deba@432
|
1211 |
edge = Parent::findEdge(u, v, edge);
|
deba@432
|
1212 |
}
|
deba@432
|
1213 |
return edge;
|
deba@432
|
1214 |
}
|
deba@432
|
1215 |
|
deba@559
|
1216 |
template <typename V>
|
deba@559
|
1217 |
class NodeMap
|
deba@559
|
1218 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
|
deba@559
|
1219 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> {
|
kpeter@664
|
1220 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>,
|
kpeter@664
|
1221 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, NodeMap<V>)> Parent;
|
kpeter@664
|
1222 |
|
deba@432
|
1223 |
public:
|
deba@559
|
1224 |
typedef V Value;
|
deba@559
|
1225 |
|
deba@559
|
1226 |
NodeMap(const SubGraphBase<GR, NF, EF, false>& adaptor)
|
deba@559
|
1227 |
: Parent(adaptor) {}
|
deba@559
|
1228 |
NodeMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value)
|
deba@559
|
1229 |
: Parent(adaptor, value) {}
|
deba@432
|
1230 |
|
deba@432
|
1231 |
private:
|
deba@432
|
1232 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@432
|
1233 |
return operator=<NodeMap>(cmap);
|
deba@432
|
1234 |
}
|
deba@432
|
1235 |
|
deba@432
|
1236 |
template <typename CMap>
|
deba@432
|
1237 |
NodeMap& operator=(const CMap& cmap) {
|
deba@559
|
1238 |
Parent::operator=(cmap);
|
deba@432
|
1239 |
return *this;
|
deba@432
|
1240 |
}
|
deba@432
|
1241 |
};
|
deba@432
|
1242 |
|
deba@559
|
1243 |
template <typename V>
|
deba@559
|
1244 |
class ArcMap
|
deba@559
|
1245 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
|
deba@559
|
1246 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> {
|
kpeter@664
|
1247 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>,
|
kpeter@664
|
1248 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, ArcMap<V>)> Parent;
|
kpeter@664
|
1249 |
|
deba@432
|
1250 |
public:
|
deba@559
|
1251 |
typedef V Value;
|
deba@559
|
1252 |
|
deba@559
|
1253 |
ArcMap(const SubGraphBase<GR, NF, EF, false>& adaptor)
|
deba@559
|
1254 |
: Parent(adaptor) {}
|
deba@559
|
1255 |
ArcMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value)
|
deba@559
|
1256 |
: Parent(adaptor, value) {}
|
deba@432
|
1257 |
|
deba@432
|
1258 |
private:
|
deba@432
|
1259 |
ArcMap& operator=(const ArcMap& cmap) {
|
deba@432
|
1260 |
return operator=<ArcMap>(cmap);
|
deba@432
|
1261 |
}
|
deba@432
|
1262 |
|
deba@432
|
1263 |
template <typename CMap>
|
deba@432
|
1264 |
ArcMap& operator=(const CMap& cmap) {
|
deba@559
|
1265 |
Parent::operator=(cmap);
|
deba@432
|
1266 |
return *this;
|
deba@432
|
1267 |
}
|
deba@432
|
1268 |
};
|
deba@432
|
1269 |
|
deba@559
|
1270 |
template <typename V>
|
deba@559
|
1271 |
class EdgeMap
|
deba@559
|
1272 |
: public SubMapExtender<SubGraphBase<GR, NF, EF, false>,
|
deba@559
|
1273 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> {
|
kpeter@664
|
1274 |
typedef SubMapExtender<SubGraphBase<GR, NF, EF, false>,
|
kpeter@664
|
1275 |
LEMON_SCOPE_FIX(GraphAdaptorBase<GR>, EdgeMap<V>)> Parent;
|
kpeter@664
|
1276 |
|
deba@432
|
1277 |
public:
|
deba@559
|
1278 |
typedef V Value;
|
deba@559
|
1279 |
|
deba@559
|
1280 |
EdgeMap(const SubGraphBase<GR, NF, EF, false>& adaptor)
|
deba@559
|
1281 |
: Parent(adaptor) {}
|
deba@559
|
1282 |
|
deba@559
|
1283 |
EdgeMap(const SubGraphBase<GR, NF, EF, false>& adaptor, const V& value)
|
deba@559
|
1284 |
: Parent(adaptor, value) {}
|
deba@432
|
1285 |
|
deba@432
|
1286 |
private:
|
deba@432
|
1287 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@432
|
1288 |
return operator=<EdgeMap>(cmap);
|
deba@432
|
1289 |
}
|
deba@432
|
1290 |
|
deba@432
|
1291 |
template <typename CMap>
|
deba@432
|
1292 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@559
|
1293 |
Parent::operator=(cmap);
|
deba@432
|
1294 |
return *this;
|
deba@432
|
1295 |
}
|
deba@432
|
1296 |
};
|
deba@432
|
1297 |
|
deba@432
|
1298 |
};
|
deba@432
|
1299 |
|
deba@432
|
1300 |
/// \ingroup graph_adaptors
|
deba@430
|
1301 |
///
|
kpeter@474
|
1302 |
/// \brief Adaptor class for hiding nodes and edges in an undirected
|
kpeter@474
|
1303 |
/// graph.
|
deba@430
|
1304 |
///
|
kpeter@474
|
1305 |
/// SubGraph can be used for hiding nodes and edges in a graph.
|
kpeter@474
|
1306 |
/// A \c bool node map and a \c bool edge map must be specified, which
|
kpeter@474
|
1307 |
/// define the filters for nodes and edges.
|
kpeter@474
|
1308 |
/// Only the nodes and edges with \c true filter value are
|
kpeter@476
|
1309 |
/// shown in the subgraph. The edges that are incident to hidden
|
kpeter@476
|
1310 |
/// nodes are also filtered out.
|
kpeter@476
|
1311 |
/// This adaptor conforms to the \ref concepts::Graph "Graph" concept.
|
deba@432
|
1312 |
///
|
kpeter@474
|
1313 |
/// The adapted graph can also be modified through this adaptor
|
kpeter@476
|
1314 |
/// by adding or removing nodes or edges, unless the \c GR template
|
kpeter@474
|
1315 |
/// parameter is set to be \c const.
|
kpeter@474
|
1316 |
///
|
kpeter@476
|
1317 |
/// \tparam GR The type of the adapted graph.
|
kpeter@474
|
1318 |
/// It must conform to the \ref concepts::Graph "Graph" concept.
|
kpeter@474
|
1319 |
/// It can also be specified to be \c const.
|
kpeter@476
|
1320 |
/// \tparam NF The type of the node filter map.
|
kpeter@476
|
1321 |
/// It must be a \c bool (or convertible) node map of the
|
kpeter@476
|
1322 |
/// adapted graph. The default type is
|
kpeter@476
|
1323 |
/// \ref concepts::Graph::NodeMap "GR::NodeMap<bool>".
|
kpeter@476
|
1324 |
/// \tparam EF The type of the edge filter map.
|
kpeter@476
|
1325 |
/// It must be a \c bool (or convertible) edge map of the
|
kpeter@476
|
1326 |
/// adapted graph. The default type is
|
kpeter@476
|
1327 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>".
|
kpeter@474
|
1328 |
///
|
kpeter@474
|
1329 |
/// \note The \c Node, \c Edge and \c Arc types of this adaptor and the
|
kpeter@474
|
1330 |
/// adapted graph are convertible to each other.
|
deba@432
|
1331 |
///
|
deba@432
|
1332 |
/// \see FilterNodes
|
deba@432
|
1333 |
/// \see FilterEdges
|
kpeter@474
|
1334 |
#ifdef DOXYGEN
|
kpeter@476
|
1335 |
template<typename GR, typename NF, typename EF>
|
kpeter@476
|
1336 |
class SubGraph {
|
kpeter@474
|
1337 |
#else
|
kpeter@476
|
1338 |
template<typename GR,
|
kpeter@476
|
1339 |
typename NF = typename GR::template NodeMap<bool>,
|
kpeter@476
|
1340 |
typename EF = typename GR::template EdgeMap<bool> >
|
kpeter@476
|
1341 |
class SubGraph :
|
kpeter@476
|
1342 |
public GraphAdaptorExtender<SubGraphBase<GR, NF, EF, true> > {
|
kpeter@474
|
1343 |
#endif
|
deba@430
|
1344 |
public:
|
kpeter@474
|
1345 |
/// The type of the adapted graph.
|
kpeter@476
|
1346 |
typedef GR Graph;
|
kpeter@474
|
1347 |
/// The type of the node filter map.
|
kpeter@476
|
1348 |
typedef NF NodeFilterMap;
|
kpeter@474
|
1349 |
/// The type of the edge filter map.
|
kpeter@476
|
1350 |
typedef EF EdgeFilterMap;
|
kpeter@476
|
1351 |
|
deba@559
|
1352 |
typedef GraphAdaptorExtender<SubGraphBase<GR, NF, EF, true> >
|
kpeter@476
|
1353 |
Parent;
|
deba@430
|
1354 |
|
deba@431
|
1355 |
typedef typename Parent::Node Node;
|
deba@432
|
1356 |
typedef typename Parent::Edge Edge;
|
deba@431
|
1357 |
|
deba@430
|
1358 |
protected:
|
deba@432
|
1359 |
SubGraph() { }
|
deba@430
|
1360 |
public:
|
deba@430
|
1361 |
|
deba@431
|
1362 |
/// \brief Constructor
|
deba@431
|
1363 |
///
|
kpeter@474
|
1364 |
/// Creates a subgraph for the given graph with the given node
|
kpeter@474
|
1365 |
/// and edge filter maps.
|
deba@559
|
1366 |
SubGraph(GR& graph, NF& node_filter, EF& edge_filter) {
|
deba@559
|
1367 |
initialize(graph, node_filter, edge_filter);
|
deba@430
|
1368 |
}
|
deba@430
|
1369 |
|
kpeter@475
|
1370 |
/// \brief Sets the status of the given node
|
deba@431
|
1371 |
///
|
kpeter@475
|
1372 |
/// This function sets the status of the given node.
|
kpeter@474
|
1373 |
/// It is done by simply setting the assigned value of \c n
|
kpeter@475
|
1374 |
/// to \c v in the node filter map.
|
kpeter@475
|
1375 |
void status(const Node& n, bool v) const { Parent::status(n, v); }
|
kpeter@475
|
1376 |
|
kpeter@475
|
1377 |
/// \brief Sets the status of the given edge
|
deba@432
|
1378 |
///
|
kpeter@475
|
1379 |
/// This function sets the status of the given edge.
|
kpeter@474
|
1380 |
/// It is done by simply setting the assigned value of \c e
|
kpeter@475
|
1381 |
/// to \c v in the edge filter map.
|
kpeter@475
|
1382 |
void status(const Edge& e, bool v) const { Parent::status(e, v); }
|
kpeter@475
|
1383 |
|
kpeter@475
|
1384 |
/// \brief Returns the status of the given node
|
deba@431
|
1385 |
///
|
kpeter@475
|
1386 |
/// This function returns the status of the given node.
|
kpeter@475
|
1387 |
/// It is \c true if the given node is enabled (i.e. not hidden).
|
kpeter@475
|
1388 |
bool status(const Node& n) const { return Parent::status(n); }
|
kpeter@475
|
1389 |
|
kpeter@475
|
1390 |
/// \brief Returns the status of the given edge
|
deba@432
|
1391 |
///
|
kpeter@475
|
1392 |
/// This function returns the status of the given edge.
|
kpeter@475
|
1393 |
/// It is \c true if the given edge is enabled (i.e. not hidden).
|
kpeter@475
|
1394 |
bool status(const Edge& e) const { return Parent::status(e); }
|
kpeter@475
|
1395 |
|
kpeter@475
|
1396 |
/// \brief Disables the given node
|
deba@431
|
1397 |
///
|
kpeter@475
|
1398 |
/// This function disables the given node in the subdigraph,
|
kpeter@475
|
1399 |
/// so the iteration jumps over it.
|
kpeter@475
|
1400 |
/// It is the same as \ref status() "status(n, false)".
|
kpeter@475
|
1401 |
void disable(const Node& n) const { Parent::status(n, false); }
|
kpeter@475
|
1402 |
|
kpeter@475
|
1403 |
/// \brief Disables the given edge
|
deba@431
|
1404 |
///
|
kpeter@475
|
1405 |
/// This function disables the given edge in the subgraph,
|
kpeter@475
|
1406 |
/// so the iteration jumps over it.
|
kpeter@475
|
1407 |
/// It is the same as \ref status() "status(e, false)".
|
kpeter@475
|
1408 |
void disable(const Edge& e) const { Parent::status(e, false); }
|
kpeter@475
|
1409 |
|
kpeter@475
|
1410 |
/// \brief Enables the given node
|
kpeter@475
|
1411 |
///
|
kpeter@475
|
1412 |
/// This function enables the given node in the subdigraph.
|
kpeter@475
|
1413 |
/// It is the same as \ref status() "status(n, true)".
|
kpeter@475
|
1414 |
void enable(const Node& n) const { Parent::status(n, true); }
|
kpeter@475
|
1415 |
|
kpeter@475
|
1416 |
/// \brief Enables the given edge
|
kpeter@475
|
1417 |
///
|
kpeter@475
|
1418 |
/// This function enables the given edge in the subgraph.
|
kpeter@475
|
1419 |
/// It is the same as \ref status() "status(e, true)".
|
kpeter@475
|
1420 |
void enable(const Edge& e) const { Parent::status(e, true); }
|
kpeter@475
|
1421 |
|
deba@430
|
1422 |
};
|
deba@430
|
1423 |
|
kpeter@474
|
1424 |
/// \brief Returns a read-only SubGraph adaptor
|
deba@430
|
1425 |
///
|
kpeter@474
|
1426 |
/// This function just returns a read-only \ref SubGraph adaptor.
|
kpeter@474
|
1427 |
/// \ingroup graph_adaptors
|
kpeter@474
|
1428 |
/// \relates SubGraph
|
kpeter@476
|
1429 |
template<typename GR, typename NF, typename EF>
|
kpeter@476
|
1430 |
SubGraph<const GR, NF, EF>
|
deba@559
|
1431 |
subGraph(const GR& graph, NF& node_filter, EF& edge_filter) {
|
kpeter@476
|
1432 |
return SubGraph<const GR, NF, EF>
|
deba@559
|
1433 |
(graph, node_filter, edge_filter);
|
deba@432
|
1434 |
}
|
deba@432
|
1435 |
|
kpeter@476
|
1436 |
template<typename GR, typename NF, typename EF>
|
kpeter@476
|
1437 |
SubGraph<const GR, const NF, EF>
|
deba@559
|
1438 |
subGraph(const GR& graph, const NF& node_filter, EF& edge_filter) {
|
kpeter@476
|
1439 |
return SubGraph<const GR, const NF, EF>
|
deba@559
|
1440 |
(graph, node_filter, edge_filter);
|
deba@432
|
1441 |
}
|
deba@432
|
1442 |
|
kpeter@476
|
1443 |
template<typename GR, typename NF, typename EF>
|
kpeter@476
|
1444 |
SubGraph<const GR, NF, const EF>
|
deba@559
|
1445 |
subGraph(const GR& graph, NF& node_filter, const EF& edge_filter) {
|
kpeter@476
|
1446 |
return SubGraph<const GR, NF, const EF>
|
deba@559
|
1447 |
(graph, node_filter, edge_filter);
|
deba@432
|
1448 |
}
|
deba@432
|
1449 |
|
kpeter@476
|
1450 |
template<typename GR, typename NF, typename EF>
|
kpeter@476
|
1451 |
SubGraph<const GR, const NF, const EF>
|
deba@559
|
1452 |
subGraph(const GR& graph, const NF& node_filter, const EF& edge_filter) {
|
kpeter@476
|
1453 |
return SubGraph<const GR, const NF, const EF>
|
deba@559
|
1454 |
(graph, node_filter, edge_filter);
|
deba@432
|
1455 |
}
|
deba@432
|
1456 |
|
kpeter@474
|
1457 |
|
deba@432
|
1458 |
/// \ingroup graph_adaptors
|
deba@432
|
1459 |
///
|
kpeter@474
|
1460 |
/// \brief Adaptor class for hiding nodes in a digraph or a graph.
|
deba@432
|
1461 |
///
|
kpeter@474
|
1462 |
/// FilterNodes adaptor can be used for hiding nodes in a digraph or a
|
kpeter@474
|
1463 |
/// graph. A \c bool node map must be specified, which defines the filter
|
kpeter@474
|
1464 |
/// for the nodes. Only the nodes with \c true filter value and the
|
kpeter@474
|
1465 |
/// arcs/edges incident to nodes both with \c true filter value are shown
|
kpeter@474
|
1466 |
/// in the subgraph. This adaptor conforms to the \ref concepts::Digraph
|
kpeter@474
|
1467 |
/// "Digraph" concept or the \ref concepts::Graph "Graph" concept
|
kpeter@476
|
1468 |
/// depending on the \c GR template parameter.
|
deba@432
|
1469 |
///
|
kpeter@474
|
1470 |
/// The adapted (di)graph can also be modified through this adaptor
|
kpeter@476
|
1471 |
/// by adding or removing nodes or arcs/edges, unless the \c GR template
|
kpeter@474
|
1472 |
/// parameter is set to be \c const.
|
kpeter@474
|
1473 |
///
|
kpeter@476
|
1474 |
/// \tparam GR The type of the adapted digraph or graph.
|
kpeter@474
|
1475 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept
|
kpeter@474
|
1476 |
/// or the \ref concepts::Graph "Graph" concept.
|
kpeter@474
|
1477 |
/// It can also be specified to be \c const.
|
kpeter@476
|
1478 |
/// \tparam NF The type of the node filter map.
|
kpeter@476
|
1479 |
/// It must be a \c bool (or convertible) node map of the
|
kpeter@476
|
1480 |
/// adapted (di)graph. The default type is
|
kpeter@476
|
1481 |
/// \ref concepts::Graph::NodeMap "GR::NodeMap<bool>".
|
kpeter@474
|
1482 |
///
|
kpeter@474
|
1483 |
/// \note The \c Node and <tt>Arc/Edge</tt> types of this adaptor and the
|
kpeter@474
|
1484 |
/// adapted (di)graph are convertible to each other.
|
deba@432
|
1485 |
#ifdef DOXYGEN
|
kpeter@476
|
1486 |
template<typename GR, typename NF>
|
kpeter@476
|
1487 |
class FilterNodes {
|
deba@432
|
1488 |
#else
|
kpeter@476
|
1489 |
template<typename GR,
|
kpeter@476
|
1490 |
typename NF = typename GR::template NodeMap<bool>,
|
deba@432
|
1491 |
typename Enable = void>
|
kpeter@476
|
1492 |
class FilterNodes :
|
kpeter@476
|
1493 |
public DigraphAdaptorExtender<
|
deba@559
|
1494 |
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >,
|
deba@559
|
1495 |
true> > {
|
deba@432
|
1496 |
#endif
|
kpeter@476
|
1497 |
typedef DigraphAdaptorExtender<
|
deba@559
|
1498 |
SubDigraphBase<GR, NF, ConstMap<typename GR::Arc, Const<bool, true> >,
|
deba@559
|
1499 |
true> > Parent;
|
deba@432
|
1500 |
|
kpeter@664
|
1501 |
public:
|
kpeter@664
|
1502 |
|
kpeter@664
|
1503 |
typedef GR Digraph;
|
kpeter@664
|
1504 |
typedef NF NodeFilterMap;
|
kpeter@664
|
1505 |
|
deba@432
|
1506 |
typedef typename Parent::Node Node;
|
deba@432
|
1507 |
|
deba@432
|
1508 |
protected:
|
deba@559
|
1509 |
ConstMap<typename Digraph::Arc, Const<bool, true> > const_true_map;
|
deba@559
|
1510 |
|
deba@559
|
1511 |
FilterNodes() : const_true_map() {}
|
deba@432
|
1512 |
|
deba@432
|
1513 |
public:
|
deba@432
|
1514 |
|
deba@432
|
1515 |
/// \brief Constructor
|
deba@432
|
1516 |
///
|
kpeter@474
|
1517 |
/// Creates a subgraph for the given digraph or graph with the
|
deba@432
|
1518 |
/// given node filter map.
|
deba@559
|
1519 |
FilterNodes(GR& graph, NF& node_filter)
|
deba@559
|
1520 |
: Parent(), const_true_map()
|
kpeter@476
|
1521 |
{
|
deba@559
|
1522 |
Parent::initialize(graph, node_filter, const_true_map);
|
deba@432
|
1523 |
}
|
deba@432
|
1524 |
|
kpeter@475
|
1525 |
/// \brief Sets the status of the given node
|
deba@432
|
1526 |
///
|
kpeter@475
|
1527 |
/// This function sets the status of the given node.
|
kpeter@474
|
1528 |
/// It is done by simply setting the assigned value of \c n
|
kpeter@475
|
1529 |
/// to \c v in the node filter map.
|
kpeter@475
|
1530 |
void status(const Node& n, bool v) const { Parent::status(n, v); }
|
kpeter@475
|
1531 |
|
kpeter@475
|
1532 |
/// \brief Returns the status of the given node
|
deba@432
|
1533 |
///
|
kpeter@475
|
1534 |
/// This function returns the status of the given node.
|
kpeter@475
|
1535 |
/// It is \c true if the given node is enabled (i.e. not hidden).
|
kpeter@475
|
1536 |
bool status(const Node& n) const { return Parent::status(n); }
|
kpeter@475
|
1537 |
|
kpeter@475
|
1538 |
/// \brief Disables the given node
|
deba@432
|
1539 |
///
|
kpeter@475
|
1540 |
/// This function disables the given node, so the iteration
|
kpeter@475
|
1541 |
/// jumps over it.
|
kpeter@475
|
1542 |
/// It is the same as \ref status() "status(n, false)".
|
kpeter@475
|
1543 |
void disable(const Node& n) const { Parent::status(n, false); }
|
kpeter@475
|
1544 |
|
kpeter@475
|
1545 |
/// \brief Enables the given node
|
kpeter@475
|
1546 |
///
|
kpeter@475
|
1547 |
/// This function enables the given node.
|
kpeter@475
|
1548 |
/// It is the same as \ref status() "status(n, true)".
|
kpeter@475
|
1549 |
void enable(const Node& n) const { Parent::status(n, true); }
|
deba@432
|
1550 |
|
deba@432
|
1551 |
};
|
deba@432
|
1552 |
|
kpeter@476
|
1553 |
template<typename GR, typename NF>
|
kpeter@476
|
1554 |
class FilterNodes<GR, NF,
|
kpeter@476
|
1555 |
typename enable_if<UndirectedTagIndicator<GR> >::type> :
|
kpeter@476
|
1556 |
public GraphAdaptorExtender<
|
deba@559
|
1557 |
SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >,
|
deba@559
|
1558 |
true> > {
|
kpeter@476
|
1559 |
|
kpeter@476
|
1560 |
typedef GraphAdaptorExtender<
|
deba@559
|
1561 |
SubGraphBase<GR, NF, ConstMap<typename GR::Edge, Const<bool, true> >,
|
deba@559
|
1562 |
true> > Parent;
|
deba@432
|
1563 |
|
kpeter@664
|
1564 |
public:
|
kpeter@664
|
1565 |
|
kpeter@664
|
1566 |
typedef GR Graph;
|
kpeter@664
|
1567 |
typedef NF NodeFilterMap;
|
kpeter@664
|
1568 |
|
deba@432
|
1569 |
typedef typename Parent::Node Node;
|
kpeter@664
|
1570 |
|
deba@432
|
1571 |
protected:
|
deba@559
|
1572 |
ConstMap<typename GR::Edge, Const<bool, true> > const_true_map;
|
deba@559
|
1573 |
|
deba@559
|
1574 |
FilterNodes() : const_true_map() {}
|
deba@432
|
1575 |
|
deba@432
|
1576 |
public:
|
deba@432
|
1577 |
|
deba@559
|
1578 |
FilterNodes(GR& graph, NodeFilterMap& node_filter) :
|
deba@559
|
1579 |
Parent(), const_true_map() {
|
deba@559
|
1580 |
Parent::initialize(graph, node_filter, const_true_map);
|
deba@432
|
1581 |
}
|
deba@432
|
1582 |
|
kpeter@475
|
1583 |
void status(const Node& n, bool v) const { Parent::status(n, v); }
|
kpeter@475
|
1584 |
bool status(const Node& n) const { return Parent::status(n); }
|
kpeter@475
|
1585 |
void disable(const Node& n) const { Parent::status(n, false); }
|
kpeter@475
|
1586 |
void enable(const Node& n) const { Parent::status(n, true); }
|
deba@432
|
1587 |
|
deba@432
|
1588 |
};
|
deba@432
|
1589 |
|
deba@432
|
1590 |
|
kpeter@474
|
1591 |
/// \brief Returns a read-only FilterNodes adaptor
|
deba@432
|
1592 |
///
|
kpeter@474
|
1593 |
/// This function just returns a read-only \ref FilterNodes adaptor.
|
kpeter@474
|
1594 |
/// \ingroup graph_adaptors
|
kpeter@474
|
1595 |
/// \relates FilterNodes
|
kpeter@476
|
1596 |
template<typename GR, typename NF>
|
kpeter@476
|
1597 |
FilterNodes<const GR, NF>
|
deba@559
|
1598 |
filterNodes(const GR& graph, NF& node_filter) {
|
deba@559
|
1599 |
return FilterNodes<const GR, NF>(graph, node_filter);
|
deba@430
|
1600 |
}
|
deba@430
|
1601 |
|
kpeter@476
|
1602 |
template<typename GR, typename NF>
|
kpeter@476
|
1603 |
FilterNodes<const GR, const NF>
|
deba@559
|
1604 |
filterNodes(const GR& graph, const NF& node_filter) {
|
deba@559
|
1605 |
return FilterNodes<const GR, const NF>(graph, node_filter);
|
deba@430
|
1606 |
}
|
deba@430
|
1607 |
|
deba@432
|
1608 |
/// \ingroup graph_adaptors
|
deba@430
|
1609 |
///
|
kpeter@474
|
1610 |
/// \brief Adaptor class for hiding arcs in a digraph.
|
deba@430
|
1611 |
///
|
kpeter@474
|
1612 |
/// FilterArcs adaptor can be used for hiding arcs in a digraph.
|
kpeter@474
|
1613 |
/// A \c bool arc map must be specified, which defines the filter for
|
kpeter@474
|
1614 |
/// the arcs. Only the arcs with \c true filter value are shown in the
|
kpeter@474
|
1615 |
/// subdigraph. This adaptor conforms to the \ref concepts::Digraph
|
kpeter@474
|
1616 |
/// "Digraph" concept.
|
deba@430
|
1617 |
///
|
kpeter@474
|
1618 |
/// The adapted digraph can also be modified through this adaptor
|
kpeter@476
|
1619 |
/// by adding or removing nodes or arcs, unless the \c GR template
|
kpeter@474
|
1620 |
/// parameter is set to be \c const.
|
kpeter@474
|
1621 |
///
|
deba@559
|
1622 |
/// \tparam DGR The type of the adapted digraph.
|
kpeter@474
|
1623 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept.
|
kpeter@474
|
1624 |
/// It can also be specified to be \c const.
|
kpeter@476
|
1625 |
/// \tparam AF The type of the arc filter map.
|
kpeter@476
|
1626 |
/// It must be a \c bool (or convertible) arc map of the
|
kpeter@476
|
1627 |
/// adapted digraph. The default type is
|
deba@559
|
1628 |
/// \ref concepts::Digraph::ArcMap "DGR::ArcMap<bool>".
|
kpeter@474
|
1629 |
///
|
kpeter@474
|
1630 |
/// \note The \c Node and \c Arc types of this adaptor and the adapted
|
kpeter@474
|
1631 |
/// digraph are convertible to each other.
|
kpeter@474
|
1632 |
#ifdef DOXYGEN
|
deba@559
|
1633 |
template<typename DGR,
|
kpeter@476
|
1634 |
typename AF>
|
kpeter@476
|
1635 |
class FilterArcs {
|
kpeter@474
|
1636 |
#else
|
deba@559
|
1637 |
template<typename DGR,
|
deba@559
|
1638 |
typename AF = typename DGR::template ArcMap<bool> >
|
kpeter@476
|
1639 |
class FilterArcs :
|
kpeter@476
|
1640 |
public DigraphAdaptorExtender<
|
deba@559
|
1641 |
SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >,
|
deba@559
|
1642 |
AF, false> > {
|
kpeter@474
|
1643 |
#endif
|
kpeter@664
|
1644 |
typedef DigraphAdaptorExtender<
|
kpeter@664
|
1645 |
SubDigraphBase<DGR, ConstMap<typename DGR::Node, Const<bool, true> >,
|
kpeter@664
|
1646 |
AF, false> > Parent;
|
kpeter@664
|
1647 |
|
deba@430
|
1648 |
public:
|
kpeter@664
|
1649 |
|
kpeter@476
|
1650 |
/// The type of the adapted digraph.
|
deba@559
|
1651 |
typedef DGR Digraph;
|
kpeter@476
|
1652 |
/// The type of the arc filter map.
|
kpeter@476
|
1653 |
typedef AF ArcFilterMap;
|
kpeter@476
|
1654 |
|
deba@431
|
1655 |
typedef typename Parent::Arc Arc;
|
deba@431
|
1656 |
|
deba@430
|
1657 |
protected:
|
deba@559
|
1658 |
ConstMap<typename DGR::Node, Const<bool, true> > const_true_map;
|
deba@559
|
1659 |
|
deba@559
|
1660 |
FilterArcs() : const_true_map() {}
|
deba@430
|
1661 |
|
deba@430
|
1662 |
public:
|
deba@430
|
1663 |
|
deba@431
|
1664 |
/// \brief Constructor
|
deba@431
|
1665 |
///
|
kpeter@474
|
1666 |
/// Creates a subdigraph for the given digraph with the given arc
|
kpeter@474
|
1667 |
/// filter map.
|
deba@559
|
1668 |
FilterArcs(DGR& digraph, ArcFilterMap& arc_filter)
|
deba@559
|
1669 |
: Parent(), const_true_map() {
|
deba@559
|
1670 |
Parent::initialize(digraph, const_true_map, arc_filter);
|
deba@430
|
1671 |
}
|
deba@430
|
1672 |
|
kpeter@475
|
1673 |
/// \brief Sets the status of the given arc
|
deba@431
|
1674 |
///
|
kpeter@475
|
1675 |
/// This function sets the status of the given arc.
|
kpeter@474
|
1676 |
/// It is done by simply setting the assigned value of \c a
|
kpeter@475
|
1677 |
/// to \c v in the arc filter map.
|
kpeter@475
|
1678 |
void status(const Arc& a, bool v) const { Parent::status(a, v); }
|
kpeter@475
|
1679 |
|
kpeter@475
|
1680 |
/// \brief Returns the status of the given arc
|
deba@431
|
1681 |
///
|
kpeter@475
|
1682 |
/// This function returns the status of the given arc.
|
kpeter@475
|
1683 |
/// It is \c true if the given arc is enabled (i.e. not hidden).
|
kpeter@475
|
1684 |
bool status(const Arc& a) const { return Parent::status(a); }
|
kpeter@475
|
1685 |
|
kpeter@475
|
1686 |
/// \brief Disables the given arc
|
deba@431
|
1687 |
///
|
kpeter@475
|
1688 |
/// This function disables the given arc in the subdigraph,
|
kpeter@475
|
1689 |
/// so the iteration jumps over it.
|
kpeter@475
|
1690 |
/// It is the same as \ref status() "status(a, false)".
|
kpeter@475
|
1691 |
void disable(const Arc& a) const { Parent::status(a, false); }
|
kpeter@475
|
1692 |
|
kpeter@475
|
1693 |
/// \brief Enables the given arc
|
kpeter@475
|
1694 |
///
|
kpeter@475
|
1695 |
/// This function enables the given arc in the subdigraph.
|
kpeter@475
|
1696 |
/// It is the same as \ref status() "status(a, true)".
|
kpeter@475
|
1697 |
void enable(const Arc& a) const { Parent::status(a, true); }
|
deba@431
|
1698 |
|
deba@430
|
1699 |
};
|
deba@430
|
1700 |
|
kpeter@474
|
1701 |
/// \brief Returns a read-only FilterArcs adaptor
|
deba@430
|
1702 |
///
|
kpeter@474
|
1703 |
/// This function just returns a read-only \ref FilterArcs adaptor.
|
kpeter@474
|
1704 |
/// \ingroup graph_adaptors
|
kpeter@474
|
1705 |
/// \relates FilterArcs
|
deba@559
|
1706 |
template<typename DGR, typename AF>
|
deba@559
|
1707 |
FilterArcs<const DGR, AF>
|
deba@559
|
1708 |
filterArcs(const DGR& digraph, AF& arc_filter) {
|
deba@559
|
1709 |
return FilterArcs<const DGR, AF>(digraph, arc_filter);
|
deba@430
|
1710 |
}
|
deba@430
|
1711 |
|
deba@559
|
1712 |
template<typename DGR, typename AF>
|
deba@559
|
1713 |
FilterArcs<const DGR, const AF>
|
deba@559
|
1714 |
filterArcs(const DGR& digraph, const AF& arc_filter) {
|
deba@559
|
1715 |
return FilterArcs<const DGR, const AF>(digraph, arc_filter);
|
deba@430
|
1716 |
}
|
deba@430
|
1717 |
|
deba@432
|
1718 |
/// \ingroup graph_adaptors
|
deba@432
|
1719 |
///
|
kpeter@474
|
1720 |
/// \brief Adaptor class for hiding edges in a graph.
|
deba@432
|
1721 |
///
|
kpeter@474
|
1722 |
/// FilterEdges adaptor can be used for hiding edges in a graph.
|
kpeter@474
|
1723 |
/// A \c bool edge map must be specified, which defines the filter for
|
kpeter@474
|
1724 |
/// the edges. Only the edges with \c true filter value are shown in the
|
kpeter@474
|
1725 |
/// subgraph. This adaptor conforms to the \ref concepts::Graph
|
kpeter@474
|
1726 |
/// "Graph" concept.
|
deba@432
|
1727 |
///
|
kpeter@474
|
1728 |
/// The adapted graph can also be modified through this adaptor
|
kpeter@476
|
1729 |
/// by adding or removing nodes or edges, unless the \c GR template
|
kpeter@474
|
1730 |
/// parameter is set to be \c const.
|
kpeter@474
|
1731 |
///
|
kpeter@476
|
1732 |
/// \tparam GR The type of the adapted graph.
|
kpeter@474
|
1733 |
/// It must conform to the \ref concepts::Graph "Graph" concept.
|
kpeter@474
|
1734 |
/// It can also be specified to be \c const.
|
kpeter@476
|
1735 |
/// \tparam EF The type of the edge filter map.
|
kpeter@476
|
1736 |
/// It must be a \c bool (or convertible) edge map of the
|
kpeter@476
|
1737 |
/// adapted graph. The default type is
|
kpeter@476
|
1738 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>".
|
kpeter@474
|
1739 |
///
|
kpeter@474
|
1740 |
/// \note The \c Node, \c Edge and \c Arc types of this adaptor and the
|
kpeter@474
|
1741 |
/// adapted graph are convertible to each other.
|
kpeter@474
|
1742 |
#ifdef DOXYGEN
|
kpeter@476
|
1743 |
template<typename GR,
|
kpeter@476
|
1744 |
typename EF>
|
kpeter@476
|
1745 |
class FilterEdges {
|
kpeter@474
|
1746 |
#else
|
kpeter@476
|
1747 |
template<typename GR,
|
kpeter@476
|
1748 |
typename EF = typename GR::template EdgeMap<bool> >
|
kpeter@476
|
1749 |
class FilterEdges :
|
kpeter@476
|
1750 |
public GraphAdaptorExtender<
|
deba@559
|
1751 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true> >,
|
deba@559
|
1752 |
EF, false> > {
|
kpeter@474
|
1753 |
#endif
|
kpeter@664
|
1754 |
typedef GraphAdaptorExtender<
|
kpeter@664
|
1755 |
SubGraphBase<GR, ConstMap<typename GR::Node, Const<bool, true > >,
|
kpeter@664
|
1756 |
EF, false> > Parent;
|
kpeter@664
|
1757 |
|
deba@432
|
1758 |
public:
|
kpeter@664
|
1759 |
|
kpeter@476
|
1760 |
/// The type of the adapted graph.
|
kpeter@476
|
1761 |
typedef GR Graph;
|
kpeter@476
|
1762 |
/// The type of the edge filter map.
|
kpeter@476
|
1763 |
typedef EF EdgeFilterMap;
|
kpeter@476
|
1764 |
|
deba@432
|
1765 |
typedef typename Parent::Edge Edge;
|
kpeter@476
|
1766 |
|
deba@432
|
1767 |
protected:
|
deba@559
|
1768 |
ConstMap<typename GR::Node, Const<bool, true> > const_true_map;
|
deba@432
|
1769 |
|
deba@432
|
1770 |
FilterEdges() : const_true_map(true) {
|
deba@432
|
1771 |
Parent::setNodeFilterMap(const_true_map);
|
deba@432
|
1772 |
}
|
deba@432
|
1773 |
|
deba@432
|
1774 |
public:
|
deba@432
|
1775 |
|
deba@432
|
1776 |
/// \brief Constructor
|
deba@432
|
1777 |
///
|
kpeter@474
|
1778 |
/// Creates a subgraph for the given graph with the given edge
|
kpeter@474
|
1779 |
/// filter map.
|
deba@559
|
1780 |
FilterEdges(GR& graph, EF& edge_filter)
|
deba@559
|
1781 |
: Parent(), const_true_map() {
|
deba@559
|
1782 |
Parent::initialize(graph, const_true_map, edge_filter);
|
deba@432
|
1783 |
}
|
deba@432
|
1784 |
|
kpeter@475
|
1785 |
/// \brief Sets the status of the given edge
|
deba@432
|
1786 |
///
|
kpeter@475
|
1787 |
/// This function sets the status of the given edge.
|
kpeter@474
|
1788 |
/// It is done by simply setting the assigned value of \c e
|
kpeter@475
|
1789 |
/// to \c v in the edge filter map.
|
kpeter@475
|
1790 |
void status(const Edge& e, bool v) const { Parent::status(e, v); }
|
kpeter@475
|
1791 |
|
kpeter@475
|
1792 |
/// \brief Returns the status of the given edge
|
deba@432
|
1793 |
///
|
kpeter@475
|
1794 |
/// This function returns the status of the given edge.
|
kpeter@475
|
1795 |
/// It is \c true if the given edge is enabled (i.e. not hidden).
|
kpeter@475
|
1796 |
bool status(const Edge& e) const { return Parent::status(e); }
|
kpeter@475
|
1797 |
|
kpeter@475
|
1798 |
/// \brief Disables the given edge
|
deba@432
|
1799 |
///
|
kpeter@475
|
1800 |
/// This function disables the given edge in the subgraph,
|
kpeter@475
|
1801 |
/// so the iteration jumps over it.
|
kpeter@475
|
1802 |
/// It is the same as \ref status() "status(e, false)".
|
kpeter@475
|
1803 |
void disable(const Edge& e) const { Parent::status(e, false); }
|
kpeter@475
|
1804 |
|
kpeter@475
|
1805 |
/// \brief Enables the given edge
|
kpeter@475
|
1806 |
///
|
kpeter@475
|
1807 |
/// This function enables the given edge in the subgraph.
|
kpeter@475
|
1808 |
/// It is the same as \ref status() "status(e, true)".
|
kpeter@475
|
1809 |
void enable(const Edge& e) const { Parent::status(e, true); }
|
deba@432
|
1810 |
|
deba@432
|
1811 |
};
|
deba@432
|
1812 |
|
kpeter@474
|
1813 |
/// \brief Returns a read-only FilterEdges adaptor
|
deba@432
|
1814 |
///
|
kpeter@474
|
1815 |
/// This function just returns a read-only \ref FilterEdges adaptor.
|
kpeter@474
|
1816 |
/// \ingroup graph_adaptors
|
kpeter@474
|
1817 |
/// \relates FilterEdges
|
kpeter@476
|
1818 |
template<typename GR, typename EF>
|
kpeter@476
|
1819 |
FilterEdges<const GR, EF>
|
deba@559
|
1820 |
filterEdges(const GR& graph, EF& edge_filter) {
|
deba@559
|
1821 |
return FilterEdges<const GR, EF>(graph, edge_filter);
|
deba@432
|
1822 |
}
|
deba@432
|
1823 |
|
kpeter@476
|
1824 |
template<typename GR, typename EF>
|
kpeter@476
|
1825 |
FilterEdges<const GR, const EF>
|
deba@559
|
1826 |
filterEdges(const GR& graph, const EF& edge_filter) {
|
deba@559
|
1827 |
return FilterEdges<const GR, const EF>(graph, edge_filter);
|
deba@432
|
1828 |
}
|
deba@432
|
1829 |
|
kpeter@474
|
1830 |
|
deba@559
|
1831 |
template <typename DGR>
|
deba@432
|
1832 |
class UndirectorBase {
|
deba@430
|
1833 |
public:
|
deba@559
|
1834 |
typedef DGR Digraph;
|
deba@432
|
1835 |
typedef UndirectorBase Adaptor;
|
deba@430
|
1836 |
|
deba@430
|
1837 |
typedef True UndirectedTag;
|
deba@430
|
1838 |
|
deba@430
|
1839 |
typedef typename Digraph::Arc Edge;
|
deba@430
|
1840 |
typedef typename Digraph::Node Node;
|
deba@430
|
1841 |
|
deba@703
|
1842 |
class Arc {
|
deba@432
|
1843 |
friend class UndirectorBase;
|
deba@430
|
1844 |
protected:
|
deba@703
|
1845 |
Edge _edge;
|
deba@430
|
1846 |
bool _forward;
|
deba@430
|
1847 |
|
deba@703
|
1848 |
Arc(const Edge& edge, bool forward)
|
deba@703
|
1849 |
: _edge(edge), _forward(forward) {}
|
deba@430
|
1850 |
|
deba@430
|
1851 |
public:
|
deba@430
|
1852 |
Arc() {}
|
deba@430
|
1853 |
|
deba@703
|
1854 |
Arc(Invalid) : _edge(INVALID), _forward(true) {}
|
deba@703
|
1855 |
|
deba@703
|
1856 |
operator const Edge&() const { return _edge; }
|
deba@430
|
1857 |
|
deba@430
|
1858 |
bool operator==(const Arc &other) const {
|
deba@703
|
1859 |
return _forward == other._forward && _edge == other._edge;
|
deba@430
|
1860 |
}
|
deba@430
|
1861 |
bool operator!=(const Arc &other) const {
|
deba@703
|
1862 |
return _forward != other._forward || _edge != other._edge;
|
deba@430
|
1863 |
}
|
deba@430
|
1864 |
bool operator<(const Arc &other) const {
|
deba@432
|
1865 |
return _forward < other._forward ||
|
deba@703
|
1866 |
(_forward == other._forward && _edge < other._edge);
|
deba@430
|
1867 |
}
|
deba@430
|
1868 |
};
|
deba@430
|
1869 |
|
deba@430
|
1870 |
void first(Node& n) const {
|
deba@430
|
1871 |
_digraph->first(n);
|
deba@430
|
1872 |
}
|
deba@430
|
1873 |
|
deba@430
|
1874 |
void next(Node& n) const {
|
deba@430
|
1875 |
_digraph->next(n);
|
deba@430
|
1876 |
}
|
deba@430
|
1877 |
|
deba@430
|
1878 |
void first(Arc& a) const {
|
deba@703
|
1879 |
_digraph->first(a._edge);
|
deba@430
|
1880 |
a._forward = true;
|
deba@430
|
1881 |
}
|
deba@430
|
1882 |
|
deba@430
|
1883 |
void next(Arc& a) const {
|
deba@430
|
1884 |
if (a._forward) {
|
deba@432
|
1885 |
a._forward = false;
|
deba@430
|
1886 |
} else {
|
deba@703
|
1887 |
_digraph->next(a._edge);
|
deba@432
|
1888 |
a._forward = true;
|
deba@430
|
1889 |
}
|
deba@430
|
1890 |
}
|
deba@430
|
1891 |
|
deba@430
|
1892 |
void first(Edge& e) const {
|
deba@430
|
1893 |
_digraph->first(e);
|
deba@430
|
1894 |
}
|
deba@430
|
1895 |
|
deba@430
|
1896 |
void next(Edge& e) const {
|
deba@430
|
1897 |
_digraph->next(e);
|
deba@430
|
1898 |
}
|
deba@430
|
1899 |
|
deba@430
|
1900 |
void firstOut(Arc& a, const Node& n) const {
|
deba@703
|
1901 |
_digraph->firstIn(a._edge, n);
|
deba@703
|
1902 |
if (a._edge != INVALID ) {
|
deba@432
|
1903 |
a._forward = false;
|
deba@430
|
1904 |
} else {
|
deba@703
|
1905 |
_digraph->firstOut(a._edge, n);
|
deba@432
|
1906 |
a._forward = true;
|
deba@430
|
1907 |
}
|
deba@430
|
1908 |
}
|
deba@430
|
1909 |
void nextOut(Arc &a) const {
|
deba@430
|
1910 |
if (!a._forward) {
|
deba@703
|
1911 |
Node n = _digraph->target(a._edge);
|
deba@703
|
1912 |
_digraph->nextIn(a._edge);
|
deba@703
|
1913 |
if (a._edge == INVALID) {
|
deba@703
|
1914 |
_digraph->firstOut(a._edge, n);
|
deba@432
|
1915 |
a._forward = true;
|
deba@432
|
1916 |
}
|
deba@430
|
1917 |
}
|
deba@430
|
1918 |
else {
|
deba@703
|
1919 |
_digraph->nextOut(a._edge);
|
deba@430
|
1920 |
}
|
deba@430
|
1921 |
}
|
deba@430
|
1922 |
|
deba@430
|
1923 |
void firstIn(Arc &a, const Node &n) const {
|
deba@703
|
1924 |
_digraph->firstOut(a._edge, n);
|
deba@703
|
1925 |
if (a._edge != INVALID ) {
|
deba@432
|
1926 |
a._forward = false;
|
deba@430
|
1927 |
} else {
|
deba@703
|
1928 |
_digraph->firstIn(a._edge, n);
|
deba@432
|
1929 |
a._forward = true;
|
deba@430
|
1930 |
}
|
deba@430
|
1931 |
}
|
deba@430
|
1932 |
void nextIn(Arc &a) const {
|
deba@430
|
1933 |
if (!a._forward) {
|
deba@703
|
1934 |
Node n = _digraph->source(a._edge);
|
deba@703
|
1935 |
_digraph->nextOut(a._edge);
|
deba@703
|
1936 |
if (a._edge == INVALID ) {
|
deba@703
|
1937 |
_digraph->firstIn(a._edge, n);
|
deba@432
|
1938 |
a._forward = true;
|
deba@432
|
1939 |
}
|
deba@430
|
1940 |
}
|
deba@430
|
1941 |
else {
|
deba@703
|
1942 |
_digraph->nextIn(a._edge);
|
deba@430
|
1943 |
}
|
deba@430
|
1944 |
}
|
deba@430
|
1945 |
|
deba@430
|
1946 |
void firstInc(Edge &e, bool &d, const Node &n) const {
|
deba@430
|
1947 |
d = true;
|
deba@430
|
1948 |
_digraph->firstOut(e, n);
|
deba@430
|
1949 |
if (e != INVALID) return;
|
deba@430
|
1950 |
d = false;
|
deba@430
|
1951 |
_digraph->firstIn(e, n);
|
deba@430
|
1952 |
}
|
deba@430
|
1953 |
|
deba@430
|
1954 |
void nextInc(Edge &e, bool &d) const {
|
deba@430
|
1955 |
if (d) {
|
deba@432
|
1956 |
Node s = _digraph->source(e);
|
deba@432
|
1957 |
_digraph->nextOut(e);
|
deba@432
|
1958 |
if (e != INVALID) return;
|
deba@432
|
1959 |
d = false;
|
deba@432
|
1960 |
_digraph->firstIn(e, s);
|
deba@430
|
1961 |
} else {
|
deba@432
|
1962 |
_digraph->nextIn(e);
|
deba@430
|
1963 |
}
|
deba@430
|
1964 |
}
|
deba@430
|
1965 |
|
deba@430
|
1966 |
Node u(const Edge& e) const {
|
deba@430
|
1967 |
return _digraph->source(e);
|
deba@430
|
1968 |
}
|
deba@430
|
1969 |
|
deba@430
|
1970 |
Node v(const Edge& e) const {
|
deba@430
|
1971 |
return _digraph->target(e);
|
deba@430
|
1972 |
}
|
deba@430
|
1973 |
|
deba@430
|
1974 |
Node source(const Arc &a) const {
|
deba@703
|
1975 |
return a._forward ? _digraph->source(a._edge) : _digraph->target(a._edge);
|
deba@430
|
1976 |
}
|
deba@430
|
1977 |
|
deba@430
|
1978 |
Node target(const Arc &a) const {
|
deba@703
|
1979 |
return a._forward ? _digraph->target(a._edge) : _digraph->source(a._edge);
|
deba@430
|
1980 |
}
|
deba@430
|
1981 |
|
deba@430
|
1982 |
static Arc direct(const Edge &e, bool d) {
|
deba@430
|
1983 |
return Arc(e, d);
|
deba@430
|
1984 |
}
|
deba@430
|
1985 |
|
deba@430
|
1986 |
static bool direction(const Arc &a) { return a._forward; }
|
deba@430
|
1987 |
|
deba@430
|
1988 |
Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
|
deba@430
|
1989 |
Arc arcFromId(int ix) const {
|
deba@430
|
1990 |
return direct(_digraph->arcFromId(ix >> 1), bool(ix & 1));
|
deba@430
|
1991 |
}
|
deba@430
|
1992 |
Edge edgeFromId(int ix) const { return _digraph->arcFromId(ix); }
|
deba@430
|
1993 |
|
deba@430
|
1994 |
int id(const Node &n) const { return _digraph->id(n); }
|
deba@430
|
1995 |
int id(const Arc &a) const {
|
deba@430
|
1996 |
return (_digraph->id(a) << 1) | (a._forward ? 1 : 0);
|
deba@430
|
1997 |
}
|
deba@430
|
1998 |
int id(const Edge &e) const { return _digraph->id(e); }
|
deba@430
|
1999 |
|
deba@430
|
2000 |
int maxNodeId() const { return _digraph->maxNodeId(); }
|
deba@430
|
2001 |
int maxArcId() const { return (_digraph->maxArcId() << 1) | 1; }
|
deba@430
|
2002 |
int maxEdgeId() const { return _digraph->maxArcId(); }
|
deba@430
|
2003 |
|
deba@430
|
2004 |
Node addNode() { return _digraph->addNode(); }
|
deba@432
|
2005 |
Edge addEdge(const Node& u, const Node& v) {
|
deba@432
|
2006 |
return _digraph->addArc(u, v);
|
deba@430
|
2007 |
}
|
deba@430
|
2008 |
|
deba@430
|
2009 |
void erase(const Node& i) { _digraph->erase(i); }
|
deba@430
|
2010 |
void erase(const Edge& i) { _digraph->erase(i); }
|
deba@432
|
2011 |
|
deba@430
|
2012 |
void clear() { _digraph->clear(); }
|
deba@430
|
2013 |
|
deba@430
|
2014 |
typedef NodeNumTagIndicator<Digraph> NodeNumTag;
|
kpeter@472
|
2015 |
int nodeNum() const { return _digraph->nodeNum(); }
|
kpeter@469
|
2016 |
|
kpeter@469
|
2017 |
typedef ArcNumTagIndicator<Digraph> ArcNumTag;
|
deba@430
|
2018 |
int arcNum() const { return 2 * _digraph->arcNum(); }
|
kpeter@469
|
2019 |
|
kpeter@469
|
2020 |
typedef ArcNumTag EdgeNumTag;
|
deba@430
|
2021 |
int edgeNum() const { return _digraph->arcNum(); }
|
deba@430
|
2022 |
|
kpeter@469
|
2023 |
typedef FindArcTagIndicator<Digraph> FindArcTag;
|
deba@430
|
2024 |
Arc findArc(Node s, Node t, Arc p = INVALID) const {
|
deba@430
|
2025 |
if (p == INVALID) {
|
deba@432
|
2026 |
Edge arc = _digraph->findArc(s, t);
|
deba@432
|
2027 |
if (arc != INVALID) return direct(arc, true);
|
deba@432
|
2028 |
arc = _digraph->findArc(t, s);
|
deba@432
|
2029 |
if (arc != INVALID) return direct(arc, false);
|
deba@430
|
2030 |
} else if (direction(p)) {
|
deba@432
|
2031 |
Edge arc = _digraph->findArc(s, t, p);
|
deba@432
|
2032 |
if (arc != INVALID) return direct(arc, true);
|
deba@432
|
2033 |
arc = _digraph->findArc(t, s);
|
deba@432
|
2034 |
if (arc != INVALID) return direct(arc, false);
|
deba@430
|
2035 |
} else {
|
deba@432
|
2036 |
Edge arc = _digraph->findArc(t, s, p);
|
deba@432
|
2037 |
if (arc != INVALID) return direct(arc, false);
|
deba@430
|
2038 |
}
|
deba@430
|
2039 |
return INVALID;
|
deba@430
|
2040 |
}
|
deba@430
|
2041 |
|
kpeter@469
|
2042 |
typedef FindArcTag FindEdgeTag;
|
deba@430
|
2043 |
Edge findEdge(Node s, Node t, Edge p = INVALID) const {
|
deba@430
|
2044 |
if (s != t) {
|
deba@430
|
2045 |
if (p == INVALID) {
|
deba@430
|
2046 |
Edge arc = _digraph->findArc(s, t);
|
deba@430
|
2047 |
if (arc != INVALID) return arc;
|
deba@430
|
2048 |
arc = _digraph->findArc(t, s);
|
deba@430
|
2049 |
if (arc != INVALID) return arc;
|
kpeter@472
|
2050 |
} else if (_digraph->source(p) == s) {
|
deba@430
|
2051 |
Edge arc = _digraph->findArc(s, t, p);
|
deba@430
|
2052 |
if (arc != INVALID) return arc;
|
deba@430
|
2053 |
arc = _digraph->findArc(t, s);
|
deba@432
|
2054 |
if (arc != INVALID) return arc;
|
deba@430
|
2055 |
} else {
|
deba@430
|
2056 |
Edge arc = _digraph->findArc(t, s, p);
|
deba@432
|
2057 |
if (arc != INVALID) return arc;
|
deba@430
|
2058 |
}
|
deba@430
|
2059 |
} else {
|
deba@430
|
2060 |
return _digraph->findArc(s, t, p);
|
deba@430
|
2061 |
}
|
deba@430
|
2062 |
return INVALID;
|
deba@430
|
2063 |
}
|
deba@430
|
2064 |
|
deba@430
|
2065 |
private:
|
deba@432
|
2066 |
|
deba@559
|
2067 |
template <typename V>
|
deba@430
|
2068 |
class ArcMapBase {
|
deba@430
|
2069 |
private:
|
deba@432
|
2070 |
|
deba@559
|
2071 |
typedef typename DGR::template ArcMap<V> MapImpl;
|
deba@432
|
2072 |
|
deba@430
|
2073 |
public:
|
deba@430
|
2074 |
|
deba@430
|
2075 |
typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
|
deba@430
|
2076 |
|
deba@559
|
2077 |
typedef V Value;
|
deba@430
|
2078 |
typedef Arc Key;
|
kpeter@472
|
2079 |
typedef typename MapTraits<MapImpl>::ConstReturnValue ConstReturnValue;
|
kpeter@472
|
2080 |
typedef typename MapTraits<MapImpl>::ReturnValue ReturnValue;
|
kpeter@472
|
2081 |
typedef typename MapTraits<MapImpl>::ConstReturnValue ConstReference;
|
kpeter@472
|
2082 |
typedef typename MapTraits<MapImpl>::ReturnValue Reference;
|
deba@432
|
2083 |
|
deba@559
|
2084 |
ArcMapBase(const UndirectorBase<DGR>& adaptor) :
|
deba@432
|
2085 |
_forward(*adaptor._digraph), _backward(*adaptor._digraph) {}
|
deba@432
|
2086 |
|
deba@559
|
2087 |
ArcMapBase(const UndirectorBase<DGR>& adaptor, const V& value)
|
deba@559
|
2088 |
: _forward(*adaptor._digraph, value),
|
deba@559
|
2089 |
_backward(*adaptor._digraph, value) {}
|
deba@559
|
2090 |
|
deba@559
|
2091 |
void set(const Arc& a, const V& value) {
|
deba@432
|
2092 |
if (direction(a)) {
|
deba@559
|
2093 |
_forward.set(a, value);
|
deba@432
|
2094 |
} else {
|
deba@559
|
2095 |
_backward.set(a, value);
|
deba@430
|
2096 |
}
|
deba@430
|
2097 |
}
|
deba@430
|
2098 |
|
kpeter@472
|
2099 |
ConstReturnValue operator[](const Arc& a) const {
|
deba@432
|
2100 |
if (direction(a)) {
|
deba@432
|
2101 |
return _forward[a];
|
deba@432
|
2102 |
} else {
|
deba@432
|
2103 |
return _backward[a];
|
deba@430
|
2104 |
}
|
deba@430
|
2105 |
}
|
deba@430
|
2106 |
|
kpeter@472
|
2107 |
ReturnValue operator[](const Arc& a) {
|
deba@432
|
2108 |
if (direction(a)) {
|
deba@432
|
2109 |
return _forward[a];
|
deba@432
|
2110 |
} else {
|
deba@432
|
2111 |
return _backward[a];
|
deba@432
|
2112 |
}
|
deba@432
|
2113 |
}
|
deba@432
|
2114 |
|
deba@430
|
2115 |
protected:
|
deba@430
|
2116 |
|
deba@432
|
2117 |
MapImpl _forward, _backward;
|
deba@430
|
2118 |
|
deba@430
|
2119 |
};
|
deba@430
|
2120 |
|
deba@430
|
2121 |
public:
|
deba@430
|
2122 |
|
deba@559
|
2123 |
template <typename V>
|
deba@559
|
2124 |
class NodeMap : public DGR::template NodeMap<V> {
|
kpeter@664
|
2125 |
typedef typename DGR::template NodeMap<V> Parent;
|
kpeter@664
|
2126 |
|
deba@430
|
2127 |
public:
|
deba@559
|
2128 |
typedef V Value;
|
deba@559
|
2129 |
|
deba@559
|
2130 |
explicit NodeMap(const UndirectorBase<DGR>& adaptor)
|
deba@432
|
2131 |
: Parent(*adaptor._digraph) {}
|
deba@430
|
2132 |
|
deba@559
|
2133 |
NodeMap(const UndirectorBase<DGR>& adaptor, const V& value)
|
deba@432
|
2134 |
: Parent(*adaptor._digraph, value) { }
|
deba@430
|
2135 |
|
deba@430
|
2136 |
private:
|
deba@430
|
2137 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@430
|
2138 |
return operator=<NodeMap>(cmap);
|
deba@430
|
2139 |
}
|
deba@430
|
2140 |
|
deba@430
|
2141 |
template <typename CMap>
|
deba@430
|
2142 |
NodeMap& operator=(const CMap& cmap) {
|
deba@430
|
2143 |
Parent::operator=(cmap);
|
deba@430
|
2144 |
return *this;
|
deba@430
|
2145 |
}
|
deba@432
|
2146 |
|
deba@430
|
2147 |
};
|
deba@430
|
2148 |
|
deba@559
|
2149 |
template <typename V>
|
deba@432
|
2150 |
class ArcMap
|
kpeter@664
|
2151 |
: public SubMapExtender<UndirectorBase<DGR>, ArcMapBase<V> > {
|
kpeter@664
|
2152 |
typedef SubMapExtender<UndirectorBase<DGR>, ArcMapBase<V> > Parent;
|
kpeter@664
|
2153 |
|
deba@430
|
2154 |
public:
|
deba@559
|
2155 |
typedef V Value;
|
deba@559
|
2156 |
|
deba@559
|
2157 |
explicit ArcMap(const UndirectorBase<DGR>& adaptor)
|
deba@432
|
2158 |
: Parent(adaptor) {}
|
deba@432
|
2159 |
|
deba@559
|
2160 |
ArcMap(const UndirectorBase<DGR>& adaptor, const V& value)
|
deba@432
|
2161 |
: Parent(adaptor, value) {}
|
deba@432
|
2162 |
|
deba@430
|
2163 |
private:
|
deba@430
|
2164 |
ArcMap& operator=(const ArcMap& cmap) {
|
deba@432
|
2165 |
return operator=<ArcMap>(cmap);
|
deba@430
|
2166 |
}
|
deba@432
|
2167 |
|
deba@430
|
2168 |
template <typename CMap>
|
deba@430
|
2169 |
ArcMap& operator=(const CMap& cmap) {
|
deba@430
|
2170 |
Parent::operator=(cmap);
|
deba@432
|
2171 |
return *this;
|
deba@430
|
2172 |
}
|
deba@430
|
2173 |
};
|
deba@432
|
2174 |
|
deba@559
|
2175 |
template <typename V>
|
deba@559
|
2176 |
class EdgeMap : public Digraph::template ArcMap<V> {
|
kpeter@664
|
2177 |
typedef typename Digraph::template ArcMap<V> Parent;
|
kpeter@664
|
2178 |
|
deba@430
|
2179 |
public:
|
deba@559
|
2180 |
typedef V Value;
|
deba@559
|
2181 |
|
deba@559
|
2182 |
explicit EdgeMap(const UndirectorBase<DGR>& adaptor)
|
deba@432
|
2183 |
: Parent(*adaptor._digraph) {}
|
deba@430
|
2184 |
|
deba@559
|
2185 |
EdgeMap(const UndirectorBase<DGR>& adaptor, const V& value)
|
deba@432
|
2186 |
: Parent(*adaptor._digraph, value) {}
|
deba@430
|
2187 |
|
deba@430
|
2188 |
private:
|
deba@430
|
2189 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@430
|
2190 |
return operator=<EdgeMap>(cmap);
|
deba@430
|
2191 |
}
|
deba@430
|
2192 |
|
deba@430
|
2193 |
template <typename CMap>
|
deba@430
|
2194 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@430
|
2195 |
Parent::operator=(cmap);
|
deba@430
|
2196 |
return *this;
|
deba@430
|
2197 |
}
|
deba@430
|
2198 |
|
deba@430
|
2199 |
};
|
deba@430
|
2200 |
|
deba@559
|
2201 |
typedef typename ItemSetTraits<DGR, Node>::ItemNotifier NodeNotifier;
|
deba@432
|
2202 |
NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); }
|
deba@430
|
2203 |
|
deba@559
|
2204 |
typedef typename ItemSetTraits<DGR, Edge>::ItemNotifier EdgeNotifier;
|
kpeter@472
|
2205 |
EdgeNotifier& notifier(Edge) const { return _digraph->notifier(Edge()); }
|
kpeter@626
|
2206 |
|
kpeter@626
|
2207 |
typedef EdgeNotifier ArcNotifier;
|
kpeter@626
|
2208 |
ArcNotifier& notifier(Arc) const { return _digraph->notifier(Edge()); }
|
kpeter@472
|
2209 |
|
deba@430
|
2210 |
protected:
|
deba@430
|
2211 |
|
deba@432
|
2212 |
UndirectorBase() : _digraph(0) {}
|
deba@430
|
2213 |
|
deba@559
|
2214 |
DGR* _digraph;
|
deba@559
|
2215 |
|
deba@559
|
2216 |
void initialize(DGR& digraph) {
|
deba@430
|
2217 |
_digraph = &digraph;
|
deba@430
|
2218 |
}
|
deba@432
|
2219 |
|
deba@430
|
2220 |
};
|
deba@430
|
2221 |
|
deba@432
|
2222 |
/// \ingroup graph_adaptors
|
deba@430
|
2223 |
///
|
kpeter@474
|
2224 |
/// \brief Adaptor class for viewing a digraph as an undirected graph.
|
deba@430
|
2225 |
///
|
kpeter@474
|
2226 |
/// Undirector adaptor can be used for viewing a digraph as an undirected
|
kpeter@474
|
2227 |
/// graph. All arcs of the underlying digraph are showed in the
|
kpeter@474
|
2228 |
/// adaptor as an edge (and also as a pair of arcs, of course).
|
kpeter@474
|
2229 |
/// This adaptor conforms to the \ref concepts::Graph "Graph" concept.
|
deba@430
|
2230 |
///
|
kpeter@474
|
2231 |
/// The adapted digraph can also be modified through this adaptor
|
kpeter@476
|
2232 |
/// by adding or removing nodes or edges, unless the \c GR template
|
kpeter@474
|
2233 |
/// parameter is set to be \c const.
|
kpeter@474
|
2234 |
///
|
deba@559
|
2235 |
/// \tparam DGR The type of the adapted digraph.
|
kpeter@474
|
2236 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept.
|
kpeter@474
|
2237 |
/// It can also be specified to be \c const.
|
kpeter@474
|
2238 |
///
|
kpeter@474
|
2239 |
/// \note The \c Node type of this adaptor and the adapted digraph are
|
kpeter@474
|
2240 |
/// convertible to each other, moreover the \c Edge type of the adaptor
|
kpeter@474
|
2241 |
/// and the \c Arc type of the adapted digraph are also convertible to
|
kpeter@474
|
2242 |
/// each other.
|
kpeter@474
|
2243 |
/// (Thus the \c Arc type of the adaptor is convertible to the \c Arc type
|
kpeter@474
|
2244 |
/// of the adapted digraph.)
|
deba@559
|
2245 |
template<typename DGR>
|
kpeter@476
|
2246 |
#ifdef DOXYGEN
|
kpeter@476
|
2247 |
class Undirector {
|
kpeter@476
|
2248 |
#else
|
kpeter@476
|
2249 |
class Undirector :
|
deba@559
|
2250 |
public GraphAdaptorExtender<UndirectorBase<DGR> > {
|
kpeter@476
|
2251 |
#endif
|
kpeter@664
|
2252 |
typedef GraphAdaptorExtender<UndirectorBase<DGR> > Parent;
|
deba@430
|
2253 |
public:
|
kpeter@476
|
2254 |
/// The type of the adapted digraph.
|
deba@559
|
2255 |
typedef DGR Digraph;
|
deba@430
|
2256 |
protected:
|
deba@432
|
2257 |
Undirector() { }
|
deba@430
|
2258 |
public:
|
deba@430
|
2259 |
|
deba@430
|
2260 |
/// \brief Constructor
|
deba@430
|
2261 |
///
|
kpeter@474
|
2262 |
/// Creates an undirected graph from the given digraph.
|
deba@559
|
2263 |
Undirector(DGR& digraph) {
|
deba@559
|
2264 |
initialize(digraph);
|
deba@430
|
2265 |
}
|
deba@430
|
2266 |
|
kpeter@474
|
2267 |
/// \brief Arc map combined from two original arc maps
|
deba@430
|
2268 |
///
|
kpeter@474
|
2269 |
/// This map adaptor class adapts two arc maps of the underlying
|
kpeter@474
|
2270 |
/// digraph to get an arc map of the undirected graph.
|
kpeter@606
|
2271 |
/// Its value type is inherited from the first arc map type (\c FW).
|
kpeter@606
|
2272 |
/// \tparam FW The type of the "foward" arc map.
|
kpeter@606
|
2273 |
/// \tparam BK The type of the "backward" arc map.
|
kpeter@606
|
2274 |
template <typename FW, typename BK>
|
deba@430
|
2275 |
class CombinedArcMap {
|
deba@430
|
2276 |
public:
|
deba@432
|
2277 |
|
kpeter@474
|
2278 |
/// The key type of the map
|
kpeter@474
|
2279 |
typedef typename Parent::Arc Key;
|
kpeter@474
|
2280 |
/// The value type of the map
|
kpeter@606
|
2281 |
typedef typename FW::Value Value;
|
kpeter@606
|
2282 |
|
kpeter@606
|
2283 |
typedef typename MapTraits<FW>::ReferenceMapTag ReferenceMapTag;
|
kpeter@606
|
2284 |
|
kpeter@606
|
2285 |
typedef typename MapTraits<FW>::ReturnValue ReturnValue;
|
kpeter@606
|
2286 |
typedef typename MapTraits<FW>::ConstReturnValue ConstReturnValue;
|
kpeter@606
|
2287 |
typedef typename MapTraits<FW>::ReturnValue Reference;
|
kpeter@606
|
2288 |
typedef typename MapTraits<FW>::ConstReturnValue ConstReference;
|
kpeter@472
|
2289 |
|
deba@432
|
2290 |
/// Constructor
|
kpeter@606
|
2291 |
CombinedArcMap(FW& forward, BK& backward)
|
deba@430
|
2292 |
: _forward(&forward), _backward(&backward) {}
|
deba@432
|
2293 |
|
kpeter@474
|
2294 |
/// Sets the value associated with the given key.
|
deba@432
|
2295 |
void set(const Key& e, const Value& a) {
|
deba@432
|
2296 |
if (Parent::direction(e)) {
|
deba@432
|
2297 |
_forward->set(e, a);
|
deba@432
|
2298 |
} else {
|
deba@432
|
2299 |
_backward->set(e, a);
|
deba@432
|
2300 |
}
|
deba@430
|
2301 |
}
|
deba@430
|
2302 |
|
kpeter@474
|
2303 |
/// Returns the value associated with the given key.
|
kpeter@472
|
2304 |
ConstReturnValue operator[](const Key& e) const {
|
deba@432
|
2305 |
if (Parent::direction(e)) {
|
deba@432
|
2306 |
return (*_forward)[e];
|
deba@432
|
2307 |
} else {
|
deba@432
|
2308 |
return (*_backward)[e];
|
deba@430
|
2309 |
}
|
deba@430
|
2310 |
}
|
deba@430
|
2311 |
|
kpeter@474
|
2312 |
/// Returns a reference to the value associated with the given key.
|
kpeter@472
|
2313 |
ReturnValue operator[](const Key& e) {
|
deba@432
|
2314 |
if (Parent::direction(e)) {
|
deba@432
|
2315 |
return (*_forward)[e];
|
deba@432
|
2316 |
} else {
|
deba@432
|
2317 |
return (*_backward)[e];
|
deba@430
|
2318 |
}
|
deba@430
|
2319 |
}
|
deba@430
|
2320 |
|
deba@432
|
2321 |
protected:
|
deba@432
|
2322 |
|
kpeter@606
|
2323 |
FW* _forward;
|
kpeter@606
|
2324 |
BK* _backward;
|
deba@432
|
2325 |
|
deba@432
|
2326 |
};
|
deba@432
|
2327 |
|
kpeter@474
|
2328 |
/// \brief Returns a combined arc map
|
deba@432
|
2329 |
///
|
kpeter@474
|
2330 |
/// This function just returns a combined arc map.
|
kpeter@606
|
2331 |
template <typename FW, typename BK>
|
kpeter@606
|
2332 |
static CombinedArcMap<FW, BK>
|
kpeter@606
|
2333 |
combinedArcMap(FW& forward, BK& backward) {
|
kpeter@606
|
2334 |
return CombinedArcMap<FW, BK>(forward, backward);
|
deba@432
|
2335 |
}
|
deba@432
|
2336 |
|
kpeter@606
|
2337 |
template <typename FW, typename BK>
|
kpeter@606
|
2338 |
static CombinedArcMap<const FW, BK>
|
kpeter@606
|
2339 |
combinedArcMap(const FW& forward, BK& backward) {
|
kpeter@606
|
2340 |
return CombinedArcMap<const FW, BK>(forward, backward);
|
deba@432
|
2341 |
}
|
deba@432
|
2342 |
|
kpeter@606
|
2343 |
template <typename FW, typename BK>
|
kpeter@606
|
2344 |
static CombinedArcMap<FW, const BK>
|
kpeter@606
|
2345 |
combinedArcMap(FW& forward, const BK& backward) {
|
kpeter@606
|
2346 |
return CombinedArcMap<FW, const BK>(forward, backward);
|
deba@432
|
2347 |
}
|
deba@432
|
2348 |
|
kpeter@606
|
2349 |
template <typename FW, typename BK>
|
kpeter@606
|
2350 |
static CombinedArcMap<const FW, const BK>
|
kpeter@606
|
2351 |
combinedArcMap(const FW& forward, const BK& backward) {
|
kpeter@606
|
2352 |
return CombinedArcMap<const FW, const BK>(forward, backward);
|
deba@432
|
2353 |
}
|
deba@432
|
2354 |
|
deba@432
|
2355 |
};
|
deba@432
|
2356 |
|
kpeter@474
|
2357 |
/// \brief Returns a read-only Undirector adaptor
|
deba@432
|
2358 |
///
|
kpeter@474
|
2359 |
/// This function just returns a read-only \ref Undirector adaptor.
|
kpeter@474
|
2360 |
/// \ingroup graph_adaptors
|
kpeter@474
|
2361 |
/// \relates Undirector
|
deba@559
|
2362 |
template<typename DGR>
|
deba@559
|
2363 |
Undirector<const DGR> undirector(const DGR& digraph) {
|
deba@559
|
2364 |
return Undirector<const DGR>(digraph);
|
deba@432
|
2365 |
}
|
deba@432
|
2366 |
|
kpeter@474
|
2367 |
|
deba@559
|
2368 |
template <typename GR, typename DM>
|
deba@432
|
2369 |
class OrienterBase {
|
deba@432
|
2370 |
public:
|
deba@432
|
2371 |
|
deba@559
|
2372 |
typedef GR Graph;
|
deba@559
|
2373 |
typedef DM DirectionMap;
|
deba@559
|
2374 |
|
deba@559
|
2375 |
typedef typename GR::Node Node;
|
deba@559
|
2376 |
typedef typename GR::Edge Arc;
|
deba@432
|
2377 |
|
deba@432
|
2378 |
void reverseArc(const Arc& arc) {
|
deba@432
|
2379 |
_direction->set(arc, !(*_direction)[arc]);
|
deba@432
|
2380 |
}
|
deba@432
|
2381 |
|
deba@432
|
2382 |
void first(Node& i) const { _graph->first(i); }
|
deba@432
|
2383 |
void first(Arc& i) const { _graph->first(i); }
|
deba@432
|
2384 |
void firstIn(Arc& i, const Node& n) const {
|
kpeter@470
|
2385 |
bool d = true;
|
deba@432
|
2386 |
_graph->firstInc(i, d, n);
|
deba@432
|
2387 |
while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
|
deba@432
|
2388 |
}
|
deba@432
|
2389 |
void firstOut(Arc& i, const Node& n ) const {
|
kpeter@470
|
2390 |
bool d = true;
|
deba@432
|
2391 |
_graph->firstInc(i, d, n);
|
deba@432
|
2392 |
while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
|
deba@432
|
2393 |
}
|
deba@432
|
2394 |
|
deba@432
|
2395 |
void next(Node& i) const { _graph->next(i); }
|
deba@432
|
2396 |
void next(Arc& i) const { _graph->next(i); }
|
deba@432
|
2397 |
void nextIn(Arc& i) const {
|
deba@432
|
2398 |
bool d = !(*_direction)[i];
|
deba@432
|
2399 |
_graph->nextInc(i, d);
|
deba@432
|
2400 |
while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
|
deba@432
|
2401 |
}
|
deba@432
|
2402 |
void nextOut(Arc& i) const {
|
deba@432
|
2403 |
bool d = (*_direction)[i];
|
deba@432
|
2404 |
_graph->nextInc(i, d);
|
deba@432
|
2405 |
while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
|
deba@432
|
2406 |
}
|
deba@432
|
2407 |
|
deba@432
|
2408 |
Node source(const Arc& e) const {
|
deba@432
|
2409 |
return (*_direction)[e] ? _graph->u(e) : _graph->v(e);
|
deba@432
|
2410 |
}
|
deba@432
|
2411 |
Node target(const Arc& e) const {
|
deba@432
|
2412 |
return (*_direction)[e] ? _graph->v(e) : _graph->u(e);
|
deba@432
|
2413 |
}
|
deba@432
|
2414 |
|
deba@432
|
2415 |
typedef NodeNumTagIndicator<Graph> NodeNumTag;
|
deba@432
|
2416 |
int nodeNum() const { return _graph->nodeNum(); }
|
deba@432
|
2417 |
|
kpeter@469
|
2418 |
typedef EdgeNumTagIndicator<Graph> ArcNumTag;
|
deba@432
|
2419 |
int arcNum() const { return _graph->edgeNum(); }
|
deba@432
|
2420 |
|
kpeter@469
|
2421 |
typedef FindEdgeTagIndicator<Graph> FindArcTag;
|
deba@432
|
2422 |
Arc findArc(const Node& u, const Node& v,
|
kpeter@471
|
2423 |
const Arc& prev = INVALID) const {
|
kpeter@472
|
2424 |
Arc arc = _graph->findEdge(u, v, prev);
|
kpeter@472
|
2425 |
while (arc != INVALID && source(arc) != u) {
|
deba@432
|
2426 |
arc = _graph->findEdge(u, v, arc);
|
deba@430
|
2427 |
}
|
deba@432
|
2428 |
return arc;
|
deba@432
|
2429 |
}
|
deba@432
|
2430 |
|
deba@432
|
2431 |
Node addNode() {
|
deba@432
|
2432 |
return Node(_graph->addNode());
|
deba@432
|
2433 |
}
|
deba@432
|
2434 |
|
deba@432
|
2435 |
Arc addArc(const Node& u, const Node& v) {
|
kpeter@472
|
2436 |
Arc arc = _graph->addEdge(u, v);
|
kpeter@472
|
2437 |
_direction->set(arc, _graph->u(arc) == u);
|
deba@432
|
2438 |
return arc;
|
deba@432
|
2439 |
}
|
deba@432
|
2440 |
|
deba@432
|
2441 |
void erase(const Node& i) { _graph->erase(i); }
|
deba@432
|
2442 |
void erase(const Arc& i) { _graph->erase(i); }
|
deba@432
|
2443 |
|
deba@432
|
2444 |
void clear() { _graph->clear(); }
|
deba@432
|
2445 |
|
deba@432
|
2446 |
int id(const Node& v) const { return _graph->id(v); }
|
deba@432
|
2447 |
int id(const Arc& e) const { return _graph->id(e); }
|
deba@432
|
2448 |
|
deba@432
|
2449 |
Node nodeFromId(int idx) const { return _graph->nodeFromId(idx); }
|
deba@432
|
2450 |
Arc arcFromId(int idx) const { return _graph->edgeFromId(idx); }
|
deba@432
|
2451 |
|
deba@432
|
2452 |
int maxNodeId() const { return _graph->maxNodeId(); }
|
deba@432
|
2453 |
int maxArcId() const { return _graph->maxEdgeId(); }
|
deba@432
|
2454 |
|
deba@559
|
2455 |
typedef typename ItemSetTraits<GR, Node>::ItemNotifier NodeNotifier;
|
deba@432
|
2456 |
NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
|
deba@432
|
2457 |
|
deba@559
|
2458 |
typedef typename ItemSetTraits<GR, Arc>::ItemNotifier ArcNotifier;
|
deba@432
|
2459 |
ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
|
deba@432
|
2460 |
|
deba@559
|
2461 |
template <typename V>
|
deba@559
|
2462 |
class NodeMap : public GR::template NodeMap<V> {
|
kpeter@664
|
2463 |
typedef typename GR::template NodeMap<V> Parent;
|
kpeter@664
|
2464 |
|
deba@432
|
2465 |
public:
|
deba@432
|
2466 |
|
deba@559
|
2467 |
explicit NodeMap(const OrienterBase<GR, DM>& adapter)
|
deba@432
|
2468 |
: Parent(*adapter._graph) {}
|
deba@432
|
2469 |
|
deba@559
|
2470 |
NodeMap(const OrienterBase<GR, DM>& adapter, const V& value)
|
deba@432
|
2471 |
: Parent(*adapter._graph, value) {}
|
deba@432
|
2472 |
|
deba@432
|
2473 |
private:
|
deba@432
|
2474 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@432
|
2475 |
return operator=<NodeMap>(cmap);
|
deba@432
|
2476 |
}
|
deba@432
|
2477 |
|
deba@432
|
2478 |
template <typename CMap>
|
deba@432
|
2479 |
NodeMap& operator=(const CMap& cmap) {
|
deba@432
|
2480 |
Parent::operator=(cmap);
|
deba@432
|
2481 |
return *this;
|
deba@432
|
2482 |
}
|
deba@430
|
2483 |
|
deba@430
|
2484 |
};
|
deba@430
|
2485 |
|
deba@559
|
2486 |
template <typename V>
|
deba@559
|
2487 |
class ArcMap : public GR::template EdgeMap<V> {
|
kpeter@664
|
2488 |
typedef typename Graph::template EdgeMap<V> Parent;
|
kpeter@664
|
2489 |
|
deba@432
|
2490 |
public:
|
deba@432
|
2491 |
|
deba@559
|
2492 |
explicit ArcMap(const OrienterBase<GR, DM>& adapter)
|
deba@432
|
2493 |
: Parent(*adapter._graph) { }
|
deba@432
|
2494 |
|
deba@559
|
2495 |
ArcMap(const OrienterBase<GR, DM>& adapter, const V& value)
|
deba@432
|
2496 |
: Parent(*adapter._graph, value) { }
|
deba@432
|
2497 |
|
deba@432
|
2498 |
private:
|
deba@432
|
2499 |
ArcMap& operator=(const ArcMap& cmap) {
|
deba@432
|
2500 |
return operator=<ArcMap>(cmap);
|
deba@432
|
2501 |
}
|
deba@432
|
2502 |
|
deba@432
|
2503 |
template <typename CMap>
|
deba@432
|
2504 |
ArcMap& operator=(const CMap& cmap) {
|
deba@432
|
2505 |
Parent::operator=(cmap);
|
deba@432
|
2506 |
return *this;
|
deba@432
|
2507 |
}
|
deba@432
|
2508 |
};
|
deba@432
|
2509 |
|
deba@432
|
2510 |
|
deba@432
|
2511 |
|
deba@432
|
2512 |
protected:
|
deba@432
|
2513 |
Graph* _graph;
|
deba@559
|
2514 |
DM* _direction;
|
deba@559
|
2515 |
|
deba@559
|
2516 |
void initialize(GR& graph, DM& direction) {
|
deba@559
|
2517 |
_graph = &graph;
|
deba@432
|
2518 |
_direction = &direction;
|
deba@432
|
2519 |
}
|
deba@432
|
2520 |
|
deba@430
|
2521 |
};
|
deba@430
|
2522 |
|
deba@432
|
2523 |
/// \ingroup graph_adaptors
|
deba@430
|
2524 |
///
|
kpeter@474
|
2525 |
/// \brief Adaptor class for orienting the edges of a graph to get a digraph
|
deba@432
|
2526 |
///
|
kpeter@474
|
2527 |
/// Orienter adaptor can be used for orienting the edges of a graph to
|
kpeter@474
|
2528 |
/// get a digraph. A \c bool edge map of the underlying graph must be
|
kpeter@474
|
2529 |
/// specified, which define the direction of the arcs in the adaptor.
|
kpeter@474
|
2530 |
/// The arcs can be easily reversed by the \c reverseArc() member function
|
kpeter@474
|
2531 |
/// of the adaptor.
|
kpeter@474
|
2532 |
/// This class conforms to the \ref concepts::Digraph "Digraph" concept.
|
deba@432
|
2533 |
///
|
kpeter@474
|
2534 |
/// The adapted graph can also be modified through this adaptor
|
kpeter@476
|
2535 |
/// by adding or removing nodes or arcs, unless the \c GR template
|
kpeter@474
|
2536 |
/// parameter is set to be \c const.
|
deba@432
|
2537 |
///
|
kpeter@476
|
2538 |
/// \tparam GR The type of the adapted graph.
|
kpeter@474
|
2539 |
/// It must conform to the \ref concepts::Graph "Graph" concept.
|
kpeter@474
|
2540 |
/// It can also be specified to be \c const.
|
kpeter@476
|
2541 |
/// \tparam DM The type of the direction map.
|
kpeter@476
|
2542 |
/// It must be a \c bool (or convertible) edge map of the
|
kpeter@476
|
2543 |
/// adapted graph. The default type is
|
kpeter@476
|
2544 |
/// \ref concepts::Graph::EdgeMap "GR::EdgeMap<bool>".
|
kpeter@474
|
2545 |
///
|
kpeter@474
|
2546 |
/// \note The \c Node type of this adaptor and the adapted graph are
|
kpeter@474
|
2547 |
/// convertible to each other, moreover the \c Arc type of the adaptor
|
kpeter@474
|
2548 |
/// and the \c Edge type of the adapted graph are also convertible to
|
kpeter@474
|
2549 |
/// each other.
|
kpeter@474
|
2550 |
#ifdef DOXYGEN
|
kpeter@476
|
2551 |
template<typename GR,
|
kpeter@476
|
2552 |
typename DM>
|
kpeter@476
|
2553 |
class Orienter {
|
kpeter@474
|
2554 |
#else
|
kpeter@476
|
2555 |
template<typename GR,
|
kpeter@476
|
2556 |
typename DM = typename GR::template EdgeMap<bool> >
|
kpeter@476
|
2557 |
class Orienter :
|
kpeter@476
|
2558 |
public DigraphAdaptorExtender<OrienterBase<GR, DM> > {
|
kpeter@474
|
2559 |
#endif
|
kpeter@664
|
2560 |
typedef DigraphAdaptorExtender<OrienterBase<GR, DM> > Parent;
|
deba@432
|
2561 |
public:
|
kpeter@474
|
2562 |
|
kpeter@474
|
2563 |
/// The type of the adapted graph.
|
kpeter@476
|
2564 |
typedef GR Graph;
|
kpeter@474
|
2565 |
/// The type of the direction edge map.
|
kpeter@476
|
2566 |
typedef DM DirectionMap;
|
kpeter@476
|
2567 |
|
deba@432
|
2568 |
typedef typename Parent::Arc Arc;
|
kpeter@664
|
2569 |
|
deba@432
|
2570 |
protected:
|
deba@432
|
2571 |
Orienter() { }
|
kpeter@664
|
2572 |
|
deba@432
|
2573 |
public:
|
deba@432
|
2574 |
|
kpeter@474
|
2575 |
/// \brief Constructor
|
deba@432
|
2576 |
///
|
kpeter@474
|
2577 |
/// Constructor of the adaptor.
|
deba@559
|
2578 |
Orienter(GR& graph, DM& direction) {
|
deba@559
|
2579 |
Parent::initialize(graph, direction);
|
deba@432
|
2580 |
}
|
deba@432
|
2581 |
|
kpeter@474
|
2582 |
/// \brief Reverses the given arc
|
deba@432
|
2583 |
///
|
kpeter@474
|
2584 |
/// This function reverses the given arc.
|
kpeter@474
|
2585 |
/// It is done by simply negate the assigned value of \c a
|
kpeter@474
|
2586 |
/// in the direction map.
|
deba@432
|
2587 |
void reverseArc(const Arc& a) {
|
deba@432
|
2588 |
Parent::reverseArc(a);
|
deba@432
|
2589 |
}
|
deba@432
|
2590 |
};
|
deba@432
|
2591 |
|
kpeter@474
|
2592 |
/// \brief Returns a read-only Orienter adaptor
|
deba@432
|
2593 |
///
|
kpeter@474
|
2594 |
/// This function just returns a read-only \ref Orienter adaptor.
|
kpeter@474
|
2595 |
/// \ingroup graph_adaptors
|
kpeter@474
|
2596 |
/// \relates Orienter
|
kpeter@476
|
2597 |
template<typename GR, typename DM>
|
kpeter@476
|
2598 |
Orienter<const GR, DM>
|
deba@559
|
2599 |
orienter(const GR& graph, DM& direction) {
|
deba@559
|
2600 |
return Orienter<const GR, DM>(graph, direction);
|
deba@430
|
2601 |
}
|
deba@430
|
2602 |
|
kpeter@476
|
2603 |
template<typename GR, typename DM>
|
kpeter@476
|
2604 |
Orienter<const GR, const DM>
|
deba@559
|
2605 |
orienter(const GR& graph, const DM& direction) {
|
deba@559
|
2606 |
return Orienter<const GR, const DM>(graph, direction);
|
deba@432
|
2607 |
}
|
deba@432
|
2608 |
|
deba@432
|
2609 |
namespace _adaptor_bits {
|
deba@432
|
2610 |
|
deba@559
|
2611 |
template <typename DGR, typename CM, typename FM, typename TL>
|
deba@432
|
2612 |
class ResForwardFilter {
|
deba@432
|
2613 |
public:
|
deba@432
|
2614 |
|
deba@559
|
2615 |
typedef typename DGR::Arc Key;
|
deba@432
|
2616 |
typedef bool Value;
|
deba@432
|
2617 |
|
deba@432
|
2618 |
private:
|
deba@432
|
2619 |
|
deba@559
|
2620 |
const CM* _capacity;
|
deba@559
|
2621 |
const FM* _flow;
|
deba@559
|
2622 |
TL _tolerance;
|
deba@559
|
2623 |
|
deba@432
|
2624 |
public:
|
deba@432
|
2625 |
|
deba@559
|
2626 |
ResForwardFilter(const CM& capacity, const FM& flow,
|
deba@559
|
2627 |
const TL& tolerance = TL())
|
deba@432
|
2628 |
: _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
|
deba@432
|
2629 |
|
deba@559
|
2630 |
bool operator[](const typename DGR::Arc& a) const {
|
deba@432
|
2631 |
return _tolerance.positive((*_capacity)[a] - (*_flow)[a]);
|
deba@432
|
2632 |
}
|
deba@432
|
2633 |
};
|
deba@432
|
2634 |
|
deba@559
|
2635 |
template<typename DGR,typename CM, typename FM, typename TL>
|
deba@432
|
2636 |
class ResBackwardFilter {
|
deba@432
|
2637 |
public:
|
deba@432
|
2638 |
|
deba@559
|
2639 |
typedef typename DGR::Arc Key;
|
deba@432
|
2640 |
typedef bool Value;
|
deba@432
|
2641 |
|
deba@432
|
2642 |
private:
|
deba@432
|
2643 |
|
deba@559
|
2644 |
const CM* _capacity;
|
deba@559
|
2645 |
const FM* _flow;
|
deba@559
|
2646 |
TL _tolerance;
|
deba@432
|
2647 |
|
deba@432
|
2648 |
public:
|
deba@432
|
2649 |
|
deba@559
|
2650 |
ResBackwardFilter(const CM& capacity, const FM& flow,
|
deba@559
|
2651 |
const TL& tolerance = TL())
|
deba@432
|
2652 |
: _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
|
deba@432
|
2653 |
|
deba@559
|
2654 |
bool operator[](const typename DGR::Arc& a) const {
|
deba@432
|
2655 |
return _tolerance.positive((*_flow)[a]);
|
deba@432
|
2656 |
}
|
deba@432
|
2657 |
};
|
deba@432
|
2658 |
|
deba@432
|
2659 |
}
|
deba@432
|
2660 |
|
deba@432
|
2661 |
/// \ingroup graph_adaptors
|
deba@432
|
2662 |
///
|
kpeter@474
|
2663 |
/// \brief Adaptor class for composing the residual digraph for directed
|
deba@432
|
2664 |
/// flow and circulation problems.
|
deba@432
|
2665 |
///
|
kpeter@487
|
2666 |
/// ResidualDigraph can be used for composing the \e residual digraph
|
kpeter@487
|
2667 |
/// for directed flow and circulation problems. Let \f$ G=(V, A) \f$
|
kpeter@487
|
2668 |
/// be a directed graph and let \f$ F \f$ be a number type.
|
kpeter@487
|
2669 |
/// Let \f$ flow, cap: A\to F \f$ be functions on the arcs.
|
kpeter@474
|
2670 |
/// This adaptor implements a digraph structure with node set \f$ V \f$
|
kpeter@474
|
2671 |
/// and arc set \f$ A_{forward}\cup A_{backward} \f$,
|
kpeter@474
|
2672 |
/// where \f$ A_{forward}=\{uv : uv\in A, flow(uv)<cap(uv)\} \f$ and
|
kpeter@474
|
2673 |
/// \f$ A_{backward}=\{vu : uv\in A, flow(uv)>0\} \f$, i.e. the so
|
kpeter@474
|
2674 |
/// called residual digraph.
|
kpeter@474
|
2675 |
/// When the union \f$ A_{forward}\cup A_{backward} \f$ is taken,
|
kpeter@474
|
2676 |
/// multiplicities are counted, i.e. the adaptor has exactly
|
kpeter@474
|
2677 |
/// \f$ |A_{forward}| + |A_{backward}|\f$ arcs (it may have parallel
|
kpeter@474
|
2678 |
/// arcs).
|
kpeter@474
|
2679 |
/// This class conforms to the \ref concepts::Digraph "Digraph" concept.
|
deba@432
|
2680 |
///
|
deba@559
|
2681 |
/// \tparam DGR The type of the adapted digraph.
|
kpeter@474
|
2682 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept.
|
kpeter@474
|
2683 |
/// It is implicitly \c const.
|
kpeter@476
|
2684 |
/// \tparam CM The type of the capacity map.
|
kpeter@476
|
2685 |
/// It must be an arc map of some numerical type, which defines
|
kpeter@474
|
2686 |
/// the capacities in the flow problem. It is implicitly \c const.
|
kpeter@476
|
2687 |
/// The default type is
|
kpeter@476
|
2688 |
/// \ref concepts::Digraph::ArcMap "GR::ArcMap<int>".
|
kpeter@476
|
2689 |
/// \tparam FM The type of the flow map.
|
kpeter@476
|
2690 |
/// It must be an arc map of some numerical type, which defines
|
kpeter@476
|
2691 |
/// the flow values in the flow problem. The default type is \c CM.
|
kpeter@476
|
2692 |
/// \tparam TL The tolerance type for handling inexact computation.
|
kpeter@474
|
2693 |
/// The default tolerance type depends on the value type of the
|
kpeter@474
|
2694 |
/// capacity map.
|
deba@432
|
2695 |
///
|
kpeter@474
|
2696 |
/// \note This adaptor is implemented using Undirector and FilterArcs
|
kpeter@474
|
2697 |
/// adaptors.
|
kpeter@474
|
2698 |
///
|
kpeter@474
|
2699 |
/// \note The \c Node type of this adaptor and the adapted digraph are
|
kpeter@474
|
2700 |
/// convertible to each other, moreover the \c Arc type of the adaptor
|
kpeter@474
|
2701 |
/// is convertible to the \c Arc type of the adapted digraph.
|
kpeter@474
|
2702 |
#ifdef DOXYGEN
|
deba@559
|
2703 |
template<typename DGR, typename CM, typename FM, typename TL>
|
kpeter@487
|
2704 |
class ResidualDigraph
|
kpeter@474
|
2705 |
#else
|
deba@559
|
2706 |
template<typename DGR,
|
deba@559
|
2707 |
typename CM = typename DGR::template ArcMap<int>,
|
kpeter@476
|
2708 |
typename FM = CM,
|
kpeter@476
|
2709 |
typename TL = Tolerance<typename CM::Value> >
|
deba@559
|
2710 |
class ResidualDigraph
|
deba@559
|
2711 |
: public SubDigraph<
|
deba@559
|
2712 |
Undirector<const DGR>,
|
deba@559
|
2713 |
ConstMap<typename DGR::Node, Const<bool, true> >,
|
deba@559
|
2714 |
typename Undirector<const DGR>::template CombinedArcMap<
|
deba@559
|
2715 |
_adaptor_bits::ResForwardFilter<const DGR, CM, FM, TL>,
|
deba@559
|
2716 |
_adaptor_bits::ResBackwardFilter<const DGR, CM, FM, TL> > >
|
kpeter@474
|
2717 |
#endif
|
deba@432
|
2718 |
{
|
deba@430
|
2719 |
public:
|
deba@430
|
2720 |
|
kpeter@474
|
2721 |
/// The type of the underlying digraph.
|
deba@559
|
2722 |
typedef DGR Digraph;
|
kpeter@474
|
2723 |
/// The type of the capacity map.
|
kpeter@476
|
2724 |
typedef CM CapacityMap;
|
kpeter@474
|
2725 |
/// The type of the flow map.
|
kpeter@476
|
2726 |
typedef FM FlowMap;
|
kpeter@476
|
2727 |
/// The tolerance type.
|
kpeter@476
|
2728 |
typedef TL Tolerance;
|
deba@430
|
2729 |
|
deba@430
|
2730 |
typedef typename CapacityMap::Value Value;
|
kpeter@487
|
2731 |
typedef ResidualDigraph Adaptor;
|
deba@430
|
2732 |
|
deba@430
|
2733 |
protected:
|
deba@430
|
2734 |
|
deba@432
|
2735 |
typedef Undirector<const Digraph> Undirected;
|
deba@432
|
2736 |
|
deba@559
|
2737 |
typedef ConstMap<typename DGR::Node, Const<bool, true> > NodeFilter;
|
deba@559
|
2738 |
|
deba@559
|
2739 |
typedef _adaptor_bits::ResForwardFilter<const DGR, CM,
|
deba@559
|
2740 |
FM, TL> ForwardFilter;
|
deba@559
|
2741 |
|
deba@559
|
2742 |
typedef _adaptor_bits::ResBackwardFilter<const DGR, CM,
|
deba@559
|
2743 |
FM, TL> BackwardFilter;
|
deba@432
|
2744 |
|
deba@432
|
2745 |
typedef typename Undirected::
|
kpeter@476
|
2746 |
template CombinedArcMap<ForwardFilter, BackwardFilter> ArcFilter;
|
deba@430
|
2747 |
|
deba@559
|
2748 |
typedef SubDigraph<Undirected, NodeFilter, ArcFilter> Parent;
|
deba@430
|
2749 |
|
deba@430
|
2750 |
const CapacityMap* _capacity;
|
deba@430
|
2751 |
FlowMap* _flow;
|
deba@430
|
2752 |
|
deba@432
|
2753 |
Undirected _graph;
|
deba@559
|
2754 |
NodeFilter _node_filter;
|
deba@430
|
2755 |
ForwardFilter _forward_filter;
|
deba@430
|
2756 |
BackwardFilter _backward_filter;
|
deba@430
|
2757 |
ArcFilter _arc_filter;
|
deba@430
|
2758 |
|
deba@430
|
2759 |
public:
|
deba@430
|
2760 |
|
kpeter@474
|
2761 |
/// \brief Constructor
|
deba@430
|
2762 |
///
|
kpeter@474
|
2763 |
/// Constructor of the residual digraph adaptor. The parameters are the
|
kpeter@474
|
2764 |
/// digraph, the capacity map, the flow map, and a tolerance object.
|
deba@559
|
2765 |
ResidualDigraph(const DGR& digraph, const CM& capacity,
|
deba@559
|
2766 |
FM& flow, const TL& tolerance = Tolerance())
|
deba@559
|
2767 |
: Parent(), _capacity(&capacity), _flow(&flow),
|
deba@559
|
2768 |
_graph(digraph), _node_filter(),
|
deba@432
|
2769 |
_forward_filter(capacity, flow, tolerance),
|
deba@430
|
2770 |
_backward_filter(capacity, flow, tolerance),
|
deba@430
|
2771 |
_arc_filter(_forward_filter, _backward_filter)
|
deba@430
|
2772 |
{
|
deba@559
|
2773 |
Parent::initialize(_graph, _node_filter, _arc_filter);
|
deba@430
|
2774 |
}
|
deba@430
|
2775 |
|
deba@430
|
2776 |
typedef typename Parent::Arc Arc;
|
deba@430
|
2777 |
|
kpeter@474
|
2778 |
/// \brief Returns the residual capacity of the given arc.
|
deba@430
|
2779 |
///
|
kpeter@474
|
2780 |
/// Returns the residual capacity of the given arc.
|
deba@432
|
2781 |
Value residualCapacity(const Arc& a) const {
|
deba@432
|
2782 |
if (Undirected::direction(a)) {
|
deba@432
|
2783 |
return (*_capacity)[a] - (*_flow)[a];
|
deba@430
|
2784 |
} else {
|
deba@432
|
2785 |
return (*_flow)[a];
|
deba@430
|
2786 |
}
|
deba@432
|
2787 |
}
|
deba@432
|
2788 |
|
kpeter@475
|
2789 |
/// \brief Augments on the given arc in the residual digraph.
|
deba@430
|
2790 |
///
|
kpeter@475
|
2791 |
/// Augments on the given arc in the residual digraph. It increases
|
kpeter@474
|
2792 |
/// or decreases the flow value on the original arc according to the
|
kpeter@474
|
2793 |
/// direction of the residual arc.
|
deba@432
|
2794 |
void augment(const Arc& a, const Value& v) const {
|
deba@432
|
2795 |
if (Undirected::direction(a)) {
|
deba@432
|
2796 |
_flow->set(a, (*_flow)[a] + v);
|
deba@432
|
2797 |
} else {
|
deba@432
|
2798 |
_flow->set(a, (*_flow)[a] - v);
|
deba@430
|
2799 |
}
|
deba@430
|
2800 |
}
|
deba@430
|
2801 |
|
kpeter@474
|
2802 |
/// \brief Returns \c true if the given residual arc is a forward arc.
|
deba@430
|
2803 |
///
|
kpeter@474
|
2804 |
/// Returns \c true if the given residual arc has the same orientation
|
kpeter@474
|
2805 |
/// as the original arc, i.e. it is a so called forward arc.
|
deba@432
|
2806 |
static bool forward(const Arc& a) {
|
deba@432
|
2807 |
return Undirected::direction(a);
|
deba@430
|
2808 |
}
|
deba@430
|
2809 |
|
kpeter@474
|
2810 |
/// \brief Returns \c true if the given residual arc is a backward arc.
|
deba@430
|
2811 |
///
|
kpeter@474
|
2812 |
/// Returns \c true if the given residual arc has the opposite orientation
|
kpeter@474
|
2813 |
/// than the original arc, i.e. it is a so called backward arc.
|
deba@432
|
2814 |
static bool backward(const Arc& a) {
|
deba@432
|
2815 |
return !Undirected::direction(a);
|
deba@430
|
2816 |
}
|
deba@430
|
2817 |
|
kpeter@474
|
2818 |
/// \brief Returns the forward oriented residual arc.
|
deba@430
|
2819 |
///
|
kpeter@474
|
2820 |
/// Returns the forward oriented residual arc related to the given
|
kpeter@474
|
2821 |
/// arc of the underlying digraph.
|
deba@432
|
2822 |
static Arc forward(const typename Digraph::Arc& a) {
|
deba@432
|
2823 |
return Undirected::direct(a, true);
|
deba@430
|
2824 |
}
|
deba@430
|
2825 |
|
kpeter@474
|
2826 |
/// \brief Returns the backward oriented residual arc.
|
deba@430
|
2827 |
///
|
kpeter@474
|
2828 |
/// Returns the backward oriented residual arc related to the given
|
kpeter@474
|
2829 |
/// arc of the underlying digraph.
|
deba@432
|
2830 |
static Arc backward(const typename Digraph::Arc& a) {
|
deba@432
|
2831 |
return Undirected::direct(a, false);
|
deba@430
|
2832 |
}
|
deba@430
|
2833 |
|
deba@430
|
2834 |
/// \brief Residual capacity map.
|
deba@430
|
2835 |
///
|
kpeter@474
|
2836 |
/// This map adaptor class can be used for obtaining the residual
|
kpeter@474
|
2837 |
/// capacities as an arc map of the residual digraph.
|
kpeter@474
|
2838 |
/// Its value type is inherited from the capacity map.
|
deba@432
|
2839 |
class ResidualCapacity {
|
deba@430
|
2840 |
protected:
|
deba@430
|
2841 |
const Adaptor* _adaptor;
|
deba@430
|
2842 |
public:
|
kpeter@474
|
2843 |
/// The key type of the map
|
deba@430
|
2844 |
typedef Arc Key;
|
kpeter@474
|
2845 |
/// The value type of the map
|
kpeter@476
|
2846 |
typedef typename CapacityMap::Value Value;
|
deba@430
|
2847 |
|
deba@432
|
2848 |
/// Constructor
|
deba@559
|
2849 |
ResidualCapacity(const ResidualDigraph<DGR, CM, FM, TL>& adaptor)
|
deba@559
|
2850 |
: _adaptor(&adaptor) {}
|
deba@432
|
2851 |
|
kpeter@474
|
2852 |
/// Returns the value associated with the given residual arc
|
deba@432
|
2853 |
Value operator[](const Arc& a) const {
|
deba@432
|
2854 |
return _adaptor->residualCapacity(a);
|
deba@430
|
2855 |
}
|
deba@432
|
2856 |
|
deba@430
|
2857 |
};
|
deba@430
|
2858 |
|
kpeter@473
|
2859 |
/// \brief Returns a residual capacity map
|
kpeter@473
|
2860 |
///
|
kpeter@473
|
2861 |
/// This function just returns a residual capacity map.
|
kpeter@473
|
2862 |
ResidualCapacity residualCapacity() const {
|
kpeter@473
|
2863 |
return ResidualCapacity(*this);
|
kpeter@473
|
2864 |
}
|
kpeter@473
|
2865 |
|
deba@430
|
2866 |
};
|
deba@430
|
2867 |
|
kpeter@473
|
2868 |
/// \brief Returns a (read-only) Residual adaptor
|
kpeter@473
|
2869 |
///
|
deba@559
|
2870 |
/// This function just returns a (read-only) \ref ResidualDigraph adaptor.
|
kpeter@473
|
2871 |
/// \ingroup graph_adaptors
|
deba@559
|
2872 |
/// \relates ResidualDigraph
|
deba@559
|
2873 |
template<typename DGR, typename CM, typename FM>
|
deba@559
|
2874 |
ResidualDigraph<DGR, CM, FM>
|
deba@559
|
2875 |
residualDigraph(const DGR& digraph, const CM& capacity_map, FM& flow_map) {
|
deba@559
|
2876 |
return ResidualDigraph<DGR, CM, FM> (digraph, capacity_map, flow_map);
|
kpeter@473
|
2877 |
}
|
kpeter@473
|
2878 |
|
kpeter@473
|
2879 |
|
deba@559
|
2880 |
template <typename DGR>
|
deba@432
|
2881 |
class SplitNodesBase {
|
kpeter@664
|
2882 |
typedef DigraphAdaptorBase<const DGR> Parent;
|
kpeter@664
|
2883 |
|
deba@430
|
2884 |
public:
|
deba@430
|
2885 |
|
deba@559
|
2886 |
typedef DGR Digraph;
|
deba@432
|
2887 |
typedef SplitNodesBase Adaptor;
|
deba@430
|
2888 |
|
deba@559
|
2889 |
typedef typename DGR::Node DigraphNode;
|
deba@559
|
2890 |
typedef typename DGR::Arc DigraphArc;
|
deba@430
|
2891 |
|
deba@430
|
2892 |
class Node;
|
deba@430
|
2893 |
class Arc;
|
deba@430
|
2894 |
|
deba@430
|
2895 |
private:
|
deba@430
|
2896 |
|
deba@430
|
2897 |
template <typename T> class NodeMapBase;
|
deba@430
|
2898 |
template <typename T> class ArcMapBase;
|
deba@430
|
2899 |
|
deba@430
|
2900 |
public:
|
deba@432
|
2901 |
|
deba@430
|
2902 |
class Node : public DigraphNode {
|
deba@432
|
2903 |
friend class SplitNodesBase;
|
deba@430
|
2904 |
template <typename T> friend class NodeMapBase;
|
deba@430
|
2905 |
private:
|
deba@430
|
2906 |
|
deba@430
|
2907 |
bool _in;
|
deba@430
|
2908 |
Node(DigraphNode node, bool in)
|
deba@432
|
2909 |
: DigraphNode(node), _in(in) {}
|
deba@432
|
2910 |
|
deba@430
|
2911 |
public:
|
deba@430
|
2912 |
|
deba@430
|
2913 |
Node() {}
|
deba@430
|
2914 |
Node(Invalid) : DigraphNode(INVALID), _in(true) {}
|
deba@430
|
2915 |
|
deba@430
|
2916 |
bool operator==(const Node& node) const {
|
deba@432
|
2917 |
return DigraphNode::operator==(node) && _in == node._in;
|
deba@430
|
2918 |
}
|
deba@432
|
2919 |
|
deba@430
|
2920 |
bool operator!=(const Node& node) const {
|
deba@432
|
2921 |
return !(*this == node);
|
deba@430
|
2922 |
}
|
deba@432
|
2923 |
|
deba@430
|
2924 |
bool operator<(const Node& node) const {
|
deba@432
|
2925 |
return DigraphNode::operator<(node) ||
|
deba@432
|
2926 |
(DigraphNode::operator==(node) && _in < node._in);
|
deba@430
|
2927 |
}
|
deba@430
|
2928 |
};
|
deba@430
|
2929 |
|
deba@430
|
2930 |
class Arc {
|
deba@432
|
2931 |
friend class SplitNodesBase;
|
deba@430
|
2932 |
template <typename T> friend class ArcMapBase;
|
deba@430
|
2933 |
private:
|
deba@430
|
2934 |
typedef BiVariant<DigraphArc, DigraphNode> ArcImpl;
|
deba@430
|
2935 |
|
deba@430
|
2936 |
explicit Arc(const DigraphArc& arc) : _item(arc) {}
|
deba@430
|
2937 |
explicit Arc(const DigraphNode& node) : _item(node) {}
|
deba@432
|
2938 |
|
deba@430
|
2939 |
ArcImpl _item;
|
deba@430
|
2940 |
|
deba@430
|
2941 |
public:
|
deba@430
|
2942 |
Arc() {}
|
deba@430
|
2943 |
Arc(Invalid) : _item(DigraphArc(INVALID)) {}
|
deba@430
|
2944 |
|
deba@430
|
2945 |
bool operator==(const Arc& arc) const {
|
deba@430
|
2946 |
if (_item.firstState()) {
|
deba@430
|
2947 |
if (arc._item.firstState()) {
|
deba@430
|
2948 |
return _item.first() == arc._item.first();
|
deba@430
|
2949 |
}
|
deba@430
|
2950 |
} else {
|
deba@430
|
2951 |
if (arc._item.secondState()) {
|
deba@430
|
2952 |
return _item.second() == arc._item.second();
|
deba@430
|
2953 |
}
|
deba@430
|
2954 |
}
|
deba@430
|
2955 |
return false;
|
deba@430
|
2956 |
}
|
deba@432
|
2957 |
|
deba@430
|
2958 |
bool operator!=(const Arc& arc) const {
|
deba@432
|
2959 |
return !(*this == arc);
|
deba@430
|
2960 |
}
|
deba@432
|
2961 |
|
deba@430
|
2962 |
bool operator<(const Arc& arc) const {
|
deba@430
|
2963 |
if (_item.firstState()) {
|
deba@430
|
2964 |
if (arc._item.firstState()) {
|
deba@430
|
2965 |
return _item.first() < arc._item.first();
|
deba@430
|
2966 |
}
|
deba@430
|
2967 |
return false;
|
deba@430
|
2968 |
} else {
|
deba@430
|
2969 |
if (arc._item.secondState()) {
|
deba@430
|
2970 |
return _item.second() < arc._item.second();
|
deba@430
|
2971 |
}
|
deba@430
|
2972 |
return true;
|
deba@430
|
2973 |
}
|
deba@430
|
2974 |
}
|
deba@430
|
2975 |
|
deba@430
|
2976 |
operator DigraphArc() const { return _item.first(); }
|
deba@430
|
2977 |
operator DigraphNode() const { return _item.second(); }
|
deba@430
|
2978 |
|
deba@430
|
2979 |
};
|
deba@430
|
2980 |
|
deba@430
|
2981 |
void first(Node& n) const {
|
deba@430
|
2982 |
_digraph->first(n);
|
deba@430
|
2983 |
n._in = true;
|
deba@430
|
2984 |
}
|
deba@430
|
2985 |
|
deba@430
|
2986 |
void next(Node& n) const {
|
deba@430
|
2987 |
if (n._in) {
|
deba@432
|
2988 |
n._in = false;
|
deba@430
|
2989 |
} else {
|
deba@432
|
2990 |
n._in = true;
|
deba@432
|
2991 |
_digraph->next(n);
|
deba@430
|
2992 |
}
|
deba@430
|
2993 |
}
|
deba@430
|
2994 |
|
deba@430
|
2995 |
void first(Arc& e) const {
|
deba@430
|
2996 |
e._item.setSecond();
|
deba@430
|
2997 |
_digraph->first(e._item.second());
|
deba@430
|
2998 |
if (e._item.second() == INVALID) {
|
deba@430
|
2999 |
e._item.setFirst();
|
deba@432
|
3000 |
_digraph->first(e._item.first());
|
deba@430
|
3001 |
}
|
deba@430
|
3002 |
}
|
deba@430
|
3003 |
|
deba@430
|
3004 |
void next(Arc& e) const {
|
deba@430
|
3005 |
if (e._item.secondState()) {
|
deba@432
|
3006 |
_digraph->next(e._item.second());
|
deba@430
|
3007 |
if (e._item.second() == INVALID) {
|
deba@430
|
3008 |
e._item.setFirst();
|
deba@430
|
3009 |
_digraph->first(e._item.first());
|
deba@430
|
3010 |
}
|
deba@430
|
3011 |
} else {
|
deba@432
|
3012 |
_digraph->next(e._item.first());
|
deba@432
|
3013 |
}
|
deba@430
|
3014 |
}
|
deba@430
|
3015 |
|
deba@430
|
3016 |
void firstOut(Arc& e, const Node& n) const {
|
deba@430
|
3017 |
if (n._in) {
|
deba@430
|
3018 |
e._item.setSecond(n);
|
deba@430
|
3019 |
} else {
|
deba@430
|
3020 |
e._item.setFirst();
|
deba@432
|
3021 |
_digraph->firstOut(e._item.first(), n);
|
deba@430
|
3022 |
}
|
deba@430
|
3023 |
}
|
deba@430
|
3024 |
|
deba@430
|
3025 |
void nextOut(Arc& e) const {
|
deba@430
|
3026 |
if (!e._item.firstState()) {
|
deba@432
|
3027 |
e._item.setFirst(INVALID);
|
deba@430
|
3028 |
} else {
|
deba@432
|
3029 |
_digraph->nextOut(e._item.first());
|
deba@432
|
3030 |
}
|
deba@430
|
3031 |
}
|
deba@430
|
3032 |
|
deba@430
|
3033 |
void firstIn(Arc& e, const Node& n) const {
|
deba@430
|
3034 |
if (!n._in) {
|
deba@432
|
3035 |
e._item.setSecond(n);
|
deba@430
|
3036 |
} else {
|
deba@430
|
3037 |
e._item.setFirst();
|
deba@432
|
3038 |
_digraph->firstIn(e._item.first(), n);
|
deba@430
|
3039 |
}
|
deba@430
|
3040 |
}
|
deba@430
|
3041 |
|
deba@430
|
3042 |
void nextIn(Arc& e) const {
|
deba@430
|
3043 |
if (!e._item.firstState()) {
|
deba@432
|
3044 |
e._item.setFirst(INVALID);
|
deba@430
|
3045 |
} else {
|
deba@432
|
3046 |
_digraph->nextIn(e._item.first());
|
deba@430
|
3047 |
}
|
deba@430
|
3048 |
}
|
deba@430
|
3049 |
|
deba@430
|
3050 |
Node source(const Arc& e) const {
|
deba@430
|
3051 |
if (e._item.firstState()) {
|
deba@432
|
3052 |
return Node(_digraph->source(e._item.first()), false);
|
deba@430
|
3053 |
} else {
|
deba@432
|
3054 |
return Node(e._item.second(), true);
|
deba@430
|
3055 |
}
|
deba@430
|
3056 |
}
|
deba@430
|
3057 |
|
deba@430
|
3058 |
Node target(const Arc& e) const {
|
deba@430
|
3059 |
if (e._item.firstState()) {
|
deba@432
|
3060 |
return Node(_digraph->target(e._item.first()), true);
|
deba@430
|
3061 |
} else {
|
deba@432
|
3062 |
return Node(e._item.second(), false);
|
deba@430
|
3063 |
}
|
deba@430
|
3064 |
}
|
deba@430
|
3065 |
|
deba@430
|
3066 |
int id(const Node& n) const {
|
deba@430
|
3067 |
return (_digraph->id(n) << 1) | (n._in ? 0 : 1);
|
deba@430
|
3068 |
}
|
deba@430
|
3069 |
Node nodeFromId(int ix) const {
|
deba@430
|
3070 |
return Node(_digraph->nodeFromId(ix >> 1), (ix & 1) == 0);
|
deba@430
|
3071 |
}
|
deba@430
|
3072 |
int maxNodeId() const {
|
deba@430
|
3073 |
return 2 * _digraph->maxNodeId() + 1;
|
deba@430
|
3074 |
}
|
deba@430
|
3075 |
|
deba@430
|
3076 |
int id(const Arc& e) const {
|
deba@430
|
3077 |
if (e._item.firstState()) {
|
deba@430
|
3078 |
return _digraph->id(e._item.first()) << 1;
|
deba@430
|
3079 |
} else {
|
deba@430
|
3080 |
return (_digraph->id(e._item.second()) << 1) | 1;
|
deba@430
|
3081 |
}
|
deba@430
|
3082 |
}
|
deba@430
|
3083 |
Arc arcFromId(int ix) const {
|
deba@430
|
3084 |
if ((ix & 1) == 0) {
|
deba@430
|
3085 |
return Arc(_digraph->arcFromId(ix >> 1));
|
deba@430
|
3086 |
} else {
|
deba@430
|
3087 |
return Arc(_digraph->nodeFromId(ix >> 1));
|
deba@430
|
3088 |
}
|
deba@430
|
3089 |
}
|
deba@430
|
3090 |
int maxArcId() const {
|
deba@432
|
3091 |
return std::max(_digraph->maxNodeId() << 1,
|
deba@430
|
3092 |
(_digraph->maxArcId() << 1) | 1);
|
deba@430
|
3093 |
}
|
deba@430
|
3094 |
|
deba@430
|
3095 |
static bool inNode(const Node& n) {
|
deba@430
|
3096 |
return n._in;
|
deba@430
|
3097 |
}
|
deba@430
|
3098 |
|
deba@430
|
3099 |
static bool outNode(const Node& n) {
|
deba@430
|
3100 |
return !n._in;
|
deba@430
|
3101 |
}
|
deba@430
|
3102 |
|
deba@430
|
3103 |
static bool origArc(const Arc& e) {
|
deba@430
|
3104 |
return e._item.firstState();
|
deba@430
|
3105 |
}
|
deba@430
|
3106 |
|
deba@430
|
3107 |
static bool bindArc(const Arc& e) {
|
deba@430
|
3108 |
return e._item.secondState();
|
deba@430
|
3109 |
}
|
deba@430
|
3110 |
|
deba@430
|
3111 |
static Node inNode(const DigraphNode& n) {
|
deba@430
|
3112 |
return Node(n, true);
|
deba@430
|
3113 |
}
|
deba@430
|
3114 |
|
deba@430
|
3115 |
static Node outNode(const DigraphNode& n) {
|
deba@430
|
3116 |
return Node(n, false);
|
deba@430
|
3117 |
}
|
deba@430
|
3118 |
|
deba@430
|
3119 |
static Arc arc(const DigraphNode& n) {
|
deba@430
|
3120 |
return Arc(n);
|
deba@430
|
3121 |
}
|
deba@430
|
3122 |
|
deba@430
|
3123 |
static Arc arc(const DigraphArc& e) {
|
deba@430
|
3124 |
return Arc(e);
|
deba@430
|
3125 |
}
|
deba@430
|
3126 |
|
deba@430
|
3127 |
typedef True NodeNumTag;
|
deba@430
|
3128 |
int nodeNum() const {
|
deba@430
|
3129 |
return 2 * countNodes(*_digraph);
|
deba@430
|
3130 |
}
|
deba@430
|
3131 |
|
kpeter@469
|
3132 |
typedef True ArcNumTag;
|
deba@430
|
3133 |
int arcNum() const {
|
deba@430
|
3134 |
return countArcs(*_digraph) + countNodes(*_digraph);
|
deba@430
|
3135 |
}
|
deba@430
|
3136 |
|
kpeter@469
|
3137 |
typedef True FindArcTag;
|
deba@432
|
3138 |
Arc findArc(const Node& u, const Node& v,
|
deba@432
|
3139 |
const Arc& prev = INVALID) const {
|
kpeter@472
|
3140 |
if (inNode(u) && outNode(v)) {
|
kpeter@472
|
3141 |
if (static_cast<const DigraphNode&>(u) ==
|
kpeter@472
|
3142 |
static_cast<const DigraphNode&>(v) && prev == INVALID) {
|
kpeter@472
|
3143 |
return Arc(u);
|
deba@430
|
3144 |
}
|
kpeter@472
|
3145 |
}
|
kpeter@472
|
3146 |
else if (outNode(u) && inNode(v)) {
|
kpeter@472
|
3147 |
return Arc(::lemon::findArc(*_digraph, u, v, prev));
|
deba@430
|
3148 |
}
|
deba@430
|
3149 |
return INVALID;
|
deba@430
|
3150 |
}
|
deba@430
|
3151 |
|
deba@430
|
3152 |
private:
|
deba@432
|
3153 |
|
deba@559
|
3154 |
template <typename V>
|
deba@432
|
3155 |
class NodeMapBase
|
deba@559
|
3156 |
: public MapTraits<typename Parent::template NodeMap<V> > {
|
deba@559
|
3157 |
typedef typename Parent::template NodeMap<V> NodeImpl;
|
deba@430
|
3158 |
public:
|
deba@430
|
3159 |
typedef Node Key;
|
deba@559
|
3160 |
typedef V Value;
|
kpeter@472
|
3161 |
typedef typename MapTraits<NodeImpl>::ReferenceMapTag ReferenceMapTag;
|
kpeter@472
|
3162 |
typedef typename MapTraits<NodeImpl>::ReturnValue ReturnValue;
|
kpeter@472
|
3163 |
typedef typename MapTraits<NodeImpl>::ConstReturnValue ConstReturnValue;
|
kpeter@472
|
3164 |
typedef typename MapTraits<NodeImpl>::ReturnValue Reference;
|
kpeter@472
|
3165 |
typedef typename MapTraits<NodeImpl>::ConstReturnValue ConstReference;
|
deba@432
|
3166 |
|
deba@559
|
3167 |
NodeMapBase(const SplitNodesBase<DGR>& adaptor)
|
deba@432
|
3168 |
: _in_map(*adaptor._digraph), _out_map(*adaptor._digraph) {}
|
deba@559
|
3169 |
NodeMapBase(const SplitNodesBase<DGR>& adaptor, const V& value)
|
deba@432
|
3170 |
: _in_map(*adaptor._digraph, value),
|
deba@432
|
3171 |
_out_map(*adaptor._digraph, value) {}
|
deba@430
|
3172 |
|
deba@559
|
3173 |
void set(const Node& key, const V& val) {
|
deba@559
|
3174 |
if (SplitNodesBase<DGR>::inNode(key)) { _in_map.set(key, val); }
|
deba@432
|
3175 |
else {_out_map.set(key, val); }
|
deba@430
|
3176 |
}
|
deba@432
|
3177 |
|
kpeter@472
|
3178 |
ReturnValue operator[](const Node& key) {
|
deba@559
|
3179 |
if (SplitNodesBase<DGR>::inNode(key)) { return _in_map[key]; }
|
deba@432
|
3180 |
else { return _out_map[key]; }
|
deba@430
|
3181 |
}
|
deba@430
|
3182 |
|
kpeter@472
|
3183 |
ConstReturnValue operator[](const Node& key) const {
|
deba@432
|
3184 |
if (Adaptor::inNode(key)) { return _in_map[key]; }
|
deba@432
|
3185 |
else { return _out_map[key]; }
|
deba@430
|
3186 |
}
|
deba@430
|
3187 |
|
deba@430
|
3188 |
private:
|
deba@430
|
3189 |
NodeImpl _in_map, _out_map;
|
deba@430
|
3190 |
};
|
deba@430
|
3191 |
|
deba@559
|
3192 |
template <typename V>
|
deba@432
|
3193 |
class ArcMapBase
|
deba@559
|
3194 |
: public MapTraits<typename Parent::template ArcMap<V> > {
|
deba@559
|
3195 |
typedef typename Parent::template ArcMap<V> ArcImpl;
|
deba@559
|
3196 |
typedef typename Parent::template NodeMap<V> NodeImpl;
|
deba@430
|
3197 |
public:
|
deba@430
|
3198 |
typedef Arc Key;
|
deba@559
|
3199 |
typedef V Value;
|
kpeter@472
|
3200 |
typedef typename MapTraits<ArcImpl>::ReferenceMapTag ReferenceMapTag;
|
kpeter@472
|
3201 |
typedef typename MapTraits<ArcImpl>::ReturnValue ReturnValue;
|
kpeter@472
|
3202 |
typedef typename MapTraits<ArcImpl>::ConstReturnValue ConstReturnValue;
|
kpeter@472
|
3203 |
typedef typename MapTraits<ArcImpl>::ReturnValue Reference;
|
kpeter@472
|
3204 |
typedef typename MapTraits<ArcImpl>::ConstReturnValue ConstReference;
|
deba@430
|
3205 |
|
deba@559
|
3206 |
ArcMapBase(const SplitNodesBase<DGR>& adaptor)
|
deba@432
|
3207 |
: _arc_map(*adaptor._digraph), _node_map(*adaptor._digraph) {}
|
deba@559
|
3208 |
ArcMapBase(const SplitNodesBase<DGR>& adaptor, const V& value)
|
deba@432
|
3209 |
: _arc_map(*adaptor._digraph, value),
|
deba@432
|
3210 |
_node_map(*adaptor._digraph, value) {}
|
deba@430
|
3211 |
|
deba@559
|
3212 |
void set(const Arc& key, const V& val) {
|
deba@559
|
3213 |
if (SplitNodesBase<DGR>::origArc(key)) {
|
kpeter@563
|
3214 |
_arc_map.set(static_cast<const DigraphArc&>(key), val);
|
deba@430
|
3215 |
} else {
|
kpeter@563
|
3216 |
_node_map.set(static_cast<const DigraphNode&>(key), val);
|
deba@430
|
3217 |
}
|
deba@430
|
3218 |
}
|
deba@432
|
3219 |
|
kpeter@472
|
3220 |
ReturnValue operator[](const Arc& key) {
|
deba@559
|
3221 |
if (SplitNodesBase<DGR>::origArc(key)) {
|
kpeter@563
|
3222 |
return _arc_map[static_cast<const DigraphArc&>(key)];
|
deba@430
|
3223 |
} else {
|
kpeter@563
|
3224 |
return _node_map[static_cast<const DigraphNode&>(key)];
|
deba@430
|
3225 |
}
|
deba@430
|
3226 |
}
|
deba@430
|
3227 |
|
kpeter@472
|
3228 |
ConstReturnValue operator[](const Arc& key) const {
|
deba@559
|
3229 |
if (SplitNodesBase<DGR>::origArc(key)) {
|
kpeter@563
|
3230 |
return _arc_map[static_cast<const DigraphArc&>(key)];
|
deba@430
|
3231 |
} else {
|
kpeter@563
|
3232 |
return _node_map[static_cast<const DigraphNode&>(key)];
|
deba@430
|
3233 |
}
|
deba@430
|
3234 |
}
|
deba@430
|
3235 |
|
deba@430
|
3236 |
private:
|
deba@430
|
3237 |
ArcImpl _arc_map;
|
deba@430
|
3238 |
NodeImpl _node_map;
|
deba@430
|
3239 |
};
|
deba@430
|
3240 |
|
deba@430
|
3241 |
public:
|
deba@430
|
3242 |
|
deba@559
|
3243 |
template <typename V>
|
deba@432
|
3244 |
class NodeMap
|
kpeter@664
|
3245 |
: public SubMapExtender<SplitNodesBase<DGR>, NodeMapBase<V> > {
|
kpeter@664
|
3246 |
typedef SubMapExtender<SplitNodesBase<DGR>, NodeMapBase<V> > Parent;
|
kpeter@664
|
3247 |
|
deba@430
|
3248 |
public:
|
deba@559
|
3249 |
typedef V Value;
|
deba@559
|
3250 |
|
deba@559
|
3251 |
NodeMap(const SplitNodesBase<DGR>& adaptor)
|
deba@432
|
3252 |
: Parent(adaptor) {}
|
deba@432
|
3253 |
|
deba@559
|
3254 |
NodeMap(const SplitNodesBase<DGR>& adaptor, const V& value)
|
deba@432
|
3255 |
: Parent(adaptor, value) {}
|
deba@432
|
3256 |
|
deba@430
|
3257 |
private:
|
deba@430
|
3258 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@432
|
3259 |
return operator=<NodeMap>(cmap);
|
deba@430
|
3260 |
}
|
deba@432
|
3261 |
|
deba@430
|
3262 |
template <typename CMap>
|
deba@430
|
3263 |
NodeMap& operator=(const CMap& cmap) {
|
deba@430
|
3264 |
Parent::operator=(cmap);
|
deba@432
|
3265 |
return *this;
|
deba@430
|
3266 |
}
|
deba@430
|
3267 |
};
|
deba@430
|
3268 |
|
deba@559
|
3269 |
template <typename V>
|
deba@432
|
3270 |
class ArcMap
|
kpeter@664
|
3271 |
: public SubMapExtender<SplitNodesBase<DGR>, ArcMapBase<V> > {
|
kpeter@664
|
3272 |
typedef SubMapExtender<SplitNodesBase<DGR>, ArcMapBase<V> > Parent;
|
kpeter@664
|
3273 |
|
deba@430
|
3274 |
public:
|
deba@559
|
3275 |
typedef V Value;
|
deba@559
|
3276 |
|
deba@559
|
3277 |
ArcMap(const SplitNodesBase<DGR>& adaptor)
|
deba@432
|
3278 |
: Parent(adaptor) {}
|
deba@432
|
3279 |
|
deba@559
|
3280 |
ArcMap(const SplitNodesBase<DGR>& adaptor, const V& value)
|
deba@432
|
3281 |
: Parent(adaptor, value) {}
|
deba@432
|
3282 |
|
deba@430
|
3283 |
private:
|
deba@430
|
3284 |
ArcMap& operator=(const ArcMap& cmap) {
|
deba@432
|
3285 |
return operator=<ArcMap>(cmap);
|
deba@430
|
3286 |
}
|
deba@432
|
3287 |
|
deba@430
|
3288 |
template <typename CMap>
|
deba@430
|
3289 |
ArcMap& operator=(const CMap& cmap) {
|
deba@430
|
3290 |
Parent::operator=(cmap);
|
deba@432
|
3291 |
return *this;
|
deba@430
|
3292 |
}
|
deba@430
|
3293 |
};
|
deba@430
|
3294 |
|
deba@430
|
3295 |
protected:
|
deba@430
|
3296 |
|
deba@432
|
3297 |
SplitNodesBase() : _digraph(0) {}
|
deba@430
|
3298 |
|
deba@559
|
3299 |
DGR* _digraph;
|
deba@559
|
3300 |
|
deba@559
|
3301 |
void initialize(Digraph& digraph) {
|
deba@430
|
3302 |
_digraph = &digraph;
|
deba@430
|
3303 |
}
|
deba@432
|
3304 |
|
deba@430
|
3305 |
};
|
deba@430
|
3306 |
|
deba@430
|
3307 |
/// \ingroup graph_adaptors
|
deba@430
|
3308 |
///
|
kpeter@474
|
3309 |
/// \brief Adaptor class for splitting the nodes of a digraph.
|
deba@432
|
3310 |
///
|
kpeter@474
|
3311 |
/// SplitNodes adaptor can be used for splitting each node into an
|
kpeter@474
|
3312 |
/// \e in-node and an \e out-node in a digraph. Formaly, the adaptor
|
kpeter@474
|
3313 |
/// replaces each node \f$ u \f$ in the digraph with two nodes,
|
kpeter@474
|
3314 |
/// namely node \f$ u_{in} \f$ and node \f$ u_{out} \f$.
|
kpeter@474
|
3315 |
/// If there is a \f$ (v, u) \f$ arc in the original digraph, then the
|
kpeter@474
|
3316 |
/// new target of the arc will be \f$ u_{in} \f$ and similarly the
|
kpeter@474
|
3317 |
/// source of each original \f$ (u, v) \f$ arc will be \f$ u_{out} \f$.
|
kpeter@474
|
3318 |
/// The adaptor adds an additional \e bind \e arc from \f$ u_{in} \f$
|
kpeter@474
|
3319 |
/// to \f$ u_{out} \f$ for each node \f$ u \f$ of the original digraph.
|
deba@430
|
3320 |
///
|
kpeter@474
|
3321 |
/// The aim of this class is running an algorithm with respect to node
|
kpeter@474
|
3322 |
/// costs or capacities if the algorithm considers only arc costs or
|
kpeter@474
|
3323 |
/// capacities directly.
|
kpeter@474
|
3324 |
/// In this case you can use \c SplitNodes adaptor, and set the node
|
kpeter@474
|
3325 |
/// costs/capacities of the original digraph to the \e bind \e arcs
|
kpeter@474
|
3326 |
/// in the adaptor.
|
deba@430
|
3327 |
///
|
deba@559
|
3328 |
/// \tparam DGR The type of the adapted digraph.
|
kpeter@474
|
3329 |
/// It must conform to the \ref concepts::Digraph "Digraph" concept.
|
kpeter@474
|
3330 |
/// It is implicitly \c const.
|
kpeter@474
|
3331 |
///
|
kpeter@474
|
3332 |
/// \note The \c Node type of this adaptor is converible to the \c Node
|
kpeter@474
|
3333 |
/// type of the adapted digraph.
|
deba@559
|
3334 |
template <typename DGR>
|
kpeter@476
|
3335 |
#ifdef DOXYGEN
|
kpeter@476
|
3336 |
class SplitNodes {
|
kpeter@476
|
3337 |
#else
|
deba@432
|
3338 |
class SplitNodes
|
deba@559
|
3339 |
: public DigraphAdaptorExtender<SplitNodesBase<const DGR> > {
|
kpeter@476
|
3340 |
#endif
|
kpeter@664
|
3341 |
typedef DigraphAdaptorExtender<SplitNodesBase<const DGR> > Parent;
|
kpeter@664
|
3342 |
|
deba@430
|
3343 |
public:
|
deba@559
|
3344 |
typedef DGR Digraph;
|
deba@559
|
3345 |
|
deba@559
|
3346 |
typedef typename DGR::Node DigraphNode;
|
deba@559
|
3347 |
typedef typename DGR::Arc DigraphArc;
|
deba@431
|
3348 |
|
deba@430
|
3349 |
typedef typename Parent::Node Node;
|
deba@430
|
3350 |
typedef typename Parent::Arc Arc;
|
deba@430
|
3351 |
|
kpeter@474
|
3352 |
/// \brief Constructor
|
deba@430
|
3353 |
///
|
deba@430
|
3354 |
/// Constructor of the adaptor.
|
deba@559
|
3355 |
SplitNodes(const DGR& g) {
|
deba@559
|
3356 |
Parent::initialize(g);
|
deba@430
|
3357 |
}
|
deba@430
|
3358 |
|
kpeter@474
|
3359 |
/// \brief Returns \c true if the given node is an in-node.
|
deba@431
|
3360 |
///
|
kpeter@474
|
3361 |
/// Returns \c true if the given node is an in-node.
|
deba@431
|
3362 |
static bool inNode(const Node& n) {
|
deba@431
|
3363 |
return Parent::inNode(n);
|
deba@431
|
3364 |
}
|
deba@431
|
3365 |
|
kpeter@474
|
3366 |
/// \brief Returns \c true if the given node is an out-node.
|
deba@431
|
3367 |
///
|
kpeter@474
|
3368 |
/// Returns \c true if the given node is an out-node.
|
deba@431
|
3369 |
static bool outNode(const Node& n) {
|
deba@431
|
3370 |
return Parent::outNode(n);
|
deba@431
|
3371 |
}
|
deba@431
|
3372 |
|
kpeter@474
|
3373 |
/// \brief Returns \c true if the given arc is an original arc.
|
deba@431
|
3374 |
///
|
kpeter@474
|
3375 |
/// Returns \c true if the given arc is one of the arcs in the
|
kpeter@474
|
3376 |
/// original digraph.
|
deba@431
|
3377 |
static bool origArc(const Arc& a) {
|
deba@431
|
3378 |
return Parent::origArc(a);
|
deba@431
|
3379 |
}
|
deba@431
|
3380 |
|
kpeter@474
|
3381 |
/// \brief Returns \c true if the given arc is a bind arc.
|
deba@431
|
3382 |
///
|
kpeter@474
|
3383 |
/// Returns \c true if the given arc is a bind arc, i.e. it connects
|
kpeter@474
|
3384 |
/// an in-node and an out-node.
|
deba@431
|
3385 |
static bool bindArc(const Arc& a) {
|
deba@431
|
3386 |
return Parent::bindArc(a);
|
deba@431
|
3387 |
}
|
deba@431
|
3388 |
|
kpeter@474
|
3389 |
/// \brief Returns the in-node created from the given original node.
|
deba@431
|
3390 |
///
|
kpeter@474
|
3391 |
/// Returns the in-node created from the given original node.
|
deba@431
|
3392 |
static Node inNode(const DigraphNode& n) {
|
deba@431
|
3393 |
return Parent::inNode(n);
|
deba@431
|
3394 |
}
|
deba@431
|
3395 |
|
kpeter@474
|
3396 |
/// \brief Returns the out-node created from the given original node.
|
deba@431
|
3397 |
///
|
kpeter@474
|
3398 |
/// Returns the out-node created from the given original node.
|
deba@431
|
3399 |
static Node outNode(const DigraphNode& n) {
|
deba@431
|
3400 |
return Parent::outNode(n);
|
deba@431
|
3401 |
}
|
deba@431
|
3402 |
|
kpeter@474
|
3403 |
/// \brief Returns the bind arc that corresponds to the given
|
kpeter@474
|
3404 |
/// original node.
|
deba@432
|
3405 |
///
|
kpeter@474
|
3406 |
/// Returns the bind arc in the adaptor that corresponds to the given
|
kpeter@474
|
3407 |
/// original node, i.e. the arc connecting the in-node and out-node
|
kpeter@474
|
3408 |
/// of \c n.
|
deba@431
|
3409 |
static Arc arc(const DigraphNode& n) {
|
deba@431
|
3410 |
return Parent::arc(n);
|
deba@431
|
3411 |
}
|
deba@431
|
3412 |
|
kpeter@474
|
3413 |
/// \brief Returns the arc that corresponds to the given original arc.
|
deba@432
|
3414 |
///
|
kpeter@474
|
3415 |
/// Returns the arc in the adaptor that corresponds to the given
|
kpeter@474
|
3416 |
/// original arc.
|
deba@431
|
3417 |
static Arc arc(const DigraphArc& a) {
|
deba@431
|
3418 |
return Parent::arc(a);
|
deba@431
|
3419 |
}
|
deba@431
|
3420 |
|
kpeter@474
|
3421 |
/// \brief Node map combined from two original node maps
|
deba@430
|
3422 |
///
|
kpeter@474
|
3423 |
/// This map adaptor class adapts two node maps of the original digraph
|
kpeter@474
|
3424 |
/// to get a node map of the split digraph.
|
kpeter@606
|
3425 |
/// Its value type is inherited from the first node map type (\c IN).
|
kpeter@606
|
3426 |
/// \tparam IN The type of the node map for the in-nodes.
|
kpeter@606
|
3427 |
/// \tparam OUT The type of the node map for the out-nodes.
|
kpeter@606
|
3428 |
template <typename IN, typename OUT>
|
deba@430
|
3429 |
class CombinedNodeMap {
|
deba@430
|
3430 |
public:
|
deba@430
|
3431 |
|
kpeter@474
|
3432 |
/// The key type of the map
|
deba@430
|
3433 |
typedef Node Key;
|
kpeter@474
|
3434 |
/// The value type of the map
|
kpeter@606
|
3435 |
typedef typename IN::Value Value;
|
kpeter@606
|
3436 |
|
kpeter@606
|
3437 |
typedef typename MapTraits<IN>::ReferenceMapTag ReferenceMapTag;
|
kpeter@606
|
3438 |
typedef typename MapTraits<IN>::ReturnValue ReturnValue;
|
kpeter@606
|
3439 |
typedef typename MapTraits<IN>::ConstReturnValue ConstReturnValue;
|
kpeter@606
|
3440 |
typedef typename MapTraits<IN>::ReturnValue Reference;
|
kpeter@606
|
3441 |
typedef typename MapTraits<IN>::ConstReturnValue ConstReference;
|
kpeter@472
|
3442 |
|
kpeter@474
|
3443 |
/// Constructor
|
kpeter@606
|
3444 |
CombinedNodeMap(IN& in_map, OUT& out_map)
|
deba@432
|
3445 |
: _in_map(in_map), _out_map(out_map) {}
|
deba@430
|
3446 |
|
kpeter@474
|
3447 |
/// Returns the value associated with the given key.
|
kpeter@474
|
3448 |
Value operator[](const Key& key) const {
|
deba@559
|
3449 |
if (SplitNodesBase<const DGR>::inNode(key)) {
|
kpeter@474
|
3450 |
return _in_map[key];
|
kpeter@474
|
3451 |
} else {
|
kpeter@474
|
3452 |
return _out_map[key];
|
kpeter@474
|
3453 |
}
|
kpeter@474
|
3454 |
}
|
kpeter@474
|
3455 |
|
kpeter@474
|
3456 |
/// Returns a reference to the value associated with the given key.
|
deba@430
|
3457 |
Value& operator[](const Key& key) {
|
deba@559
|
3458 |
if (SplitNodesBase<const DGR>::inNode(key)) {
|
deba@432
|
3459 |
return _in_map[key];
|
deba@432
|
3460 |
} else {
|
deba@432
|
3461 |
return _out_map[key];
|
deba@432
|
3462 |
}
|
deba@430
|
3463 |
}
|
deba@430
|
3464 |
|
kpeter@474
|
3465 |
/// Sets the value associated with the given key.
|
deba@430
|
3466 |
void set(const Key& key, const Value& value) {
|
deba@559
|
3467 |
if (SplitNodesBase<const DGR>::inNode(key)) {
|
deba@432
|
3468 |
_in_map.set(key, value);
|
deba@432
|
3469 |
} else {
|
deba@432
|
3470 |
_out_map.set(key, value);
|
deba@432
|
3471 |
}
|
deba@430
|
3472 |
}
|
deba@432
|
3473 |
|
deba@430
|
3474 |
private:
|
deba@432
|
3475 |
|
kpeter@606
|
3476 |
IN& _in_map;
|
kpeter@606
|
3477 |
OUT& _out_map;
|
deba@432
|
3478 |
|
deba@430
|
3479 |
};
|
deba@430
|
3480 |
|
deba@430
|
3481 |
|
kpeter@474
|
3482 |
/// \brief Returns a combined node map
|
deba@432
|
3483 |
///
|
kpeter@474
|
3484 |
/// This function just returns a combined node map.
|
kpeter@606
|
3485 |
template <typename IN, typename OUT>
|
kpeter@606
|
3486 |
static CombinedNodeMap<IN, OUT>
|
kpeter@606
|
3487 |
combinedNodeMap(IN& in_map, OUT& out_map) {
|
kpeter@606
|
3488 |
return CombinedNodeMap<IN, OUT>(in_map, out_map);
|
deba@430
|
3489 |
}
|
deba@430
|
3490 |
|
kpeter@606
|
3491 |
template <typename IN, typename OUT>
|
kpeter@606
|
3492 |
static CombinedNodeMap<const IN, OUT>
|
kpeter@606
|
3493 |
combinedNodeMap(const IN& in_map, OUT& out_map) {
|
kpeter@606
|
3494 |
return CombinedNodeMap<const IN, OUT>(in_map, out_map);
|
deba@430
|
3495 |
}
|
deba@430
|
3496 |
|
kpeter@606
|
3497 |
template <typename IN, typename OUT>
|
kpeter@606
|
3498 |
static CombinedNodeMap<IN, const OUT>
|
kpeter@606
|
3499 |
combinedNodeMap(IN& in_map, const OUT& out_map) {
|
kpeter@606
|
3500 |
return CombinedNodeMap<IN, const OUT>(in_map, out_map);
|
deba@430
|
3501 |
}
|
deba@430
|
3502 |
|
kpeter@606
|
3503 |
template <typename IN, typename OUT>
|
kpeter@606
|
3504 |
static CombinedNodeMap<const IN, const OUT>
|
kpeter@606
|
3505 |
combinedNodeMap(const IN& in_map, const OUT& out_map) {
|
kpeter@606
|
3506 |
return CombinedNodeMap<const IN, const OUT>(in_map, out_map);
|
deba@430
|
3507 |
}
|
deba@430
|
3508 |
|
kpeter@474
|
3509 |
/// \brief Arc map combined from an arc map and a node map of the
|
kpeter@474
|
3510 |
/// original digraph.
|
deba@430
|
3511 |
///
|
kpeter@474
|
3512 |
/// This map adaptor class adapts an arc map and a node map of the
|
kpeter@474
|
3513 |
/// original digraph to get an arc map of the split digraph.
|
kpeter@606
|
3514 |
/// Its value type is inherited from the original arc map type (\c AM).
|
kpeter@606
|
3515 |
/// \tparam AM The type of the arc map.
|
kpeter@606
|
3516 |
/// \tparam NM the type of the node map.
|
kpeter@606
|
3517 |
template <typename AM, typename NM>
|
deba@430
|
3518 |
class CombinedArcMap {
|
deba@430
|
3519 |
public:
|
deba@432
|
3520 |
|
kpeter@474
|
3521 |
/// The key type of the map
|
deba@430
|
3522 |
typedef Arc Key;
|
kpeter@474
|
3523 |
/// The value type of the map
|
kpeter@606
|
3524 |
typedef typename AM::Value Value;
|
kpeter@606
|
3525 |
|
kpeter@606
|
3526 |
typedef typename MapTraits<AM>::ReferenceMapTag ReferenceMapTag;
|
kpeter@606
|
3527 |
typedef typename MapTraits<AM>::ReturnValue ReturnValue;
|
kpeter@606
|
3528 |
typedef typename MapTraits<AM>::ConstReturnValue ConstReturnValue;
|
kpeter@606
|
3529 |
typedef typename MapTraits<AM>::ReturnValue Reference;
|
kpeter@606
|
3530 |
typedef typename MapTraits<AM>::ConstReturnValue ConstReference;
|
kpeter@472
|
3531 |
|
kpeter@474
|
3532 |
/// Constructor
|
kpeter@606
|
3533 |
CombinedArcMap(AM& arc_map, NM& node_map)
|
deba@432
|
3534 |
: _arc_map(arc_map), _node_map(node_map) {}
|
deba@430
|
3535 |
|
kpeter@474
|
3536 |
/// Returns the value associated with the given key.
|
kpeter@474
|
3537 |
Value operator[](const Key& arc) const {
|
deba@559
|
3538 |
if (SplitNodesBase<const DGR>::origArc(arc)) {
|
kpeter@474
|
3539 |
return _arc_map[arc];
|
kpeter@474
|
3540 |
} else {
|
kpeter@474
|
3541 |
return _node_map[arc];
|
kpeter@474
|
3542 |
}
|
kpeter@474
|
3543 |
}
|
kpeter@474
|
3544 |
|
kpeter@474
|
3545 |
/// Returns a reference to the value associated with the given key.
|
kpeter@474
|
3546 |
Value& operator[](const Key& arc) {
|
deba@559
|
3547 |
if (SplitNodesBase<const DGR>::origArc(arc)) {
|
kpeter@474
|
3548 |
return _arc_map[arc];
|
kpeter@474
|
3549 |
} else {
|
kpeter@474
|
3550 |
return _node_map[arc];
|
kpeter@474
|
3551 |
}
|
kpeter@474
|
3552 |
}
|
kpeter@474
|
3553 |
|
kpeter@474
|
3554 |
/// Sets the value associated with the given key.
|
deba@430
|
3555 |
void set(const Arc& arc, const Value& val) {
|
deba@559
|
3556 |
if (SplitNodesBase<const DGR>::origArc(arc)) {
|
deba@432
|
3557 |
_arc_map.set(arc, val);
|
deba@432
|
3558 |
} else {
|
deba@432
|
3559 |
_node_map.set(arc, val);
|
deba@432
|
3560 |
}
|
deba@430
|
3561 |
}
|
deba@430
|
3562 |
|
deba@430
|
3563 |
private:
|
kpeter@606
|
3564 |
|
kpeter@606
|
3565 |
AM& _arc_map;
|
kpeter@606
|
3566 |
NM& _node_map;
|
kpeter@606
|
3567 |
|
deba@430
|
3568 |
};
|
deba@432
|
3569 |
|
kpeter@474
|
3570 |
/// \brief Returns a combined arc map
|
deba@432
|
3571 |
///
|
kpeter@474
|
3572 |
/// This function just returns a combined arc map.
|
kpeter@476
|
3573 |
template <typename ArcMap, typename NodeMap>
|
kpeter@476
|
3574 |
static CombinedArcMap<ArcMap, NodeMap>
|
kpeter@476
|
3575 |
combinedArcMap(ArcMap& arc_map, NodeMap& node_map) {
|
kpeter@476
|
3576 |
return CombinedArcMap<ArcMap, NodeMap>(arc_map, node_map);
|
deba@430
|
3577 |
}
|
deba@430
|
3578 |
|
kpeter@476
|
3579 |
template <typename ArcMap, typename NodeMap>
|
kpeter@476
|
3580 |
static CombinedArcMap<const ArcMap, NodeMap>
|
kpeter@476
|
3581 |
combinedArcMap(const ArcMap& arc_map, NodeMap& node_map) {
|
kpeter@476
|
3582 |
return CombinedArcMap<const ArcMap, NodeMap>(arc_map, node_map);
|
deba@430
|
3583 |
}
|
deba@430
|
3584 |
|
kpeter@476
|
3585 |
template <typename ArcMap, typename NodeMap>
|
kpeter@476
|
3586 |
static CombinedArcMap<ArcMap, const NodeMap>
|
kpeter@476
|
3587 |
combinedArcMap(ArcMap& arc_map, const NodeMap& node_map) {
|
kpeter@476
|
3588 |
return CombinedArcMap<ArcMap, const NodeMap>(arc_map, node_map);
|
deba@430
|
3589 |
}
|
deba@430
|
3590 |
|
kpeter@476
|
3591 |
template <typename ArcMap, typename NodeMap>
|
kpeter@476
|
3592 |
static CombinedArcMap<const ArcMap, const NodeMap>
|
kpeter@476
|
3593 |
combinedArcMap(const ArcMap& arc_map, const NodeMap& node_map) {
|
kpeter@476
|
3594 |
return CombinedArcMap<const ArcMap, const NodeMap>(arc_map, node_map);
|
deba@430
|
3595 |
}
|
deba@430
|
3596 |
|
deba@430
|
3597 |
};
|
deba@430
|
3598 |
|
kpeter@474
|
3599 |
/// \brief Returns a (read-only) SplitNodes adaptor
|
deba@430
|
3600 |
///
|
kpeter@474
|
3601 |
/// This function just returns a (read-only) \ref SplitNodes adaptor.
|
kpeter@474
|
3602 |
/// \ingroup graph_adaptors
|
kpeter@474
|
3603 |
/// \relates SplitNodes
|
deba@559
|
3604 |
template<typename DGR>
|
deba@559
|
3605 |
SplitNodes<DGR>
|
deba@559
|
3606 |
splitNodes(const DGR& digraph) {
|
deba@559
|
3607 |
return SplitNodes<DGR>(digraph);
|
deba@430
|
3608 |
}
|
deba@430
|
3609 |
|
deba@559
|
3610 |
#undef LEMON_SCOPE_FIX
|
deba@559
|
3611 |
|
deba@430
|
3612 |
} //namespace lemon
|
deba@430
|
3613 |
|
deba@432
|
3614 |
#endif //LEMON_ADAPTORS_H
|