gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Improvements in graph adaptors (#67) Remove DigraphAdaptor and GraphAdaptor Remove docs of base classes Move the member documentations to real adaptors Minor improvements in documentation
0 3 0
default
3 files changed with 329 insertions and 372 deletions:
↑ Collapse diff ↑
Ignore white space 192 line context
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-2008
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_DIGRAPH_ADAPTOR_H
20 20
#define LEMON_DIGRAPH_ADAPTOR_H
21 21

	
22 22
///\ingroup graph_adaptors
23 23
///\file
24 24
///\brief Several digraph adaptors.
25 25
///
26
///This file contains several useful digraph adaptor functions.
26
///This file contains several useful digraph adaptor classes.
27 27

	
28 28
#include <lemon/core.h>
29 29
#include <lemon/maps.h>
30 30
#include <lemon/bits/variant.h>
31 31

	
32 32
#include <lemon/bits/base_extender.h>
33 33
#include <lemon/bits/graph_adaptor_extender.h>
34 34
#include <lemon/bits/graph_extender.h>
35 35
#include <lemon/tolerance.h>
36 36

	
37 37
#include <algorithm>
38 38

	
39 39
namespace lemon {
40 40

	
41
  ///\brief Base type for the Digraph Adaptors
42
  ///
43
  ///Base type for the Digraph Adaptors
44
  ///
45
  ///This is the base type for most of LEMON digraph adaptors. This
46
  ///class implements a trivial digraph adaptor i.e. it only wraps the
47
  ///functions and types of the digraph. The purpose of this class is
48
  ///to make easier implementing digraph adaptors. E.g. if an adaptor
49
  ///is considered which differs from the wrapped digraph only in some
50
  ///of its functions or types, then it can be derived from
51
  ///DigraphAdaptor, and only the differences should be implemented.
52 41
  template<typename _Digraph>
53 42
  class DigraphAdaptorBase {
54 43
  public:
55 44
    typedef _Digraph Digraph;
56 45
    typedef DigraphAdaptorBase Adaptor;
57 46
    typedef Digraph ParentDigraph;
58 47

	
59 48
  protected:
60 49
    Digraph* _digraph;
61 50
    DigraphAdaptorBase() : _digraph(0) { }
62 51
    void setDigraph(Digraph& digraph) { _digraph = &digraph; }
63 52

	
64 53
  public:
65 54
    DigraphAdaptorBase(Digraph& digraph) : _digraph(&digraph) { }
66 55

	
67 56
    typedef typename Digraph::Node Node;
68 57
    typedef typename Digraph::Arc Arc;
69 58
   
70 59
    void first(Node& i) const { _digraph->first(i); }
71 60
    void first(Arc& i) const { _digraph->first(i); }
72 61
    void firstIn(Arc& i, const Node& n) const { _digraph->firstIn(i, n); }
73 62
    void firstOut(Arc& i, const Node& n ) const { _digraph->firstOut(i, n); }
74 63

	
75 64
    void next(Node& i) const { _digraph->next(i); }
76 65
    void next(Arc& i) const { _digraph->next(i); }
77 66
    void nextIn(Arc& i) const { _digraph->nextIn(i); }
78 67
    void nextOut(Arc& i) const { _digraph->nextOut(i); }
79 68

	
80 69
    Node source(const Arc& a) const { return _digraph->source(a); }
81 70
    Node target(const Arc& a) const { return _digraph->target(a); }
82 71

	
83 72
    typedef NodeNumTagIndicator<Digraph> NodeNumTag;
84 73
    int nodeNum() const { return _digraph->nodeNum(); }
85 74
    
86 75
    typedef EdgeNumTagIndicator<Digraph> EdgeNumTag;
87 76
    int arcNum() const { return _digraph->arcNum(); }
88 77

	
89 78
    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
90 79
    Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
91 80
      return _digraph->findArc(u, v, prev);
92 81
    }
93 82
  
94 83
    Node addNode() { return _digraph->addNode(); }
95 84
    Arc addArc(const Node& u, const Node& v) { return _digraph->addArc(u, v); }
96 85

	
97 86
    void erase(const Node& n) const { _digraph->erase(n); }
98 87
    void erase(const Arc& a) const { _digraph->erase(a); }
99 88
  
100 89
    void clear() const { _digraph->clear(); }
101 90
    
102 91
    int id(const Node& n) const { return _digraph->id(n); }
103 92
    int id(const Arc& a) const { return _digraph->id(a); }
104 93

	
105 94
    Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
106 95
    Arc arcFromId(int ix) const { return _digraph->arcFromId(ix); }
107 96

	
108 97
    int maxNodeId() const { return _digraph->maxNodeId(); }
109 98
    int maxArcId() const { return _digraph->maxArcId(); }
110 99

	
111 100
    typedef typename ItemSetTraits<Digraph, Node>::ItemNotifier NodeNotifier;
112 101
    NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); } 
113 102

	
114 103
    typedef typename ItemSetTraits<Digraph, Arc>::ItemNotifier ArcNotifier;
115 104
    ArcNotifier& notifier(Arc) const { return _digraph->notifier(Arc()); } 
116 105
    
117 106
    template <typename _Value>
118 107
    class NodeMap : public Digraph::template NodeMap<_Value> {
119 108
    public:
120 109

	
121 110
      typedef typename Digraph::template NodeMap<_Value> Parent;
122 111

	
123 112
      explicit NodeMap(const Adaptor& adaptor) 
124 113
	: Parent(*adaptor._digraph) {}
125 114

	
126 115
      NodeMap(const Adaptor& adaptor, const _Value& value)
127 116
	: Parent(*adaptor._digraph, value) { }
128 117

	
129 118
    private:
130 119
      NodeMap& operator=(const NodeMap& cmap) {
131 120
        return operator=<NodeMap>(cmap);
132 121
      }
133 122

	
134 123
      template <typename CMap>
135 124
      NodeMap& operator=(const CMap& cmap) {
136 125
        Parent::operator=(cmap);
137 126
        return *this;
138 127
      }
139 128
      
140 129
    };
141 130

	
142 131
    template <typename _Value>
143 132
    class ArcMap : public Digraph::template ArcMap<_Value> {
144 133
    public:
145 134
      
146 135
      typedef typename Digraph::template ArcMap<_Value> Parent;
147 136
      
148 137
      explicit ArcMap(const Adaptor& adaptor) 
149 138
	: Parent(*adaptor._digraph) {}
150 139

	
151 140
      ArcMap(const Adaptor& adaptor, const _Value& value)
152 141
	: Parent(*adaptor._digraph, value) {}
153 142

	
154 143
    private:
155 144
      ArcMap& operator=(const ArcMap& cmap) {
156 145
        return operator=<ArcMap>(cmap);
157 146
      }
158 147

	
159 148
      template <typename CMap>
160 149
      ArcMap& operator=(const CMap& cmap) {
161 150
        Parent::operator=(cmap);
162 151
        return *this;
163 152
      }
164 153

	
165 154
    };
166 155

	
167 156
  };
168 157

	
169
  ///\ingroup graph_adaptors
170
  ///
171
  ///\brief Trivial Digraph Adaptor
172
  /// 
173
  /// This class is an adaptor which does not change the adapted
174
  /// digraph.  It can be used only to test the digraph adaptors.
175
  template <typename _Digraph>
176
  class DigraphAdaptor :
177
    public DigraphAdaptorExtender<DigraphAdaptorBase<_Digraph> > { 
178
  public:
179
    typedef _Digraph Digraph;
180
    typedef DigraphAdaptorExtender<DigraphAdaptorBase<_Digraph> > Parent;
181
  protected:
182
    DigraphAdaptor() : Parent() { }
183

	
184
  public:
185
    explicit DigraphAdaptor(Digraph& digraph) { setDigraph(digraph); }
186
  };
187

	
188
  /// \brief Just gives back a digraph adaptor
189
  ///
190
  /// Just gives back a digraph adaptor which 
191
  /// should be provide original digraph
192
  template<typename Digraph>
193
  DigraphAdaptor<const Digraph>
194
  digraphAdaptor(const Digraph& digraph) {
195
    return DigraphAdaptor<const Digraph>(digraph);
196
  }
197

	
198 158

	
199 159
  template <typename _Digraph>
200 160
  class RevDigraphAdaptorBase : public DigraphAdaptorBase<_Digraph> {
201 161
  public:
202 162
    typedef _Digraph Digraph;
203 163
    typedef DigraphAdaptorBase<_Digraph> Parent;
204 164
  protected:
205 165
    RevDigraphAdaptorBase() : Parent() { }
206 166
  public:
207 167
    typedef typename Parent::Node Node;
208 168
    typedef typename Parent::Arc Arc;
209 169

	
210 170
    void firstIn(Arc& a, const Node& n) const { Parent::firstOut(a, n); }
211 171
    void firstOut(Arc& a, const Node& n ) const { Parent::firstIn(a, n); }
212 172

	
213 173
    void nextIn(Arc& a) const { Parent::nextOut(a); }
214 174
    void nextOut(Arc& a) const { Parent::nextIn(a); }
215 175

	
216 176
    Node source(const Arc& a) const { return Parent::target(a); }
217 177
    Node target(const Arc& a) const { return Parent::source(a); }
218 178

	
219 179
    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
220 180
    Arc findArc(const Node& u, const Node& v, 
221 181
		const Arc& prev = INVALID) {
222 182
      return Parent::findArc(v, u, prev);
223 183
    }
224 184

	
225 185
  };
226 186
    
227 187

	
228 188
  ///\ingroup graph_adaptors
229 189
  ///
230 190
  ///\brief A digraph adaptor which reverses the orientation of the arcs.
231 191
  ///
232 192
  /// If \c g is defined as
233 193
  ///\code
234
  /// ListDigraph g;
194
  /// ListDigraph dg;
235 195
  ///\endcode
236 196
  /// then
237 197
  ///\code
238
  /// RevDigraphAdaptor<ListDigraph> ga(g);
198
  /// RevDigraphAdaptor<ListDigraph> dga(dg);
239 199
  ///\endcode
240
  /// implements the digraph obtained from \c g by 
200
  /// implements the digraph obtained from \c dg by 
241 201
  /// reversing the orientation of its arcs.
242 202
  ///
243
  /// A good example of using RevDigraphAdaptor is to decide that the
244
  /// directed graph is wheter strongly connected or not. If from one
245
  /// node each node is reachable and from each node is reachable this
246
  /// node then and just then the digraph is strongly
247
  /// connected. Instead of this condition we use a little bit
248
  /// different. From one node each node ahould be reachable in the
249
  /// digraph and in the reversed digraph. Now this condition can be
250
  /// checked with the Dfs algorithm class and the RevDigraphAdaptor
251
  /// algorithm class.
203
  /// A good example of using RevDigraphAdaptor is to decide whether
204
  /// the directed graph is strongly connected or not. The digraph is
205
  /// strongly connected iff each node is reachable from one node and
206
  /// this node is reachable from the others. Instead of this
207
  /// condition we use a slightly different, from one node each node
208
  /// is reachable both in the digraph and the reversed digraph. Now
209
  /// this condition can be checked with the Dfs algorithm and the
210
  /// RevDigraphAdaptor class.
252 211
  ///
253
  /// And look at the code:
254
  ///
212
  /// The implementation:
255 213
  ///\code
256 214
  /// bool stronglyConnected(const Digraph& digraph) {
257 215
  ///   if (NodeIt(digraph) == INVALID) return true;
258 216
  ///   Dfs<Digraph> dfs(digraph);
259 217
  ///   dfs.run(NodeIt(digraph));
260 218
  ///   for (NodeIt it(digraph); it != INVALID; ++it) {
261 219
  ///     if (!dfs.reached(it)) {
262 220
  ///       return false;
263 221
  ///     }
264 222
  ///   }
265 223
  ///   typedef RevDigraphAdaptor<const Digraph> RDigraph;
266 224
  ///   RDigraph rdigraph(digraph);
267 225
  ///   DfsVisit<RDigraph> rdfs(rdigraph);
268 226
  ///   rdfs.run(NodeIt(digraph));
269 227
  ///   for (NodeIt it(digraph); it != INVALID; ++it) {
270 228
  ///     if (!rdfs.reached(it)) {
271 229
  ///       return false;
272 230
  ///     }
273 231
  ///   }
274 232
  ///   return true;
275 233
  /// }
276 234
  ///\endcode
277 235
  template<typename _Digraph>
278 236
  class RevDigraphAdaptor : 
279 237
    public DigraphAdaptorExtender<RevDigraphAdaptorBase<_Digraph> > {
280 238
  public:
281 239
    typedef _Digraph Digraph;
282 240
    typedef DigraphAdaptorExtender<
283 241
      RevDigraphAdaptorBase<_Digraph> > Parent;
284 242
  protected:
285 243
    RevDigraphAdaptor() { }
286 244
  public:
245

	
246
    /// \brief Constructor
247
    ///
248
    /// Creates a reverse graph adaptor for the given digraph
287 249
    explicit RevDigraphAdaptor(Digraph& digraph) { 
288 250
      Parent::setDigraph(digraph); 
289 251
    }
290 252
  };
291 253

	
292 254
  /// \brief Just gives back a reverse digraph adaptor
293 255
  ///
294 256
  /// Just gives back a reverse digraph adaptor
295 257
  template<typename Digraph>
296 258
  RevDigraphAdaptor<const Digraph>
297 259
  revDigraphAdaptor(const Digraph& digraph) {
298 260
    return RevDigraphAdaptor<const Digraph>(digraph);
299 261
  }
300 262

	
301 263
  template <typename _Digraph, typename _NodeFilterMap, 
302 264
	    typename _ArcFilterMap, bool checked = true>
303 265
  class SubDigraphAdaptorBase : public DigraphAdaptorBase<_Digraph> {
304 266
  public:
305 267
    typedef _Digraph Digraph;
306 268
    typedef _NodeFilterMap NodeFilterMap;
307 269
    typedef _ArcFilterMap ArcFilterMap;
308 270

	
309 271
    typedef SubDigraphAdaptorBase Adaptor;
310 272
    typedef DigraphAdaptorBase<_Digraph> Parent;
311 273
  protected:
312 274
    NodeFilterMap* _node_filter;
313 275
    ArcFilterMap* _arc_filter;
314 276
    SubDigraphAdaptorBase() 
315 277
      : Parent(), _node_filter(0), _arc_filter(0) { }
316 278

	
317 279
    void setNodeFilterMap(NodeFilterMap& node_filter) {
318 280
      _node_filter = &node_filter;
319 281
    }
320 282
    void setArcFilterMap(ArcFilterMap& arc_filter) {
321 283
      _arc_filter = &arc_filter;
322 284
    }
323 285

	
324 286
  public:
325 287

	
326 288
    typedef typename Parent::Node Node;
327 289
    typedef typename Parent::Arc Arc;
328 290

	
329 291
    void first(Node& i) const { 
330 292
      Parent::first(i); 
331 293
      while (i != INVALID && !(*_node_filter)[i]) Parent::next(i); 
332 294
    }
333 295

	
334 296
    void first(Arc& i) const { 
335 297
      Parent::first(i); 
336 298
      while (i != INVALID && (!(*_arc_filter)[i] 
337 299
	     || !(*_node_filter)[Parent::source(i)]
338 300
	     || !(*_node_filter)[Parent::target(i)])) Parent::next(i); 
339 301
    }
340 302

	
341 303
    void firstIn(Arc& i, const Node& n) const { 
342 304
      Parent::firstIn(i, n); 
343 305
      while (i != INVALID && (!(*_arc_filter)[i] 
344 306
	     || !(*_node_filter)[Parent::source(i)])) Parent::nextIn(i); 
345 307
    }
346 308

	
347 309
    void firstOut(Arc& i, const Node& n) const { 
348 310
      Parent::firstOut(i, n); 
349 311
      while (i != INVALID && (!(*_arc_filter)[i] 
350 312
	     || !(*_node_filter)[Parent::target(i)])) Parent::nextOut(i); 
351 313
    }
352 314

	
353 315
    void next(Node& i) const { 
354 316
      Parent::next(i); 
355 317
      while (i != INVALID && !(*_node_filter)[i]) Parent::next(i); 
356 318
    }
357 319

	
358 320
    void next(Arc& i) const { 
359 321
      Parent::next(i); 
360 322
      while (i != INVALID && (!(*_arc_filter)[i] 
361 323
	     || !(*_node_filter)[Parent::source(i)]
362 324
	     || !(*_node_filter)[Parent::target(i)])) Parent::next(i); 
363 325
    }
364 326

	
365 327
    void nextIn(Arc& i) const { 
366 328
      Parent::nextIn(i); 
367 329
      while (i != INVALID && (!(*_arc_filter)[i] 
368 330
	     || !(*_node_filter)[Parent::source(i)])) Parent::nextIn(i); 
369 331
    }
370 332

	
371 333
    void nextOut(Arc& i) const { 
372 334
      Parent::nextOut(i); 
373 335
      while (i != INVALID && (!(*_arc_filter)[i] 
374 336
	     || !(*_node_filter)[Parent::target(i)])) Parent::nextOut(i); 
375 337
    }
376 338

	
377
    ///\e
378

	
379
    /// This function hides \c n in the digraph, i.e. the iteration 
380
    /// jumps over it. This is done by simply setting the value of \c n  
381
    /// to be false in the corresponding node-map.
382 339
    void hide(const Node& n) const { _node_filter->set(n, false); }
383

	
384
    ///\e
385

	
386
    /// This function hides \c a in the digraph, i.e. the iteration 
387
    /// jumps over it. This is done by simply setting the value of \c a
388
    /// to be false in the corresponding arc-map.
389 340
    void hide(const Arc& a) const { _arc_filter->set(a, false); }
390 341

	
391
    ///\e
392

	
393
    /// The value of \c n is set to be true in the node-map which stores 
394
    /// hide information. If \c n was hidden previuosly, then it is shown 
395
    /// again
396
     void unHide(const Node& n) const { _node_filter->set(n, true); }
397

	
398
    ///\e
399

	
400
    /// The value of \c a is set to be true in the arc-map which stores 
401
    /// hide information. If \c a was hidden previuosly, then it is shown 
402
    /// again
342
    void unHide(const Node& n) const { _node_filter->set(n, true); }
403 343
    void unHide(const Arc& a) const { _arc_filter->set(a, true); }
404 344

	
405
    /// Returns true if \c n is hidden.
406
    
407
    ///\e
408
    ///
409 345
    bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
410

	
411
    /// Returns true if \c a is hidden.
412
    
413
    ///\e
414
    ///
415 346
    bool hidden(const Arc& a) const { return !(*_arc_filter)[a]; }
416 347

	
417 348
    typedef False NodeNumTag;
418 349
    typedef False EdgeNumTag;
419 350

	
420 351
    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
421 352
    Arc findArc(const Node& source, const Node& target, 
422 353
		const Arc& prev = INVALID) {
423 354
      if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
424 355
        return INVALID;
425 356
      }
426 357
      Arc arc = Parent::findArc(source, target, prev);
427 358
      while (arc != INVALID && !(*_arc_filter)[arc]) {
428 359
        arc = Parent::findArc(source, target, arc);
429 360
      }
430 361
      return arc;
431 362
    }
432 363

	
433 364
    template <typename _Value>
434 365
    class NodeMap : public SubMapExtender<Adaptor, 
435 366
        typename Parent::template NodeMap<_Value> > {
436 367
    public:
437 368
      typedef _Value Value;
438 369
      typedef SubMapExtender<Adaptor, typename Parent::
439 370
                             template NodeMap<Value> > MapParent;
440 371
    
441 372
      NodeMap(const Adaptor& adaptor) 
442 373
	: MapParent(adaptor) {}
443 374
      NodeMap(const Adaptor& adaptor, const Value& value) 
444 375
	: MapParent(adaptor, value) {}
445 376
    
446 377
    private:
447 378
      NodeMap& operator=(const NodeMap& cmap) {
448 379
	return operator=<NodeMap>(cmap);
449 380
      }
450 381
    
451 382
      template <typename CMap>
452 383
      NodeMap& operator=(const CMap& cmap) {
453 384
        MapParent::operator=(cmap);
454 385
	return *this;
455 386
      }
456 387
    };
457 388

	
458 389
    template <typename _Value>
459 390
    class ArcMap : public SubMapExtender<Adaptor, 
460 391
	typename Parent::template ArcMap<_Value> > {
461 392
    public:
462 393
      typedef _Value Value;
463 394
      typedef SubMapExtender<Adaptor, typename Parent::
464 395
                             template ArcMap<Value> > MapParent;
465 396
    
466 397
      ArcMap(const Adaptor& adaptor) 
467 398
	: MapParent(adaptor) {}
468 399
      ArcMap(const Adaptor& adaptor, const Value& value) 
469 400
	: MapParent(adaptor, value) {}
470 401
    
471 402
    private:
472 403
      ArcMap& operator=(const ArcMap& cmap) {
473 404
	return operator=<ArcMap>(cmap);
474 405
      }
475 406
    
476 407
      template <typename CMap>
477 408
      ArcMap& operator=(const CMap& cmap) {
478 409
        MapParent::operator=(cmap);
479 410
	return *this;
480 411
      }
481 412
    };
482 413

	
483 414
  };
484 415

	
485 416
  template <typename _Digraph, typename _NodeFilterMap, typename _ArcFilterMap>
486 417
  class SubDigraphAdaptorBase<_Digraph, _NodeFilterMap, _ArcFilterMap, false> 
