0
2
0
1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2007 |
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_CONCEPT_DIGRAPH_H |
20 | 20 |
#define LEMON_CONCEPT_DIGRAPH_H |
21 | 21 |
|
22 | 22 |
///\ingroup graph_concepts |
23 | 23 |
///\file |
24 | 24 |
///\brief The concept of directed graphs. |
25 | 25 |
|
26 | 26 |
#include <lemon/bits/invalid.h> |
27 | 27 |
#include <lemon/bits/utility.h> |
28 | 28 |
#include <lemon/concepts/maps.h> |
29 | 29 |
#include <lemon/concept_check.h> |
30 | 30 |
#include <lemon/concepts/graph_components.h> |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
namespace concepts { |
34 | 34 |
|
35 | 35 |
/// \ingroup graph_concepts |
36 | 36 |
/// |
37 | 37 |
/// \brief Class describing the concept of directed graphs. |
38 | 38 |
/// |
39 | 39 |
/// This class describes the \ref concept "concept" of the |
40 | 40 |
/// immutable directed digraphs. |
41 | 41 |
/// |
42 | 42 |
/// Note that actual digraph implementation like @ref ListDigraph or |
43 | 43 |
/// @ref SmartDigraph may have several additional functionality. |
44 | 44 |
/// |
45 | 45 |
/// \sa concept |
46 | 46 |
class Digraph { |
47 | 47 |
private: |
48 | 48 |
///Digraphs are \e not copy constructible. Use DigraphCopy() instead. |
49 | 49 |
|
50 | 50 |
///Digraphs are \e not copy constructible. Use DigraphCopy() instead. |
51 | 51 |
/// |
52 | 52 |
Digraph(const Digraph &) {}; |
53 | 53 |
///\brief Assignment of \ref Digraph "Digraph"s to another ones are |
54 | 54 |
///\e not allowed. Use DigraphCopy() instead. |
55 | 55 |
|
56 | 56 |
///Assignment of \ref Digraph "Digraph"s to another ones are |
57 | 57 |
///\e not allowed. Use DigraphCopy() instead. |
58 | 58 |
|
59 | 59 |
void operator=(const Digraph &) {} |
60 | 60 |
public: |
61 | 61 |
///\e |
62 | 62 |
|
63 | 63 |
/// Defalult constructor. |
64 | 64 |
|
65 | 65 |
/// Defalult constructor. |
66 | 66 |
/// |
67 | 67 |
Digraph() { } |
68 | 68 |
/// Class for identifying a node of the digraph |
69 | 69 |
|
70 | 70 |
/// This class identifies a node of the digraph. It also serves |
71 | 71 |
/// as a base class of the node iterators, |
72 | 72 |
/// thus they will convert to this type. |
73 | 73 |
class Node { |
74 | 74 |
public: |
75 | 75 |
/// Default constructor |
76 | 76 |
|
77 | 77 |
/// @warning The default constructor sets the iterator |
78 | 78 |
/// to an undefined value. |
79 | 79 |
Node() { } |
80 | 80 |
/// Copy constructor. |
81 | 81 |
|
82 | 82 |
/// Copy constructor. |
83 | 83 |
/// |
84 | 84 |
Node(const Node&) { } |
85 | 85 |
|
86 | 86 |
/// Invalid constructor \& conversion. |
87 | 87 |
|
88 | 88 |
/// This constructor initializes the iterator to be invalid. |
89 | 89 |
/// \sa Invalid for more details. |
90 | 90 |
Node(Invalid) { } |
91 | 91 |
/// Equality operator |
92 | 92 |
|
93 | 93 |
/// Two iterators are equal if and only if they point to the |
94 | 94 |
/// same object or both are invalid. |
95 | 95 |
bool operator==(Node) const { return true; } |
96 | 96 |
|
97 | 97 |
/// Inequality operator |
98 | 98 |
|
99 | 99 |
/// \sa operator==(Node n) |
100 | 100 |
/// |
101 | 101 |
bool operator!=(Node) const { return true; } |
102 | 102 |
|
103 | 103 |
/// Artificial ordering operator. |
104 | 104 |
|
105 | 105 |
/// To allow the use of digraph descriptors as key type in std::map or |
106 | 106 |
/// similar associative container we require this. |
107 | 107 |
/// |
108 | 108 |
/// \note This operator only have to define some strict ordering of |
109 | 109 |
/// the items; this order has nothing to do with the iteration |
110 | 110 |
/// ordering of the items. |
111 | 111 |
bool operator<(Node) const { return false; } |
112 | 112 |
|
113 | 113 |
}; |
114 | 114 |
|
115 | 115 |
/// This iterator goes through each node. |
116 | 116 |
|
117 | 117 |
/// This iterator goes through each node. |
118 | 118 |
/// Its usage is quite simple, for example you can count the number |
119 | 119 |
/// of nodes in digraph \c g of type \c Digraph like this: |
120 | 120 |
///\code |
121 | 121 |
/// int count=0; |
122 | 122 |
/// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count; |
123 | 123 |
///\endcode |
124 | 124 |
class NodeIt : public Node { |
125 | 125 |
public: |
126 | 126 |
/// Default constructor |
127 | 127 |
|
128 | 128 |
/// @warning The default constructor sets the iterator |
129 | 129 |
/// to an undefined value. |
130 | 130 |
NodeIt() { } |
131 | 131 |
/// Copy constructor. |
132 | 132 |
|
133 | 133 |
/// Copy constructor. |
134 | 134 |
/// |
135 | 135 |
NodeIt(const NodeIt& n) : Node(n) { } |
136 | 136 |
/// Invalid constructor \& conversion. |
137 | 137 |
|
138 | 138 |
/// Initialize the iterator to be invalid. |
139 | 139 |
/// \sa Invalid for more details. |
140 | 140 |
NodeIt(Invalid) { } |
141 | 141 |
/// Sets the iterator to the first node. |
142 | 142 |
|
143 | 143 |
/// Sets the iterator to the first node of \c g. |
144 | 144 |
/// |
145 | 145 |
NodeIt(const Digraph&) { } |
146 | 146 |
/// Node -> NodeIt conversion. |
147 | 147 |
|
148 | 148 |
/// Sets the iterator to the node of \c the digraph pointed by |
149 | 149 |
/// the trivial iterator. |
150 | 150 |
/// This feature necessitates that each time we |
151 | 151 |
/// iterate the arc-set, the iteration order is the same. |
152 | 152 |
NodeIt(const Digraph&, const Node&) { } |
153 | 153 |
/// Next node. |
154 | 154 |
|
155 | 155 |
/// Assign the iterator to the next node. |
156 | 156 |
/// |
157 | 157 |
NodeIt& operator++() { return *this; } |
158 | 158 |
}; |
159 | 159 |
|
160 | 160 |
|
161 | 161 |
/// Class for identifying an arc of the digraph |
162 | 162 |
|
163 | 163 |
/// This class identifies an arc of the digraph. It also serves |
164 | 164 |
/// as a base class of the arc iterators, |
165 | 165 |
/// thus they will convert to this type. |
166 | 166 |
class Arc { |
167 | 167 |
public: |
168 | 168 |
/// Default constructor |
169 | 169 |
|
170 | 170 |
/// @warning The default constructor sets the iterator |
171 | 171 |
/// to an undefined value. |
172 | 172 |
Arc() { } |
173 | 173 |
/// Copy constructor. |
174 | 174 |
|
175 | 175 |
/// Copy constructor. |
176 | 176 |
/// |
177 | 177 |
Arc(const Arc&) { } |
178 | 178 |
/// Initialize the iterator to be invalid. |
179 | 179 |
|
180 | 180 |
/// Initialize the iterator to be invalid. |
181 | 181 |
/// |
182 | 182 |
Arc(Invalid) { } |
183 | 183 |
/// Equality operator |
184 | 184 |
|
185 | 185 |
/// Two iterators are equal if and only if they point to the |
186 | 186 |
/// same object or both are invalid. |
187 | 187 |
bool operator==(Arc) const { return true; } |
188 | 188 |
/// Inequality operator |
189 | 189 |
|
190 | 190 |
/// \sa operator==(Arc n) |
191 | 191 |
/// |
192 | 192 |
bool operator!=(Arc) const { return true; } |
193 | 193 |
|
194 | 194 |
/// Artificial ordering operator. |
195 | 195 |
|
196 | 196 |
/// To allow the use of digraph descriptors as key type in std::map or |
197 | 197 |
/// similar associative container we require this. |
198 | 198 |
/// |
199 | 199 |
/// \note This operator only have to define some strict ordering of |
200 | 200 |
/// the items; this order has nothing to do with the iteration |
201 | 201 |
/// ordering of the items. |
202 | 202 |
bool operator<(Arc) const { return false; } |
203 | 203 |
}; |
204 | 204 |
|
205 | 205 |
/// This iterator goes trough the outgoing arcs of a node. |
206 | 206 |
|
207 | 207 |
/// This iterator goes trough the \e outgoing arcs of a certain node |
208 | 208 |
/// of a digraph. |
209 | 209 |
/// Its usage is quite simple, for example you can count the number |
210 | 210 |
/// of outgoing arcs of a node \c n |
211 | 211 |
/// in digraph \c g of type \c Digraph as follows. |
212 | 212 |
///\code |
213 | 213 |
/// int count=0; |
214 | 214 |
/// for (Digraph::OutArcIt e(g, n); e!=INVALID; ++e) ++count; |
215 | 215 |
///\endcode |
216 | 216 |
|
217 | 217 |
class OutArcIt : public Arc { |
218 | 218 |
public: |
219 | 219 |
/// Default constructor |
220 | 220 |
|
221 | 221 |
/// @warning The default constructor sets the iterator |
222 | 222 |
/// to an undefined value. |
223 | 223 |
OutArcIt() { } |
224 | 224 |
/// Copy constructor. |
225 | 225 |
|
226 | 226 |
/// Copy constructor. |
227 | 227 |
/// |
228 | 228 |
OutArcIt(const OutArcIt& e) : Arc(e) { } |
229 | 229 |
/// Initialize the iterator to be invalid. |
230 | 230 |
|
231 | 231 |
/// Initialize the iterator to be invalid. |
232 | 232 |
/// |
233 | 233 |
OutArcIt(Invalid) { } |
234 | 234 |
/// This constructor sets the iterator to the first outgoing arc. |
235 | 235 |
|
236 | 236 |
/// This constructor sets the iterator to the first outgoing arc of |
237 | 237 |
/// the node. |
238 | 238 |
OutArcIt(const Digraph&, const Node&) { } |
239 | 239 |
/// Arc -> OutArcIt conversion |
240 | 240 |
|
241 | 241 |
/// Sets the iterator to the value of the trivial iterator. |
242 | 242 |
/// This feature necessitates that each time we |
243 | 243 |
/// iterate the arc-set, the iteration order is the same. |
244 | 244 |
OutArcIt(const Digraph&, const Arc&) { } |
245 | 245 |
///Next outgoing arc |
246 | 246 |
|
247 | 247 |
/// Assign the iterator to the next |
248 | 248 |
/// outgoing arc of the corresponding node. |
249 | 249 |
OutArcIt& operator++() { return *this; } |
250 | 250 |
}; |
251 | 251 |
|
252 | 252 |
/// This iterator goes trough the incoming arcs of a node. |
253 | 253 |
|
254 | 254 |
/// This iterator goes trough the \e incoming arcs of a certain node |
255 | 255 |
/// of a digraph. |
256 | 256 |
/// Its usage is quite simple, for example you can count the number |
257 | 257 |
/// of outgoing arcs of a node \c n |
258 | 258 |
/// in digraph \c g of type \c Digraph as follows. |
259 | 259 |
///\code |
260 | 260 |
/// int count=0; |
261 | 261 |
/// for(Digraph::InArcIt e(g, n); e!=INVALID; ++e) ++count; |
262 | 262 |
///\endcode |
263 | 263 |
|
264 | 264 |
class InArcIt : public Arc { |
265 | 265 |
public: |
266 | 266 |
/// Default constructor |
267 | 267 |
|
268 | 268 |
/// @warning The default constructor sets the iterator |
269 | 269 |
/// to an undefined value. |
270 | 270 |
InArcIt() { } |
271 | 271 |
/// Copy constructor. |
272 | 272 |
|
273 | 273 |
/// Copy constructor. |
274 | 274 |
/// |
275 | 275 |
InArcIt(const InArcIt& e) : Arc(e) { } |
276 | 276 |
/// Initialize the iterator to be invalid. |
277 | 277 |
|
278 | 278 |
/// Initialize the iterator to be invalid. |
279 | 279 |
/// |
280 | 280 |
InArcIt(Invalid) { } |
281 | 281 |
/// This constructor sets the iterator to first incoming arc. |
282 | 282 |
|
283 | 283 |
/// This constructor set the iterator to the first incoming arc of |
284 | 284 |
/// the node. |
285 | 285 |
InArcIt(const Digraph&, const Node&) { } |
286 | 286 |
/// Arc -> InArcIt conversion |
287 | 287 |
|
288 | 288 |
/// Sets the iterator to the value of the trivial iterator \c e. |
289 | 289 |
/// This feature necessitates that each time we |
290 | 290 |
/// iterate the arc-set, the iteration order is the same. |
291 | 291 |
InArcIt(const Digraph&, const Arc&) { } |
292 | 292 |
/// Next incoming arc |
293 | 293 |
|
294 | 294 |
/// Assign the iterator to the next inarc of the corresponding node. |
295 | 295 |
/// |
296 | 296 |
InArcIt& operator++() { return *this; } |
297 | 297 |
}; |
298 | 298 |
/// This iterator goes through each arc. |
299 | 299 |
|
300 | 300 |
/// This iterator goes through each arc of a digraph. |
301 | 301 |
/// Its usage is quite simple, for example you can count the number |
302 | 302 |
/// of arcs in a digraph \c g of type \c Digraph as follows: |
303 | 303 |
///\code |
304 | 304 |
/// int count=0; |
305 | 305 |
/// for(Digraph::ArcIt e(g); e!=INVALID; ++e) ++count; |
306 | 306 |
///\endcode |
307 | 307 |
class ArcIt : public Arc { |
308 | 308 |
public: |
309 | 309 |
/// Default constructor |
310 | 310 |
|
311 | 311 |
/// @warning The default constructor sets the iterator |
312 | 312 |
/// to an undefined value. |
313 | 313 |
ArcIt() { } |
314 | 314 |
/// Copy constructor. |
315 | 315 |
|
316 | 316 |
/// Copy constructor. |
317 | 317 |
/// |
318 | 318 |
ArcIt(const ArcIt& e) : Arc(e) { } |
319 | 319 |
/// Initialize the iterator to be invalid. |
320 | 320 |
|
321 | 321 |
/// Initialize the iterator to be invalid. |
322 | 322 |
/// |
323 | 323 |
ArcIt(Invalid) { } |
324 | 324 |
/// This constructor sets the iterator to the first arc. |
325 | 325 |
|
326 | 326 |
/// This constructor sets the iterator to the first arc of \c g. |
327 | 327 |
///@param g the digraph |
328 | 328 |
ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); } |
329 | 329 |
/// Arc -> ArcIt conversion |
330 | 330 |
|
331 | 331 |
/// Sets the iterator to the value of the trivial iterator \c e. |
332 | 332 |
/// This feature necessitates that each time we |
333 | 333 |
/// iterate the arc-set, the iteration order is the same. |
334 | 334 |
ArcIt(const Digraph&, const Arc&) { } |
335 | 335 |
///Next arc |
336 | 336 |
|
337 | 337 |
/// Assign the iterator to the next arc. |
338 | 338 |
ArcIt& operator++() { return *this; } |
339 | 339 |
}; |
340 | 340 |
///Gives back the target node of an arc. |
341 | 341 |
|
342 | 342 |
///Gives back the target node of an arc. |
343 | 343 |
/// |
344 | 344 |
Node target(Arc) const { return INVALID; } |
345 | 345 |
///Gives back the source node of an arc. |
346 | 346 |
|
347 | 347 |
///Gives back the source node of an arc. |
348 | 348 |
/// |
349 | 349 |
Node source(Arc) const { return INVALID; } |
350 | 350 |
|
351 |
/// \brief Returns the ID of the node. |
|
352 |
int id(Node) const { return -1; } |
|
353 |
|
|
354 |
/// \brief Returns the ID of the arc. |
|
355 |
int id(Arc) const { return -1; } |
|
356 |
|
|
357 |
/// \brief Returns the node with the given ID. |
|
358 |
/// |
|
359 |
/// \pre The argument should be a valid node ID in the graph. |
|
360 |
Node nodeFromId(int) const { return INVALID; } |
|
361 |
|
|
362 |
/// \brief Returns the arc with the given ID. |
|
363 |
/// |
|
364 |
/// \pre The argument should be a valid arc ID in the graph. |
|
365 |
Arc arcFromId(int) const { return INVALID; } |
|
366 |
|
|
367 |
/// \brief Returns an upper bound on the node IDs. |
|
368 |
int maxNodeId() const { return -1; } |
|
369 |
|
|
370 |
/// \brief Returns an upper bound on the arc IDs. |
|
371 |
int maxArcId() const { return -1; } |
|
372 |
|
|
351 | 373 |
void first(Node&) const {} |
352 | 374 |
void next(Node&) const {} |
353 | 375 |
|
354 | 376 |
void first(Arc&) const {} |
355 | 377 |
void next(Arc&) const {} |
356 | 378 |
|
357 | 379 |
|
358 | 380 |
void firstIn(Arc&, const Node&) const {} |
359 | 381 |
void nextIn(Arc&) const {} |
360 | 382 |
|
361 | 383 |
void firstOut(Arc&, const Node&) const {} |
362 | 384 |
void nextOut(Arc&) const {} |
363 | 385 |
|
386 |
// The second parameter is dummy. |
|
387 |
Node fromId(int, Node) const { return INVALID; } |
|
388 |
// The second parameter is dummy. |
|
389 |
Arc fromId(int, Arc) const { return INVALID; } |
|
390 |
|
|
391 |
// Dummy parameter. |
|
392 |
int maxId(Node) const { return -1; } |
|
393 |
// Dummy parameter. |
|
394 |
int maxId(Arc) const { return -1; } |
|
395 |
|
|
364 | 396 |
/// \brief The base node of the iterator. |
365 | 397 |
/// |
366 | 398 |
/// Gives back the base node of the iterator. |
367 | 399 |
/// It is always the target of the pointed arc. |
368 | 400 |
Node baseNode(const InArcIt&) const { return INVALID; } |
369 | 401 |
|
370 | 402 |
/// \brief The running node of the iterator. |
371 | 403 |
/// |
372 | 404 |
/// Gives back the running node of the iterator. |
373 | 405 |
/// It is always the source of the pointed arc. |
374 | 406 |
Node runningNode(const InArcIt&) const { return INVALID; } |
375 | 407 |
|
376 | 408 |
/// \brief The base node of the iterator. |
377 | 409 |
/// |
378 | 410 |
/// Gives back the base node of the iterator. |
379 | 411 |
/// It is always the source of the pointed arc. |
380 | 412 |
Node baseNode(const OutArcIt&) const { return INVALID; } |
381 | 413 |
|
382 | 414 |
/// \brief The running node of the iterator. |
383 | 415 |
/// |
384 | 416 |
/// Gives back the running node of the iterator. |
385 | 417 |
/// It is always the target of the pointed arc. |
386 | 418 |
Node runningNode(const OutArcIt&) const { return INVALID; } |
387 | 419 |
|
388 | 420 |
/// \brief The opposite node on the given arc. |
389 | 421 |
/// |
390 | 422 |
/// Gives back the opposite node on the given arc. |
391 | 423 |
Node oppositeNode(const Node&, const Arc&) const { return INVALID; } |
392 | 424 |
|
393 | 425 |
/// \brief Read write map of the nodes to type \c T. |
394 | 426 |
/// |
395 | 427 |
/// ReadWrite map of the nodes to type \c T. |
396 | 428 |
/// \sa Reference |
397 | 429 |
template<class T> |
398 | 430 |
class NodeMap : public ReadWriteMap< Node, T > { |
399 | 431 |
public: |
400 | 432 |
|
401 | 433 |
///\e |
402 | 434 |
NodeMap(const Digraph&) { } |
403 | 435 |
///\e |
404 | 436 |
NodeMap(const Digraph&, T) { } |
405 | 437 |
|
406 | 438 |
///Copy constructor |
407 | 439 |
NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } |
408 | 440 |
///Assignment operator |
409 | 441 |
template <typename CMap> |
410 | 442 |
NodeMap& operator=(const CMap&) { |
411 | 443 |
checkConcept<ReadMap<Node, T>, CMap>(); |
412 | 444 |
return *this; |
413 | 445 |
} |
414 | 446 |
}; |
415 | 447 |
|
416 | 448 |
/// \brief Read write map of the arcs to type \c T. |
417 | 449 |
/// |
418 | 450 |
/// Reference map of the arcs to type \c T. |
419 | 451 |
/// \sa Reference |
420 | 452 |
template<class T> |
421 | 453 |
class ArcMap : public ReadWriteMap<Arc,T> { |
422 | 454 |
public: |
423 | 455 |
|
424 | 456 |
///\e |
425 | 457 |
ArcMap(const Digraph&) { } |
426 | 458 |
///\e |
427 | 459 |
ArcMap(const Digraph&, T) { } |
428 | 460 |
///Copy constructor |
429 | 461 |
ArcMap(const ArcMap& em) : ReadWriteMap<Arc,T>(em) { } |
430 | 462 |
///Assignment operator |
431 | 463 |
template <typename CMap> |
432 | 464 |
ArcMap& operator=(const CMap&) { |
433 | 465 |
checkConcept<ReadMap<Arc, T>, CMap>(); |
434 | 466 |
return *this; |
435 | 467 |
} |
436 | 468 |
}; |
437 | 469 |
|
438 | 470 |
template <typename RDigraph> |
439 | 471 |
struct Constraints { |
440 | 472 |
void constraints() { |
441 | 473 |
checkConcept<IterableDigraphComponent<>, Digraph>(); |
474 |
checkConcept<IDableDigraphComponent<>, Digraph>(); |
|
442 | 475 |
checkConcept<MappableDigraphComponent<>, Digraph>(); |
443 | 476 |
} |
444 | 477 |
}; |
445 | 478 |
|
446 | 479 |
}; |
447 | 480 |
|
448 | 481 |
} //namespace concepts |
449 | 482 |
} //namespace lemon |
450 | 483 |
|
451 | 484 |
|
452 | 485 |
|
453 | 486 |
#endif // LEMON_CONCEPT_DIGRAPH_H |
... | ... |
@@ -243,460 +243,507 @@ |
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 | 273 |
/// for(Graph::IncArcIt e(g, n); e!=INVALID; ++e) ++count; |
274 | 274 |
///\endcode |
275 | 275 |
class IncArcIt : 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 |
IncArcIt() { } |
282 | 282 |
/// Copy constructor. |
283 | 283 |
|
284 | 284 |
/// Copy constructor. |
285 | 285 |
/// |
286 | 286 |
IncArcIt(const IncArcIt& 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 |
IncArcIt(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 | 296 |
IncArcIt(const Graph&, const Node&) { } |
297 | 297 |
/// Edge -> IncArcIt 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 |
IncArcIt(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 |
IncArcIt& 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 |
|
356 | 356 |
/// This iterator goes through each arc of a graph. |
357 | 357 |
/// Its usage is quite simple, for example you can count the number |
358 | 358 |
/// of arcs in a graph \c g of type \c Graph as follows: |
359 | 359 |
///\code |
360 | 360 |
/// int count=0; |
361 | 361 |
/// for(Graph::ArcIt e(g); e!=INVALID; ++e) ++count; |
362 | 362 |
///\endcode |
363 | 363 |
class ArcIt : public Arc { |
364 | 364 |
public: |
365 | 365 |
/// Default constructor |
366 | 366 |
|
367 | 367 |
/// @warning The default constructor sets the iterator |
368 | 368 |
/// to an undefined value. |
369 | 369 |
ArcIt() { } |
370 | 370 |
/// Copy constructor. |
371 | 371 |
|
372 | 372 |
/// Copy constructor. |
373 | 373 |
/// |
374 | 374 |
ArcIt(const ArcIt& e) : Arc(e) { } |
375 | 375 |
/// Initialize the iterator to be invalid. |
376 | 376 |
|
377 | 377 |
/// Initialize the iterator to be invalid. |
378 | 378 |
/// |
379 | 379 |
ArcIt(Invalid) { } |
380 | 380 |
/// This constructor sets the iterator to the first arc. |
381 | 381 |
|
382 | 382 |
/// This constructor sets the iterator to the first arc of \c g. |
383 | 383 |
///@param g the graph |
384 | 384 |
ArcIt(const Graph &g) { ignore_unused_variable_warning(g); } |
385 | 385 |
/// Arc -> ArcIt conversion |
386 | 386 |
|
387 | 387 |
/// Sets the iterator to the value of the trivial iterator \c e. |
388 | 388 |
/// This feature necessitates that each time we |
389 | 389 |
/// iterate the arc-set, the iteration order is the same. |
390 | 390 |
ArcIt(const Graph&, const Arc&) { } |
391 | 391 |
///Next arc |
392 | 392 |
|
393 | 393 |
/// Assign the iterator to the next arc. |
394 | 394 |
ArcIt& operator++() { return *this; } |
395 | 395 |
}; |
396 | 396 |
|
397 | 397 |
/// This iterator goes trough the outgoing directed arcs of a node. |
398 | 398 |
|
399 | 399 |
/// This iterator goes trough the \e outgoing arcs of a certain node |
400 | 400 |
/// of a graph. |
401 | 401 |
/// Its usage is quite simple, for example you can count the number |
402 | 402 |
/// of outgoing arcs of a node \c n |
403 | 403 |
/// in graph \c g of type \c Graph as follows. |
404 | 404 |
///\code |
405 | 405 |
/// int count=0; |
406 | 406 |
/// for (Graph::OutArcIt e(g, n); e!=INVALID; ++e) ++count; |
407 | 407 |
///\endcode |
408 | 408 |
|
409 | 409 |
class OutArcIt : public Arc { |
410 | 410 |
public: |
411 | 411 |
/// Default constructor |
412 | 412 |
|
413 | 413 |
/// @warning The default constructor sets the iterator |
414 | 414 |
/// to an undefined value. |
415 | 415 |
OutArcIt() { } |
416 | 416 |
/// Copy constructor. |
417 | 417 |
|
418 | 418 |
/// Copy constructor. |
419 | 419 |
/// |
420 | 420 |
OutArcIt(const OutArcIt& e) : Arc(e) { } |
421 | 421 |
/// Initialize the iterator to be invalid. |
422 | 422 |
|
423 | 423 |
/// Initialize the iterator to be invalid. |
424 | 424 |
/// |
425 | 425 |
OutArcIt(Invalid) { } |
426 | 426 |
/// This constructor sets the iterator to the first outgoing arc. |
427 | 427 |
|
428 | 428 |
/// This constructor sets the iterator to the first outgoing arc of |
429 | 429 |
/// the node. |
430 | 430 |
///@param n the node |
431 | 431 |
///@param g the graph |
432 | 432 |
OutArcIt(const Graph& n, const Node& g) { |
433 | 433 |
ignore_unused_variable_warning(n); |
434 | 434 |
ignore_unused_variable_warning(g); |
435 | 435 |
} |
436 | 436 |
/// Arc -> OutArcIt conversion |
437 | 437 |
|
438 | 438 |
/// Sets the iterator to the value of the trivial iterator. |
439 | 439 |
/// This feature necessitates that each time we |
440 | 440 |
/// iterate the arc-set, the iteration order is the same. |
441 | 441 |
OutArcIt(const Graph&, const Arc&) { } |
442 | 442 |
///Next outgoing arc |
443 | 443 |
|
444 | 444 |
/// Assign the iterator to the next |
445 | 445 |
/// outgoing arc of the corresponding node. |
446 | 446 |
OutArcIt& operator++() { return *this; } |
447 | 447 |
}; |
448 | 448 |
|
449 | 449 |
/// This iterator goes trough the incoming directed arcs of a node. |
450 | 450 |
|
451 | 451 |
/// This iterator goes trough the \e incoming arcs of a certain node |
452 | 452 |
/// of a graph. |
453 | 453 |
/// Its usage is quite simple, for example you can count the number |
454 | 454 |
/// of outgoing arcs of a node \c n |
455 | 455 |
/// in graph \c g of type \c Graph as follows. |
456 | 456 |
///\code |
457 | 457 |
/// int count=0; |
458 | 458 |
/// for(Graph::InArcIt e(g, n); e!=INVALID; ++e) ++count; |
459 | 459 |
///\endcode |
460 | 460 |
|
461 | 461 |
class InArcIt : public Arc { |
462 | 462 |
public: |
463 | 463 |
/// Default constructor |
464 | 464 |
|
465 | 465 |
/// @warning The default constructor sets the iterator |
466 | 466 |
/// to an undefined value. |
467 | 467 |
InArcIt() { } |
468 | 468 |
/// Copy constructor. |
469 | 469 |
|
470 | 470 |
/// Copy constructor. |
471 | 471 |
/// |
472 | 472 |
InArcIt(const InArcIt& e) : Arc(e) { } |
473 | 473 |
/// Initialize the iterator to be invalid. |
474 | 474 |
|
475 | 475 |
/// Initialize the iterator to be invalid. |
476 | 476 |
/// |
477 | 477 |
InArcIt(Invalid) { } |
478 | 478 |
/// This constructor sets the iterator to first incoming arc. |
479 | 479 |
|
480 | 480 |
/// This constructor set the iterator to the first incoming arc of |
481 | 481 |
/// the node. |
482 | 482 |
///@param n the node |
483 | 483 |
///@param g the graph |
484 | 484 |
InArcIt(const Graph& g, const Node& n) { |
485 | 485 |
ignore_unused_variable_warning(n); |
486 | 486 |
ignore_unused_variable_warning(g); |
487 | 487 |
} |
488 | 488 |
/// Arc -> InArcIt conversion |
489 | 489 |
|
490 | 490 |
/// Sets the iterator to the value of the trivial iterator \c e. |
491 | 491 |
/// This feature necessitates that each time we |
492 | 492 |
/// iterate the arc-set, the iteration order is the same. |
493 | 493 |
InArcIt(const Graph&, const Arc&) { } |
494 | 494 |
/// Next incoming arc |
495 | 495 |
|
496 | 496 |
/// Assign the iterator to the next inarc of the corresponding node. |
497 | 497 |
/// |
498 | 498 |
InArcIt& operator++() { return *this; } |
499 | 499 |
}; |
500 | 500 |
|
501 | 501 |
/// \brief Read write map of the nodes to type \c T. |
502 | 502 |
/// |
503 | 503 |
/// ReadWrite map of the nodes to type \c T. |
504 | 504 |
/// \sa Reference |
505 | 505 |
template<class T> |
506 | 506 |
class NodeMap : public ReadWriteMap< Node, T > |
507 | 507 |
{ |
508 | 508 |
public: |
509 | 509 |
|
510 | 510 |
///\e |
511 | 511 |
NodeMap(const Graph&) { } |
512 | 512 |
///\e |
513 | 513 |
NodeMap(const Graph&, T) { } |
514 | 514 |
|
515 | 515 |
///Copy constructor |
516 | 516 |
NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } |
517 | 517 |
///Assignment operator |
518 | 518 |
template <typename CMap> |
519 | 519 |
NodeMap& operator=(const CMap&) { |
520 | 520 |
checkConcept<ReadMap<Node, T>, CMap>(); |
521 | 521 |
return *this; |
522 | 522 |
} |
523 | 523 |
}; |
524 | 524 |
|
525 | 525 |
/// \brief Read write map of the directed arcs to type \c T. |
526 | 526 |
/// |
527 | 527 |
/// Reference map of the directed arcs to type \c T. |
528 | 528 |
/// \sa Reference |
529 | 529 |
template<class T> |
530 | 530 |
class ArcMap : public ReadWriteMap<Arc,T> |
531 | 531 |
{ |
532 | 532 |
public: |
533 | 533 |
|
534 | 534 |
///\e |
535 | 535 |
ArcMap(const Graph&) { } |
536 | 536 |
///\e |
537 | 537 |
ArcMap(const Graph&, T) { } |
538 | 538 |
///Copy constructor |
539 | 539 |
ArcMap(const ArcMap& em) : ReadWriteMap<Arc,T>(em) { } |
540 | 540 |
///Assignment operator |
541 | 541 |
template <typename CMap> |
542 | 542 |
ArcMap& operator=(const CMap&) { |
543 | 543 |
checkConcept<ReadMap<Arc, T>, CMap>(); |
544 | 544 |
return *this; |
545 | 545 |
} |
546 | 546 |
}; |
547 | 547 |
|
548 | 548 |
/// Read write map of the edges to type \c T. |
549 | 549 |
|
550 | 550 |
/// Reference map of the arcs to type \c T. |
551 | 551 |
/// \sa Reference |
552 | 552 |
template<class T> |
553 | 553 |
class EdgeMap : public ReadWriteMap<Edge,T> |
554 | 554 |
{ |
555 | 555 |
public: |
556 | 556 |
|
557 | 557 |
///\e |
558 | 558 |
EdgeMap(const Graph&) { } |
559 | 559 |
///\e |
560 | 560 |
EdgeMap(const Graph&, T) { } |
561 | 561 |
///Copy constructor |
562 | 562 |
EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) {} |
563 | 563 |
///Assignment operator |
564 | 564 |
template <typename CMap> |
565 | 565 |
EdgeMap& operator=(const CMap&) { |
566 | 566 |
checkConcept<ReadMap<Edge, T>, CMap>(); |
567 | 567 |
return *this; |
568 | 568 |
} |
569 | 569 |
}; |
570 | 570 |
|
571 | 571 |
/// \brief Direct the given edge. |
572 | 572 |
/// |
573 | 573 |
/// Direct the given edge. The returned arc source |
574 | 574 |
/// will be the given node. |
575 | 575 |
Arc direct(const Edge&, const Node&) const { |
576 | 576 |
return INVALID; |
577 | 577 |
} |
578 | 578 |
|
579 | 579 |
/// \brief Direct the given edge. |
580 | 580 |
/// |
581 | 581 |
/// Direct the given edge. The returned arc |
582 | 582 |
/// represents the given edge and the direction comes |
583 | 583 |
/// from the bool parameter. The source of the edge and |
584 | 584 |
/// the directed arc is the same when the given bool is true. |
585 | 585 |
Arc direct(const Edge&, bool) const { |
586 | 586 |
return INVALID; |
587 | 587 |
} |
588 | 588 |
|
589 | 589 |
/// \brief Returns true if the arc has default orientation. |
590 | 590 |
/// |
591 | 591 |
/// Returns whether the given directed arc is same orientation as |
592 | 592 |
/// the corresponding edge's default orientation. |
593 | 593 |
bool direction(Arc) const { return true; } |
594 | 594 |
|
595 | 595 |
/// \brief Returns the opposite directed arc. |
596 | 596 |
/// |
597 | 597 |
/// Returns the opposite directed arc. |
598 | 598 |
Arc oppositeArc(Arc) const { return INVALID; } |
599 | 599 |
|
600 | 600 |
/// \brief Opposite node on an arc |
601 | 601 |
/// |
602 | 602 |
/// \return the opposite of the given Node on the given Edge |
603 | 603 |
Node oppositeNode(Node, Edge) const { return INVALID; } |
604 | 604 |
|
605 | 605 |
/// \brief First node of the edge. |
606 | 606 |
/// |
607 | 607 |
/// \return the first node of the given Edge. |
608 | 608 |
/// |
609 | 609 |
/// Naturally edges don't have direction and thus |
610 | 610 |
/// don't have source and target node. But we use these two methods |
611 | 611 |
/// to query the two nodes of the arc. The direction of the arc |
612 | 612 |
/// which arises this way is called the inherent direction of the |
613 | 613 |
/// edge, and is used to define the "default" direction |
614 | 614 |
/// of the directed versions of the arcs. |
615 | 615 |
/// \sa direction |
616 | 616 |
Node u(Edge) const { return INVALID; } |
617 | 617 |
|
618 | 618 |
/// \brief Second node of the edge. |
619 | 619 |
Node v(Edge) const { return INVALID; } |
620 | 620 |
|
621 | 621 |
/// \brief Source node of the directed arc. |
622 | 622 |
Node source(Arc) const { return INVALID; } |
623 | 623 |
|
624 | 624 |
/// \brief Target node of the directed arc. |
625 | 625 |
Node target(Arc) const { return INVALID; } |
626 | 626 |
|
627 |
/// \brief Returns the id of the node. |
|
628 |
int id(Node) const { return -1; } |
|
629 |
|
|
630 |
/// \brief Returns the id of the edge. |
|
631 |
int id(Edge) const { return -1; } |
|
632 |
|
|
633 |
/// \brief Returns the id of the arc. |
|
634 |
int id(Arc) const { return -1; } |
|
635 |
|
|
636 |
/// \brief Returns the node with the given id. |
|
637 |
/// |
|
638 |
/// \pre The argument should be a valid node id in the graph. |
|
639 |
Node nodeFromId(int) const { return INVALID; } |
|
640 |
|
|
641 |
/// \brief Returns the edge with the given id. |
|
642 |
/// |
|
643 |
/// \pre The argument should be a valid edge id in the graph. |
|
644 |
Edge edgeFromId(int) const { return INVALID; } |
|
645 |
|
|
646 |
/// \brief Returns the arc with the given id. |
|
647 |
/// |
|
648 |
/// \pre The argument should be a valid arc id in the graph. |
|
649 |
Arc arcFromId(int) const { return INVALID; } |
|
650 |
|
|
651 |
/// \brief Returns an upper bound on the node IDs. |
|
652 |
int maxNodeId() const { return -1; } |
|
653 |
|
|
654 |
/// \brief Returns an upper bound on the edge IDs. |
|
655 |
int maxEdgeId() const { return -1; } |
|
656 |
|
|
657 |
/// \brief Returns an upper bound on the arc IDs. |
|
658 |
int maxArcId() const { return -1; } |
|
659 |
|
|
627 | 660 |
void first(Node&) const {} |
628 | 661 |
void next(Node&) const {} |
629 | 662 |
|
630 | 663 |
void first(Edge&) const {} |
631 | 664 |
void next(Edge&) const {} |
632 | 665 |
|
633 | 666 |
void first(Arc&) const {} |
634 | 667 |
void next(Arc&) const {} |
635 | 668 |
|
636 | 669 |
void firstOut(Arc&, Node) const {} |
637 | 670 |
void nextOut(Arc&) const {} |
638 | 671 |
|
639 | 672 |
void firstIn(Arc&, Node) const {} |
640 | 673 |
void nextIn(Arc&) const {} |
641 | 674 |
|
642 |
|
|
643 | 675 |
void firstInc(Edge &, bool &, const Node &) const {} |
644 | 676 |
void nextInc(Edge &, bool &) const {} |
645 | 677 |
|
678 |
// The second parameter is dummy. |
|
679 |
Node fromId(int, Node) const { return INVALID; } |
|
680 |
// The second parameter is dummy. |
|
681 |
Edge fromId(int, Edge) const { return INVALID; } |
|
682 |
// The second parameter is dummy. |
|
683 |
Arc fromId(int, Arc) const { return INVALID; } |
|
684 |
|
|
685 |
// Dummy parameter. |
|
686 |
int maxId(Node) const { return -1; } |
|
687 |
// Dummy parameter. |
|
688 |
int maxId(Edge) const { return -1; } |
|
689 |
// Dummy parameter. |
|
690 |
int maxId(Arc) const { return -1; } |
|
691 |
|
|
646 | 692 |
/// \brief Base node of the iterator |
647 | 693 |
/// |
648 | 694 |
/// Returns the base node (the source in this case) of the iterator |
649 | 695 |
Node baseNode(OutArcIt e) const { |
650 | 696 |
return source(e); |
651 | 697 |
} |
652 | 698 |
/// \brief Running node of the iterator |
653 | 699 |
/// |
654 | 700 |
/// Returns the running node (the target in this case) of the |
655 | 701 |
/// iterator |
656 | 702 |
Node runningNode(OutArcIt e) const { |
657 | 703 |
return target(e); |
658 | 704 |
} |
659 | 705 |
|
660 | 706 |
/// \brief Base node of the iterator |
661 | 707 |
/// |
662 | 708 |
/// Returns the base node (the target in this case) of the iterator |
663 | 709 |
Node baseNode(InArcIt e) const { |
664 | 710 |
return target(e); |
665 | 711 |
} |
666 | 712 |
/// \brief Running node of the iterator |
667 | 713 |
/// |
668 | 714 |
/// Returns the running node (the source in this case) of the |
669 | 715 |
/// iterator |
670 | 716 |
Node runningNode(InArcIt e) const { |
671 | 717 |
return source(e); |
672 | 718 |
} |
673 | 719 |
|
674 | 720 |
/// \brief Base node of the iterator |
675 | 721 |
/// |
676 | 722 |
/// Returns the base node of the iterator |
677 | 723 |
Node baseNode(IncArcIt) const { |
678 | 724 |
return INVALID; |
679 | 725 |
} |
680 | 726 |
|
681 | 727 |
/// \brief Running node of the iterator |
682 | 728 |
/// |
683 | 729 |
/// Returns the running node of the iterator |
684 | 730 |
Node runningNode(IncArcIt) const { |
685 | 731 |
return INVALID; |
686 | 732 |
} |
687 | 733 |
|
688 | 734 |
template <typename Graph> |
689 | 735 |
struct Constraints { |
690 | 736 |
void constraints() { |
691 | 737 |
checkConcept<IterableGraphComponent<>, Graph>(); |
738 |
checkConcept<IDableGraphComponent<>, Graph>(); |
|
692 | 739 |
checkConcept<MappableGraphComponent<>, Graph>(); |
693 | 740 |
} |
694 | 741 |
}; |
695 | 742 |
|
696 | 743 |
}; |
697 | 744 |
|
698 | 745 |
} |
699 | 746 |
|
700 | 747 |
} |
701 | 748 |
|
702 | 749 |
#endif |
0 comments (0 inline)