gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Reorganication of graph adaptors and doc improvements (#67) - Moving to one file, lemon/adaptors.h - Renamings - Doc cleanings
2 5 1
default
8 files changed with 2163 insertions and 2494 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
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
/**
20 20
@defgroup datas Data Structures
21 21
This group describes the several data structures implemented in LEMON.
22 22
*/
23 23

	
24 24
/**
25 25
@defgroup graphs Graph Structures
26 26
@ingroup datas
27 27
\brief Graph structures implemented in LEMON.
28 28

	
29 29
The implementation of combinatorial algorithms heavily relies on
30 30
efficient graph implementations. LEMON offers data structures which are
31 31
planned to be easily used in an experimental phase of implementation studies,
32 32
and thereafter the program code can be made efficient by small modifications.
33 33

	
34 34
The most efficient implementation of diverse applications require the
35 35
usage of different physical graph implementations. These differences
36 36
appear in the size of graph we require to handle, memory or time usage
37 37
limitations or in the set of operations through which the graph can be
38 38
accessed.  LEMON provides several physical graph structures to meet
39 39
the diverging requirements of the possible users.  In order to save on
40 40
running time or on memory usage, some structures may fail to provide
41 41
some graph features like arc/edge or node deletion.
42 42

	
43 43
Alteration of standard containers need a very limited number of
44 44
operations, these together satisfy the everyday requirements.
45 45
In the case of graph structures, different operations are needed which do
46 46
not alter the physical graph, but gives another view. If some nodes or
47 47
arcs have to be hidden or the reverse oriented graph have to be used, then
48 48
this is the case. It also may happen that in a flow implementation
49 49
the residual graph can be accessed by another algorithm, or a node-set
50 50
is to be shrunk for another algorithm.
51 51
LEMON also provides a variety of graphs for these requirements called
52 52
\ref graph_adaptors "graph adaptors". Adaptors cannot be used alone but only
53 53
in conjunction with other graph representations.
54 54

	
55 55
You are free to use the graph structure that fit your requirements
56 56
the best, most graph algorithms and auxiliary data structures can be used
57 57
with any graph structure.
58 58

	
59 59
<b>See also:</b> \ref graph_concepts "Graph Structure Concepts".
60 60
*/
61 61

	
62 62
/**
63
@defgroup graph_adaptors Adaptor Classes for graphs
64
@ingroup graphs
65
\brief This group contains several adaptor classes for digraphs and graphs
66

	
67
The main parts of LEMON are the different graph structures, generic
68
graph algorithms, graph concepts which couple these, and graph
69
adaptors. While the previous notions are more or less clear, the
70
latter one needs further explanation. Graph adaptors are graph classes
71
which serve for considering graph structures in different ways.
72

	
73
A short example makes this much clearer.  Suppose that we have an
74
instance \c g of a directed graph type say ListDigraph and an algorithm
75
\code
76
template <typename Digraph>
77
int algorithm(const Digraph&);
78
\endcode
79
is needed to run on the reverse oriented graph.  It may be expensive
80
(in time or in memory usage) to copy \c g with the reversed
81
arcs.  In this case, an adaptor class is used, which (according
82
to LEMON digraph concepts) works as a digraph.  The adaptor uses the
83
original digraph structure and digraph operations when methods of the
84
reversed oriented graph are called.  This means that the adaptor have
85
minor memory usage, and do not perform sophisticated algorithmic
86
actions.  The purpose of it is to give a tool for the cases when a
87
graph have to be used in a specific alteration.  If this alteration is
88
obtained by a usual construction like filtering the arc-set or
89
considering a new orientation, then an adaptor is worthwhile to use.
90
To come back to the reverse oriented graph, in this situation
91
\code
92
template<typename Digraph> class ReverseDigraph;
93
\endcode
94
template class can be used. The code looks as follows
95
\code
96
ListDigraph g;
97
ReverseDigraph<ListGraph> rg(g);
98
int result = algorithm(rg);
99
\endcode
100
After running the algorithm, the original graph \c g is untouched.
101
This techniques gives rise to an elegant code, and based on stable
102
graph adaptors, complex algorithms can be implemented easily.
103

	
104
In flow, circulation and bipartite matching problems, the residual
105
graph is of particular importance. Combining an adaptor implementing
106
this, shortest path algorithms and minimum mean cycle algorithms,
107
a range of weighted and cardinality optimization algorithms can be
108
obtained. For other examples, the interested user is referred to the
109
detailed documentation of particular adaptors.
110

	
111
The behavior of graph adaptors can be very different. Some of them keep
112
capabilities of the original graph while in other cases this would be
113
meaningless. This means that the concepts that they are models of depend
114
on the graph adaptor, and the wrapped graph(s).
115
If an arc of \c rg is deleted, this is carried out by deleting the
116
corresponding arc of \c g, thus the adaptor modifies the original graph.
117

	
118
But for a residual graph, this operation has no sense.
119
Let us stand one more example here to simplify your work.
120
RevGraphAdaptor has constructor
121
\code
122
ReverseDigraph(Digraph& digraph);
123
\endcode
124
This means that in a situation, when a <tt>const ListDigraph&</tt>
125
reference to a graph is given, then it have to be instantiated with
126
<tt>Digraph=const ListDigraph</tt>.
127
\code
128
int algorithm1(const ListDigraph& g) {
129
  RevGraphAdaptor<const ListDigraph> rg(g);
130
  return algorithm2(rg);
131
}
132
\endcode
133
*/
134

	
135
/**
63 136
@defgroup semi_adaptors Semi-Adaptor Classes for Graphs
64 137
@ingroup graphs
65 138
\brief Graph types between real graphs and graph adaptors.
66 139

	
67 140
This group describes some graph types between real graphs and graph adaptors.
68 141
These classes wrap graphs to give new functionality as the adaptors do it.
69 142
On the other hand they are not light-weight structures as the adaptors.
70 143
*/
71 144

	
72 145
/**
73 146
@defgroup maps Maps
74 147
@ingroup datas
75 148
\brief Map structures implemented in LEMON.
76 149

	
77 150
This group describes the map structures implemented in LEMON.
78 151

	
79 152
LEMON provides several special purpose maps and map adaptors that e.g. combine
80 153
new maps from existing ones.
81 154

	
82 155
<b>See also:</b> \ref map_concepts "Map Concepts".
83 156
*/
84 157

	
85 158
/**
86 159
@defgroup graph_maps Graph Maps
87 160
@ingroup maps
88 161
\brief Special graph-related maps.
89 162

	
90 163
This group describes maps that are specifically designed to assign
91 164
values to the nodes and arcs of graphs.
92 165
*/
93 166

	
94 167
/**
95 168
\defgroup map_adaptors Map Adaptors
96 169
\ingroup maps
97 170
\brief Tools to create new maps from existing ones
98 171

	
99 172
This group describes map adaptors that are used to create "implicit"
100 173
maps from other maps.
101 174

	
102 175
Most of them are \ref lemon::concepts::ReadMap "read-only maps".
103 176
They can make arithmetic and logical operations between one or two maps
104 177
(negation, shifting, addition, multiplication, logical 'and', 'or',
105 178
'not' etc.) or e.g. convert a map to another one of different Value type.
106 179

	
107 180
The typical usage of this classes is passing implicit maps to
108 181
algorithms.  If a function type algorithm is called then the function
109 182
type map adaptors can be used comfortable. For example let's see the
110 183
usage of map adaptors with the \c graphToEps() function.
111 184
\code
112 185
  Color nodeColor(int deg) {
113 186
    if (deg >= 2) {
114 187
      return Color(0.5, 0.0, 0.5);
115 188
    } else if (deg == 1) {
116 189
      return Color(1.0, 0.5, 1.0);
117 190
    } else {
118 191
      return Color(0.0, 0.0, 0.0);
119 192
    }
120 193
  }
121 194

	
122 195
  Digraph::NodeMap<int> degree_map(graph);
123 196

	
124 197
  graphToEps(graph, "graph.eps")
125 198
    .coords(coords).scaleToA4().undirected()
126 199
    .nodeColors(composeMap(functorToMap(nodeColor), degree_map))
127 200
    .run();
128 201
\endcode
129 202
The \c functorToMap() function makes an \c int to \c Color map from the
130 203
\c nodeColor() function. The \c composeMap() compose the \c degree_map
131 204
and the previously created map. The composed map is a proper function to
132 205
get the color of each node.
133 206

	
134 207
The usage with class type algorithms is little bit harder. In this
135 208
case the function type map adaptors can not be used, because the
136 209
function map adaptors give back temporary objects.
137 210
\code
138 211
  Digraph graph;
139 212

	
140 213
  typedef Digraph::ArcMap<double> DoubleArcMap;
141 214
  DoubleArcMap length(graph);
142 215
  DoubleArcMap speed(graph);
143 216

	
144 217
  typedef DivMap<DoubleArcMap, DoubleArcMap> TimeMap;
145 218
  TimeMap time(length, speed);
146 219

	
147 220
  Dijkstra<Digraph, TimeMap> dijkstra(graph, time);
148 221
  dijkstra.run(source, target);
149 222
\endcode
150 223
We have a length map and a maximum speed map on the arcs of a digraph.
151 224
The minimum time to pass the arc can be calculated as the division of
152 225
the two maps which can be done implicitly with the \c DivMap template
153 226
class. We use the implicit minimum time map as the length map of the
154 227
\c Dijkstra algorithm.
155 228
*/
156 229

	
157 230
/**
158 231
@defgroup matrices Matrices
159 232
@ingroup datas
160 233
\brief Two dimensional data storages implemented in LEMON.
161 234

	
162 235
This group describes two dimensional data storages implemented in LEMON.
163 236
*/
164 237

	
165 238
/**
166 239
@defgroup paths Path Structures
167 240
@ingroup datas
168 241
\brief %Path structures implemented in LEMON.
169 242

	
170 243
This group describes the path structures implemented in LEMON.
171 244

	
172 245
LEMON provides flexible data structures to work with paths.
173 246
All of them have similar interfaces and they can be copied easily with
174 247
assignment operators and copy constructors. This makes it easy and
175 248
efficient to have e.g. the Dijkstra algorithm to store its result in
176 249
any kind of path structure.
177 250

	
178 251
\sa lemon::concepts::Path
179 252
*/
180 253

	
181 254
/**
182 255
@defgroup auxdat Auxiliary Data Structures
183 256
@ingroup datas
184 257
\brief Auxiliary data structures implemented in LEMON.
185 258

	
186 259
This group describes some data structures implemented in LEMON in
187 260
order to make it easier to implement combinatorial algorithms.
188 261
*/
189 262

	
190 263
/**
191 264
@defgroup algs Algorithms
192 265
\brief This group describes the several algorithms
193 266
implemented in LEMON.
194 267

	
195 268
This group describes the several algorithms
196 269
implemented in LEMON.
197 270
*/
198 271

	
199 272
/**
200 273
@defgroup search Graph Search
201 274
@ingroup algs
202 275
\brief Common graph search algorithms.
203 276

	
204 277
This group describes the common graph search algorithms like
205 278
Breadth-First Search (BFS) and Depth-First Search (DFS).
206 279
*/
207 280

	
208 281
/**
209 282
@defgroup shortest_path Shortest Path Algorithms
210 283
@ingroup algs
211 284
\brief Algorithms for finding shortest paths.
212 285

	
213 286
This group describes the algorithms for finding shortest paths in graphs.
214 287
*/
215 288

	
216 289
/**
217 290
@defgroup max_flow Maximum Flow Algorithms
218 291
@ingroup algs
219 292
\brief Algorithms for finding maximum flows.
220 293

	
221 294
This group describes the algorithms for finding maximum flows and
222 295
feasible circulations.
223 296

	
224 297
The maximum flow problem is to find a flow between a single source and
225 298
a single target that is maximum. Formally, there is a \f$G=(V,A)\f$
226 299
directed graph, an \f$c_a:A\rightarrow\mathbf{R}^+_0\f$ capacity
227 300
function and given \f$s, t \in V\f$ source and target node. The
228 301
maximum flow is the \f$f_a\f$ solution of the next optimization problem:
229 302

	
230 303
\f[ 0 \le f_a \le c_a \f]
231 304
\f[ \sum_{v\in\delta^{-}(u)}f_{vu}=\sum_{v\in\delta^{+}(u)}f_{uv}
232 305
\qquad \forall u \in V \setminus \{s,t\}\f]
233 306
\f[ \max \sum_{v\in\delta^{+}(s)}f_{uv} - \sum_{v\in\delta^{-}(s)}f_{vu}\f]
234 307

	
235 308
LEMON contains several algorithms for solving maximum flow problems:
236 309
- \ref lemon::EdmondsKarp "Edmonds-Karp"
237 310
- \ref lemon::Preflow "Goldberg's Preflow algorithm"
238 311
- \ref lemon::DinitzSleatorTarjan "Dinitz's blocking flow algorithm with dynamic trees"
239 312
- \ref lemon::GoldbergTarjan "Preflow algorithm with dynamic trees"
240 313

	
241 314
In most cases the \ref lemon::Preflow "Preflow" algorithm provides the
242 315
fastest method to compute the maximum flow. All impelementations
243 316
provides functions to query the minimum cut, which is the dual linear
244 317
programming problem of the maximum flow.
245 318
*/
246 319

	
247 320
/**
248 321
@defgroup min_cost_flow Minimum Cost Flow Algorithms
249 322
@ingroup algs
250 323

	
251 324
\brief Algorithms for finding minimum cost flows and circulations.
252 325

	
253 326
This group describes the algorithms for finding minimum cost flows and
254 327
circulations.
255 328
*/
256 329

	
257 330
/**
258 331
@defgroup min_cut Minimum Cut Algorithms
259 332
@ingroup algs
260 333

	
261 334
\brief Algorithms for finding minimum cut in graphs.
262 335

	
263 336
This group describes the algorithms for finding minimum cut in graphs.
264 337

	
265 338
The minimum cut problem is to find a non-empty and non-complete
266 339
\f$X\f$ subset of the vertices with minimum overall capacity on
267 340
outgoing arcs. Formally, there is \f$G=(V,A)\f$ directed graph, an
268 341
\f$c_a:A\rightarrow\mathbf{R}^+_0\f$ capacity function. The minimum
269 342
cut is the \f$X\f$ solution of the next optimization problem:
270 343

	
271 344
\f[ \min_{X \subset V, X\not\in \{\emptyset, V\}}
272 345
\sum_{uv\in A, u\in X, v\not\in X}c_{uv}\f]
273 346

	
274 347
LEMON contains several algorithms related to minimum cut problems:
275 348

	
276 349
- \ref lemon::HaoOrlin "Hao-Orlin algorithm" to calculate minimum cut
277 350
  in directed graphs
278 351
- \ref lemon::NagamochiIbaraki "Nagamochi-Ibaraki algorithm" to
279 352
  calculate minimum cut in undirected graphs
280 353
- \ref lemon::GomoryHuTree "Gomory-Hu tree computation" to calculate all
281 354
  pairs minimum cut in undirected graphs
282 355

	
283 356
If you want to find minimum cut just between two distinict nodes,
284 357
please see the \ref max_flow "Maximum Flow page".
285 358
*/
286 359

	
287 360
/**
288 361
@defgroup graph_prop Connectivity and Other Graph Properties
289 362
@ingroup algs
290 363
\brief Algorithms for discovering the graph properties
291 364

	
292 365
This group describes the algorithms for discovering the graph properties
293 366
like connectivity, bipartiteness, euler property, simplicity etc.
294 367

	
295 368
\image html edge_biconnected_components.png
296 369
\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth
297 370
*/
298 371

	
299 372
/**
300 373
@defgroup planar Planarity Embedding and Drawing
301 374
@ingroup algs
302 375
\brief Algorithms for planarity checking, embedding and drawing
303 376

	
304 377
This group describes the algorithms for planarity checking,
305 378
embedding and drawing.
306 379

	
307 380
\image html planar.png
308 381
\image latex planar.eps "Plane graph" width=\textwidth
309 382
*/
310 383

	
311 384
/**
312 385
@defgroup matching Matching Algorithms
313 386
@ingroup algs
314 387
\brief Algorithms for finding matchings in graphs and bipartite graphs.
315 388

	
316 389
This group contains algorithm objects and functions to calculate
317 390
matchings in graphs and bipartite graphs. The general matching problem is
318 391
finding a subset of the arcs which does not shares common endpoints.
319 392

	
320 393
There are several different algorithms for calculate matchings in
321 394
graphs.  The matching problems in bipartite graphs are generally
322 395
easier than in general graphs. The goal of the matching optimization
323 396
can be the finding maximum cardinality, maximum weight or minimum cost
324 397
matching. The search can be constrained to find perfect or
325 398
maximum cardinality matching.
326 399

	
327 400
LEMON contains the next algorithms:
328 401
- \ref lemon::MaxBipartiteMatching "MaxBipartiteMatching" Hopcroft-Karp
329 402
  augmenting path algorithm for calculate maximum cardinality matching in
330 403
  bipartite graphs
331 404
- \ref lemon::PrBipartiteMatching "PrBipartiteMatching" Push-Relabel
332 405
  algorithm for calculate maximum cardinality matching in bipartite graphs
333 406
- \ref lemon::MaxWeightedBipartiteMatching "MaxWeightedBipartiteMatching"
334 407
  Successive shortest path algorithm for calculate maximum weighted matching
335 408
  and maximum weighted bipartite matching in bipartite graph
336 409
- \ref lemon::MinCostMaxBipartiteMatching "MinCostMaxBipartiteMatching"
337 410
  Successive shortest path algorithm for calculate minimum cost maximum
338 411
  matching in bipartite graph
339 412
- \ref lemon::MaxMatching "MaxMatching" Edmond's blossom shrinking algorithm
340 413
  for calculate maximum cardinality matching in general graph
341 414
- \ref lemon::MaxWeightedMatching "MaxWeightedMatching" Edmond's blossom
342 415
  shrinking algorithm for calculate maximum weighted matching in general
343 416
  graph
344 417
- \ref lemon::MaxWeightedPerfectMatching "MaxWeightedPerfectMatching"
345 418
  Edmond's blossom shrinking algorithm for calculate maximum weighted
346 419
  perfect matching in general graph
347 420

	
348 421
\image html bipartite_matching.png
349 422
\image latex bipartite_matching.eps "Bipartite Matching" width=\textwidth
350 423
*/
351 424

	
352 425
/**
353 426
@defgroup spantree Minimum Spanning Tree Algorithms
354 427
@ingroup algs
355 428
\brief Algorithms for finding a minimum cost spanning tree in a graph.
356 429

	
357 430
This group describes the algorithms for finding a minimum cost spanning
358 431
tree in a graph
359 432
*/
360 433

	
361 434
/**
362 435
@defgroup auxalg Auxiliary Algorithms
363 436
@ingroup algs
364 437
\brief Auxiliary algorithms implemented in LEMON.
365 438

	
366 439
This group describes some algorithms implemented in LEMON
367 440
in order to make it easier to implement complex algorithms.
368 441
*/
369 442

	
370 443
/**
371 444
@defgroup approx Approximation Algorithms
372 445
@ingroup algs
373 446
\brief Approximation algorithms.
374 447

	
375 448
This group describes the approximation and heuristic algorithms
376 449
implemented in LEMON.
377 450
*/
378 451

	
379 452
/**
380 453
@defgroup gen_opt_group General Optimization Tools
381 454
\brief This group describes some general optimization frameworks
382 455
implemented in LEMON.
383 456

	
384 457
This group describes some general optimization frameworks
385 458
implemented in LEMON.
386 459
*/
387 460

	
388 461
/**
389 462
@defgroup lp_group Lp and Mip Solvers
390 463
@ingroup gen_opt_group
391 464
\brief Lp and Mip solver interfaces for LEMON.
392 465

	
393 466
This group describes Lp and Mip solver interfaces for LEMON. The
394 467
various LP solvers could be used in the same manner with this
395 468
interface.
396 469
*/
397 470

	
398 471
/**
399 472
@defgroup lp_utils Tools for Lp and Mip Solvers
400 473
@ingroup lp_group
401 474
\brief Helper tools to the Lp and Mip solvers.
402 475

	
403 476
This group adds some helper tools to general optimization framework
404 477
implemented in LEMON.
405 478
*/
406 479

	
407 480
/**
408 481
@defgroup metah Metaheuristics
409 482
@ingroup gen_opt_group
410 483
\brief Metaheuristics for LEMON library.
411 484

	
412 485
This group describes some metaheuristic optimization tools.
413 486
*/
414 487

	
415 488
/**
416 489
@defgroup utils Tools and Utilities
417 490
\brief Tools and utilities for programming in LEMON
418 491

	
419 492
Tools and utilities for programming in LEMON.
420 493
*/
421 494

	
422 495
/**
423 496
@defgroup gutils Basic Graph Utilities
424 497
@ingroup utils
425 498
\brief Simple basic graph utilities.
426 499

	
427 500
This group describes some simple basic graph utilities.
428 501
*/
429 502

	
430 503
/**
431 504
@defgroup misc Miscellaneous Tools
432 505
@ingroup utils
433 506
\brief Tools for development, debugging and testing.
434 507

	
435 508
This group describes several useful tools for development,
436 509
debugging and testing.
437 510
*/
438 511

	
439 512
/**
440 513
@defgroup timecount Time Measuring and Counting
441 514
@ingroup misc
442 515
\brief Simple tools for measuring the performance of algorithms.
443 516

	
444 517
This group describes simple tools for measuring the performance
445 518
of algorithms.
446 519
*/
447 520

	
448 521
/**
449 522
@defgroup exceptions Exceptions
450 523
@ingroup utils
451 524
\brief Exceptions defined in LEMON.
452 525

	
453 526
This group describes the exceptions defined in LEMON.
454 527
*/
455 528

	
456 529
/**
457 530
@defgroup io_group Input-Output
458 531
\brief Graph Input-Output methods
459 532

	
460 533
This group describes the tools for importing and exporting graphs
461 534
and graph related data. Now it supports the \ref lgf-format
462 535
"LEMON Graph Format", the \c DIMACS format and the encapsulated
463 536
postscript (EPS) format.
464 537
*/
465 538

	
466 539
/**
467 540
@defgroup lemon_io LEMON Graph Format
468 541
@ingroup io_group
469 542
\brief Reading and writing LEMON Graph Format.
470 543

	
471 544
This group describes methods for reading and writing
472 545
\ref lgf-format "LEMON Graph Format".
473 546
*/
474 547

	
475 548
/**
476 549
@defgroup eps_io Postscript Exporting
477 550
@ingroup io_group
478 551
\brief General \c EPS drawer and graph exporter
479 552

	
480 553
This group describes general \c EPS drawing methods and special
481 554
graph exporting tools.
482 555
*/
483 556

	
484 557
/**
485 558
@defgroup dimacs_group DIMACS format
486 559
@ingroup io_group
487 560
\brief Read and write files in DIMACS format
488 561

	
489 562
Tools to read a digraph from or write it to a file in DIMACS format data.
490 563
*/
491 564

	
492 565
/**
493 566
@defgroup nauty_group NAUTY Format
494 567
@ingroup io_group
495 568
\brief Read \e Nauty format
496 569

	
497 570
Tool to read graphs from \e Nauty format data.
498 571
*/
499 572

	
500 573
/**
501 574
@defgroup concept Concepts
502 575
\brief Skeleton classes and concept checking classes
503 576

	
504 577
This group describes the data/algorithm skeletons and concept checking
505 578
classes implemented in LEMON.
506 579

	
507 580
The purpose of the classes in this group is fourfold.
508 581

	
509 582
- These classes contain the documentations of the %concepts. In order
510 583
  to avoid document multiplications, an implementation of a concept
511 584
  simply refers to the corresponding concept class.
512 585

	
513 586
- These classes declare every functions, <tt>typedef</tt>s etc. an
514 587
  implementation of the %concepts should provide, however completely
515 588
  without implementations and real data structures behind the
516 589
  interface. On the other hand they should provide nothing else. All
517 590
  the algorithms working on a data structure meeting a certain concept
518 591
  should compile with these classes. (Though it will not run properly,
519 592
  of course.) In this way it is easily to check if an algorithm
520 593
  doesn't use any extra feature of a certain implementation.
521 594

	
522 595
- The concept descriptor classes also provide a <em>checker class</em>
523 596
  that makes it possible to check whether a certain implementation of a
524 597
  concept indeed provides all the required features.
525 598

	
526 599
- Finally, They can serve as a skeleton of a new implementation of a concept.
527 600
*/
528 601

	
529 602
/**
530 603
@defgroup graph_concepts Graph Structure Concepts
531 604
@ingroup concept
532 605
\brief Skeleton and concept checking classes for graph structures
533 606

	
534 607
This group describes the skeletons and concept checking classes of LEMON's
535 608
graph structures and helper classes used to implement these.
536 609
*/
537 610

	
538 611
/**
539 612
@defgroup map_concepts Map Concepts
540 613
@ingroup concept
541 614
\brief Skeleton and concept checking classes for maps
542 615

	
543 616
This group describes the skeletons and concept checking classes of maps.
544 617
*/
545 618

	
546 619
/**
547 620
\anchor demoprograms
548 621

	
549 622
@defgroup demos Demo programs
550 623

	
551 624
Some demo programs are listed here. Their full source codes can be found in
552 625
the \c demo subdirectory of the source tree.
553 626

	
554 627
It order to compile them, use <tt>--enable-demo</tt> configure option when
555 628
build the library.
556 629
*/
557 630

	
558 631
/**
559 632
@defgroup tools Standalone utility applications
560 633

	
561 634
Some utility applications are listed here.
562 635

	
563 636
The standard compilation procedure (<tt>./configure;make</tt>) will compile
564 637
them, as well.
565 638
*/
566 639

	
Ignore white space 6 line context
1 1
EXTRA_DIST += \
2 2
	lemon/lemon.pc.in \
3 3
	lemon/CMakeLists.txt
4 4

	
5 5
pkgconfig_DATA += lemon/lemon.pc
6 6

	
7 7
lib_LTLIBRARIES += lemon/libemon.la
8 8

	
9 9
lemon_libemon_la_SOURCES = \
10 10
        lemon/arg_parser.cc \
11 11
        lemon/base.cc \
12 12
        lemon/color.cc \
13 13
        lemon/random.cc
14 14

	
15 15
#lemon_libemon_la_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS) $(SOPLEX_CXXFLAGS) $(AM_CXXFLAGS)
16 16
#lemon_libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS) $(SOPLEX_LIBS)
17 17

	
18 18
lemon_HEADERS += \
19
	lemon/adaptors.h \
19 20
        lemon/arg_parser.h \
20 21
	lemon/assert.h \
21 22
        lemon/bfs.h \
22 23
        lemon/bin_heap.h \
23 24
        lemon/color.h \
24 25
	lemon/concept_check.h \
25 26
        lemon/counter.h \
26 27
	lemon/core.h \
27 28
        lemon/dfs.h \
28 29
        lemon/dijkstra.h \
29 30
        lemon/dim2.h \
30 31
        lemon/dimacs.h \
31 32
	lemon/elevator.h \
32 33
	lemon/error.h \
33 34
	lemon/full_graph.h \
34 35
        lemon/graph_to_eps.h \
35 36
        lemon/grid_graph.h \
36 37
	lemon/hypercube_graph.h \
37 38
	lemon/kruskal.h \
38 39
	lemon/lgf_reader.h \
39 40
	lemon/lgf_writer.h \
40 41
	lemon/list_graph.h \
41 42
	lemon/maps.h \
42 43
	lemon/math.h \
43 44
	lemon/max_matching.h \
44 45
	lemon/nauty_reader.h \
45 46
	lemon/path.h \
46 47
	lemon/preflow.h \
47 48
        lemon/random.h \
48 49
	lemon/smart_graph.h \
49 50
	lemon/suurballe.h \
50 51
        lemon/time_measure.h \
51 52
        lemon/tolerance.h \
52 53
	lemon/unionfind.h
53 54

	
54 55
bits_HEADERS += \
55 56
	lemon/bits/alteration_notifier.h \
56 57
	lemon/bits/array_map.h \
57 58
	lemon/bits/base_extender.h \
58 59
        lemon/bits/bezier.h \
59 60
	lemon/bits/default_map.h \
60 61
        lemon/bits/enable_if.h \
61 62
	lemon/bits/graph_adaptor_extender.h \
62 63
	lemon/bits/graph_extender.h \
63 64
	lemon/bits/map_extender.h \
64 65
	lemon/bits/path_dump.h \
65 66
	lemon/bits/traits.h \
66 67
	lemon/bits/variant.h \
67 68
	lemon/bits/vector_map.h
68 69

	
69 70
concept_HEADERS += \
70 71
	lemon/concepts/digraph.h \
71 72
	lemon/concepts/graph.h \
72 73
	lemon/concepts/graph_components.h \
73 74
	lemon/concepts/heap.h \
74 75
	lemon/concepts/maps.h \
75 76
	lemon/concepts/path.h
Ignore white space 6 line context
1
/* -*- C++ -*-
1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3
 * This file is a part of LEMON, a generic C++ optimization library
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
#ifndef LEMON_DIGRAPH_ADAPTOR_H
20
#define LEMON_DIGRAPH_ADAPTOR_H
21

	
22
///\ingroup graph_adaptors
23
///\file
24
///\brief Several digraph adaptors.
19
#ifndef LEMON_ADAPTORS_H
20
#define LEMON_ADAPTORS_H
21

	
22
/// \ingroup graph_adaptors
23
/// \file
24
/// \brief Several graph adaptors
25 25
///
26
///This file contains several useful digraph adaptor classes.
26
/// This file contains several useful adaptors for digraphs and graphs.
27 27

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

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

	
37 35
#include <algorithm>
38 36

	
39 37
namespace lemon {
40 38

	
41 39
  template<typename _Digraph>
42 40
  class DigraphAdaptorBase {
43 41
  public:
44 42
    typedef _Digraph Digraph;
45 43
    typedef DigraphAdaptorBase Adaptor;
46 44
    typedef Digraph ParentDigraph;
47 45

	
48 46
  protected:
49 47
    Digraph* _digraph;
50 48
    DigraphAdaptorBase() : _digraph(0) { }
51 49
    void setDigraph(Digraph& digraph) { _digraph = &digraph; }
52 50

	
53 51
  public:
54 52
    DigraphAdaptorBase(Digraph& digraph) : _digraph(&digraph) { }
55 53

	
56 54
    typedef typename Digraph::Node Node;
57 55
    typedef typename Digraph::Arc Arc;
58
   
56

	
59 57
    void first(Node& i) const { _digraph->first(i); }
60 58
    void first(Arc& i) const { _digraph->first(i); }
61 59
    void firstIn(Arc& i, const Node& n) const { _digraph->firstIn(i, n); }
62 60
    void firstOut(Arc& i, const Node& n ) const { _digraph->firstOut(i, n); }
63 61

	
64 62
    void next(Node& i) const { _digraph->next(i); }
65 63
    void next(Arc& i) const { _digraph->next(i); }
66 64
    void nextIn(Arc& i) const { _digraph->nextIn(i); }
67 65
    void nextOut(Arc& i) const { _digraph->nextOut(i); }
68 66

	
69 67
    Node source(const Arc& a) const { return _digraph->source(a); }
70 68
    Node target(const Arc& a) const { return _digraph->target(a); }
71 69

	
72 70
    typedef NodeNumTagIndicator<Digraph> NodeNumTag;
73 71
    int nodeNum() const { return _digraph->nodeNum(); }
74
    
72

	
75 73
    typedef EdgeNumTagIndicator<Digraph> EdgeNumTag;
76 74
    int arcNum() const { return _digraph->arcNum(); }
77 75

	
78 76
    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
79 77
    Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
80 78
      return _digraph->findArc(u, v, prev);
81 79
    }
82
  
80

	
83 81
    Node addNode() { return _digraph->addNode(); }
84 82
    Arc addArc(const Node& u, const Node& v) { return _digraph->addArc(u, v); }
85 83

	
86 84
    void erase(const Node& n) const { _digraph->erase(n); }
87 85
    void erase(const Arc& a) const { _digraph->erase(a); }
88
  
86

	
89 87
    void clear() const { _digraph->clear(); }
90
    
88

	
91 89
    int id(const Node& n) const { return _digraph->id(n); }
92 90
    int id(const Arc& a) const { return _digraph->id(a); }
93 91

	
94 92
    Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
95 93
    Arc arcFromId(int ix) const { return _digraph->arcFromId(ix); }
96 94

	
97 95
    int maxNodeId() const { return _digraph->maxNodeId(); }
98 96
    int maxArcId() const { return _digraph->maxArcId(); }
99 97

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

	
103 101
    typedef typename ItemSetTraits<Digraph, Arc>::ItemNotifier ArcNotifier;
104
    ArcNotifier& notifier(Arc) const { return _digraph->notifier(Arc()); } 
105
    
102
    ArcNotifier& notifier(Arc) const { return _digraph->notifier(Arc()); }
103

	
106 104
    template <typename _Value>
107 105
    class NodeMap : public Digraph::template NodeMap<_Value> {
108 106
    public:
109 107

	
110 108
      typedef typename Digraph::template NodeMap<_Value> Parent;
111 109

	
112
      explicit NodeMap(const Adaptor& adaptor) 
113
	: Parent(*adaptor._digraph) {}
110
      explicit NodeMap(const Adaptor& adaptor)
111
        : Parent(*adaptor._digraph) {}
114 112

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

	
118 116
    private:
119 117
      NodeMap& operator=(const NodeMap& cmap) {
120 118
        return operator=<NodeMap>(cmap);
121 119
      }
122 120

	
123 121
      template <typename CMap>
124 122
      NodeMap& operator=(const CMap& cmap) {
125 123
        Parent::operator=(cmap);
126 124
        return *this;
127 125
      }
128
      
126

	
129 127
    };
130 128

	
131 129
    template <typename _Value>
132 130
    class ArcMap : public Digraph::template ArcMap<_Value> {
133 131
    public:
134
      
132

	
135 133
      typedef typename Digraph::template ArcMap<_Value> Parent;
136
      
137
      explicit ArcMap(const Adaptor& adaptor) 
138
	: Parent(*adaptor._digraph) {}
134

	
135
      explicit ArcMap(const Adaptor& adaptor)
136
        : Parent(*adaptor._digraph) {}
139 137

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

	
143 141
    private:
144 142
      ArcMap& operator=(const ArcMap& cmap) {
145 143
        return operator=<ArcMap>(cmap);
146 144
      }
147 145

	
148 146
      template <typename CMap>
149 147
      ArcMap& operator=(const CMap& cmap) {
150 148
        Parent::operator=(cmap);
151 149
        return *this;
152 150
      }
153 151

	
154 152
    };
155 153

	
156 154
  };
157 155

	
156
  template<typename _Graph>
157
  class GraphAdaptorBase {
158
  public:
159
    typedef _Graph Graph;
160
    typedef Graph ParentGraph;
161

	
162
  protected:
163
    Graph* _graph;
164

	
165
    GraphAdaptorBase() : _graph(0) {}
166

	
167
    void setGraph(Graph& graph) { _graph = &graph; }
168

	
169
  public:
170
    GraphAdaptorBase(Graph& graph) : _graph(&graph) {}
171

	
172
    typedef typename Graph::Node Node;
173
    typedef typename Graph::Arc Arc;
174
    typedef typename Graph::Edge Edge;
175

	
176
    void first(Node& i) const { _graph->first(i); }
177
    void first(Arc& i) const { _graph->first(i); }
178
    void first(Edge& i) const { _graph->first(i); }
179
    void firstIn(Arc& i, const Node& n) const { _graph->firstIn(i, n); }
180
    void firstOut(Arc& i, const Node& n ) const { _graph->firstOut(i, n); }
181
    void firstInc(Edge &i, bool &d, const Node &n) const {
182
      _graph->firstInc(i, d, n);
183
    }
184

	
185
    void next(Node& i) const { _graph->next(i); }
186
    void next(Arc& i) const { _graph->next(i); }
187
    void next(Edge& i) const { _graph->next(i); }
188
    void nextIn(Arc& i) const { _graph->nextIn(i); }
189
    void nextOut(Arc& i) const { _graph->nextOut(i); }
190
    void nextInc(Edge &i, bool &d) const { _graph->nextInc(i, d); }
191

	
192
    Node u(const Edge& e) const { return _graph->u(e); }
193
    Node v(const Edge& e) const { return _graph->v(e); }
194

	
195
    Node source(const Arc& a) const { return _graph->source(a); }
196
    Node target(const Arc& a) const { return _graph->target(a); }
197

	
198
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
199
    int nodeNum() const { return _graph->nodeNum(); }
200

	
201
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
202
    int arcNum() const { return _graph->arcNum(); }
203
    int edgeNum() const { return _graph->edgeNum(); }
204

	
205
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
206
    Arc findArc(const Node& u, const Node& v, const Arc& prev = INVALID) {
207
      return _graph->findArc(u, v, prev);
208
    }
209
    Edge findEdge(const Node& u, const Node& v, const Edge& prev = INVALID) {
210
      return _graph->findEdge(u, v, prev);
211
    }
212

	
213
    Node addNode() { return _graph->addNode(); }
214
    Edge addEdge(const Node& u, const Node& v) { return _graph->addEdge(u, v); }
215

	
216
    void erase(const Node& i) { _graph->erase(i); }
217
    void erase(const Edge& i) { _graph->erase(i); }
218

	
219
    void clear() { _graph->clear(); }
220

	
221
    bool direction(const Arc& a) const { return _graph->direction(a); }
222
    Arc direct(const Edge& e, bool d) const { return _graph->direct(e, d); }
223

	
224
    int id(const Node& v) const { return _graph->id(v); }
225
    int id(const Arc& a) const { return _graph->id(a); }
226
    int id(const Edge& e) const { return _graph->id(e); }
227

	
228
    Node nodeFromId(int ix) const { return _graph->nodeFromId(ix); }
229
    Arc arcFromId(int ix) const { return _graph->arcFromId(ix); }
230
    Edge edgeFromId(int ix) const { return _graph->edgeFromId(ix); }
231

	
232
    int maxNodeId() const { return _graph->maxNodeId(); }
233
    int maxArcId() const { return _graph->maxArcId(); }
234
    int maxEdgeId() const { return _graph->maxEdgeId(); }
235

	
236
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
237
    NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
238

	
239
    typedef typename ItemSetTraits<Graph, Arc>::ItemNotifier ArcNotifier;
240
    ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
241

	
242
    typedef typename ItemSetTraits<Graph, Edge>::ItemNotifier EdgeNotifier;
243
    EdgeNotifier& notifier(Edge) const { return _graph->notifier(Edge()); }
244

	
245
    template <typename _Value>
246
    class NodeMap : public Graph::template NodeMap<_Value> {
247
    public:
248
      typedef typename Graph::template NodeMap<_Value> Parent;
249
      explicit NodeMap(const GraphAdaptorBase<Graph>& adapter)
250
        : Parent(*adapter._graph) {}
251
      NodeMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
252
        : Parent(*adapter._graph, value) {}
253

	
254
    private:
255
      NodeMap& operator=(const NodeMap& cmap) {
256
        return operator=<NodeMap>(cmap);
257
      }
258

	
259
      template <typename CMap>
260
      NodeMap& operator=(const CMap& cmap) {
261
        Parent::operator=(cmap);
262
        return *this;
263
      }
264

	
265
    };
266

	
267
    template <typename _Value>
268
    class ArcMap : public Graph::template ArcMap<_Value> {
269
    public:
270
      typedef typename Graph::template ArcMap<_Value> Parent;
271
      explicit ArcMap(const GraphAdaptorBase<Graph>& adapter)
272
        : Parent(*adapter._graph) {}
273
      ArcMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
274
        : Parent(*adapter._graph, value) {}
275

	
276
    private:
277
      ArcMap& operator=(const ArcMap& cmap) {
278
        return operator=<ArcMap>(cmap);
279
      }
280

	
281
      template <typename CMap>
282
      ArcMap& operator=(const CMap& cmap) {
283
        Parent::operator=(cmap);
284
        return *this;
285
      }
286
    };
287

	
288
    template <typename _Value>
289
    class EdgeMap : public Graph::template EdgeMap<_Value> {
290
    public:
291
      typedef typename Graph::template EdgeMap<_Value> Parent;
292
      explicit EdgeMap(const GraphAdaptorBase<Graph>& adapter)
293
        : Parent(*adapter._graph) {}
294
      EdgeMap(const GraphAdaptorBase<Graph>& adapter, const _Value& value)
295
        : Parent(*adapter._graph, value) {}
296

	
297
    private:
298
      EdgeMap& operator=(const EdgeMap& cmap) {
299
        return operator=<EdgeMap>(cmap);
300
      }
301

	
302
      template <typename CMap>
303
      EdgeMap& operator=(const CMap& cmap) {
304
        Parent::operator=(cmap);
305
        return *this;
306
      }
307
    };
308

	
309
  };
158 310

	
159 311
  template <typename _Digraph>
160
  class RevDigraphAdaptorBase : public DigraphAdaptorBase<_Digraph> {
312
  class ReverseDigraphBase : public DigraphAdaptorBase<_Digraph> {
161 313
  public:
162 314
    typedef _Digraph Digraph;
163 315
    typedef DigraphAdaptorBase<_Digraph> Parent;
164 316
  protected:
165
    RevDigraphAdaptorBase() : Parent() { }
317
    ReverseDigraphBase() : Parent() { }
166 318
  public:
167 319
    typedef typename Parent::Node Node;
168 320
    typedef typename Parent::Arc Arc;
169 321

	
170 322
    void firstIn(Arc& a, const Node& n) const { Parent::firstOut(a, n); }
171 323
    void firstOut(Arc& a, const Node& n ) const { Parent::firstIn(a, n); }
172 324

	
173 325
    void nextIn(Arc& a) const { Parent::nextOut(a); }
174 326
    void nextOut(Arc& a) const { Parent::nextIn(a); }
175 327

	
176 328
    Node source(const Arc& a) const { return Parent::target(a); }
177 329
    Node target(const Arc& a) const { return Parent::source(a); }
178 330

	
331
    Arc addArc(const Node& u, const Node& v) { return Parent::addArc(v, u); }
332

	
179 333
    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
180
    Arc findArc(const Node& u, const Node& v, 
181
		const Arc& prev = INVALID) {
334
    Arc findArc(const Node& u, const Node& v,
335
                const Arc& prev = INVALID) {
182 336
      return Parent::findArc(v, u, prev);
183 337
    }
184 338

	
185 339
  };
186
    
187

	
188
  ///\ingroup graph_adaptors
340

	
341
  /// \ingroup graph_adaptors
189 342
  ///
190
  ///\brief A digraph adaptor which reverses the orientation of the arcs.
343
  /// \brief A digraph adaptor which reverses the orientation of the arcs.
191 344
  ///
192
  /// If \c g is defined as
193
  ///\code
194
  /// ListDigraph dg;
195
  ///\endcode
196
  /// then
197
  ///\code
198
  /// RevDigraphAdaptor<ListDigraph> dga(dg);
199
  ///\endcode
200
  /// implements the digraph obtained from \c dg by 
201
  /// reversing the orientation of its arcs.
345
  /// ReverseDigraph reverses the arcs in the adapted digraph. The
346
  /// SubDigraph is conform to the \ref concepts::Digraph
347
  /// "Digraph concept".
202 348
  ///
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.
211
  ///
212
  /// The implementation:
213
  ///\code
214
  /// bool stronglyConnected(const Digraph& digraph) {
215
  ///   if (NodeIt(digraph) == INVALID) return true;
216
  ///   Dfs<Digraph> dfs(digraph);
217
  ///   dfs.run(NodeIt(digraph));
218
  ///   for (NodeIt it(digraph); it != INVALID; ++it) {
219
  ///     if (!dfs.reached(it)) {
220
  ///       return false;
221
  ///     }
222
  ///   }
223
  ///   typedef RevDigraphAdaptor<const Digraph> RDigraph;
224
  ///   RDigraph rdigraph(digraph);
225
  ///   DfsVisit<RDigraph> rdfs(rdigraph);
226
  ///   rdfs.run(NodeIt(digraph));
227
  ///   for (NodeIt it(digraph); it != INVALID; ++it) {
228
  ///     if (!rdfs.reached(it)) {
229
  ///       return false;
230
  ///     }
231
  ///   }
232
  ///   return true;
233
  /// }
234
  ///\endcode
349
  /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
350
  /// "Digraph concept". The type can be specified to be const.
235 351
  template<typename _Digraph>
236
  class RevDigraphAdaptor : 
237
    public DigraphAdaptorExtender<RevDigraphAdaptorBase<_Digraph> > {
352
  class ReverseDigraph :
353
    public DigraphAdaptorExtender<ReverseDigraphBase<_Digraph> > {
238 354
  public:
239 355
    typedef _Digraph Digraph;
240 356
    typedef DigraphAdaptorExtender<
241
      RevDigraphAdaptorBase<_Digraph> > Parent;
357
      ReverseDigraphBase<_Digraph> > Parent;
242 358
  protected:
243
    RevDigraphAdaptor() { }
359
    ReverseDigraph() { }
244 360
  public:
245 361

	
246 362
    /// \brief Constructor
247 363
    ///
248
    /// Creates a reverse graph adaptor for the given digraph
249
    explicit RevDigraphAdaptor(Digraph& digraph) { 
250
      Parent::setDigraph(digraph); 
364
    /// Creates a reverse digraph adaptor for the given digraph
365
    explicit ReverseDigraph(Digraph& digraph) {
366
      Parent::setDigraph(digraph);
251 367
    }
252 368
  };
253 369

	
254 370
  /// \brief Just gives back a reverse digraph adaptor
255 371
  ///
256 372
  /// Just gives back a reverse digraph adaptor
257 373
  template<typename Digraph>
258
  RevDigraphAdaptor<const Digraph>
259
  revDigraphAdaptor(const Digraph& digraph) {
260
    return RevDigraphAdaptor<const Digraph>(digraph);
374
  ReverseDigraph<const Digraph> reverseDigraph(const Digraph& digraph) {
375
    return ReverseDigraph<const Digraph>(digraph);
261 376
  }
262 377

	
263
  template <typename _Digraph, typename _NodeFilterMap, 
264
	    typename _ArcFilterMap, bool checked = true>
265
  class SubDigraphAdaptorBase : public DigraphAdaptorBase<_Digraph> {
378
  template <typename _Digraph, typename _NodeFilterMap,
379
            typename _ArcFilterMap, bool _checked = true>
380
  class SubDigraphBase : public DigraphAdaptorBase<_Digraph> {
266 381
  public:
267 382
    typedef _Digraph Digraph;
268 383
    typedef _NodeFilterMap NodeFilterMap;
269 384
    typedef _ArcFilterMap ArcFilterMap;
270 385

	
271
    typedef SubDigraphAdaptorBase Adaptor;
386
    typedef SubDigraphBase Adaptor;
272 387
    typedef DigraphAdaptorBase<_Digraph> Parent;
273 388
  protected:
274 389
    NodeFilterMap* _node_filter;
275 390
    ArcFilterMap* _arc_filter;
276
    SubDigraphAdaptorBase() 
391
    SubDigraphBase()
277 392
      : Parent(), _node_filter(0), _arc_filter(0) { }
278 393

	
279 394
    void setNodeFilterMap(NodeFilterMap& node_filter) {
280 395
      _node_filter = &node_filter;
281 396
    }
282 397
    void setArcFilterMap(ArcFilterMap& arc_filter) {
283 398
      _arc_filter = &arc_filter;
284 399
    }
285 400

	
286 401
  public:
287 402

	
288 403
    typedef typename Parent::Node Node;
289 404
    typedef typename Parent::Arc Arc;
290 405

	
291
    void first(Node& i) const { 
292
      Parent::first(i); 
293
      while (i != INVALID && !(*_node_filter)[i]) Parent::next(i); 
406
    void first(Node& i) const {
407
      Parent::first(i);
408
      while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
294 409
    }
295 410

	
296
    void first(Arc& i) const { 
297
      Parent::first(i); 
298
      while (i != INVALID && (!(*_arc_filter)[i] 
299
	     || !(*_node_filter)[Parent::source(i)]
300
	     || !(*_node_filter)[Parent::target(i)])) Parent::next(i); 
411
    void first(Arc& i) const {
412
      Parent::first(i);
413
      while (i != INVALID && (!(*_arc_filter)[i]
414
                              || !(*_node_filter)[Parent::source(i)]
415
                              || !(*_node_filter)[Parent::target(i)]))
416
        Parent::next(i);
301 417
    }
302 418

	
303
    void firstIn(Arc& i, const Node& n) const { 
304
      Parent::firstIn(i, n); 
305
      while (i != INVALID && (!(*_arc_filter)[i] 
306
	     || !(*_node_filter)[Parent::source(i)])) Parent::nextIn(i); 
419
    void firstIn(Arc& i, const Node& n) const {
420
      Parent::firstIn(i, n);
421
      while (i != INVALID && (!(*_arc_filter)[i]
422
                              || !(*_node_filter)[Parent::source(i)]))
423
        Parent::nextIn(i);
307 424
    }
308 425

	
309
    void firstOut(Arc& i, const Node& n) const { 
310
      Parent::firstOut(i, n); 
311
      while (i != INVALID && (!(*_arc_filter)[i] 
312
	     || !(*_node_filter)[Parent::target(i)])) Parent::nextOut(i); 
426
    void firstOut(Arc& i, const Node& n) const {
427
      Parent::firstOut(i, n);
428
      while (i != INVALID && (!(*_arc_filter)[i]
429
                              || !(*_node_filter)[Parent::target(i)]))
430
        Parent::nextOut(i);
313 431
    }
314 432

	
315
    void next(Node& i) const { 
316
      Parent::next(i); 
317
      while (i != INVALID && !(*_node_filter)[i]) Parent::next(i); 
433
    void next(Node& i) const {
434
      Parent::next(i);
435
      while (i != INVALID && !(*_node_filter)[i]) Parent::next(i);
318 436
    }
319 437

	
320
    void next(Arc& i) const { 
321
      Parent::next(i); 
322
      while (i != INVALID && (!(*_arc_filter)[i] 
323
	     || !(*_node_filter)[Parent::source(i)]
324
	     || !(*_node_filter)[Parent::target(i)])) Parent::next(i); 
438
    void next(Arc& i) const {
439
      Parent::next(i);
440
      while (i != INVALID && (!(*_arc_filter)[i]
441
                              || !(*_node_filter)[Parent::source(i)]
442
                              || !(*_node_filter)[Parent::target(i)]))
443
        Parent::next(i);
325 444
    }
326 445

	
327
    void nextIn(Arc& i) const { 
328
      Parent::nextIn(i); 
329
      while (i != INVALID && (!(*_arc_filter)[i] 
330
	     || !(*_node_filter)[Parent::source(i)])) Parent::nextIn(i); 
446
    void nextIn(Arc& i) const {
447
      Parent::nextIn(i);
448
      while (i != INVALID && (!(*_arc_filter)[i]
449
                              || !(*_node_filter)[Parent::source(i)]))
450
        Parent::nextIn(i);
331 451
    }
332 452

	
333
    void nextOut(Arc& i) const { 
334
      Parent::nextOut(i); 
335
      while (i != INVALID && (!(*_arc_filter)[i] 
336
	     || !(*_node_filter)[Parent::target(i)])) Parent::nextOut(i); 
453
    void nextOut(Arc& i) const {
454
      Parent::nextOut(i);
455
      while (i != INVALID && (!(*_arc_filter)[i]
456
                              || !(*_node_filter)[Parent::target(i)]))
457
        Parent::nextOut(i);
337 458
    }
338 459

	
339 460
    void hide(const Node& n) const { _node_filter->set(n, false); }
340 461
    void hide(const Arc& a) const { _arc_filter->set(a, false); }
341 462

	
342 463
    void unHide(const Node& n) const { _node_filter->set(n, true); }
343 464
    void unHide(const Arc& a) const { _arc_filter->set(a, true); }
344 465

	
345 466
    bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
346 467
    bool hidden(const Arc& a) const { return !(*_arc_filter)[a]; }
347 468

	
348 469
    typedef False NodeNumTag;
349 470
    typedef False EdgeNumTag;
350 471

	
351 472
    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
352
    Arc findArc(const Node& source, const Node& target, 
353
		const Arc& prev = INVALID) {
473
    Arc findArc(const Node& source, const Node& target,
474
                const Arc& prev = INVALID) {
354 475
      if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
355 476
        return INVALID;
356 477
      }
357 478
      Arc arc = Parent::findArc(source, target, prev);
358 479
      while (arc != INVALID && !(*_arc_filter)[arc]) {
359 480
        arc = Parent::findArc(source, target, arc);
360 481
      }
361 482
      return arc;
362 483
    }
363 484

	
364 485
    template <typename _Value>
365
    class NodeMap : public SubMapExtender<Adaptor, 
366
        typename Parent::template NodeMap<_Value> > {
486
    class NodeMap : public SubMapExtender<Adaptor,
487
      typename Parent::template NodeMap<_Value> > {
367 488
    public:
368 489
      typedef _Value Value;
369 490
      typedef SubMapExtender<Adaptor, typename Parent::
370 491
                             template NodeMap<Value> > MapParent;
371
    
372
      NodeMap(const Adaptor& adaptor) 
373
	: MapParent(adaptor) {}
374
      NodeMap(const Adaptor& adaptor, const Value& value) 
375
	: MapParent(adaptor, value) {}
376
    
492

	
493
      NodeMap(const Adaptor& adaptor)
494
        : MapParent(adaptor) {}
495
      NodeMap(const Adaptor& adaptor, const Value& value)
496
        : MapParent(adaptor, value) {}
497

	
377 498
    private:
378 499
      NodeMap& operator=(const NodeMap& cmap) {
379
	return operator=<NodeMap>(cmap);
500
        return operator=<NodeMap>(cmap);
380 501
      }
381
    
502

	
382 503
      template <typename CMap>
383 504
      NodeMap& operator=(const CMap& cmap) {
384 505
        MapParent::operator=(cmap);
385
	return *this;
506
        return *this;
386 507
      }
387 508
    };
388 509

	
389 510
    template <typename _Value>
390
    class ArcMap : public SubMapExtender<Adaptor, 
391
	typename Parent::template ArcMap<_Value> > {
511
    class ArcMap : public SubMapExtender<Adaptor,
512
      typename Parent::template ArcMap<_Value> > {
392 513
    public:
393 514
      typedef _Value Value;
394 515
      typedef SubMapExtender<Adaptor, typename Parent::
395 516
                             template ArcMap<Value> > MapParent;
396
    
397
      ArcMap(const Adaptor& adaptor) 
398
	: MapParent(adaptor) {}
399
      ArcMap(const Adaptor& adaptor, const Value& value) 
400
	: MapParent(adaptor, value) {}
401
    
517

	
518
      ArcMap(const Adaptor& adaptor)
519
        : MapParent(adaptor) {}
520
      ArcMap(const Adaptor& adaptor, const Value& value)
521
        : MapParent(adaptor, value) {}
522

	
402 523
    private:
403 524
      ArcMap& operator=(const ArcMap& cmap) {
404
	return operator=<ArcMap>(cmap);
525
        return operator=<ArcMap>(cmap);
405 526
      }
406
    
527

	
407 528
      template <typename CMap>
408 529
      ArcMap& operator=(const CMap& cmap) {
409 530
        MapParent::operator=(cmap);
410
	return *this;
531
        return *this;
411 532
      }
412 533
    };
413 534

	
414 535
  };
415 536

	
416 537
  template <typename _Digraph, typename _NodeFilterMap, typename _ArcFilterMap>
417
  class SubDigraphAdaptorBase<_Digraph, _NodeFilterMap, _ArcFilterMap, false> 
538
  class SubDigraphBase<_Digraph, _NodeFilterMap, _ArcFilterMap, false>
418 539
    : public DigraphAdaptorBase<_Digraph> {
419 540
  public:
420 541
    typedef _Digraph Digraph;
421 542
    typedef _NodeFilterMap NodeFilterMap;
422 543
    typedef _ArcFilterMap ArcFilterMap;
423 544

	
424
    typedef SubDigraphAdaptorBase Adaptor;
545
    typedef SubDigraphBase Adaptor;
425 546
    typedef DigraphAdaptorBase<Digraph> Parent;
426 547
  protected:
427 548
    NodeFilterMap* _node_filter;
428 549
    ArcFilterMap* _arc_filter;
429
    SubDigraphAdaptorBase() 
550
    SubDigraphBase()
430 551
      : Parent(), _node_filter(0), _arc_filter(0) { }
431 552

	
432 553
    void setNodeFilterMap(NodeFilterMap& node_filter) {
433 554
      _node_filter = &node_filter;
434 555
    }
435 556
    void setArcFilterMap(ArcFilterMap& arc_filter) {
436 557
      _arc_filter = &arc_filter;
437 558
    }
438 559

	
439 560
  public:
440 561

	
441 562
    typedef typename Parent::Node Node;
442 563
    typedef typename Parent::Arc Arc;
443 564

	
444
    void first(Node& i) const { 
445
      Parent::first(i); 
446
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i); 
565
    void first(Node& i) const {
566
      Parent::first(i);
567
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
447 568
    }
448 569

	
449
    void first(Arc& i) const { 
450
      Parent::first(i); 
451
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i); 
570
    void first(Arc& i) const {
571
      Parent::first(i);
572
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
452 573
    }
453 574

	
454
    void firstIn(Arc& i, const Node& n) const { 
455
      Parent::firstIn(i, n); 
456
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i); 
575
    void firstIn(Arc& i, const Node& n) const {
576
      Parent::firstIn(i, n);
577
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
457 578
    }
458 579

	
459
    void firstOut(Arc& i, const Node& n) const { 
460
      Parent::firstOut(i, n); 
461
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i); 
580
    void firstOut(Arc& i, const Node& n) const {
581
      Parent::firstOut(i, n);
582
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
462 583
    }
463 584

	
464
    void next(Node& i) const { 
465
      Parent::next(i); 
466
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i); 
585
    void next(Node& i) const {
586
      Parent::next(i);
587
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
467 588
    }
468
    void next(Arc& i) const { 
469
      Parent::next(i); 
470
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i); 
589
    void next(Arc& i) const {
590
      Parent::next(i);
591
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
471 592
    }
472
    void nextIn(Arc& i) const { 
473
      Parent::nextIn(i); 
474
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i); 
593
    void nextIn(Arc& i) const {
594
      Parent::nextIn(i);
595
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
475 596
    }
476 597

	
477
    void nextOut(Arc& i) const { 
478
      Parent::nextOut(i); 
479
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i); 
598
    void nextOut(Arc& i) const {
599
      Parent::nextOut(i);
600
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextOut(i);
480 601
    }
481 602

	
482 603
    void hide(const Node& n) const { _node_filter->set(n, false); }
483 604
    void hide(const Arc& e) const { _arc_filter->set(e, false); }
484 605

	
485 606
    void unHide(const Node& n) const { _node_filter->set(n, true); }
486 607
    void unHide(const Arc& e) const { _arc_filter->set(e, true); }
487 608

	
488 609
    bool hidden(const Node& n) const { return !(*_node_filter)[n]; }
489 610
    bool hidden(const Arc& e) const { return !(*_arc_filter)[e]; }
490 611

	
491 612
    typedef False NodeNumTag;
492 613
    typedef False EdgeNumTag;
493 614

	
494 615
    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
495
    Arc findArc(const Node& source, const Node& target, 
496
		  const Arc& prev = INVALID) {
616
    Arc findArc(const Node& source, const Node& target,
617
                const Arc& prev = INVALID) {
497 618
      if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
498 619
        return INVALID;
499 620
      }
500 621
      Arc arc = Parent::findArc(source, target, prev);
501 622
      while (arc != INVALID && !(*_arc_filter)[arc]) {
502 623
        arc = Parent::findArc(source, target, arc);
503 624
      }
504 625
      return arc;
505 626
    }
506 627

	
507 628
    template <typename _Value>
508
    class NodeMap : public SubMapExtender<Adaptor, 
509
        typename Parent::template NodeMap<_Value> > {
629
    class NodeMap : public SubMapExtender<Adaptor,
630
      typename Parent::template NodeMap<_Value> > {
510 631
    public:
511 632
      typedef _Value Value;
512 633
      typedef SubMapExtender<Adaptor, typename Parent::
513 634
                             template NodeMap<Value> > MapParent;
514
    
515
      NodeMap(const Adaptor& adaptor) 
516
	: MapParent(adaptor) {}
517
      NodeMap(const Adaptor& adaptor, const Value& value) 
518
	: MapParent(adaptor, value) {}
519
    
635

	
636
      NodeMap(const Adaptor& adaptor)
637
        : MapParent(adaptor) {}
638
      NodeMap(const Adaptor& adaptor, const Value& value)
639
        : MapParent(adaptor, value) {}
640

	
520 641
    private:
521 642
      NodeMap& operator=(const NodeMap& cmap) {
522
	return operator=<NodeMap>(cmap);
643
        return operator=<NodeMap>(cmap);
523 644
      }
524
    
645

	
525 646
      template <typename CMap>
526 647
      NodeMap& operator=(const CMap& cmap) {
527 648
        MapParent::operator=(cmap);
528
	return *this;
649
        return *this;
529 650
      }
530 651
    };
531 652

	
532 653
    template <typename _Value>
533
    class ArcMap : public SubMapExtender<Adaptor, 
534
	typename Parent::template ArcMap<_Value> > {
654
    class ArcMap : public SubMapExtender<Adaptor,
655
      typename Parent::template ArcMap<_Value> > {
535 656
    public:
536 657
      typedef _Value Value;
537 658
      typedef SubMapExtender<Adaptor, typename Parent::
538 659
                             template ArcMap<Value> > MapParent;
539
    
540
      ArcMap(const Adaptor& adaptor) 
541
	: MapParent(adaptor) {}
542
      ArcMap(const Adaptor& adaptor, const Value& value) 
543
	: MapParent(adaptor, value) {}
544
    
660

	
661
      ArcMap(const Adaptor& adaptor)
662
        : MapParent(adaptor) {}
663
      ArcMap(const Adaptor& adaptor, const Value& value)
664
        : MapParent(adaptor, value) {}
665

	
545 666
    private:
546 667
      ArcMap& operator=(const ArcMap& cmap) {
547
	return operator=<ArcMap>(cmap);
668
        return operator=<ArcMap>(cmap);
548 669
      }
549
    
670

	
550 671
      template <typename CMap>
551 672
      ArcMap& operator=(const CMap& cmap) {
552 673
        MapParent::operator=(cmap);
553
	return *this;
674
        return *this;
554 675
      }
555 676
    };
556 677

	
557 678
  };
558 679

	
559 680
  /// \ingroup graph_adaptors
560 681
  ///
561
  /// \brief A digraph adaptor for hiding nodes and arcs from a digraph.
562
  /// 
563
  /// SubDigraphAdaptor shows the digraph with filtered node-set and 
564
  /// arc-set. If the \c checked parameter is true then it filters the arc-set
565
  /// respect to the source and target.
566
  /// 
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.
572
  ///\code
573
  /// typedef ListDigraph Digraph;
574
  /// DIGRAPH_TYPEDEFS(Digraph);
575
  /// Digraph g;
576
  /// Node u=g.addNode(); //node of id 0
577
  /// Node v=g.addNode(); //node of id 1
578
  /// Arc a=g.addArc(u, v); //arc of id 0
579
  /// Arc f=g.addArc(v, u); //arc of id 1
580
  /// BoolNodeMap nm(g, true);
581
  /// nm.set(u, false);
582
  /// BoolArcMap am(g, true);
583
  /// am.set(a, false);
584
  /// typedef SubDigraphAdaptor<Digraph, BoolNodeMap, BoolArcMap> SubDGA;
585
  /// SubDGA ga(g, nm, am);
586
  /// for (SubDGA::NodeIt n(ga); n!=INVALID; ++n)
587
  ///   std::cout << g.id(n) << std::endl;
588
  /// for (SubDGA::ArcIt a(ga); a!=INVALID; ++a) 
589
  ///   std::cout << g.id(a) << std::endl;
590
  ///\endcode
591
  /// The output of the above code is the following.
592
  ///\code
593
  /// 1
594
  /// 1
595
  ///\endcode
596
  /// Note that \c n is of type \c SubDGA::NodeIt, but it can be converted to
597
  /// \c Digraph::Node that is why \c g.id(n) can be applied.
598
  /// 
599
  /// For other examples see also the documentation of
600
  /// NodeSubDigraphAdaptor and ArcSubDigraphAdaptor.
601
  template<typename _Digraph, 
602
	   typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>, 
603
	   typename _ArcFilterMap = typename _Digraph::template ArcMap<bool>, 
604
	   bool checked = true>
605
  class SubDigraphAdaptor : 
606
    public DigraphAdaptorExtender<
607
    SubDigraphAdaptorBase<_Digraph, _NodeFilterMap, _ArcFilterMap, checked> > {
682
  /// \brief An adaptor for hiding nodes and arcs in a digraph
683
  ///
684
  /// SubDigraph hides nodes and arcs in a digraph. A bool node map
685
  /// and a bool arc map must be specified, which define the filters
686
  /// for nodes and arcs. Just the nodes and arcs with true value are
687
  /// shown in the subdigraph. The SubDigraph is conform to the \ref
688
  /// concepts::Digraph "Digraph concept". If the \c _checked parameter
689
  /// is true, then the arcs incident to filtered nodes are also
690
  /// filtered out.
691
  ///
692
  /// \tparam _Digraph It must be conform to the \ref
693
  /// concepts::Digraph "Digraph concept". The type can be specified
694
  /// to const.
695
  /// \tparam _NodeFilterMap A bool valued node map of the the adapted digraph.
696
  /// \tparam _ArcFilterMap A bool valued arc map of the the adapted digraph.
697
  /// \tparam _checked If the parameter is false then the arc filtering
698
  /// is not checked with respect to node filter. Otherwise, each arc
699
  /// is automatically filtered, which is incident to a filtered node.
700
  ///
701
  /// \see FilterNodes
702
  /// \see FilterArcs
703
  template<typename _Digraph,
704
           typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
705
           typename _ArcFilterMap = typename _Digraph::template ArcMap<bool>,
706
           bool _checked = true>
707
  class SubDigraph
708
    : public DigraphAdaptorExtender<
709
      SubDigraphBase<_Digraph, _NodeFilterMap, _ArcFilterMap, _checked> > {
608 710
  public:
609 711
    typedef _Digraph Digraph;
610 712
    typedef _NodeFilterMap NodeFilterMap;
611 713
    typedef _ArcFilterMap ArcFilterMap;
612 714

	
613 715
    typedef DigraphAdaptorExtender<
614
      SubDigraphAdaptorBase<Digraph, NodeFilterMap, ArcFilterMap, checked> >
716
      SubDigraphBase<Digraph, NodeFilterMap, ArcFilterMap, _checked> >
615 717
    Parent;
616 718

	
617 719
    typedef typename Parent::Node Node;
618 720
    typedef typename Parent::Arc Arc;
619 721

	
620 722
  protected:
621
    SubDigraphAdaptor() { }
723
    SubDigraph() { }
622 724
  public:
623 725

	
624 726
    /// \brief Constructor
625 727
    ///
626
    /// Creates a sub-digraph-adaptor for the given digraph with
728
    /// Creates a subdigraph for the given digraph with
627 729
    /// given node and arc map filters.
628
    SubDigraphAdaptor(Digraph& digraph, NodeFilterMap& node_filter, 
629
		      ArcFilterMap& arc_filter) { 
730
    SubDigraph(Digraph& digraph, NodeFilterMap& node_filter,
731
               ArcFilterMap& arc_filter) {
630 732
      setDigraph(digraph);
631 733
      setNodeFilterMap(node_filter);
632 734
      setArcFilterMap(arc_filter);
633 735
    }
634 736

	
635 737
    /// \brief Hides the node of the graph
636 738
    ///
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  
739
    /// This function hides \c n in the digraph, i.e. the iteration
740
    /// jumps over it. This is done by simply setting the value of \c n
639 741
    /// to be false in the corresponding node-map.
640 742
    void hide(const Node& n) const { Parent::hide(n); }
641 743

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

	
649 751
    /// \brief Unhides the node of the graph
650 752
    ///
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 
753
    /// The value of \c n is set to be true in the node-map which stores
754
    /// hide information. If \c n was hidden previuosly, then it is shown
653 755
    /// again
654 756
    void unHide(const Node& n) const { Parent::unHide(n); }
655 757

	
656 758
    /// \brief Unhides the arc of the graph
657 759
    ///
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 
760
    /// The value of \c a is set to be true in the arc-map which stores
761
    /// hide information. If \c a was hidden previuosly, then it is shown
660 762
    /// again
661 763
    void unHide(const Arc& a) const { Parent::unHide(a); }
662 764

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

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

	
675 777
  };
676 778

	
677
  /// \brief Just gives back a sub-digraph-adaptor
779
  /// \brief Just gives back a subdigraph
678 780
  ///
679
  /// Just gives back a sub-digraph-adaptor
781
  /// Just gives back a subdigraph
680 782
  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
681
  SubDigraphAdaptor<const Digraph, NodeFilterMap, ArcFilterMap>
682
  subDigraphAdaptor(const Digraph& digraph, 
683
		    NodeFilterMap& nfm, ArcFilterMap& afm) {
684
    return SubDigraphAdaptor<const Digraph, NodeFilterMap, ArcFilterMap>
783
  SubDigraph<const Digraph, NodeFilterMap, ArcFilterMap>
784
  subDigraph(const Digraph& digraph, NodeFilterMap& nfm, ArcFilterMap& afm) {
785
    return SubDigraph<const Digraph, NodeFilterMap, ArcFilterMap>
685 786
      (digraph, nfm, afm);
686 787
  }
687 788

	
688 789
  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
689
  SubDigraphAdaptor<const Digraph, const NodeFilterMap, ArcFilterMap>
690
  subDigraphAdaptor(const Digraph& digraph, 
691
                   NodeFilterMap& nfm, ArcFilterMap& afm) {
692
    return SubDigraphAdaptor<const Digraph, const NodeFilterMap, ArcFilterMap>
790
  SubDigraph<const Digraph, const NodeFilterMap, ArcFilterMap>
791
  subDigraph(const Digraph& digraph,
792
             const NodeFilterMap& nfm, ArcFilterMap& afm) {
793
    return SubDigraph<const Digraph, const NodeFilterMap, ArcFilterMap>
693 794
      (digraph, nfm, afm);
694 795
  }
695 796

	
696 797
  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
697
  SubDigraphAdaptor<const Digraph, NodeFilterMap, const ArcFilterMap>
698
  subDigraphAdaptor(const Digraph& digraph, 
699
                   NodeFilterMap& nfm, ArcFilterMap& afm) {
700
    return SubDigraphAdaptor<const Digraph, NodeFilterMap, const ArcFilterMap>
798
  SubDigraph<const Digraph, NodeFilterMap, const ArcFilterMap>
799
  subDigraph(const Digraph& digraph,
800
             NodeFilterMap& nfm, const ArcFilterMap& afm) {
801
    return SubDigraph<const Digraph, NodeFilterMap, const ArcFilterMap>
701 802
      (digraph, nfm, afm);
702 803
  }
703 804

	
704 805
  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
705
  SubDigraphAdaptor<const Digraph, const NodeFilterMap, const ArcFilterMap>
706
  subDigraphAdaptor(const Digraph& digraph, 
707
                   NodeFilterMap& nfm, ArcFilterMap& afm) {
708
    return SubDigraphAdaptor<const Digraph, const NodeFilterMap, 
806
  SubDigraph<const Digraph, const NodeFilterMap, const ArcFilterMap>
807
  subDigraph(const Digraph& digraph,
808
             const NodeFilterMap& nfm, const ArcFilterMap& afm) {
809
    return SubDigraph<const Digraph, const NodeFilterMap,
709 810
      const ArcFilterMap>(digraph, nfm, afm);
710

	
711 811
  }
712 812

	
713 813

	
714

	
715
  ///\ingroup graph_adaptors
814
  template <typename _Graph, typename NodeFilterMap,
815
            typename EdgeFilterMap, bool _checked = true>
816
  class SubGraphBase : public GraphAdaptorBase<_Graph> {
817
  public:
818
    typedef _Graph Graph;
819
    typedef SubGraphBase Adaptor;
820
    typedef GraphAdaptorBase<_Graph> Parent;
821
  protected:
822

	
823
    NodeFilterMap* _node_filter_map;
824
    EdgeFilterMap* _edge_filter_map;
825

	
826
    SubGraphBase()
827
      : Parent(), _node_filter_map(0), _edge_filter_map(0) { }
828

	
829
    void setNodeFilterMap(NodeFilterMap& node_filter_map) {
830
      _node_filter_map=&node_filter_map;
831
    }
832
    void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
833
      _edge_filter_map=&edge_filter_map;
834
    }
835

	
836
  public:
837

	
838
    typedef typename Parent::Node Node;
839
    typedef typename Parent::Arc Arc;
840
    typedef typename Parent::Edge Edge;
841

	
842
    void first(Node& i) const {
843
      Parent::first(i);
844
      while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
845
    }
846

	
847
    void first(Arc& i) const {
848
      Parent::first(i);
849
      while (i!=INVALID && (!(*_edge_filter_map)[i]
850
                            || !(*_node_filter_map)[Parent::source(i)]
851
                            || !(*_node_filter_map)[Parent::target(i)]))
852
        Parent::next(i);
853
    }
854

	
855
    void first(Edge& i) const {
856
      Parent::first(i);
857
      while (i!=INVALID && (!(*_edge_filter_map)[i]
858
                            || !(*_node_filter_map)[Parent::u(i)]
859
                            || !(*_node_filter_map)[Parent::v(i)]))
860
        Parent::next(i);
861
    }
862

	
863
    void firstIn(Arc& i, const Node& n) const {
864
      Parent::firstIn(i, n);
865
      while (i!=INVALID && (!(*_edge_filter_map)[i]
866
                            || !(*_node_filter_map)[Parent::source(i)]))
867
        Parent::nextIn(i);
868
    }
869

	
870
    void firstOut(Arc& i, const Node& n) const {
871
      Parent::firstOut(i, n);
872
      while (i!=INVALID && (!(*_edge_filter_map)[i]
873
                            || !(*_node_filter_map)[Parent::target(i)]))
874
        Parent::nextOut(i);
875
    }
876

	
877
    void firstInc(Edge& i, bool& d, const Node& n) const {
878
      Parent::firstInc(i, d, n);
879
      while (i!=INVALID && (!(*_edge_filter_map)[i]
880
                            || !(*_node_filter_map)[Parent::u(i)]
881
                            || !(*_node_filter_map)[Parent::v(i)]))
882
        Parent::nextInc(i, d);
883
    }
884

	
885
    void next(Node& i) const {
886
      Parent::next(i);
887
      while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
888
    }
889

	
890
    void next(Arc& i) const {
891
      Parent::next(i);
892
      while (i!=INVALID && (!(*_edge_filter_map)[i]
893
                            || !(*_node_filter_map)[Parent::source(i)]
894
                            || !(*_node_filter_map)[Parent::target(i)]))
895
        Parent::next(i);
896
    }
897

	
898
    void next(Edge& i) const {
899
      Parent::next(i);
900
      while (i!=INVALID && (!(*_edge_filter_map)[i]
901
                            || !(*_node_filter_map)[Parent::u(i)]
902
                            || !(*_node_filter_map)[Parent::v(i)]))
903
        Parent::next(i);
904
    }
905

	
906
    void nextIn(Arc& i) const {
907
      Parent::nextIn(i);
908
      while (i!=INVALID && (!(*_edge_filter_map)[i]
909
                            || !(*_node_filter_map)[Parent::source(i)]))
910
        Parent::nextIn(i);
911
    }
912

	
913
    void nextOut(Arc& i) const {
914
      Parent::nextOut(i);
915
      while (i!=INVALID && (!(*_edge_filter_map)[i]
916
                            || !(*_node_filter_map)[Parent::target(i)]))
917
        Parent::nextOut(i);
918
    }
919

	
920
    void nextInc(Edge& i, bool& d) const {
921
      Parent::nextInc(i, d);
922
      while (i!=INVALID && (!(*_edge_filter_map)[i]
923
                            || !(*_node_filter_map)[Parent::u(i)]
924
                            || !(*_node_filter_map)[Parent::v(i)]))
925
        Parent::nextInc(i, d);
926
    }
927

	
928
    void hide(const Node& n) const { _node_filter_map->set(n, false); }
929
    void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
930

	
931
    void unHide(const Node& n) const { _node_filter_map->set(n, true); }
932
    void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
933

	
934
    bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; }
935
    bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
936

	
937
    typedef False NodeNumTag;
938
    typedef False EdgeNumTag;
939

	
940
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
941
    Arc findArc(const Node& u, const Node& v,
942
                const Arc& prev = INVALID) {
943
      if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
944
        return INVALID;
945
      }
946
      Arc arc = Parent::findArc(u, v, prev);
947
      while (arc != INVALID && !(*_edge_filter_map)[arc]) {
948
        arc = Parent::findArc(u, v, arc);
949
      }
950
      return arc;
951
    }
952
    Edge findEdge(const Node& u, const Node& v,
953
                  const Edge& prev = INVALID) {
954
      if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
955
        return INVALID;
956
      }
957
      Edge edge = Parent::findEdge(u, v, prev);
958
      while (edge != INVALID && !(*_edge_filter_map)[edge]) {
959
        edge = Parent::findEdge(u, v, edge);
960
      }
961
      return edge;
962
    }
963

	
964
    template <typename _Value>
965
    class NodeMap : public SubMapExtender<Adaptor,
966
      typename Parent::template NodeMap<_Value> > {
967
    public:
968
      typedef _Value Value;
969
      typedef SubMapExtender<Adaptor, typename Parent::
970
                             template NodeMap<Value> > MapParent;
971

	
972
      NodeMap(const Adaptor& adaptor)
973
        : MapParent(adaptor) {}
974
      NodeMap(const Adaptor& adaptor, const Value& value)
975
        : MapParent(adaptor, value) {}
976

	
977
    private:
978
      NodeMap& operator=(const NodeMap& cmap) {
979
        return operator=<NodeMap>(cmap);
980
      }
981

	
982
      template <typename CMap>
983
      NodeMap& operator=(const CMap& cmap) {
984
        MapParent::operator=(cmap);
985
        return *this;
986
      }
987
    };
988

	
989
    template <typename _Value>
990
    class ArcMap : public SubMapExtender<Adaptor,
991
      typename Parent::template ArcMap<_Value> > {
992
    public:
993
      typedef _Value Value;
994
      typedef SubMapExtender<Adaptor, typename Parent::
995
                             template ArcMap<Value> > MapParent;
996

	
997
      ArcMap(const Adaptor& adaptor)
998
        : MapParent(adaptor) {}
999
      ArcMap(const Adaptor& adaptor, const Value& value)
1000
        : MapParent(adaptor, value) {}
1001

	
1002
    private:
1003
      ArcMap& operator=(const ArcMap& cmap) {
1004
        return operator=<ArcMap>(cmap);
1005
      }
1006

	
1007
      template <typename CMap>
1008
      ArcMap& operator=(const CMap& cmap) {
1009
        MapParent::operator=(cmap);
1010
        return *this;
1011
      }
1012
    };
1013

	
1014
    template <typename _Value>
1015
    class EdgeMap : public SubMapExtender<Adaptor,
1016
      typename Parent::template EdgeMap<_Value> > {
1017
    public:
1018
      typedef _Value Value;
1019
      typedef SubMapExtender<Adaptor, typename Parent::
1020
                             template EdgeMap<Value> > MapParent;
1021

	
1022
      EdgeMap(const Adaptor& adaptor)
1023
        : MapParent(adaptor) {}
1024

	
1025
      EdgeMap(const Adaptor& adaptor, const Value& value)
1026
        : MapParent(adaptor, value) {}
1027

	
1028
    private:
1029
      EdgeMap& operator=(const EdgeMap& cmap) {
1030
        return operator=<EdgeMap>(cmap);
1031
      }
1032

	
1033
      template <typename CMap>
1034
      EdgeMap& operator=(const CMap& cmap) {
1035
        MapParent::operator=(cmap);
1036
        return *this;
1037
      }
1038
    };
1039

	
1040
  };
1041

	
1042
  template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
1043
  class SubGraphBase<_Graph, NodeFilterMap, EdgeFilterMap, false>
1044
    : public GraphAdaptorBase<_Graph> {
1045
  public:
1046
    typedef _Graph Graph;
1047
    typedef SubGraphBase Adaptor;
1048
    typedef GraphAdaptorBase<_Graph> Parent;
1049
  protected:
1050
    NodeFilterMap* _node_filter_map;
1051
    EdgeFilterMap* _edge_filter_map;
1052
    SubGraphBase() : Parent(),
1053
                     _node_filter_map(0), _edge_filter_map(0) { }
1054

	
1055
    void setNodeFilterMap(NodeFilterMap& node_filter_map) {
1056
      _node_filter_map=&node_filter_map;
1057
    }
1058
    void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
1059
      _edge_filter_map=&edge_filter_map;
1060
    }
1061

	
1062
  public:
1063

	
1064
    typedef typename Parent::Node Node;
1065
    typedef typename Parent::Arc Arc;
1066
    typedef typename Parent::Edge Edge;
1067

	
1068
    void first(Node& i) const {
1069
      Parent::first(i);
1070
      while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
1071
    }
1072

	
1073
    void first(Arc& i) const {
1074
      Parent::first(i);
1075
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
1076
    }
1077

	
1078
    void first(Edge& i) const {
1079
      Parent::first(i);
1080
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
1081
    }
1082

	
1083
    void firstIn(Arc& i, const Node& n) const {
1084
      Parent::firstIn(i, n);
1085
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i);
1086
    }
1087

	
1088
    void firstOut(Arc& i, const Node& n) const {
1089
      Parent::firstOut(i, n);
1090
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i);
1091
    }
1092

	
1093
    void firstInc(Edge& i, bool& d, const Node& n) const {
1094
      Parent::firstInc(i, d, n);
1095
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d);
1096
    }
1097

	
1098
    void next(Node& i) const {
1099
      Parent::next(i);
1100
      while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i);
1101
    }
1102
    void next(Arc& i) const {
1103
      Parent::next(i);
1104
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
1105
    }
1106
    void next(Edge& i) const {
1107
      Parent::next(i);
1108
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i);
1109
    }
1110
    void nextIn(Arc& i) const {
1111
      Parent::nextIn(i);
1112
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i);
1113
    }
1114

	
1115
    void nextOut(Arc& i) const {
1116
      Parent::nextOut(i);
1117
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i);
1118
    }
1119
    void nextInc(Edge& i, bool& d) const {
1120
      Parent::nextInc(i, d);
1121
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d);
1122
    }
1123

	
1124
    void hide(const Node& n) const { _node_filter_map->set(n, false); }
1125
    void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
1126

	
1127
    void unHide(const Node& n) const { _node_filter_map->set(n, true); }
1128
    void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
1129

	
1130
    bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; }
1131
    bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
1132

	
1133
    typedef False NodeNumTag;
1134
    typedef False EdgeNumTag;
1135

	
1136
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
1137
    Arc findArc(const Node& u, const Node& v,
1138
                const Arc& prev = INVALID) {
1139
      Arc arc = Parent::findArc(u, v, prev);
1140
      while (arc != INVALID && !(*_edge_filter_map)[arc]) {
1141
        arc = Parent::findArc(u, v, arc);
1142
      }
1143
      return arc;
1144
    }
1145
    Edge findEdge(const Node& u, const Node& v,
1146
                  const Edge& prev = INVALID) {
1147
      Edge edge = Parent::findEdge(u, v, prev);
1148
      while (edge != INVALID && !(*_edge_filter_map)[edge]) {
1149
        edge = Parent::findEdge(u, v, edge);
1150
      }
1151
      return edge;
1152
    }
1153

	
1154
    template <typename _Value>
1155
    class NodeMap : public SubMapExtender<Adaptor,
1156
      typename Parent::template NodeMap<_Value> > {
1157
    public:
1158
      typedef _Value Value;
1159
      typedef SubMapExtender<Adaptor, typename Parent::
1160
                             template NodeMap<Value> > MapParent;
1161

	
1162
      NodeMap(const Adaptor& adaptor)
1163
        : MapParent(adaptor) {}
1164
      NodeMap(const Adaptor& adaptor, const Value& value)
1165
        : MapParent(adaptor, value) {}
1166

	
1167
    private:
1168
      NodeMap& operator=(const NodeMap& cmap) {
1169
        return operator=<NodeMap>(cmap);
1170
      }
1171

	
1172
      template <typename CMap>
1173
      NodeMap& operator=(const CMap& cmap) {
1174
        MapParent::operator=(cmap);
1175
        return *this;
1176
      }
1177
    };
1178

	
1179
    template <typename _Value>
1180
    class ArcMap : public SubMapExtender<Adaptor,
1181
      typename Parent::template ArcMap<_Value> > {
1182
    public:
1183
      typedef _Value Value;
1184
      typedef SubMapExtender<Adaptor, typename Parent::
1185
                             template ArcMap<Value> > MapParent;
1186

	
1187
      ArcMap(const Adaptor& adaptor)
1188
        : MapParent(adaptor) {}
1189
      ArcMap(const Adaptor& adaptor, const Value& value)
1190
        : MapParent(adaptor, value) {}
1191

	
1192
    private:
1193
      ArcMap& operator=(const ArcMap& cmap) {
1194
        return operator=<ArcMap>(cmap);
1195
      }
1196

	
1197
      template <typename CMap>
1198
      ArcMap& operator=(const CMap& cmap) {
1199
        MapParent::operator=(cmap);
1200
        return *this;
1201
      }
1202
    };
1203

	
1204
    template <typename _Value>
1205
    class EdgeMap : public SubMapExtender<Adaptor,
1206
      typename Parent::template EdgeMap<_Value> > {
1207
    public:
1208
      typedef _Value Value;
1209
      typedef SubMapExtender<Adaptor, typename Parent::
1210
                             template EdgeMap<Value> > MapParent;
1211

	
1212
      EdgeMap(const Adaptor& adaptor)
1213
        : MapParent(adaptor) {}
1214

	
1215
      EdgeMap(const Adaptor& adaptor, const _Value& value)
1216
        : MapParent(adaptor, value) {}
1217

	
1218
    private:
1219
      EdgeMap& operator=(const EdgeMap& cmap) {
1220
        return operator=<EdgeMap>(cmap);
1221
      }
1222

	
1223
      template <typename CMap>
1224
      EdgeMap& operator=(const CMap& cmap) {
1225
        MapParent::operator=(cmap);
1226
        return *this;
1227
      }
1228
    };
1229

	
1230
  };
1231

	
1232
  /// \ingroup graph_adaptors
716 1233
  ///
717
  ///\brief An adaptor for hiding nodes from a digraph.
1234
  /// \brief A graph adaptor for hiding nodes and edges in an
1235
  /// undirected graph.
718 1236
  ///
719
  ///An adaptor for hiding nodes from a digraph.  This adaptor
720
  ///specializes SubDigraphAdaptor in the way that only the node-set
721
  ///can be filtered. In usual case the checked parameter is true, we
722
  ///get the induced subgraph. But if the checked parameter is false
723
  ///then we can filter only isolated nodes.
724
  template<typename _Digraph, 
725
	   typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>, 
726
	   bool checked = true>
727
  class NodeSubDigraphAdaptor : 
728
    public SubDigraphAdaptor<_Digraph, _NodeFilterMap, 
729
			     ConstMap<typename _Digraph::Arc, bool>, checked> {
1237
  /// SubGraph hides nodes and edges in a graph. A bool node map and a
1238
  /// bool edge map must be specified, which define the filters for
1239
  /// nodes and edges. Just the nodes and edges with true value are
1240
  /// shown in the subgraph. The SubGraph is conform to the \ref
1241
  /// concepts::Graph "Graph concept". If the \c _checked parameter is
1242
  /// true, then the edges incident to filtered nodes are also
1243
  /// filtered out.
1244
  ///
1245
  /// \tparam _Graph It must be conform to the \ref
1246
  /// concepts::Graph "Graph concept". The type can be specified
1247
  /// to const.
1248
  /// \tparam _NodeFilterMap A bool valued node map of the the adapted graph.
1249
  /// \tparam _EdgeFilterMap A bool valued edge map of the the adapted graph.
1250
  /// \tparam _checked If the parameter is false then the edge filtering
1251
  /// is not checked with respect to node filter. Otherwise, each edge
1252
  /// is automatically filtered, which is incident to a filtered node.
1253
  ///
1254
  /// \see FilterNodes
1255
  /// \see FilterEdges
1256
  template<typename _Graph, typename NodeFilterMap,
1257
           typename EdgeFilterMap, bool _checked = true>
1258
  class SubGraph
1259
    : public GraphAdaptorExtender<
1260
      SubGraphBase<_Graph, NodeFilterMap, EdgeFilterMap, _checked> > {
730 1261
  public:
731

	
732
    typedef _Digraph Digraph;
733
    typedef _NodeFilterMap NodeFilterMap;
734

	
735
    typedef SubDigraphAdaptor<Digraph, NodeFilterMap, 
736
			      ConstMap<typename Digraph::Arc, bool>, checked> 
737
    Parent;
1262
    typedef _Graph Graph;
1263
    typedef GraphAdaptorExtender<
1264
      SubGraphBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent;
738 1265

	
739 1266
    typedef typename Parent::Node Node;
1267
    typedef typename Parent::Edge Edge;
740 1268

	
741 1269
  protected:
742
    ConstMap<typename Digraph::Arc, bool> const_true_map;
743

	
744
    NodeSubDigraphAdaptor() : const_true_map(true) {
745
      Parent::setArcFilterMap(const_true_map);
746
    }
747

	
1270
    SubGraph() { }
748 1271
  public:
749 1272

	
750 1273
    /// \brief Constructor
751 1274
    ///
752
    /// Creates a node-sub-digraph-adaptor for the given digraph with
753
    /// given node map filter.
754
    NodeSubDigraphAdaptor(Digraph& _digraph, NodeFilterMap& node_filter) : 
755
      Parent(), const_true_map(true) { 
756
      Parent::setDigraph(_digraph);
757
      Parent::setNodeFilterMap(node_filter);
758
      Parent::setArcFilterMap(const_true_map);
1275
    /// Creates a subgraph for the given graph with given node and
1276
    /// edge map filters.
1277
    SubGraph(Graph& _graph, NodeFilterMap& node_filter_map,
1278
             EdgeFilterMap& edge_filter_map) {
1279
      setGraph(_graph);
1280
      setNodeFilterMap(node_filter_map);
1281
      setEdgeFilterMap(edge_filter_map);
759 1282
    }
760 1283

	
761 1284
    /// \brief Hides the node of the graph
762 1285
    ///
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  
1286
    /// This function hides \c n in the graph, i.e. the iteration
1287
    /// jumps over it. This is done by simply setting the value of \c n
765 1288
    /// to be false in the corresponding node-map.
766 1289
    void hide(const Node& n) const { Parent::hide(n); }
767 1290

	
1291
    /// \brief Hides the edge of the graph
1292
    ///
1293
    /// This function hides \c e in the graph, i.e. the iteration
1294
    /// jumps over it. This is done by simply setting the value of \c e
1295
    /// to be false in the corresponding edge-map.
1296
    void hide(const Edge& e) const { Parent::hide(e); }
1297

	
768 1298
    /// \brief Unhides the node of the graph
769 1299
    ///
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 
1300
    /// The value of \c n is set to be true in the node-map which stores
1301
    /// hide information. If \c n was hidden previuosly, then it is shown
772 1302
    /// again
773 1303
    void unHide(const Node& n) const { Parent::unHide(n); }
774 1304

	
1305
    /// \brief Unhides the edge of the graph
1306
    ///
1307
    /// The value of \c e is set to be true in the edge-map which stores
1308
    /// hide information. If \c e was hidden previuosly, then it is shown
1309
    /// again
1310
    void unHide(const Edge& e) const { Parent::unHide(e); }
1311

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

	
1318
    /// \brief Returns true if \c e is hidden.
1319
    ///
1320
    /// Returns true if \c e is hidden.
1321
    ///
1322
    bool hidden(const Edge& e) const { return Parent::hidden(e); }
781 1323
  };
782 1324

	
783

	
784
  /// \brief Just gives back a  node-sub-digraph adaptor
1325
  /// \brief Just gives back a subgraph
785 1326
  ///
786
  /// Just gives back a node-sub-digraph adaptor
1327
  /// Just gives back a subgraph
1328
  template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
1329
  SubGraph<const Graph, NodeFilterMap, ArcFilterMap>
1330
  subGraph(const Graph& graph, NodeFilterMap& nfm, ArcFilterMap& efm) {
1331
    return SubGraph<const Graph, NodeFilterMap, ArcFilterMap>(graph, nfm, efm);
1332
  }
1333

	
1334
  template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
1335
  SubGraph<const Graph, const NodeFilterMap, ArcFilterMap>
1336
  subGraph(const Graph& graph,
1337
           const NodeFilterMap& nfm, ArcFilterMap& efm) {
1338
    return SubGraph<const Graph, const NodeFilterMap, ArcFilterMap>
1339
      (graph, nfm, efm);
1340
  }
1341

	
1342
  template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
1343
  SubGraph<const Graph, NodeFilterMap, const ArcFilterMap>
1344
  subGraph(const Graph& graph,
1345
           NodeFilterMap& nfm, const ArcFilterMap& efm) {
1346
    return SubGraph<const Graph, NodeFilterMap, const ArcFilterMap>
1347
      (graph, nfm, efm);
1348
  }
1349

	
1350
  template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
1351
  SubGraph<const Graph, const NodeFilterMap, const ArcFilterMap>
1352
  subGraph(const Graph& graph,
1353
           const NodeFilterMap& nfm, const ArcFilterMap& efm) {
1354
    return SubGraph<const Graph, const NodeFilterMap, const ArcFilterMap>
1355
      (graph, nfm, efm);
1356
  }
1357

	
1358
  /// \ingroup graph_adaptors
1359
  ///
1360
  /// \brief An adaptor for hiding nodes from a digraph or a graph.
1361
  ///
1362
  /// FilterNodes adaptor hides nodes in a graph or a digraph. A bool
1363
  /// node map must be specified, which defines the filters for
1364
  /// nodes. Just the unfiltered nodes and the arcs or edges incident
1365
  /// to unfiltered nodes are shown in the subdigraph or subgraph. The
1366
  /// FilterNodes is conform to the \ref concepts::Digraph
1367
  /// "Digraph concept" or \ref concepts::Graph "Graph concept" depending
1368
  /// on the \c _Digraph template parameter. If the \c _checked
1369
  /// parameter is true, then the arc or edges incident to filtered nodes
1370
  /// are also filtered out.
1371
  ///
1372
  /// \tparam _Digraph It must be conform to the \ref
1373
  /// concepts::Digraph "Digraph concept" or \ref concepts::Graph
1374
  /// "Graph concept". The type can be specified to be const.
1375
  /// \tparam _NodeFilterMap A bool valued node map of the the adapted graph.
1376
  /// \tparam _checked If the parameter is false then the arc or edge
1377
  /// filtering is not checked with respect to node filter. In this
1378
  /// case just isolated nodes can be filtered out from the
1379
  /// graph.
1380
#ifdef DOXYGEN
1381
  template<typename _Digraph,
1382
           typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
1383
           bool _checked = true>
1384
#else
1385
  template<typename _Digraph,
1386
           typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
1387
           bool _checked = true,
1388
           typename Enable = void>
1389
#endif
1390
  class FilterNodes
1391
    : public SubDigraph<_Digraph, _NodeFilterMap,
1392
                        ConstMap<typename _Digraph::Arc, bool>, _checked> {
1393
  public:
1394

	
1395
    typedef _Digraph Digraph;
1396
    typedef _NodeFilterMap NodeFilterMap;
1397

	
1398
    typedef SubDigraph<Digraph, NodeFilterMap,
1399
                       ConstMap<typename Digraph::Arc, bool>, _checked>
1400
    Parent;
1401

	
1402
    typedef typename Parent::Node Node;
1403

	
1404
  protected:
1405
    ConstMap<typename Digraph::Arc, bool> const_true_map;
1406

	
1407
    FilterNodes() : const_true_map(true) {
1408
      Parent::setArcFilterMap(const_true_map);
1409
    }
1410

	
1411
  public:
1412

	
1413
    /// \brief Constructor
1414
    ///
1415
    /// Creates an adaptor for the given digraph or graph with
1416
    /// given node filter map.
1417
    FilterNodes(Digraph& _digraph, NodeFilterMap& node_filter) :
1418
      Parent(), const_true_map(true) {
1419
      Parent::setDigraph(_digraph);
1420
      Parent::setNodeFilterMap(node_filter);
1421
      Parent::setArcFilterMap(const_true_map);
1422
    }
1423

	
1424
    /// \brief Hides the node of the graph
1425
    ///
1426
    /// This function hides \c n in the digraph or graph, i.e. the iteration
1427
    /// jumps over it. This is done by simply setting the value of \c n
1428
    /// to be false in the corresponding node map.
1429
    void hide(const Node& n) const { Parent::hide(n); }
1430

	
1431
    /// \brief Unhides the node of the graph
1432
    ///
1433
    /// The value of \c n is set to be true in the node-map which stores
1434
    /// hide information. If \c n was hidden previuosly, then it is shown
1435
    /// again
1436
    void unHide(const Node& n) const { Parent::unHide(n); }
1437

	
1438
    /// \brief Returns true if \c n is hidden.
1439
    ///
1440
    /// Returns true if \c n is hidden.
1441
    ///
1442
    bool hidden(const Node& n) const { return Parent::hidden(n); }
1443

	
1444
  };
1445

	
1446
  template<typename _Graph, typename _NodeFilterMap, bool _checked>
1447
  class FilterNodes<_Graph, _NodeFilterMap, _checked,
1448
                    typename enable_if<UndirectedTagIndicator<_Graph> >::type>
1449
    : public SubGraph<_Graph, _NodeFilterMap,
1450
                      ConstMap<typename _Graph::Edge, bool>, _checked> {
1451
  public:
1452
    typedef _Graph Graph;
1453
    typedef _NodeFilterMap NodeFilterMap;
1454
    typedef SubGraph<Graph, NodeFilterMap,
1455
                     ConstMap<typename Graph::Edge, bool> > Parent;
1456

	
1457
    typedef typename Parent::Node Node;
1458
  protected:
1459
    ConstMap<typename Graph::Edge, bool> const_true_map;
1460

	
1461
    FilterNodes() : const_true_map(true) {
1462
      Parent::setEdgeFilterMap(const_true_map);
1463
    }
1464

	
1465
  public:
1466

	
1467
    FilterNodes(Graph& _graph, NodeFilterMap& node_filter_map) :
1468
      Parent(), const_true_map(true) {
1469
      Parent::setGraph(_graph);
1470
      Parent::setNodeFilterMap(node_filter_map);
1471
      Parent::setEdgeFilterMap(const_true_map);
1472
    }
1473

	
1474
    void hide(const Node& n) const { Parent::hide(n); }
1475
    void unHide(const Node& n) const { Parent::unHide(n); }
1476
    bool hidden(const Node& n) const { return Parent::hidden(n); }
1477

	
1478
  };
1479

	
1480

	
1481
  /// \brief Just gives back a FilterNodes adaptor
1482
  ///
1483
  /// Just gives back a FilterNodes adaptor
787 1484
  template<typename Digraph, typename NodeFilterMap>
788
  NodeSubDigraphAdaptor<const Digraph, NodeFilterMap>
789
  nodeSubDigraphAdaptor(const Digraph& digraph, NodeFilterMap& nfm) {
790
    return NodeSubDigraphAdaptor<const Digraph, NodeFilterMap>(digraph, nfm);
1485
  FilterNodes<const Digraph, NodeFilterMap>
1486
  filterNodes(const Digraph& digraph, NodeFilterMap& nfm) {
1487
    return FilterNodes<const Digraph, NodeFilterMap>(digraph, nfm);
791 1488
  }
792 1489

	
793 1490
  template<typename Digraph, typename NodeFilterMap>
794
  NodeSubDigraphAdaptor<const Digraph, const NodeFilterMap>
795
  nodeSubDigraphAdaptor(const Digraph& digraph, const NodeFilterMap& nfm) {
796
    return NodeSubDigraphAdaptor<const Digraph, const NodeFilterMap>
797
      (digraph, nfm);
1491
  FilterNodes<const Digraph, const NodeFilterMap>
1492
  filterNodes(const Digraph& digraph, const NodeFilterMap& nfm) {
1493
    return FilterNodes<const Digraph, const NodeFilterMap>(digraph, nfm);
798 1494
  }
799 1495

	
800
  ///\ingroup graph_adaptors
1496
  /// \ingroup graph_adaptors
801 1497
  ///
802
  ///\brief An adaptor for hiding arcs from a digraph.
1498
  /// \brief An adaptor for hiding arcs from a digraph.
803 1499
  ///
804
  ///An adaptor for hiding arcs from a digraph. This adaptor
805
  ///specializes SubDigraphAdaptor in the way that only the arc-set
806
  ///can be filtered. The usefulness of this adaptor is demonstrated
807
  ///in the problem of searching a maximum number of arc-disjoint
808
  ///shortest paths between two nodes \c s and \c t. Shortest here
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.
1500
  /// FilterArcs adaptor hides arcs in a digraph. A bool arc map must
1501
  /// be specified, which defines the filters for arcs. Just the
1502
  /// unfiltered arcs are shown in the subdigraph. The FilterArcs is
1503
  /// conform to the \ref concepts::Digraph "Digraph concept".
813 1504
  ///
814
  ///If a single shortest path is to be searched between \c s and \c
815
  ///t, then this can be done easily by applying the Dijkstra
816
  ///algorithm. What happens, if a maximum number of arc-disjoint
817
  ///shortest paths is to be computed. It can be proved that an arc
818
  ///can be in a shortest path if and only if it is tight with respect
819
  ///to the potential function computed by Dijkstra.  Moreover, any
820
  ///path containing only such arcs is a shortest one.  Thus we have
821
  ///to compute a maximum number of arc-disjoint paths between \c s
822
  ///and \c t in the digraph which has arc-set all the tight arcs. The
823
  ///computation will be demonstrated on the following digraph, which
824
  ///is read from the dimacs file \c sub_digraph_adaptor_demo.dim.
825
  ///The full source code is available in \ref
826
  ///sub_digraph_adaptor_demo.cc.  If you are interested in more demo
827
  ///programs, you can use \ref dim_to_dot.cc to generate .dot files
828
  ///from dimacs files.  The .dot file of the following figure was
829
  ///generated by the demo program \ref dim_to_dot.cc.
830
  ///
831
  ///\dot
832
  ///digraph lemon_dot_example {
833
  ///node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
834
  ///n0 [ label="0 (s)" ];
835
  ///n1 [ label="1" ];
836
  ///n2 [ label="2" ];
837
  ///n3 [ label="3" ];
838
  ///n4 [ label="4" ];
839
  ///n5 [ label="5" ];
840
  ///n6 [ label="6 (t)" ];
841
  ///arc [ shape=ellipse, fontname=Helvetica, fontsize=10 ];
842
  ///n5 ->  n6 [ label="9, length:4" ];
843
  ///n4 ->  n6 [ label="8, length:2" ];
844
  ///n3 ->  n5 [ label="7, length:1" ];
845
  ///n2 ->  n5 [ label="6, length:3" ];
846
  ///n2 ->  n6 [ label="5, length:5" ];
847
  ///n2 ->  n4 [ label="4, length:2" ];
848
  ///n1 ->  n4 [ label="3, length:3" ];
849
  ///n0 ->  n3 [ label="2, length:1" ];
850
  ///n0 ->  n2 [ label="1, length:2" ];
851
  ///n0 ->  n1 [ label="0, length:3" ];
852
  ///}
853
  ///\enddot
854
  ///
855
  ///\code
856
  ///Digraph g;
857
  ///Node s, t;
858
  ///LengthMap length(g);
859
  ///
860
  ///readDimacs(std::cin, g, length, s, t);
861
  ///
862
  ///cout << "arcs with lengths (of form id, source--length->target): " << endl;
863
  ///for(ArcIt e(g); e!=INVALID; ++e) 
864
  ///  cout << g.id(e) << ", " << g.id(g.source(e)) << "--" 
865
  ///       << length[e] << "->" << g.id(g.target(e)) << endl;
866
  ///
867
  ///cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
868
  ///\endcode
869
  ///Next, the potential function is computed with Dijkstra.
870
  ///\code
871
  ///typedef Dijkstra<Digraph, LengthMap> Dijkstra;
872
  ///Dijkstra dijkstra(g, length);
873
  ///dijkstra.run(s);
874
  ///\endcode
875
  ///Next, we consrtruct a map which filters the arc-set to the tight arcs.
876
  ///\code
877
  ///typedef TightArcFilterMap<Digraph, const Dijkstra::DistMap, LengthMap> 
878
  ///  TightArcFilter;
879
  ///TightArcFilter tight_arc_filter(g, dijkstra.distMap(), length);
880
  ///
881
  ///typedef ArcSubDigraphAdaptor<Digraph, TightArcFilter> SubGA;
882
  ///SubGA ga(g, tight_arc_filter);
883
  ///\endcode
884
  ///Then, the maximum nimber of arc-disjoint \c s-\c t paths are computed 
885
  ///with a max flow algorithm Preflow.
886
  ///\code
887
  ///ConstMap<Arc, int> const_1_map(1);
888
  ///Digraph::ArcMap<int> flow(g, 0);
889
  ///
890
  ///Preflow<SubGA, ConstMap<Arc, int>, Digraph::ArcMap<int> > 
891
  ///  preflow(ga, const_1_map, s, t);
892
  ///preflow.run();
893
  ///\endcode
894
  ///Last, the output is:
895
  ///\code  
896
  ///cout << "maximum number of arc-disjoint shortest path: " 
897
  ///     << preflow.flowValue() << endl;
898
  ///cout << "arcs of the maximum number of arc-disjoint shortest s-t paths: " 
899
  ///     << endl;
900
  ///for(ArcIt e(g); e!=INVALID; ++e) 
901
  ///  if (preflow.flow(e))
902
  ///    cout << " " << g.id(g.source(e)) << "--"
903
  ///         << length[e] << "->" << g.id(g.target(e)) << endl;
904
  ///\endcode
905
  ///The program has the following (expected :-)) output:
906
  ///\code
907
  ///arcs with lengths (of form id, source--length->target):
908
  /// 9, 5--4->6
909
  /// 8, 4--2->6
910
  /// 7, 3--1->5
911
  /// 6, 2--3->5
912
  /// 5, 2--5->6
913
  /// 4, 2--2->4
914
  /// 3, 1--3->4
915
  /// 2, 0--1->3
916
  /// 1, 0--2->2
917
  /// 0, 0--3->1
918
  ///s: 0 t: 6
919
  ///maximum number of arc-disjoint shortest path: 2
920
  ///arcs of the maximum number of arc-disjoint shortest s-t paths:
921
  /// 9, 5--4->6
922
  /// 8, 4--2->6
923
  /// 7, 3--1->5
924
  /// 4, 2--2->4
925
  /// 2, 0--1->3
926
  /// 1, 0--2->2
927
  ///\endcode
1505
  /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
1506
  /// "Digraph concept". The type can be specified to be const.
1507
  /// \tparam _ArcFilterMap A bool valued arc map of the the adapted
1508
  /// graph.
928 1509
  template<typename _Digraph, typename _ArcFilterMap>
929
  class ArcSubDigraphAdaptor : 
930
    public SubDigraphAdaptor<_Digraph, ConstMap<typename _Digraph::Node, bool>, 
931
			     _ArcFilterMap, false> {
1510
  class FilterArcs :
1511
    public SubDigraph<_Digraph, ConstMap<typename _Digraph::Node, bool>,
1512
                      _ArcFilterMap, false> {
932 1513
  public:
933 1514
    typedef _Digraph Digraph;
934 1515
    typedef _ArcFilterMap ArcFilterMap;
935 1516

	
936
    typedef SubDigraphAdaptor<Digraph, ConstMap<typename Digraph::Node, bool>, 
937
			      ArcFilterMap, false> Parent;
1517
    typedef SubDigraph<Digraph, ConstMap<typename Digraph::Node, bool>,
1518
                       ArcFilterMap, false> Parent;
938 1519

	
939 1520
    typedef typename Parent::Arc Arc;
940 1521

	
941 1522
  protected:
942 1523
    ConstMap<typename Digraph::Node, bool> const_true_map;
943 1524

	
944
    ArcSubDigraphAdaptor() : const_true_map(true) {
1525
    FilterArcs() : const_true_map(true) {
945 1526
      Parent::setNodeFilterMap(const_true_map);
946 1527
    }
947 1528

	
948 1529
  public:
949 1530

	
950 1531
    /// \brief Constructor
951 1532
    ///
952
    /// Creates a arc-sub-digraph-adaptor for the given digraph with
1533
    /// Creates a FilterArcs adaptor for the given graph with
953 1534
    /// given arc map filter.
954
    ArcSubDigraphAdaptor(Digraph& digraph, ArcFilterMap& arc_filter) 
955
      : Parent(), const_true_map(true) { 
1535
    FilterArcs(Digraph& digraph, ArcFilterMap& arc_filter)
1536
      : Parent(), const_true_map(true) {
956 1537
      Parent::setDigraph(digraph);
957 1538
      Parent::setNodeFilterMap(const_true_map);
958 1539
      Parent::setArcFilterMap(arc_filter);
959 1540
    }
960 1541

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

	
968 1549
    /// \brief Unhides the arc of the graph
969 1550
    ///
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 
1551
    /// The value of \c a is set to be true in the arc-map which stores
1552
    /// hide information. If \c a was hidden previuosly, then it is shown
972 1553
    /// again
973 1554
    void unHide(const Arc& a) const { Parent::unHide(a); }
974 1555

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

	
981 1562
  };
982 1563

	
983
  /// \brief Just gives back an arc-sub-digraph adaptor
1564
  /// \brief Just gives back an FilterArcs adaptor
984 1565
  ///
985
  /// Just gives back an arc-sub-digraph adaptor
1566
  /// Just gives back an FilterArcs adaptor
986 1567
  template<typename Digraph, typename ArcFilterMap>
987
  ArcSubDigraphAdaptor<const Digraph, ArcFilterMap>
988
  arcSubDigraphAdaptor(const Digraph& digraph, ArcFilterMap& afm) {
989
    return ArcSubDigraphAdaptor<const Digraph, ArcFilterMap>(digraph, afm);
1568
  FilterArcs<const Digraph, ArcFilterMap>
1569
  filterArcs(const Digraph& digraph, ArcFilterMap& afm) {
1570
    return FilterArcs<const Digraph, ArcFilterMap>(digraph, afm);
990 1571
  }
991 1572

	
992 1573
  template<typename Digraph, typename ArcFilterMap>
993
  ArcSubDigraphAdaptor<const Digraph, const ArcFilterMap>
994
  arcSubDigraphAdaptor(const Digraph& digraph, const ArcFilterMap& afm) {
995
    return ArcSubDigraphAdaptor<const Digraph, const ArcFilterMap>
996
      (digraph, afm);
1574
  FilterArcs<const Digraph, const ArcFilterMap>
1575
  filterArcs(const Digraph& digraph, const ArcFilterMap& afm) {
1576
    return FilterArcs<const Digraph, const ArcFilterMap>(digraph, afm);
997 1577
  }
998 1578

	
1579
  /// \ingroup graph_adaptors
1580
  ///
1581
  /// \brief An adaptor for hiding edges from a graph.
1582
  ///
1583
  /// FilterEdges adaptor hides edges in a digraph. A bool edge map must
1584
  /// be specified, which defines the filters for edges. Just the
1585
  /// unfiltered edges are shown in the subdigraph. The FilterEdges is
1586
  /// conform to the \ref concepts::Graph "Graph concept".
1587
  ///
1588
  /// \tparam _Graph It must be conform to the \ref concepts::Graph
1589
  /// "Graph concept". The type can be specified to be const.
1590
  /// \tparam _EdgeFilterMap A bool valued edge map of the the adapted
1591
  /// graph.
1592
  template<typename _Graph, typename _EdgeFilterMap>
1593
  class FilterEdges :
1594
    public SubGraph<_Graph, ConstMap<typename _Graph::Node,bool>,
1595
                    _EdgeFilterMap, false> {
1596
  public:
1597
    typedef _Graph Graph;
1598
    typedef _EdgeFilterMap EdgeFilterMap;
1599
    typedef SubGraph<Graph, ConstMap<typename Graph::Node,bool>,
1600
                     EdgeFilterMap, false> Parent;
1601
    typedef typename Parent::Edge Edge;
1602
  protected:
1603
    ConstMap<typename Graph::Node, bool> const_true_map;
1604

	
1605
    FilterEdges() : const_true_map(true) {
1606
      Parent::setNodeFilterMap(const_true_map);
1607
    }
1608

	
1609
  public:
1610

	
1611
    /// \brief Constructor
1612
    ///
1613
    /// Creates a FilterEdges adaptor for the given graph with
1614
    /// given edge map filters.
1615
    FilterEdges(Graph& _graph, EdgeFilterMap& edge_filter_map) :
1616
      Parent(), const_true_map(true) {
1617
      Parent::setGraph(_graph);
1618
      Parent::setNodeFilterMap(const_true_map);
1619
      Parent::setEdgeFilterMap(edge_filter_map);
1620
    }
1621

	
1622
    /// \brief Hides the edge of the graph
1623
    ///
1624
    /// This function hides \c e in the graph, i.e. the iteration
1625
    /// jumps over it. This is done by simply setting the value of \c e
1626
    /// to be false in the corresponding edge-map.
1627
    void hide(const Edge& e) const { Parent::hide(e); }
1628

	
1629
    /// \brief Unhides the edge of the graph
1630
    ///
1631
    /// The value of \c e is set to be true in the edge-map which stores
1632
    /// hide information. If \c e was hidden previuosly, then it is shown
1633
    /// again
1634
    void unHide(const Edge& e) const { Parent::unHide(e); }
1635

	
1636
    /// \brief Returns true if \c e is hidden.
1637
    ///
1638
    /// Returns true if \c e is hidden.
1639
    ///
1640
    bool hidden(const Edge& e) const { return Parent::hidden(e); }
1641

	
1642
  };
1643

	
1644
  /// \brief Just gives back a FilterEdges adaptor
1645
  ///
1646
  /// Just gives back a FilterEdges adaptor
1647
  template<typename Graph, typename EdgeFilterMap>
1648
  FilterEdges<const Graph, EdgeFilterMap>
1649
  filterEdges(const Graph& graph, EdgeFilterMap& efm) {
1650
    return FilterEdges<const Graph, EdgeFilterMap>(graph, efm);
1651
  }
1652

	
1653
  template<typename Graph, typename EdgeFilterMap>
1654
  FilterEdges<const Graph, const EdgeFilterMap>
1655
  filterEdges(const Graph& graph, const EdgeFilterMap& efm) {
1656
    return FilterEdges<const Graph, const EdgeFilterMap>(graph, efm);
1657
  }
1658

	
999 1659
  template <typename _Digraph>
1000
  class UndirDigraphAdaptorBase { 
1660
  class UndirectorBase {
1001 1661
  public:
1002 1662
    typedef _Digraph Digraph;
1003
    typedef UndirDigraphAdaptorBase Adaptor;
1663
    typedef UndirectorBase Adaptor;
1004 1664

	
1005 1665
    typedef True UndirectedTag;
1006 1666

	
1007 1667
    typedef typename Digraph::Arc Edge;
1008 1668
    typedef typename Digraph::Node Node;
1009 1669

	
1010 1670
    class Arc : public Edge {
1011
      friend class UndirDigraphAdaptorBase;
1671
      friend class UndirectorBase;
1012 1672
    protected:
1013 1673
      bool _forward;
1014 1674

	
1015 1675
      Arc(const Edge& edge, bool forward) :
1016 1676
        Edge(edge), _forward(forward) {}
1017 1677

	
1018 1678
    public:
1019 1679
      Arc() {}
1020 1680

	
1021 1681
      Arc(Invalid) : Edge(INVALID), _forward(true) {}
1022 1682

	
1023 1683
      bool operator==(const Arc &other) const {
1024
	return _forward == other._forward && 
1025
	  static_cast<const Edge&>(*this) == static_cast<const Edge&>(other);
1684
        return _forward == other._forward &&
1685
          static_cast<const Edge&>(*this) == static_cast<const Edge&>(other);
1026 1686
      }
1027 1687
      bool operator!=(const Arc &other) const {
1028
	return _forward != other._forward || 
1029
	  static_cast<const Edge&>(*this) != static_cast<const Edge&>(other);
1688
        return _forward != other._forward ||
1689
          static_cast<const Edge&>(*this) != static_cast<const Edge&>(other);
1030 1690
      }
1031 1691
      bool operator<(const Arc &other) const {
1032
	return _forward < other._forward ||
1033
	  (_forward == other._forward &&
1034
	   static_cast<const Edge&>(*this) < static_cast<const Edge&>(other));
1692
        return _forward < other._forward ||
1693
          (_forward == other._forward &&
1694
           static_cast<const Edge&>(*this) < static_cast<const Edge&>(other));
1035 1695
      }
1036 1696
    };
1037 1697

	
1038 1698

	
1039 1699

	
1040 1700
    void first(Node& n) const {
1041 1701
      _digraph->first(n);
1042 1702
    }
1043 1703

	
1044 1704
    void next(Node& n) const {
1045 1705
      _digraph->next(n);
1046 1706
    }
1047 1707

	
1048 1708
    void first(Arc& a) const {
1049 1709
      _digraph->first(a);
1050 1710
      a._forward = true;
1051 1711
    }
1052 1712

	
1053 1713
    void next(Arc& a) const {
1054 1714
      if (a._forward) {
1055
	a._forward = false;
1715
        a._forward = false;
1056 1716
      } else {
1057
	_digraph->next(a);
1058
	a._forward = true;
1717
        _digraph->next(a);
1718
        a._forward = true;
1059 1719
      }
1060 1720
    }
1061 1721

	
1062 1722
    void first(Edge& e) const {
1063 1723
      _digraph->first(e);
1064 1724
    }
1065 1725

	
1066 1726
    void next(Edge& e) const {
1067 1727
      _digraph->next(e);
1068 1728
    }
1069 1729

	
1070 1730
    void firstOut(Arc& a, const Node& n) const {
1071 1731
      _digraph->firstIn(a, n);
1072 1732
      if( static_cast<const Edge&>(a) != INVALID ) {
1073
	a._forward = false;
1733
        a._forward = false;
1074 1734
      } else {
1075
	_digraph->firstOut(a, n);
1076
	a._forward = true;
1735
        _digraph->firstOut(a, n);
1736
        a._forward = true;
1077 1737
      }
1078 1738
    }
1079 1739
    void nextOut(Arc &a) const {
1080 1740
      if (!a._forward) {
1081
	Node n = _digraph->target(a);
1082
	_digraph->nextIn(a);
1083
	if (static_cast<const Edge&>(a) == INVALID ) {
1084
	  _digraph->firstOut(a, n);
1085
	  a._forward = true;
1086
	}
1741
        Node n = _digraph->target(a);
1742
        _digraph->nextIn(a);
1743
        if (static_cast<const Edge&>(a) == INVALID ) {
1744
          _digraph->firstOut(a, n);
1745
          a._forward = true;
1746
        }
1087 1747
      }
1088 1748
      else {
1089
	_digraph->nextOut(a);
1749
        _digraph->nextOut(a);
1090 1750
      }
1091 1751
    }
1092 1752

	
1093 1753
    void firstIn(Arc &a, const Node &n) const {
1094 1754
      _digraph->firstOut(a, n);
1095 1755
      if (static_cast<const Edge&>(a) != INVALID ) {
1096
	a._forward = false;
1756
        a._forward = false;
1097 1757
      } else {
1098
	_digraph->firstIn(a, n);
1099
	a._forward = true;
1758
        _digraph->firstIn(a, n);
1759
        a._forward = true;
1100 1760
      }
1101 1761
    }
1102 1762
    void nextIn(Arc &a) const {
1103 1763
      if (!a._forward) {
1104
	Node n = _digraph->source(a);
1105
	_digraph->nextOut(a);
1106
	if( static_cast<const Edge&>(a) == INVALID ) {
1107
	  _digraph->firstIn(a, n);
1108
	  a._forward = true;
1109
	}
1764
        Node n = _digraph->source(a);
1765
        _digraph->nextOut(a);
1766
        if( static_cast<const Edge&>(a) == INVALID ) {
1767
          _digraph->firstIn(a, n);
1768
          a._forward = true;
1769
        }
1110 1770
      }
1111 1771
      else {
1112
	_digraph->nextIn(a);
1772
        _digraph->nextIn(a);
1113 1773
      }
1114 1774
    }
1115 1775

	
1116 1776
    void firstInc(Edge &e, bool &d, const Node &n) const {
1117 1777
      d = true;
1118 1778
      _digraph->firstOut(e, n);
1119 1779
      if (e != INVALID) return;
1120 1780
      d = false;
1121 1781
      _digraph->firstIn(e, n);
1122 1782
    }
1123 1783

	
1124 1784
    void nextInc(Edge &e, bool &d) const {
1125 1785
      if (d) {
1126
	Node s = _digraph->source(e);
1127
	_digraph->nextOut(e);
1128
	if (e != INVALID) return;
1129
	d = false;
1130
	_digraph->firstIn(e, s);
1786
        Node s = _digraph->source(e);
1787
        _digraph->nextOut(e);
1788
        if (e != INVALID) return;
1789
        d = false;
1790
        _digraph->firstIn(e, s);
1131 1791
      } else {
1132
	_digraph->nextIn(e);
1792
        _digraph->nextIn(e);
1133 1793
      }
1134 1794
    }
1135 1795

	
1136 1796
    Node u(const Edge& e) const {
1137 1797
      return _digraph->source(e);
1138 1798
    }
1139 1799

	
1140 1800
    Node v(const Edge& e) const {
1141 1801
      return _digraph->target(e);
1142 1802
    }
1143 1803

	
1144 1804
    Node source(const Arc &a) const {
1145 1805
      return a._forward ? _digraph->source(a) : _digraph->target(a);
1146 1806
    }
1147 1807

	
1148 1808
    Node target(const Arc &a) const {
1149 1809
      return a._forward ? _digraph->target(a) : _digraph->source(a);
1150 1810
    }
1151 1811

	
1152 1812
    static Arc direct(const Edge &e, bool d) {
1153 1813
      return Arc(e, d);
1154 1814
    }
1155 1815
    Arc direct(const Edge &e, const Node& n) const {
1156 1816
      return Arc(e, _digraph->source(e) == n);
1157 1817
    }
1158 1818

	
1159 1819
    static bool direction(const Arc &a) { return a._forward; }
1160 1820

	
1161 1821
    Node nodeFromId(int ix) const { return _digraph->nodeFromId(ix); }
1162 1822
    Arc arcFromId(int ix) const {
1163 1823
      return direct(_digraph->arcFromId(ix >> 1), bool(ix & 1));
1164 1824
    }
1165 1825
    Edge edgeFromId(int ix) const { return _digraph->arcFromId(ix); }
1166 1826

	
1167 1827
    int id(const Node &n) const { return _digraph->id(n); }
1168 1828
    int id(const Arc &a) const {
1169 1829
      return  (_digraph->id(a) << 1) | (a._forward ? 1 : 0);
1170 1830
    }
1171 1831
    int id(const Edge &e) const { return _digraph->id(e); }
1172 1832

	
1173 1833
    int maxNodeId() const { return _digraph->maxNodeId(); }
1174 1834
    int maxArcId() const { return (_digraph->maxArcId() << 1) | 1; }
1175 1835
    int maxEdgeId() const { return _digraph->maxArcId(); }
1176 1836

	
1177 1837
    Node addNode() { return _digraph->addNode(); }
1178
    Edge addEdge(const Node& u, const Node& v) { 
1179
      return _digraph->addArc(u, v); 
1838
    Edge addEdge(const Node& u, const Node& v) {
1839
      return _digraph->addArc(u, v);
1180 1840
    }
1181 1841

	
1182 1842
    void erase(const Node& i) { _digraph->erase(i); }
1183 1843
    void erase(const Edge& i) { _digraph->erase(i); }
1184
  
1844

	
1185 1845
    void clear() { _digraph->clear(); }
1186 1846

	
1187 1847
    typedef NodeNumTagIndicator<Digraph> NodeNumTag;
1188 1848
    int nodeNum() const { return 2 * _digraph->arcNum(); }
1189 1849
    typedef EdgeNumTagIndicator<Digraph> EdgeNumTag;
1190 1850
    int arcNum() const { return 2 * _digraph->arcNum(); }
1191 1851
    int edgeNum() const { return _digraph->arcNum(); }
1192 1852

	
1193 1853
    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
1194 1854
    Arc findArc(Node s, Node t, Arc p = INVALID) const {
1195 1855
      if (p == INVALID) {
1196
	Edge arc = _digraph->findArc(s, t);
1197
	if (arc != INVALID) return direct(arc, true);
1198
	arc = _digraph->findArc(t, s);
1199
	if (arc != INVALID) return direct(arc, false);
1856
        Edge arc = _digraph->findArc(s, t);
1857
        if (arc != INVALID) return direct(arc, true);
1858
        arc = _digraph->findArc(t, s);
1859
        if (arc != INVALID) return direct(arc, false);
1200 1860
      } else if (direction(p)) {
1201
	Edge arc = _digraph->findArc(s, t, p);
1202
	if (arc != INVALID) return direct(arc, true);
1203
	arc = _digraph->findArc(t, s);
1204
	if (arc != INVALID) return direct(arc, false);	
1861
        Edge arc = _digraph->findArc(s, t, p);
1862
        if (arc != INVALID) return direct(arc, true);
1863
        arc = _digraph->findArc(t, s);
1864
        if (arc != INVALID) return direct(arc, false);
1205 1865
      } else {
1206
	Edge arc = _digraph->findArc(t, s, p);
1207
	if (arc != INVALID) return direct(arc, false);	      
1866
        Edge arc = _digraph->findArc(t, s, p);
1867
        if (arc != INVALID) return direct(arc, false);
1208 1868
      }
1209 1869
      return INVALID;
1210 1870
    }
1211 1871

	
1212 1872
    Edge findEdge(Node s, Node t, Edge p = INVALID) const {
1213 1873
      if (s != t) {
1214 1874
        if (p == INVALID) {
1215 1875
          Edge arc = _digraph->findArc(s, t);
1216 1876
          if (arc != INVALID) return arc;
1217 1877
          arc = _digraph->findArc(t, s);
1218 1878
          if (arc != INVALID) return arc;
1219 1879
        } else if (_digraph->s(p) == s) {
1220 1880
          Edge arc = _digraph->findArc(s, t, p);
1221 1881
          if (arc != INVALID) return arc;
1222 1882
          arc = _digraph->findArc(t, s);
1223
          if (arc != INVALID) return arc;	
1883
          if (arc != INVALID) return arc;
1224 1884
        } else {
1225 1885
          Edge arc = _digraph->findArc(t, s, p);
1226
          if (arc != INVALID) return arc;	      
1886
          if (arc != INVALID) return arc;
1227 1887
        }
1228 1888
      } else {
1229 1889
        return _digraph->findArc(s, t, p);
1230 1890
      }
1231 1891
      return INVALID;
1232 1892
    }
1233 1893

	
1234 1894
  private:
1235
    
1895

	
1236 1896
    template <typename _Value>
1237 1897
    class ArcMapBase {
1238 1898
    private:
1239
      
1899

	
1240 1900
      typedef typename Digraph::template ArcMap<_Value> MapImpl;
1241
      
1901

	
1242 1902
    public:
1243 1903

	
1244 1904
      typedef typename MapTraits<MapImpl>::ReferenceMapTag ReferenceMapTag;
1245 1905

	
1246 1906
      typedef _Value Value;
1247 1907
      typedef Arc Key;
1248
      
1908

	
1249 1909
      ArcMapBase(const Adaptor& adaptor) :
1250
	_forward(*adaptor._digraph), _backward(*adaptor._digraph) {}
1251

	
1252
      ArcMapBase(const Adaptor& adaptor, const Value& v) 
1910
        _forward(*adaptor._digraph), _backward(*adaptor._digraph) {}
1911

	
1912
      ArcMapBase(const Adaptor& adaptor, const Value& v)
1253 1913
        : _forward(*adaptor._digraph, v), _backward(*adaptor._digraph, v) {}
1254
      
1255
      void set(const Arc& a, const Value& v) { 
1256
	if (direction(a)) {
1257
	  _forward.set(a, v); 
1258
        } else { 
1259
	  _backward.set(a, v);
1260
        } 
1261
      }
1262

	
1263
      typename MapTraits<MapImpl>::ConstReturnValue 
1264
      operator[](const Arc& a) const { 
1265
	if (direction(a)) {
1266
	  return _forward[a]; 
1267
	} else { 
1268
	  return _backward[a]; 
1914

	
1915
      void set(const Arc& a, const Value& v) {
1916
        if (direction(a)) {
1917
          _forward.set(a, v);
1918
        } else {
1919
          _backward.set(a, v);
1269 1920
        }
1270 1921
      }
1271 1922

	
1272
      typename MapTraits<MapImpl>::ReturnValue 
1273
      operator[](const Arc& a) { 
1274
	if (direction(a)) {
1275
	  return _forward[a]; 
1276
	} else { 
1277
	  return _backward[a]; 
1923
      typename MapTraits<MapImpl>::ConstReturnValue
1924
      operator[](const Arc& a) const {
1925
        if (direction(a)) {
1926
          return _forward[a];
1927
        } else {
1928
          return _backward[a];
1278 1929
        }
1279 1930
      }
1280 1931

	
1932
      typename MapTraits<MapImpl>::ReturnValue
1933
      operator[](const Arc& a) {
1934
        if (direction(a)) {
1935
          return _forward[a];
1936
        } else {
1937
          return _backward[a];
1938
        }
1939
      }
1940

	
1281 1941
    protected:
1282 1942

	
1283
      MapImpl _forward, _backward; 
1943
      MapImpl _forward, _backward;
1284 1944

	
1285 1945
    };
1286 1946

	
1287 1947
  public:
1288 1948

	
1289 1949
    template <typename _Value>
1290 1950
    class NodeMap : public Digraph::template NodeMap<_Value> {
1291 1951
    public:
1292 1952

	
1293 1953
      typedef _Value Value;
1294 1954
      typedef typename Digraph::template NodeMap<Value> Parent;
1295 1955

	
1296
      explicit NodeMap(const Adaptor& adaptor) 
1297
	: Parent(*adaptor._digraph) {}
1956
      explicit NodeMap(const Adaptor& adaptor)
1957
        : Parent(*adaptor._digraph) {}
1298 1958

	
1299 1959
      NodeMap(const Adaptor& adaptor, const _Value& value)
1300
	: Parent(*adaptor._digraph, value) { }
1960
        : Parent(*adaptor._digraph, value) { }
1301 1961

	
1302 1962
    private:
1303 1963
      NodeMap& operator=(const NodeMap& cmap) {
1304 1964
        return operator=<NodeMap>(cmap);
1305 1965
      }
1306 1966

	
1307 1967
      template <typename CMap>
1308 1968
      NodeMap& operator=(const CMap& cmap) {
1309 1969
        Parent::operator=(cmap);
1310 1970
        return *this;
1311 1971
      }
1312
      
1972

	
1313 1973
    };
1314 1974

	
1315 1975
    template <typename _Value>
1316
    class ArcMap 
1317
      : public SubMapExtender<Adaptor, ArcMapBase<_Value> > 
1976
    class ArcMap
1977
      : public SubMapExtender<Adaptor, ArcMapBase<_Value> >
1318 1978
    {
1319 1979
    public:
1320 1980
      typedef _Value Value;
1321 1981
      typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
1322
    
1323
      ArcMap(const Adaptor& adaptor) 
1324
	: Parent(adaptor) {}
1325

	
1326
      ArcMap(const Adaptor& adaptor, const Value& value) 
1327
	: Parent(adaptor, value) {}
1328
    
1982

	
1983
      ArcMap(const Adaptor& adaptor)
1984
        : Parent(adaptor) {}
1985

	
1986
      ArcMap(const Adaptor& adaptor, const Value& value)
1987
        : Parent(adaptor, value) {}
1988

	
1329 1989
    private:
1330 1990
      ArcMap& operator=(const ArcMap& cmap) {
1331
	return operator=<ArcMap>(cmap);
1991
        return operator=<ArcMap>(cmap);
1332 1992
      }
1333
    
1993

	
1334 1994
      template <typename CMap>
1335 1995
      ArcMap& operator=(const CMap& cmap) {
1336 1996
        Parent::operator=(cmap);
1337
	return *this;
1997
        return *this;
1338 1998
      }
1339 1999
    };
1340
        
2000

	
1341 2001
    template <typename _Value>
1342 2002
    class EdgeMap : public Digraph::template ArcMap<_Value> {
1343 2003
    public:
1344
      
2004

	
1345 2005
      typedef _Value Value;
1346 2006
      typedef typename Digraph::template ArcMap<Value> Parent;
1347
      
1348
      explicit EdgeMap(const Adaptor& adaptor) 
1349
	: Parent(*adaptor._digraph) {}
2007

	
2008
      explicit EdgeMap(const Adaptor& adaptor)
2009
        : Parent(*adaptor._digraph) {}
1350 2010

	
1351 2011
      EdgeMap(const Adaptor& adaptor, const Value& value)
1352
	: Parent(*adaptor._digraph, value) {}
2012
        : Parent(*adaptor._digraph, value) {}
1353 2013

	
1354 2014
    private:
1355 2015
      EdgeMap& operator=(const EdgeMap& cmap) {
1356 2016
        return operator=<EdgeMap>(cmap);
1357 2017
      }
1358 2018

	
1359 2019
      template <typename CMap>
1360 2020
      EdgeMap& operator=(const CMap& cmap) {
1361 2021
        Parent::operator=(cmap);
1362 2022
        return *this;
1363 2023
      }
1364 2024

	
1365 2025
    };
1366 2026

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

	
1370 2030
  protected:
1371 2031

	
1372
    UndirDigraphAdaptorBase() : _digraph(0) {}
2032
    UndirectorBase() : _digraph(0) {}
1373 2033

	
1374 2034
    Digraph* _digraph;
1375 2035

	
1376 2036
    void setDigraph(Digraph& digraph) {
1377 2037
      _digraph = &digraph;
1378 2038
    }
1379
    
2039

	
1380 2040
  };
1381 2041

	
1382
  ///\ingroup graph_adaptors
2042
  /// \ingroup graph_adaptors
1383 2043
  ///
1384
  /// \brief A graph is made from a directed digraph by an adaptor
2044
  /// \brief Undirect the graph
1385 2045
  ///
1386 2046
  /// This adaptor makes an undirected graph from a directed
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.
2047
  /// graph. All arcs of the underlying digraph will be showed in the
2048
  /// adaptor as an edge. The Orienter adaptor is conform to the \ref
2049
  /// concepts::Graph "Graph concept".
1390 2050
  ///
1391
  /// There is a network of the streets of a town. Of course there are
1392
  /// some one-way street in the town hence the network is a directed
1393
  /// one. There is a crazy driver who go oppositely in the one-way
1394
  /// street without moral sense. Of course he can pass this streets
1395
  /// slower than the regular way, in fact his speed is half of the
1396
  /// normal speed. How long should he drive to get from a source
1397
  /// point to the target? Let see the example code which calculate it:
1398
  ///
1399
  /// \todo BadCode, SimpleMap does no exists
1400
  ///\code
1401
  /// typedef UndirDigraphAdaptor<Digraph> Graph;
1402
  /// Graph graph(digraph);
1403
  ///
1404
  /// typedef SimpleMap<LengthMap> FLengthMap;
1405
  /// FLengthMap flength(length);
1406
  ///
1407
  /// typedef ScaleMap<LengthMap> RLengthMap;
1408
  /// RLengthMap rlength(length, 2.0);
1409
  ///
1410
  /// typedef Graph::CombinedArcMap<FLengthMap, RLengthMap > ULengthMap;
1411
  /// ULengthMap ulength(flength, rlength);
1412
  /// 
1413
  /// Dijkstra<Graph, ULengthMap> dijkstra(graph, ulength);
1414
  /// std::cout << "Driving time : " << dijkstra.run(src, trg) << std::endl;
1415
  ///\endcode
1416
  ///
1417
  /// The combined arc map makes the length map for the undirected
1418
  /// graph. It is created from a forward and reverse map. The forward
1419
  /// map is created from the original length map with a SimpleMap
1420
  /// adaptor which just makes a read-write map from the reference map
1421
  /// i.e. it forgets that it can be return reference to values. The
1422
  /// reverse map is just the scaled original map with the ScaleMap
1423
  /// adaptor. The combination solves that passing the reverse way
1424
  /// takes double time than the original. To get the driving time we
1425
  /// run the dijkstra algorithm on the graph.
2051
  /// \tparam _Digraph It must be conform to the \ref
2052
  /// concepts::Digraph "Digraph concept". The type can be specified
2053
  /// to const.
1426 2054
  template<typename _Digraph>
1427
  class UndirDigraphAdaptor 
1428
    : public GraphAdaptorExtender<UndirDigraphAdaptorBase<_Digraph> > {
2055
  class Undirector
2056
    : public GraphAdaptorExtender<UndirectorBase<_Digraph> > {
1429 2057
  public:
1430 2058
    typedef _Digraph Digraph;
1431
    typedef GraphAdaptorExtender<UndirDigraphAdaptorBase<Digraph> > Parent;
2059
    typedef GraphAdaptorExtender<UndirectorBase<Digraph> > Parent;
1432 2060
  protected:
1433
    UndirDigraphAdaptor() { }
2061
    Undirector() { }
1434 2062
  public:
1435 2063

	
1436 2064
    /// \brief Constructor
1437 2065
    ///
1438
    /// Constructor
1439
    UndirDigraphAdaptor(_Digraph& _digraph) { 
1440
      setDigraph(_digraph);
2066
    /// Creates a undirected graph from the given digraph
2067
    Undirector(_Digraph& digraph) {
2068
      setDigraph(digraph);
1441 2069
    }
1442 2070

	
1443 2071
    /// \brief ArcMap combined from two original ArcMap
1444 2072
    ///
1445 2073
    /// This class adapts two original digraph ArcMap to
1446
    /// get an arc map on the adaptor.
2074
    /// get an arc map on the undirected graph.
1447 2075
    template <typename _ForwardMap, typename _BackwardMap>
1448 2076
    class CombinedArcMap {
1449 2077
    public:
1450
      
2078

	
1451 2079
      typedef _ForwardMap ForwardMap;
1452 2080
      typedef _BackwardMap BackwardMap;
1453 2081

	
1454 2082
      typedef typename MapTraits<ForwardMap>::ReferenceMapTag ReferenceMapTag;
1455 2083

	
1456 2084
      typedef typename ForwardMap::Value Value;
1457 2085
      typedef typename Parent::Arc Key;
1458 2086

	
1459
      /// \brief Constructor      
2087
      /// \brief Constructor
1460 2088
      ///
1461
      /// Constructor      
1462
      CombinedArcMap() : _forward(0), _backward(0) {}
1463

	
1464
      /// \brief Constructor      
1465
      ///
1466
      /// Constructor      
1467
      CombinedArcMap(ForwardMap& forward, BackwardMap& backward) 
2089
      /// Constructor
2090
      CombinedArcMap(ForwardMap& forward, BackwardMap& backward)
1468 2091
        : _forward(&forward), _backward(&backward) {}
1469
      
2092

	
1470 2093

	
1471 2094
      /// \brief Sets the value associated with a key.
1472 2095
      ///
1473 2096
      /// Sets the value associated with a key.
1474
      void set(const Key& e, const Value& a) { 
1475
	if (Parent::direction(e)) {
1476
	  _forward->set(e, a); 
1477
        } else { 
1478
	  _backward->set(e, a);
1479
        } 
2097
      void set(const Key& e, const Value& a) {
2098
        if (Parent::direction(e)) {
2099
          _forward->set(e, a);
2100
        } else {
2101
          _backward->set(e, a);
2102
        }
1480 2103
      }
1481 2104

	
1482 2105
      /// \brief Returns the value associated with a key.
1483 2106
      ///
1484 2107
      /// Returns the value associated with a key.
1485
      typename MapTraits<ForwardMap>::ConstReturnValue 
1486
      operator[](const Key& e) const { 
1487
	if (Parent::direction(e)) {
1488
	  return (*_forward)[e]; 
1489
	} else { 
1490
	  return (*_backward)[e]; 
2108
      typename MapTraits<ForwardMap>::ConstReturnValue
2109
      operator[](const Key& e) const {
2110
        if (Parent::direction(e)) {
2111
          return (*_forward)[e];
2112
        } else {
2113
          return (*_backward)[e];
1491 2114
        }
1492 2115
      }
1493 2116

	
1494 2117
      /// \brief Returns the value associated with a key.
1495 2118
      ///
1496 2119
      /// Returns the value associated with a key.
1497
      typename MapTraits<ForwardMap>::ReturnValue 
1498
      operator[](const Key& e) { 
1499
	if (Parent::direction(e)) {
1500
	  return (*_forward)[e]; 
1501
	} else { 
1502
	  return (*_backward)[e]; 
2120
      typename MapTraits<ForwardMap>::ReturnValue
2121
      operator[](const Key& e) {
2122
        if (Parent::direction(e)) {
2123
          return (*_forward)[e];
2124
        } else {
2125
          return (*_backward)[e];
1503 2126
        }
1504 2127
      }
1505 2128

	
1506
      /// \brief Sets the forward map
1507
      ///
1508
      /// Sets the forward map
1509
      void setForwardMap(ForwardMap& forward) {
1510
        _forward = &forward;
2129
    protected:
2130

	
2131
      ForwardMap* _forward;
2132
      BackwardMap* _backward;
2133

	
2134
    };
2135

	
2136
    /// \brief Just gives back a combined arc map
2137
    ///
2138
    /// Just gives back a combined arc map
2139
    template <typename ForwardMap, typename BackwardMap>
2140
    static CombinedArcMap<ForwardMap, BackwardMap>
2141
    combinedArcMap(ForwardMap& forward, BackwardMap& backward) {
2142
      return CombinedArcMap<ForwardMap, BackwardMap>(forward, backward);
2143
    }
2144

	
2145
    template <typename ForwardMap, typename BackwardMap>
2146
    static CombinedArcMap<const ForwardMap, BackwardMap>
2147
    combinedArcMap(const ForwardMap& forward, BackwardMap& backward) {
2148
      return CombinedArcMap<const ForwardMap,
2149
        BackwardMap>(forward, backward);
2150
    }
2151

	
2152
    template <typename ForwardMap, typename BackwardMap>
2153
    static CombinedArcMap<ForwardMap, const BackwardMap>
2154
    combinedArcMap(ForwardMap& forward, const BackwardMap& backward) {
2155
      return CombinedArcMap<ForwardMap,
2156
        const BackwardMap>(forward, backward);
2157
    }
2158

	
2159
    template <typename ForwardMap, typename BackwardMap>
2160
    static CombinedArcMap<const ForwardMap, const BackwardMap>
2161
    combinedArcMap(const ForwardMap& forward, const BackwardMap& backward) {
2162
      return CombinedArcMap<const ForwardMap,
2163
        const BackwardMap>(forward, backward);
2164
    }
2165

	
2166
  };
2167

	
2168
  /// \brief Just gives back an undirected view of the given digraph
2169
  ///
2170
  /// Just gives back an undirected view of the given digraph
2171
  template<typename Digraph>
2172
  Undirector<const Digraph>
2173
  undirector(const Digraph& digraph) {
2174
    return Undirector<const Digraph>(digraph);
2175
  }
2176

	
2177
  template <typename _Graph, typename _DirectionMap>
2178
  class OrienterBase {
2179
  public:
2180

	
2181
    typedef _Graph Graph;
2182
    typedef _DirectionMap DirectionMap;
2183

	
2184
    typedef typename Graph::Node Node;
2185
    typedef typename Graph::Edge Arc;
2186

	
2187
    void reverseArc(const Arc& arc) {
2188
      _direction->set(arc, !(*_direction)[arc]);
2189
    }
2190

	
2191
    void first(Node& i) const { _graph->first(i); }
2192
    void first(Arc& i) const { _graph->first(i); }
2193
    void firstIn(Arc& i, const Node& n) const {
2194
      bool d;
2195
      _graph->firstInc(i, d, n);
2196
      while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
2197
    }
2198
    void firstOut(Arc& i, const Node& n ) const {
2199
      bool d;
2200
      _graph->firstInc(i, d, n);
2201
      while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
2202
    }
2203

	
2204
    void next(Node& i) const { _graph->next(i); }
2205
    void next(Arc& i) const { _graph->next(i); }
2206
    void nextIn(Arc& i) const {
2207
      bool d = !(*_direction)[i];
2208
      _graph->nextInc(i, d);
2209
      while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
2210
    }
2211
    void nextOut(Arc& i) const {
2212
      bool d = (*_direction)[i];
2213
      _graph->nextInc(i, d);
2214
      while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
2215
    }
2216

	
2217
    Node source(const Arc& e) const {
2218
      return (*_direction)[e] ? _graph->u(e) : _graph->v(e);
2219
    }
2220
    Node target(const Arc& e) const {
2221
      return (*_direction)[e] ? _graph->v(e) : _graph->u(e);
2222
    }
2223

	
2224
    typedef NodeNumTagIndicator<Graph> NodeNumTag;
2225
    int nodeNum() const { return _graph->nodeNum(); }
2226

	
2227
    typedef EdgeNumTagIndicator<Graph> EdgeNumTag;
2228
    int arcNum() const { return _graph->edgeNum(); }
2229

	
2230
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
2231
    Arc findArc(const Node& u, const Node& v,
2232
                const Arc& prev = INVALID) {
2233
      Arc arc = prev;
2234
      bool d = arc == INVALID ? true : (*_direction)[arc];
2235
      if (d) {
2236
        arc = _graph->findEdge(u, v, arc);
2237
        while (arc != INVALID && !(*_direction)[arc]) {
2238
          _graph->findEdge(u, v, arc);
2239
        }
2240
        if (arc != INVALID) return arc;
1511 2241
      }
1512

	
1513
      /// \brief Sets the backward map
1514
      ///
1515
      /// Sets the backward map
1516
      void setBackwardMap(BackwardMap& backward) {
1517
        _backward = &backward;
2242
      _graph->findEdge(v, u, arc);
2243
      while (arc != INVALID && (*_direction)[arc]) {
2244
        _graph->findEdge(u, v, arc);
1518 2245
      }
1519

	
1520
    protected:
1521

	
1522
      ForwardMap* _forward;
1523
      BackwardMap* _backward; 
2246
      return arc;
2247
    }
2248

	
2249
    Node addNode() {
2250
      return Node(_graph->addNode());
2251
    }
2252

	
2253
    Arc addArc(const Node& u, const Node& v) {
2254
      Arc arc = _graph->addArc(u, v);
2255
      _direction->set(arc, _graph->source(arc) == u);
2256
      return arc;
2257
    }
2258

	
2259
    void erase(const Node& i) { _graph->erase(i); }
2260
    void erase(const Arc& i) { _graph->erase(i); }
2261

	
2262
    void clear() { _graph->clear(); }
2263

	
2264
    int id(const Node& v) const { return _graph->id(v); }
2265
    int id(const Arc& e) const { return _graph->id(e); }
2266

	
2267
    Node nodeFromId(int idx) const { return _graph->nodeFromId(idx); }
2268
    Arc arcFromId(int idx) const { return _graph->edgeFromId(idx); }
2269

	
2270
    int maxNodeId() const { return _graph->maxNodeId(); }
2271
    int maxArcId() const { return _graph->maxEdgeId(); }
2272

	
2273
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
2274
    NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); }
2275

	
2276
    typedef typename ItemSetTraits<Graph, Arc>::ItemNotifier ArcNotifier;
2277
    ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); }
2278

	
2279
    template <typename _Value>
2280
    class NodeMap : public _Graph::template NodeMap<_Value> {
2281
    public:
2282

	
2283
      typedef typename _Graph::template NodeMap<_Value> Parent;
2284

	
2285
      explicit NodeMap(const OrienterBase& adapter)
2286
        : Parent(*adapter._graph) {}
2287

	
2288
      NodeMap(const OrienterBase& adapter, const _Value& value)
2289
        : Parent(*adapter._graph, value) {}
2290

	
2291
    private:
2292
      NodeMap& operator=(const NodeMap& cmap) {
2293
        return operator=<NodeMap>(cmap);
2294
      }
2295

	
2296
      template <typename CMap>
2297
      NodeMap& operator=(const CMap& cmap) {
2298
        Parent::operator=(cmap);
2299
        return *this;
2300
      }
1524 2301

	
1525 2302
    };
1526 2303

	
2304
    template <typename _Value>
2305
    class ArcMap : public _Graph::template EdgeMap<_Value> {
2306
    public:
2307

	
2308
      typedef typename Graph::template EdgeMap<_Value> Parent;
2309

	
2310
      explicit ArcMap(const OrienterBase& adapter)
2311
        : Parent(*adapter._graph) { }
2312

	
2313
      ArcMap(const OrienterBase& adapter, const _Value& value)
2314
        : Parent(*adapter._graph, value) { }
2315

	
2316
    private:
2317
      ArcMap& operator=(const ArcMap& cmap) {
2318
        return operator=<ArcMap>(cmap);
2319
      }
2320

	
2321
      template <typename CMap>
2322
      ArcMap& operator=(const CMap& cmap) {
2323
        Parent::operator=(cmap);
2324
        return *this;
2325
      }
2326
    };
2327

	
2328

	
2329

	
2330
  protected:
2331
    Graph* _graph;
2332
    DirectionMap* _direction;
2333

	
2334
    void setDirectionMap(DirectionMap& direction) {
2335
      _direction = &direction;
2336
    }
2337

	
2338
    void setGraph(Graph& graph) {
2339
      _graph = &graph;
2340
    }
2341

	
1527 2342
  };
1528 2343

	
1529
  /// \brief Just gives back an undir digraph adaptor
2344
  /// \ingroup graph_adaptors
1530 2345
  ///
1531
  /// Just gives back an undir digraph adaptor
1532
  template<typename Digraph>
1533
  UndirDigraphAdaptor<const Digraph>
1534
  undirDigraphAdaptor(const Digraph& digraph) {
1535
    return UndirDigraphAdaptor<const Digraph>(digraph);
2346
  /// \brief Orients the edges of the graph to get a digraph
2347
  ///
2348
  /// This adaptor orients each edge in the undirected graph. The
2349
  /// direction of the arcs stored in an edge node map.  The arcs can
2350
  /// be easily reverted by the \c reverseArc() member function in the
2351
  /// adaptor. The Orienter adaptor is conform to the \ref
2352
  /// concepts::Digraph "Digraph concept".
2353
  ///
2354
  /// \tparam _Graph It must be conform to the \ref concepts::Graph
2355
  /// "Graph concept". The type can be specified to be const.
2356
  /// \tparam _DirectionMap A bool valued edge map of the the adapted
2357
  /// graph.
2358
  ///
2359
  /// \sa orienter
2360
  template<typename _Graph,
2361
           typename DirectionMap = typename _Graph::template EdgeMap<bool> >
2362
  class Orienter :
2363
    public DigraphAdaptorExtender<OrienterBase<_Graph, DirectionMap> > {
2364
  public:
2365
    typedef _Graph Graph;
2366
    typedef DigraphAdaptorExtender<
2367
      OrienterBase<_Graph, DirectionMap> > Parent;
2368
    typedef typename Parent::Arc Arc;
2369
  protected:
2370
    Orienter() { }
2371
  public:
2372

	
2373
    /// \brief Constructor of the adaptor
2374
    ///
2375
    /// Constructor of the adaptor
2376
    Orienter(Graph& graph, DirectionMap& direction) {
2377
      setGraph(graph);
2378
      setDirectionMap(direction);
2379
    }
2380

	
2381
    /// \brief Reverse arc
2382
    ///
2383
    /// It reverse the given arc. It simply negate the direction in the map.
2384
    void reverseArc(const Arc& a) {
2385
      Parent::reverseArc(a);
2386
    }
2387
  };
2388

	
2389
  /// \brief Just gives back a Orienter
2390
  ///
2391
  /// Just gives back a Orienter
2392
  template<typename Graph, typename DirectionMap>
2393
  Orienter<const Graph, DirectionMap>
2394
  orienter(const Graph& graph, DirectionMap& dm) {
2395
    return Orienter<const Graph, DirectionMap>(graph, dm);
1536 2396
  }
1537 2397

	
1538
  template<typename _Digraph, 
1539
	   typename _CapacityMap = typename _Digraph::template ArcMap<int>, 
1540
	   typename _FlowMap = _CapacityMap, 
2398
  template<typename Graph, typename DirectionMap>
2399
  Orienter<const Graph, const DirectionMap>
2400
  orienter(const Graph& graph, const DirectionMap& dm) {
2401
    return Orienter<const Graph, const DirectionMap>(graph, dm);
2402
  }
2403

	
2404
  namespace _adaptor_bits {
2405

	
2406
    template<typename _Digraph,
2407
             typename _CapacityMap = typename _Digraph::template ArcMap<int>,
2408
             typename _FlowMap = _CapacityMap,
2409
             typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
2410
    class ResForwardFilter {
2411
    public:
2412

	
2413
      typedef _Digraph Digraph;
2414
      typedef _CapacityMap CapacityMap;
2415
      typedef _FlowMap FlowMap;
2416
      typedef _Tolerance Tolerance;
2417

	
2418
      typedef typename Digraph::Arc Key;
2419
      typedef bool Value;
2420

	
2421
    private:
2422

	
2423
      const CapacityMap* _capacity;
2424
      const FlowMap* _flow;
2425
      Tolerance _tolerance;
2426
    public:
2427

	
2428
      ResForwardFilter(const CapacityMap& capacity, const FlowMap& flow,
2429
                       const Tolerance& tolerance = Tolerance())
2430
        : _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
2431

	
2432
      bool operator[](const typename Digraph::Arc& a) const {
2433
        return _tolerance.positive((*_capacity)[a] - (*_flow)[a]);
2434
      }
2435
    };
2436

	
2437
    template<typename _Digraph,
2438
             typename _CapacityMap = typename _Digraph::template ArcMap<int>,
2439
             typename _FlowMap = _CapacityMap,
2440
             typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
2441
    class ResBackwardFilter {
2442
    public:
2443

	
2444
      typedef _Digraph Digraph;
2445
      typedef _CapacityMap CapacityMap;
2446
      typedef _FlowMap FlowMap;
2447
      typedef _Tolerance Tolerance;
2448

	
2449
      typedef typename Digraph::Arc Key;
2450
      typedef bool Value;
2451

	
2452
    private:
2453

	
2454
      const CapacityMap* _capacity;
2455
      const FlowMap* _flow;
2456
      Tolerance _tolerance;
2457

	
2458
    public:
2459

	
2460
      ResBackwardFilter(const CapacityMap& capacity, const FlowMap& flow,
2461
                        const Tolerance& tolerance = Tolerance())
2462
        : _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
2463

	
2464
      bool operator[](const typename Digraph::Arc& a) const {
2465
        return _tolerance.positive((*_flow)[a]);
2466
      }
2467
    };
2468

	
2469
  }
2470

	
2471
  /// \ingroup graph_adaptors
2472
  ///
2473
  /// \brief An adaptor for composing the residual graph for directed
2474
  /// flow and circulation problems.
2475
  ///
2476
  /// An adaptor for composing the residual graph for directed flow and
2477
  /// circulation problems.  Let \f$ G=(V, A) \f$ be a directed graph
2478
  /// and let \f$ F \f$ be a number type. Let moreover \f$ f,c:A\to F \f$,
2479
  /// be functions on the arc-set.
2480
  ///
2481
  /// Then Residual implements the digraph structure with
2482
  /// node-set \f$ V \f$ and arc-set \f$ A_{forward}\cup A_{backward} \f$,
2483
  /// where \f$ A_{forward}=\{uv : uv\in A, f(uv)<c(uv)\} \f$ and
2484
  /// \f$ A_{backward}=\{vu : uv\in A, f(uv)>0\} \f$, i.e. the so
2485
  /// called residual graph.  When we take the union
2486
  /// \f$ A_{forward}\cup A_{backward} \f$, multiplicities are counted,
2487
  /// i.e.  if an arc is in both \f$ A_{forward} \f$ and
2488
  /// \f$ A_{backward} \f$, then in the adaptor it appears in both
2489
  /// orientation.
2490
  ///
2491
  /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
2492
  /// "Digraph concept". The type is implicitly const.
2493
  /// \tparam _CapacityMap An arc map of some numeric type, it defines
2494
  /// the capacities in the flow problem. The map is implicitly const.
2495
  /// \tparam _FlowMap An arc map of some numeric type, it defines
2496
  /// the capacities in the flow problem.
2497
  /// \tparam _Tolerance Handler for inexact computation.
2498
  template<typename _Digraph,
2499
           typename _CapacityMap = typename _Digraph::template ArcMap<int>,
2500
           typename _FlowMap = _CapacityMap,
1541 2501
           typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
1542
  class ResForwardFilter {
2502
  class Residual :
2503
    public FilterArcs<
2504
    Undirector<const _Digraph>,
2505
    typename Undirector<const _Digraph>::template CombinedArcMap<
2506
      _adaptor_bits::ResForwardFilter<const _Digraph, _CapacityMap,
2507
                                      _FlowMap, _Tolerance>,
2508
      _adaptor_bits::ResBackwardFilter<const _Digraph, _CapacityMap,
2509
                                       _FlowMap, _Tolerance> > >
2510
  {
1543 2511
  public:
1544 2512

	
1545 2513
    typedef _Digraph Digraph;
1546 2514
    typedef _CapacityMap CapacityMap;
1547 2515
    typedef _FlowMap FlowMap;
1548 2516
    typedef _Tolerance Tolerance;
1549 2517

	
1550
    typedef typename Digraph::Arc Key;
1551
    typedef bool Value;
1552

	
1553
  private:
1554

	
1555
    const CapacityMap* _capacity;
1556
    const FlowMap* _flow;
1557
    Tolerance _tolerance;
1558
  public:
1559

	
1560
    ResForwardFilter(const CapacityMap& capacity, const FlowMap& flow,
1561
                     const Tolerance& tolerance = Tolerance()) 
1562
      : _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
1563

	
1564
    ResForwardFilter(const Tolerance& tolerance = Tolerance()) 
1565
      : _capacity(0), _flow(0), _tolerance(tolerance)  { }
1566

	
1567
    void setCapacity(const CapacityMap& capacity) { _capacity = &capacity; }
1568
    void setFlow(const FlowMap& flow) { _flow = &flow; }
1569

	
1570
    bool operator[](const typename Digraph::Arc& a) const {
1571
      return _tolerance.positive((*_capacity)[a] - (*_flow)[a]);
1572
    }
1573
  };
1574

	
1575
  template<typename _Digraph, 
1576
	   typename _CapacityMap = typename _Digraph::template ArcMap<int>, 
1577
	   typename _FlowMap = _CapacityMap, 
1578
           typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
1579
  class ResBackwardFilter {
1580
  public:
1581

	
1582
    typedef _Digraph Digraph;
1583
    typedef _CapacityMap CapacityMap;
1584
    typedef _FlowMap FlowMap;
1585
    typedef _Tolerance Tolerance;
1586

	
1587
    typedef typename Digraph::Arc Key;
1588
    typedef bool Value;
1589

	
1590
  private:
1591

	
1592
    const CapacityMap* _capacity;
1593
    const FlowMap* _flow;
1594
    Tolerance _tolerance;
1595

	
1596
  public:
1597

	
1598
    ResBackwardFilter(const CapacityMap& capacity, const FlowMap& flow,
1599
                      const Tolerance& tolerance = Tolerance())
1600
      : _capacity(&capacity), _flow(&flow), _tolerance(tolerance) { }
1601
    ResBackwardFilter(const Tolerance& tolerance = Tolerance())
1602
      : _capacity(0), _flow(0), _tolerance(tolerance) { }
1603

	
1604
    void setCapacity(const CapacityMap& capacity) { _capacity = &capacity; }
1605
    void setFlow(const FlowMap& flow) { _flow = &flow; }
1606

	
1607
    bool operator[](const typename Digraph::Arc& a) const {
1608
      return _tolerance.positive((*_flow)[a]);
1609
    }
1610
  };
1611

	
1612
  
1613
  ///\ingroup graph_adaptors
1614
  ///
1615
  ///\brief An adaptor for composing the residual graph for directed
1616
  ///flow and circulation problems.
1617
  ///
1618
  ///An adaptor for composing the residual graph for directed flow and
1619
  ///circulation problems.  Let \f$ G=(V, A) \f$ be a directed digraph
1620
  ///and let \f$ F \f$ be a number type. Let moreover \f$ f,c:A\to F
1621
  ///\f$, be functions on the arc-set.
1622
  ///
1623
  ///In the appications of ResDigraphAdaptor, \f$ f \f$ usually stands
1624
  ///for a flow and \f$ c \f$ for a capacity function.  Suppose that a
1625
  ///graph instance \c g of type \c ListDigraph implements \f$ G \f$.
1626
  ///
1627
  ///\code 
1628
  ///  ListDigraph g;
1629
  ///\endcode 
1630
  ///
1631
  ///Then ResDigraphAdaptor implements the digraph structure with
1632
  /// node-set \f$ V \f$ and arc-set \f$ A_{forward}\cup A_{backward}
1633
  /// \f$, where \f$ A_{forward}=\{uv : uv\in A, f(uv)<c(uv)\} \f$ and
1634
  /// \f$ A_{backward}=\{vu : uv\in A, f(uv)>0\} \f$, i.e. the so
1635
  /// called residual graph.  When we take the union \f$
1636
  /// A_{forward}\cup A_{backward} \f$, multilicities are counted,
1637
  /// i.e.  if an arc is in both \f$ A_{forward} \f$ and \f$
1638
  /// A_{backward} \f$, then in the adaptor it appears twice. The
1639
  /// following code shows how such an instance can be constructed.
1640
  ///
1641
  ///\code 
1642
  ///  typedef ListDigraph Digraph; 
1643
  ///  IntArcMap f(g), c(g);
1644
  ///  ResDigraphAdaptor<Digraph, int, IntArcMap, IntArcMap> ga(g); 
1645
  ///\endcode
1646
  template<typename _Digraph, 
1647
	   typename _CapacityMap = typename _Digraph::template ArcMap<int>, 
1648
	   typename _FlowMap = _CapacityMap,
1649
           typename _Tolerance = Tolerance<typename _CapacityMap::Value> >
1650
  class ResDigraphAdaptor : 
1651
    public ArcSubDigraphAdaptor< 
1652
    UndirDigraphAdaptor<const _Digraph>, 
1653
    typename UndirDigraphAdaptor<const _Digraph>::template CombinedArcMap<
1654
      ResForwardFilter<const _Digraph, _CapacityMap, _FlowMap>,  
1655
      ResBackwardFilter<const _Digraph, _CapacityMap, _FlowMap> > > {
1656
  public:
1657

	
1658
    typedef _Digraph Digraph;
1659
    typedef _CapacityMap CapacityMap;
1660
    typedef _FlowMap FlowMap;
1661
    typedef _Tolerance Tolerance;
1662

	
1663 2518
    typedef typename CapacityMap::Value Value;
1664
    typedef ResDigraphAdaptor Adaptor;
2519
    typedef Residual Adaptor;
1665 2520

	
1666 2521
  protected:
1667 2522

	
1668
    typedef UndirDigraphAdaptor<const Digraph> UndirDigraph;
1669

	
1670
    typedef ResForwardFilter<const Digraph, CapacityMap, FlowMap> 
1671
    ForwardFilter;
1672

	
1673
    typedef ResBackwardFilter<const Digraph, CapacityMap, FlowMap> 
1674
    BackwardFilter;
1675

	
1676
    typedef typename UndirDigraph::
2523
    typedef Undirector<const Digraph> Undirected;
2524

	
2525
    typedef _adaptor_bits::ResForwardFilter<const Digraph, CapacityMap,
2526
                                            FlowMap, Tolerance> ForwardFilter;
2527

	
2528
    typedef _adaptor_bits::ResBackwardFilter<const Digraph, CapacityMap,
2529
                                             FlowMap, Tolerance> BackwardFilter;
2530

	
2531
    typedef typename Undirected::
1677 2532
    template CombinedArcMap<ForwardFilter, BackwardFilter> ArcFilter;
1678 2533

	
1679
    typedef ArcSubDigraphAdaptor<UndirDigraph, ArcFilter> Parent;
2534
    typedef FilterArcs<Undirected, ArcFilter> Parent;
1680 2535

	
1681 2536
    const CapacityMap* _capacity;
1682 2537
    FlowMap* _flow;
1683 2538

	
1684
    UndirDigraph _graph;
2539
    Undirected _graph;
1685 2540
    ForwardFilter _forward_filter;
1686 2541
    BackwardFilter _backward_filter;
1687 2542
    ArcFilter _arc_filter;
1688 2543

	
1689
    void setCapacityMap(const CapacityMap& capacity) {
1690
      _capacity = &capacity;
1691
      _forward_filter.setCapacity(capacity);
1692
      _backward_filter.setCapacity(capacity);
1693
    }
1694

	
1695
    void setFlowMap(FlowMap& flow) {
1696
      _flow = &flow;
1697
      _forward_filter.setFlow(flow);
1698
      _backward_filter.setFlow(flow);
1699
    }
1700

	
1701 2544
  public:
1702 2545

	
1703 2546
    /// \brief Constructor of the residual digraph.
1704 2547
    ///
1705
    /// Constructor of the residual graph. The parameters are the digraph type,
2548
    /// Constructor of the residual graph. The parameters are the digraph,
1706 2549
    /// the flow map, the capacity map and a tolerance object.
1707
    ResDigraphAdaptor(const Digraph& digraph, const CapacityMap& capacity, 
1708
                    FlowMap& flow, const Tolerance& tolerance = Tolerance()) 
2550
    Residual(const Digraph& digraph, const CapacityMap& capacity,
2551
             FlowMap& flow, const Tolerance& tolerance = Tolerance())
1709 2552
      : Parent(), _capacity(&capacity), _flow(&flow), _graph(digraph),
1710
        _forward_filter(capacity, flow, tolerance), 
2553
        _forward_filter(capacity, flow, tolerance),
1711 2554
        _backward_filter(capacity, flow, tolerance),
1712 2555
        _arc_filter(_forward_filter, _backward_filter)
1713 2556
    {
1714 2557
      Parent::setDigraph(_graph);
1715 2558
      Parent::setArcFilterMap(_arc_filter);
1716 2559
    }
1717 2560

	
1718 2561
    typedef typename Parent::Arc Arc;
1719 2562

	
1720 2563
    /// \brief Gives back the residual capacity of the arc.
1721 2564
    ///
1722 2565
    /// Gives back the residual capacity of the arc.
1723
    Value rescap(const Arc& arc) const {
1724
      if (UndirDigraph::direction(arc)) {
1725
        return (*_capacity)[arc] - (*_flow)[arc]; 
2566
    Value residualCapacity(const Arc& a) const {
2567
      if (Undirected::direction(a)) {
2568
        return (*_capacity)[a] - (*_flow)[a];
1726 2569
      } else {
1727
        return (*_flow)[arc];
2570
        return (*_flow)[a];
1728 2571
      }
1729
    } 
1730

	
1731
    /// \brief Augment on the given arc in the residual digraph.
2572
    }
2573

	
2574
    /// \brief Augment on the given arc in the residual graph.
1732 2575
    ///
1733
    /// Augment on the given arc in the residual digraph. It increase
2576
    /// Augment on the given arc in the residual graph. It increase
1734 2577
    /// or decrease the flow on the original arc depend on the direction
1735 2578
    /// of the residual arc.
1736
    void augment(const Arc& e, const Value& a) const {
1737
      if (UndirDigraph::direction(e)) {
1738
        _flow->set(e, (*_flow)[e] + a);
1739
      } else {  
1740
        _flow->set(e, (*_flow)[e] - a);
2579
    void augment(const Arc& a, const Value& v) const {
2580
      if (Undirected::direction(a)) {
2581
        _flow->set(a, (*_flow)[a] + v);
2582
      } else {
2583
        _flow->set(a, (*_flow)[a] - v);
1741 2584
      }
1742 2585
    }
1743 2586

	
1744 2587
    /// \brief Returns the direction of the arc.
1745 2588
    ///
1746 2589
    /// Returns true when the arc is same oriented as the original arc.
1747
    static bool forward(const Arc& e) {
1748
      return UndirDigraph::direction(e);
2590
    static bool forward(const Arc& a) {
2591
      return Undirected::direction(a);
1749 2592
    }
1750 2593

	
1751 2594
    /// \brief Returns the direction of the arc.
1752 2595
    ///
1753 2596
    /// Returns true when the arc is opposite oriented as the original arc.
1754
    static bool backward(const Arc& e) {
1755
      return !UndirDigraph::direction(e);
2597
    static bool backward(const Arc& a) {
2598
      return !Undirected::direction(a);
1756 2599
    }
1757 2600

	
1758 2601
    /// \brief Gives back the forward oriented residual arc.
1759 2602
    ///
1760 2603
    /// Gives back the forward oriented residual arc.
1761
    static Arc forward(const typename Digraph::Arc& e) {
1762
      return UndirDigraph::direct(e, true);
2604
    static Arc forward(const typename Digraph::Arc& a) {
2605
      return Undirected::direct(a, true);
1763 2606
    }
1764 2607

	
1765 2608
    /// \brief Gives back the backward oriented residual arc.
1766 2609
    ///
1767 2610
    /// Gives back the backward oriented residual arc.
1768
    static Arc backward(const typename Digraph::Arc& e) {
1769
      return UndirDigraph::direct(e, false);
2611
    static Arc backward(const typename Digraph::Arc& a) {
2612
      return Undirected::direct(a, false);
1770 2613
    }
1771 2614

	
1772 2615
    /// \brief Residual capacity map.
1773 2616
    ///
1774
    /// In generic residual digraphs the residual capacity can be obtained 
1775
    /// as a map. 
1776
    class ResCap {
2617
    /// In generic residual graph the residual capacity can be obtained
2618
    /// as a map.
2619
    class ResidualCapacity {
1777 2620
    protected:
1778 2621
      const Adaptor* _adaptor;
1779 2622
    public:
2623
      /// The Key type
1780 2624
      typedef Arc Key;
2625
      /// The Value type
1781 2626
      typedef typename _CapacityMap::Value Value;
1782 2627

	
1783
      ResCap(const Adaptor& adaptor) : _adaptor(&adaptor) {}
1784
      
1785
      Value operator[](const Arc& e) const {
1786
        return _adaptor->rescap(e);
2628
      /// Constructor
2629
      ResidualCapacity(const Adaptor& adaptor) : _adaptor(&adaptor) {}
2630

	
2631
      /// \e
2632
      Value operator[](const Arc& a) const {
2633
        return _adaptor->residualCapacity(a);
1787 2634
      }
1788
      
2635

	
1789 2636
    };
1790 2637

	
1791 2638
  };
1792 2639

	
1793 2640
  template <typename _Digraph>
1794
  class SplitDigraphAdaptorBase {
2641
  class SplitNodesBase {
1795 2642
  public:
1796 2643

	
1797 2644
    typedef _Digraph Digraph;
1798 2645
    typedef DigraphAdaptorBase<const _Digraph> Parent;
1799
    typedef SplitDigraphAdaptorBase Adaptor;
2646
    typedef SplitNodesBase Adaptor;
1800 2647

	
1801 2648
    typedef typename Digraph::Node DigraphNode;
1802 2649
    typedef typename Digraph::Arc DigraphArc;
1803 2650

	
1804 2651
    class Node;
1805 2652
    class Arc;
1806 2653

	
1807 2654
  private:
1808 2655

	
1809 2656
    template <typename T> class NodeMapBase;
1810 2657
    template <typename T> class ArcMapBase;
1811 2658

	
1812 2659
  public:
1813
    
2660

	
1814 2661
    class Node : public DigraphNode {
1815
      friend class SplitDigraphAdaptorBase;
2662
      friend class SplitNodesBase;
1816 2663
      template <typename T> friend class NodeMapBase;
1817 2664
    private:
1818 2665

	
1819 2666
      bool _in;
1820 2667
      Node(DigraphNode node, bool in)
1821
	: DigraphNode(node), _in(in) {}
1822
      
2668
        : DigraphNode(node), _in(in) {}
2669

	
1823 2670
    public:
1824 2671

	
1825 2672
      Node() {}
1826 2673
      Node(Invalid) : DigraphNode(INVALID), _in(true) {}
1827 2674

	
1828 2675
      bool operator==(const Node& node) const {
1829
	return DigraphNode::operator==(node) && _in == node._in;
2676
        return DigraphNode::operator==(node) && _in == node._in;
1830 2677
      }
1831
      
2678

	
1832 2679
      bool operator!=(const Node& node) const {
1833
	return !(*this == node);
2680
        return !(*this == node);
1834 2681
      }
1835
      
2682

	
1836 2683
      bool operator<(const Node& node) const {
1837
	return DigraphNode::operator<(node) || 
1838
	  (DigraphNode::operator==(node) && _in < node._in);
2684
        return DigraphNode::operator<(node) ||
2685
          (DigraphNode::operator==(node) && _in < node._in);
1839 2686
      }
1840 2687
    };
1841 2688

	
1842 2689
    class Arc {
1843
      friend class SplitDigraphAdaptorBase;
2690
      friend class SplitNodesBase;
1844 2691
      template <typename T> friend class ArcMapBase;
1845 2692
    private:
1846 2693
      typedef BiVariant<DigraphArc, DigraphNode> ArcImpl;
1847 2694

	
1848 2695
      explicit Arc(const DigraphArc& arc) : _item(arc) {}
1849 2696
      explicit Arc(const DigraphNode& node) : _item(node) {}
1850
      
2697

	
1851 2698
      ArcImpl _item;
1852 2699

	
1853 2700
    public:
1854 2701
      Arc() {}
1855 2702
      Arc(Invalid) : _item(DigraphArc(INVALID)) {}
1856 2703

	
1857 2704
      bool operator==(const Arc& arc) const {
1858 2705
        if (_item.firstState()) {
1859 2706
          if (arc._item.firstState()) {
1860 2707
            return _item.first() == arc._item.first();
1861 2708
          }
1862 2709
        } else {
1863 2710
          if (arc._item.secondState()) {
1864 2711
            return _item.second() == arc._item.second();
1865 2712
          }
1866 2713
        }
1867 2714
        return false;
1868 2715
      }
1869
      
2716

	
1870 2717
      bool operator!=(const Arc& arc) const {
1871
	return !(*this == arc);
2718
        return !(*this == arc);
1872 2719
      }
1873
      
2720

	
1874 2721
      bool operator<(const Arc& arc) const {
1875 2722
        if (_item.firstState()) {
1876 2723
          if (arc._item.firstState()) {
1877 2724
            return _item.first() < arc._item.first();
1878 2725
          }
1879 2726
          return false;
1880 2727
        } else {
1881 2728
          if (arc._item.secondState()) {
1882 2729
            return _item.second() < arc._item.second();
1883 2730
          }
1884 2731
          return true;
1885 2732
        }
1886 2733
      }
1887 2734

	
1888 2735
      operator DigraphArc() const { return _item.first(); }
1889 2736
      operator DigraphNode() const { return _item.second(); }
1890 2737

	
1891 2738
    };
1892 2739

	
1893 2740
    void first(Node& n) const {
1894 2741
      _digraph->first(n);
1895 2742
      n._in = true;
1896 2743
    }
1897 2744

	
1898 2745
    void next(Node& n) const {
1899 2746
      if (n._in) {
1900
	n._in = false;
2747
        n._in = false;
1901 2748
      } else {
1902
	n._in = true;
1903
	_digraph->next(n);
2749
        n._in = true;
2750
        _digraph->next(n);
1904 2751
      }
1905 2752
    }
1906 2753

	
1907 2754
    void first(Arc& e) const {
1908 2755
      e._item.setSecond();
1909 2756
      _digraph->first(e._item.second());
1910 2757
      if (e._item.second() == INVALID) {
1911 2758
        e._item.setFirst();
1912
	_digraph->first(e._item.first());
2759
        _digraph->first(e._item.first());
1913 2760
      }
1914 2761
    }
1915 2762

	
1916 2763
    void next(Arc& e) const {
1917 2764
      if (e._item.secondState()) {
1918
	_digraph->next(e._item.second());
2765
        _digraph->next(e._item.second());
1919 2766
        if (e._item.second() == INVALID) {
1920 2767
          e._item.setFirst();
1921 2768
          _digraph->first(e._item.first());
1922 2769
        }
1923 2770
      } else {
1924
	_digraph->next(e._item.first());
1925
      }      
2771
        _digraph->next(e._item.first());
2772
      }
1926 2773
    }
1927 2774

	
1928 2775
    void firstOut(Arc& e, const Node& n) const {
1929 2776
      if (n._in) {
1930 2777
        e._item.setSecond(n);
1931 2778
      } else {
1932 2779
        e._item.setFirst();
1933
	_digraph->firstOut(e._item.first(), n);
2780
        _digraph->firstOut(e._item.first(), n);
1934 2781
      }
1935 2782
    }
1936 2783

	
1937 2784
    void nextOut(Arc& e) const {
1938 2785
      if (!e._item.firstState()) {
1939
	e._item.setFirst(INVALID);
2786
        e._item.setFirst(INVALID);
1940 2787
      } else {
1941
	_digraph->nextOut(e._item.first());
1942
      }      
2788
        _digraph->nextOut(e._item.first());
2789
      }
1943 2790
    }
1944 2791

	
1945 2792
    void firstIn(Arc& e, const Node& n) const {
1946 2793
      if (!n._in) {
1947
        e._item.setSecond(n);        
2794
        e._item.setSecond(n);
1948 2795
      } else {
1949 2796
        e._item.setFirst();
1950
	_digraph->firstIn(e._item.first(), n);
2797
        _digraph->firstIn(e._item.first(), n);
1951 2798
      }
1952 2799
    }
1953 2800

	
1954 2801
    void nextIn(Arc& e) const {
1955 2802
      if (!e._item.firstState()) {
1956
	e._item.setFirst(INVALID);
2803
        e._item.setFirst(INVALID);
1957 2804
      } else {
1958
	_digraph->nextIn(e._item.first());
2805
        _digraph->nextIn(e._item.first());
1959 2806
      }
1960 2807
    }
1961 2808

	
1962 2809
    Node source(const Arc& e) const {
1963 2810
      if (e._item.firstState()) {
1964
	return Node(_digraph->source(e._item.first()), false);
2811
        return Node(_digraph->source(e._item.first()), false);
1965 2812
      } else {
1966
	return Node(e._item.second(), true);
2813
        return Node(e._item.second(), true);
1967 2814
      }
1968 2815
    }
1969 2816

	
1970 2817
    Node target(const Arc& e) const {
1971 2818
      if (e._item.firstState()) {
1972
	return Node(_digraph->target(e._item.first()), true);
2819
        return Node(_digraph->target(e._item.first()), true);
1973 2820
      } else {
1974
	return Node(e._item.second(), false);
2821
        return Node(e._item.second(), false);
1975 2822
      }
1976 2823
    }
1977 2824

	
1978 2825
    int id(const Node& n) const {
1979 2826
      return (_digraph->id(n) << 1) | (n._in ? 0 : 1);
1980 2827
    }
1981 2828
    Node nodeFromId(int ix) const {
1982 2829
      return Node(_digraph->nodeFromId(ix >> 1), (ix & 1) == 0);
1983 2830
    }
1984 2831
    int maxNodeId() const {
1985 2832
      return 2 * _digraph->maxNodeId() + 1;
1986 2833
    }
1987 2834

	
1988 2835
    int id(const Arc& e) const {
1989 2836
      if (e._item.firstState()) {
1990 2837
        return _digraph->id(e._item.first()) << 1;
1991 2838
      } else {
1992 2839
        return (_digraph->id(e._item.second()) << 1) | 1;
1993 2840
      }
1994 2841
    }
1995 2842
    Arc arcFromId(int ix) const {
1996 2843
      if ((ix & 1) == 0) {
1997 2844
        return Arc(_digraph->arcFromId(ix >> 1));
1998 2845
      } else {
1999 2846
        return Arc(_digraph->nodeFromId(ix >> 1));
2000 2847
      }
2001 2848
    }
2002 2849
    int maxArcId() const {
2003
      return std::max(_digraph->maxNodeId() << 1, 
2850
      return std::max(_digraph->maxNodeId() << 1,
2004 2851
                      (_digraph->maxArcId() << 1) | 1);
2005 2852
    }
2006 2853

	
2007 2854
    static bool inNode(const Node& n) {
2008 2855
      return n._in;
2009 2856
    }
2010 2857

	
2011 2858
    static bool outNode(const Node& n) {
2012 2859
      return !n._in;
2013 2860
    }
2014 2861

	
2015 2862
    static bool origArc(const Arc& e) {
2016 2863
      return e._item.firstState();
2017 2864
    }
2018 2865

	
2019 2866
    static bool bindArc(const Arc& e) {
2020 2867
      return e._item.secondState();
2021 2868
    }
2022 2869

	
2023 2870
    static Node inNode(const DigraphNode& n) {
2024 2871
      return Node(n, true);
2025 2872
    }
2026 2873

	
2027 2874
    static Node outNode(const DigraphNode& n) {
2028 2875
      return Node(n, false);
2029 2876
    }
2030 2877

	
2031 2878
    static Arc arc(const DigraphNode& n) {
2032 2879
      return Arc(n);
2033 2880
    }
2034 2881

	
2035 2882
    static Arc arc(const DigraphArc& e) {
2036 2883
      return Arc(e);
2037 2884
    }
2038 2885

	
2039 2886
    typedef True NodeNumTag;
2040 2887

	
2041 2888
    int nodeNum() const {
2042 2889
      return  2 * countNodes(*_digraph);
2043 2890
    }
2044 2891

	
2045 2892
    typedef True EdgeNumTag;
2046 2893
    int arcNum() const {
2047 2894
      return countArcs(*_digraph) + countNodes(*_digraph);
2048 2895
    }
2049 2896

	
2050 2897
    typedef True FindEdgeTag;
2051
    Arc findArc(const Node& u, const Node& v, 
2052
		const Arc& prev = INVALID) const {
2898
    Arc findArc(const Node& u, const Node& v,
2899
                const Arc& prev = INVALID) const {
2053 2900
      if (inNode(u)) {
2054 2901
        if (outNode(v)) {
2055
          if (static_cast<const DigraphNode&>(u) == 
2902
          if (static_cast<const DigraphNode&>(u) ==
2056 2903
              static_cast<const DigraphNode&>(v) && prev == INVALID) {
2057 2904
            return Arc(u);
2058 2905
          }
2059 2906
        }
2060 2907
      } else {
2061 2908
        if (inNode(v)) {
2062 2909
          return Arc(::lemon::findArc(*_digraph, u, v, prev));
2063 2910
        }
2064 2911
      }
2065 2912
      return INVALID;
2066 2913
    }
2067 2914

	
2068 2915
  private:
2069
    
2916

	
2070 2917
    template <typename _Value>
2071
    class NodeMapBase 
2918
    class NodeMapBase
2072 2919
      : public MapTraits<typename Parent::template NodeMap<_Value> > {
2073 2920
      typedef typename Parent::template NodeMap<_Value> NodeImpl;
2074 2921
    public:
2075 2922
      typedef Node Key;
2076 2923
      typedef _Value Value;
2077
      
2078
      NodeMapBase(const Adaptor& adaptor) 
2079
	: _in_map(*adaptor._digraph), _out_map(*adaptor._digraph) {}
2080
      NodeMapBase(const Adaptor& adaptor, const Value& value) 
2081
	: _in_map(*adaptor._digraph, value), 
2082
	  _out_map(*adaptor._digraph, value) {}
2924

	
2925
      NodeMapBase(const Adaptor& adaptor)
2926
        : _in_map(*adaptor._digraph), _out_map(*adaptor._digraph) {}
2927
      NodeMapBase(const Adaptor& adaptor, const Value& value)
2928
        : _in_map(*adaptor._digraph, value),
2929
          _out_map(*adaptor._digraph, value) {}
2083 2930

	
2084 2931
      void set(const Node& key, const Value& val) {
2085
	if (Adaptor::inNode(key)) { _in_map.set(key, val); }
2086
	else {_out_map.set(key, val); }
2932
        if (Adaptor::inNode(key)) { _in_map.set(key, val); }
2933
        else {_out_map.set(key, val); }
2087 2934
      }
2088
      
2089
      typename MapTraits<NodeImpl>::ReturnValue 
2935

	
2936
      typename MapTraits<NodeImpl>::ReturnValue
2090 2937
      operator[](const Node& key) {
2091
	if (Adaptor::inNode(key)) { return _in_map[key]; }
2092
	else { return _out_map[key]; }
2938
        if (Adaptor::inNode(key)) { return _in_map[key]; }
2939
        else { return _out_map[key]; }
2093 2940
      }
2094 2941

	
2095 2942
      typename MapTraits<NodeImpl>::ConstReturnValue
2096 2943
      operator[](const Node& key) const {
2097
	if (Adaptor::inNode(key)) { return _in_map[key]; }
2098
	else { return _out_map[key]; }
2944
        if (Adaptor::inNode(key)) { return _in_map[key]; }
2945
        else { return _out_map[key]; }
2099 2946
      }
2100 2947

	
2101 2948
    private:
2102 2949
      NodeImpl _in_map, _out_map;
2103 2950
    };
2104 2951

	
2105 2952
    template <typename _Value>
2106
    class ArcMapBase 
2953
    class ArcMapBase
2107 2954
      : public MapTraits<typename Parent::template ArcMap<_Value> > {
2108 2955
      typedef typename Parent::template ArcMap<_Value> ArcImpl;
2109 2956
      typedef typename Parent::template NodeMap<_Value> NodeImpl;
2110 2957
    public:
2111 2958
      typedef Arc Key;
2112 2959
      typedef _Value Value;
2113 2960

	
2114
      ArcMapBase(const Adaptor& adaptor) 
2115
	: _arc_map(*adaptor._digraph), _node_map(*adaptor._digraph) {}
2116
      ArcMapBase(const Adaptor& adaptor, const Value& value) 
2117
	: _arc_map(*adaptor._digraph, value), 
2118
	  _node_map(*adaptor._digraph, value) {}
2961
      ArcMapBase(const Adaptor& adaptor)
2962
        : _arc_map(*adaptor._digraph), _node_map(*adaptor._digraph) {}
2963
      ArcMapBase(const Adaptor& adaptor, const Value& value)
2964
        : _arc_map(*adaptor._digraph, value),
2965
          _node_map(*adaptor._digraph, value) {}
2119 2966

	
2120 2967
      void set(const Arc& key, const Value& val) {
2121
	if (Adaptor::origArc(key)) { 
2122
          _arc_map.set(key._item.first(), val); 
2968
        if (Adaptor::origArc(key)) {
2969
          _arc_map.set(key._item.first(), val);
2123 2970
        } else {
2124
          _node_map.set(key._item.second(), val); 
2971
          _node_map.set(key._item.second(), val);
2125 2972
        }
2126 2973
      }
2127
      
2974

	
2128 2975
      typename MapTraits<ArcImpl>::ReturnValue
2129 2976
      operator[](const Arc& key) {
2130
	if (Adaptor::origArc(key)) { 
2977
        if (Adaptor::origArc(key)) {
2131 2978
          return _arc_map[key._item.first()];
2132 2979
        } else {
2133 2980
          return _node_map[key._item.second()];
2134 2981
        }
2135 2982
      }
2136 2983

	
2137 2984
      typename MapTraits<ArcImpl>::ConstReturnValue
2138 2985
      operator[](const Arc& key) const {
2139
	if (Adaptor::origArc(key)) { 
2986
        if (Adaptor::origArc(key)) {
2140 2987
          return _arc_map[key._item.first()];
2141 2988
        } else {
2142 2989
          return _node_map[key._item.second()];
2143 2990
        }
2144 2991
      }
2145 2992

	
2146 2993
    private:
2147 2994
      ArcImpl _arc_map;
2148 2995
      NodeImpl _node_map;
2149 2996
    };
2150 2997

	
2151 2998
  public:
2152 2999

	
2153 3000
    template <typename _Value>
2154
    class NodeMap 
2155
      : public SubMapExtender<Adaptor, NodeMapBase<_Value> > 
3001
    class NodeMap
3002
      : public SubMapExtender<Adaptor, NodeMapBase<_Value> >
2156 3003
    {
2157 3004
    public:
2158 3005
      typedef _Value Value;
2159 3006
      typedef SubMapExtender<Adaptor, NodeMapBase<Value> > Parent;
2160
    
2161
      NodeMap(const Adaptor& adaptor) 
2162
	: Parent(adaptor) {}
2163

	
2164
      NodeMap(const Adaptor& adaptor, const Value& value) 
2165
	: Parent(adaptor, value) {}
2166
    
3007

	
3008
      NodeMap(const Adaptor& adaptor)
3009
        : Parent(adaptor) {}
3010

	
3011
      NodeMap(const Adaptor& adaptor, const Value& value)
3012
        : Parent(adaptor, value) {}
3013

	
2167 3014
    private:
2168 3015
      NodeMap& operator=(const NodeMap& cmap) {
2169
	return operator=<NodeMap>(cmap);
3016
        return operator=<NodeMap>(cmap);
2170 3017
      }
2171
    
3018

	
2172 3019
      template <typename CMap>
2173 3020
      NodeMap& operator=(const CMap& cmap) {
2174 3021
        Parent::operator=(cmap);
2175
	return *this;
3022
        return *this;
2176 3023
      }
2177 3024
    };
2178 3025

	
2179 3026
    template <typename _Value>
2180
    class ArcMap 
2181
      : public SubMapExtender<Adaptor, ArcMapBase<_Value> > 
3027
    class ArcMap
3028
      : public SubMapExtender<Adaptor, ArcMapBase<_Value> >
2182 3029
    {
2183 3030
    public:
2184 3031
      typedef _Value Value;
2185 3032
      typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
2186
    
2187
      ArcMap(const Adaptor& adaptor) 
2188
	: Parent(adaptor) {}
2189

	
2190
      ArcMap(const Adaptor& adaptor, const Value& value) 
2191
	: Parent(adaptor, value) {}
2192
    
3033

	
3034
      ArcMap(const Adaptor& adaptor)
3035
        : Parent(adaptor) {}
3036

	
3037
      ArcMap(const Adaptor& adaptor, const Value& value)
3038
        : Parent(adaptor, value) {}
3039

	
2193 3040
    private:
2194 3041
      ArcMap& operator=(const ArcMap& cmap) {
2195
	return operator=<ArcMap>(cmap);
3042
        return operator=<ArcMap>(cmap);
2196 3043
      }
2197
    
3044

	
2198 3045
      template <typename CMap>
2199 3046
      ArcMap& operator=(const CMap& cmap) {
2200 3047
        Parent::operator=(cmap);
2201
	return *this;
3048
        return *this;
2202 3049
      }
2203 3050
    };
2204 3051

	
2205 3052
  protected:
2206 3053

	
2207
    SplitDigraphAdaptorBase() : _digraph(0) {}
3054
    SplitNodesBase() : _digraph(0) {}
2208 3055

	
2209 3056
    Digraph* _digraph;
2210 3057

	
2211 3058
    void setDigraph(Digraph& digraph) {
2212 3059
      _digraph = &digraph;
2213 3060
    }
2214
    
3061

	
2215 3062
  };
2216 3063

	
2217 3064
  /// \ingroup graph_adaptors
2218 3065
  ///
2219
  /// \brief Split digraph adaptor class
2220
  /// 
2221
  /// This is an digraph adaptor which splits all node into an in-node
2222
  /// and an out-node. Formaly, the adaptor replaces each \f$ u \f$
2223
  /// node in the digraph with two node, \f$ u_{in} \f$ node and 
2224
  /// \f$ u_{out} \f$ node. If there is an \f$ (v, u) \f$ arc in the 
2225
  /// original digraph the new target of the arc will be \f$ u_{in} \f$ and
2226
  /// similarly the source of the original \f$ (u, v) \f$ arc will be
2227
  /// \f$ u_{out} \f$.  The adaptor will add for each node in the 
2228
  /// original digraph an additional arc which will connect 
3066
  /// \brief Split the nodes of a directed graph
3067
  ///
3068
  /// The SplitNodes adaptor splits each node into an in-node and an
3069
  /// out-node. Formaly, the adaptor replaces each \f$ u \f$ node in
3070
  /// the digraph with two nodes(namely node \f$ u_{in} \f$ and node
3071
  /// \f$ u_{out} \f$). If there is a \f$ (v, u) \f$ arc in the
3072
  /// original digraph the new target of the arc will be \f$ u_{in} \f$
3073
  /// and similarly the source of the original \f$ (u, v) \f$ arc
3074
  /// will be \f$ u_{out} \f$.  The adaptor will add for each node in
3075
  /// the original digraph an additional arc which connects
2229 3076
  /// \f$ (u_{in}, u_{out}) \f$.
2230 3077
  ///
2231
  /// The aim of this class is to run algorithm with node costs if the 
3078
  /// The aim of this class is to run algorithm with node costs if the
2232 3079
  /// algorithm can use directly just arc costs. In this case we should use
2233
  /// a \c SplitDigraphAdaptor and set the node cost of the digraph to the
2234
  /// bind arc in the adapted digraph.
2235
  /// 
2236
  /// For example a maximum flow algorithm can compute how many arc
2237
  /// disjoint paths are in the digraph. But we would like to know how
2238
  /// many node disjoint paths are in the digraph. First we have to
2239
  /// adapt the digraph with the \c SplitDigraphAdaptor. Then run the flow
2240
  /// algorithm on the adapted digraph. The bottleneck of the flow will
2241
  /// be the bind arcs which bounds the flow with the count of the
2242
  /// node disjoint paths.
3080
  /// a \c SplitNodes and set the node cost of the graph to the
3081
  /// bind arc in the adapted graph.
2243 3082
  ///
2244
  ///\code
2245
  ///
2246
  /// typedef SplitDigraphAdaptor<SmartDigraph> SDigraph;
2247
  ///
2248
  /// SDigraph sdigraph(digraph);
2249
  ///
2250
  /// typedef ConstMap<SDigraph::Arc, int> SCapacity;
2251
  /// SCapacity scapacity(1);
2252
  ///
2253
  /// SDigraph::ArcMap<int> sflow(sdigraph);
2254
  ///
2255
  /// Preflow<SDigraph, SCapacity> 
2256
  ///   spreflow(sdigraph, scapacity, 
2257
  ///            SDigraph::outNode(source), SDigraph::inNode(target));
2258
  ///                                            
2259
  /// spreflow.run();
2260
  ///
2261
  ///\endcode
2262
  ///
2263
  /// The result of the mamixum flow on the original digraph
2264
  /// shows the next figure:
2265
  ///
2266
  /// \image html arc_disjoint.png
2267
  /// \image latex arc_disjoint.eps "Arc disjoint paths" width=\textwidth
2268
  /// 
2269
  /// And the maximum flow on the adapted digraph:
2270
  ///
2271
  /// \image html node_disjoint.png
2272
  /// \image latex node_disjoint.eps "Node disjoint paths" width=\textwidth
2273
  ///
2274
  /// The second solution contains just 3 disjoint paths while the first 4.
2275
  /// The full code can be found in the \ref disjoint_paths_demo.cc demo file.
2276
  ///
2277
  /// This digraph adaptor is fully conform to the 
2278
  /// \ref concepts::Digraph "Digraph" concept and
2279
  /// contains some additional member functions and types. The 
2280
  /// documentation of some member functions may be found just in the
2281
  /// SplitDigraphAdaptorBase class.
2282
  ///
2283
  /// \sa SplitDigraphAdaptorBase
3083
  /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
3084
  /// "Digraph concept". The type can be specified to be const.
2284 3085
  template <typename _Digraph>
2285
  class SplitDigraphAdaptor 
2286
    : public DigraphAdaptorExtender<SplitDigraphAdaptorBase<_Digraph> > {
3086
  class SplitNodes
3087
    : public DigraphAdaptorExtender<SplitNodesBase<_Digraph> > {
2287 3088
  public:
2288 3089
    typedef _Digraph Digraph;
2289
    typedef DigraphAdaptorExtender<SplitDigraphAdaptorBase<Digraph> > Parent;
3090
    typedef DigraphAdaptorExtender<SplitNodesBase<Digraph> > Parent;
2290 3091

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

	
2294 3095
    typedef typename Parent::Node Node;
2295 3096
    typedef typename Parent::Arc Arc;
2296 3097

	
2297 3098
    /// \brief Constructor of the adaptor.
2298 3099
    ///
2299 3100
    /// Constructor of the adaptor.
2300
    SplitDigraphAdaptor(Digraph& g) {
3101
    SplitNodes(Digraph& g) {
2301 3102
      Parent::setDigraph(g);
2302 3103
    }
2303 3104

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

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

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

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

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

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

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

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

	
2360 3161
    /// \brief NodeMap combined from two original NodeMap
2361 3162
    ///
2362 3163
    /// This class adapt two of the original digraph NodeMap to
2363 3164
    /// get a node map on the adapted digraph.
2364 3165
    template <typename InNodeMap, typename OutNodeMap>
2365 3166
    class CombinedNodeMap {
2366 3167
    public:
2367 3168

	
2368 3169
      typedef Node Key;
2369 3170
      typedef typename InNodeMap::Value Value;
2370 3171

	
2371 3172
      /// \brief Constructor
2372 3173
      ///
2373 3174
      /// Constructor.
2374
      CombinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) 
2375
	: _in_map(in_map), _out_map(out_map) {}
3175
      CombinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map)
3176
        : _in_map(in_map), _out_map(out_map) {}
2376 3177

	
2377 3178
      /// \brief The subscript operator.
2378 3179
      ///
2379 3180
      /// The subscript operator.
2380 3181
      Value& operator[](const Key& key) {
2381
	if (Parent::inNode(key)) {
2382
	  return _in_map[key];
2383
	} else {
2384
	  return _out_map[key];
2385
	}
3182
        if (Parent::inNode(key)) {
3183
          return _in_map[key];
3184
        } else {
3185
          return _out_map[key];
3186
        }
2386 3187
      }
2387 3188

	
2388 3189
      /// \brief The const subscript operator.
2389 3190
      ///
2390 3191
      /// The const subscript operator.
2391 3192
      Value operator[](const Key& key) const {
2392
	if (Parent::inNode(key)) {
2393
	  return _in_map[key];
2394
	} else {
2395
	  return _out_map[key];
2396
	}
3193
        if (Parent::inNode(key)) {
3194
          return _in_map[key];
3195
        } else {
3196
          return _out_map[key];
3197
        }
2397 3198
      }
2398 3199

	
2399 3200
      /// \brief The setter function of the map.
2400
      /// 
3201
      ///
2401 3202
      /// The setter function of the map.
2402 3203
      void set(const Key& key, const Value& value) {
2403
	if (Parent::inNode(key)) {
2404
	  _in_map.set(key, value);
2405
	} else {
2406
	  _out_map.set(key, value);
2407
	}
3204
        if (Parent::inNode(key)) {
3205
          _in_map.set(key, value);
3206
        } else {
3207
          _out_map.set(key, value);
3208
        }
2408 3209
      }
2409
      
3210

	
2410 3211
    private:
2411
      
3212

	
2412 3213
      InNodeMap& _in_map;
2413 3214
      OutNodeMap& _out_map;
2414
      
3215

	
2415 3216
    };
2416 3217

	
2417 3218

	
2418
    /// \brief Just gives back a combined node map.
2419
    /// 
2420
    /// Just gives back a combined node map.
3219
    /// \brief Just gives back a combined node map
3220
    ///
3221
    /// Just gives back a combined node map
2421 3222
    template <typename InNodeMap, typename OutNodeMap>
2422
    static CombinedNodeMap<InNodeMap, OutNodeMap> 
3223
    static CombinedNodeMap<InNodeMap, OutNodeMap>
2423 3224
    combinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) {
2424 3225
      return CombinedNodeMap<InNodeMap, OutNodeMap>(in_map, out_map);
2425 3226
    }
2426 3227

	
2427 3228
    template <typename InNodeMap, typename OutNodeMap>
2428
    static CombinedNodeMap<const InNodeMap, OutNodeMap> 
3229
    static CombinedNodeMap<const InNodeMap, OutNodeMap>
2429 3230
    combinedNodeMap(const InNodeMap& in_map, OutNodeMap& out_map) {
2430 3231
      return CombinedNodeMap<const InNodeMap, OutNodeMap>(in_map, out_map);
2431 3232
    }
2432 3233

	
2433 3234
    template <typename InNodeMap, typename OutNodeMap>
2434
    static CombinedNodeMap<InNodeMap, const OutNodeMap> 
3235
    static CombinedNodeMap<InNodeMap, const OutNodeMap>
2435 3236
    combinedNodeMap(InNodeMap& in_map, const OutNodeMap& out_map) {
2436 3237
      return CombinedNodeMap<InNodeMap, const OutNodeMap>(in_map, out_map);
2437 3238
    }
2438 3239

	
2439 3240
    template <typename InNodeMap, typename OutNodeMap>
2440
    static CombinedNodeMap<const InNodeMap, const OutNodeMap> 
3241
    static CombinedNodeMap<const InNodeMap, const OutNodeMap>
2441 3242
    combinedNodeMap(const InNodeMap& in_map, const OutNodeMap& out_map) {
2442
      return CombinedNodeMap<const InNodeMap, 
3243
      return CombinedNodeMap<const InNodeMap,
2443 3244
        const OutNodeMap>(in_map, out_map);
2444 3245
    }
2445 3246

	
2446
    /// \brief ArcMap combined from an original ArcMap and NodeMap
3247
    /// \brief ArcMap combined from an original ArcMap and a NodeMap
2447 3248
    ///
2448
    /// This class adapt an original digraph ArcMap and NodeMap to
2449
    /// get an arc map on the adapted digraph.
3249
    /// This class adapt an original ArcMap and a NodeMap to get an
3250
    /// arc map on the adapted digraph
2450 3251
    template <typename DigraphArcMap, typename DigraphNodeMap>
2451 3252
    class CombinedArcMap {
2452 3253
    public:
2453
      
3254

	
2454 3255
      typedef Arc Key;
2455 3256
      typedef typename DigraphArcMap::Value Value;
2456
      
3257

	
2457 3258
      /// \brief Constructor
2458 3259
      ///
2459 3260
      /// Constructor.
2460
      CombinedArcMap(DigraphArcMap& arc_map, DigraphNodeMap& node_map) 
2461
	: _arc_map(arc_map), _node_map(node_map) {}
3261
      CombinedArcMap(DigraphArcMap& arc_map, DigraphNodeMap& node_map)
3262
        : _arc_map(arc_map), _node_map(node_map) {}
2462 3263

	
2463 3264
      /// \brief The subscript operator.
2464 3265
      ///
2465 3266
      /// The subscript operator.
2466 3267
      void set(const Arc& arc, const Value& val) {
2467
	if (Parent::origArc(arc)) {
2468
	  _arc_map.set(arc, val);
2469
	} else {
2470
	  _node_map.set(arc, val);
2471
	}
3268
        if (Parent::origArc(arc)) {
3269
          _arc_map.set(arc, val);
3270
        } else {
3271
          _node_map.set(arc, val);
3272
        }
2472 3273
      }
2473 3274

	
2474 3275
      /// \brief The const subscript operator.
2475 3276
      ///
2476 3277
      /// The const subscript operator.
2477 3278
      Value operator[](const Key& arc) const {
2478
	if (Parent::origArc(arc)) {
2479
	  return _arc_map[arc];
2480
	} else {
2481
	  return _node_map[arc];
2482
	}
2483
      }      
3279
        if (Parent::origArc(arc)) {
3280
          return _arc_map[arc];
3281
        } else {
3282
          return _node_map[arc];
3283
        }
3284
      }
2484 3285

	
2485 3286
      /// \brief The const subscript operator.
2486 3287
      ///
2487 3288
      /// The const subscript operator.
2488 3289
      Value& operator[](const Key& arc) {
2489
	if (Parent::origArc(arc)) {
2490
	  return _arc_map[arc];
2491
	} else {
2492
	  return _node_map[arc];
2493
	}
2494
      }      
2495
      
3290
        if (Parent::origArc(arc)) {
3291
          return _arc_map[arc];
3292
        } else {
3293
          return _node_map[arc];
3294
        }
3295
      }
3296

	
2496 3297
    private:
2497 3298
      DigraphArcMap& _arc_map;
2498 3299
      DigraphNodeMap& _node_map;
2499 3300
    };
2500
                    
2501
    /// \brief Just gives back a combined arc map.
2502
    /// 
2503
    /// Just gives back a combined arc map.
3301

	
3302
    /// \brief Just gives back a combined arc map
3303
    ///
3304
    /// Just gives back a combined arc map
2504 3305
    template <typename DigraphArcMap, typename DigraphNodeMap>
2505
    static CombinedArcMap<DigraphArcMap, DigraphNodeMap> 
3306
    static CombinedArcMap<DigraphArcMap, DigraphNodeMap>
2506 3307
    combinedArcMap(DigraphArcMap& arc_map, DigraphNodeMap& node_map) {
2507 3308
      return CombinedArcMap<DigraphArcMap, DigraphNodeMap>(arc_map, node_map);
2508 3309
    }
2509 3310

	
2510 3311
    template <typename DigraphArcMap, typename DigraphNodeMap>
2511
    static CombinedArcMap<const DigraphArcMap, DigraphNodeMap> 
3312
    static CombinedArcMap<const DigraphArcMap, DigraphNodeMap>
2512 3313
    combinedArcMap(const DigraphArcMap& arc_map, DigraphNodeMap& node_map) {
2513
      return CombinedArcMap<const DigraphArcMap, 
3314
      return CombinedArcMap<const DigraphArcMap,
2514 3315
        DigraphNodeMap>(arc_map, node_map);
2515 3316
    }
2516 3317

	
2517 3318
    template <typename DigraphArcMap, typename DigraphNodeMap>
2518
    static CombinedArcMap<DigraphArcMap, const DigraphNodeMap> 
3319
    static CombinedArcMap<DigraphArcMap, const DigraphNodeMap>
2519 3320
    combinedArcMap(DigraphArcMap& arc_map, const DigraphNodeMap& node_map) {
2520
      return CombinedArcMap<DigraphArcMap, 
3321
      return CombinedArcMap<DigraphArcMap,
2521 3322
        const DigraphNodeMap>(arc_map, node_map);
2522 3323
    }
2523 3324

	
2524 3325
    template <typename DigraphArcMap, typename DigraphNodeMap>
2525
    static CombinedArcMap<const DigraphArcMap, const DigraphNodeMap> 
2526
    combinedArcMap(const DigraphArcMap& arc_map, 
2527
                    const DigraphNodeMap& node_map) {
2528
      return CombinedArcMap<const DigraphArcMap, 
3326
    static CombinedArcMap<const DigraphArcMap, const DigraphNodeMap>
3327
    combinedArcMap(const DigraphArcMap& arc_map,
3328
                   const DigraphNodeMap& node_map) {
3329
      return CombinedArcMap<const DigraphArcMap,
2529 3330
        const DigraphNodeMap>(arc_map, node_map);
2530 3331
    }
2531 3332

	
2532 3333
  };
2533 3334

	
2534
  /// \brief Just gives back a split digraph adaptor
3335
  /// \brief Just gives back a node splitter
2535 3336
  ///
2536
  /// Just gives back a split digraph adaptor
3337
  /// Just gives back a node splitter
2537 3338
  template<typename Digraph>
2538
  SplitDigraphAdaptor<Digraph>
2539
  splitDigraphAdaptor(const Digraph& digraph) {
2540
    return SplitDigraphAdaptor<Digraph>(digraph);
3339
  SplitNodes<Digraph>
3340
  splitNodes(const Digraph& digraph) {
3341
    return SplitNodes<Digraph>(digraph);
2541 3342
  }
2542 3343

	
2543 3344

	
2544 3345
} //namespace lemon
2545 3346

	
2546
#endif //LEMON_DIGRAPH_ADAPTOR_H
2547

	
3347
#endif //LEMON_ADAPTORS_H
1
/* -*- C++ -*-
1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3
 * This file is a part of LEMON, a generic C++ optimization library
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_BITS_GRAPH_ADAPTOR_EXTENDER_H
20 20
#define LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H
21 21

	
22 22
#include <lemon/core.h>
23 23
#include <lemon/error.h>
24 24

	
25 25
#include <lemon/bits/default_map.h>
26 26

	
27

	
28
///\ingroup digraphbits
29
///\file
30
///\brief Extenders for the digraph adaptor types
31 27
namespace lemon {
32 28

	
33
  /// \ingroup digraphbits
34
  ///
35
  /// \brief Extender for the DigraphAdaptors
36 29
  template <typename _Digraph>
37 30
  class DigraphAdaptorExtender : public _Digraph {
38 31
  public:
39 32

	
40 33
    typedef _Digraph Parent;
41 34
    typedef _Digraph Digraph;
42 35
    typedef DigraphAdaptorExtender Adaptor;
43 36

	
44 37
    // Base extensions
45 38

	
46 39
    typedef typename Parent::Node Node;
47 40
    typedef typename Parent::Arc Arc;
48 41

	
49 42
    int maxId(Node) const {
50 43
      return Parent::maxNodeId();
51 44
    }
52 45

	
53 46
    int maxId(Arc) const {
54 47
      return Parent::maxArcId();
55 48
    }
56 49

	
57 50
    Node fromId(int id, Node) const {
58 51
      return Parent::nodeFromId(id);
59 52
    }
60 53

	
61 54
    Arc fromId(int id, Arc) const {
62 55
      return Parent::arcFromId(id);
63 56
    }
64 57

	
65 58
    Node oppositeNode(const Node &n, const Arc &e) const {
66 59
      if (n == Parent::source(e))
67
	return Parent::target(e);
60
        return Parent::target(e);
68 61
      else if(n==Parent::target(e))
69
	return Parent::source(e);
62
        return Parent::source(e);
70 63
      else
71
	return INVALID;
64
        return INVALID;
72 65
    }
73 66

	
74
    class NodeIt : public Node { 
67
    class NodeIt : public Node {
75 68
      const Adaptor* _adaptor;
76 69
    public:
77 70

	
78 71
      NodeIt() {}
79 72

	
80 73
      NodeIt(Invalid i) : Node(i) { }
81 74

	
82 75
      explicit NodeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
83
	_adaptor->first(static_cast<Node&>(*this));
76
        _adaptor->first(static_cast<Node&>(*this));
84 77
      }
85 78

	
86
      NodeIt(const Adaptor& adaptor, const Node& node) 
87
	: Node(node), _adaptor(&adaptor) {}
79
      NodeIt(const Adaptor& adaptor, const Node& node)
80
        : Node(node), _adaptor(&adaptor) {}
88 81

	
89
      NodeIt& operator++() { 
90
	_adaptor->next(*this);
91
	return *this; 
82
      NodeIt& operator++() {
83
        _adaptor->next(*this);
84
        return *this;
92 85
      }
93 86

	
94 87
    };
95 88

	
96 89

	
97
    class ArcIt : public Arc { 
90
    class ArcIt : public Arc {
98 91
      const Adaptor* _adaptor;
99 92
    public:
100 93

	
101 94
      ArcIt() { }
102 95

	
103 96
      ArcIt(Invalid i) : Arc(i) { }
104 97

	
105 98
      explicit ArcIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
106
	_adaptor->first(static_cast<Arc&>(*this));
99
        _adaptor->first(static_cast<Arc&>(*this));
107 100
      }
108 101

	
109
      ArcIt(const Adaptor& adaptor, const Arc& e) : 
110
	Arc(e), _adaptor(&adaptor) { }
102
      ArcIt(const Adaptor& adaptor, const Arc& e) :
103
        Arc(e), _adaptor(&adaptor) { }
111 104

	
112
      ArcIt& operator++() { 
113
	_adaptor->next(*this);
114
	return *this; 
105
      ArcIt& operator++() {
106
        _adaptor->next(*this);
107
        return *this;
115 108
      }
116 109

	
117 110
    };
118 111

	
119 112

	
120
    class OutArcIt : public Arc { 
113
    class OutArcIt : public Arc {
121 114
      const Adaptor* _adaptor;
122 115
    public:
123 116

	
124 117
      OutArcIt() { }
125 118

	
126 119
      OutArcIt(Invalid i) : Arc(i) { }
127 120

	
128
      OutArcIt(const Adaptor& adaptor, const Node& node) 
129
	: _adaptor(&adaptor) {
130
	_adaptor->firstOut(*this, node);
121
      OutArcIt(const Adaptor& adaptor, const Node& node)
122
        : _adaptor(&adaptor) {
123
        _adaptor->firstOut(*this, node);
131 124
      }
132 125

	
133
      OutArcIt(const Adaptor& adaptor, const Arc& arc) 
134
	: Arc(arc), _adaptor(&adaptor) {}
126
      OutArcIt(const Adaptor& adaptor, const Arc& arc)
127
        : Arc(arc), _adaptor(&adaptor) {}
135 128

	
136
      OutArcIt& operator++() { 
137
	_adaptor->nextOut(*this);
138
	return *this; 
129
      OutArcIt& operator++() {
130
        _adaptor->nextOut(*this);
131
        return *this;
139 132
      }
140 133

	
141 134
    };
142 135

	
143 136

	
144
    class InArcIt : public Arc { 
137
    class InArcIt : public Arc {
145 138
      const Adaptor* _adaptor;
146 139
    public:
147 140

	
148 141
      InArcIt() { }
149 142

	
150 143
      InArcIt(Invalid i) : Arc(i) { }
151 144

	
152
      InArcIt(const Adaptor& adaptor, const Node& node) 
153
	: _adaptor(&adaptor) {
154
	_adaptor->firstIn(*this, node);
145
      InArcIt(const Adaptor& adaptor, const Node& node)
146
        : _adaptor(&adaptor) {
147
        _adaptor->firstIn(*this, node);
155 148
      }
156 149

	
157
      InArcIt(const Adaptor& adaptor, const Arc& arc) : 
158
	Arc(arc), _adaptor(&adaptor) {}
150
      InArcIt(const Adaptor& adaptor, const Arc& arc) :
151
        Arc(arc), _adaptor(&adaptor) {}
159 152

	
160
      InArcIt& operator++() { 
161
	_adaptor->nextIn(*this);
162
	return *this; 
153
      InArcIt& operator++() {
154
        _adaptor->nextIn(*this);
155
        return *this;
163 156
      }
164 157

	
165 158
    };
166 159

	
167
    /// \brief Base node of the iterator
168
    ///
169
    /// Returns the base node (ie. the source in this case) of the iterator
170 160
    Node baseNode(const OutArcIt &e) const {
171 161
      return Parent::source(e);
172 162
    }
173
    /// \brief Running node of the iterator
174
    ///
175
    /// Returns the running node (ie. the target in this case) of the
176
    /// iterator
177 163
    Node runningNode(const OutArcIt &e) const {
178 164
      return Parent::target(e);
179 165
    }
180 166

	
181
    /// \brief Base node of the iterator
182
    ///
183
    /// Returns the base node (ie. the target in this case) of the iterator
184 167
    Node baseNode(const InArcIt &e) const {
185 168
      return Parent::target(e);
186 169
    }
187
    /// \brief Running node of the iterator
188
    ///
189
    /// Returns the running node (ie. the source in this case) of the
190
    /// iterator
191 170
    Node runningNode(const InArcIt &e) const {
192 171
      return Parent::source(e);
193 172
    }
194 173

	
195 174
  };
196 175

	
197 176

	
198 177
  /// \ingroup digraphbits
199 178
  ///
200 179
  /// \brief Extender for the GraphAdaptors
201
  template <typename _Graph> 
180
  template <typename _Graph>
202 181
  class GraphAdaptorExtender : public _Graph {
203 182
  public:
204
    
183

	
205 184
    typedef _Graph Parent;
206 185
    typedef _Graph Graph;
207 186
    typedef GraphAdaptorExtender Adaptor;
208 187

	
209 188
    typedef typename Parent::Node Node;
210 189
    typedef typename Parent::Arc Arc;
211 190
    typedef typename Parent::Edge Edge;
212 191

	
213
    // Graph extension    
192
    // Graph extension
214 193

	
215 194
    int maxId(Node) const {
216 195
      return Parent::maxNodeId();
217 196
    }
218 197

	
219 198
    int maxId(Arc) const {
220 199
      return Parent::maxArcId();
221 200
    }
222 201

	
223 202
    int maxId(Edge) const {
224 203
      return Parent::maxEdgeId();
225 204
    }
226 205

	
227 206
    Node fromId(int id, Node) const {
228 207
      return Parent::nodeFromId(id);
229 208
    }
230 209

	
231 210
    Arc fromId(int id, Arc) const {
232 211
      return Parent::arcFromId(id);
233 212
    }
234 213

	
235 214
    Edge fromId(int id, Edge) const {
236 215
      return Parent::edgeFromId(id);
237 216
    }
238 217

	
239 218
    Node oppositeNode(const Node &n, const Edge &e) const {
240 219
      if( n == Parent::u(e))
241
	return Parent::v(e);
220
        return Parent::v(e);
242 221
      else if( n == Parent::v(e))
243
	return Parent::u(e);
222
        return Parent::u(e);
244 223
      else
245
	return INVALID;
224
        return INVALID;
246 225
    }
247 226

	
248 227
    Arc oppositeArc(const Arc &a) const {
249 228
      return Parent::direct(a, !Parent::direction(a));
250 229
    }
251 230

	
252 231
    using Parent::direct;
253 232
    Arc direct(const Edge &e, const Node &s) const {
254 233
      return Parent::direct(e, Parent::u(e) == s);
255 234
    }
256 235

	
257 236

	
258
    class NodeIt : public Node { 
237
    class NodeIt : public Node {
259 238
      const Adaptor* _adaptor;
260 239
    public:
261 240

	
262 241
      NodeIt() {}
263 242

	
264 243
      NodeIt(Invalid i) : Node(i) { }
265 244

	
266 245
      explicit NodeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
267
	_adaptor->first(static_cast<Node&>(*this));
246
        _adaptor->first(static_cast<Node&>(*this));
268 247
      }
269 248

	
270
      NodeIt(const Adaptor& adaptor, const Node& node) 
271
	: Node(node), _adaptor(&adaptor) {}
249
      NodeIt(const Adaptor& adaptor, const Node& node)
250
        : Node(node), _adaptor(&adaptor) {}
272 251

	
273
      NodeIt& operator++() { 
274
	_adaptor->next(*this);
275
	return *this; 
252
      NodeIt& operator++() {
253
        _adaptor->next(*this);
254
        return *this;
276 255
      }
277 256

	
278 257
    };
279 258

	
280 259

	
281
    class ArcIt : public Arc { 
260
    class ArcIt : public Arc {
282 261
      const Adaptor* _adaptor;
283 262
    public:
284 263

	
285 264
      ArcIt() { }
286 265

	
287 266
      ArcIt(Invalid i) : Arc(i) { }
288 267

	
289 268
      explicit ArcIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
290
	_adaptor->first(static_cast<Arc&>(*this));
269
        _adaptor->first(static_cast<Arc&>(*this));
291 270
      }
292 271

	
293
      ArcIt(const Adaptor& adaptor, const Arc& e) : 
294
	Arc(e), _adaptor(&adaptor) { }
272
      ArcIt(const Adaptor& adaptor, const Arc& e) :
273
        Arc(e), _adaptor(&adaptor) { }
295 274

	
296
      ArcIt& operator++() { 
297
	_adaptor->next(*this);
298
	return *this; 
275
      ArcIt& operator++() {
276
        _adaptor->next(*this);
277
        return *this;
299 278
      }
300 279

	
301 280
    };
302 281

	
303 282

	
304
    class OutArcIt : public Arc { 
283
    class OutArcIt : public Arc {
305 284
      const Adaptor* _adaptor;
306 285
    public:
307 286

	
308 287
      OutArcIt() { }
309 288

	
310 289
      OutArcIt(Invalid i) : Arc(i) { }
311 290

	
312
      OutArcIt(const Adaptor& adaptor, const Node& node) 
313
	: _adaptor(&adaptor) {
314
	_adaptor->firstOut(*this, node);
291
      OutArcIt(const Adaptor& adaptor, const Node& node)
292
        : _adaptor(&adaptor) {
293
        _adaptor->firstOut(*this, node);
315 294
      }
316 295

	
317
      OutArcIt(const Adaptor& adaptor, const Arc& arc) 
318
	: Arc(arc), _adaptor(&adaptor) {}
296
      OutArcIt(const Adaptor& adaptor, const Arc& arc)
297
        : Arc(arc), _adaptor(&adaptor) {}
319 298

	
320
      OutArcIt& operator++() { 
321
	_adaptor->nextOut(*this);
322
	return *this; 
299
      OutArcIt& operator++() {
300
        _adaptor->nextOut(*this);
301
        return *this;
323 302
      }
324 303

	
325 304
    };
326 305

	
327 306

	
328
    class InArcIt : public Arc { 
307
    class InArcIt : public Arc {
329 308
      const Adaptor* _adaptor;
330 309
    public:
331 310

	
332 311
      InArcIt() { }
333 312

	
334 313
      InArcIt(Invalid i) : Arc(i) { }
335 314

	
336
      InArcIt(const Adaptor& adaptor, const Node& node) 
337
	: _adaptor(&adaptor) {
338
	_adaptor->firstIn(*this, node);
315
      InArcIt(const Adaptor& adaptor, const Node& node)
316
        : _adaptor(&adaptor) {
317
        _adaptor->firstIn(*this, node);
339 318
      }
340 319

	
341
      InArcIt(const Adaptor& adaptor, const Arc& arc) : 
342
	Arc(arc), _adaptor(&adaptor) {}
320
      InArcIt(const Adaptor& adaptor, const Arc& arc) :
321
        Arc(arc), _adaptor(&adaptor) {}
343 322

	
344
      InArcIt& operator++() { 
345
	_adaptor->nextIn(*this);
346
	return *this; 
323
      InArcIt& operator++() {
324
        _adaptor->nextIn(*this);
325
        return *this;
347 326
      }
348 327

	
349 328
    };
350 329

	
351
    class EdgeIt : public Parent::Edge { 
330
    class EdgeIt : public Parent::Edge {
352 331
      const Adaptor* _adaptor;
353 332
    public:
354 333

	
355 334
      EdgeIt() { }
356 335

	
357 336
      EdgeIt(Invalid i) : Edge(i) { }
358 337

	
359 338
      explicit EdgeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
360
	_adaptor->first(static_cast<Edge&>(*this));
339
        _adaptor->first(static_cast<Edge&>(*this));
361 340
      }
362 341

	
363
      EdgeIt(const Adaptor& adaptor, const Edge& e) : 
364
	Edge(e), _adaptor(&adaptor) { }
342
      EdgeIt(const Adaptor& adaptor, const Edge& e) :
343
        Edge(e), _adaptor(&adaptor) { }
365 344

	
366
      EdgeIt& operator++() { 
367
	_adaptor->next(*this);
368
	return *this; 
345
      EdgeIt& operator++() {
346
        _adaptor->next(*this);
347
        return *this;
369 348
      }
370 349

	
371 350
    };
372 351

	
373
    class IncEdgeIt : public Edge { 
352
    class IncEdgeIt : public Edge {
374 353
      friend class GraphAdaptorExtender;
375 354
      const Adaptor* _adaptor;
376 355
      bool direction;
377 356
    public:
378 357

	
379 358
      IncEdgeIt() { }
380 359

	
381 360
      IncEdgeIt(Invalid i) : Edge(i), direction(false) { }
382 361

	
383 362
      IncEdgeIt(const Adaptor& adaptor, const Node &n) : _adaptor(&adaptor) {
384
	_adaptor->firstInc(static_cast<Edge&>(*this), direction, n);
363
        _adaptor->firstInc(static_cast<Edge&>(*this), direction, n);
385 364
      }
386 365

	
387 366
      IncEdgeIt(const Adaptor& adaptor, const Edge &e, const Node &n)
388
	: _adaptor(&adaptor), Edge(e) {
389
	direction = (_adaptor->u(e) == n);
367
        : _adaptor(&adaptor), Edge(e) {
368
        direction = (_adaptor->u(e) == n);
390 369
      }
391 370

	
392 371
      IncEdgeIt& operator++() {
393
	_adaptor->nextInc(*this, direction);
394
	return *this; 
372
        _adaptor->nextInc(*this, direction);
373
        return *this;
395 374
      }
396 375
    };
397 376

	
398
    /// \brief Base node of the iterator
399
    ///
400
    /// Returns the base node (ie. the source in this case) of the iterator
401 377
    Node baseNode(const OutArcIt &a) const {
402 378
      return Parent::source(a);
403 379
    }
404
    /// \brief Running node of the iterator
405
    ///
406
    /// Returns the running node (ie. the target in this case) of the
407
    /// iterator
408 380
    Node runningNode(const OutArcIt &a) const {
409 381
      return Parent::target(a);
410 382
    }
411 383

	
412
    /// \brief Base node of the iterator
413
    ///
414
    /// Returns the base node (ie. the target in this case) of the iterator
415 384
    Node baseNode(const InArcIt &a) const {
416 385
      return Parent::target(a);
417 386
    }
418
    /// \brief Running node of the iterator
419
    ///
420
    /// Returns the running node (ie. the source in this case) of the
421
    /// iterator
422 387
    Node runningNode(const InArcIt &a) const {
423 388
      return Parent::source(a);
424 389
    }
425 390

	
426
    /// Base node of the iterator
427
    ///
428
    /// Returns the base node of the iterator
429 391
    Node baseNode(const IncEdgeIt &e) const {
430 392
      return e.direction ? Parent::u(e) : Parent::v(e);
431 393
    }
432
    /// Running node of the iterator
433
    ///
434
    /// Returns the running node of the iterator
435 394
    Node runningNode(const IncEdgeIt &e) const {
436 395
      return e.direction ? Parent::v(e) : Parent::u(e);
437 396
    }
438 397

	
439 398
  };
440 399

	
441 400
}
442 401

	
443 402

	
444 403
#endif
Ignore white space 6 line context
1
/* -*- C++ -*-
1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3
 * This file is a part of LEMON, a generic C++ optimization library
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_BITS_VARIANT_H
20 20
#define LEMON_BITS_VARIANT_H
21 21

	
22 22
#include <lemon/assert.h>
23 23

	
24 24
/// \file
25 25
/// \brief Variant types
26 26

	
27 27
namespace lemon {
28 28

	
29 29
  namespace _variant_bits {
30
  
30

	
31 31
    template <int left, int right>
32 32
    struct CTMax {
33 33
      static const int value = left < right ? right : left;
34 34
    };
35 35

	
36 36
  }
37 37

	
38 38

	
39 39
  /// \brief Simple Variant type for two types
40 40
  ///
41 41
  /// Simple Variant type for two types. The Variant type is a type
42 42
  /// safe union. The C++ has strong limitations for using unions, by
43 43
  /// example we can not store type with non default constructor or
44 44
  /// destructor in an union. This class always knowns the current
45 45
  /// state of the variant and it cares for the proper construction
46 46
  /// and destruction.
47 47
  template <typename _First, typename _Second>
48 48
  class BiVariant {
49 49
  public:
50 50

	
51 51
    /// \brief The \c First type.
52 52
    typedef _First First;
53 53
    /// \brief The \c Second type.
54 54
    typedef _Second Second;
55 55

	
56 56
    /// \brief Constructor
57 57
    ///
58 58
    /// This constructor initalizes to the default value of the \c First
59 59
    /// type.
60 60
    BiVariant() {
61 61
      flag = true;
62 62
      new(reinterpret_cast<First*>(data)) First();
63 63
    }
64 64

	
65 65
    /// \brief Constructor
66 66
    ///
67 67
    /// This constructor initalizes to the given value of the \c First
68 68
    /// type.
69 69
    BiVariant(const First& f) {
70 70
      flag = true;
71 71
      new(reinterpret_cast<First*>(data)) First(f);
72 72
    }
73 73

	
74 74
    /// \brief Constructor
75 75
    ///
76 76
    /// This constructor initalizes to the given value of the \c
77 77
    /// Second type.
78 78
    BiVariant(const Second& s) {
79 79
      flag = false;
80 80
      new(reinterpret_cast<Second*>(data)) Second(s);
81 81
    }
82 82

	
83 83
    /// \brief Copy constructor
84 84
    ///
85 85
    /// Copy constructor
86 86
    BiVariant(const BiVariant& bivariant) {
87 87
      flag = bivariant.flag;
88 88
      if (flag) {
89
        new(reinterpret_cast<First*>(data)) First(bivariant.first());      
89
        new(reinterpret_cast<First*>(data)) First(bivariant.first());
90 90
      } else {
91
        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());      
91
        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());
92 92
      }
93 93
    }
94 94

	
95 95
    /// \brief Destrcutor
96 96
    ///
97 97
    /// Destructor
98 98
    ~BiVariant() {
99 99
      destroy();
100 100
    }
101 101

	
102 102
    /// \brief Set to the default value of the \c First type.
103 103
    ///
104 104
    /// This function sets the variant to the default value of the \c
105 105
    /// First type.
106 106
    BiVariant& setFirst() {
107 107
      destroy();
108 108
      flag = true;
109
      new(reinterpret_cast<First*>(data)) First();   
109
      new(reinterpret_cast<First*>(data)) First();
110 110
      return *this;
111 111
    }
112 112

	
113 113
    /// \brief Set to the given value of the \c First type.
114 114
    ///
115 115
    /// This function sets the variant to the given value of the \c
116 116
    /// First type.
117 117
    BiVariant& setFirst(const First& f) {
118 118
      destroy();
119 119
      flag = true;
120
      new(reinterpret_cast<First*>(data)) First(f);   
120
      new(reinterpret_cast<First*>(data)) First(f);
121 121
      return *this;
122 122
    }
123 123

	
124 124
    /// \brief Set to the default value of the \c Second type.
125 125
    ///
126 126
    /// This function sets the variant to the default value of the \c
127 127
    /// Second type.
128 128
    BiVariant& setSecond() {
129 129
      destroy();
130 130
      flag = false;
131
      new(reinterpret_cast<Second*>(data)) Second();   
131
      new(reinterpret_cast<Second*>(data)) Second();
132 132
      return *this;
133 133
    }
134 134

	
135 135
    /// \brief Set to the given value of the \c Second type.
136 136
    ///
137 137
    /// This function sets the variant to the given value of the \c
138 138
    /// Second type.
139 139
    BiVariant& setSecond(const Second& s) {
140 140
      destroy();
141 141
      flag = false;
142
      new(reinterpret_cast<Second*>(data)) Second(s);   
142
      new(reinterpret_cast<Second*>(data)) Second(s);
143 143
      return *this;
144 144
    }
145 145

	
146 146
    /// \brief Operator form of the \c setFirst()
147 147
    BiVariant& operator=(const First& f) {
148 148
      return setFirst(f);
149 149
    }
150 150

	
151 151
    /// \brief Operator form of the \c setSecond()
152 152
    BiVariant& operator=(const Second& s) {
153 153
      return setSecond(s);
154 154
    }
155 155

	
156 156
    /// \brief Assign operator
157 157
    BiVariant& operator=(const BiVariant& bivariant) {
158 158
      if (this == &bivariant) return *this;
159 159
      destroy();
160 160
      flag = bivariant.flag;
161 161
      if (flag) {
162
        new(reinterpret_cast<First*>(data)) First(bivariant.first());      
162
        new(reinterpret_cast<First*>(data)) First(bivariant.first());
163 163
      } else {
164
        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());      
164
        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());
165 165
      }
166 166
      return *this;
167 167
    }
168 168

	
169 169
    /// \brief Reference to the value
170 170
    ///
171 171
    /// Reference to the value of the \c First type.
172 172
    /// \pre The BiVariant should store value of \c First type.
173 173
    First& first() {
174 174
      LEMON_DEBUG(flag, "Variant wrong state");
175 175
      return *reinterpret_cast<First*>(data); 
176 176
    }
177 177

	
178 178
    /// \brief Const reference to the value
179 179
    ///
180 180
    /// Const reference to the value of the \c First type.
181 181
    /// \pre The BiVariant should store value of \c First type.
182 182
    const First& first() const { 
183 183
      LEMON_DEBUG(flag, "Variant wrong state");
184 184
      return *reinterpret_cast<const First*>(data); 
185 185
    }
186 186

	
187 187
    /// \brief Operator form of the \c first()
188 188
    operator First&() { return first(); }
189 189
    /// \brief Operator form of the const \c first()
190 190
    operator const First&() const { return first(); }
191 191

	
192 192
    /// \brief Reference to the value
193 193
    ///
194 194
    /// Reference to the value of the \c Second type.
195 195
    /// \pre The BiVariant should store value of \c Second type.
196 196
    Second& second() { 
197 197
      LEMON_DEBUG(!flag, "Variant wrong state");
198 198
      return *reinterpret_cast<Second*>(data); 
199 199
    }
200 200

	
201 201
    /// \brief Const reference to the value
202 202
    ///
203 203
    /// Const reference to the value of the \c Second type.
204 204
    /// \pre The BiVariant should store value of \c Second type.
205 205
    const Second& second() const { 
206 206
      LEMON_DEBUG(!flag, "Variant wrong state");
207 207
      return *reinterpret_cast<const Second*>(data); 
208 208
    }
209 209

	
210 210
    /// \brief Operator form of the \c second()
211 211
    operator Second&() { return second(); }
212 212
    /// \brief Operator form of the const \c second()
213 213
    operator const Second&() const { return second(); }
214 214

	
215 215
    /// \brief %True when the variant is in the first state
216 216
    ///
217 217
    /// %True when the variant stores value of the \c First type.
218 218
    bool firstState() const { return flag; }
219 219

	
220 220
    /// \brief %True when the variant is in the second state
221 221
    ///
222 222
    /// %True when the variant stores value of the \c Second type.
223 223
    bool secondState() const { return !flag; }
224 224

	
225 225
  private:
226 226

	
227 227
    void destroy() {
228 228
      if (flag) {
229 229
        reinterpret_cast<First*>(data)->~First();
230 230
      } else {
231 231
        reinterpret_cast<Second*>(data)->~Second();
232 232
      }
233 233
    }
234
    
234

	
235 235
    char data[_variant_bits::CTMax<sizeof(First), sizeof(Second)>::value];
236 236
    bool flag;
237 237
  };
238 238

	
239 239
  namespace _variant_bits {
240
    
240

	
241 241
    template <int _idx, typename _TypeMap>
242 242
    struct Memory {
243 243

	
244 244
      typedef typename _TypeMap::template Map<_idx>::Type Current;
245 245

	
246 246
      static void destroy(int index, char* place) {
247 247
        if (index == _idx) {
248 248
          reinterpret_cast<Current*>(place)->~Current();
249 249
        } else {
250 250
          Memory<_idx - 1, _TypeMap>::destroy(index, place);
251 251
        }
252 252
      }
253 253

	
254 254
      static void copy(int index, char* to, const char* from) {
255 255
        if (index == _idx) {
256 256
          new (reinterpret_cast<Current*>(to))
257 257
            Current(reinterpret_cast<const Current*>(from));
258 258
        } else {
259 259
          Memory<_idx - 1, _TypeMap>::copy(index, to, from);
260 260
        }
261 261
      }
262 262

	
263 263
    };
264 264

	
265 265
    template <typename _TypeMap>
266 266
    struct Memory<-1, _TypeMap> {
267 267

	
268 268
      static void destroy(int, char*) {
269 269
        LEMON_DEBUG(false, "Variant wrong index.");
270 270
      }
271 271

	
272 272
      static void copy(int, char*, const char*) {
273 273
        LEMON_DEBUG(false, "Variant wrong index.");
274 274
      }
275 275
    };
276 276

	
277 277
    template <int _idx, typename _TypeMap>
278 278
    struct Size {
279
      static const int value = 
280
      CTMax<sizeof(typename _TypeMap::template Map<_idx>::Type), 
279
      static const int value =
280
      CTMax<sizeof(typename _TypeMap::template Map<_idx>::Type),
281 281
            Size<_idx - 1, _TypeMap>::value>::value;
282 282
    };
283 283

	
284 284
    template <typename _TypeMap>
285 285
    struct Size<0, _TypeMap> {
286
      static const int value = 
286
      static const int value =
287 287
      sizeof(typename _TypeMap::template Map<0>::Type);
288 288
    };
289 289

	
290 290
  }
291 291

	
292 292
  /// \brief Variant type
293 293
  ///
294 294
  /// Simple Variant type. The Variant type is a type safe union. The
295 295
  /// C++ has strong limitations for using unions, for example we
296 296
  /// cannot store type with non default constructor or destructor in
297 297
  /// a union. This class always knowns the current state of the
298 298
  /// variant and it cares for the proper construction and
299 299
  /// destruction.
300 300
  ///
301 301
  /// \param _num The number of the types which can be stored in the
302 302
  /// variant type.
303 303
  /// \param _TypeMap This class describes the types of the Variant. The
304
  /// _TypeMap::Map<index>::Type should be a valid type for each index 
304
  /// _TypeMap::Map<index>::Type should be a valid type for each index
305 305
  /// in the range {0, 1, ..., _num - 1}. The \c VariantTypeMap is helper
306 306
  /// class to define such type mappings up to 10 types.
307 307
  ///
308 308
  /// And the usage of the class:
309 309
  ///\code
310 310
  /// typedef Variant<3, VariantTypeMap<int, std::string, double> > MyVariant;
311 311
  /// MyVariant var;
312 312
  /// var.set<0>(12);
313 313
  /// std::cout << var.get<0>() << std::endl;
314 314
  /// var.set<1>("alpha");
315 315
  /// std::cout << var.get<1>() << std::endl;
316 316
  /// var.set<2>(0.75);
317 317
  /// std::cout << var.get<2>() << std::endl;
318 318
  ///\endcode
319 319
  ///
320 320
  /// The result of course:
321 321
  ///\code
322 322
  /// 12
323 323
  /// alpha
324 324
  /// 0.75
325 325
  ///\endcode
326 326
  template <int _num, typename _TypeMap>
327 327
  class Variant {
328 328
  public:
329 329

	
330 330
    static const int num = _num;
331 331

	
332 332
    typedef _TypeMap TypeMap;
333 333

	
334 334
    /// \brief Constructor
335 335
    ///
336 336
    /// This constructor initalizes to the default value of the \c type
337 337
    /// with 0 index.
338 338
    Variant() {
339 339
      flag = 0;
340
      new(reinterpret_cast<typename TypeMap::template Map<0>::Type*>(data)) 
340
      new(reinterpret_cast<typename TypeMap::template Map<0>::Type*>(data))
341 341
        typename TypeMap::template Map<0>::Type();
342 342
    }
343 343

	
344 344

	
345 345
    /// \brief Copy constructor
346 346
    ///
347 347
    /// Copy constructor
348 348
    Variant(const Variant& variant) {
349 349
      flag = variant.flag;
350 350
      _variant_bits::Memory<num - 1, TypeMap>::copy(flag, data, variant.data);
351 351
    }
352 352

	
353 353
    /// \brief Assign operator
354 354
    ///
355 355
    /// Assign operator
356 356
    Variant& operator=(const Variant& variant) {
357 357
      if (this == &variant) return *this;
358 358
      _variant_bits::Memory<num - 1, TypeMap>::
359 359
        destroy(flag, data);
360 360
      flag = variant.flag;
361 361
      _variant_bits::Memory<num - 1, TypeMap>::
362 362
        copy(flag, data, variant.data);
363 363
      return *this;
364 364
    }
365 365

	
366 366
    /// \brief Destrcutor
367 367
    ///
368 368
    /// Destructor
369 369
    ~Variant() {
370 370
      _variant_bits::Memory<num - 1, TypeMap>::destroy(flag, data);
371 371
    }
372 372

	
373 373
    /// \brief Set to the default value of the type with \c _idx index.
374 374
    ///
375 375
    /// This function sets the variant to the default value of the
376 376
    /// type with \c _idx index.
377 377
    template <int _idx>
378 378
    Variant& set() {
379 379
      _variant_bits::Memory<num - 1, TypeMap>::destroy(flag, data);
380 380
      flag = _idx;
381
      new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data)) 
381
      new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data))
382 382
        typename TypeMap::template Map<_idx>::Type();
383 383
      return *this;
384 384
    }
385 385

	
386 386
    /// \brief Set to the given value of the type with \c _idx index.
387 387
    ///
388 388
    /// This function sets the variant to the given value of the type
389 389
    /// with \c _idx index.
390 390
    template <int _idx>
391 391
    Variant& set(const typename _TypeMap::template Map<_idx>::Type& init) {
392 392
      _variant_bits::Memory<num - 1, TypeMap>::destroy(flag, data);
393 393
      flag = _idx;
394
      new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data)) 
394
      new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data))
395 395
        typename TypeMap::template Map<_idx>::Type(init);
396 396
      return *this;
397 397
    }
398 398

	
399 399
    /// \brief Gets the current value of the type with \c _idx index.
400 400
    ///
401 401
    /// Gets the current value of the type with \c _idx index.
402 402
    template <int _idx>
403 403
    const typename TypeMap::template Map<_idx>::Type& get() const {
404 404
      LEMON_DEBUG(_idx == flag, "Variant wrong index");
405 405
      return *reinterpret_cast<const typename TypeMap::
406
        template Map<_idx>::Type*>(data); 
406
        template Map<_idx>::Type*>(data);
407 407
    }
408 408

	
409 409
    /// \brief Gets the current value of the type with \c _idx index.
410 410
    ///
411 411
    /// Gets the current value of the type with \c _idx index.
412 412
    template <int _idx>
413 413
    typename _TypeMap::template Map<_idx>::Type& get() {
414 414
      LEMON_DEBUG(_idx == flag, "Variant wrong index");
415 415
      return *reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>
416
        (data); 
416
        (data);
417 417
    }
418 418

	
419 419
    /// \brief Returns the current state of the variant.
420 420
    ///
421 421
    /// Returns the current state of the variant.
422 422
    int state() const {
423 423
      return flag;
424 424
    }
425 425

	
426 426
  private:
427
    
427

	
428 428
    char data[_variant_bits::Size<num - 1, TypeMap>::value];
429 429
    int flag;
430 430
  };
431 431

	
432 432
  namespace _variant_bits {
433 433

	
434 434
    template <int _index, typename _List>
435 435
    struct Get {
436 436
      typedef typename Get<_index - 1, typename _List::Next>::Type Type;
437 437
    };
438 438

	
439 439
    template <typename _List>
440 440
    struct Get<0, _List> {
441 441
      typedef typename _List::Type Type;
442 442
    };
443 443

	
444 444
    struct List {};
445
    
445

	
446 446
    template <typename _Type, typename _List>
447 447
    struct Insert {
448 448
      typedef _List Next;
449 449
      typedef _Type Type;
450 450
    };
451 451

	
452
    template <int _idx, typename _T0, typename _T1, typename _T2, 
452
    template <int _idx, typename _T0, typename _T1, typename _T2,
453 453
              typename _T3, typename _T5, typename _T4, typename _T6,
454 454
              typename _T7, typename _T8, typename _T9>
455 455
    struct Mapper {
456 456
      typedef List L10;
457 457
      typedef Insert<_T9, L10> L9;
458 458
      typedef Insert<_T8, L9> L8;
459 459
      typedef Insert<_T7, L8> L7;
460 460
      typedef Insert<_T6, L7> L6;
461 461
      typedef Insert<_T5, L6> L5;
462 462
      typedef Insert<_T4, L5> L4;
463 463
      typedef Insert<_T3, L4> L3;
464 464
      typedef Insert<_T2, L3> L2;
465 465
      typedef Insert<_T1, L2> L1;
466 466
      typedef Insert<_T0, L1> L0;
467 467
      typedef typename Get<_idx, L0>::Type Type;
468 468
    };
469
    
469

	
470 470
  }
471 471

	
472 472
  /// \brief Helper class for Variant
473 473
  ///
474 474
  /// Helper class to define type mappings for Variant. This class
475 475
  /// converts the template parameters to be mappable by integer.
476 476
  /// \see Variant
477 477
  template <
478
    typename _T0, 
478
    typename _T0,
479 479
    typename _T1 = void, typename _T2 = void, typename _T3 = void,
480 480
    typename _T5 = void, typename _T4 = void, typename _T6 = void,
481 481
    typename _T7 = void, typename _T8 = void, typename _T9 = void>
482 482
  struct VariantTypeMap {
483 483
    template <int _idx>
484 484
    struct Map {
485 485
      typedef typename _variant_bits::
486 486
      Mapper<_idx, _T0, _T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9>::Type
487 487
      Type;
488 488
    };
489 489
  };
490
  
490

	
491 491
}
492 492

	
493 493

	
494 494
#endif
Ignore white space 16777216 line context
1
/* -*- C++ -*-
1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3
 * This file is a part of LEMON, a generic C++ optimization library
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
#include<lemon/digraph_adaptor.h>
29
#include<lemon/graph_adaptor.h>
28
#include<lemon/adaptors.h>
30 29

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

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

	
38 37
using namespace lemon;
39 38

	
40
void checkRevDigraphAdaptor() {
41
  checkConcept<concepts::Digraph, RevDigraphAdaptor<concepts::Digraph> >();
39
void checkReverseDigraph() {
40
  checkConcept<concepts::Digraph, ReverseDigraph<concepts::Digraph> >();
42 41

	
43 42
  typedef ListDigraph Digraph;
44
  typedef RevDigraphAdaptor<Digraph> Adaptor;
43
  typedef ReverseDigraph<Digraph> Adaptor;
45 44

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

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

	
53 52
  Digraph::Arc a1 = digraph.addArc(n1, n2);
54 53
  Digraph::Arc a2 = digraph.addArc(n1, n3);
55 54
  Digraph::Arc a3 = digraph.addArc(n2, n3);
56
  
55

	
57 56
  checkGraphNodeList(adaptor, 3);
58 57
  checkGraphArcList(adaptor, 3);
59 58
  checkGraphConArcList(adaptor, 3);
60 59

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

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

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

	
72 71
  checkGraphNodeMap(adaptor);
73 72
  checkGraphArcMap(adaptor);
74 73

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

	
81
void checkSubDigraphAdaptor() {
82
  checkConcept<concepts::Digraph, 
83
    SubDigraphAdaptor<concepts::Digraph, 
80
void checkSubDigraph() {
81
  checkConcept<concepts::Digraph,
82
    SubDigraph<concepts::Digraph,
84 83
    concepts::Digraph::NodeMap<bool>,
85 84
    concepts::Digraph::ArcMap<bool> > >();
86 85

	
87 86
  typedef ListDigraph Digraph;
88 87
  typedef Digraph::NodeMap<bool> NodeFilter;
89 88
  typedef Digraph::ArcMap<bool> ArcFilter;
90
  typedef SubDigraphAdaptor<Digraph, NodeFilter, ArcFilter> Adaptor;
89
  typedef SubDigraph<Digraph, NodeFilter, ArcFilter> Adaptor;
91 90

	
92 91
  Digraph digraph;
93 92
  NodeFilter node_filter(digraph);
94 93
  ArcFilter arc_filter(digraph);
95 94
  Adaptor adaptor(digraph, node_filter, arc_filter);
96 95

	
97 96
  Digraph::Node n1 = digraph.addNode();
98 97
  Digraph::Node n2 = digraph.addNode();
99 98
  Digraph::Node n3 = digraph.addNode();
100 99

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

	
105 104
  node_filter[n1] = node_filter[n2] = node_filter[n3] = true;
106 105
  arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = true;
107 106
  
108 107
  checkGraphNodeList(adaptor, 3);
109 108
  checkGraphArcList(adaptor, 3);
110 109
  checkGraphConArcList(adaptor, 3);
111 110

	
112 111
  checkGraphOutArcList(adaptor, n1, 2);
113 112
  checkGraphOutArcList(adaptor, n2, 1);
114 113
  checkGraphOutArcList(adaptor, n3, 0);
115 114

	
116 115
  checkGraphInArcList(adaptor, n1, 0);
117 116
  checkGraphInArcList(adaptor, n2, 1);
118 117
  checkGraphInArcList(adaptor, n3, 2);
119 118

	
120 119
  checkNodeIds(adaptor);
121 120
  checkArcIds(adaptor);
122 121

	
123 122
  checkGraphNodeMap(adaptor);
124 123
  checkGraphArcMap(adaptor);
125 124

	
126
  arc_filter[a2] = false; 
125
  arc_filter[a2] = false;
127 126

	
128 127
  checkGraphNodeList(adaptor, 3);
129 128
  checkGraphArcList(adaptor, 2);
130 129
  checkGraphConArcList(adaptor, 2);
131 130

	
132 131
  checkGraphOutArcList(adaptor, n1, 1);
133 132
  checkGraphOutArcList(adaptor, n2, 1);
134 133
  checkGraphOutArcList(adaptor, n3, 0);
135 134

	
136 135
  checkGraphInArcList(adaptor, n1, 0);
137 136
  checkGraphInArcList(adaptor, n2, 1);
138 137
  checkGraphInArcList(adaptor, n3, 1);
139 138

	
140 139
  checkNodeIds(adaptor);
141 140
  checkArcIds(adaptor);
142 141

	
143 142
  checkGraphNodeMap(adaptor);
144 143
  checkGraphArcMap(adaptor);
145 144

	
146
  node_filter[n1] = false; 
145
  node_filter[n1] = false;
147 146

	
148 147
  checkGraphNodeList(adaptor, 2);
149 148
  checkGraphArcList(adaptor, 1);
150 149
  checkGraphConArcList(adaptor, 1);
151 150

	
152 151
  checkGraphOutArcList(adaptor, n2, 1);
153 152
  checkGraphOutArcList(adaptor, n3, 0);
154 153

	
155 154
  checkGraphInArcList(adaptor, n2, 0);
156 155
  checkGraphInArcList(adaptor, n3, 1);
157 156

	
158 157
  checkNodeIds(adaptor);
159 158
  checkArcIds(adaptor);
160 159

	
161 160
  checkGraphNodeMap(adaptor);
162 161
  checkGraphArcMap(adaptor);
163 162

	
164 163
  node_filter[n1] = node_filter[n2] = node_filter[n3] = false;
165 164
  arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = false;
166 165

	
167 166
  checkGraphNodeList(adaptor, 0);
168 167
  checkGraphArcList(adaptor, 0);
169 168
  checkGraphConArcList(adaptor, 0);
170 169

	
171 170
  checkNodeIds(adaptor);
172 171
  checkArcIds(adaptor);
173 172

	
174 173
  checkGraphNodeMap(adaptor);
175 174
  checkGraphArcMap(adaptor);
176 175
}
177 176

	
178
void checkNodeSubDigraphAdaptor() {
179
  checkConcept<concepts::Digraph, 
180
    NodeSubDigraphAdaptor<concepts::Digraph, 
177
void checkFilterNodes1() {
178
  checkConcept<concepts::Digraph,
179
    FilterNodes<concepts::Digraph,
181 180
      concepts::Digraph::NodeMap<bool> > >();
182 181

	
183 182
  typedef ListDigraph Digraph;
184 183
  typedef Digraph::NodeMap<bool> NodeFilter;
185
  typedef NodeSubDigraphAdaptor<Digraph, NodeFilter> Adaptor;
184
  typedef FilterNodes<Digraph, NodeFilter> Adaptor;
186 185

	
187 186
  Digraph digraph;
188 187
  NodeFilter node_filter(digraph);
189 188
  Adaptor adaptor(digraph, node_filter);
190 189

	
191 190
  Digraph::Node n1 = digraph.addNode();
192 191
  Digraph::Node n2 = digraph.addNode();
193 192
  Digraph::Node n3 = digraph.addNode();
194 193

	
195 194
  Digraph::Arc a1 = digraph.addArc(n1, n2);
196 195
  Digraph::Arc a2 = digraph.addArc(n1, n3);
197 196
  Digraph::Arc a3 = digraph.addArc(n2, n3);
198 197

	
199 198
  node_filter[n1] = node_filter[n2] = node_filter[n3] = true;
200 199
  
201 200
  checkGraphNodeList(adaptor, 3);
202 201
  checkGraphArcList(adaptor, 3);
203 202
  checkGraphConArcList(adaptor, 3);
204 203

	
205 204
  checkGraphOutArcList(adaptor, n1, 2);
206 205
  checkGraphOutArcList(adaptor, n2, 1);
207 206
  checkGraphOutArcList(adaptor, n3, 0);
208 207

	
209 208
  checkGraphInArcList(adaptor, n1, 0);
210 209
  checkGraphInArcList(adaptor, n2, 1);
211 210
  checkGraphInArcList(adaptor, n3, 2);
212 211

	
213 212
  checkNodeIds(adaptor);
214 213
  checkArcIds(adaptor);
215 214

	
216 215
  checkGraphNodeMap(adaptor);
217 216
  checkGraphArcMap(adaptor);
218 217

	
219
  node_filter[n1] = false; 
218
  node_filter[n1] = false;
220 219

	
221 220
  checkGraphNodeList(adaptor, 2);
222 221
  checkGraphArcList(adaptor, 1);
223 222
  checkGraphConArcList(adaptor, 1);
224 223

	
225 224
  checkGraphOutArcList(adaptor, n2, 1);
226 225
  checkGraphOutArcList(adaptor, n3, 0);
227 226

	
228 227
  checkGraphInArcList(adaptor, n2, 0);
229 228
  checkGraphInArcList(adaptor, n3, 1);
230 229

	
231 230
  checkNodeIds(adaptor);
232 231
  checkArcIds(adaptor);
233 232

	
234 233
  checkGraphNodeMap(adaptor);
235 234
  checkGraphArcMap(adaptor);
236 235

	
237 236
  node_filter[n1] = node_filter[n2] = node_filter[n3] = false;
238 237

	
239 238
  checkGraphNodeList(adaptor, 0);
240 239
  checkGraphArcList(adaptor, 0);
241 240
  checkGraphConArcList(adaptor, 0);
242 241

	
243 242
  checkNodeIds(adaptor);
244 243
  checkArcIds(adaptor);
245 244

	
246 245
  checkGraphNodeMap(adaptor);
247 246
  checkGraphArcMap(adaptor);
248 247
}
249 248

	
250
void checkArcSubDigraphAdaptor() {
251
  checkConcept<concepts::Digraph, 
252
    ArcSubDigraphAdaptor<concepts::Digraph, 
249
void checkFilterArcs() {
250
  checkConcept<concepts::Digraph,
251
    FilterArcs<concepts::Digraph,
253 252
    concepts::Digraph::ArcMap<bool> > >();
254 253

	
255 254
  typedef ListDigraph Digraph;
256 255
  typedef Digraph::ArcMap<bool> ArcFilter;
257
  typedef ArcSubDigraphAdaptor<Digraph, ArcFilter> Adaptor;
256
  typedef FilterArcs<Digraph, ArcFilter> Adaptor;
258 257

	
259 258
  Digraph digraph;
260 259
  ArcFilter arc_filter(digraph);
261 260
  Adaptor adaptor(digraph, arc_filter);
262 261

	
263 262
  Digraph::Node n1 = digraph.addNode();
264 263
  Digraph::Node n2 = digraph.addNode();
265 264
  Digraph::Node n3 = digraph.addNode();
266 265

	
267 266
  Digraph::Arc a1 = digraph.addArc(n1, n2);
268 267
  Digraph::Arc a2 = digraph.addArc(n1, n3);
269 268
  Digraph::Arc a3 = digraph.addArc(n2, n3);
270 269

	
271 270
  arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = true;
272 271
  
273 272
  checkGraphNodeList(adaptor, 3);
274 273
  checkGraphArcList(adaptor, 3);
275 274
  checkGraphConArcList(adaptor, 3);
276 275

	
277 276
  checkGraphOutArcList(adaptor, n1, 2);
278 277
  checkGraphOutArcList(adaptor, n2, 1);
279 278
  checkGraphOutArcList(adaptor, n3, 0);
280 279

	
281 280
  checkGraphInArcList(adaptor, n1, 0);
282 281
  checkGraphInArcList(adaptor, n2, 1);
283 282
  checkGraphInArcList(adaptor, n3, 2);
284 283

	
285 284
  checkNodeIds(adaptor);
286 285
  checkArcIds(adaptor);
287 286

	
288 287
  checkGraphNodeMap(adaptor);
289 288
  checkGraphArcMap(adaptor);
290 289

	
291
  arc_filter[a2] = false; 
290
  arc_filter[a2] = false;
292 291

	
293 292
  checkGraphNodeList(adaptor, 3);
294 293
  checkGraphArcList(adaptor, 2);
295 294
  checkGraphConArcList(adaptor, 2);
296 295

	
297 296
  checkGraphOutArcList(adaptor, n1, 1);
298 297
  checkGraphOutArcList(adaptor, n2, 1);
299 298
  checkGraphOutArcList(adaptor, n3, 0);
300 299

	
301 300
  checkGraphInArcList(adaptor, n1, 0);
302 301
  checkGraphInArcList(adaptor, n2, 1);
303 302
  checkGraphInArcList(adaptor, n3, 1);
304 303

	
305 304
  checkNodeIds(adaptor);
306 305
  checkArcIds(adaptor);
307 306

	
308 307
  checkGraphNodeMap(adaptor);
309 308
  checkGraphArcMap(adaptor);
310 309

	
311 310
  arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = false;
312 311

	
313 312
  checkGraphNodeList(adaptor, 3);
314 313
  checkGraphArcList(adaptor, 0);
315 314
  checkGraphConArcList(adaptor, 0);
316 315

	
317 316
  checkNodeIds(adaptor);
318 317
  checkArcIds(adaptor);
319 318

	
320 319
  checkGraphNodeMap(adaptor);
321 320
  checkGraphArcMap(adaptor);
322 321
}
323 322

	
324
void checkUndirDigraphAdaptor() {
325
  checkConcept<concepts::Graph, UndirDigraphAdaptor<concepts::Digraph> >();
323
void checkUndirector() {
324
  checkConcept<concepts::Graph, Undirector<concepts::Digraph> >();
326 325

	
327 326
  typedef ListDigraph Digraph;
328
  typedef UndirDigraphAdaptor<Digraph> Adaptor;
327
  typedef Undirector<Digraph> Adaptor;
329 328

	
330 329
  Digraph digraph;
331 330
  Adaptor adaptor(digraph);
332 331

	
333 332
  Digraph::Node n1 = digraph.addNode();
334 333
  Digraph::Node n2 = digraph.addNode();
335 334
  Digraph::Node n3 = digraph.addNode();
336 335

	
337 336
  Digraph::Arc a1 = digraph.addArc(n1, n2);
338 337
  Digraph::Arc a2 = digraph.addArc(n1, n3);
339 338
  Digraph::Arc a3 = digraph.addArc(n2, n3);
340
  
339

	
341 340
  checkGraphNodeList(adaptor, 3);
342 341
  checkGraphArcList(adaptor, 6);
343 342
  checkGraphEdgeList(adaptor, 3);
344 343
  checkGraphConArcList(adaptor, 6);
345 344
  checkGraphConEdgeList(adaptor, 3);
346 345

	
347 346
  checkGraphOutArcList(adaptor, n1, 2);
348 347
  checkGraphOutArcList(adaptor, n2, 2);
349 348
  checkGraphOutArcList(adaptor, n3, 2);
350 349

	
351 350
  checkGraphInArcList(adaptor, n1, 2);
352 351
  checkGraphInArcList(adaptor, n2, 2);
353 352
  checkGraphInArcList(adaptor, n3, 2);
354 353

	
355 354
  checkGraphIncEdgeList(adaptor, n1, 2);
356 355
  checkGraphIncEdgeList(adaptor, n2, 2);
357 356
  checkGraphIncEdgeList(adaptor, n3, 2);
358 357

	
359 358
  checkNodeIds(adaptor);
360 359
  checkArcIds(adaptor);
361 360
  checkEdgeIds(adaptor);
362 361

	
363 362
  checkGraphNodeMap(adaptor);
364 363
  checkGraphArcMap(adaptor);
365 364
  checkGraphEdgeMap(adaptor);
366 365

	
367 366
  for (Adaptor::EdgeIt e(adaptor); e != INVALID; ++e) {
368 367
    check(adaptor.u(e) == digraph.source(e), "Wrong undir");
369 368
    check(adaptor.v(e) == digraph.target(e), "Wrong undir");
370 369
  }
371 370

	
372 371
}
373 372

	
374
void checkResDigraphAdaptor() {
375
  checkConcept<concepts::Digraph, 
376
    ResDigraphAdaptor<concepts::Digraph, 
377
    concepts::Digraph::ArcMap<int>, 
373
void checkResidual() {
374
  checkConcept<concepts::Digraph,
375
    Residual<concepts::Digraph,
376
    concepts::Digraph::ArcMap<int>,
378 377
    concepts::Digraph::ArcMap<int> > >();
379 378

	
380 379
  typedef ListDigraph Digraph;
381 380
  typedef Digraph::ArcMap<int> IntArcMap;
382
  typedef ResDigraphAdaptor<Digraph, IntArcMap> Adaptor;
381
  typedef Residual<Digraph, IntArcMap> Adaptor;
383 382

	
384 383
  Digraph digraph;
385 384
  IntArcMap capacity(digraph), flow(digraph);
386 385
  Adaptor adaptor(digraph, capacity, flow);
387 386

	
388 387
  Digraph::Node n1 = digraph.addNode();
389 388
  Digraph::Node n2 = digraph.addNode();
390 389
  Digraph::Node n3 = digraph.addNode();
391 390
  Digraph::Node n4 = digraph.addNode();
392 391

	
393 392
  Digraph::Arc a1 = digraph.addArc(n1, n2);
394 393
  Digraph::Arc a2 = digraph.addArc(n1, n3);
395 394
  Digraph::Arc a3 = digraph.addArc(n1, n4);
396 395
  Digraph::Arc a4 = digraph.addArc(n2, n3);
397 396
  Digraph::Arc a5 = digraph.addArc(n2, n4);
398 397
  Digraph::Arc a6 = digraph.addArc(n3, n4);
399 398

	
400 399
  capacity[a1] = 8;
401 400
  capacity[a2] = 6;
402 401
  capacity[a3] = 4;
403 402
  capacity[a4] = 4;
404 403
  capacity[a5] = 6;
405 404
  capacity[a6] = 10;
406 405

	
407 406
  for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
408 407
    flow[a] = 0;
409 408
  }
410
  
409

	
411 410
  checkGraphNodeList(adaptor, 4);
412 411
  checkGraphArcList(adaptor, 6);
413 412
  checkGraphConArcList(adaptor, 6);
414 413

	
415 414
  checkGraphOutArcList(adaptor, n1, 3);
416 415
  checkGraphOutArcList(adaptor, n2, 2);
417 416
  checkGraphOutArcList(adaptor, n3, 1);
418 417
  checkGraphOutArcList(adaptor, n4, 0);
419 418

	
420 419
  checkGraphInArcList(adaptor, n1, 0);
421 420
  checkGraphInArcList(adaptor, n2, 1);
422 421
  checkGraphInArcList(adaptor, n3, 2);
423 422
  checkGraphInArcList(adaptor, n4, 3);
424 423

	
425 424
  for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
426 425
    flow[a] = capacity[a] / 2;
427 426
  }
428
  
427

	
429 428
  checkGraphNodeList(adaptor, 4);
430 429
  checkGraphArcList(adaptor, 12);
431 430
  checkGraphConArcList(adaptor, 12);
432 431

	
433 432
  checkGraphOutArcList(adaptor, n1, 3);
434 433
  checkGraphOutArcList(adaptor, n2, 3);
435 434
  checkGraphOutArcList(adaptor, n3, 3);
436 435
  checkGraphOutArcList(adaptor, n4, 3);
437 436

	
438 437
  checkGraphInArcList(adaptor, n1, 3);
439 438
  checkGraphInArcList(adaptor, n2, 3);
440 439
  checkGraphInArcList(adaptor, n3, 3);
441 440
  checkGraphInArcList(adaptor, n4, 3);
442 441

	
443 442
  checkNodeIds(adaptor);
444 443
  checkArcIds(adaptor);
445 444

	
446 445
  checkGraphNodeMap(adaptor);
447 446
  checkGraphArcMap(adaptor);
448 447

	
449 448
  for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
450 449
    flow[a] = capacity[a];
451 450
  }
452
  
451

	
453 452
  checkGraphNodeList(adaptor, 4);
454 453
  checkGraphArcList(adaptor, 6);
455 454
  checkGraphConArcList(adaptor, 6);
456 455

	
457 456
  checkGraphOutArcList(adaptor, n1, 0);
458 457
  checkGraphOutArcList(adaptor, n2, 1);
459 458
  checkGraphOutArcList(adaptor, n3, 2);
460 459
  checkGraphOutArcList(adaptor, n4, 3);
461 460

	
462 461
  checkGraphInArcList(adaptor, n1, 3);
463 462
  checkGraphInArcList(adaptor, n2, 2);
464 463
  checkGraphInArcList(adaptor, n3, 1);
465 464
  checkGraphInArcList(adaptor, n4, 0);
466 465

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

	
471 470
  int flow_value = 0;
472 471
  while (true) {
473
    
472

	
474 473
    Bfs<Adaptor> bfs(adaptor);
475 474
    bfs.run(n1, n4);
476
    
475

	
477 476
    if (!bfs.reached(n4)) break;
478 477

	
479 478
    Path<Adaptor> p = bfs.path(n4);
480
    
479

	
481 480
    int min = std::numeric_limits<int>::max();
482 481
    for (Path<Adaptor>::ArcIt a(p); a != INVALID; ++a) {
483
      if (adaptor.rescap(a) < min) min = adaptor.rescap(a);
482
      if (adaptor.residualCapacity(a) < min)
483
        min = adaptor.residualCapacity(a);
484 484
    }
485 485

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

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

	
494 494
}
495 495

	
496
void checkSplitDigraphAdaptor() {
497
  checkConcept<concepts::Digraph, SplitDigraphAdaptor<concepts::Digraph> >();
496
void checkSplitNodes() {
497
  checkConcept<concepts::Digraph, SplitNodes<concepts::Digraph> >();
498 498

	
499 499
  typedef ListDigraph Digraph;
500
  typedef SplitDigraphAdaptor<Digraph> Adaptor;
500
  typedef SplitNodes<Digraph> Adaptor;
501 501

	
502 502
  Digraph digraph;
503 503
  Adaptor adaptor(digraph);
504 504

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

	
509 509
  Digraph::Arc a1 = digraph.addArc(n1, n2);
510 510
  Digraph::Arc a2 = digraph.addArc(n1, n3);
511 511
  Digraph::Arc a3 = digraph.addArc(n2, n3);
512
  
512

	
513 513
  checkGraphNodeList(adaptor, 6);
514 514
  checkGraphArcList(adaptor, 6);
515 515
  checkGraphConArcList(adaptor, 6);
516 516

	
517 517
  checkGraphOutArcList(adaptor, adaptor.inNode(n1), 1);
518 518
  checkGraphOutArcList(adaptor, adaptor.outNode(n1), 2);
519 519
  checkGraphOutArcList(adaptor, adaptor.inNode(n2), 1);
520 520
  checkGraphOutArcList(adaptor, adaptor.outNode(n2), 1);
521 521
  checkGraphOutArcList(adaptor, adaptor.inNode(n3), 1);
522 522
  checkGraphOutArcList(adaptor, adaptor.outNode(n3), 0);
523 523

	
524 524
  checkGraphInArcList(adaptor, adaptor.inNode(n1), 0);
525 525
  checkGraphInArcList(adaptor, adaptor.outNode(n1), 1);
526 526
  checkGraphInArcList(adaptor, adaptor.inNode(n2), 1);
527 527
  checkGraphInArcList(adaptor, adaptor.outNode(n2), 1);
528 528
  checkGraphInArcList(adaptor, adaptor.inNode(n3), 2);
529 529
  checkGraphInArcList(adaptor, adaptor.outNode(n3), 1);
530 530

	
531 531
  checkNodeIds(adaptor);
532 532
  checkArcIds(adaptor);
533
  
533

	
534 534
  checkGraphNodeMap(adaptor);
535 535
  checkGraphArcMap(adaptor);
536 536

	
537 537
  for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
538 538
    if (adaptor.origArc(a)) {
539 539
      Digraph::Arc oa = a;
540
      check(adaptor.source(a) == adaptor.outNode(digraph.source(oa)), 
541
	    "Wrong split");
542
      check(adaptor.target(a) == adaptor.inNode(digraph.target(oa)), 
543
	    "Wrong split"); 
540
      check(adaptor.source(a) == adaptor.outNode(digraph.source(oa)),
541
            "Wrong split");
542
      check(adaptor.target(a) == adaptor.inNode(digraph.target(oa)),
543
            "Wrong split");
544 544
    } else {
545 545
      Digraph::Node on = a;
546 546
      check(adaptor.source(a) == adaptor.inNode(on), "Wrong split");
547 547
      check(adaptor.target(a) == adaptor.outNode(on), "Wrong split");
548 548
    }
549 549
  }
550 550
}
551 551

	
552
void checkSubGraphAdaptor() {
553
  checkConcept<concepts::Graph, 
554
    SubGraphAdaptor<concepts::Graph, 
552
void checkSubGraph() {
553
  checkConcept<concepts::Graph,
554
    SubGraph<concepts::Graph,
555 555
    concepts::Graph::NodeMap<bool>,
556 556
    concepts::Graph::EdgeMap<bool> > >();
557 557

	
558 558
  typedef ListGraph Graph;
559 559
  typedef Graph::NodeMap<bool> NodeFilter;
560 560
  typedef Graph::EdgeMap<bool> EdgeFilter;
561
  typedef SubGraphAdaptor<Graph, NodeFilter, EdgeFilter> Adaptor;
561
  typedef SubGraph<Graph, NodeFilter, EdgeFilter> Adaptor;
562 562

	
563 563
  Graph graph;
564 564
  NodeFilter node_filter(graph);
565 565
  EdgeFilter edge_filter(graph);
566 566
  Adaptor adaptor(graph, node_filter, edge_filter);
567 567

	
568 568
  Graph::Node n1 = graph.addNode();
569 569
  Graph::Node n2 = graph.addNode();
570 570
  Graph::Node n3 = graph.addNode();
571 571
  Graph::Node n4 = graph.addNode();
572 572

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

	
578 578
  node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = true;
579 579
  edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = true;
580 580
  
581 581
  checkGraphNodeList(adaptor, 4);
582 582
  checkGraphArcList(adaptor, 8);
583 583
  checkGraphEdgeList(adaptor, 4);
584 584
  checkGraphConArcList(adaptor, 8);
585 585
  checkGraphConEdgeList(adaptor, 4);
586 586

	
587 587
  checkGraphOutArcList(adaptor, n1, 2);
588 588
  checkGraphOutArcList(adaptor, n2, 2);
589 589
  checkGraphOutArcList(adaptor, n3, 3);
590 590
  checkGraphOutArcList(adaptor, n4, 1);
591 591

	
592 592
  checkGraphInArcList(adaptor, n1, 2);
593 593
  checkGraphInArcList(adaptor, n2, 2);
594 594
  checkGraphInArcList(adaptor, n3, 3);
595 595
  checkGraphInArcList(adaptor, n4, 1);
596 596

	
597 597
  checkGraphIncEdgeList(adaptor, n1, 2);
598 598
  checkGraphIncEdgeList(adaptor, n2, 2);
599 599
  checkGraphIncEdgeList(adaptor, n3, 3);
600 600
  checkGraphIncEdgeList(adaptor, n4, 1);
601 601

	
602 602
  checkNodeIds(adaptor);
603 603
  checkArcIds(adaptor);
604 604
  checkEdgeIds(adaptor);
605 605

	
606 606
  checkGraphNodeMap(adaptor);
607 607
  checkGraphArcMap(adaptor);
608 608
  checkGraphEdgeMap(adaptor);
609 609

	
610
  edge_filter[e2] = false; 
610
  edge_filter[e2] = false;
611 611

	
612 612
  checkGraphNodeList(adaptor, 4);
613 613
  checkGraphArcList(adaptor, 6);
614 614
  checkGraphEdgeList(adaptor, 3);
615 615
  checkGraphConArcList(adaptor, 6);
616 616
  checkGraphConEdgeList(adaptor, 3);
617 617

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

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

	
628 628
  checkGraphIncEdgeList(adaptor, n1, 1);
629 629
  checkGraphIncEdgeList(adaptor, n2, 2);
630 630
  checkGraphIncEdgeList(adaptor, n3, 2);
631 631
  checkGraphIncEdgeList(adaptor, n4, 1);
632 632

	
633 633
  checkNodeIds(adaptor);
634 634
  checkArcIds(adaptor);
635 635
  checkEdgeIds(adaptor);
636 636

	
637 637
  checkGraphNodeMap(adaptor);
638 638
  checkGraphArcMap(adaptor);
639 639
  checkGraphEdgeMap(adaptor);
640 640

	
641
  node_filter[n1] = false; 
641
  node_filter[n1] = false;
642 642

	
643 643
  checkGraphNodeList(adaptor, 3);
644 644
  checkGraphArcList(adaptor, 4);
645 645
  checkGraphEdgeList(adaptor, 2);
646 646
  checkGraphConArcList(adaptor, 4);
647 647
  checkGraphConEdgeList(adaptor, 2);
648 648

	
649 649
  checkGraphOutArcList(adaptor, n2, 1);
650 650
  checkGraphOutArcList(adaptor, n3, 2);
651 651
  checkGraphOutArcList(adaptor, n4, 1);
652 652

	
653 653
  checkGraphInArcList(adaptor, n2, 1);
654 654
  checkGraphInArcList(adaptor, n3, 2);
655 655
  checkGraphInArcList(adaptor, n4, 1);
656 656

	
657 657
  checkGraphIncEdgeList(adaptor, n2, 1);
658 658
  checkGraphIncEdgeList(adaptor, n3, 2);
659 659
  checkGraphIncEdgeList(adaptor, n4, 1);
660 660

	
661 661
  checkNodeIds(adaptor);
662 662
  checkArcIds(adaptor);
663 663
  checkEdgeIds(adaptor);
664 664

	
665 665
  checkGraphNodeMap(adaptor);
666 666
  checkGraphArcMap(adaptor);
667 667
  checkGraphEdgeMap(adaptor);
668 668

	
669 669
  node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = false;
670 670
  edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = false;
671 671

	
672 672
  checkGraphNodeList(adaptor, 0);
673 673
  checkGraphArcList(adaptor, 0);
674 674
  checkGraphEdgeList(adaptor, 0);
675 675
  checkGraphConArcList(adaptor, 0);
676 676
  checkGraphConEdgeList(adaptor, 0);
677 677

	
678 678
  checkNodeIds(adaptor);
679 679
  checkArcIds(adaptor);
680 680
  checkEdgeIds(adaptor);
681 681

	
682 682
  checkGraphNodeMap(adaptor);
683 683
  checkGraphArcMap(adaptor);
684 684
  checkGraphEdgeMap(adaptor);
685 685
}
686 686

	
687
void checkNodeSubGraphAdaptor() {
688
  checkConcept<concepts::Graph, 
689
    NodeSubGraphAdaptor<concepts::Graph, 
687
void checkFilterNodes2() {
688
  checkConcept<concepts::Graph,
689
    FilterNodes<concepts::Graph,
690 690
      concepts::Graph::NodeMap<bool> > >();
691 691

	
692 692
  typedef ListGraph Graph;
693 693
  typedef Graph::NodeMap<bool> NodeFilter;
694
  typedef NodeSubGraphAdaptor<Graph, NodeFilter> Adaptor;
694
  typedef FilterNodes<Graph, NodeFilter> Adaptor;
695 695

	
696 696
  Graph graph;
697 697
  NodeFilter node_filter(graph);
698 698
  Adaptor adaptor(graph, node_filter);
699 699

	
700 700
  Graph::Node n1 = graph.addNode();
701 701
  Graph::Node n2 = graph.addNode();
702 702
  Graph::Node n3 = graph.addNode();
703 703
  Graph::Node n4 = graph.addNode();
704 704

	
705 705
  Graph::Edge e1 = graph.addEdge(n1, n2);
706 706
  Graph::Edge e2 = graph.addEdge(n1, n3);
707 707
  Graph::Edge e3 = graph.addEdge(n2, n3);
708 708
  Graph::Edge e4 = graph.addEdge(n3, n4);
709 709

	
710 710
  node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = true;
711 711
  
712 712
  checkGraphNodeList(adaptor, 4);
713 713
  checkGraphArcList(adaptor, 8);
714 714
  checkGraphEdgeList(adaptor, 4);
715 715
  checkGraphConArcList(adaptor, 8);
716 716
  checkGraphConEdgeList(adaptor, 4);
717 717

	
718 718
  checkGraphOutArcList(adaptor, n1, 2);
719 719
  checkGraphOutArcList(adaptor, n2, 2);
720 720
  checkGraphOutArcList(adaptor, n3, 3);
721 721
  checkGraphOutArcList(adaptor, n4, 1);
722 722

	
723 723
  checkGraphInArcList(adaptor, n1, 2);
724 724
  checkGraphInArcList(adaptor, n2, 2);
725 725
  checkGraphInArcList(adaptor, n3, 3);
726 726
  checkGraphInArcList(adaptor, n4, 1);
727 727

	
728 728
  checkGraphIncEdgeList(adaptor, n1, 2);
729 729
  checkGraphIncEdgeList(adaptor, n2, 2);
730 730
  checkGraphIncEdgeList(adaptor, n3, 3);
731 731
  checkGraphIncEdgeList(adaptor, n4, 1);
732 732

	
733 733
  checkNodeIds(adaptor);
734 734
  checkArcIds(adaptor);
735 735
  checkEdgeIds(adaptor);
736 736

	
737 737
  checkGraphNodeMap(adaptor);
738 738
  checkGraphArcMap(adaptor);
739 739
  checkGraphEdgeMap(adaptor);
740 740

	
741
  node_filter[n1] = false; 
741
  node_filter[n1] = false;
742 742

	
743 743
  checkGraphNodeList(adaptor, 3);
744 744
  checkGraphArcList(adaptor, 4);
745 745
  checkGraphEdgeList(adaptor, 2);
746 746
  checkGraphConArcList(adaptor, 4);
747 747
  checkGraphConEdgeList(adaptor, 2);
748 748

	
749 749
  checkGraphOutArcList(adaptor, n2, 1);
750 750
  checkGraphOutArcList(adaptor, n3, 2);
751 751
  checkGraphOutArcList(adaptor, n4, 1);
752 752

	
753 753
  checkGraphInArcList(adaptor, n2, 1);
754 754
  checkGraphInArcList(adaptor, n3, 2);
755 755
  checkGraphInArcList(adaptor, n4, 1);
756 756

	
757 757
  checkGraphIncEdgeList(adaptor, n2, 1);
758 758
  checkGraphIncEdgeList(adaptor, n3, 2);
759 759
  checkGraphIncEdgeList(adaptor, n4, 1);
760 760

	
761 761
  checkNodeIds(adaptor);
762 762
  checkArcIds(adaptor);
763 763
  checkEdgeIds(adaptor);
764 764

	
765 765
  checkGraphNodeMap(adaptor);
766 766
  checkGraphArcMap(adaptor);
767 767
  checkGraphEdgeMap(adaptor);
768 768

	
769 769
  node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = false;
770 770

	
771 771
  checkGraphNodeList(adaptor, 0);
772 772
  checkGraphArcList(adaptor, 0);
773 773
  checkGraphEdgeList(adaptor, 0);
774 774
  checkGraphConArcList(adaptor, 0);
775 775
  checkGraphConEdgeList(adaptor, 0);
776 776

	
777 777
  checkNodeIds(adaptor);
778 778
  checkArcIds(adaptor);
779 779
  checkEdgeIds(adaptor);
780 780

	
781 781
  checkGraphNodeMap(adaptor);
782 782
  checkGraphArcMap(adaptor);
783 783
  checkGraphEdgeMap(adaptor);
784 784
}
785 785

	
786
void checkEdgeSubGraphAdaptor() {
787
  checkConcept<concepts::Graph, 
788
    EdgeSubGraphAdaptor<concepts::Graph, 
786
void checkFilterEdges() {
787
  checkConcept<concepts::Graph,
788
    FilterEdges<concepts::Graph,
789 789
    concepts::Graph::EdgeMap<bool> > >();
790 790

	
791 791
  typedef ListGraph Graph;
792 792
  typedef Graph::EdgeMap<bool> EdgeFilter;
793
  typedef EdgeSubGraphAdaptor<Graph, EdgeFilter> Adaptor;
793
  typedef FilterEdges<Graph, EdgeFilter> Adaptor;
794 794

	
795 795
  Graph graph;
796 796
  EdgeFilter edge_filter(graph);
797 797
  Adaptor adaptor(graph, edge_filter);
798 798

	
799 799
  Graph::Node n1 = graph.addNode();
800 800
  Graph::Node n2 = graph.addNode();
801 801
  Graph::Node n3 = graph.addNode();
802 802
  Graph::Node n4 = graph.addNode();
803 803

	
804 804
  Graph::Edge e1 = graph.addEdge(n1, n2);
805 805
  Graph::Edge e2 = graph.addEdge(n1, n3);
806 806
  Graph::Edge e3 = graph.addEdge(n2, n3);
807 807
  Graph::Edge e4 = graph.addEdge(n3, n4);
808 808

	
809 809
  edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = true;
810 810
  
811 811
  checkGraphNodeList(adaptor, 4);
812 812
  checkGraphArcList(adaptor, 8);
813 813
  checkGraphEdgeList(adaptor, 4);
814 814
  checkGraphConArcList(adaptor, 8);
815 815
  checkGraphConEdgeList(adaptor, 4);
816 816

	
817 817
  checkGraphOutArcList(adaptor, n1, 2);
818 818
  checkGraphOutArcList(adaptor, n2, 2);
819 819
  checkGraphOutArcList(adaptor, n3, 3);
820 820
  checkGraphOutArcList(adaptor, n4, 1);
821 821

	
822 822
  checkGraphInArcList(adaptor, n1, 2);
823 823
  checkGraphInArcList(adaptor, n2, 2);
824 824
  checkGraphInArcList(adaptor, n3, 3);
825 825
  checkGraphInArcList(adaptor, n4, 1);
826 826

	
827 827
  checkGraphIncEdgeList(adaptor, n1, 2);
828 828
  checkGraphIncEdgeList(adaptor, n2, 2);
829 829
  checkGraphIncEdgeList(adaptor, n3, 3);
830 830
  checkGraphIncEdgeList(adaptor, n4, 1);
831 831

	
832 832
  checkNodeIds(adaptor);
833 833
  checkArcIds(adaptor);
834 834
  checkEdgeIds(adaptor);
835 835

	
836 836
  checkGraphNodeMap(adaptor);
837 837
  checkGraphArcMap(adaptor);
838 838
  checkGraphEdgeMap(adaptor);
839 839

	
840
  edge_filter[e2] = false; 
840
  edge_filter[e2] = false;
841 841

	
842 842
  checkGraphNodeList(adaptor, 4);
843 843
  checkGraphArcList(adaptor, 6);
844 844
  checkGraphEdgeList(adaptor, 3);
845 845
  checkGraphConArcList(adaptor, 6);
846 846
  checkGraphConEdgeList(adaptor, 3);
847 847

	
848 848
  checkGraphOutArcList(adaptor, n1, 1);
849 849
  checkGraphOutArcList(adaptor, n2, 2);
850 850
  checkGraphOutArcList(adaptor, n3, 2);
851 851
  checkGraphOutArcList(adaptor, n4, 1);
852 852

	
853 853
  checkGraphInArcList(adaptor, n1, 1);
854 854
  checkGraphInArcList(adaptor, n2, 2);
855 855
  checkGraphInArcList(adaptor, n3, 2);
856 856
  checkGraphInArcList(adaptor, n4, 1);
857 857

	
858 858
  checkGraphIncEdgeList(adaptor, n1, 1);
859 859
  checkGraphIncEdgeList(adaptor, n2, 2);
860 860
  checkGraphIncEdgeList(adaptor, n3, 2);
861 861
  checkGraphIncEdgeList(adaptor, n4, 1);
862 862

	
863 863
  checkNodeIds(adaptor);
864 864
  checkArcIds(adaptor);
865 865
  checkEdgeIds(adaptor);
866 866

	
867 867
  checkGraphNodeMap(adaptor);
868 868
  checkGraphArcMap(adaptor);
869 869
  checkGraphEdgeMap(adaptor);
870 870

	
871 871
  edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = false;
872 872

	
873 873
  checkGraphNodeList(adaptor, 4);
874 874
  checkGraphArcList(adaptor, 0);
875 875
  checkGraphEdgeList(adaptor, 0);
876 876
  checkGraphConArcList(adaptor, 0);
877 877
  checkGraphConEdgeList(adaptor, 0);
878 878

	
879 879
  checkNodeIds(adaptor);
880 880
  checkArcIds(adaptor);
881 881
  checkEdgeIds(adaptor);
882 882

	
883 883
  checkGraphNodeMap(adaptor);
884 884
  checkGraphArcMap(adaptor);
885 885
  checkGraphEdgeMap(adaptor);
886 886
}
887 887

	
888
void checkDirGraphAdaptor() {
889
  checkConcept<concepts::Digraph, 
890
    DirGraphAdaptor<concepts::Graph, concepts::Graph::EdgeMap<bool> > >();
888
void checkOrienter() {
889
  checkConcept<concepts::Digraph,
890
    Orienter<concepts::Graph, concepts::Graph::EdgeMap<bool> > >();
891 891

	
892 892
  typedef ListGraph Graph;
893 893
  typedef ListGraph::EdgeMap<bool> DirMap;
894
  typedef DirGraphAdaptor<Graph> Adaptor;
894
  typedef Orienter<Graph> Adaptor;
895 895

	
896 896
  Graph graph;
897 897
  DirMap dir(graph, true);
898 898
  Adaptor adaptor(graph, dir);
899 899

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

	
904 904
  Graph::Edge e1 = graph.addEdge(n1, n2);
905 905
  Graph::Edge e2 = graph.addEdge(n1, n3);
906 906
  Graph::Edge e3 = graph.addEdge(n2, n3);
907
  
907

	
908 908
  checkGraphNodeList(adaptor, 3);
909 909
  checkGraphArcList(adaptor, 3);
910 910
  checkGraphConArcList(adaptor, 3);
911
  
911

	
912 912
  {
913 913
    dir[e1] = true;
914 914
    Adaptor::Node u = adaptor.source(e1);
915 915
    Adaptor::Node v = adaptor.target(e1);
916
    
916

	
917 917
    dir[e1] = false;
918 918
    check (u == adaptor.target(e1), "Wrong dir");
919 919
    check (v == adaptor.source(e1), "Wrong dir");
920 920

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

	
925 925
  {
926 926
    dir[e2] = true;
927 927
    Adaptor::Node u = adaptor.source(e2);
928 928
    Adaptor::Node v = adaptor.target(e2);
929
    
929

	
930 930
    dir[e2] = false;
931 931
    check (u == adaptor.target(e2), "Wrong dir");
932 932
    check (v == adaptor.source(e2), "Wrong dir");
933 933

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

	
938 938
  {
939 939
    dir[e3] = true;
940 940
    Adaptor::Node u = adaptor.source(e3);
941 941
    Adaptor::Node v = adaptor.target(e3);
942
    
942

	
943 943
    dir[e3] = false;
944 944
    check (u == adaptor.target(e3), "Wrong dir");
945 945
    check (v == adaptor.source(e3), "Wrong dir");
946 946

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

	
951 951
  checkGraphOutArcList(adaptor, n1, 1);
952 952
  checkGraphOutArcList(adaptor, n2, 1);
953 953
  checkGraphOutArcList(adaptor, n3, 1);
954 954

	
955 955
  checkGraphInArcList(adaptor, n1, 1);
956 956
  checkGraphInArcList(adaptor, n2, 1);
957 957
  checkGraphInArcList(adaptor, n3, 1);
958 958

	
959 959
  checkNodeIds(adaptor);
960 960
  checkArcIds(adaptor);
961 961

	
962 962
  checkGraphNodeMap(adaptor);
963 963
  checkGraphArcMap(adaptor);
964 964

	
965 965
}
966 966

	
967 967

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

	
970
  checkRevDigraphAdaptor();
971
  checkSubDigraphAdaptor();
972
  checkNodeSubDigraphAdaptor();
973
  checkArcSubDigraphAdaptor();
974
  checkUndirDigraphAdaptor();
975
  checkResDigraphAdaptor();
976
  checkSplitDigraphAdaptor();
970
  checkReverseDigraph();
971
  checkSubDigraph();
972
  checkFilterNodes1();
973
  checkFilterArcs();
974
  checkUndirector();
975
  checkResidual();
976
  checkSplitNodes();
977 977

	
978
  checkSubGraphAdaptor();
979
  checkNodeSubGraphAdaptor();
980
  checkEdgeSubGraphAdaptor();
981
  checkDirGraphAdaptor();
978
  checkSubGraph();
979
  checkFilterNodes2();
980
  checkFilterEdges();
981
  checkOrienter();
982 982

	
983 983
  return 0;
984 984
}
Ignore white space 6 line context
1
/* -*- C++ -*-
2
 *
3
 * This file is a part of LEMON, a generic C++ optimization library
4
 *
5
 * Copyright (C) 2003-2008
6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8
 *
9
 * Permission to use, modify and distribute this software is granted
10
 * provided that this copyright notice appears in all copies. For
11
 * precise terms see the accompanying LICENSE file.
12
 *
13
 * This software is provided "AS IS" with no warranty of any kind,
14
 * express or implied, and with no claim as to its suitability for any
15
 * purpose.
16
 *
17
 */
18

	
19
#ifndef LEMON_GRAPH_ADAPTOR_H
20
#define LEMON_GRAPH_ADAPTOR_H
21

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

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

	
32
namespace lemon {
33

	
34
  template<typename _Graph>
35
  class GraphAdaptorBase {
36
  public:
37
    typedef _Graph Graph;
38
    typedef Graph ParentGraph;
39

	
40
  protected:
41
    Graph* _graph;
42

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	
137
      template <typename CMap>
138
      NodeMap& operator=(const CMap& cmap) {
139
        Parent::operator=(cmap);
140
        return *this;
141
      }
142
      
143
    };
144

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

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

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

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

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

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

	
187
  };
188

	
189
  template <typename _Graph, typename NodeFilterMap, 
190
	    typename EdgeFilterMap, bool checked = true>
191
  class SubGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
192
  public:
193
    typedef _Graph Graph;
194
    typedef SubGraphAdaptorBase Adaptor;
195
    typedef GraphAdaptorBase<_Graph> Parent;
196
  protected:
197

	
198
    NodeFilterMap* _node_filter_map;
199
    EdgeFilterMap* _edge_filter_map;
200

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

	
204
    void setNodeFilterMap(NodeFilterMap& node_filter_map) {
205
      _node_filter_map=&node_filter_map;
206
    }
207
    void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
208
      _edge_filter_map=&edge_filter_map;
209
    }
