0
3
0
... | ... |
@@ -19,245 +19,245 @@ |
19 | 19 |
#ifndef LEMON_BITS_GRAPH_EXTENDER_H |
20 | 20 |
#define LEMON_BITS_GRAPH_EXTENDER_H |
21 | 21 |
|
22 | 22 |
#include <lemon/bits/invalid.h> |
23 | 23 |
#include <lemon/bits/utility.h> |
24 | 24 |
|
25 | 25 |
#include <lemon/bits/map_extender.h> |
26 | 26 |
#include <lemon/bits/default_map.h> |
27 | 27 |
|
28 | 28 |
#include <lemon/concept_check.h> |
29 | 29 |
#include <lemon/concepts/maps.h> |
30 | 30 |
|
31 | 31 |
///\ingroup graphbits |
32 | 32 |
///\file |
33 | 33 |
///\brief Extenders for the digraph types |
34 | 34 |
namespace lemon { |
35 | 35 |
|
36 | 36 |
/// \ingroup graphbits |
37 | 37 |
/// |
38 | 38 |
/// \brief Extender for the Digraphs |
39 | 39 |
template <typename Base> |
40 | 40 |
class DigraphExtender : public Base { |
41 | 41 |
public: |
42 | 42 |
|
43 | 43 |
typedef Base Parent; |
44 | 44 |
typedef DigraphExtender Digraph; |
45 | 45 |
|
46 | 46 |
// Base extensions |
47 | 47 |
|
48 | 48 |
typedef typename Parent::Node Node; |
49 | 49 |
typedef typename Parent::Arc Arc; |
50 | 50 |
|
51 | 51 |
int maxId(Node) const { |
52 | 52 |
return Parent::maxNodeId(); |
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
int maxId(Arc) const { |
56 | 56 |
return Parent::maxArcId(); |
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
Node fromId(int id, Node) const { |
60 | 60 |
return Parent::nodeFromId(id); |
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
Arc fromId(int id, Arc) const { |
64 | 64 |
return Parent::arcFromId(id); |
65 | 65 |
} |
66 | 66 |
|
67 |
Node oppositeNode(const Node &n, const Arc &e) const { |
|
68 |
if (n == Parent::source(e)) |
|
69 |
return Parent::target(e); |
|
70 |
else if(n==Parent::target(e)) |
|
71 |
|
|
67 |
Node oppositeNode(const Node &node, const Arc &arc) const { |
|
68 |
if (node == Parent::source(arc)) |
|
69 |
return Parent::target(arc); |
|
70 |
else if(node == Parent::target(arc)) |
|
71 |
return Parent::source(arc); |
|
72 | 72 |
else |
73 | 73 |
return INVALID; |
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
// Alterable extension |
77 | 77 |
|
78 | 78 |
typedef AlterationNotifier<DigraphExtender, Node> NodeNotifier; |
79 | 79 |
typedef AlterationNotifier<DigraphExtender, Arc> ArcNotifier; |
80 | 80 |
|
81 | 81 |
|
82 | 82 |
protected: |
83 | 83 |
|
84 | 84 |
mutable NodeNotifier node_notifier; |
85 | 85 |
mutable ArcNotifier arc_notifier; |
86 | 86 |
|
87 | 87 |
public: |
88 | 88 |
|
89 | 89 |
NodeNotifier& notifier(Node) const { |
90 | 90 |
return node_notifier; |
91 | 91 |
} |
92 | 92 |
|
93 | 93 |
ArcNotifier& notifier(Arc) const { |
94 | 94 |
return arc_notifier; |
95 | 95 |
} |
96 | 96 |
|
97 | 97 |
class NodeIt : public Node { |
98 |
const Digraph* |
|
98 |
const Digraph* _digraph; |
|
99 | 99 |
public: |
100 | 100 |
|
101 | 101 |
NodeIt() {} |
102 | 102 |
|
103 | 103 |
NodeIt(Invalid i) : Node(i) { } |
104 | 104 |
|
105 |
explicit NodeIt(const Digraph& _digraph) : digraph(&_digraph) { |
|
106 |
_digraph.first(static_cast<Node&>(*this)); |
|
105 |
explicit NodeIt(const Digraph& digraph) : _digraph(&digraph) { |
|
106 |
_digraph->first(static_cast<Node&>(*this)); |
|
107 | 107 |
} |
108 | 108 |
|
109 |
NodeIt(const Digraph& _digraph, const Node& node) |
|
110 |
: Node(node), digraph(&_digraph) {} |
|
109 |
NodeIt(const Digraph& digraph, const Node& node) |
|
110 |
: Node(node), _digraph(&digraph) {} |
|
111 | 111 |
|
112 | 112 |
NodeIt& operator++() { |
113 |
|
|
113 |
_digraph->next(*this); |
|
114 | 114 |
return *this; |
115 | 115 |
} |
116 | 116 |
|
117 | 117 |
}; |
118 | 118 |
|
119 | 119 |
|
120 | 120 |
class ArcIt : public Arc { |
121 |
const Digraph* |
|
121 |
const Digraph* _digraph; |
|
122 | 122 |
public: |
123 | 123 |
|
124 | 124 |
ArcIt() { } |
125 | 125 |
|
126 | 126 |
ArcIt(Invalid i) : Arc(i) { } |
127 | 127 |
|
128 |
explicit ArcIt(const Digraph& _digraph) : digraph(&_digraph) { |
|
129 |
_digraph.first(static_cast<Arc&>(*this)); |
|
128 |
explicit ArcIt(const Digraph& digraph) : _digraph(&digraph) { |
|
129 |
_digraph->first(static_cast<Arc&>(*this)); |
|
130 | 130 |
} |
131 | 131 |
|
132 |
ArcIt(const Digraph& _digraph, const Arc& e) : |
|
133 |
Arc(e), digraph(&_digraph) { } |
|
132 |
ArcIt(const Digraph& digraph, const Arc& arc) : |
|
133 |
Arc(arc), _digraph(&digraph) { } |
|
134 | 134 |
|
135 | 135 |
ArcIt& operator++() { |
136 |
|
|
136 |
_digraph->next(*this); |
|
137 | 137 |
return *this; |
138 | 138 |
} |
139 | 139 |
|
140 | 140 |
}; |
141 | 141 |
|
142 | 142 |
|
143 | 143 |
class OutArcIt : public Arc { |
144 |
const Digraph* |
|
144 |
const Digraph* _digraph; |
|
145 | 145 |
public: |
146 | 146 |
|
147 | 147 |
OutArcIt() { } |
148 | 148 |
|
149 | 149 |
OutArcIt(Invalid i) : Arc(i) { } |
150 | 150 |
|
151 |
OutArcIt(const Digraph& _digraph, const Node& node) |
|
152 |
: digraph(&_digraph) { |
|
153 |
|
|
151 |
OutArcIt(const Digraph& digraph, const Node& node) |
|
152 |
: _digraph(&digraph) { |
|
153 |
_digraph->firstOut(*this, node); |
|
154 | 154 |
} |
155 | 155 |
|
156 |
OutArcIt(const Digraph& _digraph, const Arc& arc) |
|
157 |
: Arc(arc), digraph(&_digraph) {} |
|
156 |
OutArcIt(const Digraph& digraph, const Arc& arc) |
|
157 |
: Arc(arc), _digraph(&digraph) {} |
|
158 | 158 |
|
159 | 159 |
OutArcIt& operator++() { |
160 |
|
|
160 |
_digraph->nextOut(*this); |
|
161 | 161 |
return *this; |
162 | 162 |
} |
163 | 163 |
|
164 | 164 |
}; |
165 | 165 |
|
166 | 166 |
|
167 | 167 |
class InArcIt : public Arc { |
168 |
const Digraph* |
|
168 |
const Digraph* _digraph; |
|
169 | 169 |
public: |
170 | 170 |
|
171 | 171 |
InArcIt() { } |
172 | 172 |
|
173 | 173 |
InArcIt(Invalid i) : Arc(i) { } |
174 | 174 |
|
175 |
InArcIt(const Digraph& _digraph, const Node& node) |
|
176 |
: digraph(&_digraph) { |
|
177 |
|
|
175 |
InArcIt(const Digraph& digraph, const Node& node) |
|
176 |
: _digraph(&digraph) { |
|
177 |
_digraph->firstIn(*this, node); |
|
178 | 178 |
} |
179 | 179 |
|
180 |
InArcIt(const Digraph& _digraph, const Arc& arc) : |
|
181 |
Arc(arc), digraph(&_digraph) {} |
|
180 |
InArcIt(const Digraph& digraph, const Arc& arc) : |
|
181 |
Arc(arc), _digraph(&digraph) {} |
|
182 | 182 |
|
183 | 183 |
InArcIt& operator++() { |
184 |
|
|
184 |
_digraph->nextIn(*this); |
|
185 | 185 |
return *this; |
186 | 186 |
} |
187 | 187 |
|
188 | 188 |
}; |
189 | 189 |
|
190 | 190 |
/// \brief Base node of the iterator |
191 | 191 |
/// |
192 | 192 |
/// Returns the base node (i.e. the source in this case) of the iterator |
193 |
Node baseNode(const OutArcIt &e) const { |
|
194 |
return Parent::source(e); |
|
193 |
Node baseNode(const OutArcIt &arc) const { |
|
194 |
return Parent::source(arc); |
|
195 | 195 |
} |
196 | 196 |
/// \brief Running node of the iterator |
197 | 197 |
/// |
198 | 198 |
/// Returns the running node (i.e. the target in this case) of the |
199 | 199 |
/// iterator |
200 |
Node runningNode(const OutArcIt &e) const { |
|
201 |
return Parent::target(e); |
|
200 |
Node runningNode(const OutArcIt &arc) const { |
|
201 |
return Parent::target(arc); |
|
202 | 202 |
} |
203 | 203 |
|
204 | 204 |
/// \brief Base node of the iterator |
205 | 205 |
/// |
206 | 206 |
/// Returns the base node (i.e. the target in this case) of the iterator |
207 |
Node baseNode(const InArcIt &e) const { |
|
208 |
return Parent::target(e); |
|
207 |
Node baseNode(const InArcIt &arc) const { |
|
208 |
return Parent::target(arc); |
|
209 | 209 |
} |
210 | 210 |
/// \brief Running node of the iterator |
211 | 211 |
/// |
212 | 212 |
/// Returns the running node (i.e. the source in this case) of the |
213 | 213 |
/// iterator |
214 |
Node runningNode(const InArcIt &e) const { |
|
215 |
return Parent::source(e); |
|
214 |
Node runningNode(const InArcIt &arc) const { |
|
215 |
return Parent::source(arc); |
|
216 | 216 |
} |
217 | 217 |
|
218 | 218 |
|
219 | 219 |
template <typename _Value> |
220 | 220 |
class NodeMap |
221 | 221 |
: public MapExtender<DefaultMap<Digraph, Node, _Value> > { |
222 | 222 |
public: |
223 | 223 |
typedef DigraphExtender Digraph; |
224 | 224 |
typedef MapExtender<DefaultMap<Digraph, Node, _Value> > Parent; |
225 | 225 |
|
226 | 226 |
explicit NodeMap(const Digraph& digraph) |
227 | 227 |
: Parent(digraph) {} |
228 | 228 |
NodeMap(const Digraph& digraph, const _Value& value) |
229 | 229 |
: Parent(digraph, value) {} |
230 | 230 |
|
231 | 231 |
NodeMap& operator=(const NodeMap& cmap) { |
232 | 232 |
return operator=<NodeMap>(cmap); |
233 | 233 |
} |
234 | 234 |
|
235 | 235 |
template <typename CMap> |
236 | 236 |
NodeMap& operator=(const CMap& cmap) { |
237 | 237 |
Parent::operator=(cmap); |
238 | 238 |
return *this; |
239 | 239 |
} |
240 | 240 |
|
241 | 241 |
}; |
242 | 242 |
|
243 | 243 |
template <typename _Value> |
244 | 244 |
class ArcMap |
245 | 245 |
: public MapExtender<DefaultMap<Digraph, Arc, _Value> > { |
246 | 246 |
public: |
247 | 247 |
typedef DigraphExtender Digraph; |
248 | 248 |
typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent; |
249 | 249 |
|
250 | 250 |
explicit ArcMap(const Digraph& digraph) |
251 | 251 |
: Parent(digraph) {} |
252 | 252 |
ArcMap(const Digraph& digraph, const _Value& value) |
253 | 253 |
: Parent(digraph, value) {} |
254 | 254 |
|
255 | 255 |
ArcMap& operator=(const ArcMap& cmap) { |
256 | 256 |
return operator=<ArcMap>(cmap); |
257 | 257 |
} |
258 | 258 |
|
259 | 259 |
template <typename CMap> |
260 | 260 |
ArcMap& operator=(const CMap& cmap) { |
261 | 261 |
Parent::operator=(cmap); |
262 | 262 |
return *this; |
263 | 263 |
} |
... | ... |
@@ -279,472 +279,472 @@ |
279 | 279 |
void clear() { |
280 | 280 |
notifier(Arc()).clear(); |
281 | 281 |
notifier(Node()).clear(); |
282 | 282 |
Parent::clear(); |
283 | 283 |
} |
284 | 284 |
|
285 | 285 |
template <typename Digraph, typename NodeRefMap, typename ArcRefMap> |
286 | 286 |
void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) { |
287 | 287 |
Parent::build(digraph, nodeRef, arcRef); |
288 | 288 |
notifier(Node()).build(); |
289 | 289 |
notifier(Arc()).build(); |
290 | 290 |
} |
291 | 291 |
|
292 | 292 |
void erase(const Node& node) { |
293 | 293 |
Arc arc; |
294 | 294 |
Parent::firstOut(arc, node); |
295 | 295 |
while (arc != INVALID ) { |
296 | 296 |
erase(arc); |
297 | 297 |
Parent::firstOut(arc, node); |
298 | 298 |
} |
299 | 299 |
|
300 | 300 |
Parent::firstIn(arc, node); |
301 | 301 |
while (arc != INVALID ) { |
302 | 302 |
erase(arc); |
303 | 303 |
Parent::firstIn(arc, node); |
304 | 304 |
} |
305 | 305 |
|
306 | 306 |
notifier(Node()).erase(node); |
307 | 307 |
Parent::erase(node); |
308 | 308 |
} |
309 | 309 |
|
310 | 310 |
void erase(const Arc& arc) { |
311 | 311 |
notifier(Arc()).erase(arc); |
312 | 312 |
Parent::erase(arc); |
313 | 313 |
} |
314 | 314 |
|
315 | 315 |
DigraphExtender() { |
316 | 316 |
node_notifier.setContainer(*this); |
317 | 317 |
arc_notifier.setContainer(*this); |
318 | 318 |
} |
319 | 319 |
|
320 | 320 |
|
321 | 321 |
~DigraphExtender() { |
322 | 322 |
arc_notifier.clear(); |
323 | 323 |
node_notifier.clear(); |
324 | 324 |
} |
325 | 325 |
}; |
326 | 326 |
|
327 |
/// \ingroup |
|
327 |
/// \ingroup _graphbits |
|
328 | 328 |
/// |
329 | 329 |
/// \brief Extender for the Graphs |
330 | 330 |
template <typename Base> |
331 | 331 |
class GraphExtender : public Base { |
332 | 332 |
public: |
333 | 333 |
|
334 | 334 |
typedef Base Parent; |
335 |
typedef GraphExtender |
|
335 |
typedef GraphExtender Graph; |
|
336 | 336 |
|
337 | 337 |
typedef True UndirectedTag; |
338 | 338 |
|
339 | 339 |
typedef typename Parent::Node Node; |
340 | 340 |
typedef typename Parent::Arc Arc; |
341 | 341 |
typedef typename Parent::Edge Edge; |
342 | 342 |
|
343 | 343 |
// Graph extension |
344 | 344 |
|
345 | 345 |
int maxId(Node) const { |
346 | 346 |
return Parent::maxNodeId(); |
347 | 347 |
} |
348 | 348 |
|
349 | 349 |
int maxId(Arc) const { |
350 | 350 |
return Parent::maxArcId(); |
351 | 351 |
} |
352 | 352 |
|
353 | 353 |
int maxId(Edge) const { |
354 | 354 |
return Parent::maxEdgeId(); |
355 | 355 |
} |
356 | 356 |
|
357 | 357 |
Node fromId(int id, Node) const { |
358 | 358 |
return Parent::nodeFromId(id); |
359 | 359 |
} |
360 | 360 |
|
361 | 361 |
Arc fromId(int id, Arc) const { |
362 | 362 |
return Parent::arcFromId(id); |
363 | 363 |
} |
364 | 364 |
|
365 | 365 |
Edge fromId(int id, Edge) const { |
366 | 366 |
return Parent::edgeFromId(id); |
367 | 367 |
} |
368 | 368 |
|
369 | 369 |
Node oppositeNode(const Node &n, const Edge &e) const { |
370 | 370 |
if( n == Parent::source(e)) |
371 | 371 |
return Parent::target(e); |
372 | 372 |
else if( n == Parent::target(e)) |
373 | 373 |
return Parent::source(e); |
374 | 374 |
else |
375 | 375 |
return INVALID; |
376 | 376 |
} |
377 | 377 |
|
378 |
Arc oppositeArc(const Arc &e) const { |
|
379 |
return Parent::direct(e, !Parent::direction(e)); |
|
378 |
Arc oppositeArc(const Arc &arc) const { |
|
379 |
return Parent::direct(arc, !Parent::direction(arc)); |
|
380 | 380 |
} |
381 | 381 |
|
382 | 382 |
using Parent::direct; |
383 |
Arc direct(const Edge &ue, const Node &s) const { |
|
384 |
return Parent::direct(ue, Parent::source(ue) == s); |
|
383 |
Arc direct(const Edge &edge, const Node &node) const { |
|
384 |
return Parent::direct(edge, Parent::source(edge) == node); |
|
385 | 385 |
} |
386 | 386 |
|
387 | 387 |
// Alterable extension |
388 | 388 |
|
389 | 389 |
typedef AlterationNotifier<GraphExtender, Node> NodeNotifier; |
390 | 390 |
typedef AlterationNotifier<GraphExtender, Arc> ArcNotifier; |
391 | 391 |
typedef AlterationNotifier<GraphExtender, Edge> EdgeNotifier; |
392 | 392 |
|
393 | 393 |
|
394 | 394 |
protected: |
395 | 395 |
|
396 | 396 |
mutable NodeNotifier node_notifier; |
397 | 397 |
mutable ArcNotifier arc_notifier; |
398 | 398 |
mutable EdgeNotifier edge_notifier; |
399 | 399 |
|
400 | 400 |
public: |
401 | 401 |
|
402 | 402 |
NodeNotifier& notifier(Node) const { |
403 | 403 |
return node_notifier; |
404 | 404 |
} |
405 | 405 |
|
406 | 406 |
ArcNotifier& notifier(Arc) const { |
407 | 407 |
return arc_notifier; |
408 | 408 |
} |
409 | 409 |
|
410 | 410 |
EdgeNotifier& notifier(Edge) const { |
411 | 411 |
return edge_notifier; |
412 | 412 |
} |
413 | 413 |
|
414 | 414 |
|
415 | 415 |
|
416 | 416 |
class NodeIt : public Node { |
417 |
const |
|
417 |
const Graph* _graph; |
|
418 | 418 |
public: |
419 | 419 |
|
420 | 420 |
NodeIt() {} |
421 | 421 |
|
422 | 422 |
NodeIt(Invalid i) : Node(i) { } |
423 | 423 |
|
424 |
explicit NodeIt(const Digraph& _digraph) : digraph(&_digraph) { |
|
425 |
_digraph.first(static_cast<Node&>(*this)); |
|
424 |
explicit NodeIt(const Graph& graph) : _graph(&graph) { |
|
425 |
_graph->first(static_cast<Node&>(*this)); |
|
426 | 426 |
} |
427 | 427 |
|
428 |
NodeIt(const Digraph& _digraph, const Node& node) |
|
429 |
: Node(node), digraph(&_digraph) {} |
|
428 |
NodeIt(const Graph& graph, const Node& node) |
|
429 |
: Node(node), _graph(&graph) {} |
|
430 | 430 |
|
431 | 431 |
NodeIt& operator++() { |
432 |
|
|
432 |
_graph->next(*this); |
|
433 | 433 |
return *this; |
434 | 434 |
} |
435 | 435 |
|
436 | 436 |
}; |
437 | 437 |
|
438 | 438 |
|
439 | 439 |
class ArcIt : public Arc { |
440 |
const |
|
440 |
const Graph* _graph; |
|
441 | 441 |
public: |
442 | 442 |
|
443 | 443 |
ArcIt() { } |
444 | 444 |
|
445 | 445 |
ArcIt(Invalid i) : Arc(i) { } |
446 | 446 |
|
447 |
explicit ArcIt(const Digraph& _digraph) : digraph(&_digraph) { |
|
448 |
_digraph.first(static_cast<Arc&>(*this)); |
|
447 |
explicit ArcIt(const Graph& graph) : _graph(&graph) { |
|
448 |
_graph->first(static_cast<Arc&>(*this)); |
|
449 | 449 |
} |
450 | 450 |
|
451 |
ArcIt(const Digraph& _digraph, const Arc& e) : |
|
452 |
Arc(e), digraph(&_digraph) { } |
|
451 |
ArcIt(const Graph& graph, const Arc& arc) : |
|
452 |
Arc(arc), _graph(&graph) { } |
|
453 | 453 |
|
454 | 454 |
ArcIt& operator++() { |
455 |
|
|
455 |
_graph->next(*this); |
|
456 | 456 |
return *this; |
457 | 457 |
} |
458 | 458 |
|
459 | 459 |
}; |
460 | 460 |
|
461 | 461 |
|
462 | 462 |
class OutArcIt : public Arc { |
463 |
const |
|
463 |
const Graph* _graph; |
|
464 | 464 |
public: |
465 | 465 |
|
466 | 466 |
OutArcIt() { } |
467 | 467 |
|
468 | 468 |
OutArcIt(Invalid i) : Arc(i) { } |
469 | 469 |
|
470 |
OutArcIt(const Digraph& _digraph, const Node& node) |
|
471 |
: digraph(&_digraph) { |
|
472 |
|
|
470 |
OutArcIt(const Graph& graph, const Node& node) |
|
471 |
: _graph(&graph) { |
|
472 |
_graph->firstOut(*this, node); |
|
473 | 473 |
} |
474 | 474 |
|
475 |
OutArcIt(const Digraph& _digraph, const Arc& arc) |
|
476 |
: Arc(arc), digraph(&_digraph) {} |
|
475 |
OutArcIt(const Graph& graph, const Arc& arc) |
|
476 |
: Arc(arc), _graph(&graph) {} |
|
477 | 477 |
|
478 | 478 |
OutArcIt& operator++() { |
479 |
|
|
479 |
_graph->nextOut(*this); |
|
480 | 480 |
return *this; |
481 | 481 |
} |
482 | 482 |
|
483 | 483 |
}; |
484 | 484 |
|
485 | 485 |
|
486 | 486 |
class InArcIt : public Arc { |
487 |
const |
|
487 |
const Graph* _graph; |
|
488 | 488 |
public: |
489 | 489 |
|
490 | 490 |
InArcIt() { } |
491 | 491 |
|
492 | 492 |
InArcIt(Invalid i) : Arc(i) { } |
493 | 493 |
|
494 |
InArcIt(const Digraph& _digraph, const Node& node) |
|
495 |
: digraph(&_digraph) { |
|
496 |
|
|
494 |
InArcIt(const Graph& graph, const Node& node) |
|
495 |
: _graph(&graph) { |
|
496 |
_graph->firstIn(*this, node); |
|
497 | 497 |
} |
498 | 498 |
|
499 |
InArcIt(const Digraph& _digraph, const Arc& arc) : |
|
500 |
Arc(arc), digraph(&_digraph) {} |
|
499 |
InArcIt(const Graph& graph, const Arc& arc) : |
|
500 |
Arc(arc), _graph(&graph) {} |
|
501 | 501 |
|
502 | 502 |
InArcIt& operator++() { |
503 |
|
|
503 |
_graph->nextIn(*this); |
|
504 | 504 |
return *this; |
505 | 505 |
} |
506 | 506 |
|
507 | 507 |
}; |
508 | 508 |
|
509 | 509 |
|
510 | 510 |
class EdgeIt : public Parent::Edge { |
511 |
const |
|
511 |
const Graph* _graph; |
|
512 | 512 |
public: |
513 | 513 |
|
514 | 514 |
EdgeIt() { } |
515 | 515 |
|
516 | 516 |
EdgeIt(Invalid i) : Edge(i) { } |
517 | 517 |
|
518 |
explicit EdgeIt(const Digraph& _digraph) : digraph(&_digraph) { |
|
519 |
_digraph.first(static_cast<Edge&>(*this)); |
|
518 |
explicit EdgeIt(const Graph& graph) : _graph(&graph) { |
|
519 |
_graph->first(static_cast<Edge&>(*this)); |
|
520 | 520 |
} |
521 | 521 |
|
522 |
EdgeIt(const Digraph& _digraph, const Edge& e) : |
|
523 |
Edge(e), digraph(&_digraph) { } |
|
522 |
EdgeIt(const Graph& graph, const Edge& edge) : |
|
523 |
Edge(edge), _graph(&graph) { } |
|
524 | 524 |
|
525 | 525 |
EdgeIt& operator++() { |
526 |
|
|
526 |
_graph->next(*this); |
|
527 | 527 |
return *this; |
528 | 528 |
} |
529 | 529 |
|
530 | 530 |
}; |
531 | 531 |
|
532 |
class |
|
532 |
class IncEdgeIt : public Parent::Edge { |
|
533 | 533 |
friend class GraphExtender; |
534 |
const Digraph* digraph; |
|
535 |
bool direction; |
|
534 |
const Graph* _graph; |
|
535 |
bool _direction; |
|
536 | 536 |
public: |
537 | 537 |
|
538 |
|
|
538 |
IncEdgeIt() { } |
|
539 | 539 |
|
540 |
|
|
540 |
IncEdgeIt(Invalid i) : Edge(i), _direction(false) { } |
|
541 | 541 |
|
542 |
IncArcIt(const Digraph& _digraph, const Node &n) : digraph(&_digraph) { |
|
543 |
_digraph.firstInc(*this, direction, n); |
|
542 |
IncEdgeIt(const Graph& graph, const Node &node) : _graph(&graph) { |
|
543 |
_graph->firstInc(*this, _direction, node); |
|
544 | 544 |
} |
545 | 545 |
|
546 |
IncArcIt(const Digraph& _digraph, const Edge &ue, const Node &n) |
|
547 |
: digraph(&_digraph), Edge(ue) { |
|
548 |
|
|
546 |
IncEdgeIt(const Graph& graph, const Edge &edge, const Node &node) |
|
547 |
: _graph(&graph), Edge(edge) { |
|
548 |
_direction = (_graph->source(edge) == node); |
|
549 | 549 |
} |
550 | 550 |
|
551 |
IncArcIt& operator++() { |
|
552 |
digraph->nextInc(*this, direction); |
|
551 |
IncEdgeIt& operator++() { |
|
552 |
_graph->nextInc(*this, _direction); |
|
553 | 553 |
return *this; |
554 | 554 |
} |
555 | 555 |
}; |
556 | 556 |
|
557 | 557 |
/// \brief Base node of the iterator |
558 | 558 |
/// |
559 | 559 |
/// Returns the base node (ie. the source in this case) of the iterator |
560 |
Node baseNode(const OutArcIt &e) const { |
|
561 |
return Parent::source(static_cast<const Arc&>(e)); |
|
560 |
Node baseNode(const OutArcIt &arc) const { |
|
561 |
return Parent::source(static_cast<const Arc&>(arc)); |
|
562 | 562 |
} |
563 | 563 |
/// \brief Running node of the iterator |
564 | 564 |
/// |
565 | 565 |
/// Returns the running node (ie. the target in this case) of the |
566 | 566 |
/// iterator |
567 |
Node runningNode(const OutArcIt &e) const { |
|
568 |
return Parent::target(static_cast<const Arc&>(e)); |
|
567 |
Node runningNode(const OutArcIt &arc) const { |
|
568 |
return Parent::target(static_cast<const Arc&>(arc)); |
|
569 | 569 |
} |
570 | 570 |
|
571 | 571 |
/// \brief Base node of the iterator |
572 | 572 |
/// |
573 | 573 |
/// Returns the base node (ie. the target in this case) of the iterator |
574 |
Node baseNode(const InArcIt &e) const { |
|
575 |
return Parent::target(static_cast<const Arc&>(e)); |
|
574 |
Node baseNode(const InArcIt &arc) const { |
|
575 |
return Parent::target(static_cast<const Arc&>(arc)); |
|
576 | 576 |
} |
577 | 577 |
/// \brief Running node of the iterator |
578 | 578 |
/// |
579 | 579 |
/// Returns the running node (ie. the source in this case) of the |
580 | 580 |
/// iterator |
581 |
Node runningNode(const InArcIt &e) const { |
|
582 |
return Parent::source(static_cast<const Arc&>(e)); |
|
581 |
Node runningNode(const InArcIt &arc) const { |
|
582 |
return Parent::source(static_cast<const Arc&>(arc)); |
|
583 | 583 |
} |
584 | 584 |
|
585 | 585 |
/// Base node of the iterator |
586 | 586 |
/// |
587 | 587 |
/// Returns the base node of the iterator |
588 |
Node baseNode(const IncArcIt &e) const { |
|
589 |
return e.direction ? source(e) : target(e); |
|
588 |
Node baseNode(const IncEdgeIt &edge) const { |
|
589 |
return edge._direction ? source(edge) : target(edge); |
|
590 | 590 |
} |
591 | 591 |
/// Running node of the iterator |
592 | 592 |
/// |
593 | 593 |
/// Returns the running node of the iterator |
594 |
Node runningNode(const IncArcIt &e) const { |
|
595 |
return e.direction ? target(e) : source(e); |
|
594 |
Node runningNode(const IncEdgeIt &edge) const { |
|
595 |
return edge._direction ? target(edge) : source(edge); |
|
596 | 596 |
} |
597 | 597 |
|
598 | 598 |
// Mappable extension |
599 | 599 |
|
600 | 600 |
template <typename _Value> |
601 | 601 |
class NodeMap |
602 |
: public MapExtender<DefaultMap< |
|
602 |
: public MapExtender<DefaultMap<Graph, Node, _Value> > { |
|
603 | 603 |
public: |
604 |
typedef GraphExtender Digraph; |
|
605 |
typedef MapExtender<DefaultMap<Digraph, Node, _Value> > Parent; |
|
604 |
typedef GraphExtender Graph; |
|
605 |
typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent; |
|
606 | 606 |
|
607 |
NodeMap(const Digraph& digraph) |
|
608 |
: Parent(digraph) {} |
|
609 |
NodeMap(const Digraph& digraph, const _Value& value) |
|
610 |
: Parent(digraph, value) {} |
|
607 |
NodeMap(const Graph& graph) |
|
608 |
: Parent(graph) {} |
|
609 |
NodeMap(const Graph& graph, const _Value& value) |
|
610 |
: Parent(graph, value) {} |
|
611 | 611 |
|
612 | 612 |
NodeMap& operator=(const NodeMap& cmap) { |
613 | 613 |
return operator=<NodeMap>(cmap); |
614 | 614 |
} |
615 | 615 |
|
616 | 616 |
template <typename CMap> |
617 | 617 |
NodeMap& operator=(const CMap& cmap) { |
618 | 618 |
Parent::operator=(cmap); |
619 | 619 |
return *this; |
620 | 620 |
} |
621 | 621 |
|
622 | 622 |
}; |
623 | 623 |
|
624 | 624 |
template <typename _Value> |
625 | 625 |
class ArcMap |
626 |
: public MapExtender<DefaultMap< |
|
626 |
: public MapExtender<DefaultMap<Graph, Arc, _Value> > { |
|
627 | 627 |
public: |
628 |
typedef GraphExtender Digraph; |
|
629 |
typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent; |
|
628 |
typedef GraphExtender Graph; |
|
629 |
typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent; |
|
630 | 630 |
|
631 |
ArcMap(const Digraph& digraph) |
|
632 |
: Parent(digraph) {} |
|
633 |
ArcMap(const Digraph& digraph, const _Value& value) |
|
634 |
: Parent(digraph, value) {} |
|
631 |
ArcMap(const Graph& graph) |
|
632 |
: Parent(graph) {} |
|
633 |
ArcMap(const Graph& graph, const _Value& value) |
|
634 |
: Parent(graph, value) {} |
|
635 | 635 |
|
636 | 636 |
ArcMap& operator=(const ArcMap& cmap) { |
637 | 637 |
return operator=<ArcMap>(cmap); |
638 | 638 |
} |
639 | 639 |
|
640 | 640 |
template <typename CMap> |
641 | 641 |
ArcMap& operator=(const CMap& cmap) { |
642 | 642 |
Parent::operator=(cmap); |
643 | 643 |
return *this; |
644 | 644 |
} |
645 | 645 |
}; |
646 | 646 |
|
647 | 647 |
|
648 | 648 |
template <typename _Value> |
649 | 649 |
class EdgeMap |
650 |
: public MapExtender<DefaultMap< |
|
650 |
: public MapExtender<DefaultMap<Graph, Edge, _Value> > { |
|
651 | 651 |
public: |
652 |
typedef GraphExtender Digraph; |
|
653 |
typedef MapExtender<DefaultMap<Digraph, Edge, _Value> > Parent; |
|
652 |
typedef GraphExtender Graph; |
|
653 |
typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent; |
|
654 | 654 |
|
655 |
EdgeMap(const Digraph& digraph) |
|
656 |
: Parent(digraph) {} |
|
655 |
EdgeMap(const Graph& graph) |
|
656 |
: Parent(graph) {} |
|
657 | 657 |
|
658 |
EdgeMap(const Digraph& digraph, const _Value& value) |
|
659 |
: Parent(digraph, value) {} |
|
658 |
EdgeMap(const Graph& graph, const _Value& value) |
|
659 |
: Parent(graph, value) {} |
|
660 | 660 |
|
661 | 661 |
EdgeMap& operator=(const EdgeMap& cmap) { |
662 | 662 |
return operator=<EdgeMap>(cmap); |
663 | 663 |
} |
664 | 664 |
|
665 | 665 |
template <typename CMap> |
666 | 666 |
EdgeMap& operator=(const CMap& cmap) { |
667 | 667 |
Parent::operator=(cmap); |
668 | 668 |
return *this; |
669 | 669 |
} |
670 | 670 |
|
671 | 671 |
}; |
672 | 672 |
|
673 | 673 |
// Alteration extension |
674 | 674 |
|
675 | 675 |
Node addNode() { |
676 | 676 |
Node node = Parent::addNode(); |
677 | 677 |
notifier(Node()).add(node); |
678 | 678 |
return node; |
679 | 679 |
} |
680 | 680 |
|
681 | 681 |
Edge addEdge(const Node& from, const Node& to) { |
682 | 682 |
Edge edge = Parent::addEdge(from, to); |
683 | 683 |
notifier(Edge()).add(edge); |
684 | 684 |
std::vector<Arc> ev; |
685 | 685 |
ev.push_back(Parent::direct(edge, true)); |
686 | 686 |
ev.push_back(Parent::direct(edge, false)); |
687 | 687 |
notifier(Arc()).add(ev); |
688 | 688 |
return edge; |
689 | 689 |
} |
690 | 690 |
|
691 | 691 |
void clear() { |
692 | 692 |
notifier(Arc()).clear(); |
693 | 693 |
notifier(Edge()).clear(); |
694 | 694 |
notifier(Node()).clear(); |
695 | 695 |
Parent::clear(); |
696 | 696 |
} |
697 | 697 |
|
698 |
template <typename Digraph, typename NodeRefMap, typename EdgeRefMap> |
|
699 |
void build(const Digraph& digraph, NodeRefMap& nodeRef, |
|
698 |
template <typename Graph, typename NodeRefMap, typename EdgeRefMap> |
|
699 |
void build(const Graph& graph, NodeRefMap& nodeRef, |
|
700 | 700 |
EdgeRefMap& edgeRef) { |
701 |
Parent::build( |
|
701 |
Parent::build(graph, nodeRef, edgeRef); |
|
702 | 702 |
notifier(Node()).build(); |
703 | 703 |
notifier(Edge()).build(); |
704 | 704 |
notifier(Arc()).build(); |
705 | 705 |
} |
706 | 706 |
|
707 | 707 |
void erase(const Node& node) { |
708 | 708 |
Arc arc; |
709 | 709 |
Parent::firstOut(arc, node); |
710 | 710 |
while (arc != INVALID ) { |
711 | 711 |
erase(arc); |
712 | 712 |
Parent::firstOut(arc, node); |
713 | 713 |
} |
714 | 714 |
|
715 | 715 |
Parent::firstIn(arc, node); |
716 | 716 |
while (arc != INVALID ) { |
717 | 717 |
erase(arc); |
718 | 718 |
Parent::firstIn(arc, node); |
719 | 719 |
} |
720 | 720 |
|
721 | 721 |
notifier(Node()).erase(node); |
722 | 722 |
Parent::erase(node); |
723 | 723 |
} |
724 | 724 |
|
725 | 725 |
void erase(const Edge& edge) { |
726 |
std::vector<Arc> ev; |
|
727 |
ev.push_back(Parent::direct(edge, true)); |
|
728 |
ev.push_back(Parent::direct(edge, false)); |
|
729 |
notifier(Arc()).erase(ev); |
|
726 |
std::vector<Arc> av; |
|
727 |
av.push_back(Parent::direct(edge, true)); |
|
728 |
av.push_back(Parent::direct(edge, false)); |
|
729 |
notifier(Arc()).erase(av); |
|
730 | 730 |
notifier(Edge()).erase(edge); |
731 | 731 |
Parent::erase(edge); |
732 | 732 |
} |
733 | 733 |
|
734 | 734 |
GraphExtender() { |
735 | 735 |
node_notifier.setContainer(*this); |
736 | 736 |
arc_notifier.setContainer(*this); |
737 | 737 |
edge_notifier.setContainer(*this); |
738 | 738 |
} |
739 | 739 |
|
740 | 740 |
~GraphExtender() { |
741 | 741 |
edge_notifier.clear(); |
742 | 742 |
arc_notifier.clear(); |
743 | 743 |
node_notifier.clear(); |
744 | 744 |
} |
745 | 745 |
|
746 | 746 |
}; |
747 | 747 |
|
748 | 748 |
} |
749 | 749 |
|
750 | 750 |
#endif |
... | ... |
@@ -18,97 +18,97 @@ |
18 | 18 |
|
19 | 19 |
///\ingroup graph_concepts |
20 | 20 |
///\file |
21 | 21 |
///\brief The concept of Undirected Graphs. |
22 | 22 |
|
23 | 23 |
#ifndef LEMON_CONCEPT_GRAPH_H |
24 | 24 |
#define LEMON_CONCEPT_GRAPH_H |
25 | 25 |
|
26 | 26 |
#include <lemon/concepts/graph_components.h> |
27 | 27 |
#include <lemon/concepts/graph.h> |
28 | 28 |
#include <lemon/bits/utility.h> |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
namespace concepts { |
32 | 32 |
|
33 | 33 |
/// \ingroup graph_concepts |
34 | 34 |
/// |
35 | 35 |
/// \brief Class describing the concept of Undirected Graphs. |
36 | 36 |
/// |
37 | 37 |
/// This class describes the common interface of all Undirected |
38 | 38 |
/// Graphs. |
39 | 39 |
/// |
40 | 40 |
/// As all concept describing classes it provides only interface |
41 | 41 |
/// without any sensible implementation. So any algorithm for |
42 | 42 |
/// undirected graph should compile with this class, but it will not |
43 | 43 |
/// run properly, of course. |
44 | 44 |
/// |
45 | 45 |
/// The LEMON undirected graphs also fulfill the concept of |
46 | 46 |
/// directed graphs (\ref lemon::concepts::Digraph "Digraph |
47 | 47 |
/// Concept"). Each edges can be seen as two opposite |
48 | 48 |
/// directed arc and consequently the undirected graph can be |
49 | 49 |
/// seen as the direceted graph of these directed arcs. The |
50 | 50 |
/// Graph has the Edge inner class for the edges and |
51 | 51 |
/// the Arc type for the directed arcs. The Arc type is |
52 | 52 |
/// convertible to Edge or inherited from it so from a directed |
53 | 53 |
/// arc we can get the represented edge. |
54 | 54 |
/// |
55 | 55 |
/// In the sense of the LEMON each edge has a default |
56 | 56 |
/// direction (it should be in every computer implementation, |
57 | 57 |
/// because the order of edge's nodes defines an |
58 | 58 |
/// orientation). With the default orientation we can define that |
59 | 59 |
/// the directed arc is forward or backward directed. With the \c |
60 | 60 |
/// direction() and \c direct() function we can get the direction |
61 | 61 |
/// of the directed arc and we can direct an edge. |
62 | 62 |
/// |
63 | 63 |
/// The EdgeIt is an iterator for the edges. We can use |
64 | 64 |
/// the EdgeMap to map values for the edges. The InArcIt and |
65 | 65 |
/// OutArcIt iterates on the same edges but with opposite |
66 |
/// direction. The |
|
66 |
/// direction. The IncEdgeIt iterates also on the same edges |
|
67 | 67 |
/// as the OutArcIt and InArcIt but it is not convertible to Arc just |
68 | 68 |
/// to Edge. |
69 | 69 |
class Graph { |
70 | 70 |
public: |
71 | 71 |
/// \brief The undirected graph should be tagged by the |
72 | 72 |
/// UndirectedTag. |
73 | 73 |
/// |
74 | 74 |
/// The undirected graph should be tagged by the UndirectedTag. This |
75 | 75 |
/// tag helps the enable_if technics to make compile time |
76 | 76 |
/// specializations for undirected graphs. |
77 | 77 |
typedef True UndirectedTag; |
78 | 78 |
|
79 | 79 |
/// \brief The base type of node iterators, |
80 | 80 |
/// or in other words, the trivial node iterator. |
81 | 81 |
/// |
82 | 82 |
/// This is the base type of each node iterator, |
83 | 83 |
/// thus each kind of node iterator converts to this. |
84 | 84 |
/// More precisely each kind of node iterator should be inherited |
85 | 85 |
/// from the trivial node iterator. |
86 | 86 |
class Node { |
87 | 87 |
public: |
88 | 88 |
/// Default constructor |
89 | 89 |
|
90 | 90 |
/// @warning The default constructor sets the iterator |
91 | 91 |
/// to an undefined value. |
92 | 92 |
Node() { } |
93 | 93 |
/// Copy constructor. |
94 | 94 |
|
95 | 95 |
/// Copy constructor. |
96 | 96 |
/// |
97 | 97 |
Node(const Node&) { } |
98 | 98 |
|
99 | 99 |
/// Invalid constructor \& conversion. |
100 | 100 |
|
101 | 101 |
/// This constructor initializes the iterator to be invalid. |
102 | 102 |
/// \sa Invalid for more details. |
103 | 103 |
Node(Invalid) { } |
104 | 104 |
/// Equality operator |
105 | 105 |
|
106 | 106 |
/// Two iterators are equal if and only if they point to the |
107 | 107 |
/// same object or both are invalid. |
108 | 108 |
bool operator==(Node) const { return true; } |
109 | 109 |
|
110 | 110 |
/// Inequality operator |
111 | 111 |
|
112 | 112 |
/// \sa operator==(Node n) |
113 | 113 |
/// |
114 | 114 |
bool operator!=(Node) const { return true; } |
... | ... |
@@ -225,131 +225,131 @@ |
225 | 225 |
///\endcode |
226 | 226 |
class EdgeIt : public Edge { |
227 | 227 |
public: |
228 | 228 |
/// Default constructor |
229 | 229 |
|
230 | 230 |
/// @warning The default constructor sets the iterator |
231 | 231 |
/// to an undefined value. |
232 | 232 |
EdgeIt() { } |
233 | 233 |
/// Copy constructor. |
234 | 234 |
|
235 | 235 |
/// Copy constructor. |
236 | 236 |
/// |
237 | 237 |
EdgeIt(const EdgeIt& e) : Edge(e) { } |
238 | 238 |
/// Initialize the iterator to be invalid. |
239 | 239 |
|
240 | 240 |
/// Initialize the iterator to be invalid. |
241 | 241 |
/// |
242 | 242 |
EdgeIt(Invalid) { } |
243 | 243 |
/// This constructor sets the iterator to the first edge. |
244 | 244 |
|
245 | 245 |
/// This constructor sets the iterator to the first edge. |
246 | 246 |
EdgeIt(const Graph&) { } |
247 | 247 |
/// Edge -> EdgeIt conversion |
248 | 248 |
|
249 | 249 |
/// Sets the iterator to the value of the trivial iterator. |
250 | 250 |
/// This feature necessitates that each time we |
251 | 251 |
/// iterate the edge-set, the iteration order is the |
252 | 252 |
/// same. |
253 | 253 |
EdgeIt(const Graph&, const Edge&) { } |
254 | 254 |
/// Next edge |
255 | 255 |
|
256 | 256 |
/// Assign the iterator to the next edge. |
257 | 257 |
EdgeIt& operator++() { return *this; } |
258 | 258 |
}; |
259 | 259 |
|
260 | 260 |
/// \brief This iterator goes trough the incident undirected |
261 | 261 |
/// arcs of a node. |
262 | 262 |
/// |
263 | 263 |
/// This iterator goes trough the incident edges |
264 | 264 |
/// of a certain node of a graph. You should assume that the |
265 | 265 |
/// loop arcs will be iterated twice. |
266 | 266 |
/// |
267 | 267 |
/// Its usage is quite simple, for example you can compute the |
268 | 268 |
/// degree (i.e. count the number of incident arcs of a node \c n |
269 | 269 |
/// in graph \c g of type \c Graph as follows. |
270 | 270 |
/// |
271 | 271 |
///\code |
272 | 272 |
/// int count=0; |
273 |
/// for(Graph:: |
|
273 |
/// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count; |
|
274 | 274 |
///\endcode |
275 |
class |
|
275 |
class IncEdgeIt : public Edge { |
|
276 | 276 |
public: |
277 | 277 |
/// Default constructor |
278 | 278 |
|
279 | 279 |
/// @warning The default constructor sets the iterator |
280 | 280 |
/// to an undefined value. |
281 |
|
|
281 |
IncEdgeIt() { } |
|
282 | 282 |
/// Copy constructor. |
283 | 283 |
|
284 | 284 |
/// Copy constructor. |
285 | 285 |
/// |
286 |
|
|
286 |
IncEdgeIt(const IncEdgeIt& e) : Edge(e) { } |
|
287 | 287 |
/// Initialize the iterator to be invalid. |
288 | 288 |
|
289 | 289 |
/// Initialize the iterator to be invalid. |
290 | 290 |
/// |
291 |
|
|
291 |
IncEdgeIt(Invalid) { } |
|
292 | 292 |
/// This constructor sets the iterator to first incident arc. |
293 | 293 |
|
294 | 294 |
/// This constructor set the iterator to the first incident arc of |
295 | 295 |
/// the node. |
296 |
IncArcIt(const Graph&, const Node&) { } |
|
297 |
/// Edge -> IncArcIt conversion |
|
296 |
IncEdgeIt(const Graph&, const Node&) { } |
|
297 |
/// Edge -> IncEdgeIt conversion |
|
298 | 298 |
|
299 | 299 |
/// Sets the iterator to the value of the trivial iterator \c e. |
300 | 300 |
/// This feature necessitates that each time we |
301 | 301 |
/// iterate the arc-set, the iteration order is the same. |
302 |
|
|
302 |
IncEdgeIt(const Graph&, const Edge&) { } |
|
303 | 303 |
/// Next incident arc |
304 | 304 |
|
305 | 305 |
/// Assign the iterator to the next incident arc |
306 | 306 |
/// of the corresponding node. |
307 |
|
|
307 |
IncEdgeIt& operator++() { return *this; } |
|
308 | 308 |
}; |
309 | 309 |
|
310 | 310 |
/// The directed arc type. |
311 | 311 |
|
312 | 312 |
/// The directed arc type. It can be converted to the |
313 | 313 |
/// edge or it should be inherited from the undirected |
314 | 314 |
/// arc. |
315 | 315 |
class Arc : public Edge { |
316 | 316 |
public: |
317 | 317 |
/// Default constructor |
318 | 318 |
|
319 | 319 |
/// @warning The default constructor sets the iterator |
320 | 320 |
/// to an undefined value. |
321 | 321 |
Arc() { } |
322 | 322 |
/// Copy constructor. |
323 | 323 |
|
324 | 324 |
/// Copy constructor. |
325 | 325 |
/// |
326 | 326 |
Arc(const Arc& e) : Edge(e) { } |
327 | 327 |
/// Initialize the iterator to be invalid. |
328 | 328 |
|
329 | 329 |
/// Initialize the iterator to be invalid. |
330 | 330 |
/// |
331 | 331 |
Arc(Invalid) { } |
332 | 332 |
/// Equality operator |
333 | 333 |
|
334 | 334 |
/// Two iterators are equal if and only if they point to the |
335 | 335 |
/// same object or both are invalid. |
336 | 336 |
bool operator==(Arc) const { return true; } |
337 | 337 |
/// Inequality operator |
338 | 338 |
|
339 | 339 |
/// \sa operator==(Arc n) |
340 | 340 |
/// |
341 | 341 |
bool operator!=(Arc) const { return true; } |
342 | 342 |
|
343 | 343 |
/// Artificial ordering operator. |
344 | 344 |
|
345 | 345 |
/// To allow the use of graph descriptors as key type in std::map or |
346 | 346 |
/// similar associative container we require this. |
347 | 347 |
/// |
348 | 348 |
/// \note This operator only have to define some strict ordering of |
349 | 349 |
/// the items; this order has nothing to do with the iteration |
350 | 350 |
/// ordering of the items. |
351 | 351 |
bool operator<(Arc) const { return false; } |
352 | 352 |
|
353 | 353 |
}; |
354 | 354 |
/// This iterator goes through each directed arc. |
355 | 355 |
|
... | ... |
@@ -675,75 +675,75 @@ |
675 | 675 |
void firstInc(Edge &, bool &, const Node &) const {} |
676 | 676 |
void nextInc(Edge &, bool &) const {} |
677 | 677 |
|
678 | 678 |
// The second parameter is dummy. |
679 | 679 |
Node fromId(int, Node) const { return INVALID; } |
680 | 680 |
// The second parameter is dummy. |
681 | 681 |
Edge fromId(int, Edge) const { return INVALID; } |
682 | 682 |
// The second parameter is dummy. |
683 | 683 |
Arc fromId(int, Arc) const { return INVALID; } |
684 | 684 |
|
685 | 685 |
// Dummy parameter. |
686 | 686 |
int maxId(Node) const { return -1; } |
687 | 687 |
// Dummy parameter. |
688 | 688 |
int maxId(Edge) const { return -1; } |
689 | 689 |
// Dummy parameter. |
690 | 690 |
int maxId(Arc) const { return -1; } |
691 | 691 |
|
692 | 692 |
/// \brief Base node of the iterator |
693 | 693 |
/// |
694 | 694 |
/// Returns the base node (the source in this case) of the iterator |
695 | 695 |
Node baseNode(OutArcIt e) const { |
696 | 696 |
return source(e); |
697 | 697 |
} |
698 | 698 |
/// \brief Running node of the iterator |
699 | 699 |
/// |
700 | 700 |
/// Returns the running node (the target in this case) of the |
701 | 701 |
/// iterator |
702 | 702 |
Node runningNode(OutArcIt e) const { |
703 | 703 |
return target(e); |
704 | 704 |
} |
705 | 705 |
|
706 | 706 |
/// \brief Base node of the iterator |
707 | 707 |
/// |
708 | 708 |
/// Returns the base node (the target in this case) of the iterator |
709 | 709 |
Node baseNode(InArcIt e) const { |
710 | 710 |
return target(e); |
711 | 711 |
} |
712 | 712 |
/// \brief Running node of the iterator |
713 | 713 |
/// |
714 | 714 |
/// Returns the running node (the source in this case) of the |
715 | 715 |
/// iterator |
716 | 716 |
Node runningNode(InArcIt e) const { |
717 | 717 |
return source(e); |
718 | 718 |
} |
719 | 719 |
|
720 | 720 |
/// \brief Base node of the iterator |
721 | 721 |
/// |
722 | 722 |
/// Returns the base node of the iterator |
723 |
Node baseNode( |
|
723 |
Node baseNode(IncEdgeIt) const { |
|
724 | 724 |
return INVALID; |
725 | 725 |
} |
726 | 726 |
|
727 | 727 |
/// \brief Running node of the iterator |
728 | 728 |
/// |
729 | 729 |
/// Returns the running node of the iterator |
730 |
Node runningNode( |
|
730 |
Node runningNode(IncEdgeIt) const { |
|
731 | 731 |
return INVALID; |
732 | 732 |
} |
733 | 733 |
|
734 | 734 |
template <typename Graph> |
735 | 735 |
struct Constraints { |
736 | 736 |
void constraints() { |
737 | 737 |
checkConcept<IterableGraphComponent<>, Graph>(); |
738 | 738 |
checkConcept<IDableGraphComponent<>, Graph>(); |
739 | 739 |
checkConcept<MappableGraphComponent<>, Graph>(); |
740 | 740 |
} |
741 | 741 |
}; |
742 | 742 |
|
743 | 743 |
}; |
744 | 744 |
|
745 | 745 |
} |
746 | 746 |
|
747 | 747 |
} |
748 | 748 |
|
749 | 749 |
#endif |
... | ... |
@@ -783,137 +783,137 @@ |
783 | 783 |
/// |
784 | 784 |
void first(Edge&) const {} |
785 | 785 |
|
786 | 786 |
/// \brief Gives back the next edge in the iterating |
787 | 787 |
/// order. |
788 | 788 |
/// |
789 | 789 |
/// Gives back the next edge in the iterating order. |
790 | 790 |
/// |
791 | 791 |
void next(Edge&) const {} |
792 | 792 |
|
793 | 793 |
|
794 | 794 |
/// \brief Gives back the first of the edges from the |
795 | 795 |
/// given node. |
796 | 796 |
/// |
797 | 797 |
/// Gives back the first of the edges from the given |
798 | 798 |
/// node. The bool parameter gives back that direction which |
799 | 799 |
/// gives a good direction of the edge so the source of the |
800 | 800 |
/// directed arc is the given node. |
801 | 801 |
void firstInc(Edge&, bool&, const Node&) const {} |
802 | 802 |
|
803 | 803 |
/// \brief Gives back the next of the edges from the |
804 | 804 |
/// given node. |
805 | 805 |
/// |
806 | 806 |
/// Gives back the next of the edges from the given |
807 | 807 |
/// node. The bool parameter should be used as the \c firstInc() |
808 | 808 |
/// use it. |
809 | 809 |
void nextInc(Edge&, bool&) const {} |
810 | 810 |
|
811 | 811 |
using IterableDigraphComponent<_Base>::baseNode; |
812 | 812 |
using IterableDigraphComponent<_Base>::runningNode; |
813 | 813 |
|
814 | 814 |
/// @} |
815 | 815 |
|
816 | 816 |
/// \name Class based iteration |
817 | 817 |
/// |
818 | 818 |
/// This interface provides functions for iteration on graph items |
819 | 819 |
/// |
820 | 820 |
/// @{ |
821 | 821 |
|
822 | 822 |
/// \brief This iterator goes through each node. |
823 | 823 |
/// |
824 | 824 |
/// This iterator goes through each node. |
825 | 825 |
typedef GraphItemIt<Graph, Edge> EdgeIt; |
826 | 826 |
/// \brief This iterator goes trough the incident arcs of a |
827 | 827 |
/// node. |
828 | 828 |
/// |
829 | 829 |
/// This iterator goes trough the incident arcs of a certain |
830 | 830 |
/// node of a graph. |
831 |
typedef GraphIncIt<Graph, Edge, Node, 'u'> |
|
831 |
typedef GraphIncIt<Graph, Edge, Node, 'u'> IncEdgeIt; |
|
832 | 832 |
/// \brief The base node of the iterator. |
833 | 833 |
/// |
834 | 834 |
/// Gives back the base node of the iterator. |
835 |
Node baseNode(const |
|
835 |
Node baseNode(const IncEdgeIt&) const { return INVALID; } |
|
836 | 836 |
|
837 | 837 |
/// \brief The running node of the iterator. |
838 | 838 |
/// |
839 | 839 |
/// Gives back the running node of the iterator. |
840 |
Node runningNode(const |
|
840 |
Node runningNode(const IncEdgeIt&) const { return INVALID; } |
|
841 | 841 |
|
842 | 842 |
/// @} |
843 | 843 |
|
844 | 844 |
template <typename _Graph> |
845 | 845 |
struct Constraints { |
846 | 846 |
void constraints() { |
847 | 847 |
checkConcept<IterableDigraphComponent<Base>, _Graph>(); |
848 | 848 |
|
849 | 849 |
{ |
850 | 850 |
typename _Graph::Node node(INVALID); |
851 | 851 |
typename _Graph::Edge edge(INVALID); |
852 | 852 |
bool dir; |
853 | 853 |
{ |
854 | 854 |
graph.first(edge); |
855 | 855 |
graph.next(edge); |
856 | 856 |
} |
857 | 857 |
{ |
858 | 858 |
graph.firstInc(edge, dir, node); |
859 | 859 |
graph.nextInc(edge, dir); |
860 | 860 |
} |
861 | 861 |
|
862 | 862 |
} |
863 | 863 |
|
864 | 864 |
{ |
865 | 865 |
checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>, |
866 | 866 |
typename _Graph::EdgeIt >(); |
867 | 867 |
checkConcept<GraphIncIt<_Graph, typename _Graph::Edge, |
868 |
typename _Graph::Node, 'u'>, typename _Graph:: |
|
868 |
typename _Graph::Node, 'u'>, typename _Graph::IncEdgeIt>(); |
|
869 | 869 |
|
870 | 870 |
typename _Graph::Node n; |
871 |
typename _Graph:: |
|
871 |
typename _Graph::IncEdgeIt ueit(INVALID); |
|
872 | 872 |
n = graph.baseNode(ueit); |
873 | 873 |
n = graph.runningNode(ueit); |
874 | 874 |
} |
875 | 875 |
} |
876 | 876 |
|
877 | 877 |
const _Graph& graph; |
878 | 878 |
|
879 | 879 |
}; |
880 | 880 |
}; |
881 | 881 |
|
882 | 882 |
/// \brief An empty alteration notifier digraph class. |
883 | 883 |
/// |
884 | 884 |
/// This class provides beside the core digraph features alteration |
885 | 885 |
/// notifier interface for the digraph structure. This implements |
886 | 886 |
/// an observer-notifier pattern for each digraph item. More |
887 | 887 |
/// obsevers can be registered into the notifier and whenever an |
888 | 888 |
/// alteration occured in the digraph all the observers will |
889 | 889 |
/// notified about it. |
890 | 890 |
template <typename _Base = BaseDigraphComponent> |
891 | 891 |
class AlterableDigraphComponent : public _Base { |
892 | 892 |
public: |
893 | 893 |
|
894 | 894 |
typedef _Base Base; |
895 | 895 |
typedef typename Base::Node Node; |
896 | 896 |
typedef typename Base::Arc Arc; |
897 | 897 |
|
898 | 898 |
|
899 | 899 |
/// The node observer registry. |
900 | 900 |
typedef AlterationNotifier<AlterableDigraphComponent, Node> |
901 | 901 |
NodeNotifier; |
902 | 902 |
/// The arc observer registry. |
903 | 903 |
typedef AlterationNotifier<AlterableDigraphComponent, Arc> |
904 | 904 |
ArcNotifier; |
905 | 905 |
|
906 | 906 |
/// \brief Gives back the node alteration notifier. |
907 | 907 |
/// |
908 | 908 |
/// Gives back the node alteration notifier. |
909 | 909 |
NodeNotifier& notifier(Node) const { |
910 | 910 |
return NodeNotifier(); |
911 | 911 |
} |
912 | 912 |
|
913 | 913 |
/// \brief Gives back the arc alteration notifier. |
914 | 914 |
/// |
915 | 915 |
/// Gives back the arc alteration notifier. |
916 | 916 |
ArcNotifier& notifier(Arc) const { |
917 | 917 |
return ArcNotifier(); |
918 | 918 |
} |
919 | 919 |
|
0 comments (0 inline)