klao@959
|
1 |
/* -*- C++ -*-
|
ladanyi@1435
|
2 |
* lemon/concept/graph.h - Part of LEMON, a generic C++ optimization library
|
klao@959
|
3 |
*
|
alpar@1164
|
4 |
* Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@1359
|
5 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
klao@959
|
6 |
*
|
klao@959
|
7 |
* Permission to use, modify and distribute this software is granted
|
klao@959
|
8 |
* provided that this copyright notice appears in all copies. For
|
klao@959
|
9 |
* precise terms see the accompanying LICENSE file.
|
klao@959
|
10 |
*
|
klao@959
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
klao@959
|
12 |
* express or implied, and with no claim as to its suitability for any
|
klao@959
|
13 |
* purpose.
|
klao@959
|
14 |
*
|
klao@959
|
15 |
*/
|
klao@959
|
16 |
|
klao@959
|
17 |
#ifndef LEMON_CONCEPT_GRAPH_H
|
klao@959
|
18 |
#define LEMON_CONCEPT_GRAPH_H
|
klao@959
|
19 |
|
klao@1030
|
20 |
///\ingroup graph_concepts
|
klao@959
|
21 |
///\file
|
klao@959
|
22 |
///\brief Declaration of Graph.
|
klao@959
|
23 |
|
klao@959
|
24 |
#include <lemon/invalid.h>
|
alpar@1448
|
25 |
#include <lemon/utility.h>
|
klao@959
|
26 |
#include <lemon/concept/maps.h>
|
klao@959
|
27 |
#include <lemon/concept_check.h>
|
klao@959
|
28 |
#include <lemon/concept/graph_component.h>
|
klao@959
|
29 |
|
klao@959
|
30 |
namespace lemon {
|
klao@959
|
31 |
namespace concept {
|
deba@1136
|
32 |
|
klao@959
|
33 |
|
klao@961
|
34 |
/**************** The full-featured graph concepts ****************/
|
klao@959
|
35 |
|
deba@1136
|
36 |
|
ladanyi@1426
|
37 |
/// \brief Modular static graph class.
|
deba@1136
|
38 |
///
|
deba@1136
|
39 |
/// It should be the same as the \c StaticGraph class.
|
deba@1136
|
40 |
class _StaticGraph
|
klao@961
|
41 |
: virtual public BaseGraphComponent,
|
ladanyi@1426
|
42 |
public IterableGraphComponent, public MappableGraphComponent {
|
klao@959
|
43 |
public:
|
alpar@1448
|
44 |
///\e
|
alpar@1448
|
45 |
|
alpar@1448
|
46 |
///\todo undocumented
|
alpar@1448
|
47 |
///
|
alpar@1448
|
48 |
typedef False UndirTag;
|
alpar@1448
|
49 |
|
klao@959
|
50 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
51 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
52 |
|
deba@989
|
53 |
template <typename _Graph>
|
deba@989
|
54 |
struct Constraints {
|
ladanyi@1426
|
55 |
void constraints() {
|
ladanyi@1426
|
56 |
checkConcept<IterableGraphComponent, _Graph>();
|
ladanyi@1426
|
57 |
checkConcept<MappableGraphComponent, _Graph>();
|
ladanyi@1426
|
58 |
}
|
deba@989
|
59 |
};
|
klao@959
|
60 |
};
|
klao@959
|
61 |
|
ladanyi@1426
|
62 |
/// \brief Modular extendable graph class.
|
deba@1136
|
63 |
///
|
deba@1136
|
64 |
/// It should be the same as the \c ExtendableGraph class.
|
deba@1136
|
65 |
class _ExtendableGraph
|
deba@1136
|
66 |
: virtual public BaseGraphComponent, public _StaticGraph,
|
ladanyi@1426
|
67 |
public ExtendableGraphComponent, public ClearableGraphComponent {
|
klao@959
|
68 |
public:
|
klao@959
|
69 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
70 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
71 |
|
deba@989
|
72 |
template <typename _Graph>
|
deba@989
|
73 |
struct Constraints {
|
ladanyi@1426
|
74 |
void constraints() {
|
ladanyi@1426
|
75 |
checkConcept<_StaticGraph, _Graph >();
|
ladanyi@1426
|
76 |
checkConcept<ExtendableGraphComponent, _Graph >();
|
ladanyi@1426
|
77 |
checkConcept<ClearableGraphComponent, _Graph >();
|
ladanyi@1426
|
78 |
}
|
deba@989
|
79 |
};
|
klao@959
|
80 |
};
|
klao@959
|
81 |
|
ladanyi@1426
|
82 |
/// \brief Modular erasable graph class.
|
deba@1136
|
83 |
///
|
deba@1136
|
84 |
/// It should be the same as the \c ErasableGraph class.
|
deba@1136
|
85 |
class _ErasableGraph
|
deba@1136
|
86 |
: virtual public BaseGraphComponent, public _ExtendableGraph,
|
ladanyi@1426
|
87 |
public ErasableGraphComponent {
|
klao@959
|
88 |
public:
|
klao@959
|
89 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
90 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
91 |
|
deba@989
|
92 |
template <typename _Graph>
|
deba@989
|
93 |
struct Constraints {
|
ladanyi@1426
|
94 |
void constraints() {
|
ladanyi@1426
|
95 |
checkConcept<_ExtendableGraph, _Graph >();
|
ladanyi@1426
|
96 |
checkConcept<ErasableGraphComponent, _Graph >();
|
ladanyi@1426
|
97 |
}
|
deba@989
|
98 |
};
|
klao@959
|
99 |
};
|
klao@959
|
100 |
|
alpar@1620
|
101 |
/// \addtogroup graph_concepts
|
alpar@1620
|
102 |
/// @{
|
alpar@1620
|
103 |
|
deba@1136
|
104 |
/// An empty static graph class.
|
deba@1136
|
105 |
|
deba@1136
|
106 |
/// This class provides all the common features of a graph structure,
|
deba@1136
|
107 |
/// however completely without implementations and real data structures
|
deba@1136
|
108 |
/// behind the interface.
|
deba@1136
|
109 |
/// All graph algorithms should compile with this class, but it will not
|
deba@1136
|
110 |
/// run properly, of course.
|
deba@1136
|
111 |
///
|
deba@1136
|
112 |
/// It can be used for checking the interface compatibility,
|
deba@1136
|
113 |
/// or it can serve as a skeleton of a new graph structure.
|
deba@1136
|
114 |
///
|
deba@1136
|
115 |
/// Also, you will find here the full documentation of a certain graph
|
deba@1136
|
116 |
/// feature, the documentation of a real graph imlementation
|
deba@1136
|
117 |
/// like @ref ListGraph or
|
deba@1136
|
118 |
/// @ref SmartGraph will just refer to this structure.
|
deba@1136
|
119 |
///
|
deba@1136
|
120 |
/// \todo A pages describing the concept of concept description would
|
deba@1136
|
121 |
/// be nice.
|
deba@1136
|
122 |
class StaticGraph
|
deba@1136
|
123 |
{
|
deba@1136
|
124 |
public:
|
alpar@1448
|
125 |
///\e
|
alpar@1448
|
126 |
|
alpar@1448
|
127 |
///\todo undocumented
|
alpar@1448
|
128 |
///
|
alpar@1448
|
129 |
typedef False UndirTag;
|
alpar@1448
|
130 |
|
deba@1136
|
131 |
/// Defalult constructor.
|
deba@1136
|
132 |
|
deba@1136
|
133 |
/// Defalult constructor.
|
deba@1136
|
134 |
///
|
deba@1136
|
135 |
StaticGraph() { }
|
deba@1136
|
136 |
///Copy consructor.
|
deba@1136
|
137 |
|
deba@1136
|
138 |
// ///\todo It is not clear, what we expect from a copy constructor.
|
deba@1136
|
139 |
// ///E.g. How to assign the nodes/edges to each other? What about maps?
|
deba@1136
|
140 |
// StaticGraph(const StaticGraph& g) { }
|
deba@1136
|
141 |
|
deba@1136
|
142 |
/// The base type of node iterators,
|
deba@1136
|
143 |
/// or in other words, the trivial node iterator.
|
deba@1136
|
144 |
|
deba@1136
|
145 |
/// This is the base type of each node iterator,
|
deba@1136
|
146 |
/// thus each kind of node iterator converts to this.
|
deba@1136
|
147 |
/// More precisely each kind of node iterator should be inherited
|
deba@1136
|
148 |
/// from the trivial node iterator.
|
deba@1136
|
149 |
class Node {
|
deba@1136
|
150 |
public:
|
ladanyi@1426
|
151 |
/// Default constructor
|
deba@1136
|
152 |
|
ladanyi@1426
|
153 |
/// @warning The default constructor sets the iterator
|
ladanyi@1426
|
154 |
/// to an undefined value.
|
ladanyi@1426
|
155 |
Node() { }
|
ladanyi@1426
|
156 |
/// Copy constructor.
|
deba@1136
|
157 |
|
ladanyi@1426
|
158 |
/// Copy constructor.
|
ladanyi@1426
|
159 |
///
|
ladanyi@1426
|
160 |
Node(const Node&) { }
|
deba@1136
|
161 |
|
ladanyi@1426
|
162 |
/// Invalid constructor \& conversion.
|
deba@1136
|
163 |
|
ladanyi@1426
|
164 |
/// This constructor initializes the iterator to be invalid.
|
ladanyi@1426
|
165 |
/// \sa Invalid for more details.
|
ladanyi@1426
|
166 |
Node(Invalid) { }
|
ladanyi@1426
|
167 |
/// Equality operator
|
deba@1136
|
168 |
|
ladanyi@1426
|
169 |
/// Two iterators are equal if and only if they point to the
|
ladanyi@1426
|
170 |
/// same object or both are invalid.
|
ladanyi@1426
|
171 |
bool operator==(Node) const { return true; }
|
deba@1136
|
172 |
|
ladanyi@1426
|
173 |
/// Inequality operator
|
ladanyi@1426
|
174 |
|
ladanyi@1426
|
175 |
/// \sa operator==(Node n)
|
ladanyi@1426
|
176 |
///
|
ladanyi@1426
|
177 |
bool operator!=(Node) const { return true; }
|
deba@1136
|
178 |
|
deba@1622
|
179 |
/// Artificial ordering operator.
|
deba@1622
|
180 |
|
deba@1622
|
181 |
/// To allow the use of graph descriptors as key type in std::map or
|
deba@1622
|
182 |
/// similar associative container we require this.
|
deba@1622
|
183 |
///
|
deba@1622
|
184 |
/// \note This operator only have to define some strict ordering of
|
deba@1622
|
185 |
/// the items; this order has nothing to do with the iteration
|
deba@1622
|
186 |
/// ordering of the items.
|
deba@1622
|
187 |
///
|
deba@1622
|
188 |
/// \bug This is a technical requirement. Do we really need this?
|
deba@1622
|
189 |
bool operator<(Node) const { return false; }
|
deba@1622
|
190 |
|
deba@1136
|
191 |
};
|
deba@1136
|
192 |
|
deba@1136
|
193 |
/// This iterator goes through each node.
|
deba@1136
|
194 |
|
deba@1136
|
195 |
/// This iterator goes through each node.
|
deba@1136
|
196 |
/// Its usage is quite simple, for example you can count the number
|
deba@1136
|
197 |
/// of nodes in graph \c g of type \c Graph like this:
|
deba@1136
|
198 |
/// \code
|
deba@1136
|
199 |
/// int count=0;
|
ladanyi@1426
|
200 |
/// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
|
deba@1136
|
201 |
/// \endcode
|
deba@1136
|
202 |
class NodeIt : public Node {
|
deba@1136
|
203 |
public:
|
ladanyi@1426
|
204 |
/// Default constructor
|
deba@1136
|
205 |
|
ladanyi@1426
|
206 |
/// @warning The default constructor sets the iterator
|
ladanyi@1426
|
207 |
/// to an undefined value.
|
ladanyi@1426
|
208 |
NodeIt() { }
|
ladanyi@1426
|
209 |
/// Copy constructor.
|
ladanyi@1426
|
210 |
|
ladanyi@1426
|
211 |
/// Copy constructor.
|
ladanyi@1426
|
212 |
///
|
ladanyi@1426
|
213 |
NodeIt(const NodeIt& n) : Node(n) { }
|
ladanyi@1426
|
214 |
/// Invalid constructor \& conversion.
|
deba@1136
|
215 |
|
ladanyi@1426
|
216 |
/// Initialize the iterator to be invalid.
|
ladanyi@1426
|
217 |
/// \sa Invalid for more details.
|
ladanyi@1426
|
218 |
NodeIt(Invalid) { }
|
ladanyi@1426
|
219 |
/// Sets the iterator to the first node.
|
deba@1136
|
220 |
|
ladanyi@1426
|
221 |
/// Sets the iterator to the first node of \c g.
|
ladanyi@1426
|
222 |
///
|
ladanyi@1426
|
223 |
NodeIt(const StaticGraph&) { }
|
ladanyi@1426
|
224 |
/// Node -> NodeIt conversion.
|
deba@1136
|
225 |
|
deba@1470
|
226 |
/// Sets the iterator to the node of \c the graph pointed by
|
deba@1470
|
227 |
/// the trivial iterator.
|
ladanyi@1426
|
228 |
/// This feature necessitates that each time we
|
ladanyi@1426
|
229 |
/// iterate the edge-set, the iteration order is the same.
|
deba@1470
|
230 |
NodeIt(const StaticGraph&, const Node&) { }
|
ladanyi@1426
|
231 |
/// Next node.
|
deba@1136
|
232 |
|
ladanyi@1426
|
233 |
/// Assign the iterator to the next node.
|
ladanyi@1426
|
234 |
///
|
ladanyi@1426
|
235 |
NodeIt& operator++() { return *this; }
|
deba@1136
|
236 |
};
|
deba@1136
|
237 |
|
deba@1136
|
238 |
|
deba@1136
|
239 |
/// The base type of the edge iterators.
|
deba@1136
|
240 |
|
deba@1136
|
241 |
/// The base type of the edge iterators.
|
deba@1136
|
242 |
///
|
deba@1136
|
243 |
class Edge {
|
deba@1136
|
244 |
public:
|
ladanyi@1426
|
245 |
/// Default constructor
|
deba@1136
|
246 |
|
ladanyi@1426
|
247 |
/// @warning The default constructor sets the iterator
|
ladanyi@1426
|
248 |
/// to an undefined value.
|
ladanyi@1426
|
249 |
Edge() { }
|
ladanyi@1426
|
250 |
/// Copy constructor.
|
deba@1136
|
251 |
|
ladanyi@1426
|
252 |
/// Copy constructor.
|
ladanyi@1426
|
253 |
///
|
ladanyi@1426
|
254 |
Edge(const Edge&) { }
|
ladanyi@1426
|
255 |
/// Initialize the iterator to be invalid.
|
deba@1136
|
256 |
|
ladanyi@1426
|
257 |
/// Initialize the iterator to be invalid.
|
ladanyi@1426
|
258 |
///
|
ladanyi@1426
|
259 |
Edge(Invalid) { }
|
ladanyi@1426
|
260 |
/// Equality operator
|
deba@1136
|
261 |
|
ladanyi@1426
|
262 |
/// Two iterators are equal if and only if they point to the
|
ladanyi@1426
|
263 |
/// same object or both are invalid.
|
ladanyi@1426
|
264 |
bool operator==(Edge) const { return true; }
|
ladanyi@1426
|
265 |
/// Inequality operator
|
deba@1136
|
266 |
|
alpar@1620
|
267 |
/// \sa operator==(Edge n)
|
ladanyi@1426
|
268 |
///
|
ladanyi@1426
|
269 |
bool operator!=(Edge) const { return true; }
|
deba@1622
|
270 |
|
deba@1622
|
271 |
/// Artificial ordering operator.
|
deba@1622
|
272 |
|
deba@1622
|
273 |
/// To allow the use of graph descriptors as key type in std::map or
|
deba@1622
|
274 |
/// similar associative container we require this.
|
deba@1622
|
275 |
///
|
deba@1622
|
276 |
/// \note This operator only have to define some strict ordering of
|
deba@1622
|
277 |
/// the items; this order has nothing to do with the iteration
|
deba@1622
|
278 |
/// ordering of the items.
|
deba@1622
|
279 |
///
|
deba@1622
|
280 |
/// \bug This is a technical requirement. Do we really need this?
|
deba@1622
|
281 |
bool operator<(Edge) const { return false; }
|
deba@1136
|
282 |
};
|
deba@1136
|
283 |
|
deba@1136
|
284 |
/// This iterator goes trough the outgoing edges of a node.
|
deba@1136
|
285 |
|
deba@1136
|
286 |
/// This iterator goes trough the \e outgoing edges of a certain node
|
deba@1136
|
287 |
/// of a graph.
|
deba@1136
|
288 |
/// Its usage is quite simple, for example you can count the number
|
deba@1136
|
289 |
/// of outgoing edges of a node \c n
|
deba@1136
|
290 |
/// in graph \c g of type \c Graph as follows.
|
deba@1136
|
291 |
/// \code
|
deba@1136
|
292 |
/// int count=0;
|
deba@1136
|
293 |
/// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
|
deba@1136
|
294 |
/// \endcode
|
deba@1136
|
295 |
|
deba@1136
|
296 |
class OutEdgeIt : public Edge {
|
deba@1136
|
297 |
public:
|
ladanyi@1426
|
298 |
/// Default constructor
|
deba@1136
|
299 |
|
ladanyi@1426
|
300 |
/// @warning The default constructor sets the iterator
|
ladanyi@1426
|
301 |
/// to an undefined value.
|
ladanyi@1426
|
302 |
OutEdgeIt() { }
|
ladanyi@1426
|
303 |
/// Copy constructor.
|
deba@1136
|
304 |
|
ladanyi@1426
|
305 |
/// Copy constructor.
|
ladanyi@1426
|
306 |
///
|
ladanyi@1426
|
307 |
OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
|
ladanyi@1426
|
308 |
/// Initialize the iterator to be invalid.
|
deba@1136
|
309 |
|
ladanyi@1426
|
310 |
/// Initialize the iterator to be invalid.
|
ladanyi@1426
|
311 |
///
|
ladanyi@1426
|
312 |
OutEdgeIt(Invalid) { }
|
ladanyi@1426
|
313 |
/// This constructor sets the iterator to the first outgoing edge.
|
deba@1136
|
314 |
|
ladanyi@1426
|
315 |
/// This constructor sets the iterator to the first outgoing edge of
|
ladanyi@1426
|
316 |
/// the node.
|
ladanyi@1426
|
317 |
///@param n the node
|
ladanyi@1426
|
318 |
///@param g the graph
|
ladanyi@1426
|
319 |
OutEdgeIt(const StaticGraph&, const Node&) { }
|
ladanyi@1426
|
320 |
/// Edge -> OutEdgeIt conversion
|
deba@1136
|
321 |
|
deba@1470
|
322 |
/// Sets the iterator to the value of the trivial iterator.
|
deba@1470
|
323 |
/// This feature necessitates that each time we
|
ladanyi@1426
|
324 |
/// iterate the edge-set, the iteration order is the same.
|
deba@1470
|
325 |
OutEdgeIt(const StaticGraph&, const Edge&) { }
|
ladanyi@1426
|
326 |
///Next outgoing edge
|
ladanyi@1426
|
327 |
|
ladanyi@1426
|
328 |
/// Assign the iterator to the next
|
ladanyi@1426
|
329 |
/// outgoing edge of the corresponding node.
|
ladanyi@1426
|
330 |
OutEdgeIt& operator++() { return *this; }
|
deba@1136
|
331 |
};
|
deba@1136
|
332 |
|
deba@1136
|
333 |
/// This iterator goes trough the incoming edges of a node.
|
deba@1136
|
334 |
|
deba@1136
|
335 |
/// This iterator goes trough the \e incoming edges of a certain node
|
deba@1136
|
336 |
/// of a graph.
|
deba@1136
|
337 |
/// Its usage is quite simple, for example you can count the number
|
deba@1136
|
338 |
/// of outgoing edges of a node \c n
|
deba@1136
|
339 |
/// in graph \c g of type \c Graph as follows.
|
deba@1136
|
340 |
/// \code
|
deba@1136
|
341 |
/// int count=0;
|
deba@1136
|
342 |
/// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
|
deba@1136
|
343 |
/// \endcode
|
deba@1136
|
344 |
|
deba@1136
|
345 |
class InEdgeIt : public Edge {
|
deba@1136
|
346 |
public:
|
ladanyi@1426
|
347 |
/// Default constructor
|
deba@1136
|
348 |
|
ladanyi@1426
|
349 |
/// @warning The default constructor sets the iterator
|
ladanyi@1426
|
350 |
/// to an undefined value.
|
ladanyi@1426
|
351 |
InEdgeIt() { }
|
ladanyi@1426
|
352 |
/// Copy constructor.
|
deba@1136
|
353 |
|
ladanyi@1426
|
354 |
/// Copy constructor.
|
ladanyi@1426
|
355 |
///
|
ladanyi@1426
|
356 |
InEdgeIt(const InEdgeIt& e) : Edge(e) { }
|
ladanyi@1426
|
357 |
/// Initialize the iterator to be invalid.
|
deba@1136
|
358 |
|
ladanyi@1426
|
359 |
/// Initialize the iterator to be invalid.
|
ladanyi@1426
|
360 |
///
|
ladanyi@1426
|
361 |
InEdgeIt(Invalid) { }
|
ladanyi@1426
|
362 |
/// This constructor sets the iterator to first incoming edge.
|
deba@1136
|
363 |
|
ladanyi@1426
|
364 |
/// This constructor set the iterator to the first incoming edge of
|
ladanyi@1426
|
365 |
/// the node.
|
ladanyi@1426
|
366 |
///@param n the node
|
ladanyi@1426
|
367 |
///@param g the graph
|
ladanyi@1426
|
368 |
InEdgeIt(const StaticGraph&, const Node&) { }
|
ladanyi@1426
|
369 |
/// Edge -> InEdgeIt conversion
|
deba@1136
|
370 |
|
ladanyi@1426
|
371 |
/// Sets the iterator to the value of the trivial iterator \c e.
|
ladanyi@1426
|
372 |
/// This feature necessitates that each time we
|
ladanyi@1426
|
373 |
/// iterate the edge-set, the iteration order is the same.
|
ladanyi@1426
|
374 |
InEdgeIt(const StaticGraph&, const Edge&) { }
|
ladanyi@1426
|
375 |
/// Next incoming edge
|
deba@1136
|
376 |
|
ladanyi@1426
|
377 |
/// Assign the iterator to the next inedge of the corresponding node.
|
ladanyi@1426
|
378 |
///
|
ladanyi@1426
|
379 |
InEdgeIt& operator++() { return *this; }
|
deba@1136
|
380 |
};
|
deba@1136
|
381 |
/// This iterator goes through each edge.
|
deba@1136
|
382 |
|
deba@1136
|
383 |
/// This iterator goes through each edge of a graph.
|
deba@1136
|
384 |
/// Its usage is quite simple, for example you can count the number
|
deba@1136
|
385 |
/// of edges in a graph \c g of type \c Graph as follows:
|
deba@1136
|
386 |
/// \code
|
deba@1136
|
387 |
/// int count=0;
|
deba@1136
|
388 |
/// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
|
deba@1136
|
389 |
/// \endcode
|
deba@1136
|
390 |
class EdgeIt : public Edge {
|
deba@1136
|
391 |
public:
|
ladanyi@1426
|
392 |
/// Default constructor
|
deba@1136
|
393 |
|
ladanyi@1426
|
394 |
/// @warning The default constructor sets the iterator
|
ladanyi@1426
|
395 |
/// to an undefined value.
|
ladanyi@1426
|
396 |
EdgeIt() { }
|
ladanyi@1426
|
397 |
/// Copy constructor.
|
deba@1136
|
398 |
|
ladanyi@1426
|
399 |
/// Copy constructor.
|
ladanyi@1426
|
400 |
///
|
ladanyi@1426
|
401 |
EdgeIt(const EdgeIt& e) : Edge(e) { }
|
ladanyi@1426
|
402 |
/// Initialize the iterator to be invalid.
|
deba@1136
|
403 |
|
ladanyi@1426
|
404 |
/// Initialize the iterator to be invalid.
|
ladanyi@1426
|
405 |
///
|
ladanyi@1426
|
406 |
EdgeIt(Invalid) { }
|
ladanyi@1426
|
407 |
/// This constructor sets the iterator to the first edge.
|
deba@1136
|
408 |
|
ladanyi@1426
|
409 |
/// This constructor sets the iterator to the first edge of \c g.
|
ladanyi@1426
|
410 |
///@param g the graph
|
ladanyi@1426
|
411 |
EdgeIt(const StaticGraph&) { }
|
ladanyi@1426
|
412 |
/// Edge -> EdgeIt conversion
|
deba@1136
|
413 |
|
ladanyi@1426
|
414 |
/// Sets the iterator to the value of the trivial iterator \c e.
|
ladanyi@1426
|
415 |
/// This feature necessitates that each time we
|
ladanyi@1426
|
416 |
/// iterate the edge-set, the iteration order is the same.
|
ladanyi@1426
|
417 |
EdgeIt(const StaticGraph&, const Edge&) { }
|
ladanyi@1426
|
418 |
///Next edge
|
ladanyi@1426
|
419 |
|
ladanyi@1426
|
420 |
/// Assign the iterator to the next edge.
|
ladanyi@1426
|
421 |
EdgeIt& operator++() { return *this; }
|
deba@1136
|
422 |
};
|
deba@1136
|
423 |
///Gives back the target node of an edge.
|
deba@1136
|
424 |
|
deba@1136
|
425 |
///Gives back the target node of an edge.
|
deba@1136
|
426 |
///
|
deba@1136
|
427 |
Node target(Edge) const { return INVALID; }
|
deba@1136
|
428 |
///Gives back the source node of an edge.
|
deba@1136
|
429 |
|
deba@1136
|
430 |
///Gives back the source node of an edge.
|
deba@1136
|
431 |
///
|
deba@1136
|
432 |
Node source(Edge) const { return INVALID; }
|
deba@1563
|
433 |
|
deba@1563
|
434 |
/// Gives back the first Node in the iterating order.
|
deba@1563
|
435 |
|
deba@1563
|
436 |
/// Gives back the first Node in the iterating order.
|
deba@1563
|
437 |
///
|
deba@1563
|
438 |
void first(Node&) const {}
|
deba@1563
|
439 |
|
deba@1563
|
440 |
/// Gives back the next Node in the iterating order.
|
deba@1563
|
441 |
|
deba@1563
|
442 |
/// Gives back the next Node in the iterating order.
|
deba@1563
|
443 |
///
|
deba@1563
|
444 |
void next(Node&) const {}
|
deba@1563
|
445 |
|
deba@1563
|
446 |
/// Gives back the first Edge in the iterating order.
|
deba@1563
|
447 |
|
deba@1563
|
448 |
/// Gives back the first Edge in the iterating order.
|
deba@1563
|
449 |
///
|
deba@1563
|
450 |
void first(Edge&) const {}
|
deba@1563
|
451 |
/// Gives back the next Edge in the iterating order.
|
deba@1563
|
452 |
|
deba@1563
|
453 |
/// Gives back the next Edge in the iterating order.
|
deba@1563
|
454 |
///
|
deba@1563
|
455 |
void next(Edge&) const {}
|
deba@1563
|
456 |
|
deba@1563
|
457 |
|
deba@1563
|
458 |
/// Gives back the first of the Edges point to the given Node.
|
deba@1563
|
459 |
|
deba@1563
|
460 |
/// Gives back the first of the Edges point to the given Node.
|
deba@1563
|
461 |
///
|
deba@1563
|
462 |
void firstIn(Edge&, const Node&) const {}
|
deba@1563
|
463 |
|
deba@1563
|
464 |
/// Gives back the next of the Edges points to the given Node.
|
deba@1563
|
465 |
|
deba@1563
|
466 |
|
deba@1563
|
467 |
/// Gives back the next of the Edges points to the given Node.
|
deba@1563
|
468 |
///
|
deba@1563
|
469 |
void nextIn(Edge&) const {}
|
deba@1563
|
470 |
|
deba@1563
|
471 |
/// Gives back the first of the Edges start from the given Node.
|
deba@1563
|
472 |
|
deba@1563
|
473 |
/// Gives back the first of the Edges start from the given Node.
|
deba@1563
|
474 |
///
|
deba@1563
|
475 |
void firstOut(Edge&, const Node&) const {}
|
deba@1563
|
476 |
|
deba@1563
|
477 |
/// Gives back the next of the Edges start from the given Node.
|
deba@1563
|
478 |
|
deba@1563
|
479 |
/// Gives back the next of the Edges start from the given Node.
|
deba@1563
|
480 |
///
|
deba@1563
|
481 |
void nextOut(Edge&) const {}
|
deba@1563
|
482 |
|
deba@1563
|
483 |
/// \brief The base node of the iterator.
|
deba@1563
|
484 |
///
|
deba@1563
|
485 |
/// Gives back the base node of the iterator.
|
deba@1563
|
486 |
Node baseNode(const InEdgeIt&) const { return INVALID; }
|
deba@1563
|
487 |
|
deba@1563
|
488 |
/// \brief The running node of the iterator.
|
deba@1563
|
489 |
///
|
deba@1563
|
490 |
/// Gives back the running node of the iterator.
|
deba@1563
|
491 |
Node runningNode(const InEdgeIt&) const { return INVALID; }
|
deba@1563
|
492 |
|
deba@1563
|
493 |
/// \brief The base node of the iterator.
|
deba@1563
|
494 |
///
|
deba@1563
|
495 |
/// Gives back the base node of the iterator.
|
deba@1563
|
496 |
Node baseNode(const OutEdgeIt&) const { return INVALID; }
|
deba@1563
|
497 |
|
deba@1563
|
498 |
/// \brief The running node of the iterator.
|
deba@1563
|
499 |
///
|
deba@1563
|
500 |
/// Gives back the running node of the iterator.
|
deba@1563
|
501 |
Node runningNode(const OutEdgeIt&) const { return INVALID; }
|
deba@1136
|
502 |
/// Read write map of the nodes to type \c T.
|
deba@1136
|
503 |
|
deba@1136
|
504 |
/// \ingroup concept
|
deba@1136
|
505 |
/// ReadWrite map of the nodes to type \c T.
|
deba@1136
|
506 |
/// \sa Reference
|
deba@1136
|
507 |
/// \warning Making maps that can handle bool type (NodeMap<bool>)
|
deba@1136
|
508 |
/// needs some extra attention!
|
deba@1136
|
509 |
template<class T>
|
deba@1136
|
510 |
class NodeMap : public ReadWriteMap< Node, T >
|
deba@1136
|
511 |
{
|
deba@1136
|
512 |
public:
|
deba@1136
|
513 |
|
ladanyi@1426
|
514 |
///\e
|
ladanyi@1426
|
515 |
NodeMap(const StaticGraph&) { }
|
ladanyi@1426
|
516 |
///\e
|
ladanyi@1426
|
517 |
NodeMap(const StaticGraph&, T) { }
|
deba@1136
|
518 |
|
ladanyi@1426
|
519 |
///Copy constructor
|
ladanyi@1426
|
520 |
NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
|
ladanyi@1426
|
521 |
///Assignment operator
|
ladanyi@1426
|
522 |
NodeMap& operator=(const NodeMap&) { return *this; }
|
ladanyi@1426
|
523 |
// \todo fix this concept
|
deba@1136
|
524 |
};
|
deba@1136
|
525 |
|
deba@1136
|
526 |
/// Read write map of the edges to type \c T.
|
deba@1136
|
527 |
|
deba@1136
|
528 |
/// \ingroup concept
|
deba@1136
|
529 |
///Reference map of the edges to type \c T.
|
deba@1136
|
530 |
/// \sa Reference
|
deba@1136
|
531 |
/// \warning Making maps that can handle bool type (EdgeMap<bool>)
|
deba@1136
|
532 |
/// needs some extra attention!
|
deba@1136
|
533 |
template<class T>
|
deba@1136
|
534 |
class EdgeMap : public ReadWriteMap<Edge,T>
|
deba@1136
|
535 |
{
|
deba@1136
|
536 |
public:
|
deba@1136
|
537 |
|
ladanyi@1426
|
538 |
///\e
|
ladanyi@1426
|
539 |
EdgeMap(const StaticGraph&) { }
|
ladanyi@1426
|
540 |
///\e
|
ladanyi@1426
|
541 |
EdgeMap(const StaticGraph&, T) { }
|
ladanyi@1426
|
542 |
///Copy constructor
|
ladanyi@1426
|
543 |
EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
|
ladanyi@1426
|
544 |
///Assignment operator
|
ladanyi@1426
|
545 |
EdgeMap& operator=(const EdgeMap&) { return *this; }
|
ladanyi@1426
|
546 |
// \todo fix this concept
|
deba@1136
|
547 |
};
|
deba@1136
|
548 |
|
deba@1136
|
549 |
template <typename _Graph>
|
deba@1136
|
550 |
struct Constraints : public _StaticGraph::Constraints<_Graph> {};
|
deba@1136
|
551 |
|
deba@1136
|
552 |
};
|
deba@1136
|
553 |
|
deba@1136
|
554 |
/// An empty non-static graph class.
|
deba@1136
|
555 |
|
ladanyi@1426
|
556 |
/// This class provides everything that \ref StaticGraph does.
|
ladanyi@1426
|
557 |
/// Additionally it enables building graphs from scratch.
|
deba@1136
|
558 |
class ExtendableGraph : public StaticGraph
|
deba@1136
|
559 |
{
|
deba@1136
|
560 |
public:
|
deba@1136
|
561 |
/// Defalult constructor.
|
deba@1136
|
562 |
|
deba@1136
|
563 |
/// Defalult constructor.
|
deba@1136
|
564 |
///
|
deba@1136
|
565 |
ExtendableGraph() { }
|
deba@1136
|
566 |
///Add a new node to the graph.
|
deba@1136
|
567 |
|
deba@1136
|
568 |
/// \return the new node.
|
deba@1136
|
569 |
///
|
deba@1136
|
570 |
Node addNode() { return INVALID; }
|
deba@1136
|
571 |
///Add a new edge to the graph.
|
deba@1136
|
572 |
|
deba@1136
|
573 |
///Add a new edge to the graph with source node \c s
|
deba@1136
|
574 |
///and target node \c t.
|
deba@1136
|
575 |
///\return the new edge.
|
alpar@1367
|
576 |
Edge addEdge(Node, Node) { return INVALID; }
|
deba@1136
|
577 |
|
deba@1136
|
578 |
/// Resets the graph.
|
deba@1136
|
579 |
|
deba@1136
|
580 |
/// This function deletes all edges and nodes of the graph.
|
deba@1136
|
581 |
/// It also frees the memory allocated to store them.
|
deba@1136
|
582 |
/// \todo It might belong to \ref ErasableGraph.
|
deba@1136
|
583 |
void clear() { }
|
deba@1136
|
584 |
|
deba@1136
|
585 |
template <typename _Graph>
|
deba@1136
|
586 |
struct Constraints : public _ExtendableGraph::Constraints<_Graph> {};
|
deba@1136
|
587 |
|
deba@1136
|
588 |
};
|
deba@1136
|
589 |
|
deba@1136
|
590 |
/// An empty erasable graph class.
|
deba@1136
|
591 |
|
ladanyi@1426
|
592 |
/// This class is an extension of \ref ExtendableGraph. It makes it
|
deba@1136
|
593 |
/// possible to erase edges or nodes.
|
deba@1136
|
594 |
class ErasableGraph : public ExtendableGraph
|
deba@1136
|
595 |
{
|
deba@1136
|
596 |
public:
|
deba@1136
|
597 |
/// Defalult constructor.
|
deba@1136
|
598 |
|
deba@1136
|
599 |
/// Defalult constructor.
|
deba@1136
|
600 |
///
|
deba@1136
|
601 |
ErasableGraph() { }
|
deba@1136
|
602 |
/// Deletes a node.
|
deba@1136
|
603 |
|
deba@1136
|
604 |
/// Deletes node \c n node.
|
deba@1136
|
605 |
///
|
alpar@1367
|
606 |
void erase(Node) { }
|
deba@1136
|
607 |
/// Deletes an edge.
|
deba@1136
|
608 |
|
deba@1136
|
609 |
/// Deletes edge \c e edge.
|
deba@1136
|
610 |
///
|
alpar@1367
|
611 |
void erase(Edge) { }
|
deba@1136
|
612 |
|
deba@1136
|
613 |
template <typename _Graph>
|
deba@1136
|
614 |
struct Constraints : public _ErasableGraph::Constraints<_Graph> {};
|
deba@1136
|
615 |
|
deba@1136
|
616 |
};
|
deba@1136
|
617 |
|
deba@1136
|
618 |
|
deba@1136
|
619 |
/************* New GraphBase stuff **************/
|
deba@1136
|
620 |
|
deba@1136
|
621 |
|
deba@1136
|
622 |
// /// A minimal GraphBase concept
|
deba@1136
|
623 |
|
deba@1136
|
624 |
// /// This class describes a minimal concept which can be extended to a
|
deba@1136
|
625 |
// /// full-featured graph with \ref GraphFactory.
|
deba@1136
|
626 |
// class GraphBase {
|
deba@1136
|
627 |
// public:
|
deba@1136
|
628 |
|
deba@1136
|
629 |
// GraphBase() {}
|
deba@1136
|
630 |
|
deba@1136
|
631 |
// /// \bug Should we demand that Node and Edge be subclasses of the
|
deba@1136
|
632 |
// /// Graph class???
|
deba@1136
|
633 |
|
deba@1136
|
634 |
// typedef GraphItem<'n'> Node;
|
deba@1136
|
635 |
// typedef GraphItem<'e'> Edge;
|
deba@1136
|
636 |
|
deba@1136
|
637 |
// // class Node : public BaseGraphItem<'n'> {};
|
deba@1136
|
638 |
// // class Edge : public BaseGraphItem<'e'> {};
|
deba@1136
|
639 |
|
deba@1136
|
640 |
// // Graph operation
|
deba@1136
|
641 |
// void firstNode(Node &n) const { }
|
deba@1136
|
642 |
// void firstEdge(Edge &e) const { }
|
deba@1136
|
643 |
|
deba@1136
|
644 |
// void firstOutEdge(Edge &e, Node) const { }
|
deba@1136
|
645 |
// void firstInEdge(Edge &e, Node) const { }
|
deba@1136
|
646 |
|
deba@1136
|
647 |
// void nextNode(Node &n) const { }
|
deba@1136
|
648 |
// void nextEdge(Edge &e) const { }
|
deba@1136
|
649 |
|
deba@1136
|
650 |
|
deba@1136
|
651 |
// // Question: isn't it reasonable if this methods have a Node
|
deba@1136
|
652 |
// // parameter? Like this:
|
deba@1136
|
653 |
// // Edge& nextOut(Edge &e, Node) const { return e; }
|
deba@1136
|
654 |
// void nextOutEdge(Edge &e) const { }
|
deba@1136
|
655 |
// void nextInEdge(Edge &e) const { }
|
deba@1136
|
656 |
|
deba@1136
|
657 |
// Node target(Edge) const { return Node(); }
|
deba@1136
|
658 |
// Node source(Edge) const { return Node(); }
|
deba@1136
|
659 |
|
deba@1136
|
660 |
|
deba@1136
|
661 |
// // Do we need id, nodeNum, edgeNum and co. in this basic graphbase
|
deba@1136
|
662 |
// // concept?
|
deba@1136
|
663 |
|
deba@1136
|
664 |
|
deba@1136
|
665 |
// // Maps.
|
deba@1136
|
666 |
// //
|
deba@1136
|
667 |
// // We need a special slimer concept which does not provide maps (it
|
deba@1136
|
668 |
// // wouldn't be strictly slimer, cause for map-factory id() & friends
|
deba@1136
|
669 |
// // a required...)
|
deba@1136
|
670 |
|
deba@1136
|
671 |
// template<typename T>
|
deba@1136
|
672 |
// class NodeMap : public GraphMap<GraphBase, Node, T> {};
|
deba@1136
|
673 |
|
deba@1136
|
674 |
// template<typename T>
|
deba@1136
|
675 |
// class EdgeMap : public GraphMap<GraphBase, Node, T> {};
|
deba@1136
|
676 |
// };
|
deba@1136
|
677 |
|
klao@959
|
678 |
// @}
|
klao@959
|
679 |
} //namespace concept
|
klao@959
|
680 |
} //namespace lemon
|
klao@959
|
681 |
|
klao@959
|
682 |
|
klao@959
|
683 |
|
klao@959
|
684 |
#endif // LEMON_CONCEPT_GRAPH_H
|