487 418
    : public DigraphAdaptorBase<_Digraph> {
488 419
  public:
489 420
    typedef _Digraph Digraph;
490 421
    typedef _NodeFilterMap NodeFilterMap;
491 422
    typedef _ArcFilterMap ArcFilterMap;
492 423

	
493 424
    typedef SubDigraphAdaptorBase Adaptor;
494 425
    typedef DigraphAdaptorBase<Digraph> Parent;
495 426
  protected:
496 427
    NodeFilterMap* _node_filter;
497 428
    ArcFilterMap* _arc_filter;
498 429
    SubDigraphAdaptorBase() 
499 430
      : Parent(), _node_filter(0), _arc_filter(0) { }
500 431

	
501 432
    void setNodeFilterMap(NodeFilterMap& node_filter) {
502 433
      _node_filter = &node_filter;
503 434
    }
504 435
    void setArcFilterMap(ArcFilterMap& arc_filter) {
505 436
      _arc_filter = &arc_filter;
506 437
    }
507 438

	
508 439
  public:
509 440

	
510 441
    typedef typename Parent::Node Node;
511 442
    typedef typename Parent::Arc Arc;
512 443

	
513 444
    void first(Node& i) const { 
514 445
      Parent::first(i); 
515 446
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i); 
516 447
    }
517 448

	
518 449
    void first(Arc& i) const { 
519 450
      Parent::first(i); 
520 451
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i); 
521 452
    }
522 453

	
523 454
    void firstIn(Arc& i, const Node& n) const { 
524 455
      Parent::firstIn(i, n); 
525 456
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i); 
526 457
    }
527 458

	
528 459
    void firstOut(Arc& i, const Node& n) const { 
529 460
      Parent::firstOut(i, n); 
530 461
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i); 
531 462
    }
532 463

	
533 464
    void next(Node& i) const { 
534 465
      Parent::next(i); 
535 466
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i); 
536 467
    }
537 468
    void next(Arc& i) const { 
538 469
      Parent::next(i); 
539 470
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i); 
540 471
    }
541 472
    void nextIn(Arc& i) const { 
542 473
      Parent::nextIn(i); 
543 474
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i); 
544 475
    }
545 476

	
546 477
    void nextOut(Arc& i) const { 
547 478
      Parent::nextOut(i); 
548 479
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i); 
549 480
    }
550 481

	
551
    ///\e
552

	
553
    /// This function hides \c n in the digraph, i.e. the iteration 
554
    /// jumps over it. This is done by simply setting the value of \c n  
555
    /// to be false in the corresponding node-map.
556 482
    void hide(const Node& n) const { _node_filter->set(n, false); }
557

	
558
    ///\e
559

	
560
    /// This function hides \c e in the digraph, i.e. the iteration 
561
    /// jumps over it. This is done by simply setting the value of \c e  
562
    /// to be false in the corresponding arc-map.
563 483
    void hide(const Arc& e) const { _arc_filter->set(e, false); }
564 484

	
565
    ///\e
566

	
567
    /// The value of \c n is set to be true in the node-map which stores 
568
    /// hide information. If \c n was hidden previuosly, then it is shown 
569
    /// again
570
     void unHide(const Node& n) const { _node_filter->set(n, true); }
571

	
572
    ///\e
573

	
574
    /// The value of \c e is set to be true in the arc-map which stores 
575
    /// hide information. If \c e was hidden previuosly, then it is shown 
576
    /// again
485
    void unHide(const Node& n) const { _node_filter->set(n, true); }
577 486
    void unHide(const Arc& e) const { _arc_filter->set(e, true); }
578 487

	
579
    /// Returns true if \c n is hidden.
580
    
581
    ///\e
582
    ///
583 488
    bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
584

	
585
    /// Returns true if \c n is hidden.
586
    
587
    ///\e
588
    ///
589 489
    bool hidden(const Arc& e) const { return !(*_arc_filter)[e]; }
590 490

	
591 491
    typedef False NodeNumTag;
592 492
    typedef False EdgeNumTag;
593 493

	
594 494
    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
595 495
    Arc findArc(const Node& source, const Node& target, 
596 496
		  const Arc& prev = INVALID) {
597 497
      if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
598 498
        return INVALID;
599 499
      }
600 500
      Arc arc = Parent::findArc(source, target, prev);
601 501
      while (arc != INVALID && !(*_arc_filter)[arc]) {
602 502
        arc = Parent::findArc(source, target, arc);
603 503
      }
604 504
      return arc;
605 505
    }
606 506

	
607 507
    template <typename _Value>
608 508
    class NodeMap : public SubMapExtender<Adaptor, 
609 509
        typename Parent::template NodeMap<_Value> > {
610 510
    public:
611 511
      typedef _Value Value;
612 512
      typedef SubMapExtender<Adaptor, typename Parent::
613 513
                             template NodeMap<Value> > MapParent;
614 514
    
615 515
      NodeMap(const Adaptor& adaptor) 
616 516
	: MapParent(adaptor) {}
617 517
      NodeMap(const Adaptor& adaptor, const Value& value) 
618 518
	: MapParent(adaptor, value) {}
619 519
    
620 520
    private:
621 521
      NodeMap& operator=(const NodeMap& cmap) {
622 522
	return operator=<NodeMap>(cmap);
623 523
      }
624 524
    
625 525
      template <typename CMap>
626 526
      NodeMap& operator=(const CMap& cmap) {
627 527
        MapParent::operator=(cmap);
628 528
	return *this;
629 529
      }
630 530
    };
631 531

	
632 532
    template <typename _Value>
633 533
    class ArcMap : public SubMapExtender<Adaptor, 
634 534
	typename Parent::template ArcMap<_Value> > {
635 535
    public:
636 536
      typedef _Value Value;
637 537
      typedef SubMapExtender<Adaptor, typename Parent::
638 538
                             template ArcMap<Value> > MapParent;
639 539
    
640 540
      ArcMap(const Adaptor& adaptor) 
641 541
	: MapParent(adaptor) {}
642 542
      ArcMap(const Adaptor& adaptor, const Value& value) 
643 543
	: MapParent(adaptor, value) {}
644 544
    
645 545
    private:
646 546
      ArcMap& operator=(const ArcMap& cmap) {
647 547
	return operator=<ArcMap>(cmap);
648 548
      }
649 549
    
650 550
      template <typename CMap>
651 551
      ArcMap& operator=(const CMap& cmap) {
652 552
        MapParent::operator=(cmap);
653 553
	return *this;
654 554
      }
655 555
    };
656 556

	
657 557
  };
658 558

	
659 559
  /// \ingroup graph_adaptors
660 560
  ///
661 561
  /// \brief A digraph adaptor for hiding nodes and arcs from a digraph.
662 562
  /// 
663 563
  /// SubDigraphAdaptor shows the digraph with filtered node-set and 
664
  /// arc-set. If the \c checked parameter is true then it filters the arcset
665
  /// to do not get invalid arcs without source or target.
666
  /// Let \f$ G=(V, A) \f$ be a directed digraph
667
  /// and suppose that the digraph instance \c g of type ListDigraph
668
  /// implements \f$ G \f$.
669
  /// Let moreover \f$ b_V \f$ and \f$ b_A \f$ be bool-valued functions resp.
670
  /// on the node-set and arc-set.
671
  /// SubDigraphAdaptor<...>::NodeIt iterates 
672
  /// on the node-set \f$ \{v\in V : b_V(v)=true\} \f$ and 
673
  /// SubDigraphAdaptor<...>::ArcIt iterates 
674
  /// on the arc-set \f$ \{e\in A : b_A(e)=true\} \f$. Similarly, 
675
  /// SubDigraphAdaptor<...>::OutArcIt and
676
  /// SubDigraphAdaptor<...>::InArcIt iterates 
677
  /// only on arcs leaving and entering a specific node which have true value.
564
  /// arc-set. If the \c checked parameter is true then it filters the arc-set
565
  /// respect to the source and target.
678 566
  /// 
679
  /// If the \c checked template parameter is false then we have to
680
  /// note that the node-iterator cares only the filter on the
681
  /// node-set, and the arc-iterator cares only the filter on the
682
  /// arc-set.  This way the arc-map should filter all arcs which's
683
  /// source or target is filtered by the node-filter.
567
  /// If the \c checked template parameter is false then the
568
  /// node-iterator cares only the filter on the node-set, and the
569
  /// arc-iterator cares only the filter on the arc-set.  Therefore
570
  /// the arc-map have to filter all arcs which's source or target is
571
  /// filtered by the node-filter.
684 572
  ///\code
685 573
  /// typedef ListDigraph Digraph;
686 574
  /// DIGRAPH_TYPEDEFS(Digraph);
687 575
  /// Digraph g;
688 576
  /// Node u=g.addNode(); //node of id 0
689 577
  /// Node v=g.addNode(); //node of id 1
690 578
  /// Arc a=g.addArc(u, v); //arc of id 0
691 579
  /// Arc f=g.addArc(v, u); //arc of id 1
692 580
  /// BoolNodeMap nm(g, true);
693 581
  /// nm.set(u, false);
694 582
  /// BoolArcMap am(g, true);
695 583
  /// am.set(a, false);
696
  /// typedef SubDigraphAdaptor<Digraph, BoolNodeMap, BoolArcMap> SubGA;
697
  /// SubGA ga(g, nm, am);
698
  /// for (SubGA::NodeIt n(ga); n!=INVALID; ++n)
584
  /// typedef SubDigraphAdaptor<Digraph, BoolNodeMap, BoolArcMap> SubDGA;
585
  /// SubDGA ga(g, nm, am);
586
  /// for (SubDGA::NodeIt n(ga); n!=INVALID; ++n)
699 587
  ///   std::cout << g.id(n) << std::endl;
700
  /// std::cout << ":-)" << std::endl;
701
  /// for (SubGA::ArcIt a(ga); a!=INVALID; ++a) 
588
  /// for (SubDGA::ArcIt a(ga); a!=INVALID; ++a) 
702 589
  ///   std::cout << g.id(a) << std::endl;
703 590
  ///\endcode
704 591
  /// The output of the above code is the following.
705 592
  ///\code
706 593
  /// 1
707
  /// :-)
708 594
  /// 1
709 595
  ///\endcode
710
  /// Note that \c n is of type \c SubGA::NodeIt, but it can be converted to
596
  /// Note that \c n is of type \c SubDGA::NodeIt, but it can be converted to
711 597
  /// \c Digraph::Node that is why \c g.id(n) can be applied.
712 598
  /// 
713 599
  /// For other examples see also the documentation of
714 600
  /// NodeSubDigraphAdaptor and ArcSubDigraphAdaptor.
715 601
  template<typename _Digraph, 
716 602
	   typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>, 
717 603
	   typename _ArcFilterMap = typename _Digraph::template ArcMap<bool>, 
718 604
	   bool checked = true>
719 605
  class SubDigraphAdaptor : 
720 606
    public DigraphAdaptorExtender<
721 607
    SubDigraphAdaptorBase<_Digraph, _NodeFilterMap, _ArcFilterMap, checked> > {
722 608
  public:
723 609
    typedef _Digraph Digraph;
724 610
    typedef _NodeFilterMap NodeFilterMap;
725 611
    typedef _ArcFilterMap ArcFilterMap;
726 612

	
727 613
    typedef DigraphAdaptorExtender<
728 614
      SubDigraphAdaptorBase<Digraph, NodeFilterMap, ArcFilterMap, checked> >
729 615
    Parent;
730 616

	
617
    typedef typename Parent::Node Node;
618
    typedef typename Parent::Arc Arc;
619

	
731 620
  protected:
732 621
    SubDigraphAdaptor() { }
733 622
  public:
734 623

	
624
    /// \brief Constructor
625
    ///
626
    /// Creates a sub-digraph-adaptor for the given digraph with
627
    /// given node and arc map filters.
735 628
    SubDigraphAdaptor(Digraph& digraph, NodeFilterMap& node_filter, 
736 629
		      ArcFilterMap& arc_filter) { 
737 630
      setDigraph(digraph);
738 631
      setNodeFilterMap(node_filter);
739 632
      setArcFilterMap(arc_filter);
740 633
    }
741 634

	
635
    /// \brief Hides the node of the graph
636
    ///
637
    /// This function hides \c n in the digraph, i.e. the iteration 
638
    /// jumps over it. This is done by simply setting the value of \c n  
639
    /// to be false in the corresponding node-map.
640
    void hide(const Node& n) const { Parent::hide(n); }
641

	
642
    /// \brief Hides the arc of the graph
643
    ///
644
    /// This function hides \c a in the digraph, i.e. the iteration 
645
    /// jumps over it. This is done by simply setting the value of \c a
646
    /// to be false in the corresponding arc-map.
647
    void hide(const Arc& a) const { Parent::hide(a); }
648

	
649
    /// \brief Unhides the node of the graph
650
    ///
651
    /// The value of \c n is set to be true in the node-map which stores 
652
    /// hide information. If \c n was hidden previuosly, then it is shown 
653
    /// again
654
    void unHide(const Node& n) const { Parent::unHide(n); }
655

	
656
    /// \brief Unhides the arc of the graph
657
    ///
658
    /// The value of \c a is set to be true in the arc-map which stores 
659
    /// hide information. If \c a was hidden previuosly, then it is shown 
660
    /// again
661
    void unHide(const Arc& a) const { Parent::unHide(a); }
662

	
663
    /// \brief Returns true if \c n is hidden.
664
    ///
665
    /// Returns true if \c n is hidden.
666
    ///
667
    bool hidden(const Node& n) const { return Parent::hidden(n); }
668

	
669
    /// \brief Returns true if \c a is hidden.
670
    ///
671
    /// Returns true if \c a is hidden.
672
    ///
673
    bool hidden(const Arc& a) const { return Parent::hidden(a); }
674

	
742 675
  };
743 676

	
744
  /// \brief Just gives back a sub digraph adaptor
677
  /// \brief Just gives back a sub-digraph-adaptor
745 678
  ///
746
  /// Just gives back a sub digraph adaptor
679
  /// Just gives back a sub-digraph-adaptor
747 680
  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
748 681
  SubDigraphAdaptor<const Digraph, NodeFilterMap, ArcFilterMap>
749 682
  subDigraphAdaptor(const Digraph& digraph, 
750 683
		    NodeFilterMap& nfm, ArcFilterMap& afm) {
751 684
    return SubDigraphAdaptor<const Digraph, NodeFilterMap, ArcFilterMap>
752 685
      (digraph, nfm, afm);
753 686
  }
754 687

	
755 688
  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
756 689
  SubDigraphAdaptor<const Digraph, const NodeFilterMap, ArcFilterMap>
757 690
  subDigraphAdaptor(const Digraph& digraph, 
758 691
                   NodeFilterMap& nfm, ArcFilterMap& afm) {
759 692
    return SubDigraphAdaptor<const Digraph, const NodeFilterMap, ArcFilterMap>
760 693
      (digraph, nfm, afm);
761 694
  }
762 695

	
763 696
  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
764 697
  SubDigraphAdaptor<const Digraph, NodeFilterMap, const ArcFilterMap>
765 698
  subDigraphAdaptor(const Digraph& digraph, 
766 699
                   NodeFilterMap& nfm, ArcFilterMap& afm) {
767 700
    return SubDigraphAdaptor<const Digraph, NodeFilterMap, const ArcFilterMap>
768 701
      (digraph, nfm, afm);
769 702
  }
770 703

	
771 704
  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
772 705
  SubDigraphAdaptor<const Digraph, const NodeFilterMap, const ArcFilterMap>
773 706
  subDigraphAdaptor(const Digraph& digraph, 
774 707
                   NodeFilterMap& nfm, ArcFilterMap& afm) {
775 708
    return SubDigraphAdaptor<const Digraph, const NodeFilterMap, 
776 709
      const ArcFilterMap>(digraph, nfm, afm);
710

	
777 711
  }
778 712

	
779 713

	
780 714

	
781 715
  ///\ingroup graph_adaptors
782 716
  ///
783 717
  ///\brief An adaptor for hiding nodes from a digraph.
784 718
  ///
785 719
  ///An adaptor for hiding nodes from a digraph.  This adaptor
786 720
  ///specializes SubDigraphAdaptor in the way that only the node-set
787 721
  ///can be filtered. In usual case the checked parameter is true, we
788 722
  ///get the induced subgraph. But if the checked parameter is false
789 723
  ///then we can filter only isolated nodes.
790 724
  template<typename _Digraph, 
791 725
	   typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>, 
792 726
	   bool checked = true>
793 727
  class NodeSubDigraphAdaptor : 
794 728
    public SubDigraphAdaptor<_Digraph, _NodeFilterMap, 
795 729
			     ConstMap<typename _Digraph::Arc, bool>, checked> {
796 730
  public:
797 731

	
798 732
    typedef _Digraph Digraph;
799 733
    typedef _NodeFilterMap NodeFilterMap;
800 734

	
801 735
    typedef SubDigraphAdaptor<Digraph, NodeFilterMap, 
802 736
			      ConstMap<typename Digraph::Arc, bool>, checked> 
803 737
    Parent;
804 738

	
739
    typedef typename Parent::Node Node;
740

	
805 741
  protected:
806 742
    ConstMap<typename Digraph::Arc, bool> const_true_map;
807 743

	
808 744
    NodeSubDigraphAdaptor() : const_true_map(true) {
809 745
      Parent::setArcFilterMap(const_true_map);
810 746
    }
811 747

	
812 748
  public:
813 749

	
750
    /// \brief Constructor
751
    ///
752
    /// Creates a node-sub-digraph-adaptor for the given digraph with
753
    /// given node map filter.
814 754
    NodeSubDigraphAdaptor(Digraph& _digraph, NodeFilterMap& node_filter) : 
815 755
      Parent(), const_true_map(true) { 
816 756
      Parent::setDigraph(_digraph);
817 757
      Parent::setNodeFilterMap(node_filter);
818 758
      Parent::setArcFilterMap(const_true_map);
819 759
    }
820 760

	
761
    /// \brief Hides the node of the graph
762
    ///
763
    /// This function hides \c n in the digraph, i.e. the iteration 
764
    /// jumps over it. This is done by simply setting the value of \c n  
765
    /// to be false in the corresponding node-map.
766
    void hide(const Node& n) const { Parent::hide(n); }
767

	
768
    /// \brief Unhides the node of the graph
769
    ///
770
    /// The value of \c n is set to be true in the node-map which stores 
771
    /// hide information. If \c n was hidden previuosly, then it is shown 
772
    /// again
773
    void unHide(const Node& n) const { Parent::unHide(n); }
774

	
775
    /// \brief Returns true if \c n is hidden.
776
    ///
777
    /// Returns true if \c n is hidden.
778
    ///
779
    bool hidden(const Node& n) const { return Parent::hidden(n); }
780

	
821 781
  };
822 782

	
823 783

	
824
  /// \brief Just gives back a \c NodeSubDigraphAdaptor
784
  /// \brief Just gives back a  node-sub-digraph adaptor
825 785
  ///
826
  /// Just gives back a \c NodeSubDigraphAdaptor
786
  /// Just gives back a node-sub-digraph adaptor
827 787
  template<typename Digraph, typename NodeFilterMap>
828 788
  NodeSubDigraphAdaptor<const Digraph, NodeFilterMap>
829 789
  nodeSubDigraphAdaptor(const Digraph& digraph, NodeFilterMap& nfm) {
830 790
    return NodeSubDigraphAdaptor<const Digraph, NodeFilterMap>(digraph, nfm);
831 791
  }
832 792

	
833 793
  template<typename Digraph, typename NodeFilterMap>
834 794
  NodeSubDigraphAdaptor<const Digraph, const NodeFilterMap>
835 795
  nodeSubDigraphAdaptor(const Digraph& digraph, const NodeFilterMap& nfm) {
836 796
    return NodeSubDigraphAdaptor<const Digraph, const NodeFilterMap>
837 797
      (digraph, nfm);
838 798
  }
839 799

	
840 800
  ///\ingroup graph_adaptors
841 801
  ///
842 802
  ///\brief An adaptor for hiding arcs from a digraph.
843 803
  ///
844 804
  ///An adaptor for hiding arcs from a digraph. This adaptor
845 805
  ///specializes SubDigraphAdaptor in the way that only the arc-set
846 806
  ///can be filtered. The usefulness of this adaptor is demonstrated
847 807
  ///in the problem of searching a maximum number of arc-disjoint
848 808
  ///shortest paths between two nodes \c s and \c t. Shortest here
849
  ///means being shortest w.r.t.  non-negative arc-lengths. Note that
850
  ///the comprehension of the presented solution need's some
851
  ///elementary knowlarc from combinatorial optimization.
809
  ///means being shortest with respect to non-negative
810
  ///arc-lengths. Note that the comprehension of the presented
811
  ///solution need's some elementary knowledge from combinatorial
812
  ///optimization.
852 813
  ///
853 814
  ///If a single shortest path is to be searched between \c s and \c
854 815
  ///t, then this can be done easily by applying the Dijkstra
855 816
  ///algorithm. What happens, if a maximum number of arc-disjoint
856 817
  ///shortest paths is to be computed. It can be proved that an arc
857 818
  ///can be in a shortest path if and only if it is tight with respect
858 819
  ///to the potential function computed by Dijkstra.  Moreover, any
859 820
  ///path containing only such arcs is a shortest one.  Thus we have
860 821
  ///to compute a maximum number of arc-disjoint paths between \c s
861 822
  ///and \c t in the digraph which has arc-set all the tight arcs. The
862 823
  ///computation will be demonstrated on the following digraph, which
863 824
  ///is read from the dimacs file \c sub_digraph_adaptor_demo.dim.
864 825
  ///The full source code is available in \ref
865 826
  ///sub_digraph_adaptor_demo.cc.  If you are interested in more demo
866 827
  ///programs, you can use \ref dim_to_dot.cc to generate .dot files
867 828
  ///from dimacs files.  The .dot file of the following figure was
868 829
  ///generated by the demo program \ref dim_to_dot.cc.
