deba@1979
|
1 |
/* -*- C++ -*-
|
deba@1979
|
2 |
*
|
deba@1979
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
deba@1979
|
4 |
*
|
alpar@2553
|
5 |
* Copyright (C) 2003-2008
|
deba@1979
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@1979
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@1979
|
8 |
*
|
deba@1979
|
9 |
* Permission to use, modify and distribute this software is granted
|
deba@1979
|
10 |
* provided that this copyright notice appears in all copies. For
|
deba@1979
|
11 |
* precise terms see the accompanying LICENSE file.
|
deba@1979
|
12 |
*
|
deba@1979
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@1979
|
14 |
* express or implied, and with no claim as to its suitability for any
|
deba@1979
|
15 |
* purpose.
|
deba@1979
|
16 |
*
|
deba@1979
|
17 |
*/
|
deba@1979
|
18 |
|
deba@1996
|
19 |
#ifndef LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H
|
deba@1996
|
20 |
#define LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H
|
deba@1979
|
21 |
|
deba@1996
|
22 |
#include <lemon/bits/invalid.h>
|
deba@1996
|
23 |
#include <lemon/error.h>
|
deba@1979
|
24 |
|
deba@1996
|
25 |
#include <lemon/bits/default_map.h>
|
deba@1996
|
26 |
|
deba@1996
|
27 |
|
deba@1996
|
28 |
///\ingroup graphbits
|
deba@1996
|
29 |
///\file
|
deba@1996
|
30 |
///\brief Extenders for the graph adaptor types
|
deba@1979
|
31 |
namespace lemon {
|
deba@1979
|
32 |
|
deba@1996
|
33 |
/// \ingroup graphbits
|
deba@1996
|
34 |
///
|
deba@1996
|
35 |
/// \brief Extender for the GraphAdaptors
|
deba@2031
|
36 |
template <typename _Graph>
|
deba@2031
|
37 |
class GraphAdaptorExtender : public _Graph {
|
deba@1979
|
38 |
public:
|
deba@1979
|
39 |
|
deba@2031
|
40 |
typedef _Graph Parent;
|
deba@2031
|
41 |
typedef _Graph Graph;
|
deba@2031
|
42 |
typedef GraphAdaptorExtender Adaptor;
|
deba@1979
|
43 |
|
deba@1979
|
44 |
// Base extensions
|
deba@1979
|
45 |
|
deba@1979
|
46 |
typedef typename Parent::Node Node;
|
deba@1979
|
47 |
typedef typename Parent::Edge Edge;
|
deba@1979
|
48 |
|
deba@1979
|
49 |
int maxId(Node) const {
|
deba@1979
|
50 |
return Parent::maxNodeId();
|
deba@1979
|
51 |
}
|
deba@1979
|
52 |
|
deba@1979
|
53 |
int maxId(Edge) const {
|
deba@1979
|
54 |
return Parent::maxEdgeId();
|
deba@1979
|
55 |
}
|
deba@1979
|
56 |
|
deba@1979
|
57 |
Node fromId(int id, Node) const {
|
deba@1979
|
58 |
return Parent::nodeFromId(id);
|
deba@1979
|
59 |
}
|
deba@1979
|
60 |
|
deba@1979
|
61 |
Edge fromId(int id, Edge) const {
|
deba@1979
|
62 |
return Parent::edgeFromId(id);
|
deba@1979
|
63 |
}
|
deba@1979
|
64 |
|
deba@1979
|
65 |
Node oppositeNode(const Node &n, const Edge &e) const {
|
deba@1979
|
66 |
if (n == Parent::source(e))
|
deba@1979
|
67 |
return Parent::target(e);
|
deba@1979
|
68 |
else if(n==Parent::target(e))
|
deba@1979
|
69 |
return Parent::source(e);
|
deba@1979
|
70 |
else
|
deba@1979
|
71 |
return INVALID;
|
deba@1979
|
72 |
}
|
deba@1979
|
73 |
|
deba@1979
|
74 |
class NodeIt : public Node {
|
deba@2031
|
75 |
const Adaptor* graph;
|
deba@1979
|
76 |
public:
|
deba@1979
|
77 |
|
deba@1979
|
78 |
NodeIt() {}
|
deba@1979
|
79 |
|
deba@1979
|
80 |
NodeIt(Invalid i) : Node(i) { }
|
deba@1979
|
81 |
|
deba@2031
|
82 |
explicit NodeIt(const Adaptor& _graph) : graph(&_graph) {
|
deba@2031
|
83 |
_graph.first(static_cast<Node&>(*this));
|
deba@1979
|
84 |
}
|
deba@1979
|
85 |
|
deba@2031
|
86 |
NodeIt(const Adaptor& _graph, const Node& node)
|
deba@1979
|
87 |
: Node(node), graph(&_graph) {}
|
deba@1979
|
88 |
|
deba@1979
|
89 |
NodeIt& operator++() {
|
deba@1979
|
90 |
graph->next(*this);
|
deba@1979
|
91 |
return *this;
|
deba@1979
|
92 |
}
|
deba@1979
|
93 |
|
deba@1979
|
94 |
};
|
deba@1979
|
95 |
|
deba@1979
|
96 |
|
deba@1979
|
97 |
class EdgeIt : public Edge {
|
deba@2031
|
98 |
const Adaptor* graph;
|
deba@1979
|
99 |
public:
|
deba@1979
|
100 |
|
deba@1979
|
101 |
EdgeIt() { }
|
deba@1979
|
102 |
|
deba@1979
|
103 |
EdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
104 |
|
deba@2031
|
105 |
explicit EdgeIt(const Adaptor& _graph) : graph(&_graph) {
|
deba@2031
|
106 |
_graph.first(static_cast<Edge&>(*this));
|
deba@1979
|
107 |
}
|
deba@1979
|
108 |
|
deba@2031
|
109 |
EdgeIt(const Adaptor& _graph, const Edge& e) :
|
deba@1979
|
110 |
Edge(e), graph(&_graph) { }
|
deba@1979
|
111 |
|
deba@1979
|
112 |
EdgeIt& operator++() {
|
deba@1979
|
113 |
graph->next(*this);
|
deba@1979
|
114 |
return *this;
|
deba@1979
|
115 |
}
|
deba@1979
|
116 |
|
deba@1979
|
117 |
};
|
deba@1979
|
118 |
|
deba@1979
|
119 |
|
deba@1979
|
120 |
class OutEdgeIt : public Edge {
|
deba@2031
|
121 |
const Adaptor* graph;
|
deba@1979
|
122 |
public:
|
deba@1979
|
123 |
|
deba@1979
|
124 |
OutEdgeIt() { }
|
deba@1979
|
125 |
|
deba@1979
|
126 |
OutEdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
127 |
|
deba@2031
|
128 |
OutEdgeIt(const Adaptor& _graph, const Node& node)
|
deba@1979
|
129 |
: graph(&_graph) {
|
deba@1979
|
130 |
_graph.firstOut(*this, node);
|
deba@1979
|
131 |
}
|
deba@1979
|
132 |
|
deba@2031
|
133 |
OutEdgeIt(const Adaptor& _graph, const Edge& edge)
|
deba@1979
|
134 |
: Edge(edge), graph(&_graph) {}
|
deba@1979
|
135 |
|
deba@1979
|
136 |
OutEdgeIt& operator++() {
|
deba@1979
|
137 |
graph->nextOut(*this);
|
deba@1979
|
138 |
return *this;
|
deba@1979
|
139 |
}
|
deba@1979
|
140 |
|
deba@1979
|
141 |
};
|
deba@1979
|
142 |
|
deba@1979
|
143 |
|
deba@1979
|
144 |
class InEdgeIt : public Edge {
|
deba@2031
|
145 |
const Adaptor* graph;
|
deba@1979
|
146 |
public:
|
deba@1979
|
147 |
|
deba@1979
|
148 |
InEdgeIt() { }
|
deba@1979
|
149 |
|
deba@1979
|
150 |
InEdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
151 |
|
deba@2031
|
152 |
InEdgeIt(const Adaptor& _graph, const Node& node)
|
deba@1979
|
153 |
: graph(&_graph) {
|
deba@1979
|
154 |
_graph.firstIn(*this, node);
|
deba@1979
|
155 |
}
|
deba@1979
|
156 |
|
deba@2031
|
157 |
InEdgeIt(const Adaptor& _graph, const Edge& edge) :
|
deba@1979
|
158 |
Edge(edge), graph(&_graph) {}
|
deba@1979
|
159 |
|
deba@1979
|
160 |
InEdgeIt& operator++() {
|
deba@1979
|
161 |
graph->nextIn(*this);
|
deba@1979
|
162 |
return *this;
|
deba@1979
|
163 |
}
|
deba@1979
|
164 |
|
deba@1979
|
165 |
};
|
deba@1979
|
166 |
|
deba@1979
|
167 |
/// \brief Base node of the iterator
|
deba@1979
|
168 |
///
|
deba@1979
|
169 |
/// Returns the base node (ie. the source in this case) of the iterator
|
deba@1979
|
170 |
Node baseNode(const OutEdgeIt &e) const {
|
deba@1979
|
171 |
return Parent::source(e);
|
deba@1979
|
172 |
}
|
deba@1979
|
173 |
/// \brief Running node of the iterator
|
deba@1979
|
174 |
///
|
deba@1979
|
175 |
/// Returns the running node (ie. the target in this case) of the
|
deba@1979
|
176 |
/// iterator
|
deba@1979
|
177 |
Node runningNode(const OutEdgeIt &e) const {
|
deba@1979
|
178 |
return Parent::target(e);
|
deba@1979
|
179 |
}
|
deba@1979
|
180 |
|
deba@1979
|
181 |
/// \brief Base node of the iterator
|
deba@1979
|
182 |
///
|
deba@1979
|
183 |
/// Returns the base node (ie. the target in this case) of the iterator
|
deba@1979
|
184 |
Node baseNode(const InEdgeIt &e) const {
|
deba@1979
|
185 |
return Parent::target(e);
|
deba@1979
|
186 |
}
|
deba@1979
|
187 |
/// \brief Running node of the iterator
|
deba@1979
|
188 |
///
|
deba@1979
|
189 |
/// Returns the running node (ie. the source in this case) of the
|
deba@1979
|
190 |
/// iterator
|
deba@1979
|
191 |
Node runningNode(const InEdgeIt &e) const {
|
deba@1979
|
192 |
return Parent::source(e);
|
deba@1979
|
193 |
}
|
deba@1979
|
194 |
|
deba@1979
|
195 |
};
|
deba@1979
|
196 |
|
deba@1979
|
197 |
|
deba@1996
|
198 |
/// \ingroup graphbits
|
deba@1996
|
199 |
///
|
deba@1996
|
200 |
/// \brief Extender for the UGraphAdaptors
|
deba@2031
|
201 |
template <typename _UGraph>
|
deba@2031
|
202 |
class UGraphAdaptorExtender : public _UGraph {
|
deba@1979
|
203 |
public:
|
deba@1979
|
204 |
|
deba@2031
|
205 |
typedef _UGraph Parent;
|
deba@2031
|
206 |
typedef _UGraph UGraph;
|
deba@2031
|
207 |
typedef UGraphAdaptorExtender Adaptor;
|
deba@1979
|
208 |
|
deba@1979
|
209 |
typedef typename Parent::Node Node;
|
deba@1979
|
210 |
typedef typename Parent::Edge Edge;
|
deba@1979
|
211 |
typedef typename Parent::UEdge UEdge;
|
deba@1979
|
212 |
|
deba@1979
|
213 |
// UGraph extension
|
deba@1979
|
214 |
|
deba@1979
|
215 |
int maxId(Node) const {
|
deba@1979
|
216 |
return Parent::maxNodeId();
|
deba@1979
|
217 |
}
|
deba@1979
|
218 |
|
deba@1979
|
219 |
int maxId(Edge) const {
|
deba@1979
|
220 |
return Parent::maxEdgeId();
|
deba@1979
|
221 |
}
|
deba@1979
|
222 |
|
deba@1979
|
223 |
int maxId(UEdge) const {
|
deba@1979
|
224 |
return Parent::maxUEdgeId();
|
deba@1979
|
225 |
}
|
deba@1979
|
226 |
|
deba@1979
|
227 |
Node fromId(int id, Node) const {
|
deba@1979
|
228 |
return Parent::nodeFromId(id);
|
deba@1979
|
229 |
}
|
deba@1979
|
230 |
|
deba@1979
|
231 |
Edge fromId(int id, Edge) const {
|
deba@1979
|
232 |
return Parent::edgeFromId(id);
|
deba@1979
|
233 |
}
|
deba@1979
|
234 |
|
deba@1979
|
235 |
UEdge fromId(int id, UEdge) const {
|
deba@1979
|
236 |
return Parent::uEdgeFromId(id);
|
deba@1979
|
237 |
}
|
deba@1979
|
238 |
|
deba@1979
|
239 |
Node oppositeNode(const Node &n, const UEdge &e) const {
|
deba@1979
|
240 |
if( n == Parent::source(e))
|
deba@1979
|
241 |
return Parent::target(e);
|
deba@1979
|
242 |
else if( n == Parent::target(e))
|
deba@1979
|
243 |
return Parent::source(e);
|
deba@1979
|
244 |
else
|
deba@1979
|
245 |
return INVALID;
|
deba@1979
|
246 |
}
|
deba@1979
|
247 |
|
deba@1979
|
248 |
Edge oppositeEdge(const Edge &e) const {
|
deba@1979
|
249 |
return Parent::direct(e, !Parent::direction(e));
|
deba@1979
|
250 |
}
|
deba@1979
|
251 |
|
deba@1979
|
252 |
using Parent::direct;
|
deba@1979
|
253 |
Edge direct(const UEdge &ue, const Node &s) const {
|
deba@1979
|
254 |
return Parent::direct(ue, Parent::source(ue) == s);
|
deba@1979
|
255 |
}
|
deba@1979
|
256 |
|
deba@1979
|
257 |
|
deba@1979
|
258 |
class NodeIt : public Node {
|
deba@2031
|
259 |
const Adaptor* graph;
|
deba@1979
|
260 |
public:
|
deba@1979
|
261 |
|
deba@1979
|
262 |
NodeIt() {}
|
deba@1979
|
263 |
|
deba@1979
|
264 |
NodeIt(Invalid i) : Node(i) { }
|
deba@1979
|
265 |
|
deba@2031
|
266 |
explicit NodeIt(const Adaptor& _graph) : graph(&_graph) {
|
deba@2031
|
267 |
_graph.first(static_cast<Node&>(*this));
|
deba@1979
|
268 |
}
|
deba@1979
|
269 |
|
deba@2031
|
270 |
NodeIt(const Adaptor& _graph, const Node& node)
|
deba@1979
|
271 |
: Node(node), graph(&_graph) {}
|
deba@1979
|
272 |
|
deba@1979
|
273 |
NodeIt& operator++() {
|
deba@1979
|
274 |
graph->next(*this);
|
deba@1979
|
275 |
return *this;
|
deba@1979
|
276 |
}
|
deba@1979
|
277 |
|
deba@1979
|
278 |
};
|
deba@1979
|
279 |
|
deba@1979
|
280 |
|
deba@1979
|
281 |
class EdgeIt : public Edge {
|
deba@2031
|
282 |
const Adaptor* graph;
|
deba@1979
|
283 |
public:
|
deba@1979
|
284 |
|
deba@1979
|
285 |
EdgeIt() { }
|
deba@1979
|
286 |
|
deba@1979
|
287 |
EdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
288 |
|
deba@2031
|
289 |
explicit EdgeIt(const Adaptor& _graph) : graph(&_graph) {
|
deba@2031
|
290 |
_graph.first(static_cast<Edge&>(*this));
|
deba@1979
|
291 |
}
|
deba@1979
|
292 |
|
deba@2031
|
293 |
EdgeIt(const Adaptor& _graph, const Edge& e) :
|
deba@1979
|
294 |
Edge(e), graph(&_graph) { }
|
deba@1979
|
295 |
|
deba@1979
|
296 |
EdgeIt& operator++() {
|
deba@1979
|
297 |
graph->next(*this);
|
deba@1979
|
298 |
return *this;
|
deba@1979
|
299 |
}
|
deba@1979
|
300 |
|
deba@1979
|
301 |
};
|
deba@1979
|
302 |
|
deba@1979
|
303 |
|
deba@1979
|
304 |
class OutEdgeIt : public Edge {
|
deba@2031
|
305 |
const Adaptor* graph;
|
deba@1979
|
306 |
public:
|
deba@1979
|
307 |
|
deba@1979
|
308 |
OutEdgeIt() { }
|
deba@1979
|
309 |
|
deba@1979
|
310 |
OutEdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
311 |
|
deba@2031
|
312 |
OutEdgeIt(const Adaptor& _graph, const Node& node)
|
deba@1979
|
313 |
: graph(&_graph) {
|
deba@1979
|
314 |
_graph.firstOut(*this, node);
|
deba@1979
|
315 |
}
|
deba@1979
|
316 |
|
deba@2031
|
317 |
OutEdgeIt(const Adaptor& _graph, const Edge& edge)
|
deba@1979
|
318 |
: Edge(edge), graph(&_graph) {}
|
deba@1979
|
319 |
|
deba@1979
|
320 |
OutEdgeIt& operator++() {
|
deba@1979
|
321 |
graph->nextOut(*this);
|
deba@1979
|
322 |
return *this;
|
deba@1979
|
323 |
}
|
deba@1979
|
324 |
|
deba@1979
|
325 |
};
|
deba@1979
|
326 |
|
deba@1979
|
327 |
|
deba@1979
|
328 |
class InEdgeIt : public Edge {
|
deba@2031
|
329 |
const Adaptor* graph;
|
deba@1979
|
330 |
public:
|
deba@1979
|
331 |
|
deba@1979
|
332 |
InEdgeIt() { }
|
deba@1979
|
333 |
|
deba@1979
|
334 |
InEdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
335 |
|
deba@2031
|
336 |
InEdgeIt(const Adaptor& _graph, const Node& node)
|
deba@1979
|
337 |
: graph(&_graph) {
|
deba@1979
|
338 |
_graph.firstIn(*this, node);
|
deba@1979
|
339 |
}
|
deba@1979
|
340 |
|
deba@2031
|
341 |
InEdgeIt(const Adaptor& _graph, const Edge& edge) :
|
deba@1979
|
342 |
Edge(edge), graph(&_graph) {}
|
deba@1979
|
343 |
|
deba@1979
|
344 |
InEdgeIt& operator++() {
|
deba@1979
|
345 |
graph->nextIn(*this);
|
deba@1979
|
346 |
return *this;
|
deba@1979
|
347 |
}
|
deba@1979
|
348 |
|
deba@1979
|
349 |
};
|
deba@1979
|
350 |
|
deba@1979
|
351 |
class UEdgeIt : public Parent::UEdge {
|
deba@2031
|
352 |
const Adaptor* graph;
|
deba@1979
|
353 |
public:
|
deba@1979
|
354 |
|
deba@1979
|
355 |
UEdgeIt() { }
|
deba@1979
|
356 |
|
deba@1979
|
357 |
UEdgeIt(Invalid i) : UEdge(i) { }
|
deba@1979
|
358 |
|
deba@2031
|
359 |
explicit UEdgeIt(const Adaptor& _graph) : graph(&_graph) {
|
deba@2031
|
360 |
_graph.first(static_cast<UEdge&>(*this));
|
deba@1979
|
361 |
}
|
deba@1979
|
362 |
|
deba@2031
|
363 |
UEdgeIt(const Adaptor& _graph, const UEdge& e) :
|
deba@1979
|
364 |
UEdge(e), graph(&_graph) { }
|
deba@1979
|
365 |
|
deba@1979
|
366 |
UEdgeIt& operator++() {
|
deba@1979
|
367 |
graph->next(*this);
|
deba@1979
|
368 |
return *this;
|
deba@1979
|
369 |
}
|
deba@1979
|
370 |
|
deba@1979
|
371 |
};
|
deba@1979
|
372 |
|
deba@1979
|
373 |
class IncEdgeIt : public Parent::UEdge {
|
deba@1979
|
374 |
friend class UGraphAdaptorExtender;
|
deba@2031
|
375 |
const Adaptor* graph;
|
deba@1979
|
376 |
bool direction;
|
deba@1979
|
377 |
public:
|
deba@1979
|
378 |
|
deba@1979
|
379 |
IncEdgeIt() { }
|
deba@1979
|
380 |
|
deba@1979
|
381 |
IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
|
deba@1979
|
382 |
|
deba@2031
|
383 |
IncEdgeIt(const Adaptor& _graph, const Node &n) : graph(&_graph) {
|
deba@1979
|
384 |
_graph.firstInc(static_cast<UEdge&>(*this), direction, n);
|
deba@1979
|
385 |
}
|
deba@1979
|
386 |
|
deba@2031
|
387 |
IncEdgeIt(const Adaptor& _graph, const UEdge &ue, const Node &n)
|
deba@1979
|
388 |
: graph(&_graph), UEdge(ue) {
|
deba@1979
|
389 |
direction = (_graph.source(ue) == n);
|
deba@1979
|
390 |
}
|
deba@1979
|
391 |
|
deba@1979
|
392 |
IncEdgeIt& operator++() {
|
deba@1979
|
393 |
graph->nextInc(*this, direction);
|
deba@1979
|
394 |
return *this;
|
deba@1979
|
395 |
}
|
deba@1979
|
396 |
};
|
deba@1979
|
397 |
|
deba@1979
|
398 |
/// \brief Base node of the iterator
|
deba@1979
|
399 |
///
|
deba@1979
|
400 |
/// Returns the base node (ie. the source in this case) of the iterator
|
deba@1979
|
401 |
Node baseNode(const OutEdgeIt &e) const {
|
deba@2386
|
402 |
return Parent::source(static_cast<const Edge&>(e));
|
deba@1979
|
403 |
}
|
deba@1979
|
404 |
/// \brief Running node of the iterator
|
deba@1979
|
405 |
///
|
deba@1979
|
406 |
/// Returns the running node (ie. the target in this case) of the
|
deba@1979
|
407 |
/// iterator
|
deba@1979
|
408 |
Node runningNode(const OutEdgeIt &e) const {
|
deba@2386
|
409 |
return Parent::target(static_cast<const Edge&>(e));
|
deba@1979
|
410 |
}
|
deba@1979
|
411 |
|
deba@1979
|
412 |
/// \brief Base node of the iterator
|
deba@1979
|
413 |
///
|
deba@1979
|
414 |
/// Returns the base node (ie. the target in this case) of the iterator
|
deba@1979
|
415 |
Node baseNode(const InEdgeIt &e) const {
|
deba@2386
|
416 |
return Parent::target(static_cast<const Edge&>(e));
|
deba@1979
|
417 |
}
|
deba@1979
|
418 |
/// \brief Running node of the iterator
|
deba@1979
|
419 |
///
|
deba@1979
|
420 |
/// Returns the running node (ie. the source in this case) of the
|
deba@1979
|
421 |
/// iterator
|
deba@1979
|
422 |
Node runningNode(const InEdgeIt &e) const {
|
deba@2386
|
423 |
return Parent::source(static_cast<const Edge&>(e));
|
deba@1979
|
424 |
}
|
deba@1979
|
425 |
|
deba@1979
|
426 |
/// Base node of the iterator
|
deba@1979
|
427 |
///
|
deba@1979
|
428 |
/// Returns the base node of the iterator
|
deba@1979
|
429 |
Node baseNode(const IncEdgeIt &e) const {
|
deba@1979
|
430 |
return e.direction ? source(e) : target(e);
|
deba@1979
|
431 |
}
|
deba@1979
|
432 |
/// Running node of the iterator
|
deba@1979
|
433 |
///
|
deba@1979
|
434 |
/// Returns the running node of the iterator
|
deba@1979
|
435 |
Node runningNode(const IncEdgeIt &e) const {
|
deba@1979
|
436 |
return e.direction ? target(e) : source(e);
|
deba@1979
|
437 |
}
|
deba@1979
|
438 |
|
deba@1979
|
439 |
};
|
deba@1979
|
440 |
|
deba@2031
|
441 |
/// \ingroup graphbits
|
deba@2031
|
442 |
///
|
deba@2031
|
443 |
/// \brief Extender for the BpUGraphAdaptors
|
deba@2031
|
444 |
template <typename Base>
|
deba@2031
|
445 |
class BpUGraphAdaptorExtender : public Base {
|
deba@2031
|
446 |
public:
|
deba@2031
|
447 |
typedef Base Parent;
|
deba@2031
|
448 |
typedef BpUGraphAdaptorExtender Graph;
|
deba@2031
|
449 |
|
deba@2031
|
450 |
typedef typename Parent::Node Node;
|
deba@2031
|
451 |
typedef typename Parent::BNode BNode;
|
deba@2031
|
452 |
typedef typename Parent::ANode ANode;
|
deba@2031
|
453 |
typedef typename Parent::Edge Edge;
|
deba@2031
|
454 |
typedef typename Parent::UEdge UEdge;
|
deba@2031
|
455 |
|
deba@2031
|
456 |
|
deba@2031
|
457 |
int maxId(Node) const {
|
deba@2031
|
458 |
return Parent::maxNodeId();
|
deba@2031
|
459 |
}
|
deba@2031
|
460 |
int maxId(BNode) const {
|
deba@2031
|
461 |
return Parent::maxBNodeId();
|
deba@2031
|
462 |
}
|
deba@2031
|
463 |
int maxId(ANode) const {
|
deba@2031
|
464 |
return Parent::maxANodeId();
|
deba@2031
|
465 |
}
|
deba@2031
|
466 |
int maxId(Edge) const {
|
deba@2031
|
467 |
return Parent::maxEdgeId();
|
deba@2031
|
468 |
}
|
deba@2031
|
469 |
int maxId(UEdge) const {
|
deba@2031
|
470 |
return Parent::maxUEdgeId();
|
deba@2031
|
471 |
}
|
deba@2031
|
472 |
|
deba@2031
|
473 |
|
deba@2031
|
474 |
Node fromId(int id, Node) const {
|
deba@2031
|
475 |
return Parent::nodeFromId(id);
|
deba@2031
|
476 |
}
|
deba@2031
|
477 |
ANode fromId(int id, ANode) const {
|
deba@2231
|
478 |
return Parent::nodeFromANodeId(id);
|
deba@2031
|
479 |
}
|
deba@2031
|
480 |
BNode fromId(int id, BNode) const {
|
deba@2231
|
481 |
return Parent::nodeFromBNodeId(id);
|
deba@2031
|
482 |
}
|
deba@2031
|
483 |
Edge fromId(int id, Edge) const {
|
deba@2031
|
484 |
return Parent::edgeFromId(id);
|
deba@2031
|
485 |
}
|
deba@2031
|
486 |
UEdge fromId(int id, UEdge) const {
|
deba@2031
|
487 |
return Parent::uEdgeFromId(id);
|
deba@2031
|
488 |
}
|
deba@2031
|
489 |
|
deba@2031
|
490 |
class NodeIt : public Node {
|
deba@2031
|
491 |
const Graph* graph;
|
deba@2031
|
492 |
public:
|
deba@2031
|
493 |
|
deba@2031
|
494 |
NodeIt() { }
|
deba@2031
|
495 |
|
deba@2031
|
496 |
NodeIt(Invalid i) : Node(INVALID) { }
|
deba@2031
|
497 |
|
deba@2031
|
498 |
explicit NodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2031
|
499 |
graph->first(static_cast<Node&>(*this));
|
deba@2031
|
500 |
}
|
deba@2031
|
501 |
|
deba@2031
|
502 |
NodeIt(const Graph& _graph, const Node& node)
|
deba@2031
|
503 |
: Node(node), graph(&_graph) { }
|
deba@2031
|
504 |
|
deba@2031
|
505 |
NodeIt& operator++() {
|
deba@2031
|
506 |
graph->next(*this);
|
deba@2031
|
507 |
return *this;
|
deba@2031
|
508 |
}
|
deba@2031
|
509 |
|
deba@2031
|
510 |
};
|
deba@2031
|
511 |
|
deba@2031
|
512 |
class ANodeIt : public Node {
|
deba@2031
|
513 |
friend class BpUGraphAdaptorExtender;
|
deba@2031
|
514 |
const Graph* graph;
|
deba@2031
|
515 |
public:
|
deba@2031
|
516 |
|
deba@2031
|
517 |
ANodeIt() { }
|
deba@2031
|
518 |
|
deba@2031
|
519 |
ANodeIt(Invalid i) : Node(INVALID) { }
|
deba@2031
|
520 |
|
deba@2031
|
521 |
explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2031
|
522 |
graph->firstANode(static_cast<Node&>(*this));
|
deba@2031
|
523 |
}
|
deba@2031
|
524 |
|
deba@2031
|
525 |
ANodeIt(const Graph& _graph, const Node& node)
|
deba@2031
|
526 |
: Node(node), graph(&_graph) {}
|
deba@2031
|
527 |
|
deba@2031
|
528 |
ANodeIt& operator++() {
|
deba@2031
|
529 |
graph->nextANode(*this);
|
deba@2031
|
530 |
return *this;
|
deba@2031
|
531 |
}
|
deba@2031
|
532 |
};
|
deba@2031
|
533 |
|
deba@2031
|
534 |
class BNodeIt : public Node {
|
deba@2031
|
535 |
friend class BpUGraphAdaptorExtender;
|
deba@2031
|
536 |
const Graph* graph;
|
deba@2031
|
537 |
public:
|
deba@2031
|
538 |
|
deba@2031
|
539 |
BNodeIt() { }
|
deba@2031
|
540 |
|
deba@2031
|
541 |
BNodeIt(Invalid i) : Node(INVALID) { }
|
deba@2031
|
542 |
|
deba@2031
|
543 |
explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2031
|
544 |
graph->firstBNode(static_cast<Node&>(*this));
|
deba@2031
|
545 |
}
|
deba@2031
|
546 |
|
deba@2031
|
547 |
BNodeIt(const Graph& _graph, const Node& node)
|
deba@2031
|
548 |
: Node(node), graph(&_graph) {}
|
deba@2031
|
549 |
|
deba@2031
|
550 |
BNodeIt& operator++() {
|
deba@2031
|
551 |
graph->nextBNode(*this);
|
deba@2031
|
552 |
return *this;
|
deba@2031
|
553 |
}
|
deba@2031
|
554 |
};
|
deba@2031
|
555 |
|
deba@2031
|
556 |
class EdgeIt : public Edge {
|
deba@2031
|
557 |
friend class BpUGraphAdaptorExtender;
|
deba@2031
|
558 |
const Graph* graph;
|
deba@2031
|
559 |
public:
|
deba@2031
|
560 |
|
deba@2031
|
561 |
EdgeIt() { }
|
deba@2031
|
562 |
|
deba@2031
|
563 |
EdgeIt(Invalid i) : Edge(INVALID) { }
|
deba@2031
|
564 |
|
deba@2031
|
565 |
explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2031
|
566 |
graph->first(static_cast<Edge&>(*this));
|
deba@2031
|
567 |
}
|
deba@2031
|
568 |
|
deba@2031
|
569 |
EdgeIt(const Graph& _graph, const Edge& edge)
|
deba@2031
|
570 |
: Edge(edge), graph(&_graph) { }
|
deba@2031
|
571 |
|
deba@2031
|
572 |
EdgeIt& operator++() {
|
deba@2031
|
573 |
graph->next(*this);
|
deba@2031
|
574 |
return *this;
|
deba@2031
|
575 |
}
|
deba@2031
|
576 |
|
deba@2031
|
577 |
};
|
deba@2031
|
578 |
|
deba@2031
|
579 |
class UEdgeIt : public UEdge {
|
deba@2031
|
580 |
friend class BpUGraphAdaptorExtender;
|
deba@2031
|
581 |
const Graph* graph;
|
deba@2031
|
582 |
public:
|
deba@2031
|
583 |
|
deba@2031
|
584 |
UEdgeIt() { }
|
deba@2031
|
585 |
|
deba@2031
|
586 |
UEdgeIt(Invalid i) : UEdge(INVALID) { }
|
deba@2031
|
587 |
|
deba@2031
|
588 |
explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2031
|
589 |
graph->first(static_cast<UEdge&>(*this));
|
deba@2031
|
590 |
}
|
deba@2031
|
591 |
|
deba@2031
|
592 |
UEdgeIt(const Graph& _graph, const UEdge& edge)
|
deba@2031
|
593 |
: UEdge(edge), graph(&_graph) { }
|
deba@2031
|
594 |
|
deba@2031
|
595 |
UEdgeIt& operator++() {
|
deba@2031
|
596 |
graph->next(*this);
|
deba@2031
|
597 |
return *this;
|
deba@2031
|
598 |
}
|
deba@2031
|
599 |
};
|
deba@2031
|
600 |
|
deba@2031
|
601 |
class OutEdgeIt : public Edge {
|
deba@2031
|
602 |
friend class BpUGraphAdaptorExtender;
|
deba@2031
|
603 |
const Graph* graph;
|
deba@2031
|
604 |
public:
|
deba@2031
|
605 |
|
deba@2031
|
606 |
OutEdgeIt() { }
|
deba@2031
|
607 |
|
deba@2031
|
608 |
OutEdgeIt(Invalid i) : Edge(i) { }
|
deba@2031
|
609 |
|
deba@2031
|
610 |
OutEdgeIt(const Graph& _graph, const Node& node)
|
deba@2031
|
611 |
: graph(&_graph) {
|
deba@2031
|
612 |
graph->firstOut(*this, node);
|
deba@2031
|
613 |
}
|
deba@2031
|
614 |
|
deba@2031
|
615 |
OutEdgeIt(const Graph& _graph, const Edge& edge)
|
deba@2031
|
616 |
: Edge(edge), graph(&_graph) {}
|
deba@2031
|
617 |
|
deba@2031
|
618 |
OutEdgeIt& operator++() {
|
deba@2031
|
619 |
graph->nextOut(*this);
|
deba@2031
|
620 |
return *this;
|
deba@2031
|
621 |
}
|
deba@2031
|
622 |
|
deba@2031
|
623 |
};
|
deba@2031
|
624 |
|
deba@2031
|
625 |
|
deba@2031
|
626 |
class InEdgeIt : public Edge {
|
deba@2031
|
627 |
friend class BpUGraphAdaptorExtender;
|
deba@2031
|
628 |
const Graph* graph;
|
deba@2031
|
629 |
public:
|
deba@2031
|
630 |
|
deba@2031
|
631 |
InEdgeIt() { }
|
deba@2031
|
632 |
|
deba@2031
|
633 |
InEdgeIt(Invalid i) : Edge(i) { }
|
deba@2031
|
634 |
|
deba@2031
|
635 |
InEdgeIt(const Graph& _graph, const Node& node)
|
deba@2031
|
636 |
: graph(&_graph) {
|
deba@2031
|
637 |
graph->firstIn(*this, node);
|
deba@2031
|
638 |
}
|
deba@2031
|
639 |
|
deba@2031
|
640 |
InEdgeIt(const Graph& _graph, const Edge& edge) :
|
deba@2031
|
641 |
Edge(edge), graph(&_graph) {}
|
deba@2031
|
642 |
|
deba@2031
|
643 |
InEdgeIt& operator++() {
|
deba@2031
|
644 |
graph->nextIn(*this);
|
deba@2031
|
645 |
return *this;
|
deba@2031
|
646 |
}
|
deba@2031
|
647 |
|
deba@2031
|
648 |
};
|
deba@2031
|
649 |
|
deba@2031
|
650 |
/// \brief Base node of the iterator
|
deba@2031
|
651 |
///
|
deba@2031
|
652 |
/// Returns the base node (ie. the source in this case) of the iterator
|
deba@2031
|
653 |
Node baseNode(const OutEdgeIt &e) const {
|
deba@2386
|
654 |
return Parent::source(static_cast<const Edge&>(e));
|
deba@2031
|
655 |
}
|
deba@2031
|
656 |
/// \brief Running node of the iterator
|
deba@2031
|
657 |
///
|
deba@2031
|
658 |
/// Returns the running node (ie. the target in this case) of the
|
deba@2031
|
659 |
/// iterator
|
deba@2031
|
660 |
Node runningNode(const OutEdgeIt &e) const {
|
deba@2386
|
661 |
return Parent::target(static_cast<const Edge&>(e));
|
deba@2031
|
662 |
}
|
deba@2031
|
663 |
|
deba@2031
|
664 |
/// \brief Base node of the iterator
|
deba@2031
|
665 |
///
|
deba@2031
|
666 |
/// Returns the base node (ie. the target in this case) of the iterator
|
deba@2031
|
667 |
Node baseNode(const InEdgeIt &e) const {
|
deba@2386
|
668 |
return Parent::target(static_cast<const Edge&>(e));
|
deba@2031
|
669 |
}
|
deba@2031
|
670 |
/// \brief Running node of the iterator
|
deba@2031
|
671 |
///
|
deba@2031
|
672 |
/// Returns the running node (ie. the source in this case) of the
|
deba@2031
|
673 |
/// iterator
|
deba@2031
|
674 |
Node runningNode(const InEdgeIt &e) const {
|
deba@2386
|
675 |
return Parent::source(static_cast<const Edge&>(e));
|
deba@2031
|
676 |
}
|
deba@2031
|
677 |
|
deba@2031
|
678 |
class IncEdgeIt : public Parent::UEdge {
|
deba@2031
|
679 |
friend class BpUGraphAdaptorExtender;
|
deba@2031
|
680 |
const Graph* graph;
|
deba@2031
|
681 |
bool direction;
|
deba@2031
|
682 |
public:
|
deba@2031
|
683 |
|
deba@2031
|
684 |
IncEdgeIt() { }
|
deba@2031
|
685 |
|
deba@2031
|
686 |
IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
|
deba@2031
|
687 |
|
deba@2031
|
688 |
IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
|
deba@2031
|
689 |
graph->firstInc(*this, direction, n);
|
deba@2031
|
690 |
}
|
deba@2031
|
691 |
|
deba@2031
|
692 |
IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
|
deba@2031
|
693 |
: graph(&_graph), UEdge(ue) {
|
deba@2031
|
694 |
direction = (graph->source(ue) == n);
|
deba@2031
|
695 |
}
|
deba@2031
|
696 |
|
deba@2031
|
697 |
IncEdgeIt& operator++() {
|
deba@2031
|
698 |
graph->nextInc(*this, direction);
|
deba@2031
|
699 |
return *this;
|
deba@2031
|
700 |
}
|
deba@2031
|
701 |
};
|
deba@2031
|
702 |
|
deba@2031
|
703 |
|
deba@2031
|
704 |
/// Base node of the iterator
|
deba@2031
|
705 |
///
|
deba@2031
|
706 |
/// Returns the base node of the iterator
|
deba@2031
|
707 |
Node baseNode(const IncEdgeIt &e) const {
|
deba@2031
|
708 |
return e.direction ? source(e) : target(e);
|
deba@2031
|
709 |
}
|
deba@2031
|
710 |
|
deba@2031
|
711 |
/// Running node of the iterator
|
deba@2031
|
712 |
///
|
deba@2031
|
713 |
/// Returns the running node of the iterator
|
deba@2031
|
714 |
Node runningNode(const IncEdgeIt &e) const {
|
deba@2031
|
715 |
return e.direction ? target(e) : source(e);
|
deba@2031
|
716 |
}
|
deba@2031
|
717 |
|
deba@2041
|
718 |
Node oppositeNode(const Node &n, const UEdge &e) const {
|
deba@2041
|
719 |
if( n == Parent::source(e))
|
deba@2041
|
720 |
return Parent::target(e);
|
deba@2041
|
721 |
else if( n == Parent::target(e))
|
deba@2041
|
722 |
return Parent::source(e);
|
deba@2041
|
723 |
else
|
deba@2041
|
724 |
return INVALID;
|
deba@2041
|
725 |
}
|
deba@2041
|
726 |
|
deba@2041
|
727 |
Edge oppositeEdge(const Edge &e) const {
|
deba@2041
|
728 |
return Parent::direct(e, !Parent::direction(e));
|
deba@2041
|
729 |
}
|
deba@2041
|
730 |
|
deba@2041
|
731 |
using Parent::direct;
|
deba@2041
|
732 |
Edge direct(const UEdge &ue, const Node &s) const {
|
deba@2041
|
733 |
return Parent::direct(ue, Parent::source(ue) == s);
|
deba@2041
|
734 |
}
|
deba@2041
|
735 |
|
deba@2031
|
736 |
};
|
deba@2031
|
737 |
|
deba@1979
|
738 |
|
deba@1979
|
739 |
}
|
deba@1979
|
740 |
|
deba@1979
|
741 |
|
deba@1979
|
742 |
#endif
|