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