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