klao@959
|
1 |
/* -*- C++ -*-
|
klao@959
|
2 |
* src/lemon/concept/graph_component.h - Part of LEMON, a generic C++ optimization library
|
klao@959
|
3 |
*
|
klao@959
|
4 |
* Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
klao@959
|
5 |
* (Egervary Combinatorial Optimization Research Group, EGRES).
|
klao@959
|
6 |
*
|
klao@959
|
7 |
* Permission to use, modify and distribute this software is granted
|
klao@959
|
8 |
* provided that this copyright notice appears in all copies. For
|
klao@959
|
9 |
* precise terms see the accompanying LICENSE file.
|
klao@959
|
10 |
*
|
klao@959
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
klao@959
|
12 |
* express or implied, and with no claim as to its suitability for any
|
klao@959
|
13 |
* purpose.
|
klao@959
|
14 |
*
|
klao@959
|
15 |
*/
|
klao@959
|
16 |
|
klao@959
|
17 |
///\ingroup concept
|
klao@959
|
18 |
///\file
|
klao@959
|
19 |
///\brief The graph components.
|
klao@959
|
20 |
|
klao@959
|
21 |
|
klao@959
|
22 |
#ifndef LEMON_CONCEPT_GRAPH_COMPONENT_H
|
klao@959
|
23 |
#define LEMON_CONCEPT_GRAPH_COMPONENT_H
|
klao@959
|
24 |
|
klao@959
|
25 |
#include <lemon/invalid.h>
|
klao@959
|
26 |
#include <lemon/concept/maps.h>
|
klao@959
|
27 |
|
klao@959
|
28 |
namespace lemon {
|
klao@959
|
29 |
namespace concept {
|
klao@959
|
30 |
|
klao@961
|
31 |
|
klao@961
|
32 |
/**************** Graph iterator concepts ****************/
|
klao@961
|
33 |
|
klao@961
|
34 |
/// Skeleton class for graph Node and Edge
|
klao@961
|
35 |
|
klao@961
|
36 |
/// \note Because Node and Edge are forbidden to inherit from the same
|
alpar@964
|
37 |
/// base class, this is a template. For Node you should instantiate it
|
klao@961
|
38 |
/// with character 'n' and for Edge with 'e'.
|
klao@961
|
39 |
|
deba@989
|
40 |
template<char _selector>
|
klao@961
|
41 |
class GraphItem {
|
klao@961
|
42 |
public:
|
deba@989
|
43 |
/// Default constructor.
|
deba@989
|
44 |
|
deba@989
|
45 |
/// @warning The default constructor sets the item
|
deba@989
|
46 |
/// to an undefined value.
|
klao@961
|
47 |
GraphItem() {}
|
deba@989
|
48 |
/// Copy constructor.
|
deba@989
|
49 |
|
deba@989
|
50 |
/// Copy constructor.
|
deba@989
|
51 |
///
|
deba@989
|
52 |
GraphItem(GraphItem const&) {}
|
deba@989
|
53 |
/// Invalid constructor \& conversion.
|
deba@989
|
54 |
|
deba@989
|
55 |
/// This constructor initializes the item to be invalid.
|
deba@989
|
56 |
/// \sa Invalid for more details.
|
klao@961
|
57 |
GraphItem(Invalid) {}
|
deba@989
|
58 |
/// Assign operator for nodes.
|
klao@961
|
59 |
|
deba@989
|
60 |
/// The nodes are assignable.
|
deba@989
|
61 |
///
|
klao@961
|
62 |
GraphItem& operator=(GraphItem const&) { return *this; }
|
deba@989
|
63 |
/// Equality operator.
|
deba@989
|
64 |
|
deba@989
|
65 |
/// Two iterators are equal if and only if they represents the
|
deba@989
|
66 |
/// same node in the graph or both are invalid.
|
klao@961
|
67 |
bool operator==(GraphItem) const { return false; }
|
deba@989
|
68 |
/// Inequality operator.
|
deba@989
|
69 |
|
deba@989
|
70 |
/// \sa operator==(const Node& n)
|
deba@989
|
71 |
///
|
klao@961
|
72 |
bool operator!=(GraphItem) const { return false; }
|
klao@961
|
73 |
|
klao@961
|
74 |
// Technical requirement. Do we really need this?
|
deba@989
|
75 |
// bool operator<(GraphItem) const { return false; }
|
deba@989
|
76 |
|
deba@989
|
77 |
|
deba@989
|
78 |
template<typename _GraphItem>
|
deba@989
|
79 |
struct Constraints {
|
deba@989
|
80 |
void constraints() {
|
deba@989
|
81 |
_GraphItem i1;
|
deba@989
|
82 |
_GraphItem i2 = i1;
|
deba@989
|
83 |
_GraphItem i3 = INVALID;
|
deba@989
|
84 |
|
deba@989
|
85 |
i1 = i2 = i3;
|
deba@989
|
86 |
|
deba@989
|
87 |
bool b;
|
deba@989
|
88 |
// b = (ia == ib) && (ia != ib) && (ia < ib);
|
deba@989
|
89 |
b = (ia == ib) && (ia != ib);
|
deba@989
|
90 |
b = (ia == INVALID) && (ib != INVALID);
|
deba@989
|
91 |
}
|
deba@989
|
92 |
|
deba@989
|
93 |
const _GraphItem &ia;
|
deba@989
|
94 |
const _GraphItem &ib;
|
deba@989
|
95 |
};
|
klao@961
|
96 |
};
|
klao@961
|
97 |
|
klao@959
|
98 |
/// An empty base graph class.
|
klao@959
|
99 |
|
klao@961
|
100 |
/// This class provides the minimal set of features needed for a graph
|
klao@961
|
101 |
/// structure. All graph concepts have to be conform to this base
|
klao@961
|
102 |
/// graph.
|
klao@961
|
103 |
///
|
klao@961
|
104 |
/// \bug This is not true. The minimal graph concept is the
|
klao@961
|
105 |
/// BaseIterableGraphComponent.
|
klao@959
|
106 |
|
klao@959
|
107 |
class BaseGraphComponent {
|
klao@959
|
108 |
public:
|
klao@959
|
109 |
|
klao@959
|
110 |
typedef BaseGraphComponent Graph;
|
klao@959
|
111 |
|
klao@959
|
112 |
/// Node class of the graph.
|
klao@959
|
113 |
|
klao@959
|
114 |
/// This class represents the Nodes of the graph.
|
klao@959
|
115 |
///
|
deba@989
|
116 |
typedef GraphItem<'n'> Node;
|
klao@959
|
117 |
|
klao@959
|
118 |
/// Edge class of the graph.
|
klao@959
|
119 |
|
klao@959
|
120 |
/// This class represents the Edges of the graph.
|
klao@959
|
121 |
///
|
deba@989
|
122 |
typedef GraphItem<'e'> Edge;
|
klao@959
|
123 |
|
alpar@986
|
124 |
///Gives back the target node of an edge.
|
klao@959
|
125 |
|
alpar@986
|
126 |
///Gives back the target node of an edge.
|
klao@959
|
127 |
///
|
alpar@986
|
128 |
Node target(const Edge&) const { return INVALID;}
|
klao@959
|
129 |
|
alpar@986
|
130 |
///Gives back the source node of an edge.
|
klao@959
|
131 |
|
alpar@986
|
132 |
///Gives back the source node of an edge.
|
klao@959
|
133 |
///
|
alpar@986
|
134 |
Node source(const Edge&) const { return INVALID;}
|
klao@959
|
135 |
|
klao@961
|
136 |
|
deba@989
|
137 |
template <typename _Graph>
|
deba@989
|
138 |
struct Constraints {
|
deba@989
|
139 |
typedef typename _Graph::Node Node;
|
deba@989
|
140 |
typedef typename _Graph::Edge Edge;
|
klao@959
|
141 |
|
deba@989
|
142 |
void constraints() {
|
deba@989
|
143 |
checkConcept<GraphItem<'n'>, Node>();
|
deba@989
|
144 |
checkConcept<GraphItem<'e'>, Edge>();
|
deba@989
|
145 |
{
|
deba@989
|
146 |
Node n;
|
deba@989
|
147 |
Edge e;
|
deba@989
|
148 |
n = graph.source(e);
|
deba@989
|
149 |
n = graph.target(e);
|
deba@989
|
150 |
}
|
deba@989
|
151 |
}
|
klao@959
|
152 |
|
deba@989
|
153 |
const _Graph& graph;
|
deba@989
|
154 |
};
|
klao@959
|
155 |
};
|
klao@959
|
156 |
|
klao@959
|
157 |
/// An empty iterable base graph class.
|
klao@959
|
158 |
|
klao@959
|
159 |
/// This class provides beside the core graph features
|
klao@959
|
160 |
/// core iterable interface for the graph structure.
|
klao@959
|
161 |
/// Most of the base graphs should be conform to this concept.
|
klao@959
|
162 |
|
klao@959
|
163 |
class BaseIterableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
164 |
public:
|
klao@959
|
165 |
|
klao@959
|
166 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
167 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
168 |
|
klao@959
|
169 |
/// Gives back the first Node in the iterating order.
|
klao@959
|
170 |
|
klao@959
|
171 |
/// Gives back the first Node in the iterating order.
|
klao@959
|
172 |
///
|
klao@959
|
173 |
void first(Node&) const {}
|
klao@959
|
174 |
|
klao@959
|
175 |
/// Gives back the next Node in the iterating order.
|
klao@959
|
176 |
|
klao@959
|
177 |
/// Gives back the next Node in the iterating order.
|
klao@959
|
178 |
///
|
klao@959
|
179 |
void next(Node&) const {}
|
klao@959
|
180 |
|
klao@959
|
181 |
/// Gives back the first Edge in the iterating order.
|
klao@959
|
182 |
|
klao@959
|
183 |
/// Gives back the first Edge in the iterating order.
|
klao@959
|
184 |
///
|
klao@959
|
185 |
void first(Edge&) const {}
|
klao@959
|
186 |
/// Gives back the next Edge in the iterating order.
|
klao@959
|
187 |
|
klao@959
|
188 |
/// Gives back the next Edge in the iterating order.
|
klao@959
|
189 |
///
|
klao@959
|
190 |
void next(Edge&) const {}
|
klao@959
|
191 |
|
klao@959
|
192 |
|
klao@959
|
193 |
/// Gives back the first of the Edges point to the given Node.
|
klao@959
|
194 |
|
klao@959
|
195 |
/// Gives back the first of the Edges point to the given Node.
|
klao@959
|
196 |
///
|
klao@959
|
197 |
void firstIn(Edge&, const Node&) const {}
|
klao@959
|
198 |
|
klao@959
|
199 |
/// Gives back the next of the Edges points to the given Node.
|
klao@959
|
200 |
|
klao@959
|
201 |
|
klao@959
|
202 |
/// Gives back the next of the Edges points to the given Node.
|
klao@959
|
203 |
///
|
klao@959
|
204 |
void nextIn(Edge&) const {}
|
klao@959
|
205 |
|
klao@959
|
206 |
/// Gives back the first of the Edges start from the given Node.
|
klao@959
|
207 |
|
klao@959
|
208 |
/// Gives back the first of the Edges start from the given Node.
|
klao@959
|
209 |
///
|
klao@959
|
210 |
void firstOut(Edge&, const Node&) const {}
|
klao@959
|
211 |
|
klao@959
|
212 |
/// Gives back the next of the Edges start from the given Node.
|
klao@959
|
213 |
|
klao@959
|
214 |
/// Gives back the next of the Edges start from the given Node.
|
klao@959
|
215 |
///
|
klao@959
|
216 |
void nextOut(Edge&) const {}
|
klao@959
|
217 |
|
klao@959
|
218 |
|
deba@989
|
219 |
template <typename _Graph>
|
deba@989
|
220 |
struct Constraints {
|
deba@989
|
221 |
|
deba@989
|
222 |
void constraints() {
|
deba@989
|
223 |
checkConcept< BaseGraphComponent, _Graph >();
|
deba@989
|
224 |
typename _Graph::Node node;
|
deba@989
|
225 |
typename _Graph::Edge edge;
|
deba@989
|
226 |
{
|
deba@989
|
227 |
graph.first(node);
|
deba@989
|
228 |
graph.next(node);
|
deba@989
|
229 |
}
|
deba@989
|
230 |
{
|
deba@989
|
231 |
graph.first(edge);
|
deba@989
|
232 |
graph.next(edge);
|
deba@989
|
233 |
}
|
deba@989
|
234 |
{
|
deba@989
|
235 |
graph.firstIn(edge, node);
|
deba@989
|
236 |
graph.nextIn(edge);
|
deba@989
|
237 |
}
|
deba@989
|
238 |
{
|
deba@989
|
239 |
graph.firstOut(edge, node);
|
deba@989
|
240 |
graph.nextOut(edge);
|
deba@989
|
241 |
}
|
deba@989
|
242 |
}
|
klao@959
|
243 |
|
deba@989
|
244 |
const _Graph& graph;
|
deba@989
|
245 |
};
|
klao@959
|
246 |
};
|
klao@959
|
247 |
|
klao@959
|
248 |
/// An empty idable base graph class.
|
klao@959
|
249 |
|
klao@959
|
250 |
/// This class provides beside the core graph features
|
klao@959
|
251 |
/// core id functions for the graph structure.
|
klao@959
|
252 |
/// The most of the base graphs should be conform to this concept.
|
klao@959
|
253 |
/// The id's are unique and immutable.
|
klao@959
|
254 |
class IDableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
255 |
public:
|
klao@959
|
256 |
|
klao@959
|
257 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
258 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
259 |
|
klao@959
|
260 |
/// Gives back an unique integer id for the Node.
|
klao@959
|
261 |
|
klao@959
|
262 |
/// Gives back an unique integer id for the Node.
|
klao@959
|
263 |
///
|
klao@959
|
264 |
int id(const Node&) const { return -1;}
|
klao@959
|
265 |
|
klao@959
|
266 |
/// Gives back an unique integer id for the Edge.
|
klao@959
|
267 |
|
klao@959
|
268 |
/// Gives back an unique integer id for the Edge.
|
klao@959
|
269 |
///
|
klao@959
|
270 |
int id(const Edge&) const { return -1;}
|
klao@959
|
271 |
|
deba@989
|
272 |
template <typename _Graph>
|
deba@989
|
273 |
struct Constraints {
|
klao@959
|
274 |
|
deba@989
|
275 |
void constraints() {
|
deba@989
|
276 |
checkConcept< BaseGraphComponent, _Graph >();
|
deba@989
|
277 |
typename _Graph::Node node;
|
deba@989
|
278 |
int nid = graph.id(node);
|
deba@989
|
279 |
nid = graph.id(node);
|
deba@989
|
280 |
typename _Graph::Edge edge;
|
deba@989
|
281 |
int eid = graph.id(edge);
|
deba@989
|
282 |
eid = graph.id(edge);
|
deba@989
|
283 |
}
|
klao@959
|
284 |
|
deba@989
|
285 |
const _Graph& graph;
|
deba@989
|
286 |
};
|
klao@959
|
287 |
};
|
klao@959
|
288 |
|
klao@959
|
289 |
|
klao@959
|
290 |
/// An empty max-idable base graph class.
|
klao@959
|
291 |
|
klao@959
|
292 |
/// This class provides beside the core graph features
|
klao@959
|
293 |
/// core max id functions for the graph structure.
|
klao@959
|
294 |
/// The most of the base graphs should be conform to this concept.
|
klao@959
|
295 |
/// The id's are unique and immutable.
|
klao@959
|
296 |
class MaxIDableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
297 |
public:
|
klao@959
|
298 |
|
klao@959
|
299 |
/// Gives back an integer greater or equal to the maximum Node id.
|
klao@959
|
300 |
|
klao@959
|
301 |
/// Gives back an integer greater or equal to the maximum Node id.
|
klao@959
|
302 |
///
|
deba@980
|
303 |
int maxId(Node = INVALID) const { return -1;}
|
klao@959
|
304 |
|
klao@959
|
305 |
/// Gives back an integer greater or equal to the maximum Edge id.
|
klao@959
|
306 |
|
klao@959
|
307 |
/// Gives back an integer greater or equal to the maximum Edge id.
|
klao@959
|
308 |
///
|
deba@980
|
309 |
int maxId(Edge = INVALID) const { return -1;}
|
klao@959
|
310 |
|
deba@989
|
311 |
template <typename _Graph>
|
deba@989
|
312 |
struct Constraints {
|
klao@959
|
313 |
|
deba@989
|
314 |
void constraints() {
|
deba@989
|
315 |
checkConcept<BaseGraphComponent, _Graph>();
|
deba@989
|
316 |
int nid = graph.maxId(typename _Graph::Node());
|
deba@989
|
317 |
ignore_unused_variable_warning(nid);
|
deba@989
|
318 |
int eid = graph.maxId(typename _Graph::Edge());
|
deba@989
|
319 |
ignore_unused_variable_warning(eid);
|
deba@989
|
320 |
}
|
deba@989
|
321 |
|
deba@989
|
322 |
const _Graph& graph;
|
deba@989
|
323 |
};
|
klao@959
|
324 |
};
|
klao@959
|
325 |
|
klao@959
|
326 |
/// An empty extendable base graph class.
|
klao@959
|
327 |
|
klao@959
|
328 |
/// This class provides beside the core graph features
|
klao@959
|
329 |
/// core graph extend interface for the graph structure.
|
klao@959
|
330 |
/// The most of the base graphs should be conform to this concept.
|
klao@959
|
331 |
class BaseExtendableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
332 |
public:
|
klao@959
|
333 |
|
klao@959
|
334 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
335 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
336 |
|
klao@959
|
337 |
/// Adds a new Node to the graph.
|
klao@959
|
338 |
|
klao@959
|
339 |
/// Adds a new Node to the graph.
|
klao@959
|
340 |
///
|
klao@959
|
341 |
Node addNode() {
|
klao@959
|
342 |
return INVALID;
|
klao@959
|
343 |
}
|
klao@959
|
344 |
|
klao@959
|
345 |
/// Adds a new Edge connects the two Nodes to the graph.
|
klao@959
|
346 |
|
klao@959
|
347 |
/// Adds a new Edge connects the two Nodes to the graph.
|
klao@959
|
348 |
///
|
klao@959
|
349 |
Edge addEdge(const Node& from, const Node& to) {
|
klao@959
|
350 |
return INVALID;
|
klao@959
|
351 |
}
|
klao@959
|
352 |
|
deba@989
|
353 |
template <typename _Graph>
|
deba@989
|
354 |
struct Constraints {
|
deba@989
|
355 |
void constraints() {
|
deba@989
|
356 |
checkConcept<BaseGraphComponent, _Graph >();
|
deba@989
|
357 |
typename _Graph::Node node_a, node_b;
|
deba@989
|
358 |
node_a = graph.addNode();
|
deba@989
|
359 |
typename _Graph::Edge edge;
|
deba@989
|
360 |
edge = graph.addEdge(node_a, node_b);
|
deba@989
|
361 |
}
|
klao@959
|
362 |
|
deba@989
|
363 |
_Graph& graph;
|
deba@989
|
364 |
};
|
klao@959
|
365 |
};
|
klao@959
|
366 |
|
klao@959
|
367 |
/// An empty erasable base graph class.
|
klao@959
|
368 |
|
klao@959
|
369 |
/// This class provides beside the core graph features
|
klao@959
|
370 |
/// core erase functions for the graph structure.
|
klao@959
|
371 |
/// The most of the base graphs should be conform to this concept.
|
klao@959
|
372 |
class BaseErasableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
373 |
public:
|
klao@959
|
374 |
|
klao@959
|
375 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
376 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
377 |
|
klao@959
|
378 |
/// Erase a Node from the graph.
|
klao@959
|
379 |
|
klao@959
|
380 |
/// Erase a Node from the graph. This function should not
|
klao@959
|
381 |
/// erase edges connecting to the Node.
|
klao@959
|
382 |
void erase(const Node&) {}
|
klao@959
|
383 |
|
klao@959
|
384 |
/// Erase an Edge from the graph.
|
klao@959
|
385 |
|
klao@959
|
386 |
/// Erase an Edge from the graph.
|
klao@959
|
387 |
///
|
klao@959
|
388 |
void erase(const Edge&) {}
|
klao@959
|
389 |
|
deba@989
|
390 |
template <typename _Graph>
|
deba@989
|
391 |
struct Constraints {
|
deba@989
|
392 |
void constraints() {
|
deba@989
|
393 |
checkConcept<BaseGraphComponent, _Graph>();
|
deba@989
|
394 |
typename _Graph::Node node;
|
deba@989
|
395 |
graph.erase(node);
|
deba@989
|
396 |
typename _Graph::Edge edge;
|
deba@989
|
397 |
graph.erase(edge);
|
deba@989
|
398 |
}
|
klao@959
|
399 |
|
deba@989
|
400 |
_Graph& graph;
|
deba@989
|
401 |
};
|
klao@959
|
402 |
};
|
klao@959
|
403 |
|
klao@959
|
404 |
/// An empty clearable base graph class.
|
klao@959
|
405 |
|
klao@959
|
406 |
/// This class provides beside the core graph features
|
klao@959
|
407 |
/// core clear functions for the graph structure.
|
klao@959
|
408 |
/// The most of the base graphs should be conform to this concept.
|
klao@959
|
409 |
class BaseClearableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
410 |
public:
|
klao@959
|
411 |
|
klao@959
|
412 |
/// Erase all the Nodes and Edges from the graph.
|
klao@959
|
413 |
|
klao@959
|
414 |
/// Erase all the Nodes and Edges from the graph.
|
klao@959
|
415 |
///
|
klao@959
|
416 |
void clear() {}
|
deba@989
|
417 |
|
deba@989
|
418 |
template <typename _Graph>
|
deba@989
|
419 |
struct Constraints {
|
deba@989
|
420 |
void constraints() {
|
deba@989
|
421 |
checkConcept< BaseGraphComponent, _Graph>();
|
deba@989
|
422 |
graph.clear();
|
deba@989
|
423 |
}
|
deba@989
|
424 |
|
deba@989
|
425 |
_Graph& graph;
|
deba@989
|
426 |
};
|
klao@959
|
427 |
};
|
klao@959
|
428 |
|
klao@959
|
429 |
|
deba@989
|
430 |
/// Skeleton class for graph NodeIt and EdgeIt
|
deba@989
|
431 |
|
deba@989
|
432 |
/// Skeleton class for graph NodeIt and EdgeIt.
|
klao@959
|
433 |
///
|
deba@989
|
434 |
template <typename _Graph, typename _Item>
|
deba@989
|
435 |
class GraphIterator : public _Item {
|
deba@989
|
436 |
public:
|
deba@989
|
437 |
/// \todo Don't we need the Item type as typedef?
|
klao@959
|
438 |
|
deba@989
|
439 |
/// Default constructor.
|
deba@989
|
440 |
|
deba@989
|
441 |
/// @warning The default constructor sets the iterator
|
deba@989
|
442 |
/// to an undefined value.
|
deba@989
|
443 |
GraphIterator() {}
|
deba@989
|
444 |
/// Copy constructor.
|
deba@989
|
445 |
|
deba@989
|
446 |
/// Copy constructor.
|
deba@989
|
447 |
///
|
deba@989
|
448 |
GraphIterator(GraphIterator const&) {}
|
deba@989
|
449 |
/// Sets the iterator to the first item.
|
deba@989
|
450 |
|
deba@989
|
451 |
/// Sets the iterator to the first item of \c the graph.
|
deba@989
|
452 |
///
|
deba@989
|
453 |
explicit GraphIterator(const _Graph&) {}
|
deba@989
|
454 |
/// Invalid constructor \& conversion.
|
deba@989
|
455 |
|
deba@989
|
456 |
/// This constructor initializes the item to be invalid.
|
deba@989
|
457 |
/// \sa Invalid for more details.
|
deba@989
|
458 |
GraphIterator(Invalid) {}
|
deba@989
|
459 |
/// Assign operator for items.
|
deba@989
|
460 |
|
deba@989
|
461 |
/// The items are assignable.
|
deba@989
|
462 |
///
|
deba@989
|
463 |
GraphIterator& operator=(GraphIterator const&) { return *this; }
|
deba@989
|
464 |
/// Next item.
|
deba@989
|
465 |
|
deba@989
|
466 |
/// Assign the iterator to the next item.
|
deba@989
|
467 |
///
|
deba@989
|
468 |
GraphIterator& operator++() { return *this; }
|
deba@989
|
469 |
// Node operator*() const { return INVALID; }
|
deba@989
|
470 |
/// Equality operator
|
deba@989
|
471 |
|
deba@989
|
472 |
/// Two iterators are equal if and only if they point to the
|
deba@989
|
473 |
/// same object or both are invalid.
|
deba@989
|
474 |
bool operator==(const GraphIterator&) const { return true;}
|
deba@989
|
475 |
/// Inequality operator
|
deba@989
|
476 |
|
deba@989
|
477 |
/// \sa operator==(Node n)
|
deba@989
|
478 |
///
|
deba@989
|
479 |
bool operator!=(const GraphIterator&) const { return true;}
|
deba@989
|
480 |
|
deba@989
|
481 |
template<typename _GraphIterator>
|
deba@989
|
482 |
struct Constraints {
|
deba@989
|
483 |
void constraints() {
|
deba@989
|
484 |
// checkConcept< Item, _GraphIterator >();
|
deba@989
|
485 |
_GraphIterator it1(g);
|
deba@989
|
486 |
|
deba@989
|
487 |
/// \todo Do we need NodeIt(Node) kind of constructor?
|
deba@989
|
488 |
// _GraphIterator it2(bj);
|
deba@989
|
489 |
_GraphIterator it2;
|
deba@989
|
490 |
|
deba@989
|
491 |
it2 = ++it1;
|
deba@989
|
492 |
++it2 = it1;
|
deba@989
|
493 |
++(++it1);
|
deba@989
|
494 |
/// \bug This should be: is_base_and_derived<BaseItem, _GraphIterator>
|
deba@989
|
495 |
_Item bi = it1;
|
deba@989
|
496 |
bi = it2;
|
deba@989
|
497 |
}
|
deba@989
|
498 |
_Graph& g;
|
deba@989
|
499 |
};
|
klao@959
|
500 |
};
|
klao@959
|
501 |
|
deba@989
|
502 |
/// Skeleton class for graph InEdgeIt and OutEdgeIt
|
klao@959
|
503 |
|
deba@989
|
504 |
/// \note Because InEdgeIt and OutEdgeIt may not inherit from the same
|
deba@989
|
505 |
/// base class, the _selector is a additional template parameter. For
|
deba@989
|
506 |
/// InEdgeIt you should instantiate it with character 'i' and for
|
deba@989
|
507 |
/// OutEdgeIt with 'o'.
|
deba@989
|
508 |
/// \todo check the name of the concept GraphIncEdgeIterator
|
deba@989
|
509 |
template <typename _Graph, char _selector>
|
deba@989
|
510 |
class GraphIncEdgeIterator : public _Graph::Edge {
|
deba@989
|
511 |
public:
|
deba@989
|
512 |
/// Default constructor.
|
deba@989
|
513 |
|
deba@989
|
514 |
/// @warning The default constructor sets the iterator
|
deba@989
|
515 |
/// to an undefined value.
|
deba@989
|
516 |
GraphIncEdgeIterator() {}
|
deba@989
|
517 |
/// Copy constructor.
|
deba@989
|
518 |
|
deba@989
|
519 |
/// Copy constructor.
|
deba@989
|
520 |
///
|
deba@989
|
521 |
GraphIncEdgeIterator(GraphIncEdgeIterator const&) {}
|
deba@989
|
522 |
/// Sets the iterator to the first edge incoming into or outgoing from the node.
|
deba@989
|
523 |
|
deba@989
|
524 |
/// Sets the iterator to the first edge incoming into or outgoing from the node.
|
deba@989
|
525 |
///
|
deba@989
|
526 |
explicit GraphIncEdgeIterator(const _Graph&, const typename _Graph::Node&) {}
|
deba@989
|
527 |
/// Invalid constructor \& conversion.
|
deba@989
|
528 |
|
deba@989
|
529 |
/// This constructor initializes the item to be invalid.
|
deba@989
|
530 |
/// \sa Invalid for more details.
|
deba@989
|
531 |
GraphIncEdgeIterator(Invalid) {}
|
deba@989
|
532 |
/// Assign operator for nodes.
|
deba@989
|
533 |
|
deba@989
|
534 |
/// The nodes are assignable.
|
deba@989
|
535 |
///
|
deba@989
|
536 |
GraphIncEdgeIterator& operator=(GraphIncEdgeIterator const&) { return *this; }
|
deba@989
|
537 |
/// Next edge.
|
deba@989
|
538 |
|
deba@989
|
539 |
/// Assign the iterator to the next node.
|
deba@989
|
540 |
///
|
deba@989
|
541 |
GraphIncEdgeIterator& operator++() { return *this; }
|
deba@989
|
542 |
// Node operator*() const { return INVALID; }
|
deba@989
|
543 |
/// Equality operator
|
deba@989
|
544 |
|
deba@989
|
545 |
/// Two iterators are equal if and only if they point to the
|
deba@989
|
546 |
/// same object or both are invalid.
|
deba@989
|
547 |
bool operator==(const GraphIncEdgeIterator&) const { return true;}
|
deba@989
|
548 |
/// Inequality operator
|
deba@989
|
549 |
|
deba@989
|
550 |
/// \sa operator==(Node n)
|
deba@989
|
551 |
///
|
deba@989
|
552 |
bool operator!=(const GraphIncEdgeIterator&) const { return true;}
|
deba@989
|
553 |
|
deba@989
|
554 |
template <typename _GraphIncEdgeIterator>
|
deba@989
|
555 |
struct Constraints {
|
deba@989
|
556 |
typedef typename _Graph::Node Node;
|
deba@989
|
557 |
typedef typename _Graph::Edge Edge;
|
deba@989
|
558 |
void constraints() {
|
deba@989
|
559 |
checkConcept<GraphItem<'e'>, _GraphIncEdgeIterator>();
|
deba@989
|
560 |
_GraphIncEdgeIterator it1(graph, node);
|
deba@989
|
561 |
/// \todo Do we need OutEdgeIt(Edge) kind of constructor?
|
deba@989
|
562 |
// _GraphIncEdgeIterator it2(edge);
|
deba@989
|
563 |
_GraphIncEdgeIterator it2;
|
deba@989
|
564 |
|
deba@989
|
565 |
it2 = ++it1;
|
deba@989
|
566 |
++it2 = it1;
|
deba@989
|
567 |
++(++it1);
|
deba@989
|
568 |
Edge e = it1;
|
deba@989
|
569 |
e = it2;
|
deba@989
|
570 |
}
|
deba@989
|
571 |
|
deba@989
|
572 |
Edge& edge;
|
deba@989
|
573 |
Node& node;
|
deba@989
|
574 |
_Graph& graph;
|
deba@989
|
575 |
};
|
deba@989
|
576 |
};
|
deba@989
|
577 |
/// An empty iterable base graph class.
|
deba@989
|
578 |
|
deba@989
|
579 |
/// This class provides beside the core graph features
|
deba@989
|
580 |
/// iterator based iterable interface for the graph structure.
|
deba@989
|
581 |
/// This concept is part of the StaticGraphConcept.
|
deba@989
|
582 |
class IterableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
583 |
|
klao@959
|
584 |
public:
|
klao@959
|
585 |
|
klao@959
|
586 |
typedef IterableGraphComponent Graph;
|
klao@959
|
587 |
|
klao@959
|
588 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
589 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
590 |
|
deba@989
|
591 |
/// This iterator goes through each node.
|
klao@959
|
592 |
|
deba@989
|
593 |
/// This iterator goes through each node.
|
deba@989
|
594 |
///
|
deba@989
|
595 |
typedef GraphIterator<Graph, Node> NodeIt;
|
deba@989
|
596 |
/// This iterator goes through each node.
|
klao@959
|
597 |
|
deba@989
|
598 |
/// This iterator goes through each node.
|
deba@989
|
599 |
///
|
deba@989
|
600 |
typedef GraphIterator<Graph, Edge> EdgeIt;
|
deba@989
|
601 |
/// This iterator goes trough the incoming edges of a node.
|
klao@959
|
602 |
|
deba@989
|
603 |
/// This iterator goes trough the \e inccoming edges of a certain node
|
deba@989
|
604 |
/// of a graph.
|
deba@989
|
605 |
typedef GraphIncEdgeIterator<Graph, 'i'> InEdgeIt;
|
deba@989
|
606 |
/// This iterator goes trough the outgoing edges of a node.
|
klao@959
|
607 |
|
deba@989
|
608 |
/// This iterator goes trough the \e outgoing edges of a certain node
|
deba@989
|
609 |
/// of a graph.
|
deba@989
|
610 |
typedef GraphIncEdgeIterator<Graph, 'o'> OutEdgeIt;
|
deba@989
|
611 |
};
|
deba@989
|
612 |
|
deba@989
|
613 |
template <typename _Graph>
|
deba@989
|
614 |
struct Constraints {
|
deba@989
|
615 |
void constraints() {
|
deba@989
|
616 |
checkConcept< BaseGraphComponent, _Graph>();
|
klao@959
|
617 |
|
deba@989
|
618 |
checkConcept<GraphIterator<_Graph, typename _Graph::Edge>, typename _Graph::EdgeIt >();
|
deba@989
|
619 |
checkConcept<GraphIterator<_Graph, typename _Graph::Node>, typename _Graph::NodeIt >();
|
deba@989
|
620 |
checkConcept<GraphIncEdgeIterator<_Graph, 'i'>, typename _Graph::InEdgeIt >();
|
deba@989
|
621 |
checkConcept<GraphIncEdgeIterator<_Graph, 'o'>, typename _Graph::OutEdgeIt >();
|
deba@989
|
622 |
}
|
deba@989
|
623 |
};
|
klao@959
|
624 |
|
klao@959
|
625 |
|
deba@989
|
626 |
template <typename Graph, typename Item, typename _Value>
|
deba@989
|
627 |
class GraphMap : public ReadWriteMap<Item, _Value> {
|
deba@989
|
628 |
protected:
|
deba@989
|
629 |
GraphMap() {}
|
deba@989
|
630 |
public:
|
deba@989
|
631 |
explicit GraphMap(const Graph&) {}
|
deba@989
|
632 |
GraphMap(const Graph&, const _Value&) {}
|
deba@989
|
633 |
GraphMap(const GraphMap&) {}
|
deba@989
|
634 |
|
deba@989
|
635 |
GraphMap& operator=(const GraphMap&) { return *this;}
|
klao@959
|
636 |
|
deba@989
|
637 |
template<typename _Map>
|
deba@989
|
638 |
struct Constraints {
|
deba@989
|
639 |
void constraints() {
|
deba@989
|
640 |
checkConcept<ReadWriteMap<Item, _Value>, _Map >();
|
deba@989
|
641 |
// Construction with a graph parameter
|
deba@989
|
642 |
_Map a(g);
|
deba@989
|
643 |
// Constructor with a graph and a default value parameter
|
deba@989
|
644 |
_Map a2(g,t);
|
deba@989
|
645 |
// Copy constructor. Do we need it?
|
deba@989
|
646 |
_Map b=c;
|
deba@989
|
647 |
// Copy operator. Do we need it?
|
deba@989
|
648 |
a=b;
|
klao@959
|
649 |
|
deba@989
|
650 |
ignore_unused_variable_warning(a2);
|
deba@989
|
651 |
}
|
klao@959
|
652 |
|
deba@989
|
653 |
const _Map &c;
|
deba@989
|
654 |
const Graph &g;
|
deba@989
|
655 |
const typename GraphMap::Value &t;
|
klao@959
|
656 |
};
|
klao@959
|
657 |
|
klao@959
|
658 |
};
|
klao@961
|
659 |
|
deba@989
|
660 |
/// An empty mappable base graph class.
|
klao@959
|
661 |
|
deba@989
|
662 |
/// This class provides beside the core graph features
|
deba@989
|
663 |
/// map interface for the graph structure.
|
deba@989
|
664 |
/// This concept is part of the StaticGraphConcept.
|
klao@959
|
665 |
class MappableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
666 |
public:
|
klao@959
|
667 |
|
klao@959
|
668 |
typedef MappableGraphComponent Graph;
|
klao@959
|
669 |
|
klao@959
|
670 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
671 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
672 |
|
deba@989
|
673 |
/// ReadWrite map of the nodes.
|
deba@989
|
674 |
|
deba@989
|
675 |
/// ReadWrite map of the nodes.
|
deba@989
|
676 |
///
|
alpar@987
|
677 |
template <typename _Value>
|
deba@989
|
678 |
class NodeMap : public GraphMap<Graph, Node, _Value> {
|
deba@989
|
679 |
private:
|
deba@989
|
680 |
NodeMap();
|
klao@959
|
681 |
public:
|
deba@989
|
682 |
// \todo call the right parent class constructor
|
deba@989
|
683 |
explicit NodeMap(const Graph&) {}
|
alpar@987
|
684 |
NodeMap(const Graph&, const _Value&) {}
|
klao@959
|
685 |
NodeMap(const NodeMap&) {}
|
klao@959
|
686 |
|
klao@959
|
687 |
NodeMap& operator=(const NodeMap&) { return *this;}
|
deba@989
|
688 |
|
klao@959
|
689 |
};
|
klao@959
|
690 |
|
deba@989
|
691 |
/// ReadWrite map of the edges.
|
deba@989
|
692 |
|
deba@989
|
693 |
/// ReadWrite map of the edges.
|
deba@989
|
694 |
///
|
alpar@987
|
695 |
template <typename _Value>
|
deba@989
|
696 |
class EdgeMap : public GraphMap<Graph, Edge, _Value> {
|
deba@989
|
697 |
private:
|
deba@989
|
698 |
EdgeMap();
|
klao@959
|
699 |
public:
|
deba@989
|
700 |
// \todo call the right parent class constructor
|
deba@989
|
701 |
explicit EdgeMap(const Graph&) {}
|
alpar@987
|
702 |
EdgeMap(const Graph&, const _Value&) {}
|
klao@959
|
703 |
EdgeMap(const EdgeMap&) {}
|
klao@959
|
704 |
|
klao@959
|
705 |
EdgeMap& operator=(const EdgeMap&) { return *this;}
|
deba@989
|
706 |
|
klao@959
|
707 |
};
|
klao@959
|
708 |
|
deba@989
|
709 |
template <typename _Graph>
|
deba@989
|
710 |
struct Constraints {
|
klao@959
|
711 |
|
deba@989
|
712 |
struct Type {
|
deba@989
|
713 |
int value;
|
deba@989
|
714 |
Type() : value(0) {}
|
deba@989
|
715 |
Type(int _v) : value(_v) {}
|
deba@989
|
716 |
};
|
klao@959
|
717 |
|
deba@989
|
718 |
void constraints() {
|
deba@989
|
719 |
checkConcept<BaseGraphComponent, _Graph>();
|
deba@989
|
720 |
{ // int map test
|
deba@989
|
721 |
typedef typename _Graph::template NodeMap<int> IntNodeMap;
|
deba@989
|
722 |
checkConcept<GraphMap<_Graph, typename _Graph::Node, int>, IntNodeMap >();
|
deba@989
|
723 |
} { // bool map test
|
deba@989
|
724 |
typedef typename _Graph::template NodeMap<bool> BoolNodeMap;
|
deba@989
|
725 |
checkConcept<GraphMap<_Graph, typename _Graph::Node, bool>, BoolNodeMap >();
|
deba@989
|
726 |
} { // Type map test
|
deba@989
|
727 |
typedef typename _Graph::template NodeMap<Type> TypeNodeMap;
|
deba@989
|
728 |
checkConcept<GraphMap<_Graph, typename _Graph::Node, Type>, TypeNodeMap >();
|
deba@989
|
729 |
}
|
deba@989
|
730 |
|
deba@989
|
731 |
{ // int map test
|
deba@989
|
732 |
typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
|
deba@989
|
733 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>, IntEdgeMap >();
|
deba@989
|
734 |
} { // bool map test
|
deba@989
|
735 |
typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
|
deba@989
|
736 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>, BoolEdgeMap >();
|
deba@989
|
737 |
} { // Type map test
|
deba@989
|
738 |
typedef typename _Graph::template EdgeMap<Type> TypeEdgeMap;
|
deba@989
|
739 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, Type>, TypeEdgeMap >();
|
deba@989
|
740 |
}
|
deba@989
|
741 |
}
|
deba@989
|
742 |
|
deba@989
|
743 |
_Graph& graph;
|
klao@959
|
744 |
};
|
klao@959
|
745 |
};
|
klao@959
|
746 |
|
klao@959
|
747 |
|
klao@959
|
748 |
class ExtendableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
749 |
public:
|
klao@959
|
750 |
|
klao@959
|
751 |
typedef ExtendableGraphComponent Graph;
|
klao@959
|
752 |
|
klao@959
|
753 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
754 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
755 |
|
klao@959
|
756 |
Node addNode() {
|
klao@959
|
757 |
return INVALID;
|
klao@959
|
758 |
}
|
klao@959
|
759 |
|
klao@959
|
760 |
Edge addEdge(const Node& from, const Node& to) {
|
klao@959
|
761 |
return INVALID;
|
klao@959
|
762 |
}
|
klao@959
|
763 |
|
deba@989
|
764 |
template <typename _Graph>
|
deba@989
|
765 |
struct Constraints {
|
deba@989
|
766 |
void constraints() {
|
deba@989
|
767 |
checkConcept<BaseGraphComponent, _Graph >();
|
deba@989
|
768 |
typename _Graph::Node node_a, node_b;
|
deba@989
|
769 |
node_a = graph.addNode();
|
deba@989
|
770 |
typename _Graph::Edge edge;
|
deba@989
|
771 |
edge = graph.addEdge(node_a, node_b);
|
deba@989
|
772 |
}
|
deba@989
|
773 |
_Graph& graph;
|
deba@989
|
774 |
};
|
klao@959
|
775 |
};
|
klao@959
|
776 |
class ErasableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
777 |
public:
|
klao@959
|
778 |
|
klao@959
|
779 |
typedef ErasableGraphComponent Graph;
|
klao@959
|
780 |
|
klao@959
|
781 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
782 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
783 |
|
klao@959
|
784 |
void erase(const Node&) {}
|
klao@959
|
785 |
void erase(const Edge&) {}
|
klao@959
|
786 |
|
deba@989
|
787 |
template <typename _Graph>
|
deba@989
|
788 |
struct Constraints {
|
deba@989
|
789 |
void constraints() {
|
deba@989
|
790 |
checkConcept<BaseGraphComponent, _Graph >();
|
deba@989
|
791 |
typename _Graph::Node node;
|
deba@989
|
792 |
graph.erase(node);
|
deba@989
|
793 |
typename _Graph::Edge edge;
|
deba@989
|
794 |
graph.erase(edge);
|
deba@989
|
795 |
}
|
klao@959
|
796 |
|
deba@989
|
797 |
_Graph& graph;
|
deba@989
|
798 |
};
|
klao@959
|
799 |
};
|
klao@959
|
800 |
|
klao@959
|
801 |
class ClearableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
802 |
public:
|
klao@959
|
803 |
|
klao@959
|
804 |
typedef ClearableGraphComponent Graph;
|
klao@959
|
805 |
|
klao@959
|
806 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
807 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
808 |
|
klao@959
|
809 |
void clear() {}
|
klao@959
|
810 |
|
klao@959
|
811 |
|
deba@989
|
812 |
template <typename _Graph>
|
deba@989
|
813 |
struct ClearableGraphComponentConcept {
|
deba@989
|
814 |
void constraints() {
|
deba@989
|
815 |
checkConcept< BaseGraphComponent, _Graph >();
|
deba@989
|
816 |
graph.clear();
|
deba@989
|
817 |
}
|
deba@989
|
818 |
_Graph& graph;
|
deba@989
|
819 |
};
|
klao@959
|
820 |
};
|
klao@959
|
821 |
|
klao@959
|
822 |
}
|
klao@959
|
823 |
|
klao@959
|
824 |
}
|
klao@959
|
825 |
|
klao@959
|
826 |
#endif
|