gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Happy New Year again - update the copyright headers + run the source unifier
! ! !
default
105 files changed:
↑ Collapse diff ↑
Ignore white space 6 line context
1 1
LEMON code without an explicit copyright is covered by the following
2 2
copyright/license.
3 3

	
4
Copyright (C) 2003-2008 Egervary Jeno Kombinatorikus Optimalizalasi
4
Copyright (C) 2003-2009 Egervary Jeno Kombinatorikus Optimalizalasi
5 5
Kutatocsoport (Egervary Combinatorial Optimization Research Group,
6 6
EGRES).
7 7

	
8 8
Permission is hereby granted, free of charge, to any person or organization
9 9
obtaining a copy of the software and accompanying documentation covered by
10 10
this license (the "Software") to use, reproduce, display, distribute,
11 11
execute, and transmit the Software, and to prepare derivative works of the
12 12
Software, and to permit third-parties to whom the Software is furnished to
13 13
do so, all subject to the following:
14 14

	
15 15
The copyright notices in the Software and this entire statement, including
16 16
the above license grant, this restriction and the following disclaimer,
17 17
must be included in all copies of the Software, in whole or in part, and
18 18
all derivative works of the Software, unless such copies or derivative
19 19
works are solely in the form of machine-executable object code generated by
20 20
a source language processor.
21 21

	
22 22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 24
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
25 25
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
26 26
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
27 27
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 28
DEALINGS IN THE SOFTWARE.
29 29

	
30 30
===========================================================================
31 31
This license is a verbatim copy of the Boost Software License, Version 1.0.
32 32

	
33 33

	
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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
///\ingroup demos
20 20
///\file
21 21
///\brief Argument parser demo
22 22
///
23 23
/// This example shows how the argument parser can be used.
24 24
///
25 25
/// \include arg_parser_demo.cc
26 26

	
27 27
#include <lemon/arg_parser.h>
28 28

	
29 29
using namespace lemon;
30 30
int main(int argc, char **argv)
31 31
{
32 32
  // Initialize the argument parser
33 33
  ArgParser ap(argc, argv);
34 34
  int i;
35 35
  std::string s;
36 36
  double d = 1.0;
37 37
  bool b, nh;
38 38
  bool g1, g2, g3;
39 39

	
40 40
  // Add a mandatory integer option with storage reference
41 41
  ap.refOption("n", "An integer input.", i, true);
42 42
  // Add a double option with storage reference (the default value is 1.0)
43 43
  ap.refOption("val", "A double input.", d);
44 44
  // Add a double option without storage reference (the default value is 3.14)
45 45
  ap.doubleOption("val2", "A double input.", 3.14);
46 46
  // Set synonym for -val option
47 47
  ap.synonym("vals", "val");
48 48
  // Add a string option
49 49
  ap.refOption("name", "A string input.", s);
50 50
  // Add bool options
51 51
  ap.refOption("f", "A switch.", b)
52 52
    .refOption("nohelp", "", nh)
53 53
    .refOption("gra", "Choice A", g1)
54 54
    .refOption("grb", "Choice B", g2)
55 55
    .refOption("grc", "Choice C", g3);
56 56
  // Bundle -gr* options into a group
57 57
  ap.optionGroup("gr", "gra")
58 58
    .optionGroup("gr", "grb")
59 59
    .optionGroup("gr", "grc");
60 60
  // Set the group mandatory
61 61
  ap.mandatoryGroup("gr");
62 62
  // Set the options of the group exclusive (only one option can be given)
63 63
  ap.onlyOneGroup("gr");
64 64
  // Add non-parsed arguments (e.g. input files)
65 65
  ap.other("infile", "The input file.")
66 66
    .other("...");
67 67

	
68 68
  // Perform the parsing process
69 69
  // (in case of any error it terminates the program)
70 70
  ap.parse();
71 71

	
72 72
  // Check each option if it has been given and print its value
73 73
  std::cout << "Parameters of '" << ap.commandName() << "':\n";
74 74

	
75 75
  std::cout << "  Value of -n: " << i << std::endl;
76 76
  if(ap.given("val")) std::cout << "  Value of -val: " << d << std::endl;
77 77
  if(ap.given("val2")) {
78 78
    d = ap["val2"];
79 79
    std::cout << "  Value of -val2: " << d << std::endl;
80 80
  }
81 81
  if(ap.given("name")) std::cout << "  Value of -name: " << s << std::endl;
82 82
  if(ap.given("f")) std::cout << "  -f is given\n";
83 83
  if(ap.given("nohelp")) std::cout << "  Value of -nohelp: " << nh << std::endl;
84 84
  if(ap.given("gra")) std::cout << "  -gra is given\n";
85 85
  if(ap.given("grb")) std::cout << "  -grb is given\n";
86 86
  if(ap.given("grc")) std::cout << "  -grc is given\n";
87 87

	
88 88
  switch(ap.files().size()) {
89 89
  case 0:
90 90
    std::cout << "  No file argument was given.\n";
91 91
    break;
92 92
  case 1:
93 93
    std::cout << "  1 file argument was given. It is:\n";
94 94
    break;
95 95
  default:
96 96
    std::cout << "  "
97 97
              << ap.files().size() << " file arguments were given. They are:\n";
98 98
  }
99 99
  for(unsigned int i=0;i<ap.files().size();++i)
100 100
    std::cout << "    '" << ap.files()[i] << "'\n";
101 101

	
102 102
  return 0;
103 103
}
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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
/// \ingroup demos
20 20
/// \file
21 21
/// \brief Demo of the graph drawing function \ref graphToEps()
22 22
///
23 23
/// This demo program shows examples how to use the function \ref
24 24
/// graphToEps(). It takes no input but simply creates seven
25 25
/// <tt>.eps</tt> files demonstrating the capability of \ref
26 26
/// graphToEps(), and showing how to draw directed graphs,
27 27
/// how to handle parallel egdes, how to change the properties (like
28 28
/// color, shape, size, title etc.) of nodes and arcs individually
29 29
/// using appropriate graph maps.
30 30
///
31 31
/// \include graph_to_eps_demo.cc
32 32

	
33 33
#include<lemon/list_graph.h>
34 34
#include<lemon/graph_to_eps.h>
35 35
#include<lemon/math.h>
36 36

	
37 37
using namespace std;
38 38
using namespace lemon;
39 39

	
40 40
int main()
41 41
{
42 42
  Palette palette;
43 43
  Palette paletteW(true);
44 44

	
45 45
  // Create a small digraph
46 46
  ListDigraph g;
47 47
  typedef ListDigraph::Node Node;
48 48
  typedef ListDigraph::NodeIt NodeIt;
49 49
  typedef ListDigraph::Arc Arc;
50 50
  typedef dim2::Point<int> Point;
51 51

	
52 52
  Node n1=g.addNode();
53 53
  Node n2=g.addNode();
54 54
  Node n3=g.addNode();
55 55
  Node n4=g.addNode();
56 56
  Node n5=g.addNode();
57 57

	
58 58
  ListDigraph::NodeMap<Point> coords(g);
59 59
  ListDigraph::NodeMap<double> sizes(g);
60 60
  ListDigraph::NodeMap<int> colors(g);
61 61
  ListDigraph::NodeMap<int> shapes(g);
62 62
  ListDigraph::ArcMap<int> acolors(g);
63 63
  ListDigraph::ArcMap<int> widths(g);
64 64

	
65 65
  coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
66 66
  coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
67 67
  coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
68 68
  coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
69 69
  coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
70 70

	
71 71
  Arc a;
72 72

	
73 73
  a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1;
74 74
  a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1;
75 75
  a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3;
76 76
  a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1;
77 77
  a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1;
78 78
  a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2;
79 79
  a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1;
80 80

	
81 81
  IdMap<ListDigraph,Node> id(g);
82 82

	
83 83
  // Create .eps files showing the digraph with different options
84 84
  cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl;
85 85
  graphToEps(g,"graph_to_eps_demo_out_1_pure.eps").
86 86
    coords(coords).
87 87
    title("Sample .eps figure").
88
    copyright("(C) 2003-2008 LEMON Project").
88
    copyright("(C) 2003-2009 LEMON Project").
89 89
    run();
90 90

	
91 91
  cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl;
92 92
  graphToEps(g,"graph_to_eps_demo_out_2.eps").
93 93
    coords(coords).
94 94
    title("Sample .eps figure").
95
    copyright("(C) 2003-2008 LEMON Project").
95
    copyright("(C) 2003-2009 LEMON Project").
96 96
    absoluteNodeSizes().absoluteArcWidths().
97 97
    nodeScale(2).nodeSizes(sizes).
98 98
    nodeShapes(shapes).
99 99
    nodeColors(composeMap(palette,colors)).
100 100
    arcColors(composeMap(palette,acolors)).
101 101
    arcWidthScale(.4).arcWidths(widths).
102 102
    nodeTexts(id).nodeTextSize(3).
103 103
    run();
104 104

	
105 105
  cout << "Create 'graph_to_eps_demo_out_3_arr.eps'" << endl;
106 106
  graphToEps(g,"graph_to_eps_demo_out_3_arr.eps").
107 107
    title("Sample .eps figure (with arrowheads)").
108
    copyright("(C) 2003-2008 LEMON Project").
108
    copyright("(C) 2003-2009 LEMON Project").
109 109
    absoluteNodeSizes().absoluteArcWidths().
110 110
    nodeColors(composeMap(palette,colors)).
111 111
    coords(coords).
112 112
    nodeScale(2).nodeSizes(sizes).
113 113
    nodeShapes(shapes).
114 114
    arcColors(composeMap(palette,acolors)).
115 115
    arcWidthScale(.4).arcWidths(widths).
116 116
    nodeTexts(id).nodeTextSize(3).
117 117
    drawArrows().arrowWidth(2).arrowLength(2).
118 118
    run();
119 119

	
120 120
  // Add more arcs to the digraph
121 121
  a=g.addArc(n1,n4); acolors[a]=2; widths[a]=1;
122 122
  a=g.addArc(n4,n1); acolors[a]=1; widths[a]=2;
123 123

	
124 124
  a=g.addArc(n1,n2); acolors[a]=1; widths[a]=1;
125 125
  a=g.addArc(n1,n2); acolors[a]=2; widths[a]=1;
126 126
  a=g.addArc(n1,n2); acolors[a]=3; widths[a]=1;
127 127
  a=g.addArc(n1,n2); acolors[a]=4; widths[a]=1;
128 128
  a=g.addArc(n1,n2); acolors[a]=5; widths[a]=1;
129 129
  a=g.addArc(n1,n2); acolors[a]=6; widths[a]=1;
130 130
  a=g.addArc(n1,n2); acolors[a]=7; widths[a]=1;
131 131

	
132 132
  cout << "Create 'graph_to_eps_demo_out_4_par.eps'" << endl;
133 133
  graphToEps(g,"graph_to_eps_demo_out_4_par.eps").
134 134
    title("Sample .eps figure (parallel arcs)").
135
    copyright("(C) 2003-2008 LEMON Project").
135
    copyright("(C) 2003-2009 LEMON Project").
136 136
    absoluteNodeSizes().absoluteArcWidths().
137 137
    nodeShapes(shapes).
138 138
    coords(coords).
139 139
    nodeScale(2).nodeSizes(sizes).
140 140
    nodeColors(composeMap(palette,colors)).
141 141
    arcColors(composeMap(palette,acolors)).
142 142
    arcWidthScale(.4).arcWidths(widths).
143 143
    nodeTexts(id).nodeTextSize(3).
144 144
    enableParallel().parArcDist(1.5).
145 145
    run();
146 146

	
147 147
  cout << "Create 'graph_to_eps_demo_out_5_par_arr.eps'" << endl;
148 148
  graphToEps(g,"graph_to_eps_demo_out_5_par_arr.eps").
149 149
    title("Sample .eps figure (parallel arcs and arrowheads)").
150
    copyright("(C) 2003-2008 LEMON Project").
150
    copyright("(C) 2003-2009 LEMON Project").
151 151
    absoluteNodeSizes().absoluteArcWidths().
152 152
    nodeScale(2).nodeSizes(sizes).
153 153
    coords(coords).
154 154
    nodeShapes(shapes).
155 155
    nodeColors(composeMap(palette,colors)).
156 156
    arcColors(composeMap(palette,acolors)).
157 157
    arcWidthScale(.3).arcWidths(widths).
158 158
    nodeTexts(id).nodeTextSize(3).
159 159
    enableParallel().parArcDist(1).
160 160
    drawArrows().arrowWidth(1).arrowLength(1).
161 161
    run();
162 162

	
163 163
  cout << "Create 'graph_to_eps_demo_out_6_par_arr_a4.eps'" << endl;
164 164
  graphToEps(g,"graph_to_eps_demo_out_6_par_arr_a4.eps").
165 165
    title("Sample .eps figure (fits to A4)").
166
    copyright("(C) 2003-2008 LEMON Project").
166
    copyright("(C) 2003-2009 LEMON Project").
167 167
    scaleToA4().
168 168
    absoluteNodeSizes().absoluteArcWidths().
169 169
    nodeScale(2).nodeSizes(sizes).
170 170
    coords(coords).
171 171
    nodeShapes(shapes).
172 172
    nodeColors(composeMap(palette,colors)).
173 173
    arcColors(composeMap(palette,acolors)).
174 174
    arcWidthScale(.3).arcWidths(widths).
175 175
    nodeTexts(id).nodeTextSize(3).
176 176
    enableParallel().parArcDist(1).
177 177
    drawArrows().arrowWidth(1).arrowLength(1).
178 178
    run();
179 179

	
180 180
  // Create an .eps file showing the colors of a default Palette
181 181
  ListDigraph h;
182 182
  ListDigraph::NodeMap<int> hcolors(h);
183 183
  ListDigraph::NodeMap<Point> hcoords(h);
184 184

	
185 185
  int cols=int(sqrt(double(palette.size())));
186 186
  for(int i=0;i<int(paletteW.size());i++) {
187 187
    Node n=h.addNode();
188 188
    hcoords[n]=Point(1+i%cols,1+i/cols);
189 189
    hcolors[n]=i;
190 190
  }
191 191

	
192 192
  cout << "Create 'graph_to_eps_demo_out_7_colors.eps'" << endl;
193 193
  graphToEps(h,"graph_to_eps_demo_out_7_colors.eps").
194 194
    scale(60).
195 195
    title("Sample .eps figure (Palette demo)").
196
    copyright("(C) 2003-2008 LEMON Project").
196
    copyright("(C) 2003-2009 LEMON Project").
197 197
    coords(hcoords).
198 198
    absoluteNodeSizes().absoluteArcWidths().
199 199
    nodeScale(.45).
200 200
    distantColorNodeTexts().
201 201
    nodeTexts(hcolors).nodeTextSize(.6).
202 202
    nodeColors(composeMap(paletteW,hcolors)).
203 203
    run();
204 204

	
205 205
  return 0;
206 206
}
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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
///\ingroup demos
20 20
///\file
21 21
///\brief Demonstrating graph input and output
22 22
///
23 23
/// This program gives an example of how to read and write a digraph
24 24
/// and additional maps from/to a stream or a file using the
25 25
/// \ref lgf-format "LGF" format.
26 26
///
27 27
/// The \c "digraph.lgf" file:
28 28
/// \include digraph.lgf
29 29
///
30 30
/// And the program which reads it and prints the digraph to the
31 31
/// standard output:
32 32
/// \include lgf_demo.cc
33 33

	
34 34
#include <iostream>
35 35
#include <lemon/smart_graph.h>
36 36
#include <lemon/lgf_reader.h>
37 37
#include <lemon/lgf_writer.h>
38 38

	
39 39
using namespace lemon;
40 40

	
41 41
int main() {
42 42
  SmartDigraph g;
43 43
  SmartDigraph::ArcMap<int> cap(g);
44 44
  SmartDigraph::Node s, t;
45 45

	
46 46
  try {
47 47
    digraphReader(g, "digraph.lgf"). // read the directed graph into g
48 48
      arcMap("capacity", cap).       // read the 'capacity' arc map into cap
49 49
      node("source", s).             // read 'source' node to s
50 50
      node("target", t).             // read 'target' node to t
51 51
      run();
52 52
  } catch (Exception& error) { // check if there was any error
53 53
    std::cerr << "Error: " << error.what() << std::endl;
54 54
    return -1;
55 55
  }
56 56

	
57 57
  std::cout << "A digraph is read from 'digraph.lgf'." << std::endl;
58 58
  std::cout << "Number of nodes: " << countNodes(g) << std::endl;
59 59
  std::cout << "Number of arcs: " << countArcs(g) << std::endl;
60 60

	
61 61
  std::cout << "We can write it to the standard output:" << std::endl;
62 62

	
63 63
  digraphWriter(g).                // write g to the standard output
64 64
    arcMap("capacity", cap).       // write cap into 'capacity'
65 65
    node("source", s).             // write s to 'source'
66 66
    node("target", t).             // write t to 'target'
67 67
    run();
68 68

	
69 69
  return 0;
70 70
}
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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

	
21 21
\page coding_style LEMON Coding Style
22 22

	
23 23
\section naming_conv Naming Conventions
24 24

	
25 25
In order to make development easier we have made some conventions
26 26
according to coding style. These include names of types, classes,
27 27
functions, variables, constants and exceptions. If these conventions
28 28
are met in one's code then it is easier to read and maintain
29 29
it. Please comply with these conventions if you want to contribute
30 30
developing LEMON library.
31 31

	
32 32
\note When the coding style requires the capitalization of an abbreviation,
33 33
only the first letter should be upper case.
34 34

	
35 35
\code
36 36
XmlReader
37 37
\endcode
38 38

	
39 39

	
40 40
\warning In some cases we diverge from these rules.
41 41
This is primary done because STL uses different naming convention and
42 42
in certain cases
43 43
it is beneficial to provide STL compatible interface.
44 44

	
45 45
\subsection cs-files File Names
46 46

	
47 47
The header file names should look like the following.
48 48

	
49 49
\code
50 50
header_file.h
51 51
\endcode
52 52

	
53 53
Note that all standard LEMON headers are located in the \c lemon subdirectory,
54 54
so you should include them from C++ source like this:
55 55

	
56 56
\code
57 57
#include <lemon/header_file.h>
58 58
\endcode
59 59

	
60 60
The source code files use the same style and they have '.cc' extension.
61 61

	
62 62
\code
63 63
source_code.cc
64 64
\endcode
65 65

	
66 66
\subsection cs-class Classes and other types
67 67

	
68 68
The name of a class or any type should look like the following.
69 69

	
70 70
\code
71 71
AllWordsCapitalizedWithoutUnderscores
72 72
\endcode
73 73

	
74 74
\subsection cs-func Methods and other functions
75 75

	
76 76
The name of a function should look like the following.
77 77

	
78 78
\code
79 79
firstWordLowerCaseRestCapitalizedWithoutUnderscores
80 80
\endcode
81 81

	
82 82
\subsection cs-funcs Constants, Macros
83 83

	
84 84
The names of constants and macros should look like the following.
85 85

	
86 86
\code
87 87
ALL_UPPER_CASE_WITH_UNDERSCORES
88 88
\endcode
89 89

	
90 90
\subsection cs-loc-var Class and instance member variables, auto variables
91 91

	
92 92
The names of class and instance member variables and auto variables
93 93
(=variables used locally in methods) should look like the following.
94 94

	
95 95
\code
96 96
all_lower_case_with_underscores
97 97
\endcode
98 98

	
99 99
\subsection pri-loc-var Private member variables
100 100

	
101 101
Private member variables should start with underscore
102 102

	
103 103
\code
104 104
_start_with_underscores
105 105
\endcode
106 106

	
107 107
\subsection cs-excep Exceptions
108 108

	
109 109
When writing exceptions please comply the following naming conventions.
110 110

	
111 111
\code
112 112
ClassNameEndsWithException
113 113
\endcode
114 114

	
115 115
or
116 116

	
117 117
\code
118 118
ClassNameEndsWithError
119 119
\endcode
120 120

	
121 121
\section header-template Template Header File
122 122

	
123 123
Each LEMON header file should look like this:
124 124

	
125 125
\include template.h
126 126

	
127 127
*/
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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
\dir demo
21 21
\brief A collection of demo applications.
22 22

	
23 23
This directory contains several simple demo applications, mainly
24 24
for educational purposes.
25 25
*/
26 26

	
27 27
/**
28 28
\dir doc
29 29
\brief Auxiliary (and the whole generated) documentation.
30 30

	
31 31
This directory contains some auxiliary pages and the whole generated
32 32
documentation.
33 33
*/
34 34

	
35 35
/**
36 36
\dir test
37 37
\brief Test programs.
38 38

	
39 39
This directory contains several test programs that check the consistency
40 40
of the code.
41 41
*/
42 42

	
43 43
/**
44 44
\dir tools
45 45
\brief Some useful executables.
46 46

	
47 47
This directory contains the sources of some useful complete executables.
48 48
*/
49 49

	
50 50
/**
51 51
\dir lemon
52 52
\brief Base include directory of LEMON.
53 53

	
54 54
This is the base directory of LEMON includes, so each include file must be
55 55
prefixed with this, e.g.
56 56
\code
57 57
#include<lemon/list_graph.h>
58 58
#include<lemon/dijkstra.h>
59 59
\endcode
60 60
*/
61 61

	
62 62
/**
63 63
\dir concepts
64 64
\brief Concept descriptors and checking classes.
65 65

	
66 66
This directory contains the concept descriptors and concept checking tools.
67 67
For more information see the \ref concept "Concepts" module.
68 68
*/
69 69

	
70 70
/**
71 71
\dir bits
72 72
\brief Auxiliary tools for implementation.
73 73

	
74
This directory contains some auxiliary classes for implementing graphs, 
74
This directory contains some auxiliary classes for implementing graphs,
75 75
maps and some other classes.
76 76
As a user you typically don't have to deal with these files.
77 77
*/
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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
namespace lemon {
20 20

	
21 21
/**
22 22
@defgroup datas Data Structures
23 23
This group describes the several data structures implemented in LEMON.
24 24
*/
25 25

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

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

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

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

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

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

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

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

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

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

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

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

	
137 137
/**
138 138
@defgroup semi_adaptors Semi-Adaptor Classes for Graphs
139 139
@ingroup graphs
140 140
\brief Graph types between real graphs and graph adaptors.
141 141

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

	
147 147
/**
148 148
@defgroup maps Maps
149 149
@ingroup datas
150 150
\brief Map structures implemented in LEMON.
151 151

	
152 152
This group describes the map structures implemented in LEMON.
153 153

	
154 154
LEMON provides several special purpose maps and map adaptors that e.g. combine
155 155
new maps from existing ones.
156 156

	
157 157
<b>See also:</b> \ref map_concepts "Map Concepts".
158 158
*/
159 159

	
160 160
/**
161 161
@defgroup graph_maps Graph Maps
162 162
@ingroup maps
163 163
\brief Special graph-related maps.
164 164

	
165 165
This group describes maps that are specifically designed to assign
166 166
values to the nodes and arcs/edges of graphs.
167 167

	
168 168
If you are looking for the standard graph maps (\c NodeMap, \c ArcMap,
169 169
\c EdgeMap), see the \ref graph_concepts "Graph Structure Concepts".
170 170
*/
171 171

	
172 172
/**
173 173
\defgroup map_adaptors Map Adaptors
174 174
\ingroup maps
175 175
\brief Tools to create new maps from existing ones
176 176

	
177 177
This group describes map adaptors that are used to create "implicit"
178 178
maps from other maps.
179 179

	
180 180
Most of them are \ref concepts::ReadMap "read-only maps".
181 181
They can make arithmetic and logical operations between one or two maps
182 182
(negation, shifting, addition, multiplication, logical 'and', 'or',
183 183
'not' etc.) or e.g. convert a map to another one of different Value type.
184 184

	
185 185
The typical usage of this classes is passing implicit maps to
186 186
algorithms.  If a function type algorithm is called then the function
187 187
type map adaptors can be used comfortable. For example let's see the
188 188
usage of map adaptors with the \c graphToEps() function.
189 189
\code
190 190
  Color nodeColor(int deg) {
191 191
    if (deg >= 2) {
192 192
      return Color(0.5, 0.0, 0.5);
193 193
    } else if (deg == 1) {
194 194
      return Color(1.0, 0.5, 1.0);
195 195
    } else {
196 196
      return Color(0.0, 0.0, 0.0);
197 197
    }
198 198
  }
199 199

	
200 200
  Digraph::NodeMap<int> degree_map(graph);
201 201

	
202 202
  graphToEps(graph, "graph.eps")
203 203
    .coords(coords).scaleToA4().undirected()
204 204
    .nodeColors(composeMap(functorToMap(nodeColor), degree_map))
205 205
    .run();
206 206
\endcode
207 207
The \c functorToMap() function makes an \c int to \c Color map from the
208 208
\c nodeColor() function. The \c composeMap() compose the \c degree_map
209 209
and the previously created map. The composed map is a proper function to
210 210
get the color of each node.
211 211

	
212 212
The usage with class type algorithms is little bit harder. In this
213 213
case the function type map adaptors can not be used, because the
214 214
function map adaptors give back temporary objects.
215 215
\code
216 216
  Digraph graph;
217 217

	
218 218
  typedef Digraph::ArcMap<double> DoubleArcMap;
219 219
  DoubleArcMap length(graph);
220 220
  DoubleArcMap speed(graph);
221 221

	
222 222
  typedef DivMap<DoubleArcMap, DoubleArcMap> TimeMap;
223 223
  TimeMap time(length, speed);
224 224

	
225 225
  Dijkstra<Digraph, TimeMap> dijkstra(graph, time);
226 226
  dijkstra.run(source, target);
227 227
\endcode
228 228
We have a length map and a maximum speed map on the arcs of a digraph.
229 229
The minimum time to pass the arc can be calculated as the division of
230 230
the two maps which can be done implicitly with the \c DivMap template
231 231
class. We use the implicit minimum time map as the length map of the
232 232
\c Dijkstra algorithm.
233 233
*/
234 234

	
235 235
/**
236 236
@defgroup matrices Matrices
237 237
@ingroup datas
238 238
\brief Two dimensional data storages implemented in LEMON.
239 239

	
240 240
This group describes two dimensional data storages implemented in LEMON.
241 241
*/
242 242

	
243 243
/**
244 244
@defgroup paths Path Structures
245 245
@ingroup datas
246 246
\brief %Path structures implemented in LEMON.
247 247

	
248 248
This group describes the path structures implemented in LEMON.
249 249

	
250 250
LEMON provides flexible data structures to work with paths.
251 251
All of them have similar interfaces and they can be copied easily with
252 252
assignment operators and copy constructors. This makes it easy and
253 253
efficient to have e.g. the Dijkstra algorithm to store its result in
254 254
any kind of path structure.
255 255

	
256 256
\sa lemon::concepts::Path
257 257
*/
258 258

	
259 259
/**
260 260
@defgroup auxdat Auxiliary Data Structures
261 261
@ingroup datas
262 262
\brief Auxiliary data structures implemented in LEMON.
263 263

	
264 264
This group describes some data structures implemented in LEMON in
265 265
order to make it easier to implement combinatorial algorithms.
266 266
*/
267 267

	
268 268
/**
269 269
@defgroup algs Algorithms
270 270
\brief This group describes the several algorithms
271 271
implemented in LEMON.
272 272

	
273 273
This group describes the several algorithms
274 274
implemented in LEMON.
275 275
*/
276 276

	
277 277
/**
278 278
@defgroup search Graph Search
279 279
@ingroup algs
280 280
\brief Common graph search algorithms.
281 281

	
282 282
This group describes the common graph search algorithms, namely
283 283
\e breadth-first \e search (BFS) and \e depth-first \e search (DFS).
284 284
*/
285 285

	
286 286
/**
287 287
@defgroup shortest_path Shortest Path Algorithms
288 288
@ingroup algs
289 289
\brief Algorithms for finding shortest paths.
290 290

	
291 291
This group describes the algorithms for finding shortest paths in digraphs.
292 292

	
293 293
 - \ref Dijkstra algorithm for finding shortest paths from a source node
294 294
   when all arc lengths are non-negative.
295 295
 - \ref BellmanFord "Bellman-Ford" algorithm for finding shortest paths
296 296
   from a source node when arc lenghts can be either positive or negative,
297 297
   but the digraph should not contain directed cycles with negative total
298 298
   length.
299 299
 - \ref FloydWarshall "Floyd-Warshall" and \ref Johnson "Johnson" algorithms
300 300
   for solving the \e all-pairs \e shortest \e paths \e problem when arc
301 301
   lenghts can be either positive or negative, but the digraph should
302 302
   not contain directed cycles with negative total length.
303 303
 - \ref Suurballe A successive shortest path algorithm for finding
304 304
   arc-disjoint paths between two nodes having minimum total length.
305 305
*/
306 306

	
307 307
/**
308 308
@defgroup max_flow Maximum Flow Algorithms
309 309
@ingroup algs
310 310
\brief Algorithms for finding maximum flows.
311 311

	
312 312
This group describes the algorithms for finding maximum flows and
313 313
feasible circulations.
314 314

	
315 315
The \e maximum \e flow \e problem is to find a flow of maximum value between
316 316
a single source and a single target. Formally, there is a \f$G=(V,A)\f$
317 317
digraph, a \f$cap:A\rightarrow\mathbf{R}^+_0\f$ capacity function and
318 318
\f$s, t \in V\f$ source and target nodes.
319 319
A maximum flow is an \f$f:A\rightarrow\mathbf{R}^+_0\f$ solution of the
320 320
following optimization problem.
321 321

	
322 322
\f[ \max\sum_{a\in\delta_{out}(s)}f(a) - \sum_{a\in\delta_{in}(s)}f(a) \f]
323 323
\f[ \sum_{a\in\delta_{out}(v)} f(a) = \sum_{a\in\delta_{in}(v)} f(a)
324 324
    \qquad \forall v\in V\setminus\{s,t\} \f]
325 325
\f[ 0 \leq f(a) \leq cap(a) \qquad \forall a\in A \f]
326 326

	
327 327
LEMON contains several algorithms for solving maximum flow problems:
328 328
- \ref EdmondsKarp Edmonds-Karp algorithm.
329 329
- \ref Preflow Goldberg-Tarjan's preflow push-relabel algorithm.
330 330
- \ref DinitzSleatorTarjan Dinitz's blocking flow algorithm with dynamic trees.
331 331
- \ref GoldbergTarjan Preflow push-relabel algorithm with dynamic trees.
332 332

	
333 333
In most cases the \ref Preflow "Preflow" algorithm provides the
334 334
fastest method for computing a maximum flow. All implementations
335 335
provides functions to also query the minimum cut, which is the dual
336 336
problem of the maximum flow.
337 337
*/
338 338

	
339 339
/**
340 340
@defgroup min_cost_flow Minimum Cost Flow Algorithms
341 341
@ingroup algs
342 342

	
343 343
\brief Algorithms for finding minimum cost flows and circulations.
344 344

	
345 345
This group describes the algorithms for finding minimum cost flows and
346 346
circulations.
347 347

	
348 348
The \e minimum \e cost \e flow \e problem is to find a feasible flow of
349 349
minimum total cost from a set of supply nodes to a set of demand nodes
350 350
in a network with capacity constraints and arc costs.
351 351
Formally, let \f$G=(V,A)\f$ be a digraph,
352 352
\f$lower, upper: A\rightarrow\mathbf{Z}^+_0\f$ denote the lower and
353 353
upper bounds for the flow values on the arcs,
354 354
\f$cost: A\rightarrow\mathbf{Z}^+_0\f$ denotes the cost per unit flow
355 355
on the arcs, and
356 356
\f$supply: V\rightarrow\mathbf{Z}\f$ denotes the supply/demand values
357 357
of the nodes.
358 358
A minimum cost flow is an \f$f:A\rightarrow\mathbf{R}^+_0\f$ solution of
359 359
the following optimization problem.
360 360

	
361 361
\f[ \min\sum_{a\in A} f(a) cost(a) \f]
362 362
\f[ \sum_{a\in\delta_{out}(v)} f(a) - \sum_{a\in\delta_{in}(v)} f(a) =
363 363
    supply(v) \qquad \forall v\in V \f]
364 364
\f[ lower(a) \leq f(a) \leq upper(a) \qquad \forall a\in A \f]
365 365

	
366 366
LEMON contains several algorithms for solving minimum cost flow problems:
367 367
 - \ref CycleCanceling Cycle-canceling algorithms.
368 368
 - \ref CapacityScaling Successive shortest path algorithm with optional
369 369
   capacity scaling.
370 370
 - \ref CostScaling Push-relabel and augment-relabel algorithms based on
371 371
   cost scaling.
372 372
 - \ref NetworkSimplex Primal network simplex algorithm with various
373 373
   pivot strategies.
374 374
*/
375 375

	
376 376
/**
377 377
@defgroup min_cut Minimum Cut Algorithms
378 378
@ingroup algs
379 379

	
380 380
\brief Algorithms for finding minimum cut in graphs.
381 381

	
382 382
This group describes the algorithms for finding minimum cut in graphs.
383 383

	
384 384
The \e minimum \e cut \e problem is to find a non-empty and non-complete
385 385
\f$X\f$ subset of the nodes with minimum overall capacity on
386 386
outgoing arcs. Formally, there is a \f$G=(V,A)\f$ digraph, a
387 387
\f$cap: A\rightarrow\mathbf{R}^+_0\f$ capacity function. The minimum
388 388
cut is the \f$X\f$ solution of the next optimization problem:
389 389

	
390 390
\f[ \min_{X \subset V, X\not\in \{\emptyset, V\}}
391 391
    \sum_{uv\in A, u\in X, v\not\in X}cap(uv) \f]
392 392

	
393 393
LEMON contains several algorithms related to minimum cut problems:
394 394

	
395 395
- \ref HaoOrlin "Hao-Orlin algorithm" for calculating minimum cut
396 396
  in directed graphs.
397 397
- \ref NagamochiIbaraki "Nagamochi-Ibaraki algorithm" for
398 398
  calculating minimum cut in undirected graphs.
399 399
- \ref GomoryHuTree "Gomory-Hu tree computation" for calculating
400 400
  all-pairs minimum cut in undirected graphs.
401 401

	
402 402
If you want to find minimum cut just between two distinict nodes,
403 403
see the \ref max_flow "maximum flow problem".
404 404
*/
405 405

	
406 406
/**
407 407
@defgroup graph_prop Connectivity and Other Graph Properties
408 408
@ingroup algs
409 409
\brief Algorithms for discovering the graph properties
410 410

	
411 411
This group describes the algorithms for discovering the graph properties
412 412
like connectivity, bipartiteness, euler property, simplicity etc.
413 413

	
414 414
\image html edge_biconnected_components.png
415 415
\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth
416 416
*/
417 417

	
418 418
/**
419 419
@defgroup planar Planarity Embedding and Drawing
420 420
@ingroup algs
421 421
\brief Algorithms for planarity checking, embedding and drawing
422 422

	
423 423
This group describes the algorithms for planarity checking,
424 424
embedding and drawing.
425 425

	
426 426
\image html planar.png
427 427
\image latex planar.eps "Plane graph" width=\textwidth
428 428
*/
429 429

	
430 430
/**
431 431
@defgroup matching Matching Algorithms
432 432
@ingroup algs
433 433
\brief Algorithms for finding matchings in graphs and bipartite graphs.
434 434

	
435 435
This group contains algorithm objects and functions to calculate
436 436
matchings in graphs and bipartite graphs. The general matching problem is
437 437
finding a subset of the arcs which does not shares common endpoints.
438 438

	
439 439
There are several different algorithms for calculate matchings in
440 440
graphs.  The matching problems in bipartite graphs are generally
441 441
easier than in general graphs. The goal of the matching optimization
442 442
can be finding maximum cardinality, maximum weight or minimum cost
443 443
matching. The search can be constrained to find perfect or
444 444
maximum cardinality matching.
445 445

	
446 446
The matching algorithms implemented in LEMON:
447 447
- \ref MaxBipartiteMatching Hopcroft-Karp augmenting path algorithm
448 448
  for calculating maximum cardinality matching in bipartite graphs.
449 449
- \ref PrBipartiteMatching Push-relabel algorithm
450 450
  for calculating maximum cardinality matching in bipartite graphs.
451 451
- \ref MaxWeightedBipartiteMatching
452 452
  Successive shortest path algorithm for calculating maximum weighted
453 453
  matching and maximum weighted bipartite matching in bipartite graphs.
454 454
- \ref MinCostMaxBipartiteMatching
455 455
  Successive shortest path algorithm for calculating minimum cost maximum
456 456
  matching in bipartite graphs.
457 457
- \ref MaxMatching Edmond's blossom shrinking algorithm for calculating
458 458
  maximum cardinality matching in general graphs.
459 459
- \ref MaxWeightedMatching Edmond's blossom shrinking algorithm for calculating
460 460
  maximum weighted matching in general graphs.
461 461
- \ref MaxWeightedPerfectMatching
462 462
  Edmond's blossom shrinking algorithm for calculating maximum weighted
463 463
  perfect matching in general graphs.
464 464

	
465 465
\image html bipartite_matching.png
466 466
\image latex bipartite_matching.eps "Bipartite Matching" width=\textwidth
467 467
*/
468 468

	
469 469
/**
470 470
@defgroup spantree Minimum Spanning Tree Algorithms
471 471
@ingroup algs
472 472
\brief Algorithms for finding a minimum cost spanning tree in a graph.
473 473

	
474 474
This group describes the algorithms for finding a minimum cost spanning
475 475
tree in a graph.
476 476
*/
477 477

	
478 478
/**
479 479
@defgroup auxalg Auxiliary Algorithms
480 480
@ingroup algs
481 481
\brief Auxiliary algorithms implemented in LEMON.
482 482

	
483 483
This group describes some algorithms implemented in LEMON
484 484
in order to make it easier to implement complex algorithms.
485 485
*/
486 486

	
487 487
/**
488 488
@defgroup approx Approximation Algorithms
489 489
@ingroup algs
490 490
\brief Approximation algorithms.
491 491

	
492 492
This group describes the approximation and heuristic algorithms
493 493
implemented in LEMON.
494 494
*/
495 495

	
496 496
/**
497 497
@defgroup gen_opt_group General Optimization Tools
498 498
\brief This group describes some general optimization frameworks
499 499
implemented in LEMON.
500 500

	
501 501
This group describes some general optimization frameworks
502 502
implemented in LEMON.
503 503
*/
504 504

	
505 505
/**
506 506
@defgroup lp_group Lp and Mip Solvers
507 507
@ingroup gen_opt_group
508 508
\brief Lp and Mip solver interfaces for LEMON.
509 509

	
510 510
This group describes Lp and Mip solver interfaces for LEMON. The
511 511
various LP solvers could be used in the same manner with this
512 512
interface.
513 513
*/
514 514

	
515 515
/**
516 516
@defgroup lp_utils Tools for Lp and Mip Solvers
517 517
@ingroup lp_group
518 518
\brief Helper tools to the Lp and Mip solvers.
519 519

	
520 520
This group adds some helper tools to general optimization framework
521 521
implemented in LEMON.
522 522
*/
523 523

	
524 524
/**
525 525
@defgroup metah Metaheuristics
526 526
@ingroup gen_opt_group
527 527
\brief Metaheuristics for LEMON library.
528 528

	
529 529
This group describes some metaheuristic optimization tools.
530 530
*/
531 531

	
532 532
/**
533 533
@defgroup utils Tools and Utilities
534 534
\brief Tools and utilities for programming in LEMON
535 535

	
536 536
Tools and utilities for programming in LEMON.
537 537
*/
538 538

	
539 539
/**
540 540
@defgroup gutils Basic Graph Utilities
541 541
@ingroup utils
542 542
\brief Simple basic graph utilities.
543 543

	
544 544
This group describes some simple basic graph utilities.
545 545
*/
546 546

	
547 547
/**
548 548
@defgroup misc Miscellaneous Tools
549 549
@ingroup utils
550 550
\brief Tools for development, debugging and testing.
551 551

	
552 552
This group describes several useful tools for development,
553 553
debugging and testing.
554 554
*/
555 555

	
556 556
/**
557 557
@defgroup timecount Time Measuring and Counting
558 558
@ingroup misc
559 559
\brief Simple tools for measuring the performance of algorithms.
560 560

	
561 561
This group describes simple tools for measuring the performance
562 562
of algorithms.
563 563
*/
564 564

	
565 565
/**
566 566
@defgroup exceptions Exceptions
567 567
@ingroup utils
568 568
\brief Exceptions defined in LEMON.
569 569

	
570 570
This group describes the exceptions defined in LEMON.
571 571
*/
572 572

	
573 573
/**
574 574
@defgroup io_group Input-Output
575 575
\brief Graph Input-Output methods
576 576

	
577 577
This group describes the tools for importing and exporting graphs
578 578
and graph related data. Now it supports the \ref lgf-format
579 579
"LEMON Graph Format", the \c DIMACS format and the encapsulated
580 580
postscript (EPS) format.
581 581
*/
582 582

	
583 583
/**
584 584
@defgroup lemon_io LEMON Graph Format
585 585
@ingroup io_group
586 586
\brief Reading and writing LEMON Graph Format.
587 587

	
588 588
This group describes methods for reading and writing
589 589
\ref lgf-format "LEMON Graph Format".
590 590
*/
591 591

	
592 592
/**
593 593
@defgroup eps_io Postscript Exporting
594 594
@ingroup io_group
595 595
\brief General \c EPS drawer and graph exporter
596 596

	
597 597
This group describes general \c EPS drawing methods and special
598 598
graph exporting tools.
599 599
*/
600 600

	
601 601
/**
602 602
@defgroup dimacs_group DIMACS format
603 603
@ingroup io_group
604 604
\brief Read and write files in DIMACS format
605 605

	
606 606
Tools to read a digraph from or write it to a file in DIMACS format data.
607 607
*/
608 608

	
609 609
/**
610 610
@defgroup nauty_group NAUTY Format
611 611
@ingroup io_group
612 612
\brief Read \e Nauty format
613 613

	
614 614
Tool to read graphs from \e Nauty format data.
615 615
*/
616 616

	
617 617
/**
618 618
@defgroup concept Concepts
619 619
\brief Skeleton classes and concept checking classes
620 620

	
621 621
This group describes the data/algorithm skeletons and concept checking
622 622
classes implemented in LEMON.
623 623

	
624 624
The purpose of the classes in this group is fourfold.
625 625

	
626 626
- These classes contain the documentations of the %concepts. In order
627 627
  to avoid document multiplications, an implementation of a concept
628 628
  simply refers to the corresponding concept class.
629 629

	
630 630
- These classes declare every functions, <tt>typedef</tt>s etc. an
631 631
  implementation of the %concepts should provide, however completely
632 632
  without implementations and real data structures behind the
633 633
  interface. On the other hand they should provide nothing else. All
634 634
  the algorithms working on a data structure meeting a certain concept
635 635
  should compile with these classes. (Though it will not run properly,
636 636
  of course.) In this way it is easily to check if an algorithm
637 637
  doesn't use any extra feature of a certain implementation.
638 638

	
639 639
- The concept descriptor classes also provide a <em>checker class</em>
640 640
  that makes it possible to check whether a certain implementation of a
641 641
  concept indeed provides all the required features.
642 642

	
643 643
- Finally, They can serve as a skeleton of a new implementation of a concept.
644 644
*/
645 645

	
646 646
/**
647 647
@defgroup graph_concepts Graph Structure Concepts
648 648
@ingroup concept
649 649
\brief Skeleton and concept checking classes for graph structures
650 650

	
651 651
This group describes the skeletons and concept checking classes of LEMON's
652 652
graph structures and helper classes used to implement these.
653 653
*/
654 654

	
655 655
/**
656 656
@defgroup map_concepts Map Concepts
657 657
@ingroup concept
658 658
\brief Skeleton and concept checking classes for maps
659 659

	
660 660
This group describes the skeletons and concept checking classes of maps.
661 661
*/
662 662

	
663 663
/**
664 664
\anchor demoprograms
665 665

	
666 666
@defgroup demos Demo Programs
667 667

	
668 668
Some demo programs are listed here. Their full source codes can be found in
669 669
the \c demo subdirectory of the source tree.
670 670

	
671 671
It order to compile them, use <tt>--enable-demo</tt> configure option when
672 672
build the library.
673 673
*/
674 674

	
675 675
/**
676 676
@defgroup tools Standalone Utility Applications
677 677

	
678 678
Some utility applications are listed here.
679 679

	
680 680
The standard compilation procedure (<tt>./configure;make</tt>) will compile
681 681
them, as well.
682 682
*/
683 683

	
684 684
}
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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
namespace lemon {
20 20
/*!
21 21

	
22 22

	
23 23

	
24 24
\page lgf-format LEMON Graph Format (LGF)
25 25

	
26 26
The \e LGF is a <em>column oriented</em>
27 27
file format for storing graphs and associated data like
28 28
node and edge maps.
29 29

	
30 30
Each line with \c '#' first non-whitespace
31 31
character is considered as a comment line.
32 32

	
33 33
Otherwise the file consists of sections starting with
34 34
a header line. The header lines starts with an \c '@' character followed by the
35 35
type of section. The standard section types are \c \@nodes, \c
36 36
\@arcs and \c \@edges
37 37
and \@attributes. Each header line may also have an optional
38 38
\e name, which can be use to distinguish the sections of the same
39 39
type.
40 40

	
41 41
The standard sections are column oriented, each line consists of
42 42
<em>token</em>s separated by whitespaces. A token can be \e plain or
43 43
\e quoted. A plain token is just a sequence of non-whitespace characters,
44 44
while a quoted token is a
45 45
character sequence surrounded by double quotes, and it can also
46 46
contain whitespaces and escape sequences.
47 47

	
48 48
The \c \@nodes section describes a set of nodes and associated
49 49
maps. The first is a header line, its columns are the names of the
50 50
maps appearing in the following lines.
51 51
One of the maps must be called \c
52 52
"label", which plays special role in the file.
53 53
The following
54 54
non-empty lines until the next section describes nodes of the
55 55
graph. Each line contains the values of the node maps
56 56
associated to the current node.
57 57

	
58 58
\code
59 59
 @nodes
60 60
 label  coordinates  size    title
61 61
 1      (10,20)      10      "First node"
62 62
 2      (80,80)      8       "Second node"
63 63
 3      (40,10)      10      "Third node"
64 64
\endcode
65 65

	
66 66
The \c \@arcs section is very similar to the \c \@nodes section,
67 67
it again starts with a header line describing the names of the maps,
68 68
but the \c "label" map is not obligatory here. The following lines
69 69
describe the arcs. The first two tokens of each line are
70 70
the source and the target node of the arc, respectively, then come the map
71 71
values. The source and target tokens must be node labels.
72 72

	
73 73
\code
74 74
 @arcs
75 75
         capacity
76 76
 1   2   16
77 77
 1   3   12
78 78
 2   3   18
79 79
\endcode
80 80

	
81 81
The \c \@edges is just a synonym of \c \@arcs. The \@arcs section can
82 82
also store the edge set of an undirected graph. In such case there is
83 83
a conventional method for store arc maps in the file, if two columns
84 84
has the same caption with \c '+' and \c '-' prefix, then these columns
85 85
can be regarded as the values of an arc map.
86 86

	
87 87
The \c \@attributes section contains key-value pairs, each line
88 88
consists of two tokens, an attribute name, and then an attribute
89 89
value. The value of the attribute could be also a label value of a
90 90
node or an edge, or even an edge label prefixed with \c '+' or \c '-',
91 91
which regards to the forward or backward directed arc of the
92 92
corresponding edge.
93 93

	
94 94
\code
95 95
 @attributes
96 96
 source 1
97 97
 target 3
98 98
 caption "LEMON test digraph"
99 99
\endcode
100 100

	
101 101
The \e LGF can contain extra sections, but there is no restriction on
102 102
the format of such sections.
103 103

	
104 104
*/
105 105
}
106 106

	
107 107
//  LocalWords:  whitespace whitespaces
Ignore white space 16384 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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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

	
21 21
\page license License Terms
22 22

	
23 23
\verbinclude LICENSE
24 24

	
25 25
*/
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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
\mainpage LEMON Documentation
21 21

	
22 22
\section intro Introduction
23 23

	
24 24
\subsection whatis What is LEMON
25 25

	
26 26
LEMON stands for
27 27
<b>L</b>ibrary of <b>E</b>fficient <b>M</b>odels
28 28
and <b>O</b>ptimization in <b>N</b>etworks.
29 29
It is a C++ template
30 30
library aimed at combinatorial optimization tasks which
31 31
often involve in working
32 32
with graphs.
33 33

	
34 34
<b>
35 35
LEMON is an <a class="el" href="http://opensource.org/">open&nbsp;source</a>
36 36
project.
37 37
You are free to use it in your commercial or
38 38
non-commercial applications under very permissive
39 39
\ref license "license terms".
40 40
</b>
41 41

	
42 42
\subsection howtoread How to read the documentation
43 43

	
44 44
If you want to get a quick start and see the most important features then
45 45
take a look at our \ref quicktour
46 46
"Quick Tour to LEMON" which will guide you along.
47 47

	
48 48
If you already feel like using our library, see the page that tells you
49 49
\ref getstart "How to start using LEMON".
50 50

	
51 51
If you
52 52
want to see how LEMON works, see
53 53
some \ref demoprograms "demo programs".
54 54

	
55 55
If you know what you are looking for then try to find it under the
56 56
<a class="el" href="modules.html">Modules</a>
57 57
section.
58 58

	
59 59
If you are a user of the old (0.x) series of LEMON, please check out the
60 60
\ref migration "Migration Guide" for the backward incompatibilities.
61 61
*/
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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
namespace lemon {
20 20
/*!
21 21

	
22 22
\page migration Migration from the 0.x Series
23 23

	
24 24
This guide gives an in depth description on what has changed compared
25 25
to the 0.x release series.
26 26

	
27 27
Many of these changes adjusted automatically by the
28 28
<tt>lemon-0.x-to-1.x.sh</tt> tool. Those requiring manual
29 29
update are typeset <b>boldface</b>.
30 30

	
31 31
\section migration-graph Graph Related Name Changes
32 32

	
33 33
- \ref concepts::Digraph "Directed graphs" are called \c Digraph and
34 34
  they have <tt>Arc</tt>s (instead of <tt>Edge</tt>s), while
35 35
  \ref concepts::Graph "undirected graphs" are called \c Graph
36 36
  (instead of \c UGraph) and they have <tt>Edge</tt>s (instead of
37 37
  <tt>UEdge</tt>s). These changes reflected thoroughly everywhere in
38 38
  the library. Namely,
39 39
  - \c Graph -> \c Digraph
40 40
    - \c %ListGraph -> \c ListDigraph, \c %SmartGraph -> \c SmartDigraph etc.
41 41
  - \c UGraph -> \c Graph
42 42
    - \c ListUGraph -> \c ListGraph, \c SmartUGraph -> \c SmartGraph etc.
43 43
  - \c Edge -> \c Arc, \c UEdge -> \c Edge
44 44
  - \c EdgeMap -> \c ArcMap, \c UEdgeMap -> \c EdgeMap
45 45
  - \c EdgeIt -> \c ArcIt, \c UEdgeIt -> \c EdgeIt
46 46
  - Class names and function names containing the words \c graph,
47 47
    \c ugraph, \e edge or \e arc should also be updated.
48 48
- <b>The two endpoints of an (\e undirected) \c Edge can be obtained by the
49 49
  <tt>u()</tt> and <tt>v()</tt> member function of the graph
50 50
  (instead of <tt>source()</tt> and <tt>target()</tt>). This change
51 51
  must be done by hand.</b>
52 52
  \n Of course, you can still use <tt>source()</tt> and <tt>target()</tt>
53 53
  for <tt>Arc</tt>s (directed edges).
54 54

	
55 55
\warning
56 56
<b>The <tt>lemon-0.x-to-1.x.sh</tt> script replaces the words \c graph,
57 57
\c ugraph, \c edge and \c uedge in your own identifiers and in
58 58
strings, comments etc. as well as in all LEMON specific identifiers.
59 59
So use the script carefully and make a backup copy of your source files
60 60
before applying the script to them.</b>
61 61

	
62 62
\section migration-lgf LGF tools
63 63
 - The \ref lgf-format "LGF file format" has changed,
64 64
   <tt>\@nodeset</tt> has changed to <tt>\@nodes</tt>,
65 65
   <tt>\@edgeset</tt> and <tt>\@uedgeset</tt> to <tt>\@arcs</tt> or
66 66
   <tt>\@edges</tt>, which become completely equivalents. The
67 67
   <tt>\@nodes</tt>, <tt>\@edges</tt> and <tt>\@uedges</tt> sections are
68 68
   removed from the format, the content of them should be
69 69
   the part of <tt>\@attributes</tt> section. The data fields in
70 70
   the sections must follow a strict format, they must be either character
71 71
   sequences without whitespaces or quoted strings.
72 72
 - The <tt>LemonReader</tt> and <tt>LemonWriter</tt> core interfaces
73 73
   are no longer available.
74 74
 - The implementation of the general section readers and writers has changed
75 75
   they are simple functors now. Beside the old
76 76
   stream based section handling, currently line oriented section
77 77
   reading and writing are also supported. In the
78 78
   section readers the lines must be counted manually. The sections
79 79
   should be read and written with the SectionWriter and SectionReader
80 80
   classes.
81 81
 - Instead of the item readers and writers, item converters should be
82 82
   used. The converters are functors, which map the type to
83 83
   std::string or std::string to the type. The converters for standard
84 84
   containers hasn't yet been implemented in the new LEMON. The converters
85 85
   can return strings in any format, because if it is necessary, the LGF
86 86
   writer and reader will quote and unquote the given value.
87 87
 - The DigraphReader and DigraphWriter can used similarly to the
88 88
   0.x series, however the <tt>read</tt> or <tt>write</tt> prefix of
89 89
   the member functions are removed.
90 90
 - The new LEMON supports the function like interface, the \c
91 91
   digraphReader and \c digraphWriter functions are more convenient than
92 92
   using the classes directly.
93 93

	
94 94
\section migration-search BFS, DFS and Dijkstra
95 95
- <b>Using the function interface of BFS, DFS and %Dijkstra both source and
96 96
  target nodes can be given as parameters of the <tt>run()</tt> function
97 97
  (instead of \c bfs(), \c dfs() or \c dijkstra() itself).</b>
98 98
- \ref named-templ-param "Named class template parameters" of \c Bfs,
99 99
  \c Dfs, \c Dijkstra, \c BfsVisit, \c DfsVisit are renamed to start
100 100
  with "Set" instead of "Def". Namely,
101 101
  - \c DefPredMap -> \c SetPredMap
102 102
  - \c DefDistMap -> \c SetDistMap
103 103
  - \c DefReachedMap -> \c SetReachedMap
104 104
  - \c DefProcessedMap -> \c SetProcessedMap
105 105
  - \c DefHeap -> \c SetHeap
106 106
  - \c DefStandardHeap -> \c SetStandardHeap
107 107
  - \c DefOperationTraits -> \c SetOperationTraits
108 108
  - \c DefProcessedMapToBeDefaultMap -> \c SetStandardProcessedMap
109 109

	
110 110
\section migration-error Exceptions and Debug tools
111 111

	
112 112
<b>The class hierarchy of exceptions has largely been simplified. Now,
113 113
only the i/o related tools may throw exceptions. All other exceptions
114 114
have been replaced with either the \c LEMON_ASSERT or the \c LEMON_DEBUG
115 115
macros.</b>
116 116

	
117 117
<b>On the other hand, the parameter order of constructors of the
118 118
exceptions has been changed. See \ref IoError and \ref FormatError for
119 119
more details.</b>
120 120

	
121 121
\section migration-other Others
122 122
- <b>The contents of <tt>graph_utils.h</tt> are moved to <tt>core.h</tt>
123 123
  and <tt>maps.h</tt>. <tt>core.h</tt> is included by all graph types,
124 124
  therefore it usually do not have to be included directly.</b>
125 125
- <b><tt>path_utils.h</tt> is merged to \c path.h.</b>
126 126
- <b>The semantic of the assignment operations and copy constructors of maps
127 127
  are still under discussion. So, you must copy them by hand (i.e. copy
128 128
  each entry one-by-one)</b>
129 129
- <b>The parameters of the graph copying tools (i.e. \c GraphCopy,
130 130
  \c DigraphCopy) have to be given in the from-to order.</b>
131 131
- \c copyDigraph() and \c copyGraph() are renamed to \c digraphCopy()
132 132
  and \c graphCopy(), respectively.
133 133
- <b>The interface of \ref DynArcLookUp has changed. It is now the same as
134 134
  of \ref ArcLookUp and \ref AllArcLookUp</b>
135 135
- Some map types should also been renamed. Namely,
136 136
  - \c IntegerMap -> \c RangeMap
137 137
  - \c StdMap -> \c SparseMap
138 138
  - \c FunctorMap -> \c FunctorToMap
139 139
  - \c MapFunctor -> \c MapToFunctor
140 140
  - \c ForkWriteMap -> \c ForkMap
141 141
  - \c StoreBoolMap -> \c LoggerBoolMap
142 142
- \c dim2::BoundingBox -> \c dim2::Box
143 143

	
144 144
*/
145 145
}
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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

	
21 21
\page named-param Named Parameters
22 22

	
23 23
\section named-func-param Named Function Parameters
24 24

	
25 25
Several modern languages provide a convenient way to refer the
26 26
function parameters by name also when you call the function. It is
27 27
especially comfortable in case of a function having tons of parameters
28 28
with natural default values. Sadly, C++ lack this amenity.
29 29

	
30 30
However, with a crafty trick and with some little
31 31
inconvenience, it is possible to emulate is.
32 32
The example below shows how to do it.
33 33

	
34 34
\code
35 35
class namedFn
36 36
{
37 37
  int _id;
38 38
  double _val;
39 39
  int _dim;
40 40

	
41 41
  public:
42 42
  namedFn() : _id(0), _val(1), _dim(2) {}
43 43
  namedFn& id(int p)     { _id  = p ; return *this; }
44 44
  namedFn& val(double p) { _val = p ; return *this; }
45 45
  namedFn& dim(int p)    { _dim = p ; return *this; }
46 46

	
47 47
  run() {
48 48
    std::cout << "Here comes the function itself\n" <<
49 49
              << "With parameters "
50 50
              << _id << ", " << _val << ", " << _dim << std::endl;
51 51
  }
52 52
};
53 53
\endcode
54 54

	
55 55
Then you can use it like this.
56 56

	
57 57
\code
58 58
namedFn().id(3).val(2).run();
59 59
\endcode
60 60

	
61 61
The trick is obvious, each "named parameter" changes one component of
62 62
the underlying class, then gives back a reference to it. Finally,
63 63
<tt>run()</tt> executes the algorithm itself.
64 64

	
65 65
\note Although it is a class, namedFn is used pretty much like as it were
66 66
a function. That it why we called it namedFn instead of \c NamedFn.
67 67

	
68 68
\note In fact, the final <tt>.run()</tt> could be made unnecessary,
69 69
because the algorithm could also be implemented in the destructor of
70 70
\c namedFn instead. This however would make it impossible to implement
71 71
functions with return values, and would also cause serious problems when
72 72
implementing \ref named-templ-func-param "named template parameters".
73 73
<b>Therefore, by convention, <tt>.run()</tt> must be used
74 74
explicitly to execute a function having named parameters
75 75
everywhere in LEMON.</b>
76 76

	
77 77
\section named-templ-func-param Named Function Template Parameters
78 78

	
79 79
A named parameter can also be a template function. The usage is
80 80
exactly the same, but the implementation behind is a kind of black
81 81
magic and they are the dirtiest part of the LEMON code.
82 82

	
83 83
You will probably never need to know how it works, but if you really
84 84
committed, have a look at \ref lemon/graph_to_eps.h for an example.
85 85

	
86 86
\section traits-classes Traits Classes
87 87

	
88 88
A similar game can also be played when defining classes. In this case
89 89
the type of the class attributes can be changed. Initially we have to
90 90
define a special class called <em>Traits Class</em> defining the
91 91
default type of the attributes. Then the types of these attributes can
92 92
be changed in the same way as described in the next section.
93 93

	
94 94
See \ref lemon::DijkstraDefaultTraits for an
95 95
example how a traits class implementation looks like.
96 96

	
97 97
\section named-templ-param Named Class Template Parameters
98 98

	
99 99
If we would like to change the type of an attribute in a class that
100 100
was instantiated by using a traits class as a template parameter, and
101 101
the class contains named parameters, we do not have to instantiate again
102 102
the class with new traits class, but instead adaptor classes can
103 103
be used as shown in the following example.
104 104

	
105 105
\code
106 106
Dijkstra<>::SetPredMap<NullMap<Node,Arc> >::Create
107 107
\endcode
108 108

	
109 109
It can also be used in conjunction with other named template
110 110
parameters in arbitrary order.
111 111

	
112 112
\code
113 113
Dijkstra<>::SetDistMap<MyMap>::SetPredMap<NullMap<Node,Arc> >::Create
114 114
\endcode
115 115

	
116 116
The result will be an instantiated Dijkstra class, in which the
117 117
DistMap and the PredMap is modified.
118 118

	
119 119
*/
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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
/// The namespace of LEMON
20 20

	
21 21
/// The namespace of LEMON
22 22
///
23 23
namespace lemon {
24 24

	
25 25
  /// The namespace of LEMON concepts and concept checking classes
26 26

	
27 27
  /// The namespace of LEMON concepts and concept checking classes
28 28
  ///
29 29
  namespace concepts {}
30 30
}
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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_TEMPLATE_H
20 20
#define LEMON_TEMPLATE_H
21 21

	
22 22
#endif // LEMON_TEMPLATE_H
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
        lemon/arg_parser.cc \
