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