210

	
211
  public:
212

	
213
    typedef typename Parent::Node Node;
214
    typedef typename Parent::Arc Arc;
215
    typedef typename Parent::Edge Edge;
216

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

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

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

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

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

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

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

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

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

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

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

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

	
293
    void hide(const Node& n) const { _node_filter_map->set(n, false); }
294
    void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
295

	
296
    void unHide(const Node& n) const { _node_filter_map->set(n, true); }
297
    void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
298

	
299
    bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; }
300
    bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
301

	
302
    typedef False NodeNumTag;
303
    typedef False EdgeNumTag;
304

	
305
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
306
    Arc findArc(const Node& u, const Node& v, 
307
		  const Arc& prev = INVALID) {
308
      if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
309
        return INVALID;
310
      }
311
      Arc arc = Parent::findArc(u, v, prev);
312
      while (arc != INVALID && !(*_edge_filter_map)[arc]) {
313
        arc = Parent::findArc(u, v, arc);
314
      }
315
      return arc;
316
    }
317
    Edge findEdge(const Node& u, const Node& v, 
318
		  const Edge& prev = INVALID) {
319
      if (!(*_node_filter_map)[u] || !(*_node_filter_map)[v]) {
320
        return INVALID;
321
      }
322
      Edge edge = Parent::findEdge(u, v, prev);
323
      while (edge != INVALID && !(*_edge_filter_map)[edge]) {
324
        edge = Parent::findEdge(u, v, edge);
325
      }
326
      return edge;
327
    }