11
        lemon/base.cc \
12
        lemon/color.cc \
13
        lemon/random.cc
10
	lemon/arg_parser.cc \
11
	lemon/base.cc \
12
	lemon/color.cc \
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 19
	lemon/adaptors.h \
20
        lemon/arg_parser.h \
20
	lemon/arg_parser.h \
21 21
	lemon/assert.h \
22
        lemon/bfs.h \
23
        lemon/bin_heap.h \
24
        lemon/circulation.h \
25
        lemon/color.h \
22
	lemon/bfs.h \
23
	lemon/bin_heap.h \
24
	lemon/circulation.h \
25
	lemon/color.h \
26 26
	lemon/concept_check.h \
27
        lemon/counter.h \
27
	lemon/counter.h \
28 28
	lemon/core.h \
29
        lemon/dfs.h \
30
        lemon/dijkstra.h \
31
        lemon/dim2.h \
32
        lemon/dimacs.h \
29
	lemon/dfs.h \
30
	lemon/dijkstra.h \
31
	lemon/dim2.h \
32
	lemon/dimacs.h \
33 33
	lemon/elevator.h \
34 34
	lemon/error.h \
35 35
	lemon/full_graph.h \
36
        lemon/graph_to_eps.h \
37
        lemon/grid_graph.h \