869 830
  ///
870 831
  ///\dot
871
  ///didigraph lemon_dot_example {
832
  ///digraph lemon_dot_example {
872 833
  ///node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
873 834
  ///n0 [ label="0 (s)" ];
874 835
  ///n1 [ label="1" ];
875 836
  ///n2 [ label="2" ];
876 837
  ///n3 [ label="3" ];
877 838
  ///n4 [ label="4" ];
878 839
  ///n5 [ label="5" ];
879 840
  ///n6 [ label="6 (t)" ];
880 841
  ///arc [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
881 842
  ///n5 ->  n6 [ label="9, length:4" ];
882 843
  ///n4 ->  n6 [ label="8, length:2" ];
883 844
  ///n3 ->  n5 [ label="7, length:1" ];
884 845
  ///n2 ->  n5 [ label="6, length:3" ];
885 846
  ///n2 ->  n6 [ label="5, length:5" ];
886 847
  ///n2 ->  n4 [ label="4, length:2" ];
887 848
  ///n1 ->  n4 [ label="3, length:3" ];
888 849
  ///n0 ->  n3 [ label="2, length:1" ];
889 850
  ///n0 ->  n2 [ label="1, length:2" ];
890 851
  ///n0 ->  n1 [ label="0, length:3" ];
891 852
  ///}
892 853
  ///\enddot
893 854
  ///
894 855
  ///\code
895 856
  ///Digraph g;
896 857
  ///Node s, t;
897 858
  ///LengthMap length(g);
898 859
  ///
899 860
  ///readDimacs(std::cin, g, length, s, t);
900 861
  ///
901 862
  ///cout << "arcs with lengths (of form id, source--length->target): " << endl;
902 863
  ///for(ArcIt e(g); e!=INVALID; ++e) 
903 864
  ///  cout << g.id(e) << ", " << g.id(g.source(e)) << "--" 
904 865
  ///       << length[e] << "->" << g.id(g.target(e)) << endl;
905 866
  ///
906 867
  ///cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
907 868
  ///\endcode
908 869
  ///Next, the potential function is computed with Dijkstra.
909 870
  ///\code
910 871
  ///typedef Dijkstra<Digraph, LengthMap> Dijkstra;
911 872
  ///Dijkstra dijkstra(g, length);
912 873
  ///dijkstra.run(s);
913 874
  ///\endcode
914 875
  ///Next, we consrtruct a map which filters the arc-set to the tight arcs.
915 876
  ///\code
916 877
  ///typedef TightArcFilterMap<Digraph, const Dijkstra::DistMap, LengthMap> 
917 878
  ///  TightArcFilter;
918 879
  ///TightArcFilter tight_arc_filter(g, dijkstra.distMap(), length);
919 880
  ///
920 881
  ///typedef ArcSubDigraphAdaptor<Digraph, TightArcFilter> SubGA;
921 882
  ///SubGA ga(g, tight_arc_filter);
922 883
  ///\endcode
923 884
  ///Then, the maximum nimber of arc-disjoint \c s-\c t paths are computed 
924 885
  ///with a max flow algorithm Preflow.
925 886
  ///\code
926 887
  ///ConstMap<Arc, int> const_1_map(1);
927 888
  ///Digraph::ArcMap<int> flow(g, 0);
928 889
  ///
929 890
  ///Preflow<SubGA, ConstMap<Arc, int>, Digraph::ArcMap<int> > 
930 891
  ///  preflow(ga, const_1_map, s, t);
931 892
  ///preflow.run();
932 893
  ///\endcode
933 894
  ///Last, the output is:
934 895
  ///\code  
935 896
  ///cout << "maximum number of arc-disjoint shortest path: " 
936 897
  ///     << preflow.flowValue() << endl;
937 898
  ///cout << "arcs of the maximum number of arc-disjoint shortest s-t paths: " 
938 899
  ///     << endl;
939 900
  ///for(ArcIt e(g); e!=INVALID; ++e) 
940 901
  ///  if (preflow.flow(e))
941 902
  ///    cout << " " << g.id(g.source(e)) << "--"
942 903
  ///         << length[e] << "->" << g.id(g.target(e)) << endl;
943 904
  ///\endcode
944 905
  ///The program has the following (expected :-)) output:
945 906
  ///\code
946 907
  ///arcs with lengths (of form id, source--length->target):
947 908
  /// 9, 5--4->6
948 909
  /// 8, 4--2->6
949 910
  /// 7, 3--1->5
950 911
  /// 6, 2--3->5
951 912
  /// 5, 2--5->6
952 913
  /// 4, 2--2->4
953 914
  /// 3, 1--3->4
954 915
  /// 2, 0--1->3
955 916
  /// 1, 0--2->2
956 917
  /// 0, 0--3->1
957 918
  ///s: 0 t: 6
958 919
  ///maximum number of arc-disjoint shortest path: 2
959 920
  ///arcs of the maximum number of arc-disjoint shortest s-t paths:
960 921
  /// 9, 5--4->6
961 922
  /// 8, 4--2->6
962 923
  /// 7, 3--1->5
963 924
  /// 4, 2--2->4
964 925
  /// 2, 0--1->3
965 926
  /// 1, 0--2->2
966 927
  ///\endcode
967 928
  template<typename _Digraph, typename _ArcFilterMap>
968 929
  class ArcSubDigraphAdaptor : 
969 930
    public SubDigraphAdaptor<_Digraph, ConstMap<typename _Digraph::Node, bool>, 
970 931
			     _ArcFilterMap, false> {
971 932
  public:
972 933
    typedef _Digraph Digraph;
973 934
    typedef _ArcFilterMap ArcFilterMap;
974 935

	
975 936
    typedef SubDigraphAdaptor<Digraph, ConstMap<typename Digraph::Node, bool>, 
976 937
			      ArcFilterMap, false> Parent;
938

	
939
    typedef typename Parent::Arc Arc;
940

	
977 941
  protected:
978 942
    ConstMap<typename Digraph::Node, bool> const_true_map;
979 943

	
980 944
    ArcSubDigraphAdaptor() : const_true_map(true) {
981 945
      Parent::setNodeFilterMap(const_true_map);
982 946
    }
983 947

	
984 948
  public:
985 949

	
950
    /// \brief Constructor
951
    ///
952
    /// Creates a arc-sub-digraph-adaptor for the given digraph with
953
    /// given arc map filter.
986 954
    ArcSubDigraphAdaptor(Digraph& digraph, ArcFilterMap& arc_filter) 
987 955
      : Parent(), const_true_map(true) { 
988 956
      Parent::setDigraph(digraph);
989 957
      Parent::setNodeFilterMap(const_true_map);
990 958
      Parent::setArcFilterMap(arc_filter);
991 959
    }
992 960

	
961
    /// \brief Hides the arc of the graph
962
    ///
963
    /// This function hides \c a in the digraph, i.e. the iteration 
964
    /// jumps over it. This is done by simply setting the value of \c a
965
    /// to be false in the corresponding arc-map.
966
    void hide(const Arc& a) const { Parent::hide(a); }
967

	
968
    /// \brief Unhides the arc of the graph
969
    ///
970
    /// The value of \c a is set to be true in the arc-map which stores 
971
    /// hide information. If \c a was hidden previuosly, then it is shown 
972
    /// again
973
    void unHide(const Arc& a) const { Parent::unHide(a); }
974

	
975
    /// \brief Returns true if \c a is hidden.
976
    ///
977
    /// Returns true if \c a is hidden.
978
    ///
979
    bool hidden(const Arc& a) const { return Parent::hidden(a); }
980

	
993 981
  };
994 982

	
995
  /// \brief Just gives back an arc sub digraph adaptor
983
  /// \brief Just gives back an arc-sub-digraph adaptor
996 984
  ///
997
  /// Just gives back an arc sub digraph adaptor
985
  /// Just gives back an arc-sub-digraph adaptor
998 986
  template<typename Digraph, typename ArcFilterMap>
999 987
  ArcSubDigraphAdaptor<const Digraph, ArcFilterMap>
1000 988
  arcSubDigraphAdaptor(const Digraph& digraph, ArcFilterMap& afm) {
1001 989
    return ArcSubDigraphAdaptor<const Digraph, ArcFilterMap>(digraph, afm);
1002 990
  }
1003 991

	
1004 992
  template<typename Digraph, typename ArcFilterMap>
1005 993
  ArcSubDigraphAdaptor<const Digraph, const ArcFilterMap>
1006 994
  arcSubDigraphAdaptor(const Digraph& digraph, const ArcFilterMap& afm) {
1007 995
    return ArcSubDigraphAdaptor<const Digraph, const ArcFilterMap>
1008 996
      (digraph, afm);
1009 997
  }
1010 998

	
1011 999
  template <typename _Digraph>