328

	
329
    template <typename _Value>
330
    class NodeMap : public SubMapExtender<Adaptor, 
331
        typename Parent::template NodeMap<_Value> > {
332
    public:
333
      typedef _Value Value;
334
      typedef SubMapExtender<Adaptor, typename Parent::
335
                             template NodeMap<Value> > MapParent;
336
    
337
      NodeMap(const Adaptor& adaptor) 
338
	: MapParent(adaptor) {}
339
      NodeMap(const Adaptor& adaptor, const Value& value) 
340
	: MapParent(adaptor, value) {}
341

	
342
    private:
343
      NodeMap& operator=(const NodeMap& cmap) {
344
	return operator=<NodeMap>(cmap);
345
      }
346
    
347
      template <typename CMap>
348
      NodeMap& operator=(const CMap& cmap) {
349
        MapParent::operator=(cmap);
350
	return *this;
351
      }
352
    };
353

	
354
    template <typename _Value>
355
    class ArcMap : public SubMapExtender<Adaptor, 
356
	typename Parent::template ArcMap<_Value> > {
357
    public:
358
      typedef _Value Value;
359
      typedef SubMapExtender<Adaptor, typename Parent::
360
                             template ArcMap<Value> > MapParent;
361
    
362
      ArcMap(const Adaptor& adaptor) 
363
	: MapParent(adaptor) {}
364
      ArcMap(const Adaptor& adaptor, const Value& value) 
365
	: MapParent(adaptor, value) {}
366

	
367
    private:
368
      ArcMap& operator=(const ArcMap& cmap) {
369
	return operator=<ArcMap>(cmap);
370
      }
371
    
372
      template <typename CMap>
373
      ArcMap& operator=(const CMap& cmap) {
374
        MapParent::operator=(cmap);
375
	return *this;
376
      }
377
    };