36
	lemon/graph_to_eps.h \
37
	lemon/grid_graph.h \
38 38
	lemon/hypercube_graph.h \
39 39
	lemon/kruskal.h \
40 40
	lemon/hao_orlin.h \
41 41
	lemon/lgf_reader.h \
42 42
	lemon/lgf_writer.h \
43 43
	lemon/list_graph.h \
44 44
	lemon/maps.h \
45 45
	lemon/math.h \
46 46
	lemon/max_matching.h \
47 47
	lemon/nauty_reader.h \
48 48
	lemon/path.h \
49 49
	lemon/preflow.h \
50
        lemon/random.h \
50
	lemon/random.h \
51 51
	lemon/smart_graph.h \
52 52
	lemon/suurballe.h \
53
        lemon/time_measure.h \
54
        lemon/tolerance.h \
53
	lemon/time_measure.h \
54
	lemon/tolerance.h \
55 55
	lemon/unionfind.h
56 56

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

	
72 72
concept_HEADERS += \
73 73
	lemon/concepts/digraph.h \
74 74
	lemon/concepts/graph.h \
75 75
	lemon/concepts/graph_components.h \
76 76
	lemon/concepts/heap.h \
77 77
	lemon/concepts/maps.h \
78 78
	lemon/concepts/path.h
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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_ADAPTORS_H
20 20
#define LEMON_ADAPTORS_H
21 21

	
22 22
/// \ingroup graph_adaptors
23 23
/// \file
24 24
/// \brief Several graph adaptors
25 25
///
26 26
/// This file contains several useful 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 32
#include <lemon/bits/graph_adaptor_extender.h>
33 33
#include <lemon/tolerance.h>
34 34

	
35 35
#include <algorithm>
36 36

	
37 37
namespace lemon {
38 38

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	
127 127
    };