1012 1000
  class UndirDigraphAdaptorBase { 
1013 1001
  public:
1014 1002
    typedef _Digraph Digraph;
1015 1003
    typedef UndirDigraphAdaptorBase Adaptor;
1016 1004

	
1017 1005
    typedef True UndirectedTag;
1018 1006

	
1019 1007
    typedef typename Digraph::Arc Edge;
1020 1008
    typedef typename Digraph::Node Node;
1021 1009

	
1022 1010
    class Arc : public Edge {
1023 1011
      friend class UndirDigraphAdaptorBase;
1024 1012
    protected:
1025 1013
      bool _forward;
1026 1014

	
1027 1015
      Arc(const Edge& edge, bool forward) :
1028 1016
        Edge(edge), _forward(forward) {}
1029 1017

	
1030 1018
    public:
1031 1019
      Arc() {}
1032 1020

	
1033 1021
      Arc(Invalid) : Edge(INVALID), _forward(true) {}
1034 1022

	
1035 1023
      bool operator==(const Arc &other) const {
1036 1024
	return _forward == other._forward && 
1037 1025
	  static_cast<const Edge&>(*this) == static_cast<const Edge&>(other);
1038 1026
      }
1039 1027
      bool operator!=(const Arc &other) const {
1040 1028
	return _forward != other._forward || 
1041 1029
	  static_cast<const Edge&>(*this) != static_cast<const Edge&>(other);
1042 1030
      }
1043 1031
      bool operator<(const Arc &other) const {
1044 1032
	return _forward < other._forward ||
1045 1033
	  (_forward == other._forward &&
1046 1034
	   static_cast<const Edge&>(*this) < static_cast<const Edge&>(other));
1047 1035
      }
1048 1036
    };
1049 1037

	
1050 1038

	
1051 1039

	
1052 1040
    void first(Node& n) const {
1053 1041
      _digraph->first(n);
1054 1042
    }
1055 1043

	
1056 1044
    void next(Node& n) const {
1057 1045
      _digraph->next(n);
1058 1046
    }
1059 1047

	
1060 1048
    void first(Arc& a) const {
1061 1049
      _digraph->first(a);
1062 1050
      a._forward = true;
1063 1051
    }
1064 1052

	
1065 1053
    void next(Arc& a) const {
1066 1054
      if (a._forward) {
1067 1055
	a._forward = false;
1068 1056
      } else {
1069 1057
	_digraph->next(a);
1070 1058
	a._forward = true;
1071 1059
      }
1072 1060
    }
1073 1061

	
1074 1062
    void first(Edge& e) const {
1075 1063
      _digraph->first(e);
1076 1064
    }
1077 1065

	
1078 1066
    void next(Edge& e) const {
1079 1067
      _digraph->next(e);
1080 1068
    }
1081 1069

	
1082 1070
    void firstOut(Arc& a, const Node& n) const {
1083 1071
      _digraph->firstIn(a, n);
1084 1072
      if( static_cast<const Edge&>(a) != INVALID ) {
1085 1073
	a._forward = false;
1086 1074
      } else {
1087 1075
	_digraph->firstOut(a, n);
1088 1076
	a._forward = true;
1089 1077
      }
1090 1078
    }
1091 1079
    void nextOut(Arc &a) const {
1092 1080
      if (!a._forward) {
1093 1081
	Node n = _digraph->target(a);
... ...
@@ -1300,198 +1288,198 @@
1300 1288

	
1301 1289
    template <typename _Value>
1302 1290
    class NodeMap : public Digraph::template NodeMap<_Value> {
1303 1291
    public:
1304 1292

	
1305 1293
      typedef _Value Value;
1306 1294
      typedef typename Digraph::template NodeMap<Value> Parent;
1307 1295

	
1308 1296
      explicit NodeMap(const Adaptor& adaptor) 
1309 1297
	: Parent(*adaptor._digraph) {}
1310 1298

	
1311 1299
      NodeMap(const Adaptor& adaptor, const _Value& value)
1312 1300
	: Parent(*adaptor._digraph, value) { }
1313 1301

	
1314 1302
    private:
1315 1303
      NodeMap& operator=(const NodeMap& cmap) {
1316 1304
        return operator=<NodeMap>(cmap);
1317 1305
      }
1318 1306

	
1319 1307
      template <typename CMap>
1320 1308
      NodeMap& operator=(const CMap& cmap) {
1321 1309
        Parent::operator=(cmap);
1322 1310
        return *this;
1323 1311
      }
1324 1312
      
1325 1313
    };
1326 1314

	
1327 1315
    template <typename _Value>
1328 1316
    class ArcMap 
1329 1317
      : public SubMapExtender<Adaptor, ArcMapBase<_Value> > 
1330 1318
    {
1331 1319
    public:
1332 1320
      typedef _Value Value;
1333 1321
      typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
1334 1322
    
1335 1323
      ArcMap(const Adaptor& adaptor) 
1336 1324
	: Parent(adaptor) {}
1337 1325

	
1338 1326
      ArcMap(const Adaptor& adaptor, const Value& value) 
1339 1327
	: Parent(adaptor, value) {}
1340 1328
    
1341 1329
    private:
1342 1330
      ArcMap& operator=(const ArcMap& cmap) {
1343 1331
	return operator=<ArcMap>(cmap);
1344 1332
      }
1345 1333
    
1346 1334
      template <typename CMap>
1347 1335
      ArcMap& operator=(const CMap& cmap) {
1348 1336
        Parent::operator=(cmap);
1349 1337
	return *this;
1350 1338
      }
1351 1339
    };
1352 1340
        
1353 1341
    template <typename _Value>
1354 1342
    class EdgeMap : public Digraph::template ArcMap<_Value> {
1355 1343
    public:
1356 1344
      
1357 1345
      typedef _Value Value;
1358 1346
      typedef typename Digraph::template ArcMap<Value> Parent;
1359 1347
      
1360 1348
      explicit EdgeMap(const Adaptor& adaptor) 
1361 1349
	: Parent(*adaptor._digraph) {}
1362 1350

	
1363 1351
      EdgeMap(const Adaptor& adaptor, const Value& value)
1364 1352
	: Parent(*adaptor._digraph, value) {}
1365 1353

	
1366 1354
    private:
1367 1355
      EdgeMap& operator=(const EdgeMap& cmap) {
1368 1356
        return operator=<EdgeMap>(cmap);
1369 1357
      }
1370 1358

	
1371 1359
      template <typename CMap>
1372 1360
      EdgeMap& operator=(const CMap& cmap) {
1373 1361
        Parent::operator=(cmap);
1374 1362
        return *this;
1375 1363
      }
1376 1364

	
1377 1365
    };
1378 1366

	
1379 1367
    typedef typename ItemSetTraits<Digraph, Node>::ItemNotifier NodeNotifier;
1380 1368
    NodeNotifier& notifier(Node) const { return _digraph->notifier(Node()); } 
1381 1369

	
1382 1370
  protected:
1383 1371

	
1384 1372
    UndirDigraphAdaptorBase() : _digraph(0) {}
1385 1373

	
1386 1374
    Digraph* _digraph;
1387 1375

	
1388 1376
    void setDigraph(Digraph& digraph) {
1389 1377
      _digraph = &digraph;
1390 1378
    }
1391 1379
    
1392 1380
  };
1393 1381

	
1394 1382
  ///\ingroup graph_adaptors
1395 1383
  ///
1396
  /// \brief An graph is made from a directed digraph by an adaptor
1384
  /// \brief A graph is made from a directed digraph by an adaptor
1397 1385
  ///
1398 1386
  /// This adaptor makes an undirected graph from a directed
1399
  /// digraph. All arc of the underlying will be showed in the adaptor
1400
  /// as an edge. Let's see an informal example about using
1401
  /// this adaptor:
1387
  /// graph. All arc of the underlying digraph will be showed in the
1388
  /// adaptor as an edge. Let's see an informal example about using
1389
  /// this adaptor.
1402 1390
  ///
1403 1391
  /// There is a network of the streets of a town. Of course there are
1404 1392
  /// some one-way street in the town hence the network is a directed
1405 1393
  /// one. There is a crazy driver who go oppositely in the one-way
1406 1394
  /// street without moral sense. Of course he can pass this streets
1407 1395
  /// slower than the regular way, in fact his speed is half of the
1408 1396
  /// normal speed. How long should he drive to get from a source
1409 1397
  /// point to the target? Let see the example code which calculate it:
1410 1398
  ///
1411 1399
  /// \todo BadCode, SimpleMap does no exists
1412 1400
  ///\code
1413 1401
  /// typedef UndirDigraphAdaptor<Digraph> Graph;
1414 1402
  /// Graph graph(digraph);
1415 1403
  ///
1416 1404
  /// typedef SimpleMap<LengthMap> FLengthMap;
1417 1405
  /// FLengthMap flength(length);
1418 1406
  ///
1419 1407
  /// typedef ScaleMap<LengthMap> RLengthMap;
1420 1408
  /// RLengthMap rlength(length, 2.0);
1421 1409
  ///
1422 1410
  /// typedef Graph::CombinedArcMap<FLengthMap, RLengthMap > ULengthMap;
1423 1411
  /// ULengthMap ulength(flength, rlength);
1424 1412
  /// 
1425 1413
  /// Dijkstra<Graph, ULengthMap> dijkstra(graph, ulength);
1426 1414
  /// std::cout << "Driving time : " << dijkstra.run(src, trg) << std::endl;
1427 1415
  ///\endcode
1428 1416
  ///
1429 1417
  /// The combined arc map makes the length map for the undirected
1430 1418
  /// graph. It is created from a forward and reverse map. The forward
1431 1419
  /// map is created from the original length map with a SimpleMap
1432 1420
  /// adaptor which just makes a read-write map from the reference map
1433 1421
  /// i.e. it forgets that it can be return reference to values. The
1434 1422
  /// reverse map is just the scaled original map with the ScaleMap
1435 1423
  /// adaptor. The combination solves that passing the reverse way
1436 1424
  /// takes double time than the original. To get the driving time we
1437 1425
  /// run the dijkstra algorithm on the graph.
1438 1426
  template<typename _Digraph>
1439 1427
  class UndirDigraphAdaptor 
1440 1428
    : public GraphAdaptorExtender<UndirDigraphAdaptorBase<_Digraph> > {
1441 1429
  public:
1442 1430
    typedef _Digraph Digraph;
1443 1431
    typedef GraphAdaptorExtender<UndirDigraphAdaptorBase<Digraph> > Parent;
1444 1432
  protected:
1445 1433
    UndirDigraphAdaptor() { }
1446 1434
  public:
1447 1435

	
1448 1436
    /// \brief Constructor
1449 1437
    ///
1450 1438
    /// Constructor
1451 1439
    UndirDigraphAdaptor(_Digraph& _digraph) { 
1452 1440
      setDigraph(_digraph);
1453 1441
    }
1454 1442

	
1455 1443
    /// \brief ArcMap combined from two original ArcMap
1456 1444
    ///
1457 1445
    /// This class adapts two original digraph ArcMap to
1458 1446
    /// get an arc map on the adaptor.
1459 1447
    template <typename _ForwardMap, typename _BackwardMap>
1460 1448
    class CombinedArcMap {
1461 1449
    public:
1462 1450
      
1463 1451
      typedef _ForwardMap ForwardMap;
1464 1452
      typedef _BackwardMap BackwardMap;
1465 1453

	
1466 1454
      typedef typename MapTraits<ForwardMap>::ReferenceMapTag ReferenceMapTag;
1467 1455

	
1468 1456
      typedef typename ForwardMap::Value Value;
1469 1457
      typedef typename Parent::Arc Key;
1470 1458

	
1471 1459
      /// \brief Constructor      
1472 1460
      ///
1473 1461
      /// Constructor      
1474 1462
      CombinedArcMap() : _forward(0), _backward(0) {}
1475 1463

	
1476 1464
      /// \brief Constructor      
1477 1465
      ///
1478 1466
      /// Constructor      
1479 1467
      CombinedArcMap(ForwardMap& forward, BackwardMap& backward) 
1480 1468
        : _forward(&forward), _backward(&backward) {}
1481 1469
      
1482 1470

	
1483 1471
      /// \brief Sets the value associated with a key.
1484 1472
      ///
1485 1473
      /// Sets the value associated with a key.
1486 1474
      void set(const Key& e, const Value& a) { 
1487 1475
	if (Parent::direction(e)) {
1488 1476
	  _forward->set(e, a); 
1489 1477
        } else { 
1490 1478
	  _backward->set(e, a);
1491 1479
        } 
1492 1480
      }
1493 1481

	
1494 1482
      /// \brief Returns the value associated with a key.
1495 1483
      ///
1496 1484
      /// Returns the value associated with a key.
1497 1485
      typename MapTraits<ForwardMap>::ConstReturnValue 
... ...
@@ -1709,198 +1697,192 @@
1709 1697
      _forward_filter.setFlow(flow);
1710 1698
      _backward_filter.setFlow(flow);
1711 1699
    }
1712 1700

	
1713 1701
  public:
1714 1702

	
1715 1703
    /// \brief Constructor of the residual digraph.
1716 1704
    ///
1717 1705
    /// Constructor of the residual graph. The parameters are the digraph type,
1718 1706
    /// the flow map, the capacity map and a tolerance object.
1719 1707
    ResDigraphAdaptor(const Digraph& digraph, const CapacityMap& capacity, 
1720 1708
                    FlowMap& flow, const Tolerance& tolerance = Tolerance()) 
1721 1709
      : Parent(), _capacity(&capacity), _flow(&flow), _graph(digraph),
1722 1710
        _forward_filter(capacity, flow, tolerance), 
1723 1711
        _backward_filter(capacity, flow, tolerance),
1724 1712
        _arc_filter(_forward_filter, _backward_filter)
1725 1713
    {
1726 1714
      Parent::setDigraph(_graph);
1727 1715
      Parent::setArcFilterMap(_arc_filter);
1728 1716
    }
1729 1717

	
1730 1718
    typedef typename Parent::Arc Arc;
1731 1719

	
1732 1720
    /// \brief Gives back the residual capacity of the arc.
1733 1721
    ///
1734 1722
    /// Gives back the residual capacity of the arc.
1735 1723
    Value rescap(const Arc& arc) const {
1736 1724
      if (UndirDigraph::direction(arc)) {
1737 1725
        return (*_capacity)[arc] - (*_flow)[arc]; 
1738 1726
      } else {
1739 1727
        return (*_flow)[arc];
1740 1728
      }
1741 1729
    } 
1742 1730

	
1743 1731
    /// \brief Augment on the given arc in the residual digraph.
1744 1732
    ///
1745 1733
    /// Augment on the given arc in the residual digraph. It increase
1746 1734
    /// or decrease the flow on the original arc depend on the direction
1747 1735
    /// of the residual arc.
1748 1736
    void augment(const Arc& e, const Value& a) const {
1749 1737
      if (UndirDigraph::direction(e)) {
1750 1738
        _flow->set(e, (*_flow)[e] + a);
1751 1739
      } else {  
1752 1740
        _flow->set(e, (*_flow)[e] - a);
1753 1741
      }
1754 1742
    }
1755 1743

	
1756 1744
    /// \brief Returns the direction of the arc.
1757 1745
    ///
1758 1746
    /// Returns true when the arc is same oriented as the original arc.
1759 1747
    static bool forward(const Arc& e) {
1760 1748
      return UndirDigraph::direction(e);
1761 1749
    }
1762 1750

	
1763 1751
    /// \brief Returns the direction of the arc.
1764 1752
    ///
1765 1753
    /// Returns true when the arc is opposite oriented as the original arc.
1766 1754
    static bool backward(const Arc& e) {
1767 1755
      return !UndirDigraph::direction(e);
1768 1756
    }
1769 1757

	
1770 1758
    /// \brief Gives back the forward oriented residual arc.
1771 1759
    ///
1772 1760
    /// Gives back the forward oriented residual arc.
1773 1761
    static Arc forward(const typename Digraph::Arc& e) {
1774 1762
      return UndirDigraph::direct(e, true);
1775 1763
    }
1776 1764

	
1777 1765
    /// \brief Gives back the backward oriented residual arc.
1778 1766
    ///
1779 1767
    /// Gives back the backward oriented residual arc.
1780 1768
    static Arc backward(const typename Digraph::Arc& e) {
1781 1769
      return UndirDigraph::direct(e, false);
1782 1770
    }
1783 1771

	
1784 1772
    /// \brief Residual capacity map.
1785 1773
    ///
1786 1774
    /// In generic residual digraphs the residual capacity can be obtained 
1787 1775
    /// as a map. 
1788 1776
    class ResCap {
1789 1777
    protected:
1790 1778
      const Adaptor* _adaptor;
1791 1779
    public:
1792 1780
      typedef Arc Key;
1793 1781
      typedef typename _CapacityMap::Value Value;
1794 1782

	
1795 1783
      ResCap(const Adaptor& adaptor) : _adaptor(&adaptor) {}
1796 1784
      
1797 1785
      Value operator[](const Arc& e) const {
1798 1786
        return _adaptor->rescap(e);
1799 1787
      }
1800 1788
      
1801 1789
    };
1802 1790

	
1803 1791
  };
1804 1792

	
1805
  /// \brief Base class for split digraph adaptor
1806
  ///
1807
  /// Base class of split digraph adaptor. In most case you do not need to
1808
  /// use it directly but the documented member functions of this class can 
1809
  /// be used with the SplitDigraphAdaptor class.
1810
  /// \sa SplitDigraphAdaptor
1811 1793
  template <typename _Digraph>
1812 1794
  class SplitDigraphAdaptorBase {
1813 1795
  public:
1814 1796

	
1815 1797
    typedef _Digraph Digraph;
1816 1798
    typedef DigraphAdaptorBase<const _Digraph> Parent;
1817 1799
    typedef SplitDigraphAdaptorBase Adaptor;
1818 1800

	
1819 1801
    typedef typename Digraph::Node DigraphNode;
1820 1802
    typedef typename Digraph::Arc DigraphArc;
1821 1803

	
1822 1804
    class Node;
1823 1805
    class Arc;
1824 1806

	
1825 1807
  private:
1826 1808

	
1827 1809
    template <typename T> class NodeMapBase;
1828 1810
    template <typename T> class ArcMapBase;
1829 1811

	
1830 1812
  public:
1831 1813
    
1832 1814
    class Node : public DigraphNode {
1833 1815
      friend class SplitDigraphAdaptorBase;
1834 1816
      template <typename T> friend class NodeMapBase;
1835 1817
    private:
1836 1818

	
1837 1819
      bool _in;
1838 1820
      Node(DigraphNode node, bool in)
1839 1821
	: DigraphNode(node), _in(in) {}
1840 1822
      
1841 1823
    public:
1842 1824

	
1843 1825
      Node() {}
1844 1826
      Node(Invalid) : DigraphNode(INVALID), _in(true) {}
1845 1827

	
1846 1828
      bool operator==(const Node& node) const {
1847 1829
	return DigraphNode::operator==(node) && _in == node._in;
1848 1830
      }
1849 1831
      
1850 1832
      bool operator!=(const Node& node) const {
1851 1833
	return !(*this == node);
1852 1834
      }
1853 1835
      
1854 1836
      bool operator<(const Node& node) const {
1855 1837
	return DigraphNode::operator<(node) || 
1856 1838
	  (DigraphNode::operator==(node) && _in < node._in);
1857 1839
      }
1858 1840
    };
1859 1841

	
1860 1842
    class Arc {
1861 1843
      friend class SplitDigraphAdaptorBase;
1862 1844
      template <typename T> friend class ArcMapBase;
1863 1845
    private:
1864 1846
      typedef BiVariant<DigraphArc, DigraphNode> ArcImpl;
1865 1847

	
1866 1848
      explicit Arc(const DigraphArc& arc) : _item(arc) {}
1867 1849
      explicit Arc(const DigraphNode& node) : _item(node) {}
1868 1850
      
1869 1851
      ArcImpl _item;
1870 1852

	
1871 1853
    public:
1872 1854
      Arc() {}
1873 1855
      Arc(Invalid) : _item(DigraphArc(INVALID)) {}
1874 1856

	
1875 1857
      bool operator==(const Arc& arc) const {
1876 1858
        if (_item.firstState()) {
1877 1859
          if (arc._item.firstState()) {
1878 1860
            return _item.first() == arc._item.first();
1879 1861
          }
1880 1862
        } else {
1881 1863
          if (arc._item.secondState()) {
1882 1864
            return _item.second() == arc._item.second();
1883 1865
          }
1884 1866
        }
1885 1867
        return false;
1886 1868
      }
1887 1869
      
1888 1870
      bool operator!=(const Arc& arc) const {
1889 1871
	return !(*this == arc);
1890 1872
      }
1891 1873
      
1892 1874
      bool operator<(const Arc& arc) const {
1893 1875
        if (_item.firstState()) {
1894 1876
          if (arc._item.firstState()) {
1895 1877
            return _item.first() < arc._item.first();
1896 1878
          }
1897 1879
          return false;
1898 1880
        } else {
1899 1881
          if (arc._item.secondState()) {
1900 1882
            return _item.second() < arc._item.second();
1901 1883
          }
1902 1884
          return true;
1903 1885
        }
1904 1886
      }
1905 1887

	
1906 1888
      operator DigraphArc() const { return _item.first(); }
... ...
@@ -1929,244 +1911,220 @@
1929 1911
        e._item.setFirst();
1930 1912
	_digraph->first(e._item.first());
1931 1913
      }
1932 1914
    }
1933 1915

	
1934 1916
    void next(Arc& e) const {
1935 1917
      if (e._item.secondState()) {
1936 1918
	_digraph->next(e._item.second());
1937 1919
        if (e._item.second() == INVALID) {
1938 1920
          e._item.setFirst();
1939 1921
          _digraph->first(e._item.first());
1940 1922
        }
1941 1923
      } else {
1942 1924
	_digraph->next(e._item.first());
1943 1925
      }      
1944 1926
    }
1945 1927

	
1946 1928
    void firstOut(Arc& e, const Node& n) const {
1947 1929
      if (n._in) {
1948 1930
        e._item.setSecond(n);
1949 1931
      } else {
1950 1932
        e._item.setFirst();
1951 1933
	_digraph->firstOut(e._item.first(), n);
1952 1934
      }
1953 1935
    }
1954 1936

	
1955 1937
    void nextOut(Arc& e) const {
1956 1938
      if (!e._item.firstState()) {
1957 1939
	e._item.setFirst(INVALID);
1958 1940
      } else {
1959 1941
	_digraph->nextOut(e._item.first());
1960 1942
      }      
1961 1943
    }
1962 1944

	
1963 1945
    void firstIn(Arc& e, const Node& n) const {
1964 1946
      if (!n._in) {
1965 1947
        e._item.setSecond(n);        
1966 1948
      } else {
1967 1949
        e._item.setFirst();
1968 1950
	_digraph->firstIn(e._item.first(), n);
1969 1951
      }
1970 1952
    }
1971 1953

	
1972 1954
    void nextIn(Arc& e) const {
1973 1955
      if (!e._item.firstState()) {
1974 1956
	e._item.setFirst(INVALID);
1975 1957
      } else {
1976 1958
	_digraph->nextIn(e._item.first());
1977 1959
      }
1978 1960
    }
1979 1961

	
1980 1962
    Node source(const Arc& e) const {
1981 1963
      if (e._item.firstState()) {
1982 1964
	return Node(_digraph->source(e._item.first()), false);
1983 1965
      } else {
1984 1966
	return Node(e._item.second(), true);
1985 1967
      }
1986 1968
    }
1987 1969

	
1988 1970
    Node target(const Arc& e) const {
1989 1971
      if (e._item.firstState()) {
1990 1972
	return Node(_digraph->target(e._item.first()), true);
1991 1973
      } else {
1992 1974
	return Node(e._item.second(), false);
1993 1975
      }
1994 1976
    }
1995 1977

	
1996 1978
    int id(const Node& n) const {
1997 1979
      return (_digraph->id(n) << 1) | (n._in ? 0 : 1);
1998 1980
    }
1999 1981
    Node nodeFromId(int ix) const {
2000 1982
      return Node(_digraph->nodeFromId(ix >> 1), (ix & 1) == 0);
2001 1983
    }
2002 1984
    int maxNodeId() const {
2003 1985
      return 2 * _digraph->maxNodeId() + 1;
2004 1986
    }
2005 1987

	
2006 1988
    int id(const Arc& e) const {
2007 1989
      if (e._item.firstState()) {
2008 1990
        return _digraph->id(e._item.first()) << 1;
2009 1991
      } else {
2010 1992
        return (_digraph->id(e._item.second()) << 1) | 1;
2011 1993
      }
2012 1994
    }
2013 1995
    Arc arcFromId(int ix) const {
2014 1996
      if ((ix & 1) == 0) {
2015 1997
        return Arc(_digraph->arcFromId(ix >> 1));
2016 1998
      } else {
2017 1999
        return Arc(_digraph->nodeFromId(ix >> 1));
2018 2000
      }
2019 2001
    }
2020 2002
    int maxArcId() const {
2021 2003
      return std::max(_digraph->maxNodeId() << 1, 
2022 2004
                      (_digraph->maxArcId() << 1) | 1);
2023 2005
    }
2024 2006

	
2025
    /// \brief Returns true when the node is in-node.
2026
    ///
2027
    /// Returns true when the node is in-node.
2028 2007
    static bool inNode(const Node& n) {
2029 2008
      return n._in;
2030 2009
    }
2031 2010

	
2032
    /// \brief Returns true when the node is out-node.
2033
    ///
2034
    /// Returns true when the node is out-node.
2035 2011
    static bool outNode(const Node& n) {
2036 2012
      return !n._in;
2037 2013
    }
2038 2014

	
2039
    /// \brief Returns true when the arc is arc in the original digraph.
2040
    ///
2041
    /// Returns true when the arc is arc in the original digraph.
2042 2015
    static bool origArc(const Arc& e) {
2043 2016
      return e._item.firstState();
2044 2017
    }
2045 2018

	
2046
    /// \brief Returns true when the arc binds an in-node and an out-node.
2047
    ///
2048
    /// Returns true when the arc binds an in-node and an out-node.
2049 2019
    static bool bindArc(const Arc& e) {
2050 2020
      return e._item.secondState();
2051 2021
    }
2052 2022

	
2053
    /// \brief Gives back the in-node created from the \c node.
2054
    ///
2055
    /// Gives back the in-node created from the \c node.
2056 2023
    static Node inNode(const DigraphNode& n) {
2057 2024
      return Node(n, true);
2058 2025
    }
2059 2026

	
2060
    /// \brief Gives back the out-node created from the \c node.
2061
    ///
2062
    /// Gives back the out-node created from the \c node.
2063 2027
    static Node outNode(const DigraphNode& n) {
2064 2028
      return Node(n, false);
2065 2029
    }
2066 2030

	
2067
    /// \brief Gives back the arc binds the two part of the node.
2068
    /// 
2069
    /// Gives back the arc binds the two part of the node.
2070 2031
    static Arc arc(const DigraphNode& n) {
2071 2032
      return Arc(n);
2072 2033
    }
2073 2034

	
2074
    /// \brief Gives back the arc of the original arc.
2075
    /// 
2076
    /// Gives back the arc of the original arc.
2077 2035
    static Arc arc(const DigraphArc& e) {
2078 2036
      return Arc(e);
2079 2037
    }
2080 2038

	
2081 2039
    typedef True NodeNumTag;
2082 2040

	
2083 2041
    int nodeNum() const {
2084 2042
      return  2 * countNodes(*_digraph);
2085 2043
    }
2086 2044

	
2087 2045
    typedef True EdgeNumTag;
2088 2046
    int arcNum() const {
2089 2047
      return countArcs(*_digraph) + countNodes(*_digraph);
2090 2048
    }
2091 2049

	
2092 2050
    typedef True FindEdgeTag;
2093 2051
    Arc findArc(const Node& u, const Node& v, 
2094 2052
		const Arc& prev = INVALID) const {
2095 2053
      if (inNode(u)) {
2096 2054
        if (outNode(v)) {
2097 2055
          if (static_cast<const DigraphNode&>(u) == 
2098 2056
              static_cast<const DigraphNode&>(v) && prev == INVALID) {
2099 2057
            return Arc(u);
2100 2058
          }
2101 2059
        }
2102 2060
      } else {
2103 2061
        if (inNode(v)) {
2104 2062
          return Arc(::lemon::findArc(*_digraph, u, v, prev));
2105 2063
        }
2106 2064
      }
2107 2065
      return INVALID;
2108 2066
    }
2109 2067

	
2110 2068
  private:
2111 2069
    
2112 2070
    template <typename _Value>
2113 2071
    class NodeMapBase 
2114 2072
      : public MapTraits<typename Parent::template NodeMap<_Value> > {
2115 2073
      typedef typename Parent::template NodeMap<_Value> NodeImpl;
2116 2074
    public:
2117 2075
      typedef Node Key;
2118 2076
      typedef _Value Value;
2119 2077
      
2120 2078
      NodeMapBase(const Adaptor& adaptor) 
2121 2079
	: _in_map(*adaptor._digraph), _out_map(*adaptor._digraph) {}
2122 2080
      NodeMapBase(const Adaptor& adaptor, const Value& value) 
2123 2081
	: _in_map(*adaptor._digraph, value), 
2124 2082
	  _out_map(*adaptor._digraph, value) {}
2125 2083

	
2126 2084
      void set(const Node& key, const Value& val) {
2127 2085
	if (Adaptor::inNode(key)) { _in_map.set(key, val); }
2128 2086
	else {_out_map.set(key, val); }
2129 2087
      }
2130 2088
      
2131 2089
      typename MapTraits<NodeImpl>::ReturnValue 
2132 2090
      operator[](const Node& key) {
2133 2091
	if (Adaptor::inNode(key)) { return _in_map[key]; }
2134 2092
	else { return _out_map[key]; }
2135 2093
      }
2136 2094

	
2137 2095
      typename MapTraits<NodeImpl>::ConstReturnValue
2138 2096
      operator[](const Node& key) const {
2139 2097
	if (Adaptor::inNode(key)) { return _in_map[key]; }
2140 2098
	else { return _out_map[key]; }
2141 2099
      }
2142 2100

	
2143 2101
    private:
2144 2102
      NodeImpl _in_map, _out_map;
2145 2103
    };
2146 2104

	
2147 2105
    template <typename _Value>
2148 2106
    class ArcMapBase 
2149 2107
      : public MapTraits<typename Parent::template ArcMap<_Value> > {
2150 2108
      typedef typename Parent::template ArcMap<_Value> ArcImpl;
2151 2109
      typedef typename Parent::template NodeMap<_Value> NodeImpl;
2152 2110
    public:
2153 2111
      typedef Arc Key;
2154 2112
      typedef _Value Value;
2155 2113

	
2156 2114
      ArcMapBase(const Adaptor& adaptor) 
2157 2115
	: _arc_map(*adaptor._digraph), _node_map(*adaptor._digraph) {}
2158 2116
      ArcMapBase(const Adaptor& adaptor, const Value& value) 
2159 2117
	: _arc_map(*adaptor._digraph, value), 
2160 2118
	  _node_map(*adaptor._digraph, value) {}
2161 2119

	
2162 2120
      void set(const Arc& key, const Value& val) {
2163 2121
	if (Adaptor::origArc(key)) { 
2164 2122
          _arc_map.set(key._item.first(), val); 
2165 2123
        } else {
2166 2124
          _node_map.set(key._item.second(), val); 
2167 2125
        }
2168 2126
      }
2169 2127
      
2170 2128
      typename MapTraits<ArcImpl>::ReturnValue
2171 2129
      operator[](const Arc& key) {
2172 2130
	if (Adaptor::origArc(key)) { 
... ...
@@ -2182,257 +2140,316 @@
2182 2140
          return _arc_map[key._item.first()];
2183 2141
        } else {
2184 2142
          return _node_map[key._item.second()];
2185 2143
        }
2186 2144
      }
2187 2145

	
2188 2146
    private:
2189 2147
      ArcImpl _arc_map;
2190 2148
      NodeImpl _node_map;
2191 2149
    };
2192 2150

	
2193 2151
  public:
2194 2152

	
2195 2153
    template <typename _Value>
2196 2154
    class NodeMap 
2197 2155
      : public SubMapExtender<Adaptor, NodeMapBase<_Value> > 
2198 2156
    {
2199 2157
    public:
2200 2158
      typedef _Value Value;
2201 2159
      typedef SubMapExtender<Adaptor, NodeMapBase<Value> > Parent;
2202 2160
    
2203 2161
      NodeMap(const Adaptor& adaptor) 
2204 2162
	: Parent(adaptor) {}
2205 2163

	
2206 2164
      NodeMap(const Adaptor& adaptor, const Value& value) 
2207 2165
	: Parent(adaptor, value) {}
2208 2166
    
2209 2167
    private:
2210 2168
      NodeMap& operator=(const NodeMap& cmap) {
2211 2169
	return operator=<NodeMap>(cmap);
2212 2170
      }
2213 2171
    
2214 2172
      template <typename CMap>
2215 2173
      NodeMap& operator=(const CMap& cmap) {
2216 2174
        Parent::operator=(cmap);
2217 2175
	return *this;
2218 2176
      }
2219 2177
    };
2220 2178

	
2221 2179
    template <typename _Value>
2222 2180
    class ArcMap 
2223 2181
      : public SubMapExtender<Adaptor, ArcMapBase<_Value> > 
2224 2182
    {
2225 2183
    public:
2226 2184
      typedef _Value Value;
2227 2185
      typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
2228 2186
    
2229 2187
      ArcMap(const Adaptor& adaptor) 
2230 2188
	: Parent(adaptor) {}
2231 2189

	
2232 2190
      ArcMap(const Adaptor& adaptor, const Value& value) 
2233 2191
	: Parent(adaptor, value) {}
2234 2192
    
2235 2193
    private:
2236 2194
      ArcMap& operator=(const ArcMap& cmap) {
2237 2195
	return operator=<ArcMap>(cmap);
2238 2196
      }
2239 2197
    
2240 2198
      template <typename CMap>
2241 2199
      ArcMap& operator=(const CMap& cmap) {
2242 2200
        Parent::operator=(cmap);
2243 2201
	return *this;
2244 2202
      }
2245 2203
    };
2246 2204

	
2247 2205
  protected:
2248 2206

	
2249 2207
    SplitDigraphAdaptorBase() : _digraph(0) {}
2250 2208

	
2251 2209
    Digraph* _digraph;
2252 2210

	
2253 2211
    void setDigraph(Digraph& digraph) {
2254 2212
      _digraph = &digraph;
2255 2213
    }
2256 2214
    
2257 2215
  };
2258 2216

	
2259 2217
  /// \ingroup graph_adaptors
2260 2218
  ///
2261 2219
  /// \brief Split digraph adaptor class
2262 2220
  /// 
2263 2221
  /// This is an digraph adaptor which splits all node into an in-node
2264 2222
  /// and an out-node. Formaly, the adaptor replaces each \f$ u \f$
2265 2223
  /// node in the digraph with two node, \f$ u_{in} \f$ node and 
2266 2224
  /// \f$ u_{out} \f$ node. If there is an \f$ (v, u) \f$ arc in the 
2267 2225
  /// original digraph the new target of the arc will be \f$ u_{in} \f$ and
2268 2226
  /// similarly the source of the original \f$ (u, v) \f$ arc will be
2269 2227
  /// \f$ u_{out} \f$.  The adaptor will add for each node in the 
2270 2228
  /// original digraph an additional arc which will connect 
2271 2229
  /// \f$ (u_{in}, u_{out}) \f$.
2272 2230
  ///
2273 2231
  /// The aim of this class is to run algorithm with node costs if the 
2274 2232
  /// algorithm can use directly just arc costs. In this case we should use
2275 2233
  /// a \c SplitDigraphAdaptor and set the node cost of the digraph to the
2276 2234
  /// bind arc in the adapted digraph.
2277 2235
  /// 
2278
  /// By example a maximum flow algoritm can compute how many arc
2236
  /// For example a maximum flow algorithm can compute how many arc
2279 2237
  /// disjoint paths are in the digraph. But we would like to know how
2280 2238
  /// many node disjoint paths are in the digraph. First we have to
2281 2239
  /// adapt the digraph with the \c SplitDigraphAdaptor. Then run the flow
2282 2240
  /// algorithm on the adapted digraph. The bottleneck of the flow will
2283 2241
  /// be the bind arcs which bounds the flow with the count of the
2284 2242
  /// node disjoint paths.
2285 2243
  ///
2286 2244
  ///\code
2287 2245
  ///
2288 2246
  /// typedef SplitDigraphAdaptor<SmartDigraph> SDigraph;
2289 2247
  ///
2290 2248
  /// SDigraph sdigraph(digraph);
2291 2249
  ///
2292 2250
  /// typedef ConstMap<SDigraph::Arc, int> SCapacity;
2293 2251
  /// SCapacity scapacity(1);
2294 2252
  ///
2295 2253
  /// SDigraph::ArcMap<int> sflow(sdigraph);
2296 2254
  ///
2297 2255
  /// Preflow<SDigraph, SCapacity> 
2298 2256
  ///   spreflow(sdigraph, scapacity, 
2299 2257
  ///            SDigraph::outNode(source), SDigraph::inNode(target));
2300 2258
  ///                                            
2301 2259
  /// spreflow.run();
2302 2260
  ///
2303 2261
  ///\endcode
2304 2262
  ///
2305 2263
  /// The result of the mamixum flow on the original digraph
2306 2264
  /// shows the next figure:
2307 2265
  ///
2308 2266
  /// \image html arc_disjoint.png
2309 2267
  /// \image latex arc_disjoint.eps "Arc disjoint paths" width=\textwidth
2310 2268
  /// 
2311 2269
  /// And the maximum flow on the adapted digraph:
2312 2270
  ///
2313 2271
  /// \image html node_disjoint.png
2314 2272
  /// \image latex node_disjoint.eps "Node disjoint paths" width=\textwidth
2315 2273
  ///
2316 2274
  /// The second solution contains just 3 disjoint paths while the first 4.
2317 2275
  /// The full code can be found in the \ref disjoint_paths_demo.cc demo file.
2318 2276
  ///
2319 2277
  /// This digraph adaptor is fully conform to the 
2320 2278
  /// \ref concepts::Digraph "Digraph" concept and
2321 2279
  /// contains some additional member functions and types. The 
2322 2280
  /// documentation of some member functions may be found just in the
2323 2281
  /// SplitDigraphAdaptorBase class.
2324 2282
  ///
2325 2283
  /// \sa SplitDigraphAdaptorBase
2326 2284
  template <typename _Digraph>
2327 2285
  class SplitDigraphAdaptor 
2328 2286
    : public DigraphAdaptorExtender<SplitDigraphAdaptorBase<_Digraph> > {
2329 2287
  public:
2330 2288
    typedef _Digraph Digraph;
2331 2289
    typedef DigraphAdaptorExtender<SplitDigraphAdaptorBase<Digraph> > Parent;
2332 2290

	
2291
    typedef typename Digraph::Node DigraphNode;
2292
    typedef typename Digraph::Arc DigraphArc;
2293

	
2333 2294
    typedef typename Parent::Node Node;
2334 2295
    typedef typename Parent::Arc Arc;
2335 2296

	
2336 2297
    /// \brief Constructor of the adaptor.
2337 2298
    ///
2338 2299
    /// Constructor of the adaptor.
2339 2300
    SplitDigraphAdaptor(Digraph& g) {
2340 2301
      Parent::setDigraph(g);
2341 2302
    }
2342 2303

	
2304
    /// \brief Returns true when the node is in-node.
2305
    ///
2306
    /// Returns true when the node is in-node.
2307
    static bool inNode(const Node& n) {
2308
      return Parent::inNode(n);
2309
    }
2310

	
2311
    /// \brief Returns true when the node is out-node.
2312
    ///
2313
    /// Returns true when the node is out-node.
2314
    static bool outNode(const Node& n) {
2315
      return Parent::outNode(n);
2316
    }
2317

	
2318
    /// \brief Returns true when the arc is arc in the original digraph.
2319
    ///
2320
    /// Returns true when the arc is arc in the original digraph.
2321
    static bool origArc(const Arc& a) {
2322
      return Parent::origArc(a);
2323
    }
2324

	
2325
    /// \brief Returns true when the arc binds an in-node and an out-node.
2326
    ///
2327
    /// Returns true when the arc binds an in-node and an out-node.
2328
    static bool bindArc(const Arc& a) {
2329
      return Parent::bindArc(a);
2330
    }
2331

	
2332
    /// \brief Gives back the in-node created from the \c node.
2333
    ///
2334
    /// Gives back the in-node created from the \c node.
2335
    static Node inNode(const DigraphNode& n) {
2336
      return Parent::inNode(n);
2337
    }
2338

	
2339
    /// \brief Gives back the out-node created from the \c node.
2340
    ///
2341
    /// Gives back the out-node created from the \c node.
2342
    static Node outNode(const DigraphNode& n) {
2343
      return Parent::outNode(n);
2344
    }
2345

	
2346
    /// \brief Gives back the arc binds the two part of the node.
2347
    /// 
2348
    /// Gives back the arc binds the two part of the node.
2349
    static Arc arc(const DigraphNode& n) {
2350
      return Parent::arc(n);
2351
    }
2352

	
2353
    /// \brief Gives back the arc of the original arc.
2354
    /// 
2355
    /// Gives back the arc of the original arc.
2356
    static Arc arc(const DigraphArc& a) {
2357
      return Parent::arc(a);
2358
    }
2359

	
2343 2360
    /// \brief NodeMap combined from two original NodeMap
2344 2361
    ///
2345 2362
    /// This class adapt two of the original digraph NodeMap to
2346 2363
    /// get a node map on the adapted digraph.
2347 2364
    template <typename InNodeMap, typename OutNodeMap>
2348 2365
    class CombinedNodeMap {
2349 2366
    public:
2350 2367

	
2351 2368
      typedef Node Key;
2352 2369
      typedef typename InNodeMap::Value Value;
2353 2370

	
2354 2371
      /// \brief Constructor
2355 2372
      ///
2356 2373
      /// Constructor.
2357 2374
      CombinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) 
2358 2375
	: _in_map(in_map), _out_map(out_map) {}
2359 2376

	
2360 2377
      /// \brief The subscript operator.
2361 2378
      ///
2362 2379
      /// The subscript operator.
2363 2380
      Value& operator[](const Key& key) {
2364 2381
	if (Parent::inNode(key)) {
2365 2382
	  return _in_map[key];
2366 2383
	} else {
2367 2384
	  return _out_map[key];
2368 2385
	}
2369 2386
      }
2370 2387

	
2371 2388
      /// \brief The const subscript operator.
2372 2389
      ///
2373 2390
      /// The const subscript operator.
2374 2391
      Value operator[](const Key& key) const {
2375 2392
	if (Parent::inNode(key)) {
2376 2393
	  return _in_map[key];
2377 2394
	} else {
2378 2395
	  return _out_map[key];
2379 2396
	}
2380 2397
      }
2381 2398

	
2382 2399
      /// \brief The setter function of the map.
2383 2400
      /// 
2384 2401
      /// The setter function of the map.
2385 2402
      void set(const Key& key, const Value& value) {
2386 2403
	if (Parent::inNode(key)) {
2387 2404
	  _in_map.set(key, value);
2388 2405
	} else {
2389 2406
	  _out_map.set(key, value);
2390 2407
	}
2391 2408
      }
2392 2409
      
2393 2410
    private:
2394 2411
      
2395 2412
      InNodeMap& _in_map;
2396 2413
      OutNodeMap& _out_map;
2397 2414
      
2398 2415
    };
2399 2416

	
2400 2417

	
2401 2418
    /// \brief Just gives back a combined node map.
2402 2419
    /// 
2403 2420
    /// Just gives back a combined node map.
2404 2421
    template <typename InNodeMap, typename OutNodeMap>
2405 2422
    static CombinedNodeMap<InNodeMap, OutNodeMap> 
2406 2423
    combinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) {
2407 2424
      return CombinedNodeMap<InNodeMap, OutNodeMap>(in_map, out_map);
2408 2425
    }
