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@1956
|
5 |
* Copyright (C) 2003-2006
|
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@1791
|
19 |
#ifndef LEMON_GRAPH_EXTENDER_H
|
deba@1791
|
20 |
#define LEMON_GRAPH_EXTENDER_H
|
deba@1791
|
21 |
|
deba@1791
|
22 |
#include <lemon/invalid.h>
|
deba@1820
|
23 |
#include <lemon/error.h>
|
deba@1791
|
24 |
|
deba@1979
|
25 |
#include <lemon/bits/default_map.h>
|
deba@1979
|
26 |
|
deba@1791
|
27 |
namespace lemon {
|
deba@1791
|
28 |
|
deba@1979
|
29 |
template <typename Base>
|
deba@1979
|
30 |
class GraphExtender : public Base {
|
deba@1791
|
31 |
public:
|
deba@1791
|
32 |
|
deba@1979
|
33 |
typedef Base Parent;
|
deba@1791
|
34 |
typedef GraphExtender Graph;
|
deba@1791
|
35 |
|
deba@1979
|
36 |
// Base extensions
|
deba@1979
|
37 |
|
deba@1791
|
38 |
typedef typename Parent::Node Node;
|
deba@1791
|
39 |
typedef typename Parent::Edge Edge;
|
deba@1791
|
40 |
|
deba@1791
|
41 |
int maxId(Node) const {
|
deba@1791
|
42 |
return Parent::maxNodeId();
|
deba@1791
|
43 |
}
|
deba@1791
|
44 |
|
deba@1791
|
45 |
int maxId(Edge) const {
|
deba@1791
|
46 |
return Parent::maxEdgeId();
|
deba@1791
|
47 |
}
|
deba@1791
|
48 |
|
deba@1791
|
49 |
Node fromId(int id, Node) const {
|
deba@1791
|
50 |
return Parent::nodeFromId(id);
|
deba@1791
|
51 |
}
|
deba@1791
|
52 |
|
deba@1791
|
53 |
Edge fromId(int id, Edge) const {
|
deba@1791
|
54 |
return Parent::edgeFromId(id);
|
deba@1791
|
55 |
}
|
deba@1791
|
56 |
|
deba@1791
|
57 |
Node oppositeNode(const Node &n, const Edge &e) const {
|
deba@1791
|
58 |
if (n == Parent::source(e))
|
deba@1791
|
59 |
return Parent::target(e);
|
deba@1791
|
60 |
else if(n==Parent::target(e))
|
deba@1791
|
61 |
return Parent::source(e);
|
deba@1791
|
62 |
else
|
deba@1791
|
63 |
return INVALID;
|
deba@1791
|
64 |
}
|
deba@1791
|
65 |
|
deba@1979
|
66 |
// Alterable extension
|
deba@1791
|
67 |
|
deba@1979
|
68 |
typedef AlterationNotifier<Node> NodeNotifier;
|
deba@1979
|
69 |
typedef AlterationNotifier<Edge> EdgeNotifier;
|
deba@1979
|
70 |
|
deba@1979
|
71 |
|
deba@1979
|
72 |
protected:
|
deba@1979
|
73 |
|
deba@1979
|
74 |
mutable NodeNotifier node_notifier;
|
deba@1979
|
75 |
mutable EdgeNotifier edge_notifier;
|
deba@1791
|
76 |
|
deba@1791
|
77 |
public:
|
deba@1791
|
78 |
|
deba@1979
|
79 |
NodeNotifier& getNotifier(Node) const {
|
deba@1979
|
80 |
return node_notifier;
|
deba@1979
|
81 |
}
|
deba@1979
|
82 |
|
deba@1979
|
83 |
EdgeNotifier& getNotifier(Edge) const {
|
deba@1979
|
84 |
return edge_notifier;
|
deba@1979
|
85 |
}
|
deba@1979
|
86 |
|
deba@1979
|
87 |
class NodeIt : public Node {
|
deba@1979
|
88 |
const Graph* graph;
|
deba@1979
|
89 |
public:
|
deba@1979
|
90 |
|
deba@1979
|
91 |
NodeIt() {}
|
deba@1979
|
92 |
|
deba@1979
|
93 |
NodeIt(Invalid i) : Node(i) { }
|
deba@1979
|
94 |
|
deba@1979
|
95 |
explicit NodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@1979
|
96 |
_graph.first(*static_cast<Node*>(this));
|
deba@1979
|
97 |
}
|
deba@1979
|
98 |
|
deba@1979
|
99 |
NodeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
100 |
: Node(node), graph(&_graph) {}
|
deba@1979
|
101 |
|
deba@1979
|
102 |
NodeIt& operator++() {
|
deba@1979
|
103 |
graph->next(*this);
|
deba@1979
|
104 |
return *this;
|
deba@1979
|
105 |
}
|
deba@1979
|
106 |
|
deba@1979
|
107 |
};
|
deba@1979
|
108 |
|
deba@1979
|
109 |
|
deba@1979
|
110 |
class EdgeIt : public Edge {
|
deba@1979
|
111 |
const Graph* graph;
|
deba@1979
|
112 |
public:
|
deba@1979
|
113 |
|
deba@1979
|
114 |
EdgeIt() { }
|
deba@1979
|
115 |
|
deba@1979
|
116 |
EdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
117 |
|
deba@1979
|
118 |
explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
|
deba@1979
|
119 |
_graph.first(*static_cast<Edge*>(this));
|
deba@1979
|
120 |
}
|
deba@1979
|
121 |
|
deba@1979
|
122 |
EdgeIt(const Graph& _graph, const Edge& e) :
|
deba@1979
|
123 |
Edge(e), graph(&_graph) { }
|
deba@1979
|
124 |
|
deba@1979
|
125 |
EdgeIt& operator++() {
|
deba@1979
|
126 |
graph->next(*this);
|
deba@1979
|
127 |
return *this;
|
deba@1979
|
128 |
}
|
deba@1979
|
129 |
|
deba@1979
|
130 |
};
|
deba@1979
|
131 |
|
deba@1979
|
132 |
|
deba@1979
|
133 |
class OutEdgeIt : public Edge {
|
deba@1979
|
134 |
const Graph* graph;
|
deba@1979
|
135 |
public:
|
deba@1979
|
136 |
|
deba@1979
|
137 |
OutEdgeIt() { }
|
deba@1979
|
138 |
|
deba@1979
|
139 |
OutEdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
140 |
|
deba@1979
|
141 |
OutEdgeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
142 |
: graph(&_graph) {
|
deba@1979
|
143 |
_graph.firstOut(*this, node);
|
deba@1979
|
144 |
}
|
deba@1979
|
145 |
|
deba@1979
|
146 |
OutEdgeIt(const Graph& _graph, const Edge& edge)
|
deba@1979
|
147 |
: Edge(edge), graph(&_graph) {}
|
deba@1979
|
148 |
|
deba@1979
|
149 |
OutEdgeIt& operator++() {
|
deba@1979
|
150 |
graph->nextOut(*this);
|
deba@1979
|
151 |
return *this;
|
deba@1979
|
152 |
}
|
deba@1979
|
153 |
|
deba@1979
|
154 |
};
|
deba@1979
|
155 |
|
deba@1979
|
156 |
|
deba@1979
|
157 |
class InEdgeIt : public Edge {
|
deba@1979
|
158 |
const Graph* graph;
|
deba@1979
|
159 |
public:
|
deba@1979
|
160 |
|
deba@1979
|
161 |
InEdgeIt() { }
|
deba@1979
|
162 |
|
deba@1979
|
163 |
InEdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
164 |
|
deba@1979
|
165 |
InEdgeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
166 |
: graph(&_graph) {
|
deba@1979
|
167 |
_graph.firstIn(*this, node);
|
deba@1979
|
168 |
}
|
deba@1979
|
169 |
|
deba@1979
|
170 |
InEdgeIt(const Graph& _graph, const Edge& edge) :
|
deba@1979
|
171 |
Edge(edge), graph(&_graph) {}
|
deba@1979
|
172 |
|
deba@1979
|
173 |
InEdgeIt& operator++() {
|
deba@1979
|
174 |
graph->nextIn(*this);
|
deba@1979
|
175 |
return *this;
|
deba@1979
|
176 |
}
|
deba@1979
|
177 |
|
deba@1979
|
178 |
};
|
deba@1979
|
179 |
|
deba@1979
|
180 |
/// \brief Base node of the iterator
|
deba@1979
|
181 |
///
|
deba@1979
|
182 |
/// Returns the base node (ie. the source in this case) of the iterator
|
deba@1979
|
183 |
Node baseNode(const OutEdgeIt &e) const {
|
deba@1979
|
184 |
return Parent::source(e);
|
deba@1979
|
185 |
}
|
deba@1979
|
186 |
/// \brief Running node of the iterator
|
deba@1979
|
187 |
///
|
deba@1979
|
188 |
/// Returns the running node (ie. the target in this case) of the
|
deba@1979
|
189 |
/// iterator
|
deba@1979
|
190 |
Node runningNode(const OutEdgeIt &e) const {
|
deba@1979
|
191 |
return Parent::target(e);
|
deba@1979
|
192 |
}
|
deba@1979
|
193 |
|
deba@1979
|
194 |
/// \brief Base node of the iterator
|
deba@1979
|
195 |
///
|
deba@1979
|
196 |
/// Returns the base node (ie. the target in this case) of the iterator
|
deba@1979
|
197 |
Node baseNode(const InEdgeIt &e) const {
|
deba@1979
|
198 |
return Parent::target(e);
|
deba@1979
|
199 |
}
|
deba@1979
|
200 |
/// \brief Running node of the iterator
|
deba@1979
|
201 |
///
|
deba@1979
|
202 |
/// Returns the running node (ie. the source in this case) of the
|
deba@1979
|
203 |
/// iterator
|
deba@1979
|
204 |
Node runningNode(const InEdgeIt &e) const {
|
deba@1979
|
205 |
return Parent::source(e);
|
deba@1979
|
206 |
}
|
deba@1979
|
207 |
|
deba@1979
|
208 |
|
deba@1979
|
209 |
template <typename _Value>
|
deba@1979
|
210 |
class NodeMap
|
deba@1979
|
211 |
: public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
|
deba@1979
|
212 |
public:
|
deba@1979
|
213 |
typedef GraphExtender Graph;
|
deba@1979
|
214 |
typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
|
deba@1979
|
215 |
|
deba@1979
|
216 |
NodeMap(const Graph& _g)
|
deba@1979
|
217 |
: Parent(_g) {}
|
deba@1979
|
218 |
NodeMap(const Graph& _g, const _Value& _v)
|
deba@1979
|
219 |
: Parent(_g, _v) {}
|
deba@1979
|
220 |
|
deba@1979
|
221 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@1979
|
222 |
return operator=<NodeMap>(cmap);
|
deba@1979
|
223 |
}
|
deba@1979
|
224 |
|
deba@1979
|
225 |
|
deba@1979
|
226 |
/// \brief Template assign operator.
|
deba@1979
|
227 |
///
|
deba@1979
|
228 |
/// The given parameter should be conform to the ReadMap
|
deba@1979
|
229 |
/// concecpt and could be indiced by the current item set of
|
deba@1979
|
230 |
/// the NodeMap. In this case the value for each item
|
deba@1979
|
231 |
/// is assigned by the value of the given ReadMap.
|
deba@1979
|
232 |
template <typename CMap>
|
deba@1979
|
233 |
NodeMap& operator=(const CMap& cmap) {
|
deba@1979
|
234 |
checkConcept<concept::ReadMap<Node, _Value>, CMap>();
|
deba@1979
|
235 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1979
|
236 |
Node it;
|
deba@1979
|
237 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1979
|
238 |
Parent::set(it, cmap[it]);
|
deba@1979
|
239 |
}
|
deba@1979
|
240 |
return *this;
|
deba@1979
|
241 |
}
|
deba@1979
|
242 |
|
deba@1979
|
243 |
};
|
deba@1979
|
244 |
|
deba@1979
|
245 |
template <typename _Value>
|
deba@1979
|
246 |
class EdgeMap
|
deba@1979
|
247 |
: public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
|
deba@1979
|
248 |
public:
|
deba@1979
|
249 |
typedef GraphExtender Graph;
|
deba@1979
|
250 |
typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
|
deba@1979
|
251 |
|
deba@1979
|
252 |
EdgeMap(const Graph& _g)
|
deba@1979
|
253 |
: Parent(_g) {}
|
deba@1979
|
254 |
EdgeMap(const Graph& _g, const _Value& _v)
|
deba@1979
|
255 |
: Parent(_g, _v) {}
|
deba@1979
|
256 |
|
deba@1979
|
257 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@1979
|
258 |
return operator=<EdgeMap>(cmap);
|
deba@1979
|
259 |
}
|
deba@1979
|
260 |
|
deba@1979
|
261 |
template <typename CMap>
|
deba@1979
|
262 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@1979
|
263 |
checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
|
deba@1979
|
264 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1979
|
265 |
Edge it;
|
deba@1979
|
266 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1979
|
267 |
Parent::set(it, cmap[it]);
|
deba@1979
|
268 |
}
|
deba@1979
|
269 |
return *this;
|
deba@1979
|
270 |
}
|
deba@1979
|
271 |
};
|
deba@1979
|
272 |
|
deba@1979
|
273 |
|
deba@1979
|
274 |
Node addNode() {
|
deba@1979
|
275 |
Node node = Parent::addNode();
|
deba@1979
|
276 |
getNotifier(Node()).add(node);
|
deba@1979
|
277 |
return node;
|
deba@1979
|
278 |
}
|
deba@1979
|
279 |
|
deba@1979
|
280 |
Edge addEdge(const Node& from, const Node& to) {
|
deba@1979
|
281 |
Edge edge = Parent::addEdge(from, to);
|
deba@1979
|
282 |
getNotifier(Edge()).add(edge);
|
deba@1979
|
283 |
return edge;
|
deba@1979
|
284 |
}
|
deba@1979
|
285 |
|
deba@1979
|
286 |
void clear() {
|
deba@1979
|
287 |
getNotifier(Edge()).clear();
|
deba@1979
|
288 |
getNotifier(Node()).clear();
|
deba@1979
|
289 |
Parent::clear();
|
deba@1979
|
290 |
}
|
deba@1979
|
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@1979
|
307 |
getNotifier(Node()).erase(node);
|
deba@1979
|
308 |
Parent::erase(node);
|
deba@1979
|
309 |
}
|
deba@1979
|
310 |
|
deba@1979
|
311 |
void erase(const Edge& edge) {
|
deba@1979
|
312 |
getNotifier(Edge()).erase(edge);
|
deba@1979
|
313 |
Parent::erase(edge);
|
deba@1979
|
314 |
}
|
deba@1979
|
315 |
|
deba@1979
|
316 |
|
deba@1979
|
317 |
~GraphExtender() {
|
deba@1979
|
318 |
getNotifier(Edge()).clear();
|
deba@1979
|
319 |
getNotifier(Node()).clear();
|
deba@1979
|
320 |
}
|
deba@1979
|
321 |
};
|
deba@1979
|
322 |
|
deba@1979
|
323 |
template <typename Base>
|
deba@1979
|
324 |
class UGraphBaseExtender : public Base {
|
deba@1979
|
325 |
|
deba@1979
|
326 |
public:
|
deba@1979
|
327 |
|
deba@1979
|
328 |
typedef Base Parent;
|
klao@1909
|
329 |
typedef typename Parent::Edge UEdge;
|
deba@1791
|
330 |
typedef typename Parent::Node Node;
|
deba@1791
|
331 |
|
deba@1979
|
332 |
typedef True UndirectedTag;
|
deba@1979
|
333 |
|
klao@1909
|
334 |
class Edge : public UEdge {
|
deba@1979
|
335 |
friend class UGraphBaseExtender;
|
deba@1791
|
336 |
|
deba@1791
|
337 |
protected:
|
deba@1791
|
338 |
bool forward;
|
deba@1791
|
339 |
|
klao@1909
|
340 |
Edge(const UEdge &ue, bool _forward) :
|
klao@1909
|
341 |
UEdge(ue), forward(_forward) {}
|
deba@1791
|
342 |
|
deba@1791
|
343 |
public:
|
deba@1791
|
344 |
Edge() {}
|
deba@1791
|
345 |
|
deba@1791
|
346 |
/// Invalid edge constructor
|
klao@1909
|
347 |
Edge(Invalid i) : UEdge(i), forward(true) {}
|
deba@1791
|
348 |
|
deba@1791
|
349 |
bool operator==(const Edge &that) const {
|
klao@1909
|
350 |
return forward==that.forward && UEdge(*this)==UEdge(that);
|
deba@1791
|
351 |
}
|
deba@1791
|
352 |
bool operator!=(const Edge &that) const {
|
klao@1909
|
353 |
return forward!=that.forward || UEdge(*this)!=UEdge(that);
|
deba@1791
|
354 |
}
|
deba@1791
|
355 |
bool operator<(const Edge &that) const {
|
deba@1791
|
356 |
return forward<that.forward ||
|
klao@1909
|
357 |
(!(that.forward<forward) && UEdge(*this)<UEdge(that));
|
deba@1791
|
358 |
}
|
deba@1791
|
359 |
};
|
deba@1791
|
360 |
|
deba@1791
|
361 |
|
deba@1791
|
362 |
|
deba@1791
|
363 |
using Parent::source;
|
deba@1791
|
364 |
|
deba@1791
|
365 |
/// Source of the given Edge.
|
deba@1791
|
366 |
Node source(const Edge &e) const {
|
deba@1791
|
367 |
return e.forward ? Parent::source(e) : Parent::target(e);
|
deba@1791
|
368 |
}
|
deba@1791
|
369 |
|
deba@1791
|
370 |
using Parent::target;
|
deba@1791
|
371 |
|
deba@1791
|
372 |
/// Target of the given Edge.
|
deba@1791
|
373 |
Node target(const Edge &e) const {
|
deba@1791
|
374 |
return e.forward ? Parent::target(e) : Parent::source(e);
|
deba@1791
|
375 |
}
|
deba@1791
|
376 |
|
deba@1791
|
377 |
/// \brief Directed edge from an undirected edge.
|
deba@1791
|
378 |
///
|
klao@1909
|
379 |
/// Returns a directed edge corresponding to the specified UEdge.
|
deba@1791
|
380 |
/// If the given bool is true the given undirected edge and the
|
deba@1791
|
381 |
/// returned edge have the same source node.
|
deba@1981
|
382 |
static Edge direct(const UEdge &ue, bool d) {
|
deba@1791
|
383 |
return Edge(ue, d);
|
deba@1791
|
384 |
}
|
deba@1791
|
385 |
|
deba@1791
|
386 |
/// Returns whether the given directed edge is same orientation as the
|
deba@1791
|
387 |
/// corresponding undirected edge.
|
deba@1791
|
388 |
///
|
deba@1791
|
389 |
/// \todo reference to the corresponding point of the undirected graph
|
deba@1791
|
390 |
/// concept. "What does the direction of an undirected edge mean?"
|
deba@1981
|
391 |
static bool direction(const Edge &e) { return e.forward; }
|
deba@1791
|
392 |
|
deba@1791
|
393 |
|
deba@1791
|
394 |
using Parent::first;
|
deba@1979
|
395 |
using Parent::next;
|
deba@1979
|
396 |
|
deba@1791
|
397 |
void first(Edge &e) const {
|
deba@1791
|
398 |
Parent::first(e);
|
deba@1791
|
399 |
e.forward=true;
|
deba@1791
|
400 |
}
|
deba@1791
|
401 |
|
deba@1791
|
402 |
void next(Edge &e) const {
|
deba@1791
|
403 |
if( e.forward ) {
|
deba@1791
|
404 |
e.forward = false;
|
deba@1791
|
405 |
}
|
deba@1791
|
406 |
else {
|
deba@1791
|
407 |
Parent::next(e);
|
deba@1791
|
408 |
e.forward = true;
|
deba@1791
|
409 |
}
|
deba@1791
|
410 |
}
|
deba@1791
|
411 |
|
deba@1791
|
412 |
void firstOut(Edge &e, const Node &n) const {
|
deba@1791
|
413 |
Parent::firstIn(e,n);
|
klao@1909
|
414 |
if( UEdge(e) != INVALID ) {
|
deba@1791
|
415 |
e.forward = false;
|
deba@1791
|
416 |
}
|
deba@1791
|
417 |
else {
|
deba@1791
|
418 |
Parent::firstOut(e,n);
|
deba@1791
|
419 |
e.forward = true;
|
deba@1791
|
420 |
}
|
deba@1791
|
421 |
}
|
deba@1791
|
422 |
void nextOut(Edge &e) const {
|
deba@1791
|
423 |
if( ! e.forward ) {
|
deba@1791
|
424 |
Node n = Parent::target(e);
|
deba@1791
|
425 |
Parent::nextIn(e);
|
klao@1909
|
426 |
if( UEdge(e) == INVALID ) {
|
deba@1791
|
427 |
Parent::firstOut(e, n);
|
deba@1791
|
428 |
e.forward = true;
|
deba@1791
|
429 |
}
|
deba@1791
|
430 |
}
|
deba@1791
|
431 |
else {
|
deba@1791
|
432 |
Parent::nextOut(e);
|
deba@1791
|
433 |
}
|
deba@1791
|
434 |
}
|
deba@1791
|
435 |
|
deba@1791
|
436 |
void firstIn(Edge &e, const Node &n) const {
|
deba@1791
|
437 |
Parent::firstOut(e,n);
|
klao@1909
|
438 |
if( UEdge(e) != INVALID ) {
|
deba@1791
|
439 |
e.forward = false;
|
deba@1791
|
440 |
}
|
deba@1791
|
441 |
else {
|
deba@1791
|
442 |
Parent::firstIn(e,n);
|
deba@1791
|
443 |
e.forward = true;
|
deba@1791
|
444 |
}
|
deba@1791
|
445 |
}
|
deba@1791
|
446 |
void nextIn(Edge &e) const {
|
deba@1791
|
447 |
if( ! e.forward ) {
|
deba@1791
|
448 |
Node n = Parent::source(e);
|
deba@1791
|
449 |
Parent::nextOut(e);
|
klao@1909
|
450 |
if( UEdge(e) == INVALID ) {
|
deba@1791
|
451 |
Parent::firstIn(e, n);
|
deba@1791
|
452 |
e.forward = true;
|
deba@1791
|
453 |
}
|
deba@1791
|
454 |
}
|
deba@1791
|
455 |
else {
|
deba@1791
|
456 |
Parent::nextIn(e);
|
deba@1791
|
457 |
}
|
deba@1791
|
458 |
}
|
deba@1791
|
459 |
|
klao@1909
|
460 |
void firstInc(UEdge &e, bool &d, const Node &n) const {
|
deba@1791
|
461 |
d = true;
|
deba@1791
|
462 |
Parent::firstOut(e, n);
|
deba@1791
|
463 |
if (e != INVALID) return;
|
deba@1791
|
464 |
d = false;
|
deba@1791
|
465 |
Parent::firstIn(e, n);
|
deba@1791
|
466 |
}
|
deba@1979
|
467 |
|
klao@1909
|
468 |
void nextInc(UEdge &e, bool &d) const {
|
deba@1791
|
469 |
if (d) {
|
deba@1791
|
470 |
Node s = Parent::source(e);
|
deba@1791
|
471 |
Parent::nextOut(e);
|
deba@1791
|
472 |
if (e != INVALID) return;
|
deba@1791
|
473 |
d = false;
|
deba@1791
|
474 |
Parent::firstIn(e, s);
|
deba@1791
|
475 |
} else {
|
deba@1791
|
476 |
Parent::nextIn(e);
|
deba@1791
|
477 |
}
|
deba@1791
|
478 |
}
|
deba@1791
|
479 |
|
deba@1979
|
480 |
Node nodeFromId(int id) const {
|
deba@1979
|
481 |
return Parent::nodeFromId(id);
|
deba@1979
|
482 |
}
|
deba@1791
|
483 |
|
deba@1979
|
484 |
Edge edgeFromId(int id) const {
|
deba@1979
|
485 |
return direct(Parent::edgeFromId(id >> 1), bool(id & 1));
|
deba@1979
|
486 |
}
|
deba@1791
|
487 |
|
deba@1979
|
488 |
UEdge uEdgeFromId(int id) const {
|
deba@1979
|
489 |
return Parent::edgeFromId(id >> 1);
|
deba@1979
|
490 |
}
|
deba@1791
|
491 |
|
deba@1791
|
492 |
int id(const Node &n) const {
|
deba@1791
|
493 |
return Parent::id(n);
|
deba@1791
|
494 |
}
|
deba@1791
|
495 |
|
klao@1909
|
496 |
int id(const UEdge &e) const {
|
deba@1791
|
497 |
return Parent::id(e);
|
deba@1791
|
498 |
}
|
deba@1791
|
499 |
|
deba@1791
|
500 |
int id(const Edge &e) const {
|
deba@1791
|
501 |
return 2 * Parent::id(e) + int(e.forward);
|
deba@1791
|
502 |
}
|
deba@1791
|
503 |
|
deba@1791
|
504 |
int maxNodeId() const {
|
deba@1791
|
505 |
return Parent::maxNodeId();
|
deba@1791
|
506 |
}
|
deba@1791
|
507 |
|
deba@1791
|
508 |
int maxEdgeId() const {
|
deba@1791
|
509 |
return 2 * Parent::maxEdgeId() + 1;
|
deba@1791
|
510 |
}
|
deba@1791
|
511 |
|
klao@1909
|
512 |
int maxUEdgeId() const {
|
deba@1791
|
513 |
return Parent::maxEdgeId();
|
deba@1791
|
514 |
}
|
deba@1791
|
515 |
|
deba@1791
|
516 |
|
deba@1791
|
517 |
int edgeNum() const {
|
deba@1791
|
518 |
return 2 * Parent::edgeNum();
|
deba@1791
|
519 |
}
|
deba@1791
|
520 |
|
klao@1909
|
521 |
int uEdgeNum() const {
|
deba@1791
|
522 |
return Parent::edgeNum();
|
deba@1791
|
523 |
}
|
deba@1791
|
524 |
|
deba@1791
|
525 |
Edge findEdge(Node source, Node target, Edge prev) const {
|
deba@1791
|
526 |
if (prev == INVALID) {
|
klao@1909
|
527 |
UEdge edge = Parent::findEdge(source, target);
|
deba@1791
|
528 |
if (edge != INVALID) return direct(edge, true);
|
deba@1791
|
529 |
edge = Parent::findEdge(target, source);
|
deba@1791
|
530 |
if (edge != INVALID) return direct(edge, false);
|
deba@1791
|
531 |
} else if (direction(prev)) {
|
klao@1909
|
532 |
UEdge edge = Parent::findEdge(source, target, prev);
|
deba@1791
|
533 |
if (edge != INVALID) return direct(edge, true);
|
deba@1791
|
534 |
edge = Parent::findEdge(target, source);
|
deba@1791
|
535 |
if (edge != INVALID) return direct(edge, false);
|
deba@1791
|
536 |
} else {
|
klao@1909
|
537 |
UEdge edge = Parent::findEdge(target, source, prev);
|
deba@1791
|
538 |
if (edge != INVALID) return direct(edge, false);
|
deba@1791
|
539 |
}
|
deba@1791
|
540 |
return INVALID;
|
deba@1791
|
541 |
}
|
deba@1791
|
542 |
|
klao@1909
|
543 |
UEdge findUEdge(Node source, Node target, UEdge prev) const {
|
deba@1791
|
544 |
if (prev == INVALID) {
|
klao@1909
|
545 |
UEdge edge = Parent::findEdge(source, target);
|
deba@1791
|
546 |
if (edge != INVALID) return edge;
|
deba@1791
|
547 |
edge = Parent::findEdge(target, source);
|
deba@1791
|
548 |
if (edge != INVALID) return edge;
|
deba@1791
|
549 |
} else if (Parent::source(prev) == source) {
|
klao@1909
|
550 |
UEdge edge = Parent::findEdge(source, target, prev);
|
deba@1791
|
551 |
if (edge != INVALID) return edge;
|
deba@1791
|
552 |
edge = Parent::findEdge(target, source);
|
deba@1791
|
553 |
if (edge != INVALID) return edge;
|
deba@1791
|
554 |
} else {
|
klao@1909
|
555 |
UEdge edge = Parent::findEdge(target, source, prev);
|
deba@1791
|
556 |
if (edge != INVALID) return edge;
|
deba@1791
|
557 |
}
|
deba@1791
|
558 |
return INVALID;
|
deba@1791
|
559 |
}
|
deba@1979
|
560 |
};
|
deba@1979
|
561 |
|
deba@1979
|
562 |
|
deba@1979
|
563 |
template <typename Base>
|
deba@1979
|
564 |
class UGraphExtender : public Base {
|
deba@1979
|
565 |
public:
|
deba@1979
|
566 |
|
deba@1979
|
567 |
typedef Base Parent;
|
deba@1979
|
568 |
typedef UGraphExtender Graph;
|
deba@1979
|
569 |
|
deba@1979
|
570 |
typedef typename Parent::Node Node;
|
deba@1979
|
571 |
typedef typename Parent::Edge Edge;
|
deba@1979
|
572 |
typedef typename Parent::UEdge UEdge;
|
deba@1979
|
573 |
|
deba@1979
|
574 |
// UGraph extension
|
deba@1979
|
575 |
|
deba@1979
|
576 |
int maxId(Node) const {
|
deba@1979
|
577 |
return Parent::maxNodeId();
|
deba@1979
|
578 |
}
|
deba@1979
|
579 |
|
deba@1979
|
580 |
int maxId(Edge) const {
|
deba@1979
|
581 |
return Parent::maxEdgeId();
|
deba@1979
|
582 |
}
|
deba@1979
|
583 |
|
deba@1979
|
584 |
int maxId(UEdge) const {
|
deba@1979
|
585 |
return Parent::maxUEdgeId();
|
deba@1979
|
586 |
}
|
deba@1979
|
587 |
|
deba@1979
|
588 |
Node fromId(int id, Node) const {
|
deba@1979
|
589 |
return Parent::nodeFromId(id);
|
deba@1979
|
590 |
}
|
deba@1979
|
591 |
|
deba@1979
|
592 |
Edge fromId(int id, Edge) const {
|
deba@1979
|
593 |
return Parent::edgeFromId(id);
|
deba@1979
|
594 |
}
|
deba@1979
|
595 |
|
deba@1979
|
596 |
UEdge fromId(int id, UEdge) const {
|
deba@1979
|
597 |
return Parent::uEdgeFromId(id);
|
deba@1979
|
598 |
}
|
deba@1979
|
599 |
|
deba@1979
|
600 |
Node oppositeNode(const Node &n, const UEdge &e) const {
|
deba@1979
|
601 |
if( n == Parent::source(e))
|
deba@1979
|
602 |
return Parent::target(e);
|
deba@1979
|
603 |
else if( n == Parent::target(e))
|
deba@1979
|
604 |
return Parent::source(e);
|
deba@1979
|
605 |
else
|
deba@1979
|
606 |
return INVALID;
|
deba@1979
|
607 |
}
|
deba@1979
|
608 |
|
deba@1979
|
609 |
Edge oppositeEdge(const Edge &e) const {
|
deba@1979
|
610 |
return Parent::direct(e, !Parent::direction(e));
|
deba@1979
|
611 |
}
|
deba@1979
|
612 |
|
deba@1979
|
613 |
using Parent::direct;
|
deba@1979
|
614 |
Edge direct(const UEdge &ue, const Node &s) const {
|
deba@1979
|
615 |
return Parent::direct(ue, Parent::source(ue) == s);
|
deba@1979
|
616 |
}
|
deba@1979
|
617 |
|
deba@1979
|
618 |
// Alterable extension
|
deba@1979
|
619 |
|
deba@1979
|
620 |
typedef AlterationNotifier<Node> NodeNotifier;
|
deba@1979
|
621 |
typedef AlterationNotifier<Edge> EdgeNotifier;
|
deba@1979
|
622 |
typedef AlterationNotifier<UEdge> UEdgeNotifier;
|
deba@1979
|
623 |
|
deba@1979
|
624 |
|
deba@1979
|
625 |
protected:
|
deba@1979
|
626 |
|
deba@1979
|
627 |
mutable NodeNotifier node_notifier;
|
deba@1979
|
628 |
mutable EdgeNotifier edge_notifier;
|
deba@1979
|
629 |
mutable UEdgeNotifier uedge_notifier;
|
deba@1979
|
630 |
|
deba@1979
|
631 |
public:
|
deba@1979
|
632 |
|
deba@1979
|
633 |
NodeNotifier& getNotifier(Node) const {
|
deba@1979
|
634 |
return node_notifier;
|
deba@1979
|
635 |
}
|
deba@1979
|
636 |
|
deba@1979
|
637 |
EdgeNotifier& getNotifier(Edge) const {
|
deba@1979
|
638 |
return edge_notifier;
|
deba@1979
|
639 |
}
|
deba@1979
|
640 |
|
deba@1979
|
641 |
UEdgeNotifier& getNotifier(UEdge) const {
|
deba@1979
|
642 |
return uedge_notifier;
|
deba@1979
|
643 |
}
|
deba@1979
|
644 |
|
deba@1979
|
645 |
|
deba@1979
|
646 |
|
deba@1979
|
647 |
class NodeIt : public Node {
|
deba@1979
|
648 |
const Graph* graph;
|
deba@1979
|
649 |
public:
|
deba@1979
|
650 |
|
deba@1979
|
651 |
NodeIt() {}
|
deba@1979
|
652 |
|
deba@1979
|
653 |
NodeIt(Invalid i) : Node(i) { }
|
deba@1979
|
654 |
|
deba@1979
|
655 |
explicit NodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@1979
|
656 |
_graph.first(*static_cast<Node*>(this));
|
deba@1979
|
657 |
}
|
deba@1979
|
658 |
|
deba@1979
|
659 |
NodeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
660 |
: Node(node), graph(&_graph) {}
|
deba@1979
|
661 |
|
deba@1979
|
662 |
NodeIt& operator++() {
|
deba@1979
|
663 |
graph->next(*this);
|
deba@1979
|
664 |
return *this;
|
deba@1979
|
665 |
}
|
deba@1979
|
666 |
|
deba@1979
|
667 |
};
|
deba@1979
|
668 |
|
deba@1979
|
669 |
|
deba@1979
|
670 |
class EdgeIt : public Edge {
|
deba@1979
|
671 |
const Graph* graph;
|
deba@1979
|
672 |
public:
|
deba@1979
|
673 |
|
deba@1979
|
674 |
EdgeIt() { }
|
deba@1979
|
675 |
|
deba@1979
|
676 |
EdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
677 |
|
deba@1979
|
678 |
explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
|
deba@1979
|
679 |
_graph.first(*static_cast<Edge*>(this));
|
deba@1979
|
680 |
}
|
deba@1979
|
681 |
|
deba@1979
|
682 |
EdgeIt(const Graph& _graph, const Edge& e) :
|
deba@1979
|
683 |
Edge(e), graph(&_graph) { }
|
deba@1979
|
684 |
|
deba@1979
|
685 |
EdgeIt& operator++() {
|
deba@1979
|
686 |
graph->next(*this);
|
deba@1979
|
687 |
return *this;
|
deba@1979
|
688 |
}
|
deba@1979
|
689 |
|
deba@1979
|
690 |
};
|
deba@1979
|
691 |
|
deba@1979
|
692 |
|
deba@1979
|
693 |
class OutEdgeIt : public Edge {
|
deba@1979
|
694 |
const Graph* graph;
|
deba@1979
|
695 |
public:
|
deba@1979
|
696 |
|
deba@1979
|
697 |
OutEdgeIt() { }
|
deba@1979
|
698 |
|
deba@1979
|
699 |
OutEdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
700 |
|
deba@1979
|
701 |
OutEdgeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
702 |
: graph(&_graph) {
|
deba@1979
|
703 |
_graph.firstOut(*this, node);
|
deba@1979
|
704 |
}
|
deba@1979
|
705 |
|
deba@1979
|
706 |
OutEdgeIt(const Graph& _graph, const Edge& edge)
|
deba@1979
|
707 |
: Edge(edge), graph(&_graph) {}
|
deba@1979
|
708 |
|
deba@1979
|
709 |
OutEdgeIt& operator++() {
|
deba@1979
|
710 |
graph->nextOut(*this);
|
deba@1979
|
711 |
return *this;
|
deba@1979
|
712 |
}
|
deba@1979
|
713 |
|
deba@1979
|
714 |
};
|
deba@1979
|
715 |
|
deba@1979
|
716 |
|
deba@1979
|
717 |
class InEdgeIt : public Edge {
|
deba@1979
|
718 |
const Graph* graph;
|
deba@1979
|
719 |
public:
|
deba@1979
|
720 |
|
deba@1979
|
721 |
InEdgeIt() { }
|
deba@1979
|
722 |
|
deba@1979
|
723 |
InEdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
724 |
|
deba@1979
|
725 |
InEdgeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
726 |
: graph(&_graph) {
|
deba@1979
|
727 |
_graph.firstIn(*this, node);
|
deba@1979
|
728 |
}
|
deba@1979
|
729 |
|
deba@1979
|
730 |
InEdgeIt(const Graph& _graph, const Edge& edge) :
|
deba@1979
|
731 |
Edge(edge), graph(&_graph) {}
|
deba@1979
|
732 |
|
deba@1979
|
733 |
InEdgeIt& operator++() {
|
deba@1979
|
734 |
graph->nextIn(*this);
|
deba@1979
|
735 |
return *this;
|
deba@1979
|
736 |
}
|
deba@1979
|
737 |
|
deba@1979
|
738 |
};
|
deba@1979
|
739 |
|
deba@1979
|
740 |
|
deba@1979
|
741 |
class UEdgeIt : public Parent::UEdge {
|
deba@1979
|
742 |
const Graph* graph;
|
deba@1979
|
743 |
public:
|
deba@1979
|
744 |
|
deba@1979
|
745 |
UEdgeIt() { }
|
deba@1979
|
746 |
|
deba@1979
|
747 |
UEdgeIt(Invalid i) : UEdge(i) { }
|
deba@1979
|
748 |
|
deba@1979
|
749 |
explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
|
deba@1979
|
750 |
_graph.first(*static_cast<UEdge*>(this));
|
deba@1979
|
751 |
}
|
deba@1979
|
752 |
|
deba@1979
|
753 |
UEdgeIt(const Graph& _graph, const UEdge& e) :
|
deba@1979
|
754 |
UEdge(e), graph(&_graph) { }
|
deba@1979
|
755 |
|
deba@1979
|
756 |
UEdgeIt& operator++() {
|
deba@1979
|
757 |
graph->next(*this);
|
deba@1979
|
758 |
return *this;
|
deba@1979
|
759 |
}
|
deba@1979
|
760 |
|
deba@1979
|
761 |
};
|
deba@1979
|
762 |
|
deba@1979
|
763 |
class IncEdgeIt : public Parent::UEdge {
|
deba@1979
|
764 |
friend class UGraphExtender;
|
deba@1979
|
765 |
const Graph* graph;
|
deba@1979
|
766 |
bool direction;
|
deba@1979
|
767 |
public:
|
deba@1979
|
768 |
|
deba@1979
|
769 |
IncEdgeIt() { }
|
deba@1979
|
770 |
|
deba@1979
|
771 |
IncEdgeIt(Invalid i) : UEdge(i), direction(false) { }
|
deba@1979
|
772 |
|
deba@1979
|
773 |
IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
|
deba@1979
|
774 |
_graph.firstInc(*this, direction, n);
|
deba@1979
|
775 |
}
|
deba@1979
|
776 |
|
deba@1979
|
777 |
IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
|
deba@1979
|
778 |
: graph(&_graph), UEdge(ue) {
|
deba@1979
|
779 |
direction = (_graph.source(ue) == n);
|
deba@1979
|
780 |
}
|
deba@1979
|
781 |
|
deba@1979
|
782 |
IncEdgeIt& operator++() {
|
deba@1979
|
783 |
graph->nextInc(*this, direction);
|
deba@1979
|
784 |
return *this;
|
deba@1979
|
785 |
}
|
deba@1979
|
786 |
};
|
deba@1979
|
787 |
|
deba@1979
|
788 |
/// \brief Base node of the iterator
|
deba@1979
|
789 |
///
|
deba@1979
|
790 |
/// Returns the base node (ie. the source in this case) of the iterator
|
deba@1979
|
791 |
Node baseNode(const OutEdgeIt &e) const {
|
deba@1979
|
792 |
return Parent::source((Edge)e);
|
deba@1979
|
793 |
}
|
deba@1979
|
794 |
/// \brief Running node of the iterator
|
deba@1979
|
795 |
///
|
deba@1979
|
796 |
/// Returns the running node (ie. the target in this case) of the
|
deba@1979
|
797 |
/// iterator
|
deba@1979
|
798 |
Node runningNode(const OutEdgeIt &e) const {
|
deba@1979
|
799 |
return Parent::target((Edge)e);
|
deba@1979
|
800 |
}
|
deba@1979
|
801 |
|
deba@1979
|
802 |
/// \brief Base node of the iterator
|
deba@1979
|
803 |
///
|
deba@1979
|
804 |
/// Returns the base node (ie. the target in this case) of the iterator
|
deba@1979
|
805 |
Node baseNode(const InEdgeIt &e) const {
|
deba@1979
|
806 |
return Parent::target((Edge)e);
|
deba@1979
|
807 |
}
|
deba@1979
|
808 |
/// \brief Running node of the iterator
|
deba@1979
|
809 |
///
|
deba@1979
|
810 |
/// Returns the running node (ie. the source in this case) of the
|
deba@1979
|
811 |
/// iterator
|
deba@1979
|
812 |
Node runningNode(const InEdgeIt &e) const {
|
deba@1979
|
813 |
return Parent::source((Edge)e);
|
deba@1979
|
814 |
}
|
deba@1979
|
815 |
|
deba@1979
|
816 |
/// Base node of the iterator
|
deba@1979
|
817 |
///
|
deba@1979
|
818 |
/// Returns the base node of the iterator
|
deba@1979
|
819 |
Node baseNode(const IncEdgeIt &e) const {
|
deba@1979
|
820 |
return e.direction ? source(e) : target(e);
|
deba@1979
|
821 |
}
|
deba@1979
|
822 |
/// Running node of the iterator
|
deba@1979
|
823 |
///
|
deba@1979
|
824 |
/// Returns the running node of the iterator
|
deba@1979
|
825 |
Node runningNode(const IncEdgeIt &e) const {
|
deba@1979
|
826 |
return e.direction ? target(e) : source(e);
|
deba@1979
|
827 |
}
|
deba@1979
|
828 |
|
deba@1979
|
829 |
// Mappable extension
|
deba@1979
|
830 |
|
deba@1979
|
831 |
template <typename _Value>
|
deba@1979
|
832 |
class NodeMap
|
deba@1979
|
833 |
: public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
|
deba@1979
|
834 |
public:
|
deba@1979
|
835 |
typedef UGraphExtender Graph;
|
deba@1979
|
836 |
typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
|
deba@1979
|
837 |
|
deba@1979
|
838 |
NodeMap(const Graph& _g)
|
deba@1979
|
839 |
: Parent(_g) {}
|
deba@1979
|
840 |
NodeMap(const Graph& _g, const _Value& _v)
|
deba@1979
|
841 |
: Parent(_g, _v) {}
|
deba@1979
|
842 |
|
deba@1979
|
843 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@1979
|
844 |
return operator=<NodeMap>(cmap);
|
deba@1979
|
845 |
}
|
deba@1979
|
846 |
|
deba@1979
|
847 |
|
deba@1979
|
848 |
/// \brief Template assign operator.
|
deba@1979
|
849 |
///
|
deba@1979
|
850 |
/// The given parameter should be conform to the ReadMap
|
deba@1979
|
851 |
/// concecpt and could be indiced by the current item set of
|
deba@1979
|
852 |
/// the NodeMap. In this case the value for each item
|
deba@1979
|
853 |
/// is assigned by the value of the given ReadMap.
|
deba@1979
|
854 |
template <typename CMap>
|
deba@1979
|
855 |
NodeMap& operator=(const CMap& cmap) {
|
deba@1979
|
856 |
checkConcept<concept::ReadMap<Node, _Value>, CMap>();
|
deba@1979
|
857 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1979
|
858 |
Node it;
|
deba@1979
|
859 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1979
|
860 |
Parent::set(it, cmap[it]);
|
deba@1979
|
861 |
}
|
deba@1979
|
862 |
return *this;
|
deba@1979
|
863 |
}
|
deba@1979
|
864 |
|
deba@1979
|
865 |
};
|
deba@1979
|
866 |
|
deba@1979
|
867 |
template <typename _Value>
|
deba@1979
|
868 |
class EdgeMap
|
deba@1979
|
869 |
: public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
|
deba@1979
|
870 |
public:
|
deba@1979
|
871 |
typedef UGraphExtender Graph;
|
deba@1979
|
872 |
typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
|
deba@1979
|
873 |
|
deba@1979
|
874 |
EdgeMap(const Graph& _g)
|
deba@1979
|
875 |
: Parent(_g) {}
|
deba@1979
|
876 |
EdgeMap(const Graph& _g, const _Value& _v)
|
deba@1979
|
877 |
: Parent(_g, _v) {}
|
deba@1979
|
878 |
|
deba@1979
|
879 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@1979
|
880 |
return operator=<EdgeMap>(cmap);
|
deba@1979
|
881 |
}
|
deba@1979
|
882 |
|
deba@1979
|
883 |
template <typename CMap>
|
deba@1979
|
884 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@1979
|
885 |
checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
|
deba@1979
|
886 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1979
|
887 |
Edge it;
|
deba@1979
|
888 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1979
|
889 |
Parent::set(it, cmap[it]);
|
deba@1979
|
890 |
}
|
deba@1979
|
891 |
return *this;
|
deba@1979
|
892 |
}
|
deba@1979
|
893 |
};
|
deba@1979
|
894 |
|
deba@1979
|
895 |
|
deba@1979
|
896 |
template <typename _Value>
|
deba@1979
|
897 |
class UEdgeMap
|
deba@1979
|
898 |
: public IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > {
|
deba@1979
|
899 |
public:
|
deba@1979
|
900 |
typedef UGraphExtender Graph;
|
deba@1979
|
901 |
typedef IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > Parent;
|
deba@1979
|
902 |
|
deba@1979
|
903 |
UEdgeMap(const Graph& _g)
|
deba@1979
|
904 |
: Parent(_g) {}
|
deba@1979
|
905 |
UEdgeMap(const Graph& _g, const _Value& _v)
|
deba@1979
|
906 |
: Parent(_g, _v) {}
|
deba@1979
|
907 |
|
deba@1979
|
908 |
UEdgeMap& operator=(const UEdgeMap& cmap) {
|
deba@1979
|
909 |
return operator=<UEdgeMap>(cmap);
|
deba@1979
|
910 |
}
|
deba@1979
|
911 |
|
deba@1979
|
912 |
template <typename CMap>
|
deba@1979
|
913 |
UEdgeMap& operator=(const CMap& cmap) {
|
deba@1979
|
914 |
checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
|
deba@1979
|
915 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1979
|
916 |
UEdge it;
|
deba@1979
|
917 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1979
|
918 |
Parent::set(it, cmap[it]);
|
deba@1979
|
919 |
}
|
deba@1979
|
920 |
return *this;
|
deba@1979
|
921 |
}
|
deba@1979
|
922 |
};
|
deba@1979
|
923 |
|
deba@1979
|
924 |
// Alteration extension
|
deba@1979
|
925 |
|
deba@1979
|
926 |
Node addNode() {
|
deba@1979
|
927 |
Node node = Parent::addNode();
|
deba@1979
|
928 |
getNotifier(Node()).add(node);
|
deba@1979
|
929 |
return node;
|
deba@1979
|
930 |
}
|
deba@1979
|
931 |
|
deba@1979
|
932 |
UEdge addEdge(const Node& from, const Node& to) {
|
deba@1979
|
933 |
UEdge uedge = Parent::addEdge(from, to);
|
deba@1979
|
934 |
getNotifier(UEdge()).add(uedge);
|
deba@1979
|
935 |
getNotifier(Edge()).add(Parent::direct(uedge, true));
|
deba@1979
|
936 |
getNotifier(Edge()).add(Parent::direct(uedge, false));
|
deba@1979
|
937 |
return uedge;
|
deba@1979
|
938 |
}
|
deba@1979
|
939 |
|
deba@1979
|
940 |
void clear() {
|
deba@1979
|
941 |
getNotifier(Edge()).clear();
|
deba@1979
|
942 |
getNotifier(UEdge()).clear();
|
deba@1979
|
943 |
getNotifier(Node()).clear();
|
deba@1979
|
944 |
Parent::clear();
|
deba@1979
|
945 |
}
|
deba@1979
|
946 |
|
deba@1979
|
947 |
void erase(const Node& node) {
|
deba@1979
|
948 |
Edge edge;
|
deba@1979
|
949 |
Parent::firstOut(edge, node);
|
deba@1979
|
950 |
while (edge != INVALID ) {
|
deba@1979
|
951 |
erase(edge);
|
deba@1979
|
952 |
Parent::firstOut(edge, node);
|
deba@1979
|
953 |
}
|
deba@1979
|
954 |
|
deba@1979
|
955 |
Parent::firstIn(edge, node);
|
deba@1979
|
956 |
while (edge != INVALID ) {
|
deba@1979
|
957 |
erase(edge);
|
deba@1979
|
958 |
Parent::firstIn(edge, node);
|
deba@1979
|
959 |
}
|
deba@1979
|
960 |
|
deba@1979
|
961 |
getNotifier(Node()).erase(node);
|
deba@1979
|
962 |
Parent::erase(node);
|
deba@1979
|
963 |
}
|
deba@1979
|
964 |
|
deba@1979
|
965 |
void erase(const UEdge& uedge) {
|
deba@1979
|
966 |
getNotifier(Edge()).erase(Parent::direct(uedge, true));
|
deba@1979
|
967 |
getNotifier(Edge()).erase(Parent::direct(uedge, false));
|
deba@1979
|
968 |
getNotifier(UEdge()).erase(uedge);
|
deba@1979
|
969 |
Parent::erase(uedge);
|
deba@1979
|
970 |
}
|
deba@1979
|
971 |
|
deba@1979
|
972 |
~UGraphExtender() {
|
deba@1979
|
973 |
getNotifier(Edge()).clear();
|
deba@1979
|
974 |
getNotifier(UEdge()).clear();
|
deba@1979
|
975 |
getNotifier(Node()).clear();
|
deba@1979
|
976 |
}
|
deba@1791
|
977 |
|
deba@1791
|
978 |
};
|
deba@1791
|
979 |
|
deba@1820
|
980 |
|
deba@1979
|
981 |
template <typename Base>
|
deba@1979
|
982 |
class BpUGraphBaseExtender : public Base {
|
deba@1820
|
983 |
public:
|
deba@1979
|
984 |
typedef Base Parent;
|
deba@1979
|
985 |
typedef BpUGraphBaseExtender Graph;
|
deba@1820
|
986 |
|
deba@1820
|
987 |
typedef typename Parent::Node Node;
|
klao@1909
|
988 |
typedef typename Parent::Edge UEdge;
|
deba@1820
|
989 |
|
deba@1979
|
990 |
|
deba@1820
|
991 |
using Parent::first;
|
deba@1820
|
992 |
using Parent::next;
|
deba@1820
|
993 |
|
deba@1820
|
994 |
using Parent::id;
|
deba@1820
|
995 |
|
deba@1979
|
996 |
class ANode : public Node {
|
deba@1979
|
997 |
friend class BpUGraphBaseExtender;
|
deba@1979
|
998 |
public:
|
deba@1979
|
999 |
ANode() {}
|
deba@1979
|
1000 |
ANode(const Node& node) : Node(node) {
|
deba@1979
|
1001 |
LEMON_ASSERT(Parent::aNode(node) || node == INVALID,
|
deba@1979
|
1002 |
typename Parent::NodeSetError());
|
deba@1979
|
1003 |
}
|
deba@1979
|
1004 |
ANode(Invalid) : Node(INVALID) {}
|
deba@1979
|
1005 |
};
|
deba@1979
|
1006 |
|
deba@1979
|
1007 |
void first(ANode& node) const {
|
deba@1979
|
1008 |
Parent::firstANode(static_cast<Node&>(node));
|
deba@1979
|
1009 |
}
|
deba@1979
|
1010 |
void next(ANode& node) const {
|
deba@1979
|
1011 |
Parent::nextANode(static_cast<Node&>(node));
|
deba@1979
|
1012 |
}
|
deba@1979
|
1013 |
|
deba@1979
|
1014 |
int id(const ANode& node) const {
|
deba@1979
|
1015 |
return Parent::aNodeId(node);
|
deba@1979
|
1016 |
}
|
deba@1979
|
1017 |
|
deba@1979
|
1018 |
class BNode : public Node {
|
deba@1979
|
1019 |
friend class BpUGraphBaseExtender;
|
deba@1979
|
1020 |
public:
|
deba@1979
|
1021 |
BNode() {}
|
deba@1979
|
1022 |
BNode(const Node& node) : Node(node) {
|
deba@1979
|
1023 |
LEMON_ASSERT(Parent::bNode(node) || node == INVALID,
|
deba@1979
|
1024 |
typename Parent::NodeSetError());
|
deba@1979
|
1025 |
}
|
deba@1979
|
1026 |
BNode(Invalid) : Node(INVALID) {}
|
deba@1979
|
1027 |
};
|
deba@1979
|
1028 |
|
deba@1979
|
1029 |
void first(BNode& node) const {
|
deba@1979
|
1030 |
Parent::firstBNode(static_cast<Node&>(node));
|
deba@1979
|
1031 |
}
|
deba@1979
|
1032 |
void next(BNode& node) const {
|
deba@1979
|
1033 |
Parent::nextBNode(static_cast<Node&>(node));
|
deba@1979
|
1034 |
}
|
deba@1979
|
1035 |
|
deba@1979
|
1036 |
int id(const BNode& node) const {
|
deba@1979
|
1037 |
return Parent::aNodeId(node);
|
deba@1979
|
1038 |
}
|
deba@1979
|
1039 |
|
klao@1909
|
1040 |
Node source(const UEdge& edge) const {
|
deba@1910
|
1041 |
return aNode(edge);
|
deba@1820
|
1042 |
}
|
klao@1909
|
1043 |
Node target(const UEdge& edge) const {
|
deba@1910
|
1044 |
return bNode(edge);
|
deba@1820
|
1045 |
}
|
deba@1820
|
1046 |
|
klao@1909
|
1047 |
void firstInc(UEdge& edge, bool& direction, const Node& node) const {
|
deba@1910
|
1048 |
if (Parent::aNode(node)) {
|
deba@1910
|
1049 |
Parent::firstOut(edge, node);
|
deba@1820
|
1050 |
direction = true;
|
deba@1820
|
1051 |
} else {
|
deba@1910
|
1052 |
Parent::firstIn(edge, node);
|
klao@1909
|
1053 |
direction = static_cast<UEdge&>(edge) == INVALID;
|
deba@1820
|
1054 |
}
|
deba@1820
|
1055 |
}
|
klao@1909
|
1056 |
void nextInc(UEdge& edge, bool& direction) const {
|
deba@1820
|
1057 |
if (direction) {
|
deba@1910
|
1058 |
Parent::nextOut(edge);
|
deba@1820
|
1059 |
} else {
|
deba@1910
|
1060 |
Parent::nextIn(edge);
|
deba@1820
|
1061 |
if (edge == INVALID) direction = true;
|
deba@1820
|
1062 |
}
|
deba@1820
|
1063 |
}
|
deba@1820
|
1064 |
|
klao@1909
|
1065 |
int maxUEdgeId() const {
|
deba@1820
|
1066 |
return Parent::maxEdgeId();
|
deba@1820
|
1067 |
}
|
deba@1820
|
1068 |
|
klao@1909
|
1069 |
UEdge uEdgeFromId(int id) const {
|
deba@1820
|
1070 |
return Parent::edgeFromId(id);
|
deba@1820
|
1071 |
}
|
deba@1820
|
1072 |
|
klao@1909
|
1073 |
class Edge : public UEdge {
|
deba@1979
|
1074 |
friend class BpUGraphBaseExtender;
|
deba@1820
|
1075 |
protected:
|
deba@1820
|
1076 |
bool forward;
|
deba@1820
|
1077 |
|
klao@1909
|
1078 |
Edge(const UEdge& edge, bool _forward)
|
klao@1909
|
1079 |
: UEdge(edge), forward(_forward) {}
|
deba@1820
|
1080 |
|
deba@1820
|
1081 |
public:
|
deba@1820
|
1082 |
Edge() {}
|
klao@1909
|
1083 |
Edge (Invalid) : UEdge(INVALID), forward(true) {}
|
deba@1820
|
1084 |
bool operator==(const Edge& i) const {
|
klao@1909
|
1085 |
return UEdge::operator==(i) && forward == i.forward;
|
deba@1820
|
1086 |
}
|
deba@1820
|
1087 |
bool operator!=(const Edge& i) const {
|
klao@1909
|
1088 |
return UEdge::operator!=(i) || forward != i.forward;
|
deba@1820
|
1089 |
}
|
deba@1820
|
1090 |
bool operator<(const Edge& i) const {
|
klao@1909
|
1091 |
return UEdge::operator<(i) ||
|
klao@1909
|
1092 |
(!(i.forward<forward) && UEdge(*this)<UEdge(i));
|
deba@1820
|
1093 |
}
|
deba@1820
|
1094 |
};
|
deba@1820
|
1095 |
|
deba@1820
|
1096 |
void first(Edge& edge) const {
|
klao@1909
|
1097 |
Parent::first(static_cast<UEdge&>(edge));
|
deba@1820
|
1098 |
edge.forward = true;
|
deba@1820
|
1099 |
}
|
deba@1820
|
1100 |
|
deba@1820
|
1101 |
void next(Edge& edge) const {
|
deba@1820
|
1102 |
if (!edge.forward) {
|
klao@1909
|
1103 |
Parent::next(static_cast<UEdge&>(edge));
|
deba@1820
|
1104 |
}
|
deba@1820
|
1105 |
edge.forward = !edge.forward;
|
deba@1820
|
1106 |
}
|
deba@1820
|
1107 |
|
deba@1820
|
1108 |
void firstOut(Edge& edge, const Node& node) const {
|
deba@1910
|
1109 |
if (Parent::aNode(node)) {
|
deba@1910
|
1110 |
Parent::firstOut(edge, node);
|
deba@1820
|
1111 |
edge.forward = true;
|
deba@1820
|
1112 |
} else {
|
deba@1910
|
1113 |
Parent::firstIn(edge, node);
|
klao@1909
|
1114 |
edge.forward = static_cast<UEdge&>(edge) == INVALID;
|
deba@1820
|
1115 |
}
|
deba@1820
|
1116 |
}
|
deba@1820
|
1117 |
void nextOut(Edge& edge) const {
|
deba@1820
|
1118 |
if (edge.forward) {
|
deba@1910
|
1119 |
Parent::nextOut(edge);
|
deba@1820
|
1120 |
} else {
|
deba@1910
|
1121 |
Parent::nextIn(edge);
|
klao@1909
|
1122 |
edge.forward = static_cast<UEdge&>(edge) == INVALID;
|
deba@1820
|
1123 |
}
|
deba@1820
|
1124 |
}
|
deba@1820
|
1125 |
|
deba@1820
|
1126 |
void firstIn(Edge& edge, const Node& node) const {
|
deba@1910
|
1127 |
if (Parent::bNode(node)) {
|
deba@1910
|
1128 |
Parent::firstIn(edge, node);
|
deba@1820
|
1129 |
edge.forward = true;
|
deba@1820
|
1130 |
} else {
|
deba@1910
|
1131 |
Parent::firstOut(edge, node);
|
klao@1909
|
1132 |
edge.forward = static_cast<UEdge&>(edge) == INVALID;
|
deba@1820
|
1133 |
}
|
deba@1820
|
1134 |
}
|
deba@1820
|
1135 |
void nextIn(Edge& edge) const {
|
deba@1820
|
1136 |
if (edge.forward) {
|
deba@1910
|
1137 |
Parent::nextIn(edge);
|
deba@1820
|
1138 |
} else {
|
deba@1910
|
1139 |
Parent::nextOut(edge);
|
klao@1909
|
1140 |
edge.forward = static_cast<UEdge&>(edge) == INVALID;
|
deba@1820
|
1141 |
}
|
deba@1820
|
1142 |
}
|
deba@1820
|
1143 |
|
deba@1820
|
1144 |
Node source(const Edge& edge) const {
|
deba@1910
|
1145 |
return edge.forward ? Parent::aNode(edge) : Parent::bNode(edge);
|
deba@1820
|
1146 |
}
|
deba@1820
|
1147 |
Node target(const Edge& edge) const {
|
deba@1910
|
1148 |
return edge.forward ? Parent::bNode(edge) : Parent::aNode(edge);
|
deba@1820
|
1149 |
}
|
deba@1820
|
1150 |
|
deba@1820
|
1151 |
int id(const Edge& edge) const {
|
deba@1820
|
1152 |
return (Parent::id(edge) << 1) + (edge.forward ? 0 : 1);
|
deba@1820
|
1153 |
}
|
deba@1820
|
1154 |
Edge edgeFromId(int id) const {
|
klao@1909
|
1155 |
return Edge(Parent::fromId(id >> 1, UEdge()), (id & 1) == 0);
|
deba@1820
|
1156 |
}
|
deba@1820
|
1157 |
int maxEdgeId() const {
|
klao@1909
|
1158 |
return (Parent::maxId(UEdge()) << 1) + 1;
|
deba@1820
|
1159 |
}
|
deba@1820
|
1160 |
|
deba@1979
|
1161 |
bool direction(const Edge& edge) const {
|
deba@1979
|
1162 |
return edge.forward;
|
deba@1820
|
1163 |
}
|
deba@1820
|
1164 |
|
deba@1979
|
1165 |
Edge direct(const UEdge& edge, bool direction) const {
|
deba@1979
|
1166 |
return Edge(edge, direction);
|
deba@1979
|
1167 |
}
|
deba@1979
|
1168 |
};
|
deba@1979
|
1169 |
|
deba@1979
|
1170 |
template <typename Base>
|
deba@1979
|
1171 |
class BpUGraphExtender : public Base {
|
deba@1979
|
1172 |
public:
|
deba@1979
|
1173 |
typedef Base Parent;
|
deba@1979
|
1174 |
typedef BpUGraphExtender Graph;
|
deba@1979
|
1175 |
|
deba@1979
|
1176 |
typedef typename Parent::Node Node;
|
deba@1979
|
1177 |
typedef typename Parent::BNode BNode;
|
deba@1979
|
1178 |
typedef typename Parent::ANode ANode;
|
deba@1979
|
1179 |
typedef typename Parent::Edge Edge;
|
deba@1979
|
1180 |
typedef typename Parent::UEdge UEdge;
|
deba@1979
|
1181 |
|
deba@1979
|
1182 |
Node oppositeNode(const UEdge& edge, const Node& node) const {
|
deba@1979
|
1183 |
return source(edge) == node ?
|
deba@1979
|
1184 |
target(edge) : source(edge);
|
deba@1820
|
1185 |
}
|
deba@1820
|
1186 |
|
deba@1979
|
1187 |
using Parent::direct;
|
deba@1979
|
1188 |
Edge direct(const UEdge& edge, const Node& node) const {
|
deba@1979
|
1189 |
return Edge(edge, node == Parent::source(edge));
|
deba@1820
|
1190 |
}
|
deba@1820
|
1191 |
|
deba@1979
|
1192 |
Edge oppositeEdge(const Edge& edge) const {
|
deba@1979
|
1193 |
return Parent::direct(edge, !Parent::direction(edge));
|
deba@1979
|
1194 |
}
|
deba@1820
|
1195 |
|
deba@1820
|
1196 |
|
deba@1820
|
1197 |
int maxId(Node) const {
|
deba@1820
|
1198 |
return Parent::maxNodeId();
|
deba@1820
|
1199 |
}
|
deba@1910
|
1200 |
int maxId(BNode) const {
|
deba@1910
|
1201 |
return Parent::maxBNodeId();
|
deba@1820
|
1202 |
}
|
deba@1910
|
1203 |
int maxId(ANode) const {
|
deba@1910
|
1204 |
return Parent::maxANodeId();
|
deba@1820
|
1205 |
}
|
deba@1820
|
1206 |
int maxId(Edge) const {
|
deba@1979
|
1207 |
return Parent::maxEdgeId();
|
deba@1820
|
1208 |
}
|
klao@1909
|
1209 |
int maxId(UEdge) const {
|
deba@1979
|
1210 |
return Parent::maxUEdgeId();
|
deba@1820
|
1211 |
}
|
deba@1820
|
1212 |
|
deba@1820
|
1213 |
|
deba@1820
|
1214 |
Node fromId(int id, Node) const {
|
deba@1820
|
1215 |
return Parent::nodeFromId(id);
|
deba@1820
|
1216 |
}
|
deba@1910
|
1217 |
ANode fromId(int id, ANode) const {
|
deba@1910
|
1218 |
return Parent::fromANodeId(id);
|
deba@1820
|
1219 |
}
|
deba@1910
|
1220 |
BNode fromId(int id, BNode) const {
|
deba@1910
|
1221 |
return Parent::fromBNodeId(id);
|
deba@1820
|
1222 |
}
|
deba@1820
|
1223 |
Edge fromId(int id, Edge) const {
|
deba@1979
|
1224 |
return Parent::edgeFromId(id);
|
deba@1820
|
1225 |
}
|
klao@1909
|
1226 |
UEdge fromId(int id, UEdge) const {
|
deba@1979
|
1227 |
return Parent::uEdgeFromId(id);
|
deba@1979
|
1228 |
}
|
deba@1979
|
1229 |
|
deba@1979
|
1230 |
typedef AlterationNotifier<Node> NodeNotifier;
|
deba@1979
|
1231 |
typedef AlterationNotifier<BNode> BNodeNotifier;
|
deba@1979
|
1232 |
typedef AlterationNotifier<ANode> ANodeNotifier;
|
deba@1979
|
1233 |
typedef AlterationNotifier<Edge> EdgeNotifier;
|
deba@1979
|
1234 |
typedef AlterationNotifier<UEdge> UEdgeNotifier;
|
deba@1979
|
1235 |
|
deba@1979
|
1236 |
protected:
|
deba@1979
|
1237 |
|
deba@1979
|
1238 |
mutable NodeNotifier nodeNotifier;
|
deba@1979
|
1239 |
mutable BNodeNotifier bNodeNotifier;
|
deba@1979
|
1240 |
mutable ANodeNotifier aNodeNotifier;
|
deba@1979
|
1241 |
mutable EdgeNotifier edgeNotifier;
|
deba@1979
|
1242 |
mutable UEdgeNotifier uEdgeNotifier;
|
deba@1979
|
1243 |
|
deba@1979
|
1244 |
public:
|
deba@1979
|
1245 |
|
deba@1979
|
1246 |
NodeNotifier& getNotifier(Node) const {
|
deba@1979
|
1247 |
return nodeNotifier;
|
deba@1820
|
1248 |
}
|
deba@1820
|
1249 |
|
deba@1979
|
1250 |
BNodeNotifier& getNotifier(BNode) const {
|
deba@1979
|
1251 |
return bNodeNotifier;
|
deba@1979
|
1252 |
}
|
deba@1979
|
1253 |
|
deba@1979
|
1254 |
ANodeNotifier& getNotifier(ANode) const {
|
deba@1979
|
1255 |
return aNodeNotifier;
|
deba@1979
|
1256 |
}
|
deba@1979
|
1257 |
|
deba@1979
|
1258 |
EdgeNotifier& getNotifier(Edge) const {
|
deba@1979
|
1259 |
return edgeNotifier;
|
deba@1979
|
1260 |
}
|
deba@1979
|
1261 |
|
deba@1979
|
1262 |
UEdgeNotifier& getNotifier(UEdge) const {
|
deba@1979
|
1263 |
return uEdgeNotifier;
|
deba@1979
|
1264 |
}
|
deba@1979
|
1265 |
|
deba@1979
|
1266 |
class NodeIt : public Node {
|
deba@1979
|
1267 |
const Graph* graph;
|
deba@1979
|
1268 |
public:
|
deba@1979
|
1269 |
|
deba@1979
|
1270 |
NodeIt() { }
|
deba@1979
|
1271 |
|
deba@1979
|
1272 |
NodeIt(Invalid i) : Node(INVALID) { }
|
deba@1979
|
1273 |
|
deba@1979
|
1274 |
explicit NodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@1979
|
1275 |
graph->first(static_cast<Node&>(*this));
|
deba@1979
|
1276 |
}
|
deba@1979
|
1277 |
|
deba@1979
|
1278 |
NodeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
1279 |
: Node(node), graph(&_graph) { }
|
deba@1979
|
1280 |
|
deba@1979
|
1281 |
NodeIt& operator++() {
|
deba@1979
|
1282 |
graph->next(*this);
|
deba@1979
|
1283 |
return *this;
|
deba@1979
|
1284 |
}
|
deba@1979
|
1285 |
|
deba@1979
|
1286 |
};
|
deba@1979
|
1287 |
|
deba@1979
|
1288 |
class ANodeIt : public Node {
|
deba@1979
|
1289 |
friend class BpUGraphExtender;
|
deba@1979
|
1290 |
const Graph* graph;
|
deba@1979
|
1291 |
public:
|
deba@1979
|
1292 |
|
deba@1979
|
1293 |
ANodeIt() { }
|
deba@1979
|
1294 |
|
deba@1979
|
1295 |
ANodeIt(Invalid i) : Node(INVALID) { }
|
deba@1979
|
1296 |
|
deba@1979
|
1297 |
explicit ANodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@1979
|
1298 |
graph->firstANode(static_cast<Node&>(*this));
|
deba@1979
|
1299 |
}
|
deba@1979
|
1300 |
|
deba@1979
|
1301 |
ANodeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
1302 |
: Node(node), graph(&_graph) {}
|
deba@1979
|
1303 |
|
deba@1979
|
1304 |
ANodeIt& operator++() {
|
deba@1979
|
1305 |
graph->nextANode(*this);
|
deba@1979
|
1306 |
return *this;
|
deba@1979
|
1307 |
}
|
deba@1979
|
1308 |
};
|
deba@1979
|
1309 |
|
deba@1979
|
1310 |
class BNodeIt : public Node {
|
deba@1979
|
1311 |
friend class BpUGraphExtender;
|
deba@1979
|
1312 |
const Graph* graph;
|
deba@1979
|
1313 |
public:
|
deba@1979
|
1314 |
|
deba@1979
|
1315 |
BNodeIt() { }
|
deba@1979
|
1316 |
|
deba@1979
|
1317 |
BNodeIt(Invalid i) : Node(INVALID) { }
|
deba@1979
|
1318 |
|
deba@1979
|
1319 |
explicit BNodeIt(const Graph& _graph) : graph(&_graph) {
|
deba@1979
|
1320 |
graph->firstBNode(static_cast<Node&>(*this));
|
deba@1979
|
1321 |
}
|
deba@1979
|
1322 |
|
deba@1979
|
1323 |
BNodeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
1324 |
: Node(node), graph(&_graph) {}
|
deba@1979
|
1325 |
|
deba@1979
|
1326 |
BNodeIt& operator++() {
|
deba@1979
|
1327 |
graph->nextBNode(*this);
|
deba@1979
|
1328 |
return *this;
|
deba@1979
|
1329 |
}
|
deba@1979
|
1330 |
};
|
deba@1979
|
1331 |
|
deba@1979
|
1332 |
class EdgeIt : public Edge {
|
deba@1979
|
1333 |
friend class BpUGraphExtender;
|
deba@1979
|
1334 |
const Graph* graph;
|
deba@1979
|
1335 |
public:
|
deba@1979
|
1336 |
|
deba@1979
|
1337 |
EdgeIt() { }
|
deba@1979
|
1338 |
|
deba@1979
|
1339 |
EdgeIt(Invalid i) : Edge(INVALID) { }
|
deba@1979
|
1340 |
|
deba@1979
|
1341 |
explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
|
deba@1979
|
1342 |
graph->first(static_cast<Edge&>(*this));
|
deba@1979
|
1343 |
}
|
deba@1979
|
1344 |
|
deba@1979
|
1345 |
EdgeIt(const Graph& _graph, const Edge& edge)
|
deba@1979
|
1346 |
: Edge(edge), graph(&_graph) { }
|
deba@1979
|
1347 |
|
deba@1979
|
1348 |
EdgeIt& operator++() {
|
deba@1979
|
1349 |
graph->next(*this);
|
deba@1979
|
1350 |
return *this;
|
deba@1979
|
1351 |
}
|
deba@1979
|
1352 |
|
deba@1979
|
1353 |
};
|
deba@1979
|
1354 |
|
deba@1979
|
1355 |
class UEdgeIt : public UEdge {
|
deba@1979
|
1356 |
friend class BpUGraphExtender;
|
deba@1979
|
1357 |
const Graph* graph;
|
deba@1979
|
1358 |
public:
|
deba@1979
|
1359 |
|
deba@1979
|
1360 |
UEdgeIt() { }
|
deba@1979
|
1361 |
|
deba@1979
|
1362 |
UEdgeIt(Invalid i) : UEdge(INVALID) { }
|
deba@1979
|
1363 |
|
deba@1979
|
1364 |
explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
|
deba@1979
|
1365 |
graph->first(static_cast<UEdge&>(*this));
|
deba@1979
|
1366 |
}
|
deba@1979
|
1367 |
|
deba@1979
|
1368 |
UEdgeIt(const Graph& _graph, const UEdge& edge)
|
deba@1979
|
1369 |
: UEdge(edge), graph(&_graph) { }
|
deba@1979
|
1370 |
|
deba@1979
|
1371 |
UEdgeIt& operator++() {
|
deba@1979
|
1372 |
graph->next(*this);
|
deba@1979
|
1373 |
return *this;
|
deba@1979
|
1374 |
}
|
deba@1979
|
1375 |
};
|
deba@1979
|
1376 |
|
deba@1979
|
1377 |
class OutEdgeIt : public Edge {
|
deba@1979
|
1378 |
friend class BpUGraphExtender;
|
deba@1979
|
1379 |
const Graph* graph;
|
deba@1979
|
1380 |
public:
|
deba@1979
|
1381 |
|
deba@1979
|
1382 |
OutEdgeIt() { }
|
deba@1979
|
1383 |
|
deba@1979
|
1384 |
OutEdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
1385 |
|
deba@1979
|
1386 |
OutEdgeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
1387 |
: graph(&_graph) {
|
deba@1979
|
1388 |
graph->firstOut(*this, node);
|
deba@1979
|
1389 |
}
|
deba@1979
|
1390 |
|
deba@1979
|
1391 |
OutEdgeIt(const Graph& _graph, const Edge& edge)
|
deba@1979
|
1392 |
: Edge(edge), graph(&_graph) {}
|
deba@1979
|
1393 |
|
deba@1979
|
1394 |
OutEdgeIt& operator++() {
|
deba@1979
|
1395 |
graph->nextOut(*this);
|
deba@1979
|
1396 |
return *this;
|
deba@1979
|
1397 |
}
|
deba@1979
|
1398 |
|
deba@1979
|
1399 |
};
|
deba@1979
|
1400 |
|
deba@1979
|
1401 |
|
deba@1979
|
1402 |
class InEdgeIt : public Edge {
|
deba@1979
|
1403 |
friend class BpUGraphExtender;
|
deba@1979
|
1404 |
const Graph* graph;
|
deba@1979
|
1405 |
public:
|
deba@1979
|
1406 |
|
deba@1979
|
1407 |
InEdgeIt() { }
|
deba@1979
|
1408 |
|
deba@1979
|
1409 |
InEdgeIt(Invalid i) : Edge(i) { }
|
deba@1979
|
1410 |
|
deba@1979
|
1411 |
InEdgeIt(const Graph& _graph, const Node& node)
|
deba@1979
|
1412 |
: graph(&_graph) {
|
deba@1979
|
1413 |
graph->firstIn(*this, node);
|
deba@1979
|
1414 |
}
|
deba@1979
|
1415 |
|
deba@1979
|
1416 |
InEdgeIt(const Graph& _graph, const Edge& edge) :
|
deba@1979
|
1417 |
Edge(edge), graph(&_graph) {}
|
deba@1979
|
1418 |
|
deba@1979
|
1419 |
InEdgeIt& operator++() {
|
deba@1979
|
1420 |
graph->nextIn(*this);
|
deba@1979
|
1421 |
return *this;
|
deba@1979
|
1422 |
}
|
deba@1979
|
1423 |
|
deba@1979
|
1424 |
};
|
deba@1979
|
1425 |
|
deba@1979
|
1426 |
/// \brief Base node of the iterator
|
deba@1979
|
1427 |
///
|
deba@1979
|
1428 |
/// Returns the base node (ie. the source in this case) of the iterator
|
deba@1979
|
1429 |
Node baseNode(const OutEdgeIt &e) const {
|
deba@1979
|
1430 |
return Parent::source((Edge&)e);
|
deba@1979
|
1431 |
}
|
deba@1979
|
1432 |
/// \brief Running node of the iterator
|
deba@1979
|
1433 |
///
|
deba@1979
|
1434 |
/// Returns the running node (ie. the target in this case) of the
|
deba@1979
|
1435 |
/// iterator
|
deba@1979
|
1436 |
Node runningNode(const OutEdgeIt &e) const {
|
deba@1979
|
1437 |
return Parent::target((Edge&)e);
|
deba@1979
|
1438 |
}
|
deba@1979
|
1439 |
|
deba@1979
|
1440 |
/// \brief Base node of the iterator
|
deba@1979
|
1441 |
///
|
deba@1979
|
1442 |
/// Returns the base node (ie. the target in this case) of the iterator
|
deba@1979
|
1443 |
Node baseNode(const InEdgeIt &e) const {
|
deba@1979
|
1444 |
return Parent::target((Edge&)e);
|
deba@1979
|
1445 |
}
|
deba@1979
|
1446 |
/// \brief Running node of the iterator
|
deba@1979
|
1447 |
///
|
deba@1979
|
1448 |
/// Returns the running node (ie. the source in this case) of the
|
deba@1979
|
1449 |
/// iterator
|
deba@1979
|
1450 |
Node runningNode(const InEdgeIt &e) const {
|
deba@1979
|
1451 |
return Parent::source((Edge&)e);
|
deba@1979
|
1452 |
}
|
deba@1979
|
1453 |
|
deba@1979
|
1454 |
class IncEdgeIt : public Parent::UEdge {
|
deba@1979
|
1455 |
friend class BpUGraphExtender;
|
deba@1979
|
1456 |
const Graph* graph;
|
deba@1979
|
1457 |
bool direction;
|
deba@1979
|
1458 |
public:
|
deba@1979
|
1459 |
|
deba@1979
|
1460 |
IncEdgeIt() { }
|
deba@1979
|
1461 |
|
deba@1979
|
1462 |
IncEdgeIt(Invalid i) : UEdge(i), direction(true) { }
|
deba@1979
|
1463 |
|
deba@1979
|
1464 |
IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
|
deba@1979
|
1465 |
graph->firstInc(*this, direction, n);
|
deba@1979
|
1466 |
}
|
deba@1979
|
1467 |
|
deba@1979
|
1468 |
IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)
|
deba@1979
|
1469 |
: graph(&_graph), UEdge(ue) {
|
deba@1979
|
1470 |
direction = (graph->source(ue) == n);
|
deba@1979
|
1471 |
}
|
deba@1979
|
1472 |
|
deba@1979
|
1473 |
IncEdgeIt& operator++() {
|
deba@1979
|
1474 |
graph->nextInc(*this, direction);
|
deba@1979
|
1475 |
return *this;
|
deba@1979
|
1476 |
}
|
deba@1979
|
1477 |
};
|
deba@1979
|
1478 |
|
deba@1979
|
1479 |
|
deba@1979
|
1480 |
/// Base node of the iterator
|
deba@1979
|
1481 |
///
|
deba@1979
|
1482 |
/// Returns the base node of the iterator
|
deba@1979
|
1483 |
Node baseNode(const IncEdgeIt &e) const {
|
deba@1979
|
1484 |
return e.direction ? source(e) : target(e);
|
deba@1979
|
1485 |
}
|
deba@1979
|
1486 |
|
deba@1979
|
1487 |
/// Running node of the iterator
|
deba@1979
|
1488 |
///
|
deba@1979
|
1489 |
/// Returns the running node of the iterator
|
deba@1979
|
1490 |
Node runningNode(const IncEdgeIt &e) const {
|
deba@1979
|
1491 |
return e.direction ? target(e) : source(e);
|
deba@1979
|
1492 |
}
|
deba@1979
|
1493 |
|
deba@1979
|
1494 |
template <typename _Value>
|
deba@1979
|
1495 |
class ANodeMap
|
deba@1979
|
1496 |
: public IterableMapExtender<DefaultMap<Graph, ANode, _Value> > {
|
deba@1979
|
1497 |
public:
|
deba@1979
|
1498 |
typedef BpUGraphExtender Graph;
|
deba@1979
|
1499 |
typedef IterableMapExtender<DefaultMap<Graph, ANode, _Value> >
|
deba@1979
|
1500 |
Parent;
|
deba@1979
|
1501 |
|
deba@1979
|
1502 |
ANodeMap(const Graph& _g)
|
deba@1979
|
1503 |
: Parent(_g) {}
|
deba@1979
|
1504 |
ANodeMap(const Graph& _g, const _Value& _v)
|
deba@1979
|
1505 |
: Parent(_g, _v) {}
|
deba@1979
|
1506 |
|
deba@1979
|
1507 |
ANodeMap& operator=(const ANodeMap& cmap) {
|
deba@1979
|
1508 |
return operator=<ANodeMap>(cmap);
|
deba@1979
|
1509 |
}
|
deba@1979
|
1510 |
|
deba@1979
|
1511 |
|
deba@1979
|
1512 |
/// \brief Template assign operator.
|
deba@1979
|
1513 |
///
|
deba@1979
|
1514 |
/// The given parameter should be conform to the ReadMap
|
deba@1979
|
1515 |
/// concept and could be indiced by the current item set of
|
deba@1979
|
1516 |
/// the ANodeMap. In this case the value for each item
|
deba@1979
|
1517 |
/// is assigned by the value of the given ReadMap.
|
deba@1979
|
1518 |
template <typename CMap>
|
deba@1979
|
1519 |
ANodeMap& operator=(const CMap& cmap) {
|
deba@1979
|
1520 |
checkConcept<concept::ReadMap<ANode, _Value>, CMap>();
|
deba@1979
|
1521 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1979
|
1522 |
ANode it;
|
deba@1979
|
1523 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1979
|
1524 |
Parent::set(it, cmap[it]);
|
deba@1979
|
1525 |
}
|
deba@1979
|
1526 |
return *this;
|
deba@1979
|
1527 |
}
|
deba@1979
|
1528 |
|
deba@1979
|
1529 |
};
|
deba@1979
|
1530 |
|
deba@1979
|
1531 |
template <typename _Value>
|
deba@1979
|
1532 |
class BNodeMap
|
deba@1979
|
1533 |
: public IterableMapExtender<DefaultMap<Graph, BNode, _Value> > {
|
deba@1979
|
1534 |
public:
|
deba@1979
|
1535 |
typedef BpUGraphExtender Graph;
|
deba@1979
|
1536 |
typedef IterableMapExtender<DefaultMap<Graph, BNode, _Value> >
|
deba@1979
|
1537 |
Parent;
|
deba@1979
|
1538 |
|
deba@1979
|
1539 |
BNodeMap(const Graph& _g)
|
deba@1979
|
1540 |
: Parent(_g) {}
|
deba@1979
|
1541 |
BNodeMap(const Graph& _g, const _Value& _v)
|
deba@1979
|
1542 |
: Parent(_g, _v) {}
|
deba@1979
|
1543 |
|
deba@1979
|
1544 |
BNodeMap& operator=(const BNodeMap& cmap) {
|
deba@1979
|
1545 |
return operator=<BNodeMap>(cmap);
|
deba@1979
|
1546 |
}
|
deba@1979
|
1547 |
|
deba@1979
|
1548 |
|
deba@1979
|
1549 |
/// \brief Template assign operator.
|
deba@1979
|
1550 |
///
|
deba@1979
|
1551 |
/// The given parameter should be conform to the ReadMap
|
deba@1979
|
1552 |
/// concept and could be indiced by the current item set of
|
deba@1979
|
1553 |
/// the BNodeMap. In this case the value for each item
|
deba@1979
|
1554 |
/// is assigned by the value of the given ReadMap.
|
deba@1979
|
1555 |
template <typename CMap>
|
deba@1979
|
1556 |
BNodeMap& operator=(const CMap& cmap) {
|
deba@1979
|
1557 |
checkConcept<concept::ReadMap<BNode, _Value>, CMap>();
|
deba@1979
|
1558 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1979
|
1559 |
BNode it;
|
deba@1979
|
1560 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1979
|
1561 |
Parent::set(it, cmap[it]);
|
deba@1979
|
1562 |
}
|
deba@1979
|
1563 |
return *this;
|
deba@1979
|
1564 |
}
|
deba@1979
|
1565 |
|
deba@1979
|
1566 |
};
|
deba@1979
|
1567 |
|
deba@1979
|
1568 |
protected:
|
deba@1979
|
1569 |
|
deba@1979
|
1570 |
template <typename _Value>
|
deba@1979
|
1571 |
class NodeMapBase : public NodeNotifier::ObserverBase {
|
deba@1979
|
1572 |
public:
|
deba@1979
|
1573 |
typedef BpUGraphExtender Graph;
|
deba@1979
|
1574 |
|
deba@1979
|
1575 |
typedef Node Key;
|
deba@1979
|
1576 |
typedef _Value Value;
|
deba@1979
|
1577 |
|
deba@1979
|
1578 |
/// The reference type of the map;
|
deba@1979
|
1579 |
typedef typename BNodeMap<_Value>::Reference Reference;
|
deba@1979
|
1580 |
/// The pointer type of the map;
|
deba@1979
|
1581 |
typedef typename BNodeMap<_Value>::Pointer Pointer;
|
deba@1979
|
1582 |
|
deba@1979
|
1583 |
/// The const value type of the map.
|
deba@1979
|
1584 |
typedef const Value ConstValue;
|
deba@1979
|
1585 |
/// The const reference type of the map;
|
deba@1979
|
1586 |
typedef typename BNodeMap<_Value>::ConstReference ConstReference;
|
deba@1979
|
1587 |
/// The pointer type of the map;
|
deba@1979
|
1588 |
typedef typename BNodeMap<_Value>::ConstPointer ConstPointer;
|
deba@1979
|
1589 |
|
deba@1979
|
1590 |
typedef True ReferenceMapTag;
|
deba@1979
|
1591 |
|
deba@1979
|
1592 |
NodeMapBase(const Graph& _g)
|
deba@1979
|
1593 |
: graph(&_g), bNodeMap(_g), aNodeMap(_g) {
|
deba@1979
|
1594 |
NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
|
deba@1979
|
1595 |
}
|
deba@1979
|
1596 |
NodeMapBase(const Graph& _g, const _Value& _v)
|
deba@1979
|
1597 |
: graph(&_g), bNodeMap(_g, _v),
|
deba@1979
|
1598 |
aNodeMap(_g, _v) {
|
deba@1979
|
1599 |
NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
|
deba@1979
|
1600 |
}
|
deba@1979
|
1601 |
|
deba@1979
|
1602 |
virtual ~NodeMapBase() {
|
deba@1979
|
1603 |
if (NodeNotifier::ObserverBase::attached()) {
|
deba@1979
|
1604 |
NodeNotifier::ObserverBase::detach();
|
deba@1979
|
1605 |
}
|
deba@1979
|
1606 |
}
|
deba@1979
|
1607 |
|
deba@1979
|
1608 |
ConstReference operator[](const Key& node) const {
|
deba@1979
|
1609 |
if (Parent::aNode(node)) {
|
deba@1979
|
1610 |
return aNodeMap[node];
|
deba@1979
|
1611 |
} else {
|
deba@1979
|
1612 |
return bNodeMap[node];
|
deba@1979
|
1613 |
}
|
deba@1979
|
1614 |
}
|
deba@1979
|
1615 |
|
deba@1979
|
1616 |
Reference operator[](const Key& node) {
|
deba@1979
|
1617 |
if (Parent::aNode(node)) {
|
deba@1979
|
1618 |
return aNodeMap[node];
|
deba@1979
|
1619 |
} else {
|
deba@1979
|
1620 |
return bNodeMap[node];
|
deba@1979
|
1621 |
}
|
deba@1979
|
1622 |
}
|
deba@1979
|
1623 |
|
deba@1979
|
1624 |
void set(const Key& node, const Value& value) {
|
deba@1979
|
1625 |
if (Parent::aNode(node)) {
|
deba@1979
|
1626 |
aNodeMap.set(node, value);
|
deba@1979
|
1627 |
} else {
|
deba@1979
|
1628 |
bNodeMap.set(node, value);
|
deba@1979
|
1629 |
}
|
deba@1979
|
1630 |
}
|
deba@1979
|
1631 |
|
deba@1979
|
1632 |
protected:
|
deba@1979
|
1633 |
|
deba@1979
|
1634 |
virtual void add(const Node&) {}
|
deba@1979
|
1635 |
virtual void add(const std::vector<Node>&) {}
|
deba@1979
|
1636 |
virtual void erase(const Node&) {}
|
deba@1979
|
1637 |
virtual void erase(const std::vector<Node>&) {}
|
deba@1979
|
1638 |
virtual void clear() {}
|
deba@1979
|
1639 |
virtual void build() {}
|
deba@1979
|
1640 |
|
deba@1979
|
1641 |
const Graph* getGraph() const { return graph; }
|
deba@1979
|
1642 |
|
deba@1979
|
1643 |
private:
|
deba@1979
|
1644 |
const Graph* graph;
|
deba@1979
|
1645 |
BNodeMap<_Value> bNodeMap;
|
deba@1979
|
1646 |
ANodeMap<_Value> aNodeMap;
|
deba@1979
|
1647 |
};
|
deba@1979
|
1648 |
|
deba@1979
|
1649 |
public:
|
deba@1979
|
1650 |
|
deba@1979
|
1651 |
template <typename _Value>
|
deba@1979
|
1652 |
class NodeMap
|
deba@1979
|
1653 |
: public IterableMapExtender<NodeMapBase<_Value> > {
|
deba@1979
|
1654 |
public:
|
deba@1979
|
1655 |
typedef BpUGraphExtender Graph;
|
deba@1979
|
1656 |
typedef IterableMapExtender< NodeMapBase<_Value> > Parent;
|
deba@1979
|
1657 |
|
deba@1979
|
1658 |
NodeMap(const Graph& _g)
|
deba@1979
|
1659 |
: Parent(_g) {}
|
deba@1979
|
1660 |
NodeMap(const Graph& _g, const _Value& _v)
|
deba@1979
|
1661 |
: Parent(_g, _v) {}
|
deba@1979
|
1662 |
|
deba@1979
|
1663 |
NodeMap& operator=(const NodeMap& cmap) {
|
deba@1979
|
1664 |
return operator=<NodeMap>(cmap);
|
deba@1979
|
1665 |
}
|
deba@1979
|
1666 |
|
deba@1979
|
1667 |
|
deba@1979
|
1668 |
/// \brief Template assign operator.
|
deba@1979
|
1669 |
///
|
deba@1979
|
1670 |
/// The given parameter should be conform to the ReadMap
|
deba@1979
|
1671 |
/// concept and could be indiced by the current item set of
|
deba@1979
|
1672 |
/// the NodeMap. In this case the value for each item
|
deba@1979
|
1673 |
/// is assigned by the value of the given ReadMap.
|
deba@1979
|
1674 |
template <typename CMap>
|
deba@1979
|
1675 |
NodeMap& operator=(const CMap& cmap) {
|
deba@1979
|
1676 |
checkConcept<concept::ReadMap<Node, _Value>, CMap>();
|
deba@1979
|
1677 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1979
|
1678 |
Node it;
|
deba@1979
|
1679 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1979
|
1680 |
Parent::set(it, cmap[it]);
|
deba@1979
|
1681 |
}
|
deba@1979
|
1682 |
return *this;
|
deba@1979
|
1683 |
}
|
deba@1979
|
1684 |
|
deba@1979
|
1685 |
};
|
deba@1979
|
1686 |
|
deba@1979
|
1687 |
|
deba@1979
|
1688 |
|
deba@1979
|
1689 |
template <typename _Value>
|
deba@1979
|
1690 |
class EdgeMap
|
deba@1979
|
1691 |
: public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
|
deba@1979
|
1692 |
public:
|
deba@1979
|
1693 |
typedef BpUGraphExtender Graph;
|
deba@1979
|
1694 |
typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
|
deba@1979
|
1695 |
|
deba@1979
|
1696 |
EdgeMap(const Graph& _g)
|
deba@1979
|
1697 |
: Parent(_g) {}
|
deba@1979
|
1698 |
EdgeMap(const Graph& _g, const _Value& _v)
|
deba@1979
|
1699 |
: Parent(_g, _v) {}
|
deba@1979
|
1700 |
|
deba@1979
|
1701 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
deba@1979
|
1702 |
return operator=<EdgeMap>(cmap);
|
deba@1979
|
1703 |
}
|
deba@1979
|
1704 |
|
deba@1979
|
1705 |
template <typename CMap>
|
deba@1979
|
1706 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@1979
|
1707 |
checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
|
deba@1979
|
1708 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1979
|
1709 |
Edge it;
|
deba@1979
|
1710 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1979
|
1711 |
Parent::set(it, cmap[it]);
|
deba@1979
|
1712 |
}
|
deba@1979
|
1713 |
return *this;
|
deba@1979
|
1714 |
}
|
deba@1979
|
1715 |
};
|
deba@1979
|
1716 |
|
deba@1979
|
1717 |
template <typename _Value>
|
deba@1979
|
1718 |
class UEdgeMap
|
deba@1979
|
1719 |
: public IterableMapExtender<DefaultMap<Graph, UEdge, _Value> > {
|
deba@1979
|
1720 |
public:
|
deba@1979
|
1721 |
typedef BpUGraphExtender Graph;
|
deba@1979
|
1722 |
typedef IterableMapExtender<DefaultMap<Graph, UEdge, _Value> >
|
deba@1979
|
1723 |
Parent;
|
deba@1979
|
1724 |
|
deba@1979
|
1725 |
UEdgeMap(const Graph& _g)
|
deba@1979
|
1726 |
: Parent(_g) {}
|
deba@1979
|
1727 |
UEdgeMap(const Graph& _g, const _Value& _v)
|
deba@1979
|
1728 |
: Parent(_g, _v) {}
|
deba@1979
|
1729 |
|
deba@1979
|
1730 |
UEdgeMap& operator=(const UEdgeMap& cmap) {
|
deba@1979
|
1731 |
return operator=<UEdgeMap>(cmap);
|
deba@1979
|
1732 |
}
|
deba@1979
|
1733 |
|
deba@1979
|
1734 |
template <typename CMap>
|
deba@1979
|
1735 |
UEdgeMap& operator=(const CMap& cmap) {
|
deba@1979
|
1736 |
checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
|
deba@1979
|
1737 |
const typename Parent::Graph* graph = Parent::getGraph();
|
deba@1979
|
1738 |
UEdge it;
|
deba@1979
|
1739 |
for (graph->first(it); it != INVALID; graph->next(it)) {
|
deba@1979
|
1740 |
Parent::set(it, cmap[it]);
|
deba@1979
|
1741 |
}
|
deba@1979
|
1742 |
return *this;
|
deba@1979
|
1743 |
}
|
deba@1979
|
1744 |
};
|
deba@1979
|
1745 |
|
deba@1979
|
1746 |
|
deba@1979
|
1747 |
Node addANode() {
|
deba@1979
|
1748 |
Node node = Parent::addANode();
|
deba@1979
|
1749 |
getNotifier(ANode()).add(node);
|
deba@1979
|
1750 |
getNotifier(Node()).add(node);
|
deba@1979
|
1751 |
return node;
|
deba@1979
|
1752 |
}
|
deba@1979
|
1753 |
|
deba@1979
|
1754 |
Node addBNode() {
|
deba@1979
|
1755 |
Node node = Parent::addBNode();
|
deba@1979
|
1756 |
getNotifier(BNode()).add(node);
|
deba@1979
|
1757 |
getNotifier(Node()).add(node);
|
deba@1979
|
1758 |
return node;
|
deba@1979
|
1759 |
}
|
deba@1979
|
1760 |
|
deba@1979
|
1761 |
UEdge addEdge(const Node& source, const Node& target) {
|
deba@1979
|
1762 |
UEdge uedge = Parent::addEdge(source, target);
|
deba@1979
|
1763 |
getNotifier(UEdge()).add(uedge);
|
deba@1979
|
1764 |
|
deba@1979
|
1765 |
std::vector<Edge> edges;
|
deba@1979
|
1766 |
edges.push_back(direct(uedge, true));
|
deba@1979
|
1767 |
edges.push_back(direct(uedge, false));
|
deba@1979
|
1768 |
getNotifier(Edge()).add(edges);
|
deba@1979
|
1769 |
|
deba@1979
|
1770 |
return uedge;
|
deba@1979
|
1771 |
}
|
deba@1979
|
1772 |
|
deba@1979
|
1773 |
void clear() {
|
deba@1979
|
1774 |
getNotifier(Edge()).clear();
|
deba@1979
|
1775 |
getNotifier(UEdge()).clear();
|
deba@1979
|
1776 |
getNotifier(Node()).clear();
|
deba@1979
|
1777 |
getNotifier(BNode()).clear();
|
deba@1979
|
1778 |
getNotifier(ANode()).clear();
|
deba@1979
|
1779 |
Parent::clear();
|
deba@1979
|
1780 |
}
|
deba@1979
|
1781 |
|
deba@1979
|
1782 |
void erase(const Node& node) {
|
deba@1979
|
1783 |
UEdge uedge;
|
deba@1979
|
1784 |
bool dir;
|
deba@1979
|
1785 |
Parent::firstInc(uedge, dir, node);
|
deba@1979
|
1786 |
while (uedge != INVALID ) {
|
deba@1979
|
1787 |
erase(uedge);
|
deba@1979
|
1788 |
Parent::firstInc(uedge, dir, node);
|
deba@1979
|
1789 |
}
|
deba@1979
|
1790 |
|
deba@1979
|
1791 |
getNotifier(Node()).erase(node);
|
deba@1979
|
1792 |
Parent::erase(node);
|
deba@1979
|
1793 |
}
|
deba@1979
|
1794 |
|
deba@1979
|
1795 |
void erase(const UEdge& uedge) {
|
deba@1979
|
1796 |
std::vector<Edge> edges;
|
deba@1979
|
1797 |
edges.push_back(direct(uedge, true));
|
deba@1979
|
1798 |
edges.push_back(direct(uedge, false));
|
deba@1979
|
1799 |
getNotifier(Edge()).erase(edges);
|
deba@1979
|
1800 |
getNotifier(UEdge()).erase(uedge);
|
deba@1979
|
1801 |
Parent::erase(uedge);
|
deba@1979
|
1802 |
}
|
deba@1979
|
1803 |
|
deba@1979
|
1804 |
|
deba@1979
|
1805 |
~BpUGraphExtender() {
|
deba@1979
|
1806 |
getNotifier(Edge()).clear();
|
deba@1979
|
1807 |
getNotifier(UEdge()).clear();
|
deba@1979
|
1808 |
getNotifier(Node()).clear();
|
deba@1979
|
1809 |
getNotifier(BNode()).clear();
|
deba@1979
|
1810 |
getNotifier(ANode()).clear();
|
deba@1979
|
1811 |
}
|
deba@1979
|
1812 |
|
deba@1979
|
1813 |
|
deba@1820
|
1814 |
};
|
deba@1820
|
1815 |
|
deba@1791
|
1816 |
}
|
deba@1791
|
1817 |
|
deba@1791
|
1818 |
#endif // LEMON_UNDIR_GRAPH_EXTENDER_H
|