128 128

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

	
133 133
      typedef typename Digraph::template ArcMap<_Value> Parent;
134 134

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

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

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

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

	
152 152
    };
153 153

	
154 154
  };
155 155

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

	
162 162
  protected:
163 163
    Graph* _graph;
164 164

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	
265 265
    };
266 266

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

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

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

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

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

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

	
309 309
  };
310 310

	
311 311
  template <typename _Digraph>
312 312
  class ReverseDigraphBase : public DigraphAdaptorBase<_Digraph> {
313 313
  public:
314 314
    typedef _Digraph Digraph;
315 315
    typedef DigraphAdaptorBase<_Digraph> Parent;
316 316
  protected:
317 317
    ReverseDigraphBase() : Parent() { }
318 318
  public:
319 319
    typedef typename Parent::Node Node;
320 320
    typedef typename Parent::Arc Arc;
321 321

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

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

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

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

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

	
339 339
  };
340 340

	
341 341
  /// \ingroup graph_adaptors
342 342
  ///
343 343
  /// \brief A digraph adaptor which reverses the orientation of the arcs.
344 344
  ///
345 345
  /// ReverseDigraph reverses the arcs in the adapted digraph. The
346 346
  /// SubDigraph is conform to the \ref concepts::Digraph
347 347
  /// "Digraph concept".
348 348
  ///
349 349
  /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
350 350
  /// "Digraph concept". The type can be specified to be const.
351 351
  template<typename _Digraph>
352 352
  class ReverseDigraph :
353 353
    public DigraphAdaptorExtender<ReverseDigraphBase<_Digraph> > {
354 354
  public:
355 355
    typedef _Digraph Digraph;
356 356
    typedef DigraphAdaptorExtender<
357 357
      ReverseDigraphBase<_Digraph> > Parent;
358 358
  protected:
359 359
    ReverseDigraph() { }
360 360
  public:
361 361

	
362 362
    /// \brief Constructor
363 363
    ///
364 364
    /// Creates a reverse digraph adaptor for the given digraph
365 365
    explicit ReverseDigraph(Digraph& digraph) {
366 366
      Parent::setDigraph(digraph);
367 367
    }
368 368
  };
369 369

	
370 370
  /// \brief Just gives back a reverse digraph adaptor
371 371
  ///
372 372
  /// Just gives back a reverse digraph adaptor
373 373
  template<typename Digraph>
374 374
  ReverseDigraph<const Digraph> reverseDigraph(const Digraph& digraph) {
375 375
    return ReverseDigraph<const Digraph>(digraph);
376 376
  }
377 377

	
378 378
  template <typename _Digraph, typename _NodeFilterMap,
379 379
            typename _ArcFilterMap, bool _checked = true>
380 380
  class SubDigraphBase : public DigraphAdaptorBase<_Digraph> {
381 381
  public:
382 382
    typedef _Digraph Digraph;
383 383
    typedef _NodeFilterMap NodeFilterMap;
384 384
    typedef _ArcFilterMap ArcFilterMap;
385 385

	
386 386
    typedef SubDigraphBase Adaptor;
387 387
    typedef DigraphAdaptorBase<_Digraph> Parent;
388 388
  protected:
389 389
    NodeFilterMap* _node_filter;
390 390
    ArcFilterMap* _arc_filter;
391 391
    SubDigraphBase()
392 392
      : Parent(), _node_filter(0), _arc_filter(0) { }
393 393

	
394 394
    void setNodeFilterMap(NodeFilterMap& node_filter) {
395 395
      _node_filter = &node_filter;
396 396
    }
397 397
    void setArcFilterMap(ArcFilterMap& arc_filter) {
398 398
      _arc_filter = &arc_filter;
399 399
    }
400 400

	
401 401
  public:
402 402

	
403 403
    typedef typename Parent::Node Node;
404 404
    typedef typename Parent::Arc Arc;
405 405

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

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

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

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

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

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

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

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

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

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

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

	
469 469
    typedef False NodeNumTag;
470 470
    typedef False EdgeNumTag;
471 471

	
472 472
    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
473 473
    Arc findArc(const Node& source, const Node& target,
474 474
                const Arc& prev = INVALID) {
475 475
      if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
476 476
        return INVALID;
477 477
      }
478 478
      Arc arc = Parent::findArc(source, target, prev);
479 479
      while (arc != INVALID && !(*_arc_filter)[arc]) {
480 480
        arc = Parent::findArc(source, target, arc);
481 481
      }
482 482
      return arc;
483 483
    }
484 484

	
485 485
    template <typename _Value>
486 486
    class NodeMap : public SubMapExtender<Adaptor,
487 487
      typename Parent::template NodeMap<_Value> > {
488 488
    public:
489 489
      typedef _Value Value;
490 490
      typedef SubMapExtender<Adaptor, typename Parent::
491 491
                             template NodeMap<Value> > MapParent;
492 492

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

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

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

	
510 510
    template <typename _Value>
511 511
    class ArcMap : public SubMapExtender<Adaptor,
512 512
      typename Parent::template ArcMap<_Value> > {
513 513
    public:
514 514
      typedef _Value Value;
515 515
      typedef SubMapExtender<Adaptor, typename Parent::
516 516
                             template ArcMap<Value> > MapParent;
517 517

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

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

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

	
535 535
  };
536 536

	
537 537
  template <typename _Digraph, typename _NodeFilterMap, typename _ArcFilterMap>
538 538
  class SubDigraphBase<_Digraph, _NodeFilterMap, _ArcFilterMap, false>
539 539
    : public DigraphAdaptorBase<_Digraph> {
540 540
  public:
541 541
    typedef _Digraph Digraph;
542 542
    typedef _NodeFilterMap NodeFilterMap;
543 543
    typedef _ArcFilterMap ArcFilterMap;
544 544

	
545 545
    typedef SubDigraphBase Adaptor;
546 546
    typedef DigraphAdaptorBase<Digraph> Parent;
547 547
  protected:
548 548
    NodeFilterMap* _node_filter;
549 549
    ArcFilterMap* _arc_filter;
550 550
    SubDigraphBase()
551 551
      : Parent(), _node_filter(0), _arc_filter(0) { }
552 552

	
553 553
    void setNodeFilterMap(NodeFilterMap& node_filter) {
554 554
      _node_filter = &node_filter;
555 555
    }
556 556
    void setArcFilterMap(ArcFilterMap& arc_filter) {
557 557
      _arc_filter = &arc_filter;
558 558
    }
559 559

	
560 560
  public:
561 561

	
562 562
    typedef typename Parent::Node Node;
563 563
    typedef typename Parent::Arc Arc;
564 564

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

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

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

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

	
585 585
    void next(Node& i) const {
586 586
      Parent::next(i);
587 587
      while (i!=INVALID && !(*_node_filter)[i]) Parent::next(i);
588 588
    }
589 589
    void next(Arc& i) const {
590 590
      Parent::next(i);
591 591
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::next(i);
592 592
    }
593 593
    void nextIn(Arc& i) const {
594 594
      Parent::nextIn(i);
595 595
      while (i!=INVALID && !(*_arc_filter)[i]) Parent::nextIn(i);
596 596
    }
597 597

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

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

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

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

	
612 612
    typedef False NodeNumTag;
613 613
    typedef False EdgeNumTag;
614 614

	
615 615
    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
616 616
    Arc findArc(const Node& source, const Node& target,
617 617
                const Arc& prev = INVALID) {
618 618
      if (!(*_node_filter)[source] || !(*_node_filter)[target]) {
619 619
        return INVALID;
620 620
      }
621 621
      Arc arc = Parent::findArc(source, target, prev);
622 622
      while (arc != INVALID && !(*_arc_filter)[arc]) {
623 623
        arc = Parent::findArc(source, target, arc);
624 624
      }
625 625
      return arc;
626 626
    }
627 627

	
628 628
    template <typename _Value>
629 629
    class NodeMap : public SubMapExtender<Adaptor,
630 630
      typename Parent::template NodeMap<_Value> > {
631 631
    public:
632 632
      typedef _Value Value;
633 633
      typedef SubMapExtender<Adaptor, typename Parent::
634 634
                             template NodeMap<Value> > MapParent;
635 635

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

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

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

	
653 653
    template <typename _Value>
654 654
    class ArcMap : public SubMapExtender<Adaptor,
655 655
      typename Parent::template ArcMap<_Value> > {
656 656
    public:
657 657
      typedef _Value Value;
658 658
      typedef SubMapExtender<Adaptor, typename Parent::
659 659
                             template ArcMap<Value> > MapParent;
660 660

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

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

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

	
678 678
  };
679 679

	
680 680
  /// \ingroup graph_adaptors
681 681
  ///
682 682
  /// \brief An adaptor for hiding nodes and arcs in a digraph
683 683
  ///
684 684
  /// SubDigraph hides nodes and arcs in a digraph. A bool node map
685 685
  /// and a bool arc map must be specified, which define the filters
686 686
  /// for nodes and arcs. Just the nodes and arcs with true value are
687 687
  /// shown in the subdigraph. The SubDigraph is conform to the \ref
688 688
  /// concepts::Digraph "Digraph concept". If the \c _checked parameter
689 689
  /// is true, then the arcs incident to filtered nodes are also
690 690
  /// filtered out.
691 691
  ///
692 692
  /// \tparam _Digraph It must be conform to the \ref
693 693
  /// concepts::Digraph "Digraph concept". The type can be specified
694 694
  /// to const.
695 695
  /// \tparam _NodeFilterMap A bool valued node map of the the adapted digraph.
696 696
  /// \tparam _ArcFilterMap A bool valued arc map of the the adapted digraph.
697 697
  /// \tparam _checked If the parameter is false then the arc filtering
698 698
  /// is not checked with respect to node filter. Otherwise, each arc
699 699
  /// is automatically filtered, which is incident to a filtered node.
700 700
  ///
701 701
  /// \see FilterNodes
702 702
  /// \see FilterArcs
703 703
  template<typename _Digraph,
704 704
           typename _NodeFilterMap = typename _Digraph::template NodeMap<bool>,
705 705
           typename _ArcFilterMap = typename _Digraph::template ArcMap<bool>,
706 706
           bool _checked = true>
707 707
  class SubDigraph
708 708
    : public DigraphAdaptorExtender<
709 709
      SubDigraphBase<_Digraph, _NodeFilterMap, _ArcFilterMap, _checked> > {
710 710
  public:
711 711
    typedef _Digraph Digraph;
712 712
    typedef _NodeFilterMap NodeFilterMap;
713 713
    typedef _ArcFilterMap ArcFilterMap;
714 714

	
715 715
    typedef DigraphAdaptorExtender<
716 716
      SubDigraphBase<Digraph, NodeFilterMap, ArcFilterMap, _checked> >
717 717
    Parent;
718 718

	
719 719
    typedef typename Parent::Node Node;
720 720
    typedef typename Parent::Arc Arc;
721 721

	
722 722
  protected:
723 723
    SubDigraph() { }
724 724
  public:
725 725

	
726 726
    /// \brief Constructor
727 727
    ///
728 728
    /// Creates a subdigraph for the given digraph with
729 729
    /// given node and arc map filters.
730 730
    SubDigraph(Digraph& digraph, NodeFilterMap& node_filter,
731 731
               ArcFilterMap& arc_filter) {
732 732
      setDigraph(digraph);
733 733
      setNodeFilterMap(node_filter);
734 734
      setArcFilterMap(arc_filter);
735 735
    }
736 736

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

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

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

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

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

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

	
777 777
  };
778 778

	
779 779
  /// \brief Just gives back a subdigraph
780 780
  ///
781 781
  /// Just gives back a subdigraph
782 782
  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
783 783
  SubDigraph<const Digraph, NodeFilterMap, ArcFilterMap>
784 784
  subDigraph(const Digraph& digraph, NodeFilterMap& nfm, ArcFilterMap& afm) {
785 785
    return SubDigraph<const Digraph, NodeFilterMap, ArcFilterMap>
786 786
      (digraph, nfm, afm);
787 787
  }
788 788

	
789 789
  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
790 790
  SubDigraph<const Digraph, const NodeFilterMap, ArcFilterMap>
791 791
  subDigraph(const Digraph& digraph,
792 792
             const NodeFilterMap& nfm, ArcFilterMap& afm) {
793 793
    return SubDigraph<const Digraph, const NodeFilterMap, ArcFilterMap>
794 794
      (digraph, nfm, afm);
795 795
  }
796 796

	
797 797
  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
798 798
  SubDigraph<const Digraph, NodeFilterMap, const ArcFilterMap>
799 799
  subDigraph(const Digraph& digraph,
800 800
             NodeFilterMap& nfm, const ArcFilterMap& afm) {
801 801
    return SubDigraph<const Digraph, NodeFilterMap, const ArcFilterMap>
802 802
      (digraph, nfm, afm);
803 803
  }
804 804

	
805 805
  template<typename Digraph, typename NodeFilterMap, typename ArcFilterMap>
806 806
  SubDigraph<const Digraph, const NodeFilterMap, const ArcFilterMap>
807 807
  subDigraph(const Digraph& digraph,
808 808
             const NodeFilterMap& nfm, const ArcFilterMap& afm) {
809 809
    return SubDigraph<const Digraph, const NodeFilterMap,
810 810
      const ArcFilterMap>(digraph, nfm, afm);
811 811
  }
812 812

	
813 813

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

	
823 823
    NodeFilterMap* _node_filter_map;
824 824
    EdgeFilterMap* _edge_filter_map;
825 825

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

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

	
836 836
  public:
837 837

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	
937 937
    typedef False NodeNumTag;
938 938
    typedef False EdgeNumTag;
939 939

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	
1040 1040
  };
1041 1041

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

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

	
1062 1062
  public:
1063 1063

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

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

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

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

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

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

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

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

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

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

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

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

	
1133 1133
    typedef False NodeNumTag;
1134 1134
    typedef False EdgeNumTag;
1135 1135

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	
1230 1230
  };
1231 1231

	
1232 1232
  /// \ingroup graph_adaptors
1233 1233
  ///
1234 1234
  /// \brief A graph adaptor for hiding nodes and edges in an
1235 1235
  /// undirected graph.
1236 1236
  ///
1237 1237
  /// SubGraph hides nodes and edges in a graph. A bool node map and a
1238 1238
  /// bool edge map must be specified, which define the filters for
1239 1239
  /// nodes and edges. Just the nodes and edges with true value are
1240 1240
  /// shown in the subgraph. The SubGraph is conform to the \ref
1241 1241
  /// concepts::Graph "Graph concept". If the \c _checked parameter is
1242 1242
  /// true, then the edges incident to filtered nodes are also
1243 1243
  /// filtered out.
1244 1244
  ///
1245 1245
  /// \tparam _Graph It must be conform to the \ref
1246 1246
  /// concepts::Graph "Graph concept". The type can be specified
1247 1247
  /// to const.
1248 1248
  /// \tparam _NodeFilterMap A bool valued node map of the the adapted graph.
1249 1249
  /// \tparam _EdgeFilterMap A bool valued edge map of the the adapted graph.
1250 1250
  /// \tparam _checked If the parameter is false then the edge filtering
1251 1251
  /// is not checked with respect to node filter. Otherwise, each edge
1252 1252
  /// is automatically filtered, which is incident to a filtered node.
1253 1253
  ///
1254 1254
  /// \see FilterNodes
1255 1255
  /// \see FilterEdges
1256 1256
  template<typename _Graph, typename NodeFilterMap,
1257 1257
           typename EdgeFilterMap, bool _checked = true>
1258 1258
  class SubGraph
1259 1259
    : public GraphAdaptorExtender<
1260 1260
      SubGraphBase<_Graph, NodeFilterMap, EdgeFilterMap, _checked> > {
1261 1261
  public:
1262 1262
    typedef _Graph Graph;
1263 1263
    typedef GraphAdaptorExtender<
1264 1264
      SubGraphBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent;
1265 1265

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

	
1269 1269
  protected:
1270 1270
    SubGraph() { }
1271 1271
  public:
1272 1272

	
1273 1273
    /// \brief Constructor
1274 1274
    ///
1275 1275
    /// Creates a subgraph for the given graph with given node and
1276 1276
    /// edge map filters.
1277 1277
    SubGraph(Graph& _graph, NodeFilterMap& node_filter_map,
1278 1278
             EdgeFilterMap& edge_filter_map) {
1279 1279
      setGraph(_graph);
1280 1280
      setNodeFilterMap(node_filter_map);
1281 1281
      setEdgeFilterMap(edge_filter_map);
1282 1282
    }
1283 1283

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

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

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

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

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

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

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

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

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

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

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

	
1395 1395
    typedef _Digraph Digraph;
1396 1396
    typedef _NodeFilterMap NodeFilterMap;
1397 1397

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

	
1402 1402
    typedef typename Parent::Node Node;
1403 1403

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

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

	
1411 1411
  public:
1412 1412

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

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

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

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

	
1444 1444
  };
1445 1445

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

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

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

	
1465 1465
  public:
1466 1466

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

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

	
1478 1478
  };
