1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
2 | * |
---|
3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
4 | * |
---|
5 | * Copyright (C) 2003-2013 |
---|
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
8 | * |
---|
9 | * Permission to use, modify and distribute this software is granted |
---|
10 | * provided that this copyright notice appears in all copies. For |
---|
11 | * precise terms see the accompanying LICENSE file. |
---|
12 | * |
---|
13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
14 | * express or implied, and with no claim as to its suitability for any |
---|
15 | * purpose. |
---|
16 | * |
---|
17 | */ |
---|
18 | |
---|
19 | ///\ingroup graph_concepts |
---|
20 | ///\file |
---|
21 | ///\brief The concept of undirected graphs. |
---|
22 | |
---|
23 | #ifndef LEMON_CONCEPTS_GRAPH_H |
---|
24 | #define LEMON_CONCEPTS_GRAPH_H |
---|
25 | |
---|
26 | #include <lemon/concepts/graph_components.h> |
---|
27 | #include <lemon/concepts/maps.h> |
---|
28 | #include <lemon/concept_check.h> |
---|
29 | #include <lemon/core.h> |
---|
30 | #include <lemon/bits/stl_iterators.h> |
---|
31 | |
---|
32 | namespace lemon { |
---|
33 | namespace concepts { |
---|
34 | |
---|
35 | /// \ingroup graph_concepts |
---|
36 | /// |
---|
37 | /// \brief Class describing the concept of undirected graphs. |
---|
38 | /// |
---|
39 | /// This class describes the common interface of all undirected |
---|
40 | /// graphs. |
---|
41 | /// |
---|
42 | /// Like all concept classes, it only provides an interface |
---|
43 | /// without any sensible implementation. So any general algorithm for |
---|
44 | /// undirected graphs should compile with this class, but it will not |
---|
45 | /// run properly, of course. |
---|
46 | /// An actual graph implementation like \ref ListGraph or |
---|
47 | /// \ref SmartGraph may have additional functionality. |
---|
48 | /// |
---|
49 | /// The undirected graphs also fulfill the concept of \ref Digraph |
---|
50 | /// "directed graphs", since each edge can also be regarded as two |
---|
51 | /// oppositely directed arcs. |
---|
52 | /// Undirected graphs provide an Edge type for the undirected edges and |
---|
53 | /// an Arc type for the directed arcs. The Arc type is convertible to |
---|
54 | /// Edge or inherited from it, i.e. the corresponding edge can be |
---|
55 | /// obtained from an arc. |
---|
56 | /// EdgeIt and EdgeMap classes can be used for the edges, while ArcIt |
---|
57 | /// and ArcMap classes can be used for the arcs (just like in digraphs). |
---|
58 | /// Both InArcIt and OutArcIt iterates on the same edges but with |
---|
59 | /// opposite direction. IncEdgeIt also iterates on the same edges |
---|
60 | /// as OutArcIt and InArcIt, but it is not convertible to Arc, |
---|
61 | /// only to Edge. |
---|
62 | /// |
---|
63 | /// In LEMON, each undirected edge has an inherent orientation. |
---|
64 | /// Thus it can defined if an arc is forward or backward oriented in |
---|
65 | /// an undirected graph with respect to this default oriantation of |
---|
66 | /// the represented edge. |
---|
67 | /// With the direction() and direct() functions the direction |
---|
68 | /// of an arc can be obtained and set, respectively. |
---|
69 | /// |
---|
70 | /// Only nodes and edges can be added to or removed from an undirected |
---|
71 | /// graph and the corresponding arcs are added or removed automatically. |
---|
72 | /// |
---|
73 | /// \sa Digraph |
---|
74 | class Graph { |
---|
75 | private: |
---|
76 | /// Graphs are \e not copy constructible. Use GraphCopy instead. |
---|
77 | Graph(const Graph&) {} |
---|
78 | /// \brief Assignment of a graph to another one is \e not allowed. |
---|
79 | /// Use GraphCopy instead. |
---|
80 | void operator=(const Graph&) {} |
---|
81 | |
---|
82 | public: |
---|
83 | /// Default constructor. |
---|
84 | Graph() {} |
---|
85 | |
---|
86 | /// \brief Undirected graphs should be tagged with \c UndirectedTag. |
---|
87 | /// |
---|
88 | /// Undirected graphs should be tagged with \c UndirectedTag. |
---|
89 | /// |
---|
90 | /// This tag helps the \c enable_if technics to make compile time |
---|
91 | /// specializations for undirected graphs. |
---|
92 | typedef True UndirectedTag; |
---|
93 | |
---|
94 | /// The node type of the graph |
---|
95 | |
---|
96 | /// This class identifies a node of the graph. It also serves |
---|
97 | /// as a base class of the node iterators, |
---|
98 | /// thus they convert to this type. |
---|
99 | class Node { |
---|
100 | public: |
---|
101 | /// Default constructor |
---|
102 | |
---|
103 | /// Default constructor. |
---|
104 | /// \warning It sets the object to an undefined value. |
---|
105 | Node() { } |
---|
106 | /// Copy constructor. |
---|
107 | |
---|
108 | /// Copy constructor. |
---|
109 | /// |
---|
110 | Node(const Node&) { } |
---|
111 | |
---|
112 | /// %Invalid constructor \& conversion. |
---|
113 | |
---|
114 | /// Initializes the object to be invalid. |
---|
115 | /// \sa Invalid for more details. |
---|
116 | Node(Invalid) { } |
---|
117 | /// Equality operator |
---|
118 | |
---|
119 | /// Equality operator. |
---|
120 | /// |
---|
121 | /// Two iterators are equal if and only if they point to the |
---|
122 | /// same object or both are \c INVALID. |
---|
123 | bool operator==(Node) const { return true; } |
---|
124 | |
---|
125 | /// Inequality operator |
---|
126 | |
---|
127 | /// Inequality operator. |
---|
128 | bool operator!=(Node) const { return true; } |
---|
129 | |
---|
130 | /// Artificial ordering operator. |
---|
131 | |
---|
132 | /// Artificial ordering operator. |
---|
133 | /// |
---|
134 | /// \note This operator only has to define some strict ordering of |
---|
135 | /// the items; this order has nothing to do with the iteration |
---|
136 | /// ordering of the items. |
---|
137 | bool operator<(Node) const { return false; } |
---|
138 | |
---|
139 | }; |
---|
140 | |
---|
141 | /// Iterator class for the nodes. |
---|
142 | |
---|
143 | /// This iterator goes through each node of the graph. |
---|
144 | /// Its usage is quite simple, for example, you can count the number |
---|
145 | /// of nodes in a graph \c g of type \c %Graph like this: |
---|
146 | ///\code |
---|
147 | /// int count=0; |
---|
148 | /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count; |
---|
149 | ///\endcode |
---|
150 | class NodeIt : public Node { |
---|
151 | public: |
---|
152 | /// Default constructor |
---|
153 | |
---|
154 | /// Default constructor. |
---|
155 | /// \warning It sets the iterator to an undefined value. |
---|
156 | NodeIt() { } |
---|
157 | /// Copy constructor. |
---|
158 | |
---|
159 | /// Copy constructor. |
---|
160 | /// |
---|
161 | NodeIt(const NodeIt& n) : Node(n) { } |
---|
162 | /// %Invalid constructor \& conversion. |
---|
163 | |
---|
164 | /// Initializes the iterator to be invalid. |
---|
165 | /// \sa Invalid for more details. |
---|
166 | NodeIt(Invalid) { } |
---|
167 | /// Sets the iterator to the first node. |
---|
168 | |
---|
169 | /// Sets the iterator to the first node of the given digraph. |
---|
170 | /// |
---|
171 | explicit NodeIt(const Graph&) { } |
---|
172 | /// Sets the iterator to the given node. |
---|
173 | |
---|
174 | /// Sets the iterator to the given node of the given digraph. |
---|
175 | /// |
---|
176 | NodeIt(const Graph&, const Node&) { } |
---|
177 | /// Next node. |
---|
178 | |
---|
179 | /// Assign the iterator to the next node. |
---|
180 | /// |
---|
181 | NodeIt& operator++() { return *this; } |
---|
182 | }; |
---|
183 | |
---|
184 | /// \brief Gets the collection of the nodes of the graph. |
---|
185 | /// |
---|
186 | /// This function can be used for iterating on |
---|
187 | /// the nodes of the graph. It returns a wrapped NodeIt, which looks |
---|
188 | /// like an STL container (by having begin() and end()) |
---|
189 | /// which you can use in range-based for loops, STL algorithms, etc. |
---|
190 | /// For example you can write: |
---|
191 | ///\code |
---|
192 | /// ListGraph g; |
---|
193 | /// for(auto v: g.nodes()) |
---|
194 | /// doSomething(v); |
---|
195 | /// |
---|
196 | /// //Using an STL algorithm: |
---|
197 | /// copy(g.nodes().begin(), g.nodes().end(), vect.begin()); |
---|
198 | ///\endcode |
---|
199 | LemonRangeWrapper1<NodeIt, Graph> nodes() const { |
---|
200 | return LemonRangeWrapper1<NodeIt, Graph>(*this); |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | /// The edge type of the graph |
---|
205 | |
---|
206 | /// This class identifies an edge of the graph. It also serves |
---|
207 | /// as a base class of the edge iterators, |
---|
208 | /// thus they will convert to this type. |
---|
209 | class Edge { |
---|
210 | public: |
---|
211 | /// Default constructor |
---|
212 | |
---|
213 | /// Default constructor. |
---|
214 | /// \warning It sets the object to an undefined value. |
---|
215 | Edge() { } |
---|
216 | /// Copy constructor. |
---|
217 | |
---|
218 | /// Copy constructor. |
---|
219 | /// |
---|
220 | Edge(const Edge&) { } |
---|
221 | /// %Invalid constructor \& conversion. |
---|
222 | |
---|
223 | /// Initializes the object to be invalid. |
---|
224 | /// \sa Invalid for more details. |
---|
225 | Edge(Invalid) { } |
---|
226 | /// Equality operator |
---|
227 | |
---|
228 | /// Equality operator. |
---|
229 | /// |
---|
230 | /// Two iterators are equal if and only if they point to the |
---|
231 | /// same object or both are \c INVALID. |
---|
232 | bool operator==(Edge) const { return true; } |
---|
233 | /// Inequality operator |
---|
234 | |
---|
235 | /// Inequality operator. |
---|
236 | bool operator!=(Edge) const { return true; } |
---|
237 | |
---|
238 | /// Artificial ordering operator. |
---|
239 | |
---|
240 | /// Artificial ordering operator. |
---|
241 | /// |
---|
242 | /// \note This operator only has to define some strict ordering of |
---|
243 | /// the edges; this order has nothing to do with the iteration |
---|
244 | /// ordering of the edges. |
---|
245 | bool operator<(Edge) const { return false; } |
---|
246 | }; |
---|
247 | |
---|
248 | /// Iterator class for the edges. |
---|
249 | |
---|
250 | /// This iterator goes through each edge of the graph. |
---|
251 | /// Its usage is quite simple, for example, you can count the number |
---|
252 | /// of edges in a graph \c g of type \c %Graph as follows: |
---|
253 | ///\code |
---|
254 | /// int count=0; |
---|
255 | /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count; |
---|
256 | ///\endcode |
---|
257 | class EdgeIt : public Edge { |
---|
258 | public: |
---|
259 | /// Default constructor |
---|
260 | |
---|
261 | /// Default constructor. |
---|
262 | /// \warning It sets the iterator to an undefined value. |
---|
263 | EdgeIt() { } |
---|
264 | /// Copy constructor. |
---|
265 | |
---|
266 | /// Copy constructor. |
---|
267 | /// |
---|
268 | EdgeIt(const EdgeIt& e) : Edge(e) { } |
---|
269 | /// %Invalid constructor \& conversion. |
---|
270 | |
---|
271 | /// Initializes the iterator to be invalid. |
---|
272 | /// \sa Invalid for more details. |
---|
273 | EdgeIt(Invalid) { } |
---|
274 | /// Sets the iterator to the first edge. |
---|
275 | |
---|
276 | /// Sets the iterator to the first edge of the given graph. |
---|
277 | /// |
---|
278 | explicit EdgeIt(const Graph&) { } |
---|
279 | /// Sets the iterator to the given edge. |
---|
280 | |
---|
281 | /// Sets the iterator to the given edge of the given graph. |
---|
282 | /// |
---|
283 | EdgeIt(const Graph&, const Edge&) { } |
---|
284 | /// Next edge |
---|
285 | |
---|
286 | /// Assign the iterator to the next edge. |
---|
287 | /// |
---|
288 | EdgeIt& operator++() { return *this; } |
---|
289 | }; |
---|
290 | |
---|
291 | /// \brief Gets the collection of the edges of the graph. |
---|
292 | /// |
---|
293 | /// This function can be used for iterating on the |
---|
294 | /// edges of the graph. It returns a wrapped |
---|
295 | /// EdgeIt, which looks like an STL container |
---|
296 | /// (by having begin() and end()) which you can use in range-based |
---|
297 | /// for loops, STL algorithms, etc. |
---|
298 | /// For example you can write: |
---|
299 | ///\code |
---|
300 | /// ListGraph g; |
---|
301 | /// for(auto e: g.edges()) |
---|
302 | /// doSomething(e); |
---|
303 | /// |
---|
304 | /// //Using an STL algorithm: |
---|
305 | /// copy(g.edges().begin(), g.edges().end(), vect.begin()); |
---|
306 | ///\endcode |
---|
307 | LemonRangeWrapper1<EdgeIt, Graph> edges() const { |
---|
308 | return LemonRangeWrapper1<EdgeIt, Graph>(*this); |
---|
309 | } |
---|
310 | |
---|
311 | |
---|
312 | /// Iterator class for the incident edges of a node. |
---|
313 | |
---|
314 | /// This iterator goes trough the incident undirected edges |
---|
315 | /// of a certain node of a graph. |
---|
316 | /// Its usage is quite simple, for example, you can compute the |
---|
317 | /// degree (i.e. the number of incident edges) of a node \c n |
---|
318 | /// in a graph \c g of type \c %Graph as follows. |
---|
319 | /// |
---|
320 | ///\code |
---|
321 | /// int count=0; |
---|
322 | /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count; |
---|
323 | ///\endcode |
---|
324 | /// |
---|
325 | /// \warning Loop edges will be iterated twice. |
---|
326 | class IncEdgeIt : public Edge { |
---|
327 | public: |
---|
328 | /// Default constructor |
---|
329 | |
---|
330 | /// Default constructor. |
---|
331 | /// \warning It sets the iterator to an undefined value. |
---|
332 | IncEdgeIt() { } |
---|
333 | /// Copy constructor. |
---|
334 | |
---|
335 | /// Copy constructor. |
---|
336 | /// |
---|
337 | IncEdgeIt(const IncEdgeIt& e) : Edge(e) { } |
---|
338 | /// %Invalid constructor \& conversion. |
---|
339 | |
---|
340 | /// Initializes the iterator to be invalid. |
---|
341 | /// \sa Invalid for more details. |
---|
342 | IncEdgeIt(Invalid) { } |
---|
343 | /// Sets the iterator to the first incident edge. |
---|
344 | |
---|
345 | /// Sets the iterator to the first incident edge of the given node. |
---|
346 | /// |
---|
347 | IncEdgeIt(const Graph&, const Node&) { } |
---|
348 | /// Sets the iterator to the given edge. |
---|
349 | |
---|
350 | /// Sets the iterator to the given edge of the given graph. |
---|
351 | /// |
---|
352 | IncEdgeIt(const Graph&, const Edge&) { } |
---|
353 | /// Next incident edge |
---|
354 | |
---|
355 | /// Assign the iterator to the next incident edge |
---|
356 | /// of the corresponding node. |
---|
357 | IncEdgeIt& operator++() { return *this; } |
---|
358 | }; |
---|
359 | |
---|
360 | /// \brief Gets the collection of the incident undirected edges |
---|
361 | /// of a certain node of the graph. |
---|
362 | /// |
---|
363 | /// This function can be used for iterating on the |
---|
364 | /// incident undirected edges of a certain node of the graph. |
---|
365 | /// It returns a wrapped |
---|
366 | /// IncEdgeIt, which looks like an STL container |
---|
367 | /// (by having begin() and end()) which you can use in range-based |
---|
368 | /// for loops, STL algorithms, etc. |
---|
369 | /// For example if g is a Graph and u is a Node, you can write: |
---|
370 | ///\code |
---|
371 | /// for(auto e: g.incEdges(u)) |
---|
372 | /// doSomething(e); |
---|
373 | /// |
---|
374 | /// //Using an STL algorithm: |
---|
375 | /// copy(g.incEdges(u).begin(), g.incEdges(u).end(), vect.begin()); |
---|
376 | ///\endcode |
---|
377 | LemonRangeWrapper2<IncEdgeIt, Graph, Node> incEdges(const Node& u) const { |
---|
378 | return LemonRangeWrapper2<IncEdgeIt, Graph, Node>(*this, u); |
---|
379 | } |
---|
380 | |
---|
381 | |
---|
382 | /// The arc type of the graph |
---|
383 | |
---|
384 | /// This class identifies a directed arc of the graph. It also serves |
---|
385 | /// as a base class of the arc iterators, |
---|
386 | /// thus they will convert to this type. |
---|
387 | class Arc { |
---|
388 | public: |
---|
389 | /// Default constructor |
---|
390 | |
---|
391 | /// Default constructor. |
---|
392 | /// \warning It sets the object to an undefined value. |
---|
393 | Arc() { } |
---|
394 | /// Copy constructor. |
---|
395 | |
---|
396 | /// Copy constructor. |
---|
397 | /// |
---|
398 | Arc(const Arc&) { } |
---|
399 | /// %Invalid constructor \& conversion. |
---|
400 | |
---|
401 | /// Initializes the object to be invalid. |
---|
402 | /// \sa Invalid for more details. |
---|
403 | Arc(Invalid) { } |
---|
404 | /// Equality operator |
---|
405 | |
---|
406 | /// Equality operator. |
---|
407 | /// |
---|
408 | /// Two iterators are equal if and only if they point to the |
---|
409 | /// same object or both are \c INVALID. |
---|
410 | bool operator==(Arc) const { return true; } |
---|
411 | /// Inequality operator |
---|
412 | |
---|
413 | /// Inequality operator. |
---|
414 | bool operator!=(Arc) const { return true; } |
---|
415 | |
---|
416 | /// Artificial ordering operator. |
---|
417 | |
---|
418 | /// Artificial ordering operator. |
---|
419 | /// |
---|
420 | /// \note This operator only has to define some strict ordering of |
---|
421 | /// the arcs; this order has nothing to do with the iteration |
---|
422 | /// ordering of the arcs. |
---|
423 | bool operator<(Arc) const { return false; } |
---|
424 | |
---|
425 | /// Converison to \c Edge |
---|
426 | |
---|
427 | /// Converison to \c Edge. |
---|
428 | /// |
---|
429 | operator Edge() const { return Edge(); } |
---|
430 | }; |
---|
431 | |
---|
432 | /// Iterator class for the arcs. |
---|
433 | |
---|
434 | /// This iterator goes through each directed arc of the graph. |
---|
435 | /// Its usage is quite simple, for example, you can count the number |
---|
436 | /// of arcs in a graph \c g of type \c %Graph as follows: |
---|
437 | ///\code |
---|
438 | /// int count=0; |
---|
439 | /// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count; |
---|
440 | ///\endcode |
---|
441 | class ArcIt : public Arc { |
---|
442 | public: |
---|
443 | /// Default constructor |
---|
444 | |
---|
445 | /// Default constructor. |
---|
446 | /// \warning It sets the iterator to an undefined value. |
---|
447 | ArcIt() { } |
---|
448 | /// Copy constructor. |
---|
449 | |
---|
450 | /// Copy constructor. |
---|
451 | /// |
---|
452 | ArcIt(const ArcIt& e) : Arc(e) { } |
---|
453 | /// %Invalid constructor \& conversion. |
---|
454 | |
---|
455 | /// Initializes the iterator to be invalid. |
---|
456 | /// \sa Invalid for more details. |
---|
457 | ArcIt(Invalid) { } |
---|
458 | /// Sets the iterator to the first arc. |
---|
459 | |
---|
460 | /// Sets the iterator to the first arc of the given graph. |
---|
461 | /// |
---|
462 | explicit ArcIt(const Graph &g) { |
---|
463 | ::lemon::ignore_unused_variable_warning(g); |
---|
464 | } |
---|
465 | /// Sets the iterator to the given arc. |
---|
466 | |
---|
467 | /// Sets the iterator to the given arc of the given graph. |
---|
468 | /// |
---|
469 | ArcIt(const Graph&, const Arc&) { } |
---|
470 | /// Next arc |
---|
471 | |
---|
472 | /// Assign the iterator to the next arc. |
---|
473 | /// |
---|
474 | ArcIt& operator++() { return *this; } |
---|
475 | }; |
---|
476 | |
---|
477 | /// \brief Gets the collection of the directed arcs of the graph. |
---|
478 | /// |
---|
479 | /// This function can be used for iterating on the |
---|
480 | /// arcs of the graph. It returns a wrapped |
---|
481 | /// ArcIt, which looks like an STL container |
---|
482 | /// (by having begin() and end()) which you can use in range-based |
---|
483 | /// for loops, STL algorithms, etc. |
---|
484 | /// For example you can write: |
---|
485 | ///\code |
---|
486 | /// ListGraph g; |
---|
487 | /// for(auto a: g.arcs()) |
---|
488 | /// doSomething(a); |
---|
489 | /// |
---|
490 | /// //Using an STL algorithm: |
---|
491 | /// copy(g.arcs().begin(), g.arcs().end(), vect.begin()); |
---|
492 | ///\endcode |
---|
493 | LemonRangeWrapper1<ArcIt, Graph> arcs() const { |
---|
494 | return LemonRangeWrapper1<ArcIt, Graph>(*this); |
---|
495 | } |
---|
496 | |
---|
497 | |
---|
498 | /// Iterator class for the outgoing arcs of a node. |
---|
499 | |
---|
500 | /// This iterator goes trough the \e outgoing directed arcs of a |
---|
501 | /// certain node of a graph. |
---|
502 | /// Its usage is quite simple, for example, you can count the number |
---|
503 | /// of outgoing arcs of a node \c n |
---|
504 | /// in a graph \c g of type \c %Graph as follows. |
---|
505 | ///\code |
---|
506 | /// int count=0; |
---|
507 | /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count; |
---|
508 | ///\endcode |
---|
509 | class OutArcIt : public Arc { |
---|
510 | public: |
---|
511 | /// Default constructor |
---|
512 | |
---|
513 | /// Default constructor. |
---|
514 | /// \warning It sets the iterator to an undefined value. |
---|
515 | OutArcIt() { } |
---|
516 | /// Copy constructor. |
---|
517 | |
---|
518 | /// Copy constructor. |
---|
519 | /// |
---|
520 | OutArcIt(const OutArcIt& e) : Arc(e) { } |
---|
521 | /// %Invalid constructor \& conversion. |
---|
522 | |
---|
523 | /// Initializes the iterator to be invalid. |
---|
524 | /// \sa Invalid for more details. |
---|
525 | OutArcIt(Invalid) { } |
---|
526 | /// Sets the iterator to the first outgoing arc. |
---|
527 | |
---|
528 | /// Sets the iterator to the first outgoing arc of the given node. |
---|
529 | /// |
---|
530 | OutArcIt(const Graph& n, const Node& g) { |
---|
531 | ::lemon::ignore_unused_variable_warning(n); |
---|
532 | ::lemon::ignore_unused_variable_warning(g); |
---|
533 | } |
---|
534 | /// Sets the iterator to the given arc. |
---|
535 | |
---|
536 | /// Sets the iterator to the given arc of the given graph. |
---|
537 | /// |
---|
538 | OutArcIt(const Graph&, const Arc&) { } |
---|
539 | /// Next outgoing arc |
---|
540 | |
---|
541 | /// Assign the iterator to the next |
---|
542 | /// outgoing arc of the corresponding node. |
---|
543 | OutArcIt& operator++() { return *this; } |
---|
544 | }; |
---|
545 | |
---|
546 | /// \brief Gets the collection of the outgoing directed arcs of a |
---|
547 | /// certain node of the graph. |
---|
548 | /// |
---|
549 | /// This function can be used for iterating on the |
---|
550 | /// outgoing arcs of a certain node of the graph. It returns a wrapped |
---|
551 | /// OutArcIt, which looks like an STL container |
---|
552 | /// (by having begin() and end()) which you can use in range-based |
---|
553 | /// for loops, STL algorithms, etc. |
---|
554 | /// For example if g is a Graph and u is a Node, you can write: |
---|
555 | ///\code |
---|
556 | /// for(auto a: g.outArcs(u)) |
---|
557 | /// doSomething(a); |
---|
558 | /// |
---|
559 | /// //Using an STL algorithm: |
---|
560 | /// copy(g.outArcs(u).begin(), g.outArcs(u).end(), vect.begin()); |
---|
561 | ///\endcode |
---|
562 | LemonRangeWrapper2<OutArcIt, Graph, Node> outArcs(const Node& u) const { |
---|
563 | return LemonRangeWrapper2<OutArcIt, Graph, Node>(*this, u); |
---|
564 | } |
---|
565 | |
---|
566 | |
---|
567 | /// Iterator class for the incoming arcs of a node. |
---|
568 | |
---|
569 | /// This iterator goes trough the \e incoming directed arcs of a |
---|
570 | /// certain node of a graph. |
---|
571 | /// Its usage is quite simple, for example, you can count the number |
---|
572 | /// of incoming arcs of a node \c n |
---|
573 | /// in a graph \c g of type \c %Graph as follows. |
---|
574 | ///\code |
---|
575 | /// int count=0; |
---|
576 | /// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count; |
---|
577 | ///\endcode |
---|
578 | class InArcIt : public Arc { |
---|
579 | public: |
---|
580 | /// Default constructor |
---|
581 | |
---|
582 | /// Default constructor. |
---|
583 | /// \warning It sets the iterator to an undefined value. |
---|
584 | InArcIt() { } |
---|
585 | /// Copy constructor. |
---|
586 | |
---|
587 | /// Copy constructor. |
---|
588 | /// |
---|
589 | InArcIt(const InArcIt& e) : Arc(e) { } |
---|
590 | /// %Invalid constructor \& conversion. |
---|
591 | |
---|
592 | /// Initializes the iterator to be invalid. |
---|
593 | /// \sa Invalid for more details. |
---|
594 | InArcIt(Invalid) { } |
---|
595 | /// Sets the iterator to the first incoming arc. |
---|
596 | |
---|
597 | /// Sets the iterator to the first incoming arc of the given node. |
---|
598 | /// |
---|
599 | InArcIt(const Graph& g, const Node& n) { |
---|
600 | ::lemon::ignore_unused_variable_warning(n); |
---|
601 | ::lemon::ignore_unused_variable_warning(g); |
---|
602 | } |
---|
603 | /// Sets the iterator to the given arc. |
---|
604 | |
---|
605 | /// Sets the iterator to the given arc of the given graph. |
---|
606 | /// |
---|
607 | InArcIt(const Graph&, const Arc&) { } |
---|
608 | /// Next incoming arc |
---|
609 | |
---|
610 | /// Assign the iterator to the next |
---|
611 | /// incoming arc of the corresponding node. |
---|
612 | InArcIt& operator++() { return *this; } |
---|
613 | }; |
---|
614 | |
---|
615 | /// \brief Gets the collection of the incoming directed arcs of |
---|
616 | /// a certain node of the graph. |
---|
617 | /// |
---|
618 | /// This function can be used for iterating on the |
---|
619 | /// incoming directed arcs of a certain node of the graph. It returns |
---|
620 | /// a wrapped InArcIt, which looks like an STL container |
---|
621 | /// (by having begin() and end()) which you can use in range-based |
---|
622 | /// for loops, STL algorithms, etc. |
---|
623 | /// For example if g is a Graph and u is a Node, you can write: |
---|
624 | ///\code |
---|
625 | /// for(auto a: g.inArcs(u)) |
---|
626 | /// doSomething(a); |
---|
627 | /// |
---|
628 | /// //Using an STL algorithm: |
---|
629 | /// copy(g.inArcs(u).begin(), g.inArcs(u).end(), vect.begin()); |
---|
630 | ///\endcode |
---|
631 | LemonRangeWrapper2<InArcIt, Graph, Node> inArcs(const Node& u) const { |
---|
632 | return LemonRangeWrapper2<InArcIt, Graph, Node>(*this, u); |
---|
633 | } |
---|
634 | |
---|
635 | /// \brief Standard graph map type for the nodes. |
---|
636 | /// |
---|
637 | /// Standard graph map type for the nodes. |
---|
638 | /// It conforms to the ReferenceMap concept. |
---|
639 | template<class T> |
---|
640 | class NodeMap : public ReferenceMap<Node, T, T&, const T&> |
---|
641 | { |
---|
642 | public: |
---|
643 | |
---|
644 | /// Constructor |
---|
645 | explicit NodeMap(const Graph&) { } |
---|
646 | /// Constructor with given initial value |
---|
647 | NodeMap(const Graph&, T) { } |
---|
648 | |
---|
649 | private: |
---|
650 | ///Copy constructor |
---|
651 | NodeMap(const NodeMap& nm) : |
---|
652 | ReferenceMap<Node, T, T&, const T&>(nm) { } |
---|
653 | ///Assignment operator |
---|
654 | template <typename CMap> |
---|
655 | NodeMap& operator=(const CMap&) { |
---|
656 | checkConcept<ReadMap<Node, T>, CMap>(); |
---|
657 | return *this; |
---|
658 | } |
---|
659 | }; |
---|
660 | |
---|
661 | /// \brief Standard graph map type for the arcs. |
---|
662 | /// |
---|
663 | /// Standard graph map type for the arcs. |
---|
664 | /// It conforms to the ReferenceMap concept. |
---|
665 | template<class T> |
---|
666 | class ArcMap : public ReferenceMap<Arc, T, T&, const T&> |
---|
667 | { |
---|
668 | public: |
---|
669 | |
---|
670 | /// Constructor |
---|
671 | explicit ArcMap(const Graph&) { } |
---|
672 | /// Constructor with given initial value |
---|
673 | ArcMap(const Graph&, T) { } |
---|
674 | |
---|
675 | private: |
---|
676 | ///Copy constructor |
---|
677 | ArcMap(const ArcMap& em) : |
---|
678 | ReferenceMap<Arc, T, T&, const T&>(em) { } |
---|
679 | ///Assignment operator |
---|
680 | template <typename CMap> |
---|
681 | ArcMap& operator=(const CMap&) { |
---|
682 | checkConcept<ReadMap<Arc, T>, CMap>(); |
---|
683 | return *this; |
---|
684 | } |
---|
685 | }; |
---|
686 | |
---|
687 | /// \brief Standard graph map type for the edges. |
---|
688 | /// |
---|
689 | /// Standard graph map type for the edges. |
---|
690 | /// It conforms to the ReferenceMap concept. |
---|
691 | template<class T> |
---|
692 | class EdgeMap : public ReferenceMap<Edge, T, T&, const T&> |
---|
693 | { |
---|
694 | public: |
---|
695 | |
---|
696 | /// Constructor |
---|
697 | explicit EdgeMap(const Graph&) { } |
---|
698 | /// Constructor with given initial value |
---|
699 | EdgeMap(const Graph&, T) { } |
---|
700 | |
---|
701 | private: |
---|
702 | ///Copy constructor |
---|
703 | EdgeMap(const EdgeMap& em) : |
---|
704 | ReferenceMap<Edge, T, T&, const T&>(em) {} |
---|
705 | ///Assignment operator |
---|
706 | template <typename CMap> |
---|
707 | EdgeMap& operator=(const CMap&) { |
---|
708 | checkConcept<ReadMap<Edge, T>, CMap>(); |
---|
709 | return *this; |
---|
710 | } |
---|
711 | }; |
---|
712 | |
---|
713 | /// \brief The first node of the edge. |
---|
714 | /// |
---|
715 | /// Returns the first node of the given edge. |
---|
716 | /// |
---|
717 | /// Edges don't have source and target nodes, however, methods |
---|
718 | /// u() and v() are used to query the two end-nodes of an edge. |
---|
719 | /// The orientation of an edge that arises this way is called |
---|
720 | /// the inherent direction, it is used to define the default |
---|
721 | /// direction for the corresponding arcs. |
---|
722 | /// \sa v() |
---|
723 | /// \sa direction() |
---|
724 | Node u(Edge) const { return INVALID; } |
---|
725 | |
---|
726 | /// \brief The second node of the edge. |
---|
727 | /// |
---|
728 | /// Returns the second node of the given edge. |
---|
729 | /// |
---|
730 | /// Edges don't have source and target nodes, however, methods |
---|
731 | /// u() and v() are used to query the two end-nodes of an edge. |
---|
732 | /// The orientation of an edge that arises this way is called |
---|
733 | /// the inherent direction, it is used to define the default |
---|
734 | /// direction for the corresponding arcs. |
---|
735 | /// \sa u() |
---|
736 | /// \sa direction() |
---|
737 | Node v(Edge) const { return INVALID; } |
---|
738 | |
---|
739 | /// \brief The source node of the arc. |
---|
740 | /// |
---|
741 | /// Returns the source node of the given arc. |
---|
742 | Node source(Arc) const { return INVALID; } |
---|
743 | |
---|
744 | /// \brief The target node of the arc. |
---|
745 | /// |
---|
746 | /// Returns the target node of the given arc. |
---|
747 | Node target(Arc) const { return INVALID; } |
---|
748 | |
---|
749 | /// \brief The ID of the node. |
---|
750 | /// |
---|
751 | /// Returns the ID of the given node. |
---|
752 | int id(Node) const { return -1; } |
---|
753 | |
---|
754 | /// \brief The ID of the edge. |
---|
755 | /// |
---|
756 | /// Returns the ID of the given edge. |
---|
757 | int id(Edge) const { return -1; } |
---|
758 | |
---|
759 | /// \brief The ID of the arc. |
---|
760 | /// |
---|
761 | /// Returns the ID of the given arc. |
---|
762 | int id(Arc) const { return -1; } |
---|
763 | |
---|
764 | /// \brief The node with the given ID. |
---|
765 | /// |
---|
766 | /// Returns the node with the given ID. |
---|
767 | /// \pre The argument should be a valid node ID in the graph. |
---|
768 | Node nodeFromId(int) const { return INVALID; } |
---|
769 | |
---|
770 | /// \brief The edge with the given ID. |
---|
771 | /// |
---|
772 | /// Returns the edge with the given ID. |
---|
773 | /// \pre The argument should be a valid edge ID in the graph. |
---|
774 | Edge edgeFromId(int) const { return INVALID; } |
---|
775 | |
---|
776 | /// \brief The arc with the given ID. |
---|
777 | /// |
---|
778 | /// Returns the arc with the given ID. |
---|
779 | /// \pre The argument should be a valid arc ID in the graph. |
---|
780 | Arc arcFromId(int) const { return INVALID; } |
---|
781 | |
---|
782 | /// \brief An upper bound on the node IDs. |
---|
783 | /// |
---|
784 | /// Returns an upper bound on the node IDs. |
---|
785 | int maxNodeId() const { return -1; } |
---|
786 | |
---|
787 | /// \brief An upper bound on the edge IDs. |
---|
788 | /// |
---|
789 | /// Returns an upper bound on the edge IDs. |
---|
790 | int maxEdgeId() const { return -1; } |
---|
791 | |
---|
792 | /// \brief An upper bound on the arc IDs. |
---|
793 | /// |
---|
794 | /// Returns an upper bound on the arc IDs. |
---|
795 | int maxArcId() const { return -1; } |
---|
796 | |
---|
797 | /// \brief The direction of the arc. |
---|
798 | /// |
---|
799 | /// Returns \c true if the direction of the given arc is the same as |
---|
800 | /// the inherent orientation of the represented edge. |
---|
801 | bool direction(Arc) const { return true; } |
---|
802 | |
---|
803 | /// \brief Direct the edge. |
---|
804 | /// |
---|
805 | /// Direct the given edge. The returned arc |
---|
806 | /// represents the given edge and its direction comes |
---|
807 | /// from the bool parameter. If it is \c true, then the direction |
---|
808 | /// of the arc is the same as the inherent orientation of the edge. |
---|
809 | Arc direct(Edge, bool) const { |
---|
810 | return INVALID; |
---|
811 | } |
---|
812 | |
---|
813 | /// \brief Direct the edge. |
---|
814 | /// |
---|
815 | /// Direct the given edge. The returned arc represents the given |
---|
816 | /// edge and its source node is the given node. |
---|
817 | Arc direct(Edge, Node) const { |
---|
818 | return INVALID; |
---|
819 | } |
---|
820 | |
---|
821 | /// \brief The oppositely directed arc. |
---|
822 | /// |
---|
823 | /// Returns the oppositely directed arc representing the same edge. |
---|
824 | Arc oppositeArc(Arc) const { return INVALID; } |
---|
825 | |
---|
826 | /// \brief The opposite node on the edge. |
---|
827 | /// |
---|
828 | /// Returns the opposite node on the given edge. |
---|
829 | Node oppositeNode(Node, Edge) const { return INVALID; } |
---|
830 | |
---|
831 | void first(Node&) const {} |
---|
832 | void next(Node&) const {} |
---|
833 | |
---|
834 | void first(Edge&) const {} |
---|
835 | void next(Edge&) const {} |
---|
836 | |
---|
837 | void first(Arc&) const {} |
---|
838 | void next(Arc&) const {} |
---|
839 | |
---|
840 | void firstOut(Arc&, Node) const {} |
---|
841 | void nextOut(Arc&) const {} |
---|
842 | |
---|
843 | void firstIn(Arc&, Node) const {} |
---|
844 | void nextIn(Arc&) const {} |
---|
845 | |
---|
846 | void firstInc(Edge &, bool &, const Node &) const {} |
---|
847 | void nextInc(Edge &, bool &) const {} |
---|
848 | |
---|
849 | // The second parameter is dummy. |
---|
850 | Node fromId(int, Node) const { return INVALID; } |
---|
851 | // The second parameter is dummy. |
---|
852 | Edge fromId(int, Edge) const { return INVALID; } |
---|
853 | // The second parameter is dummy. |
---|
854 | Arc fromId(int, Arc) const { return INVALID; } |
---|
855 | |
---|
856 | // Dummy parameter. |
---|
857 | int maxId(Node) const { return -1; } |
---|
858 | // Dummy parameter. |
---|
859 | int maxId(Edge) const { return -1; } |
---|
860 | // Dummy parameter. |
---|
861 | int maxId(Arc) const { return -1; } |
---|
862 | |
---|
863 | /// \brief The base node of the iterator. |
---|
864 | /// |
---|
865 | /// Returns the base node of the given incident edge iterator. |
---|
866 | Node baseNode(IncEdgeIt) const { return INVALID; } |
---|
867 | |
---|
868 | /// \brief The running node of the iterator. |
---|
869 | /// |
---|
870 | /// Returns the running node of the given incident edge iterator. |
---|
871 | Node runningNode(IncEdgeIt) const { return INVALID; } |
---|
872 | |
---|
873 | /// \brief The base node of the iterator. |
---|
874 | /// |
---|
875 | /// Returns the base node of the given outgoing arc iterator |
---|
876 | /// (i.e. the source node of the corresponding arc). |
---|
877 | Node baseNode(OutArcIt) const { return INVALID; } |
---|
878 | |
---|
879 | /// \brief The running node of the iterator. |
---|
880 | /// |
---|
881 | /// Returns the running node of the given outgoing arc iterator |
---|
882 | /// (i.e. the target node of the corresponding arc). |
---|
883 | Node runningNode(OutArcIt) const { return INVALID; } |
---|
884 | |
---|
885 | /// \brief The base node of the iterator. |
---|
886 | /// |
---|
887 | /// Returns the base node of the given incoming arc iterator |
---|
888 | /// (i.e. the target node of the corresponding arc). |
---|
889 | Node baseNode(InArcIt) const { return INVALID; } |
---|
890 | |
---|
891 | /// \brief The running node of the iterator. |
---|
892 | /// |
---|
893 | /// Returns the running node of the given incoming arc iterator |
---|
894 | /// (i.e. the source node of the corresponding arc). |
---|
895 | Node runningNode(InArcIt) const { return INVALID; } |
---|
896 | |
---|
897 | template <typename _Graph> |
---|
898 | struct Constraints { |
---|
899 | void constraints() { |
---|
900 | checkConcept<BaseGraphComponent, _Graph>(); |
---|
901 | checkConcept<IterableGraphComponent<>, _Graph>(); |
---|
902 | checkConcept<IDableGraphComponent<>, _Graph>(); |
---|
903 | checkConcept<MappableGraphComponent<>, _Graph>(); |
---|
904 | } |
---|
905 | }; |
---|
906 | |
---|
907 | }; |
---|
908 | |
---|
909 | } |
---|
910 | |
---|
911 | } |
---|
912 | |
---|
913 | #endif |
---|