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