1479 1479

	
1480 1480

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

	
1490 1490
  template<typename Digraph, typename NodeFilterMap>
1491 1491
  FilterNodes<const Digraph, const NodeFilterMap>
1492 1492
  filterNodes(const Digraph& digraph, const NodeFilterMap& nfm) {
1493 1493
    return FilterNodes<const Digraph, const NodeFilterMap>(digraph, nfm);
1494 1494
  }
1495 1495

	
1496 1496
  /// \ingroup graph_adaptors
1497 1497
  ///
1498 1498
  /// \brief An adaptor for hiding arcs from a digraph.
1499 1499
  ///
1500 1500
  /// FilterArcs adaptor hides arcs in a digraph. A bool arc map must
1501 1501
  /// be specified, which defines the filters for arcs. Just the
1502 1502
  /// unfiltered arcs are shown in the subdigraph. The FilterArcs is
1503 1503
  /// conform to the \ref concepts::Digraph "Digraph concept".
1504 1504
  ///
1505 1505
  /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
1506 1506
  /// "Digraph concept". The type can be specified to be const.
1507 1507
  /// \tparam _ArcFilterMap A bool valued arc map of the the adapted
1508 1508
  /// graph.
1509 1509
  template<typename _Digraph, typename _ArcFilterMap>
1510 1510
  class FilterArcs :
1511 1511
    public SubDigraph<_Digraph, ConstMap<typename _Digraph::Node, bool>,
1512 1512
                      _ArcFilterMap, false> {
1513 1513
  public:
1514 1514
    typedef _Digraph Digraph;
1515 1515
    typedef _ArcFilterMap ArcFilterMap;
1516 1516

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

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

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

	
1525 1525
    FilterArcs() : const_true_map(true) {
1526 1526
      Parent::setNodeFilterMap(const_true_map);
1527 1527
    }
1528 1528

	
1529 1529
  public:
1530 1530

	
1531 1531
    /// \brief Constructor
1532 1532
    ///
1533 1533
    /// Creates a FilterArcs adaptor for the given graph with
1534 1534
    /// given arc map filter.
1535 1535
    FilterArcs(Digraph& digraph, ArcFilterMap& arc_filter)
1536 1536
      : Parent(), const_true_map(true) {
1537 1537
      Parent::setDigraph(digraph);
1538 1538
      Parent::setNodeFilterMap(const_true_map);
1539 1539
      Parent::setArcFilterMap(arc_filter);
1540 1540
    }
1541 1541

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

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

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

	
1562 1562
  };
1563 1563

	
1564 1564
  /// \brief Just gives back an FilterArcs adaptor
1565 1565
  ///
1566 1566
  /// Just gives back an FilterArcs adaptor
1567 1567
  template<typename Digraph, typename ArcFilterMap>
1568 1568
  FilterArcs<const Digraph, ArcFilterMap>
1569 1569
  filterArcs(const Digraph& digraph, ArcFilterMap& afm) {
1570 1570
    return FilterArcs<const Digraph, ArcFilterMap>(digraph, afm);
1571 1571
  }
1572 1572

	
1573 1573
  template<typename Digraph, typename ArcFilterMap>
1574 1574
  FilterArcs<const Digraph, const ArcFilterMap>
1575 1575
  filterArcs(const Digraph& digraph, const ArcFilterMap& afm) {
1576 1576
    return FilterArcs<const Digraph, const ArcFilterMap>(digraph, afm);
1577 1577
  }
1578 1578

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

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

	
1609 1609
  public:
1610 1610

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

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

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

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

	
1642 1642
  };
1643 1643

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

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

	
1659 1659
  template <typename _Digraph>
1660 1660
  class UndirectorBase {
1661 1661
  public:
1662 1662
    typedef _Digraph Digraph;
1663 1663
    typedef UndirectorBase Adaptor;
1664 1664

	
1665 1665
    typedef True UndirectedTag;
1666 1666

	
1667 1667
    typedef typename Digraph::Arc Edge;
1668 1668
    typedef typename Digraph::Node Node;
1669 1669

	
1670 1670
    class Arc : public Edge {
1671 1671
      friend class UndirectorBase;
1672 1672
    protected:
1673 1673
      bool _forward;
1674 1674

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

	
1678 1678
    public:
1679 1679
      Arc() {}
1680 1680

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

	
1683 1683
      bool operator==(const Arc &other) const {
1684 1684
        return _forward == other._forward &&
1685 1685
          static_cast<const Edge&>(*this) == static_cast<const Edge&>(other);
1686 1686
      }
1687 1687
      bool operator!=(const Arc &other) const {
1688 1688
        return _forward != other._forward ||
1689 1689
          static_cast<const Edge&>(*this) != static_cast<const Edge&>(other);
1690 1690
      }
1691 1691
      bool operator<(const Arc &other) const {
1692 1692
        return _forward < other._forward ||
1693 1693
          (_forward == other._forward &&
1694 1694
           static_cast<const Edge&>(*this) < static_cast<const Edge&>(other));
1695 1695
      }
1696 1696
    };
1697 1697

	
1698 1698

	
1699 1699

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

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

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

	
1713 1713
    void next(Arc& a) const {
1714 1714
      if (a._forward) {
1715 1715
        a._forward = false;
1716 1716
      } else {
1717 1717
        _digraph->next(a);
1718 1718
        a._forward = true;
1719 1719
      }
1720 1720
    }
1721 1721

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

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

	
1730 1730
    void firstOut(Arc& a, const Node& n) const {
1731 1731
      _digraph->firstIn(a, n);
1732 1732
      if( static_cast<const Edge&>(a) != INVALID ) {
1733 1733
        a._forward = false;
1734 1734
      } else {
1735 1735
        _digraph->firstOut(a, n);
1736 1736
        a._forward = true;
1737 1737
      }
1738 1738
    }
1739 1739
    void nextOut(Arc &a) const {
1740 1740
      if (!a._forward) {
1741 1741
        Node n = _digraph->target(a);
1742 1742
        _digraph->nextIn(a);
1743 1743
        if (static_cast<const Edge&>(a) == INVALID ) {
1744 1744
          _digraph->firstOut(a, n);
1745 1745
          a._forward = true;
1746 1746
        }
1747 1747
      }
1748 1748
      else {
1749 1749
        _digraph->nextOut(a);
1750 1750
      }
1751 1751
    }
1752 1752

	
1753 1753
    void firstIn(Arc &a, const Node &n) const {
1754 1754
      _digraph->firstOut(a, n);
1755 1755
      if (static_cast<const Edge&>(a) != INVALID ) {
1756 1756
        a._forward = false;
1757 1757
      } else {
1758 1758
        _digraph->firstIn(a, n);
1759 1759
        a._forward = true;
1760 1760
      }
1761 1761
    }
1762 1762
    void nextIn(Arc &a) const {
1763 1763
      if (!a._forward) {
1764 1764
        Node n = _digraph->source(a);
1765 1765
        _digraph->nextOut(a);
1766 1766
        if( static_cast<const Edge&>(a) == INVALID ) {
1767 1767
          _digraph->firstIn(a, n);
1768 1768
          a._forward = true;
1769 1769
        }
1770 1770
      }
1771 1771
      else {
1772 1772
        _digraph->nextIn(a);
1773 1773
      }
1774 1774
    }
1775 1775

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

	
1784 1784
    void nextInc(Edge &e, bool &d) const {
1785 1785
      if (d) {
1786 1786
        Node s = _digraph->source(e);
1787 1787
        _digraph->nextOut(e);
1788 1788
        if (e != INVALID) return;
1789 1789
        d = false;
1790 1790
        _digraph->firstIn(e, s);
1791 1791
      } else {
1792 1792
        _digraph->nextIn(e);
1793 1793
      }
1794 1794
    }
1795 1795

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

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

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

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

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

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

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

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

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

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

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

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

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

	
1853 1853
    typedef FindEdgeTagIndicator<Digraph> FindEdgeTag;
1854 1854
    Arc findArc(Node s, Node t, Arc p = INVALID) const {
1855 1855
      if (p == INVALID) {
1856 1856
        Edge arc = _digraph->findArc(s, t);
1857 1857
        if (arc != INVALID) return direct(arc, true);
1858 1858
        arc = _digraph->findArc(t, s);
1859 1859
        if (arc != INVALID) return direct(arc, false);
1860 1860
      } else if (direction(p)) {
1861 1861
        Edge arc = _digraph->findArc(s, t, p);
1862 1862
        if (arc != INVALID) return direct(arc, true);
1863 1863
        arc = _digraph->findArc(t, s);
1864 1864
        if (arc != INVALID) return direct(arc, false);
1865 1865
      } else {
1866 1866
        Edge arc = _digraph->findArc(t, s, p);
1867 1867
        if (arc != INVALID) return direct(arc, false);
1868 1868
      }
1869 1869
      return INVALID;
1870 1870
    }
1871 1871

	
1872 1872
    Edge findEdge(Node s, Node t, Edge p = INVALID) const {
1873 1873
      if (s != t) {
1874 1874
        if (p == INVALID) {
1875 1875
          Edge arc = _digraph->findArc(s, t);
1876 1876
          if (arc != INVALID) return arc;
1877 1877
          arc = _digraph->findArc(t, s);
1878 1878
          if (arc != INVALID) return arc;
1879 1879
        } else if (_digraph->s(p) == s) {
1880 1880
          Edge arc = _digraph->findArc(s, t, p);
1881 1881
          if (arc != INVALID) return arc;
1882 1882
          arc = _digraph->findArc(t, s);
1883 1883
          if (arc != INVALID) return arc;
1884 1884
        } else {
1885 1885
          Edge arc = _digraph->findArc(t, s, p);
1886 1886
          if (arc != INVALID) return arc;
1887 1887
        }
1888 1888
      } else {
1889 1889
        return _digraph->findArc(s, t, p);
1890 1890
      }
1891 1891
      return INVALID;
1892 1892
    }
1893 1893

	
1894 1894
  private:
1895 1895

	
1896 1896
    template <typename _Value>
1897 1897
    class ArcMapBase {
1898 1898
    private:
1899 1899

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

	
1902 1902
    public:
1903 1903

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

	
1906 1906
      typedef _Value Value;
1907 1907
      typedef Arc Key;
1908 1908

	
1909 1909
      ArcMapBase(const Adaptor& adaptor) :
1910 1910
        _forward(*adaptor._digraph), _backward(*adaptor._digraph) {}
1911 1911

	
1912 1912
      ArcMapBase(const Adaptor& adaptor, const Value& v)
1913 1913
        : _forward(*adaptor._digraph, v), _backward(*adaptor._digraph, v) {}
1914 1914

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

	
1923 1923
      typename MapTraits<MapImpl>::ConstReturnValue
1924 1924
      operator[](const Arc& a) const {
1925 1925
        if (direction(a)) {
1926 1926
          return _forward[a];
1927 1927
        } else {
1928 1928
          return _backward[a];
1929 1929
        }
1930 1930
      }
1931 1931

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

	
1941 1941
    protected:
1942 1942

	
1943 1943
      MapImpl _forward, _backward;
1944 1944

	
1945 1945
    };
1946 1946

	
1947 1947
  public:
1948 1948

	
1949 1949
    template <typename _Value>
1950 1950
    class NodeMap : public Digraph::template NodeMap<_Value> {
1951 1951
    public:
1952 1952

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

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

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

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

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

	
1973 1973
    };
1974 1974

	
1975 1975
    template <typename _Value>
1976 1976
    class ArcMap
1977 1977
      : public SubMapExtender<Adaptor, ArcMapBase<_Value> >
1978 1978
    {
1979 1979
    public:
1980 1980
      typedef _Value Value;
1981 1981
      typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
1982 1982

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

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

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

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

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

	
2005 2005
      typedef _Value Value;
2006 2006
      typedef typename Digraph::template ArcMap<Value> Parent;
2007 2007

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

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

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

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

	
2025 2025
    };
2026 2026

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

	
2030 2030
  protected:
2031 2031

	
2032 2032
    UndirectorBase() : _digraph(0) {}
2033 2033

	
2034 2034
    Digraph* _digraph;
2035 2035

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

	
2040 2040
  };
2041 2041

	
2042 2042
  /// \ingroup graph_adaptors
2043 2043
  ///
2044 2044
  /// \brief Undirect the graph
2045 2045
  ///
2046 2046
  /// This adaptor makes an undirected graph from a directed
2047 2047
  /// graph. All arcs of the underlying digraph will be showed in the
2048 2048
  /// adaptor as an edge. The Orienter adaptor is conform to the \ref
2049 2049
  /// concepts::Graph "Graph concept".
2050 2050
  ///
2051 2051
  /// \tparam _Digraph It must be conform to the \ref
2052 2052
  /// concepts::Digraph "Digraph concept". The type can be specified
2053 2053
  /// to const.
2054 2054
  template<typename _Digraph>
2055 2055
  class Undirector
2056 2056
    : public GraphAdaptorExtender<UndirectorBase<_Digraph> > {
2057 2057
  public:
2058 2058
    typedef _Digraph Digraph;
2059 2059
    typedef GraphAdaptorExtender<UndirectorBase<Digraph> > Parent;
2060 2060
  protected:
2061 2061
    Undirector() { }
2062 2062
  public:
2063 2063

	
2064 2064
    /// \brief Constructor
2065 2065
    ///
2066 2066
    /// Creates a undirected graph from the given digraph
2067 2067
    Undirector(_Digraph& digraph) {
2068 2068
      setDigraph(digraph);
2069 2069
    }
2070 2070

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

	
2079 2079
      typedef _ForwardMap ForwardMap;
2080 2080
      typedef _BackwardMap BackwardMap;
2081 2081

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

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

	
2087 2087
      /// \brief Constructor
2088 2088
      ///
2089 2089
      /// Constructor
2090 2090
      CombinedArcMap(ForwardMap& forward, BackwardMap& backward)
2091 2091
        : _forward(&forward), _backward(&backward) {}
2092 2092

	
2093 2093

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

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

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

	
2129 2129
    protected:
2130 2130

	
2131 2131
      ForwardMap* _forward;
2132 2132
      BackwardMap* _backward;
2133 2133

	
2134 2134
    };
2135 2135

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

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

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

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

	
2166 2166
  };
2167 2167

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

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

	
2181 2181
    typedef _Graph Graph;
2182 2182
    typedef _DirectionMap DirectionMap;
2183 2183

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	
2302 2302
    };
2303 2303

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

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

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

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

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

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

	
2328 2328

	
2329 2329

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

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

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

	
2342 2342
  };
2343 2343

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

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

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

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

	
2398 2398
  template<typename Graph, typename DirectionMap>
2399 2399
  Orienter<const Graph, const DirectionMap>
2400 2400
  orienter(const Graph& graph, const DirectionMap& dm) {
2401 2401
    return Orienter<const Graph, const DirectionMap>(graph, dm);
2402 2402
  }
2403 2403

	
2404 2404
  namespace _adaptor_bits {
2405 2405

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

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

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

	
2421 2421
    private:
2422 2422

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

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

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

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

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

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

	
2452 2452
    private:
2453 2453

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

	
2458 2458
    public:
2459 2459

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

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

	
2469 2469
  }
2470 2470

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

	
2513 2513
    typedef _Digraph Digraph;
2514 2514
    typedef _CapacityMap CapacityMap;
2515 2515
    typedef _FlowMap FlowMap;
2516 2516
    typedef _Tolerance Tolerance;
2517 2517

	
2518 2518
    typedef typename CapacityMap::Value Value;
2519 2519
    typedef Residual Adaptor;
2520 2520

	
2521 2521
  protected:
2522 2522

	
2523 2523
    typedef Undirector<const Digraph> Undirected;
2524 2524

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

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

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

	
2534 2534
    typedef FilterArcs<Undirected, ArcFilter> Parent;
2535 2535

	
2536 2536
    const CapacityMap* _capacity;
2537 2537
    FlowMap* _flow;
2538 2538

	
2539 2539
    Undirected _graph;
2540 2540
    ForwardFilter _forward_filter;
2541 2541
    BackwardFilter _backward_filter;
2542 2542
    ArcFilter _arc_filter;
2543 2543

	
2544 2544
  public:
2545 2545

	
2546 2546
    /// \brief Constructor of the residual digraph.
2547 2547
    ///
2548 2548
    /// Constructor of the residual graph. The parameters are the digraph,
2549 2549
    /// the flow map, the capacity map and a tolerance object.
2550 2550
    Residual(const Digraph& digraph, const CapacityMap& capacity,
2551 2551
             FlowMap& flow, const Tolerance& tolerance = Tolerance())
2552 2552
      : Parent(), _capacity(&capacity), _flow(&flow), _graph(digraph),
2553 2553
        _forward_filter(capacity, flow, tolerance),
