1 | 1 |
/* -*- C++ -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2007 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#ifndef LEMON_BITS_GRAPH_EXTENDER_H |
20 | 20 |
#define LEMON_BITS_GRAPH_EXTENDER_H |
21 | 21 |
|
22 | 22 |
#include <lemon/bits/invalid.h> |
23 |
#include <lemon/bits/utility.h> |
|
23 | 24 |
|
24 | 25 |
#include <lemon/bits/map_extender.h> |
25 | 26 |
#include <lemon/bits/default_map.h> |
26 | 27 |
|
27 | 28 |
#include <lemon/concept_check.h> |
28 | 29 |
#include <lemon/concepts/maps.h> |
29 | 30 |
|
30 | 31 |
///\ingroup graphbits |
31 | 32 |
///\file |
32 | 33 |
///\brief Extenders for the digraph types |
33 | 34 |
namespace lemon { |
34 | 35 |
|
35 | 36 |
/// \ingroup graphbits |
36 | 37 |
/// |
37 | 38 |
/// \brief Extender for the Digraphs |
38 | 39 |
template <typename Base> |
39 | 40 |
class DigraphExtender : public Base { |
40 | 41 |
public: |
41 | 42 |
|
42 | 43 |
typedef Base Parent; |
43 | 44 |
typedef DigraphExtender Digraph; |
44 | 45 |
|
45 | 46 |
// Base extensions |
46 | 47 |
|
47 | 48 |
typedef typename Parent::Node Node; |
48 | 49 |
typedef typename Parent::Arc Arc; |
49 | 50 |
|
50 | 51 |
int maxId(Node) const { |
51 | 52 |
return Parent::maxNodeId(); |
52 | 53 |
} |
53 | 54 |
|
54 | 55 |
int maxId(Arc) const { |
55 | 56 |
return Parent::maxArcId(); |
56 | 57 |
} |
57 | 58 |
|
58 | 59 |
Node fromId(int id, Node) const { |
59 | 60 |
return Parent::nodeFromId(id); |
60 | 61 |
} |
61 | 62 |
|
62 | 63 |
Arc fromId(int id, Arc) const { |
63 | 64 |
return Parent::arcFromId(id); |
64 | 65 |
} |
65 | 66 |
|
66 | 67 |
Node oppositeNode(const Node &n, const Arc &e) const { |
67 | 68 |
if (n == Parent::source(e)) |
68 | 69 |
return Parent::target(e); |
69 | 70 |
else if(n==Parent::target(e)) |
70 | 71 |
return Parent::source(e); |
... | ... |
@@ -288,96 +289,98 @@ |
288 | 289 |
notifier(Arc()).build(); |
289 | 290 |
} |
290 | 291 |
|
291 | 292 |
void erase(const Node& node) { |
292 | 293 |
Arc arc; |
293 | 294 |
Parent::firstOut(arc, node); |
294 | 295 |
while (arc != INVALID ) { |
295 | 296 |
erase(arc); |
296 | 297 |
Parent::firstOut(arc, node); |
297 | 298 |
} |
298 | 299 |
|
299 | 300 |
Parent::firstIn(arc, node); |
300 | 301 |
while (arc != INVALID ) { |
301 | 302 |
erase(arc); |
302 | 303 |
Parent::firstIn(arc, node); |
303 | 304 |
} |
304 | 305 |
|
305 | 306 |
notifier(Node()).erase(node); |
306 | 307 |
Parent::erase(node); |
307 | 308 |
} |
308 | 309 |
|
309 | 310 |
void erase(const Arc& arc) { |
310 | 311 |
notifier(Arc()).erase(arc); |
311 | 312 |
Parent::erase(arc); |
312 | 313 |
} |
313 | 314 |
|
314 | 315 |
DigraphExtender() { |
315 | 316 |
node_notifier.setContainer(*this); |
316 | 317 |
arc_notifier.setContainer(*this); |
317 | 318 |
} |
318 | 319 |
|
319 | 320 |
|
320 | 321 |
~DigraphExtender() { |
321 | 322 |
arc_notifier.clear(); |
322 | 323 |
node_notifier.clear(); |
323 | 324 |
} |
324 | 325 |
}; |
325 | 326 |
|
326 | 327 |
/// \ingroup graphbits |
327 | 328 |
/// |
328 | 329 |
/// \brief Extender for the Graphs |
329 | 330 |
template <typename Base> |
330 | 331 |
class GraphExtender : public Base { |
331 | 332 |
public: |
332 | 333 |
|
333 | 334 |
typedef Base Parent; |
334 | 335 |
typedef GraphExtender Digraph; |
335 | 336 |
|
337 |
typedef True UndirectedTag; |
|
338 |
|
|
336 | 339 |
typedef typename Parent::Node Node; |
337 | 340 |
typedef typename Parent::Arc Arc; |
338 | 341 |
typedef typename Parent::Edge Edge; |
339 | 342 |
|
340 | 343 |
// Graph extension |
341 | 344 |
|
342 | 345 |
int maxId(Node) const { |
343 | 346 |
return Parent::maxNodeId(); |
344 | 347 |
} |
345 | 348 |
|
346 | 349 |
int maxId(Arc) const { |
347 | 350 |
return Parent::maxArcId(); |
348 | 351 |
} |
349 | 352 |
|
350 | 353 |
int maxId(Edge) const { |
351 | 354 |
return Parent::maxEdgeId(); |
352 | 355 |
} |
353 | 356 |
|
354 | 357 |
Node fromId(int id, Node) const { |
355 | 358 |
return Parent::nodeFromId(id); |
356 | 359 |
} |
357 | 360 |
|
358 | 361 |
Arc fromId(int id, Arc) const { |
359 | 362 |
return Parent::arcFromId(id); |
360 | 363 |
} |
361 | 364 |
|
362 | 365 |
Edge fromId(int id, Edge) const { |
363 | 366 |
return Parent::edgeFromId(id); |
364 | 367 |
} |
365 | 368 |
|
366 | 369 |
Node oppositeNode(const Node &n, const Edge &e) const { |
367 | 370 |
if( n == Parent::source(e)) |
368 | 371 |
return Parent::target(e); |
369 | 372 |
else if( n == Parent::target(e)) |
370 | 373 |
return Parent::source(e); |
371 | 374 |
else |
372 | 375 |
return INVALID; |
373 | 376 |
} |
374 | 377 |
|
375 | 378 |
Arc oppositeArc(const Arc &e) const { |
376 | 379 |
return Parent::direct(e, !Parent::direction(e)); |
377 | 380 |
} |
378 | 381 |
|
379 | 382 |
using Parent::direct; |
380 | 383 |
Arc direct(const Edge &ue, const Node &s) const { |
381 | 384 |
return Parent::direct(ue, Parent::source(ue) == s); |
382 | 385 |
} |
383 | 386 |
|
0 comments (0 inline)