378

	
379
    template <typename _Value>
380
    class EdgeMap : public SubMapExtender<Adaptor, 
381
        typename Parent::template EdgeMap<_Value> > {
382
    public:
383
      typedef _Value Value;
384
      typedef SubMapExtender<Adaptor, typename Parent::
385
                             template EdgeMap<Value> > MapParent;
386
    
387
      EdgeMap(const Adaptor& adaptor) 
388
	: MapParent(adaptor) {}
389

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

	
393
    private:
394
      EdgeMap& operator=(const EdgeMap& cmap) {
395
	return operator=<EdgeMap>(cmap);
396
      }
397
    
398
      template <typename CMap>
399
      EdgeMap& operator=(const CMap& cmap) {
400
        MapParent::operator=(cmap);
401
	return *this;
402
      }
403
    };
404

	
405
  };
406

	
407
  template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
408
  class SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap, false> 
409
    : public GraphAdaptorBase<_Graph> {
410
  public:
411
    typedef _Graph Graph;
412
    typedef SubGraphAdaptorBase Adaptor;
413
    typedef GraphAdaptorBase<_Graph> Parent;
414
  protected:
415
    NodeFilterMap* _node_filter_map;
416
    EdgeFilterMap* _edge_filter_map;
417
    SubGraphAdaptorBase() : Parent(), 
418
			    _node_filter_map(0), _edge_filter_map(0) { }
419

	
420
    void setNodeFilterMap(NodeFilterMap& node_filter_map) {
421
      _node_filter_map=&node_filter_map;
422
    }
423
    void setEdgeFilterMap(EdgeFilterMap& edge_filter_map) {
424
      _edge_filter_map=&edge_filter_map;
425
    }
426

	
427
  public:
428

	
429
    typedef typename Parent::Node Node;
430
    typedef typename Parent::Arc Arc;
431
    typedef typename Parent::Edge Edge;
432

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

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

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

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

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

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

	
463
    void next(Node& i) const { 
464
      Parent::next(i); 
465
      while (i!=INVALID && !(*_node_filter_map)[i]) Parent::next(i); 
466
    }
467
    void next(Arc& i) const { 
468
      Parent::next(i); 
469
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i); 
470
    }
