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@1022
|
409 |
class ClearableGraphComponent : 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() {
|
klao@1022
|
421 |
checkConcept<BaseGraphComponent, _Graph>();
|
deba@989
|
422 |
graph.clear();
|
deba@989
|
423 |
}
|
deba@989
|
424 |
|
klao@1022
|
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'.
|
klao@1021
|
508 |
/// \todo Is this a good name for this concept?
|
klao@1021
|
509 |
template <typename Graph,
|
klao@1021
|
510 |
typename Edge = typename Graph::Edge,
|
klao@1021
|
511 |
char _selector = '0'>
|
klao@1021
|
512 |
class GraphIncIterator : public Edge {
|
deba@989
|
513 |
public:
|
deba@989
|
514 |
/// Default constructor.
|
deba@989
|
515 |
|
deba@989
|
516 |
/// @warning The default constructor sets the iterator
|
deba@989
|
517 |
/// to an undefined value.
|
klao@1021
|
518 |
GraphIncIterator() {}
|
deba@989
|
519 |
/// Copy constructor.
|
deba@989
|
520 |
|
deba@989
|
521 |
/// Copy constructor.
|
deba@989
|
522 |
///
|
klao@1021
|
523 |
GraphIncIterator(GraphIncIterator const&) {}
|
deba@989
|
524 |
/// Sets the iterator to the first edge incoming into or outgoing from the node.
|
deba@989
|
525 |
|
deba@989
|
526 |
/// Sets the iterator to the first edge incoming into or outgoing from the node.
|
deba@989
|
527 |
///
|
klao@1021
|
528 |
explicit GraphIncIterator(const Graph&, const typename Graph::Node&) {}
|
deba@989
|
529 |
/// Invalid constructor \& conversion.
|
deba@989
|
530 |
|
deba@989
|
531 |
/// This constructor initializes the item to be invalid.
|
deba@989
|
532 |
/// \sa Invalid for more details.
|
klao@1021
|
533 |
GraphIncIterator(Invalid) {}
|
deba@989
|
534 |
/// Assign operator for nodes.
|
deba@989
|
535 |
|
deba@989
|
536 |
/// The nodes are assignable.
|
deba@989
|
537 |
///
|
klao@1021
|
538 |
GraphIncIterator& operator=(GraphIncIterator const&) { return *this; }
|
deba@989
|
539 |
/// Next edge.
|
deba@989
|
540 |
|
deba@989
|
541 |
/// Assign the iterator to the next node.
|
deba@989
|
542 |
///
|
klao@1021
|
543 |
GraphIncIterator& operator++() { return *this; }
|
klao@1021
|
544 |
|
deba@989
|
545 |
// Node operator*() const { return INVALID; }
|
klao@1021
|
546 |
|
deba@989
|
547 |
/// Equality operator
|
deba@989
|
548 |
|
deba@989
|
549 |
/// Two iterators are equal if and only if they point to the
|
deba@989
|
550 |
/// same object or both are invalid.
|
klao@1021
|
551 |
bool operator==(const GraphIncIterator&) const { return true;}
|
klao@1021
|
552 |
|
deba@989
|
553 |
/// Inequality operator
|
deba@989
|
554 |
|
deba@989
|
555 |
/// \sa operator==(Node n)
|
deba@989
|
556 |
///
|
klao@1021
|
557 |
bool operator!=(const GraphIncIterator&) const { return true;}
|
deba@989
|
558 |
|
klao@1021
|
559 |
template <typename _GraphIncIterator>
|
deba@989
|
560 |
struct Constraints {
|
klao@1021
|
561 |
typedef typename Graph::Node Node;
|
deba@989
|
562 |
void constraints() {
|
klao@1021
|
563 |
checkConcept<GraphItem<'e'>, _GraphIncIterator>();
|
klao@1021
|
564 |
_GraphIncIterator it1(graph, node);
|
deba@989
|
565 |
/// \todo Do we need OutEdgeIt(Edge) kind of constructor?
|
klao@1021
|
566 |
// _GraphIncIterator it2(edge);
|
klao@1021
|
567 |
_GraphIncIterator it2;
|
deba@989
|
568 |
|
deba@989
|
569 |
it2 = ++it1;
|
deba@989
|
570 |
++it2 = it1;
|
deba@989
|
571 |
++(++it1);
|
deba@989
|
572 |
Edge e = it1;
|
deba@989
|
573 |
e = it2;
|
deba@989
|
574 |
}
|
deba@989
|
575 |
|
deba@989
|
576 |
Edge& edge;
|
deba@989
|
577 |
Node& node;
|
klao@1021
|
578 |
Graph& graph;
|
deba@989
|
579 |
};
|
deba@989
|
580 |
};
|
klao@1021
|
581 |
|
klao@1021
|
582 |
|
deba@989
|
583 |
/// An empty iterable base graph class.
|
deba@989
|
584 |
|
deba@989
|
585 |
/// This class provides beside the core graph features
|
deba@989
|
586 |
/// iterator based iterable interface for the graph structure.
|
deba@989
|
587 |
/// This concept is part of the StaticGraphConcept.
|
deba@989
|
588 |
class IterableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
589 |
|
klao@959
|
590 |
public:
|
klao@959
|
591 |
|
klao@959
|
592 |
typedef IterableGraphComponent Graph;
|
klao@959
|
593 |
|
klao@959
|
594 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
595 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
596 |
|
deba@989
|
597 |
/// This iterator goes through each node.
|
klao@959
|
598 |
|
deba@989
|
599 |
/// This iterator goes through each node.
|
deba@989
|
600 |
///
|
deba@989
|
601 |
typedef GraphIterator<Graph, Node> NodeIt;
|
deba@989
|
602 |
/// This iterator goes through each node.
|
klao@959
|
603 |
|
deba@989
|
604 |
/// This iterator goes through each node.
|
deba@989
|
605 |
///
|
deba@989
|
606 |
typedef GraphIterator<Graph, Edge> EdgeIt;
|
deba@989
|
607 |
/// This iterator goes trough the incoming edges of a node.
|
klao@959
|
608 |
|
deba@989
|
609 |
/// This iterator goes trough the \e inccoming edges of a certain node
|
deba@989
|
610 |
/// of a graph.
|
klao@1021
|
611 |
typedef GraphIncIterator<Graph, Edge, 'i'> InEdgeIt;
|
deba@989
|
612 |
/// This iterator goes trough the outgoing edges of a node.
|
klao@959
|
613 |
|
deba@989
|
614 |
/// This iterator goes trough the \e outgoing edges of a certain node
|
deba@989
|
615 |
/// of a graph.
|
klao@1021
|
616 |
typedef GraphIncIterator<Graph, Edge, 'o'> OutEdgeIt;
|
deba@989
|
617 |
};
|
deba@989
|
618 |
|
deba@989
|
619 |
template <typename _Graph>
|
deba@989
|
620 |
struct Constraints {
|
deba@989
|
621 |
void constraints() {
|
deba@989
|
622 |
checkConcept< BaseGraphComponent, _Graph>();
|
klao@959
|
623 |
|
deba@989
|
624 |
checkConcept<GraphIterator<_Graph, typename _Graph::Edge>, typename _Graph::EdgeIt >();
|
deba@989
|
625 |
checkConcept<GraphIterator<_Graph, typename _Graph::Node>, typename _Graph::NodeIt >();
|
klao@1021
|
626 |
checkConcept<GraphIncIterator<_Graph>, typename _Graph::InEdgeIt >();
|
klao@1021
|
627 |
checkConcept<GraphIncIterator<_Graph>, typename _Graph::OutEdgeIt >();
|
deba@989
|
628 |
}
|
deba@989
|
629 |
};
|
klao@959
|
630 |
|
klao@959
|
631 |
|
deba@989
|
632 |
template <typename Graph, typename Item, typename _Value>
|
deba@989
|
633 |
class GraphMap : public ReadWriteMap<Item, _Value> {
|
deba@989
|
634 |
protected:
|
deba@989
|
635 |
GraphMap() {}
|
deba@989
|
636 |
public:
|
deba@989
|
637 |
explicit GraphMap(const Graph&) {}
|
deba@989
|
638 |
GraphMap(const Graph&, const _Value&) {}
|
deba@989
|
639 |
GraphMap(const GraphMap&) {}
|
deba@989
|
640 |
|
deba@989
|
641 |
GraphMap& operator=(const GraphMap&) { return *this;}
|
klao@959
|
642 |
|
deba@989
|
643 |
template<typename _Map>
|
deba@989
|
644 |
struct Constraints {
|
deba@989
|
645 |
void constraints() {
|
deba@989
|
646 |
checkConcept<ReadWriteMap<Item, _Value>, _Map >();
|
deba@989
|
647 |
// Construction with a graph parameter
|
deba@989
|
648 |
_Map a(g);
|
deba@989
|
649 |
// Constructor with a graph and a default value parameter
|
deba@989
|
650 |
_Map a2(g,t);
|
deba@989
|
651 |
// Copy constructor. Do we need it?
|
deba@989
|
652 |
_Map b=c;
|
deba@989
|
653 |
// Copy operator. Do we need it?
|
deba@989
|
654 |
a=b;
|
klao@959
|
655 |
|
deba@989
|
656 |
ignore_unused_variable_warning(a2);
|
deba@989
|
657 |
}
|
klao@959
|
658 |
|
deba@989
|
659 |
const _Map &c;
|
deba@989
|
660 |
const Graph &g;
|
deba@989
|
661 |
const typename GraphMap::Value &t;
|
klao@959
|
662 |
};
|
klao@959
|
663 |
|
klao@959
|
664 |
};
|
klao@961
|
665 |
|
deba@989
|
666 |
/// An empty mappable base graph class.
|
klao@959
|
667 |
|
deba@989
|
668 |
/// This class provides beside the core graph features
|
deba@989
|
669 |
/// map interface for the graph structure.
|
deba@989
|
670 |
/// This concept is part of the StaticGraphConcept.
|
klao@959
|
671 |
class MappableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
672 |
public:
|
klao@959
|
673 |
|
klao@959
|
674 |
typedef MappableGraphComponent Graph;
|
klao@959
|
675 |
|
klao@959
|
676 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
677 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
678 |
|
deba@989
|
679 |
/// ReadWrite map of the nodes.
|
deba@989
|
680 |
|
deba@989
|
681 |
/// ReadWrite map of the nodes.
|
deba@989
|
682 |
///
|
alpar@987
|
683 |
template <typename _Value>
|
deba@989
|
684 |
class NodeMap : public GraphMap<Graph, Node, _Value> {
|
deba@989
|
685 |
private:
|
deba@989
|
686 |
NodeMap();
|
klao@959
|
687 |
public:
|
deba@989
|
688 |
// \todo call the right parent class constructor
|
deba@989
|
689 |
explicit NodeMap(const Graph&) {}
|
alpar@987
|
690 |
NodeMap(const Graph&, const _Value&) {}
|
klao@959
|
691 |
NodeMap(const NodeMap&) {}
|
klao@959
|
692 |
|
klao@959
|
693 |
NodeMap& operator=(const NodeMap&) { return *this;}
|
deba@989
|
694 |
|
klao@959
|
695 |
};
|
klao@959
|
696 |
|
deba@989
|
697 |
/// ReadWrite map of the edges.
|
deba@989
|
698 |
|
deba@989
|
699 |
/// ReadWrite map of the edges.
|
deba@989
|
700 |
///
|
alpar@987
|
701 |
template <typename _Value>
|
deba@989
|
702 |
class EdgeMap : public GraphMap<Graph, Edge, _Value> {
|
deba@989
|
703 |
private:
|
deba@989
|
704 |
EdgeMap();
|
klao@959
|
705 |
public:
|
deba@989
|
706 |
// \todo call the right parent class constructor
|
deba@989
|
707 |
explicit EdgeMap(const Graph&) {}
|
alpar@987
|
708 |
EdgeMap(const Graph&, const _Value&) {}
|
klao@959
|
709 |
EdgeMap(const EdgeMap&) {}
|
klao@959
|
710 |
|
klao@959
|
711 |
EdgeMap& operator=(const EdgeMap&) { return *this;}
|
deba@989
|
712 |
|
klao@959
|
713 |
};
|
klao@959
|
714 |
|
deba@989
|
715 |
template <typename _Graph>
|
deba@989
|
716 |
struct Constraints {
|
klao@959
|
717 |
|
deba@989
|
718 |
struct Type {
|
deba@989
|
719 |
int value;
|
deba@989
|
720 |
Type() : value(0) {}
|
deba@989
|
721 |
Type(int _v) : value(_v) {}
|
deba@989
|
722 |
};
|
klao@959
|
723 |
|
deba@989
|
724 |
void constraints() {
|
deba@989
|
725 |
checkConcept<BaseGraphComponent, _Graph>();
|
deba@989
|
726 |
{ // int map test
|
deba@989
|
727 |
typedef typename _Graph::template NodeMap<int> IntNodeMap;
|
deba@989
|
728 |
checkConcept<GraphMap<_Graph, typename _Graph::Node, int>, IntNodeMap >();
|
deba@989
|
729 |
} { // bool map test
|
deba@989
|
730 |
typedef typename _Graph::template NodeMap<bool> BoolNodeMap;
|
deba@989
|
731 |
checkConcept<GraphMap<_Graph, typename _Graph::Node, bool>, BoolNodeMap >();
|
deba@989
|
732 |
} { // Type map test
|
deba@989
|
733 |
typedef typename _Graph::template NodeMap<Type> TypeNodeMap;
|
deba@989
|
734 |
checkConcept<GraphMap<_Graph, typename _Graph::Node, Type>, TypeNodeMap >();
|
deba@989
|
735 |
}
|
deba@989
|
736 |
|
deba@989
|
737 |
{ // int map test
|
deba@989
|
738 |
typedef typename _Graph::template EdgeMap<int> IntEdgeMap;
|
deba@989
|
739 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>, IntEdgeMap >();
|
deba@989
|
740 |
} { // bool map test
|
deba@989
|
741 |
typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap;
|
deba@989
|
742 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>, BoolEdgeMap >();
|
deba@989
|
743 |
} { // Type map test
|
deba@989
|
744 |
typedef typename _Graph::template EdgeMap<Type> TypeEdgeMap;
|
deba@989
|
745 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, Type>, TypeEdgeMap >();
|
deba@989
|
746 |
}
|
deba@989
|
747 |
}
|
deba@989
|
748 |
|
deba@989
|
749 |
_Graph& graph;
|
klao@959
|
750 |
};
|
klao@959
|
751 |
};
|
klao@959
|
752 |
|
klao@959
|
753 |
|
klao@959
|
754 |
class ExtendableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
755 |
public:
|
klao@959
|
756 |
|
klao@959
|
757 |
typedef ExtendableGraphComponent Graph;
|
klao@959
|
758 |
|
klao@959
|
759 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
760 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
761 |
|
klao@959
|
762 |
Node addNode() {
|
klao@959
|
763 |
return INVALID;
|
klao@959
|
764 |
}
|
klao@959
|
765 |
|
klao@959
|
766 |
Edge addEdge(const Node& from, const Node& to) {
|
klao@959
|
767 |
return INVALID;
|
klao@959
|
768 |
}
|
klao@959
|
769 |
|
deba@989
|
770 |
template <typename _Graph>
|
deba@989
|
771 |
struct Constraints {
|
deba@989
|
772 |
void constraints() {
|
deba@989
|
773 |
checkConcept<BaseGraphComponent, _Graph >();
|
deba@989
|
774 |
typename _Graph::Node node_a, node_b;
|
deba@989
|
775 |
node_a = graph.addNode();
|
deba@989
|
776 |
typename _Graph::Edge edge;
|
deba@989
|
777 |
edge = graph.addEdge(node_a, node_b);
|
deba@989
|
778 |
}
|
deba@989
|
779 |
_Graph& graph;
|
deba@989
|
780 |
};
|
klao@959
|
781 |
};
|
klao@959
|
782 |
class ErasableGraphComponent : virtual public BaseGraphComponent {
|
klao@959
|
783 |
public:
|
klao@959
|
784 |
|
klao@959
|
785 |
typedef ErasableGraphComponent Graph;
|
klao@959
|
786 |
|
klao@959
|
787 |
typedef BaseGraphComponent::Node Node;
|
klao@959
|
788 |
typedef BaseGraphComponent::Edge Edge;
|
klao@959
|
789 |
|
klao@959
|
790 |
void erase(const Node&) {}
|
klao@959
|
791 |
void erase(const Edge&) {}
|
klao@959
|
792 |
|
deba@989
|
793 |
template <typename _Graph>
|
deba@989
|
794 |
struct Constraints {
|
deba@989
|
795 |
void constraints() {
|
deba@989
|
796 |
checkConcept<BaseGraphComponent, _Graph >();
|
deba@989
|
797 |
typename _Graph::Node node;
|
deba@989
|
798 |
graph.erase(node);
|
deba@989
|
799 |
typename _Graph::Edge edge;
|
deba@989
|
800 |
graph.erase(edge);
|
deba@989
|
801 |
}
|
klao@959
|
802 |
|
deba@989
|
803 |
_Graph& graph;
|
deba@989
|
804 |
};
|
klao@959
|
805 |
};
|
klao@959
|
806 |
|
klao@959
|
807 |
}
|
klao@959
|
808 |
|
klao@959
|
809 |
}
|
klao@959
|
810 |
|
klao@959
|
811 |
#endif
|