alpar@906
|
1 |
/* -*- C++ -*-
|
alpar@921
|
2 |
* src/lemon/skeletons/graph.h - Part of LEMON, a generic C++ optimization library
|
alpar@906
|
3 |
*
|
alpar@906
|
4 |
* Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@906
|
5 |
* (Egervary Combinatorial Optimization Research Group, EGRES).
|
alpar@906
|
6 |
*
|
alpar@906
|
7 |
* Permission to use, modify and distribute this software is granted
|
alpar@906
|
8 |
* provided that this copyright notice appears in all copies. For
|
alpar@906
|
9 |
* precise terms see the accompanying LICENSE file.
|
alpar@906
|
10 |
*
|
alpar@906
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@906
|
12 |
* express or implied, and with no claim as to its suitability for any
|
alpar@906
|
13 |
* purpose.
|
alpar@906
|
14 |
*
|
alpar@906
|
15 |
*/
|
alpar@906
|
16 |
|
alpar@921
|
17 |
#ifndef LEMON_SKELETON_GRAPH_H
|
alpar@921
|
18 |
#define LEMON_SKELETON_GRAPH_H
|
alpar@52
|
19 |
|
alpar@794
|
20 |
///\ingroup skeletons
|
alpar@242
|
21 |
///\file
|
alpar@880
|
22 |
///\brief Declaration of Graph.
|
alpar@242
|
23 |
|
alpar@921
|
24 |
#include <lemon/invalid.h>
|
alpar@921
|
25 |
#include <lemon/skeletons/maps.h>
|
alpar@145
|
26 |
|
alpar@921
|
27 |
namespace lemon {
|
alpar@732
|
28 |
namespace skeleton {
|
alpar@732
|
29 |
|
alpar@794
|
30 |
/// \addtogroup skeletons
|
alpar@794
|
31 |
/// @{
|
alpar@163
|
32 |
|
alpar@732
|
33 |
/// An empty static graph class.
|
alpar@732
|
34 |
|
alpar@732
|
35 |
/// This class provides all the common features of a graph structure,
|
alpar@732
|
36 |
/// however completely without implementations and real data structures
|
alpar@732
|
37 |
/// behind the interface.
|
alpar@732
|
38 |
/// All graph algorithms should compile with this class, but it will not
|
alpar@732
|
39 |
/// run properly, of course.
|
alpar@732
|
40 |
///
|
alpar@732
|
41 |
/// It can be used for checking the interface compatibility,
|
alpar@732
|
42 |
/// or it can serve as a skeleton of a new graph structure.
|
alpar@732
|
43 |
///
|
alpar@732
|
44 |
/// Also, you will find here the full documentation of a certain graph
|
alpar@732
|
45 |
/// feature, the documentation of a real graph imlementation
|
alpar@732
|
46 |
/// like @ref ListGraph or
|
alpar@732
|
47 |
/// @ref SmartGraph will just refer to this structure.
|
alpar@938
|
48 |
///
|
alpar@938
|
49 |
/// \todo A pages describing the concept of concept description would
|
alpar@938
|
50 |
/// be nice.
|
alpar@880
|
51 |
class StaticGraph
|
alpar@732
|
52 |
{
|
alpar@732
|
53 |
public:
|
alpar@732
|
54 |
/// Defalult constructor.
|
alpar@801
|
55 |
|
alpar@801
|
56 |
/// Defalult constructor.
|
alpar@801
|
57 |
///
|
alpar@880
|
58 |
StaticGraph() { }
|
alpar@732
|
59 |
///Copy consructor.
|
alpar@163
|
60 |
|
alpar@801
|
61 |
// ///\todo It is not clear, what we expect from a copy constructor.
|
alpar@801
|
62 |
// ///E.g. How to assign the nodes/edges to each other? What about maps?
|
alpar@880
|
63 |
// StaticGraph(const StaticGraph& g) { }
|
alpar@732
|
64 |
|
alpar@774
|
65 |
/// The base type of node iterators,
|
alpar@774
|
66 |
/// or in other words, the trivial node iterator.
|
alpar@732
|
67 |
|
alpar@774
|
68 |
/// This is the base type of each node iterator,
|
alpar@774
|
69 |
/// thus each kind of node iterator converts to this.
|
alpar@801
|
70 |
/// More precisely each kind of node iterator should be inherited
|
alpar@774
|
71 |
/// from the trivial node iterator.
|
alpar@732
|
72 |
class Node {
|
alpar@732
|
73 |
public:
|
alpar@801
|
74 |
/// Default constructor
|
alpar@801
|
75 |
|
alpar@732
|
76 |
/// @warning The default constructor sets the iterator
|
alpar@732
|
77 |
/// to an undefined value.
|
alpar@774
|
78 |
Node() { }
|
alpar@774
|
79 |
/// Copy constructor.
|
alpar@801
|
80 |
|
alpar@801
|
81 |
/// Copy constructor.
|
alpar@801
|
82 |
///
|
alpar@774
|
83 |
Node(const Node&) { }
|
alpar@801
|
84 |
|
alpar@732
|
85 |
/// Invalid constructor \& conversion.
|
alpar@732
|
86 |
|
alpar@732
|
87 |
/// This constructor initializes the iterator to be invalid.
|
alpar@732
|
88 |
/// \sa Invalid for more details.
|
alpar@774
|
89 |
Node(Invalid) { }
|
alpar@801
|
90 |
/// Equality operator
|
alpar@801
|
91 |
|
alpar@732
|
92 |
/// Two iterators are equal if and only if they point to the
|
alpar@732
|
93 |
/// same object or both are invalid.
|
alpar@732
|
94 |
bool operator==(Node) const { return true; }
|
alpar@732
|
95 |
|
alpar@801
|
96 |
/// Inequality operator
|
alpar@801
|
97 |
|
alpar@911
|
98 |
/// \sa operator==(Node n)
|
alpar@732
|
99 |
///
|
alpar@732
|
100 |
bool operator!=(Node) const { return true; }
|
alpar@732
|
101 |
|
alpar@801
|
102 |
///Comparison operator.
|
alpar@801
|
103 |
|
alpar@801
|
104 |
///This is a strict ordering between the nodes.
|
alpar@801
|
105 |
///
|
alpar@801
|
106 |
///This ordering can be different from the order in which NodeIt
|
alpar@801
|
107 |
///goes through the nodes.
|
alpar@801
|
108 |
///\todo Possibly we don't need it.
|
alpar@732
|
109 |
bool operator<(Node) const { return true; }
|
alpar@732
|
110 |
};
|
alpar@732
|
111 |
|
alpar@732
|
112 |
/// This iterator goes through each node.
|
alpar@732
|
113 |
|
alpar@732
|
114 |
/// This iterator goes through each node.
|
alpar@732
|
115 |
/// Its usage is quite simple, for example you can count the number
|
alpar@774
|
116 |
/// of nodes in graph \c g of type \c Graph like this:
|
alpar@732
|
117 |
/// \code
|
alpar@774
|
118 |
/// int count=0;
|
alpar@801
|
119 |
/// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
|
alpar@732
|
120 |
/// \endcode
|
alpar@732
|
121 |
class NodeIt : public Node {
|
alpar@732
|
122 |
public:
|
alpar@801
|
123 |
/// Default constructor
|
alpar@801
|
124 |
|
alpar@732
|
125 |
/// @warning The default constructor sets the iterator
|
alpar@732
|
126 |
/// to an undefined value.
|
alpar@774
|
127 |
NodeIt() { }
|
alpar@774
|
128 |
/// Copy constructor.
|
alpar@801
|
129 |
|
alpar@801
|
130 |
/// Copy constructor.
|
alpar@801
|
131 |
///
|
alpar@774
|
132 |
NodeIt(const NodeIt&) { }
|
alpar@732
|
133 |
/// Invalid constructor \& conversion.
|
alpar@732
|
134 |
|
alpar@774
|
135 |
/// Initialize the iterator to be invalid.
|
alpar@732
|
136 |
/// \sa Invalid for more details.
|
alpar@774
|
137 |
NodeIt(Invalid) { }
|
alpar@801
|
138 |
/// Sets the iterator to the first node.
|
alpar@801
|
139 |
|
alpar@774
|
140 |
/// Sets the iterator to the first node of \c g.
|
alpar@801
|
141 |
///
|
alpar@880
|
142 |
NodeIt(const StaticGraph& g) { }
|
alpar@801
|
143 |
/// Node -> NodeIt conversion.
|
alpar@801
|
144 |
|
alpar@774
|
145 |
/// Sets the iterator to the node of \c g pointed by the trivial
|
alpar@801
|
146 |
/// iterator n.
|
alpar@801
|
147 |
/// This feature necessitates that each time we
|
alpar@801
|
148 |
/// iterate the edge-set, the iteration order is the same.
|
alpar@880
|
149 |
NodeIt(const StaticGraph& g, const Node& n) { }
|
alpar@801
|
150 |
/// Next node.
|
alpar@801
|
151 |
|
alpar@774
|
152 |
/// Assign the iterator to the next node.
|
alpar@801
|
153 |
///
|
alpar@774
|
154 |
NodeIt& operator++() { return *this; }
|
alpar@732
|
155 |
};
|
alpar@732
|
156 |
|
alpar@732
|
157 |
|
alpar@732
|
158 |
/// The base type of the edge iterators.
|
alpar@801
|
159 |
|
alpar@801
|
160 |
/// The base type of the edge iterators.
|
alpar@801
|
161 |
///
|
alpar@732
|
162 |
class Edge {
|
alpar@732
|
163 |
public:
|
alpar@801
|
164 |
/// Default constructor
|
alpar@801
|
165 |
|
alpar@732
|
166 |
/// @warning The default constructor sets the iterator
|
alpar@732
|
167 |
/// to an undefined value.
|
alpar@774
|
168 |
Edge() { }
|
alpar@774
|
169 |
/// Copy constructor.
|
alpar@801
|
170 |
|
alpar@801
|
171 |
/// Copy constructor.
|
alpar@801
|
172 |
///
|
alpar@774
|
173 |
Edge(const Edge&) { }
|
alpar@774
|
174 |
/// Initialize the iterator to be invalid.
|
alpar@801
|
175 |
|
alpar@801
|
176 |
/// Initialize the iterator to be invalid.
|
alpar@801
|
177 |
///
|
alpar@774
|
178 |
Edge(Invalid) { }
|
alpar@801
|
179 |
/// Equality operator
|
alpar@801
|
180 |
|
alpar@732
|
181 |
/// Two iterators are equal if and only if they point to the
|
alpar@732
|
182 |
/// same object or both are invalid.
|
alpar@732
|
183 |
bool operator==(Edge) const { return true; }
|
alpar@801
|
184 |
/// Inequality operator
|
alpar@801
|
185 |
|
alpar@911
|
186 |
/// \sa operator==(Node n)
|
alpar@801
|
187 |
///
|
alpar@732
|
188 |
bool operator!=(Edge) const { return true; }
|
alpar@801
|
189 |
///Comparison operator.
|
alpar@801
|
190 |
|
alpar@801
|
191 |
///This is a strict ordering between the nodes.
|
alpar@801
|
192 |
///
|
alpar@801
|
193 |
///This ordering can be different from the order in which NodeIt
|
alpar@801
|
194 |
///goes through the nodes.
|
alpar@801
|
195 |
///\todo Possibly we don't need it.
|
alpar@801
|
196 |
bool operator<(Edge) const { return true; }
|
alpar@732
|
197 |
};
|
alpar@732
|
198 |
|
alpar@732
|
199 |
/// This iterator goes trough the outgoing edges of a node.
|
alpar@732
|
200 |
|
alpar@732
|
201 |
/// This iterator goes trough the \e outgoing edges of a certain node
|
alpar@732
|
202 |
/// of a graph.
|
alpar@732
|
203 |
/// Its usage is quite simple, for example you can count the number
|
alpar@732
|
204 |
/// of outgoing edges of a node \c n
|
alpar@774
|
205 |
/// in graph \c g of type \c Graph as follows.
|
alpar@732
|
206 |
/// \code
|
alpar@774
|
207 |
/// int count=0;
|
alpar@801
|
208 |
/// for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) ++count;
|
alpar@732
|
209 |
/// \endcode
|
alpar@732
|
210 |
|
alpar@732
|
211 |
class OutEdgeIt : public Edge {
|
alpar@732
|
212 |
public:
|
alpar@801
|
213 |
/// Default constructor
|
alpar@801
|
214 |
|
alpar@732
|
215 |
/// @warning The default constructor sets the iterator
|
alpar@732
|
216 |
/// to an undefined value.
|
alpar@774
|
217 |
OutEdgeIt() { }
|
alpar@774
|
218 |
/// Copy constructor.
|
alpar@801
|
219 |
|
alpar@801
|
220 |
/// Copy constructor.
|
alpar@801
|
221 |
///
|
alpar@774
|
222 |
OutEdgeIt(const OutEdgeIt&) { }
|
alpar@774
|
223 |
/// Initialize the iterator to be invalid.
|
alpar@801
|
224 |
|
alpar@801
|
225 |
/// Initialize the iterator to be invalid.
|
alpar@801
|
226 |
///
|
alpar@774
|
227 |
OutEdgeIt(Invalid) { }
|
alpar@732
|
228 |
/// This constructor sets the iterator to first outgoing edge.
|
alpar@732
|
229 |
|
alpar@732
|
230 |
/// This constructor set the iterator to the first outgoing edge of
|
alpar@732
|
231 |
/// node
|
alpar@732
|
232 |
///@param n the node
|
alpar@774
|
233 |
///@param g the graph
|
alpar@880
|
234 |
OutEdgeIt(const StaticGraph& g, const Node& n) { }
|
alpar@801
|
235 |
/// Edge -> OutEdgeIt conversion
|
alpar@801
|
236 |
|
alpar@774
|
237 |
/// Sets the iterator to the value of the trivial iterator \c e.
|
alpar@774
|
238 |
/// This feature necessitates that each time we
|
alpar@774
|
239 |
/// iterate the edge-set, the iteration order is the same.
|
alpar@880
|
240 |
OutEdgeIt(const StaticGraph& g, const Edge& e) { }
|
alpar@801
|
241 |
///Next outgoing edge
|
alpar@801
|
242 |
|
alpar@801
|
243 |
/// Assign the iterator to the next
|
alpar@801
|
244 |
/// outgoing edge of the corresponding node.
|
alpar@774
|
245 |
OutEdgeIt& operator++() { return *this; }
|
alpar@732
|
246 |
};
|
alpar@732
|
247 |
|
alpar@732
|
248 |
/// This iterator goes trough the incoming edges of a node.
|
alpar@732
|
249 |
|
alpar@732
|
250 |
/// This iterator goes trough the \e incoming edges of a certain node
|
alpar@732
|
251 |
/// of a graph.
|
alpar@732
|
252 |
/// Its usage is quite simple, for example you can count the number
|
alpar@732
|
253 |
/// of outgoing edges of a node \c n
|
alpar@774
|
254 |
/// in graph \c g of type \c Graph as follows.
|
alpar@732
|
255 |
/// \code
|
alpar@774
|
256 |
/// int count=0;
|
alpar@801
|
257 |
/// for(Graph::InEdgeIt e(g, n); e!=INVALID; ++e) ++count;
|
alpar@732
|
258 |
/// \endcode
|
alpar@732
|
259 |
|
alpar@732
|
260 |
class InEdgeIt : public Edge {
|
alpar@732
|
261 |
public:
|
alpar@801
|
262 |
/// Default constructor
|
alpar@801
|
263 |
|
alpar@732
|
264 |
/// @warning The default constructor sets the iterator
|
alpar@732
|
265 |
/// to an undefined value.
|
alpar@774
|
266 |
InEdgeIt() { }
|
alpar@774
|
267 |
/// Copy constructor.
|
alpar@801
|
268 |
|
alpar@801
|
269 |
/// Copy constructor.
|
alpar@801
|
270 |
///
|
alpar@774
|
271 |
InEdgeIt(const InEdgeIt&) { }
|
alpar@774
|
272 |
/// Initialize the iterator to be invalid.
|
alpar@801
|
273 |
|
alpar@801
|
274 |
/// Initialize the iterator to be invalid.
|
alpar@801
|
275 |
///
|
alpar@774
|
276 |
InEdgeIt(Invalid) { }
|
alpar@801
|
277 |
/// This constructor sets the iterator to first incoming edge.
|
alpar@801
|
278 |
|
alpar@801
|
279 |
/// This constructor set the iterator to the first incoming edge of
|
alpar@801
|
280 |
/// node
|
alpar@801
|
281 |
///@param n the node
|
alpar@801
|
282 |
///@param g the graph
|
alpar@880
|
283 |
InEdgeIt(const StaticGraph& g, const Node& n) { }
|
alpar@801
|
284 |
/// Edge -> InEdgeIt conversion
|
alpar@801
|
285 |
|
alpar@801
|
286 |
/// Sets the iterator to the value of the trivial iterator \c e.
|
alpar@801
|
287 |
/// This feature necessitates that each time we
|
alpar@801
|
288 |
/// iterate the edge-set, the iteration order is the same.
|
alpar@880
|
289 |
InEdgeIt(const StaticGraph& g, const Edge& n) { }
|
alpar@801
|
290 |
/// Next incoming edge
|
alpar@801
|
291 |
|
alpar@774
|
292 |
/// Assign the iterator to the next inedge of the corresponding node.
|
alpar@801
|
293 |
///
|
alpar@774
|
294 |
InEdgeIt& operator++() { return *this; }
|
alpar@732
|
295 |
};
|
alpar@732
|
296 |
/// This iterator goes through each edge.
|
alpar@732
|
297 |
|
alpar@732
|
298 |
/// This iterator goes through each edge of a graph.
|
alpar@732
|
299 |
/// Its usage is quite simple, for example you can count the number
|
alpar@774
|
300 |
/// of edges in a graph \c g of type \c Graph as follows:
|
alpar@732
|
301 |
/// \code
|
alpar@774
|
302 |
/// int count=0;
|
alpar@801
|
303 |
/// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
|
alpar@732
|
304 |
/// \endcode
|
alpar@732
|
305 |
class EdgeIt : public Edge {
|
alpar@732
|
306 |
public:
|
alpar@801
|
307 |
/// Default constructor
|
alpar@801
|
308 |
|
alpar@732
|
309 |
/// @warning The default constructor sets the iterator
|
alpar@732
|
310 |
/// to an undefined value.
|
alpar@774
|
311 |
EdgeIt() { }
|
alpar@774
|
312 |
/// Copy constructor.
|
alpar@801
|
313 |
|
alpar@801
|
314 |
/// Copy constructor.
|
alpar@801
|
315 |
///
|
alpar@774
|
316 |
EdgeIt(const EdgeIt&) { }
|
alpar@774
|
317 |
/// Initialize the iterator to be invalid.
|
alpar@801
|
318 |
|
alpar@801
|
319 |
/// Initialize the iterator to be invalid.
|
alpar@801
|
320 |
///
|
alpar@774
|
321 |
EdgeIt(Invalid) { }
|
alpar@801
|
322 |
/// This constructor sets the iterator to first edge.
|
alpar@801
|
323 |
|
alpar@801
|
324 |
/// This constructor set the iterator to the first edge of
|
alpar@801
|
325 |
/// node
|
alpar@801
|
326 |
///@param g the graph
|
alpar@880
|
327 |
EdgeIt(const StaticGraph& g) { }
|
alpar@801
|
328 |
/// Edge -> EdgeIt conversion
|
alpar@801
|
329 |
|
alpar@801
|
330 |
/// Sets the iterator to the value of the trivial iterator \c e.
|
alpar@801
|
331 |
/// This feature necessitates that each time we
|
alpar@801
|
332 |
/// iterate the edge-set, the iteration order is the same.
|
alpar@880
|
333 |
EdgeIt(const StaticGraph&, const Edge&) { }
|
alpar@801
|
334 |
///Next edge
|
alpar@801
|
335 |
|
alpar@801
|
336 |
/// Assign the iterator to the next
|
alpar@801
|
337 |
/// edge of the corresponding node.
|
alpar@774
|
338 |
EdgeIt& operator++() { return *this; }
|
alpar@732
|
339 |
};
|
alpar@732
|
340 |
|
alpar@732
|
341 |
/// First node of the graph.
|
alpar@732
|
342 |
|
alpar@732
|
343 |
/// \retval i the first node.
|
alpar@732
|
344 |
/// \return the first node.
|
alpar@732
|
345 |
///
|
alpar@774
|
346 |
NodeIt& first(NodeIt& i) const { return i; }
|
alpar@732
|
347 |
|
alpar@732
|
348 |
/// The first incoming edge.
|
alpar@801
|
349 |
|
alpar@801
|
350 |
/// The first incoming edge.
|
alpar@801
|
351 |
///
|
alpar@774
|
352 |
InEdgeIt& first(InEdgeIt &i, Node) const { return i; }
|
alpar@732
|
353 |
/// The first outgoing edge.
|
alpar@801
|
354 |
|
alpar@801
|
355 |
/// The first outgoing edge.
|
alpar@801
|
356 |
///
|
alpar@774
|
357 |
OutEdgeIt& first(OutEdgeIt& i, Node) const { return i; }
|
alpar@732
|
358 |
/// The first edge of the Graph.
|
alpar@801
|
359 |
|
alpar@801
|
360 |
/// The first edge of the Graph.
|
alpar@801
|
361 |
///
|
alpar@774
|
362 |
EdgeIt& first(EdgeIt& i) const { return i; }
|
alpar@732
|
363 |
|
alpar@801
|
364 |
///Gives back the head node of an edge.
|
alpar@732
|
365 |
|
alpar@732
|
366 |
///Gives back the head node of an edge.
|
alpar@801
|
367 |
///
|
alpar@732
|
368 |
Node head(Edge) const { return INVALID; }
|
alpar@732
|
369 |
///Gives back the tail node of an edge.
|
alpar@801
|
370 |
|
alpar@801
|
371 |
///Gives back the tail node of an edge.
|
alpar@801
|
372 |
///
|
alpar@732
|
373 |
Node tail(Edge) const { return INVALID; }
|
alpar@163
|
374 |
|
alpar@732
|
375 |
///Gives back the \e id of a node.
|
alpar@182
|
376 |
|
alpar@732
|
377 |
///\warning Not all graph structures provide this feature.
|
alpar@732
|
378 |
///
|
alpar@801
|
379 |
///\todo Should each graph provide \c id?
|
alpar@774
|
380 |
int id(const Node&) const { return 0; }
|
alpar@732
|
381 |
///Gives back the \e id of an edge.
|
alpar@182
|
382 |
|
alpar@732
|
383 |
///\warning Not all graph structures provide this feature.
|
alpar@182
|
384 |
///
|
alpar@801
|
385 |
///\todo Should each graph provide \c id?
|
alpar@774
|
386 |
int id(const Edge&) const { return 0; }
|
alpar@182
|
387 |
|
alpar@911
|
388 |
///\e
|
alpar@801
|
389 |
|
alpar@880
|
390 |
///\todo Should it be in the concept?
|
alpar@801
|
391 |
///
|
alpar@774
|
392 |
int nodeNum() const { return 0; }
|
alpar@911
|
393 |
///\e
|
alpar@880
|
394 |
|
alpar@880
|
395 |
///\todo Should it be in the concept?
|
alpar@801
|
396 |
///
|
alpar@774
|
397 |
int edgeNum() const { return 0; }
|
alpar@732
|
398 |
|
alpar@732
|
399 |
|
alpar@732
|
400 |
///Reference map of the nodes to type \c T.
|
alpar@732
|
401 |
|
alpar@880
|
402 |
/// \ingroup skeletons
|
alpar@732
|
403 |
///Reference map of the nodes to type \c T.
|
alpar@880
|
404 |
/// \sa Reference
|
alpar@732
|
405 |
/// \warning Making maps that can handle bool type (NodeMap<bool>)
|
alpar@801
|
406 |
/// needs some extra attention!
|
alpar@880
|
407 |
template<class T> class NodeMap : public ReferenceMap< Node, T >
|
alpar@732
|
408 |
{
|
alpar@732
|
409 |
public:
|
alpar@732
|
410 |
|
alpar@911
|
411 |
///\e
|
alpar@880
|
412 |
NodeMap(const StaticGraph&) { }
|
alpar@911
|
413 |
///\e
|
alpar@880
|
414 |
NodeMap(const StaticGraph&, T) { }
|
alpar@732
|
415 |
|
alpar@732
|
416 |
///Copy constructor
|
alpar@774
|
417 |
template<typename TT> NodeMap(const NodeMap<TT>&) { }
|
alpar@732
|
418 |
///Assignment operator
|
alpar@774
|
419 |
template<typename TT> NodeMap& operator=(const NodeMap<TT>&)
|
alpar@774
|
420 |
{ return *this; }
|
alpar@732
|
421 |
};
|
alpar@732
|
422 |
|
alpar@732
|
423 |
///Reference map of the edges to type \c T.
|
alpar@732
|
424 |
|
alpar@880
|
425 |
/// \ingroup skeletons
|
alpar@732
|
426 |
///Reference map of the edges to type \c T.
|
alpar@880
|
427 |
/// \sa Reference
|
alpar@732
|
428 |
/// \warning Making maps that can handle bool type (EdgeMap<bool>)
|
alpar@801
|
429 |
/// needs some extra attention!
|
alpar@732
|
430 |
template<class T> class EdgeMap
|
alpar@732
|
431 |
: public ReferenceMap<Edge,T>
|
alpar@732
|
432 |
{
|
alpar@732
|
433 |
public:
|
alpar@732
|
434 |
|
alpar@911
|
435 |
///\e
|
alpar@880
|
436 |
EdgeMap(const StaticGraph&) { }
|
alpar@911
|
437 |
///\e
|
alpar@880
|
438 |
EdgeMap(const StaticGraph&, T) { }
|
alpar@147
|
439 |
|
alpar@732
|
440 |
///Copy constructor
|
alpar@774
|
441 |
template<typename TT> EdgeMap(const EdgeMap<TT>&) { }
|
alpar@732
|
442 |
///Assignment operator
|
alpar@774
|
443 |
template<typename TT> EdgeMap &operator=(const EdgeMap<TT>&)
|
alpar@774
|
444 |
{ return *this; }
|
alpar@732
|
445 |
};
|
alpar@163
|
446 |
};
|
alpar@163
|
447 |
|
alpar@938
|
448 |
struct DummyType {
|
alpar@938
|
449 |
int value;
|
alpar@938
|
450 |
DummyType() {}
|
alpar@938
|
451 |
DummyType(int p) : value(p) {}
|
alpar@938
|
452 |
DummyType& operator=(int p) { value = p; return *this;}
|
alpar@938
|
453 |
};
|
alpar@938
|
454 |
|
alpar@938
|
455 |
///\brief Checks whether \c G meets the
|
alpar@938
|
456 |
///\ref lemon::skeleton::StaticGraph "StaticGraph" concept
|
alpar@938
|
457 |
template<class Graph> void checkCompileStaticGraph(Graph &G)
|
alpar@938
|
458 |
{
|
alpar@938
|
459 |
typedef typename Graph::Node Node;
|
alpar@938
|
460 |
typedef typename Graph::NodeIt NodeIt;
|
alpar@938
|
461 |
typedef typename Graph::Edge Edge;
|
alpar@938
|
462 |
typedef typename Graph::EdgeIt EdgeIt;
|
alpar@938
|
463 |
typedef typename Graph::InEdgeIt InEdgeIt;
|
alpar@938
|
464 |
typedef typename Graph::OutEdgeIt OutEdgeIt;
|
alpar@938
|
465 |
|
alpar@938
|
466 |
{
|
alpar@938
|
467 |
Node i; Node j(i); Node k(INVALID);
|
alpar@938
|
468 |
i=j;
|
alpar@938
|
469 |
bool b; b=true;
|
alpar@938
|
470 |
b=(i==INVALID); b=(i!=INVALID);
|
alpar@938
|
471 |
b=(i==j); b=(i!=j); b=(i<j);
|
alpar@938
|
472 |
}
|
alpar@938
|
473 |
{
|
alpar@938
|
474 |
NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G);
|
alpar@938
|
475 |
i=j;
|
alpar@938
|
476 |
j=G.first(i);
|
alpar@938
|
477 |
j=++i;
|
alpar@938
|
478 |
bool b; b=true;
|
alpar@938
|
479 |
b=(i==INVALID); b=(i!=INVALID);
|
alpar@938
|
480 |
Node n(i);
|
alpar@938
|
481 |
n=i;
|
alpar@938
|
482 |
b=(i==j); b=(i!=j); b=(i<j);
|
alpar@938
|
483 |
//Node ->NodeIt conversion
|
alpar@938
|
484 |
NodeIt ni(G,n);
|
alpar@938
|
485 |
}
|
alpar@938
|
486 |
{
|
alpar@938
|
487 |
Edge i; Edge j(i); Edge k(INVALID);
|
alpar@938
|
488 |
i=j;
|
alpar@938
|
489 |
bool b; b=true;
|
alpar@938
|
490 |
b=(i==INVALID); b=(i!=INVALID);
|
alpar@938
|
491 |
b=(i==j); b=(i!=j); b=(i<j);
|
alpar@938
|
492 |
}
|
alpar@938
|
493 |
{
|
alpar@938
|
494 |
EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G);
|
alpar@938
|
495 |
i=j;
|
alpar@938
|
496 |
j=G.first(i);
|
alpar@938
|
497 |
j=++i;
|
alpar@938
|
498 |
bool b; b=true;
|
alpar@938
|
499 |
b=(i==INVALID); b=(i!=INVALID);
|
alpar@938
|
500 |
Edge e(i);
|
alpar@938
|
501 |
e=i;
|
alpar@938
|
502 |
b=(i==j); b=(i!=j); b=(i<j);
|
alpar@938
|
503 |
//Edge ->EdgeIt conversion
|
alpar@938
|
504 |
EdgeIt ei(G,e);
|
alpar@938
|
505 |
}
|
alpar@938
|
506 |
{
|
alpar@938
|
507 |
Node n;
|
alpar@938
|
508 |
InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n);
|
alpar@938
|
509 |
i=j;
|
alpar@938
|
510 |
j=G.first(i,n);
|
alpar@938
|
511 |
j=++i;
|
alpar@938
|
512 |
bool b; b=true;
|
alpar@938
|
513 |
b=(i==INVALID); b=(i!=INVALID);
|
alpar@938
|
514 |
Edge e(i);
|
alpar@938
|
515 |
e=i;
|
alpar@938
|
516 |
b=(i==j); b=(i!=j); b=(i<j);
|
alpar@938
|
517 |
//Edge ->InEdgeIt conversion
|
alpar@938
|
518 |
InEdgeIt ei(G,e);
|
alpar@938
|
519 |
}
|
alpar@938
|
520 |
{
|
alpar@938
|
521 |
Node n;
|
alpar@938
|
522 |
OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n);
|
alpar@938
|
523 |
i=j;
|
alpar@938
|
524 |
j=G.first(i,n);
|
alpar@938
|
525 |
j=++i;
|
alpar@938
|
526 |
bool b; b=true;
|
alpar@938
|
527 |
b=(i==INVALID); b=(i!=INVALID);
|
alpar@938
|
528 |
Edge e(i);
|
alpar@938
|
529 |
e=i;
|
alpar@938
|
530 |
b=(i==j); b=(i!=j); b=(i<j);
|
alpar@938
|
531 |
//Edge ->OutEdgeIt conversion
|
alpar@938
|
532 |
OutEdgeIt ei(G,e);
|
alpar@938
|
533 |
}
|
alpar@938
|
534 |
{
|
alpar@938
|
535 |
Node n,m;
|
alpar@938
|
536 |
n=m=INVALID;
|
alpar@938
|
537 |
Edge e;
|
alpar@938
|
538 |
e=INVALID;
|
alpar@938
|
539 |
n=G.tail(e);
|
alpar@938
|
540 |
n=G.head(e);
|
alpar@938
|
541 |
}
|
alpar@938
|
542 |
// id tests
|
alpar@938
|
543 |
{ Node n; int i=G.id(n); i=i; }
|
alpar@938
|
544 |
{ Edge e; int i=G.id(e); i=i; }
|
alpar@938
|
545 |
//NodeMap tests
|
alpar@938
|
546 |
{
|
alpar@938
|
547 |
Node k;
|
alpar@938
|
548 |
typename Graph::template NodeMap<int> m(G);
|
alpar@938
|
549 |
//Const map
|
alpar@938
|
550 |
typename Graph::template NodeMap<int> const &cm = m;
|
alpar@938
|
551 |
//Inicialize with default value
|
alpar@938
|
552 |
typename Graph::template NodeMap<int> mdef(G,12);
|
alpar@938
|
553 |
//Copy
|
alpar@938
|
554 |
typename Graph::template NodeMap<int> mm(cm);
|
alpar@938
|
555 |
//Copy from another type
|
alpar@938
|
556 |
typename Graph::template NodeMap<double> dm(cm);
|
alpar@938
|
557 |
//Copy to more complex type
|
alpar@938
|
558 |
typename Graph::template NodeMap<DummyType> em(cm);
|
alpar@938
|
559 |
int v;
|
alpar@938
|
560 |
v=m[k]; m[k]=v; m.set(k,v);
|
alpar@938
|
561 |
v=cm[k];
|
alpar@938
|
562 |
|
alpar@938
|
563 |
m=cm;
|
alpar@938
|
564 |
dm=cm; //Copy from another type
|
alpar@938
|
565 |
em=cm; //Copy to more complex type
|
alpar@938
|
566 |
{
|
alpar@938
|
567 |
//Check the typedef's
|
alpar@938
|
568 |
typename Graph::template NodeMap<int>::ValueType val;
|
alpar@938
|
569 |
val=1;
|
alpar@938
|
570 |
typename Graph::template NodeMap<int>::KeyType key;
|
alpar@938
|
571 |
key = typename Graph::NodeIt(G);
|
alpar@938
|
572 |
}
|
alpar@938
|
573 |
}
|
alpar@938
|
574 |
{ //bool NodeMap
|
alpar@938
|
575 |
Node k;
|
alpar@938
|
576 |
typename Graph::template NodeMap<bool> m(G);
|
alpar@938
|
577 |
typename Graph::template NodeMap<bool> const &cm = m; //Const map
|
alpar@938
|
578 |
//Inicialize with default value
|
alpar@938
|
579 |
typename Graph::template NodeMap<bool> mdef(G,12);
|
alpar@938
|
580 |
typename Graph::template NodeMap<bool> mm(cm); //Copy
|
alpar@938
|
581 |
typename Graph::template NodeMap<int> dm(cm); //Copy from another type
|
alpar@938
|
582 |
bool v;
|
alpar@938
|
583 |
v=m[k]; m[k]=v; m.set(k,v);
|
alpar@938
|
584 |
v=cm[k];
|
alpar@938
|
585 |
|
alpar@938
|
586 |
m=cm;
|
alpar@938
|
587 |
dm=cm; //Copy from another type
|
alpar@938
|
588 |
m=dm; //Copy to another type
|
alpar@186
|
589 |
|
alpar@938
|
590 |
{
|
alpar@938
|
591 |
//Check the typedef's
|
alpar@938
|
592 |
typename Graph::template NodeMap<bool>::ValueType val;
|
alpar@938
|
593 |
val=true;
|
alpar@938
|
594 |
typename Graph::template NodeMap<bool>::KeyType key;
|
alpar@938
|
595 |
key= typename Graph::NodeIt(G);
|
alpar@938
|
596 |
}
|
alpar@938
|
597 |
}
|
alpar@938
|
598 |
//EdgeMap tests
|
alpar@938
|
599 |
{
|
alpar@938
|
600 |
Edge k;
|
alpar@938
|
601 |
typename Graph::template EdgeMap<int> m(G);
|
alpar@938
|
602 |
typename Graph::template EdgeMap<int> const &cm = m; //Const map
|
alpar@938
|
603 |
//Inicialize with default value
|
alpar@938
|
604 |
typename Graph::template EdgeMap<int> mdef(G,12);
|
alpar@938
|
605 |
typename Graph::template EdgeMap<int> mm(cm); //Copy
|
alpar@938
|
606 |
typename Graph::template EdgeMap<double> dm(cm);//Copy from another type
|
alpar@938
|
607 |
int v;
|
alpar@938
|
608 |
v=m[k]; m[k]=v; m.set(k,v);
|
alpar@938
|
609 |
v=cm[k];
|
alpar@938
|
610 |
|
alpar@938
|
611 |
m=cm;
|
alpar@938
|
612 |
dm=cm; //Copy from another type
|
alpar@938
|
613 |
{
|
alpar@938
|
614 |
//Check the typedef's
|
alpar@938
|
615 |
typename Graph::template EdgeMap<int>::ValueType val;
|
alpar@938
|
616 |
val=1;
|
alpar@938
|
617 |
typename Graph::template EdgeMap<int>::KeyType key;
|
alpar@938
|
618 |
key= typename Graph::EdgeIt(G);
|
alpar@938
|
619 |
}
|
alpar@938
|
620 |
}
|
alpar@938
|
621 |
{ //bool EdgeMap
|
alpar@938
|
622 |
Edge k;
|
alpar@938
|
623 |
typename Graph::template EdgeMap<bool> m(G);
|
alpar@938
|
624 |
typename Graph::template EdgeMap<bool> const &cm = m; //Const map
|
alpar@938
|
625 |
//Inicialize with default value
|
alpar@938
|
626 |
typename Graph::template EdgeMap<bool> mdef(G,12);
|
alpar@938
|
627 |
typename Graph::template EdgeMap<bool> mm(cm); //Copy
|
alpar@938
|
628 |
typename Graph::template EdgeMap<int> dm(cm); //Copy from another type
|
alpar@938
|
629 |
bool v;
|
alpar@938
|
630 |
v=m[k]; m[k]=v; m.set(k,v);
|
alpar@938
|
631 |
v=cm[k];
|
alpar@938
|
632 |
|
alpar@938
|
633 |
m=cm;
|
alpar@938
|
634 |
dm=cm; //Copy from another type
|
alpar@938
|
635 |
m=dm; //Copy to another type
|
alpar@938
|
636 |
{
|
alpar@938
|
637 |
//Check the typedef's
|
alpar@938
|
638 |
typename Graph::template EdgeMap<bool>::ValueType val;
|
alpar@938
|
639 |
val=true;
|
alpar@938
|
640 |
typename Graph::template EdgeMap<bool>::KeyType key;
|
alpar@938
|
641 |
key= typename Graph::EdgeIt(G);
|
alpar@938
|
642 |
}
|
alpar@938
|
643 |
}
|
alpar@938
|
644 |
}
|
alpar@938
|
645 |
|
alpar@801
|
646 |
/// An empty non-static graph class.
|
alpar@938
|
647 |
|
alpar@880
|
648 |
/// This class provides everything that \ref StaticGraph
|
alpar@732
|
649 |
/// with additional functionality which enables to build a
|
alpar@732
|
650 |
/// graph from scratch.
|
alpar@880
|
651 |
class ExtendableGraph : public StaticGraph
|
alpar@732
|
652 |
{
|
alpar@163
|
653 |
public:
|
alpar@732
|
654 |
/// Defalult constructor.
|
alpar@801
|
655 |
|
alpar@801
|
656 |
/// Defalult constructor.
|
alpar@801
|
657 |
///
|
alpar@880
|
658 |
ExtendableGraph() { }
|
alpar@732
|
659 |
///Add a new node to the graph.
|
alpar@732
|
660 |
|
alpar@732
|
661 |
/// \return the new node.
|
alpar@732
|
662 |
///
|
alpar@774
|
663 |
Node addNode() { return INVALID; }
|
alpar@732
|
664 |
///Add a new edge to the graph.
|
alpar@732
|
665 |
|
alpar@880
|
666 |
///Add a new edge to the graph with tail node \c t
|
alpar@880
|
667 |
///and head node \c h.
|
alpar@732
|
668 |
///\return the new edge.
|
alpar@880
|
669 |
Edge addEdge(Node h, Node t) { return INVALID; }
|
alpar@732
|
670 |
|
alpar@732
|
671 |
/// Resets the graph.
|
alpar@732
|
672 |
|
alpar@732
|
673 |
/// This function deletes all edges and nodes of the graph.
|
alpar@732
|
674 |
/// It also frees the memory allocated to store them.
|
alpar@880
|
675 |
/// \todo It might belong to \ref ErasableGraph.
|
alpar@774
|
676 |
void clear() { }
|
alpar@163
|
677 |
};
|
alpar@163
|
678 |
|
alpar@938
|
679 |
|
alpar@938
|
680 |
///\brief Checks whether \c G meets the
|
alpar@938
|
681 |
///\ref lemon::skeleton::ExtendableGraph "ExtendableGraph" concept
|
alpar@938
|
682 |
template<class Graph> void checkCompileExtendableGraph(Graph &G)
|
alpar@938
|
683 |
{
|
alpar@938
|
684 |
checkCompileStaticGraph(G);
|
alpar@938
|
685 |
|
alpar@938
|
686 |
typedef typename Graph::Node Node;
|
alpar@938
|
687 |
typedef typename Graph::NodeIt NodeIt;
|
alpar@938
|
688 |
typedef typename Graph::Edge Edge;
|
alpar@938
|
689 |
typedef typename Graph::EdgeIt EdgeIt;
|
alpar@938
|
690 |
typedef typename Graph::InEdgeIt InEdgeIt;
|
alpar@938
|
691 |
typedef typename Graph::OutEdgeIt OutEdgeIt;
|
alpar@938
|
692 |
|
alpar@938
|
693 |
Node n,m;
|
alpar@938
|
694 |
n=G.addNode();
|
alpar@938
|
695 |
m=G.addNode();
|
alpar@938
|
696 |
Edge e;
|
alpar@938
|
697 |
e=G.addEdge(n,m);
|
alpar@938
|
698 |
|
alpar@938
|
699 |
// G.clear();
|
alpar@938
|
700 |
}
|
alpar@938
|
701 |
|
alpar@938
|
702 |
|
alpar@826
|
703 |
/// An empty erasable graph class.
|
alpar@52
|
704 |
|
alpar@880
|
705 |
/// This class is an extension of \ref ExtendableGraph. It also makes it
|
alpar@732
|
706 |
/// possible to erase edges or nodes.
|
alpar@880
|
707 |
class ErasableGraph : public ExtendableGraph
|
alpar@163
|
708 |
{
|
alpar@163
|
709 |
public:
|
alpar@801
|
710 |
/// Defalult constructor.
|
alpar@801
|
711 |
|
alpar@801
|
712 |
/// Defalult constructor.
|
alpar@801
|
713 |
///
|
alpar@880
|
714 |
ErasableGraph() { }
|
alpar@732
|
715 |
/// Deletes a node.
|
alpar@801
|
716 |
|
alpar@801
|
717 |
/// Deletes node \c n node.
|
alpar@801
|
718 |
///
|
alpar@774
|
719 |
void erase(Node n) { }
|
alpar@732
|
720 |
/// Deletes an edge.
|
alpar@801
|
721 |
|
alpar@801
|
722 |
/// Deletes edge \c e edge.
|
alpar@801
|
723 |
///
|
alpar@774
|
724 |
void erase(Edge e) { }
|
alpar@163
|
725 |
};
|
alpar@938
|
726 |
|
alpar@938
|
727 |
template<class Graph> void checkCompileGraphEraseEdge(Graph &G)
|
alpar@938
|
728 |
{
|
alpar@938
|
729 |
typename Graph::Edge e;
|
alpar@938
|
730 |
G.erase(e);
|
alpar@938
|
731 |
}
|
alpar@163
|
732 |
|
alpar@938
|
733 |
template<class Graph> void checkCompileGraphEraseNode(Graph &G)
|
alpar@938
|
734 |
{
|
alpar@938
|
735 |
typename Graph::Node n;
|
alpar@938
|
736 |
G.erase(n);
|
alpar@938
|
737 |
}
|
alpar@938
|
738 |
|
alpar@938
|
739 |
///\brief Checks whether \c G meets the
|
alpar@938
|
740 |
///\ref lemon::skeleton::EresableGraph "EresableGraph" concept
|
alpar@938
|
741 |
template<class Graph> void checkCompileErasableGraph(Graph &G)
|
alpar@938
|
742 |
{
|
alpar@938
|
743 |
checkCompileExtendableGraph(G);
|
alpar@938
|
744 |
checkCompileGraphEraseNode(G);
|
alpar@938
|
745 |
checkCompileGraphEraseEdge(G);
|
alpar@938
|
746 |
}
|
alpar@938
|
747 |
|
alpar@938
|
748 |
///Checks whether a graph has findEdge() member function.
|
alpar@938
|
749 |
|
alpar@938
|
750 |
///\todo findEdge() might be a global function.
|
alpar@938
|
751 |
///
|
alpar@938
|
752 |
template<class Graph> void checkCompileGraphFindEdge(Graph &G)
|
alpar@938
|
753 |
{
|
alpar@938
|
754 |
typedef typename Graph::NodeIt Node;
|
alpar@938
|
755 |
typedef typename Graph::NodeIt NodeIt;
|
alpar@938
|
756 |
|
alpar@938
|
757 |
G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));
|
alpar@938
|
758 |
G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));
|
alpar@938
|
759 |
}
|
alpar@938
|
760 |
|
alpar@732
|
761 |
// @}
|
alpar@801
|
762 |
} //namespace skeleton
|
alpar@921
|
763 |
} //namespace lemon
|
alpar@52
|
764 |
|
alpar@145
|
765 |
|
alpar@145
|
766 |
|
alpar@921
|
767 |
#endif // LEMON_SKELETON_GRAPH_H
|