471
    void next(Edge& i) const { 
472
      Parent::next(i); 
473
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::next(i); 
474
    }
475
    void nextIn(Arc& i) const { 
476
      Parent::nextIn(i); 
477
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextIn(i); 
478
    }
479

	
480
    void nextOut(Arc& i) const { 
481
      Parent::nextOut(i); 
482
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextOut(i); 
483
    }
484
    void nextInc(Edge& i, bool& d) const { 
485
      Parent::nextInc(i, d); 
486
      while (i!=INVALID && !(*_edge_filter_map)[i]) Parent::nextInc(i, d); 
487
    }
488

	
489
    void hide(const Node& n) const { _node_filter_map->set(n, false); }
490
    void hide(const Edge& e) const { _edge_filter_map->set(e, false); }
491

	
492
    void unHide(const Node& n) const { _node_filter_map->set(n, true); }
493
    void unHide(const Edge& e) const { _edge_filter_map->set(e, true); }
494

	
495
    bool hidden(const Node& n) const { return !(*_node_filter_map)[n]; }
496
    bool hidden(const Edge& e) const { return !(*_edge_filter_map)[e]; }
497

	
498
    typedef False NodeNumTag;
499
    typedef False EdgeNumTag;
500

	
501
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
502
    Arc findArc(const Node& u, const Node& v, 
503
		  const Arc& prev = INVALID) {
504
      Arc arc = Parent::findArc(u, v, prev);
505
      while (arc != INVALID && !(*_edge_filter_map)[arc]) {
506
        arc = Parent::findArc(u, v, arc);
507
      }
508
      return arc;
509
    }
