klao@962
|
1 |
/* -*- C++ -*-
|
klao@962
|
2 |
*
|
alpar@1956
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
klao@962
|
4 |
*
|
alpar@1956
|
5 |
* Copyright (C) 2003-2006
|
alpar@1956
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@1956
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
klao@962
|
8 |
*
|
klao@962
|
9 |
* Permission to use, modify and distribute this software is granted
|
klao@962
|
10 |
* provided that this copyright notice appears in all copies. For
|
klao@962
|
11 |
* precise terms see the accompanying LICENSE file.
|
klao@962
|
12 |
*
|
klao@962
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
klao@962
|
14 |
* express or implied, and with no claim as to its suitability for any
|
klao@962
|
15 |
* purpose.
|
klao@962
|
16 |
*
|
klao@962
|
17 |
*/
|
klao@962
|
18 |
|
klao@1030
|
19 |
///\ingroup graph_concepts
|
klao@962
|
20 |
///\file
|
deba@2111
|
21 |
///\brief The concept of the undirected graphs.
|
klao@962
|
22 |
|
klao@962
|
23 |
|
deba@1910
|
24 |
#ifndef LEMON_CONCEPT_UGRAPH_H
|
deba@1910
|
25 |
#define LEMON_CONCEPT_UGRAPH_H
|
klao@962
|
26 |
|
klao@962
|
27 |
#include <lemon/concept/graph_component.h>
|
alpar@1620
|
28 |
#include <lemon/concept/graph.h>
|
deba@1993
|
29 |
#include <lemon/bits/utility.h>
|
klao@962
|
30 |
|
klao@962
|
31 |
namespace lemon {
|
klao@962
|
32 |
namespace concept {
|
klao@962
|
33 |
|
alpar@1620
|
34 |
/// \addtogroup graph_concepts
|
alpar@1620
|
35 |
/// @{
|
alpar@1620
|
36 |
|
alpar@1620
|
37 |
|
klao@1030
|
38 |
/// Class describing the concept of Undirected Graphs.
|
klao@1030
|
39 |
|
klao@1030
|
40 |
/// This class describes the common interface of all Undirected
|
klao@1030
|
41 |
/// Graphs.
|
klao@1030
|
42 |
///
|
klao@1030
|
43 |
/// As all concept describing classes it provides only interface
|
klao@1030
|
44 |
/// without any sensible implementation. So any algorithm for
|
klao@1030
|
45 |
/// undirected graph should compile with this class, but it will not
|
klao@1030
|
46 |
/// run properly, of couse.
|
klao@1030
|
47 |
///
|
klao@1030
|
48 |
/// In LEMON undirected graphs also fulfill the concept of directed
|
deba@2111
|
49 |
/// graphs (\ref lemon::concept::Graph "Graph Concept"). For
|
deba@2111
|
50 |
/// explanation of this and more see also the page \ref graphs,
|
deba@2111
|
51 |
/// a tutorial about graphs.
|
deba@1627
|
52 |
///
|
deba@1627
|
53 |
/// You can assume that all undirected graph can be handled
|
deba@2111
|
54 |
/// as a directed graph. This way it is fully conform
|
deba@2111
|
55 |
/// to the Graph concept.
|
klao@1030
|
56 |
|
klao@1909
|
57 |
class UGraph {
|
klao@1022
|
58 |
public:
|
alpar@1448
|
59 |
///\e
|
alpar@1448
|
60 |
|
alpar@1448
|
61 |
///\todo undocumented
|
alpar@1448
|
62 |
///
|
deba@1979
|
63 |
typedef True UndirectedTag;
|
klao@1022
|
64 |
|
deba@1669
|
65 |
/// \brief The base type of node iterators,
|
deba@1627
|
66 |
/// or in other words, the trivial node iterator.
|
deba@1669
|
67 |
///
|
deba@1627
|
68 |
/// This is the base type of each node iterator,
|
deba@1627
|
69 |
/// thus each kind of node iterator converts to this.
|
deba@1627
|
70 |
/// More precisely each kind of node iterator should be inherited
|
deba@1627
|
71 |
/// from the trivial node iterator.
|
deba@1627
|
72 |
class Node {
|
deba@1627
|
73 |
public:
|
deba@1627
|
74 |
/// Default constructor
|
deba@1627
|
75 |
|
deba@1627
|
76 |
/// @warning The default constructor sets the iterator
|
deba@1627
|
77 |
/// to an undefined value.
|
deba@1627
|
78 |
Node() { }
|
deba@1627
|
79 |
/// Copy constructor.
|
deba@1627
|
80 |
|
deba@1627
|
81 |
/// Copy constructor.
|
deba@1627
|
82 |
///
|
deba@1627
|
83 |
Node(const Node&) { }
|
deba@1627
|
84 |
|
deba@1627
|
85 |
/// Invalid constructor \& conversion.
|
deba@1627
|
86 |
|
deba@1627
|
87 |
/// This constructor initializes the iterator to be invalid.
|
deba@1627
|
88 |
/// \sa Invalid for more details.
|
deba@1627
|
89 |
Node(Invalid) { }
|
deba@1627
|
90 |
/// Equality operator
|
deba@1627
|
91 |
|
deba@1627
|
92 |
/// Two iterators are equal if and only if they point to the
|
deba@1627
|
93 |
/// same object or both are invalid.
|
deba@1627
|
94 |
bool operator==(Node) const { return true; }
|
deba@1627
|
95 |
|
deba@1627
|
96 |
/// Inequality operator
|
deba@1627
|
97 |
|
deba@1627
|
98 |
/// \sa operator==(Node n)
|
deba@1627
|
99 |
///
|
deba@1627
|
100 |
bool operator!=(Node) const { return true; }
|
deba@1627
|
101 |
|
deba@1627
|
102 |
/// Artificial ordering operator.
|
deba@1627
|
103 |
|
deba@1627
|
104 |
/// To allow the use of graph descriptors as key type in std::map or
|
deba@1627
|
105 |
/// similar associative container we require this.
|
deba@1627
|
106 |
///
|
deba@1627
|
107 |
/// \note This operator only have to define some strict ordering of
|
deba@1627
|
108 |
/// the items; this order has nothing to do with the iteration
|
deba@1627
|
109 |
/// ordering of the items.
|
deba@1627
|
110 |
///
|
deba@1627
|
111 |
/// \bug This is a technical requirement. Do we really need this?
|
deba@1627
|
112 |
bool operator<(Node) const { return false; }
|
deba@1627
|
113 |
|
deba@1627
|
114 |
};
|
deba@1627
|
115 |
|
deba@1627
|
116 |
/// This iterator goes through each node.
|
deba@1627
|
117 |
|
deba@1627
|
118 |
/// This iterator goes through each node.
|
deba@1627
|
119 |
/// Its usage is quite simple, for example you can count the number
|
deba@1627
|
120 |
/// of nodes in graph \c g of type \c Graph like this:
|
alpar@1946
|
121 |
///\code
|
deba@1627
|
122 |
/// int count=0;
|
deba@1627
|
123 |
/// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
|
alpar@1946
|
124 |
///\endcode
|
deba@1627
|
125 |
class NodeIt : public Node {
|
deba@1627
|
126 |
public:
|
deba@1627
|
127 |
/// Default constructor
|
deba@1627
|
128 |
|
deba@1627
|
129 |
/// @warning The default constructor sets the iterator
|
deba@1627
|
130 |
/// to an undefined value.
|
deba@1627
|
131 |
NodeIt() { }
|
deba@1627
|
132 |
/// Copy constructor.
|
deba@1627
|
133 |
|
deba@1627
|
134 |
/// Copy constructor.
|
deba@1627
|
135 |
///
|
deba@1627
|
136 |
NodeIt(const NodeIt& n) : Node(n) { }
|
deba@1627
|
137 |
/// Invalid constructor \& conversion.
|
deba@1627
|
138 |
|
deba@1627
|
139 |
/// Initialize the iterator to be invalid.
|
deba@1627
|
140 |
/// \sa Invalid for more details.
|
deba@1627
|
141 |
NodeIt(Invalid) { }
|
deba@1627
|
142 |
/// Sets the iterator to the first node.
|
deba@1627
|
143 |
|
deba@1627
|
144 |
/// Sets the iterator to the first node of \c g.
|
deba@1627
|
145 |
///
|
klao@1909
|
146 |
NodeIt(const UGraph&) { }
|
deba@1627
|
147 |
/// Node -> NodeIt conversion.
|
deba@1627
|
148 |
|
deba@1627
|
149 |
/// Sets the iterator to the node of \c the graph pointed by
|
deba@1627
|
150 |
/// the trivial iterator.
|
deba@1627
|
151 |
/// This feature necessitates that each time we
|
deba@1627
|
152 |
/// iterate the edge-set, the iteration order is the same.
|
klao@1909
|
153 |
NodeIt(const UGraph&, const Node&) { }
|
deba@1627
|
154 |
/// Next node.
|
deba@1627
|
155 |
|
deba@1627
|
156 |
/// Assign the iterator to the next node.
|
deba@1627
|
157 |
///
|
deba@1627
|
158 |
NodeIt& operator++() { return *this; }
|
deba@1627
|
159 |
};
|
deba@1627
|
160 |
|
deba@1627
|
161 |
|
alpar@1620
|
162 |
/// The base type of the undirected edge iterators.
|
deba@1627
|
163 |
|
alpar@1620
|
164 |
/// The base type of the undirected edge iterators.
|
alpar@1620
|
165 |
///
|
klao@1909
|
166 |
class UEdge {
|
alpar@1620
|
167 |
public:
|
alpar@1620
|
168 |
/// Default constructor
|
klao@1030
|
169 |
|
alpar@1620
|
170 |
/// @warning The default constructor sets the iterator
|
alpar@1620
|
171 |
/// to an undefined value.
|
klao@1909
|
172 |
UEdge() { }
|
alpar@1620
|
173 |
/// Copy constructor.
|
klao@1030
|
174 |
|
alpar@1620
|
175 |
/// Copy constructor.
|
alpar@1620
|
176 |
///
|
klao@1909
|
177 |
UEdge(const UEdge&) { }
|
alpar@1620
|
178 |
/// Initialize the iterator to be invalid.
|
klao@1030
|
179 |
|
alpar@1620
|
180 |
/// Initialize the iterator to be invalid.
|
alpar@1620
|
181 |
///
|
klao@1909
|
182 |
UEdge(Invalid) { }
|
alpar@1620
|
183 |
/// Equality operator
|
klao@1030
|
184 |
|
alpar@1620
|
185 |
/// Two iterators are equal if and only if they point to the
|
alpar@1620
|
186 |
/// same object or both are invalid.
|
klao@1909
|
187 |
bool operator==(UEdge) const { return true; }
|
alpar@1620
|
188 |
/// Inequality operator
|
klao@1030
|
189 |
|
klao@1909
|
190 |
/// \sa operator==(UEdge n)
|
alpar@1620
|
191 |
///
|
klao@1909
|
192 |
bool operator!=(UEdge) const { return true; }
|
klao@1030
|
193 |
|
deba@1627
|
194 |
/// Artificial ordering operator.
|
deba@1627
|
195 |
|
deba@1627
|
196 |
/// To allow the use of graph descriptors as key type in std::map or
|
deba@1627
|
197 |
/// similar associative container we require this.
|
deba@1627
|
198 |
///
|
deba@1627
|
199 |
/// \note This operator only have to define some strict ordering of
|
deba@1627
|
200 |
/// the items; this order has nothing to do with the iteration
|
deba@1627
|
201 |
/// ordering of the items.
|
deba@1627
|
202 |
///
|
deba@1627
|
203 |
/// \bug This is a technical requirement. Do we really need this?
|
klao@1909
|
204 |
bool operator<(UEdge) const { return false; }
|
deba@1627
|
205 |
};
|
klao@1030
|
206 |
|
alpar@1620
|
207 |
/// This iterator goes through each undirected edge.
|
klao@1030
|
208 |
|
alpar@1620
|
209 |
/// This iterator goes through each undirected edge of a graph.
|
alpar@1620
|
210 |
/// Its usage is quite simple, for example you can count the number
|
deba@1627
|
211 |
/// of undirected edges in a graph \c g of type \c Graph as follows:
|
alpar@1946
|
212 |
///\code
|
alpar@1620
|
213 |
/// int count=0;
|
klao@1909
|
214 |
/// for(Graph::UEdgeIt e(g); e!=INVALID; ++e) ++count;
|
alpar@1946
|
215 |
///\endcode
|
klao@1909
|
216 |
class UEdgeIt : public UEdge {
|
alpar@1620
|
217 |
public:
|
alpar@1620
|
218 |
/// Default constructor
|
deba@1627
|
219 |
|
alpar@1620
|
220 |
/// @warning The default constructor sets the iterator
|
alpar@1620
|
221 |
/// to an undefined value.
|
klao@1909
|
222 |
UEdgeIt() { }
|
alpar@1620
|
223 |
/// Copy constructor.
|
deba@1627
|
224 |
|
alpar@1620
|
225 |
/// Copy constructor.
|
alpar@1620
|
226 |
///
|
klao@1909
|
227 |
UEdgeIt(const UEdgeIt& e) : UEdge(e) { }
|
alpar@1620
|
228 |
/// Initialize the iterator to be invalid.
|
klao@1030
|
229 |
|
alpar@1620
|
230 |
/// Initialize the iterator to be invalid.
|
alpar@1620
|
231 |
///
|
klao@1909
|
232 |
UEdgeIt(Invalid) { }
|
deba@1627
|
233 |
/// This constructor sets the iterator to the first undirected edge.
|
alpar@1620
|
234 |
|
deba@1627
|
235 |
/// This constructor sets the iterator to the first undirected edge.
|
klao@1909
|
236 |
UEdgeIt(const UGraph&) { }
|
klao@1909
|
237 |
/// UEdge -> UEdgeIt conversion
|
klao@1030
|
238 |
|
deba@1627
|
239 |
/// Sets the iterator to the value of the trivial iterator.
|
deba@1627
|
240 |
/// This feature necessitates that each time we
|
deba@1627
|
241 |
/// iterate the undirected edge-set, the iteration order is the
|
deba@1627
|
242 |
/// same.
|
klao@1909
|
243 |
UEdgeIt(const UGraph&, const UEdge&) { }
|
deba@1627
|
244 |
/// Next undirected edge
|
alpar@1620
|
245 |
|
deba@1627
|
246 |
/// Assign the iterator to the next undirected edge.
|
klao@1909
|
247 |
UEdgeIt& operator++() { return *this; }
|
alpar@1620
|
248 |
};
|
klao@1030
|
249 |
|
deba@1627
|
250 |
/// \brief This iterator goes trough the incident undirected
|
deba@1627
|
251 |
/// edges of a node.
|
deba@1627
|
252 |
///
|
alpar@1620
|
253 |
/// This iterator goes trough the incident undirected edges
|
deba@2021
|
254 |
/// of a certain node of a graph. You should assume that the
|
deba@2021
|
255 |
/// loop edges will be iterated twice.
|
deba@2021
|
256 |
///
|
alpar@1620
|
257 |
/// Its usage is quite simple, for example you can compute the
|
deba@2021
|
258 |
/// degree (i.e. count the number of incident edges of a node \c n
|
deba@2021
|
259 |
/// in graph \c g of type \c Graph as follows.
|
deba@2021
|
260 |
///
|
alpar@1946
|
261 |
///\code
|
alpar@1620
|
262 |
/// int count=0;
|
alpar@1620
|
263 |
/// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
|
alpar@1946
|
264 |
///\endcode
|
klao@1909
|
265 |
class IncEdgeIt : public UEdge {
|
alpar@1620
|
266 |
public:
|
alpar@1620
|
267 |
/// Default constructor
|
klao@1030
|
268 |
|
alpar@1620
|
269 |
/// @warning The default constructor sets the iterator
|
alpar@1620
|
270 |
/// to an undefined value.
|
alpar@1620
|
271 |
IncEdgeIt() { }
|
alpar@1620
|
272 |
/// Copy constructor.
|
alpar@1620
|
273 |
|
alpar@1620
|
274 |
/// Copy constructor.
|
alpar@1620
|
275 |
///
|
klao@1909
|
276 |
IncEdgeIt(const IncEdgeIt& e) : UEdge(e) { }
|
alpar@1620
|
277 |
/// Initialize the iterator to be invalid.
|
alpar@1620
|
278 |
|
alpar@1620
|
279 |
/// Initialize the iterator to be invalid.
|
alpar@1620
|
280 |
///
|
alpar@1620
|
281 |
IncEdgeIt(Invalid) { }
|
alpar@1620
|
282 |
/// This constructor sets the iterator to first incident edge.
|
alpar@1620
|
283 |
|
alpar@1620
|
284 |
/// This constructor set the iterator to the first incident edge of
|
alpar@1620
|
285 |
/// the node.
|
klao@1909
|
286 |
IncEdgeIt(const UGraph&, const Node&) { }
|
klao@1909
|
287 |
/// UEdge -> IncEdgeIt conversion
|
alpar@1620
|
288 |
|
alpar@1620
|
289 |
/// Sets the iterator to the value of the trivial iterator \c e.
|
alpar@1620
|
290 |
/// This feature necessitates that each time we
|
alpar@1620
|
291 |
/// iterate the edge-set, the iteration order is the same.
|
klao@1909
|
292 |
IncEdgeIt(const UGraph&, const UEdge&) { }
|
alpar@1620
|
293 |
/// Next incident edge
|
alpar@1620
|
294 |
|
alpar@1620
|
295 |
/// Assign the iterator to the next incident edge
|
alpar@1620
|
296 |
/// of the corresponding node.
|
alpar@1620
|
297 |
IncEdgeIt& operator++() { return *this; }
|
alpar@1620
|
298 |
};
|
alpar@1620
|
299 |
|
deba@1627
|
300 |
/// The directed edge type.
|
deba@1627
|
301 |
|
deba@1627
|
302 |
/// The directed edge type. It can be converted to the
|
deba@1627
|
303 |
/// undirected edge.
|
klao@1909
|
304 |
class Edge : public UEdge {
|
deba@1627
|
305 |
public:
|
deba@1627
|
306 |
/// Default constructor
|
deba@1627
|
307 |
|
deba@1627
|
308 |
/// @warning The default constructor sets the iterator
|
deba@1627
|
309 |
/// to an undefined value.
|
deba@1627
|
310 |
Edge() { }
|
deba@1627
|
311 |
/// Copy constructor.
|
deba@1627
|
312 |
|
deba@1627
|
313 |
/// Copy constructor.
|
deba@1627
|
314 |
///
|
klao@1909
|
315 |
Edge(const Edge& e) : UEdge(e) { }
|
deba@1627
|
316 |
/// Initialize the iterator to be invalid.
|
deba@1627
|
317 |
|
deba@1627
|
318 |
/// Initialize the iterator to be invalid.
|
deba@1627
|
319 |
///
|
deba@1627
|
320 |
Edge(Invalid) { }
|
deba@1627
|
321 |
/// Equality operator
|
deba@1627
|
322 |
|
deba@1627
|
323 |
/// Two iterators are equal if and only if they point to the
|
deba@1627
|
324 |
/// same object or both are invalid.
|
deba@1627
|
325 |
bool operator==(Edge) const { return true; }
|
deba@1627
|
326 |
/// Inequality operator
|
deba@1627
|
327 |
|
deba@1627
|
328 |
/// \sa operator==(Edge n)
|
deba@1627
|
329 |
///
|
deba@1627
|
330 |
bool operator!=(Edge) const { return true; }
|
deba@1627
|
331 |
|
deba@1627
|
332 |
/// Artificial ordering operator.
|
deba@1627
|
333 |
|
deba@1627
|
334 |
/// To allow the use of graph descriptors as key type in std::map or
|
deba@1627
|
335 |
/// similar associative container we require this.
|
deba@1627
|
336 |
///
|
deba@1627
|
337 |
/// \note This operator only have to define some strict ordering of
|
deba@1627
|
338 |
/// the items; this order has nothing to do with the iteration
|
deba@1627
|
339 |
/// ordering of the items.
|
deba@1627
|
340 |
///
|
deba@1627
|
341 |
/// \bug This is a technical requirement. Do we really need this?
|
deba@1627
|
342 |
bool operator<(Edge) const { return false; }
|
deba@1627
|
343 |
|
deba@1627
|
344 |
};
|
deba@1627
|
345 |
/// This iterator goes through each directed edge.
|
deba@1627
|
346 |
|
deba@1627
|
347 |
/// This iterator goes through each edge of a graph.
|
deba@1627
|
348 |
/// Its usage is quite simple, for example you can count the number
|
deba@1627
|
349 |
/// of edges in a graph \c g of type \c Graph as follows:
|
alpar@1946
|
350 |
///\code
|
deba@1627
|
351 |
/// int count=0;
|
deba@1627
|
352 |
/// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
|
alpar@1946
|
353 |
///\endcode
|
deba@1627
|
354 |
class EdgeIt : public Edge {
|
deba@1627
|
355 |
public:
|
deba@1627
|
356 |
/// Default constructor
|
deba@1627
|
357 |
|
deba@1627
|
358 |
/// @warning The default constructor sets the iterator
|
deba@1627
|
359 |
/// to an undefined value.
|
deba@1627
|
360 |
EdgeIt() { }
|
deba@1627
|
361 |
/// Copy constructor.
|
deba@1627
|
362 |
|
deba@1627
|
363 |
/// Copy constructor.
|
deba@1627
|
364 |
///
|
deba@1627
|
365 |
EdgeIt(const EdgeIt& e) : Edge(e) { }
|
deba@1627
|
366 |
/// Initialize the iterator to be invalid.
|
deba@1627
|
367 |
|
deba@1627
|
368 |
/// Initialize the iterator to be invalid.
|
deba@1627
|
369 |
///
|
deba@1627
|
370 |
EdgeIt(Invalid) { }
|
deba@1627
|
371 |
/// This constructor sets the iterator to the first edge.
|
deba@1627
|
372 |
|
deba@1627
|
373 |
/// This constructor sets the iterator to the first edge of \c g.
|
deba@1627
|
374 |
///@param g the graph
|
klao@1909
|
375 |
EdgeIt(const UGraph &g) { ignore_unused_variable_warning(g); }
|
deba@1627
|
376 |
/// Edge -> EdgeIt conversion
|
deba@1627
|
377 |
|
deba@1627
|
378 |
/// Sets the iterator to the value of the trivial iterator \c e.
|
deba@1627
|
379 |
/// This feature necessitates that each time we
|
deba@1627
|
380 |
/// iterate the edge-set, the iteration order is the same.
|
klao@1909
|
381 |
EdgeIt(const UGraph&, const Edge&) { }
|
deba@1627
|
382 |
///Next edge
|
deba@1627
|
383 |
|
deba@1627
|
384 |
/// Assign the iterator to the next edge.
|
deba@1627
|
385 |
EdgeIt& operator++() { return *this; }
|
deba@1627
|
386 |
};
|
deba@1627
|
387 |
|
deba@1627
|
388 |
/// This iterator goes trough the outgoing directed edges of a node.
|
deba@1627
|
389 |
|
deba@1627
|
390 |
/// This iterator goes trough the \e outgoing edges of a certain node
|
deba@1627
|
391 |
/// of a graph.
|
deba@1627
|
392 |
/// Its usage is quite simple, for example you can count the number
|
deba@1627
|
393 |
/// of outgoing edges of a node \c n
|
deba@1627
|
394 |
/// in graph \c g of type \c Graph as follows.
|
alpar@1946
|
395 |
///\code
|
deba@1627
|
396 |
/// int count=0;
|
deba@1627
|
397 |
/// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
|
alpar@1946
|
398 |
///\endcode
|
deba@1627
|
399 |
|
deba@1627
|
400 |
class OutEdgeIt : public Edge {
|
deba@1627
|
401 |
public:
|
deba@1627
|
402 |
/// Default constructor
|
deba@1627
|
403 |
|
deba@1627
|
404 |
/// @warning The default constructor sets the iterator
|
deba@1627
|
405 |
/// to an undefined value.
|
deba@1627
|
406 |
OutEdgeIt() { }
|
deba@1627
|
407 |
/// Copy constructor.
|
deba@1627
|
408 |
|
deba@1627
|
409 |
/// Copy constructor.
|
deba@1627
|
410 |
///
|
deba@1627
|
411 |
OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
|
deba@1627
|
412 |
/// Initialize the iterator to be invalid.
|
deba@1627
|
413 |
|
deba@1627
|
414 |
/// Initialize the iterator to be invalid.
|
deba@1627
|
415 |
///
|
deba@1627
|
416 |
OutEdgeIt(Invalid) { }
|
deba@1627
|
417 |
/// This constructor sets the iterator to the first outgoing edge.
|
deba@1627
|
418 |
|
deba@1627
|
419 |
/// This constructor sets the iterator to the first outgoing edge of
|
deba@1627
|
420 |
/// the node.
|
deba@1627
|
421 |
///@param n the node
|
deba@1627
|
422 |
///@param g the graph
|
klao@1909
|
423 |
OutEdgeIt(const UGraph& n, const Node& g) {
|
alpar@1643
|
424 |
ignore_unused_variable_warning(n);
|
alpar@1643
|
425 |
ignore_unused_variable_warning(g);
|
alpar@1643
|
426 |
}
|
deba@1627
|
427 |
/// Edge -> OutEdgeIt conversion
|
deba@1627
|
428 |
|
deba@1627
|
429 |
/// Sets the iterator to the value of the trivial iterator.
|
deba@1627
|
430 |
/// This feature necessitates that each time we
|
deba@1627
|
431 |
/// iterate the edge-set, the iteration order is the same.
|
klao@1909
|
432 |
OutEdgeIt(const UGraph&, const Edge&) { }
|
deba@1627
|
433 |
///Next outgoing edge
|
deba@1627
|
434 |
|
deba@1627
|
435 |
/// Assign the iterator to the next
|
deba@1627
|
436 |
/// outgoing edge of the corresponding node.
|
deba@1627
|
437 |
OutEdgeIt& operator++() { return *this; }
|
deba@1627
|
438 |
};
|
deba@1627
|
439 |
|
deba@1627
|
440 |
/// This iterator goes trough the incoming directed edges of a node.
|
deba@1627
|
441 |
|
deba@1627
|
442 |
/// This iterator goes trough the \e incoming edges of a certain node
|
deba@1627
|
443 |
/// of a graph.
|
deba@1627
|
444 |
/// Its usage is quite simple, for example you can count the number
|
deba@1627
|
445 |
/// of outgoing edges of a node \c n
|
deba@1627
|
446 |
/// in graph \c g of type \c Graph as follows.
|
alpar@1946
|
447 |
///\code
|
deba@1627
|
448 |
/// int count=0;
|
deba@1627
|
449 |
/// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
|
alpar@1946
|
450 |
///\endcode
|
deba@1627
|
451 |
|
deba@1627
|
452 |
class InEdgeIt : public Edge {
|
deba@1627
|
453 |
public:
|
deba@1627
|
454 |
/// Default constructor
|
deba@1627
|
455 |
|
deba@1627
|
456 |
/// @warning The default constructor sets the iterator
|
deba@1627
|
457 |
/// to an undefined value.
|
deba@1627
|
458 |
InEdgeIt() { }
|
deba@1627
|
459 |
/// Copy constructor.
|
deba@1627
|
460 |
|
deba@1627
|
461 |
/// Copy constructor.
|
deba@1627
|
462 |
///
|
deba@1627
|
463 |
InEdgeIt(const InEdgeIt& e) : Edge(e) { }
|
deba@1627
|
464 |
/// Initialize the iterator to be invalid.
|
deba@1627
|
465 |
|
deba@1627
|
466 |
/// Initialize the iterator to be invalid.
|
deba@1627
|
467 |
///
|
deba@1627
|
468 |
InEdgeIt(Invalid) { }
|
deba@1627
|
469 |
/// This constructor sets the iterator to first incoming edge.
|
deba@1627
|
470 |
|
deba@1627
|
471 |
/// This constructor set the iterator to the first incoming edge of
|
deba@1627
|
472 |
/// the node.
|
deba@1627
|
473 |
///@param n the node
|
deba@1627
|
474 |
///@param g the graph
|
klao@1909
|
475 |
InEdgeIt(const UGraph& g, const Node& n) {
|
alpar@1643
|
476 |
ignore_unused_variable_warning(n);
|
alpar@1643
|
477 |
ignore_unused_variable_warning(g);
|
alpar@1643
|
478 |
}
|
deba@1627
|
479 |
/// Edge -> InEdgeIt conversion
|
deba@1627
|
480 |
|
deba@1627
|
481 |
/// Sets the iterator to the value of the trivial iterator \c e.
|
deba@1627
|
482 |
/// This feature necessitates that each time we
|
deba@1627
|
483 |
/// iterate the edge-set, the iteration order is the same.
|
klao@1909
|
484 |
InEdgeIt(const UGraph&, const Edge&) { }
|
deba@1627
|
485 |
/// Next incoming edge
|
deba@1627
|
486 |
|
deba@1627
|
487 |
/// Assign the iterator to the next inedge of the corresponding node.
|
deba@1627
|
488 |
///
|
deba@1627
|
489 |
InEdgeIt& operator++() { return *this; }
|
deba@1627
|
490 |
};
|
deba@1627
|
491 |
|
deba@1627
|
492 |
/// \brief Read write map of the nodes to type \c T.
|
deba@1627
|
493 |
///
|
deba@1627
|
494 |
/// ReadWrite map of the nodes to type \c T.
|
deba@1627
|
495 |
/// \sa Reference
|
deba@1627
|
496 |
/// \warning Making maps that can handle bool type (NodeMap<bool>)
|
deba@1627
|
497 |
/// needs some extra attention!
|
alpar@1630
|
498 |
/// \todo Wrong documentation
|
deba@1627
|
499 |
template<class T>
|
deba@1627
|
500 |
class NodeMap : public ReadWriteMap< Node, T >
|
deba@1627
|
501 |
{
|
deba@1627
|
502 |
public:
|
deba@1627
|
503 |
|
deba@1627
|
504 |
///\e
|
klao@1909
|
505 |
NodeMap(const UGraph&) { }
|
deba@1627
|
506 |
///\e
|
klao@1909
|
507 |
NodeMap(const UGraph&, T) { }
|
deba@1627
|
508 |
|
deba@1627
|
509 |
///Copy constructor
|
deba@1627
|
510 |
NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
|
deba@1627
|
511 |
///Assignment operator
|
deba@1627
|
512 |
NodeMap& operator=(const NodeMap&) { return *this; }
|
deba@1627
|
513 |
// \todo fix this concept
|
deba@1627
|
514 |
};
|
deba@1627
|
515 |
|
deba@1627
|
516 |
/// \brief Read write map of the directed edges to type \c T.
|
deba@1627
|
517 |
///
|
deba@1627
|
518 |
/// Reference map of the directed edges to type \c T.
|
deba@1627
|
519 |
/// \sa Reference
|
deba@1627
|
520 |
/// \warning Making maps that can handle bool type (EdgeMap<bool>)
|
deba@1627
|
521 |
/// needs some extra attention!
|
alpar@1630
|
522 |
/// \todo Wrong documentation
|
deba@1627
|
523 |
template<class T>
|
deba@1627
|
524 |
class EdgeMap : public ReadWriteMap<Edge,T>
|
deba@1627
|
525 |
{
|
deba@1627
|
526 |
public:
|
deba@1627
|
527 |
|
deba@1627
|
528 |
///\e
|
klao@1909
|
529 |
EdgeMap(const UGraph&) { }
|
deba@1627
|
530 |
///\e
|
klao@1909
|
531 |
EdgeMap(const UGraph&, T) { }
|
deba@1627
|
532 |
///Copy constructor
|
deba@1627
|
533 |
EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
|
deba@1627
|
534 |
///Assignment operator
|
deba@1627
|
535 |
EdgeMap& operator=(const EdgeMap&) { return *this; }
|
deba@1627
|
536 |
// \todo fix this concept
|
deba@1627
|
537 |
};
|
deba@1627
|
538 |
|
alpar@1620
|
539 |
/// Read write map of the undirected edges to type \c T.
|
alpar@1620
|
540 |
|
alpar@1620
|
541 |
/// Reference map of the edges to type \c T.
|
alpar@1620
|
542 |
/// \sa Reference
|
klao@1909
|
543 |
/// \warning Making maps that can handle bool type (UEdgeMap<bool>)
|
alpar@1620
|
544 |
/// needs some extra attention!
|
alpar@1630
|
545 |
/// \todo Wrong documentation
|
alpar@1620
|
546 |
template<class T>
|
klao@1909
|
547 |
class UEdgeMap : public ReadWriteMap<UEdge,T>
|
alpar@1620
|
548 |
{
|
klao@1030
|
549 |
public:
|
klao@1030
|
550 |
|
alpar@1620
|
551 |
///\e
|
klao@1909
|
552 |
UEdgeMap(const UGraph&) { }
|
alpar@1620
|
553 |
///\e
|
klao@1909
|
554 |
UEdgeMap(const UGraph&, T) { }
|
alpar@1620
|
555 |
///Copy constructor
|
klao@1909
|
556 |
UEdgeMap(const UEdgeMap& em) : ReadWriteMap<UEdge,T>(em) {}
|
alpar@1620
|
557 |
///Assignment operator
|
klao@1909
|
558 |
UEdgeMap &operator=(const UEdgeMap&) { return *this; }
|
alpar@1620
|
559 |
// \todo fix this concept
|
klao@1030
|
560 |
};
|
klao@1030
|
561 |
|
deba@1627
|
562 |
/// \brief Direct the given undirected edge.
|
deba@1627
|
563 |
///
|
deba@1627
|
564 |
/// Direct the given undirected edge. The returned edge source
|
deba@1627
|
565 |
/// will be the given edge.
|
klao@1909
|
566 |
Edge direct(const UEdge&, const Node&) const {
|
deba@1627
|
567 |
return INVALID;
|
deba@1627
|
568 |
}
|
klao@1030
|
569 |
|
deba@1627
|
570 |
/// \brief Direct the given undirected edge.
|
deba@1627
|
571 |
///
|
deba@1627
|
572 |
/// Direct the given undirected edge. The returned edge source
|
deba@1627
|
573 |
/// will be the source of the undirected edge if the given bool
|
deba@1627
|
574 |
/// is true.
|
klao@1909
|
575 |
Edge direct(const UEdge&, bool) const {
|
deba@1627
|
576 |
return INVALID;
|
deba@1627
|
577 |
}
|
deba@1627
|
578 |
|
deba@1627
|
579 |
/// \brief Returns true if the edge has default orientation.
|
deba@1627
|
580 |
///
|
klao@1030
|
581 |
/// Returns whether the given directed edge is same orientation as
|
klao@1030
|
582 |
/// the corresponding undirected edge.
|
deba@1627
|
583 |
bool direction(Edge) const { return true; }
|
deba@1627
|
584 |
|
deba@1627
|
585 |
/// \brief Returns the opposite directed edge.
|
klao@1030
|
586 |
///
|
deba@1627
|
587 |
/// Returns the opposite directed edge.
|
deba@1627
|
588 |
Edge oppositeEdge(Edge) const { return INVALID; }
|
klao@1030
|
589 |
|
deba@1627
|
590 |
/// \brief Opposite node on an edge
|
deba@1627
|
591 |
///
|
klao@1030
|
592 |
/// \return the opposite of the given Node on the given Edge
|
klao@1909
|
593 |
Node oppositeNode(Node, UEdge) const { return INVALID; }
|
klao@1030
|
594 |
|
deba@1627
|
595 |
/// \brief First node of the undirected edge.
|
deba@1627
|
596 |
///
|
klao@1909
|
597 |
/// \return the first node of the given UEdge.
|
klao@1030
|
598 |
///
|
klao@1909
|
599 |
/// Naturally uectected edges don't have direction and thus
|
klao@1030
|
600 |
/// don't have source and target node. But we use these two methods
|
klao@1030
|
601 |
/// to query the two endnodes of the edge. The direction of the edge
|
klao@1030
|
602 |
/// which arises this way is called the inherent direction of the
|
deba@1627
|
603 |
/// undirected edge, and is used to define the "default" direction
|
klao@1030
|
604 |
/// of the directed versions of the edges.
|
deba@1627
|
605 |
/// \sa direction
|
klao@1909
|
606 |
Node source(UEdge) const { return INVALID; }
|
klao@1030
|
607 |
|
deba@1627
|
608 |
/// \brief Second node of the undirected edge.
|
klao@1909
|
609 |
Node target(UEdge) const { return INVALID; }
|
klao@1030
|
610 |
|
deba@1627
|
611 |
/// \brief Source node of the directed edge.
|
klao@1030
|
612 |
Node source(Edge) const { return INVALID; }
|
klao@1030
|
613 |
|
deba@1627
|
614 |
/// \brief Target node of the directed edge.
|
klao@1030
|
615 |
Node target(Edge) const { return INVALID; }
|
klao@1030
|
616 |
|
klao@1030
|
617 |
void first(Node&) const {}
|
klao@1030
|
618 |
void next(Node&) const {}
|
klao@1030
|
619 |
|
klao@1909
|
620 |
void first(UEdge&) const {}
|
klao@1909
|
621 |
void next(UEdge&) const {}
|
klao@1030
|
622 |
|
klao@1030
|
623 |
void first(Edge&) const {}
|
klao@1030
|
624 |
void next(Edge&) const {}
|
klao@1030
|
625 |
|
klao@1030
|
626 |
void firstOut(Edge&, Node) const {}
|
klao@1030
|
627 |
void nextOut(Edge&) const {}
|
klao@1030
|
628 |
|
klao@1030
|
629 |
void firstIn(Edge&, Node) const {}
|
klao@1030
|
630 |
void nextIn(Edge&) const {}
|
klao@1030
|
631 |
|
klao@1030
|
632 |
|
deba@1980
|
633 |
void firstInc(UEdge &, bool &, const Node &) const {}
|
deba@1980
|
634 |
void nextInc(UEdge &, bool &) const {}
|
deba@1980
|
635 |
|
deba@1627
|
636 |
/// \brief Base node of the iterator
|
klao@1158
|
637 |
///
|
klao@1158
|
638 |
/// Returns the base node (the source in this case) of the iterator
|
klao@1158
|
639 |
Node baseNode(OutEdgeIt e) const {
|
klao@1158
|
640 |
return source(e);
|
klao@1158
|
641 |
}
|
deba@1627
|
642 |
/// \brief Running node of the iterator
|
klao@1158
|
643 |
///
|
klao@1158
|
644 |
/// Returns the running node (the target in this case) of the
|
klao@1158
|
645 |
/// iterator
|
klao@1158
|
646 |
Node runningNode(OutEdgeIt e) const {
|
klao@1158
|
647 |
return target(e);
|
klao@1158
|
648 |
}
|
klao@1158
|
649 |
|
deba@1627
|
650 |
/// \brief Base node of the iterator
|
klao@1158
|
651 |
///
|
klao@1158
|
652 |
/// Returns the base node (the target in this case) of the iterator
|
klao@1158
|
653 |
Node baseNode(InEdgeIt e) const {
|
klao@1158
|
654 |
return target(e);
|
klao@1158
|
655 |
}
|
deba@1627
|
656 |
/// \brief Running node of the iterator
|
klao@1158
|
657 |
///
|
klao@1158
|
658 |
/// Returns the running node (the source in this case) of the
|
klao@1158
|
659 |
/// iterator
|
klao@1158
|
660 |
Node runningNode(InEdgeIt e) const {
|
klao@1158
|
661 |
return source(e);
|
klao@1158
|
662 |
}
|
klao@1158
|
663 |
|
deba@1627
|
664 |
/// \brief Base node of the iterator
|
klao@1158
|
665 |
///
|
klao@1158
|
666 |
/// Returns the base node of the iterator
|
alpar@1367
|
667 |
Node baseNode(IncEdgeIt) const {
|
klao@1158
|
668 |
return INVALID;
|
klao@1158
|
669 |
}
|
deba@1627
|
670 |
|
deba@1627
|
671 |
/// \brief Running node of the iterator
|
klao@1158
|
672 |
///
|
klao@1158
|
673 |
/// Returns the running node of the iterator
|
alpar@1367
|
674 |
Node runningNode(IncEdgeIt) const {
|
klao@1158
|
675 |
return INVALID;
|
klao@1158
|
676 |
}
|
klao@1158
|
677 |
|
klao@1022
|
678 |
template <typename Graph>
|
klao@1022
|
679 |
struct Constraints {
|
klao@1022
|
680 |
void constraints() {
|
klao@1909
|
681 |
checkConcept<BaseIterableUGraphConcept, Graph>();
|
klao@1909
|
682 |
checkConcept<IterableUGraphConcept, Graph>();
|
klao@1909
|
683 |
checkConcept<MappableUGraphConcept, Graph>();
|
klao@1022
|
684 |
}
|
klao@1022
|
685 |
};
|
klao@1022
|
686 |
|
klao@1022
|
687 |
};
|
klao@1022
|
688 |
|
klao@1030
|
689 |
/// @}
|
klao@1030
|
690 |
|
klao@962
|
691 |
}
|
klao@962
|
692 |
|
klao@962
|
693 |
}
|
klao@962
|
694 |
|
klao@962
|
695 |
#endif
|