2409 2426

	
2410 2427
    template <typename InNodeMap, typename OutNodeMap>
2411 2428
    static CombinedNodeMap<const InNodeMap, OutNodeMap> 
2412 2429
    combinedNodeMap(const InNodeMap& in_map, OutNodeMap& out_map) {
2413 2430
      return CombinedNodeMap<const InNodeMap, OutNodeMap>(in_map, out_map);
2414 2431
    }
2415 2432

	
2416 2433
    template <typename InNodeMap, typename OutNodeMap>
2417 2434
    static CombinedNodeMap<InNodeMap, const OutNodeMap> 
2418 2435
    combinedNodeMap(InNodeMap& in_map, const OutNodeMap& out_map) {
2419 2436
      return CombinedNodeMap<InNodeMap, const OutNodeMap>(in_map, out_map);
2420 2437
    }
2421 2438

	
2422 2439
    template <typename InNodeMap, typename OutNodeMap>
2423 2440
    static CombinedNodeMap<const InNodeMap, const OutNodeMap> 
2424 2441
    combinedNodeMap(const InNodeMap& in_map, const OutNodeMap& out_map) {
2425 2442
      return CombinedNodeMap<const InNodeMap, 
2426 2443
        const OutNodeMap>(in_map, out_map);
2427 2444
    }
2428 2445

	
2429 2446
    /// \brief ArcMap combined from an original ArcMap and NodeMap
2430 2447
    ///
2431 2448
    /// This class adapt an original digraph ArcMap and NodeMap to
2432 2449
    /// get an arc map on the adapted digraph.
2433 2450
    template <typename DigraphArcMap, typename DigraphNodeMap>
2434 2451
    class CombinedArcMap {
2435 2452
    public:
2436 2453
      
2437 2454
      typedef Arc Key;
2438 2455
      typedef typename DigraphArcMap::Value Value;
Ignore white space 6 line context
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-2008
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_GRAPH_ADAPTOR_H
20 20
#define LEMON_GRAPH_ADAPTOR_H
21 21

	
22 22
///\ingroup graph_adaptors
23 23
///\file
24 24
///\brief Several graph adaptors.
25 25
///
26 26
///This file contains several useful undirected graph adaptor classes.
27 27

	
28 28
#include <lemon/core.h>
29 29
#include <lemon/maps.h>
30 30
#include <lemon/bits/graph_adaptor_extender.h>
31 31

	
32 32
namespace lemon {
33 33

	
34
  /// \brief Base type for the Graph Adaptors
35
  ///
36
  /// This is the base type for most of LEMON graph adaptors. 
37
  /// This class implements a trivial graph adaptor i.e. it only wraps the 
38
  /// functions and types of the graph. The purpose of this class is to 
39
  /// make easier implementing graph adaptors. E.g. if an adaptor is 
40
  /// considered which differs from the wrapped graph only in some of its 
41
  /// functions or types, then it can be derived from GraphAdaptor, and only 
42
  /// the differences should be implemented.
43 34
  template<typename _Graph>
44 35
  class GraphAdaptorBase {
45 36
  public:
46 37
    typedef _Graph Graph;
47 38
    typedef Graph ParentGraph;
48 39

	
49 40
  protected:
50 41
    Graph* _graph;
51 42

	
52 43
    GraphAdaptorBase() : _graph(0) {}
53 44

	
54 45
    void setGraph(Graph& graph) { _graph = &graph; }
55 46

	
56 47
  public:
57 48
    GraphAdaptorBase(Graph& graph) : _graph(&graph) {}
58 49
 
59 50
    typedef typename Graph::Node Node;
60 51
    typedef typename Graph::Arc Arc;
61 52
    typedef typename Graph::Edge Edge;
62 53
   
63 54
    void first(Node& i) const { _graph->first(i); }
64 55
    void first(Arc& i) const { _graph->first(i); }
65 56
    void first(Edge& i) const { _graph->first(i); }
66 57
    void firstIn(Arc& i, const Node& n) const { _graph->firstIn(i, n); }
67 58
    void firstOut(Arc& i, const Node& n ) const { _graph->firstOut(i, n); }
68 59
    void firstInc(Edge &i, bool &d, const Node &n) const {
69 60
      _graph->firstInc(i, d, n);
70 61
    }
71 62

	
72 63
    void next(Node& i) const { _graph->next(i); }
73 64
    void next(Arc& i) const { _graph->next(i); }
74 65
    void next(Edge& i) const { _graph->next(i); }
75 66
    void nextIn(Arc& i) const { _graph->nextIn(i); }
76 67
    void nextOut(Arc& i) const { _graph->nextOut(i); }
77 68
    void nextInc(Edge &i, bool &d) const { _graph->nextInc(i, d); }
78 69

	
79 70
    Node u(const Edge& e) const { return _graph->u(e); }
80 71
    Node v(const Edge& e) const { return _graph->v(e); }
81 72

	
82 73
    Node source(const Arc& a) const { return _graph->source(a); }
83 74
    Node target(const Arc& a) const { return _graph->target(a); }
84 75

	
85 76
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
86 77
    int nodeNum() const { return _graph->nodeNum(); }
87 78
    
88 79
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
89 80
    int arcNum() const { return _graph->arcNum(); }
90 81
    int edgeNum() const { return _graph->edgeNum(); }
91 82

	
92 83
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
93 84
    Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
94 85
      return _graph->findArc(u, v, prev);
95 86
    }
96 87
    Edge findEdge(const Node& u, const Node& v, const Edge& prev = INVALID) {
97 88
      return _graph->findEdge(u, v, prev);
98 89
    }
99 90
  
100 91
    Node addNode() { return _graph->addNode(); }
101 92
    Edge addEdge(const Node& u, const Node& v) { return _graph->addEdge(u, v); }
102 93

	
103 94
    void erase(const Node& i) { _graph->erase(i); }
104 95
    void erase(const Edge& i) { _graph->erase(i); }
105 96
  
106 97
    void clear() { _graph->clear(); }
107 98
    
108 99
    bool direction(const Arc& a) const { return _graph->direction(a); }
109 100
    Arc direct(const Edge& e, bool d) const { return _graph->direct(e, d); }
110 101

	
111 102
    int id(const Node& v) const { return _graph->id(v); }
112 103
    int id(const Arc& a) const { return _graph->id(a); }
113 104
    int id(const Edge& e) const { return _graph->id(e); }
114 105

	
115 106
    Node nodeFromId(int ix) const { return _graph->nodeFromId(ix); }
116 107
    Arc arcFromId(int ix) const { return _graph->arcFromId(ix); }
117 108
    Edge edgeFromId(int ix) const { return _graph->edgeFromId(ix); }
118 109

	
119 110
    int maxNodeId() const { return _graph->maxNodeId(); }
120 111
    int maxArcId() const { return _graph->maxArcId(); }
121 112
    int maxEdgeId() const { return _graph->maxEdgeId(); }
122 113

	
123 114
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
124 115
    NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); } 
125 116

	
126 117
    typedef typename ItemSetTraits<Graph, Arc>::ItemNotifier ArcNotifier;
127 118
    ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); } 
128 119

	
129 120
    typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
130 121
    EdgeNotifier& notifier(Edge) const { return _graph->notifier(Edge()); } 
131 122

	
132 123
    template <typename _Value>
133 124
    class NodeMap : public Graph::template NodeMap<_Value> {
134 125
    public:
135 126
      typedef typename Graph::template NodeMap<_Value> Parent;
136 127
      explicit NodeMap(const GraphAdaptorBase<Graph>& adapter) 
137 128
	: Parent(*adapter._graph) {}
138 129
      NodeMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
139 130
	: Parent(*adapter._graph, value) {}
140 131

	
141 132
    private:
142 133
      NodeMap& operator=(const NodeMap& cmap) {
143 134
	return operator=<NodeMap>(cmap);
144 135
      }
145 136

	
146 137
      template <typename CMap>
147 138
      NodeMap& operator=(const CMap& cmap) {
148 139
        Parent::operator=(cmap);
149 140
        return *this;
150 141
      }
151 142
      
152 143
    };
153 144

	
154 145
    template <typename _Value>
155 146
    class ArcMap : public Graph::template ArcMap<_Value> {
156 147
    public:
157 148
      typedef typename Graph::template ArcMap<_Value> Parent;
158 149
      explicit ArcMap(const GraphAdaptorBase<Graph>& adapter) 
159 150
	: Parent(*adapter._graph) {}
160 151
      ArcMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
161 152
	: Parent(*adapter._graph, value) {}
162 153

	
163 154
    private:
164 155
      ArcMap& operator=(const ArcMap& cmap) {
165 156
	return operator=<ArcMap>(cmap);
166 157
      }
167 158

	
168 159
      template <typename CMap>
169 160
      ArcMap& operator=(const CMap& cmap) {
170 161
        Parent::operator=(cmap);
171 162
	return *this;
172 163
      }
173 164
    };
174 165

	
175 166
    template <typename _Value>
176 167
    class EdgeMap : public Graph::template EdgeMap<_Value> {
177 168
    public:
178 169
      typedef typename Graph::template EdgeMap<_Value> Parent;
179 170
      explicit EdgeMap(const GraphAdaptorBase<Graph>& adapter) 
180 171
	: Parent(*adapter._graph) {}
181 172
      EdgeMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
182 173
	: Parent(*adapter._graph, value) {}
183 174

	
184 175
    private:
185 176
      EdgeMap& operator=(const EdgeMap& cmap) {
186 177
	return operator=<EdgeMap>(cmap);
187 178
      }
188 179

	
189 180
      template <typename CMap>
190 181
      EdgeMap& operator=(const CMap& cmap) {
191 182
        Parent::operator=(cmap);
192 183
        return *this;
193 184
      }
194 185
    };
195 186

	
196 187
  };
197 188

	
198
  /// \ingroup graph_adaptors
199
  ///
200
  /// \brief Trivial graph adaptor
201
  ///
202
  /// This class is an adaptor which does not change the adapted undirected
203
  /// graph. It can be used only to test the graph adaptors.
204
  template <typename _Graph>
205
  class GraphAdaptor 
206
    : public GraphAdaptorExtender< GraphAdaptorBase<_Graph> > { 
207
  public:
208
    typedef _Graph Graph;
209
    typedef GraphAdaptorExtender<GraphAdaptorBase<_Graph> > Parent;
210
  protected:
211
    GraphAdaptor() : Parent() {}
212

	
213
  public:
214
    explicit GraphAdaptor(Graph& graph) { setGraph(graph); }
215
  };
216

	
217 189
  template <typename _Graph, typename NodeFilterMap, 
218 190
	    typename EdgeFilterMap, bool checked = true>
219 191
  class SubGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
220 192
  public:
221 193
    typedef _Graph Graph;
222 194
    typedef SubGraphAdaptorBase Adaptor;
223 195
    typedef GraphAdaptorBase<_Graph> Parent;
224 196
  protected:
225 197

	
226 198
    NodeFilterMap* _node_filter_map;
227 199
    EdgeFilterMap* _edge_filter_map;
228 200

	
229 201
    SubGraphAdaptorBase() 
230 202
      : Parent(), _node_filter_map(0), _edge_filter_map(0) { }
231 203

	
232 204
    void setNodeFilterMap(NodeFilterMap& node_filter_map) {
233 205
      _node_filter_map=&node_filter_map;
234 206
    }
235 207
    void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
236 208
      _edge_filter_map=&edge_filter_map;
237 209
    }
238 210

	
239 211
  public:
240 212

	
241 213
    typedef typename Parent::Node Node;
242 214
    typedef typename Parent::Arc Arc;
243 215
    typedef typename Parent::Edge Edge;
244 216

	
245 217
    void first(Node& i) const { 
246 218
      Parent::first(i); 
247 219
      while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i); 
248 220
    }
249 221

	
250 222
    void first(Arc& i) const { 
251 223
      Parent::first(i); 
252 224
      while (i!=INVALID && (!(*_edge_filter_map)[i] 
253 225
	     || !(*_node_filter_map)[Parent::source(i)]
254 226
	     || !(*_node_filter_map)[Parent::target(i)])) Parent::next(i); 
255 227
    }