510
    Edge findEdge(const Node& u, const Node& v, 
511
		  const Edge& prev = INVALID) {
512
      Edge edge = Parent::findEdge(u, v, prev);
513
      while (edge != INVALID && !(*_edge_filter_map)[edge]) {
514
        edge = Parent::findEdge(u, v, edge);
515
      }
516
      return edge;
517
    }
518

	
519
    template <typename _Value>
520
    class NodeMap : public SubMapExtender<Adaptor, 
521
        typename Parent::template NodeMap<_Value> > {
522
    public:
523
      typedef _Value Value;
524
      typedef SubMapExtender<Adaptor, typename Parent::
525
                             template NodeMap<Value> > MapParent;
526
    
527
      NodeMap(const Adaptor& adaptor) 
528
	: MapParent(adaptor) {}
529
      NodeMap(const Adaptor& adaptor, const Value& value) 
530
	: MapParent(adaptor, value) {}
531
    
532
    private:
533
      NodeMap& operator=(const NodeMap& cmap) {
534
	return operator=<NodeMap>(cmap);
535
      }
536
    
537
      template <typename CMap>
538
      NodeMap& operator=(const CMap& cmap) {
539
        MapParent::operator=(cmap);
540
	return *this;
541
      }
542
    };
543

	
544
    template <typename _Value>
