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