256 228

	
257 229
    void first(Edge& i) const { 
258 230
      Parent::first(i); 
259 231
      while (i!=INVALID && (!(*_edge_filter_map)[i] 
260 232
	     || !(*_node_filter_map)[Parent::u(i)]
261 233
	     || !(*_node_filter_map)[Parent::v(i)])) Parent::next(i); 
262 234
    }
263 235

	
264 236
    void firstIn(Arc& i, const Node& n) const { 
265 237
      Parent::firstIn(i, n); 
266 238
      while (i!=INVALID && (!(*_edge_filter_map)[i] 
267 239
	     || !(*_node_filter_map)[Parent::source(i)])) Parent::nextIn(i); 
268 240
    }
269 241

	
270 242
    void firstOut(Arc& i, const Node& n) const { 
271 243
      Parent::firstOut(i, n); 
272 244
      while (i!=INVALID && (!(*_edge_filter_map)[i] 
273 245
	     || !(*_node_filter_map)[Parent::target(i)])) Parent::nextOut(i); 
274 246
    }
275 247

	
276 248
    void firstInc(Edge& i, bool& d, const Node& n) const { 
277 249
      Parent::firstInc(i, d, n); 
278 250
      while (i!=INVALID && (!(*_edge_filter_map)[i] 
279 251
            || !(*_node_filter_map)[Parent::u(i)]
280 252
            || !(*_node_filter_map)[Parent::v(i)])) Parent::nextInc(i, d); 
281 253
    }
282 254

	
283 255
    void next(Node& i) const { 
284 256
      Parent::next(i); 
285 257
      while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i); 
286 258
    }
287 259

	
288 260
    void next(Arc& i) const { 
289 261
      Parent::next(i); 
290 262
      while (i!=INVALID && (!(*_edge_filter_map)[i] 
291 263
	     || !(*_node_filter_map)[Parent::source(i)]
292 264
	     || !(*_node_filter_map)[Parent::target(i)])) Parent::next(i); 
293 265
    }
294 266

	
295 267
    void next(Edge& i) const { 
296 268
      Parent::next(i); 
297 269
      while (i!=INVALID && (!(*_edge_filter_map)[i] 
298 270
	     || !(*_node_filter_map)[Parent::u(i)]
299 271
	     || !(*_node_filter_map)[Parent::v(i)])) Parent::next(i); 
300 272
    }
301 273

	
302 274
    void nextIn(Arc& i) const { 
303 275
      Parent::nextIn(i); 
304 276
      while (i!=INVALID && (!(*_edge_filter_map)[i] 
305 277
	     || !(*_node_filter_map)[Parent::source(i)])) Parent::nextIn(i); 
306 278
    }
307 279

	
308 280
    void nextOut(Arc& i) const { 
309 281
      Parent::nextOut(i); 
310 282
      while (i!=INVALID && (!(*_edge_filter_map)[i] 
311 283
	     || !(*_node_filter_map)[Parent::target(i)])) Parent::nextOut(i); 
312 284
    }
313 285

	
314 286
    void nextInc(Edge& i, bool& d) const { 
315 287
      Parent::nextInc(i, d); 
316 288
      while (i!=INVALID && (!(*_edge_filter_map)[i]
317 289
            || !(*_node_filter_map)[Parent::u(i)]
318 290
            || !(*_node_filter_map)[Parent::v(i)])) Parent::nextInc(i, d); 
319 291
    }
320 292

	
321
    /// \brief Hide the given node in the graph.
322
    ///
323
    /// This function hides \c n in the graph, i.e. the iteration 
324
    /// jumps over it. This is done by simply setting the value of \c n  
325
    /// to be false in the corresponding node-map.
326 293
    void hide(const Node& n) const { _node_filter_map->set(n, false); }
327

	
328
    /// \brief Hide the given edge in the graph.
329
    ///
330
    /// This function hides \c e in the graph, i.e. the iteration 
331
    /// jumps over it. This is done by simply setting the value of \c e  
332
    /// to be false in the corresponding edge-map.
333 294
    void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
334 295

	
335
    /// \brief Unhide the given node in the graph.
336
    ///
337
    /// The value of \c n is set to be true in the node-map which stores 
338
    /// hide information. If \c n was hidden previuosly, then it is shown 
339
    /// again
340
     void unHide(const Node& n) const { _node_filter_map->set(n, true); }
341

	
342
    /// \brief Hide the given edge in the graph.
343
    ///
344
    /// The value of \c e is set to be true in the edge-map which stores 
345
    /// hide information. If \c e was hidden previuosly, then it is shown 
346
    /// again
296
    void unHide(const Node& n) const { _node_filter_map->set(n, true); }
347 297
    void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
348 298

	
349
    /// \brief Returns true if \c n is hidden.
350
    ///
351
    /// Returns true if \c n is hidden.
352 299
    bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; }
353

	
354
    /// \brief Returns true if \c e is hidden.
355
    ///
356
    /// Returns true if \c e is hidden.
357 300
    bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
358 301

	
359 302
    typedef False NodeNumTag;
360 303
    typedef False EdgeNumTag;
361 304

	
362 305
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
363 306
    Arc findArc(const Node& u, const Node& v, 
364 307
		  const Arc& prev = INVALID) {
365 308
      if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
366 309
        return INVALID;
367 310
      }
368 311
      Arc arc = Parent::findArc(u, v, prev);
369 312
      while (arc != INVALID && !(*_edge_filter_map)[arc]) {
370 313
        arc = Parent::findArc(u, v, arc);
371 314
      }
372 315
      return arc;
373 316
    }
374 317
    Edge findEdge(const Node& u, const Node& v, 
375 318
		  const Edge& prev = INVALID) {
376 319
      if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
377 320
        return INVALID;
378 321
      }
379 322
      Edge edge = Parent::findEdge(u, v, prev);
380 323
      while (edge != INVALID && !(*_edge_filter_map)[edge]) {
381 324
        edge = Parent::findEdge(u, v, edge);
382 325
      }
383 326
      return edge;
384 327
    }
385 328

	
386 329
    template <typename _Value>
387 330
    class NodeMap : public SubMapExtender<Adaptor, 
388 331
        typename Parent::template NodeMap<_Value> > {
389 332
    public:
390 333
      typedef _Value Value;
391 334
      typedef SubMapExtender<Adaptor, typename Parent::
392 335
                             template NodeMap<Value> > MapParent;
393 336
    
394 337
      NodeMap(const Adaptor& adaptor) 
395 338
	: MapParent(adaptor) {}
396 339
      NodeMap(const Adaptor& adaptor, const Value& value) 
397 340
	: MapParent(adaptor, value) {}
398 341

	
399 342
    private:
400 343
      NodeMap& operator=(const NodeMap& cmap) {
401 344
	return operator=<NodeMap>(cmap);
402 345
      }
403 346
    
404 347
      template <typename CMap>
405 348
      NodeMap& operator=(const CMap& cmap) {
406 349
        MapParent::operator=(cmap);
407 350
	return *this;
408 351
      }
409 352
    };
410 353

	
411 354
    template <typename _Value>
412 355
    class ArcMap : public SubMapExtender<Adaptor, 
413 356
	typename Parent::template ArcMap<_Value> > {
414 357
    public:
415 358
      typedef _Value Value;
416 359
      typedef SubMapExtender<Adaptor, typename Parent::
417 360
                             template ArcMap<Value> > MapParent;
418 361
    
419 362
      ArcMap(const Adaptor& adaptor) 
420 363
	: MapParent(adaptor) {}
421 364
      ArcMap(const Adaptor& adaptor, const Value& value) 
422 365
	: MapParent(adaptor, value) {}
423 366

	
424 367
    private:
425 368
      ArcMap& operator=(const ArcMap& cmap) {
426 369
	return operator=<ArcMap>(cmap);
427 370
      }
428 371
    
429 372
      template <typename CMap>
430 373
      ArcMap& operator=(const CMap& cmap) {
431 374
        MapParent::operator=(cmap);
432 375
	return *this;
433 376
      }
434 377
    };
435 378

	
436 379
    template <typename _Value>
437 380
    class EdgeMap : public SubMapExtender<Adaptor, 
438 381
        typename Parent::template EdgeMap<_Value> > {
439 382
    public:
440 383
      typedef _Value Value;
441 384
      typedef SubMapExtender<Adaptor, typename Parent::
442 385
                             template EdgeMap<Value> > MapParent;
443 386
    
444 387
      EdgeMap(const Adaptor& adaptor) 
445 388
	: MapParent(adaptor) {}
446 389

	
447 390
      EdgeMap(const Adaptor& adaptor, const Value& value) 
448 391
	: MapParent(adaptor, value) {}
449 392

	
450 393
    private:
451 394
      EdgeMap& operator=(const EdgeMap& cmap) {
452 395
	return operator=<EdgeMap>(cmap);
453 396
      }
454 397
    
455 398
      template <typename CMap>
456 399
      EdgeMap& operator=(const CMap& cmap) {
457 400
        MapParent::operator=(cmap);
458 401
	return *this;
459 402
      }
460 403
    };
461 404

	
462 405
  };
463 406

	
464 407
  template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
465 408
  class SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap, false> 
466 409
    : public GraphAdaptorBase<_Graph> {
467 410
  public:
468 411
    typedef _Graph Graph;
469 412
    typedef SubGraphAdaptorBase Adaptor;
470 413
    typedef GraphAdaptorBase<_Graph> Parent;
471 414
  protected:
472 415
    NodeFilterMap* _node_filter_map;
473 416
    EdgeFilterMap* _edge_filter_map;
474 417
    SubGraphAdaptorBase() : Parent(), 
475 418
			    _node_filter_map(0), _edge_filter_map(0) { }
476 419

	
477 420
    void setNodeFilterMap(NodeFilterMap& node_filter_map) {
478 421
      _node_filter_map=&node_filter_map;
479 422
    }
480 423
    void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
481 424
      _edge_filter_map=&edge_filter_map;
482 425
    }
483 426

	
484 427
  public:
485 428

	
486 429
    typedef typename Parent::Node Node;
487 430
    typedef typename Parent::Arc Arc;
488 431
    typedef typename Parent::Edge Edge;
489 432

	
490 433
    void first(Node& i) const { 
491 434
      Parent::first(i); 
492 435
      while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i); 
493 436
    }
494 437

	
495 438
    void first(Arc& i) const { 
496 439
      Parent::first(i); 
497 440
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i); 
498 441
    }
499 442

	
500 443
    void first(Edge& i) const { 
501 444
      Parent::first(i); 
502 445
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i); 
503 446
    }
504 447

	
505 448
    void firstIn(Arc& i, const Node& n) const { 
506 449
      Parent::firstIn(i, n); 
507 450
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i); 
508 451
    }
509 452

	
510 453
    void firstOut(Arc& i, const Node& n) const { 
511 454
      Parent::firstOut(i, n); 
512 455
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i); 
513 456
    }
514 457

	
515 458
    void firstInc(Edge& i, bool& d, const Node& n) const { 
516 459
      Parent::firstInc(i, d, n); 
517 460
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d); 
518 461
    }
519 462

	
520 463
    void next(Node& i) const { 
521 464
      Parent::next(i); 
522 465
      while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i); 
523 466
    }
524 467
    void next(Arc& i) const { 
525 468
      Parent::next(i); 
526 469
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i); 
527 470
    }
528 471
    void next(Edge& i) const { 
529 472
      Parent::next(i); 
530 473
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i); 
531 474
    }
532 475
    void nextIn(Arc& i) const { 
533 476
      Parent::nextIn(i); 
534 477
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i); 
535 478
    }
536 479

	
537 480
    void nextOut(Arc& i) const { 
538 481
      Parent::nextOut(i); 
539 482
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i); 
540 483
    }
541 484
    void nextInc(Edge& i, bool& d) const { 
542 485
      Parent::nextInc(i, d); 
543 486
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d); 
544 487
    }
545 488

	
546
    /// \brief Hide the given node in the graph.
547
    ///
548
    /// This function hides \c n in the graph, i.e. the iteration 
549
    /// jumps over it. This is done by simply setting the value of \c n  
550
    /// to be false in the corresponding node-map.
551 489
    void hide(const Node& n) const { _node_filter_map->set(n, false); }
552

	
553
    /// \brief Hide the given edge in the graph.
554
    ///
555
    /// This function hides \c e in the graph, i.e. the iteration 
556
    /// jumps over it. This is done by simply setting the value of \c e  
557
    /// to be false in the corresponding edge-map.
558 490
    void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
559 491

	
560
    /// \brief Unhide the given node in the graph.
561
    ///
562
    /// The value of \c n is set to be true in the node-map which stores 
563
    /// hide information. If \c n was hidden previuosly, then it is shown 
564
    /// again
565
     void unHide(const Node& n) const { _node_filter_map->set(n, true); }
566

	
567
    /// \brief Hide the given edge in the graph.
568
    ///
569
    /// The value of \c e is set to be true in the edge-map which stores 
570
    /// hide information. If \c e was hidden previuosly, then it is shown 
571
    /// again
492
    void unHide(const Node& n) const { _node_filter_map->set(n, true); }
572 493
    void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
573 494

	
574
    /// \brief Returns true if \c n is hidden.
575
    ///
576
    /// Returns true if \c n is hidden.
577 495
    bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; }
578

	
579
    /// \brief Returns true if \c e is hidden.
580
    ///
581
    /// Returns true if \c e is hidden.
582 496
    bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
583 497

	
584 498
    typedef False NodeNumTag;
585 499
    typedef False EdgeNumTag;
586 500

	
587 501
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
588 502
    Arc findArc(const Node& u, const Node& v, 
589 503
		  const Arc& prev = INVALID) {
590 504
      Arc arc = Parent::findArc(u, v, prev);
591 505
      while (arc != INVALID && !(*_edge_filter_map)[arc]) {
592 506
        arc = Parent::findArc(u, v, arc);
593 507
      }
594 508
      return arc;
595 509
    }
596 510
    Edge findEdge(const Node& u, const Node& v, 
597 511
		  const Edge& prev = INVALID) {
598 512
      Edge edge = Parent::findEdge(u, v, prev);
599 513
      while (edge != INVALID && !(*_edge_filter_map)[edge]) {
600 514
        edge = Parent::findEdge(u, v, edge);
601 515
      }
602 516
      return edge;
603 517
    }
604 518

	
605 519
    template <typename _Value>
606 520
    class NodeMap : public SubMapExtender<Adaptor, 
607 521
        typename Parent::template NodeMap<_Value> > {
608 522
    public:
609 523
      typedef _Value Value;
610 524
      typedef SubMapExtender<Adaptor, typename Parent::
611 525
                             template NodeMap<Value> > MapParent;
612 526
    
613 527
      NodeMap(const Adaptor& adaptor) 
614 528
	: MapParent(adaptor) {}
615 529
      NodeMap(const Adaptor& adaptor, const Value& value) 
616 530
	: MapParent(adaptor, value) {}
617 531
    
618 532
    private:
619 533
      NodeMap& operator=(const NodeMap& cmap) {
620 534
	return operator=<NodeMap>(cmap);
621 535
      }
622 536
    
623 537
      template <typename CMap>
624 538
      NodeMap& operator=(const CMap& cmap) {
625 539
        MapParent::operator=(cmap);
626 540
	return *this;
627 541
      }
628 542
    };
629 543

	
630 544
    template <typename _Value>
631 545
    class ArcMap : public SubMapExtender<Adaptor, 
632 546
	typename Parent::template ArcMap<_Value> > {
633 547
    public:
634 548
      typedef _Value Value;
635 549
      typedef SubMapExtender<Adaptor, typename Parent::
636 550
                             template ArcMap<Value> > MapParent;
637 551
    
638 552
      ArcMap(const Adaptor& adaptor) 
639 553
	: MapParent(adaptor) {}
640 554
      ArcMap(const Adaptor& adaptor, const Value& value) 
641 555
	: MapParent(adaptor, value) {}
642 556

	
643 557
    private:
644 558
      ArcMap& operator=(const ArcMap& cmap) {
645 559
	return operator=<ArcMap>(cmap);
646 560
      }
647 561
    
648 562
      template <typename CMap>
649 563
      ArcMap& operator=(const CMap& cmap) {
650 564
        MapParent::operator=(cmap);
651 565
	return *this;
652 566
      }
653 567
    };
654 568

	
655 569
    template <typename _Value>
656 570
    class EdgeMap : public SubMapExtender<Adaptor, 
657 571
        typename Parent::template EdgeMap<_Value> > {
658 572
    public:
659 573
      typedef _Value Value;
660 574
      typedef SubMapExtender<Adaptor, typename Parent::
661 575
                             template EdgeMap<Value> > MapParent;
662 576
    
663 577
      EdgeMap(const Adaptor& adaptor) 
664 578
	: MapParent(adaptor) {}
665 579

	
666 580
      EdgeMap(const Adaptor& adaptor, const _Value& value) 
667 581
	: MapParent(adaptor, value) {}
668 582

	
669 583
    private:
670 584
      EdgeMap& operator=(const EdgeMap& cmap) {
671 585
	return operator=<EdgeMap>(cmap);
672 586
      }
673 587
    
674 588
      template <typename CMap>
675 589
      EdgeMap& operator=(const CMap& cmap) {
676 590
        MapParent::operator=(cmap);
677 591
	return *this;
678 592
      }
679 593
    };
680 594

	
681 595
  };
682 596

	
683 597
  /// \ingroup graph_adaptors
684 598
  ///
685
  /// \brief A graph adaptor for hiding nodes and arcs from an
599
  /// \brief A graph adaptor for hiding nodes and edges from an
686 600
  /// undirected graph.
687 601
  /// 
688 602
  /// SubGraphAdaptor shows the graph with filtered node-set and
689 603
  /// edge-set. If the \c checked parameter is true then it filters
690 604
  /// the edge-set to do not get invalid edges which incident node is
691 605
  /// filtered.
692 606
  /// 
693 607
  /// If the \c checked template parameter is false then we have to
694 608
  /// note that the node-iterator cares only the filter on the
695 609
  /// node-set, and the edge-iterator cares only the filter on the
696 610
  /// edge-set.  This way the edge-map should filter all arcs which
697 611
  /// has filtered end node.
698 612
  template<typename _Graph, typename NodeFilterMap, 
699 613
	   typename EdgeFilterMap, bool checked = true>
700 614
  class SubGraphAdaptor : 
701 615
    public GraphAdaptorExtender<
702 616
    SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap, checked> > {
703 617
  public:
704 618
    typedef _Graph Graph;
705 619
    typedef GraphAdaptorExtender<
706 620
      SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent;
621

	
622
    typedef typename Parent::Node Node;
623
    typedef typename Parent::Edge Edge;
624

	
707 625
  protected:
708 626
    SubGraphAdaptor() { }
709 627
  public:
628
    
629
    /// \brief Constructor
630
    ///
631
    /// Creates a sub-graph-adaptor for the given graph with
632
    /// given node and edge map filters.
710 633
    SubGraphAdaptor(Graph& _graph, NodeFilterMap& node_filter_map, 
711 634
		    EdgeFilterMap& edge_filter_map) { 
712 635
      setGraph(_graph);
713 636
      setNodeFilterMap(node_filter_map);
714 637
      setEdgeFilterMap(edge_filter_map);
715 638
    }
639

	
640
    /// \brief Hides the node of the graph
641
    ///
642
    /// This function hides \c n in the digraph, i.e. the iteration 
643
    /// jumps over it. This is done by simply setting the value of \c n  
644
    /// to be false in the corresponding node-map.
645
    void hide(const Node& n) const { Parent::hide(n); }
646

	
647
    /// \brief Hides the edge of the graph
648
    ///
649
    /// This function hides \c e in the digraph, i.e. the iteration 
650
    /// jumps over it. This is done by simply setting the value of \c e
651
    /// to be false in the corresponding edge-map.
652
    void hide(const Edge& e) const { Parent::hide(e); }
653

	
654
    /// \brief Unhides the node of the graph
655
    ///
656
    /// The value of \c n is set to be true in the node-map which stores 
657
    /// hide information. If \c n was hidden previuosly, then it is shown 
658
    /// again
659
    void unHide(const Node& n) const { Parent::unHide(n); }
660

	
661
    /// \brief Unhides the edge of the graph
662
    ///
663
    /// The value of \c e is set to be true in the edge-map which stores 
664
    /// hide information. If \c e was hidden previuosly, then it is shown 
665
    /// again
666
    void unHide(const Edge& e) const { Parent::unHide(e); }
667

	
668
    /// \brief Returns true if \c n is hidden.
669
    ///
670
    /// Returns true if \c n is hidden.
671
    ///
672
    bool hidden(const Node& n) const { return Parent::hidden(n); }
673

	
674
    /// \brief Returns true if \c e is hidden.
675
    ///
676
    /// Returns true if \c e is hidden.
677
    ///
678
    bool hidden(const Edge& e) const { return Parent::hidden(e); }
716 679
  };
717 680

	
681
  /// \brief Just gives back a sub-graph adaptor
682
  ///
683
  /// Just gives back a sub-graph adaptor
718 684
  template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
719 685
  SubGraphAdaptor<const Graph, NodeFilterMap, ArcFilterMap>
720 686
  subGraphAdaptor(const Graph& graph, 
721 687
                   NodeFilterMap& nfm, ArcFilterMap& efm) {
722 688
    return SubGraphAdaptor<const Graph, NodeFilterMap, ArcFilterMap>
723 689
      (graph, nfm, efm);
724 690
  }
725 691

	
726 692
  template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
727 693
  SubGraphAdaptor<const Graph, const NodeFilterMap, ArcFilterMap>
728 694
  subGraphAdaptor(const Graph& graph, 
729 695
                   NodeFilterMap& nfm, ArcFilterMap& efm) {
730 696
    return SubGraphAdaptor<const Graph, const NodeFilterMap, ArcFilterMap>
731 697
      (graph, nfm, efm);
732 698
  }
