!
!
!
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1 | 1 |
LEMON code without an explicit copyright is covered by the following |
2 | 2 |
copyright/license. |
3 | 3 |
|
4 |
Copyright (C) 2003- |
|
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 |
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- |
|
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) |
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- |
|
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- |
|
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- |
|
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- |
|
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- |
|
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- |
|
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- |
|
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- |
|
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 |
} |
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- |
|
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; |
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- |
|
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 |
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- |
|
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 |
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- |
|
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 |
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- |
|
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 |
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- |
|
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 |
*/ |
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- |
|
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 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 |
*/ |
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- |
|
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 |
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- |
|
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 |
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- |
|
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 |
} |
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- |
|
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 |
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- |
|
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 |
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- |
|
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; |
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- |
|
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; |
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- |
|
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)) && \ |
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- |
|
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 |
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- |
|
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_BFS_H |
20 | 20 |
#define LEMON_BFS_H |
21 | 21 |
|
22 | 22 |
///\ingroup search |
23 | 23 |
///\file |
24 | 24 |
///\brief BFS algorithm. |
25 | 25 |
|
26 | 26 |
#include <lemon/list_graph.h> |
27 | 27 |
#include <lemon/bits/path_dump.h> |
28 | 28 |
#include <lemon/core.h> |
29 | 29 |
#include <lemon/error.h> |
30 | 30 |
#include <lemon/maps.h> |
31 | 31 |
#include <lemon/path.h> |
32 | 32 |
|
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
///Default traits class of Bfs class. |
36 | 36 |
|
37 | 37 |
///Default traits class of Bfs class. |
38 | 38 |
///\tparam GR Digraph type. |
39 | 39 |
template<class GR> |
40 | 40 |
struct BfsDefaultTraits |
41 | 41 |
{ |
42 | 42 |
///The type of the digraph the algorithm runs on. |
43 | 43 |
typedef GR Digraph; |
44 | 44 |
|
45 | 45 |
///\brief The type of the map that stores the predecessor |
46 | 46 |
///arcs of the shortest paths. |
47 | 47 |
/// |
48 | 48 |
///The type of the map that stores the predecessor |
49 | 49 |
///arcs of the shortest paths. |
50 | 50 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
51 | 51 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
52 | 52 |
///Instantiates a PredMap. |
53 | 53 |
|
54 | 54 |
///This function instantiates a PredMap. |
55 | 55 |
///\param g is the digraph, to which we would like to define the |
56 | 56 |
///PredMap. |
57 | 57 |
static PredMap *createPredMap(const Digraph &g) |
58 | 58 |
{ |
59 | 59 |
return new PredMap(g); |
60 | 60 |
} |
61 | 61 |
|
62 | 62 |
///The type of the map that indicates which nodes are processed. |
63 | 63 |
|
64 | 64 |
///The type of the map that indicates which nodes are processed. |
65 | 65 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
66 | 66 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
67 | 67 |
///Instantiates a ProcessedMap. |
68 | 68 |
|
69 | 69 |
///This function instantiates a ProcessedMap. |
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- |
|
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_BIN_HEAP_H |
20 | 20 |
#define LEMON_BIN_HEAP_H |
21 | 21 |
|
22 | 22 |
///\ingroup auxdat |
23 | 23 |
///\file |
24 | 24 |
///\brief Binary Heap implementation. |
25 | 25 |
|
26 | 26 |
#include <vector> |
27 | 27 |
#include <utility> |
28 | 28 |
#include <functional> |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
|
32 | 32 |
///\ingroup auxdat |
33 | 33 |
/// |
34 | 34 |
///\brief A Binary Heap implementation. |
35 | 35 |
/// |
36 | 36 |
///This class implements the \e binary \e heap data structure. A \e heap |
37 | 37 |
///is a data structure for storing items with specified values called \e |
38 | 38 |
///priorities in such a way that finding the item with minimum priority is |
39 | 39 |
///efficient. \c Compare specifies the ordering of the priorities. In a heap |
40 | 40 |
///one can change the priority of an item, add or erase an item, etc. |
41 | 41 |
/// |
42 | 42 |
///\tparam _Prio Type of the priority of the items. |
43 | 43 |
///\tparam _ItemIntMap A read and writable Item int map, used internally |
44 | 44 |
///to handle the cross references. |
45 | 45 |
///\tparam _Compare A class for the ordering of the priorities. The |
46 | 46 |
///default is \c std::less<_Prio>. |
47 | 47 |
/// |
48 | 48 |
///\sa FibHeap |
49 | 49 |
///\sa Dijkstra |
50 | 50 |
template <typename _Prio, typename _ItemIntMap, |
51 | 51 |
typename _Compare = std::less<_Prio> > |
52 | 52 |
class BinHeap { |
53 | 53 |
|
54 | 54 |
public: |
55 | 55 |
///\e |
56 | 56 |
typedef _ItemIntMap ItemIntMap; |
57 | 57 |
///\e |
58 | 58 |
typedef _Prio Prio; |
59 | 59 |
///\e |
60 | 60 |
typedef typename ItemIntMap::Key Item; |
61 | 61 |
///\e |
62 | 62 |
typedef std::pair<Item,Prio> Pair; |
63 | 63 |
///\e |
64 | 64 |
typedef _Compare Compare; |
65 | 65 |
|
66 | 66 |
/// \brief Type to represent the items states. |
67 | 67 |
/// |
68 | 68 |
/// Each Item element have a state associated to it. It may be "in heap", |
69 | 69 |
/// "pre heap" or "post heap". The latter two are indifferent from the |
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- |
|
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_BITS_ALTERATION_NOTIFIER_H |
20 | 20 |
#define LEMON_BITS_ALTERATION_NOTIFIER_H |
21 | 21 |
|
22 | 22 |
#include <vector> |
23 | 23 |
#include <list> |
24 | 24 |
|
25 | 25 |
#include <lemon/core.h> |
26 | 26 |
|
27 | 27 |
//\ingroup graphbits |
28 | 28 |
//\file |
29 | 29 |
//\brief Observer notifier for graph alteration observers. |
30 | 30 |
|
31 | 31 |
namespace lemon { |
32 | 32 |
|
33 | 33 |
// \ingroup graphbits |
34 | 34 |
// |
35 | 35 |
// \brief Notifier class to notify observes about alterations in |
36 | 36 |
// a container. |
37 | 37 |
// |
38 | 38 |
// The simple graphs can be refered as two containers: a node container |
39 | 39 |
// and an edge container. But they do not store values directly, they |
40 | 40 |
// are just key continars for more value containers, which are the |
41 | 41 |
// node and edge maps. |
42 | 42 |
// |
43 | 43 |
// The node and edge sets of the graphs can be changed as we add or erase |
44 | 44 |
// nodes and edges in the graph. LEMON would like to handle easily |
45 | 45 |
// that the node and edge maps should contain values for all nodes or |
46 | 46 |
// edges. If we want to check on every indicing if the map contains |
47 | 47 |
// the current indicing key that cause a drawback in the performance |
48 | 48 |
// in the library. We use another solution: we notify all maps about |
49 | 49 |
// an alteration in the graph, which cause only drawback on the |
50 | 50 |
// alteration of the graph. |
51 | 51 |
// |
52 | 52 |
// This class provides an interface to a node or edge container. |
53 | 53 |
// The first() and next() member functions make possible |
54 | 54 |
// to iterate on the keys of the container. |
55 | 55 |
// The id() function returns an integer id for each key. |
56 | 56 |
// The maxId() function gives back an upper bound of the ids. |
57 | 57 |
// |
58 | 58 |
// For the proper functonality of this class, we should notify it |
59 | 59 |
// about each alteration in the container. The alterations have four type: |
60 | 60 |
// add(), erase(), build() and clear(). The add() and |
61 | 61 |
// erase() signal that only one or few items added or erased to or |
62 | 62 |
// from the graph. If all items are erased from the graph or if a new graph |
63 | 63 |
// is built from an empty graph, then it can be signaled with the |
64 | 64 |
// clear() and build() members. Important rule that if we erase items |
65 | 65 |
// from graphs we should first signal the alteration and after that erase |
66 | 66 |
// them from the container, on the other way on item addition we should |
67 | 67 |
// first extend the container and just after that signal the alteration. |
68 | 68 |
// |
69 | 69 |
// The alteration can be observed with a class inherited from the |
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- |
|
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_BITS_ARRAY_MAP_H |
20 | 20 |
#define LEMON_BITS_ARRAY_MAP_H |
21 | 21 |
|
22 | 22 |
#include <memory> |
23 | 23 |
|
24 | 24 |
#include <lemon/bits/traits.h> |
25 | 25 |
#include <lemon/bits/alteration_notifier.h> |
26 | 26 |
#include <lemon/concept_check.h> |
27 | 27 |
#include <lemon/concepts/maps.h> |
28 | 28 |
|
29 | 29 |
// \ingroup graphbits |
30 | 30 |
// \file |
31 | 31 |
// \brief Graph map based on the array storage. |
32 | 32 |
|
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
// \ingroup graphbits |
36 | 36 |
// |
37 | 37 |
// \brief Graph map based on the array storage. |
38 | 38 |
// |
39 | 39 |
// The ArrayMap template class is graph map structure that automatically |
40 | 40 |
// updates the map when a key is added to or erased from the graph. |
41 | 41 |
// This map uses the allocators to implement the container functionality. |
42 | 42 |
// |
43 | 43 |
// The template parameters are the Graph, the current Item type and |
44 | 44 |
// the Value type of the map. |
45 | 45 |
template <typename _Graph, typename _Item, typename _Value> |
46 | 46 |
class ArrayMap |
47 | 47 |
: public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { |
48 | 48 |
public: |
49 | 49 |
// The graph type. |
50 | 50 |
typedef _Graph Graph; |
51 | 51 |
// The item type. |
52 | 52 |
typedef _Item Item; |
53 | 53 |
// The reference map tag. |
54 | 54 |
typedef True ReferenceMapTag; |
55 | 55 |
|
56 | 56 |
// The key type of the map. |
57 | 57 |
typedef _Item Key; |
58 | 58 |
// The value type of the map. |
59 | 59 |
typedef _Value Value; |
60 | 60 |
|
61 | 61 |
// The const reference type of the map. |
62 | 62 |
typedef const _Value& ConstReference; |
63 | 63 |
// The reference type of the map. |
64 | 64 |
typedef _Value& Reference; |
65 | 65 |
|
66 | 66 |
// The notifier type. |
67 | 67 |
typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier; |
68 | 68 |
|
69 | 69 |
// The MapBase of the Map which imlements the core regisitry function. |
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- |
|
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_BITS_BASE_EXTENDER_H |
20 | 20 |
#define LEMON_BITS_BASE_EXTENDER_H |
21 | 21 |
|
22 | 22 |
#include <lemon/core.h> |
23 | 23 |
#include <lemon/error.h> |
24 | 24 |
|
25 | 25 |
#include <lemon/bits/map_extender.h> |
26 | 26 |
#include <lemon/bits/default_map.h> |
27 | 27 |
|
28 | 28 |
#include <lemon/concept_check.h> |
29 | 29 |
#include <lemon/concepts/maps.h> |
30 | 30 |
|
31 | 31 |
//\ingroup digraphbits |
32 | 32 |
//\file |
33 | 33 |
//\brief Extenders for the graph types |
34 | 34 |
namespace lemon { |
35 | 35 |
|
36 | 36 |
// \ingroup digraphbits |
37 | 37 |
// |
38 | 38 |
// \brief BaseDigraph to BaseGraph extender |
39 | 39 |
template <typename Base> |
40 | 40 |
class UndirDigraphExtender : public Base { |
41 | 41 |
|
42 | 42 |
public: |
43 | 43 |
|
44 | 44 |
typedef Base Parent; |
45 | 45 |
typedef typename Parent::Arc Edge; |
46 | 46 |
typedef typename Parent::Node Node; |
47 | 47 |
|
48 | 48 |
typedef True UndirectedTag; |
49 | 49 |
|
50 | 50 |
class Arc : public Edge { |
51 | 51 |
friend class UndirDigraphExtender; |
52 | 52 |
|
53 | 53 |
protected: |
54 | 54 |
bool forward; |
55 | 55 |
|
56 | 56 |
Arc(const Edge &ue, bool _forward) : |
57 | 57 |
Edge(ue), forward(_forward) {} |
58 | 58 |
|
59 | 59 |
public: |
60 | 60 |
Arc() {} |
61 | 61 |
|
62 | 62 |
// Invalid arc constructor |
63 | 63 |
Arc(Invalid i) : Edge(i), forward(true) {} |
64 | 64 |
|
65 | 65 |
bool operator==(const Arc &that) const { |
66 | 66 |
return forward==that.forward && Edge(*this)==Edge(that); |
67 | 67 |
} |
68 | 68 |
bool operator!=(const Arc &that) const { |
69 | 69 |
return forward!=that.forward || Edge(*this)!=Edge(that); |
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- |
|
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_BEZIER_H |
20 | 20 |
#define LEMON_BEZIER_H |
21 | 21 |
|
22 | 22 |
//\ingroup misc |
23 | 23 |
//\file |
24 | 24 |
//\brief Classes to compute with Bezier curves. |
25 | 25 |
// |
26 | 26 |
//Up to now this file is used internally by \ref graph_to_eps.h |
27 | 27 |
|
28 | 28 |
#include<lemon/dim2.h> |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
namespace dim2 { |
32 | 32 |
|
33 | 33 |
class BezierBase { |
34 | 34 |
public: |
35 | 35 |
typedef lemon::dim2::Point<double> Point; |
36 | 36 |
protected: |
37 | 37 |
static Point conv(Point x,Point y,double t) {return (1-t)*x+t*y;} |
38 | 38 |
}; |
39 | 39 |
|
40 | 40 |
class Bezier1 : public BezierBase |
41 | 41 |
{ |
42 | 42 |
public: |
43 | 43 |
Point p1,p2; |
44 | 44 |
|
45 | 45 |
Bezier1() {} |
46 | 46 |
Bezier1(Point _p1, Point _p2) :p1(_p1), p2(_p2) {} |
47 | 47 |
|
48 | 48 |
Point operator()(double t) const |
49 | 49 |
{ |
50 | 50 |
// return conv(conv(p1,p2,t),conv(p2,p3,t),t); |
51 | 51 |
return conv(p1,p2,t); |
52 | 52 |
} |
53 | 53 |
Bezier1 before(double t) const |
54 | 54 |
{ |
55 | 55 |
return Bezier1(p1,conv(p1,p2,t)); |
56 | 56 |
} |
57 | 57 |
|
58 | 58 |
Bezier1 after(double t) const |
59 | 59 |
{ |
60 | 60 |
return Bezier1(conv(p1,p2,t),p2); |
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
Bezier1 revert() const { return Bezier1(p2,p1);} |
64 | 64 |
Bezier1 operator()(double a,double b) const { return before(b).after(a/b); } |
65 | 65 |
Point grad() const { return p2-p1; } |
66 | 66 |
Point norm() const { return rot90(p2-p1); } |
67 | 67 |
Point grad(double) const { return grad(); } |
68 | 68 |
Point norm(double t) const { return rot90(grad(t)); } |
69 | 69 |
}; |
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- |
|
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_BITS_DEFAULT_MAP_H |
20 | 20 |
#define LEMON_BITS_DEFAULT_MAP_H |
21 | 21 |
|
22 | 22 |
#include <lemon/bits/array_map.h> |
23 | 23 |
#include <lemon/bits/vector_map.h> |
24 | 24 |
//#include <lemon/bits/debug_map.h> |
25 | 25 |
|
26 | 26 |
//\ingroup graphbits |
27 | 27 |
//\file |
28 | 28 |
//\brief Graph maps that construct and destruct their elements dynamically. |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
|
32 | 32 |
|
33 | 33 |
//#ifndef LEMON_USE_DEBUG_MAP |
34 | 34 |
|
35 | 35 |
template <typename _Graph, typename _Item, typename _Value> |
36 | 36 |
struct DefaultMapSelector { |
37 | 37 |
typedef ArrayMap<_Graph, _Item, _Value> Map; |
38 | 38 |
}; |
39 | 39 |
|
40 | 40 |
// bool |
41 | 41 |
template <typename _Graph, typename _Item> |
42 | 42 |
struct DefaultMapSelector<_Graph, _Item, bool> { |
43 | 43 |
typedef VectorMap<_Graph, _Item, bool> Map; |
44 | 44 |
}; |
45 | 45 |
|
46 | 46 |
// char |
47 | 47 |
template <typename _Graph, typename _Item> |
48 | 48 |
struct DefaultMapSelector<_Graph, _Item, char> { |
49 | 49 |
typedef VectorMap<_Graph, _Item, char> Map; |
50 | 50 |
}; |
51 | 51 |
|
52 | 52 |
template <typename _Graph, typename _Item> |
53 | 53 |
struct DefaultMapSelector<_Graph, _Item, signed char> { |
54 | 54 |
typedef VectorMap<_Graph, _Item, signed char> Map; |
55 | 55 |
}; |
56 | 56 |
|
57 | 57 |
template <typename _Graph, typename _Item> |
58 | 58 |
struct DefaultMapSelector<_Graph, _Item, unsigned char> { |
59 | 59 |
typedef VectorMap<_Graph, _Item, unsigned char> Map; |
60 | 60 |
}; |
61 | 61 |
|
62 | 62 |
|
63 | 63 |
// int |
64 | 64 |
template <typename _Graph, typename _Item> |
65 | 65 |
struct DefaultMapSelector<_Graph, _Item, signed int> { |
66 | 66 |
typedef VectorMap<_Graph, _Item, signed int> Map; |
67 | 67 |
}; |
68 | 68 |
|
69 | 69 |
template <typename _Graph, typename _Item> |
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- |
|
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 |
// This file contains a modified version of the enable_if library from BOOST. |
20 | 20 |
// See the appropriate copyright notice below. |
21 | 21 |
|
22 | 22 |
// Boost enable_if library |
23 | 23 |
|
24 | 24 |
// Copyright 2003 (c) The Trustees of Indiana University. |
25 | 25 |
|
26 | 26 |
// Use, modification, and distribution is subject to the Boost Software |
27 | 27 |
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
28 | 28 |
// http://www.boost.org/LICENSE_1_0.txt) |
29 | 29 |
|
30 | 30 |
// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) |
31 | 31 |
// Jeremiah Willcock (jewillco at osl.iu.edu) |
32 | 32 |
// Andrew Lumsdaine (lums at osl.iu.edu) |
33 | 33 |
|
34 | 34 |
|
35 | 35 |
#ifndef LEMON_BITS_ENABLE_IF_H |
36 | 36 |
#define LEMON_BITS_ENABLE_IF_H |
37 | 37 |
|
38 | 38 |
//\file |
39 | 39 |
//\brief Miscellaneous basic utilities |
40 | 40 |
|
41 | 41 |
namespace lemon |
42 | 42 |
{ |
43 | 43 |
|
44 | 44 |
// Basic type for defining "tags". A "YES" condition for \c enable_if. |
45 | 45 |
|
46 | 46 |
// Basic type for defining "tags". A "YES" condition for \c enable_if. |
47 | 47 |
// |
48 | 48 |
//\sa False |
49 | 49 |
struct True { |
50 | 50 |
//\e |
51 | 51 |
static const bool value = true; |
52 | 52 |
}; |
53 | 53 |
|
54 | 54 |
// Basic type for defining "tags". A "NO" condition for \c enable_if. |
55 | 55 |
|
56 | 56 |
// Basic type for defining "tags". A "NO" condition for \c enable_if. |
57 | 57 |
// |
58 | 58 |
//\sa True |
59 | 59 |
struct False { |
60 | 60 |
//\e |
61 | 61 |
static const bool value = false; |
62 | 62 |
}; |
63 | 63 |
|
64 | 64 |
|
65 | 65 |
|
66 | 66 |
template <typename T> |
67 | 67 |
struct Wrap { |
68 | 68 |
const T &value; |
69 | 69 |
Wrap(const T &t) : value(t) {} |
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- |
|
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_BITS_GRAPH_ADAPTOR_EXTENDER_H |
20 | 20 |
#define LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H |
21 | 21 |
|
22 | 22 |
#include <lemon/core.h> |
23 | 23 |
#include <lemon/error.h> |
24 | 24 |
|
25 | 25 |
#include <lemon/bits/default_map.h> |
26 | 26 |
|
27 | 27 |
namespace lemon { |
28 | 28 |
|
29 | 29 |
template <typename _Digraph> |
30 | 30 |
class DigraphAdaptorExtender : public _Digraph { |
31 | 31 |
public: |
32 | 32 |
|
33 | 33 |
typedef _Digraph Parent; |
34 | 34 |
typedef _Digraph Digraph; |
35 | 35 |
typedef DigraphAdaptorExtender Adaptor; |
36 | 36 |
|
37 | 37 |
// Base extensions |
38 | 38 |
|
39 | 39 |
typedef typename Parent::Node Node; |
40 | 40 |
typedef typename Parent::Arc Arc; |
41 | 41 |
|
42 | 42 |
int maxId(Node) const { |
43 | 43 |
return Parent::maxNodeId(); |
44 | 44 |
} |
45 | 45 |
|
46 | 46 |
int maxId(Arc) const { |
47 | 47 |
return Parent::maxArcId(); |
48 | 48 |
} |
49 | 49 |
|
50 | 50 |
Node fromId(int id, Node) const { |
51 | 51 |
return Parent::nodeFromId(id); |
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
Arc fromId(int id, Arc) const { |
55 | 55 |
return Parent::arcFromId(id); |
56 | 56 |
} |
57 | 57 |
|
58 | 58 |
Node oppositeNode(const Node &n, const Arc &e) const { |
59 | 59 |
if (n == Parent::source(e)) |
60 | 60 |
return Parent::target(e); |
61 | 61 |
else if(n==Parent::target(e)) |
62 | 62 |
return Parent::source(e); |
63 | 63 |
else |
64 | 64 |
return INVALID; |
65 | 65 |
} |
66 | 66 |
|
67 | 67 |
class NodeIt : public Node { |
68 | 68 |
const Adaptor* _adaptor; |
69 | 69 |
public: |
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- |
|
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_BITS_GRAPH_EXTENDER_H |
20 | 20 |
#define LEMON_BITS_GRAPH_EXTENDER_H |
21 | 21 |
|
22 | 22 |
#include <lemon/core.h> |
23 | 23 |
|
24 | 24 |
#include <lemon/bits/map_extender.h> |
25 | 25 |
#include <lemon/bits/default_map.h> |
26 | 26 |
|
27 | 27 |
#include <lemon/concept_check.h> |
28 | 28 |
#include <lemon/concepts/maps.h> |
29 | 29 |
|
30 | 30 |
//\ingroup graphbits |
31 | 31 |
//\file |
32 | 32 |
//\brief Extenders for the graph types |
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
// \ingroup graphbits |
36 | 36 |
// |
37 | 37 |
// \brief Extender for the digraph implementations |
38 | 38 |
template <typename Base> |
39 | 39 |
class DigraphExtender : public Base { |
40 | 40 |
public: |
41 | 41 |
|
42 | 42 |
typedef Base Parent; |
43 | 43 |
typedef DigraphExtender Digraph; |
44 | 44 |
|
45 | 45 |
// Base extensions |
46 | 46 |
|
47 | 47 |
typedef typename Parent::Node Node; |
48 | 48 |
typedef typename Parent::Arc Arc; |
49 | 49 |
|
50 | 50 |
int maxId(Node) const { |
51 | 51 |
return Parent::maxNodeId(); |
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
int maxId(Arc) const { |
55 | 55 |
return Parent::maxArcId(); |
56 | 56 |
} |
57 | 57 |
|
58 | 58 |
Node fromId(int id, Node) const { |
59 | 59 |
return Parent::nodeFromId(id); |
60 | 60 |
} |
61 | 61 |
|
62 | 62 |
Arc fromId(int id, Arc) const { |
63 | 63 |
return Parent::arcFromId(id); |
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
Node oppositeNode(const Node &node, const Arc &arc) const { |
67 | 67 |
if (node == Parent::source(arc)) |
68 | 68 |
return Parent::target(arc); |
69 | 69 |
else if(node == Parent::target(arc)) |
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- |
|
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_BITS_MAP_EXTENDER_H |
20 | 20 |
#define LEMON_BITS_MAP_EXTENDER_H |
21 | 21 |
|
22 | 22 |
#include <iterator> |
23 | 23 |
|
24 | 24 |
#include <lemon/bits/traits.h> |
25 | 25 |
|
26 | 26 |
#include <lemon/concept_check.h> |
27 | 27 |
#include <lemon/concepts/maps.h> |
28 | 28 |
|
29 | 29 |
//\file |
30 | 30 |
//\brief Extenders for iterable maps. |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
|
34 | 34 |
// \ingroup graphbits |
35 | 35 |
// |
36 | 36 |
// \brief Extender for maps |
37 | 37 |
template <typename _Map> |
38 | 38 |
class MapExtender : public _Map { |
39 | 39 |
public: |
40 | 40 |
|
41 | 41 |
typedef _Map Parent; |
42 | 42 |
typedef MapExtender Map; |
43 | 43 |
|
44 | 44 |
|
45 | 45 |
typedef typename Parent::Graph Graph; |
46 | 46 |
typedef typename Parent::Key Item; |
47 | 47 |
|
48 | 48 |
typedef typename Parent::Key Key; |
49 | 49 |
typedef typename Parent::Value Value; |
50 | 50 |
|
51 | 51 |
class MapIt; |
52 | 52 |
class ConstMapIt; |
53 | 53 |
|
54 | 54 |
friend class MapIt; |
55 | 55 |
friend class ConstMapIt; |
56 | 56 |
|
57 | 57 |
public: |
58 | 58 |
|
59 | 59 |
MapExtender(const Graph& graph) |
60 | 60 |
: Parent(graph) {} |
61 | 61 |
|
62 | 62 |
MapExtender(const Graph& graph, const Value& value) |
63 | 63 |
: Parent(graph, value) {} |
64 | 64 |
|
65 | 65 |
private: |
66 | 66 |
MapExtender& operator=(const MapExtender& cmap) { |
67 | 67 |
return operator=<MapExtender>(cmap); |
68 | 68 |
} |
69 | 69 |
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- |
|
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_BITS_PRED_MAP_PATH_H |
20 | 20 |
#define LEMON_BITS_PRED_MAP_PATH_H |
21 | 21 |
|
22 | 22 |
namespace lemon { |
23 | 23 |
|
24 | 24 |
template <typename _Digraph, typename _PredMap> |
25 | 25 |
class PredMapPath { |
26 | 26 |
public: |
27 | 27 |
typedef True RevPathTag; |
28 | 28 |
|
29 | 29 |
typedef _Digraph Digraph; |
30 | 30 |
typedef typename Digraph::Arc Arc; |
31 | 31 |
typedef _PredMap PredMap; |
32 | 32 |
|
33 | 33 |
PredMapPath(const Digraph& _digraph, const PredMap& _predMap, |
34 | 34 |
typename Digraph::Node _target) |
35 | 35 |
: digraph(_digraph), predMap(_predMap), target(_target) {} |
36 | 36 |
|
37 | 37 |
int length() const { |
38 | 38 |
int len = 0; |
39 | 39 |
typename Digraph::Node node = target; |
40 | 40 |
typename Digraph::Arc arc; |
41 | 41 |
while ((arc = predMap[node]) != INVALID) { |
42 | 42 |
node = digraph.source(arc); |
43 | 43 |
++len; |
44 | 44 |
} |
45 | 45 |
return len; |
46 | 46 |
} |
47 | 47 |
|
48 | 48 |
bool empty() const { |
49 | 49 |
return predMap[target] != INVALID; |
50 | 50 |
} |
51 | 51 |
|
52 | 52 |
class RevArcIt { |
53 | 53 |
public: |
54 | 54 |
RevArcIt() {} |
55 | 55 |
RevArcIt(Invalid) : path(0), current(INVALID) {} |
56 | 56 |
RevArcIt(const PredMapPath& _path) |
57 | 57 |
: path(&_path), current(_path.target) { |
58 | 58 |
if (path->predMap[current] == INVALID) current = INVALID; |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
operator const typename Digraph::Arc() const { |
62 | 62 |
return path->predMap[current]; |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
RevArcIt& operator++() { |
66 | 66 |
current = path->digraph.source(path->predMap[current]); |
67 | 67 |
if (path->predMap[current] == INVALID) current = INVALID; |
68 | 68 |
return *this; |
69 | 69 |
} |
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- |
|
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_BITS_TRAITS_H |
20 | 20 |
#define LEMON_BITS_TRAITS_H |
21 | 21 |
|
22 | 22 |
//\file |
23 | 23 |
//\brief Traits for graphs and maps |
24 | 24 |
// |
25 | 25 |
|
26 | 26 |
#include <lemon/bits/enable_if.h> |
27 | 27 |
|
28 | 28 |
namespace lemon { |
29 | 29 |
|
30 | 30 |
struct InvalidType {}; |
31 | 31 |
|
32 | 32 |
template <typename _Graph, typename _Item> |
33 | 33 |
class ItemSetTraits {}; |
34 | 34 |
|
35 | 35 |
|
36 | 36 |
template <typename Graph, typename Enable = void> |
37 | 37 |
struct NodeNotifierIndicator { |
38 | 38 |
typedef InvalidType Type; |
39 | 39 |
}; |
40 | 40 |
template <typename Graph> |
41 | 41 |
struct NodeNotifierIndicator< |
42 | 42 |
Graph, |
43 | 43 |
typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type |
44 | 44 |
> { |
45 | 45 |
typedef typename Graph::NodeNotifier Type; |
46 | 46 |
}; |
47 | 47 |
|
48 | 48 |
template <typename _Graph> |
49 | 49 |
class ItemSetTraits<_Graph, typename _Graph::Node> { |
50 | 50 |
public: |
51 | 51 |
|
52 | 52 |
typedef _Graph Graph; |
53 | 53 |
|
54 | 54 |
typedef typename Graph::Node Item; |
55 | 55 |
typedef typename Graph::NodeIt ItemIt; |
56 | 56 |
|
57 | 57 |
typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier; |
58 | 58 |
|
59 | 59 |
template <typename _Value> |
60 | 60 |
class Map : public Graph::template NodeMap<_Value> { |
61 | 61 |
public: |
62 | 62 |
typedef typename Graph::template NodeMap<_Value> Parent; |
63 | 63 |
typedef typename Graph::template NodeMap<_Value> Type; |
64 | 64 |
typedef typename Parent::Value Value; |
65 | 65 |
|
66 | 66 |
Map(const Graph& _digraph) : Parent(_digraph) {} |
67 | 67 |
Map(const Graph& _digraph, const Value& _value) |
68 | 68 |
: Parent(_digraph, _value) {} |
69 | 69 |
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- |
|
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_BITS_VARIANT_H |
20 | 20 |
#define LEMON_BITS_VARIANT_H |
21 | 21 |
|
22 | 22 |
#include <lemon/assert.h> |
23 | 23 |
|
24 | 24 |
// \file |
25 | 25 |
// \brief Variant types |
26 | 26 |
|
27 | 27 |
namespace lemon { |
28 | 28 |
|
29 | 29 |
namespace _variant_bits { |
30 | 30 |
|
31 | 31 |
template <int left, int right> |
32 | 32 |
struct CTMax { |
33 | 33 |
static const int value = left < right ? right : left; |
34 | 34 |
}; |
35 | 35 |
|
36 | 36 |
} |
37 | 37 |
|
38 | 38 |
|
39 | 39 |
// \brief Simple Variant type for two types |
40 | 40 |
// |
41 | 41 |
// Simple Variant type for two types. The Variant type is a type-safe |
42 | 42 |
// union. C++ has strong limitations for using unions, for |
43 | 43 |
// example you cannot store a type with non-default constructor or |
44 | 44 |
// destructor in a union. This class always knowns the current |
45 | 45 |
// state of the variant and it cares for the proper construction |
46 | 46 |
// and destruction. |
47 | 47 |
template <typename _First, typename _Second> |
48 | 48 |
class BiVariant { |
49 | 49 |
public: |
50 | 50 |
|
51 | 51 |
// \brief The \c First type. |
52 | 52 |
typedef _First First; |
53 | 53 |
// \brief The \c Second type. |
54 | 54 |
typedef _Second Second; |
55 | 55 |
|
56 | 56 |
// \brief Constructor |
57 | 57 |
// |
58 | 58 |
// This constructor initalizes to the default value of the \c First |
59 | 59 |
// type. |
60 | 60 |
BiVariant() { |
61 | 61 |
flag = true; |
62 | 62 |
new(reinterpret_cast<First*>(data)) First(); |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
// \brief Constructor |
66 | 66 |
// |
67 | 67 |
// This constructor initalizes to the given value of the \c First |
68 | 68 |
// type. |
69 | 69 |
BiVariant(const First& f) { |
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- |
|
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_BITS_VECTOR_MAP_H |
20 | 20 |
#define LEMON_BITS_VECTOR_MAP_H |
21 | 21 |
|
22 | 22 |
#include <vector> |
23 | 23 |
#include <algorithm> |
24 | 24 |
|
25 | 25 |
#include <lemon/core.h> |
26 | 26 |
#include <lemon/bits/alteration_notifier.h> |
27 | 27 |
|
28 | 28 |
#include <lemon/concept_check.h> |
29 | 29 |
#include <lemon/concepts/maps.h> |
30 | 30 |
|
31 | 31 |
//\ingroup graphbits |
32 | 32 |
// |
33 | 33 |
//\file |
34 | 34 |
//\brief Vector based graph maps. |
35 | 35 |
namespace lemon { |
36 | 36 |
|
37 | 37 |
// \ingroup graphbits |
38 | 38 |
// |
39 | 39 |
// \brief Graph map based on the std::vector storage. |
40 | 40 |
// |
41 | 41 |
// The VectorMap template class is graph map structure that automatically |
42 | 42 |
// updates the map when a key is added to or erased from the graph. |
43 | 43 |
// This map type uses std::vector to store the values. |
44 | 44 |
// |
45 | 45 |
// \tparam _Graph The graph this map is attached to. |
46 | 46 |
// \tparam _Item The item type of the graph items. |
47 | 47 |
// \tparam _Value The value type of the map. |
48 | 48 |
template <typename _Graph, typename _Item, typename _Value> |
49 | 49 |
class VectorMap |
50 | 50 |
: public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { |
51 | 51 |
private: |
52 | 52 |
|
53 | 53 |
// The container type of the map. |
54 | 54 |
typedef std::vector<_Value> Container; |
55 | 55 |
|
56 | 56 |
public: |
57 | 57 |
|
58 | 58 |
// The graph type of the map. |
59 | 59 |
typedef _Graph Graph; |
60 | 60 |
// The item type of the map. |
61 | 61 |
typedef _Item Item; |
62 | 62 |
// The reference map tag. |
63 | 63 |
typedef True ReferenceMapTag; |
64 | 64 |
|
65 | 65 |
// The key type of the map. |
66 | 66 |
typedef _Item Key; |
67 | 67 |
// The value type of the map. |
68 | 68 |
typedef _Value Value; |
69 | 69 |
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- |
|
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_CIRCULATION_H |
20 | 20 |
#define LEMON_CIRCULATION_H |
21 | 21 |
|
22 | 22 |
#include <lemon/tolerance.h> |
23 | 23 |
#include <lemon/elevator.h> |
24 | 24 |
|
25 | 25 |
///\ingroup max_flow |
26 | 26 |
///\file |
27 | 27 |
///\brief Push-relabel algorithm for finding a feasible circulation. |
28 | 28 |
/// |
29 | 29 |
namespace lemon { |
30 | 30 |
|
31 | 31 |
/// \brief Default traits class of Circulation class. |
32 | 32 |
/// |
33 | 33 |
/// Default traits class of Circulation class. |
34 | 34 |
/// \tparam _Diraph Digraph type. |
35 | 35 |
/// \tparam _LCapMap Lower bound capacity map type. |
36 | 36 |
/// \tparam _UCapMap Upper bound capacity map type. |
37 | 37 |
/// \tparam _DeltaMap Delta map type. |
38 | 38 |
template <typename _Diraph, typename _LCapMap, |
39 | 39 |
typename _UCapMap, typename _DeltaMap> |
40 | 40 |
struct CirculationDefaultTraits { |
41 | 41 |
|
42 | 42 |
/// \brief The type of the digraph the algorithm runs on. |
43 | 43 |
typedef _Diraph Digraph; |
44 | 44 |
|
45 | 45 |
/// \brief The type of the map that stores the circulation lower |
46 | 46 |
/// bound. |
47 | 47 |
/// |
48 | 48 |
/// The type of the map that stores the circulation lower bound. |
49 | 49 |
/// It must meet the \ref concepts::ReadMap "ReadMap" concept. |
50 | 50 |
typedef _LCapMap LCapMap; |
51 | 51 |
|
52 | 52 |
/// \brief The type of the map that stores the circulation upper |
53 | 53 |
/// bound. |
54 | 54 |
/// |
55 | 55 |
/// The type of the map that stores the circulation upper bound. |
56 | 56 |
/// It must meet the \ref concepts::ReadMap "ReadMap" concept. |
57 | 57 |
typedef _UCapMap UCapMap; |
58 | 58 |
|
59 | 59 |
/// \brief The type of the map that stores the lower bound for |
60 | 60 |
/// the supply of the nodes. |
61 | 61 |
/// |
62 | 62 |
/// The type of the map that stores the lower bound for the supply |
63 | 63 |
/// of the nodes. It must meet the \ref concepts::ReadMap "ReadMap" |
64 | 64 |
/// concept. |
65 | 65 |
typedef _DeltaMap DeltaMap; |
66 | 66 |
|
67 | 67 |
/// \brief The type of the flow values. |
68 | 68 |
typedef typename DeltaMap::Value Value; |
69 | 69 |
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- |
|
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 Color constants |
21 | 21 |
|
22 | 22 |
#include<lemon/color.h> |
23 | 23 |
|
24 | 24 |
namespace lemon { |
25 | 25 |
|
26 | 26 |
const Color WHITE(1,1,1); |
27 | 27 |
|
28 | 28 |
const Color BLACK(0,0,0); |
29 | 29 |
const Color RED(1,0,0); |
30 | 30 |
const Color GREEN(0,1,0); |
31 | 31 |
const Color BLUE(0,0,1); |
32 | 32 |
const Color YELLOW(1,1,0); |
33 | 33 |
const Color MAGENTA(1,0,1); |
34 | 34 |
const Color CYAN(0,1,1); |
35 | 35 |
|
36 | 36 |
const Color GREY(0,0,0); |
37 | 37 |
const Color DARK_RED(.5,0,0); |
38 | 38 |
const Color DARK_GREEN(0,.5,0); |
39 | 39 |
const Color DARK_BLUE(0,0,.5); |
40 | 40 |
const Color DARK_YELLOW(.5,.5,0); |
41 | 41 |
const Color DARK_MAGENTA(.5,0,.5); |
42 | 42 |
const Color DARK_CYAN(0,.5,.5); |
43 | 43 |
|
44 | 44 |
} //namespace lemon |
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- |
|
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_COLOR_H |
20 | 20 |
#define LEMON_COLOR_H |
21 | 21 |
|
22 | 22 |
#include<vector> |
23 | 23 |
#include<lemon/math.h> |
24 | 24 |
#include<lemon/maps.h> |
25 | 25 |
|
26 | 26 |
|
27 | 27 |
///\ingroup misc |
28 | 28 |
///\file |
29 | 29 |
///\brief Tools to manage RGB colors. |
30 | 30 |
|
31 | 31 |
namespace lemon { |
32 | 32 |
|
33 | 33 |
|
34 | 34 |
/// \addtogroup misc |
35 | 35 |
/// @{ |
36 | 36 |
|
37 | 37 |
///Data structure representing RGB colors. |
38 | 38 |
|
39 | 39 |
///Data structure representing RGB colors. |
40 | 40 |
class Color |
41 | 41 |
{ |
42 | 42 |
double _r,_g,_b; |
43 | 43 |
public: |
44 | 44 |
///Default constructor |
45 | 45 |
Color() {} |
46 | 46 |
///Constructor |
47 | 47 |
Color(double r,double g,double b) :_r(r),_g(g),_b(b) {}; |
48 | 48 |
///Set the red component |
49 | 49 |
double & red() {return _r;} |
50 | 50 |
///Return the red component |
51 | 51 |
const double & red() const {return _r;} |
52 | 52 |
///Set the green component |
53 | 53 |
double & green() {return _g;} |
54 | 54 |
///Return the green component |
55 | 55 |
const double & green() const {return _g;} |
56 | 56 |
///Set the blue component |
57 | 57 |
double & blue() {return _b;} |
58 | 58 |
///Return the blue component |
59 | 59 |
const double & blue() const {return _b;} |
60 | 60 |
///Set the color components |
61 | 61 |
void set(double r,double g,double b) { _r=r;_g=g;_b=b; }; |
62 | 62 |
}; |
63 | 63 |
|
64 | 64 |
/// White color constant |
65 | 65 |
extern const Color WHITE; |
66 | 66 |
/// Black color constant |
67 | 67 |
extern const Color BLACK; |
68 | 68 |
/// Red color constant |
69 | 69 |
extern const Color RED; |
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- |
|
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 contents of this file was inspired by the concept checking |
20 | 20 |
// utility of the BOOST library (http://www.boost.org). |
21 | 21 |
|
22 | 22 |
///\file |
23 | 23 |
///\brief Basic utilities for concept checking. |
24 | 24 |
/// |
25 | 25 |
|
26 | 26 |
#ifndef LEMON_CONCEPT_CHECK_H |
27 | 27 |
#define LEMON_CONCEPT_CHECK_H |
28 | 28 |
|
29 | 29 |
namespace lemon { |
30 | 30 |
|
31 | 31 |
/* |
32 | 32 |
"inline" is used for ignore_unused_variable_warning() |
33 | 33 |
and function_requires() to make sure there is no |
34 | 34 |
overtarget with g++. |
35 | 35 |
*/ |
36 | 36 |
|
37 | 37 |
template <class T> inline void ignore_unused_variable_warning(const T&) { } |
38 | 38 |
|
39 | 39 |
///\e |
40 | 40 |
template <class Concept> |
41 | 41 |
inline void function_requires() |
42 | 42 |
{ |
43 | 43 |
#if !defined(NDEBUG) |
44 | 44 |
void (Concept::*x)() = & Concept::constraints; |
45 | 45 |
ignore_unused_variable_warning(x); |
46 | 46 |
#endif |
47 | 47 |
} |
48 | 48 |
|
49 | 49 |
///\e |
50 | 50 |
template <typename Concept, typename Type> |
51 | 51 |
inline void checkConcept() { |
52 | 52 |
#if !defined(NDEBUG) |
53 | 53 |
typedef typename Concept::template Constraints<Type> ConceptCheck; |
54 | 54 |
void (ConceptCheck::*x)() = & ConceptCheck::constraints; |
55 | 55 |
ignore_unused_variable_warning(x); |
56 | 56 |
#endif |
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
} // namespace lemon |
60 | 60 |
|
61 | 61 |
#endif // LEMON_CONCEPT_CHECK_H |
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- |
|
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_CONCEPT_DIGRAPH_H |
20 | 20 |
#define LEMON_CONCEPT_DIGRAPH_H |
21 | 21 |
|
22 | 22 |
///\ingroup graph_concepts |
23 | 23 |
///\file |
24 | 24 |
///\brief The concept of directed graphs. |
25 | 25 |
|
26 | 26 |
#include <lemon/core.h> |
27 | 27 |
#include <lemon/concepts/maps.h> |
28 | 28 |
#include <lemon/concept_check.h> |
29 | 29 |
#include <lemon/concepts/graph_components.h> |
30 | 30 |
|
31 | 31 |
namespace lemon { |
32 | 32 |
namespace concepts { |
33 | 33 |
|
34 | 34 |
/// \ingroup graph_concepts |
35 | 35 |
/// |
36 | 36 |
/// \brief Class describing the concept of directed graphs. |
37 | 37 |
/// |
38 | 38 |
/// This class describes the \ref concept "concept" of the |
39 | 39 |
/// immutable directed digraphs. |
40 | 40 |
/// |
41 | 41 |
/// Note that actual digraph implementation like @ref ListDigraph or |
42 | 42 |
/// @ref SmartDigraph may have several additional functionality. |
43 | 43 |
/// |
44 | 44 |
/// \sa concept |
45 | 45 |
class Digraph { |
46 | 46 |
private: |
47 | 47 |
///Digraphs are \e not copy constructible. Use DigraphCopy() instead. |
48 | 48 |
|
49 | 49 |
///Digraphs are \e not copy constructible. Use DigraphCopy() instead. |
50 | 50 |
/// |
51 | 51 |
Digraph(const Digraph &) {}; |
52 | 52 |
///\brief Assignment of \ref Digraph "Digraph"s to another ones are |
53 | 53 |
///\e not allowed. Use DigraphCopy() instead. |
54 | 54 |
|
55 | 55 |
///Assignment of \ref Digraph "Digraph"s to another ones are |
56 | 56 |
///\e not allowed. Use DigraphCopy() instead. |
57 | 57 |
|
58 | 58 |
void operator=(const Digraph &) {} |
59 | 59 |
public: |
60 | 60 |
///\e |
61 | 61 |
|
62 | 62 |
/// Defalult constructor. |
63 | 63 |
|
64 | 64 |
/// Defalult constructor. |
65 | 65 |
/// |
66 | 66 |
Digraph() { } |
67 | 67 |
/// Class for identifying a node of the digraph |
68 | 68 |
|
69 | 69 |
/// This class identifies a node of the digraph. It also serves |
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- |
|
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 graph_concepts |
20 | 20 |
///\file |
21 | 21 |
///\brief The concept of Undirected Graphs. |
22 | 22 |
|
23 | 23 |
#ifndef LEMON_CONCEPT_GRAPH_H |
24 | 24 |
#define LEMON_CONCEPT_GRAPH_H |
25 | 25 |
|
26 | 26 |
#include <lemon/concepts/graph_components.h> |
27 | 27 |
#include <lemon/concepts/graph.h> |
28 | 28 |
#include <lemon/core.h> |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
namespace concepts { |
32 | 32 |
|
33 | 33 |
/// \ingroup graph_concepts |
34 | 34 |
/// |
35 | 35 |
/// \brief Class describing the concept of Undirected Graphs. |
36 | 36 |
/// |
37 | 37 |
/// This class describes the common interface of all Undirected |
38 | 38 |
/// Graphs. |
39 | 39 |
/// |
40 | 40 |
/// As all concept describing classes it provides only interface |
41 | 41 |
/// without any sensible implementation. So any algorithm for |
42 | 42 |
/// undirected graph should compile with this class, but it will not |
43 | 43 |
/// run properly, of course. |
44 | 44 |
/// |
45 | 45 |
/// The LEMON undirected graphs also fulfill the concept of |
46 | 46 |
/// directed graphs (\ref lemon::concepts::Digraph "Digraph |
47 | 47 |
/// Concept"). Each edges can be seen as two opposite |
48 | 48 |
/// directed arc and consequently the undirected graph can be |
49 | 49 |
/// seen as the direceted graph of these directed arcs. The |
50 | 50 |
/// Graph has the Edge inner class for the edges and |
51 | 51 |
/// the Arc type for the directed arcs. The Arc type is |
52 | 52 |
/// convertible to Edge or inherited from it so from a directed |
53 | 53 |
/// arc we can get the represented edge. |
54 | 54 |
/// |
55 | 55 |
/// In the sense of the LEMON each edge has a default |
56 | 56 |
/// direction (it should be in every computer implementation, |
57 | 57 |
/// because the order of edge's nodes defines an |
58 | 58 |
/// orientation). With the default orientation we can define that |
59 | 59 |
/// the directed arc is forward or backward directed. With the \c |
60 | 60 |
/// direction() and \c direct() function we can get the direction |
61 | 61 |
/// of the directed arc and we can direct an edge. |
62 | 62 |
/// |
63 | 63 |
/// The EdgeIt is an iterator for the edges. We can use |
64 | 64 |
/// the EdgeMap to map values for the edges. The InArcIt and |
65 | 65 |
/// OutArcIt iterates on the same edges but with opposite |
66 | 66 |
/// direction. The IncEdgeIt iterates also on the same edges |
67 | 67 |
/// as the OutArcIt and InArcIt but it is not convertible to Arc just |
68 | 68 |
/// to Edge. |
69 | 69 |
class Graph { |
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- |
|
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 graph_concepts |
20 | 20 |
///\file |
21 | 21 |
///\brief The concept of graph components. |
22 | 22 |
|
23 | 23 |
|
24 | 24 |
#ifndef LEMON_CONCEPT_GRAPH_COMPONENTS_H |
25 | 25 |
#define LEMON_CONCEPT_GRAPH_COMPONENTS_H |
26 | 26 |
|
27 | 27 |
#include <lemon/core.h> |
28 | 28 |
#include <lemon/concepts/maps.h> |
29 | 29 |
|
30 | 30 |
#include <lemon/bits/alteration_notifier.h> |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
namespace concepts { |
34 | 34 |
|
35 | 35 |
/// \brief Skeleton class for graph Node and Arc types |
36 | 36 |
/// |
37 | 37 |
/// This class describes the interface of Node and Arc (and Edge |
38 | 38 |
/// in undirected graphs) subtypes of graph types. |
39 | 39 |
/// |
40 | 40 |
/// \note This class is a template class so that we can use it to |
41 | 41 |
/// create graph skeleton classes. The reason for this is than Node |
42 | 42 |
/// and Arc types should \em not derive from the same base class. |
43 | 43 |
/// For Node you should instantiate it with character 'n' and for Arc |
44 | 44 |
/// with 'a'. |
45 | 45 |
|
46 | 46 |
#ifndef DOXYGEN |
47 | 47 |
template <char _selector = '0'> |
48 | 48 |
#endif |
49 | 49 |
class GraphItem { |
50 | 50 |
public: |
51 | 51 |
/// \brief Default constructor. |
52 | 52 |
/// |
53 | 53 |
/// \warning The default constructor is not required to set |
54 | 54 |
/// the item to some well-defined value. So you should consider it |
55 | 55 |
/// as uninitialized. |
56 | 56 |
GraphItem() {} |
57 | 57 |
/// \brief Copy constructor. |
58 | 58 |
/// |
59 | 59 |
/// Copy constructor. |
60 | 60 |
/// |
61 | 61 |
GraphItem(const GraphItem &) {} |
62 | 62 |
/// \brief Invalid constructor \& conversion. |
63 | 63 |
/// |
64 | 64 |
/// This constructor initializes the item to be invalid. |
65 | 65 |
/// \sa Invalid for more details. |
66 | 66 |
GraphItem(Invalid) {} |
67 | 67 |
/// \brief Assign operator for nodes. |
68 | 68 |
/// |
69 | 69 |
/// The nodes are assignable. |
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- |
|
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 concept |
20 | 20 |
///\file |
21 | 21 |
///\brief The concept of heaps. |
22 | 22 |
|
23 | 23 |
#ifndef LEMON_CONCEPT_HEAP_H |
24 | 24 |
#define LEMON_CONCEPT_HEAP_H |
25 | 25 |
|
26 | 26 |
#include <lemon/core.h> |
27 | 27 |
|
28 | 28 |
namespace lemon { |
29 | 29 |
|
30 | 30 |
namespace concepts { |
31 | 31 |
|
32 | 32 |
/// \addtogroup concept |
33 | 33 |
/// @{ |
34 | 34 |
|
35 | 35 |
/// \brief The heap concept. |
36 | 36 |
/// |
37 | 37 |
/// Concept class describing the main interface of heaps. |
38 | 38 |
template <typename Priority, typename ItemIntMap> |
39 | 39 |
class Heap { |
40 | 40 |
public: |
41 | 41 |
|
42 | 42 |
/// Type of the items stored in the heap. |
43 | 43 |
typedef typename ItemIntMap::Key Item; |
44 | 44 |
|
45 | 45 |
/// Type of the priorities. |
46 | 46 |
typedef Priority Prio; |
47 | 47 |
|
48 | 48 |
/// \brief Type to represent the states of the items. |
49 | 49 |
/// |
50 | 50 |
/// Each item has a state associated to it. It can be "in heap", |
51 | 51 |
/// "pre heap" or "post heap". The later two are indifferent |
52 | 52 |
/// from the point of view of the heap, but may be useful for |
53 | 53 |
/// the user. |
54 | 54 |
/// |
55 | 55 |
/// The \c ItemIntMap must be initialized in such a way, that it |
56 | 56 |
/// assigns \c PRE_HEAP (<tt>-1</tt>) to every item. |
57 | 57 |
enum State { |
58 | 58 |
IN_HEAP = 0, |
59 | 59 |
PRE_HEAP = -1, |
60 | 60 |
POST_HEAP = -2 |
61 | 61 |
}; |
62 | 62 |
|
63 | 63 |
/// \brief The constructor. |
64 | 64 |
/// |
65 | 65 |
/// The constructor. |
66 | 66 |
/// \param map A map that assigns \c int values to keys of type |
67 | 67 |
/// \c Item. It is used internally by the heap implementations to |
68 | 68 |
/// handle the cross references. The assigned value must be |
69 | 69 |
/// \c PRE_HEAP (<tt>-1</tt>) for every item. |
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- |
|
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_CONCEPT_MAPS_H |
20 | 20 |
#define LEMON_CONCEPT_MAPS_H |
21 | 21 |
|
22 | 22 |
#include <lemon/core.h> |
23 | 23 |
#include <lemon/concept_check.h> |
24 | 24 |
|
25 | 25 |
///\ingroup map_concepts |
26 | 26 |
///\file |
27 | 27 |
///\brief The concept of maps. |
28 | 28 |
|
29 | 29 |
namespace lemon { |
30 | 30 |
|
31 | 31 |
namespace concepts { |
32 | 32 |
|
33 | 33 |
/// \addtogroup map_concepts |
34 | 34 |
/// @{ |
35 | 35 |
|
36 | 36 |
/// Readable map concept |
37 | 37 |
|
38 | 38 |
/// Readable map concept. |
39 | 39 |
/// |
40 | 40 |
template<typename K, typename T> |
41 | 41 |
class ReadMap |
42 | 42 |
{ |
43 | 43 |
public: |
44 | 44 |
/// The key type of the map. |
45 | 45 |
typedef K Key; |
46 | 46 |
/// \brief The value type of the map. |
47 | 47 |
/// (The type of objects associated with the keys). |
48 | 48 |
typedef T Value; |
49 | 49 |
|
50 | 50 |
/// Returns the value associated with the given key. |
51 | 51 |
Value operator[](const Key &) const { |
52 | 52 |
return *static_cast<Value *>(0); |
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
template<typename _ReadMap> |
56 | 56 |
struct Constraints { |
57 | 57 |
void constraints() { |
58 | 58 |
Value val = m[key]; |
59 | 59 |
val = m[key]; |
60 | 60 |
typename _ReadMap::Value own_val = m[own_key]; |
61 | 61 |
own_val = m[own_key]; |
62 | 62 |
|
63 | 63 |
ignore_unused_variable_warning(key); |
64 | 64 |
ignore_unused_variable_warning(val); |
65 | 65 |
ignore_unused_variable_warning(own_key); |
66 | 66 |
ignore_unused_variable_warning(own_val); |
67 | 67 |
} |
68 | 68 |
const Key& key; |
69 | 69 |
const typename _ReadMap::Key& own_key; |
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- |
|
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 concept |
20 | 20 |
///\file |
21 | 21 |
///\brief Classes for representing paths in digraphs. |
22 | 22 |
/// |
23 | 23 |
|
24 | 24 |
#ifndef LEMON_CONCEPT_PATH_H |
25 | 25 |
#define LEMON_CONCEPT_PATH_H |
26 | 26 |
|
27 | 27 |
#include <lemon/core.h> |
28 | 28 |
#include <lemon/concept_check.h> |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
namespace concepts { |
32 | 32 |
|
33 | 33 |
/// \addtogroup concept |
34 | 34 |
/// @{ |
35 | 35 |
|
36 | 36 |
/// \brief A skeleton structure for representing directed paths in |
37 | 37 |
/// a digraph. |
38 | 38 |
/// |
39 | 39 |
/// A skeleton structure for representing directed paths in a |
40 | 40 |
/// digraph. |
41 | 41 |
/// \tparam _Digraph The digraph type in which the path is. |
42 | 42 |
/// |
43 | 43 |
/// In a sense, the path can be treated as a list of arcs. The |
44 | 44 |
/// lemon path type stores just this list. As a consequence it |
45 | 45 |
/// cannot enumerate the nodes in the path and the zero length |
46 | 46 |
/// paths cannot store the source. |
47 | 47 |
/// |
48 | 48 |
template <typename _Digraph> |
49 | 49 |
class Path { |
50 | 50 |
public: |
51 | 51 |
|
52 | 52 |
/// Type of the underlying digraph. |
53 | 53 |
typedef _Digraph Digraph; |
54 | 54 |
/// Arc type of the underlying digraph. |
55 | 55 |
typedef typename Digraph::Arc Arc; |
56 | 56 |
|
57 | 57 |
class ArcIt; |
58 | 58 |
|
59 | 59 |
/// \brief Default constructor |
60 | 60 |
Path() {} |
61 | 61 |
|
62 | 62 |
/// \brief Template constructor |
63 | 63 |
template <typename CPath> |
64 | 64 |
Path(const CPath& cpath) {} |
65 | 65 |
|
66 | 66 |
/// \brief Template assigment |
67 | 67 |
template <typename CPath> |
68 | 68 |
Path& operator=(const CPath& cpath) { |
69 | 69 |
ignore_unused_variable_warning(cpath); |
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- |
|
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_CONNECTIVITY_H |
20 | 20 |
#define LEMON_CONNECTIVITY_H |
21 | 21 |
|
22 | 22 |
#include <lemon/dfs.h> |
23 | 23 |
#include <lemon/bfs.h> |
24 | 24 |
#include <lemon/core.h> |
25 | 25 |
#include <lemon/maps.h> |
26 | 26 |
#include <lemon/adaptors.h> |
27 | 27 |
|
28 | 28 |
#include <lemon/concepts/digraph.h> |
29 | 29 |
#include <lemon/concepts/graph.h> |
30 | 30 |
#include <lemon/concept_check.h> |
31 | 31 |
|
32 | 32 |
#include <stack> |
33 | 33 |
#include <functional> |
34 | 34 |
|
35 | 35 |
/// \ingroup connectivity |
36 | 36 |
/// \file |
37 | 37 |
/// \brief Connectivity algorithms |
38 | 38 |
/// |
39 | 39 |
/// Connectivity algorithms |
40 | 40 |
|
41 | 41 |
namespace lemon { |
42 | 42 |
|
43 | 43 |
/// \ingroup connectivity |
44 | 44 |
/// |
45 | 45 |
/// \brief Check whether the given undirected graph is connected. |
46 | 46 |
/// |
47 | 47 |
/// Check whether the given undirected graph is connected. |
48 | 48 |
/// \param graph The undirected graph. |
49 | 49 |
/// \return %True when there is path between any two nodes in the graph. |
50 | 50 |
/// \note By definition, the empty graph is connected. |
51 | 51 |
template <typename Graph> |
52 | 52 |
bool connected(const Graph& graph) { |
53 | 53 |
checkConcept<concepts::Graph, Graph>(); |
54 | 54 |
typedef typename Graph::NodeIt NodeIt; |
55 | 55 |
if (NodeIt(graph) == INVALID) return true; |
56 | 56 |
Dfs<Graph> dfs(graph); |
57 | 57 |
dfs.run(NodeIt(graph)); |
58 | 58 |
for (NodeIt it(graph); it != INVALID; ++it) { |
59 | 59 |
if (!dfs.reached(it)) { |
60 | 60 |
return false; |
61 | 61 |
} |
62 | 62 |
} |
63 | 63 |
return true; |
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
/// \ingroup connectivity |
67 | 67 |
/// |
68 | 68 |
/// \brief Count the number of connected components of an undirected graph |
69 | 69 |
/// |
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- |
|
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_CORE_H |
20 | 20 |
#define LEMON_CORE_H |
21 | 21 |
|
22 | 22 |
#include <vector> |
23 | 23 |
#include <algorithm> |
24 | 24 |
|
25 | 25 |
#include <lemon/bits/enable_if.h> |
26 | 26 |
#include <lemon/bits/traits.h> |
27 | 27 |
#include <lemon/assert.h> |
28 | 28 |
|
29 | 29 |
///\file |
30 | 30 |
///\brief LEMON core utilities. |
31 | 31 |
/// |
32 | 32 |
///This header file contains core utilities for LEMON. |
33 | 33 |
///It is automatically included by all graph types, therefore it usually |
34 | 34 |
///do not have to be included directly. |
35 | 35 |
|
36 | 36 |
namespace lemon { |
37 | 37 |
|
38 | 38 |
/// \brief Dummy type to make it easier to create invalid iterators. |
39 | 39 |
/// |
40 | 40 |
/// Dummy type to make it easier to create invalid iterators. |
41 | 41 |
/// See \ref INVALID for the usage. |
42 | 42 |
struct Invalid { |
43 | 43 |
public: |
44 | 44 |
bool operator==(Invalid) { return true; } |
45 | 45 |
bool operator!=(Invalid) { return false; } |
46 | 46 |
bool operator< (Invalid) { return false; } |
47 | 47 |
}; |
48 | 48 |
|
49 | 49 |
/// \brief Invalid iterators. |
50 | 50 |
/// |
51 | 51 |
/// \ref Invalid is a global type that converts to each iterator |
52 | 52 |
/// in such a way that the value of the target iterator will be invalid. |
53 | 53 |
#ifdef LEMON_ONLY_TEMPLATES |
54 | 54 |
const Invalid INVALID = Invalid(); |
55 | 55 |
#else |
56 | 56 |
extern const Invalid INVALID; |
57 | 57 |
#endif |
58 | 58 |
|
59 | 59 |
/// \addtogroup gutils |
60 | 60 |
/// @{ |
61 | 61 |
|
62 | 62 |
///Create convenience typedefs for the digraph types and iterators |
63 | 63 |
|
64 | 64 |
///This \c \#define creates convenient type definitions for the following |
65 | 65 |
///types of \c Digraph: \c Node, \c NodeIt, \c Arc, \c ArcIt, \c InArcIt, |
66 | 66 |
///\c OutArcIt, \c BoolNodeMap, \c IntNodeMap, \c DoubleNodeMap, |
67 | 67 |
///\c BoolArcMap, \c IntArcMap, \c DoubleArcMap. |
68 | 68 |
/// |
69 | 69 |
///\note If the graph type is a dependent type, ie. the graph type depend |
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- |
|
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_COUNTER_H |
20 | 20 |
#define LEMON_COUNTER_H |
21 | 21 |
|
22 | 22 |
#include <string> |
23 | 23 |
#include <iostream> |
24 | 24 |
|
25 | 25 |
///\ingroup timecount |
26 | 26 |
///\file |
27 | 27 |
///\brief Tools for counting steps and events |
28 | 28 |
|
29 | 29 |
namespace lemon |
30 | 30 |
{ |
31 | 31 |
|
32 | 32 |
template<class P> class _NoSubCounter; |
33 | 33 |
|
34 | 34 |
template<class P> |
35 | 35 |
class _SubCounter |
36 | 36 |
{ |
37 | 37 |
P &_parent; |
38 | 38 |
std::string _title; |
39 | 39 |
std::ostream &_os; |
40 | 40 |
int count; |
41 | 41 |
public: |
42 | 42 |
|
43 | 43 |
typedef _SubCounter<_SubCounter<P> > SubCounter; |
44 | 44 |
typedef _NoSubCounter<_SubCounter<P> > NoSubCounter; |
45 | 45 |
|
46 | 46 |
_SubCounter(P &parent) |
47 | 47 |
: _parent(parent), _title(), _os(std::cerr), count(0) {} |
48 | 48 |
_SubCounter(P &parent,std::string title,std::ostream &os=std::cerr) |
49 | 49 |
: _parent(parent), _title(title), _os(os), count(0) {} |
50 | 50 |
_SubCounter(P &parent,const char *title,std::ostream &os=std::cerr) |
51 | 51 |
: _parent(parent), _title(title), _os(os), count(0) {} |
52 | 52 |
~_SubCounter() { |
53 | 53 |
_os << _title << count <<std::endl; |
54 | 54 |
_parent+=count; |
55 | 55 |
} |
56 | 56 |
_SubCounter &operator++() { count++; return *this;} |
57 | 57 |
int operator++(int) { return count++; } |
58 | 58 |
_SubCounter &operator--() { count--; return *this;} |
59 | 59 |
int operator--(int) { return count--; } |
60 | 60 |
_SubCounter &operator+=(int c) { count+=c; return *this;} |
61 | 61 |
_SubCounter &operator-=(int c) { count-=c; return *this;} |
62 | 62 |
operator int() {return count;} |
63 | 63 |
}; |
64 | 64 |
|
65 | 65 |
template<class P> |
66 | 66 |
class _NoSubCounter |
67 | 67 |
{ |
68 | 68 |
P &_parent; |
69 | 69 |
public: |
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- |
|
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_DFS_H |
20 | 20 |
#define LEMON_DFS_H |
21 | 21 |
|
22 | 22 |
///\ingroup search |
23 | 23 |
///\file |
24 | 24 |
///\brief DFS algorithm. |
25 | 25 |
|
26 | 26 |
#include <lemon/list_graph.h> |
27 | 27 |
#include <lemon/bits/path_dump.h> |
28 | 28 |
#include <lemon/core.h> |
29 | 29 |
#include <lemon/error.h> |
30 | 30 |
#include <lemon/maps.h> |
31 | 31 |
#include <lemon/path.h> |
32 | 32 |
|
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
///Default traits class of Dfs class. |
36 | 36 |
|
37 | 37 |
///Default traits class of Dfs class. |
38 | 38 |
///\tparam GR Digraph type. |
39 | 39 |
template<class GR> |
40 | 40 |
struct DfsDefaultTraits |
41 | 41 |
{ |
42 | 42 |
///The type of the digraph the algorithm runs on. |
43 | 43 |
typedef GR Digraph; |
44 | 44 |
|
45 | 45 |
///\brief The type of the map that stores the predecessor |
46 | 46 |
///arcs of the %DFS paths. |
47 | 47 |
/// |
48 | 48 |
///The type of the map that stores the predecessor |
49 | 49 |
///arcs of the %DFS paths. |
50 | 50 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
51 | 51 |
typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap; |
52 | 52 |
///Instantiates a PredMap. |
53 | 53 |
|
54 | 54 |
///This function instantiates a PredMap. |
55 | 55 |
///\param g is the digraph, to which we would like to define the |
56 | 56 |
///PredMap. |
57 | 57 |
static PredMap *createPredMap(const Digraph &g) |
58 | 58 |
{ |
59 | 59 |
return new PredMap(g); |
60 | 60 |
} |
61 | 61 |
|
62 | 62 |
///The type of the map that indicates which nodes are processed. |
63 | 63 |
|
64 | 64 |
///The type of the map that indicates which nodes are processed. |
65 | 65 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
66 | 66 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
67 | 67 |
///Instantiates a ProcessedMap. |
68 | 68 |
|
69 | 69 |
///This function instantiates a ProcessedMap. |
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- |
|
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_DIJKSTRA_H |
20 | 20 |
#define LEMON_DIJKSTRA_H |
21 | 21 |
|
22 | 22 |
///\ingroup shortest_path |
23 | 23 |
///\file |
24 | 24 |
///\brief Dijkstra algorithm. |
25 | 25 |
|
26 | 26 |
#include <limits> |
27 | 27 |
#include <lemon/list_graph.h> |
28 | 28 |
#include <lemon/bin_heap.h> |
29 | 29 |
#include <lemon/bits/path_dump.h> |
30 | 30 |
#include <lemon/core.h> |
31 | 31 |
#include <lemon/error.h> |
32 | 32 |
#include <lemon/maps.h> |
33 | 33 |
#include <lemon/path.h> |
34 | 34 |
|
35 | 35 |
namespace lemon { |
36 | 36 |
|
37 | 37 |
/// \brief Default operation traits for the Dijkstra algorithm class. |
38 | 38 |
/// |
39 | 39 |
/// This operation traits class defines all computational operations and |
40 | 40 |
/// constants which are used in the Dijkstra algorithm. |
41 | 41 |
template <typename Value> |
42 | 42 |
struct DijkstraDefaultOperationTraits { |
43 | 43 |
/// \brief Gives back the zero value of the type. |
44 | 44 |
static Value zero() { |
45 | 45 |
return static_cast<Value>(0); |
46 | 46 |
} |
47 | 47 |
/// \brief Gives back the sum of the given two elements. |
48 | 48 |
static Value plus(const Value& left, const Value& right) { |
49 | 49 |
return left + right; |
50 | 50 |
} |
51 | 51 |
/// \brief Gives back true only if the first value is less than the second. |
52 | 52 |
static bool less(const Value& left, const Value& right) { |
53 | 53 |
return left < right; |
54 | 54 |
} |
55 | 55 |
}; |
56 | 56 |
|
57 | 57 |
///Default traits class of Dijkstra class. |
58 | 58 |
|
59 | 59 |
///Default traits class of Dijkstra class. |
60 | 60 |
///\tparam GR The type of the digraph. |
61 | 61 |
///\tparam LM The type of the length map. |
62 | 62 |
template<class GR, class LM> |
63 | 63 |
struct DijkstraDefaultTraits |
64 | 64 |
{ |
65 | 65 |
///The type of the digraph the algorithm runs on. |
66 | 66 |
typedef GR Digraph; |
67 | 67 |
|
68 | 68 |
///The type of the map that stores the arc lengths. |
69 | 69 |
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- |
|
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_DIM2_H |
20 | 20 |
#define LEMON_DIM2_H |
21 | 21 |
|
22 | 22 |
#include <iostream> |
23 | 23 |
|
24 | 24 |
///\ingroup misc |
25 | 25 |
///\file |
26 | 26 |
///\brief A simple two dimensional vector and a bounding box implementation |
27 | 27 |
/// |
28 | 28 |
/// The class \ref lemon::dim2::Point "dim2::Point" implements |
29 | 29 |
/// a two dimensional vector with the usual operations. |
30 | 30 |
/// |
31 | 31 |
/// The class \ref lemon::dim2::Box "dim2::Box" can be used to determine |
32 | 32 |
/// the rectangular bounding box of a set of |
33 | 33 |
/// \ref lemon::dim2::Point "dim2::Point"'s. |
34 | 34 |
|
35 | 35 |
namespace lemon { |
36 | 36 |
|
37 | 37 |
///Tools for handling two dimensional coordinates |
38 | 38 |
|
39 | 39 |
///This namespace is a storage of several |
40 | 40 |
///tools for handling two dimensional coordinates |
41 | 41 |
namespace dim2 { |
42 | 42 |
|
43 | 43 |
/// \addtogroup misc |
44 | 44 |
/// @{ |
45 | 45 |
|
46 | 46 |
/// Two dimensional vector (plain vector) |
47 | 47 |
|
48 | 48 |
/// A simple two dimensional vector (plain vector) implementation |
49 | 49 |
/// with the usual vector operations. |
50 | 50 |
template<typename T> |
51 | 51 |
class Point { |
52 | 52 |
|
53 | 53 |
public: |
54 | 54 |
|
55 | 55 |
typedef T Value; |
56 | 56 |
|
57 | 57 |
///First coordinate |
58 | 58 |
T x; |
59 | 59 |
///Second coordinate |
60 | 60 |
T y; |
61 | 61 |
|
62 | 62 |
///Default constructor |
63 | 63 |
Point() {} |
64 | 64 |
|
65 | 65 |
///Construct an instance from coordinates |
66 | 66 |
Point(T a, T b) : x(a), y(b) { } |
67 | 67 |
|
68 | 68 |
///Returns the dimension of the vector (i.e. returns 2). |
69 | 69 |
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- |
|
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_DIMACS_H |
20 | 20 |
#define LEMON_DIMACS_H |
21 | 21 |
|
22 | 22 |
#include <iostream> |
23 | 23 |
#include <string> |
24 | 24 |
#include <vector> |
25 | 25 |
#include <lemon/maps.h> |
26 | 26 |
#include <lemon/error.h> |
27 | 27 |
|
28 | 28 |
/// \ingroup dimacs_group |
29 | 29 |
/// \file |
30 | 30 |
/// \brief DIMACS file format reader. |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
|
34 | 34 |
/// \addtogroup dimacs_group |
35 | 35 |
/// @{ |
36 | 36 |
|
37 | 37 |
/// DIMACS file type descriptor. |
38 | 38 |
struct DimacsDescriptor |
39 | 39 |
{ |
40 | 40 |
///File type enum |
41 | 41 |
enum Type |
42 | 42 |
{ |
43 | 43 |
NONE, MIN, MAX, SP, MAT |
44 | 44 |
}; |
45 | 45 |
///The file type |
46 | 46 |
Type type; |
47 | 47 |
///The number of nodes in the graph |
48 | 48 |
int nodeNum; |
49 | 49 |
///The number of edges in the graph |
50 | 50 |
int edgeNum; |
51 | 51 |
int lineShift; |
52 | 52 |
/// Constructor. Sets the type to NONE. |
53 | 53 |
DimacsDescriptor() : type(NONE) {} |
54 | 54 |
}; |
55 | 55 |
|
56 | 56 |
///Discover the type of a DIMACS file |
57 | 57 |
|
58 | 58 |
///It starts seeking the begining of the file for the problem type |
59 | 59 |
///and size info. The found data is returned in a special struct |
60 | 60 |
///that can be evaluated and passed to the appropriate reader |
61 | 61 |
///function. |
62 | 62 |
DimacsDescriptor dimacsType(std::istream& is) |
63 | 63 |
{ |
64 | 64 |
DimacsDescriptor r; |
65 | 65 |
std::string problem,str; |
66 | 66 |
char c; |
67 | 67 |
r.lineShift=0; |
68 | 68 |
while (is >> c) |
69 | 69 |
switch(c) |
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- |
|
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_ELEVATOR_H |
20 | 20 |
#define LEMON_ELEVATOR_H |
21 | 21 |
|
22 | 22 |
///\ingroup auxdat |
23 | 23 |
///\file |
24 | 24 |
///\brief Elevator class |
25 | 25 |
/// |
26 | 26 |
///Elevator class implements an efficient data structure |
27 | 27 |
///for labeling items in push-relabel type algorithms. |
28 | 28 |
/// |
29 | 29 |
|
30 | 30 |
#include <lemon/bits/traits.h> |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
|
34 | 34 |
///Class for handling "labels" in push-relabel type algorithms. |
35 | 35 |
|
36 | 36 |
///A class for handling "labels" in push-relabel type algorithms. |
37 | 37 |
/// |
38 | 38 |
///\ingroup auxdat |
39 | 39 |
///Using this class you can assign "labels" (nonnegative integer numbers) |
40 | 40 |
///to the edges or nodes of a graph, manipulate and query them through |
41 | 41 |
///operations typically arising in "push-relabel" type algorithms. |
42 | 42 |
/// |
43 | 43 |
///Each item is either \em active or not, and you can also choose a |
44 | 44 |
///highest level active item. |
45 | 45 |
/// |
46 | 46 |
///\sa LinkedElevator |
47 | 47 |
/// |
48 | 48 |
///\param Graph Type of the underlying graph. |
49 | 49 |
///\param Item Type of the items the data is assigned to (Graph::Node, |
50 | 50 |
///Graph::Arc, Graph::Edge). |
51 | 51 |
template<class Graph, class Item> |
52 | 52 |
class Elevator |
53 | 53 |
{ |
54 | 54 |
public: |
55 | 55 |
|
56 | 56 |
typedef Item Key; |
57 | 57 |
typedef int Value; |
58 | 58 |
|
59 | 59 |
private: |
60 | 60 |
|
61 | 61 |
typedef Item *Vit; |
62 | 62 |
typedef typename ItemSetTraits<Graph,Item>::template Map<Vit>::Type VitMap; |
63 | 63 |
typedef typename ItemSetTraits<Graph,Item>::template Map<int>::Type IntMap; |
64 | 64 |
|
65 | 65 |
const Graph &_g; |
66 | 66 |
int _max_level; |
67 | 67 |
int _item_num; |
68 | 68 |
VitMap _where; |
69 | 69 |
IntMap _level; |
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- |
|
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_ERROR_H |
20 | 20 |
#define LEMON_ERROR_H |
21 | 21 |
|
22 | 22 |
/// \ingroup exceptions |
23 | 23 |
/// \file |
24 | 24 |
/// \brief Basic exception classes and error handling. |
25 | 25 |
|
26 | 26 |
#include <exception> |
27 | 27 |
#include <string> |
28 | 28 |
#include <sstream> |
29 | 29 |
#include <iostream> |
30 | 30 |
#include <cstdlib> |
31 | 31 |
#include <memory> |
32 | 32 |
|
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
/// \addtogroup exceptions |
36 | 36 |
/// @{ |
37 | 37 |
|
38 | 38 |
/// \brief Generic exception class. |
39 | 39 |
/// |
40 | 40 |
/// Base class for exceptions used in LEMON. |
41 | 41 |
/// |
42 | 42 |
class Exception : public std::exception { |
43 | 43 |
public: |
44 | 44 |
///Constructor |
45 | 45 |
Exception() throw() {} |
46 | 46 |
///Virtual destructor |
47 | 47 |
virtual ~Exception() throw() {} |
48 | 48 |
///A short description of the exception |
49 | 49 |
virtual const char* what() const throw() { |
50 | 50 |
return "lemon::Exception"; |
51 | 51 |
} |
52 | 52 |
}; |
53 | 53 |
|
54 | 54 |
/// \brief Input-Output error |
55 | 55 |
/// |
56 | 56 |
/// This exception is thrown when a file operation cannot be |
57 | 57 |
/// succeeded. |
58 | 58 |
class IoError : public Exception { |
59 | 59 |
protected: |
60 | 60 |
std::string _message; |
61 | 61 |
std::string _file; |
62 | 62 |
|
63 | 63 |
mutable std::string _what; |
64 | 64 |
public: |
65 | 65 |
|
66 | 66 |
/// Copy constructor |
67 | 67 |
IoError(const IoError &error) throw() : Exception() { |
68 | 68 |
message(error._message); |
69 | 69 |
file(error._file); |
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- |
|
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_FULL_GRAPH_H |
20 | 20 |
#define LEMON_FULL_GRAPH_H |
21 | 21 |
|
22 | 22 |
#include <lemon/core.h> |
23 | 23 |
#include <lemon/bits/graph_extender.h> |
24 | 24 |
|
25 | 25 |
///\ingroup graphs |
26 | 26 |
///\file |
27 | 27 |
///\brief FullGraph and FullDigraph classes. |
28 | 28 |
|
29 | 29 |
namespace lemon { |
30 | 30 |
|
31 | 31 |
class FullDigraphBase { |
32 | 32 |
public: |
33 | 33 |
|
34 | 34 |
typedef FullDigraphBase Graph; |
35 | 35 |
|
36 | 36 |
class Node; |
37 | 37 |
class Arc; |
38 | 38 |
|
39 | 39 |
protected: |
40 | 40 |
|
41 | 41 |
int _node_num; |
42 | 42 |
int _arc_num; |
43 | 43 |
|
44 | 44 |
FullDigraphBase() {} |
45 | 45 |
|
46 | 46 |
void construct(int n) { _node_num = n; _arc_num = n * n; } |
47 | 47 |
|
48 | 48 |
public: |
49 | 49 |
|
50 | 50 |
typedef True NodeNumTag; |
51 | 51 |
typedef True ArcNumTag; |
52 | 52 |
|
53 | 53 |
Node operator()(int ix) const { return Node(ix); } |
54 | 54 |
int index(const Node& node) const { return node._id; } |
55 | 55 |
|
56 | 56 |
Arc arc(const Node& s, const Node& t) const { |
57 | 57 |
return Arc(s._id * _node_num + t._id); |
58 | 58 |
} |
59 | 59 |
|
60 | 60 |
int nodeNum() const { return _node_num; } |
61 | 61 |
int arcNum() const { return _arc_num; } |
62 | 62 |
|
63 | 63 |
int maxNodeId() const { return _node_num - 1; } |
64 | 64 |
int maxArcId() const { return _arc_num - 1; } |
65 | 65 |
|
66 | 66 |
Node source(Arc arc) const { return arc._id / _node_num; } |
67 | 67 |
Node target(Arc arc) const { return arc._id % _node_num; } |
68 | 68 |
|
69 | 69 |
static int id(Node node) { return node._id; } |
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- |
|
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_GRAPH_TO_EPS_H |
20 | 20 |
#define LEMON_GRAPH_TO_EPS_H |
21 | 21 |
|
22 | 22 |
#include<iostream> |
23 | 23 |
#include<fstream> |
24 | 24 |
#include<sstream> |
25 | 25 |
#include<algorithm> |
26 | 26 |
#include<vector> |
27 | 27 |
|
28 | 28 |
#ifndef WIN32 |
29 | 29 |
#include<sys/time.h> |
30 | 30 |
#include<ctime> |
31 | 31 |
#else |
32 | 32 |
#define WIN32_LEAN_AND_MEAN |
33 | 33 |
#define NOMINMAX |
34 | 34 |
#include<windows.h> |
35 | 35 |
#endif |
36 | 36 |
|
37 | 37 |
#include<lemon/math.h> |
38 | 38 |
#include<lemon/core.h> |
39 | 39 |
#include<lemon/dim2.h> |
40 | 40 |
#include<lemon/maps.h> |
41 | 41 |
#include<lemon/color.h> |
42 | 42 |
#include<lemon/bits/bezier.h> |
43 | 43 |
#include<lemon/error.h> |
44 | 44 |
|
45 | 45 |
|
46 | 46 |
///\ingroup eps_io |
47 | 47 |
///\file |
48 | 48 |
///\brief A well configurable tool for visualizing graphs |
49 | 49 |
|
50 | 50 |
namespace lemon { |
51 | 51 |
|
52 | 52 |
namespace _graph_to_eps_bits { |
53 | 53 |
template<class MT> |
54 | 54 |
class _NegY { |
55 | 55 |
public: |
56 | 56 |
typedef typename MT::Key Key; |
57 | 57 |
typedef typename MT::Value Value; |
58 | 58 |
const MT ↦ |
59 | 59 |
int yscale; |
60 | 60 |
_NegY(const MT &m,bool b) : map(m), yscale(1-b*2) {} |
61 | 61 |
Value operator[](Key n) { return Value(map[n].x,map[n].y*yscale);} |
62 | 62 |
}; |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
///Default traits class of GraphToEps |
66 | 66 |
|
67 | 67 |
///Default traits class of \ref GraphToEps. |
68 | 68 |
/// |
69 | 69 |
///\c G is the type of the underlying graph. |
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- |
|
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 GRID_GRAPH_H |
20 | 20 |
#define GRID_GRAPH_H |
21 | 21 |
|
22 | 22 |
#include <lemon/core.h> |
23 | 23 |
#include <lemon/bits/graph_extender.h> |
24 | 24 |
#include <lemon/dim2.h> |
25 | 25 |
#include <lemon/assert.h> |
26 | 26 |
|
27 | 27 |
///\ingroup graphs |
28 | 28 |
///\file |
29 | 29 |
///\brief GridGraph class. |
30 | 30 |
|
31 | 31 |
namespace lemon { |
32 | 32 |
|
33 | 33 |
class GridGraphBase { |
34 | 34 |
|
35 | 35 |
public: |
36 | 36 |
|
37 | 37 |
typedef GridGraphBase Graph; |
38 | 38 |
|
39 | 39 |
class Node; |
40 | 40 |
class Edge; |
41 | 41 |
class Arc; |
42 | 42 |
|
43 | 43 |
public: |
44 | 44 |
|
45 | 45 |
GridGraphBase() {} |
46 | 46 |
|
47 | 47 |
protected: |
48 | 48 |
|
49 | 49 |
void construct(int width, int height) { |
50 | 50 |
_width = width; _height = height; |
51 | 51 |
_node_num = width * height; |
52 | 52 |
_edge_num = 2 * _node_num - width - height; |
53 | 53 |
_edge_limit = _node_num - _width; |
54 | 54 |
} |
55 | 55 |
|
56 | 56 |
public: |
57 | 57 |
|
58 | 58 |
Node operator()(int i, int j) const { |
59 | 59 |
LEMON_DEBUG(0 <= i && i < _width && |
60 | 60 |
0 <= j && j < _height, "Index out of range"); |
61 | 61 |
return Node(i + j * _width); |
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
int col(Node n) const { |
65 | 65 |
return n._id % _width; |
66 | 66 |
} |
67 | 67 |
|
68 | 68 |
int row(Node n) const { |
69 | 69 |
return n._id / _width; |
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- |
|
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_HAO_ORLIN_H |
20 | 20 |
#define LEMON_HAO_ORLIN_H |
21 | 21 |
|
22 | 22 |
#include <vector> |
23 | 23 |
#include <list> |
24 | 24 |
#include <limits> |
25 | 25 |
|
26 | 26 |
#include <lemon/maps.h> |
27 | 27 |
#include <lemon/core.h> |
28 | 28 |
#include <lemon/tolerance.h> |
29 | 29 |
|
30 | 30 |
/// \file |
31 | 31 |
/// \ingroup min_cut |
32 | 32 |
/// \brief Implementation of the Hao-Orlin algorithm. |
33 | 33 |
/// |
34 | 34 |
/// Implementation of the Hao-Orlin algorithm class for testing network |
35 | 35 |
/// reliability. |
36 | 36 |
|
37 | 37 |
namespace lemon { |
38 | 38 |
|
39 | 39 |
/// \ingroup min_cut |
40 | 40 |
/// |
41 | 41 |
/// \brief %Hao-Orlin algorithm to find a minimum cut in directed graphs. |
42 | 42 |
/// |
43 | 43 |
/// Hao-Orlin calculates a minimum cut in a directed graph |
44 | 44 |
/// \f$D=(V,A)\f$. It takes a fixed node \f$ source \in V \f$ and |
45 | 45 |
/// consists of two phases: in the first phase it determines a |
46 | 46 |
/// minimum cut with \f$ source \f$ on the source-side (i.e. a set |
47 | 47 |
/// \f$ X\subsetneq V \f$ with \f$ source \in X \f$ and minimal |
48 | 48 |
/// out-degree) and in the second phase it determines a minimum cut |
49 | 49 |
/// with \f$ source \f$ on the sink-side (i.e. a set |
50 | 50 |
/// \f$ X\subsetneq V \f$ with \f$ source \notin X \f$ and minimal |
51 | 51 |
/// out-degree). Obviously, the smaller of these two cuts will be a |
52 | 52 |
/// minimum cut of \f$ D \f$. The algorithm is a modified |
53 | 53 |
/// push-relabel preflow algorithm and our implementation calculates |
54 | 54 |
/// the minimum cut in \f$ O(n^2\sqrt{m}) \f$ time (we use the |
55 | 55 |
/// highest-label rule), or in \f$O(nm)\f$ for unit capacities. The |
56 | 56 |
/// purpose of such algorithm is testing network reliability. For an |
57 | 57 |
/// undirected graph you can run just the first phase of the |
58 | 58 |
/// algorithm or you can use the algorithm of Nagamochi and Ibaraki |
59 | 59 |
/// which solves the undirected problem in |
60 | 60 |
/// \f$ O(nm + n^2 \log(n)) \f$ time: it is implemented in the |
61 | 61 |
/// NagamochiIbaraki algorithm class. |
62 | 62 |
/// |
63 | 63 |
/// \param _Digraph is the graph type of the algorithm. |
64 | 64 |
/// \param _CapacityMap is an edge map of capacities which should |
65 | 65 |
/// be any numreric type. The default type is _Digraph::ArcMap<int>. |
66 | 66 |
/// \param _Tolerance is the handler of the inexact computation. The |
67 | 67 |
/// default type for this is Tolerance<CapacityMap::Value>. |
68 | 68 |
#ifdef DOXYGEN |
69 | 69 |
template <typename _Digraph, typename _CapacityMap, typename _Tolerance> |
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- |
|
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 HYPERCUBE_GRAPH_H |
20 | 20 |
#define HYPERCUBE_GRAPH_H |
21 | 21 |
|
22 | 22 |
#include <vector> |
23 | 23 |
#include <lemon/core.h> |
24 | 24 |
#include <lemon/assert.h> |
25 | 25 |
#include <lemon/bits/graph_extender.h> |
26 | 26 |
|
27 | 27 |
///\ingroup graphs |
28 | 28 |
///\file |
29 | 29 |
///\brief HypercubeGraph class. |
30 | 30 |
|
31 | 31 |
namespace lemon { |
32 | 32 |
|
33 | 33 |
class HypercubeGraphBase { |
34 | 34 |
|
35 | 35 |
public: |
36 | 36 |
|
37 | 37 |
typedef HypercubeGraphBase Graph; |
38 | 38 |
|
39 | 39 |
class Node; |
40 | 40 |
class Edge; |
41 | 41 |
class Arc; |
42 | 42 |
|
43 | 43 |
public: |
44 | 44 |
|
45 | 45 |
HypercubeGraphBase() {} |
46 | 46 |
|
47 | 47 |
protected: |
48 | 48 |
|
49 | 49 |
void construct(int dim) { |
50 | 50 |
LEMON_ASSERT(dim >= 1, "The number of dimensions must be at least 1."); |
51 | 51 |
_dim = dim; |
52 | 52 |
_node_num = 1 << dim; |
53 | 53 |
_edge_num = dim * (1 << (dim-1)); |
54 | 54 |
} |
55 | 55 |
|
56 | 56 |
public: |
57 | 57 |
|
58 | 58 |
typedef True NodeNumTag; |
59 | 59 |
typedef True EdgeNumTag; |
60 | 60 |
typedef True ArcNumTag; |
61 | 61 |
|
62 | 62 |
int nodeNum() const { return _node_num; } |
63 | 63 |
int edgeNum() const { return _edge_num; } |
64 | 64 |
int arcNum() const { return 2 * _edge_num; } |
65 | 65 |
|
66 | 66 |
int maxNodeId() const { return _node_num - 1; } |
67 | 67 |
int maxEdgeId() const { return _edge_num - 1; } |
68 | 68 |
int maxArcId() const { return 2 * _edge_num - 1; } |
69 | 69 |
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- |
|
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_KRUSKAL_H |
20 | 20 |
#define LEMON_KRUSKAL_H |
21 | 21 |
|
22 | 22 |
#include <algorithm> |
23 | 23 |
#include <vector> |
24 | 24 |
#include <lemon/unionfind.h> |
25 | 25 |
#include <lemon/maps.h> |
26 | 26 |
|
27 | 27 |
#include <lemon/core.h> |
28 | 28 |
#include <lemon/bits/traits.h> |
29 | 29 |
|
30 | 30 |
///\ingroup spantree |
31 | 31 |
///\file |
32 | 32 |
///\brief Kruskal's algorithm to compute a minimum cost spanning tree |
33 | 33 |
/// |
34 | 34 |
///Kruskal's algorithm to compute a minimum cost spanning tree. |
35 | 35 |
/// |
36 | 36 |
|
37 | 37 |
namespace lemon { |
38 | 38 |
|
39 | 39 |
namespace _kruskal_bits { |
40 | 40 |
|
41 | 41 |
// Kruskal for directed graphs. |
42 | 42 |
|
43 | 43 |
template <typename Digraph, typename In, typename Out> |
44 | 44 |
typename disable_if<lemon::UndirectedTagIndicator<Digraph>, |
45 | 45 |
typename In::value_type::second_type >::type |
46 | 46 |
kruskal(const Digraph& digraph, const In& in, Out& out,dummy<0> = 0) { |
47 | 47 |
typedef typename In::value_type::second_type Value; |
48 | 48 |
typedef typename Digraph::template NodeMap<int> IndexMap; |
49 | 49 |
typedef typename Digraph::Node Node; |
50 | 50 |
|
51 | 51 |
IndexMap index(digraph); |
52 | 52 |
UnionFind<IndexMap> uf(index); |
53 | 53 |
for (typename Digraph::NodeIt it(digraph); it != INVALID; ++it) { |
54 | 54 |
uf.insert(it); |
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
Value tree_value = 0; |
58 | 58 |
for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) { |
59 | 59 |
if (uf.join(digraph.target(it->first),digraph.source(it->first))) { |
60 | 60 |
out.set(it->first, true); |
61 | 61 |
tree_value += it->second; |
62 | 62 |
} |
63 | 63 |
else { |
64 | 64 |
out.set(it->first, false); |
65 | 65 |
} |
66 | 66 |
} |
67 | 67 |
return tree_value; |
68 | 68 |
} |
69 | 69 |
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- |
|
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 lemon_io |
20 | 20 |
///\file |
21 | 21 |
///\brief \ref lgf-format "LEMON Graph Format" reader. |
22 | 22 |
|
23 | 23 |
|
24 | 24 |
#ifndef LEMON_LGF_READER_H |
25 | 25 |
#define LEMON_LGF_READER_H |
26 | 26 |
|
27 | 27 |
#include <iostream> |
28 | 28 |
#include <fstream> |
29 | 29 |
#include <sstream> |
30 | 30 |
|
31 | 31 |
#include <set> |
32 | 32 |
#include <map> |
33 | 33 |
|
34 | 34 |
#include <lemon/core.h> |
35 | 35 |
|
36 | 36 |
#include <lemon/lgf_writer.h> |
37 | 37 |
|
38 | 38 |
#include <lemon/concept_check.h> |
39 | 39 |
#include <lemon/concepts/maps.h> |
40 | 40 |
|
41 | 41 |
namespace lemon { |
42 | 42 |
|
43 | 43 |
namespace _reader_bits { |
44 | 44 |
|
45 | 45 |
template <typename Value> |
46 | 46 |
struct DefaultConverter { |
47 | 47 |
Value operator()(const std::string& str) { |
48 | 48 |
std::istringstream is(str); |
49 | 49 |
Value value; |
50 | 50 |
if (!(is >> value)) { |
51 | 51 |
throw FormatError("Cannot read token"); |
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
char c; |
55 | 55 |
if (is >> std::ws >> c) { |
56 | 56 |
throw FormatError("Remaining characters in token"); |
57 | 57 |
} |
58 | 58 |
return value; |
59 | 59 |
} |
60 | 60 |
}; |
61 | 61 |
|
62 | 62 |
template <> |
63 | 63 |
struct DefaultConverter<std::string> { |
64 | 64 |
std::string operator()(const std::string& str) { |
65 | 65 |
return str; |
66 | 66 |
} |
67 | 67 |
}; |
68 | 68 |
|
69 | 69 |
template <typename _Item> |
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- |
|
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 lemon_io |
20 | 20 |
///\file |
21 | 21 |
///\brief \ref lgf-format "LEMON Graph Format" writer. |
22 | 22 |
|
23 | 23 |
|
24 | 24 |
#ifndef LEMON_LGF_WRITER_H |
25 | 25 |
#define LEMON_LGF_WRITER_H |
26 | 26 |
|
27 | 27 |
#include <iostream> |
28 | 28 |
#include <fstream> |
29 | 29 |
#include <sstream> |
30 | 30 |
|
31 | 31 |
#include <algorithm> |
32 | 32 |
|
33 | 33 |
#include <vector> |
34 | 34 |
#include <functional> |
35 | 35 |
|
36 | 36 |
#include <lemon/core.h> |
37 | 37 |
#include <lemon/maps.h> |
38 | 38 |
|
39 | 39 |
#include <lemon/concept_check.h> |
40 | 40 |
#include <lemon/concepts/maps.h> |
41 | 41 |
|
42 | 42 |
namespace lemon { |
43 | 43 |
|
44 | 44 |
namespace _writer_bits { |
45 | 45 |
|
46 | 46 |
template <typename Value> |
47 | 47 |
struct DefaultConverter { |
48 | 48 |
std::string operator()(const Value& value) { |
49 | 49 |
std::ostringstream os; |
50 | 50 |
os << value; |
51 | 51 |
return os.str(); |
52 | 52 |
} |
53 | 53 |
}; |
54 | 54 |
|
55 | 55 |
template <typename T> |
56 | 56 |
bool operator<(const T&, const T&) { |
57 | 57 |
throw FormatError("Label map is not comparable"); |
58 | 58 |
} |
59 | 59 |
|
60 | 60 |
template <typename _Map> |
61 | 61 |
class MapLess { |
62 | 62 |
public: |
63 | 63 |
typedef _Map Map; |
64 | 64 |
typedef typename Map::Key Item; |
65 | 65 |
|
66 | 66 |
private: |
67 | 67 |
const Map& _map; |
68 | 68 |
|
69 | 69 |
public: |
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- |
|
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_LIST_GRAPH_H |
20 | 20 |
#define LEMON_LIST_GRAPH_H |
21 | 21 |
|
22 | 22 |
///\ingroup graphs |
23 | 23 |
///\file |
24 | 24 |
///\brief ListDigraph, ListGraph classes. |
25 | 25 |
|
26 | 26 |
#include <lemon/core.h> |
27 | 27 |
#include <lemon/error.h> |
28 | 28 |
#include <lemon/bits/graph_extender.h> |
29 | 29 |
|
30 | 30 |
#include <vector> |
31 | 31 |
#include <list> |
32 | 32 |
|
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
class ListDigraphBase { |
36 | 36 |
|
37 | 37 |
protected: |
38 | 38 |
struct NodeT { |
39 | 39 |
int first_in, first_out; |
40 | 40 |
int prev, next; |
41 | 41 |
}; |
42 | 42 |
|
43 | 43 |
struct ArcT { |
44 | 44 |
int target, source; |
45 | 45 |
int prev_in, prev_out; |
46 | 46 |
int next_in, next_out; |
47 | 47 |
}; |
48 | 48 |
|
49 | 49 |
std::vector<NodeT> nodes; |
50 | 50 |
|
51 | 51 |
int first_node; |
52 | 52 |
|
53 | 53 |
int first_free_node; |
54 | 54 |
|
55 | 55 |
std::vector<ArcT> arcs; |
56 | 56 |
|
57 | 57 |
int first_free_arc; |
58 | 58 |
|
59 | 59 |
public: |
60 | 60 |
|
61 | 61 |
typedef ListDigraphBase Digraph; |
62 | 62 |
|
63 | 63 |
class Node { |
64 | 64 |
friend class ListDigraphBase; |
65 | 65 |
protected: |
66 | 66 |
|
67 | 67 |
int id; |
68 | 68 |
explicit Node(int pid) { id = pid;} |
69 | 69 |
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- |
|
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_MAPS_H |
20 | 20 |
#define LEMON_MAPS_H |
21 | 21 |
|
22 | 22 |
#include <iterator> |
23 | 23 |
#include <functional> |
24 | 24 |
#include <vector> |
25 | 25 |
|
26 | 26 |
#include <lemon/core.h> |
27 | 27 |
|
28 | 28 |
///\file |
29 | 29 |
///\ingroup maps |
30 | 30 |
///\brief Miscellaneous property maps |
31 | 31 |
|
32 | 32 |
#include <map> |
33 | 33 |
|
34 | 34 |
namespace lemon { |
35 | 35 |
|
36 | 36 |
/// \addtogroup maps |
37 | 37 |
/// @{ |
38 | 38 |
|
39 | 39 |
/// Base class of maps. |
40 | 40 |
|
41 | 41 |
/// Base class of maps. It provides the necessary type definitions |
42 | 42 |
/// required by the map %concepts. |
43 | 43 |
template<typename K, typename V> |
44 | 44 |
class MapBase { |
45 | 45 |
public: |
46 | 46 |
/// \brief The key type of the map. |
47 | 47 |
typedef K Key; |
48 | 48 |
/// \brief The value type of the map. |
49 | 49 |
/// (The type of objects associated with the keys). |
50 | 50 |
typedef V Value; |
51 | 51 |
}; |
52 | 52 |
|
53 | 53 |
|
54 | 54 |
/// Null map. (a.k.a. DoNothingMap) |
55 | 55 |
|
56 | 56 |
/// This map can be used if you have to provide a map only for |
57 | 57 |
/// its type definitions, or if you have to provide a writable map, |
58 | 58 |
/// but data written to it is not required (i.e. it will be sent to |
59 | 59 |
/// <tt>/dev/null</tt>). |
60 | 60 |
/// It conforms the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
61 | 61 |
/// |
62 | 62 |
/// \sa ConstMap |
63 | 63 |
template<typename K, typename V> |
64 | 64 |
class NullMap : public MapBase<K, V> { |
65 | 65 |
public: |
66 | 66 |
typedef MapBase<K, V> Parent; |
67 | 67 |
typedef typename Parent::Key Key; |
68 | 68 |
typedef typename Parent::Value Value; |
69 | 69 |
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- |
|
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_MATH_H |
20 | 20 |
#define LEMON_MATH_H |
21 | 21 |
|
22 | 22 |
///\ingroup misc |
23 | 23 |
///\file |
24 | 24 |
///\brief Some extensions to the standard \c cmath library. |
25 | 25 |
/// |
26 | 26 |
///Some extensions to the standard \c cmath library. |
27 | 27 |
/// |
28 | 28 |
///This file includes the standard math library (cmath). |
29 | 29 |
|
30 | 30 |
#include<cmath> |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
|
34 | 34 |
/// \addtogroup misc |
35 | 35 |
/// @{ |
36 | 36 |
|
37 | 37 |
/// The Euler constant |
38 | 38 |
const long double E = 2.7182818284590452353602874713526625L; |
39 | 39 |
/// log_2(e) |
40 | 40 |
const long double LOG2E = 1.4426950408889634073599246810018921L; |
41 | 41 |
/// log_10(e) |
42 | 42 |
const long double LOG10E = 0.4342944819032518276511289189166051L; |
43 | 43 |
/// ln(2) |
44 | 44 |
const long double LN2 = 0.6931471805599453094172321214581766L; |
45 | 45 |
/// ln(10) |
46 | 46 |
const long double LN10 = 2.3025850929940456840179914546843642L; |
47 | 47 |
/// pi |
48 | 48 |
const long double PI = 3.1415926535897932384626433832795029L; |
49 | 49 |
/// pi/2 |
50 | 50 |
const long double PI_2 = 1.5707963267948966192313216916397514L; |
51 | 51 |
/// pi/4 |
52 | 52 |
const long double PI_4 = 0.7853981633974483096156608458198757L; |
53 | 53 |
/// sqrt(2) |
54 | 54 |
const long double SQRT2 = 1.4142135623730950488016887242096981L; |
55 | 55 |
/// 1/sqrt(2) |
56 | 56 |
const long double SQRT1_2 = 0.7071067811865475244008443621048490L; |
57 | 57 |
|
58 | 58 |
|
59 | 59 |
/// @} |
60 | 60 |
|
61 | 61 |
} //namespace lemon |
62 | 62 |
|
63 | 63 |
#endif //LEMON_TOLERANCE_H |
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- |
|
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_MAX_MATCHING_H |
20 | 20 |
#define LEMON_MAX_MATCHING_H |
21 | 21 |
|
22 | 22 |
#include <vector> |
23 | 23 |
#include <queue> |
24 | 24 |
#include <set> |
25 | 25 |
#include <limits> |
26 | 26 |
|
27 | 27 |
#include <lemon/core.h> |
28 | 28 |
#include <lemon/unionfind.h> |
29 | 29 |
#include <lemon/bin_heap.h> |
30 | 30 |
#include <lemon/maps.h> |
31 | 31 |
|
32 | 32 |
///\ingroup matching |
33 | 33 |
///\file |
34 | 34 |
///\brief Maximum matching algorithms in general graphs. |
35 | 35 |
|
36 | 36 |
namespace lemon { |
37 | 37 |
|
38 | 38 |
/// \ingroup matching |
39 | 39 |
/// |
40 | 40 |
/// \brief Edmonds' alternating forest maximum matching algorithm. |
41 | 41 |
/// |
42 | 42 |
/// This class implements Edmonds' alternating forest matching |
43 | 43 |
/// algorithm. The algorithm can be started from an arbitrary initial |
44 | 44 |
/// matching (the default is the empty one) |
45 | 45 |
/// |
46 | 46 |
/// The dual solution of the problem is a map of the nodes to |
47 | 47 |
/// MaxMatching::Status, having values \c EVEN/D, \c ODD/A and \c |
48 | 48 |
/// MATCHED/C showing the Gallai-Edmonds decomposition of the |
49 | 49 |
/// graph. The nodes in \c EVEN/D induce a graph with |
50 | 50 |
/// factor-critical components, the nodes in \c ODD/A form the |
51 | 51 |
/// barrier, and the nodes in \c MATCHED/C induce a graph having a |
52 | 52 |
/// perfect matching. The number of the factor-critical components |
53 | 53 |
/// minus the number of barrier nodes is a lower bound on the |
54 | 54 |
/// unmatched nodes, and the matching is optimal if and only if this bound is |
55 | 55 |
/// tight. This decomposition can be attained by calling \c |
56 | 56 |
/// decomposition() after running the algorithm. |
57 | 57 |
/// |
58 | 58 |
/// \param _Graph The graph type the algorithm runs on. |
59 | 59 |
template <typename _Graph> |
60 | 60 |
class MaxMatching { |
61 | 61 |
public: |
62 | 62 |
|
63 | 63 |
typedef _Graph Graph; |
64 | 64 |
typedef typename Graph::template NodeMap<typename Graph::Arc> |
65 | 65 |
MatchingMap; |
66 | 66 |
|
67 | 67 |
///\brief Indicates the Gallai-Edmonds decomposition of the graph. |
68 | 68 |
/// |
69 | 69 |
///Indicates the Gallai-Edmonds decomposition of the graph. The |
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- |
|
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_NAUTY_READER_H |
20 | 20 |
#define LEMON_NAUTY_READER_H |
21 | 21 |
|
22 | 22 |
#include <vector> |
23 | 23 |
#include <iostream> |
24 | 24 |
#include <string> |
25 | 25 |
|
26 | 26 |
/// \ingroup nauty_group |
27 | 27 |
/// \file |
28 | 28 |
/// \brief Nauty file reader. |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
|
32 | 32 |
/// \ingroup nauty_group |
33 | 33 |
/// |
34 | 34 |
/// \brief Nauty file reader |
35 | 35 |
/// |
36 | 36 |
/// The \e geng program is in the \e gtools suite of the nauty |
37 | 37 |
/// package. This tool can generate all non-isomorphic undirected |
38 | 38 |
/// graphs of several classes with given node number (e.g. |
39 | 39 |
/// general, connected, biconnected, triangle-free, 4-cycle-free, |
40 | 40 |
/// bipartite and graphs with given edge number and degree |
41 | 41 |
/// constraints). This function reads a \e nauty \e graph6 \e format |
42 | 42 |
/// line from the given stream and builds it in the given graph. |
43 | 43 |
/// |
44 | 44 |
/// The site of nauty package: http://cs.anu.edu.au/~bdm/nauty/ |
45 | 45 |
/// |
46 | 46 |
/// For example, the number of all non-isomorphic planar graphs |
47 | 47 |
/// can be computed with the following code. |
48 | 48 |
///\code |
49 | 49 |
/// int num = 0; |
50 | 50 |
/// SmartGraph graph; |
51 | 51 |
/// while (readNautyGraph(graph, std::cin)) { |
52 | 52 |
/// PlanarityChecking<SmartGraph> pc(graph); |
53 | 53 |
/// if (pc.run()) ++num; |
54 | 54 |
/// } |
55 | 55 |
/// std::cout << "Number of planar graphs: " << num << std::endl; |
56 | 56 |
///\endcode |
57 | 57 |
/// |
58 | 58 |
/// The nauty files are quite huge, therefore instead of the direct |
59 | 59 |
/// file generation pipelining is recommended. For example, |
60 | 60 |
///\code |
61 | 61 |
/// ./geng -c 10 | ./num_of_planar_graphs |
62 | 62 |
///\endcode |
63 | 63 |
template <typename Graph> |
64 | 64 |
std::istream& readNautyGraph(Graph& graph, std::istream& is = std::cin) { |
65 | 65 |
graph.clear(); |
66 | 66 |
|
67 | 67 |
std::string line; |
68 | 68 |
if (getline(is, line)) { |
69 | 69 |
int index = 0; |
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- |
|
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 paths |
20 | 20 |
///\file |
21 | 21 |
///\brief Classes for representing paths in digraphs. |
22 | 22 |
/// |
23 | 23 |
|
24 | 24 |
#ifndef LEMON_PATH_H |
25 | 25 |
#define LEMON_PATH_H |
26 | 26 |
|
27 | 27 |
#include <vector> |
28 | 28 |
#include <algorithm> |
29 | 29 |
|
30 | 30 |
#include <lemon/error.h> |
31 | 31 |
#include <lemon/core.h> |
32 | 32 |
#include <lemon/concepts/path.h> |
33 | 33 |
|
34 | 34 |
namespace lemon { |
35 | 35 |
|
36 | 36 |
/// \addtogroup paths |
37 | 37 |
/// @{ |
38 | 38 |
|
39 | 39 |
|
40 | 40 |
/// \brief A structure for representing directed paths in a digraph. |
41 | 41 |
/// |
42 | 42 |
/// A structure for representing directed path in a digraph. |
43 | 43 |
/// \tparam _Digraph The digraph type in which the path is. |
44 | 44 |
/// |
45 | 45 |
/// In a sense, the path can be treated as a list of arcs. The |
46 | 46 |
/// lemon path type stores just this list. As a consequence, it |
47 | 47 |
/// cannot enumerate the nodes of the path and the source node of |
48 | 48 |
/// a zero length path is undefined. |
49 | 49 |
/// |
50 | 50 |
/// This implementation is a back and front insertable and erasable |
51 | 51 |
/// path type. It can be indexed in O(1) time. The front and back |
52 | 52 |
/// insertion and erase is done in O(1) (amortized) time. The |
53 | 53 |
/// implementation uses two vectors for storing the front and back |
54 | 54 |
/// insertions. |
55 | 55 |
template <typename _Digraph> |
56 | 56 |
class Path { |
57 | 57 |
public: |
58 | 58 |
|
59 | 59 |
typedef _Digraph Digraph; |
60 | 60 |
typedef typename Digraph::Arc Arc; |
61 | 61 |
|
62 | 62 |
/// \brief Default constructor |
63 | 63 |
/// |
64 | 64 |
/// Default constructor |
65 | 65 |
Path() {} |
66 | 66 |
|
67 | 67 |
/// \brief Template copy constructor |
68 | 68 |
/// |
69 | 69 |
/// This constuctor initializes the path from any other path type. |
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- |
|
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_PREFLOW_H |
20 | 20 |
#define LEMON_PREFLOW_H |
21 | 21 |
|
22 | 22 |
#include <lemon/tolerance.h> |
23 | 23 |
#include <lemon/elevator.h> |
24 | 24 |
|
25 | 25 |
/// \file |
26 | 26 |
/// \ingroup max_flow |
27 | 27 |
/// \brief Implementation of the preflow algorithm. |
28 | 28 |
|
29 | 29 |
namespace lemon { |
30 | 30 |
|
31 | 31 |
/// \brief Default traits class of Preflow class. |
32 | 32 |
/// |
33 | 33 |
/// Default traits class of Preflow class. |
34 | 34 |
/// \tparam _Digraph Digraph type. |
35 | 35 |
/// \tparam _CapacityMap Capacity map type. |
36 | 36 |
template <typename _Digraph, typename _CapacityMap> |
37 | 37 |
struct PreflowDefaultTraits { |
38 | 38 |
|
39 | 39 |
/// \brief The type of the digraph the algorithm runs on. |
40 | 40 |
typedef _Digraph Digraph; |
41 | 41 |
|
42 | 42 |
/// \brief The type of the map that stores the arc capacities. |
43 | 43 |
/// |
44 | 44 |
/// The type of the map that stores the arc capacities. |
45 | 45 |
/// It must meet the \ref concepts::ReadMap "ReadMap" concept. |
46 | 46 |
typedef _CapacityMap CapacityMap; |
47 | 47 |
|
48 | 48 |
/// \brief The type of the flow values. |
49 | 49 |
typedef typename CapacityMap::Value Value; |
50 | 50 |
|
51 | 51 |
/// \brief The type of the map that stores the flow values. |
52 | 52 |
/// |
53 | 53 |
/// The type of the map that stores the flow values. |
54 | 54 |
/// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
55 | 55 |
typedef typename Digraph::template ArcMap<Value> FlowMap; |
56 | 56 |
|
57 | 57 |
/// \brief Instantiates a FlowMap. |
58 | 58 |
/// |
59 | 59 |
/// This function instantiates a \ref FlowMap. |
60 | 60 |
/// \param digraph The digraph, to which we would like to define |
61 | 61 |
/// the flow map. |
62 | 62 |
static FlowMap* createFlowMap(const Digraph& digraph) { |
63 | 63 |
return new FlowMap(digraph); |
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
/// \brief The elevator type used by Preflow algorithm. |
67 | 67 |
/// |
68 | 68 |
/// The elevator type used by Preflow algorithm. |
69 | 69 |
/// |
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- |
|
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 Instantiation of the Random class. |
21 | 21 |
|
22 | 22 |
#include <lemon/random.h> |
23 | 23 |
|
24 | 24 |
namespace lemon { |
25 | 25 |
/// \brief Global random number generator instance |
26 | 26 |
/// |
27 | 27 |
/// A global Mersenne Twister random number generator instance. |
28 | 28 |
Random rnd; |
29 | 29 |
} |
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- |
|
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 |
* This file contains the reimplemented version of the Mersenne Twister |
21 | 21 |
* Generator of Matsumoto and Nishimura. |
22 | 22 |
* |
23 | 23 |
* See the appropriate copyright notice below. |
24 | 24 |
* |
25 | 25 |
* Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, |
26 | 26 |
* All rights reserved. |
27 | 27 |
* |
28 | 28 |
* Redistribution and use in source and binary forms, with or without |
29 | 29 |
* modification, are permitted provided that the following conditions |
30 | 30 |
* are met: |
31 | 31 |
* |
32 | 32 |
* 1. Redistributions of source code must retain the above copyright |
33 | 33 |
* notice, this list of conditions and the following disclaimer. |
34 | 34 |
* |
35 | 35 |
* 2. Redistributions in binary form must reproduce the above copyright |
36 | 36 |
* notice, this list of conditions and the following disclaimer in the |
37 | 37 |
* documentation and/or other materials provided with the distribution. |
38 | 38 |
* |
39 | 39 |
* 3. The names of its contributors may not be used to endorse or promote |
40 | 40 |
* products derived from this software without specific prior written |
41 | 41 |
* permission. |
42 | 42 |
* |
43 | 43 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
44 | 44 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
45 | 45 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
46 | 46 |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
47 | 47 |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
48 | 48 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
49 | 49 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
50 | 50 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
51 | 51 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
52 | 52 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | 53 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
54 | 54 |
* OF THE POSSIBILITY OF SUCH DAMAGE. |
55 | 55 |
* |
56 | 56 |
* |
57 | 57 |
* Any feedback is very welcome. |
58 | 58 |
* http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html |
59 | 59 |
* email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) |
60 | 60 |
*/ |
61 | 61 |
|
62 | 62 |
#ifndef LEMON_RANDOM_H |
63 | 63 |
#define LEMON_RANDOM_H |
64 | 64 |
|
65 | 65 |
#include <algorithm> |
66 | 66 |
#include <iterator> |
67 | 67 |
#include <vector> |
68 | 68 |
#include <limits> |
69 | 69 |
#include <fstream> |
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- |
|
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_SMART_GRAPH_H |
20 | 20 |
#define LEMON_SMART_GRAPH_H |
21 | 21 |
|
22 | 22 |
///\ingroup graphs |
23 | 23 |
///\file |
24 | 24 |
///\brief SmartDigraph and SmartGraph classes. |
25 | 25 |
|
26 | 26 |
#include <vector> |
27 | 27 |
|
28 | 28 |
#include <lemon/core.h> |
29 | 29 |
#include <lemon/error.h> |
30 | 30 |
#include <lemon/bits/graph_extender.h> |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
|
34 | 34 |
class SmartDigraph; |
35 | 35 |
///Base of SmartDigraph |
36 | 36 |
|
37 | 37 |
///Base of SmartDigraph |
38 | 38 |
/// |
39 | 39 |
class SmartDigraphBase { |
40 | 40 |
protected: |
41 | 41 |
|
42 | 42 |
struct NodeT |
43 | 43 |
{ |
44 | 44 |
int first_in, first_out; |
45 | 45 |
NodeT() {} |
46 | 46 |
}; |
47 | 47 |
struct ArcT |
48 | 48 |
{ |
49 | 49 |
int target, source, next_in, next_out; |
50 | 50 |
ArcT() {} |
51 | 51 |
}; |
52 | 52 |
|
53 | 53 |
std::vector<NodeT> nodes; |
54 | 54 |
std::vector<ArcT> arcs; |
55 | 55 |
|
56 | 56 |
public: |
57 | 57 |
|
58 | 58 |
typedef SmartDigraphBase Graph; |
59 | 59 |
|
60 | 60 |
class Node; |
61 | 61 |
class Arc; |
62 | 62 |
|
63 | 63 |
public: |
64 | 64 |
|
65 | 65 |
SmartDigraphBase() : nodes(), arcs() { } |
66 | 66 |
SmartDigraphBase(const SmartDigraphBase &_g) |
67 | 67 |
: nodes(_g.nodes), arcs(_g.arcs) { } |
68 | 68 |
|
69 | 69 |
typedef True NodeNumTag; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
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_SUURBALLE_H |
20 | 20 |
#define LEMON_SUURBALLE_H |
21 | 21 |
|
22 | 22 |
///\ingroup shortest_path |
23 | 23 |
///\file |
24 | 24 |
///\brief An algorithm for finding arc-disjoint paths between two |
25 | 25 |
/// nodes having minimum total length. |
26 | 26 |
|
27 | 27 |
#include <vector> |
28 | 28 |
#include <lemon/bin_heap.h> |
29 | 29 |
#include <lemon/path.h> |
30 | 30 |
|
31 | 31 |
namespace lemon { |
32 | 32 |
|
33 | 33 |
/// \addtogroup shortest_path |
34 | 34 |
/// @{ |
35 | 35 |
|
36 | 36 |
/// \brief Algorithm for finding arc-disjoint paths between two nodes |
37 | 37 |
/// having minimum total length. |
38 | 38 |
/// |
39 | 39 |
/// \ref lemon::Suurballe "Suurballe" implements an algorithm for |
40 | 40 |
/// finding arc-disjoint paths having minimum total length (cost) |
41 | 41 |
/// from a given source node to a given target node in a digraph. |
42 | 42 |
/// |
43 | 43 |
/// In fact, this implementation is the specialization of the |
44 | 44 |
/// \ref CapacityScaling "successive shortest path" algorithm. |
45 | 45 |
/// |
46 | 46 |
/// \tparam Digraph The digraph type the algorithm runs on. |
47 | 47 |
/// The default value is \c ListDigraph. |
48 | 48 |
/// \tparam LengthMap The type of the length (cost) map. |
49 | 49 |
/// The default value is <tt>Digraph::ArcMap<int></tt>. |
50 | 50 |
/// |
51 | 51 |
/// \warning Length values should be \e non-negative \e integers. |
52 | 52 |
/// |
53 | 53 |
/// \note For finding node-disjoint paths this algorithm can be used |
54 | 54 |
/// with \ref SplitNodes. |
55 | 55 |
#ifdef DOXYGEN |
56 | 56 |
template <typename Digraph, typename LengthMap> |
57 | 57 |
#else |
58 | 58 |
template < typename Digraph = ListDigraph, |
59 | 59 |
typename LengthMap = typename Digraph::template ArcMap<int> > |
60 | 60 |
#endif |
61 | 61 |
class Suurballe |
62 | 62 |
{ |
63 | 63 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
64 | 64 |
|
65 | 65 |
typedef typename LengthMap::Value Length; |
66 | 66 |
typedef ConstMap<Arc, int> ConstArcMap; |
67 | 67 |
typedef typename Digraph::template NodeMap<Arc> PredMap; |
68 | 68 |
|
69 | 69 |
public: |
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- |
|
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_TIME_MEASURE_H |
20 | 20 |
#define LEMON_TIME_MEASURE_H |
21 | 21 |
|
22 | 22 |
///\ingroup timecount |
23 | 23 |
///\file |
24 | 24 |
///\brief Tools for measuring cpu usage |
25 | 25 |
|
26 | 26 |
#ifdef WIN32 |
27 | 27 |
#define WIN32_LEAN_AND_MEAN |
28 | 28 |
#define NOMINMAX |
29 | 29 |
#include <windows.h> |
30 | 30 |
#include <cmath> |
31 | 31 |
#else |
32 | 32 |
#include <sys/times.h> |
33 | 33 |
#include <sys/time.h> |
34 | 34 |
#endif |
35 | 35 |
|
36 | 36 |
#include <string> |
37 | 37 |
#include <fstream> |
38 | 38 |
#include <iostream> |
39 | 39 |
|
40 | 40 |
namespace lemon { |
41 | 41 |
|
42 | 42 |
/// \addtogroup timecount |
43 | 43 |
/// @{ |
44 | 44 |
|
45 | 45 |
/// A class to store (cpu)time instances. |
46 | 46 |
|
47 | 47 |
/// This class stores five time values. |
48 | 48 |
/// - a real time |
49 | 49 |
/// - a user cpu time |
50 | 50 |
/// - a system cpu time |
51 | 51 |
/// - a user cpu time of children |
52 | 52 |
/// - a system cpu time of children |
53 | 53 |
/// |
54 | 54 |
/// TimeStamp's can be added to or substracted from each other and |
55 | 55 |
/// they can be pushed to a stream. |
56 | 56 |
/// |
57 | 57 |
/// In most cases, perhaps the \ref Timer or the \ref TimeReport |
58 | 58 |
/// class is what you want to use instead. |
59 | 59 |
|
60 | 60 |
class TimeStamp |
61 | 61 |
{ |
62 | 62 |
double utime; |
63 | 63 |
double stime; |
64 | 64 |
double cutime; |
65 | 65 |
double cstime; |
66 | 66 |
double rtime; |
67 | 67 |
|
68 | 68 |
void _reset() { |
69 | 69 |
utime = stime = cutime = cstime = rtime = 0; |
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- |
|
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_TOLERANCE_H |
20 | 20 |
#define LEMON_TOLERANCE_H |
21 | 21 |
|
22 | 22 |
///\ingroup misc |
23 | 23 |
///\file |
24 | 24 |
///\brief A basic tool to handle the anomalies of calculation with |
25 | 25 |
///floating point numbers. |
26 | 26 |
/// |
27 | 27 |
|
28 | 28 |
namespace lemon { |
29 | 29 |
|
30 | 30 |
/// \addtogroup misc |
31 | 31 |
/// @{ |
32 | 32 |
|
33 | 33 |
///\brief A class to provide a basic way to |
34 | 34 |
///handle the comparison of numbers that are obtained |
35 | 35 |
///as a result of a probably inexact computation. |
36 | 36 |
/// |
37 | 37 |
///\ref Tolerance is a class to provide a basic way to |
38 | 38 |
///handle the comparison of numbers that are obtained |
39 | 39 |
///as a result of a probably inexact computation. |
40 | 40 |
/// |
41 | 41 |
///This is an abstract class, it should be specialized for all |
42 | 42 |
///numerical data types. These specialized classes like |
43 | 43 |
///Tolerance<double> may offer additional tuning parameters. |
44 | 44 |
/// |
45 | 45 |
///\sa Tolerance<float> |
46 | 46 |
///\sa Tolerance<double> |
47 | 47 |
///\sa Tolerance<long double> |
48 | 48 |
///\sa Tolerance<int> |
49 | 49 |
///\sa Tolerance<long long int> |
50 | 50 |
///\sa Tolerance<unsigned int> |
51 | 51 |
///\sa Tolerance<unsigned long long int> |
52 | 52 |
|
53 | 53 |
template<class T> |
54 | 54 |
class Tolerance |
55 | 55 |
{ |
56 | 56 |
public: |
57 | 57 |
typedef T Value; |
58 | 58 |
|
59 | 59 |
///\name Comparisons |
60 | 60 |
///The concept is that these bool functions return \c true only if |
61 | 61 |
///the related comparisons hold even if some numerical error appeared |
62 | 62 |
///during the computations. |
63 | 63 |
|
64 | 64 |
///@{ |
65 | 65 |
|
66 | 66 |
///Returns \c true if \c a is \e surely strictly less than \c b |
67 | 67 |
static bool less(Value a,Value b) {return false;} |
68 | 68 |
///Returns \c true if \c a is \e surely different from \c b |
69 | 69 |
static bool different(Value a,Value b) {return false;} |
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- |
|
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_UNION_FIND_H |
20 | 20 |
#define LEMON_UNION_FIND_H |
21 | 21 |
|
22 | 22 |
//!\ingroup auxdat |
23 | 23 |
//!\file |
24 | 24 |
//!\brief Union-Find data structures. |
25 | 25 |
//! |
26 | 26 |
|
27 | 27 |
#include <vector> |
28 | 28 |
#include <list> |
29 | 29 |
#include <utility> |
30 | 30 |
#include <algorithm> |
31 | 31 |
#include <functional> |
32 | 32 |
|
33 | 33 |
#include <lemon/core.h> |
34 | 34 |
|
35 | 35 |
namespace lemon { |
36 | 36 |
|
37 | 37 |
/// \ingroup auxdat |
38 | 38 |
/// |
39 | 39 |
/// \brief A \e Union-Find data structure implementation |
40 | 40 |
/// |
41 | 41 |
/// The class implements the \e Union-Find data structure. |
42 | 42 |
/// The union operation uses rank heuristic, while |
43 | 43 |
/// the find operation uses path compression. |
44 | 44 |
/// This is a very simple but efficient implementation, providing |
45 | 45 |
/// only four methods: join (union), find, insert and size. |
46 | 46 |
/// For more features see the \ref UnionFindEnum class. |
47 | 47 |
/// |
48 | 48 |
/// It is primarily used in Kruskal algorithm for finding minimal |
49 | 49 |
/// cost spanning tree in a graph. |
50 | 50 |
/// \sa kruskal() |
51 | 51 |
/// |
52 | 52 |
/// \pre You need to add all the elements by the \ref insert() |
53 | 53 |
/// method. |
54 | 54 |
template <typename _ItemIntMap> |
55 | 55 |
class UnionFind { |
56 | 56 |
public: |
57 | 57 |
|
58 | 58 |
typedef _ItemIntMap ItemIntMap; |
59 | 59 |
typedef typename ItemIntMap::Key Item; |
60 | 60 |
|
61 | 61 |
private: |
62 | 62 |
// If the items vector stores negative value for an item then |
63 | 63 |
// that item is root item and it has -items[it] component size. |
64 | 64 |
// Else the items[it] contains the index of the parent. |
65 | 65 |
std::vector<int> items; |
66 | 66 |
ItemIntMap& index; |
67 | 67 |
|
68 | 68 |
bool rep(int idx) const { |
69 | 69 |
return items[idx] < 0; |
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- |
|
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/concepts/digraph.h> |
20 | 20 |
#include <lemon/smart_graph.h> |
21 | 21 |
#include <lemon/list_graph.h> |
22 | 22 |
#include <lemon/lgf_reader.h> |
23 | 23 |
#include <lemon/bfs.h> |
24 | 24 |
#include <lemon/path.h> |
25 | 25 |
|
26 | 26 |
#include "graph_test.h" |
27 | 27 |
#include "test_tools.h" |
28 | 28 |
|
29 | 29 |
using namespace lemon; |
30 | 30 |
|
31 | 31 |
char test_lgf[] = |
32 | 32 |
"@nodes\n" |
33 | 33 |
"label\n" |
34 | 34 |
"0\n" |
35 | 35 |
"1\n" |
36 | 36 |
"2\n" |
37 | 37 |
"3\n" |
38 | 38 |
"4\n" |
39 | 39 |
"5\n" |
40 | 40 |
"@arcs\n" |
41 | 41 |
" label\n" |
42 | 42 |
"0 1 0\n" |
43 | 43 |
"1 2 1\n" |
44 | 44 |
"2 3 2\n" |
45 | 45 |
"3 4 3\n" |
46 | 46 |
"0 3 4\n" |
47 | 47 |
"0 3 5\n" |
48 | 48 |
"5 2 6\n" |
49 | 49 |
"@attributes\n" |
50 | 50 |
"source 0\n" |
51 | 51 |
"target 4\n"; |
52 | 52 |
|
53 | 53 |
void checkBfsCompile() |
54 | 54 |
{ |
55 | 55 |
typedef concepts::Digraph Digraph; |
56 | 56 |
typedef Bfs<Digraph> BType; |
57 | 57 |
typedef Digraph::Node Node; |
58 | 58 |
typedef Digraph::Arc Arc; |
59 | 59 |
|
60 | 60 |
Digraph G; |
61 | 61 |
Node s, t; |
62 | 62 |
Arc e; |
63 | 63 |
int l; |
64 | 64 |
bool b; |
65 | 65 |
BType::DistMap d(G); |
66 | 66 |
BType::PredMap p(G); |
67 | 67 |
Path<Digraph> pp; |
68 | 68 |
|
69 | 69 |
{ |
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- |
|
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 <iostream> |
20 | 20 |
|
21 | 21 |
#include "test_tools.h" |
22 | 22 |
#include <lemon/list_graph.h> |
23 | 23 |
#include <lemon/circulation.h> |
24 | 24 |
#include <lemon/lgf_reader.h> |
25 | 25 |
#include <lemon/concepts/digraph.h> |
26 | 26 |
#include <lemon/concepts/maps.h> |
27 | 27 |
|
28 | 28 |
using namespace lemon; |
29 | 29 |
|
30 | 30 |
char test_lgf[] = |
31 | 31 |
"@nodes\n" |
32 | 32 |
"label\n" |
33 | 33 |
"0\n" |
34 | 34 |
"1\n" |
35 | 35 |
"2\n" |
36 | 36 |
"3\n" |
37 | 37 |
"4\n" |
38 | 38 |
"5\n" |
39 | 39 |
"@arcs\n" |
40 | 40 |
" lcap ucap\n" |
41 | 41 |
"0 1 2 10\n" |
42 | 42 |
"0 2 2 6\n" |
43 | 43 |
"1 3 4 7\n" |
44 | 44 |
"1 4 0 5\n" |
45 | 45 |
"2 4 1 3\n" |
46 | 46 |
"3 5 3 8\n" |
47 | 47 |
"4 5 3 7\n" |
48 | 48 |
"@attributes\n" |
49 | 49 |
"source 0\n" |
50 | 50 |
"sink 5\n"; |
51 | 51 |
|
52 | 52 |
void checkCirculationCompile() |
53 | 53 |
{ |
54 | 54 |
typedef int VType; |
55 | 55 |
typedef concepts::Digraph Digraph; |
56 | 56 |
|
57 | 57 |
typedef Digraph::Node Node; |
58 | 58 |
typedef Digraph::Arc Arc; |
59 | 59 |
typedef concepts::ReadMap<Arc,VType> CapMap; |
60 | 60 |
typedef concepts::ReadMap<Node,VType> DeltaMap; |
61 | 61 |
typedef concepts::ReadWriteMap<Arc,VType> FlowMap; |
62 | 62 |
typedef concepts::WriteMap<Node,bool> BarrierMap; |
63 | 63 |
|
64 | 64 |
typedef Elevator<Digraph, Digraph::Node> Elev; |
65 | 65 |
typedef LinkedElevator<Digraph, Digraph::Node> LinkedElev; |
66 | 66 |
|
67 | 67 |
Digraph g; |
68 | 68 |
Node n; |
69 | 69 |
Arc a; |
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- |
|
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/counter.h> |
20 | 20 |
#include <vector> |
21 | 21 |
|
22 | 22 |
using namespace lemon; |
23 | 23 |
|
24 | 24 |
template <typename T> |
25 | 25 |
void bubbleSort(std::vector<T>& v) { |
26 | 26 |
Counter op("Bubble Sort - Operations: "); |
27 | 27 |
Counter::NoSubCounter as(op, "Assignments: "); |
28 | 28 |
Counter::NoSubCounter co(op, "Comparisons: "); |
29 | 29 |
for (int i = v.size()-1; i > 0; --i) { |
30 | 30 |
for (int j = 0; j < i; ++j) { |
31 | 31 |
if (v[j] > v[j+1]) { |
32 | 32 |
T tmp = v[j]; |
33 | 33 |
v[j] = v[j+1]; |
34 | 34 |
v[j+1] = tmp; |
35 | 35 |
as += 3; |
36 | 36 |
} |
37 | 37 |
++co; |
38 | 38 |
} |
39 | 39 |
} |
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
template <typename T> |
43 | 43 |
void insertionSort(std::vector<T>& v) { |
44 | 44 |
Counter op("Insertion Sort - Operations: "); |
45 | 45 |
Counter::NoSubCounter as(op, "Assignments: "); |
46 | 46 |
Counter::NoSubCounter co(op, "Comparisons: "); |
47 | 47 |
for (int i = 1; i < int(v.size()); ++i) { |
48 | 48 |
T value = v[i]; |
49 | 49 |
++as; |
50 | 50 |
int j = i; |
51 | 51 |
while (j > 0 && v[j-1] > value) { |
52 | 52 |
v[j] = v[j-1]; |
53 | 53 |
--j; |
54 | 54 |
++co; ++as; |
55 | 55 |
} |
56 | 56 |
v[j] = value; |
57 | 57 |
++as; |
58 | 58 |
} |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
template <typename MyCounter> |
62 | 62 |
void counterTest() { |
63 | 63 |
MyCounter c("Main Counter: "); |
64 | 64 |
c++; |
65 | 65 |
typename MyCounter::SubCounter d(c, "SubCounter: "); |
66 | 66 |
d++; |
67 | 67 |
typename MyCounter::SubCounter::NoSubCounter e(d, "SubSubCounter: "); |
68 | 68 |
e++; |
69 | 69 |
d+=3; |
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- |
|
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/concepts/digraph.h> |
20 | 20 |
#include <lemon/smart_graph.h> |
21 | 21 |
#include <lemon/list_graph.h> |
22 | 22 |
#include <lemon/lgf_reader.h> |
23 | 23 |
#include <lemon/dfs.h> |
24 | 24 |
#include <lemon/path.h> |
25 | 25 |
|
26 | 26 |
#include "graph_test.h" |
27 | 27 |
#include "test_tools.h" |
28 | 28 |
|
29 | 29 |
using namespace lemon; |
30 | 30 |
|
31 | 31 |
char test_lgf[] = |
32 | 32 |
"@nodes\n" |
33 | 33 |
"label\n" |
34 | 34 |
"0\n" |
35 | 35 |
"1\n" |
36 | 36 |
"2\n" |
37 | 37 |
"3\n" |
38 | 38 |
"4\n" |
39 | 39 |
"5\n" |
40 | 40 |
"6\n" |
41 | 41 |
"@arcs\n" |
42 | 42 |
" label\n" |
43 | 43 |
"0 1 0\n" |
44 | 44 |
"1 2 1\n" |
45 | 45 |
"2 3 2\n" |
46 | 46 |
"1 4 3\n" |
47 | 47 |
"4 2 4\n" |
48 | 48 |
"4 5 5\n" |
49 | 49 |
"5 0 6\n" |
50 | 50 |
"6 3 7\n" |
51 | 51 |
"@attributes\n" |
52 | 52 |
"source 0\n" |
53 | 53 |
"target 5\n"; |
54 | 54 |
|
55 | 55 |
void checkDfsCompile() |
56 | 56 |
{ |
57 | 57 |
typedef concepts::Digraph Digraph; |
58 | 58 |
typedef Dfs<Digraph> DType; |
59 | 59 |
typedef Digraph::Node Node; |
60 | 60 |
typedef Digraph::Arc Arc; |
61 | 61 |
|
62 | 62 |
Digraph G; |
63 | 63 |
Node s, t; |
64 | 64 |
Arc e; |
65 | 65 |
int l; |
66 | 66 |
bool b; |
67 | 67 |
DType::DistMap d(G); |
68 | 68 |
DType::PredMap p(G); |
69 | 69 |
Path<Digraph> pp; |
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- |
|
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/concepts/digraph.h> |
20 | 20 |
#include <lemon/list_graph.h> |
21 | 21 |
#include <lemon/smart_graph.h> |
22 | 22 |
#include <lemon/full_graph.h> |
23 | 23 |
|
24 | 24 |
#include "test_tools.h" |
25 | 25 |
#include "graph_test.h" |
26 | 26 |
|
27 | 27 |
using namespace lemon; |
28 | 28 |
using namespace lemon::concepts; |
29 | 29 |
|
30 | 30 |
template <class Digraph> |
31 | 31 |
void checkDigraphBuild() { |
32 | 32 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
33 | 33 |
Digraph G; |
34 | 34 |
|
35 | 35 |
checkGraphNodeList(G, 0); |
36 | 36 |
checkGraphArcList(G, 0); |
37 | 37 |
|
38 | 38 |
Node |
39 | 39 |
n1 = G.addNode(), |
40 | 40 |
n2 = G.addNode(), |
41 | 41 |
n3 = G.addNode(); |
42 | 42 |
checkGraphNodeList(G, 3); |
43 | 43 |
checkGraphArcList(G, 0); |
44 | 44 |
|
45 | 45 |
Arc a1 = G.addArc(n1, n2); |
46 | 46 |
check(G.source(a1) == n1 && G.target(a1) == n2, "Wrong arc"); |
47 | 47 |
checkGraphNodeList(G, 3); |
48 | 48 |
checkGraphArcList(G, 1); |
49 | 49 |
|
50 | 50 |
checkGraphOutArcList(G, n1, 1); |
51 | 51 |
checkGraphOutArcList(G, n2, 0); |
52 | 52 |
checkGraphOutArcList(G, n3, 0); |
53 | 53 |
|
54 | 54 |
checkGraphInArcList(G, n1, 0); |
55 | 55 |
checkGraphInArcList(G, n2, 1); |
56 | 56 |
checkGraphInArcList(G, n3, 0); |
57 | 57 |
|
58 | 58 |
checkGraphConArcList(G, 1); |
59 | 59 |
|
60 | 60 |
Arc a2 = G.addArc(n2, n1), |
61 | 61 |
a3 = G.addArc(n2, n3), |
62 | 62 |
a4 = G.addArc(n2, n3); |
63 | 63 |
|
64 | 64 |
checkGraphNodeList(G, 3); |
65 | 65 |
checkGraphArcList(G, 4); |
66 | 66 |
|
67 | 67 |
checkGraphOutArcList(G, n1, 1); |
68 | 68 |
checkGraphOutArcList(G, n2, 3); |
69 | 69 |
checkGraphOutArcList(G, n3, 0); |
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- |
|
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/concepts/digraph.h> |
20 | 20 |
#include <lemon/smart_graph.h> |
21 | 21 |
#include <lemon/list_graph.h> |
22 | 22 |
#include <lemon/lgf_reader.h> |
23 | 23 |
#include <lemon/dijkstra.h> |
24 | 24 |
#include <lemon/path.h> |
25 | 25 |
#include <lemon/bin_heap.h> |
26 | 26 |
|
27 | 27 |
#include "graph_test.h" |
28 | 28 |
#include "test_tools.h" |
29 | 29 |
|
30 | 30 |
using namespace lemon; |
31 | 31 |
|
32 | 32 |
char test_lgf[] = |
33 | 33 |
"@nodes\n" |
34 | 34 |
"label\n" |
35 | 35 |
"0\n" |
36 | 36 |
"1\n" |
37 | 37 |
"2\n" |
38 | 38 |
"3\n" |
39 | 39 |
"4\n" |
40 | 40 |
"@arcs\n" |
41 | 41 |
" label length\n" |
42 | 42 |
"0 1 0 1\n" |
43 | 43 |
"1 2 1 1\n" |
44 | 44 |
"2 3 2 1\n" |
45 | 45 |
"0 3 4 5\n" |
46 | 46 |
"0 3 5 10\n" |
47 | 47 |
"0 3 6 7\n" |
48 | 48 |
"4 2 7 1\n" |
49 | 49 |
"@attributes\n" |
50 | 50 |
"source 0\n" |
51 | 51 |
"target 3\n"; |
52 | 52 |
|
53 | 53 |
void checkDijkstraCompile() |
54 | 54 |
{ |
55 | 55 |
typedef int VType; |
56 | 56 |
typedef concepts::Digraph Digraph; |
57 | 57 |
typedef concepts::ReadMap<Digraph::Arc,VType> LengthMap; |
58 | 58 |
typedef Dijkstra<Digraph, LengthMap> DType; |
59 | 59 |
typedef Digraph::Node Node; |
60 | 60 |
typedef Digraph::Arc Arc; |
61 | 61 |
|
62 | 62 |
Digraph G; |
63 | 63 |
Node s, t; |
64 | 64 |
Arc e; |
65 | 65 |
VType l; |
66 | 66 |
bool b; |
67 | 67 |
DType::DistMap d(G); |
68 | 68 |
DType::PredMap p(G); |
69 | 69 |
LengthMap length; |
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- |
|
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/dim2.h> |
20 | 20 |
#include <iostream> |
21 | 21 |
#include "test_tools.h" |
22 | 22 |
|
23 | 23 |
using namespace std; |
24 | 24 |
using namespace lemon; |
25 | 25 |
|
26 | 26 |
int main() |
27 | 27 |
{ |
28 | 28 |
typedef dim2::Point<int> Point; |
29 | 29 |
|
30 | 30 |
Point p; |
31 | 31 |
check(p.size()==2, "Wrong dim2::Point initialization."); |
32 | 32 |
|
33 | 33 |
Point a(1,2); |
34 | 34 |
Point b(3,4); |
35 | 35 |
check(a[0]==1 && a[1]==2, "Wrong dim2::Point initialization."); |
36 | 36 |
|
37 | 37 |
p = a+b; |
38 | 38 |
check(p.x==4 && p.y==6, "Wrong dim2::Point addition."); |
39 | 39 |
|
40 | 40 |
p = a-b; |
41 | 41 |
check(p.x==-2 && p.y==-2, "Wrong dim2::Point subtraction."); |
42 | 42 |
|
43 | 43 |
check(a.normSquare()==5,"Wrong dim2::Point norm calculation."); |
44 | 44 |
check(a*b==11, "Wrong dim2::Point scalar product."); |
45 | 45 |
|
46 | 46 |
int l=2; |
47 | 47 |
p = a*l; |
48 | 48 |
check(p.x==2 && p.y==4, "Wrong dim2::Point multiplication by a scalar."); |
49 | 49 |
|
50 | 50 |
p = b/l; |
51 | 51 |
check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar."); |
52 | 52 |
|
53 | 53 |
typedef dim2::Box<int> Box; |
54 | 54 |
Box box1; |
55 | 55 |
check(box1.empty(), "Wrong empty() in dim2::Box."); |
56 | 56 |
|
57 | 57 |
box1.add(a); |
58 | 58 |
check(!box1.empty(), "Wrong empty() in dim2::Box."); |
59 | 59 |
box1.add(b); |
60 | 60 |
|
61 | 61 |
check(box1.left()==1 && box1.bottom()==2 && |
62 | 62 |
box1.right()==3 && box1.top()==4, |
63 | 63 |
"Wrong addition of points to dim2::Box."); |
64 | 64 |
|
65 | 65 |
check(box1.inside(Point(2,3)), "Wrong inside() in dim2::Box."); |
66 | 66 |
check(box1.inside(Point(1,3)), "Wrong inside() in dim2::Box."); |
67 | 67 |
check(!box1.inside(Point(0,3)), "Wrong inside() in dim2::Box."); |
68 | 68 |
|
69 | 69 |
Box box2(Point(2,2)); |
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- |
|
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 <iostream> |
20 | 20 |
|
21 | 21 |
#include <lemon/error.h> |
22 | 22 |
#include "test_tools.h" |
23 | 23 |
|
24 | 24 |
using namespace lemon; |
25 | 25 |
|
26 | 26 |
#ifdef LEMON_ENABLE_ASSERTS |
27 | 27 |
#undef LEMON_ENABLE_ASSERTS |
28 | 28 |
#endif |
29 | 29 |
|
30 | 30 |
#ifdef LEMON_DISABLE_ASSERTS |
31 | 31 |
#undef LEMON_DISABLE_ASSERTS |
32 | 32 |
#endif |
33 | 33 |
|
34 | 34 |
#ifdef NDEBUG |
35 | 35 |
#undef NDEBUG |
36 | 36 |
#endif |
37 | 37 |
|
38 | 38 |
//checking disabled asserts |
39 | 39 |
#define LEMON_DISABLE_ASSERTS |
40 | 40 |
#include <lemon/assert.h> |
41 | 41 |
|
42 | 42 |
void no_assertion_text_disable() { |
43 | 43 |
LEMON_ASSERT(true, "This is a fault message"); |
44 | 44 |
} |
45 | 45 |
|
46 | 46 |
void assertion_text_disable() { |
47 | 47 |
LEMON_ASSERT(false, "This is a fault message"); |
48 | 48 |
} |
49 | 49 |
|
50 | 50 |
void check_assertion_disable() { |
51 | 51 |
no_assertion_text_disable(); |
52 | 52 |
assertion_text_disable(); |
53 | 53 |
} |
54 | 54 |
#undef LEMON_DISABLE_ASSERTS |
55 | 55 |
|
56 | 56 |
//checking custom assert handler |
57 | 57 |
#define LEMON_ASSERT_CUSTOM |
58 | 58 |
|
59 | 59 |
static int cnt = 0; |
60 | 60 |
void my_assert_handler(const char*, int, const char*, |
61 | 61 |
const char*, const char*) { |
62 | 62 |
++cnt; |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
#define LEMON_CUSTOM_ASSERT_HANDLER my_assert_handler |
66 | 66 |
#include <lemon/assert.h> |
67 | 67 |
|
68 | 68 |
void no_assertion_text_custom() { |
69 | 69 |
LEMON_ASSERT(true, "This is a fault message"); |
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- |
|
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<iostream> |
20 | 20 |
#include<lemon/concept_check.h> |
21 | 21 |
|
22 | 22 |
#include<lemon/list_graph.h> |
23 | 23 |
#include<lemon/smart_graph.h> |
24 | 24 |
|
25 | 25 |
#include<lemon/concepts/digraph.h> |
26 | 26 |
#include<lemon/concepts/graph.h> |
27 | 27 |
|
28 | 28 |
#include<lemon/adaptors.h> |
29 | 29 |
|
30 | 30 |
#include <limits> |
31 | 31 |
#include <lemon/bfs.h> |
32 | 32 |
#include <lemon/path.h> |
33 | 33 |
|
34 | 34 |
#include"test/test_tools.h" |
35 | 35 |
#include"test/graph_test.h" |
36 | 36 |
|
37 | 37 |
using namespace lemon; |
38 | 38 |
|
39 | 39 |
void checkReverseDigraph() { |
40 | 40 |
checkConcept<concepts::Digraph, ReverseDigraph<concepts::Digraph> >(); |
41 | 41 |
|
42 | 42 |
typedef ListDigraph Digraph; |
43 | 43 |
typedef ReverseDigraph<Digraph> Adaptor; |
44 | 44 |
|
45 | 45 |
Digraph digraph; |
46 | 46 |
Adaptor adaptor(digraph); |
47 | 47 |
|
48 | 48 |
Digraph::Node n1 = digraph.addNode(); |
49 | 49 |
Digraph::Node n2 = digraph.addNode(); |
50 | 50 |
Digraph::Node n3 = digraph.addNode(); |
51 | 51 |
|
52 | 52 |
Digraph::Arc a1 = digraph.addArc(n1, n2); |
53 | 53 |
Digraph::Arc a2 = digraph.addArc(n1, n3); |
54 | 54 |
Digraph::Arc a3 = digraph.addArc(n2, n3); |
55 | 55 |
|
56 | 56 |
checkGraphNodeList(adaptor, 3); |
57 | 57 |
checkGraphArcList(adaptor, 3); |
58 | 58 |
checkGraphConArcList(adaptor, 3); |
59 | 59 |
|
60 | 60 |
checkGraphOutArcList(adaptor, n1, 0); |
61 | 61 |
checkGraphOutArcList(adaptor, n2, 1); |
62 | 62 |
checkGraphOutArcList(adaptor, n3, 2); |
63 | 63 |
|
64 | 64 |
checkGraphInArcList(adaptor, n1, 2); |
65 | 65 |
checkGraphInArcList(adaptor, n2, 1); |
66 | 66 |
checkGraphInArcList(adaptor, n3, 0); |
67 | 67 |
|
68 | 68 |
checkNodeIds(adaptor); |
69 | 69 |
checkArcIds(adaptor); |
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- |
|
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/smart_graph.h> |
20 | 20 |
#include <lemon/list_graph.h> |
21 | 21 |
#include <lemon/lgf_reader.h> |
22 | 22 |
#include <lemon/error.h> |
23 | 23 |
|
24 | 24 |
#include "test_tools.h" |
25 | 25 |
|
26 | 26 |
using namespace std; |
27 | 27 |
using namespace lemon; |
28 | 28 |
|
29 | 29 |
void digraph_copy_test() { |
30 | 30 |
const int nn = 10; |
31 | 31 |
|
32 | 32 |
SmartDigraph from; |
33 | 33 |
SmartDigraph::NodeMap<int> fnm(from); |
34 | 34 |
SmartDigraph::ArcMap<int> fam(from); |
35 | 35 |
SmartDigraph::Node fn = INVALID; |
36 | 36 |
SmartDigraph::Arc fa = INVALID; |
37 | 37 |
|
38 | 38 |
std::vector<SmartDigraph::Node> fnv; |
39 | 39 |
for (int i = 0; i < nn; ++i) { |
40 | 40 |
SmartDigraph::Node node = from.addNode(); |
41 | 41 |
fnv.push_back(node); |
42 | 42 |
fnm[node] = i * i; |
43 | 43 |
if (i == 0) fn = node; |
44 | 44 |
} |
45 | 45 |
|
46 | 46 |
for (int i = 0; i < nn; ++i) { |
47 | 47 |
for (int j = 0; j < nn; ++j) { |
48 | 48 |
SmartDigraph::Arc arc = from.addArc(fnv[i], fnv[j]); |
49 | 49 |
fam[arc] = i + j * j; |
50 | 50 |
if (i == 0 && j == 0) fa = arc; |
51 | 51 |
} |
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
ListDigraph to; |
55 | 55 |
ListDigraph::NodeMap<int> tnm(to); |
56 | 56 |
ListDigraph::ArcMap<int> tam(to); |
57 | 57 |
ListDigraph::Node tn; |
58 | 58 |
ListDigraph::Arc ta; |
59 | 59 |
|
60 | 60 |
SmartDigraph::NodeMap<ListDigraph::Node> nr(from); |
61 | 61 |
SmartDigraph::ArcMap<ListDigraph::Arc> er(from); |
62 | 62 |
|
63 | 63 |
ListDigraph::NodeMap<SmartDigraph::Node> ncr(to); |
64 | 64 |
ListDigraph::ArcMap<SmartDigraph::Arc> ecr(to); |
65 | 65 |
|
66 | 66 |
digraphCopy(from, to). |
67 | 67 |
nodeMap(fnm, tnm).arcMap(fam, tam). |
68 | 68 |
nodeRef(nr).arcRef(er). |
69 | 69 |
nodeCrossRef(ncr).arcCrossRef(ecr). |
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- |
|
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/concepts/graph.h> |
20 | 20 |
#include <lemon/list_graph.h> |
21 | 21 |
#include <lemon/smart_graph.h> |
22 | 22 |
#include <lemon/full_graph.h> |
23 | 23 |
#include <lemon/grid_graph.h> |
24 | 24 |
#include <lemon/hypercube_graph.h> |
25 | 25 |
|
26 | 26 |
#include "test_tools.h" |
27 | 27 |
#include "graph_test.h" |
28 | 28 |
|
29 | 29 |
using namespace lemon; |
30 | 30 |
using namespace lemon::concepts; |
31 | 31 |
|
32 | 32 |
template <class Graph> |
33 | 33 |
void checkGraphBuild() { |
34 | 34 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
35 | 35 |
|
36 | 36 |
Graph G; |
37 | 37 |
checkGraphNodeList(G, 0); |
38 | 38 |
checkGraphEdgeList(G, 0); |
39 | 39 |
checkGraphArcList(G, 0); |
40 | 40 |
|
41 | 41 |
Node |
42 | 42 |
n1 = G.addNode(), |
43 | 43 |
n2 = G.addNode(), |
44 | 44 |
n3 = G.addNode(); |
45 | 45 |
checkGraphNodeList(G, 3); |
46 | 46 |
checkGraphEdgeList(G, 0); |
47 | 47 |
checkGraphArcList(G, 0); |
48 | 48 |
|
49 | 49 |
Edge e1 = G.addEdge(n1, n2); |
50 | 50 |
check((G.u(e1) == n1 && G.v(e1) == n2) || (G.u(e1) == n2 && G.v(e1) == n1), |
51 | 51 |
"Wrong edge"); |
52 | 52 |
|
53 | 53 |
checkGraphNodeList(G, 3); |
54 | 54 |
checkGraphEdgeList(G, 1); |
55 | 55 |
checkGraphArcList(G, 2); |
56 | 56 |
|
57 | 57 |
checkGraphIncEdgeArcLists(G, n1, 1); |
58 | 58 |
checkGraphIncEdgeArcLists(G, n2, 1); |
59 | 59 |
checkGraphIncEdgeArcLists(G, n3, 0); |
60 | 60 |
|
61 | 61 |
checkGraphConEdgeList(G, 1); |
62 | 62 |
checkGraphConArcList(G, 2); |
63 | 63 |
|
64 | 64 |
Edge e2 = G.addEdge(n2, n1), |
65 | 65 |
e3 = G.addEdge(n2, n3); |
66 | 66 |
|
67 | 67 |
checkGraphNodeList(G, 3); |
68 | 68 |
checkGraphEdgeList(G, 3); |
69 | 69 |
checkGraphArcList(G, 6); |
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- |
|
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_TEST_GRAPH_TEST_H |
20 | 20 |
#define LEMON_TEST_GRAPH_TEST_H |
21 | 21 |
|
22 | 22 |
#include <set> |
23 | 23 |
|
24 | 24 |
#include <lemon/core.h> |
25 | 25 |
#include <lemon/maps.h> |
26 | 26 |
|
27 | 27 |
#include "test_tools.h" |
28 | 28 |
|
29 | 29 |
namespace lemon { |
30 | 30 |
|
31 | 31 |
template<class Graph> |
32 | 32 |
void checkGraphNodeList(const Graph &G, int cnt) |
33 | 33 |
{ |
34 | 34 |
typename Graph::NodeIt n(G); |
35 | 35 |
for(int i=0;i<cnt;i++) { |
36 | 36 |
check(n!=INVALID,"Wrong Node list linking."); |
37 | 37 |
++n; |
38 | 38 |
} |
39 | 39 |
check(n==INVALID,"Wrong Node list linking."); |
40 | 40 |
check(countNodes(G)==cnt,"Wrong Node number."); |
41 | 41 |
} |
42 | 42 |
|
43 | 43 |
template<class Graph> |
44 | 44 |
void checkGraphArcList(const Graph &G, int cnt) |
45 | 45 |
{ |
46 | 46 |
typename Graph::ArcIt e(G); |
47 | 47 |
for(int i=0;i<cnt;i++) { |
48 | 48 |
check(e!=INVALID,"Wrong Arc list linking."); |
49 | 49 |
check(G.oppositeNode(G.source(e), e) == G.target(e), |
50 | 50 |
"Wrong opposite node"); |
51 | 51 |
check(G.oppositeNode(G.target(e), e) == G.source(e), |
52 | 52 |
"Wrong opposite node"); |
53 | 53 |
++e; |
54 | 54 |
} |
55 | 55 |
check(e==INVALID,"Wrong Arc list linking."); |
56 | 56 |
check(countArcs(G)==cnt,"Wrong Arc number."); |
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
template<class Graph> |
60 | 60 |
void checkGraphOutArcList(const Graph &G, typename Graph::Node n, int cnt) |
61 | 61 |
{ |
62 | 62 |
typename Graph::OutArcIt e(G,n); |
63 | 63 |
for(int i=0;i<cnt;i++) { |
64 | 64 |
check(e!=INVALID,"Wrong OutArc list linking."); |
65 | 65 |
check(n==G.source(e),"Wrong OutArc list linking."); |
66 | 66 |
check(n==G.baseNode(e),"Wrong OutArc list linking."); |
67 | 67 |
check(G.target(e)==G.runningNode(e),"Wrong OutArc list linking."); |
68 | 68 |
++e; |
69 | 69 |
} |
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- |
|
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 <cstdlib> |
20 | 20 |
#include <ctime> |
21 | 21 |
|
22 | 22 |
#include <lemon/random.h> |
23 | 23 |
#include <lemon/list_graph.h> |
24 | 24 |
#include <lemon/smart_graph.h> |
25 | 25 |
#include <lemon/maps.h> |
26 | 26 |
|
27 | 27 |
#include "graph_test.h" |
28 | 28 |
#include "test_tools.h" |
29 | 29 |
|
30 | 30 |
using namespace lemon; |
31 | 31 |
|
32 | 32 |
template <typename Digraph> |
33 | 33 |
void checkFindArcs() { |
34 | 34 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
35 | 35 |
|
36 | 36 |
{ |
37 | 37 |
Digraph digraph; |
38 | 38 |
for (int i = 0; i < 10; ++i) { |
39 | 39 |
digraph.addNode(); |
40 | 40 |
} |
41 | 41 |
DescriptorMap<Digraph, Node> nodes(digraph); |
42 | 42 |
typename DescriptorMap<Digraph, Node>::InverseMap invNodes(nodes); |
43 | 43 |
for (int i = 0; i < 100; ++i) { |
44 | 44 |
int src = rnd[invNodes.size()]; |
45 | 45 |
int trg = rnd[invNodes.size()]; |
46 | 46 |
digraph.addArc(invNodes[src], invNodes[trg]); |
47 | 47 |
} |
48 | 48 |
typename Digraph::template ArcMap<bool> found(digraph, false); |
49 | 49 |
DescriptorMap<Digraph, Arc> arcs(digraph); |
50 | 50 |
for (NodeIt src(digraph); src != INVALID; ++src) { |
51 | 51 |
for (NodeIt trg(digraph); trg != INVALID; ++trg) { |
52 | 52 |
for (ConArcIt<Digraph> con(digraph, src, trg); con != INVALID; ++con) { |
53 | 53 |
check(digraph.source(con) == src, "Wrong source."); |
54 | 54 |
check(digraph.target(con) == trg, "Wrong target."); |
55 | 55 |
check(found[con] == false, "The arc found already."); |
56 | 56 |
found[con] = true; |
57 | 57 |
} |
58 | 58 |
} |
59 | 59 |
} |
60 | 60 |
for (ArcIt it(digraph); it != INVALID; ++it) { |
61 | 61 |
check(found[it] == true, "The arc is not found."); |
62 | 62 |
} |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
{ |
66 | 66 |
int num = 5; |
67 | 67 |
Digraph fg; |
68 | 68 |
std::vector<Node> nodes; |
69 | 69 |
for (int i = 0; i < num; ++i) { |
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- |
|
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 <sstream> |
20 | 20 |
|
21 | 21 |
#include <lemon/smart_graph.h> |
22 | 22 |
#include <lemon/hao_orlin.h> |
23 | 23 |
|
24 | 24 |
#include <lemon/lgf_reader.h> |
25 | 25 |
#include "test_tools.h" |
26 | 26 |
|
27 | 27 |
using namespace lemon; |
28 | 28 |
using namespace std; |
29 | 29 |
|
30 | 30 |
const std::string lgf = |
31 | 31 |
"@nodes\n" |
32 | 32 |
"label\n" |
33 | 33 |
"0\n" |
34 | 34 |
"1\n" |
35 | 35 |
"2\n" |
36 | 36 |
"3\n" |
37 | 37 |
"4\n" |
38 | 38 |
"5\n" |
39 | 39 |
"@edges\n" |
40 | 40 |
" label capacity\n" |
41 | 41 |
"0 1 0 2\n" |
42 | 42 |
"1 2 1 2\n" |
43 | 43 |
"2 0 2 2\n" |
44 | 44 |
"3 4 3 2\n" |
45 | 45 |
"4 5 4 2\n" |
46 | 46 |
"5 3 5 2\n" |
47 | 47 |
"2 3 6 3\n"; |
48 | 48 |
|
49 | 49 |
int main() { |
50 | 50 |
SmartGraph graph; |
51 | 51 |
SmartGraph::EdgeMap<int> capacity(graph); |
52 | 52 |
|
53 | 53 |
istringstream lgfs(lgf); |
54 | 54 |
graphReader(graph, lgfs). |
55 | 55 |
edgeMap("capacity", capacity).run(); |
56 | 56 |
|
57 | 57 |
HaoOrlin<SmartGraph, SmartGraph::EdgeMap<int> > ho(graph, capacity); |
58 | 58 |
ho.run(); |
59 | 59 |
|
60 | 60 |
check(ho.minCutValue() == 3, "Wrong cut value"); |
61 | 61 |
|
62 | 62 |
return 0; |
63 | 63 |
} |
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- |
|
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 <iostream> |
20 | 20 |
#include <fstream> |
21 | 21 |
#include <string> |
22 | 22 |
#include <vector> |
23 | 23 |
|
24 | 24 |
#include <lemon/concept_check.h> |
25 | 25 |
#include <lemon/concepts/heap.h> |
26 | 26 |
|
27 | 27 |
#include <lemon/smart_graph.h> |
28 | 28 |
|
29 | 29 |
#include <lemon/lgf_reader.h> |
30 | 30 |
#include <lemon/dijkstra.h> |
31 | 31 |
#include <lemon/maps.h> |
32 | 32 |
|
33 | 33 |
#include <lemon/bin_heap.h> |
34 | 34 |
|
35 | 35 |
#include "test_tools.h" |
36 | 36 |
|
37 | 37 |
using namespace lemon; |
38 | 38 |
using namespace lemon::concepts; |
39 | 39 |
|
40 | 40 |
typedef ListDigraph Digraph; |
41 | 41 |
DIGRAPH_TYPEDEFS(Digraph); |
42 | 42 |
|
43 | 43 |
char test_lgf[] = |
44 | 44 |
"@nodes\n" |
45 | 45 |
"label\n" |
46 | 46 |
"0\n" |
47 | 47 |
"1\n" |
48 | 48 |
"2\n" |
49 | 49 |
"3\n" |
50 | 50 |
"4\n" |
51 | 51 |
"5\n" |
52 | 52 |
"6\n" |
53 | 53 |
"7\n" |
54 | 54 |
"8\n" |
55 | 55 |
"9\n" |
56 | 56 |
"@arcs\n" |
57 | 57 |
" label capacity\n" |
58 | 58 |
"0 5 0 94\n" |
59 | 59 |
"3 9 1 11\n" |
60 | 60 |
"8 7 2 83\n" |
61 | 61 |
"1 2 3 94\n" |
62 | 62 |
"5 7 4 35\n" |
63 | 63 |
"7 4 5 84\n" |
64 | 64 |
"9 5 6 38\n" |
65 | 65 |
"0 4 7 96\n" |
66 | 66 |
"6 7 8 6\n" |
67 | 67 |
"3 1 9 27\n" |
68 | 68 |
"5 2 10 77\n" |
69 | 69 |
"5 6 11 69\n" |
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- |
|
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 <iostream> |
20 | 20 |
#include <vector> |
21 | 21 |
|
22 | 22 |
#include "test_tools.h" |
23 | 23 |
#include <lemon/maps.h> |
24 | 24 |
#include <lemon/kruskal.h> |
25 | 25 |
#include <lemon/list_graph.h> |
26 | 26 |
|
27 | 27 |
#include <lemon/concepts/maps.h> |
28 | 28 |
#include <lemon/concepts/digraph.h> |
29 | 29 |
#include <lemon/concepts/graph.h> |
30 | 30 |
|
31 | 31 |
using namespace std; |
32 | 32 |
using namespace lemon; |
33 | 33 |
|
34 | 34 |
void checkCompileKruskal() |
35 | 35 |
{ |
36 | 36 |
concepts::WriteMap<concepts::Digraph::Arc,bool> w; |
37 | 37 |
concepts::WriteMap<concepts::Graph::Edge,bool> uw; |
38 | 38 |
|
39 | 39 |
concepts::ReadMap<concepts::Digraph::Arc,int> r; |
40 | 40 |
concepts::ReadMap<concepts::Graph::Edge,int> ur; |
41 | 41 |
|
42 | 42 |
concepts::Digraph g; |
43 | 43 |
concepts::Graph ug; |
44 | 44 |
|
45 | 45 |
kruskal(g, r, w); |
46 | 46 |
kruskal(ug, ur, uw); |
47 | 47 |
|
48 | 48 |
std::vector<std::pair<concepts::Digraph::Arc, int> > rs; |
49 | 49 |
std::vector<std::pair<concepts::Graph::Edge, int> > urs; |
50 | 50 |
|
51 | 51 |
kruskal(g, rs, w); |
52 | 52 |
kruskal(ug, urs, uw); |
53 | 53 |
|
54 | 54 |
std::vector<concepts::Digraph::Arc> ws; |
55 | 55 |
std::vector<concepts::Graph::Edge> uws; |
56 | 56 |
|
57 | 57 |
kruskal(g, r, ws.begin()); |
58 | 58 |
kruskal(ug, ur, uws.begin()); |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
int main() { |
62 | 62 |
|
63 | 63 |
typedef ListGraph::Node Node; |
64 | 64 |
typedef ListGraph::Edge Edge; |
65 | 65 |
typedef ListGraph::NodeIt NodeIt; |
66 | 66 |
typedef ListGraph::ArcIt ArcIt; |
67 | 67 |
|
68 | 68 |
ListGraph G; |
69 | 69 |
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- |
|
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 <deque> |
20 | 20 |
#include <set> |
21 | 21 |
|
22 | 22 |
#include <lemon/concept_check.h> |
23 | 23 |
#include <lemon/concepts/maps.h> |
24 | 24 |
#include <lemon/maps.h> |
25 | 25 |
|
26 | 26 |
#include "test_tools.h" |
27 | 27 |
|
28 | 28 |
using namespace lemon; |
29 | 29 |
using namespace lemon::concepts; |
30 | 30 |
|
31 | 31 |
struct A {}; |
32 | 32 |
inline bool operator<(A, A) { return true; } |
33 | 33 |
struct B {}; |
34 | 34 |
|
35 | 35 |
class C { |
36 | 36 |
int x; |
37 | 37 |
public: |
38 | 38 |
C(int _x) : x(_x) {} |
39 | 39 |
}; |
40 | 40 |
|
41 | 41 |
class F { |
42 | 42 |
public: |
43 | 43 |
typedef A argument_type; |
44 | 44 |
typedef B result_type; |
45 | 45 |
|
46 | 46 |
B operator()(const A&) const { return B(); } |
47 | 47 |
private: |
48 | 48 |
F& operator=(const F&); |
49 | 49 |
}; |
50 | 50 |
|
51 | 51 |
int func(A) { return 3; } |
52 | 52 |
|
53 | 53 |
int binc(int a, B) { return a+1; } |
54 | 54 |
|
55 | 55 |
typedef ReadMap<A, double> DoubleMap; |
56 | 56 |
typedef ReadWriteMap<A, double> DoubleWriteMap; |
57 | 57 |
typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap; |
58 | 58 |
|
59 | 59 |
typedef ReadMap<A, bool> BoolMap; |
60 | 60 |
typedef ReadWriteMap<A, bool> BoolWriteMap; |
61 | 61 |
typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap; |
62 | 62 |
|
63 | 63 |
int main() |
64 | 64 |
{ |
65 | 65 |
// Map concepts |
66 | 66 |
checkConcept<ReadMap<A,B>, ReadMap<A,B> >(); |
67 | 67 |
checkConcept<ReadMap<A,C>, ReadMap<A,C> >(); |
68 | 68 |
checkConcept<WriteMap<A,B>, WriteMap<A,B> >(); |
69 | 69 |
checkConcept<WriteMap<A,C>, WriteMap<A,C> >(); |
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- |
|
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 <iostream> |
20 | 20 |
#include <sstream> |
21 | 21 |
#include <vector> |
22 | 22 |
#include <queue> |
23 | 23 |
#include <lemon/math.h> |
24 | 24 |
#include <cstdlib> |
25 | 25 |
|
26 | 26 |
#include <lemon/max_matching.h> |
27 | 27 |
#include <lemon/smart_graph.h> |
28 | 28 |
#include <lemon/lgf_reader.h> |
29 | 29 |
|
30 | 30 |
#include "test_tools.h" |
31 | 31 |
|
32 | 32 |
using namespace std; |
33 | 33 |
using namespace lemon; |
34 | 34 |
|
35 | 35 |
GRAPH_TYPEDEFS(SmartGraph); |
36 | 36 |
|
37 | 37 |
|
38 | 38 |
const int lgfn = 3; |
39 | 39 |
const std::string lgf[lgfn] = { |
40 | 40 |
"@nodes\n" |
41 | 41 |
"label\n" |
42 | 42 |
"0\n" |
43 | 43 |
"1\n" |
44 | 44 |
"2\n" |
45 | 45 |
"3\n" |
46 | 46 |
"4\n" |
47 | 47 |
"5\n" |
48 | 48 |
"6\n" |
49 | 49 |
"7\n" |
50 | 50 |
"@edges\n" |
51 | 51 |
" label weight\n" |
52 | 52 |
"7 4 0 984\n" |
53 | 53 |
"0 7 1 73\n" |
54 | 54 |
"7 1 2 204\n" |
55 | 55 |
"2 3 3 583\n" |
56 | 56 |
"2 7 4 565\n" |
57 | 57 |
"2 1 5 582\n" |
58 | 58 |
"0 4 6 551\n" |
59 | 59 |
"2 5 7 385\n" |
60 | 60 |
"1 5 8 561\n" |
61 | 61 |
"5 3 9 484\n" |
62 | 62 |
"7 5 10 904\n" |
63 | 63 |
"3 6 11 47\n" |
64 | 64 |
"7 6 12 888\n" |
65 | 65 |
"3 0 13 747\n" |
66 | 66 |
"6 1 14 310\n", |
67 | 67 |
|
68 | 68 |
"@nodes\n" |
69 | 69 |
"label\n" |
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- |
|
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 <string> |
20 | 20 |
#include <iostream> |
21 | 21 |
|
22 | 22 |
#include <lemon/concepts/path.h> |
23 | 23 |
#include <lemon/concepts/digraph.h> |
24 | 24 |
|
25 | 25 |
#include <lemon/path.h> |
26 | 26 |
#include <lemon/list_graph.h> |
27 | 27 |
|
28 | 28 |
#include "test_tools.h" |
29 | 29 |
|
30 | 30 |
using namespace std; |
31 | 31 |
using namespace lemon; |
32 | 32 |
|
33 | 33 |
void check_concepts() { |
34 | 34 |
checkConcept<concepts::Path<ListDigraph>, concepts::Path<ListDigraph> >(); |
35 | 35 |
checkConcept<concepts::Path<ListDigraph>, Path<ListDigraph> >(); |
36 | 36 |
checkConcept<concepts::Path<ListDigraph>, SimplePath<ListDigraph> >(); |
37 | 37 |
checkConcept<concepts::Path<ListDigraph>, StaticPath<ListDigraph> >(); |
38 | 38 |
checkConcept<concepts::Path<ListDigraph>, ListPath<ListDigraph> >(); |
39 | 39 |
} |
40 | 40 |
|
41 | 41 |
int main() { |
42 | 42 |
check_concepts(); |
43 | 43 |
return 0; |
44 | 44 |
} |
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- |
|
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 <iostream> |
20 | 20 |
|
21 | 21 |
#include "test_tools.h" |
22 | 22 |
#include <lemon/smart_graph.h> |
23 | 23 |
#include <lemon/preflow.h> |
24 | 24 |
#include <lemon/concepts/digraph.h> |
25 | 25 |
#include <lemon/concepts/maps.h> |
26 | 26 |
#include <lemon/lgf_reader.h> |
27 | 27 |
#include <lemon/elevator.h> |
28 | 28 |
|
29 | 29 |
using namespace lemon; |
30 | 30 |
|
31 | 31 |
char test_lgf[] = |
32 | 32 |
"@nodes\n" |
33 | 33 |
"label\n" |
34 | 34 |
"0\n" |
35 | 35 |
"1\n" |
36 | 36 |
"2\n" |
37 | 37 |
"3\n" |
38 | 38 |
"4\n" |
39 | 39 |
"5\n" |
40 | 40 |
"6\n" |
41 | 41 |
"7\n" |
42 | 42 |
"8\n" |
43 | 43 |
"9\n" |
44 | 44 |
"@arcs\n" |
45 | 45 |
" label capacity\n" |
46 | 46 |
"0 1 0 20\n" |
47 | 47 |
"0 2 1 0\n" |
48 | 48 |
"1 1 2 3\n" |
49 | 49 |
"1 2 3 8\n" |
50 | 50 |
"1 3 4 8\n" |
51 | 51 |
"2 5 5 5\n" |
52 | 52 |
"3 2 6 5\n" |
53 | 53 |
"3 5 7 5\n" |
54 | 54 |
"3 6 8 5\n" |
55 | 55 |
"4 3 9 3\n" |
56 | 56 |
"5 7 10 3\n" |
57 | 57 |
"5 6 11 10\n" |
58 | 58 |
"5 8 12 10\n" |
59 | 59 |
"6 8 13 8\n" |
60 | 60 |
"8 9 14 20\n" |
61 | 61 |
"8 1 15 5\n" |
62 | 62 |
"9 5 16 5\n" |
63 | 63 |
"@attributes\n" |
64 | 64 |
"source 1\n" |
65 | 65 |
"target 8\n"; |
66 | 66 |
|
67 | 67 |
void checkPreflowCompile() |
68 | 68 |
{ |
69 | 69 |
typedef int VType; |
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- |
|
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/random.h> |
20 | 20 |
#include "test_tools.h" |
21 | 21 |
|
22 | 22 |
int seed_array[] = {1, 2}; |
23 | 23 |
|
24 | 24 |
int main() |
25 | 25 |
{ |
26 | 26 |
double a=lemon::rnd(); |
27 | 27 |
check(a<1.0&&a>0.0,"This should be in [0,1)"); |
28 | 28 |
a=lemon::rnd.gauss(); |
29 | 29 |
a=lemon::rnd.gamma(3.45,0); |
30 | 30 |
a=lemon::rnd.gamma(4); |
31 | 31 |
//Does gamma work with integer k? |
32 | 32 |
a=lemon::rnd.gamma(4.0,0); |
33 | 33 |
a=lemon::rnd.poisson(.5); |
34 | 34 |
|
35 | 35 |
lemon::rnd.seed(100); |
36 | 36 |
lemon::rnd.seed(seed_array, seed_array + |
37 | 37 |
(sizeof(seed_array) / sizeof(seed_array[0]))); |
38 | 38 |
|
39 | 39 |
return 0; |
40 | 40 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
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 <iostream> |
20 | 20 |
|
21 | 21 |
#include <lemon/list_graph.h> |
22 | 22 |
#include <lemon/lgf_reader.h> |
23 | 23 |
#include <lemon/path.h> |
24 | 24 |
#include <lemon/suurballe.h> |
25 | 25 |
|
26 | 26 |
#include "test_tools.h" |
27 | 27 |
|
28 | 28 |
using namespace lemon; |
29 | 29 |
|
30 | 30 |
char test_lgf[] = |
31 | 31 |
"@nodes\n" |
32 | 32 |
"label supply1 supply2 supply3\n" |
33 | 33 |
"1 0 20 27\n" |
34 | 34 |
"2 0 -4 0\n" |
35 | 35 |
"3 0 0 0\n" |
36 | 36 |
"4 0 0 0\n" |
37 | 37 |
"5 0 9 0\n" |
38 | 38 |
"6 0 -6 0\n" |
39 | 39 |
"7 0 0 0\n" |
40 | 40 |
"8 0 0 0\n" |
41 | 41 |
"9 0 3 0\n" |
42 | 42 |
"10 0 -2 0\n" |
43 | 43 |
"11 0 0 0\n" |
44 | 44 |
"12 0 -20 -27\n" |
45 | 45 |
"@arcs\n" |
46 | 46 |
" cost capacity lower1 lower2\n" |
47 | 47 |
" 1 2 70 11 0 8\n" |
48 | 48 |
" 1 3 150 3 0 1\n" |
49 | 49 |
" 1 4 80 15 0 2\n" |
50 | 50 |
" 2 8 80 12 0 0\n" |
51 | 51 |
" 3 5 140 5 0 3\n" |
52 | 52 |
" 4 6 60 10 0 1\n" |
53 | 53 |
" 4 7 80 2 0 0\n" |
54 | 54 |
" 4 8 110 3 0 0\n" |
55 | 55 |
" 5 7 60 14 0 0\n" |
56 | 56 |
" 5 11 120 12 0 0\n" |
57 | 57 |
" 6 3 0 3 0 0\n" |
58 | 58 |
" 6 9 140 4 0 0\n" |
59 | 59 |
" 6 10 90 8 0 0\n" |
60 | 60 |
" 7 1 30 5 0 0\n" |
61 | 61 |
" 8 12 60 16 0 4\n" |
62 | 62 |
" 9 12 50 6 0 0\n" |
63 | 63 |
"10 12 70 13 0 5\n" |
64 | 64 |
"10 2 100 7 0 0\n" |
65 | 65 |
"10 7 60 10 0 0\n" |
66 | 66 |
"11 10 20 14 0 6\n" |
67 | 67 |
"12 11 30 10 0 0\n" |
68 | 68 |
"@attributes\n" |
69 | 69 |
"source 1\n" |
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- |
|
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_TEST_TEST_TOOLS_H |
20 | 20 |
#define LEMON_TEST_TEST_TOOLS_H |
21 | 21 |
|
22 | 22 |
///\ingroup misc |
23 | 23 |
///\file |
24 | 24 |
///\brief Some utilities to write test programs. |
25 | 25 |
|
26 | 26 |
#include <iostream> |
27 | 27 |
#include <stdlib.h> |
28 | 28 |
|
29 | 29 |
///If \c rc is fail, writes an error message and exits. |
30 | 30 |
|
31 | 31 |
///If \c rc is fail, writes an error message and exits. |
32 | 32 |
///The error message contains the file name and the line number of the |
33 | 33 |
///source code in a standard from, which makes it possible to go there |
34 | 34 |
///using good source browsers like e.g. \c emacs. |
35 | 35 |
/// |
36 | 36 |
///For example |
37 | 37 |
///\code check(0==1,"This is obviously false.");\endcode will |
38 | 38 |
///print something like this (and then exits). |
39 | 39 |
///\verbatim file_name.cc:123: error: This is obviously false. \endverbatim |
40 | 40 |
#define check(rc, msg) \ |
41 | 41 |
if(!(rc)) { \ |
42 | 42 |
std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \ |
43 | 43 |
abort(); \ |
44 | 44 |
} else { } \ |
45 | 45 |
|
46 | 46 |
#endif |
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- |
|
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 "test_tools.h" |
20 | 20 |
|
21 | 21 |
int main() |
22 | 22 |
{ |
23 | 23 |
check(false, "Don't panic. Failing is the right behaviour here."); |
24 | 24 |
return 0; |
25 | 25 |
} |
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- |
|
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 "test_tools.h" |
20 | 20 |
|
21 | 21 |
int main() |
22 | 22 |
{ |
23 | 23 |
check(true, "It should pass."); |
24 | 24 |
return 0; |
25 | 25 |
} |
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- |
|
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/time_measure.h> |
20 | 20 |
|
21 | 21 |
using namespace lemon; |
22 | 22 |
|
23 | 23 |
void f() |
24 | 24 |
{ |
25 | 25 |
double d=0; |
26 | 26 |
for(int i=0;i<1000;i++) |
27 | 27 |
d+=0.1; |
28 | 28 |
} |
29 | 29 |
|
30 | 30 |
void g() |
31 | 31 |
{ |
32 | 32 |
static Timer T; |
33 | 33 |
|
34 | 34 |
for(int i=0;i<1000;i++) |
35 | 35 |
TimeStamp x(T); |
36 | 36 |
} |
37 | 37 |
|
38 | 38 |
int main() |
39 | 39 |
{ |
40 | 40 |
Timer T; |
41 | 41 |
unsigned int n; |
42 | 42 |
for(n=0;T.realTime()<1.0;n++) ; |
43 | 43 |
std::cout << T << " (" << n << " time queries)\n"; |
44 | 44 |
T.restart(); |
45 | 45 |
while(T.realTime()<2.0) ; |
46 | 46 |
std::cout << T << '\n'; |
47 | 47 |
TimeStamp full; |
48 | 48 |
TimeStamp t; |
49 | 49 |
t=runningTimeTest(f,1,&n,&full); |
50 | 50 |
std::cout << t << " (" << n << " tests)\n"; |
51 | 51 |
std::cout << "Total: " << full << "\n"; |
52 | 52 |
|
53 | 53 |
t=runningTimeTest(g,1,&n,&full); |
54 | 54 |
std::cout << t << " (" << n << " tests)\n"; |
55 | 55 |
std::cout << "Total: " << full << "\n"; |
56 | 56 |
|
57 | 57 |
return 0; |
58 | 58 |
} |
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- |
|
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/list_graph.h> |
20 | 20 |
#include <lemon/maps.h> |
21 | 21 |
#include <lemon/unionfind.h> |
22 | 22 |
#include "test_tools.h" |
23 | 23 |
|
24 | 24 |
using namespace lemon; |
25 | 25 |
using namespace std; |
26 | 26 |
|
27 | 27 |
typedef UnionFindEnum<ListGraph::NodeMap<int> > UFE; |
28 | 28 |
|
29 | 29 |
int main() { |
30 | 30 |
ListGraph g; |
31 | 31 |
ListGraph::NodeMap<int> base(g); |
32 | 32 |
UFE U(base); |
33 | 33 |
vector<ListGraph::Node> n; |
34 | 34 |
|
35 | 35 |
for(int i=0;i<20;i++) n.push_back(g.addNode()); |
36 | 36 |
|
37 | 37 |
U.insert(n[1]); |
38 | 38 |
U.insert(n[2]); |
39 | 39 |
|
40 | 40 |
check(U.join(n[1],n[2]) != -1, "Something is wrong with UnionFindEnum"); |
41 | 41 |
|
42 | 42 |
U.insert(n[3]); |
43 | 43 |
U.insert(n[4]); |
44 | 44 |
U.insert(n[5]); |
45 | 45 |
U.insert(n[6]); |
46 | 46 |
U.insert(n[7]); |
47 | 47 |
|
48 | 48 |
|
49 | 49 |
check(U.join(n[1],n[4]) != -1, "Something is wrong with UnionFindEnum"); |
50 | 50 |
check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum"); |
51 | 51 |
check(U.join(n[3],n[5]) != -1, "Something is wrong with UnionFindEnum"); |
52 | 52 |
|
53 | 53 |
|
54 | 54 |
U.insert(n[8],U.find(n[5])); |
55 | 55 |
|
56 | 56 |
|
57 | 57 |
check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); |
58 | 58 |
check(U.size(U.find(n[5])) == 3, "Something is wrong with UnionFindEnum"); |
59 | 59 |
check(U.size(U.find(n[6])) == 1, "Something is wrong with UnionFindEnum"); |
60 | 60 |
check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum"); |
61 | 61 |
|
62 | 62 |
|
63 | 63 |
U.insert(n[9]); |
64 | 64 |
U.insert(n[10],U.find(n[9])); |
65 | 65 |
|
66 | 66 |
|
67 | 67 |
check(U.join(n[8],n[10]) != -1, "Something is wrong with UnionFindEnum"); |
68 | 68 |
|
69 | 69 |
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- |
|
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 tools |
20 | 20 |
///\file |
21 | 21 |
///\brief DIMACS to LGF converter. |
22 | 22 |
/// |
23 | 23 |
/// This program converts various DIMACS formats to the LEMON Digraph Format |
24 | 24 |
/// (LGF). |
25 | 25 |
/// |
26 | 26 |
/// See |
27 | 27 |
/// \verbatim |
28 | 28 |
/// dimacs-to-lgf --help |
29 | 29 |
/// \endverbatim |
30 | 30 |
/// for more info on usage. |
31 | 31 |
/// |
32 | 32 |
|
33 | 33 |
#include <iostream> |
34 | 34 |
#include <fstream> |
35 | 35 |
#include <cstring> |
36 | 36 |
|
37 | 37 |
#include <lemon/smart_graph.h> |
38 | 38 |
#include <lemon/dimacs.h> |
39 | 39 |
#include <lemon/lgf_writer.h> |
40 | 40 |
|
41 | 41 |
#include <lemon/arg_parser.h> |
42 | 42 |
#include <lemon/error.h> |
43 | 43 |
|
44 | 44 |
using namespace std; |
45 | 45 |
using namespace lemon; |
46 | 46 |
|
47 | 47 |
|
48 | 48 |
int main(int argc, const char *argv[]) { |
49 | 49 |
typedef SmartDigraph Digraph; |
50 | 50 |
|
51 | 51 |
typedef Digraph::Arc Arc; |
52 | 52 |
typedef Digraph::Node Node; |
53 | 53 |
typedef Digraph::ArcIt ArcIt; |
54 | 54 |
typedef Digraph::NodeIt NodeIt; |
55 | 55 |
typedef Digraph::ArcMap<double> DoubleArcMap; |
56 | 56 |
typedef Digraph::NodeMap<double> DoubleNodeMap; |
57 | 57 |
|
58 | 58 |
std::string inputName; |
59 | 59 |
std::string outputName; |
60 | 60 |
|
61 | 61 |
ArgParser ap(argc, argv); |
62 | 62 |
ap.other("[INFILE [OUTFILE]]", |
63 | 63 |
"If either the INFILE or OUTFILE file is missing the standard\n" |
64 | 64 |
" input/output will be used instead.") |
65 | 65 |
.run(); |
66 | 66 |
|
67 | 67 |
ifstream input; |
68 | 68 |
ofstream output; |
69 | 69 |
|
0 comments (0 inline)