alpar@209
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
deba@57
|
2 |
*
|
alpar@209
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
deba@57
|
4 |
*
|
alpar@440
|
5 |
* Copyright (C) 2003-2009
|
deba@57
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@57
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@57
|
8 |
*
|
deba@57
|
9 |
* Permission to use, modify and distribute this software is granted
|
deba@57
|
10 |
* provided that this copyright notice appears in all copies. For
|
deba@57
|
11 |
* precise terms see the accompanying LICENSE file.
|
deba@57
|
12 |
*
|
deba@57
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@57
|
14 |
* express or implied, and with no claim as to its suitability for any
|
deba@57
|
15 |
* purpose.
|
deba@57
|
16 |
*
|
deba@57
|
17 |
*/
|
deba@57
|
18 |
|
deba@57
|
19 |
///\ingroup graph_concepts
|
deba@57
|
20 |
///\file
|
deba@57
|
21 |
///\brief The concept of graph components.
|
deba@57
|
22 |
|
deba@529
|
23 |
#ifndef LEMON_CONCEPTS_GRAPH_COMPONENTS_H
|
deba@529
|
24 |
#define LEMON_CONCEPTS_GRAPH_COMPONENTS_H
|
deba@57
|
25 |
|
deba@220
|
26 |
#include <lemon/core.h>
|
deba@57
|
27 |
#include <lemon/concepts/maps.h>
|
deba@57
|
28 |
|
deba@57
|
29 |
#include <lemon/bits/alteration_notifier.h>
|
deba@57
|
30 |
|
deba@57
|
31 |
namespace lemon {
|
deba@57
|
32 |
namespace concepts {
|
deba@57
|
33 |
|
kpeter@579
|
34 |
/// \brief Concept class for \c Node, \c Arc and \c Edge types.
|
deba@57
|
35 |
///
|
kpeter@579
|
36 |
/// This class describes the concept of \c Node, \c Arc and \c Edge
|
kpeter@579
|
37 |
/// subtypes of digraph and graph types.
|
deba@57
|
38 |
///
|
deba@57
|
39 |
/// \note This class is a template class so that we can use it to
|
kpeter@579
|
40 |
/// create graph skeleton classes. The reason for this is that \c Node
|
kpeter@579
|
41 |
/// and \c Arc (or \c Edge) types should \e not derive from the same
|
kpeter@579
|
42 |
/// base class. For \c Node you should instantiate it with character
|
kpeter@579
|
43 |
/// \c 'n', for \c Arc with \c 'a' and for \c Edge with \c 'e'.
|
deba@57
|
44 |
#ifndef DOXYGEN
|
kpeter@559
|
45 |
template <char sel = '0'>
|
deba@57
|
46 |
#endif
|
deba@57
|
47 |
class GraphItem {
|
deba@57
|
48 |
public:
|
deba@57
|
49 |
/// \brief Default constructor.
|
alpar@209
|
50 |
///
|
kpeter@579
|
51 |
/// Default constructor.
|
deba@57
|
52 |
/// \warning The default constructor is not required to set
|
deba@57
|
53 |
/// the item to some well-defined value. So you should consider it
|
deba@57
|
54 |
/// as uninitialized.
|
deba@57
|
55 |
GraphItem() {}
|
kpeter@579
|
56 |
|
deba@57
|
57 |
/// \brief Copy constructor.
|
deba@57
|
58 |
///
|
deba@57
|
59 |
/// Copy constructor.
|
kpeter@579
|
60 |
GraphItem(const GraphItem &) {}
|
kpeter@579
|
61 |
|
kpeter@579
|
62 |
/// \brief Constructor for conversion from \c INVALID.
|
deba@57
|
63 |
///
|
kpeter@579
|
64 |
/// Constructor for conversion from \c INVALID.
|
kpeter@579
|
65 |
/// It initializes the item to be invalid.
|
deba@57
|
66 |
/// \sa Invalid for more details.
|
deba@57
|
67 |
GraphItem(Invalid) {}
|
kpeter@579
|
68 |
|
kpeter@579
|
69 |
/// \brief Assignment operator.
|
deba@57
|
70 |
///
|
kpeter@579
|
71 |
/// Assignment operator for the item.
|
kpeter@579
|
72 |
GraphItem& operator=(const GraphItem&) { return *this; }
|
kpeter@579
|
73 |
|
alpar@666
|
74 |
/// \brief Assignment operator for INVALID.
|
alpar@666
|
75 |
///
|
alpar@666
|
76 |
/// This operator makes the item invalid.
|
alpar@666
|
77 |
GraphItem& operator=(Invalid) { return *this; }
|
alpar@666
|
78 |
|
deba@57
|
79 |
/// \brief Equality operator.
|
deba@57
|
80 |
///
|
kpeter@579
|
81 |
/// Equality operator.
|
kpeter@579
|
82 |
bool operator==(const GraphItem&) const { return false; }
|
kpeter@579
|
83 |
|
deba@57
|
84 |
/// \brief Inequality operator.
|
deba@57
|
85 |
///
|
kpeter@579
|
86 |
/// Inequality operator.
|
kpeter@579
|
87 |
bool operator!=(const GraphItem&) const { return false; }
|
kpeter@579
|
88 |
|
kpeter@579
|
89 |
/// \brief Ordering operator.
|
deba@57
|
90 |
///
|
kpeter@579
|
91 |
/// This operator defines an ordering of the items.
|
kpeter@579
|
92 |
/// It makes possible to use graph item types as key types in
|
kpeter@579
|
93 |
/// associative containers (e.g. \c std::map).
|
deba@57
|
94 |
///
|
deba@57
|
95 |
/// \note This operator only have to define some strict ordering of
|
deba@57
|
96 |
/// the items; this order has nothing to do with the iteration
|
deba@57
|
97 |
/// ordering of the items.
|
kpeter@579
|
98 |
bool operator<(const GraphItem&) const { return false; }
|
deba@57
|
99 |
|
deba@57
|
100 |
template<typename _GraphItem>
|
deba@57
|
101 |
struct Constraints {
|
alpar@209
|
102 |
void constraints() {
|
alpar@209
|
103 |
_GraphItem i1;
|
alpar@666
|
104 |
i1=INVALID;
|
alpar@209
|
105 |
_GraphItem i2 = i1;
|
alpar@209
|
106 |
_GraphItem i3 = INVALID;
|
deba@57
|
107 |
|
alpar@209
|
108 |
i1 = i2 = i3;
|
alpar@209
|
109 |
|
alpar@209
|
110 |
bool b;
|
alpar@209
|
111 |
b = (ia == ib) && (ia != ib);
|
alpar@209
|
112 |
b = (ia == INVALID) && (ib != INVALID);
|
deba@57
|
113 |
b = (ia < ib);
|
alpar@209
|
114 |
}
|
deba@57
|
115 |
|
alpar@209
|
116 |
const _GraphItem &ia;
|
alpar@209
|
117 |
const _GraphItem &ib;
|
alpar@953
|
118 |
Constraints() {}
|
deba@57
|
119 |
};
|
deba@57
|
120 |
};
|
deba@57
|
121 |
|
kpeter@579
|
122 |
/// \brief Base skeleton class for directed graphs.
|
alpar@209
|
123 |
///
|
kpeter@579
|
124 |
/// This class describes the base interface of directed graph types.
|
kpeter@579
|
125 |
/// All digraph %concepts have to conform to this class.
|
kpeter@579
|
126 |
/// It just provides types for nodes and arcs and functions
|
kpeter@579
|
127 |
/// to get the source and the target nodes of arcs.
|
deba@57
|
128 |
class BaseDigraphComponent {
|
deba@57
|
129 |
public:
|
deba@57
|
130 |
|
deba@57
|
131 |
typedef BaseDigraphComponent Digraph;
|
alpar@209
|
132 |
|
deba@57
|
133 |
/// \brief Node class of the digraph.
|
deba@57
|
134 |
///
|
kpeter@579
|
135 |
/// This class represents the nodes of the digraph.
|
deba@57
|
136 |
typedef GraphItem<'n'> Node;
|
deba@57
|
137 |
|
deba@57
|
138 |
/// \brief Arc class of the digraph.
|
deba@57
|
139 |
///
|
kpeter@579
|
140 |
/// This class represents the arcs of the digraph.
|
kpeter@579
|
141 |
typedef GraphItem<'a'> Arc;
|
kpeter@579
|
142 |
|
kpeter@579
|
143 |
/// \brief Return the source node of an arc.
|
deba@57
|
144 |
///
|
kpeter@579
|
145 |
/// This function returns the source node of an arc.
|
kpeter@579
|
146 |
Node source(const Arc&) const { return INVALID; }
|
deba@57
|
147 |
|
kpeter@579
|
148 |
/// \brief Return the target node of an arc.
|
deba@57
|
149 |
///
|
kpeter@579
|
150 |
/// This function returns the target node of an arc.
|
kpeter@579
|
151 |
Node target(const Arc&) const { return INVALID; }
|
kpeter@579
|
152 |
|
kpeter@579
|
153 |
/// \brief Return the opposite node on the given arc.
|
deba@57
|
154 |
///
|
kpeter@579
|
155 |
/// This function returns the opposite node on the given arc.
|
deba@57
|
156 |
Node oppositeNode(const Node&, const Arc&) const {
|
deba@57
|
157 |
return INVALID;
|
deba@57
|
158 |
}
|
deba@57
|
159 |
|
deba@57
|
160 |
template <typename _Digraph>
|
deba@57
|
161 |
struct Constraints {
|
alpar@209
|
162 |
typedef typename _Digraph::Node Node;
|
alpar@209
|
163 |
typedef typename _Digraph::Arc Arc;
|
alpar@209
|
164 |
|
alpar@209
|
165 |
void constraints() {
|
alpar@209
|
166 |
checkConcept<GraphItem<'n'>, Node>();
|
alpar@209
|
167 |
checkConcept<GraphItem<'a'>, Arc>();
|
alpar@209
|
168 |
{
|
alpar@209
|
169 |
Node n;
|
alpar@209
|
170 |
Arc e(INVALID);
|
alpar@209
|
171 |
n = digraph.source(e);
|
alpar@209
|
172 |
n = digraph.target(e);
|
deba@57
|
173 |
n = digraph.oppositeNode(n, e);
|
alpar@209
|
174 |
}
|
alpar@209
|
175 |
}
|
alpar@209
|
176 |
|
alpar@209
|
177 |
const _Digraph& digraph;
|
alpar@953
|
178 |
Constraints() {}
|
deba@57
|
179 |
};
|
deba@57
|
180 |
};
|
deba@57
|
181 |
|
kpeter@579
|
182 |
/// \brief Base skeleton class for undirected graphs.
|
alpar@209
|
183 |
///
|
kpeter@579
|
184 |
/// This class describes the base interface of undirected graph types.
|
kpeter@579
|
185 |
/// All graph %concepts have to conform to this class.
|
kpeter@579
|
186 |
/// It extends the interface of \ref BaseDigraphComponent with an
|
kpeter@579
|
187 |
/// \c Edge type and functions to get the end nodes of edges,
|
kpeter@579
|
188 |
/// to convert from arcs to edges and to get both direction of edges.
|
deba@57
|
189 |
class BaseGraphComponent : public BaseDigraphComponent {
|
deba@57
|
190 |
public:
|
kpeter@617
|
191 |
|
kpeter@617
|
192 |
typedef BaseGraphComponent Graph;
|
kpeter@617
|
193 |
|
deba@57
|
194 |
typedef BaseDigraphComponent::Node Node;
|
deba@57
|
195 |
typedef BaseDigraphComponent::Arc Arc;
|
kpeter@579
|
196 |
|
kpeter@579
|
197 |
/// \brief Undirected edge class of the graph.
|
deba@57
|
198 |
///
|
kpeter@579
|
199 |
/// This class represents the undirected edges of the graph.
|
kpeter@579
|
200 |
/// Undirected graphs can be used as directed graphs, each edge is
|
kpeter@579
|
201 |
/// represented by two opposite directed arcs.
|
kpeter@579
|
202 |
class Edge : public GraphItem<'e'> {
|
kpeter@579
|
203 |
typedef GraphItem<'e'> Parent;
|
kpeter@579
|
204 |
|
kpeter@617
|
205 |
public:
|
deba@57
|
206 |
/// \brief Default constructor.
|
alpar@209
|
207 |
///
|
kpeter@579
|
208 |
/// Default constructor.
|
deba@57
|
209 |
/// \warning The default constructor is not required to set
|
deba@57
|
210 |
/// the item to some well-defined value. So you should consider it
|
deba@57
|
211 |
/// as uninitialized.
|
deba@57
|
212 |
Edge() {}
|
kpeter@579
|
213 |
|
deba@57
|
214 |
/// \brief Copy constructor.
|
deba@57
|
215 |
///
|
deba@57
|
216 |
/// Copy constructor.
|
kpeter@579
|
217 |
Edge(const Edge &) : Parent() {}
|
kpeter@579
|
218 |
|
kpeter@579
|
219 |
/// \brief Constructor for conversion from \c INVALID.
|
deba@57
|
220 |
///
|
kpeter@579
|
221 |
/// Constructor for conversion from \c INVALID.
|
kpeter@579
|
222 |
/// It initializes the item to be invalid.
|
deba@57
|
223 |
/// \sa Invalid for more details.
|
deba@57
|
224 |
Edge(Invalid) {}
|
kpeter@579
|
225 |
|
kpeter@579
|
226 |
/// \brief Constructor for conversion from an arc.
|
deba@57
|
227 |
///
|
kpeter@579
|
228 |
/// Constructor for conversion from an arc.
|
deba@57
|
229 |
/// Besides the core graph item functionality each arc should
|
alpar@209
|
230 |
/// be convertible to the represented edge.
|
deba@57
|
231 |
Edge(const Arc&) {}
|
alpar@666
|
232 |
};
|
deba@57
|
233 |
|
kpeter@579
|
234 |
/// \brief Return one end node of an edge.
|
kpeter@579
|
235 |
///
|
kpeter@579
|
236 |
/// This function returns one end node of an edge.
|
kpeter@579
|
237 |
Node u(const Edge&) const { return INVALID; }
|
kpeter@579
|
238 |
|
kpeter@579
|
239 |
/// \brief Return the other end node of an edge.
|
kpeter@579
|
240 |
///
|
kpeter@579
|
241 |
/// This function returns the other end node of an edge.
|
kpeter@579
|
242 |
Node v(const Edge&) const { return INVALID; }
|
kpeter@579
|
243 |
|
kpeter@579
|
244 |
/// \brief Return a directed arc related to an edge.
|
kpeter@579
|
245 |
///
|
kpeter@579
|
246 |
/// This function returns a directed arc from its direction and the
|
kpeter@579
|
247 |
/// represented edge.
|
kpeter@579
|
248 |
Arc direct(const Edge&, bool) const { return INVALID; }
|
kpeter@579
|
249 |
|
kpeter@579
|
250 |
/// \brief Return a directed arc related to an edge.
|
kpeter@579
|
251 |
///
|
kpeter@579
|
252 |
/// This function returns a directed arc from its source node and the
|
kpeter@579
|
253 |
/// represented edge.
|
kpeter@579
|
254 |
Arc direct(const Edge&, const Node&) const { return INVALID; }
|
kpeter@579
|
255 |
|
kpeter@579
|
256 |
/// \brief Return the direction of the arc.
|
deba@57
|
257 |
///
|
deba@57
|
258 |
/// Returns the direction of the arc. Each arc represents an
|
deba@57
|
259 |
/// edge with a direction. It gives back the
|
deba@57
|
260 |
/// direction.
|
deba@57
|
261 |
bool direction(const Arc&) const { return true; }
|
deba@57
|
262 |
|
kpeter@579
|
263 |
/// \brief Return the opposite arc.
|
deba@57
|
264 |
///
|
kpeter@579
|
265 |
/// This function returns the opposite arc, i.e. the arc representing
|
kpeter@579
|
266 |
/// the same edge and has opposite direction.
|
kpeter@579
|
267 |
Arc oppositeArc(const Arc&) const { return INVALID; }
|
alpar@209
|
268 |
|
deba@57
|
269 |
template <typename _Graph>
|
deba@57
|
270 |
struct Constraints {
|
alpar@209
|
271 |
typedef typename _Graph::Node Node;
|
alpar@209
|
272 |
typedef typename _Graph::Arc Arc;
|
alpar@209
|
273 |
typedef typename _Graph::Edge Edge;
|
alpar@209
|
274 |
|
alpar@209
|
275 |
void constraints() {
|
deba@57
|
276 |
checkConcept<BaseDigraphComponent, _Graph>();
|
kpeter@579
|
277 |
checkConcept<GraphItem<'e'>, Edge>();
|
alpar@209
|
278 |
{
|
alpar@209
|
279 |
Node n;
|
alpar@209
|
280 |
Edge ue(INVALID);
|
deba@57
|
281 |
Arc e;
|
alpar@209
|
282 |
n = graph.u(ue);
|
alpar@209
|
283 |
n = graph.v(ue);
|
deba@57
|
284 |
e = graph.direct(ue, true);
|
kpeter@579
|
285 |
e = graph.direct(ue, false);
|
deba@57
|
286 |
e = graph.direct(ue, n);
|
deba@57
|
287 |
e = graph.oppositeArc(e);
|
deba@57
|
288 |
ue = e;
|
deba@57
|
289 |
bool d = graph.direction(e);
|
deba@57
|
290 |
ignore_unused_variable_warning(d);
|
alpar@209
|
291 |
}
|
alpar@209
|
292 |
}
|
alpar@209
|
293 |
|
alpar@209
|
294 |
const _Graph& graph;
|
alpar@953
|
295 |
Constraints() {}
|
deba@57
|
296 |
};
|
deba@57
|
297 |
|
deba@57
|
298 |
};
|
deba@57
|
299 |
|
kpeter@579
|
300 |
/// \brief Skeleton class for \e idable directed graphs.
|
alpar@209
|
301 |
///
|
kpeter@579
|
302 |
/// This class describes the interface of \e idable directed graphs.
|
kpeter@579
|
303 |
/// It extends \ref BaseDigraphComponent with the core ID functions.
|
kpeter@579
|
304 |
/// The ids of the items must be unique and immutable.
|
kpeter@579
|
305 |
/// This concept is part of the Digraph concept.
|
kpeter@559
|
306 |
template <typename BAS = BaseDigraphComponent>
|
kpeter@559
|
307 |
class IDableDigraphComponent : public BAS {
|
deba@57
|
308 |
public:
|
deba@57
|
309 |
|
kpeter@559
|
310 |
typedef BAS Base;
|
deba@57
|
311 |
typedef typename Base::Node Node;
|
deba@57
|
312 |
typedef typename Base::Arc Arc;
|
deba@57
|
313 |
|
kpeter@579
|
314 |
/// \brief Return a unique integer id for the given node.
|
deba@57
|
315 |
///
|
kpeter@579
|
316 |
/// This function returns a unique integer id for the given node.
|
kpeter@579
|
317 |
int id(const Node&) const { return -1; }
|
kpeter@579
|
318 |
|
kpeter@579
|
319 |
/// \brief Return the node by its unique id.
|
deba@57
|
320 |
///
|
kpeter@579
|
321 |
/// This function returns the node by its unique id.
|
kpeter@579
|
322 |
/// If the digraph does not contain a node with the given id,
|
kpeter@579
|
323 |
/// then the result of the function is undefined.
|
kpeter@579
|
324 |
Node nodeFromId(int) const { return INVALID; }
|
deba@57
|
325 |
|
kpeter@579
|
326 |
/// \brief Return a unique integer id for the given arc.
|
deba@57
|
327 |
///
|
kpeter@579
|
328 |
/// This function returns a unique integer id for the given arc.
|
kpeter@579
|
329 |
int id(const Arc&) const { return -1; }
|
deba@57
|
330 |
|
kpeter@579
|
331 |
/// \brief Return the arc by its unique id.
|
deba@57
|
332 |
///
|
kpeter@579
|
333 |
/// This function returns the arc by its unique id.
|
kpeter@579
|
334 |
/// If the digraph does not contain an arc with the given id,
|
kpeter@579
|
335 |
/// then the result of the function is undefined.
|
kpeter@579
|
336 |
Arc arcFromId(int) const { return INVALID; }
|
kpeter@579
|
337 |
|
kpeter@579
|
338 |
/// \brief Return an integer greater or equal to the maximum
|
kpeter@579
|
339 |
/// node id.
|
deba@57
|
340 |
///
|
kpeter@579
|
341 |
/// This function returns an integer greater or equal to the
|
kpeter@579
|
342 |
/// maximum node id.
|
kpeter@579
|
343 |
int maxNodeId() const { return -1; }
|
deba@57
|
344 |
|
kpeter@579
|
345 |
/// \brief Return an integer greater or equal to the maximum
|
kpeter@579
|
346 |
/// arc id.
|
deba@57
|
347 |
///
|
kpeter@579
|
348 |
/// This function returns an integer greater or equal to the
|
kpeter@579
|
349 |
/// maximum arc id.
|
kpeter@579
|
350 |
int maxArcId() const { return -1; }
|
deba@57
|
351 |
|
deba@57
|
352 |
template <typename _Digraph>
|
deba@57
|
353 |
struct Constraints {
|
deba@57
|
354 |
|
alpar@209
|
355 |
void constraints() {
|
alpar@209
|
356 |
checkConcept<Base, _Digraph >();
|
alpar@209
|
357 |
typename _Digraph::Node node;
|
alpar@666
|
358 |
node=INVALID;
|
alpar@209
|
359 |
int nid = digraph.id(node);
|
alpar@209
|
360 |
nid = digraph.id(node);
|
alpar@209
|
361 |
node = digraph.nodeFromId(nid);
|
alpar@209
|
362 |
typename _Digraph::Arc arc;
|
alpar@666
|
363 |
arc=INVALID;
|
alpar@209
|
364 |
int eid = digraph.id(arc);
|
alpar@209
|
365 |
eid = digraph.id(arc);
|
alpar@209
|
366 |
arc = digraph.arcFromId(eid);
|
deba@57
|
367 |
|
alpar@209
|
368 |
nid = digraph.maxNodeId();
|
alpar@209
|
369 |
ignore_unused_variable_warning(nid);
|
alpar@209
|
370 |
eid = digraph.maxArcId();
|
alpar@209
|
371 |
ignore_unused_variable_warning(eid);
|
alpar@209
|
372 |
}
|
deba@57
|
373 |
|
alpar@209
|
374 |
const _Digraph& digraph;
|
alpar@953
|
375 |
Constraints() {}
|
deba@57
|
376 |
};
|
deba@57
|
377 |
};
|
deba@57
|
378 |
|
kpeter@579
|
379 |
/// \brief Skeleton class for \e idable undirected graphs.
|
alpar@209
|
380 |
///
|
kpeter@579
|
381 |
/// This class describes the interface of \e idable undirected
|
kpeter@579
|
382 |
/// graphs. It extends \ref IDableDigraphComponent with the core ID
|
kpeter@579
|
383 |
/// functions of undirected graphs.
|
kpeter@579
|
384 |
/// The ids of the items must be unique and immutable.
|
kpeter@579
|
385 |
/// This concept is part of the Graph concept.
|
kpeter@559
|
386 |
template <typename BAS = BaseGraphComponent>
|
kpeter@559
|
387 |
class IDableGraphComponent : public IDableDigraphComponent<BAS> {
|
deba@57
|
388 |
public:
|
deba@57
|
389 |
|
kpeter@559
|
390 |
typedef BAS Base;
|
deba@57
|
391 |
typedef typename Base::Edge Edge;
|
deba@57
|
392 |
|
kpeter@559
|
393 |
using IDableDigraphComponent<Base>::id;
|
deba@57
|
394 |
|
kpeter@579
|
395 |
/// \brief Return a unique integer id for the given edge.
|
deba@57
|
396 |
///
|
kpeter@579
|
397 |
/// This function returns a unique integer id for the given edge.
|
kpeter@579
|
398 |
int id(const Edge&) const { return -1; }
|
kpeter@579
|
399 |
|
kpeter@579
|
400 |
/// \brief Return the edge by its unique id.
|
deba@57
|
401 |
///
|
kpeter@579
|
402 |
/// This function returns the edge by its unique id.
|
kpeter@579
|
403 |
/// If the graph does not contain an edge with the given id,
|
kpeter@579
|
404 |
/// then the result of the function is undefined.
|
kpeter@579
|
405 |
Edge edgeFromId(int) const { return INVALID; }
|
deba@57
|
406 |
|
kpeter@579
|
407 |
/// \brief Return an integer greater or equal to the maximum
|
kpeter@579
|
408 |
/// edge id.
|
deba@57
|
409 |
///
|
kpeter@579
|
410 |
/// This function returns an integer greater or equal to the
|
kpeter@579
|
411 |
/// maximum edge id.
|
kpeter@579
|
412 |
int maxEdgeId() const { return -1; }
|
deba@57
|
413 |
|
deba@57
|
414 |
template <typename _Graph>
|
deba@57
|
415 |
struct Constraints {
|
deba@57
|
416 |
|
alpar@209
|
417 |
void constraints() {
|
alpar@209
|
418 |
checkConcept<IDableDigraphComponent<Base>, _Graph >();
|
alpar@209
|
419 |
typename _Graph::Edge edge;
|
alpar@209
|
420 |
int ueid = graph.id(edge);
|
alpar@209
|
421 |
ueid = graph.id(edge);
|
alpar@209
|
422 |
edge = graph.edgeFromId(ueid);
|
alpar@209
|
423 |
ueid = graph.maxEdgeId();
|
alpar@209
|
424 |
ignore_unused_variable_warning(ueid);
|
alpar@209
|
425 |
}
|
deba@57
|
426 |
|
alpar@209
|
427 |
const _Graph& graph;
|
alpar@953
|
428 |
Constraints() {}
|
deba@57
|
429 |
};
|
deba@57
|
430 |
};
|
deba@57
|
431 |
|
kpeter@579
|
432 |
/// \brief Concept class for \c NodeIt, \c ArcIt and \c EdgeIt types.
|
deba@57
|
433 |
///
|
kpeter@579
|
434 |
/// This class describes the concept of \c NodeIt, \c ArcIt and
|
kpeter@579
|
435 |
/// \c EdgeIt subtypes of digraph and graph types.
|
kpeter@559
|
436 |
template <typename GR, typename Item>
|
kpeter@559
|
437 |
class GraphItemIt : public Item {
|
deba@57
|
438 |
public:
|
deba@57
|
439 |
/// \brief Default constructor.
|
deba@57
|
440 |
///
|
kpeter@579
|
441 |
/// Default constructor.
|
kpeter@579
|
442 |
/// \warning The default constructor is not required to set
|
kpeter@579
|
443 |
/// the iterator to some well-defined value. So you should consider it
|
kpeter@579
|
444 |
/// as uninitialized.
|
deba@57
|
445 |
GraphItemIt() {}
|
kpeter@579
|
446 |
|
deba@57
|
447 |
/// \brief Copy constructor.
|
deba@57
|
448 |
///
|
deba@57
|
449 |
/// Copy constructor.
|
kpeter@579
|
450 |
GraphItemIt(const GraphItemIt& it) : Item(it) {}
|
kpeter@579
|
451 |
|
kpeter@579
|
452 |
/// \brief Constructor that sets the iterator to the first item.
|
deba@57
|
453 |
///
|
kpeter@579
|
454 |
/// Constructor that sets the iterator to the first item.
|
kpeter@579
|
455 |
explicit GraphItemIt(const GR&) {}
|
kpeter@579
|
456 |
|
kpeter@579
|
457 |
/// \brief Constructor for conversion from \c INVALID.
|
deba@57
|
458 |
///
|
kpeter@579
|
459 |
/// Constructor for conversion from \c INVALID.
|
kpeter@579
|
460 |
/// It initializes the iterator to be invalid.
|
deba@57
|
461 |
/// \sa Invalid for more details.
|
deba@57
|
462 |
GraphItemIt(Invalid) {}
|
kpeter@579
|
463 |
|
kpeter@579
|
464 |
/// \brief Assignment operator.
|
deba@57
|
465 |
///
|
kpeter@579
|
466 |
/// Assignment operator for the iterator.
|
kpeter@579
|
467 |
GraphItemIt& operator=(const GraphItemIt&) { return *this; }
|
kpeter@579
|
468 |
|
kpeter@579
|
469 |
/// \brief Increment the iterator.
|
deba@57
|
470 |
///
|
kpeter@579
|
471 |
/// This operator increments the iterator, i.e. assigns it to the
|
kpeter@579
|
472 |
/// next item.
|
deba@57
|
473 |
GraphItemIt& operator++() { return *this; }
|
kpeter@579
|
474 |
|
deba@57
|
475 |
/// \brief Equality operator
|
alpar@209
|
476 |
///
|
kpeter@579
|
477 |
/// Equality operator.
|
deba@57
|
478 |
/// Two iterators are equal if and only if they point to the
|
deba@57
|
479 |
/// same object or both are invalid.
|
deba@57
|
480 |
bool operator==(const GraphItemIt&) const { return true;}
|
kpeter@579
|
481 |
|
deba@57
|
482 |
/// \brief Inequality operator
|
alpar@209
|
483 |
///
|
kpeter@579
|
484 |
/// Inequality operator.
|
kpeter@579
|
485 |
/// Two iterators are equal if and only if they point to the
|
kpeter@579
|
486 |
/// same object or both are invalid.
|
deba@57
|
487 |
bool operator!=(const GraphItemIt&) const { return true;}
|
alpar@209
|
488 |
|
deba@57
|
489 |
template<typename _GraphItemIt>
|
deba@57
|
490 |
struct Constraints {
|
alpar@209
|
491 |
void constraints() {
|
kpeter@579
|
492 |
checkConcept<GraphItem<>, _GraphItemIt>();
|
alpar@209
|
493 |
_GraphItemIt it1(g);
|
alpar@209
|
494 |
_GraphItemIt it2;
|
kpeter@579
|
495 |
_GraphItemIt it3 = it1;
|
kpeter@579
|
496 |
_GraphItemIt it4 = INVALID;
|
deba@57
|
497 |
|
alpar@209
|
498 |
it2 = ++it1;
|
alpar@209
|
499 |
++it2 = it1;
|
alpar@209
|
500 |
++(++it1);
|
deba@57
|
501 |
|
kpeter@559
|
502 |
Item bi = it1;
|
alpar@209
|
503 |
bi = it2;
|
alpar@209
|
504 |
}
|
kpeter@579
|
505 |
const GR& g;
|
alpar@953
|
506 |
Constraints() {}
|
deba@57
|
507 |
};
|
deba@57
|
508 |
};
|
deba@57
|
509 |
|
kpeter@579
|
510 |
/// \brief Concept class for \c InArcIt, \c OutArcIt and
|
kpeter@579
|
511 |
/// \c IncEdgeIt types.
|
deba@57
|
512 |
///
|
kpeter@579
|
513 |
/// This class describes the concept of \c InArcIt, \c OutArcIt
|
kpeter@579
|
514 |
/// and \c IncEdgeIt subtypes of digraph and graph types.
|
kpeter@579
|
515 |
///
|
kpeter@579
|
516 |
/// \note Since these iterator classes do not inherit from the same
|
kpeter@579
|
517 |
/// base class, there is an additional template parameter (selector)
|
kpeter@579
|
518 |
/// \c sel. For \c InArcIt you should instantiate it with character
|
kpeter@579
|
519 |
/// \c 'i', for \c OutArcIt with \c 'o' and for \c IncEdgeIt with \c 'e'.
|
kpeter@559
|
520 |
template <typename GR,
|
kpeter@559
|
521 |
typename Item = typename GR::Arc,
|
kpeter@559
|
522 |
typename Base = typename GR::Node,
|
kpeter@559
|
523 |
char sel = '0'>
|
kpeter@559
|
524 |
class GraphIncIt : public Item {
|
deba@57
|
525 |
public:
|
deba@57
|
526 |
/// \brief Default constructor.
|
deba@57
|
527 |
///
|
kpeter@579
|
528 |
/// Default constructor.
|
kpeter@579
|
529 |
/// \warning The default constructor is not required to set
|
kpeter@579
|
530 |
/// the iterator to some well-defined value. So you should consider it
|
kpeter@579
|
531 |
/// as uninitialized.
|
deba@57
|
532 |
GraphIncIt() {}
|
kpeter@579
|
533 |
|
deba@57
|
534 |
/// \brief Copy constructor.
|
deba@57
|
535 |
///
|
deba@57
|
536 |
/// Copy constructor.
|
kpeter@579
|
537 |
GraphIncIt(const GraphIncIt& it) : Item(it) {}
|
kpeter@579
|
538 |
|
kpeter@579
|
539 |
/// \brief Constructor that sets the iterator to the first
|
kpeter@579
|
540 |
/// incoming or outgoing arc.
|
deba@57
|
541 |
///
|
kpeter@579
|
542 |
/// Constructor that sets the iterator to the first arc
|
kpeter@579
|
543 |
/// incoming to or outgoing from the given node.
|
kpeter@579
|
544 |
explicit GraphIncIt(const GR&, const Base&) {}
|
kpeter@579
|
545 |
|
kpeter@579
|
546 |
/// \brief Constructor for conversion from \c INVALID.
|
deba@57
|
547 |
///
|
kpeter@579
|
548 |
/// Constructor for conversion from \c INVALID.
|
kpeter@579
|
549 |
/// It initializes the iterator to be invalid.
|
deba@57
|
550 |
/// \sa Invalid for more details.
|
deba@57
|
551 |
GraphIncIt(Invalid) {}
|
kpeter@579
|
552 |
|
kpeter@579
|
553 |
/// \brief Assignment operator.
|
deba@57
|
554 |
///
|
kpeter@579
|
555 |
/// Assignment operator for the iterator.
|
kpeter@579
|
556 |
GraphIncIt& operator=(const GraphIncIt&) { return *this; }
|
kpeter@579
|
557 |
|
kpeter@579
|
558 |
/// \brief Increment the iterator.
|
deba@57
|
559 |
///
|
kpeter@579
|
560 |
/// This operator increments the iterator, i.e. assigns it to the
|
kpeter@579
|
561 |
/// next arc incoming to or outgoing from the given node.
|
deba@57
|
562 |
GraphIncIt& operator++() { return *this; }
|
deba@57
|
563 |
|
deba@57
|
564 |
/// \brief Equality operator
|
deba@57
|
565 |
///
|
kpeter@579
|
566 |
/// Equality operator.
|
deba@57
|
567 |
/// Two iterators are equal if and only if they point to the
|
deba@57
|
568 |
/// same object or both are invalid.
|
deba@57
|
569 |
bool operator==(const GraphIncIt&) const { return true;}
|
deba@57
|
570 |
|
deba@57
|
571 |
/// \brief Inequality operator
|
deba@57
|
572 |
///
|
kpeter@579
|
573 |
/// Inequality operator.
|
kpeter@579
|
574 |
/// Two iterators are equal if and only if they point to the
|
kpeter@579
|
575 |
/// same object or both are invalid.
|
deba@57
|
576 |
bool operator!=(const GraphIncIt&) const { return true;}
|
deba@57
|
577 |
|
deba@57
|
578 |
template <typename _GraphIncIt>
|
deba@57
|
579 |
struct Constraints {
|
alpar@209
|
580 |
void constraints() {
|
kpeter@559
|
581 |
checkConcept<GraphItem<sel>, _GraphIncIt>();
|
alpar@209
|
582 |
_GraphIncIt it1(graph, node);
|
alpar@209
|
583 |
_GraphIncIt it2;
|
kpeter@579
|
584 |
_GraphIncIt it3 = it1;
|
kpeter@579
|
585 |
_GraphIncIt it4 = INVALID;
|
deba@57
|
586 |
|
alpar@209
|
587 |
it2 = ++it1;
|
alpar@209
|
588 |
++it2 = it1;
|
alpar@209
|
589 |
++(++it1);
|
kpeter@559
|
590 |
Item e = it1;
|
alpar@209
|
591 |
e = it2;
|
alpar@209
|
592 |
}
|
kpeter@579
|
593 |
const Base& node;
|
kpeter@579
|
594 |
const GR& graph;
|
alpar@953
|
595 |
Constraints() {}
|
deba@57
|
596 |
};
|
deba@57
|
597 |
};
|
deba@57
|
598 |
|
kpeter@579
|
599 |
/// \brief Skeleton class for iterable directed graphs.
|
deba@57
|
600 |
///
|
kpeter@579
|
601 |
/// This class describes the interface of iterable directed
|
kpeter@579
|
602 |
/// graphs. It extends \ref BaseDigraphComponent with the core
|
kpeter@579
|
603 |
/// iterable interface.
|
deba@57
|
604 |
/// This concept is part of the Digraph concept.
|
kpeter@559
|
605 |
template <typename BAS = BaseDigraphComponent>
|
kpeter@559
|
606 |
class IterableDigraphComponent : public BAS {
|
deba@57
|
607 |
|
deba@57
|
608 |
public:
|
alpar@209
|
609 |
|
kpeter@559
|
610 |
typedef BAS Base;
|
deba@57
|
611 |
typedef typename Base::Node Node;
|
deba@57
|
612 |
typedef typename Base::Arc Arc;
|
deba@57
|
613 |
|
deba@57
|
614 |
typedef IterableDigraphComponent Digraph;
|
deba@57
|
615 |
|
kpeter@584
|
616 |
/// \name Base Iteration
|
alpar@209
|
617 |
///
|
kpeter@579
|
618 |
/// This interface provides functions for iteration on digraph items.
|
deba@57
|
619 |
///
|
alpar@209
|
620 |
/// @{
|
deba@57
|
621 |
|
kpeter@579
|
622 |
/// \brief Return the first node.
|
alpar@209
|
623 |
///
|
kpeter@579
|
624 |
/// This function gives back the first node in the iteration order.
|
deba@57
|
625 |
void first(Node&) const {}
|
deba@57
|
626 |
|
kpeter@579
|
627 |
/// \brief Return the next node.
|
deba@57
|
628 |
///
|
kpeter@579
|
629 |
/// This function gives back the next node in the iteration order.
|
deba@57
|
630 |
void next(Node&) const {}
|
deba@57
|
631 |
|
kpeter@579
|
632 |
/// \brief Return the first arc.
|
deba@57
|
633 |
///
|
kpeter@579
|
634 |
/// This function gives back the first arc in the iteration order.
|
deba@57
|
635 |
void first(Arc&) const {}
|
deba@57
|
636 |
|
kpeter@579
|
637 |
/// \brief Return the next arc.
|
deba@57
|
638 |
///
|
kpeter@579
|
639 |
/// This function gives back the next arc in the iteration order.
|
deba@57
|
640 |
void next(Arc&) const {}
|
deba@57
|
641 |
|
kpeter@579
|
642 |
/// \brief Return the first arc incomming to the given node.
|
deba@57
|
643 |
///
|
kpeter@579
|
644 |
/// This function gives back the first arc incomming to the
|
kpeter@579
|
645 |
/// given node.
|
deba@57
|
646 |
void firstIn(Arc&, const Node&) const {}
|
deba@57
|
647 |
|
kpeter@579
|
648 |
/// \brief Return the next arc incomming to the given node.
|
deba@57
|
649 |
///
|
kpeter@579
|
650 |
/// This function gives back the next arc incomming to the
|
kpeter@579
|
651 |
/// given node.
|
deba@57
|
652 |
void nextIn(Arc&) const {}
|
deba@57
|
653 |
|
kpeter@579
|
654 |
/// \brief Return the first arc outgoing form the given node.
|
kpeter@579
|
655 |
///
|
kpeter@579
|
656 |
/// This function gives back the first arc outgoing form the
|
deba@57
|
657 |
/// given node.
|
deba@57
|
658 |
void firstOut(Arc&, const Node&) const {}
|
deba@57
|
659 |
|
kpeter@579
|
660 |
/// \brief Return the next arc outgoing form the given node.
|
deba@57
|
661 |
///
|
kpeter@579
|
662 |
/// This function gives back the next arc outgoing form the
|
kpeter@579
|
663 |
/// given node.
|
deba@57
|
664 |
void nextOut(Arc&) const {}
|
deba@57
|
665 |
|
deba@57
|
666 |
/// @}
|
deba@57
|
667 |
|
kpeter@584
|
668 |
/// \name Class Based Iteration
|
alpar@209
|
669 |
///
|
kpeter@579
|
670 |
/// This interface provides iterator classes for digraph items.
|
deba@57
|
671 |
///
|
deba@57
|
672 |
/// @{
|
deba@57
|
673 |
|
deba@57
|
674 |
/// \brief This iterator goes through each node.
|
deba@57
|
675 |
///
|
deba@57
|
676 |
/// This iterator goes through each node.
|
deba@57
|
677 |
///
|
deba@57
|
678 |
typedef GraphItemIt<Digraph, Node> NodeIt;
|
deba@57
|
679 |
|
kpeter@579
|
680 |
/// \brief This iterator goes through each arc.
|
deba@57
|
681 |
///
|
kpeter@579
|
682 |
/// This iterator goes through each arc.
|
deba@57
|
683 |
///
|
deba@57
|
684 |
typedef GraphItemIt<Digraph, Arc> ArcIt;
|
deba@57
|
685 |
|
deba@57
|
686 |
/// \brief This iterator goes trough the incoming arcs of a node.
|
deba@57
|
687 |
///
|
kpeter@579
|
688 |
/// This iterator goes trough the \e incoming arcs of a certain node
|
deba@57
|
689 |
/// of a digraph.
|
deba@57
|
690 |
typedef GraphIncIt<Digraph, Arc, Node, 'i'> InArcIt;
|
deba@57
|
691 |
|
deba@57
|
692 |
/// \brief This iterator goes trough the outgoing arcs of a node.
|
deba@57
|
693 |
///
|
deba@57
|
694 |
/// This iterator goes trough the \e outgoing arcs of a certain node
|
deba@57
|
695 |
/// of a digraph.
|
deba@57
|
696 |
typedef GraphIncIt<Digraph, Arc, Node, 'o'> OutArcIt;
|
deba@57
|
697 |
|
deba@57
|
698 |
/// \brief The base node of the iterator.
|
deba@57
|
699 |
///
|
kpeter@579
|
700 |
/// This function gives back the base node of the iterator.
|
kpeter@579
|
701 |
/// It is always the target node of the pointed arc.
|
deba@57
|
702 |
Node baseNode(const InArcIt&) const { return INVALID; }
|
deba@57
|
703 |
|
deba@57
|
704 |
/// \brief The running node of the iterator.
|
deba@57
|
705 |
///
|
kpeter@579
|
706 |
/// This function gives back the running node of the iterator.
|
kpeter@579
|
707 |
/// It is always the source node of the pointed arc.
|
deba@57
|
708 |
Node runningNode(const InArcIt&) const { return INVALID; }
|
deba@57
|
709 |
|
deba@57
|
710 |
/// \brief The base node of the iterator.
|
deba@57
|
711 |
///
|
kpeter@579
|
712 |
/// This function gives back the base node of the iterator.
|
kpeter@579
|
713 |
/// It is always the source node of the pointed arc.
|
deba@57
|
714 |
Node baseNode(const OutArcIt&) const { return INVALID; }
|
deba@57
|
715 |
|
deba@57
|
716 |
/// \brief The running node of the iterator.
|
deba@57
|
717 |
///
|
kpeter@579
|
718 |
/// This function gives back the running node of the iterator.
|
kpeter@579
|
719 |
/// It is always the target node of the pointed arc.
|
deba@57
|
720 |
Node runningNode(const OutArcIt&) const { return INVALID; }
|
deba@57
|
721 |
|
deba@57
|
722 |
/// @}
|
deba@57
|
723 |
|
alpar@209
|
724 |
template <typename _Digraph>
|
deba@57
|
725 |
struct Constraints {
|
alpar@209
|
726 |
void constraints() {
|
alpar@209
|
727 |
checkConcept<Base, _Digraph>();
|
deba@57
|
728 |
|
deba@57
|
729 |
{
|
alpar@209
|
730 |
typename _Digraph::Node node(INVALID);
|
deba@57
|
731 |
typename _Digraph::Arc arc(INVALID);
|
deba@57
|
732 |
{
|
deba@57
|
733 |
digraph.first(node);
|
deba@57
|
734 |
digraph.next(node);
|
deba@57
|
735 |
}
|
deba@57
|
736 |
{
|
deba@57
|
737 |
digraph.first(arc);
|
deba@57
|
738 |
digraph.next(arc);
|
deba@57
|
739 |
}
|
deba@57
|
740 |
{
|
deba@57
|
741 |
digraph.firstIn(arc, node);
|
deba@57
|
742 |
digraph.nextIn(arc);
|
deba@57
|
743 |
}
|
deba@57
|
744 |
{
|
deba@57
|
745 |
digraph.firstOut(arc, node);
|
deba@57
|
746 |
digraph.nextOut(arc);
|
deba@57
|
747 |
}
|
alpar@209
|
748 |
}
|
deba@57
|
749 |
|
deba@57
|
750 |
{
|
deba@57
|
751 |
checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>,
|
deba@57
|
752 |
typename _Digraph::ArcIt >();
|
deba@57
|
753 |
checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>,
|
deba@57
|
754 |
typename _Digraph::NodeIt >();
|
alpar@209
|
755 |
checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
|
deba@57
|
756 |
typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>();
|
alpar@209
|
757 |
checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc,
|
deba@57
|
758 |
typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>();
|
deba@57
|
759 |
|
deba@57
|
760 |
typename _Digraph::Node n;
|
kpeter@579
|
761 |
const typename _Digraph::InArcIt iait(INVALID);
|
kpeter@579
|
762 |
const typename _Digraph::OutArcIt oait(INVALID);
|
kpeter@579
|
763 |
n = digraph.baseNode(iait);
|
kpeter@579
|
764 |
n = digraph.runningNode(iait);
|
kpeter@579
|
765 |
n = digraph.baseNode(oait);
|
kpeter@579
|
766 |
n = digraph.runningNode(oait);
|
deba@57
|
767 |
ignore_unused_variable_warning(n);
|
deba@57
|
768 |
}
|
deba@57
|
769 |
}
|
alpar@209
|
770 |
|
alpar@209
|
771 |
const _Digraph& digraph;
|
alpar@953
|
772 |
Constraints() {}
|
deba@57
|
773 |
};
|
deba@57
|
774 |
};
|
deba@57
|
775 |
|
kpeter@579
|
776 |
/// \brief Skeleton class for iterable undirected graphs.
|
deba@57
|
777 |
///
|
kpeter@579
|
778 |
/// This class describes the interface of iterable undirected
|
kpeter@579
|
779 |
/// graphs. It extends \ref IterableDigraphComponent with the core
|
kpeter@579
|
780 |
/// iterable interface of undirected graphs.
|
deba@57
|
781 |
/// This concept is part of the Graph concept.
|
kpeter@559
|
782 |
template <typename BAS = BaseGraphComponent>
|
kpeter@559
|
783 |
class IterableGraphComponent : public IterableDigraphComponent<BAS> {
|
deba@57
|
784 |
public:
|
deba@57
|
785 |
|
kpeter@559
|
786 |
typedef BAS Base;
|
deba@57
|
787 |
typedef typename Base::Node Node;
|
deba@57
|
788 |
typedef typename Base::Arc Arc;
|
deba@57
|
789 |
typedef typename Base::Edge Edge;
|
deba@57
|
790 |
|
alpar@209
|
791 |
|
deba@57
|
792 |
typedef IterableGraphComponent Graph;
|
deba@57
|
793 |
|
kpeter@584
|
794 |
/// \name Base Iteration
|
alpar@209
|
795 |
///
|
kpeter@579
|
796 |
/// This interface provides functions for iteration on edges.
|
kpeter@579
|
797 |
///
|
alpar@209
|
798 |
/// @{
|
deba@57
|
799 |
|
kpeter@559
|
800 |
using IterableDigraphComponent<Base>::first;
|
kpeter@559
|
801 |
using IterableDigraphComponent<Base>::next;
|
deba@57
|
802 |
|
kpeter@579
|
803 |
/// \brief Return the first edge.
|
deba@57
|
804 |
///
|
kpeter@579
|
805 |
/// This function gives back the first edge in the iteration order.
|
deba@57
|
806 |
void first(Edge&) const {}
|
deba@57
|
807 |
|
kpeter@579
|
808 |
/// \brief Return the next edge.
|
deba@57
|
809 |
///
|
kpeter@579
|
810 |
/// This function gives back the next edge in the iteration order.
|
deba@57
|
811 |
void next(Edge&) const {}
|
deba@57
|
812 |
|
kpeter@579
|
813 |
/// \brief Return the first edge incident to the given node.
|
kpeter@579
|
814 |
///
|
kpeter@579
|
815 |
/// This function gives back the first edge incident to the given
|
kpeter@579
|
816 |
/// node. The bool parameter gives back the direction for which the
|
kpeter@579
|
817 |
/// source node of the directed arc representing the edge is the
|
deba@57
|
818 |
/// given node.
|
deba@57
|
819 |
void firstInc(Edge&, bool&, const Node&) const {}
|
deba@57
|
820 |
|
deba@57
|
821 |
/// \brief Gives back the next of the edges from the
|
deba@57
|
822 |
/// given node.
|
deba@57
|
823 |
///
|
kpeter@579
|
824 |
/// This function gives back the next edge incident to the given
|
kpeter@579
|
825 |
/// node. The bool parameter should be used as \c firstInc() use it.
|
deba@57
|
826 |
void nextInc(Edge&, bool&) const {}
|
deba@57
|
827 |
|
kpeter@559
|
828 |
using IterableDigraphComponent<Base>::baseNode;
|
kpeter@559
|
829 |
using IterableDigraphComponent<Base>::runningNode;
|
deba@57
|
830 |
|
deba@57
|
831 |
/// @}
|
deba@57
|
832 |
|
kpeter@584
|
833 |
/// \name Class Based Iteration
|
alpar@209
|
834 |
///
|
kpeter@579
|
835 |
/// This interface provides iterator classes for edges.
|
deba@57
|
836 |
///
|
deba@57
|
837 |
/// @{
|
deba@57
|
838 |
|
kpeter@579
|
839 |
/// \brief This iterator goes through each edge.
|
deba@57
|
840 |
///
|
kpeter@579
|
841 |
/// This iterator goes through each edge.
|
deba@57
|
842 |
typedef GraphItemIt<Graph, Edge> EdgeIt;
|
kpeter@579
|
843 |
|
kpeter@579
|
844 |
/// \brief This iterator goes trough the incident edges of a
|
deba@57
|
845 |
/// node.
|
deba@57
|
846 |
///
|
kpeter@579
|
847 |
/// This iterator goes trough the incident edges of a certain
|
deba@57
|
848 |
/// node of a graph.
|
kpeter@579
|
849 |
typedef GraphIncIt<Graph, Edge, Node, 'e'> IncEdgeIt;
|
kpeter@579
|
850 |
|
deba@57
|
851 |
/// \brief The base node of the iterator.
|
deba@57
|
852 |
///
|
kpeter@579
|
853 |
/// This function gives back the base node of the iterator.
|
deba@78
|
854 |
Node baseNode(const IncEdgeIt&) const { return INVALID; }
|
deba@57
|
855 |
|
deba@57
|
856 |
/// \brief The running node of the iterator.
|
deba@57
|
857 |
///
|
kpeter@579
|
858 |
/// This function gives back the running node of the iterator.
|
deba@78
|
859 |
Node runningNode(const IncEdgeIt&) const { return INVALID; }
|
deba@57
|
860 |
|
deba@57
|
861 |
/// @}
|
deba@57
|
862 |
|
alpar@209
|
863 |
template <typename _Graph>
|
deba@57
|
864 |
struct Constraints {
|
alpar@209
|
865 |
void constraints() {
|
alpar@209
|
866 |
checkConcept<IterableDigraphComponent<Base>, _Graph>();
|
deba@57
|
867 |
|
deba@57
|
868 |
{
|
deba@57
|
869 |
typename _Graph::Node node(INVALID);
|
deba@57
|
870 |
typename _Graph::Edge edge(INVALID);
|
deba@57
|
871 |
bool dir;
|
deba@57
|
872 |
{
|
deba@57
|
873 |
graph.first(edge);
|
deba@57
|
874 |
graph.next(edge);
|
deba@57
|
875 |
}
|
deba@57
|
876 |
{
|
deba@57
|
877 |
graph.firstInc(edge, dir, node);
|
deba@57
|
878 |
graph.nextInc(edge, dir);
|
deba@57
|
879 |
}
|
alpar@209
|
880 |
|
alpar@209
|
881 |
}
|
alpar@209
|
882 |
|
deba@57
|
883 |
{
|
deba@57
|
884 |
checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>,
|
deba@57
|
885 |
typename _Graph::EdgeIt >();
|
alpar@209
|
886 |
checkConcept<GraphIncIt<_Graph, typename _Graph::Edge,
|
kpeter@579
|
887 |
typename _Graph::Node, 'e'>, typename _Graph::IncEdgeIt>();
|
alpar@209
|
888 |
|
deba@57
|
889 |
typename _Graph::Node n;
|
kpeter@579
|
890 |
const typename _Graph::IncEdgeIt ieit(INVALID);
|
kpeter@579
|
891 |
n = graph.baseNode(ieit);
|
kpeter@579
|
892 |
n = graph.runningNode(ieit);
|
deba@57
|
893 |
}
|
deba@57
|
894 |
}
|
alpar@209
|
895 |
|
alpar@209
|
896 |
const _Graph& graph;
|
alpar@953
|
897 |
Constraints() {}
|
deba@57
|
898 |
};
|
deba@57
|
899 |
};
|
deba@57
|
900 |
|
kpeter@579
|
901 |
/// \brief Skeleton class for alterable directed graphs.
|
alpar@209
|
902 |
///
|
kpeter@579
|
903 |
/// This class describes the interface of alterable directed
|
kpeter@579
|
904 |
/// graphs. It extends \ref BaseDigraphComponent with the alteration
|
kpeter@579
|
905 |
/// notifier interface. It implements
|
deba@57
|
906 |
/// an observer-notifier pattern for each digraph item. More
|
deba@57
|
907 |
/// obsevers can be registered into the notifier and whenever an
|
kpeter@579
|
908 |
/// alteration occured in the digraph all the observers will be
|
deba@57
|
909 |
/// notified about it.
|
kpeter@559
|
910 |
template <typename BAS = BaseDigraphComponent>
|
kpeter@559
|
911 |
class AlterableDigraphComponent : public BAS {
|
deba@57
|
912 |
public:
|
deba@57
|
913 |
|
kpeter@559
|
914 |
typedef BAS Base;
|
deba@57
|
915 |
typedef typename Base::Node Node;
|
deba@57
|
916 |
typedef typename Base::Arc Arc;
|
deba@57
|
917 |
|
deba@57
|
918 |
|
kpeter@579
|
919 |
/// Node alteration notifier class.
|
alpar@209
|
920 |
typedef AlterationNotifier<AlterableDigraphComponent, Node>
|
deba@57
|
921 |
NodeNotifier;
|
kpeter@579
|
922 |
/// Arc alteration notifier class.
|
alpar@209
|
923 |
typedef AlterationNotifier<AlterableDigraphComponent, Arc>
|
deba@57
|
924 |
ArcNotifier;
|
alpar@209
|
925 |
|
kpeter@579
|
926 |
/// \brief Return the node alteration notifier.
|
deba@57
|
927 |
///
|
kpeter@579
|
928 |
/// This function gives back the node alteration notifier.
|
deba@57
|
929 |
NodeNotifier& notifier(Node) const {
|
kpeter@579
|
930 |
return NodeNotifier();
|
deba@57
|
931 |
}
|
alpar@209
|
932 |
|
kpeter@579
|
933 |
/// \brief Return the arc alteration notifier.
|
deba@57
|
934 |
///
|
kpeter@579
|
935 |
/// This function gives back the arc alteration notifier.
|
deba@57
|
936 |
ArcNotifier& notifier(Arc) const {
|
alpar@209
|
937 |
return ArcNotifier();
|
deba@57
|
938 |
}
|
deba@57
|
939 |
|
alpar@209
|
940 |
template <typename _Digraph>
|
deba@57
|
941 |
struct Constraints {
|
alpar@209
|
942 |
void constraints() {
|
alpar@209
|
943 |
checkConcept<Base, _Digraph>();
|
alpar@209
|
944 |
typename _Digraph::NodeNotifier& nn
|
deba@57
|
945 |
= digraph.notifier(typename _Digraph::Node());
|
deba@57
|
946 |
|
alpar@209
|
947 |
typename _Digraph::ArcNotifier& en
|
deba@57
|
948 |
= digraph.notifier(typename _Digraph::Arc());
|
alpar@209
|
949 |
|
deba@57
|
950 |
ignore_unused_variable_warning(nn);
|
deba@57
|
951 |
ignore_unused_variable_warning(en);
|
alpar@209
|
952 |
}
|
alpar@209
|
953 |
|
alpar@209
|
954 |
const _Digraph& digraph;
|
alpar@953
|
955 |
Constraints() {}
|
deba@57
|
956 |
};
|
deba@57
|
957 |
};
|
deba@57
|
958 |
|
kpeter@579
|
959 |
/// \brief Skeleton class for alterable undirected graphs.
|
alpar@209
|
960 |
///
|
kpeter@579
|
961 |
/// This class describes the interface of alterable undirected
|
kpeter@579
|
962 |
/// graphs. It extends \ref AlterableDigraphComponent with the alteration
|
kpeter@579
|
963 |
/// notifier interface of undirected graphs. It implements
|
kpeter@579
|
964 |
/// an observer-notifier pattern for the edges. More
|
deba@57
|
965 |
/// obsevers can be registered into the notifier and whenever an
|
kpeter@579
|
966 |
/// alteration occured in the graph all the observers will be
|
deba@57
|
967 |
/// notified about it.
|
kpeter@559
|
968 |
template <typename BAS = BaseGraphComponent>
|
kpeter@559
|
969 |
class AlterableGraphComponent : public AlterableDigraphComponent<BAS> {
|
deba@57
|
970 |
public:
|
deba@57
|
971 |
|
kpeter@559
|
972 |
typedef BAS Base;
|
deba@57
|
973 |
typedef typename Base::Edge Edge;
|
deba@57
|
974 |
|
deba@57
|
975 |
|
kpeter@579
|
976 |
/// Edge alteration notifier class.
|
alpar@209
|
977 |
typedef AlterationNotifier<AlterableGraphComponent, Edge>
|
deba@57
|
978 |
EdgeNotifier;
|
alpar@209
|
979 |
|
kpeter@579
|
980 |
/// \brief Return the edge alteration notifier.
|
deba@57
|
981 |
///
|
kpeter@579
|
982 |
/// This function gives back the edge alteration notifier.
|
deba@57
|
983 |
EdgeNotifier& notifier(Edge) const {
|
alpar@209
|
984 |
return EdgeNotifier();
|
deba@57
|
985 |
}
|
deba@57
|
986 |
|
alpar@209
|
987 |
template <typename _Graph>
|
deba@57
|
988 |
struct Constraints {
|
alpar@209
|
989 |
void constraints() {
|
kpeter@579
|
990 |
checkConcept<AlterableDigraphComponent<Base>, _Graph>();
|
alpar@209
|
991 |
typename _Graph::EdgeNotifier& uen
|
deba@57
|
992 |
= graph.notifier(typename _Graph::Edge());
|
deba@57
|
993 |
ignore_unused_variable_warning(uen);
|
alpar@209
|
994 |
}
|
alpar@209
|
995 |
|
alpar@209
|
996 |
const _Graph& graph;
|
alpar@953
|
997 |
Constraints() {}
|
deba@57
|
998 |
};
|
deba@57
|
999 |
};
|
deba@57
|
1000 |
|
kpeter@579
|
1001 |
/// \brief Concept class for standard graph maps.
|
alpar@209
|
1002 |
///
|
kpeter@579
|
1003 |
/// This class describes the concept of standard graph maps, i.e.
|
kpeter@579
|
1004 |
/// the \c NodeMap, \c ArcMap and \c EdgeMap subtypes of digraph and
|
kpeter@579
|
1005 |
/// graph types, which can be used for associating data to graph items.
|
kpeter@580
|
1006 |
/// The standard graph maps must conform to the ReferenceMap concept.
|
kpeter@559
|
1007 |
template <typename GR, typename K, typename V>
|
kpeter@580
|
1008 |
class GraphMap : public ReferenceMap<K, V, V&, const V&> {
|
kpeter@617
|
1009 |
typedef ReferenceMap<K, V, V&, const V&> Parent;
|
kpeter@617
|
1010 |
|
deba@57
|
1011 |
public:
|
deba@57
|
1012 |
|
deba@57
|
1013 |
/// The key type of the map.
|
kpeter@559
|
1014 |
typedef K Key;
|
deba@57
|
1015 |
/// The value type of the map.
|
kpeter@559
|
1016 |
typedef V Value;
|
kpeter@580
|
1017 |
/// The reference type of the map.
|
kpeter@580
|
1018 |
typedef Value& Reference;
|
kpeter@580
|
1019 |
/// The const reference type of the map.
|
kpeter@580
|
1020 |
typedef const Value& ConstReference;
|
kpeter@580
|
1021 |
|
kpeter@580
|
1022 |
// The reference map tag.
|
kpeter@580
|
1023 |
typedef True ReferenceMapTag;
|
deba@57
|
1024 |
|
deba@57
|
1025 |
/// \brief Construct a new map.
|
deba@57
|
1026 |
///
|
deba@57
|
1027 |
/// Construct a new map for the graph.
|
kpeter@617
|
1028 |
explicit GraphMap(const GR&) {}
|
deba@57
|
1029 |
/// \brief Construct a new map with default value.
|
deba@57
|
1030 |
///
|
kpeter@579
|
1031 |
/// Construct a new map for the graph and initalize the values.
|
kpeter@617
|
1032 |
GraphMap(const GR&, const Value&) {}
|
kpeter@263
|
1033 |
|
kpeter@263
|
1034 |
private:
|
deba@57
|
1035 |
/// \brief Copy constructor.
|
deba@57
|
1036 |
///
|
deba@57
|
1037 |
/// Copy Constructor.
|
deba@57
|
1038 |
GraphMap(const GraphMap&) : Parent() {}
|
alpar@209
|
1039 |
|
kpeter@579
|
1040 |
/// \brief Assignment operator.
|
deba@57
|
1041 |
///
|
kpeter@579
|
1042 |
/// Assignment operator. It does not mofify the underlying graph,
|
deba@57
|
1043 |
/// it just iterates on the current item set and set the map
|
alpar@209
|
1044 |
/// with the value returned by the assigned map.
|
deba@57
|
1045 |
template <typename CMap>
|
alpar@209
|
1046 |
GraphMap& operator=(const CMap&) {
|
deba@57
|
1047 |
checkConcept<ReadMap<Key, Value>, CMap>();
|
deba@57
|
1048 |
return *this;
|
deba@57
|
1049 |
}
|
deba@57
|
1050 |
|
kpeter@263
|
1051 |
public:
|
deba@57
|
1052 |
template<typename _Map>
|
deba@57
|
1053 |
struct Constraints {
|
alpar@209
|
1054 |
void constraints() {
|
kpeter@580
|
1055 |
checkConcept
|
kpeter@580
|
1056 |
<ReferenceMap<Key, Value, Value&, const Value&>, _Map>();
|
kpeter@579
|
1057 |
_Map m1(g);
|
kpeter@579
|
1058 |
_Map m2(g,t);
|
kpeter@579
|
1059 |
|
kpeter@579
|
1060 |
// Copy constructor
|
kpeter@579
|
1061 |
// _Map m3(m);
|
alpar@209
|
1062 |
|
kpeter@579
|
1063 |
// Assignment operator
|
kpeter@263
|
1064 |
// ReadMap<Key, Value> cmap;
|
kpeter@579
|
1065 |
// m3 = cmap;
|
deba@57
|
1066 |
|
kpeter@579
|
1067 |
ignore_unused_variable_warning(m1);
|
kpeter@579
|
1068 |
ignore_unused_variable_warning(m2);
|
kpeter@579
|
1069 |
// ignore_unused_variable_warning(m3);
|
alpar@209
|
1070 |
}
|
deba@57
|
1071 |
|
kpeter@579
|
1072 |
const _Map &m;
|
kpeter@617
|
1073 |
const GR &g;
|
alpar@209
|
1074 |
const typename GraphMap::Value &t;
|
alpar@953
|
1075 |
Constraints() {}
|
deba@57
|
1076 |
};
|
deba@57
|
1077 |
|
deba@57
|
1078 |
};
|
deba@57
|
1079 |
|
kpeter@579
|
1080 |
/// \brief Skeleton class for mappable directed graphs.
|
deba@57
|
1081 |
///
|
kpeter@579
|
1082 |
/// This class describes the interface of mappable directed graphs.
|
kpeter@579
|
1083 |
/// It extends \ref BaseDigraphComponent with the standard digraph
|
kpeter@579
|
1084 |
/// map classes, namely \c NodeMap and \c ArcMap.
|
deba@57
|
1085 |
/// This concept is part of the Digraph concept.
|
kpeter@559
|
1086 |
template <typename BAS = BaseDigraphComponent>
|
kpeter@559
|
1087 |
class MappableDigraphComponent : public BAS {
|
deba@57
|
1088 |
public:
|
deba@57
|
1089 |
|
kpeter@559
|
1090 |
typedef BAS Base;
|
deba@57
|
1091 |
typedef typename Base::Node Node;
|
deba@57
|
1092 |
typedef typename Base::Arc Arc;
|
deba@57
|
1093 |
|
deba@57
|
1094 |
typedef MappableDigraphComponent Digraph;
|
deba@57
|
1095 |
|
kpeter@579
|
1096 |
/// \brief Standard graph map for the nodes.
|
deba@57
|
1097 |
///
|
kpeter@579
|
1098 |
/// Standard graph map for the nodes.
|
kpeter@580
|
1099 |
/// It conforms to the ReferenceMap concept.
|
kpeter@559
|
1100 |
template <typename V>
|
kpeter@579
|
1101 |
class NodeMap : public GraphMap<MappableDigraphComponent, Node, V> {
|
kpeter@559
|
1102 |
typedef GraphMap<MappableDigraphComponent, Node, V> Parent;
|
deba@57
|
1103 |
|
kpeter@617
|
1104 |
public:
|
alpar@209
|
1105 |
/// \brief Construct a new map.
|
alpar@209
|
1106 |
///
|
alpar@209
|
1107 |
/// Construct a new map for the digraph.
|
alpar@209
|
1108 |
explicit NodeMap(const MappableDigraphComponent& digraph)
|
deba@57
|
1109 |
: Parent(digraph) {}
|
deba@57
|
1110 |
|
alpar@209
|
1111 |
/// \brief Construct a new map with default value.
|
alpar@209
|
1112 |
///
|
kpeter@579
|
1113 |
/// Construct a new map for the digraph and initalize the values.
|
kpeter@559
|
1114 |
NodeMap(const MappableDigraphComponent& digraph, const V& value)
|
deba@57
|
1115 |
: Parent(digraph, value) {}
|
deba@57
|
1116 |
|
kpeter@263
|
1117 |
private:
|
alpar@209
|
1118 |
/// \brief Copy constructor.
|
alpar@209
|
1119 |
///
|
alpar@209
|
1120 |
/// Copy Constructor.
|
alpar@209
|
1121 |
NodeMap(const NodeMap& nm) : Parent(nm) {}
|
deba@57
|
1122 |
|
kpeter@579
|
1123 |
/// \brief Assignment operator.
|
alpar@209
|
1124 |
///
|
kpeter@579
|
1125 |
/// Assignment operator.
|
deba@57
|
1126 |
template <typename CMap>
|
alpar@209
|
1127 |
NodeMap& operator=(const CMap&) {
|
kpeter@559
|
1128 |
checkConcept<ReadMap<Node, V>, CMap>();
|
deba@57
|
1129 |
return *this;
|
deba@57
|
1130 |
}
|
deba@57
|
1131 |
|
deba@57
|
1132 |
};
|
deba@57
|
1133 |
|
kpeter@579
|
1134 |
/// \brief Standard graph map for the arcs.
|
deba@57
|
1135 |
///
|
kpeter@579
|
1136 |
/// Standard graph map for the arcs.
|
kpeter@580
|
1137 |
/// It conforms to the ReferenceMap concept.
|
kpeter@559
|
1138 |
template <typename V>
|
kpeter@579
|
1139 |
class ArcMap : public GraphMap<MappableDigraphComponent, Arc, V> {
|
kpeter@559
|
1140 |
typedef GraphMap<MappableDigraphComponent, Arc, V> Parent;
|
deba@57
|
1141 |
|
kpeter@617
|
1142 |
public:
|
alpar@209
|
1143 |
/// \brief Construct a new map.
|
alpar@209
|
1144 |
///
|
alpar@209
|
1145 |
/// Construct a new map for the digraph.
|
alpar@209
|
1146 |
explicit ArcMap(const MappableDigraphComponent& digraph)
|
deba@57
|
1147 |
: Parent(digraph) {}
|
deba@57
|
1148 |
|
alpar@209
|
1149 |
/// \brief Construct a new map with default value.
|
alpar@209
|
1150 |
///
|
kpeter@579
|
1151 |
/// Construct a new map for the digraph and initalize the values.
|
kpeter@559
|
1152 |
ArcMap(const MappableDigraphComponent& digraph, const V& value)
|
deba@57
|
1153 |
: Parent(digraph, value) {}
|
deba@57
|
1154 |
|
kpeter@263
|
1155 |
private:
|
alpar@209
|
1156 |
/// \brief Copy constructor.
|
alpar@209
|
1157 |
///
|
alpar@209
|
1158 |
/// Copy Constructor.
|
alpar@209
|
1159 |
ArcMap(const ArcMap& nm) : Parent(nm) {}
|
deba@57
|
1160 |
|
kpeter@579
|
1161 |
/// \brief Assignment operator.
|
alpar@209
|
1162 |
///
|
kpeter@579
|
1163 |
/// Assignment operator.
|
deba@57
|
1164 |
template <typename CMap>
|
alpar@209
|
1165 |
ArcMap& operator=(const CMap&) {
|
kpeter@559
|
1166 |
checkConcept<ReadMap<Arc, V>, CMap>();
|
deba@57
|
1167 |
return *this;
|
deba@57
|
1168 |
}
|
deba@57
|
1169 |
|
deba@57
|
1170 |
};
|
deba@57
|
1171 |
|
deba@57
|
1172 |
|
deba@57
|
1173 |
template <typename _Digraph>
|
deba@57
|
1174 |
struct Constraints {
|
deba@57
|
1175 |
|
alpar@209
|
1176 |
struct Dummy {
|
alpar@209
|
1177 |
int value;
|
alpar@209
|
1178 |
Dummy() : value(0) {}
|
alpar@209
|
1179 |
Dummy(int _v) : value(_v) {}
|
alpar@209
|
1180 |
};
|
deba@57
|
1181 |
|
alpar@209
|
1182 |
void constraints() {
|
alpar@209
|
1183 |
checkConcept<Base, _Digraph>();
|
alpar@209
|
1184 |
{ // int map test
|
alpar@209
|
1185 |
typedef typename _Digraph::template NodeMap<int> IntNodeMap;
|
alpar@209
|
1186 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>,
|
alpar@209
|
1187 |
IntNodeMap >();
|
alpar@209
|
1188 |
} { // bool map test
|
alpar@209
|
1189 |
typedef typename _Digraph::template NodeMap<bool> BoolNodeMap;
|
alpar@209
|
1190 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>,
|
alpar@209
|
1191 |
BoolNodeMap >();
|
alpar@209
|
1192 |
} { // Dummy map test
|
alpar@209
|
1193 |
typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap;
|
alpar@209
|
1194 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>,
|
alpar@209
|
1195 |
DummyNodeMap >();
|
alpar@209
|
1196 |
}
|
deba@57
|
1197 |
|
alpar@209
|
1198 |
{ // int map test
|
alpar@209
|
1199 |
typedef typename _Digraph::template ArcMap<int> IntArcMap;
|
alpar@209
|
1200 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>,
|
alpar@209
|
1201 |
IntArcMap >();
|
alpar@209
|
1202 |
} { // bool map test
|
alpar@209
|
1203 |
typedef typename _Digraph::template ArcMap<bool> BoolArcMap;
|
alpar@209
|
1204 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>,
|
alpar@209
|
1205 |
BoolArcMap >();
|
alpar@209
|
1206 |
} { // Dummy map test
|
alpar@209
|
1207 |
typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap;
|
alpar@209
|
1208 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>,
|
alpar@209
|
1209 |
DummyArcMap >();
|
alpar@209
|
1210 |
}
|
alpar@209
|
1211 |
}
|
deba@57
|
1212 |
|
kpeter@579
|
1213 |
const _Digraph& digraph;
|
alpar@953
|
1214 |
Constraints() {}
|
deba@57
|
1215 |
};
|
deba@57
|
1216 |
};
|
deba@57
|
1217 |
|
kpeter@579
|
1218 |
/// \brief Skeleton class for mappable undirected graphs.
|
deba@57
|
1219 |
///
|
kpeter@579
|
1220 |
/// This class describes the interface of mappable undirected graphs.
|
kpeter@579
|
1221 |
/// It extends \ref MappableDigraphComponent with the standard graph
|
kpeter@579
|
1222 |
/// map class for edges (\c EdgeMap).
|
deba@57
|
1223 |
/// This concept is part of the Graph concept.
|
kpeter@559
|
1224 |
template <typename BAS = BaseGraphComponent>
|
kpeter@559
|
1225 |
class MappableGraphComponent : public MappableDigraphComponent<BAS> {
|
deba@57
|
1226 |
public:
|
deba@57
|
1227 |
|
kpeter@559
|
1228 |
typedef BAS Base;
|
deba@57
|
1229 |
typedef typename Base::Edge Edge;
|
deba@57
|
1230 |
|
deba@57
|
1231 |
typedef MappableGraphComponent Graph;
|
deba@57
|
1232 |
|
kpeter@579
|
1233 |
/// \brief Standard graph map for the edges.
|
deba@57
|
1234 |
///
|
kpeter@579
|
1235 |
/// Standard graph map for the edges.
|
kpeter@580
|
1236 |
/// It conforms to the ReferenceMap concept.
|
kpeter@559
|
1237 |
template <typename V>
|
kpeter@579
|
1238 |
class EdgeMap : public GraphMap<MappableGraphComponent, Edge, V> {
|
kpeter@559
|
1239 |
typedef GraphMap<MappableGraphComponent, Edge, V> Parent;
|
deba@57
|
1240 |
|
kpeter@617
|
1241 |
public:
|
alpar@209
|
1242 |
/// \brief Construct a new map.
|
alpar@209
|
1243 |
///
|
alpar@209
|
1244 |
/// Construct a new map for the graph.
|
alpar@209
|
1245 |
explicit EdgeMap(const MappableGraphComponent& graph)
|
deba@57
|
1246 |
: Parent(graph) {}
|
deba@57
|
1247 |
|
alpar@209
|
1248 |
/// \brief Construct a new map with default value.
|
alpar@209
|
1249 |
///
|
kpeter@579
|
1250 |
/// Construct a new map for the graph and initalize the values.
|
kpeter@559
|
1251 |
EdgeMap(const MappableGraphComponent& graph, const V& value)
|
deba@57
|
1252 |
: Parent(graph, value) {}
|
deba@57
|
1253 |
|
kpeter@263
|
1254 |
private:
|
alpar@209
|
1255 |
/// \brief Copy constructor.
|
alpar@209
|
1256 |
///
|
alpar@209
|
1257 |
/// Copy Constructor.
|
alpar@209
|
1258 |
EdgeMap(const EdgeMap& nm) : Parent(nm) {}
|
deba@57
|
1259 |
|
kpeter@579
|
1260 |
/// \brief Assignment operator.
|
alpar@209
|
1261 |
///
|
kpeter@579
|
1262 |
/// Assignment operator.
|
deba@57
|
1263 |
template <typename CMap>
|
alpar@209
|
1264 |
EdgeMap& operator=(const CMap&) {
|
kpeter@559
|
1265 |
checkConcept<ReadMap<Edge, V>, CMap>();
|
deba@57
|
1266 |
return *this;
|
deba@57
|
1267 |
}
|
deba@57
|
1268 |
|
deba@57
|
1269 |
};
|
deba@57
|
1270 |
|
deba@57
|
1271 |
|
deba@57
|
1272 |
template <typename _Graph>
|
deba@57
|
1273 |
struct Constraints {
|
deba@57
|
1274 |
|
alpar@209
|
1275 |
struct Dummy {
|
alpar@209
|
1276 |
int value;
|
alpar@209
|
1277 |
Dummy() : value(0) {}
|
alpar@209
|
1278 |
Dummy(int _v) : value(_v) {}
|
alpar@209
|
1279 |
};
|
deba@57
|
1280 |
|
alpar@209
|
1281 |
void constraints() {
|
kpeter@579
|
1282 |
checkConcept<MappableDigraphComponent<Base>, _Graph>();
|
deba@57
|
1283 |
|
alpar@209
|
1284 |
{ // int map test
|
alpar@209
|
1285 |
typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
|
alpar@209
|
1286 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>,
|
alpar@209
|
1287 |
IntEdgeMap >();
|
alpar@209
|
1288 |
} { // bool map test
|
alpar@209
|
1289 |
typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
|
alpar@209
|
1290 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>,
|
alpar@209
|
1291 |
BoolEdgeMap >();
|
alpar@209
|
1292 |
} { // Dummy map test
|
alpar@209
|
1293 |
typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap;
|
alpar@209
|
1294 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>,
|
alpar@209
|
1295 |
DummyEdgeMap >();
|
alpar@209
|
1296 |
}
|
alpar@209
|
1297 |
}
|
deba@57
|
1298 |
|
kpeter@579
|
1299 |
const _Graph& graph;
|
alpar@953
|
1300 |
Constraints() {}
|
deba@57
|
1301 |
};
|
deba@57
|
1302 |
};
|
deba@57
|
1303 |
|
kpeter@579
|
1304 |
/// \brief Skeleton class for extendable directed graphs.
|
deba@57
|
1305 |
///
|
kpeter@579
|
1306 |
/// This class describes the interface of extendable directed graphs.
|
kpeter@579
|
1307 |
/// It extends \ref BaseDigraphComponent with functions for adding
|
kpeter@579
|
1308 |
/// nodes and arcs to the digraph.
|
kpeter@579
|
1309 |
/// This concept requires \ref AlterableDigraphComponent.
|
kpeter@559
|
1310 |
template <typename BAS = BaseDigraphComponent>
|
kpeter@559
|
1311 |
class ExtendableDigraphComponent : public BAS {
|
deba@57
|
1312 |
public:
|
kpeter@559
|
1313 |
typedef BAS Base;
|
deba@57
|
1314 |
|
kpeter@559
|
1315 |
typedef typename Base::Node Node;
|
kpeter@559
|
1316 |
typedef typename Base::Arc Arc;
|
deba@57
|
1317 |
|
kpeter@579
|
1318 |
/// \brief Add a new node to the digraph.
|
deba@57
|
1319 |
///
|
kpeter@579
|
1320 |
/// This function adds a new node to the digraph.
|
deba@57
|
1321 |
Node addNode() {
|
alpar@209
|
1322 |
return INVALID;
|
deba@57
|
1323 |
}
|
alpar@209
|
1324 |
|
kpeter@579
|
1325 |
/// \brief Add a new arc connecting the given two nodes.
|
deba@57
|
1326 |
///
|
kpeter@579
|
1327 |
/// This function adds a new arc connecting the given two nodes
|
kpeter@579
|
1328 |
/// of the digraph.
|
deba@57
|
1329 |
Arc addArc(const Node&, const Node&) {
|
alpar@209
|
1330 |
return INVALID;
|
deba@57
|
1331 |
}
|
deba@57
|
1332 |
|
deba@57
|
1333 |
template <typename _Digraph>
|
deba@57
|
1334 |
struct Constraints {
|
alpar@209
|
1335 |
void constraints() {
|
deba@57
|
1336 |
checkConcept<Base, _Digraph>();
|
alpar@209
|
1337 |
typename _Digraph::Node node_a, node_b;
|
alpar@209
|
1338 |
node_a = digraph.addNode();
|
alpar@209
|
1339 |
node_b = digraph.addNode();
|
alpar@209
|
1340 |
typename _Digraph::Arc arc;
|
alpar@209
|
1341 |
arc = digraph.addArc(node_a, node_b);
|
alpar@209
|
1342 |
}
|
deba@57
|
1343 |
|
alpar@209
|
1344 |
_Digraph& digraph;
|
alpar@953
|
1345 |
Constraints() {}
|
deba@57
|
1346 |
};
|
deba@57
|
1347 |
};
|
deba@57
|
1348 |
|
kpeter@579
|
1349 |
/// \brief Skeleton class for extendable undirected graphs.
|
deba@57
|
1350 |
///
|
kpeter@579
|
1351 |
/// This class describes the interface of extendable undirected graphs.
|
kpeter@579
|
1352 |
/// It extends \ref BaseGraphComponent with functions for adding
|
kpeter@579
|
1353 |
/// nodes and edges to the graph.
|
kpeter@579
|
1354 |
/// This concept requires \ref AlterableGraphComponent.
|
kpeter@559
|
1355 |
template <typename BAS = BaseGraphComponent>
|
kpeter@559
|
1356 |
class ExtendableGraphComponent : public BAS {
|
deba@57
|
1357 |
public:
|
deba@57
|
1358 |
|
kpeter@559
|
1359 |
typedef BAS Base;
|
kpeter@559
|
1360 |
typedef typename Base::Node Node;
|
kpeter@559
|
1361 |
typedef typename Base::Edge Edge;
|
deba@57
|
1362 |
|
kpeter@579
|
1363 |
/// \brief Add a new node to the digraph.
|
deba@57
|
1364 |
///
|
kpeter@579
|
1365 |
/// This function adds a new node to the digraph.
|
deba@57
|
1366 |
Node addNode() {
|
alpar@209
|
1367 |
return INVALID;
|
deba@57
|
1368 |
}
|
alpar@209
|
1369 |
|
kpeter@579
|
1370 |
/// \brief Add a new edge connecting the given two nodes.
|
deba@57
|
1371 |
///
|
kpeter@579
|
1372 |
/// This function adds a new edge connecting the given two nodes
|
kpeter@579
|
1373 |
/// of the graph.
|
kpeter@579
|
1374 |
Edge addEdge(const Node&, const Node&) {
|
alpar@209
|
1375 |
return INVALID;
|
deba@57
|
1376 |
}
|
deba@57
|
1377 |
|
deba@57
|
1378 |
template <typename _Graph>
|
deba@57
|
1379 |
struct Constraints {
|
alpar@209
|
1380 |
void constraints() {
|
alpar@209
|
1381 |
checkConcept<Base, _Graph>();
|
alpar@209
|
1382 |
typename _Graph::Node node_a, node_b;
|
alpar@209
|
1383 |
node_a = graph.addNode();
|
alpar@209
|
1384 |
node_b = graph.addNode();
|
alpar@209
|
1385 |
typename _Graph::Edge edge;
|
alpar@209
|
1386 |
edge = graph.addEdge(node_a, node_b);
|
alpar@209
|
1387 |
}
|
deba@57
|
1388 |
|
alpar@209
|
1389 |
_Graph& graph;
|
alpar@953
|
1390 |
Constraints() {}
|
deba@57
|
1391 |
};
|
deba@57
|
1392 |
};
|
deba@57
|
1393 |
|
kpeter@579
|
1394 |
/// \brief Skeleton class for erasable directed graphs.
|
alpar@209
|
1395 |
///
|
kpeter@579
|
1396 |
/// This class describes the interface of erasable directed graphs.
|
kpeter@579
|
1397 |
/// It extends \ref BaseDigraphComponent with functions for removing
|
kpeter@579
|
1398 |
/// nodes and arcs from the digraph.
|
kpeter@579
|
1399 |
/// This concept requires \ref AlterableDigraphComponent.
|
kpeter@559
|
1400 |
template <typename BAS = BaseDigraphComponent>
|
kpeter@559
|
1401 |
class ErasableDigraphComponent : public BAS {
|
deba@57
|
1402 |
public:
|
deba@57
|
1403 |
|
kpeter@559
|
1404 |
typedef BAS Base;
|
deba@57
|
1405 |
typedef typename Base::Node Node;
|
deba@57
|
1406 |
typedef typename Base::Arc Arc;
|
deba@57
|
1407 |
|
deba@57
|
1408 |
/// \brief Erase a node from the digraph.
|
deba@57
|
1409 |
///
|
kpeter@579
|
1410 |
/// This function erases the given node from the digraph and all arcs
|
kpeter@579
|
1411 |
/// connected to the node.
|
alpar@209
|
1412 |
void erase(const Node&) {}
|
deba@57
|
1413 |
|
deba@57
|
1414 |
/// \brief Erase an arc from the digraph.
|
deba@57
|
1415 |
///
|
kpeter@579
|
1416 |
/// This function erases the given arc from the digraph.
|
deba@57
|
1417 |
void erase(const Arc&) {}
|
deba@57
|
1418 |
|
deba@57
|
1419 |
template <typename _Digraph>
|
deba@57
|
1420 |
struct Constraints {
|
alpar@209
|
1421 |
void constraints() {
|
deba@57
|
1422 |
checkConcept<Base, _Digraph>();
|
kpeter@579
|
1423 |
const typename _Digraph::Node node(INVALID);
|
alpar@209
|
1424 |
digraph.erase(node);
|
kpeter@579
|
1425 |
const typename _Digraph::Arc arc(INVALID);
|
alpar@209
|
1426 |
digraph.erase(arc);
|
alpar@209
|
1427 |
}
|
deba@57
|
1428 |
|
alpar@209
|
1429 |
_Digraph& digraph;
|
alpar@953
|
1430 |
Constraints() {}
|
deba@57
|
1431 |
};
|
deba@57
|
1432 |
};
|
deba@57
|
1433 |
|
kpeter@579
|
1434 |
/// \brief Skeleton class for erasable undirected graphs.
|
alpar@209
|
1435 |
///
|
kpeter@579
|
1436 |
/// This class describes the interface of erasable undirected graphs.
|
kpeter@579
|
1437 |
/// It extends \ref BaseGraphComponent with functions for removing
|
kpeter@579
|
1438 |
/// nodes and edges from the graph.
|
kpeter@579
|
1439 |
/// This concept requires \ref AlterableGraphComponent.
|
kpeter@559
|
1440 |
template <typename BAS = BaseGraphComponent>
|
kpeter@559
|
1441 |
class ErasableGraphComponent : public BAS {
|
deba@57
|
1442 |
public:
|
deba@57
|
1443 |
|
kpeter@559
|
1444 |
typedef BAS Base;
|
deba@57
|
1445 |
typedef typename Base::Node Node;
|
deba@57
|
1446 |
typedef typename Base::Edge Edge;
|
deba@57
|
1447 |
|
deba@57
|
1448 |
/// \brief Erase a node from the graph.
|
deba@57
|
1449 |
///
|
kpeter@579
|
1450 |
/// This function erases the given node from the graph and all edges
|
kpeter@579
|
1451 |
/// connected to the node.
|
alpar@209
|
1452 |
void erase(const Node&) {}
|
deba@57
|
1453 |
|
kpeter@579
|
1454 |
/// \brief Erase an edge from the digraph.
|
deba@57
|
1455 |
///
|
kpeter@579
|
1456 |
/// This function erases the given edge from the digraph.
|
deba@57
|
1457 |
void erase(const Edge&) {}
|
deba@57
|
1458 |
|
deba@57
|
1459 |
template <typename _Graph>
|
deba@57
|
1460 |
struct Constraints {
|
alpar@209
|
1461 |
void constraints() {
|
deba@57
|
1462 |
checkConcept<Base, _Graph>();
|
kpeter@579
|
1463 |
const typename _Graph::Node node(INVALID);
|
alpar@209
|
1464 |
graph.erase(node);
|
kpeter@579
|
1465 |
const typename _Graph::Edge edge(INVALID);
|
alpar@209
|
1466 |
graph.erase(edge);
|
alpar@209
|
1467 |
}
|
deba@57
|
1468 |
|
alpar@209
|
1469 |
_Graph& graph;
|
alpar@953
|
1470 |
Constraints() {}
|
deba@57
|
1471 |
};
|
deba@57
|
1472 |
};
|
deba@57
|
1473 |
|
kpeter@579
|
1474 |
/// \brief Skeleton class for clearable directed graphs.
|
deba@57
|
1475 |
///
|
kpeter@579
|
1476 |
/// This class describes the interface of clearable directed graphs.
|
kpeter@579
|
1477 |
/// It extends \ref BaseDigraphComponent with a function for clearing
|
kpeter@579
|
1478 |
/// the digraph.
|
kpeter@579
|
1479 |
/// This concept requires \ref AlterableDigraphComponent.
|
kpeter@559
|
1480 |
template <typename BAS = BaseDigraphComponent>
|
kpeter@559
|
1481 |
class ClearableDigraphComponent : public BAS {
|
deba@57
|
1482 |
public:
|
deba@57
|
1483 |
|
kpeter@559
|
1484 |
typedef BAS Base;
|
deba@57
|
1485 |
|
deba@57
|
1486 |
/// \brief Erase all nodes and arcs from the digraph.
|
deba@57
|
1487 |
///
|
kpeter@579
|
1488 |
/// This function erases all nodes and arcs from the digraph.
|
alpar@209
|
1489 |
void clear() {}
|
deba@57
|
1490 |
|
deba@57
|
1491 |
template <typename _Digraph>
|
deba@57
|
1492 |
struct Constraints {
|
alpar@209
|
1493 |
void constraints() {
|
deba@57
|
1494 |
checkConcept<Base, _Digraph>();
|
alpar@209
|
1495 |
digraph.clear();
|
alpar@209
|
1496 |
}
|
deba@57
|
1497 |
|
kpeter@579
|
1498 |
_Digraph& digraph;
|
alpar@953
|
1499 |
Constraints() {}
|
deba@57
|
1500 |
};
|
deba@57
|
1501 |
};
|
deba@57
|
1502 |
|
kpeter@579
|
1503 |
/// \brief Skeleton class for clearable undirected graphs.
|
deba@57
|
1504 |
///
|
kpeter@579
|
1505 |
/// This class describes the interface of clearable undirected graphs.
|
kpeter@579
|
1506 |
/// It extends \ref BaseGraphComponent with a function for clearing
|
kpeter@579
|
1507 |
/// the graph.
|
kpeter@579
|
1508 |
/// This concept requires \ref AlterableGraphComponent.
|
kpeter@559
|
1509 |
template <typename BAS = BaseGraphComponent>
|
kpeter@559
|
1510 |
class ClearableGraphComponent : public ClearableDigraphComponent<BAS> {
|
deba@57
|
1511 |
public:
|
deba@57
|
1512 |
|
kpeter@559
|
1513 |
typedef BAS Base;
|
deba@57
|
1514 |
|
kpeter@579
|
1515 |
/// \brief Erase all nodes and edges from the graph.
|
kpeter@579
|
1516 |
///
|
kpeter@579
|
1517 |
/// This function erases all nodes and edges from the graph.
|
kpeter@579
|
1518 |
void clear() {}
|
kpeter@579
|
1519 |
|
deba@57
|
1520 |
template <typename _Graph>
|
deba@57
|
1521 |
struct Constraints {
|
alpar@209
|
1522 |
void constraints() {
|
kpeter@579
|
1523 |
checkConcept<Base, _Graph>();
|
kpeter@579
|
1524 |
graph.clear();
|
alpar@209
|
1525 |
}
|
deba@57
|
1526 |
|
kpeter@579
|
1527 |
_Graph& graph;
|
alpar@953
|
1528 |
Constraints() {}
|
deba@57
|
1529 |
};
|
deba@57
|
1530 |
};
|
deba@57
|
1531 |
|
deba@57
|
1532 |
}
|
deba@57
|
1533 |
|
deba@57
|
1534 |
}
|
deba@57
|
1535 |
|
deba@57
|
1536 |
#endif
|