733 699

	
734 700
  template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
735 701
  SubGraphAdaptor<const Graph, NodeFilterMap, const ArcFilterMap>
736 702
  subGraphAdaptor(const Graph& graph, 
737 703
                   NodeFilterMap& nfm, ArcFilterMap& efm) {
738 704
    return SubGraphAdaptor<const Graph, NodeFilterMap, const ArcFilterMap>
739 705
      (graph, nfm, efm);
740 706
  }
741 707

	
742 708
  template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
743 709
  SubGraphAdaptor<const Graph, const NodeFilterMap, const ArcFilterMap>
744 710
  subGraphAdaptor(const Graph& graph, 
745 711
                   NodeFilterMap& nfm, ArcFilterMap& efm) {
746 712
    return SubGraphAdaptor<const Graph, const NodeFilterMap, 
747 713
      const ArcFilterMap>(graph, nfm, efm);
748 714
  }
749 715

	
750 716
  /// \ingroup graph_adaptors
751 717
  ///
752 718
  /// \brief An adaptor for hiding nodes from an graph.
753 719
  ///
754 720
  /// An adaptor for hiding nodes from an graph.  This
755 721
  /// adaptor specializes SubGraphAdaptor in the way that only the
756 722
  /// node-set can be filtered. In usual case the checked parameter is
757 723
  /// true, we get the induced subgraph. But if the checked parameter
758 724
  /// is false then we can filter only isolated nodes.
759 725
  template<typename _Graph, typename _NodeFilterMap, bool checked = true>
760 726
  class NodeSubGraphAdaptor : 
761 727
    public SubGraphAdaptor<_Graph, _NodeFilterMap, 
762 728
			   ConstMap<typename _Graph::Edge, bool>, checked> {
763 729
  public:
764 730
    typedef _Graph Graph;
765 731
    typedef _NodeFilterMap NodeFilterMap;
766 732
    typedef SubGraphAdaptor<Graph, NodeFilterMap, 
767 733
			    ConstMap<typename Graph::Edge, bool> > Parent;
734

	
735
    typedef typename Parent::Node Node;
768 736
  protected:
769 737
    ConstMap<typename Graph::Edge, bool> const_true_map;
770 738

	
771 739
    NodeSubGraphAdaptor() : const_true_map(true) {
772 740
      Parent::setEdgeFilterMap(const_true_map);
773 741
    }
774 742

	
775 743
  public:
744

	
745
    /// \brief Constructor
746
    ///
747
    /// Creates a node-sub-graph-adaptor for the given graph with
748
    /// given node map filters.
776 749
    NodeSubGraphAdaptor(Graph& _graph, NodeFilterMap& node_filter_map) : 
777 750
      Parent(), const_true_map(true) { 
778 751
      Parent::setGraph(_graph);
779 752
      Parent::setNodeFilterMap(node_filter_map);
780 753
      Parent::setEdgeFilterMap(const_true_map);
781 754
    }
755

	
756
    /// \brief Hides the node of the graph
757
    ///
758
    /// This function hides \c n in the digraph, i.e. the iteration 
759
    /// jumps over it. This is done by simply setting the value of \c n  
760
    /// to be false in the corresponding node-map.
761
    void hide(const Node& n) const { Parent::hide(n); }
762

	
763
    /// \brief Unhides the node of the graph
764
    ///
765
    /// The value of \c n is set to be true in the node-map which stores 
766
    /// hide information. If \c n was hidden previuosly, then it is shown 
767
    /// again
768
    void unHide(const Node& n) const { Parent::unHide(n); }
769

	
770
    /// \brief Returns true if \c n is hidden.
771
    ///
772
    /// Returns true if \c n is hidden.
773
    ///
774
    bool hidden(const Node& n) const { return Parent::hidden(n); }
775

	
782 776
  };
783 777

	
778
  /// \brief Just gives back a node-sub-graph adaptor
779
  ///
780
  /// Just gives back a node-sub-graph adaptor
784 781
  template<typename Graph, typename NodeFilterMap>
785 782
  NodeSubGraphAdaptor<const Graph, NodeFilterMap>
786 783
  nodeSubGraphAdaptor(const Graph& graph, NodeFilterMap& nfm) {
787 784
    return NodeSubGraphAdaptor<const Graph, NodeFilterMap>(graph, nfm);
788 785
  }
789 786

	
790 787
  template<typename Graph, typename NodeFilterMap>
791 788
  NodeSubGraphAdaptor<const Graph, const NodeFilterMap>
792 789
  nodeSubGraphAdaptor(const Graph& graph, const NodeFilterMap& nfm) {
793 790
    return NodeSubGraphAdaptor<const Graph, const NodeFilterMap>(graph, nfm);
794 791
  }
795 792

	
796 793
  /// \ingroup graph_adaptors
797 794
  ///
798 795
  /// \brief An adaptor for hiding edges from an graph.
799 796
  ///
800 797
  /// \warning Graph adaptors are in even more experimental state
801 798
  /// than the other parts of the lib. Use them at you own risk.
802 799
  ///
803 800
  /// An adaptor for hiding edges from an graph.
804 801
  /// This adaptor specializes SubGraphAdaptor in the way that
805 802
  /// only the arc-set 
806 803
  /// can be filtered.
807 804
  template<typename _Graph, typename _EdgeFilterMap>
808 805
  class EdgeSubGraphAdaptor : 
809 806
    public SubGraphAdaptor<_Graph, ConstMap<typename _Graph::Node,bool>, 
810 807
                           _EdgeFilterMap, false> {
811 808
  public:
812 809
    typedef _Graph Graph;
813 810
    typedef _EdgeFilterMap EdgeFilterMap;
814 811
    typedef SubGraphAdaptor<Graph, ConstMap<typename Graph::Node,bool>, 
815 812
			    EdgeFilterMap, false> Parent;
813
    typedef typename Parent::Edge Edge;
816 814
  protected:
817 815
    ConstMap<typename Graph::Node, bool> const_true_map;
818 816

	
819 817
    EdgeSubGraphAdaptor() : const_true_map(true) {
820 818
      Parent::setNodeFilterMap(const_true_map);
821 819
    }
822 820

	
823 821
  public:
824 822

	
823
    /// \brief Constructor
824
    ///
825
    /// Creates a edge-sub-graph-adaptor for the given graph with
826
    /// given node map filters.
825 827
    EdgeSubGraphAdaptor(Graph& _graph, EdgeFilterMap& edge_filter_map) : 
826 828
      Parent(), const_true_map(true) { 
827 829
      Parent::setGraph(_graph);
828 830
      Parent::setNodeFilterMap(const_true_map);
829 831
      Parent::setEdgeFilterMap(edge_filter_map);
830 832
    }
831 833

	
834
    /// \brief Hides the edge of the graph
835
    ///
836
    /// This function hides \c e in the digraph, i.e. the iteration 
837
    /// jumps over it. This is done by simply setting the value of \c e
838
    /// to be false in the corresponding edge-map.
839
    void hide(const Edge& e) const { Parent::hide(e); }
840

	
841
    /// \brief Unhides the edge of the graph
842
    ///
843
    /// The value of \c e is set to be true in the edge-map which stores 
844
    /// hide information. If \c e was hidden previuosly, then it is shown 
845
    /// again
846
    void unHide(const Edge& e) const { Parent::unHide(e); }
847

	
848
    /// \brief Returns true if \c e is hidden.
849
    ///
850
    /// Returns true if \c e is hidden.
851
    ///
852
    bool hidden(const Edge& e) const { return Parent::hidden(e); }
853

	
832 854
  };
833 855

	
856
  /// \brief Just gives back an edge-sub-graph adaptor
857
  ///
858
  /// Just gives back an edge-sub-graph adaptor
834 859
  template<typename Graph, typename EdgeFilterMap>
835 860
  EdgeSubGraphAdaptor<const Graph, EdgeFilterMap>
836 861
  edgeSubGraphAdaptor(const Graph& graph, EdgeFilterMap& efm) {
837 862
    return EdgeSubGraphAdaptor<const Graph, EdgeFilterMap>(graph, efm);
838 863
  }
839 864

	
840 865
  template<typename Graph, typename EdgeFilterMap>
841 866
  EdgeSubGraphAdaptor<const Graph, const EdgeFilterMap>
842 867
  edgeSubGraphAdaptor(const Graph& graph, const EdgeFilterMap& efm) {
843 868
    return EdgeSubGraphAdaptor<const Graph, const EdgeFilterMap>(graph, efm);
844 869
  }
845 870

	
846
  /// \brief Base of direct graph adaptor
847
  ///
848
  /// Base class of the direct graph adaptor. All public member
849
  /// of this class can be used with the DirGraphAdaptor too.
850
  /// \sa DirGraphAdaptor
851 871
  template <typename _Graph, typename _DirectionMap>
852 872
  class DirGraphAdaptorBase {
853 873
  public:
854 874
    
855 875
    typedef _Graph Graph;
856 876
    typedef _DirectionMap DirectionMap;
857 877

	
858 878
    typedef typename Graph::Node Node;
859 879
    typedef typename Graph::Edge Arc;
860 880
   
861 881
    /// \brief Reverse arc
862 882
    /// 
863 883
    /// It reverse the given arc. It simply negate the direction in the map.
864 884
    void reverseArc(const Arc& arc) {
865 885
      _direction->set(arc, !(*_direction)[arc]);
866 886
    }
867 887

	
868 888
    void first(Node& i) const { _graph->first(i); }
869 889
    void first(Arc& i) const { _graph->first(i); }
870 890
    void firstIn(Arc& i, const Node& n) const {
871 891
      bool d;
872 892
      _graph->firstInc(i, d, n);
873 893
      while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
874 894
    }
875 895
    void firstOut(Arc& i, const Node& n ) const { 
876 896
      bool d;
877 897
      _graph->firstInc(i, d, n);
878 898
      while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
879 899
    }
880 900

	
881 901
    void next(Node& i) const { _graph->next(i); }
882 902
    void next(Arc& i) const { _graph->next(i); }
883 903
    void nextIn(Arc& i) const {
884 904
      bool d = !(*_direction)[i];
885 905
      _graph->nextInc(i, d);
886 906
      while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
887 907
    }
888 908
    void nextOut(Arc& i) const {
889 909
      bool d = (*_direction)[i];
890 910
      _graph->nextInc(i, d);
891 911
      while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
892 912
    }
893 913

	
894 914
    Node source(const Arc& e) const { 
895 915
      return (*_direction)[e] ? _graph->u(e) : _graph->v(e); 
896 916
    }
897 917
    Node target(const Arc& e) const { 
898 918
      return (*_direction)[e] ? _graph->v(e) : _graph->u(e); 
899 919
    }
900 920

	
901 921
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
902 922
    int nodeNum() const { return _graph->nodeNum(); }
903 923
    
904 924
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
905 925
    int arcNum() const { return _graph->edgeNum(); }
906 926

	
907 927
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
908 928
    Arc findArc(const Node& u, const Node& v, 
909 929
		  const Arc& prev = INVALID) {
910 930
      Arc arc = prev;
911 931
      bool d = arc == INVALID ? true : (*_direction)[arc];
912 932
      if (d) {
913 933
        arc = _graph->findEdge(u, v, arc);
914 934
        while (arc != INVALID && !(*_direction)[arc]) {
915 935
          _graph->findEdge(u, v, arc);
916 936
        }
917 937
        if (arc != INVALID) return arc;
918 938
      }
919 939
      _graph->findEdge(v, u, arc);
920 940
      while (arc != INVALID && (*_direction)[arc]) {
921 941
        _graph->findEdge(u, v, arc);
922 942
      }
923 943
      return arc;
924 944
    }
925 945
  
926 946
    Node addNode() { 
927 947
      return Node(_graph->addNode()); 
928 948
    }
929 949

	
930 950
    Arc addArc(const Node& u, const Node& v) {
931 951
      Arc arc = _graph->addArc(u, v);
932 952
      _direction->set(arc, _graph->source(arc) == u);
933 953
      return arc; 
934 954
    }
935 955

	
936 956
    void erase(const Node& i) { _graph->erase(i); }
937 957
    void erase(const Arc& i) { _graph->erase(i); }
938 958
  
939 959
    void clear() { _graph->clear(); }
940 960
    
941 961
    int id(const Node& v) const { return _graph->id(v); }
942 962
    int id(const Arc& e) const { return _graph->id(e); }
943 963

	
944 964
    Node nodeFromId(int idx) const { return _graph->nodeFromId(idx); }
945 965
    Arc arcFromId(int idx) const { return _graph->edgeFromId(idx); }
946 966

	
... ...
@@ -1010,127 +1030,135 @@
1010 1030

	
1011 1031
    void setDirectionMap(DirectionMap& direction) {
1012 1032
      _direction = &direction;
1013 1033
    }
1014 1034

	
1015 1035
    void setGraph(Graph& graph) {
1016 1036
      _graph = &graph;
1017 1037
    }
1018 1038

	
1019 1039
  };
1020 1040

	
1021 1041

	
1022 1042
  /// \ingroup graph_adaptors
1023 1043
  ///
1024 1044
  /// \brief A directed graph is made from an graph by an adaptor
1025 1045
  ///
1026 1046
  /// This adaptor gives a direction for each edge in the undirected
1027 1047
  /// graph. The direction of the arcs stored in the
1028 1048
  /// DirectionMap. This map is a bool map on the edges. If
1029 1049
  /// the edge is mapped to true then the direction of the directed
1030 1050
  /// arc will be the same as the default direction of the edge. The
1031 1051
  /// arcs can be easily reverted by the \ref
1032 1052
  /// DirGraphAdaptorBase::reverseArc "reverseArc()" member in the
1033 1053
  /// adaptor.
1034 1054
  ///
1035 1055
  /// It can be used to solve orientation problems on directed graphs.
1036 1056
  /// For example how can we orient an graph to get the minimum
1037 1057
  /// number of strongly connected components. If we orient the arcs with
1038 1058
  /// the dfs algorithm out from the source then we will get such an 
1039 1059
  /// orientation. 
1040 1060
  ///
1041 1061
  /// We use the \ref DfsVisitor "visitor" interface of the 
1042 1062
  /// \ref DfsVisit "dfs" algorithm:
1043 1063
  ///\code
1044 1064
  /// template <typename DirMap>
1045 1065
  /// class OrientVisitor : public DfsVisitor<Graph> {
1046 1066
  /// public:
1047 1067
  ///
1048 1068
  ///   OrientVisitor(const Graph& graph, DirMap& dirMap)
1049 1069
  ///     : _graph(graph), _dirMap(dirMap), _processed(graph, false) {}
1050 1070
  ///
1051 1071
  ///   void discover(const Arc& arc) {
1052 1072
  ///     _processed.set(arc, true);
1053 1073
  ///     _dirMap.set(arc, _graph.direction(arc));
1054 1074
  ///   }
1055 1075
  ///
1056 1076
  ///   void examine(const Arc& arc) {
1057 1077
  ///     if (_processed[arc]) return;
1058 1078
  ///     _processed.set(arc, true);
1059 1079
  ///     _dirMap.set(arc, _graph.direction(arc));
1060 1080
  ///   }  
1061 1081
  /// 
1062 1082
  /// private:
1063 1083
  ///   const Graph& _graph;  
1064 1084
  ///   DirMap& _dirMap;
1065 1085
  ///   Graph::EdgeMap<bool> _processed;
1066 1086
  /// };
1067 1087
  ///\endcode
1068 1088
  ///
1069 1089
  /// And now we can use the orientation:
1070 1090
  ///\code
1071 1091
  /// Graph::EdgeMap<bool> dmap(graph);
1072 1092
  ///
1073 1093
  /// typedef OrientVisitor<Graph::EdgeMap<bool> > Visitor;
1074 1094
  /// Visitor visitor(graph, dmap);
1075 1095
  ///
1076 1096
  /// DfsVisit<Graph, Visitor> dfs(graph, visitor);
1077 1097
  ///
1078 1098
  /// dfs.run();
1079 1099
  ///
1080 1100
  /// typedef DirGraphAdaptor<Graph> DGraph;
1081 1101
  /// DGraph dgraph(graph, dmap);
1082 1102
  ///
1083 1103
  /// LEMON_ASSERT(countStronglyConnectedComponents(dgraph) == 
1084 1104
  ///              countBiArcConnectedComponents(graph), "Wrong Orientation");
1085 1105
  ///\endcode
1086 1106
  ///
1087 1107
  /// The number of the bi-connected components is a lower bound for
1088 1108
  /// the number of the strongly connected components in the directed
1089 1109
  /// graph because if we contract the bi-connected components to
1090 1110
  /// nodes we will get a tree therefore we cannot orient arcs in
1091 1111
  /// both direction between bi-connected components. In the other way
1092 1112
  /// the algorithm will orient one component to be strongly
1093 1113
  /// connected. The two relations proof that the assertion will
1094 1114
  /// be always true and the found solution is optimal.
1095 1115
  ///
1096 1116
  /// \sa DirGraphAdaptorBase
1097 1117
  /// \sa dirGraphAdaptor
1098 1118
  template<typename _Graph, 
1099 1119
           typename DirectionMap = typename _Graph::template EdgeMap<bool> > 
1100 1120
  class DirGraphAdaptor : 
1101 1121
    public DigraphAdaptorExtender<DirGraphAdaptorBase<_Graph, DirectionMap> > {
1102 1122
  public:
1103 1123
    typedef _Graph Graph;
1104 1124
    typedef DigraphAdaptorExtender<
1105 1125
      DirGraphAdaptorBase<_Graph, DirectionMap> > Parent;
1126
    typedef typename Parent::Arc Arc;
1106 1127
  protected:
1107 1128
    DirGraphAdaptor() { }
1108 1129
  public:
1109 1130
    
1110 1131
    /// \brief Constructor of the adaptor
1111 1132
    ///
1112 1133
    /// Constructor of the adaptor
1113 1134
    DirGraphAdaptor(Graph& graph, DirectionMap& direction) { 
1114 1135
      setGraph(graph);
1115 1136
      setDirectionMap(direction);
1116 1137
    }
1138

	
1139
    /// \brief Reverse arc
1140
    /// 
1141
    /// It reverse the given arc. It simply negate the direction in the map.
1142
    void reverseArc(const Arc& a) {
1143
      Parent::reverseArc(a);
1144
    }
1117 1145
  };
1118 1146

	
1119 1147
  /// \brief Just gives back a DirGraphAdaptor
1120 1148
  ///
1121 1149
  /// Just gives back a DirGraphAdaptor
1122 1150
  template<typename Graph, typename DirectionMap>
1123 1151
  DirGraphAdaptor<const Graph, DirectionMap>
1124 1152
  dirGraphAdaptor(const Graph& graph, DirectionMap& dm) {
1125 1153
    return DirGraphAdaptor<const Graph, DirectionMap>(graph, dm);
1126 1154
  }
1127 1155

	
1128 1156
  template<typename Graph, typename DirectionMap>
1129 1157
  DirGraphAdaptor<const Graph, const DirectionMap>
1130 1158
  dirGraphAdaptor(const Graph& graph, const DirectionMap& dm) {
1131 1159
    return DirGraphAdaptor<const Graph, const DirectionMap>(graph, dm);
1132 1160
  }
1133 1161

	
1134 1162
}
1135 1163

	
1136 1164
#endif
Ignore white space 6 line context
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-2008
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
#include<iostream>
20 20
#include<lemon/concept_check.h>
21 21

	
22 22
#include<lemon/list_graph.h>
23 23
#include<lemon/smart_graph.h>
24 24

	
25 25
#include<lemon/concepts/digraph.h>
26 26
#include<lemon/concepts/graph.h>
27 27

	
28 28
#include<lemon/digraph_adaptor.h>
29 29
#include<lemon/graph_adaptor.h>
30 30

	
31 31
#include <limits>
32 32
#include <lemon/bfs.h>
33 33
#include <lemon/path.h>
34 34

	
35 35
#include"test/test_tools.h"
36 36
#include"test/graph_test.h"
37 37

	
38 38
using namespace lemon;
39 39

	
40
void checkDigraphAdaptor() {
41
  checkConcept<concepts::Digraph, DigraphAdaptor<concepts::Digraph> >();
42

	
43
  typedef ListDigraph Digraph;
44
  typedef DigraphAdaptor<Digraph> Adaptor;
45

	
46
  Digraph digraph;
47
  Adaptor adaptor(digraph);
48

	
49
  Digraph::Node n1 = digraph.addNode();
50
  Digraph::Node n2 = digraph.addNode();
51
  Digraph::Node n3 = digraph.addNode();
52

	
53
  Digraph::Arc a1 = digraph.addArc(n1, n2);
54
  Digraph::Arc a2 = digraph.addArc(n1, n3);
55
  Digraph::Arc a3 = digraph.addArc(n2, n3);
56
  
57
  checkGraphNodeList(adaptor, 3);
58
  checkGraphArcList(adaptor, 3);
59
  checkGraphConArcList(adaptor, 3);
60

	
61
  checkGraphOutArcList(adaptor, n1, 2);
62
  checkGraphOutArcList(adaptor, n2, 1);
63
  checkGraphOutArcList(adaptor, n3, 0);
64

	
65
  checkGraphInArcList(adaptor, n1, 0);
66
  checkGraphInArcList(adaptor, n2, 1);
67
  checkGraphInArcList(adaptor, n3, 2);
68

	
69
  checkNodeIds(adaptor);
70
  checkArcIds(adaptor);
71

	
72
  checkGraphNodeMap(adaptor);
73
  checkGraphArcMap(adaptor);
74
}
75

	
76 40
void checkRevDigraphAdaptor() {
77 41
  checkConcept<concepts::Digraph, RevDigraphAdaptor<concepts::Digraph> >();
78 42

	
79 43
  typedef ListDigraph Digraph;
80 44
  typedef RevDigraphAdaptor<Digraph> Adaptor;
81 45

	
82 46
  Digraph digraph;
83 47
  Adaptor adaptor(digraph);
84 48

	
85 49
  Digraph::Node n1 = digraph.addNode();
86 50
  Digraph::Node n2 = digraph.addNode();
87 51
  Digraph::Node n3 = digraph.addNode();
88 52

	
89 53
  Digraph::Arc a1 = digraph.addArc(n1, n2);
90 54
  Digraph::Arc a2 = digraph.addArc(n1, n3);
91 55
  Digraph::Arc a3 = digraph.addArc(n2, n3);
92 56
  
93 57
  checkGraphNodeList(adaptor, 3);
94 58
  checkGraphArcList(adaptor, 3);
95 59
  checkGraphConArcList(adaptor, 3);
96 60

	
97 61
  checkGraphOutArcList(adaptor, n1, 0);
98 62
  checkGraphOutArcList(adaptor, n2, 1);
99 63
  checkGraphOutArcList(adaptor, n3, 2);
100 64

	
101 65
  checkGraphInArcList(adaptor, n1, 2);
102 66
  checkGraphInArcList(adaptor, n2, 1);
103 67
  checkGraphInArcList(adaptor, n3, 0);
104 68

	
105 69
  checkNodeIds(adaptor);
106 70
  checkArcIds(adaptor);
107 71

	
108 72
  checkGraphNodeMap(adaptor);
109 73
  checkGraphArcMap(adaptor);
110 74

	
111 75
  for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
112 76
    check(adaptor.source(a) == digraph.target(a), "Wrong reverse");
113 77
    check(adaptor.target(a) == digraph.source(a), "Wrong reverse");
114 78
  }
