alpar@877
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
deba@468
|
2 |
*
|
alpar@877
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
deba@468
|
4 |
*
|
alpar@877
|
5 |
* Copyright (C) 2003-2010
|
deba@468
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@468
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@468
|
8 |
*
|
deba@468
|
9 |
* Permission to use, modify and distribute this software is granted
|
deba@468
|
10 |
* provided that this copyright notice appears in all copies. For
|
deba@468
|
11 |
* precise terms see the accompanying LICENSE file.
|
deba@468
|
12 |
*
|
deba@468
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@468
|
14 |
* express or implied, and with no claim as to its suitability for any
|
deba@468
|
15 |
* purpose.
|
deba@468
|
16 |
*
|
deba@468
|
17 |
*/
|
deba@468
|
18 |
|
deba@468
|
19 |
#ifndef LEMON_BITS_EDGE_SET_EXTENDER_H
|
deba@468
|
20 |
#define LEMON_BITS_EDGE_SET_EXTENDER_H
|
deba@468
|
21 |
|
deba@519
|
22 |
#include <lemon/core.h>
|
deba@468
|
23 |
#include <lemon/error.h>
|
deba@468
|
24 |
#include <lemon/bits/default_map.h>
|
deba@519
|
25 |
#include <lemon/bits/map_extender.h>
|
deba@468
|
26 |
|
kpeter@559
|
27 |
//\ingroup digraphbits
|
kpeter@559
|
28 |
//\file
|
kpeter@559
|
29 |
//\brief Extenders for the arc set types
|
deba@468
|
30 |
namespace lemon {
|
deba@468
|
31 |
|
kpeter@559
|
32 |
// \ingroup digraphbits
|
kpeter@559
|
33 |
//
|
kpeter@559
|
34 |
// \brief Extender for the ArcSets
|
deba@468
|
35 |
template <typename Base>
|
deba@468
|
36 |
class ArcSetExtender : public Base {
|
kpeter@617
|
37 |
typedef Base Parent;
|
kpeter@617
|
38 |
|
deba@468
|
39 |
public:
|
deba@468
|
40 |
|
deba@468
|
41 |
typedef ArcSetExtender Digraph;
|
deba@468
|
42 |
|
deba@468
|
43 |
// Base extensions
|
deba@468
|
44 |
|
deba@468
|
45 |
typedef typename Parent::Node Node;
|
deba@468
|
46 |
typedef typename Parent::Arc Arc;
|
deba@468
|
47 |
|
deba@468
|
48 |
int maxId(Node) const {
|
deba@468
|
49 |
return Parent::maxNodeId();
|
deba@468
|
50 |
}
|
deba@468
|
51 |
|
deba@468
|
52 |
int maxId(Arc) const {
|
deba@468
|
53 |
return Parent::maxArcId();
|
deba@468
|
54 |
}
|
deba@468
|
55 |
|
deba@468
|
56 |
Node fromId(int id, Node) const {
|
deba@468
|
57 |
return Parent::nodeFromId(id);
|
deba@468
|
58 |
}
|
deba@468
|
59 |
|
deba@468
|
60 |
Arc fromId(int id, Arc) const {
|
deba@468
|
61 |
return Parent::arcFromId(id);
|
deba@468
|
62 |
}
|
deba@468
|
63 |
|
deba@468
|
64 |
Node oppositeNode(const Node &n, const Arc &e) const {
|
deba@468
|
65 |
if (n == Parent::source(e))
|
alpar@877
|
66 |
return Parent::target(e);
|
deba@468
|
67 |
else if(n==Parent::target(e))
|
alpar@877
|
68 |
return Parent::source(e);
|
deba@468
|
69 |
else
|
alpar@877
|
70 |
return INVALID;
|
deba@468
|
71 |
}
|
deba@468
|
72 |
|
deba@468
|
73 |
|
deba@468
|
74 |
// Alteration notifier extensions
|
deba@468
|
75 |
|
kpeter@559
|
76 |
// The arc observer registry.
|
deba@468
|
77 |
typedef AlterationNotifier<ArcSetExtender, Arc> ArcNotifier;
|
deba@468
|
78 |
|
deba@468
|
79 |
protected:
|
deba@468
|
80 |
|
deba@468
|
81 |
mutable ArcNotifier arc_notifier;
|
deba@468
|
82 |
|
deba@468
|
83 |
public:
|
deba@468
|
84 |
|
deba@468
|
85 |
using Parent::notifier;
|
deba@468
|
86 |
|
kpeter@559
|
87 |
// Gives back the arc alteration notifier.
|
deba@468
|
88 |
ArcNotifier& notifier(Arc) const {
|
deba@468
|
89 |
return arc_notifier;
|
deba@468
|
90 |
}
|
deba@468
|
91 |
|
deba@468
|
92 |
// Iterable extensions
|
deba@468
|
93 |
|
alpar@877
|
94 |
class NodeIt : public Node {
|
deba@468
|
95 |
const Digraph* digraph;
|
deba@468
|
96 |
public:
|
deba@468
|
97 |
|
deba@468
|
98 |
NodeIt() {}
|
deba@468
|
99 |
|
deba@468
|
100 |
NodeIt(Invalid i) : Node(i) { }
|
deba@468
|
101 |
|
deba@468
|
102 |
explicit NodeIt(const Digraph& _graph) : digraph(&_graph) {
|
alpar@877
|
103 |
_graph.first(static_cast<Node&>(*this));
|
deba@468
|
104 |
}
|
deba@468
|
105 |
|
alpar@877
|
106 |
NodeIt(const Digraph& _graph, const Node& node)
|
alpar@877
|
107 |
: Node(node), digraph(&_graph) {}
|
deba@468
|
108 |
|
alpar@877
|
109 |
NodeIt& operator++() {
|
alpar@877
|
110 |
digraph->next(*this);
|
alpar@877
|
111 |
return *this;
|
deba@468
|
112 |
}
|
deba@468
|
113 |
|
deba@468
|
114 |
};
|
deba@468
|
115 |
|
deba@468
|
116 |
|
alpar@877
|
117 |
class ArcIt : public Arc {
|
deba@468
|
118 |
const Digraph* digraph;
|
deba@468
|
119 |
public:
|
deba@468
|
120 |
|
deba@468
|
121 |
ArcIt() { }
|
deba@468
|
122 |
|
deba@468
|
123 |
ArcIt(Invalid i) : Arc(i) { }
|
deba@468
|
124 |
|
deba@468
|
125 |
explicit ArcIt(const Digraph& _graph) : digraph(&_graph) {
|
alpar@877
|
126 |
_graph.first(static_cast<Arc&>(*this));
|
deba@468
|
127 |
}
|
deba@468
|
128 |
|
alpar@877
|
129 |
ArcIt(const Digraph& _graph, const Arc& e) :
|
alpar@877
|
130 |
Arc(e), digraph(&_graph) { }
|
deba@468
|
131 |
|
alpar@877
|
132 |
ArcIt& operator++() {
|
alpar@877
|
133 |
digraph->next(*this);
|
alpar@877
|
134 |
return *this;
|
deba@468
|
135 |
}
|
deba@468
|
136 |
|
deba@468
|
137 |
};
|
deba@468
|
138 |
|
deba@468
|
139 |
|
alpar@877
|
140 |
class OutArcIt : public Arc {
|
deba@468
|
141 |
const Digraph* digraph;
|
deba@468
|
142 |
public:
|
deba@468
|
143 |
|
deba@468
|
144 |
OutArcIt() { }
|
deba@468
|
145 |
|
deba@468
|
146 |
OutArcIt(Invalid i) : Arc(i) { }
|
deba@468
|
147 |
|
alpar@877
|
148 |
OutArcIt(const Digraph& _graph, const Node& node)
|
alpar@877
|
149 |
: digraph(&_graph) {
|
alpar@877
|
150 |
_graph.firstOut(*this, node);
|
deba@468
|
151 |
}
|
deba@468
|
152 |
|
alpar@877
|
153 |
OutArcIt(const Digraph& _graph, const Arc& arc)
|
alpar@877
|
154 |
: Arc(arc), digraph(&_graph) {}
|
deba@468
|
155 |
|
alpar@877
|
156 |
OutArcIt& operator++() {
|
alpar@877
|
157 |
digraph->nextOut(*this);
|
alpar@877
|
158 |
return *this;
|
deba@468
|
159 |
}
|
deba@468
|
160 |
|
deba@468
|
161 |
};
|
deba@468
|
162 |
|
deba@468
|
163 |
|
alpar@877
|
164 |
class InArcIt : public Arc {
|
deba@468
|
165 |
const Digraph* digraph;
|
deba@468
|
166 |
public:
|
deba@468
|
167 |
|
deba@468
|
168 |
InArcIt() { }
|
deba@468
|
169 |
|
deba@468
|
170 |
InArcIt(Invalid i) : Arc(i) { }
|
deba@468
|
171 |
|
alpar@877
|
172 |
InArcIt(const Digraph& _graph, const Node& node)
|
alpar@877
|
173 |
: digraph(&_graph) {
|
alpar@877
|
174 |
_graph.firstIn(*this, node);
|
deba@468
|
175 |
}
|
deba@468
|
176 |
|
alpar@877
|
177 |
InArcIt(const Digraph& _graph, const Arc& arc) :
|
alpar@877
|
178 |
Arc(arc), digraph(&_graph) {}
|
deba@468
|
179 |
|
alpar@877
|
180 |
InArcIt& operator++() {
|
alpar@877
|
181 |
digraph->nextIn(*this);
|
alpar@877
|
182 |
return *this;
|
deba@468
|
183 |
}
|
deba@468
|
184 |
|
deba@468
|
185 |
};
|
deba@468
|
186 |
|
kpeter@559
|
187 |
// \brief Base node of the iterator
|
kpeter@559
|
188 |
//
|
kpeter@559
|
189 |
// Returns the base node (ie. the source in this case) of the iterator
|
deba@468
|
190 |
Node baseNode(const OutArcIt &e) const {
|
deba@468
|
191 |
return Parent::source(static_cast<const Arc&>(e));
|
deba@468
|
192 |
}
|
kpeter@559
|
193 |
// \brief Running node of the iterator
|
kpeter@559
|
194 |
//
|
kpeter@559
|
195 |
// Returns the running node (ie. the target in this case) of the
|
kpeter@559
|
196 |
// iterator
|
deba@468
|
197 |
Node runningNode(const OutArcIt &e) const {
|
deba@468
|
198 |
return Parent::target(static_cast<const Arc&>(e));
|
deba@468
|
199 |
}
|
deba@468
|
200 |
|
kpeter@559
|
201 |
// \brief Base node of the iterator
|
kpeter@559
|
202 |
//
|
kpeter@559
|
203 |
// Returns the base node (ie. the target in this case) of the iterator
|
deba@468
|
204 |
Node baseNode(const InArcIt &e) const {
|
deba@468
|
205 |
return Parent::target(static_cast<const Arc&>(e));
|
deba@468
|
206 |
}
|
kpeter@559
|
207 |
// \brief Running node of the iterator
|
kpeter@559
|
208 |
//
|
kpeter@559
|
209 |
// Returns the running node (ie. the source in this case) of the
|
kpeter@559
|
210 |
// iterator
|
deba@468
|
211 |
Node runningNode(const InArcIt &e) const {
|
deba@468
|
212 |
return Parent::source(static_cast<const Arc&>(e));
|
deba@468
|
213 |
}
|
deba@468
|
214 |
|
deba@468
|
215 |
using Parent::first;
|
deba@468
|
216 |
|
deba@468
|
217 |
// Mappable extension
|
alpar@877
|
218 |
|
deba@468
|
219 |
template <typename _Value>
|
alpar@877
|
220 |
class ArcMap
|
deba@468
|
221 |
: public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
|
deba@468
|
222 |
typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
|
deba@468
|
223 |
|
kpeter@617
|
224 |
public:
|
alpar@877
|
225 |
explicit ArcMap(const Digraph& _g)
|
alpar@877
|
226 |
: Parent(_g) {}
|
alpar@877
|
227 |
ArcMap(const Digraph& _g, const _Value& _v)
|
alpar@877
|
228 |
: Parent(_g, _v) {}
|
deba@468
|
229 |
|
deba@468
|
230 |
ArcMap& operator=(const ArcMap& cmap) {
|
alpar@877
|
231 |
return operator=<ArcMap>(cmap);
|
deba@468
|
232 |
}
|
deba@468
|
233 |
|
deba@468
|
234 |
template <typename CMap>
|
deba@468
|
235 |
ArcMap& operator=(const CMap& cmap) {
|
deba@468
|
236 |
Parent::operator=(cmap);
|
alpar@877
|
237 |
return *this;
|
deba@468
|
238 |
}
|
deba@468
|
239 |
|
deba@468
|
240 |
};
|
deba@468
|
241 |
|
deba@468
|
242 |
|
deba@468
|
243 |
// Alteration extension
|
deba@468
|
244 |
|
deba@468
|
245 |
Arc addArc(const Node& from, const Node& to) {
|
deba@468
|
246 |
Arc arc = Parent::addArc(from, to);
|
deba@468
|
247 |
notifier(Arc()).add(arc);
|
deba@468
|
248 |
return arc;
|
deba@468
|
249 |
}
|
alpar@877
|
250 |
|
deba@468
|
251 |
void clear() {
|
deba@468
|
252 |
notifier(Arc()).clear();
|
deba@468
|
253 |
Parent::clear();
|
deba@468
|
254 |
}
|
deba@468
|
255 |
|
deba@468
|
256 |
void erase(const Arc& arc) {
|
deba@468
|
257 |
notifier(Arc()).erase(arc);
|
deba@468
|
258 |
Parent::erase(arc);
|
deba@468
|
259 |
}
|
deba@468
|
260 |
|
deba@468
|
261 |
ArcSetExtender() {
|
deba@468
|
262 |
arc_notifier.setContainer(*this);
|
deba@468
|
263 |
}
|
deba@468
|
264 |
|
deba@468
|
265 |
~ArcSetExtender() {
|
deba@468
|
266 |
arc_notifier.clear();
|
deba@468
|
267 |
}
|
deba@468
|
268 |
|
deba@468
|
269 |
};
|
deba@468
|
270 |
|
deba@468
|
271 |
|
kpeter@559
|
272 |
// \ingroup digraphbits
|
kpeter@559
|
273 |
//
|
kpeter@559
|
274 |
// \brief Extender for the EdgeSets
|
deba@468
|
275 |
template <typename Base>
|
deba@468
|
276 |
class EdgeSetExtender : public Base {
|
kpeter@617
|
277 |
typedef Base Parent;
|
deba@468
|
278 |
|
deba@468
|
279 |
public:
|
deba@468
|
280 |
|
kpeter@617
|
281 |
typedef EdgeSetExtender Graph;
|
deba@468
|
282 |
|
deba@468
|
283 |
typedef typename Parent::Node Node;
|
deba@468
|
284 |
typedef typename Parent::Arc Arc;
|
deba@468
|
285 |
typedef typename Parent::Edge Edge;
|
deba@468
|
286 |
|
deba@468
|
287 |
int maxId(Node) const {
|
deba@468
|
288 |
return Parent::maxNodeId();
|
deba@468
|
289 |
}
|
deba@468
|
290 |
|
deba@468
|
291 |
int maxId(Arc) const {
|
deba@468
|
292 |
return Parent::maxArcId();
|
deba@468
|
293 |
}
|
deba@468
|
294 |
|
deba@468
|
295 |
int maxId(Edge) const {
|
deba@468
|
296 |
return Parent::maxEdgeId();
|
deba@468
|
297 |
}
|
deba@468
|
298 |
|
deba@468
|
299 |
Node fromId(int id, Node) const {
|
deba@468
|
300 |
return Parent::nodeFromId(id);
|
deba@468
|
301 |
}
|
deba@468
|
302 |
|
deba@468
|
303 |
Arc fromId(int id, Arc) const {
|
deba@468
|
304 |
return Parent::arcFromId(id);
|
deba@468
|
305 |
}
|
deba@468
|
306 |
|
deba@468
|
307 |
Edge fromId(int id, Edge) const {
|
deba@468
|
308 |
return Parent::edgeFromId(id);
|
deba@468
|
309 |
}
|
deba@468
|
310 |
|
deba@468
|
311 |
Node oppositeNode(const Node &n, const Edge &e) const {
|
deba@468
|
312 |
if( n == Parent::u(e))
|
alpar@877
|
313 |
return Parent::v(e);
|
deba@468
|
314 |
else if( n == Parent::v(e))
|
alpar@877
|
315 |
return Parent::u(e);
|
deba@468
|
316 |
else
|
alpar@877
|
317 |
return INVALID;
|
deba@468
|
318 |
}
|
deba@468
|
319 |
|
deba@468
|
320 |
Arc oppositeArc(const Arc &e) const {
|
deba@468
|
321 |
return Parent::direct(e, !Parent::direction(e));
|
deba@468
|
322 |
}
|
deba@468
|
323 |
|
deba@468
|
324 |
using Parent::direct;
|
deba@468
|
325 |
Arc direct(const Edge &e, const Node &s) const {
|
deba@468
|
326 |
return Parent::direct(e, Parent::u(e) == s);
|
deba@468
|
327 |
}
|
deba@468
|
328 |
|
deba@468
|
329 |
typedef AlterationNotifier<EdgeSetExtender, Arc> ArcNotifier;
|
deba@468
|
330 |
typedef AlterationNotifier<EdgeSetExtender, Edge> EdgeNotifier;
|
deba@468
|
331 |
|
deba@468
|
332 |
|
deba@468
|
333 |
protected:
|
deba@468
|
334 |
|
deba@468
|
335 |
mutable ArcNotifier arc_notifier;
|
deba@468
|
336 |
mutable EdgeNotifier edge_notifier;
|
deba@468
|
337 |
|
deba@468
|
338 |
public:
|
deba@468
|
339 |
|
deba@468
|
340 |
using Parent::notifier;
|
alpar@877
|
341 |
|
deba@468
|
342 |
ArcNotifier& notifier(Arc) const {
|
deba@468
|
343 |
return arc_notifier;
|
deba@468
|
344 |
}
|
deba@468
|
345 |
|
deba@468
|
346 |
EdgeNotifier& notifier(Edge) const {
|
deba@468
|
347 |
return edge_notifier;
|
deba@468
|
348 |
}
|
deba@468
|
349 |
|
deba@468
|
350 |
|
alpar@877
|
351 |
class NodeIt : public Node {
|
kpeter@617
|
352 |
const Graph* graph;
|
deba@468
|
353 |
public:
|
deba@468
|
354 |
|
deba@468
|
355 |
NodeIt() {}
|
deba@468
|
356 |
|
deba@468
|
357 |
NodeIt(Invalid i) : Node(i) { }
|
deba@468
|
358 |
|
kpeter@617
|
359 |
explicit NodeIt(const Graph& _graph) : graph(&_graph) {
|
alpar@877
|
360 |
_graph.first(static_cast<Node&>(*this));
|
deba@468
|
361 |
}
|
deba@468
|
362 |
|
alpar@877
|
363 |
NodeIt(const Graph& _graph, const Node& node)
|
alpar@877
|
364 |
: Node(node), graph(&_graph) {}
|
deba@468
|
365 |
|
alpar@877
|
366 |
NodeIt& operator++() {
|
alpar@877
|
367 |
graph->next(*this);
|
alpar@877
|
368 |
return *this;
|
deba@468
|
369 |
}
|
deba@468
|
370 |
|
deba@468
|
371 |
};
|
deba@468
|
372 |
|
deba@468
|
373 |
|
alpar@877
|
374 |
class ArcIt : public Arc {
|
kpeter@617
|
375 |
const Graph* graph;
|
deba@468
|
376 |
public:
|
deba@468
|
377 |
|
deba@468
|
378 |
ArcIt() { }
|
deba@468
|
379 |
|
deba@468
|
380 |
ArcIt(Invalid i) : Arc(i) { }
|
deba@468
|
381 |
|
kpeter@617
|
382 |
explicit ArcIt(const Graph& _graph) : graph(&_graph) {
|
alpar@877
|
383 |
_graph.first(static_cast<Arc&>(*this));
|
deba@468
|
384 |
}
|
deba@468
|
385 |
|
alpar@877
|
386 |
ArcIt(const Graph& _graph, const Arc& e) :
|
alpar@877
|
387 |
Arc(e), graph(&_graph) { }
|
deba@468
|
388 |
|
alpar@877
|
389 |
ArcIt& operator++() {
|
alpar@877
|
390 |
graph->next(*this);
|
alpar@877
|
391 |
return *this;
|
deba@468
|
392 |
}
|
deba@468
|
393 |
|
deba@468
|
394 |
};
|
deba@468
|
395 |
|
deba@468
|
396 |
|
alpar@877
|
397 |
class OutArcIt : public Arc {
|
kpeter@617
|
398 |
const Graph* graph;
|
deba@468
|
399 |
public:
|
deba@468
|
400 |
|
deba@468
|
401 |
OutArcIt() { }
|
deba@468
|
402 |
|
deba@468
|
403 |
OutArcIt(Invalid i) : Arc(i) { }
|
deba@468
|
404 |
|
alpar@877
|
405 |
OutArcIt(const Graph& _graph, const Node& node)
|
alpar@877
|
406 |
: graph(&_graph) {
|
alpar@877
|
407 |
_graph.firstOut(*this, node);
|
deba@468
|
408 |
}
|
deba@468
|
409 |
|
alpar@877
|
410 |
OutArcIt(const Graph& _graph, const Arc& arc)
|
alpar@877
|
411 |
: Arc(arc), graph(&_graph) {}
|
deba@468
|
412 |
|
alpar@877
|
413 |
OutArcIt& operator++() {
|
alpar@877
|
414 |
graph->nextOut(*this);
|
alpar@877
|
415 |
return *this;
|
deba@468
|
416 |
}
|
deba@468
|
417 |
|
deba@468
|
418 |
};
|
deba@468
|
419 |
|
deba@468
|
420 |
|
alpar@877
|
421 |
class InArcIt : public Arc {
|
kpeter@617
|
422 |
const Graph* graph;
|
deba@468
|
423 |
public:
|
deba@468
|
424 |
|
deba@468
|
425 |
InArcIt() { }
|
deba@468
|
426 |
|
deba@468
|
427 |
InArcIt(Invalid i) : Arc(i) { }
|
deba@468
|
428 |
|
alpar@877
|
429 |
InArcIt(const Graph& _graph, const Node& node)
|
alpar@877
|
430 |
: graph(&_graph) {
|
alpar@877
|
431 |
_graph.firstIn(*this, node);
|
deba@468
|
432 |
}
|
deba@468
|
433 |
|
alpar@877
|
434 |
InArcIt(const Graph& _graph, const Arc& arc) :
|
alpar@877
|
435 |
Arc(arc), graph(&_graph) {}
|
deba@468
|
436 |
|
alpar@877
|
437 |
InArcIt& operator++() {
|
alpar@877
|
438 |
graph->nextIn(*this);
|
alpar@877
|
439 |
return *this;
|
deba@468
|
440 |
}
|
deba@468
|
441 |
|
deba@468
|
442 |
};
|
deba@468
|
443 |
|
deba@468
|
444 |
|
alpar@877
|
445 |
class EdgeIt : public Parent::Edge {
|
kpeter@617
|
446 |
const Graph* graph;
|
deba@468
|
447 |
public:
|
deba@468
|
448 |
|
deba@468
|
449 |
EdgeIt() { }
|
deba@468
|
450 |
|
deba@468
|
451 |
EdgeIt(Invalid i) : Edge(i) { }
|
deba@468
|
452 |
|
kpeter@617
|
453 |
explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
|
alpar@877
|
454 |
_graph.first(static_cast<Edge&>(*this));
|
deba@468
|
455 |
}
|
deba@468
|
456 |
|
alpar@877
|
457 |
EdgeIt(const Graph& _graph, const Edge& e) :
|
alpar@877
|
458 |
Edge(e), graph(&_graph) { }
|
deba@468
|
459 |
|
alpar@877
|
460 |
EdgeIt& operator++() {
|
alpar@877
|
461 |
graph->next(*this);
|
alpar@877
|
462 |
return *this;
|
deba@468
|
463 |
}
|
deba@468
|
464 |
|
deba@468
|
465 |
};
|
deba@468
|
466 |
|
deba@468
|
467 |
class IncEdgeIt : public Parent::Edge {
|
deba@468
|
468 |
friend class EdgeSetExtender;
|
kpeter@617
|
469 |
const Graph* graph;
|
deba@468
|
470 |
bool direction;
|
deba@468
|
471 |
public:
|
deba@468
|
472 |
|
deba@468
|
473 |
IncEdgeIt() { }
|
deba@468
|
474 |
|
deba@468
|
475 |
IncEdgeIt(Invalid i) : Edge(i), direction(false) { }
|
deba@468
|
476 |
|
kpeter@617
|
477 |
IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
|
alpar@877
|
478 |
_graph.firstInc(*this, direction, n);
|
deba@468
|
479 |
}
|
deba@468
|
480 |
|
kpeter@617
|
481 |
IncEdgeIt(const Graph& _graph, const Edge &ue, const Node &n)
|
alpar@877
|
482 |
: graph(&_graph), Edge(ue) {
|
alpar@877
|
483 |
direction = (_graph.source(ue) == n);
|
deba@468
|
484 |
}
|
deba@468
|
485 |
|
deba@468
|
486 |
IncEdgeIt& operator++() {
|
alpar@877
|
487 |
graph->nextInc(*this, direction);
|
alpar@877
|
488 |
return *this;
|
deba@468
|
489 |
}
|
deba@468
|
490 |
};
|
deba@468
|
491 |
|
kpeter@559
|
492 |
// \brief Base node of the iterator
|
kpeter@559
|
493 |
//
|
kpeter@559
|
494 |
// Returns the base node (ie. the source in this case) of the iterator
|
deba@468
|
495 |
Node baseNode(const OutArcIt &e) const {
|
deba@468
|
496 |
return Parent::source(static_cast<const Arc&>(e));
|
deba@468
|
497 |
}
|
kpeter@559
|
498 |
// \brief Running node of the iterator
|
kpeter@559
|
499 |
//
|
kpeter@559
|
500 |
// Returns the running node (ie. the target in this case) of the
|
kpeter@559
|
501 |
// iterator
|
deba@468
|
502 |
Node runningNode(const OutArcIt &e) const {
|
deba@468
|
503 |
return Parent::target(static_cast<const Arc&>(e));
|
deba@468
|
504 |
}
|
deba@468
|
505 |
|
kpeter@559
|
506 |
// \brief Base node of the iterator
|
kpeter@559
|
507 |
//
|
kpeter@559
|
508 |
// Returns the base node (ie. the target in this case) of the iterator
|
deba@468
|
509 |
Node baseNode(const InArcIt &e) const {
|
deba@468
|
510 |
return Parent::target(static_cast<const Arc&>(e));
|
deba@468
|
511 |
}
|
kpeter@559
|
512 |
// \brief Running node of the iterator
|
kpeter@559
|
513 |
//
|
kpeter@559
|
514 |
// Returns the running node (ie. the source in this case) of the
|
kpeter@559
|
515 |
// iterator
|
deba@468
|
516 |
Node runningNode(const InArcIt &e) const {
|
deba@468
|
517 |
return Parent::source(static_cast<const Arc&>(e));
|
deba@468
|
518 |
}
|
deba@468
|
519 |
|
kpeter@559
|
520 |
// Base node of the iterator
|
kpeter@559
|
521 |
//
|
kpeter@559
|
522 |
// Returns the base node of the iterator
|
deba@468
|
523 |
Node baseNode(const IncEdgeIt &e) const {
|
deba@468
|
524 |
return e.direction ? u(e) : v(e);
|
deba@468
|
525 |
}
|
kpeter@559
|
526 |
// Running node of the iterator
|
kpeter@559
|
527 |
//
|
kpeter@559
|
528 |
// Returns the running node of the iterator
|
deba@468
|
529 |
Node runningNode(const IncEdgeIt &e) const {
|
deba@468
|
530 |
return e.direction ? v(e) : u(e);
|
deba@468
|
531 |
}
|
deba@468
|
532 |
|
deba@468
|
533 |
|
deba@468
|
534 |
template <typename _Value>
|
alpar@877
|
535 |
class ArcMap
|
kpeter@617
|
536 |
: public MapExtender<DefaultMap<Graph, Arc, _Value> > {
|
kpeter@617
|
537 |
typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
|
kpeter@617
|
538 |
|
deba@468
|
539 |
public:
|
alpar@877
|
540 |
explicit ArcMap(const Graph& _g)
|
alpar@877
|
541 |
: Parent(_g) {}
|
alpar@877
|
542 |
ArcMap(const Graph& _g, const _Value& _v)
|
alpar@877
|
543 |
: Parent(_g, _v) {}
|
deba@468
|
544 |
|
deba@468
|
545 |
ArcMap& operator=(const ArcMap& cmap) {
|
alpar@877
|
546 |
return operator=<ArcMap>(cmap);
|
deba@468
|
547 |
}
|
deba@468
|
548 |
|
deba@468
|
549 |
template <typename CMap>
|
deba@468
|
550 |
ArcMap& operator=(const CMap& cmap) {
|
deba@468
|
551 |
Parent::operator=(cmap);
|
alpar@877
|
552 |
return *this;
|
deba@468
|
553 |
}
|
deba@468
|
554 |
|
deba@468
|
555 |
};
|
deba@468
|
556 |
|
deba@468
|
557 |
|
deba@468
|
558 |
template <typename _Value>
|
alpar@877
|
559 |
class EdgeMap
|
kpeter@617
|
560 |
: public MapExtender<DefaultMap<Graph, Edge, _Value> > {
|
kpeter@617
|
561 |
typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
|
kpeter@617
|
562 |
|
deba@468
|
563 |
public:
|
alpar@877
|
564 |
explicit EdgeMap(const Graph& _g)
|
alpar@877
|
565 |
: Parent(_g) {}
|
deba@468
|
566 |
|
alpar@877
|
567 |
EdgeMap(const Graph& _g, const _Value& _v)
|
alpar@877
|
568 |
: Parent(_g, _v) {}
|
deba@468
|
569 |
|
deba@468
|
570 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
alpar@877
|
571 |
return operator=<EdgeMap>(cmap);
|
deba@468
|
572 |
}
|
deba@468
|
573 |
|
deba@468
|
574 |
template <typename CMap>
|
deba@468
|
575 |
EdgeMap& operator=(const CMap& cmap) {
|
deba@468
|
576 |
Parent::operator=(cmap);
|
alpar@877
|
577 |
return *this;
|
deba@468
|
578 |
}
|
deba@468
|
579 |
|
deba@468
|
580 |
};
|
deba@468
|
581 |
|
deba@468
|
582 |
|
deba@468
|
583 |
// Alteration extension
|
deba@468
|
584 |
|
deba@468
|
585 |
Edge addEdge(const Node& from, const Node& to) {
|
deba@468
|
586 |
Edge edge = Parent::addEdge(from, to);
|
deba@468
|
587 |
notifier(Edge()).add(edge);
|
deba@468
|
588 |
std::vector<Arc> arcs;
|
deba@468
|
589 |
arcs.push_back(Parent::direct(edge, true));
|
deba@468
|
590 |
arcs.push_back(Parent::direct(edge, false));
|
deba@468
|
591 |
notifier(Arc()).add(arcs);
|
deba@468
|
592 |
return edge;
|
deba@468
|
593 |
}
|
alpar@877
|
594 |
|
deba@468
|
595 |
void clear() {
|
deba@468
|
596 |
notifier(Arc()).clear();
|
deba@468
|
597 |
notifier(Edge()).clear();
|
deba@468
|
598 |
Parent::clear();
|
deba@468
|
599 |
}
|
deba@468
|
600 |
|
deba@468
|
601 |
void erase(const Edge& edge) {
|
deba@468
|
602 |
std::vector<Arc> arcs;
|
deba@468
|
603 |
arcs.push_back(Parent::direct(edge, true));
|
deba@468
|
604 |
arcs.push_back(Parent::direct(edge, false));
|
deba@468
|
605 |
notifier(Arc()).erase(arcs);
|
deba@468
|
606 |
notifier(Edge()).erase(edge);
|
deba@468
|
607 |
Parent::erase(edge);
|
deba@468
|
608 |
}
|
deba@468
|
609 |
|
deba@468
|
610 |
|
deba@468
|
611 |
EdgeSetExtender() {
|
deba@468
|
612 |
arc_notifier.setContainer(*this);
|
deba@468
|
613 |
edge_notifier.setContainer(*this);
|
deba@468
|
614 |
}
|
deba@468
|
615 |
|
deba@468
|
616 |
~EdgeSetExtender() {
|
deba@468
|
617 |
edge_notifier.clear();
|
deba@468
|
618 |
arc_notifier.clear();
|
deba@468
|
619 |
}
|
alpar@877
|
620 |
|
deba@468
|
621 |
};
|
deba@468
|
622 |
|
deba@468
|
623 |
}
|
deba@468
|
624 |
|
deba@468
|
625 |
#endif
|