545
    class ArcMap : public SubMapExtender<Adaptor, 
546
	typename Parent::template ArcMap<_Value> > {
547
    public:
548
      typedef _Value Value;
549
      typedef SubMapExtender<Adaptor, typename Parent::
550
                             template ArcMap<Value> > MapParent;
551
    
552
      ArcMap(const Adaptor& adaptor) 
553
	: MapParent(adaptor) {}
554
      ArcMap(const Adaptor& adaptor, const Value& value) 
555
	: MapParent(adaptor, value) {}
556

	
557
    private:
558
      ArcMap& operator=(const ArcMap& cmap) {
559
	return operator=<ArcMap>(cmap);
560
      }
561
    
562
      template <typename CMap>
563
      ArcMap& operator=(const CMap& cmap) {
564
        MapParent::operator=(cmap);
565
	return *this;
566
      }
567
    };
568

	
569
    template <typename _Value>
570
    class EdgeMap : public SubMapExtender<Adaptor, 
571
        typename Parent::template EdgeMap<_Value> > {
572
    public:
573
      typedef _Value Value;
574
      typedef SubMapExtender<Adaptor, typename Parent::
575
                             template EdgeMap<Value> > MapParent;
576
    
577
      EdgeMap(const Adaptor& adaptor) 
578
	: MapParent(adaptor) {}
579

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

	
583
    private:
584
      EdgeMap& operator=(const EdgeMap& cmap) {
585
	return operator=<EdgeMap>(cmap);
586
      }
587
    
588
      template <typename CMap>
589
      EdgeMap& operator=(const CMap& cmap) {
590
        MapParent::operator=(cmap);
591
	return *this;
592
      }
593
    };