115 79
}
116 80

	
117 81
void checkSubDigraphAdaptor() {
118 82
  checkConcept<concepts::Digraph, 
119 83
    SubDigraphAdaptor<concepts::Digraph, 
120 84
    concepts::Digraph::NodeMap<bool>,
121 85
    concepts::Digraph::ArcMap<bool> > >();
122 86

	
123 87
  typedef ListDigraph Digraph;
124 88
  typedef Digraph::NodeMap<bool> NodeFilter;
125 89
  typedef Digraph::ArcMap<bool> ArcFilter;
126 90
  typedef SubDigraphAdaptor<Digraph, NodeFilter, ArcFilter> Adaptor;
127 91

	
128 92
  Digraph digraph;
129 93
  NodeFilter node_filter(digraph);
130 94
  ArcFilter arc_filter(digraph);
131 95
  Adaptor adaptor(digraph, node_filter, arc_filter);
132 96

	
133 97
  Digraph::Node n1 = digraph.addNode();
134 98
  Digraph::Node n2 = digraph.addNode();
135 99
  Digraph::Node n3 = digraph.addNode();
136 100

	
137 101
  Digraph::Arc a1 = digraph.addArc(n1, n2);
138 102
  Digraph::Arc a2 = digraph.addArc(n1, n3);
139 103
  Digraph::Arc a3 = digraph.addArc(n2, n3);
140 104

	
141 105
  node_filter[n1] = node_filter[n2] = node_filter[n3] = true;
142 106
  arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = true;
143 107
  
144 108
  checkGraphNodeList(adaptor, 3);
145 109
  checkGraphArcList(adaptor, 3);
146 110
  checkGraphConArcList(adaptor, 3);
147 111

	
148 112
  checkGraphOutArcList(adaptor, n1, 2);
149 113
  checkGraphOutArcList(adaptor, n2, 1);
150 114
  checkGraphOutArcList(adaptor, n3, 0);
151 115

	
152 116
  checkGraphInArcList(adaptor, n1, 0);
153 117
  checkGraphInArcList(adaptor, n2, 1);
154 118
  checkGraphInArcList(adaptor, n3, 2);
155 119

	
156 120
  checkNodeIds(adaptor);
157 121
  checkArcIds(adaptor);
158 122

	
159 123
  checkGraphNodeMap(adaptor);
160 124
  checkGraphArcMap(adaptor);
161 125

	
162 126
  arc_filter[a2] = false; 
163 127

	
164 128
  checkGraphNodeList(adaptor, 3);
165 129
  checkGraphArcList(adaptor, 2);
166 130
  checkGraphConArcList(adaptor, 2);
167 131

	
168 132
  checkGraphOutArcList(adaptor, n1, 1);
169 133
  checkGraphOutArcList(adaptor, n2, 1);
170 134
  checkGraphOutArcList(adaptor, n3, 0);
171 135

	
... ...
@@ -492,242 +456,192 @@
492 456

	
493 457
  checkGraphOutArcList(adaptor, n1, 0);
494 458
  checkGraphOutArcList(adaptor, n2, 1);
495 459
  checkGraphOutArcList(adaptor, n3, 2);
496 460
  checkGraphOutArcList(adaptor, n4, 3);
497 461

	
498 462
  checkGraphInArcList(adaptor, n1, 3);
499 463
  checkGraphInArcList(adaptor, n2, 2);
500 464
  checkGraphInArcList(adaptor, n3, 1);
501 465
  checkGraphInArcList(adaptor, n4, 0);
502 466

	
503 467
  for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
504 468
    flow[a] = 0;
505 469
  }
506 470

	
507 471
  int flow_value = 0;
508 472
  while (true) {
509 473
    
510 474
    Bfs<Adaptor> bfs(adaptor);
511 475
    bfs.run(n1, n4);
512 476
    
513 477
    if (!bfs.reached(n4)) break;
514 478

	
515 479
    Path<Adaptor> p = bfs.path(n4);
516 480
    
517 481
    int min = std::numeric_limits<int>::max();
518 482
    for (Path<Adaptor>::ArcIt a(p); a != INVALID; ++a) {
519 483
      if (adaptor.rescap(a) < min) min = adaptor.rescap(a);
520 484
    }
521 485

	
522 486
    for (Path<Adaptor>::ArcIt a(p); a != INVALID; ++a) {
523 487
      adaptor.augment(a, min);
524 488
    }
525 489
    flow_value += min;
526 490
  }
527 491

	
528 492
  check(flow_value == 18, "Wrong flow with res graph adaptor");
529 493

	
530 494
}
531 495

	
532 496
void checkSplitDigraphAdaptor() {
533 497
  checkConcept<concepts::Digraph, SplitDigraphAdaptor<concepts::Digraph> >();
534 498

	
535 499
  typedef ListDigraph Digraph;
536 500
  typedef SplitDigraphAdaptor<Digraph> Adaptor;
537 501

	
538 502
  Digraph digraph;
539 503
  Adaptor adaptor(digraph);
540 504

	
541 505
  Digraph::Node n1 = digraph.addNode();
542 506
  Digraph::Node n2 = digraph.addNode();
543 507
  Digraph::Node n3 = digraph.addNode();
544 508

	
545 509
  Digraph::Arc a1 = digraph.addArc(n1, n2);
546 510
  Digraph::Arc a2 = digraph.addArc(n1, n3);
547 511
  Digraph::Arc a3 = digraph.addArc(n2, n3);
548 512
  
549 513
  checkGraphNodeList(adaptor, 6);
550 514
  checkGraphArcList(adaptor, 6);
551 515
  checkGraphConArcList(adaptor, 6);
552 516

	
553 517
  checkGraphOutArcList(adaptor, adaptor.inNode(n1), 1);
554 518
  checkGraphOutArcList(adaptor, adaptor.outNode(n1), 2);
555 519
  checkGraphOutArcList(adaptor, adaptor.inNode(n2), 1);
556 520
  checkGraphOutArcList(adaptor, adaptor.outNode(n2), 1);
557 521
  checkGraphOutArcList(adaptor, adaptor.inNode(n3), 1);
558 522
  checkGraphOutArcList(adaptor, adaptor.outNode(n3), 0);
559 523

	
560 524
  checkGraphInArcList(adaptor, adaptor.inNode(n1), 0);
561 525
  checkGraphInArcList(adaptor, adaptor.outNode(n1), 1);
562 526
  checkGraphInArcList(adaptor, adaptor.inNode(n2), 1);
563 527
  checkGraphInArcList(adaptor, adaptor.outNode(n2), 1);
564 528
  checkGraphInArcList(adaptor, adaptor.inNode(n3), 2);
565 529
  checkGraphInArcList(adaptor, adaptor.outNode(n3), 1);
566 530

	
567 531
  checkNodeIds(adaptor);
568 532
  checkArcIds(adaptor);
569 533
  
570 534
  checkGraphNodeMap(adaptor);
571 535
  checkGraphArcMap(adaptor);
572 536

	
573 537
  for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
574 538
    if (adaptor.origArc(a)) {
575 539
      Digraph::Arc oa = a;
576 540
      check(adaptor.source(a) == adaptor.outNode(digraph.source(oa)), 
577 541
	    "Wrong split");
578 542
      check(adaptor.target(a) == adaptor.inNode(digraph.target(oa)), 
579 543
	    "Wrong split"); 
580 544
    } else {
581 545
      Digraph::Node on = a;
582 546
      check(adaptor.source(a) == adaptor.inNode(on), "Wrong split");
583 547
      check(adaptor.target(a) == adaptor.outNode(on), "Wrong split");
584 548
    }
585 549
  }
586 550
}
587 551

	
588
void checkGraphAdaptor() {
589
  checkConcept<concepts::Graph, GraphAdaptor<concepts::Graph> >();
590

	
591
  typedef ListGraph Graph;
592
  typedef GraphAdaptor<Graph> Adaptor;
593

	
594
  Graph graph;
595
  Adaptor adaptor(graph);
596

	
597
  Graph::Node n1 = graph.addNode();
598
  Graph::Node n2 = graph.addNode();
599
  Graph::Node n3 = graph.addNode();
600
  Graph::Node n4 = graph.addNode();
601

	
602
  Graph::Edge a1 = graph.addEdge(n1, n2);
603
  Graph::Edge a2 = graph.addEdge(n1, n3);
604
  Graph::Edge a3 = graph.addEdge(n2, n3);
605
  Graph::Edge a4 = graph.addEdge(n3, n4);
606
  
607
  checkGraphNodeList(adaptor, 4);
608
  checkGraphArcList(adaptor, 8);
609
  checkGraphEdgeList(adaptor, 4);
610
  checkGraphConArcList(adaptor, 8);
611
  checkGraphConEdgeList(adaptor, 4);
612

	
613
  checkGraphOutArcList(adaptor, n1, 2);
614
  checkGraphOutArcList(adaptor, n2, 2);
615
  checkGraphOutArcList(adaptor, n3, 3);
616
  checkGraphOutArcList(adaptor, n4, 1);
617

	
618
  checkGraphInArcList(adaptor, n1, 2);
619
  checkGraphInArcList(adaptor, n2, 2);
620
  checkGraphInArcList(adaptor, n3, 3);
621
  checkGraphInArcList(adaptor, n4, 1);
622

	
623
  checkGraphIncEdgeList(adaptor, n1, 2);
624
  checkGraphIncEdgeList(adaptor, n2, 2);
625
  checkGraphIncEdgeList(adaptor, n3, 3);
626
  checkGraphIncEdgeList(adaptor, n4, 1);
627

	
628

	
629
  checkNodeIds(adaptor);
630
  checkArcIds(adaptor);
631
  checkEdgeIds(adaptor);
632

	
633
  checkGraphNodeMap(adaptor);
634
  checkGraphArcMap(adaptor);
635
  checkGraphEdgeMap(adaptor);
636
}
637

	
638 552
void checkSubGraphAdaptor() {
639 553
  checkConcept<concepts::Graph, 
640 554
    SubGraphAdaptor<concepts::Graph, 
641 555
    concepts::Graph::NodeMap<bool>,
642 556
    concepts::Graph::EdgeMap<bool> > >();
643 557

	
644 558
  typedef ListGraph Graph;
645 559
  typedef Graph::NodeMap<bool> NodeFilter;
646 560
  typedef Graph::EdgeMap<bool> EdgeFilter;
647 561
  typedef SubGraphAdaptor<Graph, NodeFilter, EdgeFilter> Adaptor;
648 562

	
649 563
  Graph graph;
650 564
  NodeFilter node_filter(graph);
651 565
  EdgeFilter edge_filter(graph);
652 566
  Adaptor adaptor(graph, node_filter, edge_filter);
653 567

	
654 568
  Graph::Node n1 = graph.addNode();
655 569
  Graph::Node n2 = graph.addNode();
656 570
  Graph::Node n3 = graph.addNode();
657 571
  Graph::Node n4 = graph.addNode();
658 572

	
659 573
  Graph::Edge e1 = graph.addEdge(n1, n2);
660 574
  Graph::Edge e2 = graph.addEdge(n1, n3);
661 575
  Graph::Edge e3 = graph.addEdge(n2, n3);
662 576
  Graph::Edge e4 = graph.addEdge(n3, n4);
663 577

	
664 578
  node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = true;
665 579
  edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = true;
666 580
  
667 581
  checkGraphNodeList(adaptor, 4);
668 582
  checkGraphArcList(adaptor, 8);
669 583
  checkGraphEdgeList(adaptor, 4);
670 584
  checkGraphConArcList(adaptor, 8);
671 585
  checkGraphConEdgeList(adaptor, 4);
672 586

	
673 587
  checkGraphOutArcList(adaptor, n1, 2);
674 588
  checkGraphOutArcList(adaptor, n2, 2);
675 589
  checkGraphOutArcList(adaptor, n3, 3);
676 590
  checkGraphOutArcList(adaptor, n4, 1);
677 591

	
678 592
  checkGraphInArcList(adaptor, n1, 2);
679 593
  checkGraphInArcList(adaptor, n2, 2);
680 594
  checkGraphInArcList(adaptor, n3, 3);
681 595
  checkGraphInArcList(adaptor, n4, 1);
682 596

	
683 597
  checkGraphIncEdgeList(adaptor, n1, 2);
684 598
  checkGraphIncEdgeList(adaptor, n2, 2);
685 599
  checkGraphIncEdgeList(adaptor, n3, 3);
686 600
  checkGraphIncEdgeList(adaptor, n4, 1);
687 601

	
688 602
  checkNodeIds(adaptor);
689 603
  checkArcIds(adaptor);
690 604
  checkEdgeIds(adaptor);
691 605

	
692 606
  checkGraphNodeMap(adaptor);
693 607
  checkGraphArcMap(adaptor);
694 608
  checkGraphEdgeMap(adaptor);
695 609

	
696 610
  edge_filter[e2] = false; 
697 611

	
698 612
  checkGraphNodeList(adaptor, 4);
699 613
  checkGraphArcList(adaptor, 6);
700 614
  checkGraphEdgeList(adaptor, 3);
701 615
  checkGraphConArcList(adaptor, 6);
702 616
  checkGraphConEdgeList(adaptor, 3);
703 617

	
704 618
  checkGraphOutArcList(adaptor, n1, 1);
705 619
  checkGraphOutArcList(adaptor, n2, 2);
706 620
  checkGraphOutArcList(adaptor, n3, 2);
707 621
  checkGraphOutArcList(adaptor, n4, 1);
708 622

	
709 623
  checkGraphInArcList(adaptor, n1, 1);
710 624
  checkGraphInArcList(adaptor, n2, 2);
711 625
  checkGraphInArcList(adaptor, n3, 2);
712 626
  checkGraphInArcList(adaptor, n4, 1);
713 627

	
714 628
  checkGraphIncEdgeList(adaptor, n1, 1);
715 629
  checkGraphIncEdgeList(adaptor, n2, 2);
716 630
  checkGraphIncEdgeList(adaptor, n3, 2);
717 631
  checkGraphIncEdgeList(adaptor, n4, 1);
718 632

	
719 633
  checkNodeIds(adaptor);
720 634
  checkArcIds(adaptor);
721 635
  checkEdgeIds(adaptor);
722 636

	
723 637
  checkGraphNodeMap(adaptor);
724 638
  checkGraphArcMap(adaptor);
725 639
  checkGraphEdgeMap(adaptor);
726 640

	
727 641
  node_filter[n1] = false; 
728 642

	
729 643
  checkGraphNodeList(adaptor, 3);
730 644
  checkGraphArcList(adaptor, 4);
731 645
  checkGraphEdgeList(adaptor, 2);
732 646
  checkGraphConArcList(adaptor, 4);
733 647
  checkGraphConEdgeList(adaptor, 2);
... ...
@@ -960,113 +874,111 @@
960 874
  checkGraphArcList(adaptor, 0);
961 875
  checkGraphEdgeList(adaptor, 0);
962 876
  checkGraphConArcList(adaptor, 0);
963 877
  checkGraphConEdgeList(adaptor, 0);
964 878

	
965 879
  checkNodeIds(adaptor);
966 880
  checkArcIds(adaptor);
967 881
  checkEdgeIds(adaptor);
968 882

	
969 883
  checkGraphNodeMap(adaptor);
970 884
  checkGraphArcMap(adaptor);
971 885
  checkGraphEdgeMap(adaptor);
972 886
}
973 887

	
974 888
void checkDirGraphAdaptor() {
975 889
  checkConcept<concepts::Digraph, 
976 890
    DirGraphAdaptor<concepts::Graph, concepts::Graph::EdgeMap<bool> > >();
977 891

	
978 892
  typedef ListGraph Graph;
979 893
  typedef ListGraph::EdgeMap<bool> DirMap;
980 894
  typedef DirGraphAdaptor<Graph> Adaptor;
981 895

	
982 896
  Graph graph;
983 897
  DirMap dir(graph, true);
984 898
  Adaptor adaptor(graph, dir);
985 899

	
986 900
  Graph::Node n1 = graph.addNode();
987 901
  Graph::Node n2 = graph.addNode();
988 902
  Graph::Node n3 = graph.addNode();
989 903

	
990 904
  Graph::Edge e1 = graph.addEdge(n1, n2);
991 905
  Graph::Edge e2 = graph.addEdge(n1, n3);
992 906
  Graph::Edge e3 = graph.addEdge(n2, n3);
993 907
  
994 908
  checkGraphNodeList(adaptor, 3);
995 909
  checkGraphArcList(adaptor, 3);
996 910
  checkGraphConArcList(adaptor, 3);
997 911
  
998 912
  {
999 913
    dir[e1] = true;
1000 914
    Adaptor::Node u = adaptor.source(e1);
1001 915
    Adaptor::Node v = adaptor.target(e1);
1002 916
    
1003 917
    dir[e1] = false;
1004 918
    check (u == adaptor.target(e1), "Wrong dir");
1005 919
    check (v == adaptor.source(e1), "Wrong dir");
1006 920

	
1007 921
    check ((u == n1 && v == n2) || (u == n2 && v == n1), "Wrong dir");
1008 922
    dir[e1] = n1 == u;
1009 923
  }
1010 924

	
1011 925
  {
1012 926
    dir[e2] = true;
1013 927
    Adaptor::Node u = adaptor.source(e2);
1014 928
    Adaptor::Node v = adaptor.target(e2);
1015 929
    
1016 930
    dir[e2] = false;
1017 931
    check (u == adaptor.target(e2), "Wrong dir");
1018 932
    check (v == adaptor.source(e2), "Wrong dir");
1019 933

	
1020 934
    check ((u == n1 && v == n3) || (u == n3 && v == n1), "Wrong dir");
1021 935
    dir[e2] = n3 == u;
1022 936
  }
1023 937

	
1024 938
  {
1025 939
    dir[e3] = true;
1026 940
    Adaptor::Node u = adaptor.source(e3);
1027 941
    Adaptor::Node v = adaptor.target(e3);
1028 942
    
1029 943
    dir[e3] = false;
1030 944
    check (u == adaptor.target(e3), "Wrong dir");
1031 945
    check (v == adaptor.source(e3), "Wrong dir");
1032 946

	
1033 947
    check ((u == n2 && v == n3) || (u == n3 && v == n2), "Wrong dir");
1034 948
    dir[e3] = n2 == u;
1035 949
  }
1036 950

	
1037 951
  checkGraphOutArcList(adaptor, n1, 1);
1038 952
  checkGraphOutArcList(adaptor, n2, 1);
1039 953
  checkGraphOutArcList(adaptor, n3, 1);
1040 954

	
1041 955
  checkGraphInArcList(adaptor, n1, 1);
1042 956
  checkGraphInArcList(adaptor, n2, 1);
1043 957
  checkGraphInArcList(adaptor, n3, 1);
1044 958

	
1045 959
  checkNodeIds(adaptor);
1046 960
  checkArcIds(adaptor);
1047 961

	
1048 962
  checkGraphNodeMap(adaptor);
1049 963
  checkGraphArcMap(adaptor);
1050 964

	
1051 965
}
1052 966

	
1053 967

	
1054 968
int main(int, const char **) {
1055 969

	
1056
  checkDigraphAdaptor();
1057 970
  checkRevDigraphAdaptor();
1058 971
  checkSubDigraphAdaptor();
1059 972
  checkNodeSubDigraphAdaptor();
1060 973
  checkArcSubDigraphAdaptor();
1061 974
  checkUndirDigraphAdaptor();
1062 975
  checkResDigraphAdaptor();
1063 976
  checkSplitDigraphAdaptor();
1064 977

	
1065
  checkGraphAdaptor();
1066 978
  checkSubGraphAdaptor();
1067 979
  checkNodeSubGraphAdaptor();
1068 980
  checkEdgeSubGraphAdaptor();
1069 981
  checkDirGraphAdaptor();
1070 982

	
1071 983
  return 0;
1072 984
}
0 comments (0 inline)