deba@1791
|
1 |
/* -*- C++ -*-
|
deba@1791
|
2 |
*
|
alpar@1956
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@1956
|
4 |
*
|
alpar@2553
|
5 |
* Copyright (C) 2003-2008
|
alpar@1956
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@1956
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@1791
|
8 |
*
|
deba@1791
|
9 |
* Permission to use, modify and distribute this software is granted
|
deba@1791
|
10 |
* provided that this copyright notice appears in all copies. For
|
deba@1791
|
11 |
* precise terms see the accompanying LICENSE file.
|
deba@1791
|
12 |
*
|
deba@1791
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@1791
|
14 |
* express or implied, and with no claim as to its suitability for any
|
deba@1791
|
15 |
* purpose.
|
deba@1791
|
16 |
*
|
deba@1791
|
17 |
*/
|
deba@1791
|
18 |
|
deba@1996
|
19 |
#ifndef LEMON_BITS_GRAPH_EXTENDER_H
|
deba@1996
|
20 |
#define LEMON_BITS_GRAPH_EXTENDER_H
|
deba@1791
|
21 |
|
deba@1993
|
22 |
#include <lemon/bits/invalid.h>
|
deba@2585
|
23 |
#include <lemon/bits/utility.h>
|
deba@2116
|
24 |
#include <lemon/error.h>
|
deba@1791
|
25 |
|
deba@1999
|
26 |
#include <lemon/bits/map_extender.h>
|
deba@1979
|
27 |
#include <lemon/bits/default_map.h>
|
deba@1979
|
28 |
|
deba@2116
|
29 |
#include <lemon/concept_check.h>
|
alpar@2260
|
30 |
#include <lemon/concepts/maps.h>
|
deba@2116
|
31 |
|
deba@1996
|
32 |
///\ingroup graphbits
|
deba@1996
|
33 |
///\file
|
deba@1996
|
34 |
///\brief Extenders for the graph types
|
deba@1791
|
35 |
namespace lemon {
|
deba@1791
|
36 |
|
deba@1996
|
37 |
/// \ingroup graphbits
|
deba@1996
|
38 |
///
|
deba@1996
|
39 |
/// \brief Extender for the Graphs
|
deba@1979
|
40 |
template <typename Base>
|
deba@1979
|
41 |
class GraphExtender : public Base {
|
deba@1791
|
42 |
public:
|
deba@1791
|
43 |
|
deba@1979
|
44 |
typedef Base Parent;
|
deba@1791
|
45 |
typedef GraphExtender Graph;
|
deba@1791
|
46 |
|
deba@1979
|
47 |
// Base extensions
|
deba@1979
|
48 |
|
deba@1791
|
49 |
typedef typename Parent::Node Node;
|
deba@1791
|
50 |
typedef typename Parent::Edge Edge;
|
deba@1791
|
51 |
|
deba@1791
|
52 |
int maxId(Node) const {
|
deba@1791
|
53 |
return Parent::maxNodeId();
|
deba@1791
|
54 |
}
|
deba@1791
|
55 |
|
deba@1791
|
56 |
int maxId(Edge) const {
|
deba@1791
|
57 |
return Parent::maxEdgeId();
|
deba@1791
|
58 |
}
|
deba@1791
|
59 |
|
deba@1791
|
60 |
Node fromId(int id, Node) const {
|
deba@1791
|
61 |
return Parent::nodeFromId(id);
|
deba@1791
|
62 |
}
|
deba@1791
|
63 |
|
deba@1791
|
64 |
Edge fromId(int id, Edge) const {
|
deba@1791
|
65 |
return Parent::edgeFromId(id);
|
deba@1791
|
66 |
}
|
deba@1791
|
67 |
|
deba@1791
|
68 |
Node oppositeNode(const Node &n, const Edge &e) const {
|
deba@1791
|
69 |
if (n == Parent::source(e))
|
deba@1791
|
70 |
return Parent::target(e);
|
deba@1791
|
71 |
else if(n==Parent::target(e))
|
deba@1791
|
72 |
return Parent::source(e);
|
deba@1791
|
73 |
else
|
deba@1791
|
74 |
return INVALID;
|
deba@1791
|
75 |
}
|
deba@1791
|
76 |
|
deba@1979
|
77 |
// Alterable extension
|
deba@1791
|
78 |
|
deba@1999
|
79 |
typedef AlterationNotifier<GraphExtender, Node> NodeNotifier;
|
deba@1999
|
80 |
typedef AlterationNotifier<GraphExtender, Edge> EdgeNotifier;
|
deba@1979
|
81 |
|
deba@1979
|
82 |
|
deba@1979
|
83 |
protected:
|
deba@1979
|
84 |
|
deba@1979
|
85 |
mutable NodeNotifier node_notifier;
|
deba@1979
|
86 |
mutable EdgeNotifier edge_notifier;
|
deba@1791
|
87 |
|
deba@1791
|
88 |
public:
|
deba@1791
|
89 |
|
deba@2384
|
90 |
NodeNotifier& notifier(Node) const {
|
deba@1979
|
91 |
return node_notifier;
|
deba@1979
|
92 |
}
|
deba@1979
|
93 |
|
deba@2384
|
94 |
EdgeNotifier& notifier(Edge) const {
|
deba@1979
|
95 |
return edge_notifier;
|
deba@1979
|
96 |
}
|
deba@1979
|
97 |
|
deba@1979
|
98 |
class NodeIt : public Node {
|
deba@1979
|
99 |
const Graph* graph;
|
deba@1979
|
100 |
public:
|
deba@1979
|
101 |
|
deba@1979
|
102 |
NodeIt() {}
|
deba@1979
|
103 |
|
deba@1979
|
104 |
NodeIt(Invalid i) : Node(i) { }
|
deba@1979
|
105 |
|
deba@1979
|
106 |
explicit NodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2031
|
107 |
_graph.first(static_cast<Node&>(*this));
|
deba@1979
|
108 |
}
|
deba@1979
|
109 |
|
deba@1979
|
110 |
NodeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
111 |
: Node(node), graph(&_graph) {}
|
deba@1979
|
112 |
|
deba@1979
|
113 |
NodeIt& operator++() {
|
deba@1979
|
114 |
graph->next(*this);
|
deba@1979
|
115 |
return *this;
|
deba@1979
|
116 |
}
|
deba@1979
|
117 |
|
deba@1979
|
118 |
};
|
deba@1979
|
119 |
|
deba@1979
|
120 |
|
deba@1979
|
121 |
class EdgeIt : public Edge {
|
deba@1979
|
122 |
const Graph* graph;
|
deba@1979
|
123 |
public:
|
deba@1979
|
124 |
|
deba@1979
|
125 |
EdgeIt() { }
|
deba@1979
|
126 |
|
deba@1979
|
127 |
EdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
128 |
|
deba@1979
|
129 |
explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2031
|
130 |
_graph.first(static_cast<Edge&>(*this));
|
deba@1979
|
131 |
}
|
deba@1979
|
132 |
|
deba@1979
|
133 |
EdgeIt(const Graph& _graph, const Edge& e) :
|
deba@1979
|
134 |
Edge(e), graph(&_graph) { }
|
deba@1979
|
135 |
|
deba@1979
|
136 |
EdgeIt& operator++() {
|
deba@1979
|
137 |
graph->next(*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 OutEdgeIt : public Edge {
|
deba@1979
|
145 |
const Graph* graph;
|
deba@1979
|
146 |
public:
|
deba@1979
|
147 |
|
deba@1979
|
148 |
OutEdgeIt() { }
|
deba@1979
|
149 |
|
deba@1979
|
150 |
OutEdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
151 |
|
deba@1979
|
152 |
OutEdgeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
153 |
: graph(&_graph) {
|
deba@1979
|
154 |
_graph.firstOut(*this, node);
|
deba@1979
|
155 |
}
|
deba@1979
|
156 |
|
deba@1979
|
157 |
OutEdgeIt(const Graph& _graph, const Edge& edge)
|
deba@1979
|
158 |
: Edge(edge), graph(&_graph) {}
|
deba@1979
|
159 |
|
deba@1979
|
160 |
OutEdgeIt& operator++() {
|
deba@1979
|
161 |
graph->nextOut(*this);
|
deba@1979
|
162 |
return *this;
|
deba@1979
|
163 |
}
|
deba@1979
|
164 |
|
deba@1979
|
165 |
};
|
deba@1979
|
166 |
|
deba@1979
|
167 |
|
deba@1979
|
168 |
class InEdgeIt : public Edge {
|
deba@1979
|
169 |
const Graph* graph;
|
deba@1979
|
170 |
public:
|
deba@1979
|
171 |
|
deba@1979
|
172 |
InEdgeIt() { }
|
deba@1979
|
173 |
|
deba@1979
|
174 |
InEdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
175 |
|
deba@1979
|
176 |
InEdgeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
177 |
: graph(&_graph) {
|
deba@1979
|
178 |
_graph.firstIn(*this, node);
|
deba@1979
|
179 |
}
|
deba@1979
|
180 |
|
deba@1979
|
181 |
InEdgeIt(const Graph& _graph, const Edge& edge) :
|
deba@1979
|
182 |
Edge(edge), graph(&_graph) {}
|
deba@1979
|
183 |
|
deba@1979
|
184 |
InEdgeIt& operator++() {
|
deba@1979
|
185 |
graph->nextIn(*this);
|
deba@1979
|
186 |
return *this;
|
deba@1979
|
187 |
}
|
deba@1979
|
188 |
|
deba@1979
|
189 |
};
|
deba@1979
|
190 |
|
deba@1979
|
191 |
/// \brief Base node of the iterator
|
deba@1979
|
192 |
///
|
athos@2102
|
193 |
/// Returns the base node (i.e. the source in this case) of the iterator
|
deba@1979
|
194 |
Node baseNode(const OutEdgeIt &e) const {
|
deba@1979
|
195 |
return Parent::source(e);
|
deba@1979
|
196 |
}
|
deba@1979
|
197 |
/// \brief Running node of the iterator
|
deba@1979
|
198 |
///
|
athos@2102
|
199 |
/// Returns the running node (i.e. the target in this case) of the
|
deba@1979
|
200 |
/// iterator
|
deba@1979
|
201 |
Node runningNode(const OutEdgeIt &e) const {
|
deba@1979
|
202 |
return Parent::target(e);
|
deba@1979
|
203 |
}
|
deba@1979
|
204 |
|
deba@1979
|
205 |
/// \brief Base node of the iterator
|
deba@1979
|
206 |
///
|
athos@2102
|
207 |
/// Returns the base node (i.e. the target in this case) of the iterator
|
deba@1979
|
208 |
Node baseNode(const InEdgeIt &e) const {
|
deba@1979
|
209 |
return Parent::target(e);
|
deba@1979
|
210 |
}
|
deba@1979
|
211 |
/// \brief Running node of the iterator
|
deba@1979
|
212 |
///
|
athos@2102
|
213 |
/// Returns the running node (i.e. the source in this case) of the
|
deba@1979
|
214 |
/// iterator
|
deba@1979
|
215 |
Node runningNode(const InEdgeIt &e) const {
|
deba@1979
|
216 |
return Parent::source(e);
|
deba@1979
|
217 |
}
|
deba@1979
|
218 |
|
deba@1979
|
219 |
|
deba@1979
|
220 |
template <typename _Value>
|
deba@1979
|
221 |
class NodeMap
|
deba@1999
|
222 |
: public MapExtender<DefaultMap<Graph, Node, _Value> > {
|
deba@1979
|
223 |
public:
|
deba@1979
|
224 |
typedef GraphExtender Graph;
|
deba@1999
|
225 |
typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
|
deba@1979
|
226 |
|
klao@2046
|
227 |
explicit NodeMap(const Graph& graph)
|
deba@1999
|
228 |
: Parent(graph) {}
|
deba@1999
|
229 |
NodeMap(const Graph& graph, const _Value& value)
|
deba@1999
|
230 |
: Parent(graph, value) {}
|
deba@1979
|
231 |
|
deba@1979
|
232 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@1979
|
233 |
return operator=<NodeMap>(cmap);
|
deba@1979
|
234 |
}
|
deba@1979
|
235 |
|
deba@1979
|
236 |
template <typename CMap>
|
deba@1979
|
237 |
NodeMap& operator=(const CMap& cmap) {
|
deba@2031
|
238 |
Parent::operator=(cmap);
|
deba@1979
|
239 |
return *this;
|
deba@1979
|
240 |
}
|
deba@1979
|
241 |
|
deba@1979
|
242 |
};
|
deba@1979
|
243 |
|
deba@1979
|
244 |
template <typename _Value>
|
deba@1979
|
245 |
class EdgeMap
|
deba@1999
|
246 |
: public MapExtender<DefaultMap<Graph, Edge, _Value> > {
|
deba@1979
|
247 |
public:
|
deba@1979
|
248 |
typedef GraphExtender Graph;
|
deba@1999
|
249 |
typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
|
deba@1979
|
250 |
|
klao@2046
|
251 |
explicit EdgeMap(const Graph& graph)
|
deba@1999
|
252 |
: Parent(graph) {}
|
deba@1999
|
253 |
EdgeMap(const Graph& graph, const _Value& value)
|
deba@1999
|
254 |
: Parent(graph, value) {}
|
deba@1979
|
255 |
|
deba@1979
|
256 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@1979
|
257 |
return operator=<EdgeMap>(cmap);
|
deba@1979
|
258 |
}
|
deba@1979
|
259 |
|
deba@1979
|
260 |
template <typename CMap>
|
deba@1979
|
261 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@2031
|
262 |
Parent::operator=(cmap);
|
deba@1979
|
263 |
return *this;
|
deba@1979
|
264 |
}
|
deba@1979
|
265 |
};
|
deba@1979
|
266 |
|
deba@1979
|
267 |
|
deba@1979
|
268 |
Node addNode() {
|
deba@1979
|
269 |
Node node = Parent::addNode();
|
deba@2384
|
270 |
notifier(Node()).add(node);
|
deba@1979
|
271 |
return node;
|
deba@1979
|
272 |
}
|
deba@1979
|
273 |
|
deba@1979
|
274 |
Edge addEdge(const Node& from, const Node& to) {
|
deba@1979
|
275 |
Edge edge = Parent::addEdge(from, to);
|
deba@2384
|
276 |
notifier(Edge()).add(edge);
|
deba@1979
|
277 |
return edge;
|
deba@1979
|
278 |
}
|
deba@1979
|
279 |
|
deba@1979
|
280 |
void clear() {
|
deba@2384
|
281 |
notifier(Edge()).clear();
|
deba@2384
|
282 |
notifier(Node()).clear();
|
deba@1979
|
283 |
Parent::clear();
|
deba@1979
|
284 |
}
|
deba@1979
|
285 |
|
deba@2290
|
286 |
template <typename Graph, typename NodeRefMap, typename EdgeRefMap>
|
deba@2329
|
287 |
void build(const Graph& graph, NodeRefMap& nodeRef, EdgeRefMap& edgeRef) {
|
deba@2329
|
288 |
Parent::build(graph, nodeRef, edgeRef);
|
deba@2384
|
289 |
notifier(Node()).build();
|
deba@2384
|
290 |
notifier(Edge()).build();
|
deba@2290
|
291 |
}
|
deba@1979
|
292 |
|
deba@1979
|
293 |
void erase(const Node& node) {
|
deba@1979
|
294 |
Edge edge;
|
deba@1979
|
295 |
Parent::firstOut(edge, node);
|
deba@1979
|
296 |
while (edge != INVALID ) {
|
deba@1979
|
297 |
erase(edge);
|
deba@1979
|
298 |
Parent::firstOut(edge, node);
|
deba@1979
|
299 |
}
|
deba@1979
|
300 |
|
deba@1979
|
301 |
Parent::firstIn(edge, node);
|
deba@1979
|
302 |
while (edge != INVALID ) {
|
deba@1979
|
303 |
erase(edge);
|
deba@1979
|
304 |
Parent::firstIn(edge, node);
|
deba@1979
|
305 |
}
|
deba@1979
|
306 |
|
deba@2384
|
307 |
notifier(Node()).erase(node);
|
deba@1979
|
308 |
Parent::erase(node);
|
deba@1979
|
309 |
}
|
deba@1979
|
310 |
|
deba@1979
|
311 |
void erase(const Edge& edge) {
|
deba@2384
|
312 |
notifier(Edge()).erase(edge);
|
deba@1979
|
313 |
Parent::erase(edge);
|
deba@1979
|
314 |
}
|
deba@1979
|
315 |
|
deba@1999
|
316 |
GraphExtender() {
|
deba@1999
|
317 |
node_notifier.setContainer(*this);
|
deba@1999
|
318 |
edge_notifier.setContainer(*this);
|
deba@1999
|
319 |
}
|
deba@1999
|
320 |
|
deba@1979
|
321 |
|
deba@1979
|
322 |
~GraphExtender() {
|
deba@1999
|
323 |
edge_notifier.clear();
|
deba@1999
|
324 |
node_notifier.clear();
|
deba@1979
|
325 |
}
|
deba@1979
|
326 |
};
|
deba@1979
|
327 |
|
deba@2116
|
328 |
/// \ingroup graphbits
|
deba@2116
|
329 |
///
|
deba@2116
|
330 |
/// \brief Extender for the UGraphs
|
deba@2116
|
331 |
template <typename Base>
|
deba@2116
|
332 |
class UGraphExtender : public Base {
|
deba@2116
|
333 |
public:
|
deba@2585
|
334 |
|
deba@2116
|
335 |
typedef Base Parent;
|
deba@2116
|
336 |
typedef UGraphExtender Graph;
|
deba@2116
|
337 |
|
deba@2585
|
338 |
typedef True UndirectedTag;
|
deba@2585
|
339 |
|
deba@2116
|
340 |
typedef typename Parent::Node Node;
|
deba@2116
|
341 |
typedef typename Parent::Edge Edge;
|
deba@2116
|
342 |
typedef typename Parent::UEdge UEdge;
|
deba@2116
|
343 |
|
deba@2116
|
344 |
// UGraph extension
|
deba@2116
|
345 |
|
deba@2116
|
346 |
int maxId(Node) const {
|
deba@2116
|
347 |
return Parent::maxNodeId();
|
deba@2116
|
348 |
}
|
deba@2116
|
349 |
|
deba@2116
|
350 |
int maxId(Edge) const {
|
deba@2116
|
351 |
return Parent::maxEdgeId();
|
deba@2116
|
352 |
}
|
deba@2116
|
353 |
|
deba@2116
|
354 |
int maxId(UEdge) const {
|
deba@2116
|
355 |
return Parent::maxUEdgeId();
|
deba@2116
|
356 |
}
|
deba@2116
|
357 |
|
deba@2116
|
358 |
Node fromId(int id, Node) const {
|
deba@2116
|
359 |
return Parent::nodeFromId(id);
|
deba@2116
|
360 |
}
|
deba@2116
|
361 |
|
deba@2116
|
362 |
Edge fromId(int id, Edge) const {
|
deba@2116
|
363 |
return Parent::edgeFromId(id);
|
deba@2116
|
364 |
}
|
deba@2116
|
365 |
|
deba@2116
|
366 |
UEdge fromId(int id, UEdge) const {
|
deba@2116
|
367 |
return Parent::uEdgeFromId(id);
|
deba@2116
|
368 |
}
|
deba@2116
|
369 |
|
deba@2116
|
370 |
Node oppositeNode(const Node &n, const UEdge &e) const {
|
deba@2116
|
371 |
if( n == Parent::source(e))
|
deba@2116
|
372 |
return Parent::target(e);
|
deba@2116
|
373 |
else if( n == Parent::target(e))
|
deba@2116
|
374 |
return Parent::source(e);
|
deba@2116
|
375 |
else
|
deba@2116
|
376 |
return INVALID;
|
deba@2116
|
377 |
}
|
deba@2116
|
378 |
|
deba@2116
|
379 |
Edge oppositeEdge(const Edge &e) const {
|
deba@2116
|
380 |
return Parent::direct(e, !Parent::direction(e));
|
deba@2116
|
381 |
}
|
deba@2116
|
382 |
|
deba@2116
|
383 |
using Parent::direct;
|
deba@2116
|
384 |
Edge direct(const UEdge &ue, const Node &s) const {
|
deba@2116
|
385 |
return Parent::direct(ue, Parent::source(ue) == s);
|
deba@2116
|
386 |
}
|
deba@2116
|
387 |
|
deba@2116
|
388 |
// Alterable extension
|
deba@2116
|
389 |
|
deba@2116
|
390 |
typedef AlterationNotifier<UGraphExtender, Node> NodeNotifier;
|
deba@2116
|
391 |
typedef AlterationNotifier<UGraphExtender, Edge> EdgeNotifier;
|
deba@2116
|
392 |
typedef AlterationNotifier<UGraphExtender, UEdge> UEdgeNotifier;
|
deba@2116
|
393 |
|
deba@2116
|
394 |
|
deba@2116
|
395 |
protected:
|
deba@2116
|
396 |
|
deba@2116
|
397 |
mutable NodeNotifier node_notifier;
|
deba@2116
|
398 |
mutable EdgeNotifier edge_notifier;
|
deba@2116
|
399 |
mutable UEdgeNotifier uedge_notifier;
|
deba@2116
|
400 |
|
deba@2116
|
401 |
public:
|
deba@2116
|
402 |
|
deba@2384
|
403 |
NodeNotifier& notifier(Node) const {
|
deba@2116
|
404 |
return node_notifier;
|
deba@2116
|
405 |
}
|
deba@2116
|
406 |
|
deba@2384
|
407 |
EdgeNotifier& notifier(Edge) const {
|
deba@2116
|
408 |
return edge_notifier;
|
deba@2116
|
409 |
}
|
deba@2116
|
410 |
|
deba@2384
|
411 |
UEdgeNotifier& notifier(UEdge) const {
|
deba@2116
|
412 |
return uedge_notifier;
|
deba@2116
|
413 |
}
|
deba@2116
|
414 |
|
deba@2116
|
415 |
|
deba@2116
|
416 |
|
deba@2116
|
417 |
class NodeIt : public Node {
|
deba@2116
|
418 |
const Graph* graph;
|
deba@2116
|
419 |
public:
|
deba@2116
|
420 |
|
deba@2116
|
421 |
NodeIt() {}
|
deba@2116
|
422 |
|
deba@2116
|
423 |
NodeIt(Invalid i) : Node(i) { }
|
deba@2116
|
424 |
|
deba@2116
|
425 |
explicit NodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2116
|
426 |
_graph.first(static_cast<Node&>(*this));
|
deba@2116
|
427 |
}
|
deba@2116
|
428 |
|
deba@2116
|
429 |
NodeIt(const Graph& _graph, const Node& node)
|
deba@2116
|
430 |
: Node(node), graph(&_graph) {}
|
deba@2116
|
431 |
|
deba@2116
|
432 |
NodeIt& operator++() {
|
deba@2116
|
433 |
graph->next(*this);
|
deba@2116
|
434 |
return *this;
|
deba@2116
|
435 |
}
|
deba@2116
|
436 |
|
deba@2116
|
437 |
};
|
deba@2116
|
438 |
|
deba@2116
|
439 |
|
deba@2116
|
440 |
class EdgeIt : public Edge {
|
deba@2116
|
441 |
const Graph* graph;
|
deba@2116
|
442 |
public:
|
deba@2116
|
443 |
|
deba@2116
|
444 |
EdgeIt() { }
|
deba@2116
|
445 |
|
deba@2116
|
446 |
EdgeIt(Invalid i) : Edge(i) { }
|
deba@2116
|
447 |
|
deba@2116
|
448 |
explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2116
|
449 |
_graph.first(static_cast<Edge&>(*this));
|
deba@2116
|
450 |
}
|
deba@2116
|
451 |
|
deba@2116
|
452 |
EdgeIt(const Graph& _graph, const Edge& e) :
|
deba@2116
|
453 |
Edge(e), graph(&_graph) { }
|
deba@2116
|
454 |
|
deba@2116
|
455 |
EdgeIt& operator++() {
|
deba@2116
|
456 |
graph->next(*this);
|
deba@2116
|
457 |
return *this;
|
deba@2116
|
458 |
}
|
deba@2116
|
459 |
|
deba@2116
|
460 |
};
|
deba@2116
|
461 |
|
deba@2116
|
462 |
|
deba@2116
|
463 |
class OutEdgeIt : public Edge {
|
deba@2116
|
464 |
const Graph* graph;
|
deba@2116
|
465 |
public:
|
deba@2116
|
466 |
|
deba@2116
|
467 |
OutEdgeIt() { }
|
deba@2116
|
468 |
|
deba@2116
|
469 |
OutEdgeIt(Invalid i) : Edge(i) { }
|
deba@2116
|
470 |
|
deba@2116
|
471 |
OutEdgeIt(const Graph& _graph, const Node& node)
|
deba@2116
|
472 |
: graph(&_graph) {
|
deba@2116
|
473 |
_graph.firstOut(*this, node);
|
deba@2116
|
474 |
}
|
deba@2116
|
475 |
|
deba@2116
|
476 |
OutEdgeIt(const Graph& _graph, const Edge& edge)
|
deba@2116
|
477 |
: Edge(edge), graph(&_graph) {}
|
deba@2116
|
478 |
|
deba@2116
|
479 |
OutEdgeIt& operator++() {
|
deba@2116
|
480 |
graph->nextOut(*this);
|
deba@2116
|
481 |
return *this;
|
deba@2116
|
482 |
}
|
deba@2116
|
483 |
|
deba@2116
|
484 |
};
|
deba@2116
|
485 |
|
deba@2116
|
486 |
|
deba@2116
|
487 |
class InEdgeIt : public Edge {
|
deba@2116
|
488 |
const Graph* graph;
|
deba@2116
|
489 |
public:
|
deba@2116
|
490 |
|
deba@2116
|
491 |
InEdgeIt() { }
|
deba@2116
|
492 |
|
deba@2116
|
493 |
InEdgeIt(Invalid i) : Edge(i) { }
|
deba@2116
|
494 |
|
deba@2116
|
495 |
InEdgeIt(const Graph& _graph, const Node& node)
|
deba@2116
|
496 |
: graph(&_graph) {
|
deba@2116
|
497 |
_graph.firstIn(*this, node);
|
deba@2116
|
498 |
}
|
deba@2116
|
499 |
|
deba@2116
|
500 |
InEdgeIt(const Graph& _graph, const Edge& edge) :
|
deba@2116
|
501 |
Edge(edge), graph(&_graph) {}
|
deba@2116
|
502 |
|
deba@2116
|
503 |
InEdgeIt& operator++() {
|
deba@2116
|
504 |
graph->nextIn(*this);
|
deba@2116
|
505 |
return *this;
|
deba@2116
|
506 |
}
|
deba@2116
|
507 |
|
deba@2116
|
508 |
};
|
deba@2116
|
509 |
|
deba@2116
|
510 |
|
deba@2116
|
511 |
class UEdgeIt : public Parent::UEdge {
|
deba@2116
|
512 |
const Graph* graph;
|
deba@2116
|
513 |
public:
|
deba@2116
|
514 |
|
deba@2116
|
515 |
UEdgeIt() { }
|
deba@2116
|
516 |
|
deba@2116
|
517 |
UEdgeIt(Invalid i) : UEdge(i) { }
|
deba@2116
|
518 |
|
deba@2116
|
519 |
explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2116
|
520 |
_graph.first(static_cast<UEdge&>(*this));
|
deba@2116
|
521 |
}
|
deba@2116
|
522 |
|
deba@2116
|
523 |
UEdgeIt(const Graph& _graph, const UEdge& e) :
|
deba@2116
|
524 |
UEdge(e), graph(&_graph) { }
|
deba@2116
|
525 |
|
deba@2116
|
526 |
UEdgeIt& operator++() {
|
deba@2116
|
527 |
graph->next(*this);
|
deba@2116
|
528 |
return *this;
|
deba@2116
|
529 |
}
|
deba@2116
|
530 |
|
deba@2116
|
531 |
};
|
deba@2116
|
532 |
|
deba@2116
|
533 |
class IncEdgeIt : public Parent::UEdge {
|
deba@2116
|
534 |
friend class UGraphExtender;
|
deba@2116
|
535 |
const Graph* graph;
|
deba@2116
|
536 |
bool direction;
|
deba@2116
|
537 |
public:
|
deba@2116
|
538 |
|
deba@2116
|
539 |
IncEdgeIt() { }
|
deba@2116
|
540 |
|
deba@2116
|
541 |
IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
|
deba@2116
|
542 |
|
deba@2116
|
543 |
IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
|
deba@2116
|
544 |
_graph.firstInc(*this, direction, n);
|
deba@2116
|
545 |
}
|
deba@2116
|
546 |
|
deba@2116
|
547 |
IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
|
deba@2116
|
548 |
: graph(&_graph), UEdge(ue) {
|
deba@2116
|
549 |
direction = (_graph.source(ue) == n);
|
deba@2116
|
550 |
}
|
deba@2116
|
551 |
|
deba@2116
|
552 |
IncEdgeIt& operator++() {
|
deba@2116
|
553 |
graph->nextInc(*this, direction);
|
deba@2116
|
554 |
return *this;
|
deba@2116
|
555 |
}
|
deba@2116
|
556 |
};
|
deba@2116
|
557 |
|
deba@2116
|
558 |
/// \brief Base node of the iterator
|
deba@2116
|
559 |
///
|
deba@2116
|
560 |
/// Returns the base node (ie. the source in this case) of the iterator
|
deba@2116
|
561 |
Node baseNode(const OutEdgeIt &e) const {
|
deba@2386
|
562 |
return Parent::source(static_cast<const Edge&>(e));
|
deba@2116
|
563 |
}
|
deba@2116
|
564 |
/// \brief Running node of the iterator
|
deba@2116
|
565 |
///
|
deba@2116
|
566 |
/// Returns the running node (ie. the target in this case) of the
|
deba@2116
|
567 |
/// iterator
|
deba@2116
|
568 |
Node runningNode(const OutEdgeIt &e) const {
|
deba@2386
|
569 |
return Parent::target(static_cast<const Edge&>(e));
|
deba@2116
|
570 |
}
|
deba@2116
|
571 |
|
deba@2116
|
572 |
/// \brief Base node of the iterator
|
deba@2116
|
573 |
///
|
deba@2116
|
574 |
/// Returns the base node (ie. the target in this case) of the iterator
|
deba@2116
|
575 |
Node baseNode(const InEdgeIt &e) const {
|
deba@2386
|
576 |
return Parent::target(static_cast<const Edge&>(e));
|
deba@2116
|
577 |
}
|
deba@2116
|
578 |
/// \brief Running node of the iterator
|
deba@2116
|
579 |
///
|
deba@2116
|
580 |
/// Returns the running node (ie. the source in this case) of the
|
deba@2116
|
581 |
/// iterator
|
deba@2116
|
582 |
Node runningNode(const InEdgeIt &e) const {
|
deba@2386
|
583 |
return Parent::source(static_cast<const Edge&>(e));
|
deba@2116
|
584 |
}
|
deba@2116
|
585 |
|
deba@2116
|
586 |
/// Base node of the iterator
|
deba@2116
|
587 |
///
|
deba@2116
|
588 |
/// Returns the base node of the iterator
|
deba@2116
|
589 |
Node baseNode(const IncEdgeIt &e) const {
|
deba@2116
|
590 |
return e.direction ? source(e) : target(e);
|
deba@2116
|
591 |
}
|
deba@2116
|
592 |
/// Running node of the iterator
|
deba@2116
|
593 |
///
|
deba@2116
|
594 |
/// Returns the running node of the iterator
|
deba@2116
|
595 |
Node runningNode(const IncEdgeIt &e) const {
|
deba@2116
|
596 |
return e.direction ? target(e) : source(e);
|
deba@2116
|
597 |
}
|
deba@2116
|
598 |
|
deba@2116
|
599 |
// Mappable extension
|
deba@2116
|
600 |
|
deba@2116
|
601 |
template <typename _Value>
|
deba@2116
|
602 |
class NodeMap
|
deba@2116
|
603 |
: public MapExtender<DefaultMap<Graph, Node, _Value> > {
|
deba@2116
|
604 |
public:
|
deba@2116
|
605 |
typedef UGraphExtender Graph;
|
deba@2116
|
606 |
typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
|
deba@2116
|
607 |
|
deba@2116
|
608 |
NodeMap(const Graph& graph)
|
deba@2116
|
609 |
: Parent(graph) {}
|
deba@2116
|
610 |
NodeMap(const Graph& graph, const _Value& value)
|
deba@2116
|
611 |
: Parent(graph, value) {}
|
deba@2116
|
612 |
|
deba@2116
|
613 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@2116
|
614 |
return operator=<NodeMap>(cmap);
|
deba@2116
|
615 |
}
|
deba@2116
|
616 |
|
deba@2116
|
617 |
template <typename CMap>
|
deba@2116
|
618 |
NodeMap& operator=(const CMap& cmap) {
|
deba@2116
|
619 |
Parent::operator=(cmap);
|
deba@2116
|
620 |
return *this;
|
deba@2116
|
621 |
}
|
deba@2116
|
622 |
|
deba@2116
|
623 |
};
|
deba@2116
|
624 |
|
deba@2116
|
625 |
template <typename _Value>
|
deba@2116
|
626 |
class EdgeMap
|
deba@2116
|
627 |
: public MapExtender<DefaultMap<Graph, Edge, _Value> > {
|
deba@2116
|
628 |
public:
|
deba@2116
|
629 |
typedef UGraphExtender Graph;
|
deba@2116
|
630 |
typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
|
deba@2116
|
631 |
|
deba@2116
|
632 |
EdgeMap(const Graph& graph)
|
deba@2116
|
633 |
: Parent(graph) {}
|
deba@2116
|
634 |
EdgeMap(const Graph& graph, const _Value& value)
|
deba@2116
|
635 |
: Parent(graph, value) {}
|
deba@2116
|
636 |
|
deba@2116
|
637 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@2116
|
638 |
return operator=<EdgeMap>(cmap);
|
deba@2116
|
639 |
}
|
deba@2116
|
640 |
|
deba@2116
|
641 |
template <typename CMap>
|
deba@2116
|
642 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@2116
|
643 |
Parent::operator=(cmap);
|
deba@2116
|
644 |
return *this;
|
deba@2116
|
645 |
}
|
deba@2116
|
646 |
};
|
deba@2116
|
647 |
|
deba@2116
|
648 |
|
deba@2116
|
649 |
template <typename _Value>
|
deba@2116
|
650 |
class UEdgeMap
|
deba@2116
|
651 |
: public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
|
deba@2116
|
652 |
public:
|
deba@2116
|
653 |
typedef UGraphExtender Graph;
|
deba@2116
|
654 |
typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
|
deba@2116
|
655 |
|
deba@2116
|
656 |
UEdgeMap(const Graph& graph)
|
deba@2116
|
657 |
: Parent(graph) {}
|
deba@2116
|
658 |
|
deba@2116
|
659 |
UEdgeMap(const Graph& graph, const _Value& value)
|
deba@2116
|
660 |
: Parent(graph, value) {}
|
deba@2116
|
661 |
|
deba@2116
|
662 |
UEdgeMap& operator=(const UEdgeMap& cmap) {
|
deba@2116
|
663 |
return operator=<UEdgeMap>(cmap);
|
deba@2116
|
664 |
}
|
deba@2116
|
665 |
|
deba@2116
|
666 |
template <typename CMap>
|
deba@2116
|
667 |
UEdgeMap& operator=(const CMap& cmap) {
|
deba@2116
|
668 |
Parent::operator=(cmap);
|
deba@2116
|
669 |
return *this;
|
deba@2116
|
670 |
}
|
deba@2116
|
671 |
|
deba@2116
|
672 |
};
|
deba@2116
|
673 |
|
deba@2116
|
674 |
// Alteration extension
|
deba@2116
|
675 |
|
deba@2116
|
676 |
Node addNode() {
|
deba@2116
|
677 |
Node node = Parent::addNode();
|
deba@2384
|
678 |
notifier(Node()).add(node);
|
deba@2116
|
679 |
return node;
|
deba@2116
|
680 |
}
|
deba@2116
|
681 |
|
deba@2116
|
682 |
UEdge addEdge(const Node& from, const Node& to) {
|
deba@2116
|
683 |
UEdge uedge = Parent::addEdge(from, to);
|
deba@2384
|
684 |
notifier(UEdge()).add(uedge);
|
deba@2386
|
685 |
std::vector<Edge> ev;
|
deba@2386
|
686 |
ev.push_back(Parent::direct(uedge, true));
|
deba@2386
|
687 |
ev.push_back(Parent::direct(uedge, false));
|
deba@2386
|
688 |
notifier(Edge()).add(ev);
|
deba@2116
|
689 |
return uedge;
|
deba@2116
|
690 |
}
|
deba@2116
|
691 |
|
deba@2116
|
692 |
void clear() {
|
deba@2384
|
693 |
notifier(Edge()).clear();
|
deba@2384
|
694 |
notifier(UEdge()).clear();
|
deba@2384
|
695 |
notifier(Node()).clear();
|
deba@2116
|
696 |
Parent::clear();
|
deba@2116
|
697 |
}
|
deba@2116
|
698 |
|
deba@2290
|
699 |
template <typename Graph, typename NodeRefMap, typename UEdgeRefMap>
|
deba@2329
|
700 |
void build(const Graph& graph, NodeRefMap& nodeRef,
|
deba@2290
|
701 |
UEdgeRefMap& uEdgeRef) {
|
deba@2329
|
702 |
Parent::build(graph, nodeRef, uEdgeRef);
|
deba@2384
|
703 |
notifier(Node()).build();
|
deba@2384
|
704 |
notifier(UEdge()).build();
|
deba@2384
|
705 |
notifier(Edge()).build();
|
deba@2290
|
706 |
}
|
deba@2290
|
707 |
|
deba@2116
|
708 |
void erase(const Node& node) {
|
deba@2116
|
709 |
Edge edge;
|
deba@2116
|
710 |
Parent::firstOut(edge, node);
|
deba@2116
|
711 |
while (edge != INVALID ) {
|
deba@2116
|
712 |
erase(edge);
|
deba@2116
|
713 |
Parent::firstOut(edge, node);
|
deba@2116
|
714 |
}
|
deba@2116
|
715 |
|
deba@2116
|
716 |
Parent::firstIn(edge, node);
|
deba@2116
|
717 |
while (edge != INVALID ) {
|
deba@2116
|
718 |
erase(edge);
|
deba@2116
|
719 |
Parent::firstIn(edge, node);
|
deba@2116
|
720 |
}
|
deba@2116
|
721 |
|
deba@2384
|
722 |
notifier(Node()).erase(node);
|
deba@2116
|
723 |
Parent::erase(node);
|
deba@2116
|
724 |
}
|
deba@2116
|
725 |
|
deba@2116
|
726 |
void erase(const UEdge& uedge) {
|
deba@2386
|
727 |
std::vector<Edge> ev;
|
deba@2386
|
728 |
ev.push_back(Parent::direct(uedge, true));
|
deba@2386
|
729 |
ev.push_back(Parent::direct(uedge, false));
|
deba@2386
|
730 |
notifier(Edge()).erase(ev);
|
deba@2384
|
731 |
notifier(UEdge()).erase(uedge);
|
deba@2116
|
732 |
Parent::erase(uedge);
|
deba@2116
|
733 |
}
|
deba@2116
|
734 |
|
deba@2116
|
735 |
UGraphExtender() {
|
deba@2116
|
736 |
node_notifier.setContainer(*this);
|
deba@2116
|
737 |
edge_notifier.setContainer(*this);
|
deba@2116
|
738 |
uedge_notifier.setContainer(*this);
|
deba@2116
|
739 |
}
|
deba@2116
|
740 |
|
deba@2116
|
741 |
~UGraphExtender() {
|
deba@2116
|
742 |
uedge_notifier.clear();
|
deba@2116
|
743 |
edge_notifier.clear();
|
deba@2116
|
744 |
node_notifier.clear();
|
deba@2116
|
745 |
}
|
deba@2116
|
746 |
|
deba@2116
|
747 |
};
|
deba@2116
|
748 |
|
deba@2116
|
749 |
/// \ingroup graphbits
|
deba@2116
|
750 |
///
|
deba@2116
|
751 |
/// \brief Extender for the BpUGraphs
|
deba@2116
|
752 |
template <typename Base>
|
deba@2116
|
753 |
class BpUGraphExtender : public Base {
|
deba@2116
|
754 |
public:
|
deba@2231
|
755 |
|
deba@2116
|
756 |
typedef Base Parent;
|
deba@2116
|
757 |
typedef BpUGraphExtender Graph;
|
deba@2116
|
758 |
|
deba@2585
|
759 |
typedef True UndirectedTag;
|
deba@2585
|
760 |
|
deba@2116
|
761 |
typedef typename Parent::Node Node;
|
deba@2231
|
762 |
typedef typename Parent::ANode ANode;
|
deba@2231
|
763 |
typedef typename Parent::BNode BNode;
|
deba@2231
|
764 |
typedef typename Parent::Edge Edge;
|
deba@2116
|
765 |
typedef typename Parent::UEdge UEdge;
|
deba@2116
|
766 |
|
deba@2116
|
767 |
|
deba@2231
|
768 |
Node oppositeNode(const Node& node, const UEdge& edge) const {
|
deba@2231
|
769 |
return Parent::aNode(edge) == node ?
|
deba@2231
|
770 |
Parent::bNode(edge) : Parent::aNode(edge);
|
deba@2116
|
771 |
}
|
deba@2116
|
772 |
|
deba@2231
|
773 |
using Parent::direct;
|
deba@2116
|
774 |
Edge direct(const UEdge& edge, const Node& node) const {
|
deba@2231
|
775 |
return Parent::direct(edge, node == Parent::source(edge));
|
deba@2116
|
776 |
}
|
deba@2116
|
777 |
|
deba@2116
|
778 |
Edge oppositeEdge(const Edge& edge) const {
|
deba@2231
|
779 |
return direct(edge, !Parent::direction(edge));
|
deba@2116
|
780 |
}
|
deba@2231
|
781 |
|
deba@2116
|
782 |
int maxId(Node) const {
|
deba@2116
|
783 |
return Parent::maxNodeId();
|
deba@2116
|
784 |
}
|
deba@2116
|
785 |
int maxId(BNode) const {
|
deba@2116
|
786 |
return Parent::maxBNodeId();
|
deba@2116
|
787 |
}
|
deba@2116
|
788 |
int maxId(ANode) const {
|
deba@2116
|
789 |
return Parent::maxANodeId();
|
deba@2116
|
790 |
}
|
deba@2116
|
791 |
int maxId(Edge) const {
|
deba@2231
|
792 |
return Parent::maxEdgeId();
|
deba@2116
|
793 |
}
|
deba@2116
|
794 |
int maxId(UEdge) const {
|
deba@2116
|
795 |
return Parent::maxUEdgeId();
|
deba@2116
|
796 |
}
|
deba@2116
|
797 |
|
deba@2116
|
798 |
|
deba@2116
|
799 |
Node fromId(int id, Node) const {
|
deba@2116
|
800 |
return Parent::nodeFromId(id);
|
deba@2116
|
801 |
}
|
deba@2116
|
802 |
ANode fromId(int id, ANode) const {
|
deba@2231
|
803 |
return Parent::nodeFromANodeId(id);
|
deba@2116
|
804 |
}
|
deba@2116
|
805 |
BNode fromId(int id, BNode) const {
|
deba@2231
|
806 |
return Parent::nodeFromBNodeId(id);
|
deba@2116
|
807 |
}
|
deba@2116
|
808 |
Edge fromId(int id, Edge) const {
|
deba@2116
|
809 |
return Parent::edgeFromId(id);
|
deba@2116
|
810 |
}
|
deba@2116
|
811 |
UEdge fromId(int id, UEdge) const {
|
deba@2116
|
812 |
return Parent::uEdgeFromId(id);
|
deba@2116
|
813 |
}
|
deba@2116
|
814 |
|
deba@2116
|
815 |
typedef AlterationNotifier<BpUGraphExtender, ANode> ANodeNotifier;
|
deba@2116
|
816 |
typedef AlterationNotifier<BpUGraphExtender, BNode> BNodeNotifier;
|
deba@2116
|
817 |
typedef AlterationNotifier<BpUGraphExtender, Node> NodeNotifier;
|
deba@2116
|
818 |
typedef AlterationNotifier<BpUGraphExtender, Edge> EdgeNotifier;
|
deba@2116
|
819 |
typedef AlterationNotifier<BpUGraphExtender, UEdge> UEdgeNotifier;
|
deba@2116
|
820 |
|
deba@2116
|
821 |
protected:
|
deba@2116
|
822 |
|
deba@2116
|
823 |
mutable ANodeNotifier anode_notifier;
|
deba@2116
|
824 |
mutable BNodeNotifier bnode_notifier;
|
deba@2116
|
825 |
mutable NodeNotifier node_notifier;
|
deba@2116
|
826 |
mutable EdgeNotifier edge_notifier;
|
deba@2116
|
827 |
mutable UEdgeNotifier uedge_notifier;
|
deba@2116
|
828 |
|
deba@2116
|
829 |
public:
|
deba@2116
|
830 |
|
deba@2384
|
831 |
NodeNotifier& notifier(Node) const {
|
deba@2116
|
832 |
return node_notifier;
|
deba@2116
|
833 |
}
|
deba@2116
|
834 |
|
deba@2384
|
835 |
ANodeNotifier& notifier(ANode) const {
|
deba@2116
|
836 |
return anode_notifier;
|
deba@2116
|
837 |
}
|
deba@2116
|
838 |
|
deba@2384
|
839 |
BNodeNotifier& notifier(BNode) const {
|
deba@2116
|
840 |
return bnode_notifier;
|
deba@2116
|
841 |
}
|
deba@2116
|
842 |
|
deba@2384
|
843 |
EdgeNotifier& notifier(Edge) const {
|
deba@2116
|
844 |
return edge_notifier;
|
deba@2116
|
845 |
}
|
deba@2116
|
846 |
|
deba@2384
|
847 |
UEdgeNotifier& notifier(UEdge) const {
|
deba@2116
|
848 |
return uedge_notifier;
|
deba@2116
|
849 |
}
|
deba@2116
|
850 |
|
deba@2116
|
851 |
class NodeIt : public Node {
|
deba@2116
|
852 |
const Graph* graph;
|
deba@2116
|
853 |
public:
|
deba@2116
|
854 |
|
deba@2116
|
855 |
NodeIt() { }
|
deba@2116
|
856 |
|
deba@2116
|
857 |
NodeIt(Invalid i) : Node(INVALID) { }
|
deba@2116
|
858 |
|
deba@2116
|
859 |
explicit NodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2116
|
860 |
graph->first(static_cast<Node&>(*this));
|
deba@2116
|
861 |
}
|
deba@2116
|
862 |
|
deba@2116
|
863 |
NodeIt(const Graph& _graph, const Node& node)
|
deba@2116
|
864 |
: Node(node), graph(&_graph) { }
|
deba@2116
|
865 |
|
deba@2116
|
866 |
NodeIt& operator++() {
|
deba@2116
|
867 |
graph->next(*this);
|
deba@2116
|
868 |
return *this;
|
deba@2116
|
869 |
}
|
deba@2116
|
870 |
|
deba@2116
|
871 |
};
|
deba@2116
|
872 |
|
deba@2116
|
873 |
class ANodeIt : public Node {
|
deba@2116
|
874 |
friend class BpUGraphExtender;
|
deba@2116
|
875 |
const Graph* graph;
|
deba@2116
|
876 |
public:
|
deba@2116
|
877 |
|
deba@2116
|
878 |
ANodeIt() { }
|
deba@2116
|
879 |
|
deba@2116
|
880 |
ANodeIt(Invalid i) : Node(INVALID) { }
|
deba@2116
|
881 |
|
deba@2116
|
882 |
explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2116
|
883 |
graph->firstANode(static_cast<Node&>(*this));
|
deba@2116
|
884 |
}
|
deba@2116
|
885 |
|
deba@2116
|
886 |
ANodeIt(const Graph& _graph, const Node& node)
|
deba@2116
|
887 |
: Node(node), graph(&_graph) {}
|
deba@2116
|
888 |
|
deba@2116
|
889 |
ANodeIt& operator++() {
|
deba@2116
|
890 |
graph->nextANode(*this);
|
deba@2116
|
891 |
return *this;
|
deba@2116
|
892 |
}
|
deba@2116
|
893 |
};
|
deba@2116
|
894 |
|
deba@2116
|
895 |
class BNodeIt : public Node {
|
deba@2116
|
896 |
friend class BpUGraphExtender;
|
deba@2116
|
897 |
const Graph* graph;
|
deba@2116
|
898 |
public:
|
deba@2116
|
899 |
|
deba@2116
|
900 |
BNodeIt() { }
|
deba@2116
|
901 |
|
deba@2116
|
902 |
BNodeIt(Invalid i) : Node(INVALID) { }
|
deba@2116
|
903 |
|
deba@2116
|
904 |
explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2116
|
905 |
graph->firstBNode(static_cast<Node&>(*this));
|
deba@2116
|
906 |
}
|
deba@2116
|
907 |
|
deba@2116
|
908 |
BNodeIt(const Graph& _graph, const Node& node)
|
deba@2116
|
909 |
: Node(node), graph(&_graph) {}
|
deba@2116
|
910 |
|
deba@2116
|
911 |
BNodeIt& operator++() {
|
deba@2116
|
912 |
graph->nextBNode(*this);
|
deba@2116
|
913 |
return *this;
|
deba@2116
|
914 |
}
|
deba@2116
|
915 |
};
|
deba@2116
|
916 |
|
deba@2116
|
917 |
class EdgeIt : public Edge {
|
deba@2116
|
918 |
friend class BpUGraphExtender;
|
deba@2116
|
919 |
const Graph* graph;
|
deba@2116
|
920 |
public:
|
deba@2116
|
921 |
|
deba@2116
|
922 |
EdgeIt() { }
|
deba@2116
|
923 |
|
deba@2116
|
924 |
EdgeIt(Invalid i) : Edge(INVALID) { }
|
deba@2116
|
925 |
|
deba@2116
|
926 |
explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2116
|
927 |
graph->first(static_cast<Edge&>(*this));
|
deba@2116
|
928 |
}
|
deba@2116
|
929 |
|
deba@2116
|
930 |
EdgeIt(const Graph& _graph, const Edge& edge)
|
deba@2116
|
931 |
: Edge(edge), graph(&_graph) { }
|
deba@2116
|
932 |
|
deba@2116
|
933 |
EdgeIt& operator++() {
|
deba@2116
|
934 |
graph->next(*this);
|
deba@2116
|
935 |
return *this;
|
deba@2116
|
936 |
}
|
deba@2116
|
937 |
|
deba@2116
|
938 |
};
|
deba@2116
|
939 |
|
deba@2116
|
940 |
class UEdgeIt : public UEdge {
|
deba@2116
|
941 |
friend class BpUGraphExtender;
|
deba@2116
|
942 |
const Graph* graph;
|
deba@2116
|
943 |
public:
|
deba@2116
|
944 |
|
deba@2116
|
945 |
UEdgeIt() { }
|
deba@2116
|
946 |
|
deba@2116
|
947 |
UEdgeIt(Invalid i) : UEdge(INVALID) { }
|
deba@2116
|
948 |
|
deba@2116
|
949 |
explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
|
deba@2116
|
950 |
graph->first(static_cast<UEdge&>(*this));
|
deba@2116
|
951 |
}
|
deba@2116
|
952 |
|
deba@2116
|
953 |
UEdgeIt(const Graph& _graph, const UEdge& edge)
|
deba@2116
|
954 |
: UEdge(edge), graph(&_graph) { }
|
deba@2116
|
955 |
|
deba@2116
|
956 |
UEdgeIt& operator++() {
|
deba@2116
|
957 |
graph->next(*this);
|
deba@2116
|
958 |
return *this;
|
deba@2116
|
959 |
}
|
deba@2116
|
960 |
};
|
deba@2116
|
961 |
|
deba@2116
|
962 |
class OutEdgeIt : public Edge {
|
deba@2116
|
963 |
friend class BpUGraphExtender;
|
deba@2116
|
964 |
const Graph* graph;
|
deba@2116
|
965 |
public:
|
deba@2116
|
966 |
|
deba@2116
|
967 |
OutEdgeIt() { }
|
deba@2116
|
968 |
|
deba@2116
|
969 |
OutEdgeIt(Invalid i) : Edge(i) { }
|
deba@2116
|
970 |
|
deba@2116
|
971 |
OutEdgeIt(const Graph& _graph, const Node& node)
|
deba@2116
|
972 |
: graph(&_graph) {
|
deba@2116
|
973 |
graph->firstOut(*this, node);
|
deba@2116
|
974 |
}
|
deba@2116
|
975 |
|
deba@2116
|
976 |
OutEdgeIt(const Graph& _graph, const Edge& edge)
|
deba@2116
|
977 |
: Edge(edge), graph(&_graph) {}
|
deba@2116
|
978 |
|
deba@2116
|
979 |
OutEdgeIt& operator++() {
|
deba@2116
|
980 |
graph->nextOut(*this);
|
deba@2116
|
981 |
return *this;
|
deba@2116
|
982 |
}
|
deba@2116
|
983 |
|
deba@2116
|
984 |
};
|
deba@2116
|
985 |
|
deba@2116
|
986 |
|
deba@2116
|
987 |
class InEdgeIt : public Edge {
|
deba@2116
|
988 |
friend class BpUGraphExtender;
|
deba@2116
|
989 |
const Graph* graph;
|
deba@2116
|
990 |
public:
|
deba@2116
|
991 |
|
deba@2116
|
992 |
InEdgeIt() { }
|
deba@2116
|
993 |
|
deba@2116
|
994 |
InEdgeIt(Invalid i) : Edge(i) { }
|
deba@2116
|
995 |
|
deba@2116
|
996 |
InEdgeIt(const Graph& _graph, const Node& node)
|
deba@2116
|
997 |
: graph(&_graph) {
|
deba@2116
|
998 |
graph->firstIn(*this, node);
|
deba@2116
|
999 |
}
|
deba@2116
|
1000 |
|
deba@2116
|
1001 |
InEdgeIt(const Graph& _graph, const Edge& edge) :
|
deba@2116
|
1002 |
Edge(edge), graph(&_graph) {}
|
deba@2116
|
1003 |
|
deba@2116
|
1004 |
InEdgeIt& operator++() {
|
deba@2116
|
1005 |
graph->nextIn(*this);
|
deba@2116
|
1006 |
return *this;
|
deba@2116
|
1007 |
}
|
deba@2116
|
1008 |
|
deba@2116
|
1009 |
};
|
deba@2116
|
1010 |
|
deba@2116
|
1011 |
/// \brief Base node of the iterator
|
deba@2116
|
1012 |
///
|
deba@2116
|
1013 |
/// Returns the base node (ie. the source in this case) of the iterator
|
deba@2116
|
1014 |
Node baseNode(const OutEdgeIt &e) const {
|
deba@2386
|
1015 |
return Parent::source(static_cast<const Edge&>(e));
|
deba@2116
|
1016 |
}
|
deba@2116
|
1017 |
/// \brief Running node of the iterator
|
deba@2116
|
1018 |
///
|
deba@2116
|
1019 |
/// Returns the running node (ie. the target in this case) of the
|
deba@2116
|
1020 |
/// iterator
|
deba@2116
|
1021 |
Node runningNode(const OutEdgeIt &e) const {
|
deba@2386
|
1022 |
return Parent::target(static_cast<const Edge&>(e));
|
deba@2116
|
1023 |
}
|
deba@2116
|
1024 |
|
deba@2116
|
1025 |
/// \brief Base node of the iterator
|
deba@2116
|
1026 |
///
|
deba@2116
|
1027 |
/// Returns the base node (ie. the target in this case) of the iterator
|
deba@2116
|
1028 |
Node baseNode(const InEdgeIt &e) const {
|
deba@2386
|
1029 |
return Parent::target(static_cast<const Edge&>(e));
|
deba@2116
|
1030 |
}
|
deba@2116
|
1031 |
/// \brief Running node of the iterator
|
deba@2116
|
1032 |
///
|
deba@2116
|
1033 |
/// Returns the running node (ie. the source in this case) of the
|
deba@2116
|
1034 |
/// iterator
|
deba@2116
|
1035 |
Node runningNode(const InEdgeIt &e) const {
|
deba@2386
|
1036 |
return Parent::source(static_cast<const Edge&>(e));
|
deba@2116
|
1037 |
}
|
deba@2116
|
1038 |
|
deba@2116
|
1039 |
class IncEdgeIt : public Parent::UEdge {
|
deba@2116
|
1040 |
friend class BpUGraphExtender;
|
deba@2116
|
1041 |
const Graph* graph;
|
deba@2116
|
1042 |
bool direction;
|
deba@2116
|
1043 |
public:
|
deba@2116
|
1044 |
|
deba@2116
|
1045 |
IncEdgeIt() { }
|
deba@2116
|
1046 |
|
deba@2116
|
1047 |
IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
|
deba@2116
|
1048 |
|
deba@2116
|
1049 |
IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
|
deba@2116
|
1050 |
graph->firstInc(*this, direction, n);
|
deba@2116
|
1051 |
}
|
deba@2116
|
1052 |
|
deba@2116
|
1053 |
IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
|
deba@2116
|
1054 |
: graph(&_graph), UEdge(ue) {
|
deba@2116
|
1055 |
direction = (graph->source(ue) == n);
|
deba@2116
|
1056 |
}
|
deba@2116
|
1057 |
|
deba@2116
|
1058 |
IncEdgeIt& operator++() {
|
deba@2116
|
1059 |
graph->nextInc(*this, direction);
|
deba@2116
|
1060 |
return *this;
|
deba@2116
|
1061 |
}
|
deba@2116
|
1062 |
};
|
deba@2116
|
1063 |
|
deba@2116
|
1064 |
|
deba@2116
|
1065 |
/// Base node of the iterator
|
deba@2116
|
1066 |
///
|
deba@2116
|
1067 |
/// Returns the base node of the iterator
|
deba@2116
|
1068 |
Node baseNode(const IncEdgeIt &e) const {
|
deba@2116
|
1069 |
return e.direction ? source(e) : target(e);
|
deba@2116
|
1070 |
}
|
deba@2116
|
1071 |
|
deba@2116
|
1072 |
/// Running node of the iterator
|
deba@2116
|
1073 |
///
|
deba@2116
|
1074 |
/// Returns the running node of the iterator
|
deba@2116
|
1075 |
Node runningNode(const IncEdgeIt &e) const {
|
deba@2116
|
1076 |
return e.direction ? target(e) : source(e);
|
deba@2116
|
1077 |
}
|
deba@2116
|
1078 |
|
deba@2116
|
1079 |
template <typename _Value>
|
deba@2116
|
1080 |
class ANodeMap
|
deba@2116
|
1081 |
: public MapExtender<DefaultMap<Graph, ANode, _Value> > {
|
deba@2116
|
1082 |
public:
|
deba@2116
|
1083 |
typedef BpUGraphExtender Graph;
|
deba@2116
|
1084 |
typedef MapExtender<DefaultMap<Graph, ANode, _Value> > Parent;
|
deba@2116
|
1085 |
|
deba@2116
|
1086 |
ANodeMap(const Graph& graph)
|
deba@2116
|
1087 |
: Parent(graph) {}
|
deba@2116
|
1088 |
ANodeMap(const Graph& graph, const _Value& value)
|
deba@2116
|
1089 |
: Parent(graph, value) {}
|
deba@2116
|
1090 |
|
deba@2116
|
1091 |
ANodeMap& operator=(const ANodeMap& cmap) {
|
deba@2116
|
1092 |
return operator=<ANodeMap>(cmap);
|
deba@2116
|
1093 |
}
|
deba@2116
|
1094 |
|
deba@2116
|
1095 |
template <typename CMap>
|
deba@2116
|
1096 |
ANodeMap& operator=(const CMap& cmap) {
|
deba@2116
|
1097 |
Parent::operator=(cmap);
|
deba@2116
|
1098 |
return *this;
|
deba@2116
|
1099 |
}
|
deba@2116
|
1100 |
|
deba@2116
|
1101 |
};
|
deba@2116
|
1102 |
|
deba@2116
|
1103 |
template <typename _Value>
|
deba@2116
|
1104 |
class BNodeMap
|
deba@2116
|
1105 |
: public MapExtender<DefaultMap<Graph, BNode, _Value> > {
|
deba@2116
|
1106 |
public:
|
deba@2116
|
1107 |
typedef BpUGraphExtender Graph;
|
deba@2116
|
1108 |
typedef MapExtender<DefaultMap<Graph, BNode, _Value> > Parent;
|
deba@2116
|
1109 |
|
deba@2116
|
1110 |
BNodeMap(const Graph& graph)
|
deba@2116
|
1111 |
: Parent(graph) {}
|
deba@2116
|
1112 |
BNodeMap(const Graph& graph, const _Value& value)
|
deba@2116
|
1113 |
: Parent(graph, value) {}
|
deba@2116
|
1114 |
|
deba@2116
|
1115 |
BNodeMap& operator=(const BNodeMap& cmap) {
|
deba@2116
|
1116 |
return operator=<BNodeMap>(cmap);
|
deba@2116
|
1117 |
}
|
deba@2116
|
1118 |
|
deba@2116
|
1119 |
template <typename CMap>
|
deba@2116
|
1120 |
BNodeMap& operator=(const CMap& cmap) {
|
deba@2116
|
1121 |
Parent::operator=(cmap);
|
deba@2116
|
1122 |
return *this;
|
deba@2116
|
1123 |
}
|
deba@2116
|
1124 |
|
deba@2116
|
1125 |
};
|
deba@2116
|
1126 |
|
deba@2116
|
1127 |
public:
|
deba@2116
|
1128 |
|
deba@2116
|
1129 |
template <typename _Value>
|
deba@2116
|
1130 |
class NodeMap {
|
deba@2116
|
1131 |
public:
|
deba@2116
|
1132 |
typedef BpUGraphExtender Graph;
|
deba@2116
|
1133 |
|
deba@2116
|
1134 |
typedef Node Key;
|
deba@2116
|
1135 |
typedef _Value Value;
|
deba@2116
|
1136 |
|
deba@2116
|
1137 |
/// The reference type of the map;
|
deba@2116
|
1138 |
typedef typename ANodeMap<_Value>::Reference Reference;
|
deba@2116
|
1139 |
/// The const reference type of the map;
|
deba@2116
|
1140 |
typedef typename ANodeMap<_Value>::ConstReference ConstReference;
|
deba@2116
|
1141 |
|
deba@2116
|
1142 |
typedef True ReferenceMapTag;
|
deba@2116
|
1143 |
|
deba@2116
|
1144 |
NodeMap(const Graph& _graph)
|
deba@2116
|
1145 |
: graph(_graph), aNodeMap(_graph), bNodeMap(_graph) {}
|
deba@2116
|
1146 |
NodeMap(const Graph& _graph, const _Value& _value)
|
deba@2116
|
1147 |
: graph(_graph), aNodeMap(_graph, _value), bNodeMap(_graph, _value) {}
|
deba@2116
|
1148 |
|
deba@2116
|
1149 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@2116
|
1150 |
return operator=<NodeMap>(cmap);
|
deba@2116
|
1151 |
}
|
deba@2116
|
1152 |
|
deba@2116
|
1153 |
template <typename CMap>
|
deba@2116
|
1154 |
NodeMap& operator=(const CMap& cmap) {
|
alpar@2260
|
1155 |
checkConcept<concepts::ReadMap<Node, _Value>, CMap>();
|
deba@2231
|
1156 |
aNodeMap = cmap;
|
deba@2231
|
1157 |
bNodeMap = cmap;
|
deba@2231
|
1158 |
return *this;
|
deba@2116
|
1159 |
}
|
deba@2116
|
1160 |
|
deba@2116
|
1161 |
ConstReference operator[](const Key& node) const {
|
deba@2116
|
1162 |
if (Parent::aNode(node)) {
|
deba@2116
|
1163 |
return aNodeMap[node];
|
deba@2116
|
1164 |
} else {
|
deba@2116
|
1165 |
return bNodeMap[node];
|
deba@2116
|
1166 |
}
|
deba@2116
|
1167 |
}
|
deba@2116
|
1168 |
|
deba@2116
|
1169 |
Reference operator[](const Key& node) {
|
deba@2116
|
1170 |
if (Parent::aNode(node)) {
|
deba@2116
|
1171 |
return aNodeMap[node];
|
deba@2116
|
1172 |
} else {
|
deba@2116
|
1173 |
return bNodeMap[node];
|
deba@2116
|
1174 |
}
|
deba@2116
|
1175 |
}
|
deba@2116
|
1176 |
|
deba@2116
|
1177 |
void set(const Key& node, const Value& value) {
|
deba@2116
|
1178 |
if (Parent::aNode(node)) {
|
deba@2116
|
1179 |
aNodeMap.set(node, value);
|
deba@2116
|
1180 |
} else {
|
deba@2116
|
1181 |
bNodeMap.set(node, value);
|
deba@2116
|
1182 |
}
|
deba@2116
|
1183 |
}
|
deba@2116
|
1184 |
|
deba@2116
|
1185 |
class MapIt : public NodeIt {
|
deba@2116
|
1186 |
public:
|
deba@2116
|
1187 |
|
deba@2116
|
1188 |
typedef NodeIt Parent;
|
deba@2116
|
1189 |
|
deba@2116
|
1190 |
explicit MapIt(NodeMap& _map)
|
deba@2116
|
1191 |
: Parent(_map.graph), map(_map) {}
|
deba@2116
|
1192 |
|
deba@2116
|
1193 |
typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
|
deba@2116
|
1194 |
return map[*this];
|
deba@2116
|
1195 |
}
|
deba@2116
|
1196 |
|
deba@2116
|
1197 |
typename MapTraits<NodeMap>::ReturnValue operator*() {
|
deba@2116
|
1198 |
return map[*this];
|
deba@2116
|
1199 |
}
|
deba@2116
|
1200 |
|
deba@2116
|
1201 |
void set(const Value& value) {
|
deba@2116
|
1202 |
map.set(*this, value);
|
deba@2116
|
1203 |
}
|
deba@2116
|
1204 |
|
deba@2116
|
1205 |
private:
|
deba@2116
|
1206 |
NodeMap& map;
|
deba@2116
|
1207 |
};
|
deba@2116
|
1208 |
|
deba@2116
|
1209 |
class ConstMapIt : public NodeIt {
|
deba@2116
|
1210 |
public:
|
deba@2116
|
1211 |
|
deba@2116
|
1212 |
typedef NodeIt Parent;
|
deba@2116
|
1213 |
|
deba@2116
|
1214 |
explicit ConstMapIt(const NodeMap& _map)
|
deba@2116
|
1215 |
: Parent(_map.graph), map(_map) {}
|
deba@2116
|
1216 |
|
deba@2116
|
1217 |
typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
|
deba@2116
|
1218 |
return map[*this];
|
deba@2116
|
1219 |
}
|
deba@2116
|
1220 |
|
deba@2116
|
1221 |
private:
|
deba@2116
|
1222 |
const NodeMap& map;
|
deba@2116
|
1223 |
};
|
deba@2116
|
1224 |
|
deba@2116
|
1225 |
class ItemIt : public NodeIt {
|
deba@2116
|
1226 |
public:
|
deba@2116
|
1227 |
|
deba@2116
|
1228 |
typedef NodeIt Parent;
|
deba@2116
|
1229 |
|
deba@2116
|
1230 |
explicit ItemIt(const NodeMap& _map)
|
deba@2116
|
1231 |
: Parent(_map.graph) {}
|
deba@2116
|
1232 |
|
deba@2116
|
1233 |
};
|
deba@2116
|
1234 |
|
deba@2116
|
1235 |
private:
|
deba@2116
|
1236 |
const Graph& graph;
|
deba@2116
|
1237 |
ANodeMap<_Value> aNodeMap;
|
deba@2116
|
1238 |
BNodeMap<_Value> bNodeMap;
|
deba@2116
|
1239 |
};
|
deba@2116
|
1240 |
|
deba@2116
|
1241 |
|
deba@2116
|
1242 |
template <typename _Value>
|
deba@2116
|
1243 |
class EdgeMap
|
deba@2116
|
1244 |
: public MapExtender<DefaultMap<Graph, Edge, _Value> > {
|
deba@2116
|
1245 |
public:
|
deba@2116
|
1246 |
typedef BpUGraphExtender Graph;
|
deba@2116
|
1247 |
typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
|
deba@2116
|
1248 |
|
deba@2116
|
1249 |
EdgeMap(const Graph& graph)
|
deba@2116
|
1250 |
: Parent(graph) {}
|
deba@2116
|
1251 |
EdgeMap(const Graph& graph, const _Value& value)
|
deba@2116
|
1252 |
: Parent(graph, value) {}
|
deba@2116
|
1253 |
|
deba@2116
|
1254 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@2116
|
1255 |
return operator=<EdgeMap>(cmap);
|
deba@2116
|
1256 |
}
|
deba@2116
|
1257 |
|
deba@2116
|
1258 |
template <typename CMap>
|
deba@2116
|
1259 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@2116
|
1260 |
Parent::operator=(cmap);
|
deba@2116
|
1261 |
return *this;
|
deba@2116
|
1262 |
}
|
deba@2116
|
1263 |
};
|
deba@2116
|
1264 |
|
deba@2116
|
1265 |
template <typename _Value>
|
deba@2116
|
1266 |
class UEdgeMap
|
deba@2116
|
1267 |
: public MapExtender<DefaultMap<Graph, UEdge, _Value> > {
|
deba@2116
|
1268 |
public:
|
deba@2116
|
1269 |
typedef BpUGraphExtender Graph;
|
deba@2116
|
1270 |
typedef MapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
|
deba@2116
|
1271 |
|
deba@2116
|
1272 |
UEdgeMap(const Graph& graph)
|
deba@2116
|
1273 |
: Parent(graph) {}
|
deba@2116
|
1274 |
UEdgeMap(const Graph& graph, const _Value& value)
|
deba@2116
|
1275 |
: Parent(graph, value) {}
|
deba@2116
|
1276 |
|
deba@2116
|
1277 |
UEdgeMap& operator=(const UEdgeMap& cmap) {
|
deba@2116
|
1278 |
return operator=<UEdgeMap>(cmap);
|
deba@2116
|
1279 |
}
|
deba@2116
|
1280 |
|
deba@2116
|
1281 |
template <typename CMap>
|
deba@2116
|
1282 |
UEdgeMap& operator=(const CMap& cmap) {
|
deba@2116
|
1283 |
Parent::operator=(cmap);
|
deba@2116
|
1284 |
return *this;
|
deba@2116
|
1285 |
}
|
deba@2116
|
1286 |
};
|
deba@2116
|
1287 |
|
deba@2116
|
1288 |
|
deba@2116
|
1289 |
Node addANode() {
|
deba@2116
|
1290 |
Node node = Parent::addANode();
|
deba@2384
|
1291 |
notifier(ANode()).add(node);
|
deba@2384
|
1292 |
notifier(Node()).add(node);
|
deba@2116
|
1293 |
return node;
|
deba@2116
|
1294 |
}
|
deba@2116
|
1295 |
|
deba@2116
|
1296 |
Node addBNode() {
|
deba@2116
|
1297 |
Node node = Parent::addBNode();
|
deba@2384
|
1298 |
notifier(BNode()).add(node);
|
deba@2384
|
1299 |
notifier(Node()).add(node);
|
deba@2116
|
1300 |
return node;
|
deba@2116
|
1301 |
}
|
deba@2116
|
1302 |
|
deba@2386
|
1303 |
UEdge addEdge(const Node& s, const Node& t) {
|
deba@2386
|
1304 |
UEdge uedge = Parent::addEdge(s, t);
|
deba@2384
|
1305 |
notifier(UEdge()).add(uedge);
|
deba@2116
|
1306 |
|
deba@2386
|
1307 |
std::vector<Edge> ev;
|
deba@2386
|
1308 |
ev.push_back(Parent::direct(uedge, true));
|
deba@2386
|
1309 |
ev.push_back(Parent::direct(uedge, false));
|
deba@2386
|
1310 |
notifier(Edge()).add(ev);
|
deba@2116
|
1311 |
|
deba@2116
|
1312 |
return uedge;
|
deba@2116
|
1313 |
}
|
deba@2116
|
1314 |
|
deba@2116
|
1315 |
void clear() {
|
deba@2384
|
1316 |
notifier(Edge()).clear();
|
deba@2384
|
1317 |
notifier(UEdge()).clear();
|
deba@2384
|
1318 |
notifier(Node()).clear();
|
deba@2384
|
1319 |
notifier(BNode()).clear();
|
deba@2384
|
1320 |
notifier(ANode()).clear();
|
deba@2116
|
1321 |
Parent::clear();
|
deba@2116
|
1322 |
}
|
deba@2116
|
1323 |
|
deba@2290
|
1324 |
template <typename Graph, typename ANodeRefMap,
|
deba@2290
|
1325 |
typename BNodeRefMap, typename UEdgeRefMap>
|
deba@2329
|
1326 |
void build(const Graph& graph, ANodeRefMap& aNodeRef,
|
deba@2290
|
1327 |
BNodeRefMap& bNodeRef, UEdgeRefMap& uEdgeRef) {
|
deba@2329
|
1328 |
Parent::build(graph, aNodeRef, bNodeRef, uEdgeRef);
|
deba@2384
|
1329 |
notifier(ANode()).build();
|
deba@2384
|
1330 |
notifier(BNode()).build();
|
deba@2384
|
1331 |
notifier(Node()).build();
|
deba@2384
|
1332 |
notifier(UEdge()).build();
|
deba@2384
|
1333 |
notifier(Edge()).build();
|
deba@2290
|
1334 |
}
|
deba@2290
|
1335 |
|
deba@2116
|
1336 |
void erase(const Node& node) {
|
deba@2116
|
1337 |
UEdge uedge;
|
deba@2116
|
1338 |
if (Parent::aNode(node)) {
|
deba@2116
|
1339 |
Parent::firstFromANode(uedge, node);
|
deba@2116
|
1340 |
while (uedge != INVALID) {
|
deba@2116
|
1341 |
erase(uedge);
|
deba@2116
|
1342 |
Parent::firstFromANode(uedge, node);
|
deba@2116
|
1343 |
}
|
deba@2384
|
1344 |
notifier(ANode()).erase(node);
|
deba@2116
|
1345 |
} else {
|
deba@2116
|
1346 |
Parent::firstFromBNode(uedge, node);
|
deba@2116
|
1347 |
while (uedge != INVALID) {
|
deba@2116
|
1348 |
erase(uedge);
|
deba@2116
|
1349 |
Parent::firstFromBNode(uedge, node);
|
deba@2116
|
1350 |
}
|
deba@2384
|
1351 |
notifier(BNode()).erase(node);
|
deba@2116
|
1352 |
}
|
deba@2116
|
1353 |
|
deba@2384
|
1354 |
notifier(Node()).erase(node);
|
deba@2116
|
1355 |
Parent::erase(node);
|
deba@2116
|
1356 |
}
|
deba@2116
|
1357 |
|
deba@2116
|
1358 |
void erase(const UEdge& uedge) {
|
deba@2386
|
1359 |
std::vector<Edge> ev;
|
deba@2386
|
1360 |
ev.push_back(Parent::direct(uedge, true));
|
deba@2386
|
1361 |
ev.push_back(Parent::direct(uedge, false));
|
deba@2386
|
1362 |
notifier(Edge()).erase(ev);
|
deba@2384
|
1363 |
notifier(UEdge()).erase(uedge);
|
deba@2116
|
1364 |
Parent::erase(uedge);
|
deba@2116
|
1365 |
}
|
deba@2116
|
1366 |
|
deba@2116
|
1367 |
|
deba@2116
|
1368 |
BpUGraphExtender() {
|
deba@2116
|
1369 |
anode_notifier.setContainer(*this);
|
deba@2116
|
1370 |
bnode_notifier.setContainer(*this);
|
deba@2116
|
1371 |
node_notifier.setContainer(*this);
|
deba@2116
|
1372 |
edge_notifier.setContainer(*this);
|
deba@2116
|
1373 |
uedge_notifier.setContainer(*this);
|
deba@2116
|
1374 |
}
|
deba@2116
|
1375 |
|
deba@2116
|
1376 |
~BpUGraphExtender() {
|
deba@2116
|
1377 |
uedge_notifier.clear();
|
deba@2116
|
1378 |
edge_notifier.clear();
|
deba@2116
|
1379 |
node_notifier.clear();
|
deba@2116
|
1380 |
anode_notifier.clear();
|
deba@2116
|
1381 |
bnode_notifier.clear();
|
deba@2116
|
1382 |
}
|
deba@2116
|
1383 |
|
deba@2222
|
1384 |
Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
|
deba@2222
|
1385 |
UEdge uedge = Parent::findUEdge(u, v, prev);
|
deba@2222
|
1386 |
if (uedge != INVALID) {
|
deba@2231
|
1387 |
return Parent::direct(uedge, Parent::aNode(u));
|
deba@2222
|
1388 |
} else {
|
deba@2222
|
1389 |
return INVALID;
|
deba@2222
|
1390 |
}
|
deba@2222
|
1391 |
}
|
deba@2116
|
1392 |
|
deba@2116
|
1393 |
};
|
deba@2116
|
1394 |
|
deba@1791
|
1395 |
}
|
deba@1791
|
1396 |
|
deba@1996
|
1397 |
#endif
|