594

	
595
  };
596

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

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

	
625
  protected:
626
    SubGraphAdaptor() { }
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.
633
    SubGraphAdaptor(Graph& _graph, NodeFilterMap& node_filter_map, 
634
		    EdgeFilterMap& edge_filter_map) { 
635
      setGraph(_graph);
636
      setNodeFilterMap(node_filter_map);
637
      setEdgeFilterMap(edge_filter_map);
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); }
679
  };
680

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

	
692
  template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
693
  SubGraphAdaptor<const Graph, const NodeFilterMap, ArcFilterMap>
694
  subGraphAdaptor(const Graph& graph, 
695
                   NodeFilterMap& nfm, ArcFilterMap& efm) {
696
    return SubGraphAdaptor<const Graph, const NodeFilterMap, ArcFilterMap>
697
      (graph, nfm, efm);
698
  }
699

	
700
  template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
701
  SubGraphAdaptor<const Graph, NodeFilterMap, const ArcFilterMap>
702
  subGraphAdaptor(const Graph& graph, 
703
                   NodeFilterMap& nfm, ArcFilterMap& efm) {
704
    return SubGraphAdaptor<const Graph, NodeFilterMap, const ArcFilterMap>
705
      (graph, nfm, efm);
706
  }
707

	
708
  template<typename Graph, typename NodeFilterMap, typename ArcFilterMap>
709
  SubGraphAdaptor<const Graph, const NodeFilterMap, const ArcFilterMap>
710
  subGraphAdaptor(const Graph& graph, 
711
                   NodeFilterMap& nfm, ArcFilterMap& efm) {
712
    return SubGraphAdaptor<const Graph, const NodeFilterMap, 
713
      const ArcFilterMap>(graph, nfm, efm);
714
  }
715

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

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

	
739
    NodeSubGraphAdaptor() : const_true_map(true) {
740
      Parent::setEdgeFilterMap(const_true_map);
741
    }
742

	
743
  public:
744

	
745
    /// \brief Constructor
746
    ///
747
    /// Creates a node-sub-graph-adaptor for the given graph with
748
    /// given node map filters.
749
    NodeSubGraphAdaptor(Graph& _graph, NodeFilterMap& node_filter_map) : 
750
      Parent(), const_true_map(true) { 
751
      Parent::setGraph(_graph);
752
      Parent::setNodeFilterMap(node_filter_map);
753
      Parent::setEdgeFilterMap(const_true_map);
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

	
776
  };
777

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

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

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

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

	
821
  public:
822

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

	
854
  };
855

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

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

	
871
  template <typename _Graph, typename _DirectionMap>
872
  class DirGraphAdaptorBase {
873
  public:
874
    
875
    typedef _Graph Graph;
876
    typedef _DirectionMap DirectionMap;
877

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

	
888
    void first(Node& i) const { _graph->first(i); }
889
    void first(Arc& i) const { _graph->first(i); }
890
    void firstIn(Arc& i, const Node& n) const {
891
      bool d;
892
      _graph->firstInc(i, d, n);
893
      while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
894
    }
895
    void firstOut(Arc& i, const Node& n ) const { 
896
      bool d;
897
      _graph->firstInc(i, d, n);
898
      while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
899
    }
900

	
901
    void next(Node& i) const { _graph->next(i); }
902
    void next(Arc& i) const { _graph->next(i); }
903
    void nextIn(Arc& i) const {
904
      bool d = !(*_direction)[i];
905
      _graph->nextInc(i, d);
906
      while (i != INVALID && d == (*_direction)[i]) _graph->nextInc(i, d);
907
    }
908
    void nextOut(Arc& i) const {
909
      bool d = (*_direction)[i];
910
      _graph->nextInc(i, d);
911
      while (i != INVALID && d != (*_direction)[i]) _graph->nextInc(i, d);
912
    }
913

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

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

	
927
    typedef FindEdgeTagIndicator<Graph> FindEdgeTag;
928
    Arc findArc(const Node& u, const Node& v, 
929
		  const Arc& prev = INVALID) {
930
      Arc arc = prev;
931
      bool d = arc == INVALID ? true : (*_direction)[arc];
932
      if (d) {
933
        arc = _graph->findEdge(u, v, arc);
934
        while (arc != INVALID && !(*_direction)[arc]) {
935
          _graph->findEdge(u, v, arc);
936
        }
937
        if (arc != INVALID) return arc;
938
      }
939
      _graph->findEdge(v, u, arc);
940
      while (arc != INVALID && (*_direction)[arc]) {
941
        _graph->findEdge(u, v, arc);
942
      }
943
      return arc;
944
    }
945
  
946
    Node addNode() { 
947
      return Node(_graph->addNode()); 
948
    }
949

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

	
956
    void erase(const Node& i) { _graph->erase(i); }
957
    void erase(const Arc& i) { _graph->erase(i); }
958
  
959
    void clear() { _graph->clear(); }
960
    
961
    int id(const Node& v) const { return _graph->id(v); }
962
    int id(const Arc& e) const { return _graph->id(e); }
963

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

	
967
    int maxNodeId() const { return _graph->maxNodeId(); }
968
    int maxArcId() const { return _graph->maxEdgeId(); }
969

	
970
    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
971
    NodeNotifier& notifier(Node) const { return _graph->notifier(Node()); } 
972

	
973
    typedef typename ItemSetTraits<Graph, Arc>::ItemNotifier ArcNotifier;
974
    ArcNotifier& notifier(Arc) const { return _graph->notifier(Arc()); } 
975

	
976
    template <typename _Value>
977
    class NodeMap : public _Graph::template NodeMap<_Value> {
978
    public:
979

	
980
      typedef typename _Graph::template NodeMap<_Value> Parent;
981

	
982
      explicit NodeMap(const DirGraphAdaptorBase& adapter) 
983
	: Parent(*adapter._graph) {}
984

	
985
      NodeMap(const DirGraphAdaptorBase& adapter, const _Value& value)
986
	: Parent(*adapter._graph, value) {}
987

	
988
    private:
989
      NodeMap& operator=(const NodeMap& cmap) {
990
        return operator=<NodeMap>(cmap);
991
      }
992

	
993
      template <typename CMap>
994
      NodeMap& operator=(const CMap& cmap) {
995
        Parent::operator=(cmap);
996
        return *this;
997
      }
998

	
999
    };
1000

	
1001
    template <typename _Value>
1002
    class ArcMap : public _Graph::template EdgeMap<_Value> {
1003
    public:
1004

	
1005
      typedef typename Graph::template EdgeMap<_Value> Parent;
1006

	
1007
      explicit ArcMap(const DirGraphAdaptorBase& adapter) 
1008
	: Parent(*adapter._graph) { }
1009

	
1010
      ArcMap(const DirGraphAdaptorBase& adapter, const _Value& value)
1011
	: Parent(*adapter._graph, value) { }
1012

	
1013
    private:
1014
      ArcMap& operator=(const ArcMap& cmap) {
1015
        return operator=<ArcMap>(cmap);
1016
      }
1017

	
1018
      template <typename CMap>
1019
      ArcMap& operator=(const CMap& cmap) {
1020
        Parent::operator=(cmap);
1021
        return *this;
1022
      }
1023
    };
1024

	
1025
    
1026

	
1027
  protected:
1028
    Graph* _graph;
1029
    DirectionMap* _direction;
1030

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

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

	
1039
  };
1040

	
1041

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

	
1147
  /// \brief Just gives back a DirGraphAdaptor
1148
  ///
1149
  /// Just gives back a DirGraphAdaptor
1150
  template<typename Graph, typename DirectionMap>
1151
  DirGraphAdaptor<const Graph, DirectionMap>
1152
  dirGraphAdaptor(const Graph& graph, DirectionMap& dm) {
1153
    return DirGraphAdaptor<const Graph, DirectionMap>(graph, dm);
1154
  }
1155

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

	
1162
}
1163

	
1164
#endif
0 comments (0 inline)