2554 2554
        _backward_filter(capacity, flow, tolerance),
2555 2555
        _arc_filter(_forward_filter, _backward_filter)
2556 2556
    {
2557 2557
      Parent::setDigraph(_graph);
2558 2558
      Parent::setArcFilterMap(_arc_filter);
2559 2559
    }
2560 2560

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

	
2563 2563
    /// \brief Gives back the residual capacity of the arc.
2564 2564
    ///
2565 2565
    /// Gives back the residual capacity of the arc.
2566 2566
    Value residualCapacity(const Arc& a) const {
2567 2567
      if (Undirected::direction(a)) {
2568 2568
        return (*_capacity)[a] - (*_flow)[a];
2569 2569
      } else {
2570 2570
        return (*_flow)[a];
2571 2571
      }
2572 2572
    }
2573 2573

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

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

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

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

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

	
2615 2615
    /// \brief Residual capacity map.
2616 2616
    ///
2617 2617
    /// In generic residual graph the residual capacity can be obtained
2618 2618
    /// as a map.
2619 2619
    class ResidualCapacity {
2620 2620
    protected:
2621 2621
      const Adaptor* _adaptor;
2622 2622
    public:
2623 2623
      /// The Key type
2624 2624
      typedef Arc Key;
2625 2625
      /// The Value type
2626 2626
      typedef typename _CapacityMap::Value Value;
2627 2627

	
2628 2628
      /// Constructor
2629 2629
      ResidualCapacity(const Adaptor& adaptor) : _adaptor(&adaptor) {}
2630 2630

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

	
2636 2636
    };
2637 2637

	
2638 2638
  };
2639 2639

	
2640 2640
  template <typename _Digraph>
2641 2641
  class SplitNodesBase {
2642 2642
  public:
2643 2643

	
2644 2644
    typedef _Digraph Digraph;
2645 2645
    typedef DigraphAdaptorBase<const _Digraph> Parent;
2646 2646
    typedef SplitNodesBase Adaptor;
2647 2647

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

	
2651 2651
    class Node;
2652 2652
    class Arc;
2653 2653

	
2654 2654
  private:
2655 2655

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

	
2659 2659
  public:
2660 2660

	
2661 2661
    class Node : public DigraphNode {
2662 2662
      friend class SplitNodesBase;
2663 2663
      template <typename T> friend class NodeMapBase;
2664 2664
    private:
2665 2665

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

	
2670 2670
    public:
2671 2671

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

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

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

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

	
2689 2689
    class Arc {
2690 2690
      friend class SplitNodesBase;
2691 2691
      template <typename T> friend class ArcMapBase;
2692 2692
    private:
2693 2693
      typedef BiVariant<DigraphArc, DigraphNode> ArcImpl;
2694 2694

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

	
2698 2698
      ArcImpl _item;
2699 2699

	
2700 2700
    public:
2701 2701
      Arc() {}
2702 2702
      Arc(Invalid) : _item(DigraphArc(INVALID)) {}
2703 2703

	
2704 2704
      bool operator==(const Arc& arc) const {
2705 2705
        if (_item.firstState()) {
2706 2706
          if (arc._item.firstState()) {
2707 2707
            return _item.first() == arc._item.first();
2708 2708
          }
2709 2709
        } else {
2710 2710
          if (arc._item.secondState()) {
2711 2711
            return _item.second() == arc._item.second();
2712 2712
          }
2713 2713
        }
2714 2714
        return false;
2715 2715
      }
2716 2716

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

	
2721 2721
      bool operator<(const Arc& arc) const {
2722 2722
        if (_item.firstState()) {
2723 2723
          if (arc._item.firstState()) {
2724 2724
            return _item.first() < arc._item.first();
2725 2725
          }
2726 2726
          return false;
2727 2727
        } else {
2728 2728
          if (arc._item.secondState()) {
2729 2729
            return _item.second() < arc._item.second();
2730 2730
          }
2731 2731
          return true;
2732 2732
        }
2733 2733
      }
2734 2734

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

	
2738 2738
    };
2739 2739

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

	
2745 2745
    void next(Node& n) const {
2746 2746
      if (n._in) {
2747 2747
        n._in = false;
2748 2748
      } else {
2749 2749
        n._in = true;
2750 2750
        _digraph->next(n);
2751 2751
      }
2752 2752
    }
2753 2753

	
2754 2754
    void first(Arc& e) const {
2755 2755
      e._item.setSecond();
2756 2756
      _digraph->first(e._item.second());
2757 2757
      if (e._item.second() == INVALID) {
2758 2758
        e._item.setFirst();
2759 2759
        _digraph->first(e._item.first());
2760 2760
      }
2761 2761
    }
2762 2762

	
2763 2763
    void next(Arc& e) const {
2764 2764
      if (e._item.secondState()) {
2765 2765
        _digraph->next(e._item.second());
2766 2766
        if (e._item.second() == INVALID) {
2767 2767
          e._item.setFirst();
2768 2768
          _digraph->first(e._item.first());
2769 2769
        }
2770 2770
      } else {
2771 2771
        _digraph->next(e._item.first());
2772 2772
      }
2773 2773
    }
2774 2774

	
2775 2775
    void firstOut(Arc& e, const Node& n) const {
2776 2776
      if (n._in) {
2777 2777
        e._item.setSecond(n);
2778 2778
      } else {
2779 2779
        e._item.setFirst();
2780 2780
        _digraph->firstOut(e._item.first(), n);
2781 2781
      }
2782 2782
    }
2783 2783

	
2784 2784
    void nextOut(Arc& e) const {
2785 2785
      if (!e._item.firstState()) {
2786 2786
        e._item.setFirst(INVALID);
2787 2787
      } else {
2788 2788
        _digraph->nextOut(e._item.first());
2789 2789
      }
2790 2790
    }
2791 2791

	
2792 2792
    void firstIn(Arc& e, const Node& n) const {
2793 2793
      if (!n._in) {
2794 2794
        e._item.setSecond(n);
2795 2795
      } else {
2796 2796
        e._item.setFirst();
2797 2797
        _digraph->firstIn(e._item.first(), n);
2798 2798
      }
2799 2799
    }
2800 2800

	
2801 2801
    void nextIn(Arc& e) const {
2802 2802
      if (!e._item.firstState()) {
2803 2803
        e._item.setFirst(INVALID);
2804 2804
      } else {
2805 2805
        _digraph->nextIn(e._item.first());
2806 2806
      }
2807 2807
    }
2808 2808

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

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

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

	
2835 2835
    int id(const Arc& e) const {
2836 2836
      if (e._item.firstState()) {
2837 2837
        return _digraph->id(e._item.first()) << 1;
2838 2838
      } else {
2839 2839
        return (_digraph->id(e._item.second()) << 1) | 1;
2840 2840
      }
2841 2841
    }
2842 2842
    Arc arcFromId(int ix) const {
2843 2843
      if ((ix & 1) == 0) {
2844 2844
        return Arc(_digraph->arcFromId(ix >> 1));
2845 2845
      } else {
2846 2846
        return Arc(_digraph->nodeFromId(ix >> 1));
2847 2847
      }
2848 2848
    }
2849 2849
    int maxArcId() const {
2850 2850
      return std::max(_digraph->maxNodeId() << 1,
2851 2851
                      (_digraph->maxArcId() << 1) | 1);
2852 2852
    }
2853 2853

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

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

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

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

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

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

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

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

	
2886 2886
    typedef True NodeNumTag;
2887 2887

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

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

	
2897 2897
    typedef True FindEdgeTag;
2898 2898
    Arc findArc(const Node& u, const Node& v,
2899 2899
                const Arc& prev = INVALID) const {
2900 2900
      if (inNode(u)) {
2901 2901
        if (outNode(v)) {
2902 2902
          if (static_cast<const DigraphNode&>(u) ==
2903 2903
              static_cast<const DigraphNode&>(v) && prev == INVALID) {
2904 2904
            return Arc(u);
2905 2905
          }
2906 2906
        }
2907 2907
      } else {
2908 2908
        if (inNode(v)) {
2909 2909
          return Arc(::lemon::findArc(*_digraph, u, v, prev));
2910 2910
        }
2911 2911
      }
2912 2912
      return INVALID;
2913 2913
    }
2914 2914

	
2915 2915
  private:
2916 2916

	
2917 2917
    template <typename _Value>
2918 2918
    class NodeMapBase
2919 2919
      : public MapTraits<typename Parent::template NodeMap<_Value> > {
2920 2920
      typedef typename Parent::template NodeMap<_Value> NodeImpl;
2921 2921
    public:
2922 2922
      typedef Node Key;
2923 2923
      typedef _Value Value;
2924 2924

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

	
2931 2931
      void set(const Node& key, const Value& val) {
2932 2932
        if (Adaptor::inNode(key)) { _in_map.set(key, val); }
2933 2933
        else {_out_map.set(key, val); }
2934 2934
      }
2935 2935

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

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

	
2948 2948
    private:
2949 2949
      NodeImpl _in_map, _out_map;
2950 2950
    };
2951 2951

	
2952 2952
    template <typename _Value>
2953 2953
    class ArcMapBase
2954 2954
      : public MapTraits<typename Parent::template ArcMap<_Value> > {
2955 2955
      typedef typename Parent::template ArcMap<_Value> ArcImpl;
2956 2956
      typedef typename Parent::template NodeMap<_Value> NodeImpl;
2957 2957
    public:
2958 2958
      typedef Arc Key;
2959 2959
      typedef _Value Value;
2960 2960

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

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

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

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

	
2993 2993
    private:
2994 2994
      ArcImpl _arc_map;
2995 2995
      NodeImpl _node_map;
2996 2996
    };
2997 2997

	
2998 2998
  public:
2999 2999

	
3000 3000
    template <typename _Value>
3001 3001
    class NodeMap
3002 3002
      : public SubMapExtender<Adaptor, NodeMapBase<_Value> >
3003 3003
    {
3004 3004
    public:
3005 3005
      typedef _Value Value;
3006 3006
      typedef SubMapExtender<Adaptor, NodeMapBase<Value> > Parent;
3007 3007

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

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

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

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

	
3026 3026
    template <typename _Value>
3027 3027
    class ArcMap
3028 3028
      : public SubMapExtender<Adaptor, ArcMapBase<_Value> >
3029 3029
    {
3030 3030
    public:
3031 3031
      typedef _Value Value;
3032 3032
      typedef SubMapExtender<Adaptor, ArcMapBase<Value> > Parent;
3033 3033

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

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

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

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

	
3052 3052
  protected:
3053 3053

	
3054 3054
    SplitNodesBase() : _digraph(0) {}
3055 3055

	
3056 3056
    Digraph* _digraph;
3057 3057

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

	
3062 3062
  };
3063 3063

	
3064 3064
  /// \ingroup graph_adaptors
3065 3065
  ///
3066 3066
  /// \brief Split the nodes of a directed graph
3067 3067
  ///
3068 3068
  /// The SplitNodes adaptor splits each node into an in-node and an
3069 3069
  /// out-node. Formaly, the adaptor replaces each \f$ u \f$ node in
3070 3070
  /// the digraph with two nodes(namely node \f$ u_{in} \f$ and node
3071 3071
  /// \f$ u_{out} \f$). If there is a \f$ (v, u) \f$ arc in the
3072 3072
  /// original digraph the new target of the arc will be \f$ u_{in} \f$
3073 3073
  /// and similarly the source of the original \f$ (u, v) \f$ arc
3074 3074
  /// will be \f$ u_{out} \f$.  The adaptor will add for each node in
3075 3075
  /// the original digraph an additional arc which connects
3076 3076
  /// \f$ (u_{in}, u_{out}) \f$.
3077 3077
  ///
3078 3078
  /// The aim of this class is to run algorithm with node costs if the
3079 3079
  /// algorithm can use directly just arc costs. In this case we should use
3080 3080
  /// a \c SplitNodes and set the node cost of the graph to the
3081 3081
  /// bind arc in the adapted graph.
3082 3082
  ///
3083 3083
  /// \tparam _Digraph It must be conform to the \ref concepts::Digraph
3084 3084
  /// "Digraph concept". The type can be specified to be const.
3085 3085
  template <typename _Digraph>
3086 3086
  class SplitNodes
3087 3087
    : public DigraphAdaptorExtender<SplitNodesBase<_Digraph> > {
3088 3088
  public:
3089 3089
    typedef _Digraph Digraph;
3090 3090
    typedef DigraphAdaptorExtender<SplitNodesBase<Digraph> > Parent;
3091 3091

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

	
3095 3095
    typedef typename Parent::Node Node;
3096 3096
    typedef typename Parent::Arc Arc;
3097 3097

	
3098 3098
    /// \brief Constructor of the adaptor.
3099 3099
    ///
3100 3100
    /// Constructor of the adaptor.
3101 3101
    SplitNodes(Digraph& g) {
3102 3102
      Parent::setDigraph(g);
3103 3103
    }
3104 3104

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

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

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

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

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

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

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

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

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

	
3169 3169
      typedef Node Key;
3170 3170
      typedef typename InNodeMap::Value Value;
3171 3171

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

	
3178 3178
      /// \brief The subscript operator.
3179 3179
      ///
3180 3180
      /// The subscript operator.
3181 3181
      Value& operator[](const Key& key) {
3182 3182
        if (Parent::inNode(key)) {
3183 3183
          return _in_map[key];
3184 3184
        } else {
3185 3185
          return _out_map[key];
3186 3186
        }
3187 3187
      }
3188 3188

	
3189 3189
      /// \brief The const subscript operator.
3190 3190
      ///
3191 3191
      /// The const subscript operator.
3192 3192
      Value operator[](const Key& key) const {
3193 3193
        if (Parent::inNode(key)) {
3194 3194
          return _in_map[key];
3195 3195
        } else {
3196 3196
          return _out_map[key];
3197 3197
        }
3198 3198
      }
3199 3199

	
3200 3200
      /// \brief The setter function of the map.
3201 3201
      ///
3202 3202
      /// The setter function of the map.
3203 3203
      void set(const Key& key, const Value& value) {
3204 3204
        if (Parent::inNode(key)) {
3205 3205
          _in_map.set(key, value);
3206 3206
        } else {
3207 3207
          _out_map.set(key, value);
3208 3208
        }
3209 3209
      }
3210 3210

	
3211 3211
    private:
3212 3212

	
3213 3213
      InNodeMap& _in_map;
3214 3214
      OutNodeMap& _out_map;
3215 3215

	
3216 3216
    };
3217 3217

	
3218 3218

	
3219 3219
    /// \brief Just gives back a combined node map
3220 3220
    ///
3221 3221
    /// Just gives back a combined node map
3222 3222
    template <typename InNodeMap, typename OutNodeMap>
3223 3223
    static CombinedNodeMap<InNodeMap, OutNodeMap>
3224 3224
    combinedNodeMap(InNodeMap& in_map, OutNodeMap& out_map) {
3225 3225
      return CombinedNodeMap<InNodeMap, OutNodeMap>(in_map, out_map);
3226 3226
    }
3227 3227

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

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

	
3240 3240
    template <typename InNodeMap, typename OutNodeMap>
3241 3241
    static CombinedNodeMap<const InNodeMap, const OutNodeMap>
3242 3242
    combinedNodeMap(const InNodeMap& in_map, const OutNodeMap& out_map) {
3243 3243
      return CombinedNodeMap<const InNodeMap,
3244 3244
        const OutNodeMap>(in_map, out_map);
3245 3245
    }
3246 3246

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

	
3255 3255
      typedef Arc Key;
3256 3256
      typedef typename DigraphArcMap::Value Value;
3257 3257

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

	
3264 3264
      /// \brief The subscript operator.
3265 3265
      ///
3266 3266
      /// The subscript operator.
3267 3267
      void set(const Arc& arc, const Value& val) {
3268 3268
        if (Parent::origArc(arc)) {
3269 3269
          _arc_map.set(arc, val);
3270 3270
        } else {
3271 3271
          _node_map.set(arc, val);
3272 3272
        }
3273 3273
      }
3274 3274

	
3275 3275
      /// \brief The const subscript operator.
3276 3276
      ///
3277 3277
      /// The const subscript operator.
3278 3278
      Value operator[](const Key& arc) const {
3279 3279
        if (Parent::origArc(arc)) {
3280 3280
          return _arc_map[arc];
3281 3281
        } else {
3282 3282
          return _node_map[arc];
3283 3283
        }
3284 3284
      }
3285 3285

	
3286 3286
      /// \brief The const subscript operator.
3287 3287
      ///
3288 3288
      /// The const subscript operator.
3289 3289
      Value& operator[](const Key& arc) {
3290 3290
        if (Parent::origArc(arc)) {
3291 3291
          return _arc_map[arc];
3292 3292
        } else {
3293 3293
          return _node_map[arc];
3294 3294
        }
3295 3295
      }
3296 3296

	
3297 3297
    private:
3298 3298
      DigraphArcMap& _arc_map;
3299 3299
      DigraphNodeMap& _node_map;
3300 3300
    };
3301 3301

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

	
3311 3311
    template <typename DigraphArcMap, typename DigraphNodeMap>
3312 3312
    static CombinedArcMap<const DigraphArcMap, DigraphNodeMap>
3313 3313
    combinedArcMap(const DigraphArcMap& arc_map, DigraphNodeMap& node_map) {
3314 3314
      return CombinedArcMap<const DigraphArcMap,
3315 3315
        DigraphNodeMap>(arc_map, node_map);
3316 3316
    }
3317 3317

	
3318 3318
    template <typename DigraphArcMap, typename DigraphNodeMap>
3319 3319
    static CombinedArcMap<DigraphArcMap, const DigraphNodeMap>
3320 3320
    combinedArcMap(DigraphArcMap& arc_map, const DigraphNodeMap& node_map) {
3321 3321
      return CombinedArcMap<DigraphArcMap,
3322 3322
        const DigraphNodeMap>(arc_map, node_map);
3323 3323
    }
3324 3324

	
3325 3325
    template <typename DigraphArcMap, typename DigraphNodeMap>
3326 3326
    static CombinedArcMap<const DigraphArcMap, const DigraphNodeMap>
3327 3327
    combinedArcMap(const DigraphArcMap& arc_map,
3328 3328
                   const DigraphNodeMap& node_map) {
3329 3329
      return CombinedArcMap<const DigraphArcMap,
3330 3330
        const DigraphNodeMap>(arc_map, node_map);
3331 3331
    }
3332 3332

	
3333 3333
  };
3334 3334

	
3335 3335
  /// \brief Just gives back a node splitter
3336 3336
  ///
3337 3337
  /// Just gives back a node splitter
3338 3338
  template<typename Digraph>
3339 3339
  SplitNodes<Digraph>
3340 3340
  splitNodes(const Digraph& digraph) {
3341 3341
    return SplitNodes<Digraph>(digraph);
3342 3342
  }
3343 3343

	
3344 3344

	
3345 3345
} //namespace lemon
3346 3346

	
3347 3347
#endif //LEMON_ADAPTORS_H
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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 <lemon/arg_parser.h>
20 20

	
21 21
namespace lemon {
22 22

	
23 23
  void ArgParser::_showHelp(void *p)
24 24
  {
25 25
    (static_cast<ArgParser*>(p))->showHelp();
26 26
    exit(1);
27 27
  }
28 28

	
29 29
  ArgParser::ArgParser(int argc, const char * const *argv)
30 30
    :_argc(argc), _argv(argv), _command_name(argv[0]) {
31 31
    funcOption("-help","Print a short help message",_showHelp,this);
32 32
    synonym("help","-help");
33 33
    synonym("h","-help");
34 34
  }
35 35

	
36 36
  ArgParser::~ArgParser()
37 37
  {
38 38
    for(Opts::iterator i=_opts.begin();i!=_opts.end();++i)
39 39
      if(i->second.self_delete)
40 40
        switch(i->second.type) {
41 41
        case BOOL:
42 42
          delete i->second.bool_p;
43 43
          break;
44 44
        case STRING:
45 45
          delete i->second.string_p;
46 46
          break;
47 47
        case DOUBLE:
48 48
          delete i->second.double_p;
49 49
          break;
50 50
        case INTEGER:
51 51
          delete i->second.int_p;
52 52
          break;
53 53
        case UNKNOWN:
54 54
          break;
55 55
        case FUNC:
56 56
          break;
57 57
        }
58 58
  }
59 59

	
60 60

	
61 61
  ArgParser &ArgParser::intOption(const std::string &name,
62 62
                               const std::string &help,
63 63
                               int value, bool obl)
64 64
  {
65 65
    ParData p;
66 66
    p.int_p=new int(value);
67 67
    p.self_delete=true;
68 68
    p.help=help;
69 69
    p.type=INTEGER;
70 70
    p.mandatory=obl;
71 71
    _opts[name]=p;
72 72
    return *this;
73 73
  }
74 74

	
75 75
  ArgParser &ArgParser::doubleOption(const std::string &name,
76 76
                               const std::string &help,
77 77
                               double value, bool obl)
78 78
  {
79 79
    ParData p;
80 80
    p.double_p=new double(value);
81 81
    p.self_delete=true;
82 82
    p.help=help;
83 83
    p.type=DOUBLE;
84 84
    p.mandatory=obl;
85 85
    _opts[name]=p;
86 86
    return *this;
87 87
  }
88 88

	
89 89
  ArgParser &ArgParser::boolOption(const std::string &name,
90 90
                               const std::string &help,
91 91
                               bool value, bool obl)
92 92
  {
93 93
    ParData p;
94 94
    p.bool_p=new bool(value);
95 95
    p.self_delete=true;
96 96
    p.help=help;
97 97
    p.type=BOOL;
98 98
    p.mandatory=obl;
99 99
    _opts[name]=p;
100 100
    return *this;
101 101
  }
102 102

	
103 103
  ArgParser &ArgParser::stringOption(const std::string &name,
104 104
                               const std::string &help,
105 105
                               std::string value, bool obl)
106 106
  {
107 107
    ParData p;
108 108
    p.string_p=new std::string(value);
109 109
    p.self_delete=true;
110 110
    p.help=help;
111 111
    p.type=STRING;
112 112
    p.mandatory=obl;
113 113
    _opts[name]=p;
114 114
    return *this;
115 115
  }
116 116

	
117 117
  ArgParser &ArgParser::refOption(const std::string &name,
118 118
                               const std::string &help,
119 119
                               int &ref, bool obl)
120 120
  {
121 121
    ParData p;
122 122
    p.int_p=&ref;
123 123
    p.self_delete=false;
124 124
    p.help=help;
125 125
    p.type=INTEGER;
126 126
    p.mandatory=obl;
127 127
    _opts[name]=p;
128 128
    return *this;
129 129
  }
130 130

	
131 131
  ArgParser &ArgParser::refOption(const std::string &name,
132 132
                                  const std::string &help,
133 133
                                  double &ref, bool obl)
134 134
  {
135 135
    ParData p;
136 136
    p.double_p=&ref;
137 137
    p.self_delete=false;
138 138
    p.help=help;
139 139
    p.type=DOUBLE;
140 140
    p.mandatory=obl;
141 141
    _opts[name]=p;
142 142
    return *this;
143 143
  }
144 144

	
145 145
  ArgParser &ArgParser::refOption(const std::string &name,
146 146
                                  const std::string &help,
147 147
                                  bool &ref, bool obl)
148 148
  {
149 149
    ParData p;
150 150
    p.bool_p=&ref;
151 151
    p.self_delete=false;
152 152
    p.help=help;
153 153
    p.type=BOOL;
154 154
    p.mandatory=obl;
155 155
    _opts[name]=p;
156 156

	
157 157
    ref = false;
158 158

	
159 159
    return *this;
160 160
  }
161 161

	
162 162
  ArgParser &ArgParser::refOption(const std::string &name,
163 163
                               const std::string &help,
164 164
                               std::string &ref, bool obl)
165 165
  {
166 166
    ParData p;
167 167
    p.string_p=&ref;
168 168
    p.self_delete=false;
169 169
    p.help=help;
170 170
    p.type=STRING;
171 171
    p.mandatory=obl;
172 172
    _opts[name]=p;
173 173
    return *this;
174 174
  }
175 175

	
176 176
  ArgParser &ArgParser::funcOption(const std::string &name,
177 177
                               const std::string &help,
178 178
                               void (*func)(void *),void *data)
179 179
  {
180 180
    ParData p;
181 181
    p.func_p.p=func;
182 182
    p.func_p.data=data;
183 183
    p.self_delete=false;
184 184
    p.help=help;
185 185
    p.type=FUNC;
186 186
    p.mandatory=false;
187 187
    _opts[name]=p;
188 188
    return *this;
189 189
  }
190 190

	
191 191
  ArgParser &ArgParser::optionGroup(const std::string &group,
192 192
                                    const std::string &opt)
193 193
  {
194 194
    Opts::iterator i = _opts.find(opt);
195 195
    LEMON_ASSERT(i!=_opts.end(), "Unknown option: '"+opt+"'");
196 196
    LEMON_ASSERT(!(i->second.ingroup),
197 197
                 "Option already in option group: '"+opt+"'");
198 198
    GroupData &g=_groups[group];
199 199
    g.opts.push_back(opt);
200 200
    i->second.ingroup=true;
201 201
    return *this;
202 202
  }
203 203

	
204 204
  ArgParser &ArgParser::onlyOneGroup(const std::string &group)
205 205
  {
206 206
    GroupData &g=_groups[group];
207 207
    g.only_one=true;
208 208
    return *this;
209 209
  }
210 210

	
211 211
  ArgParser &ArgParser::synonym(const std::string &syn,
212 212
                                const std::string &opt)
213 213
  {
214 214
    Opts::iterator o = _opts.find(opt);
215 215
    Opts::iterator s = _opts.find(syn);
216 216
    LEMON_ASSERT(o!=_opts.end(), "Unknown option: '"+opt+"'");
217 217
    LEMON_ASSERT(s==_opts.end(), "Option already used: '"+syn+"'");
218 218
    ParData p;
219 219
    p.help=opt;
220 220
    p.mandatory=false;
221 221
    p.syn=true;
222 222
    _opts[syn]=p;
223 223
    o->second.has_syn=true;
224 224
    return *this;
225 225
  }
226 226

	
227 227
  ArgParser &ArgParser::mandatoryGroup(const std::string &group)
228 228
  {
229 229
    GroupData &g=_groups[group];
230 230
    g.mandatory=true;
231 231
    return *this;
232 232
  }
233 233

	
234 234
  ArgParser &ArgParser::other(const std::string &name,
235 235
                              const std::string &help)
236 236
  {
237 237
    _others_help.push_back(OtherArg(name,help));
238 238
    return *this;
239 239
  }
240 240

	
241 241
  void ArgParser::show(std::ostream &os,Opts::const_iterator i) const
242 242
  {
243 243
    os << "-" << i->first;
244 244
    if(i->second.has_syn)
245 245
      for(Opts::const_iterator j=_opts.begin();j!=_opts.end();++j)
246 246
        if(j->second.syn&&j->second.help==i->first)
247 247
          os << "|-" << j->first;
248 248
    switch(i->second.type) {
249 249
    case STRING:
250 250
      os << " str";
251 251
      break;
252 252
    case INTEGER:
253 253
      os << " int";
254 254
      break;
255 255
    case DOUBLE:
256 256
      os << " num";
257 257
      break;
258 258
    default:
259 259
      break;
260 260
    }
261 261
  }
262 262

	
263 263
  void ArgParser::show(std::ostream &os,Groups::const_iterator i) const
264 264
  {
265 265
    GroupData::Opts::const_iterator o=i->second.opts.begin();
266 266
    while(o!=i->second.opts.end()) {
267 267
      show(os,_opts.find(*o));
268 268
      ++o;
269 269
      if(o!=i->second.opts.end()) os<<'|';
270 270
    }
271 271
  }
272 272

	
273 273
  void ArgParser::showHelp(Opts::const_iterator i) const
274 274
  {
275 275
    if(i->second.help.size()==0||i->second.syn) return;
276 276
    std::cerr << "  ";
277 277
    show(std::cerr,i);
278 278
    std::cerr << std::endl;
279 279
    std::cerr << "     " << i->second.help << std::endl;
280 280
  }
281 281
  void ArgParser::showHelp(std::vector<ArgParser::OtherArg>::const_iterator i)
282 282
    const
283 283
  {
284 284
    if(i->help.size()==0) return;
285 285
    std::cerr << "  " << i->name << std::endl
286 286
              << "     " << i->help << std::endl;
287 287
  }
288 288

	
289 289
  void ArgParser::shortHelp() const
290 290
  {
291 291
    const unsigned int LINE_LEN=77;
292 292
    const std::string indent("    ");
293 293
    std::cerr << "Usage:\n  " << _command_name;
294 294
    int pos=_command_name.size()+2;
295 295
    for(Groups::const_iterator g=_groups.begin();g!=_groups.end();++g) {
296 296
      std::ostringstream cstr;
297 297
      cstr << ' ';
298 298
      if(!g->second.mandatory) cstr << '[';
299 299
      show(cstr,g);
300 300
      if(!g->second.mandatory) cstr << ']';
301 301
      if(pos+cstr.str().size()>LINE_LEN) {
302 302
        std::cerr << std::endl << indent;
303 303
        pos=indent.size();
304 304
      }
305 305
      std::cerr << cstr.str();
306 306
      pos+=cstr.str().size();
307 307
    }
308 308
    for(Opts::const_iterator i=_opts.begin();i!=_opts.end();++i)
309 309
      if(!i->second.ingroup&&!i->second.syn) {
310 310
        std::ostringstream cstr;
311 311
        cstr << ' ';
312 312
        if(!i->second.mandatory) cstr << '[';
313 313
        show(cstr,i);
314 314
        if(!i->second.mandatory) cstr << ']';
315 315
        if(pos+cstr.str().size()>LINE_LEN) {
316 316
          std::cerr << std::endl << indent;
317 317
          pos=indent.size();
318 318
        }
319 319
        std::cerr << cstr.str();
320 320
        pos+=cstr.str().size();
321 321
      }
322 322
    for(std::vector<OtherArg>::const_iterator i=_others_help.begin();
323 323
        i!=_others_help.end();++i)
324 324
      {
325 325
        std::ostringstream cstr;
326 326
        cstr << ' ' << i->name;
327 327

	
328 328
        if(pos+cstr.str().size()>LINE_LEN) {
329 329
          std::cerr << std::endl << indent;
330 330
          pos=indent.size();
331 331
        }
332 332
        std::cerr << cstr.str();
333 333
        pos+=cstr.str().size();
334 334
      }
335 335
    std::cerr << std::endl;
336 336
  }
337 337

	
338 338
  void ArgParser::showHelp() const
339 339
  {
340 340
    shortHelp();
341 341
    std::cerr << "Where:\n";
342 342
    for(std::vector<OtherArg>::const_iterator i=_others_help.begin();
343 343
        i!=_others_help.end();++i) showHelp(i);
344 344
    for(Opts::const_iterator i=_opts.begin();i!=_opts.end();++i) showHelp(i);
345 345
    exit(1);
346 346
  }
347 347

	
348 348

	
349 349
  void ArgParser::unknownOpt(std::string arg) const
350 350
  {
351 351
    std::cerr << "\nUnknown option: " << arg << "\n";
352 352
    std::cerr << "\nType '" << _command_name <<
353 353
      " --help' to obtain a short summary on the usage.\n\n";
354 354
    exit(1);
355 355
  }
356 356

	
357 357
  void ArgParser::requiresValue(std::string arg, OptType t) const
358 358
  {
359 359
    std::cerr << "Argument '" << arg << "' requires a";
360 360
    switch(t) {
361 361
    case STRING:
362 362
      std::cerr << " string";
363 363
      break;
364 364
    case INTEGER:
365 365
      std::cerr << "n integer";
366 366
      break;
367 367
    case DOUBLE:
368 368
      std::cerr << " floating point";
369 369
      break;
370 370
    default:
371 371
      break;
372 372
    }
373 373
    std::cerr << " value\n\n";
374 374
    showHelp();
375 375
  }
376 376

	
377 377

	
378 378
  void ArgParser::checkMandatories() const
379 379
  {
380 380
    bool ok=true;
381 381
    for(Opts::const_iterator i=_opts.begin();i!=_opts.end();++i)
382 382
      if(i->second.mandatory&&!i->second.set)
383 383
        {
384 384
          if(ok)
385 385
            std::cerr << _command_name
386 386
                      << ": The following mandatory arguments are missing.\n";
387 387
          ok=false;
388 388
          showHelp(i);
389 389
        }
390 390
    for(Groups::const_iterator i=_groups.begin();i!=_groups.end();++i)
391 391
      if(i->second.mandatory||i->second.only_one)
392 392
        {
393 393
          int set=0;
394 394
          for(GroupData::Opts::const_iterator o=i->second.opts.begin();
395 395
              o!=i->second.opts.end();++o)
396 396
            if(_opts.find(*o)->second.set) ++set;
397 397
          if(i->second.mandatory&&!set) {
398 398
            std::cerr << _command_name <<
399 399
              ": At least one of the following arguments is mandatory.\n";
400 400
            ok=false;
401 401
            for(GroupData::Opts::const_iterator o=i->second.opts.begin();
402 402
                o!=i->second.opts.end();++o)
403 403
              showHelp(_opts.find(*o));
404 404
          }
405 405
          if(i->second.only_one&&set>1) {
406 406
            std::cerr << _command_name <<
407 407
              ": At most one of the following arguments can be given.\n";
408 408
            ok=false;
409 409
            for(GroupData::Opts::const_iterator o=i->second.opts.begin();
410 410
                o!=i->second.opts.end();++o)
411 411
              showHelp(_opts.find(*o));
412 412
          }
413 413
        }
414 414
    if(!ok) {
415 415
      std::cerr << "\nType '" << _command_name <<
416 416
        " --help' to obtain a short summary on the usage.\n\n";
417 417
      exit(1);
418 418
    }
419 419
  }
420 420

	
421 421
  ArgParser &ArgParser::parse()
422 422
  {
423 423
    for(int ar=1; ar<_argc; ++ar) {
424 424
      std::string arg(_argv[ar]);
425 425
      if (arg[0] != '-' || arg.size() == 1) {
426 426
        _file_args.push_back(arg);
427 427
      }
428 428
      else {
429 429
        Opts::iterator i = _opts.find(arg.substr(1));
430 430
        if(i==_opts.end()) unknownOpt(arg);
431 431
        else {
432 432
          if(i->second.syn) i=_opts.find(i->second.help);
433 433
          ParData &p(i->second);
434 434
          if (p.type==BOOL) *p.bool_p=true;
435 435
          else if (p.type==FUNC) p.func_p.p(p.func_p.data);
436 436
          else if(++ar==_argc) requiresValue(arg, p.type);
437 437
          else {
438 438
            std::string val(_argv[ar]);
439 439
            std::istringstream vals(val);
440 440
            switch(p.type) {
441 441
            case STRING:
442 442
              *p.string_p=val;
443 443
              break;
444 444
            case INTEGER:
445 445
              vals >> *p.int_p;
446 446
              break;
447 447
            case DOUBLE:
448 448
              vals >> *p.double_p;
449 449
              break;
450 450
            default:
451 451
              break;
452 452
            }
453 453
            if(p.type!=STRING&&(!vals||!vals.eof()))
454 454
              requiresValue(arg, p.type);
455 455
          }
456 456
          p.set = true;
457 457
        }
458 458
      }
459 459
    }
460 460
    checkMandatories();
461 461

	
462 462
    return *this;
463 463
  }
464 464

	
465 465
}
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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_ARG_PARSER_H
20 20
#define LEMON_ARG_PARSER_H
21 21

	
22 22
#include <vector>
23 23
#include <map>
24 24
#include <list>
25 25
#include <string>
26 26
#include <iostream>
27 27
#include <sstream>
28 28
#include <algorithm>
29 29
#include <lemon/assert.h>
30 30

	
31 31
///\ingroup misc
32 32
///\file
33 33
///\brief A tool to parse command line arguments.
34 34

	
35 35
namespace lemon {
36 36

	
37 37
  ///Command line arguments parser
38 38

	
39 39
  ///\ingroup misc
40 40
  ///Command line arguments parser.
41 41
  ///
42 42
  ///For a complete example see the \ref arg_parser_demo.cc demo file.
43 43
  class ArgParser {
44 44

	
45 45
    static void _showHelp(void *p);
46 46
  protected:
47 47

	
48 48
    int _argc;
49 49
    const char * const *_argv;
50 50

	
51 51
    enum OptType { UNKNOWN=0, BOOL=1, STRING=2, DOUBLE=3, INTEGER=4, FUNC=5 };
52 52

	
53 53
    class ParData {
54 54
    public:
55 55
      union {
56 56
        bool *bool_p;
57 57
        int *int_p;
58 58
        double *double_p;
59 59
        std::string *string_p;
60 60
        struct {
61 61
          void (*p)(void *);
62 62
          void *data;
63 63
        } func_p;
64 64

	
65 65
      };
66 66
      std::string help;
67 67
      bool mandatory;
68 68
      OptType type;
69 69
      bool set;
70 70
      bool ingroup;
71 71
      bool has_syn;
72 72
      bool syn;
73 73
      bool self_delete;
74 74
      ParData() : mandatory(false), type(UNKNOWN), set(false), ingroup(false),
75 75
                  has_syn(false), syn(false), self_delete(false) {}
76 76
    };
77 77

	
78 78
    typedef std::map<std::string,ParData> Opts;
79 79
    Opts _opts;
80 80

	
81 81
    class GroupData
82 82
    {
83 83
    public:
84 84
      typedef std::list<std::string> Opts;
85 85
      Opts opts;
86 86
      bool only_one;
87 87
      bool mandatory;
88 88
      GroupData() :only_one(false), mandatory(false) {}
89 89
    };
90 90

	
91 91
    typedef std::map<std::string,GroupData> Groups;
92 92
    Groups _groups;
93 93

	
94 94
    struct OtherArg
95 95
    {
96 96
      std::string name;
97 97
      std::string help;
98 98
      OtherArg(std::string n, std::string h) :name(n), help(h) {}
99 99

	
100 100
    };
101 101

	
102 102
    std::vector<OtherArg> _others_help;
103 103
    std::vector<std::string> _file_args;
104 104
    std::string _command_name;
105 105

	
106 106

	
107 107
  private:
108 108
    //Bind a function to an option.
109 109

	
110 110
    //\param name The name of the option. The leading '-' must be omitted.
111 111
    //\param help A help string.
112 112
    //\retval func The function to be called when the option is given. It
113 113
    //  must be of type "void f(void *)"
114 114
    //\param data Data to be passed to \c func
115 115
    ArgParser &funcOption(const std::string &name,
116 116
                    const std::string &help,
117 117
                    void (*func)(void *),void *data);
118 118

	
119 119
  public:
120 120

	
121 121
    ///Constructor
122 122
    ArgParser(int argc, const char * const *argv);
123 123

	
124 124
    ~ArgParser();
125 125

	
126 126
    ///\name Options
127 127
    ///
128 128

	
129 129
    ///@{
130 130

	
131 131
    ///Add a new integer type option
132 132

	
133 133
    ///Add a new integer type option.
134 134
    ///\param name The name of the option. The leading '-' must be omitted.
135 135
    ///\param help A help string.
136 136
    ///\param value A default value for the option.
137 137
    ///\param obl Indicate if the option is mandatory.
138 138
    ArgParser &intOption(const std::string &name,
139 139
                    const std::string &help,
140 140
                    int value=0, bool obl=false);
141 141

	
142 142
    ///Add a new floating point type option
143 143

	
144 144
    ///Add a new floating point type option.
145 145
    ///\param name The name of the option. The leading '-' must be omitted.
146 146
    ///\param help A help string.
147 147
    ///\param value A default value for the option.
148 148
    ///\param obl Indicate if the option is mandatory.
149 149
    ArgParser &doubleOption(const std::string &name,
150 150
                      const std::string &help,
151 151
                      double value=0, bool obl=false);
152 152

	
153 153
    ///Add a new bool type option
154 154

	
155 155
    ///Add a new bool type option.
156 156
    ///\param name The name of the option. The leading '-' must be omitted.
157 157
    ///\param help A help string.
158 158
    ///\param value A default value for the option.
159 159
    ///\param obl Indicate if the option is mandatory.
160 160
    ///\note A mandatory bool obtion is of very little use.
161 161
    ArgParser &boolOption(const std::string &name,
162 162
                      const std::string &help,
163 163
                      bool value=false, bool obl=false);
164 164

	
165 165
    ///Add a new string type option
166 166

	
167 167
    ///Add a new string type option.
168 168
    ///\param name The name of the option. The leading '-' must be omitted.
169 169
    ///\param help A help string.
170 170
    ///\param value A default value for the option.
171 171
    ///\param obl Indicate if the option is mandatory.
172 172
    ArgParser &stringOption(const std::string &name,
173 173
                      const std::string &help,
174 174
                      std::string value="", bool obl=false);
175 175

	
176 176
    ///Give help string for non-parsed arguments.
177 177

	
178 178
    ///With this function you can give help string for non-parsed arguments.
179 179
    ///The parameter \c name will be printed in the short usage line, while
180 180
    ///\c help gives a more detailed description.
181 181
    ArgParser &other(const std::string &name,
182 182
                     const std::string &help="");
183 183

	
184 184
    ///@}
185 185

	
186 186
    ///\name Options with External Storage
187 187
    ///Using this functions, the value of the option will be directly written
188 188
    ///into a variable once the option appears in the command line.
189 189

	
190 190
    ///@{
191 191

	
192 192
    ///Add a new integer type option with a storage reference
193 193

	
194 194
    ///Add a new integer type option with a storage reference.
195 195
    ///\param name The name of the option. The leading '-' must be omitted.
196 196
    ///\param help A help string.
197 197
    ///\param obl Indicate if the option is mandatory.
198 198
    ///\retval ref The value of the argument will be written to this variable.
199 199
    ArgParser &refOption(const std::string &name,
200 200
                    const std::string &help,
201 201
                    int &ref, bool obl=false);
202 202

	
203 203
    ///Add a new floating type option with a storage reference
204 204

	
205 205
    ///Add a new floating type option with a storage reference.
206 206
    ///\param name The name of the option. The leading '-' must be omitted.
207 207
    ///\param help A help string.
208 208
    ///\param obl Indicate if the option is mandatory.
209 209
    ///\retval ref The value of the argument will be written to this variable.
210 210
    ArgParser &refOption(const std::string &name,
211 211
                      const std::string &help,
212 212
                      double &ref, bool obl=false);
213 213

	
214 214
    ///Add a new bool type option with a storage reference
215 215

	
216 216
    ///Add a new bool type option with a storage reference.
217 217
    ///\param name The name of the option. The leading '-' must be omitted.
218 218
    ///\param help A help string.
219 219
    ///\param obl Indicate if the option is mandatory.
220 220
    ///\retval ref The value of the argument will be written to this variable.
221 221
    ///\note A mandatory bool obtion is of very little use.
222 222
    ArgParser &refOption(const std::string &name,
223 223
                      const std::string &help,
224 224
                      bool &ref, bool obl=false);
225 225

	
226 226
    ///Add a new string type option with a storage reference
227 227

	
228 228
    ///Add a new string type option with a storage reference.
229 229
    ///\param name The name of the option. The leading '-' must be omitted.
230 230
    ///\param help A help string.
231 231
    ///\param obl Indicate if the option is mandatory.
232 232
    ///\retval ref The value of the argument will be written to this variable.
233 233
    ArgParser &refOption(const std::string &name,
234 234
                      const std::string &help,
235 235
                      std::string &ref, bool obl=false);
236 236

	
237 237
    ///@}
238 238

	
239 239
    ///\name Option Groups and Synonyms
240 240
    ///
241 241

	
242 242
    ///@{
243 243

	
244 244
    ///Bundle some options into a group
245 245

	
246 246
    /// You can group some option by calling this function repeatedly for each
247 247
    /// option to be grouped with the same groupname.
248 248
    ///\param group The group name.
249 249
    ///\param opt The option name.
250 250
    ArgParser &optionGroup(const std::string &group,
251 251
                           const std::string &opt);
252 252

	
253 253
    ///Make the members of a group exclusive
254 254

	
255 255
    ///If you call this function for a group, than at most one of them can be
256 256
    ///given at the same time.
257 257
    ArgParser &onlyOneGroup(const std::string &group);
258 258

	
259 259
    ///Make a group mandatory
260 260

	
261 261
    ///Using this function, at least one of the members of \c group
262 262
    ///must be given.
263 263
    ArgParser &mandatoryGroup(const std::string &group);
264 264

	
265 265
    ///Create synonym to an option
266 266

	
267 267
    ///With this function you can create a synonym \c syn of the
268 268
    ///option \c opt.
269 269
    ArgParser &synonym(const std::string &syn,
270 270
                           const std::string &opt);
271 271

	
272 272
    ///@}
273 273

	
274 274
  private:
275 275
    void show(std::ostream &os,Opts::const_iterator i) const;
276 276
    void show(std::ostream &os,Groups::const_iterator i) const;
277 277
    void showHelp(Opts::const_iterator i) const;
278 278
    void showHelp(std::vector<OtherArg>::const_iterator i) const;
279 279

	
280 280
    void unknownOpt(std::string arg) const;
281 281

	
282 282
    void requiresValue(std::string arg, OptType t) const;
283 283
    void checkMandatories() const;
284 284

	
285 285
    void shortHelp() const;
286 286
    void showHelp() const;
287 287
  public:
288 288

	
289 289
    ///Start the parsing process
290 290
    ArgParser &parse();
291 291

	
292 292
    /// Synonym for parse()
293 293
    ArgParser &run()
294 294
    {
295 295
      return parse();
296 296
    }
297 297

	
298 298
    ///Give back the command name (the 0th argument)
299 299
    const std::string &commandName() const { return _command_name; }
300 300

	
301 301
    ///Check if an opion has been given to the command.
302 302
    bool given(std::string op) const
303 303
    {
304 304
      Opts::const_iterator i = _opts.find(op);
305 305
      return i!=_opts.end()?i->second.set:false;
306 306
    }
307 307

	
308 308

	
309 309
    ///Magic type for operator[]
310 310

	
311 311
    ///This is the type of the return value of ArgParser::operator[]().
312 312
    ///It automatically converts to \c int, \c double, \c bool or
313 313
    ///\c std::string if the type of the option matches, which is checked
314 314
    ///with an \ref LEMON_ASSERT "assertion" (i.e. it performs runtime
315 315
    ///type checking).
316 316
    class RefType
317 317
    {
318 318
      const ArgParser &_parser;
319 319
      std::string _name;
320 320
    public:
321 321
      ///\e
322 322
      RefType(const ArgParser &p,const std::string &n) :_parser(p),_name(n) {}
323 323
      ///\e
324 324
      operator bool()
325 325
      {
326 326
        Opts::const_iterator i = _parser._opts.find(_name);
327 327
        LEMON_ASSERT(i!=_parser._opts.end(),
328 328
                     std::string()+"Unkown option: '"+_name+"'");
329 329
        LEMON_ASSERT(i->second.type==ArgParser::BOOL,
330 330
                     std::string()+"'"+_name+"' is a bool option");
331 331
        return *(i->second.bool_p);
332 332
      }
333 333
      ///\e
334 334
      operator std::string()
335 335
      {
336 336
        Opts::const_iterator i = _parser._opts.find(_name);
337 337
        LEMON_ASSERT(i!=_parser._opts.end(),
338 338
                     std::string()+"Unkown option: '"+_name+"'");
339 339
        LEMON_ASSERT(i->second.type==ArgParser::STRING,
340 340
                     std::string()+"'"+_name+"' is a string option");
341 341
        return *(i->second.string_p);
342 342
      }
343 343
      ///\e
344 344
      operator double()
345 345
      {
346 346
        Opts::const_iterator i = _parser._opts.find(_name);
347 347
        LEMON_ASSERT(i!=_parser._opts.end(),
348 348
                     std::string()+"Unkown option: '"+_name+"'");
349 349
        LEMON_ASSERT(i->second.type==ArgParser::DOUBLE ||
350 350
                     i->second.type==ArgParser::INTEGER,
351 351
                     std::string()+"'"+_name+"' is a floating point option");
352 352
        return i->second.type==ArgParser::DOUBLE ?
353 353
          *(i->second.double_p) : *(i->second.int_p);
354 354
      }
355 355
      ///\e
356 356
      operator int()
357 357
      {
358 358
        Opts::const_iterator i = _parser._opts.find(_name);
359 359
        LEMON_ASSERT(i!=_parser._opts.end(),
360 360
                     std::string()+"Unkown option: '"+_name+"'");
361 361
        LEMON_ASSERT(i->second.type==ArgParser::INTEGER,
362 362
                     std::string()+"'"+_name+"' is an integer option");
363 363
        return *(i->second.int_p);
364 364
      }
365 365

	
366 366
    };
367 367

	
368 368
    ///Give back the value of an option
369 369

	
370 370
    ///Give back the value of an option.
371 371
    ///\sa RefType
372 372
    RefType operator[](const std::string &n) const
373 373
    {
374 374
      return RefType(*this, n);
375 375
    }
376 376

	
377 377
    ///Give back the non-option type arguments.
378 378

	
379 379
    ///Give back a reference to a vector consisting of the program arguments
380 380
    ///not starting with a '-' character.
381 381
    const std::vector<std::string> &files() const { return _file_args; }
382 382

	
383 383
  };
384 384
}
385 385

	
386 386
#endif // LEMON_ARG_PARSER_H
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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_ASSERT_H
20 20
#define LEMON_ASSERT_H
21 21

	
22 22
/// \ingroup exceptions
23 23
/// \file
24 24
/// \brief Extended assertion handling
25 25

	
26 26
#include <lemon/error.h>
27 27

	
28 28
namespace lemon {
29 29

	
30 30
  inline void assert_fail_abort(const char *file, int line,
31 31
                                const char *function, const char* message,
32 32
                                const char *assertion)
33 33
  {
34 34
    std::cerr << file << ":" << line << ": ";
35 35
    if (function)
36 36
      std::cerr << function << ": ";
37 37
    std::cerr << message;
38 38
    if (assertion)
39 39
      std::cerr << " (assertion '" << assertion << "' failed)";
40 40
    std::cerr << std::endl;
41 41
    std::abort();
42 42
  }
43 43

	
44 44
  namespace _assert_bits {
45 45

	
46 46

	
47 47
    inline const char* cstringify(const std::string& str) {
48 48
      return str.c_str();
49 49
    }
50 50

	
51 51
    inline const char* cstringify(const char* str) {
52 52
      return str;
53 53
    }
54 54
  }
55 55
}
56 56

	
57 57
#endif // LEMON_ASSERT_H
58 58

	
59 59
#undef LEMON_ASSERT
60 60
#undef LEMON_DEBUG
61 61

	
62 62
#if (defined(LEMON_ASSERT_ABORT) ? 1 : 0) +               \
63 63
  (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1
64 64
#error "LEMON assertion system is not set properly"
65 65
#endif
66 66

	
67 67
#if ((defined(LEMON_ASSERT_ABORT) ? 1 : 0) +            \
68 68
     (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 ||     \
69 69
     defined(LEMON_ENABLE_ASSERTS)) &&                  \
70 70
  (defined(LEMON_DISABLE_ASSERTS) ||                    \
71 71
   defined(NDEBUG))
72 72
#error "LEMON assertion system is not set properly"
73 73
#endif
74 74

	
75 75

	
76 76
#if defined LEMON_ASSERT_ABORT
77 77
#  undef LEMON_ASSERT_HANDLER
78 78
#  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
79 79
#elif defined LEMON_ASSERT_CUSTOM
80 80
#  undef LEMON_ASSERT_HANDLER
81 81
#  ifndef LEMON_CUSTOM_ASSERT_HANDLER
82 82
#    error "LEMON_CUSTOM_ASSERT_HANDLER is not set"
83 83
#  endif
84 84
#  define LEMON_ASSERT_HANDLER LEMON_CUSTOM_ASSERT_HANDLER
85 85
#elif defined LEMON_DISABLE_ASSERTS
86 86
#  undef LEMON_ASSERT_HANDLER
87 87
#elif defined NDEBUG
88 88
#  undef LEMON_ASSERT_HANDLER
89 89
#else
90 90
#  define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
91 91
#endif
92 92

	
93 93
#ifndef LEMON_FUNCTION_NAME
94 94
#  if defined __GNUC__
95 95
#    define LEMON_FUNCTION_NAME (__PRETTY_FUNCTION__)
96 96
#  elif defined _MSC_VER
97 97
#    define LEMON_FUNCTION_NAME (__FUNCSIG__)
98 98
#  elif __STDC_VERSION__ >= 199901L
99 99
#    define LEMON_FUNCTION_NAME (__func__)
100 100
#  else
101 101
#    define LEMON_FUNCTION_NAME ("<unknown>")
102 102
#  endif
103 103
#endif
104 104

	
105 105
#ifdef DOXYGEN
106 106

	
107 107
/// \ingroup exceptions
108 108
///
109 109
/// \brief Macro for assertion with customizable message
110 110
///
111 111
/// Macro for assertion with customizable message.
112 112
/// \param exp An expression that must be convertible to \c bool.  If it is \c
113 113
/// false, then an assertion is raised. The concrete behaviour depends on the
114 114
/// settings of the assertion system.
115 115
/// \param msg A <tt>const char*</tt> parameter, which can be used to provide
116 116
/// information about the circumstances of the failed assertion.
117 117
///
118 118
/// The assertions are enabled in the default behaviour.
119 119
/// You can disable them with the following code:
120 120
/// \code
121 121
/// #define LEMON_DISABLE_ASSERTS
122 122
/// \endcode
123 123
/// or with compilation parameters:
124 124
/// \code
125 125
/// g++ -DLEMON_DISABLE_ASSERTS
126 126
/// make CXXFLAGS='-DLEMON_DISABLE_ASSERTS'
127 127
/// \endcode
128 128
/// The checking is also disabled when the standard macro \c NDEBUG is defined.
129 129
///
130 130
/// As a default behaviour the failed assertion prints a short log message to
131 131
/// the standard error and aborts the execution.
132 132
///
133 133
/// However, the following modes can be used in the assertion system:
134 134
/// - \c LEMON_ASSERT_ABORT The failed assertion prints a short log message to
135 135
///   the standard error and aborts the program. It is the default behaviour.
136 136
/// - \c LEMON_ASSERT_CUSTOM The user can define own assertion handler
137 137
///   function.
138 138
///   \code
139 139
///     void custom_assert_handler(const char* file, int line,
140 140
///                                const char* function, const char* message,
141 141
///                                const char* assertion);
142 142
///   \endcode
143 143
///   The name of the function should be defined as the \c
144 144
///   LEMON_CUSTOM_ASSERT_HANDLER macro name.
145 145
///   \code
146 146
///     #define LEMON_CUSTOM_ASSERT_HANDLER custom_assert_handler
147 147
///   \endcode
148 148
///   Whenever an assertion is occured, the custom assertion
149 149
///   handler is called with appropiate parameters.
150 150
///
151 151
/// The assertion mode can also be changed within one compilation unit.
152 152
/// If the macros are redefined with other settings and the
153 153
/// \ref lemon/assert.h "assert.h" file is reincluded, then the
154 154
/// behaviour is changed appropiately to the new settings.
155 155
#  define LEMON_ASSERT(exp, msg)                                        \
156 156
  (static_cast<void> (!!(exp) ? 0 : (                                   \
157 157
    LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                            \
158 158
                         LEMON_FUNCTION_NAME,                           \
159 159
                         ::lemon::_assert_bits::cstringify(msg), #exp), 0)))
160 160

	
161 161
/// \ingroup exceptions
162 162
///
163 163
/// \brief Macro for internal assertions
164 164
///
165 165
/// Macro for internal assertions, it is used in the library to check
166 166
/// the consistency of results of algorithms, several pre- and
167 167
/// postconditions and invariants. The checking is disabled by
168 168
/// default, but it can be turned on with the macro \c
169 169
/// LEMON_ENABLE_DEBUG.
170 170
/// \code
171 171
/// #define LEMON_ENABLE_DEBUG
172 172
/// \endcode
173 173
/// or with compilation parameters:
174 174
/// \code
175 175
/// g++ -DLEMON_ENABLE_DEBUG
176 176
/// make CXXFLAGS='-DLEMON_ENABLE_DEBUG'
177 177
/// \endcode
178 178
///
179 179
/// This macro works like the \c LEMON_ASSERT macro, therefore the
180 180
/// current behaviour depends on the settings of \c LEMON_ASSERT
181 181
/// macro.
182 182
///
183 183
/// \see LEMON_ASSERT
184 184
#  define LEMON_DEBUG(exp, msg)                                         \
185 185
  (static_cast<void> (!!(exp) ? 0 : (                                   \
186 186
    LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                            \
187 187
                         LEMON_FUNCTION_NAME,                           \
188 188
                         ::lemon::_assert_bits::cstringify(msg), #exp), 0)))
189 189

	
190 190
#else
191 191

	
192 192
#  ifndef LEMON_ASSERT_HANDLER
193 193
#    define LEMON_ASSERT(exp, msg)  (static_cast<void>(0))
194 194
#    define LEMON_DEBUG(exp, msg) (static_cast<void>(0))
195 195
#  else
196 196
#    define LEMON_ASSERT(exp, msg)                                      \
197 197
       (static_cast<void> (!!(exp) ? 0 : (                              \
198 198
        LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                        \
199 199
                             LEMON_FUNCTION_NAME,                       \
200 200
                             ::lemon::_assert_bits::cstringify(msg),    \
201 201
                             #exp), 0)))
202 202
#    if LEMON_ENABLE_DEBUG
203 203
#      define LEMON_DEBUG(exp, msg)                                     \
204 204
         (static_cast<void> (!!(exp) ? 0 : (                            \
205 205
           LEMON_ASSERT_HANDLER(__FILE__, __LINE__,                     \
206 206
                                LEMON_FUNCTION_NAME,                    \
207 207
                                ::lemon::_assert_bits::cstringify(msg), \
208 208
                                #exp), 0)))
209 209
#    else
210 210
#      define LEMON_DEBUG(exp, msg) (static_cast<void>(0))
211 211
#    endif
212 212
#  endif
213 213

	
214 214
#endif
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
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2009
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
///\file
20 20
///\brief Some basic non-inline functions and static global data.
21 21

	
22 22
#include<lemon/tolerance.h>
23 23
#include<lemon/core.h>
24 24
namespace lemon {
25 25

	
26 26
  float Tolerance<float>::def_epsilon = 1e-4;
27 27
  double Tolerance<double>::def_epsilon = 1e-10;
28 28
  long double Tolerance<long double>::def_epsilon = 1e-14;
29 29

	
30 30
#ifndef LEMON_ONLY_TEMPLATES
31 31
  const Invalid INVALID = Invalid();
32 32
#endif
33 33

	
34 34
} //namespace lemon

Changeset was too big and was cut off... Show full diff

0 comments (0 inline)