!
!
!
3
3
52
52
4
4
137
137
86
86
44
44
229
229
44
44
109
109
16
16
147
147
36
37
111
111
Changeset was too big and was cut off... Show full diff
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -64,7 +64,7 @@ |
64 | 64 |
// Add non-parsed arguments (e.g. input files) |
65 | 65 |
ap.other("infile", "The input file.") |
66 | 66 |
.other("..."); |
67 |
|
|
67 |
|
|
68 | 68 |
// Perform the parsing process |
69 | 69 |
// (in case of any error it terminates the program) |
70 | 70 |
ap.parse(); |
... | ... |
@@ -84,7 +84,7 @@ |
84 | 84 |
if(ap.given("gra")) std::cout << " -gra is given\n"; |
85 | 85 |
if(ap.given("grb")) std::cout << " -grb is given\n"; |
86 | 86 |
if(ap.given("grc")) std::cout << " -grc is given\n"; |
87 |
|
|
87 |
|
|
88 | 88 |
switch(ap.files().size()) { |
89 | 89 |
case 0: |
90 | 90 |
std::cout << " No file argument was given.\n"; |
... | ... |
@@ -94,10 +94,10 @@ |
94 | 94 |
break; |
95 | 95 |
default: |
96 | 96 |
std::cout << " " |
97 |
|
|
97 |
<< ap.files().size() << " file arguments were given. They are:\n"; |
|
98 | 98 |
} |
99 | 99 |
for(unsigned int i=0;i<ap.files().size();++i) |
100 | 100 |
std::cout << " '" << ap.files()[i] << "'\n"; |
101 |
|
|
101 |
|
|
102 | 102 |
return 0; |
103 | 103 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -49,7 +49,7 @@ |
49 | 49 |
typedef ListDigraph::NodeIt NodeIt; |
50 | 50 |
typedef ListDigraph::Arc Arc; |
51 | 51 |
typedef dim2::Point<int> Point; |
52 |
|
|
52 |
|
|
53 | 53 |
Node n1=g.addNode(); |
54 | 54 |
Node n2=g.addNode(); |
55 | 55 |
Node n3=g.addNode(); |
... | ... |
@@ -62,13 +62,13 @@ |
62 | 62 |
ListDigraph::NodeMap<int> shapes(g); |
63 | 63 |
ListDigraph::ArcMap<int> acolors(g); |
64 | 64 |
ListDigraph::ArcMap<int> widths(g); |
65 |
|
|
65 |
|
|
66 | 66 |
coords[n1]=Point(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0; |
67 | 67 |
coords[n2]=Point(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=2; |
68 | 68 |
coords[n3]=Point(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0; |
69 | 69 |
coords[n4]=Point(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1; |
70 | 70 |
coords[n5]=Point(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=2; |
71 |
|
|
71 |
|
|
72 | 72 |
Arc a; |
73 | 73 |
|
74 | 74 |
a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1; |
... | ... |
@@ -78,7 +78,7 @@ |
78 | 78 |
a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1; |
79 | 79 |
a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2; |
80 | 80 |
a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1; |
81 |
|
|
81 |
|
|
82 | 82 |
IdMap<ListDigraph,Node> id(g); |
83 | 83 |
|
84 | 84 |
// Create five .eps files showing the digraph with different options |
... | ... |
@@ -182,14 +182,14 @@ |
182 | 182 |
ListDigraph h; |
183 | 183 |
ListDigraph::NodeMap<int> hcolors(h); |
184 | 184 |
ListDigraph::NodeMap<Point> hcoords(h); |
185 |
|
|
185 |
|
|
186 | 186 |
int cols=int(sqrt(double(palette.size()))); |
187 | 187 |
for(int i=0;i<int(paletteW.size());i++) { |
188 | 188 |
Node n=h.addNode(); |
189 | 189 |
hcoords[n]=Point(1+i%cols,1+i/cols); |
190 | 190 |
hcolors[n]=i; |
191 | 191 |
} |
192 |
|
|
192 |
|
|
193 | 193 |
cout << "Create 'graph_to_eps_demo_out_6_colors.eps'" << endl; |
194 | 194 |
graphToEps(h,"graph_to_eps_demo_out_6_colors.eps"). |
195 | 195 |
scale(60). |
... | ... |
@@ -202,6 +202,6 @@ |
202 | 202 |
nodeTexts(hcolors).nodeTextSize(.6). |
203 | 203 |
nodeColors(composeMap(paletteW,hcolors)). |
204 | 204 |
run(); |
205 |
|
|
205 |
|
|
206 | 206 |
return 0; |
207 | 207 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -21,7 +21,7 @@ |
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 |
/// and additional maps from/to a stream or a file using the |
|
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: |
... | ... |
@@ -42,7 +42,7 @@ |
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("digraph.lgf", g). // read the directed graph into g |
48 | 48 |
arcMap("capacity", cap). // read the 'capacity' arc map into cap |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -18,7 +18,7 @@ |
18 | 18 |
|
19 | 19 |
/*! |
20 | 20 |
|
21 |
\page coding_style LEMON Coding Style |
|
21 |
\page coding_style LEMON Coding Style |
|
22 | 22 |
|
23 | 23 |
\section naming_conv Naming Conventions |
24 | 24 |
|
... | ... |
@@ -68,7 +68,7 @@ |
68 | 68 |
The name of a class or any type should look like the following. |
69 | 69 |
|
70 | 70 |
\code |
71 |
AllWordsCapitalizedWithoutUnderscores |
|
71 |
AllWordsCapitalizedWithoutUnderscores |
|
72 | 72 |
\endcode |
73 | 73 |
|
74 | 74 |
\subsection cs-func Methods and other functions |
... | ... |
@@ -76,7 +76,7 @@ |
76 | 76 |
The name of a function should look like the following. |
77 | 77 |
|
78 | 78 |
\code |
79 |
firstWordLowerCaseRestCapitalizedWithoutUnderscores |
|
79 |
firstWordLowerCaseRestCapitalizedWithoutUnderscores |
|
80 | 80 |
\endcode |
81 | 81 |
|
82 | 82 |
\subsection cs-funcs Constants, Macros |
... | ... |
@@ -84,15 +84,15 @@ |
84 | 84 |
The names of constants and macros should look like the following. |
85 | 85 |
|
86 | 86 |
\code |
87 |
ALL_UPPER_CASE_WITH_UNDERSCORES |
|
87 |
ALL_UPPER_CASE_WITH_UNDERSCORES |
|
88 | 88 |
\endcode |
89 | 89 |
|
90 |
\subsection cs-loc-var Class and instance member variables, auto variables |
|
90 |
\subsection cs-loc-var Class and instance member variables, auto variables |
|
91 | 91 |
|
92 | 92 |
The names of class and instance member variables and auto variables (=variables used locally in methods) should look like the following. |
93 | 93 |
|
94 | 94 |
\code |
95 |
all_lower_case_with_underscores |
|
95 |
all_lower_case_with_underscores |
|
96 | 96 |
\endcode |
97 | 97 |
|
98 | 98 |
\subsection pri-loc-var Private member variables |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -74,6 +74,6 @@ |
74 | 74 |
\brief Implementation helper files |
75 | 75 |
|
76 | 76 |
This directory contains some helper classes to implement graphs, maps and |
77 |
some other classes. As a user you typically don't have to deal with these |
|
77 |
some other classes. As a user you typically don't have to deal with these |
|
78 | 78 |
files. |
79 | 79 |
*/ |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -26,10 +26,10 @@ |
26 | 26 |
@ingroup datas |
27 | 27 |
\brief Graph structures implemented in LEMON. |
28 | 28 |
|
29 |
The implementation of combinatorial algorithms heavily relies on |
|
30 |
efficient graph implementations. LEMON offers data structures which are |
|
31 |
planned to be easily used in an experimental phase of implementation studies, |
|
32 |
and thereafter the program code can be made efficient by small modifications. |
|
29 |
The implementation of combinatorial algorithms heavily relies on |
|
30 |
efficient graph implementations. LEMON offers data structures which are |
|
31 |
planned to be easily used in an experimental phase of implementation studies, |
|
32 |
and thereafter the program code can be made efficient by small modifications. |
|
33 | 33 |
|
34 | 34 |
The most efficient implementation of diverse applications require the |
35 | 35 |
usage of different physical graph implementations. These differences |
... | ... |
@@ -40,21 +40,21 @@ |
40 | 40 |
running time or on memory usage, some structures may fail to provide |
41 | 41 |
some graph features like arc/edge or node deletion. |
42 | 42 |
|
43 |
Alteration of standard containers need a very limited number of |
|
44 |
operations, these together satisfy the everyday requirements. |
|
45 |
In the case of graph structures, different operations are needed which do |
|
46 |
not alter the physical graph, but gives another view. If some nodes or |
|
43 |
Alteration of standard containers need a very limited number of |
|
44 |
operations, these together satisfy the everyday requirements. |
|
45 |
In the case of graph structures, different operations are needed which do |
|
46 |
not alter the physical graph, but gives another view. If some nodes or |
|
47 | 47 |
arcs have to be hidden or the reverse oriented graph have to be used, then |
48 |
this is the case. It also may happen that in a flow implementation |
|
49 |
the residual graph can be accessed by another algorithm, or a node-set |
|
50 |
is to be shrunk for another algorithm. |
|
51 |
LEMON also provides a variety of graphs for these requirements called |
|
52 |
\ref graph_adaptors "graph adaptors". Adaptors cannot be used alone but only |
|
53 |
in conjunction with other graph representations. |
|
48 |
this is the case. It also may happen that in a flow implementation |
|
49 |
the residual graph can be accessed by another algorithm, or a node-set |
|
50 |
is to be shrunk for another algorithm. |
|
51 |
LEMON also provides a variety of graphs for these requirements called |
|
52 |
\ref graph_adaptors "graph adaptors". Adaptors cannot be used alone but only |
|
53 |
in conjunction with other graph representations. |
|
54 | 54 |
|
55 | 55 |
You are free to use the graph structure that fit your requirements |
56 | 56 |
the best, most graph algorithms and auxiliary data structures can be used |
57 |
with any graph structures. |
|
57 |
with any graph structures. |
|
58 | 58 |
*/ |
59 | 59 |
|
60 | 60 |
/** |
... | ... |
@@ -63,12 +63,12 @@ |
63 | 63 |
\brief Graph types between real graphs and graph adaptors. |
64 | 64 |
|
65 | 65 |
This group describes some graph types between real graphs and graph adaptors. |
66 |
These classes wrap graphs to give new functionality as the adaptors do it. |
|
66 |
These classes wrap graphs to give new functionality as the adaptors do it. |
|
67 | 67 |
On the other hand they are not light-weight structures as the adaptors. |
68 | 68 |
*/ |
69 | 69 |
|
70 | 70 |
/** |
71 |
@defgroup maps Maps |
|
71 |
@defgroup maps Maps |
|
72 | 72 |
@ingroup datas |
73 | 73 |
\brief Map structures implemented in LEMON. |
74 | 74 |
|
... | ... |
@@ -79,7 +79,7 @@ |
79 | 79 |
*/ |
80 | 80 |
|
81 | 81 |
/** |
82 |
@defgroup graph_maps Graph Maps |
|
82 |
@defgroup graph_maps Graph Maps |
|
83 | 83 |
@ingroup maps |
84 | 84 |
\brief Special graph-related maps. |
85 | 85 |
|
... | ... |
@@ -115,14 +115,14 @@ |
115 | 115 |
return Color(0.0, 0.0, 0.0); |
116 | 116 |
} |
117 | 117 |
} |
118 |
|
|
118 |
|
|
119 | 119 |
Digraph::NodeMap<int> degree_map(graph); |
120 |
|
|
120 |
|
|
121 | 121 |
digraphToEps(graph, "graph.eps") |
122 | 122 |
.coords(coords).scaleToA4().undirected() |
123 | 123 |
.nodeColors(composeMap(functorToMap(nodeColor), degree_map)) |
124 | 124 |
.run(); |
125 |
\endcode |
|
125 |
\endcode |
|
126 | 126 |
The \c functorToMap() function makes an \c int to \c Color map from the |
127 | 127 |
\e nodeColor() function. The \c composeMap() compose the \e degree_map |
128 | 128 |
and the previously created map. The composed map is a proper function to |
... | ... |
@@ -140,7 +140,7 @@ |
140 | 140 |
|
141 | 141 |
typedef DivMap<DoubleArcMap, DoubleArcMap> TimeMap; |
142 | 142 |
TimeMap time(length, speed); |
143 |
|
|
143 |
|
|
144 | 144 |
Dijkstra<Digraph, TimeMap> dijkstra(graph, time); |
145 | 145 |
dijkstra.run(source, target); |
146 | 146 |
\endcode |
... | ... |
@@ -152,7 +152,7 @@ |
152 | 152 |
*/ |
153 | 153 |
|
154 | 154 |
/** |
155 |
@defgroup matrices Matrices |
|
155 |
@defgroup matrices Matrices |
|
156 | 156 |
@ingroup datas |
157 | 157 |
\brief Two dimensional data storages implemented in LEMON. |
158 | 158 |
|
... | ... |
@@ -200,7 +200,7 @@ |
200 | 200 |
@ingroup algs |
201 | 201 |
\brief Common graph search algorithms. |
202 | 202 |
|
203 |
This group describes the common graph search algorithms like |
|
203 |
This group describes the common graph search algorithms like |
|
204 | 204 |
Breadth-first search (Bfs) and Depth-first search (Dfs). |
205 | 205 |
*/ |
206 | 206 |
|
... | ... |
@@ -212,9 +212,9 @@ |
212 | 212 |
This group describes the algorithms for finding shortest paths in graphs. |
213 | 213 |
*/ |
214 | 214 |
|
215 |
/** |
|
216 |
@defgroup max_flow Maximum Flow algorithms |
|
217 |
|
|
215 |
/** |
|
216 |
@defgroup max_flow Maximum Flow algorithms |
|
217 |
@ingroup algs |
|
218 | 218 |
\brief Algorithms for finding maximum flows. |
219 | 219 |
|
220 | 220 |
This group describes the algorithms for finding maximum flows and |
... | ... |
@@ -231,7 +231,7 @@ |
231 | 231 |
\f[ \max \sum_{v\in\delta^{+}(s)}f_{uv} - \sum_{v\in\delta^{-}(s)}f_{vu}\f] |
232 | 232 |
|
233 | 233 |
LEMON contains several algorithms for solving maximum flow problems: |
234 |
- \ref lemon::EdmondsKarp "Edmonds-Karp" |
|
234 |
- \ref lemon::EdmondsKarp "Edmonds-Karp" |
|
235 | 235 |
- \ref lemon::Preflow "Goldberg's Preflow algorithm" |
236 | 236 |
- \ref lemon::DinitzSleatorTarjan "Dinitz's blocking flow algorithm with dynamic trees" |
237 | 237 |
- \ref lemon::GoldbergTarjan "Preflow algorithm with dynamic trees" |
... | ... |
@@ -250,12 +250,12 @@ |
250 | 250 |
\brief Algorithms for finding minimum cost flows and circulations. |
251 | 251 |
|
252 | 252 |
This group describes the algorithms for finding minimum cost flows and |
253 |
circulations. |
|
253 |
circulations. |
|
254 | 254 |
*/ |
255 | 255 |
|
256 | 256 |
/** |
257 |
@defgroup min_cut Minimum Cut algorithms |
|
258 |
@ingroup algs |
|
257 |
@defgroup min_cut Minimum Cut algorithms |
|
258 |
@ingroup algs |
|
259 | 259 |
|
260 | 260 |
\brief Algorithms for finding minimum cut in graphs. |
261 | 261 |
|
... | ... |
@@ -272,7 +272,7 @@ |
272 | 272 |
LEMON contains several algorithms related to minimum cut problems: |
273 | 273 |
|
274 | 274 |
- \ref lemon::HaoOrlin "Hao-Orlin algorithm" to calculate minimum cut |
275 |
in directed graphs |
|
275 |
in directed graphs |
|
276 | 276 |
- \ref lemon::NagamochiIbaraki "Nagamochi-Ibaraki algorithm" to |
277 | 277 |
calculate minimum cut in undirected graphs |
278 | 278 |
- \ref lemon::GomoryHuTree "Gomory-Hu tree computation" to calculate all |
... | ... |
@@ -307,14 +307,14 @@ |
307 | 307 |
*/ |
308 | 308 |
|
309 | 309 |
/** |
310 |
@defgroup matching Matching algorithms |
|
310 |
@defgroup matching Matching algorithms |
|
311 | 311 |
@ingroup algs |
312 | 312 |
\brief Algorithms for finding matchings in graphs and bipartite graphs. |
313 | 313 |
|
314 | 314 |
This group contains algorithm objects and functions to calculate |
315 | 315 |
matchings in graphs and bipartite graphs. The general matching problem is |
316 | 316 |
finding a subset of the arcs which does not shares common endpoints. |
317 |
|
|
317 |
|
|
318 | 318 |
There are several different algorithms for calculate matchings in |
319 | 319 |
graphs. The matching problems in bipartite graphs are generally |
320 | 320 |
easier than in general graphs. The goal of the matching optimization |
... | ... |
@@ -323,16 +323,16 @@ |
323 | 323 |
maximum cardinality matching. |
324 | 324 |
|
325 | 325 |
Lemon contains the next algorithms: |
326 |
- \ref lemon::MaxBipartiteMatching "MaxBipartiteMatching" Hopcroft-Karp |
|
327 |
augmenting path algorithm for calculate maximum cardinality matching in |
|
326 |
- \ref lemon::MaxBipartiteMatching "MaxBipartiteMatching" Hopcroft-Karp |
|
327 |
augmenting path algorithm for calculate maximum cardinality matching in |
|
328 | 328 |
bipartite graphs |
329 |
- \ref lemon::PrBipartiteMatching "PrBipartiteMatching" Push-Relabel |
|
330 |
algorithm for calculate maximum cardinality matching in bipartite graphs |
|
331 |
- \ref lemon::MaxWeightedBipartiteMatching "MaxWeightedBipartiteMatching" |
|
332 |
Successive shortest path algorithm for calculate maximum weighted matching |
|
329 |
- \ref lemon::PrBipartiteMatching "PrBipartiteMatching" Push-Relabel |
|
330 |
algorithm for calculate maximum cardinality matching in bipartite graphs |
|
331 |
- \ref lemon::MaxWeightedBipartiteMatching "MaxWeightedBipartiteMatching" |
|
332 |
Successive shortest path algorithm for calculate maximum weighted matching |
|
333 | 333 |
and maximum weighted bipartite matching in bipartite graph |
334 |
- \ref lemon::MinCostMaxBipartiteMatching "MinCostMaxBipartiteMatching" |
|
335 |
Successive shortest path algorithm for calculate minimum cost maximum |
|
334 |
- \ref lemon::MinCostMaxBipartiteMatching "MinCostMaxBipartiteMatching" |
|
335 |
Successive shortest path algorithm for calculate minimum cost maximum |
|
336 | 336 |
matching in bipartite graph |
337 | 337 |
- \ref lemon::MaxMatching "MaxMatching" Edmond's blossom shrinking algorithm |
338 | 338 |
for calculate maximum cardinality matching in general graph |
... | ... |
@@ -396,8 +396,8 @@ |
396 | 396 |
|
397 | 397 |
*/ |
398 | 398 |
|
399 |
/** |
|
400 |
@defgroup lp_utils Tools for Lp and Mip solvers |
|
399 |
/** |
|
400 |
@defgroup lp_utils Tools for Lp and Mip solvers |
|
401 | 401 |
@ingroup lp_group |
402 | 402 |
\brief Helper tools to the Lp and Mip solvers. |
403 | 403 |
|
... | ... |
@@ -414,7 +414,7 @@ |
414 | 414 |
*/ |
415 | 415 |
|
416 | 416 |
/** |
417 |
@defgroup utils Tools and Utilities |
|
417 |
@defgroup utils Tools and Utilities |
|
418 | 418 |
\brief Tools and utilities for programming in LEMON |
419 | 419 |
|
420 | 420 |
Tools and utilities for programming in LEMON. |
... | ... |
@@ -467,7 +467,7 @@ |
467 | 467 |
@defgroup io_group Input-Output |
468 | 468 |
\brief Graph Input-Output methods |
469 | 469 |
|
470 |
This group describes the tools for importing and exporting graphs |
|
470 |
This group describes the tools for importing and exporting graphs |
|
471 | 471 |
and graph related data. Now it supports the LEMON format, the |
472 | 472 |
\c DIMACS format and the encapsulated postscript (EPS) format. |
473 | 473 |
*/ |
... | ... |
@@ -486,7 +486,7 @@ |
486 | 486 |
\brief General \c EPS drawer and graph exporter |
487 | 487 |
|
488 | 488 |
This group describes general \c EPS drawing methods and special |
489 |
graph exporting tools. |
|
489 |
graph exporting tools. |
|
490 | 490 |
*/ |
491 | 491 |
|
492 | 492 |
|
... | ... |
@@ -498,7 +498,7 @@ |
498 | 498 |
classes implemented in LEMON. |
499 | 499 |
|
500 | 500 |
The purpose of the classes in this group is fourfold. |
501 |
|
|
501 |
|
|
502 | 502 |
- These classes contain the documentations of the concepts. In order |
503 | 503 |
to avoid document multiplications, an implementation of a concept |
504 | 504 |
simply refers to the corresponding concept class. |
... | ... |
@@ -551,9 +551,9 @@ |
551 | 551 |
/** |
552 | 552 |
@defgroup tools Standalone utility applications |
553 | 553 |
|
554 |
Some utility applications are listed here. |
|
554 |
Some utility applications are listed here. |
|
555 | 555 |
|
556 | 556 |
The standard compilation procedure (<tt>./configure;make</tt>) will compile |
557 |
them, as well. |
|
557 |
them, as well. |
|
558 | 558 |
*/ |
559 | 559 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -43,7 +43,7 @@ |
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 |
contain whitespaces and escape sequences. |
|
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 |
... | ... |
@@ -72,7 +72,7 @@ |
72 | 72 |
|
73 | 73 |
\code |
74 | 74 |
@arcs |
75 |
|
|
75 |
capacity |
|
76 | 76 |
1 2 16 |
77 | 77 |
1 3 12 |
78 | 78 |
2 3 18 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -41,15 +41,15 @@ |
41 | 41 |
|
42 | 42 |
\subsection howtoread How to read the documentation |
43 | 43 |
|
44 |
If you want to get a quick start and see the most important features then |
|
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 |
If you already feel like using our library, see the page that tells you |
|
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 |
If you |
|
52 |
want to see how LEMON works, see |
|
51 |
If you |
|
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 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -38,30 +38,30 @@ |
38 | 38 |
{ |
39 | 39 |
for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) |
40 | 40 |
if(i->second.self_delete) |
41 |
switch(i->second.type) { |
|
42 |
case BOOL: |
|
43 |
delete i->second.bool_p; |
|
44 |
break; |
|
45 |
case STRING: |
|
46 |
delete i->second.string_p; |
|
47 |
break; |
|
48 |
case DOUBLE: |
|
49 |
delete i->second.double_p; |
|
50 |
break; |
|
51 |
case INTEGER: |
|
52 |
delete i->second.int_p; |
|
53 |
break; |
|
54 |
case UNKNOWN: |
|
55 |
break; |
|
56 |
case FUNC: |
|
57 |
break; |
|
58 |
} |
|
41 |
switch(i->second.type) { |
|
42 |
case BOOL: |
|
43 |
delete i->second.bool_p; |
|
44 |
break; |
|
45 |
case STRING: |
|
46 |
delete i->second.string_p; |
|
47 |
break; |
|
48 |
case DOUBLE: |
|
49 |
delete i->second.double_p; |
|
50 |
break; |
|
51 |
case INTEGER: |
|
52 |
delete i->second.int_p; |
|
53 |
break; |
|
54 |
case UNKNOWN: |
|
55 |
break; |
|
56 |
case FUNC: |
|
57 |
break; |
|
58 |
} |
|
59 | 59 |
} |
60 |
|
|
60 |
|
|
61 | 61 |
|
62 | 62 |
ArgParser &ArgParser::intOption(const std::string &name, |
63 |
const std::string &help, |
|
64 |
int value, bool obl) |
|
63 |
const std::string &help, |
|
64 |
int value, bool obl) |
|
65 | 65 |
{ |
66 | 66 |
ParData p; |
67 | 67 |
p.int_p=new int(value); |
... | ... |
@@ -74,8 +74,8 @@ |
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
ArgParser &ArgParser::doubleOption(const std::string &name, |
77 |
const std::string &help, |
|
78 |
double value, bool obl) |
|
77 |
const std::string &help, |
|
78 |
double value, bool obl) |
|
79 | 79 |
{ |
80 | 80 |
ParData p; |
81 | 81 |
p.double_p=new double(value); |
... | ... |
@@ -88,8 +88,8 @@ |
88 | 88 |
} |
89 | 89 |
|
90 | 90 |
ArgParser &ArgParser::boolOption(const std::string &name, |
91 |
const std::string &help, |
|
92 |
bool value, bool obl) |
|
91 |
const std::string &help, |
|
92 |
bool value, bool obl) |
|
93 | 93 |
{ |
94 | 94 |
ParData p; |
95 | 95 |
p.bool_p=new bool(value); |
... | ... |
@@ -102,8 +102,8 @@ |
102 | 102 |
} |
103 | 103 |
|
104 | 104 |
ArgParser &ArgParser::stringOption(const std::string &name, |
105 |
const std::string &help, |
|
106 |
std::string value, bool obl) |
|
105 |
const std::string &help, |
|
106 |
std::string value, bool obl) |
|
107 | 107 |
{ |
108 | 108 |
ParData p; |
109 | 109 |
p.string_p=new std::string(value); |
... | ... |
@@ -116,8 +116,8 @@ |
116 | 116 |
} |
117 | 117 |
|
118 | 118 |
ArgParser &ArgParser::refOption(const std::string &name, |
119 |
const std::string &help, |
|
120 |
int &ref, bool obl) |
|
119 |
const std::string &help, |
|
120 |
int &ref, bool obl) |
|
121 | 121 |
{ |
122 | 122 |
ParData p; |
123 | 123 |
p.int_p=&ref; |
... | ... |
@@ -161,8 +161,8 @@ |
161 | 161 |
} |
162 | 162 |
|
163 | 163 |
ArgParser &ArgParser::refOption(const std::string &name, |
164 |
const std::string &help, |
|
165 |
std::string &ref, bool obl) |
|
164 |
const std::string &help, |
|
165 |
std::string &ref, bool obl) |
|
166 | 166 |
{ |
167 | 167 |
ParData p; |
168 | 168 |
p.string_p=&ref; |
... | ... |
@@ -175,8 +175,8 @@ |
175 | 175 |
} |
176 | 176 |
|
177 | 177 |
ArgParser &ArgParser::funcOption(const std::string &name, |
178 |
const std::string &help, |
|
179 |
void (*func)(void *),void *data) |
|
178 |
const std::string &help, |
|
179 |
void (*func)(void *),void *data) |
|
180 | 180 |
{ |
181 | 181 |
ParData p; |
182 | 182 |
p.func_p.p=func; |
... | ... |
@@ -190,11 +190,11 @@ |
190 | 190 |
} |
191 | 191 |
|
192 | 192 |
ArgParser &ArgParser::optionGroup(const std::string &group, |
193 |
|
|
193 |
const std::string &opt) |
|
194 | 194 |
{ |
195 | 195 |
Opts::iterator i = _opts.find(opt); |
196 | 196 |
LEMON_ASSERT(i!=_opts.end(), "Unknown option: '"+opt+"'"); |
197 |
LEMON_ASSERT(!(i->second.ingroup), |
|
197 |
LEMON_ASSERT(!(i->second.ingroup), |
|
198 | 198 |
"Option already in option group: '"+opt+"'"); |
199 | 199 |
GroupData &g=_groups[group]; |
200 | 200 |
g.opts.push_back(opt); |
... | ... |
@@ -210,7 +210,7 @@ |
210 | 210 |
} |
211 | 211 |
|
212 | 212 |
ArgParser &ArgParser::synonym(const std::string &syn, |
213 |
|
|
213 |
const std::string &opt) |
|
214 | 214 |
{ |
215 | 215 |
Opts::iterator o = _opts.find(opt); |
216 | 216 |
Opts::iterator s = _opts.find(syn); |
... | ... |
@@ -233,7 +233,7 @@ |
233 | 233 |
} |
234 | 234 |
|
235 | 235 |
ArgParser &ArgParser::other(const std::string &name, |
236 |
|
|
236 |
const std::string &help) |
|
237 | 237 |
{ |
238 | 238 |
_others_help.push_back(OtherArg(name,help)); |
239 | 239 |
return *this; |
... | ... |
@@ -244,8 +244,8 @@ |
244 | 244 |
os << "-" << i->first; |
245 | 245 |
if(i->second.has_syn) |
246 | 246 |
for(Opts::iterator j=_opts.begin();j!=_opts.end();++j) |
247 |
if(j->second.syn&&j->second.help==i->first) |
|
248 |
os << "|-" << j->first; |
|
247 |
if(j->second.syn&&j->second.help==i->first) |
|
248 |
os << "|-" << j->first; |
|
249 | 249 |
switch(i->second.type) { |
250 | 250 |
case STRING: |
251 | 251 |
os << " str"; |
... | ... |
@@ -270,7 +270,7 @@ |
270 | 270 |
if(o!=i->second.opts.end()) os<<'|'; |
271 | 271 |
} |
272 | 272 |
} |
273 |
|
|
273 |
|
|
274 | 274 |
void ArgParser::showHelp(Opts::iterator i) |
275 | 275 |
{ |
276 | 276 |
if(i->second.help.size()==0||i->second.syn) return; |
... | ... |
@@ -283,9 +283,9 @@ |
283 | 283 |
{ |
284 | 284 |
if(i->help.size()==0) return; |
285 | 285 |
std::cerr << " " << i->name << std::endl |
286 |
|
|
286 |
<< " " << i->help << std::endl; |
|
287 | 287 |
} |
288 |
|
|
288 |
|
|
289 | 289 |
void ArgParser::shortHelp() |
290 | 290 |
{ |
291 | 291 |
const unsigned int LINE_LEN=77; |
... | ... |
@@ -299,62 +299,62 @@ |
299 | 299 |
show(cstr,g); |
300 | 300 |
if(!g->second.mandatory) cstr << ']'; |
301 | 301 |
if(pos+cstr.str().size()>LINE_LEN) { |
302 |
std::cerr << std::endl << indent; |
|
303 |
pos=indent.size(); |
|
302 |
std::cerr << std::endl << indent; |
|
303 |
pos=indent.size(); |
|
304 | 304 |
} |
305 | 305 |
std::cerr << cstr.str(); |
306 | 306 |
pos+=cstr.str().size(); |
307 | 307 |
} |
308 | 308 |
for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) |
309 | 309 |
if(!i->second.ingroup&&!i->second.syn) { |
310 |
std::ostringstream cstr; |
|
311 |
cstr << ' '; |
|
312 |
if(!i->second.mandatory) cstr << '['; |
|
313 |
show(cstr,i); |
|
314 |
if(!i->second.mandatory) cstr << ']'; |
|
315 |
if(pos+cstr.str().size()>LINE_LEN) { |
|
316 |
std::cerr << std::endl << indent; |
|
317 |
pos=indent.size(); |
|
318 |
} |
|
319 |
std::cerr << cstr.str(); |
|
320 |
|
|
310 |
std::ostringstream cstr; |
|
311 |
cstr << ' '; |
|
312 |
if(!i->second.mandatory) cstr << '['; |
|
313 |
show(cstr,i); |
|
314 |
if(!i->second.mandatory) cstr << ']'; |
|
315 |
if(pos+cstr.str().size()>LINE_LEN) { |
|
316 |
std::cerr << std::endl << indent; |
|
317 |
pos=indent.size(); |
|
318 |
} |
|
319 |
std::cerr << cstr.str(); |
|
320 |
pos+=cstr.str().size(); |
|
321 | 321 |
} |
322 | 322 |
for(std::vector<OtherArg>::iterator i=_others_help.begin(); |
323 |
|
|
323 |
i!=_others_help.end();++i) |
|
324 | 324 |
{ |
325 |
std::ostringstream cstr; |
|
326 |
cstr << ' ' << i->name; |
|
327 |
|
|
328 |
if(pos+cstr.str().size()>LINE_LEN) { |
|
329 |
std::cerr << std::endl << indent; |
|
330 |
pos=indent.size(); |
|
331 |
} |
|
332 |
std::cerr << cstr.str(); |
|
333 |
|
|
325 |
std::ostringstream cstr; |
|
326 |
cstr << ' ' << i->name; |
|
327 |
|
|
328 |
if(pos+cstr.str().size()>LINE_LEN) { |
|
329 |
std::cerr << std::endl << indent; |
|
330 |
pos=indent.size(); |
|
331 |
} |
|
332 |
std::cerr << cstr.str(); |
|
333 |
pos+=cstr.str().size(); |
|
334 | 334 |
} |
335 | 335 |
std::cerr << std::endl; |
336 | 336 |
} |
337 |
|
|
337 |
|
|
338 | 338 |
void ArgParser::showHelp() |
339 | 339 |
{ |
340 | 340 |
shortHelp(); |
341 | 341 |
std::cerr << "Where:\n"; |
342 | 342 |
for(std::vector<OtherArg>::iterator i=_others_help.begin(); |
343 |
|
|
343 |
i!=_others_help.end();++i) showHelp(i); |
|
344 | 344 |
for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) showHelp(i); |
345 | 345 |
exit(1); |
346 | 346 |
} |
347 |
|
|
348 |
|
|
349 |
|
|
347 |
|
|
348 |
|
|
349 |
void ArgParser::unknownOpt(std::string arg) |
|
350 | 350 |
{ |
351 | 351 |
std::cerr << "\nUnknown option: " << arg << "\n"; |
352 | 352 |
std::cerr << "\nType '" << _command_name << |
353 | 353 |
" --help' to obtain a short summary on the usage.\n\n"; |
354 | 354 |
exit(1); |
355 | 355 |
} |
356 |
|
|
357 |
void ArgParser::requiresValue(std::string arg, OptType t) |
|
356 |
|
|
357 |
void ArgParser::requiresValue(std::string arg, OptType t) |
|
358 | 358 |
{ |
359 | 359 |
std::cerr << "Argument '" << arg << "' requires a"; |
360 | 360 |
switch(t) { |
... | ... |
@@ -373,47 +373,47 @@ |
373 | 373 |
std::cerr << " value\n\n"; |
374 | 374 |
showHelp(); |
375 | 375 |
} |
376 |
|
|
376 |
|
|
377 | 377 |
|
378 | 378 |
void ArgParser::checkMandatories() |
379 | 379 |
{ |
380 | 380 |
bool ok=true; |
381 | 381 |
for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) |
382 |
if(i->second.mandatory&&!i->second.set) |
|
383 |
{ |
|
384 |
if(ok) |
|
385 |
std::cerr << _command_name |
|
386 |
<< ": The following mandatory arguments are missing.\n"; |
|
387 |
ok=false; |
|
388 |
showHelp(i); |
|
389 |
} |
|
382 |
if(i->second.mandatory&&!i->second.set) |
|
383 |
{ |
|
384 |
if(ok) |
|
385 |
std::cerr << _command_name |
|
386 |
<< ": The following mandatory arguments are missing.\n"; |
|
387 |
ok=false; |
|
388 |
showHelp(i); |
|
389 |
} |
|
390 | 390 |
for(Groups::iterator i=_groups.begin();i!=_groups.end();++i) |
391 | 391 |
if(i->second.mandatory||i->second.only_one) |
392 |
{ |
|
393 |
int set=0; |
|
394 |
for(GroupData::Opts::iterator o=i->second.opts.begin(); |
|
395 |
o!=i->second.opts.end();++o) |
|
396 |
if(_opts.find(*o)->second.set) ++set; |
|
397 |
if(i->second.mandatory&&!set) { |
|
398 |
std::cerr << _command_name |
|
399 |
<< ": At least one of the following arguments is mandatory.\n"; |
|
400 |
ok=false; |
|
401 |
for(GroupData::Opts::iterator o=i->second.opts.begin(); |
|
402 |
o!=i->second.opts.end();++o) |
|
403 |
showHelp(_opts.find(*o)); |
|
404 |
} |
|
405 |
if(i->second.only_one&&set>1) { |
|
406 |
std::cerr << _command_name |
|
407 |
<< ": At most one of the following arguments can be given.\n"; |
|
408 |
ok=false; |
|
409 |
for(GroupData::Opts::iterator o=i->second.opts.begin(); |
|
410 |
o!=i->second.opts.end();++o) |
|
411 |
showHelp(_opts.find(*o)); |
|
412 |
} |
|
413 |
} |
|
392 |
{ |
|
393 |
int set=0; |
|
394 |
for(GroupData::Opts::iterator o=i->second.opts.begin(); |
|
395 |
o!=i->second.opts.end();++o) |
|
396 |
if(_opts.find(*o)->second.set) ++set; |
|
397 |
if(i->second.mandatory&&!set) { |
|
398 |
std::cerr << _command_name |
|
399 |
<< ": At least one of the following arguments is mandatory.\n"; |
|
400 |
ok=false; |
|
401 |
for(GroupData::Opts::iterator o=i->second.opts.begin(); |
|
402 |
o!=i->second.opts.end();++o) |
|
403 |
showHelp(_opts.find(*o)); |
|
404 |
} |
|
405 |
if(i->second.only_one&&set>1) { |
|
406 |
std::cerr << _command_name |
|
407 |
<< ": At most one of the following arguments can be given.\n"; |
|
408 |
ok=false; |
|
409 |
for(GroupData::Opts::iterator o=i->second.opts.begin(); |
|
410 |
o!=i->second.opts.end();++o) |
|
411 |
showHelp(_opts.find(*o)); |
|
412 |
} |
|
413 |
} |
|
414 | 414 |
if(!ok) { |
415 | 415 |
std::cerr << "\nType '" << _command_name << |
416 |
|
|
416 |
" --help' to obtain a short summary on the usage.\n\n"; |
|
417 | 417 |
exit(1); |
418 | 418 |
} |
419 | 419 |
} |
... | ... |
@@ -423,43 +423,43 @@ |
423 | 423 |
for(int ar=1; ar<_argc; ++ar) { |
424 | 424 |
std::string arg(_argv[ar]); |
425 | 425 |
if (arg[0] != '-' || arg.size() == 1) { |
426 |
|
|
426 |
_file_args.push_back(arg); |
|
427 | 427 |
} |
428 | 428 |
else { |
429 |
Opts::iterator i = _opts.find(arg.substr(1)); |
|
430 |
if(i==_opts.end()) unknownOpt(arg); |
|
431 |
else { |
|
432 |
if(i->second.syn) i=_opts.find(i->second.help); |
|
433 |
ParData &p(i->second); |
|
434 |
if (p.type==BOOL) *p.bool_p=true; |
|
435 |
else if (p.type==FUNC) p.func_p.p(p.func_p.data); |
|
436 |
else if(++ar==_argc) requiresValue(arg, p.type); |
|
437 |
else { |
|
438 |
std::string val(_argv[ar]); |
|
439 |
std::istringstream vals(val); |
|
440 |
switch(p.type) { |
|
441 |
case STRING: |
|
442 |
*p.string_p=val; |
|
443 |
break; |
|
444 |
case INTEGER: |
|
445 |
vals >> *p.int_p; |
|
446 |
break; |
|
447 |
case DOUBLE: |
|
448 |
vals >> *p.double_p; |
|
449 |
break; |
|
450 |
default: |
|
451 |
break; |
|
452 |
} |
|
453 |
if(p.type!=STRING&&(!vals||!vals.eof())) |
|
454 |
requiresValue(arg, p.type); |
|
455 |
} |
|
456 |
p.set = true; |
|
457 |
|
|
429 |
Opts::iterator i = _opts.find(arg.substr(1)); |
|
430 |
if(i==_opts.end()) unknownOpt(arg); |
|
431 |
else { |
|
432 |
if(i->second.syn) i=_opts.find(i->second.help); |
|
433 |
ParData &p(i->second); |
|
434 |
if (p.type==BOOL) *p.bool_p=true; |
|
435 |
else if (p.type==FUNC) p.func_p.p(p.func_p.data); |
|
436 |
else if(++ar==_argc) requiresValue(arg, p.type); |
|
437 |
else { |
|
438 |
std::string val(_argv[ar]); |
|
439 |
std::istringstream vals(val); |
|
440 |
switch(p.type) { |
|
441 |
case STRING: |
|
442 |
*p.string_p=val; |
|
443 |
break; |
|
444 |
case INTEGER: |
|
445 |
vals >> *p.int_p; |
|
446 |
break; |
|
447 |
case DOUBLE: |
|
448 |
vals >> *p.double_p; |
|
449 |
break; |
|
450 |
default: |
|
451 |
break; |
|
452 |
} |
|
453 |
if(p.type!=STRING&&(!vals||!vals.eof())) |
|
454 |
requiresValue(arg, p.type); |
|
455 |
} |
|
456 |
p.set = true; |
|
457 |
} |
|
458 | 458 |
} |
459 | 459 |
} |
460 | 460 |
checkMandatories(); |
461 | 461 |
|
462 | 462 |
return *this; |
463 |
} |
|
463 |
} |
|
464 | 464 |
|
465 | 465 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -41,27 +41,27 @@ |
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 **_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 |
bool *bool_p; |
|
57 |
int *int_p; |
|
58 |
double *double_p; |
|
59 |
std::string *string_p; |
|
60 |
struct { |
|
61 |
void (*p)(void *); |
|
62 |
void *data; |
|
63 |
} func_p; |
|
64 |
|
|
56 |
bool *bool_p; |
|
57 |
int *int_p; |
|
58 |
double *double_p; |
|
59 |
std::string *string_p; |
|
60 |
struct { |
|
61 |
void (*p)(void *); |
|
62 |
void *data; |
|
63 |
} func_p; |
|
64 |
|
|
65 | 65 |
}; |
66 | 66 |
std::string help; |
67 | 67 |
bool mandatory; |
... | ... |
@@ -72,13 +72,13 @@ |
72 | 72 |
bool syn; |
73 | 73 |
bool self_delete; |
74 | 74 |
ParData() : mandatory(false), type(UNKNOWN), set(false), ingroup(false), |
75 |
|
|
75 |
has_syn(false), syn(false), self_delete(false) {} |
|
76 | 76 |
}; |
77 | 77 |
|
78 | 78 |
typedef std::map<std::string,ParData> Opts; |
79 | 79 |
Opts _opts; |
80 | 80 |
|
81 |
class GroupData |
|
81 |
class GroupData |
|
82 | 82 |
{ |
83 | 83 |
public: |
84 | 84 |
typedef std::list<std::string> Opts; |
... | ... |
@@ -87,7 +87,7 @@ |
87 | 87 |
bool mandatory; |
88 | 88 |
GroupData() :only_one(false), mandatory(false) {} |
89 | 89 |
}; |
90 |
|
|
90 |
|
|
91 | 91 |
typedef std::map<std::string,GroupData> Groups; |
92 | 92 |
Groups _groups; |
93 | 93 |
|
... | ... |
@@ -98,12 +98,12 @@ |
98 | 98 |
OtherArg(std::string n, std::string h) :name(n), help(h) {} |
99 | 99 |
|
100 | 100 |
}; |
101 |
|
|
101 |
|
|
102 | 102 |
std::vector<OtherArg> _others_help; |
103 | 103 |
std::vector<std::string> _file_args; |
104 | 104 |
std::string _command_name; |
105 | 105 |
|
106 |
|
|
106 |
|
|
107 | 107 |
private: |
108 | 108 |
//Bind a function to an option. |
109 | 109 |
|
... | ... |
@@ -113,9 +113,9 @@ |
113 | 113 |
// must be of type "void f(void *)" |
114 | 114 |
//\param data Data to be passed to \c func |
115 | 115 |
ArgParser &funcOption(const std::string &name, |
116 |
const std::string &help, |
|
117 |
void (*func)(void *),void *data); |
|
118 |
|
|
116 |
const std::string &help, |
|
117 |
void (*func)(void *),void *data); |
|
118 |
|
|
119 | 119 |
public: |
120 | 120 |
|
121 | 121 |
///Constructor |
... | ... |
@@ -136,8 +136,8 @@ |
136 | 136 |
///\param value A default value for the option. |
137 | 137 |
///\param obl Indicate if the option is mandatory. |
138 | 138 |
ArgParser &intOption(const std::string &name, |
139 |
const std::string &help, |
|
140 |
int value=0, bool obl=false); |
|
139 |
const std::string &help, |
|
140 |
int value=0, bool obl=false); |
|
141 | 141 |
|
142 | 142 |
///Add a new floating point type option |
143 | 143 |
|
... | ... |
@@ -147,8 +147,8 @@ |
147 | 147 |
///\param value A default value for the option. |
148 | 148 |
///\param obl Indicate if the option is mandatory. |
149 | 149 |
ArgParser &doubleOption(const std::string &name, |
150 |
const std::string &help, |
|
151 |
double value=0, bool obl=false); |
|
150 |
const std::string &help, |
|
151 |
double value=0, bool obl=false); |
|
152 | 152 |
|
153 | 153 |
///Add a new bool type option |
154 | 154 |
|
... | ... |
@@ -159,8 +159,8 @@ |
159 | 159 |
///\param obl Indicate if the option is mandatory. |
160 | 160 |
///\note A mandatory bool obtion is of very little use. |
161 | 161 |
ArgParser &boolOption(const std::string &name, |
162 |
const std::string &help, |
|
163 |
bool value=false, bool obl=false); |
|
162 |
const std::string &help, |
|
163 |
bool value=false, bool obl=false); |
|
164 | 164 |
|
165 | 165 |
///Add a new string type option |
166 | 166 |
|
... | ... |
@@ -170,8 +170,8 @@ |
170 | 170 |
///\param value A default value for the option. |
171 | 171 |
///\param obl Indicate if the option is mandatory. |
172 | 172 |
ArgParser &stringOption(const std::string &name, |
173 |
const std::string &help, |
|
174 |
std::string value="", bool obl=false); |
|
173 |
const std::string &help, |
|
174 |
std::string value="", bool obl=false); |
|
175 | 175 |
|
176 | 176 |
///Give help string for non-parsed arguments. |
177 | 177 |
|
... | ... |
@@ -179,8 +179,8 @@ |
179 | 179 |
///The parameter \c name will be printed in the short usage line, while |
180 | 180 |
///\c help gives a more detailed description. |
181 | 181 |
ArgParser &other(const std::string &name, |
182 |
const std::string &help=""); |
|
183 |
|
|
182 |
const std::string &help=""); |
|
183 |
|
|
184 | 184 |
///@} |
185 | 185 |
|
186 | 186 |
///\name Options with External Storage |
... | ... |
@@ -197,8 +197,8 @@ |
197 | 197 |
///\param obl Indicate if the option is mandatory. |
198 | 198 |
///\retval ref The value of the argument will be written to this variable. |
199 | 199 |
ArgParser &refOption(const std::string &name, |
200 |
const std::string &help, |
|
201 |
int &ref, bool obl=false); |
|
200 |
const std::string &help, |
|
201 |
int &ref, bool obl=false); |
|
202 | 202 |
|
203 | 203 |
///Add a new floating type option with a storage reference |
204 | 204 |
|
... | ... |
@@ -208,8 +208,8 @@ |
208 | 208 |
///\param obl Indicate if the option is mandatory. |
209 | 209 |
///\retval ref The value of the argument will be written to this variable. |
210 | 210 |
ArgParser &refOption(const std::string &name, |
211 |
const std::string &help, |
|
212 |
double &ref, bool obl=false); |
|
211 |
const std::string &help, |
|
212 |
double &ref, bool obl=false); |
|
213 | 213 |
|
214 | 214 |
///Add a new bool type option with a storage reference |
215 | 215 |
|
... | ... |
@@ -220,8 +220,8 @@ |
220 | 220 |
///\retval ref The value of the argument will be written to this variable. |
221 | 221 |
///\note A mandatory bool obtion is of very little use. |
222 | 222 |
ArgParser &refOption(const std::string &name, |
223 |
const std::string &help, |
|
224 |
bool &ref, bool obl=false); |
|
223 |
const std::string &help, |
|
224 |
bool &ref, bool obl=false); |
|
225 | 225 |
|
226 | 226 |
///Add a new string type option with a storage reference |
227 | 227 |
|
... | ... |
@@ -231,14 +231,14 @@ |
231 | 231 |
///\param obl Indicate if the option is mandatory. |
232 | 232 |
///\retval ref The value of the argument will be written to this variable. |
233 | 233 |
ArgParser &refOption(const std::string &name, |
234 |
const std::string &help, |
|
235 |
std::string &ref, bool obl=false); |
|
236 |
|
|
234 |
const std::string &help, |
|
235 |
std::string &ref, bool obl=false); |
|
236 |
|
|
237 | 237 |
///@} |
238 | 238 |
|
239 | 239 |
///\name Option Groups and Synonyms |
240 | 240 |
/// |
241 |
|
|
241 |
|
|
242 | 242 |
///@{ |
243 | 243 |
|
244 | 244 |
///Bundle some options into a group |
... | ... |
@@ -248,27 +248,27 @@ |
248 | 248 |
///\param group The group name. |
249 | 249 |
///\param opt The option name. |
250 | 250 |
ArgParser &optionGroup(const std::string &group, |
251 |
|
|
251 |
const std::string &opt); |
|
252 | 252 |
|
253 | 253 |
///Make the members of a group exclusive |
254 | 254 |
|
255 | 255 |
///If you call this function for a group, than at most one of them can be |
256 | 256 |
///given at the same time. |
257 | 257 |
ArgParser &onlyOneGroup(const std::string &group); |
258 |
|
|
258 |
|
|
259 | 259 |
///Make a group mandatory |
260 | 260 |
|
261 | 261 |
///Using this function, at least one of the members of \c group |
262 | 262 |
///must be given. |
263 | 263 |
ArgParser &mandatoryGroup(const std::string &group); |
264 |
|
|
264 |
|
|
265 | 265 |
///Create synonym to an option |
266 | 266 |
|
267 | 267 |
///With this function you can create a synonym \c syn of the |
268 | 268 |
///option \c opt. |
269 | 269 |
ArgParser &synonym(const std::string &syn, |
270 |
const std::string &opt); |
|
271 |
|
|
270 |
const std::string &opt); |
|
271 |
|
|
272 | 272 |
///@} |
273 | 273 |
|
274 | 274 |
void show(std::ostream &os,Opts::iterator i); |
... | ... |
@@ -282,21 +282,21 @@ |
282 | 282 |
|
283 | 283 |
void requiresValue(std::string arg, OptType t); |
284 | 284 |
void checkMandatories(); |
285 |
|
|
285 |
|
|
286 | 286 |
///Start the parsing process |
287 | 287 |
ArgParser &parse(); |
288 | 288 |
|
289 | 289 |
/// Synonym for parse() |
290 |
ArgParser &run() |
|
290 |
ArgParser &run() |
|
291 | 291 |
{ |
292 | 292 |
return parse(); |
293 | 293 |
} |
294 |
|
|
294 |
|
|
295 | 295 |
///Give back the command name (the 0th argument) |
296 | 296 |
const std::string &commandName() { return _command_name; } |
297 | 297 |
|
298 | 298 |
///Check if an opion has been given to the command. |
299 |
bool given(std::string op) |
|
299 |
bool given(std::string op) |
|
300 | 300 |
{ |
301 | 301 |
Opts::iterator i = _opts.find(op); |
302 | 302 |
return i!=_opts.end()?i->second.set:false; |
... | ... |
@@ -304,12 +304,12 @@ |
304 | 304 |
|
305 | 305 |
|
306 | 306 |
///Magic type for operator[] |
307 |
|
|
307 |
|
|
308 | 308 |
///This is the type of the return value of ArgParser::operator[](). |
309 | 309 |
///It automatically converts to \c int, \c double, \c bool or |
310 | 310 |
///\c std::string if the type of the option matches, otherwise it |
311 | 311 |
///throws an exception (i.e. it performs runtime type checking). |
312 |
class RefType |
|
312 |
class RefType |
|
313 | 313 |
{ |
314 | 314 |
ArgParser &_parser; |
315 | 315 |
std::string _name; |
... | ... |
@@ -317,65 +317,65 @@ |
317 | 317 |
///\e |
318 | 318 |
RefType(ArgParser &p,const std::string &n) :_parser(p),_name(n) {} |
319 | 319 |
///\e |
320 |
operator bool() |
|
320 |
operator bool() |
|
321 | 321 |
{ |
322 |
Opts::iterator i = _parser._opts.find(_name); |
|
323 |
LEMON_ASSERT(i!=_parser._opts.end(), |
|
324 |
std::string()+"Unkown option: '"+_name+"'"); |
|
325 |
LEMON_ASSERT(i->second.type==ArgParser::BOOL, |
|
326 |
std::string()+"'"+_name+"' is a bool option"); |
|
327 |
return *(i->second.bool_p); |
|
322 |
Opts::iterator i = _parser._opts.find(_name); |
|
323 |
LEMON_ASSERT(i!=_parser._opts.end(), |
|
324 |
std::string()+"Unkown option: '"+_name+"'"); |
|
325 |
LEMON_ASSERT(i->second.type==ArgParser::BOOL, |
|
326 |
std::string()+"'"+_name+"' is a bool option"); |
|
327 |
return *(i->second.bool_p); |
|
328 | 328 |
} |
329 | 329 |
///\e |
330 | 330 |
operator std::string() |
331 | 331 |
{ |
332 |
Opts::iterator i = _parser._opts.find(_name); |
|
333 |
LEMON_ASSERT(i!=_parser._opts.end(), |
|
334 |
std::string()+"Unkown option: '"+_name+"'"); |
|
335 |
LEMON_ASSERT(i->second.type==ArgParser::STRING, |
|
336 |
std::string()+"'"+_name+"' is a string option"); |
|
337 |
return *(i->second.string_p); |
|
332 |
Opts::iterator i = _parser._opts.find(_name); |
|
333 |
LEMON_ASSERT(i!=_parser._opts.end(), |
|
334 |
std::string()+"Unkown option: '"+_name+"'"); |
|
335 |
LEMON_ASSERT(i->second.type==ArgParser::STRING, |
|
336 |
std::string()+"'"+_name+"' is a string option"); |
|
337 |
return *(i->second.string_p); |
|
338 | 338 |
} |
339 | 339 |
///\e |
340 |
operator double() |
|
340 |
operator double() |
|
341 | 341 |
{ |
342 |
Opts::iterator i = _parser._opts.find(_name); |
|
343 |
LEMON_ASSERT(i!=_parser._opts.end(), |
|
344 |
std::string()+"Unkown option: '"+_name+"'"); |
|
345 |
LEMON_ASSERT(i->second.type==ArgParser::DOUBLE || |
|
346 |
i->second.type==ArgParser::INTEGER, |
|
347 |
std::string()+"'"+_name+"' is a floating point option"); |
|
348 |
return i->second.type==ArgParser::DOUBLE ? |
|
349 |
*(i->second.double_p) : *(i->second.int_p); |
|
342 |
Opts::iterator i = _parser._opts.find(_name); |
|
343 |
LEMON_ASSERT(i!=_parser._opts.end(), |
|
344 |
std::string()+"Unkown option: '"+_name+"'"); |
|
345 |
LEMON_ASSERT(i->second.type==ArgParser::DOUBLE || |
|
346 |
i->second.type==ArgParser::INTEGER, |
|
347 |
std::string()+"'"+_name+"' is a floating point option"); |
|
348 |
return i->second.type==ArgParser::DOUBLE ? |
|
349 |
*(i->second.double_p) : *(i->second.int_p); |
|
350 | 350 |
} |
351 | 351 |
///\e |
352 |
operator int() |
|
352 |
operator int() |
|
353 | 353 |
{ |
354 |
Opts::iterator i = _parser._opts.find(_name); |
|
355 |
LEMON_ASSERT(i!=_parser._opts.end(), |
|
356 |
std::string()+"Unkown option: '"+_name+"'"); |
|
357 |
LEMON_ASSERT(i->second.type==ArgParser::INTEGER, |
|
358 |
std::string()+"'"+_name+"' is an integer option"); |
|
359 |
return *(i->second.int_p); |
|
354 |
Opts::iterator i = _parser._opts.find(_name); |
|
355 |
LEMON_ASSERT(i!=_parser._opts.end(), |
|
356 |
std::string()+"Unkown option: '"+_name+"'"); |
|
357 |
LEMON_ASSERT(i->second.type==ArgParser::INTEGER, |
|
358 |
std::string()+"'"+_name+"' is an integer option"); |
|
359 |
return *(i->second.int_p); |
|
360 | 360 |
} |
361 | 361 |
|
362 | 362 |
}; |
363 | 363 |
|
364 | 364 |
///Give back the value of an option |
365 |
|
|
365 |
|
|
366 | 366 |
///Give back the value of an option. |
367 | 367 |
///\sa RefType |
368 | 368 |
RefType operator[](const std::string &n) |
369 | 369 |
{ |
370 | 370 |
return RefType(*this, n); |
371 |
} |
|
371 |
} |
|
372 | 372 |
|
373 | 373 |
///Give back the non-option type arguments. |
374 | 374 |
|
375 | 375 |
///Give back a reference to a vector consisting of the program arguments |
376 | 376 |
///not starting with a '-' character. |
377 | 377 |
std::vector<std::string> &files() { return _file_args; } |
378 |
|
|
378 |
|
|
379 | 379 |
}; |
380 | 380 |
} |
381 | 381 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -28,7 +28,7 @@ |
28 | 28 |
namespace lemon { |
29 | 29 |
|
30 | 30 |
inline void assert_fail_log(const char *file, int line, const char *function, |
31 |
|
|
31 |
const char *message, const char *assertion) |
|
32 | 32 |
{ |
33 | 33 |
std::cerr << file << ":" << line << ": "; |
34 | 34 |
if (function) |
... | ... |
@@ -40,23 +40,23 @@ |
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
inline void assert_fail_abort(const char *file, int line, |
43 |
const char *function, const char* message, |
|
44 |
const char *assertion) |
|
43 |
const char *function, const char* message, |
|
44 |
const char *assertion) |
|
45 | 45 |
{ |
46 | 46 |
assert_fail_log(file, line, function, message, assertion); |
47 | 47 |
std::abort(); |
48 | 48 |
} |
49 | 49 |
|
50 | 50 |
namespace _assert_bits { |
51 |
|
|
52 |
|
|
51 |
|
|
52 |
|
|
53 | 53 |
inline const char* cstringify(const std::string& str) { |
54 | 54 |
return str.c_str(); |
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
inline const char* cstringify(const char* str) { |
58 | 58 |
return str; |
59 |
} |
|
59 |
} |
|
60 | 60 |
} |
61 | 61 |
} |
62 | 62 |
|
... | ... |
@@ -66,17 +66,17 @@ |
66 | 66 |
#undef LEMON_FIXME |
67 | 67 |
#undef LEMON_DEBUG |
68 | 68 |
|
69 |
#if (defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ |
|
70 |
(defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ |
|
69 |
#if (defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ |
|
70 |
(defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ |
|
71 | 71 |
(defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1 |
72 | 72 |
#error "LEMON assertion system is not set properly" |
73 | 73 |
#endif |
74 | 74 |
|
75 |
#if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ |
|
76 |
(defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ |
|
77 |
(defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 || \ |
|
78 |
defined(LEMON_ENABLE_ASSERTS)) && \ |
|
79 |
|
|
75 |
#if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ |
|
76 |
(defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ |
|
77 |
(defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 || \ |
|
78 |
defined(LEMON_ENABLE_ASSERTS)) && \ |
|
79 |
(defined(LEMON_DISABLE_ASSERTS) || \ |
|
80 | 80 |
defined(NDEBUG)) |
81 | 81 |
#error "LEMON assertion system is not set properly" |
82 | 82 |
#endif |
... | ... |
@@ -136,12 +136,12 @@ |
136 | 136 |
/// make CXXFLAGS='-DLEMON_DISABLE_ASSERTS' |
137 | 137 |
/// \endcode |
138 | 138 |
/// The checking is also disabled when the standard macro \c NDEBUG is defined. |
139 |
/// |
|
139 |
/// |
|
140 | 140 |
/// The LEMON assertion system has a wide range of customization |
141 | 141 |
/// properties. As a default behaviour the failed assertion prints a |
142 | 142 |
/// short log message to the standard error and aborts the execution. |
143 | 143 |
/// |
144 |
/// The following modes can be used in the assertion system: |
|
144 |
/// The following modes can be used in the assertion system: |
|
145 | 145 |
/// |
146 | 146 |
/// - \c LEMON_ASSERT_LOG The failed assertion prints a short log |
147 | 147 |
/// message to the standard error and continues the execution. |
... | ... |
@@ -155,7 +155,7 @@ |
155 | 155 |
/// const char* message, const char* assertion); |
156 | 156 |
/// \endcode |
157 | 157 |
/// The name of the function should be defined as the \c |
158 |
/// LEMON_CUSTOM_ASSERT_HANDLER macro name. |
|
158 |
/// LEMON_CUSTOM_ASSERT_HANDLER macro name. |
|
159 | 159 |
/// \code |
160 | 160 |
/// #define LEMON_CUSTOM_ASSERT_HANDLER custom_assert_handler |
161 | 161 |
/// \endcode |
... | ... |
@@ -166,11 +166,11 @@ |
166 | 166 |
/// If the macros are redefined with other settings and the |
167 | 167 |
/// \ref lemon/assert.h "assert.h" file is reincluded, then the |
168 | 168 |
/// behaviour is changed appropiately to the new settings. |
169 |
# define LEMON_ASSERT(exp, msg) \ |
|
170 |
(static_cast<void> (!!(exp) ? 0 : ( \ |
|
171 |
LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ |
|
172 |
LEMON_FUNCTION_NAME, \ |
|
173 |
|
|
169 |
# define LEMON_ASSERT(exp, msg) \ |
|
170 |
(static_cast<void> (!!(exp) ? 0 : ( \ |
|
171 |
LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ |
|
172 |
LEMON_FUNCTION_NAME, \ |
|
173 |
::lemon::_assert_bits::cstringify(msg), #exp), 0))) |
|
174 | 174 |
|
175 | 175 |
/// \ingroup exceptions |
176 | 176 |
/// |
... | ... |
@@ -182,11 +182,11 @@ |
182 | 182 |
/// LEMON_ASSERT(false, msg); |
183 | 183 |
/// \endcode |
184 | 184 |
/// |
185 |
/// \see LEMON_ASSERT |
|
186 |
# define LEMON_FIXME(msg) \ |
|
187 |
(LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \ |
|
188 |
::lemon::_assert_bits::cstringify(msg), \ |
|
189 |
|
|
185 |
/// \see LEMON_ASSERT |
|
186 |
# define LEMON_FIXME(msg) \ |
|
187 |
(LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \ |
|
188 |
::lemon::_assert_bits::cstringify(msg), \ |
|
189 |
static_cast<const char*>(0))) |
|
190 | 190 |
|
191 | 191 |
/// \ingroup exceptions |
192 | 192 |
/// |
... | ... |
@@ -210,12 +210,12 @@ |
210 | 210 |
/// current behaviour depends on the settings of \c LEMON_ASSERT |
211 | 211 |
/// macro. |
212 | 212 |
/// |
213 |
/// \see LEMON_ASSERT |
|
214 |
# define LEMON_DEBUG(exp, msg) \ |
|
215 |
|
|
213 |
/// \see LEMON_ASSERT |
|
214 |
# define LEMON_DEBUG(exp, msg) \ |
|
215 |
(static_cast<void> (!!(exp) ? 0 : ( \ |
|
216 | 216 |
LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ |
217 |
LEMON_FUNCTION_NAME, \ |
|
218 |
::lemon::_assert_bits::cstringify(msg), #exp), 0))) |
|
217 |
LEMON_FUNCTION_NAME, \ |
|
218 |
::lemon::_assert_bits::cstringify(msg), #exp), 0))) |
|
219 | 219 |
|
220 | 220 |
#else |
221 | 221 |
|
... | ... |
@@ -224,24 +224,24 @@ |
224 | 224 |
# define LEMON_FIXME(msg) (static_cast<void>(0)) |
225 | 225 |
# define LEMON_DEBUG(exp, msg) (static_cast<void>(0)) |
226 | 226 |
# else |
227 |
# define LEMON_ASSERT(exp, msg) \ |
|
228 |
(static_cast<void> (!!(exp) ? 0 : ( \ |
|
227 |
# define LEMON_ASSERT(exp, msg) \ |
|
228 |
(static_cast<void> (!!(exp) ? 0 : ( \ |
|
229 | 229 |
LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ |
230 |
LEMON_FUNCTION_NAME, \ |
|
231 |
::lemon::_assert_bits::cstringify(msg), \ |
|
232 |
#exp), 0))) |
|
233 |
# define LEMON_FIXME(msg) \ |
|
234 |
(LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \ |
|
235 |
::lemon::_assert_bits::cstringify(msg), \ |
|
236 |
|
|
230 |
LEMON_FUNCTION_NAME, \ |
|
231 |
::lemon::_assert_bits::cstringify(msg), \ |
|
232 |
#exp), 0))) |
|
233 |
# define LEMON_FIXME(msg) \ |
|
234 |
(LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \ |
|
235 |
::lemon::_assert_bits::cstringify(msg), \ |
|
236 |
static_cast<const char*>(0))) |
|
237 | 237 |
|
238 | 238 |
# if LEMON_ENABLE_DEBUG |
239 | 239 |
# define LEMON_DEBUG(exp, msg) |
240 | 240 |
(static_cast<void> (!!(exp) ? 0 : ( \ |
241 | 241 |
LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ |
242 | 242 |
LEMON_FUNCTION_NAME, \ |
243 |
::lemon::_assert_bits::cstringify(msg), \ |
|
244 |
#exp), 0))) |
|
243 |
::lemon::_assert_bits::cstringify(msg), \ |
|
244 |
#exp), 0))) |
|
245 | 245 |
# else |
246 | 246 |
# define LEMON_DEBUG(exp, msg) (static_cast<void>(0)) |
247 | 247 |
# endif |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -33,7 +33,7 @@ |
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
|
36 |
|
|
36 |
|
|
37 | 37 |
///Default traits class of Bfs class. |
38 | 38 |
|
39 | 39 |
///Default traits class of Bfs class. |
... | ... |
@@ -41,34 +41,34 @@ |
41 | 41 |
template<class GR> |
42 | 42 |
struct BfsDefaultTraits |
43 | 43 |
{ |
44 |
///The digraph type the algorithm runs on. |
|
44 |
///The digraph type the algorithm runs on. |
|
45 | 45 |
typedef GR Digraph; |
46 | 46 |
///\brief The type of the map that stores the last |
47 | 47 |
///arcs of the shortest paths. |
48 |
/// |
|
48 |
/// |
|
49 | 49 |
///The type of the map that stores the last |
50 | 50 |
///arcs of the shortest paths. |
51 | 51 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
52 | 52 |
/// |
53 | 53 |
typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap; |
54 | 54 |
///Instantiates a PredMap. |
55 |
|
|
56 |
///This function instantiates a \ref PredMap. |
|
55 |
|
|
56 |
///This function instantiates a \ref PredMap. |
|
57 | 57 |
///\param G is the digraph, to which we would like to define the PredMap. |
58 | 58 |
///\todo The digraph alone may be insufficient to initialize |
59 |
static PredMap *createPredMap(const GR &G) |
|
59 |
static PredMap *createPredMap(const GR &G) |
|
60 | 60 |
{ |
61 | 61 |
return new PredMap(G); |
62 | 62 |
} |
63 | 63 |
///The type of the map that indicates which nodes are processed. |
64 |
|
|
64 |
|
|
65 | 65 |
///The type of the map that indicates which nodes are processed. |
66 | 66 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
67 | 67 |
///\todo named parameter to set this type, function to read and write. |
68 | 68 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
69 | 69 |
///Instantiates a ProcessedMap. |
70 |
|
|
71 |
///This function instantiates a \ref ProcessedMap. |
|
70 |
|
|
71 |
///This function instantiates a \ref ProcessedMap. |
|
72 | 72 |
///\param g is the digraph, to which |
73 | 73 |
///we would like to define the \ref ProcessedMap |
74 | 74 |
#ifdef DOXYGEN |
... | ... |
@@ -80,14 +80,14 @@ |
80 | 80 |
return new ProcessedMap(); |
81 | 81 |
} |
82 | 82 |
///The type of the map that indicates which nodes are reached. |
83 |
|
|
83 |
|
|
84 | 84 |
///The type of the map that indicates which nodes are reached. |
85 | 85 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
86 | 86 |
///\todo named parameter to set this type, function to read and write. |
87 | 87 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
88 | 88 |
///Instantiates a ReachedMap. |
89 |
|
|
90 |
///This function instantiates a \ref ReachedMap. |
|
89 |
|
|
90 |
///This function instantiates a \ref ReachedMap. |
|
91 | 91 |
///\param G is the digraph, to which |
92 | 92 |
///we would like to define the \ref ReachedMap. |
93 | 93 |
static ReachedMap *createReachedMap(const GR &G) |
... | ... |
@@ -95,23 +95,23 @@ |
95 | 95 |
return new ReachedMap(G); |
96 | 96 |
} |
97 | 97 |
///The type of the map that stores the dists of the nodes. |
98 |
|
|
98 |
|
|
99 | 99 |
///The type of the map that stores the dists of the nodes. |
100 | 100 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
101 | 101 |
/// |
102 | 102 |
typedef typename Digraph::template NodeMap<int> DistMap; |
103 | 103 |
///Instantiates a DistMap. |
104 |
|
|
105 |
///This function instantiates a \ref DistMap. |
|
104 |
|
|
105 |
///This function instantiates a \ref DistMap. |
|
106 | 106 |
///\param G is the digraph, to which we would like to define the \ref DistMap |
107 | 107 |
static DistMap *createDistMap(const GR &G) |
108 | 108 |
{ |
109 | 109 |
return new DistMap(G); |
110 | 110 |
} |
111 | 111 |
}; |
112 |
|
|
112 |
|
|
113 | 113 |
///%BFS algorithm class. |
114 |
|
|
114 |
|
|
115 | 115 |
///\ingroup search |
116 | 116 |
///This class provides an efficient implementation of the %BFS algorithm. |
117 | 117 |
/// |
... | ... |
@@ -126,10 +126,10 @@ |
126 | 126 |
|
127 | 127 |
#ifdef DOXYGEN |
128 | 128 |
template <typename GR, |
129 |
|
|
129 |
typename TR> |
|
130 | 130 |
#else |
131 | 131 |
template <typename GR=ListDigraph, |
132 |
|
|
132 |
typename TR=BfsDefaultTraits<GR> > |
|
133 | 133 |
#endif |
134 | 134 |
class Bfs { |
135 | 135 |
public: |
... | ... |
@@ -142,14 +142,14 @@ |
142 | 142 |
class UninitializedParameter : public lemon::UninitializedParameter { |
143 | 143 |
public: |
144 | 144 |
virtual const char* what() const throw() { |
145 |
|
|
145 |
return "lemon::Bfs::UninitializedParameter"; |
|
146 | 146 |
} |
147 | 147 |
}; |
148 | 148 |
|
149 | 149 |
typedef TR Traits; |
150 | 150 |
///The type of the underlying digraph. |
151 | 151 |
typedef typename TR::Digraph Digraph; |
152 |
|
|
152 |
|
|
153 | 153 |
///\brief The type of the map that stores the last |
154 | 154 |
///arcs of the shortest paths. |
155 | 155 |
typedef typename TR::PredMap PredMap; |
... | ... |
@@ -190,34 +190,34 @@ |
190 | 190 |
int _curr_dist; |
191 | 191 |
|
192 | 192 |
///Creates the maps if necessary. |
193 |
|
|
193 |
|
|
194 | 194 |
///\todo Better memory allocation (instead of new). |
195 |
void create_maps() |
|
195 |
void create_maps() |
|
196 | 196 |
{ |
197 | 197 |
if(!_pred) { |
198 |
local_pred = true; |
|
199 |
_pred = Traits::createPredMap(*G); |
|
198 |
local_pred = true; |
|
199 |
_pred = Traits::createPredMap(*G); |
|
200 | 200 |
} |
201 | 201 |
if(!_dist) { |
202 |
local_dist = true; |
|
203 |
_dist = Traits::createDistMap(*G); |
|
202 |
local_dist = true; |
|
203 |
_dist = Traits::createDistMap(*G); |
|
204 | 204 |
} |
205 | 205 |
if(!_reached) { |
206 |
local_reached = true; |
|
207 |
_reached = Traits::createReachedMap(*G); |
|
206 |
local_reached = true; |
|
207 |
_reached = Traits::createReachedMap(*G); |
|
208 | 208 |
} |
209 | 209 |
if(!_processed) { |
210 |
local_processed = true; |
|
211 |
_processed = Traits::createProcessedMap(*G); |
|
210 |
local_processed = true; |
|
211 |
_processed = Traits::createProcessedMap(*G); |
|
212 | 212 |
} |
213 | 213 |
} |
214 | 214 |
|
215 | 215 |
protected: |
216 |
|
|
216 |
|
|
217 | 217 |
Bfs() {} |
218 |
|
|
218 |
|
|
219 | 219 |
public: |
220 |
|
|
220 |
|
|
221 | 221 |
typedef Bfs Create; |
222 | 222 |
|
223 | 223 |
///\name Named template parameters |
... | ... |
@@ -227,9 +227,9 @@ |
227 | 227 |
template <class T> |
228 | 228 |
struct DefPredMapTraits : public Traits { |
229 | 229 |
typedef T PredMap; |
230 |
static PredMap *createPredMap(const Digraph &) |
|
230 |
static PredMap *createPredMap(const Digraph &) |
|
231 | 231 |
{ |
232 |
|
|
232 |
throw UninitializedParameter(); |
|
233 | 233 |
} |
234 | 234 |
}; |
235 | 235 |
///\brief \ref named-templ-param "Named parameter" for setting |
... | ... |
@@ -238,16 +238,16 @@ |
238 | 238 |
///\ref named-templ-param "Named parameter" for setting PredMap type |
239 | 239 |
/// |
240 | 240 |
template <class T> |
241 |
struct DefPredMap : public Bfs< Digraph, DefPredMapTraits<T> > { |
|
241 |
struct DefPredMap : public Bfs< Digraph, DefPredMapTraits<T> > { |
|
242 | 242 |
typedef Bfs< Digraph, DefPredMapTraits<T> > Create; |
243 | 243 |
}; |
244 |
|
|
244 |
|
|
245 | 245 |
template <class T> |
246 | 246 |
struct DefDistMapTraits : public Traits { |
247 | 247 |
typedef T DistMap; |
248 |
static DistMap *createDistMap(const Digraph &) |
|
248 |
static DistMap *createDistMap(const Digraph &) |
|
249 | 249 |
{ |
250 |
|
|
250 |
throw UninitializedParameter(); |
|
251 | 251 |
} |
252 | 252 |
}; |
253 | 253 |
///\brief \ref named-templ-param "Named parameter" for setting |
... | ... |
@@ -256,16 +256,16 @@ |
256 | 256 |
///\ref named-templ-param "Named parameter" for setting DistMap type |
257 | 257 |
/// |
258 | 258 |
template <class T> |
259 |
struct DefDistMap : public Bfs< Digraph, DefDistMapTraits<T> > { |
|
259 |
struct DefDistMap : public Bfs< Digraph, DefDistMapTraits<T> > { |
|
260 | 260 |
typedef Bfs< Digraph, DefDistMapTraits<T> > Create; |
261 | 261 |
}; |
262 |
|
|
262 |
|
|
263 | 263 |
template <class T> |
264 | 264 |
struct DefReachedMapTraits : public Traits { |
265 | 265 |
typedef T ReachedMap; |
266 |
static ReachedMap *createReachedMap(const Digraph &) |
|
266 |
static ReachedMap *createReachedMap(const Digraph &) |
|
267 | 267 |
{ |
268 |
|
|
268 |
throw UninitializedParameter(); |
|
269 | 269 |
} |
270 | 270 |
}; |
271 | 271 |
///\brief \ref named-templ-param "Named parameter" for setting |
... | ... |
@@ -274,16 +274,16 @@ |
274 | 274 |
///\ref named-templ-param "Named parameter" for setting ReachedMap type |
275 | 275 |
/// |
276 | 276 |
template <class T> |
277 |
struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits<T> > { |
|
277 |
struct DefReachedMap : public Bfs< Digraph, DefReachedMapTraits<T> > { |
|
278 | 278 |
typedef Bfs< Digraph, DefReachedMapTraits<T> > Create; |
279 | 279 |
}; |
280 |
|
|
280 |
|
|
281 | 281 |
template <class T> |
282 | 282 |
struct DefProcessedMapTraits : public Traits { |
283 | 283 |
typedef T ProcessedMap; |
284 |
static ProcessedMap *createProcessedMap(const Digraph &) |
|
284 |
static ProcessedMap *createProcessedMap(const Digraph &) |
|
285 | 285 |
{ |
286 |
|
|
286 |
throw UninitializedParameter(); |
|
287 | 287 |
} |
288 | 288 |
}; |
289 | 289 |
///\brief \ref named-templ-param "Named parameter" for setting |
... | ... |
@@ -295,12 +295,12 @@ |
295 | 295 |
struct DefProcessedMap : public Bfs< Digraph, DefProcessedMapTraits<T> > { |
296 | 296 |
typedef Bfs< Digraph, DefProcessedMapTraits<T> > Create; |
297 | 297 |
}; |
298 |
|
|
298 |
|
|
299 | 299 |
struct DefDigraphProcessedMapTraits : public Traits { |
300 | 300 |
typedef typename Digraph::template NodeMap<bool> ProcessedMap; |
301 |
static ProcessedMap *createProcessedMap(const Digraph &G) |
|
301 |
static ProcessedMap *createProcessedMap(const Digraph &G) |
|
302 | 302 |
{ |
303 |
|
|
303 |
return new ProcessedMap(G); |
|
304 | 304 |
} |
305 | 305 |
}; |
306 | 306 |
///\brief \ref named-templ-param "Named parameter" |
... | ... |
@@ -311,16 +311,16 @@ |
311 | 311 |
///If you don't set it explicitly, it will be automatically allocated. |
312 | 312 |
template <class T> |
313 | 313 |
struct DefProcessedMapToBeDefaultMap : |
314 |
public Bfs< Digraph, DefDigraphProcessedMapTraits> { |
|
314 |
public Bfs< Digraph, DefDigraphProcessedMapTraits> { |
|
315 | 315 |
typedef Bfs< Digraph, DefDigraphProcessedMapTraits> Create; |
316 | 316 |
}; |
317 |
|
|
317 |
|
|
318 | 318 |
///@} |
319 | 319 |
|
320 |
public: |
|
321 |
|
|
320 |
public: |
|
321 |
|
|
322 | 322 |
///Constructor. |
323 |
|
|
323 |
|
|
324 | 324 |
///\param _G the digraph the algorithm will run on. |
325 | 325 |
/// |
326 | 326 |
Bfs(const Digraph& _G) : |
... | ... |
@@ -330,9 +330,9 @@ |
330 | 330 |
_reached(NULL), local_reached(false), |
331 | 331 |
_processed(NULL), local_processed(false) |
332 | 332 |
{ } |
333 |
|
|
333 |
|
|
334 | 334 |
///Destructor. |
335 |
~Bfs() |
|
335 |
~Bfs() |
|
336 | 336 |
{ |
337 | 337 |
if(local_pred) delete _pred; |
338 | 338 |
if(local_dist) delete _dist; |
... | ... |
@@ -347,11 +347,11 @@ |
347 | 347 |
///it will allocate one. The destructor deallocates this |
348 | 348 |
///automatically allocated map, of course. |
349 | 349 |
///\return <tt> (*this) </tt> |
350 |
Bfs &predMap(PredMap &m) |
|
350 |
Bfs &predMap(PredMap &m) |
|
351 | 351 |
{ |
352 | 352 |
if(local_pred) { |
353 |
delete _pred; |
|
354 |
local_pred=false; |
|
353 |
delete _pred; |
|
354 |
local_pred=false; |
|
355 | 355 |
} |
356 | 356 |
_pred = &m; |
357 | 357 |
return *this; |
... | ... |
@@ -364,11 +364,11 @@ |
364 | 364 |
///it will allocate one. The destructor deallocates this |
365 | 365 |
///automatically allocated map, of course. |
366 | 366 |
///\return <tt> (*this) </tt> |
367 |
Bfs &reachedMap(ReachedMap &m) |
|
367 |
Bfs &reachedMap(ReachedMap &m) |
|
368 | 368 |
{ |
369 | 369 |
if(local_reached) { |
370 |
delete _reached; |
|
371 |
local_reached=false; |
|
370 |
delete _reached; |
|
371 |
local_reached=false; |
|
372 | 372 |
} |
373 | 373 |
_reached = &m; |
374 | 374 |
return *this; |
... | ... |
@@ -381,11 +381,11 @@ |
381 | 381 |
///it will allocate one. The destructor deallocates this |
382 | 382 |
///automatically allocated map, of course. |
383 | 383 |
///\return <tt> (*this) </tt> |
384 |
Bfs &processedMap(ProcessedMap &m) |
|
384 |
Bfs &processedMap(ProcessedMap &m) |
|
385 | 385 |
{ |
386 | 386 |
if(local_processed) { |
387 |
delete _processed; |
|
388 |
local_processed=false; |
|
387 |
delete _processed; |
|
388 |
local_processed=false; |
|
389 | 389 |
} |
390 | 390 |
_processed = &m; |
391 | 391 |
return *this; |
... | ... |
@@ -398,11 +398,11 @@ |
398 | 398 |
///it will allocate one. The destructor deallocates this |
399 | 399 |
///automatically allocated map, of course. |
400 | 400 |
///\return <tt> (*this) </tt> |
401 |
Bfs &distMap(DistMap &m) |
|
401 |
Bfs &distMap(DistMap &m) |
|
402 | 402 |
{ |
403 | 403 |
if(local_dist) { |
404 |
delete _dist; |
|
405 |
local_dist=false; |
|
404 |
delete _dist; |
|
405 |
local_dist=false; |
|
406 | 406 |
} |
407 | 407 |
_dist = &m; |
408 | 408 |
return *this; |
... | ... |
@@ -432,12 +432,12 @@ |
432 | 432 |
_queue_head=_queue_tail=0; |
433 | 433 |
_curr_dist=1; |
434 | 434 |
for ( NodeIt u(*G) ; u!=INVALID ; ++u ) { |
435 |
_pred->set(u,INVALID); |
|
436 |
_reached->set(u,false); |
|
437 |
|
|
435 |
_pred->set(u,INVALID); |
|
436 |
_reached->set(u,false); |
|
437 |
_processed->set(u,false); |
|
438 | 438 |
} |
439 | 439 |
} |
440 |
|
|
440 |
|
|
441 | 441 |
///Adds a new source node. |
442 | 442 |
|
443 | 443 |
///Adds a new source node to the set of nodes to be processed. |
... | ... |
@@ -445,15 +445,15 @@ |
445 | 445 |
void addSource(Node s) |
446 | 446 |
{ |
447 | 447 |
if(!(*_reached)[s]) |
448 |
{ |
|
449 |
_reached->set(s,true); |
|
450 |
_pred->set(s,INVALID); |
|
451 |
_dist->set(s,0); |
|
452 |
_queue[_queue_head++]=s; |
|
453 |
_queue_next_dist=_queue_head; |
|
454 |
|
|
448 |
{ |
|
449 |
_reached->set(s,true); |
|
450 |
_pred->set(s,INVALID); |
|
451 |
_dist->set(s,0); |
|
452 |
_queue[_queue_head++]=s; |
|
453 |
_queue_next_dist=_queue_head; |
|
454 |
} |
|
455 | 455 |
} |
456 |
|
|
456 |
|
|
457 | 457 |
///Processes the next node. |
458 | 458 |
|
459 | 459 |
///Processes the next node. |
... | ... |
@@ -464,19 +464,19 @@ |
464 | 464 |
Node processNextNode() |
465 | 465 |
{ |
466 | 466 |
if(_queue_tail==_queue_next_dist) { |
467 |
_curr_dist++; |
|
468 |
_queue_next_dist=_queue_head; |
|
467 |
_curr_dist++; |
|
468 |
_queue_next_dist=_queue_head; |
|
469 | 469 |
} |
470 | 470 |
Node n=_queue[_queue_tail++]; |
471 | 471 |
_processed->set(n,true); |
472 | 472 |
Node m; |
473 | 473 |
for(OutArcIt e(*G,n);e!=INVALID;++e) |
474 |
if(!(*_reached)[m=G->target(e)]) { |
|
475 |
_queue[_queue_head++]=m; |
|
476 |
_reached->set(m,true); |
|
477 |
_pred->set(m,e); |
|
478 |
_dist->set(m,_curr_dist); |
|
479 |
} |
|
474 |
if(!(*_reached)[m=G->target(e)]) { |
|
475 |
_queue[_queue_head++]=m; |
|
476 |
_reached->set(m,true); |
|
477 |
_pred->set(m,e); |
|
478 |
_dist->set(m,_curr_dist); |
|
479 |
} |
|
480 | 480 |
return n; |
481 | 481 |
} |
482 | 482 |
|
... | ... |
@@ -495,20 +495,20 @@ |
495 | 495 |
Node processNextNode(Node target, bool& reach) |
496 | 496 |
{ |
497 | 497 |
if(_queue_tail==_queue_next_dist) { |
498 |
_curr_dist++; |
|
499 |
_queue_next_dist=_queue_head; |
|
498 |
_curr_dist++; |
|
499 |
_queue_next_dist=_queue_head; |
|
500 | 500 |
} |
501 | 501 |
Node n=_queue[_queue_tail++]; |
502 | 502 |
_processed->set(n,true); |
503 | 503 |
Node m; |
504 | 504 |
for(OutArcIt e(*G,n);e!=INVALID;++e) |
505 |
if(!(*_reached)[m=G->target(e)]) { |
|
506 |
_queue[_queue_head++]=m; |
|
507 |
_reached->set(m,true); |
|
508 |
_pred->set(m,e); |
|
509 |
|
|
505 |
if(!(*_reached)[m=G->target(e)]) { |
|
506 |
_queue[_queue_head++]=m; |
|
507 |
_reached->set(m,true); |
|
508 |
_pred->set(m,e); |
|
509 |
_dist->set(m,_curr_dist); |
|
510 | 510 |
reach = reach || (target == m); |
511 |
|
|
511 |
} |
|
512 | 512 |
return n; |
513 | 513 |
} |
514 | 514 |
|
... | ... |
@@ -528,23 +528,23 @@ |
528 | 528 |
Node processNextNode(const NM& nm, Node& rnode) |
529 | 529 |
{ |
530 | 530 |
if(_queue_tail==_queue_next_dist) { |
531 |
_curr_dist++; |
|
532 |
_queue_next_dist=_queue_head; |
|
531 |
_curr_dist++; |
|
532 |
_queue_next_dist=_queue_head; |
|
533 | 533 |
} |
534 | 534 |
Node n=_queue[_queue_tail++]; |
535 | 535 |
_processed->set(n,true); |
536 | 536 |
Node m; |
537 | 537 |
for(OutArcIt e(*G,n);e!=INVALID;++e) |
538 |
if(!(*_reached)[m=G->target(e)]) { |
|
539 |
_queue[_queue_head++]=m; |
|
540 |
_reached->set(m,true); |
|
541 |
_pred->set(m,e); |
|
542 |
_dist->set(m,_curr_dist); |
|
543 |
if (nm[m] && rnode == INVALID) rnode = m; |
|
544 |
|
|
538 |
if(!(*_reached)[m=G->target(e)]) { |
|
539 |
_queue[_queue_head++]=m; |
|
540 |
_reached->set(m,true); |
|
541 |
_pred->set(m,e); |
|
542 |
_dist->set(m,_curr_dist); |
|
543 |
if (nm[m] && rnode == INVALID) rnode = m; |
|
544 |
} |
|
545 | 545 |
return n; |
546 | 546 |
} |
547 |
|
|
547 |
|
|
548 | 548 |
///Next node to be processed. |
549 | 549 |
|
550 | 550 |
///Next node to be processed. |
... | ... |
@@ -552,10 +552,10 @@ |
552 | 552 |
///\return The next node to be processed or INVALID if the queue is |
553 | 553 |
/// empty. |
554 | 554 |
Node nextNode() |
555 |
{ |
|
555 |
{ |
|
556 | 556 |
return _queue_tail<_queue_head?_queue[_queue_tail]:INVALID; |
557 | 557 |
} |
558 |
|
|
558 |
|
|
559 | 559 |
///\brief Returns \c false if there are nodes |
560 | 560 |
///to be processed in the queue |
561 | 561 |
/// |
... | ... |
@@ -563,10 +563,10 @@ |
563 | 563 |
///to be processed in the queue |
564 | 564 |
bool emptyQueue() { return _queue_tail==_queue_head; } |
565 | 565 |
///Returns the number of the nodes to be processed. |
566 |
|
|
566 |
|
|
567 | 567 |
///Returns the number of the nodes to be processed in the queue. |
568 | 568 |
int queueSize() { return _queue_head-_queue_tail; } |
569 |
|
|
569 |
|
|
570 | 570 |
///Executes the algorithm. |
571 | 571 |
|
572 | 572 |
///Executes the algorithm. |
... | ... |
@@ -584,7 +584,7 @@ |
584 | 584 |
{ |
585 | 585 |
while ( !emptyQueue() ) processNextNode(); |
586 | 586 |
} |
587 |
|
|
587 |
|
|
588 | 588 |
///Executes the algorithm until \c dest is reached. |
589 | 589 |
|
590 | 590 |
///Executes the algorithm until \c dest is reached. |
... | ... |
@@ -602,7 +602,7 @@ |
602 | 602 |
bool reach = false; |
603 | 603 |
while ( !emptyQueue() && !reach ) processNextNode(dest, reach); |
604 | 604 |
} |
605 |
|
|
605 |
|
|
606 | 606 |
///Executes the algorithm until a condition is met. |
607 | 607 |
|
608 | 608 |
///Executes the algorithm until a condition is met. |
... | ... |
@@ -621,13 +621,13 @@ |
621 | 621 |
{ |
622 | 622 |
Node rnode = INVALID; |
623 | 623 |
while ( !emptyQueue() && rnode == INVALID ) { |
624 |
|
|
624 |
processNextNode(nm, rnode); |
|
625 | 625 |
} |
626 | 626 |
return rnode; |
627 | 627 |
} |
628 |
|
|
628 |
|
|
629 | 629 |
///Runs %BFS algorithm from node \c s. |
630 |
|
|
630 |
|
|
631 | 631 |
///This method runs the %BFS algorithm from a root node \c s |
632 | 632 |
///in order to |
633 | 633 |
///compute the |
... | ... |
@@ -646,9 +646,9 @@ |
646 | 646 |
addSource(s); |
647 | 647 |
start(); |
648 | 648 |
} |
649 |
|
|
649 |
|
|
650 | 650 |
///Finds the shortest path between \c s and \c t. |
651 |
|
|
651 |
|
|
652 | 652 |
///Finds the shortest path between \c s and \c t. |
653 | 653 |
/// |
654 | 654 |
///\return The length of the shortest s---t path if there exists one, |
... | ... |
@@ -666,7 +666,7 @@ |
666 | 666 |
start(t); |
667 | 667 |
return reached(t) ? _curr_dist : 0; |
668 | 668 |
} |
669 |
|
|
669 |
|
|
670 | 670 |
///@} |
671 | 671 |
|
672 | 672 |
///\name Query Functions |
... | ... |
@@ -674,16 +674,16 @@ |
674 | 674 |
///functions.\n |
675 | 675 |
///Before the use of these functions, |
676 | 676 |
///either run() or start() must be calleb. |
677 |
|
|
677 |
|
|
678 | 678 |
///@{ |
679 | 679 |
|
680 | 680 |
typedef PredMapPath<Digraph, PredMap> Path; |
681 | 681 |
|
682 | 682 |
///Gives back the shortest path. |
683 |
|
|
683 |
|
|
684 | 684 |
///Gives back the shortest path. |
685 | 685 |
///\pre The \c t should be reachable from the source. |
686 |
Path path(Node t) |
|
686 |
Path path(Node t) |
|
687 | 687 |
{ |
688 | 688 |
return Path(*G, *_pred, t); |
689 | 689 |
} |
... | ... |
@@ -722,15 +722,15 @@ |
722 | 722 |
///\pre Either \ref run() or \ref start() must be called before |
723 | 723 |
///using this function. |
724 | 724 |
Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID: |
725 |
G->source((*_pred)[v]); } |
|
726 |
|
|
725 |
G->source((*_pred)[v]); } |
|
726 |
|
|
727 | 727 |
///Returns a reference to the NodeMap of distances. |
728 | 728 |
|
729 | 729 |
///Returns a reference to the NodeMap of distances. |
730 | 730 |
///\pre Either \ref run() or \ref init() must |
731 | 731 |
///be called before using this function. |
732 | 732 |
const DistMap &distMap() const { return *_dist;} |
733 |
|
|
733 |
|
|
734 | 734 |
///Returns a reference to the shortest path tree map. |
735 | 735 |
|
736 | 736 |
///Returns a reference to the NodeMap of the arcs of the |
... | ... |
@@ -738,7 +738,7 @@ |
738 | 738 |
///\pre Either \ref run() or \ref init() |
739 | 739 |
///must be called before using this function. |
740 | 740 |
const PredMap &predMap() const { return *_pred;} |
741 |
|
|
741 |
|
|
742 | 742 |
///Checks if a node is reachable from the root. |
743 | 743 |
|
744 | 744 |
///Returns \c true if \c v is reachable from the root. |
... | ... |
@@ -747,7 +747,7 @@ |
747 | 747 |
///must be called before using this function. |
748 | 748 |
/// |
749 | 749 |
bool reached(Node v) { return (*_reached)[v]; } |
750 |
|
|
750 |
|
|
751 | 751 |
///@} |
752 | 752 |
}; |
753 | 753 |
|
... | ... |
@@ -758,39 +758,39 @@ |
758 | 758 |
template<class GR> |
759 | 759 |
struct BfsWizardDefaultTraits |
760 | 760 |
{ |
761 |
///The digraph type the algorithm runs on. |
|
761 |
///The digraph type the algorithm runs on. |
|
762 | 762 |
typedef GR Digraph; |
763 | 763 |
///\brief The type of the map that stores the last |
764 | 764 |
///arcs of the shortest paths. |
765 |
/// |
|
765 |
/// |
|
766 | 766 |
///The type of the map that stores the last |
767 | 767 |
///arcs of the shortest paths. |
768 | 768 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
769 | 769 |
/// |
770 | 770 |
typedef NullMap<typename Digraph::Node,typename GR::Arc> PredMap; |
771 | 771 |
///Instantiates a PredMap. |
772 |
|
|
773 |
///This function instantiates a \ref PredMap. |
|
772 |
|
|
773 |
///This function instantiates a \ref PredMap. |
|
774 | 774 |
///\param g is the digraph, to which we would like to define the PredMap. |
775 | 775 |
///\todo The digraph alone may be insufficient to initialize |
776 | 776 |
#ifdef DOXYGEN |
777 |
static PredMap *createPredMap(const GR &g) |
|
777 |
static PredMap *createPredMap(const GR &g) |
|
778 | 778 |
#else |
779 |
static PredMap *createPredMap(const GR &) |
|
779 |
static PredMap *createPredMap(const GR &) |
|
780 | 780 |
#endif |
781 | 781 |
{ |
782 | 782 |
return new PredMap(); |
783 | 783 |
} |
784 | 784 |
|
785 | 785 |
///The type of the map that indicates which nodes are processed. |
786 |
|
|
786 |
|
|
787 | 787 |
///The type of the map that indicates which nodes are processed. |
788 | 788 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
789 | 789 |
///\todo named parameter to set this type, function to read and write. |
790 | 790 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
791 | 791 |
///Instantiates a ProcessedMap. |
792 |
|
|
793 |
///This function instantiates a \ref ProcessedMap. |
|
792 |
|
|
793 |
///This function instantiates a \ref ProcessedMap. |
|
794 | 794 |
///\param g is the digraph, to which |
795 | 795 |
///we would like to define the \ref ProcessedMap |
796 | 796 |
#ifdef DOXYGEN |
... | ... |
@@ -802,14 +802,14 @@ |
802 | 802 |
return new ProcessedMap(); |
803 | 803 |
} |
804 | 804 |
///The type of the map that indicates which nodes are reached. |
805 |
|
|
805 |
|
|
806 | 806 |
///The type of the map that indicates which nodes are reached. |
807 | 807 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
808 | 808 |
///\todo named parameter to set this type, function to read and write. |
809 | 809 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
810 | 810 |
///Instantiates a ReachedMap. |
811 |
|
|
812 |
///This function instantiates a \ref ReachedMap. |
|
811 |
|
|
812 |
///This function instantiates a \ref ReachedMap. |
|
813 | 813 |
///\param G is the digraph, to which |
814 | 814 |
///we would like to define the \ref ReachedMap. |
815 | 815 |
static ReachedMap *createReachedMap(const GR &G) |
... | ... |
@@ -817,14 +817,14 @@ |
817 | 817 |
return new ReachedMap(G); |
818 | 818 |
} |
819 | 819 |
///The type of the map that stores the dists of the nodes. |
820 |
|
|
820 |
|
|
821 | 821 |
///The type of the map that stores the dists of the nodes. |
822 | 822 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
823 | 823 |
/// |
824 | 824 |
typedef NullMap<typename Digraph::Node,int> DistMap; |
825 | 825 |
///Instantiates a DistMap. |
826 |
|
|
827 |
///This function instantiates a \ref DistMap. |
|
826 |
|
|
827 |
///This function instantiates a \ref DistMap. |
|
828 | 828 |
///\param g is the digraph, to which we would like to define the \ref DistMap |
829 | 829 |
#ifdef DOXYGEN |
830 | 830 |
static DistMap *createDistMap(const GR &g) |
... | ... |
@@ -835,7 +835,7 @@ |
835 | 835 |
return new DistMap(); |
836 | 836 |
} |
837 | 837 |
}; |
838 |
|
|
838 |
|
|
839 | 839 |
/// Default traits used by \ref BfsWizard |
840 | 840 |
|
841 | 841 |
/// To make it easier to use Bfs algorithm |
... | ... |
@@ -865,28 +865,28 @@ |
865 | 865 |
void *_dist; |
866 | 866 |
///Pointer to the source node. |
867 | 867 |
Node _source; |
868 |
|
|
868 |
|
|
869 | 869 |
public: |
870 | 870 |
/// Constructor. |
871 |
|
|
871 |
|
|
872 | 872 |
/// This constructor does not require parameters, therefore it initiates |
873 | 873 |
/// all of the attributes to default values (0, INVALID). |
874 | 874 |
BfsWizardBase() : _g(0), _reached(0), _processed(0), _pred(0), |
875 |
|
|
875 |
_dist(0), _source(INVALID) {} |
|
876 | 876 |
|
877 | 877 |
/// Constructor. |
878 |
|
|
878 |
|
|
879 | 879 |
/// This constructor requires some parameters, |
880 | 880 |
/// listed in the parameters list. |
881 | 881 |
/// Others are initiated to 0. |
882 | 882 |
/// \param g is the initial value of \ref _g |
883 | 883 |
/// \param s is the initial value of \ref _source |
884 | 884 |
BfsWizardBase(const GR &g, Node s=INVALID) : |
885 |
_g(reinterpret_cast<void*>(const_cast<GR*>(&g))), |
|
885 |
_g(reinterpret_cast<void*>(const_cast<GR*>(&g))), |
|
886 | 886 |
_reached(0), _processed(0), _pred(0), _dist(0), _source(s) {} |
887 | 887 |
|
888 | 888 |
}; |
889 |
|
|
889 |
|
|
890 | 890 |
/// A class to make the usage of Bfs algorithm easier |
891 | 891 |
|
892 | 892 |
/// This class is created to make it easier to use Bfs algorithm. |
... | ... |
@@ -921,7 +921,7 @@ |
921 | 921 |
typedef typename Digraph::Arc Arc; |
922 | 922 |
//\e |
923 | 923 |
typedef typename Digraph::OutArcIt OutArcIt; |
924 |
|
|
924 |
|
|
925 | 925 |
///\brief The type of the map that stores |
926 | 926 |
///the reached nodes |
927 | 927 |
typedef typename TR::ReachedMap ReachedMap; |
... | ... |
@@ -951,7 +951,7 @@ |
951 | 951 |
~BfsWizard() {} |
952 | 952 |
|
953 | 953 |
///Runs Bfs algorithm from a given node. |
954 |
|
|
954 |
|
|
955 | 955 |
///Runs Bfs algorithm from a given node. |
956 | 956 |
///The node can be given by the \ref source function. |
957 | 957 |
void run() |
... | ... |
@@ -959,12 +959,12 @@ |
959 | 959 |
if(Base::_source==INVALID) throw UninitializedParameter(); |
960 | 960 |
Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g)); |
961 | 961 |
if(Base::_reached) |
962 |
alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached)); |
|
963 |
if(Base::_processed) |
|
962 |
alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached)); |
|
963 |
if(Base::_processed) |
|
964 | 964 |
alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed)); |
965 |
if(Base::_pred) |
|
965 |
if(Base::_pred) |
|
966 | 966 |
alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
967 |
if(Base::_dist) |
|
967 |
if(Base::_dist) |
|
968 | 968 |
alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
969 | 969 |
alg.run(Base::_source); |
970 | 970 |
} |
... | ... |
@@ -985,7 +985,7 @@ |
985 | 985 |
static PredMap *createPredMap(const Digraph &) { return 0; }; |
986 | 986 |
DefPredMapBase(const TR &b) : TR(b) {} |
987 | 987 |
}; |
988 |
|
|
988 |
|
|
989 | 989 |
///\brief \ref named-templ-param "Named parameter" |
990 | 990 |
///function for setting PredMap |
991 | 991 |
/// |
... | ... |
@@ -993,20 +993,20 @@ |
993 | 993 |
///function for setting PredMap |
994 | 994 |
/// |
995 | 995 |
template<class T> |
996 |
BfsWizard<DefPredMapBase<T> > predMap(const T &t) |
|
996 |
BfsWizard<DefPredMapBase<T> > predMap(const T &t) |
|
997 | 997 |
{ |
998 | 998 |
Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t)); |
999 | 999 |
return BfsWizard<DefPredMapBase<T> >(*this); |
1000 | 1000 |
} |
1001 |
|
|
1002 |
|
|
1001 |
|
|
1002 |
|
|
1003 | 1003 |
template<class T> |
1004 | 1004 |
struct DefReachedMapBase : public Base { |
1005 | 1005 |
typedef T ReachedMap; |
1006 | 1006 |
static ReachedMap *createReachedMap(const Digraph &) { return 0; }; |
1007 | 1007 |
DefReachedMapBase(const TR &b) : TR(b) {} |
1008 | 1008 |
}; |
1009 |
|
|
1009 |
|
|
1010 | 1010 |
///\brief \ref named-templ-param "Named parameter" |
1011 | 1011 |
///function for setting ReachedMap |
1012 | 1012 |
/// |
... | ... |
@@ -1014,12 +1014,12 @@ |
1014 | 1014 |
///function for setting ReachedMap |
1015 | 1015 |
/// |
1016 | 1016 |
template<class T> |
1017 |
BfsWizard<DefReachedMapBase<T> > reachedMap(const T &t) |
|
1017 |
BfsWizard<DefReachedMapBase<T> > reachedMap(const T &t) |
|
1018 | 1018 |
{ |
1019 | 1019 |
Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t)); |
1020 | 1020 |
return BfsWizard<DefReachedMapBase<T> >(*this); |
1021 | 1021 |
} |
1022 |
|
|
1022 |
|
|
1023 | 1023 |
|
1024 | 1024 |
template<class T> |
1025 | 1025 |
struct DefProcessedMapBase : public Base { |
... | ... |
@@ -1027,7 +1027,7 @@ |
1027 | 1027 |
static ProcessedMap *createProcessedMap(const Digraph &) { return 0; }; |
1028 | 1028 |
DefProcessedMapBase(const TR &b) : TR(b) {} |
1029 | 1029 |
}; |
1030 |
|
|
1030 |
|
|
1031 | 1031 |
///\brief \ref named-templ-param "Named parameter" |
1032 | 1032 |
///function for setting ProcessedMap |
1033 | 1033 |
/// |
... | ... |
@@ -1035,20 +1035,20 @@ |
1035 | 1035 |
///function for setting ProcessedMap |
1036 | 1036 |
/// |
1037 | 1037 |
template<class T> |
1038 |
BfsWizard<DefProcessedMapBase<T> > processedMap(const T &t) |
|
1038 |
BfsWizard<DefProcessedMapBase<T> > processedMap(const T &t) |
|
1039 | 1039 |
{ |
1040 | 1040 |
Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t)); |
1041 | 1041 |
return BfsWizard<DefProcessedMapBase<T> >(*this); |
1042 | 1042 |
} |
1043 |
|
|
1044 |
|
|
1043 |
|
|
1044 |
|
|
1045 | 1045 |
template<class T> |
1046 | 1046 |
struct DefDistMapBase : public Base { |
1047 | 1047 |
typedef T DistMap; |
1048 | 1048 |
static DistMap *createDistMap(const Digraph &) { return 0; }; |
1049 | 1049 |
DefDistMapBase(const TR &b) : TR(b) {} |
1050 | 1050 |
}; |
1051 |
|
|
1051 |
|
|
1052 | 1052 |
///\brief \ref named-templ-param "Named parameter" |
1053 | 1053 |
///function for setting DistMap type |
1054 | 1054 |
/// |
... | ... |
@@ -1056,24 +1056,24 @@ |
1056 | 1056 |
///function for setting DistMap type |
1057 | 1057 |
/// |
1058 | 1058 |
template<class T> |
1059 |
BfsWizard<DefDistMapBase<T> > distMap(const T &t) |
|
1059 |
BfsWizard<DefDistMapBase<T> > distMap(const T &t) |
|
1060 | 1060 |
{ |
1061 | 1061 |
Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t)); |
1062 | 1062 |
return BfsWizard<DefDistMapBase<T> >(*this); |
1063 | 1063 |
} |
1064 |
|
|
1064 |
|
|
1065 | 1065 |
/// Sets the source node, from which the Bfs algorithm runs. |
1066 | 1066 |
|
1067 | 1067 |
/// Sets the source node, from which the Bfs algorithm runs. |
1068 | 1068 |
/// \param s is the source node. |
1069 |
BfsWizard<TR> &source(Node s) |
|
1069 |
BfsWizard<TR> &source(Node s) |
|
1070 | 1070 |
{ |
1071 | 1071 |
Base::_source=s; |
1072 | 1072 |
return *this; |
1073 | 1073 |
} |
1074 |
|
|
1074 |
|
|
1075 | 1075 |
}; |
1076 |
|
|
1076 |
|
|
1077 | 1077 |
///Function type interface for Bfs algorithm. |
1078 | 1078 |
|
1079 | 1079 |
/// \ingroup search |
... | ... |
@@ -1100,7 +1100,7 @@ |
1100 | 1100 |
|
1101 | 1101 |
#ifdef DOXYGEN |
1102 | 1102 |
/// \brief Visitor class for bfs. |
1103 |
/// |
|
1103 |
/// |
|
1104 | 1104 |
/// This class defines the interface of the BfsVisit events, and |
1105 | 1105 |
/// it could be the base of a real Visitor class. |
1106 | 1106 |
template <typename _Digraph> |
... | ... |
@@ -1109,26 +1109,26 @@ |
1109 | 1109 |
typedef typename Digraph::Arc Arc; |
1110 | 1110 |
typedef typename Digraph::Node Node; |
1111 | 1111 |
/// \brief Called when the arc reach a node. |
1112 |
/// |
|
1112 |
/// |
|
1113 | 1113 |
/// It is called when the bfs find an arc which target is not |
1114 | 1114 |
/// reached yet. |
1115 | 1115 |
void discover(const Arc& arc) {} |
1116 | 1116 |
/// \brief Called when the node reached first time. |
1117 |
/// |
|
1117 |
/// |
|
1118 | 1118 |
/// It is Called when the node reached first time. |
1119 | 1119 |
void reach(const Node& node) {} |
1120 |
/// \brief Called when the arc examined but target of the arc |
|
1120 |
/// \brief Called when the arc examined but target of the arc |
|
1121 | 1121 |
/// already discovered. |
1122 |
/// |
|
1123 |
/// It called when the arc examined but the target of the arc |
|
1122 |
/// |
|
1123 |
/// It called when the arc examined but the target of the arc |
|
1124 | 1124 |
/// already discovered. |
1125 | 1125 |
void examine(const Arc& arc) {} |
1126 | 1126 |
/// \brief Called for the source node of the bfs. |
1127 |
/// |
|
1127 |
/// |
|
1128 | 1128 |
/// It is called for the source node of the bfs. |
1129 | 1129 |
void start(const Node& node) {} |
1130 | 1130 |
/// \brief Called when the node processed. |
1131 |
/// |
|
1131 |
/// |
|
1132 | 1132 |
/// It is Called when the node processed. |
1133 | 1133 |
void process(const Node& node) {} |
1134 | 1134 |
}; |
... | ... |
@@ -1147,12 +1147,12 @@ |
1147 | 1147 |
template <typename _Visitor> |
1148 | 1148 |
struct Constraints { |
1149 | 1149 |
void constraints() { |
1150 |
Arc arc; |
|
1151 |
Node node; |
|
1152 |
visitor.discover(arc); |
|
1153 |
visitor.reach(node); |
|
1154 |
visitor.examine(arc); |
|
1155 |
visitor.start(node); |
|
1150 |
Arc arc; |
|
1151 |
Node node; |
|
1152 |
visitor.discover(arc); |
|
1153 |
visitor.reach(node); |
|
1154 |
visitor.examine(arc); |
|
1155 |
visitor.start(node); |
|
1156 | 1156 |
visitor.process(node); |
1157 | 1157 |
} |
1158 | 1158 |
_Visitor& visitor; |
... | ... |
@@ -1167,11 +1167,11 @@ |
1167 | 1167 |
template<class _Digraph> |
1168 | 1168 |
struct BfsVisitDefaultTraits { |
1169 | 1169 |
|
1170 |
/// \brief The digraph type the algorithm runs on. |
|
1170 |
/// \brief The digraph type the algorithm runs on. |
|
1171 | 1171 |
typedef _Digraph Digraph; |
1172 | 1172 |
|
1173 | 1173 |
/// \brief The type of the map that indicates which nodes are reached. |
1174 |
/// |
|
1174 |
/// |
|
1175 | 1175 |
/// The type of the map that indicates which nodes are reached. |
1176 | 1176 |
/// It must meet the \ref concepts::WriteMap "WriteMap" concept. |
1177 | 1177 |
/// \todo named parameter to set this type, function to read and write. |
... | ... |
@@ -1179,7 +1179,7 @@ |
1179 | 1179 |
|
1180 | 1180 |
/// \brief Instantiates a ReachedMap. |
1181 | 1181 |
/// |
1182 |
/// This function instantiates a \ref ReachedMap. |
|
1182 |
/// This function instantiates a \ref ReachedMap. |
|
1183 | 1183 |
/// \param digraph is the digraph, to which |
1184 | 1184 |
/// we would like to define the \ref ReachedMap. |
1185 | 1185 |
static ReachedMap *createReachedMap(const Digraph &digraph) { |
... | ... |
@@ -1189,24 +1189,24 @@ |
1189 | 1189 |
}; |
1190 | 1190 |
|
1191 | 1191 |
/// \ingroup search |
1192 |
/// |
|
1192 |
/// |
|
1193 | 1193 |
/// \brief %BFS Visit algorithm class. |
1194 |
/// |
|
1194 |
/// |
|
1195 | 1195 |
/// This class provides an efficient implementation of the %BFS algorithm |
1196 | 1196 |
/// with visitor interface. |
1197 | 1197 |
/// |
1198 | 1198 |
/// The %BfsVisit class provides an alternative interface to the Bfs |
1199 | 1199 |
/// class. It works with callback mechanism, the BfsVisit object calls |
1200 |
/// on every bfs event the \c Visitor class member functions. |
|
1200 |
/// on every bfs event the \c Visitor class member functions. |
|
1201 | 1201 |
/// |
1202 | 1202 |
/// \tparam _Digraph The digraph type the algorithm runs on. The default value is |
1203 | 1203 |
/// \ref ListDigraph. The value of _Digraph is not used directly by Bfs, it |
1204 | 1204 |
/// is only passed to \ref BfsDefaultTraits. |
1205 |
/// \tparam _Visitor The Visitor object for the algorithm. The |
|
1205 |
/// \tparam _Visitor The Visitor object for the algorithm. The |
|
1206 | 1206 |
/// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty Visitor which |
1207 | 1207 |
/// does not observe the Bfs events. If you want to observe the bfs |
1208 | 1208 |
/// events you should implement your own Visitor class. |
1209 |
/// \tparam _Traits Traits class to set various data types used by the |
|
1209 |
/// \tparam _Traits Traits class to set various data types used by the |
|
1210 | 1210 |
/// algorithm. The default traits class is |
1211 | 1211 |
/// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<_Digraph>". |
1212 | 1212 |
/// See \ref BfsVisitDefaultTraits for the documentation of |
... | ... |
@@ -1215,21 +1215,21 @@ |
1215 | 1215 |
template <typename _Digraph, typename _Visitor, typename _Traits> |
1216 | 1216 |
#else |
1217 | 1217 |
template <typename _Digraph = ListDigraph, |
1218 |
typename _Visitor = BfsVisitor<_Digraph>, |
|
1219 |
typename _Traits = BfsDefaultTraits<_Digraph> > |
|
1218 |
typename _Visitor = BfsVisitor<_Digraph>, |
|
1219 |
typename _Traits = BfsDefaultTraits<_Digraph> > |
|
1220 | 1220 |
#endif |
1221 | 1221 |
class BfsVisit { |
1222 | 1222 |
public: |
1223 |
|
|
1223 |
|
|
1224 | 1224 |
/// \brief \ref Exception for uninitialized parameters. |
1225 | 1225 |
/// |
1226 | 1226 |
/// This error represents problems in the initialization |
1227 | 1227 |
/// of the parameters of the algorithms. |
1228 | 1228 |
class UninitializedParameter : public lemon::UninitializedParameter { |
1229 | 1229 |
public: |
1230 |
virtual const char* what() const throw() |
|
1230 |
virtual const char* what() const throw() |
|
1231 | 1231 |
{ |
1232 |
|
|
1232 |
return "lemon::BfsVisit::UninitializedParameter"; |
|
1233 | 1233 |
} |
1234 | 1234 |
}; |
1235 | 1235 |
|
... | ... |
@@ -1266,15 +1266,15 @@ |
1266 | 1266 |
/// Creates the maps if necessary. |
1267 | 1267 |
void create_maps() { |
1268 | 1268 |
if(!_reached) { |
1269 |
local_reached = true; |
|
1270 |
_reached = Traits::createReachedMap(*_digraph); |
|
1269 |
local_reached = true; |
|
1270 |
_reached = Traits::createReachedMap(*_digraph); |
|
1271 | 1271 |
} |
1272 | 1272 |
} |
1273 | 1273 |
|
1274 | 1274 |
protected: |
1275 | 1275 |
|
1276 | 1276 |
BfsVisit() {} |
1277 |
|
|
1277 |
|
|
1278 | 1278 |
public: |
1279 | 1279 |
|
1280 | 1280 |
typedef BfsVisit Create; |
... | ... |
@@ -1286,22 +1286,22 @@ |
1286 | 1286 |
struct DefReachedMapTraits : public Traits { |
1287 | 1287 |
typedef T ReachedMap; |
1288 | 1288 |
static ReachedMap *createReachedMap(const Digraph &digraph) { |
1289 |
|
|
1289 |
throw UninitializedParameter(); |
|
1290 | 1290 |
} |
1291 | 1291 |
}; |
1292 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
1292 |
/// \brief \ref named-templ-param "Named parameter" for setting |
|
1293 | 1293 |
/// ReachedMap type |
1294 | 1294 |
/// |
1295 | 1295 |
/// \ref named-templ-param "Named parameter" for setting ReachedMap type |
1296 | 1296 |
template <class T> |
1297 | 1297 |
struct DefReachedMap : public BfsVisit< Digraph, Visitor, |
1298 |
|
|
1298 |
DefReachedMapTraits<T> > { |
|
1299 | 1299 |
typedef BfsVisit< Digraph, Visitor, DefReachedMapTraits<T> > Create; |
1300 | 1300 |
}; |
1301 | 1301 |
///@} |
1302 | 1302 |
|
1303 |
public: |
|
1304 |
|
|
1303 |
public: |
|
1304 |
|
|
1305 | 1305 |
/// \brief Constructor. |
1306 | 1306 |
/// |
1307 | 1307 |
/// Constructor. |
... | ... |
@@ -1309,10 +1309,10 @@ |
1309 | 1309 |
/// \param digraph the digraph the algorithm will run on. |
1310 | 1310 |
/// \param visitor The visitor of the algorithm. |
1311 | 1311 |
/// |
1312 |
BfsVisit(const Digraph& digraph, Visitor& visitor) |
|
1312 |
BfsVisit(const Digraph& digraph, Visitor& visitor) |
|
1313 | 1313 |
: _digraph(&digraph), _visitor(&visitor), |
1314 |
_reached(0), local_reached(false) {} |
|
1315 |
|
|
1314 |
_reached(0), local_reached(false) {} |
|
1315 |
|
|
1316 | 1316 |
/// \brief Destructor. |
1317 | 1317 |
/// |
1318 | 1318 |
/// Destructor. |
... | ... |
@@ -1329,8 +1329,8 @@ |
1329 | 1329 |
/// \return <tt> (*this) </tt> |
1330 | 1330 |
BfsVisit &reachedMap(ReachedMap &m) { |
1331 | 1331 |
if(local_reached) { |
1332 |
delete _reached; |
|
1333 |
local_reached = false; |
|
1332 |
delete _reached; |
|
1333 |
local_reached = false; |
|
1334 | 1334 |
} |
1335 | 1335 |
_reached = &m; |
1336 | 1336 |
return *this; |
... | ... |
@@ -1357,22 +1357,22 @@ |
1357 | 1357 |
_list.resize(countNodes(*_digraph)); |
1358 | 1358 |
_list_front = _list_back = -1; |
1359 | 1359 |
for (NodeIt u(*_digraph) ; u != INVALID ; ++u) { |
1360 |
|
|
1360 |
_reached->set(u, false); |
|
1361 | 1361 |
} |
1362 | 1362 |
} |
1363 |
|
|
1363 |
|
|
1364 | 1364 |
/// \brief Adds a new source node. |
1365 | 1365 |
/// |
1366 | 1366 |
/// Adds a new source node to the set of nodes to be processed. |
1367 | 1367 |
void addSource(Node s) { |
1368 | 1368 |
if(!(*_reached)[s]) { |
1369 |
_reached->set(s,true); |
|
1370 |
_visitor->start(s); |
|
1371 |
|
|
1369 |
_reached->set(s,true); |
|
1370 |
_visitor->start(s); |
|
1371 |
_visitor->reach(s); |
|
1372 | 1372 |
_list[++_list_back] = s; |
1373 |
|
|
1373 |
} |
|
1374 | 1374 |
} |
1375 |
|
|
1375 |
|
|
1376 | 1376 |
/// \brief Processes the next node. |
1377 | 1377 |
/// |
1378 | 1378 |
/// Processes the next node. |
... | ... |
@@ -1380,7 +1380,7 @@ |
1380 | 1380 |
/// \return The processed node. |
1381 | 1381 |
/// |
1382 | 1382 |
/// \pre The queue must not be empty! |
1383 |
Node processNextNode() { |
|
1383 |
Node processNextNode() { |
|
1384 | 1384 |
Node n = _list[++_list_front]; |
1385 | 1385 |
_visitor->process(n); |
1386 | 1386 |
Arc e; |
... | ... |
@@ -1467,7 +1467,7 @@ |
1467 | 1467 |
/// |
1468 | 1468 |
/// \return The next node to be processed or INVALID if the stack is |
1469 | 1469 |
/// empty. |
1470 |
Node nextNode() { |
|
1470 |
Node nextNode() { |
|
1471 | 1471 |
return _list_front != _list_back ? _list[_list_front + 1] : INVALID; |
1472 | 1472 |
} |
1473 | 1473 |
|
... | ... |
@@ -1482,7 +1482,7 @@ |
1482 | 1482 |
/// |
1483 | 1483 |
/// Returns the number of the nodes to be processed in the queue. |
1484 | 1484 |
int queueSize() { return _list_back - _list_front; } |
1485 |
|
|
1485 |
|
|
1486 | 1486 |
/// \brief Executes the algorithm. |
1487 | 1487 |
/// |
1488 | 1488 |
/// Executes the algorithm. |
... | ... |
@@ -1492,7 +1492,7 @@ |
1492 | 1492 |
void start() { |
1493 | 1493 |
while ( !emptyQueue() ) processNextNode(); |
1494 | 1494 |
} |
1495 |
|
|
1495 |
|
|
1496 | 1496 |
/// \brief Executes the algorithm until \c dest is reached. |
1497 | 1497 |
/// |
1498 | 1498 |
/// Executes the algorithm until \c dest is reached. |
... | ... |
@@ -1503,7 +1503,7 @@ |
1503 | 1503 |
bool reach = false; |
1504 | 1504 |
while ( !emptyQueue() && !reach ) processNextNode(dest, reach); |
1505 | 1505 |
} |
1506 |
|
|
1506 |
|
|
1507 | 1507 |
/// \brief Executes the algorithm until a condition is met. |
1508 | 1508 |
/// |
1509 | 1509 |
/// Executes the algorithm until a condition is met. |
... | ... |
@@ -1521,7 +1521,7 @@ |
1521 | 1521 |
Node start(const NM &nm) { |
1522 | 1522 |
Node rnode = INVALID; |
1523 | 1523 |
while ( !emptyQueue() && rnode == INVALID ) { |
1524 |
|
|
1524 |
processNextNode(nm, rnode); |
|
1525 | 1525 |
} |
1526 | 1526 |
return rnode; |
1527 | 1527 |
} |
... | ... |
@@ -1542,7 +1542,7 @@ |
1542 | 1542 |
} |
1543 | 1543 |
|
1544 | 1544 |
/// \brief Runs %BFSVisit algorithm to visit all nodes in the digraph. |
1545 |
/// |
|
1545 |
/// |
|
1546 | 1546 |
/// This method runs the %BFS algorithm in order to |
1547 | 1547 |
/// compute the %BFS path to each node. The algorithm computes |
1548 | 1548 |
/// - The %BFS tree. |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -48,7 +48,7 @@ |
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: |
... | ... |
@@ -90,7 +90,7 @@ |
90 | 90 |
/// internally to handle the cross references. The value of the map |
91 | 91 |
/// should be PRE_HEAP (-1) for each element. |
92 | 92 |
explicit BinHeap(ItemIntMap &_iim) : iim(_iim) {} |
93 |
|
|
93 |
|
|
94 | 94 |
/// \brief The constructor. |
95 | 95 |
/// |
96 | 96 |
/// The constructor. |
... | ... |
@@ -99,7 +99,7 @@ |
99 | 99 |
/// should be PRE_HEAP (-1) for each element. |
100 | 100 |
/// |
101 | 101 |
/// \param _comp The comparator function object. |
102 |
BinHeap(ItemIntMap &_iim, const Compare &_comp) |
|
102 |
BinHeap(ItemIntMap &_iim, const Compare &_comp) |
|
103 | 103 |
: iim(_iim), comp(_comp) {} |
104 | 104 |
|
105 | 105 |
|
... | ... |
@@ -107,20 +107,20 @@ |
107 | 107 |
/// |
108 | 108 |
/// \brief Returns the number of items stored in the heap. |
109 | 109 |
int size() const { return data.size(); } |
110 |
|
|
110 |
|
|
111 | 111 |
/// \brief Checks if the heap stores no items. |
112 | 112 |
/// |
113 | 113 |
/// Returns \c true if and only if the heap stores no items. |
114 | 114 |
bool empty() const { return data.empty(); } |
115 | 115 |
|
116 | 116 |
/// \brief Make empty this heap. |
117 |
/// |
|
117 |
/// |
|
118 | 118 |
/// Make empty this heap. It does not change the cross reference map. |
119 | 119 |
/// If you want to reuse what is not surely empty you should first clear |
120 | 120 |
/// the heap and after that you should set the cross reference map for |
121 | 121 |
/// each item to \c PRE_HEAP. |
122 |
void clear() { |
|
123 |
data.clear(); |
|
122 |
void clear() { |
|
123 |
data.clear(); |
|
124 | 124 |
} |
125 | 125 |
|
126 | 126 |
private: |
... | ... |
@@ -134,9 +134,9 @@ |
134 | 134 |
int bubble_up(int hole, Pair p) { |
135 | 135 |
int par = parent(hole); |
136 | 136 |
while( hole>0 && less(p,data[par]) ) { |
137 |
move(data[par],hole); |
|
138 |
hole = par; |
|
139 |
|
|
137 |
move(data[par],hole); |
|
138 |
hole = par; |
|
139 |
par = parent(hole); |
|
140 | 140 |
} |
141 | 141 |
move(p, hole); |
142 | 142 |
return hole; |
... | ... |
@@ -145,19 +145,19 @@ |
145 | 145 |
int bubble_down(int hole, Pair p, int length) { |
146 | 146 |
int child = second_child(hole); |
147 | 147 |
while(child < length) { |
148 |
if( less(data[child-1], data[child]) ) { |
|
149 |
--child; |
|
150 |
} |
|
151 |
if( !less(data[child], p) ) |
|
152 |
goto ok; |
|
153 |
move(data[child], hole); |
|
154 |
hole = child; |
|
155 |
child = second_child(hole); |
|
148 |
if( less(data[child-1], data[child]) ) { |
|
149 |
--child; |
|
150 |
} |
|
151 |
if( !less(data[child], p) ) |
|
152 |
goto ok; |
|
153 |
move(data[child], hole); |
|
154 |
hole = child; |
|
155 |
child = second_child(hole); |
|
156 | 156 |
} |
157 | 157 |
child--; |
158 | 158 |
if( child<length && less(data[child], p) ) { |
159 |
move(data[child], hole); |
|
160 |
hole=child; |
|
159 |
move(data[child], hole); |
|
160 |
hole=child; |
|
161 | 161 |
} |
162 | 162 |
ok: |
163 | 163 |
move(p, hole); |
... | ... |
@@ -181,8 +181,8 @@ |
181 | 181 |
} |
182 | 182 |
|
183 | 183 |
/// \brief Insert an item into the heap with the given heap. |
184 |
/// |
|
185 |
/// Adds \c i to the heap with priority \c p. |
|
184 |
/// |
|
185 |
/// Adds \c i to the heap with priority \c p. |
|
186 | 186 |
/// \param i The item to insert. |
187 | 187 |
/// \param p The priority of the item. |
188 | 188 |
void push(const Item &i, const Prio &p) { push(Pair(i,p)); } |
... | ... |
@@ -190,8 +190,8 @@ |
190 | 190 |
/// \brief Returns the item with minimum priority relative to \c Compare. |
191 | 191 |
/// |
192 | 192 |
/// This method returns the item with minimum priority relative to \c |
193 |
/// Compare. |
|
194 |
/// \pre The heap must be nonempty. |
|
193 |
/// Compare. |
|
194 |
/// \pre The heap must be nonempty. |
|
195 | 195 |
Item top() const { |
196 | 196 |
return data[0].first; |
197 | 197 |
} |
... | ... |
@@ -207,13 +207,13 @@ |
207 | 207 |
/// \brief Deletes the item with minimum priority relative to \c Compare. |
208 | 208 |
/// |
209 | 209 |
/// This method deletes the item with minimum priority relative to \c |
210 |
/// Compare from the heap. |
|
211 |
/// \pre The heap must be non-empty. |
|
210 |
/// Compare from the heap. |
|
211 |
/// \pre The heap must be non-empty. |
|
212 | 212 |
void pop() { |
213 | 213 |
int n = data.size()-1; |
214 | 214 |
iim.set(data[0].first, POST_HEAP); |
215 | 215 |
if (n > 0) { |
216 |
|
|
216 |
bubble_down(0, data[n], n); |
|
217 | 217 |
} |
218 | 218 |
data.pop_back(); |
219 | 219 |
} |
... | ... |
@@ -228,17 +228,17 @@ |
228 | 228 |
int n = data.size()-1; |
229 | 229 |
iim.set(data[h].first, POST_HEAP); |
230 | 230 |
if( h < n ) { |
231 |
if ( bubble_up(h, data[n]) == h) { |
|
232 |
bubble_down(h, data[n], n); |
|
233 |
|
|
231 |
if ( bubble_up(h, data[n]) == h) { |
|
232 |
bubble_down(h, data[n], n); |
|
233 |
} |
|
234 | 234 |
} |
235 | 235 |
data.pop_back(); |
236 | 236 |
} |
237 | 237 |
|
238 |
|
|
238 |
|
|
239 | 239 |
/// \brief Returns the priority of \c i. |
240 | 240 |
/// |
241 |
/// This function returns the priority of item \c i. |
|
241 |
/// This function returns the priority of item \c i. |
|
242 | 242 |
/// \pre \c i must be in the heap. |
243 | 243 |
/// \param i The item. |
244 | 244 |
Prio operator[](const Item &i) const { |
... | ... |
@@ -246,7 +246,7 @@ |
246 | 246 |
return data[idx].second; |
247 | 247 |
} |
248 | 248 |
|
249 |
/// \brief \c i gets to the heap with priority \c p independently |
|
249 |
/// \brief \c i gets to the heap with priority \c p independently |
|
250 | 250 |
/// if \c i was already there. |
251 | 251 |
/// |
252 | 252 |
/// This method calls \ref push(\c i, \c p) if \c i is not stored |
... | ... |
@@ -256,13 +256,13 @@ |
256 | 256 |
void set(const Item &i, const Prio &p) { |
257 | 257 |
int idx = iim[i]; |
258 | 258 |
if( idx < 0 ) { |
259 |
|
|
259 |
push(i,p); |
|
260 | 260 |
} |
261 | 261 |
else if( comp(p, data[idx].second) ) { |
262 |
|
|
262 |
bubble_up(idx, Pair(i,p)); |
|
263 | 263 |
} |
264 | 264 |
else { |
265 |
|
|
265 |
bubble_down(idx, Pair(i,p), data.size()); |
|
266 | 266 |
} |
267 | 267 |
} |
268 | 268 |
|
... | ... |
@@ -277,10 +277,10 @@ |
277 | 277 |
int idx = iim[i]; |
278 | 278 |
bubble_up(idx, Pair(i,p)); |
279 | 279 |
} |
280 |
|
|
280 |
|
|
281 | 281 |
/// \brief Increases the priority of \c i to \c p. |
282 | 282 |
/// |
283 |
/// This method sets the priority of item \c i to \c p. |
|
283 |
/// This method sets the priority of item \c i to \c p. |
|
284 | 284 |
/// \pre \c i must be stored in the heap with priority at most \c |
285 | 285 |
/// p relative to \c Compare. |
286 | 286 |
/// \param i The item. |
... | ... |
@@ -290,7 +290,7 @@ |
290 | 290 |
bubble_down(idx, Pair(i,p), data.size()); |
291 | 291 |
} |
292 | 292 |
|
293 |
/// \brief Returns if \c item is in, has already been in, or has |
|
293 |
/// \brief Returns if \c item is in, has already been in, or has |
|
294 | 294 |
/// never been in the heap. |
295 | 295 |
/// |
296 | 296 |
/// This method returns PRE_HEAP if \c item has never been in the |
... | ... |
@@ -301,7 +301,7 @@ |
301 | 301 |
State state(const Item &i) const { |
302 | 302 |
int s = iim[i]; |
303 | 303 |
if( s>=0 ) |
304 |
|
|
304 |
s=0; |
|
305 | 305 |
return State(s); |
306 | 306 |
} |
307 | 307 |
|
... | ... |
@@ -311,7 +311,7 @@ |
311 | 311 |
/// manually clear the heap when it is important to achive the |
312 | 312 |
/// better time complexity. |
313 | 313 |
/// \param i The item. |
314 |
/// \param st The state. It should not be \c IN_HEAP. |
|
314 |
/// \param st The state. It should not be \c IN_HEAP. |
|
315 | 315 |
void state(const Item& i, State st) { |
316 | 316 |
switch (st) { |
317 | 317 |
case POST_HEAP: |
... | ... |
@@ -340,7 +340,7 @@ |
340 | 340 |
} |
341 | 341 |
|
342 | 342 |
}; // class BinHeap |
343 |
|
|
343 |
|
|
344 | 344 |
} // namespace lemon |
345 | 345 |
|
346 | 346 |
#endif // LEMON_BIN_HEAP_H |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -32,7 +32,7 @@ |
32 | 32 |
|
33 | 33 |
/// \ingroup graphbits |
34 | 34 |
/// |
35 |
/// \brief Notifier class to notify observes about alterations in |
|
35 |
/// \brief Notifier class to notify observes about alterations in |
|
36 | 36 |
/// a container. |
37 | 37 |
/// |
38 | 38 |
/// The simple graph's can be refered as two containers, one node container |
... | ... |
@@ -49,7 +49,7 @@ |
49 | 49 |
/// an alteration in the graph, which cause only drawback on the |
50 | 50 |
/// alteration of the graph. |
51 | 51 |
/// |
52 |
/// This class provides an interface to the container. The \e first() and \e |
|
52 |
/// This class provides an interface to the container. The \e first() and \e |
|
53 | 53 |
/// next() member functions make possible to iterate on the keys of the |
54 | 54 |
/// container. The \e id() function returns an integer id for each key. |
55 | 55 |
/// The \e maxId() function gives back an upper bound of the ids. |
... | ... |
@@ -60,7 +60,7 @@ |
60 | 60 |
/// \e erase() signals that only one or few items added or erased to or |
61 | 61 |
/// from the graph. If all items are erased from the graph or from an empty |
62 | 62 |
/// graph a new graph is builded then it can be signaled with the |
63 |
/// clear() and build() members. Important rule that if we erase items |
|
63 |
/// clear() and build() members. Important rule that if we erase items |
|
64 | 64 |
/// from graph we should first signal the alteration and after that erase |
65 | 65 |
/// them from the container, on the other way on item addition we should |
66 | 66 |
/// first extend the container and just after that signal the alteration. |
... | ... |
@@ -68,7 +68,7 @@ |
68 | 68 |
/// The alteration can be observed with a class inherited from the |
69 | 69 |
/// \e ObserverBase nested class. The signals can be handled with |
70 | 70 |
/// overriding the virtual functions defined in the base class. The |
71 |
/// observer base can be attached to the notifier with the |
|
71 |
/// observer base can be attached to the notifier with the |
|
72 | 72 |
/// \e attach() member and can be detached with detach() function. The |
73 | 73 |
/// alteration handlers should not call any function which signals |
74 | 74 |
/// an other alteration in the same notifier and should not |
... | ... |
@@ -79,13 +79,13 @@ |
79 | 79 |
/// observeres will not be notified and the fulfilled additions will |
80 | 80 |
/// be rolled back by calling the \e erase() or \e clear() |
81 | 81 |
/// functions. Thence the \e erase() and \e clear() should not throw |
82 |
/// exception. Actullay, it can be throw only |
|
82 |
/// exception. Actullay, it can be throw only |
|
83 | 83 |
/// \ref AlterationObserver::ImmediateDetach ImmediateDetach |
84 | 84 |
/// exception which detach the observer from the notifier. |
85 | 85 |
/// |
86 | 86 |
/// There are some place when the alteration observing is not completly |
87 | 87 |
/// reliable. If we want to carry out the node degree in the graph |
88 |
/// as in the \ref InDegMap and we use the reverseEdge that cause |
|
88 |
/// as in the \ref InDegMap and we use the reverseEdge that cause |
|
89 | 89 |
/// unreliable functionality. Because the alteration observing signals |
90 | 90 |
/// only erasing and adding but not the reversing it will stores bad |
91 | 91 |
/// degrees. The sub graph adaptors cannot signal the alterations because |
... | ... |
@@ -104,7 +104,7 @@ |
104 | 104 |
typedef _Container Container; |
105 | 105 |
typedef _Item Item; |
106 | 106 |
|
107 |
/// \brief Exception which can be called from \e clear() and |
|
107 |
/// \brief Exception which can be called from \e clear() and |
|
108 | 108 |
/// \e erase(). |
109 | 109 |
/// |
110 | 110 |
/// From the \e clear() and \e erase() function only this |
... | ... |
@@ -127,7 +127,7 @@ |
127 | 127 |
/// |
128 | 128 |
/// The build() and clear() members are to notify the observer |
129 | 129 |
/// about the container is built from an empty container or |
130 |
/// is cleared to an empty container. |
|
130 |
/// is cleared to an empty container. |
|
131 | 131 |
|
132 | 132 |
class ObserverBase { |
133 | 133 |
protected: |
... | ... |
@@ -138,7 +138,7 @@ |
138 | 138 |
/// \brief Default constructor. |
139 | 139 |
/// |
140 | 140 |
/// Default constructor for ObserverBase. |
141 |
/// |
|
141 |
/// |
|
142 | 142 |
ObserverBase() : _notifier(0) {} |
143 | 143 |
|
144 | 144 |
/// \brief Constructor which attach the observer into notifier. |
... | ... |
@@ -151,13 +151,13 @@ |
151 | 151 |
/// \brief Constructor which attach the obserever to the same notifier. |
152 | 152 |
/// |
153 | 153 |
/// Constructor which attach the obserever to the same notifier as |
154 |
/// the other observer is attached to. |
|
154 |
/// the other observer is attached to. |
|
155 | 155 |
ObserverBase(const ObserverBase& copy) { |
156 |
|
|
156 |
if (copy.attached()) { |
|
157 | 157 |
attach(*copy.notifier()); |
158 |
|
|
158 |
} |
|
159 | 159 |
} |
160 |
|
|
160 |
|
|
161 | 161 |
/// \brief Destructor |
162 | 162 |
virtual ~ObserverBase() { |
163 | 163 |
if (attached()) { |
... | ... |
@@ -170,9 +170,9 @@ |
170 | 170 |
/// This member attaches the observer into an AlterationNotifier. |
171 | 171 |
/// |
172 | 172 |
void attach(AlterationNotifier& nf) { |
173 |
|
|
173 |
nf.attach(*this); |
|
174 | 174 |
} |
175 |
|
|
175 |
|
|
176 | 176 |
/// \brief Detaches the observer into an AlterationNotifier. |
177 | 177 |
/// |
178 | 178 |
/// This member detaches the observer from an AlterationNotifier. |
... | ... |
@@ -180,15 +180,15 @@ |
180 | 180 |
void detach() { |
181 | 181 |
_notifier->detach(*this); |
182 | 182 |
} |
183 |
|
|
184 |
/// \brief Gives back a pointer to the notifier which the map |
|
183 |
|
|
184 |
/// \brief Gives back a pointer to the notifier which the map |
|
185 | 185 |
/// attached into. |
186 | 186 |
/// |
187 | 187 |
/// This function gives back a pointer to the notifier which the map |
188 | 188 |
/// attached into. |
189 | 189 |
/// |
190 | 190 |
Notifier* notifier() const { return const_cast<Notifier*>(_notifier); } |
191 |
|
|
191 |
|
|
192 | 192 |
/// Gives back true when the observer is attached into a notifier. |
193 | 193 |
bool attached() const { return _notifier != 0; } |
194 | 194 |
|
... | ... |
@@ -197,7 +197,7 @@ |
197 | 197 |
ObserverBase& operator=(const ObserverBase& copy); |
198 | 198 |
|
199 | 199 |
protected: |
200 |
|
|
200 |
|
|
201 | 201 |
Notifier* _notifier; |
202 | 202 |
typename std::list<ObserverBase*>::iterator _index; |
203 | 203 |
|
... | ... |
@@ -209,7 +209,7 @@ |
209 | 209 |
/// subclasses. |
210 | 210 |
virtual void add(const Item&) = 0; |
211 | 211 |
|
212 |
/// \brief The member function to notificate the observer about |
|
212 |
/// \brief The member function to notificate the observer about |
|
213 | 213 |
/// more item is added to the container. |
214 | 214 |
/// |
215 | 215 |
/// The add() member function notificates the observer about more item |
... | ... |
@@ -222,10 +222,10 @@ |
222 | 222 |
/// |
223 | 223 |
/// The erase() member function notificates the observer about an |
224 | 224 |
/// item is erased from the container. It have to be overrided in |
225 |
/// the subclasses. |
|
225 |
/// the subclasses. |
|
226 | 226 |
virtual void erase(const Item&) = 0; |
227 | 227 |
|
228 |
/// \brief The member function to notificate the observer about |
|
228 |
/// \brief The member function to notificate the observer about |
|
229 | 229 |
/// more item is erased from the container. |
230 | 230 |
/// |
231 | 231 |
/// The erase() member function notificates the observer about more item |
... | ... |
@@ -247,50 +247,50 @@ |
247 | 247 |
/// |
248 | 248 |
/// The clear() member function notificates the observer about all |
249 | 249 |
/// items are erased from the container. It have to be overrided in |
250 |
/// the subclasses. |
|
250 |
/// the subclasses. |
|
251 | 251 |
virtual void clear() = 0; |
252 | 252 |
|
253 | 253 |
}; |
254 |
|
|
254 |
|
|
255 | 255 |
protected: |
256 | 256 |
|
257 | 257 |
const Container* container; |
258 | 258 |
|
259 |
typedef std::list<ObserverBase*> Observers; |
|
259 |
typedef std::list<ObserverBase*> Observers; |
|
260 | 260 |
Observers _observers; |
261 | 261 |
|
262 |
|
|
262 |
|
|
263 | 263 |
public: |
264 | 264 |
|
265 | 265 |
/// \brief Default constructor. |
266 | 266 |
/// |
267 |
/// The default constructor of the AlterationNotifier. |
|
267 |
/// The default constructor of the AlterationNotifier. |
|
268 | 268 |
/// It creates an empty notifier. |
269 |
AlterationNotifier() |
|
269 |
AlterationNotifier() |
|
270 | 270 |
: container(0) {} |
271 | 271 |
|
272 | 272 |
/// \brief Constructor. |
273 | 273 |
/// |
274 | 274 |
/// Constructor with the observed container parameter. |
275 |
AlterationNotifier(const Container& _container) |
|
275 |
AlterationNotifier(const Container& _container) |
|
276 | 276 |
: container(&_container) {} |
277 | 277 |
|
278 |
/// \brief Copy Constructor of the AlterationNotifier. |
|
278 |
/// \brief Copy Constructor of the AlterationNotifier. |
|
279 | 279 |
/// |
280 |
/// Copy constructor of the AlterationNotifier. |
|
280 |
/// Copy constructor of the AlterationNotifier. |
|
281 | 281 |
/// It creates only an empty notifier because the copiable |
282 | 282 |
/// notifier's observers have to be registered still into that notifier. |
283 |
AlterationNotifier(const AlterationNotifier& _notifier) |
|
283 |
AlterationNotifier(const AlterationNotifier& _notifier) |
|
284 | 284 |
: container(_notifier.container) {} |
285 | 285 |
|
286 | 286 |
/// \brief Destructor. |
287 |
/// |
|
287 |
/// |
|
288 | 288 |
/// Destructor of the AlterationNotifier. |
289 | 289 |
/// |
290 | 290 |
~AlterationNotifier() { |
291 | 291 |
typename Observers::iterator it; |
292 | 292 |
for (it = _observers.begin(); it != _observers.end(); ++it) { |
293 |
|
|
293 |
(*it)->_notifier = 0; |
|
294 | 294 |
} |
295 | 295 |
} |
296 | 296 |
|
... | ... |
@@ -338,13 +338,13 @@ |
338 | 338 |
int maxId() const { |
339 | 339 |
return container->maxId(Item()); |
340 | 340 |
} |
341 |
|
|
341 |
|
|
342 | 342 |
protected: |
343 | 343 |
|
344 | 344 |
void attach(ObserverBase& observer) { |
345 | 345 |
observer._index = _observers.insert(_observers.begin(), &observer); |
346 | 346 |
observer._notifier = this; |
347 |
} |
|
347 |
} |
|
348 | 348 |
|
349 | 349 |
void detach(ObserverBase& observer) { |
350 | 350 |
_observers.erase(observer._index); |
... | ... |
@@ -353,13 +353,13 @@ |
353 | 353 |
} |
354 | 354 |
|
355 | 355 |
public: |
356 |
|
|
357 |
/// \brief Notifies all the registed observers about an item added to |
|
356 |
|
|
357 |
/// \brief Notifies all the registed observers about an item added to |
|
358 | 358 |
/// the container. |
359 | 359 |
/// |
360 |
/// It notifies all the registed observers about an item added to |
|
360 |
/// It notifies all the registed observers about an item added to |
|
361 | 361 |
/// the container. |
362 |
/// |
|
362 |
/// |
|
363 | 363 |
void add(const Item& item) { |
364 | 364 |
typename Observers::reverse_iterator it; |
365 | 365 |
try { |
... | ... |
@@ -373,14 +373,14 @@ |
373 | 373 |
} |
374 | 374 |
throw; |
375 | 375 |
} |
376 |
} |
|
376 |
} |
|
377 | 377 |
|
378 |
/// \brief Notifies all the registed observers about more item added to |
|
378 |
/// \brief Notifies all the registed observers about more item added to |
|
379 | 379 |
/// the container. |
380 | 380 |
/// |
381 |
/// It notifies all the registed observers about more item added to |
|
381 |
/// It notifies all the registed observers about more item added to |
|
382 | 382 |
/// the container. |
383 |
/// |
|
383 |
/// |
|
384 | 384 |
void add(const std::vector<Item>& items) { |
385 | 385 |
typename Observers::reverse_iterator it; |
386 | 386 |
try { |
... | ... |
@@ -394,14 +394,14 @@ |
394 | 394 |
} |
395 | 395 |
throw; |
396 | 396 |
} |
397 |
} |
|
397 |
} |
|
398 | 398 |
|
399 |
/// \brief Notifies all the registed observers about an item erased from |
|
399 |
/// \brief Notifies all the registed observers about an item erased from |
|
400 | 400 |
/// the container. |
401 |
/// |
|
402 |
/// It notifies all the registed observers about an item erased from |
|
401 |
/// |
|
402 |
/// It notifies all the registed observers about an item erased from |
|
403 | 403 |
/// the container. |
404 |
/// |
|
404 |
/// |
|
405 | 405 |
void erase(const Item& item) throw() { |
406 | 406 |
typename Observers::iterator it = _observers.begin(); |
407 | 407 |
while (it != _observers.end()) { |
... | ... |
@@ -416,12 +416,12 @@ |
416 | 416 |
} |
417 | 417 |
} |
418 | 418 |
|
419 |
/// \brief Notifies all the registed observers about more item erased |
|
419 |
/// \brief Notifies all the registed observers about more item erased |
|
420 | 420 |
/// from the container. |
421 |
/// |
|
422 |
/// It notifies all the registed observers about more item erased from |
|
421 |
/// |
|
422 |
/// It notifies all the registed observers about more item erased from |
|
423 | 423 |
/// the container. |
424 |
/// |
|
424 |
/// |
|
425 | 425 |
void erase(const std::vector<Item>& items) { |
426 | 426 |
typename Observers::iterator it = _observers.begin(); |
427 | 427 |
while (it != _observers.end()) { |
... | ... |
@@ -436,9 +436,9 @@ |
436 | 436 |
} |
437 | 437 |
} |
438 | 438 |
|
439 |
/// \brief Notifies all the registed observers about the container is |
|
439 |
/// \brief Notifies all the registed observers about the container is |
|
440 | 440 |
/// built. |
441 |
/// |
|
441 |
/// |
|
442 | 442 |
/// Notifies all the registed observers about the container is built |
443 | 443 |
/// from an empty container. |
444 | 444 |
void build() { |
... | ... |
@@ -456,7 +456,7 @@ |
456 | 456 |
} |
457 | 457 |
} |
458 | 458 |
|
459 |
/// \brief Notifies all the registed observers about all items are |
|
459 |
/// \brief Notifies all the registed observers about all items are |
|
460 | 460 |
/// erased. |
461 | 461 |
/// |
462 | 462 |
/// Notifies all the registed observers about all items are erased |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -38,16 +38,16 @@ |
38 | 38 |
/// |
39 | 39 |
/// The ArrayMap template class is graph map structure what |
40 | 40 |
/// automatically updates the map when a key is added to or erased from |
41 |
/// the map. This map uses the allocators to implement |
|
41 |
/// the map. This map uses the allocators to implement |
|
42 | 42 |
/// the container functionality. |
43 | 43 |
/// |
44 | 44 |
/// The template parameters are the Graph the current Item type and |
45 | 45 |
/// the Value type of the map. |
46 | 46 |
template <typename _Graph, typename _Item, typename _Value> |
47 |
class ArrayMap |
|
47 |
class ArrayMap |
|
48 | 48 |
: public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { |
49 | 49 |
public: |
50 |
/// The graph type of the maps. |
|
50 |
/// The graph type of the maps. |
|
51 | 51 |
typedef _Graph Graph; |
52 | 52 |
/// The item type of the map. |
53 | 53 |
typedef _Item Item; |
... | ... |
@@ -69,7 +69,7 @@ |
69 | 69 |
|
70 | 70 |
/// The MapBase of the Map which imlements the core regisitry function. |
71 | 71 |
typedef typename Notifier::ObserverBase Parent; |
72 |
|
|
72 |
|
|
73 | 73 |
private: |
74 | 74 |
typedef std::allocator<Value> Allocator; |
75 | 75 |
|
... | ... |
@@ -84,31 +84,31 @@ |
84 | 84 |
Notifier* nf = Parent::notifier(); |
85 | 85 |
Item it; |
86 | 86 |
for (nf->first(it); it != INVALID; nf->next(it)) { |
87 |
int id = nf->id(it);; |
|
88 |
allocator.construct(&(values[id]), Value()); |
|
89 |
|
|
87 |
int id = nf->id(it);; |
|
88 |
allocator.construct(&(values[id]), Value()); |
|
89 |
} |
|
90 | 90 |
} |
91 | 91 |
|
92 |
/// \brief Constructor to use default value to initialize the map. |
|
92 |
/// \brief Constructor to use default value to initialize the map. |
|
93 | 93 |
/// |
94 |
/// It constructs a map and initialize all of the the map. |
|
94 |
/// It constructs a map and initialize all of the the map. |
|
95 | 95 |
ArrayMap(const Graph& graph, const Value& value) { |
96 | 96 |
Parent::attach(graph.notifier(Item())); |
97 | 97 |
allocate_memory(); |
98 | 98 |
Notifier* nf = Parent::notifier(); |
99 | 99 |
Item it; |
100 | 100 |
for (nf->first(it); it != INVALID; nf->next(it)) { |
101 |
int id = nf->id(it);; |
|
102 |
allocator.construct(&(values[id]), value); |
|
103 |
|
|
101 |
int id = nf->id(it);; |
|
102 |
allocator.construct(&(values[id]), value); |
|
103 |
} |
|
104 | 104 |
} |
105 | 105 |
|
106 | 106 |
/// \brief Constructor to copy a map of the same map type. |
107 | 107 |
/// |
108 |
/// Constructor to copy a map of the same map type. |
|
108 |
/// Constructor to copy a map of the same map type. |
|
109 | 109 |
ArrayMap(const ArrayMap& copy) : Parent() { |
110 | 110 |
if (copy.attached()) { |
111 |
|
|
111 |
attach(*copy.notifier()); |
|
112 | 112 |
} |
113 | 113 |
capacity = copy.capacity; |
114 | 114 |
if (capacity == 0) return; |
... | ... |
@@ -116,18 +116,18 @@ |
116 | 116 |
Notifier* nf = Parent::notifier(); |
117 | 117 |
Item it; |
118 | 118 |
for (nf->first(it); it != INVALID; nf->next(it)) { |
119 |
int id = nf->id(it);; |
|
120 |
allocator.construct(&(values[id]), copy.values[id]); |
|
119 |
int id = nf->id(it);; |
|
120 |
allocator.construct(&(values[id]), copy.values[id]); |
|
121 | 121 |
} |
122 | 122 |
} |
123 | 123 |
|
124 | 124 |
/// \brief Assign operator. |
125 | 125 |
/// |
126 | 126 |
/// This operator assigns for each item in the map the |
127 |
/// value mapped to the same item in the copied map. |
|
127 |
/// value mapped to the same item in the copied map. |
|
128 | 128 |
/// The parameter map should be indiced with the same |
129 | 129 |
/// itemset because this assign operator does not change |
130 |
/// the container of the map. |
|
130 |
/// the container of the map. |
|
131 | 131 |
ArrayMap& operator=(const ArrayMap& cmap) { |
132 | 132 |
return operator=<ArrayMap>(cmap); |
133 | 133 |
} |
... | ... |
@@ -138,7 +138,7 @@ |
138 | 138 |
/// The given parameter should be conform to the ReadMap |
139 | 139 |
/// concecpt and could be indiced by the current item set of |
140 | 140 |
/// the NodeMap. In this case the value for each item |
141 |
/// is assigned by the value of the given ReadMap. |
|
141 |
/// is assigned by the value of the given ReadMap. |
|
142 | 142 |
template <typename CMap> |
143 | 143 |
ArrayMap& operator=(const CMap& cmap) { |
144 | 144 |
checkConcept<concepts::ReadMap<Key, _Value>, CMap>(); |
... | ... |
@@ -151,15 +151,15 @@ |
151 | 151 |
} |
152 | 152 |
|
153 | 153 |
/// \brief The destructor of the map. |
154 |
/// |
|
154 |
/// |
|
155 | 155 |
/// The destructor of the map. |
156 |
virtual ~ArrayMap() { |
|
156 |
virtual ~ArrayMap() { |
|
157 | 157 |
if (attached()) { |
158 |
clear(); |
|
159 |
detach(); |
|
158 |
clear(); |
|
159 |
detach(); |
|
160 | 160 |
} |
161 | 161 |
} |
162 |
|
|
162 |
|
|
163 | 163 |
protected: |
164 | 164 |
|
165 | 165 |
using Parent::attach; |
... | ... |
@@ -168,26 +168,26 @@ |
168 | 168 |
|
169 | 169 |
public: |
170 | 170 |
|
171 |
/// \brief The subscript operator. |
|
171 |
/// \brief The subscript operator. |
|
172 | 172 |
/// |
173 | 173 |
/// The subscript operator. The map can be subscripted by the |
174 |
/// actual keys of the graph. |
|
174 |
/// actual keys of the graph. |
|
175 | 175 |
Value& operator[](const Key& key) { |
176 | 176 |
int id = Parent::notifier()->id(key); |
177 | 177 |
return values[id]; |
178 |
} |
|
179 |
|
|
178 |
} |
|
179 |
|
|
180 | 180 |
/// \brief The const subscript operator. |
181 | 181 |
/// |
182 | 182 |
/// The const subscript operator. The map can be subscripted by the |
183 |
/// actual keys of the graph. |
|
183 |
/// actual keys of the graph. |
|
184 | 184 |
const Value& operator[](const Key& key) const { |
185 | 185 |
int id = Parent::notifier()->id(key); |
186 | 186 |
return values[id]; |
187 | 187 |
} |
188 | 188 |
|
189 | 189 |
/// \brief Setter function of the map. |
190 |
/// |
|
190 |
/// |
|
191 | 191 |
/// Setter function of the map. Equivalent with map[key] = val. |
192 | 192 |
/// This is a compatibility feature with the not dereferable maps. |
193 | 193 |
void set(const Key& key, const Value& val) { |
... | ... |
@@ -197,81 +197,81 @@ |
197 | 197 |
protected: |
198 | 198 |
|
199 | 199 |
/// \brief Adds a new key to the map. |
200 |
/// |
|
200 |
/// |
|
201 | 201 |
/// It adds a new key to the map. It called by the observer notifier |
202 |
/// and it overrides the add() member function of the observer base. |
|
202 |
/// and it overrides the add() member function of the observer base. |
|
203 | 203 |
virtual void add(const Key& key) { |
204 | 204 |
Notifier* nf = Parent::notifier(); |
205 | 205 |
int id = nf->id(key); |
206 | 206 |
if (id >= capacity) { |
207 |
int new_capacity = (capacity == 0 ? 1 : capacity); |
|
208 |
while (new_capacity <= id) { |
|
209 |
new_capacity <<= 1; |
|
210 |
} |
|
211 |
Value* new_values = allocator.allocate(new_capacity); |
|
212 |
Item it; |
|
213 |
for (nf->first(it); it != INVALID; nf->next(it)) { |
|
214 |
int jd = nf->id(it);; |
|
215 |
if (id != jd) { |
|
216 |
allocator.construct(&(new_values[jd]), values[jd]); |
|
217 |
allocator.destroy(&(values[jd])); |
|
218 |
} |
|
219 |
} |
|
220 |
if (capacity != 0) allocator.deallocate(values, capacity); |
|
221 |
values = new_values; |
|
222 |
capacity = new_capacity; |
|
207 |
int new_capacity = (capacity == 0 ? 1 : capacity); |
|
208 |
while (new_capacity <= id) { |
|
209 |
new_capacity <<= 1; |
|
210 |
} |
|
211 |
Value* new_values = allocator.allocate(new_capacity); |
|
212 |
Item it; |
|
213 |
for (nf->first(it); it != INVALID; nf->next(it)) { |
|
214 |
int jd = nf->id(it);; |
|
215 |
if (id != jd) { |
|
216 |
allocator.construct(&(new_values[jd]), values[jd]); |
|
217 |
allocator.destroy(&(values[jd])); |
|
218 |
} |
|
219 |
} |
|
220 |
if (capacity != 0) allocator.deallocate(values, capacity); |
|
221 |
values = new_values; |
|
222 |
capacity = new_capacity; |
|
223 | 223 |
} |
224 | 224 |
allocator.construct(&(values[id]), Value()); |
225 | 225 |
} |
226 | 226 |
|
227 | 227 |
/// \brief Adds more new keys to the map. |
228 |
/// |
|
228 |
/// |
|
229 | 229 |
/// It adds more new keys to the map. It called by the observer notifier |
230 |
/// and it overrides the add() member function of the observer base. |
|
230 |
/// and it overrides the add() member function of the observer base. |
|
231 | 231 |
virtual void add(const std::vector<Key>& keys) { |
232 | 232 |
Notifier* nf = Parent::notifier(); |
233 | 233 |
int max_id = -1; |
234 | 234 |
for (int i = 0; i < int(keys.size()); ++i) { |
235 |
int id = nf->id(keys[i]); |
|
236 |
if (id > max_id) { |
|
237 |
max_id = id; |
|
238 |
} |
|
235 |
int id = nf->id(keys[i]); |
|
236 |
if (id > max_id) { |
|
237 |
max_id = id; |
|
238 |
} |
|
239 | 239 |
} |
240 | 240 |
if (max_id >= capacity) { |
241 |
int new_capacity = (capacity == 0 ? 1 : capacity); |
|
242 |
while (new_capacity <= max_id) { |
|
243 |
new_capacity <<= 1; |
|
244 |
} |
|
245 |
Value* new_values = allocator.allocate(new_capacity); |
|
246 |
Item it; |
|
247 |
for (nf->first(it); it != INVALID; nf->next(it)) { |
|
248 |
int id = nf->id(it); |
|
249 |
bool found = false; |
|
250 |
for (int i = 0; i < int(keys.size()); ++i) { |
|
251 |
int jd = nf->id(keys[i]); |
|
252 |
if (id == jd) { |
|
253 |
found = true; |
|
254 |
break; |
|
255 |
} |
|
256 |
} |
|
257 |
if (found) continue; |
|
258 |
allocator.construct(&(new_values[id]), values[id]); |
|
259 |
allocator.destroy(&(values[id])); |
|
260 |
} |
|
261 |
if (capacity != 0) allocator.deallocate(values, capacity); |
|
262 |
values = new_values; |
|
263 |
|
|
241 |
int new_capacity = (capacity == 0 ? 1 : capacity); |
|
242 |
while (new_capacity <= max_id) { |
|
243 |
new_capacity <<= 1; |
|
244 |
} |
|
245 |
Value* new_values = allocator.allocate(new_capacity); |
|
246 |
Item it; |
|
247 |
for (nf->first(it); it != INVALID; nf->next(it)) { |
|
248 |
int id = nf->id(it); |
|
249 |
bool found = false; |
|
250 |
for (int i = 0; i < int(keys.size()); ++i) { |
|
251 |
int jd = nf->id(keys[i]); |
|
252 |
if (id == jd) { |
|
253 |
found = true; |
|
254 |
break; |
|
255 |
} |
|
256 |
} |
|
257 |
if (found) continue; |
|
258 |
allocator.construct(&(new_values[id]), values[id]); |
|
259 |
allocator.destroy(&(values[id])); |
|
260 |
} |
|
261 |
if (capacity != 0) allocator.deallocate(values, capacity); |
|
262 |
values = new_values; |
|
263 |
capacity = new_capacity; |
|
264 | 264 |
} |
265 | 265 |
for (int i = 0; i < int(keys.size()); ++i) { |
266 |
int id = nf->id(keys[i]); |
|
267 |
allocator.construct(&(values[id]), Value()); |
|
266 |
int id = nf->id(keys[i]); |
|
267 |
allocator.construct(&(values[id]), Value()); |
|
268 | 268 |
} |
269 | 269 |
} |
270 |
|
|
270 |
|
|
271 | 271 |
/// \brief Erase a key from the map. |
272 | 272 |
/// |
273 | 273 |
/// Erase a key from the map. It called by the observer notifier |
274 |
/// and it overrides the erase() member function of the observer base. |
|
274 |
/// and it overrides the erase() member function of the observer base. |
|
275 | 275 |
virtual void erase(const Key& key) { |
276 | 276 |
int id = Parent::notifier()->id(key); |
277 | 277 |
allocator.destroy(&(values[id])); |
... | ... |
@@ -280,67 +280,67 @@ |
280 | 280 |
/// \brief Erase more keys from the map. |
281 | 281 |
/// |
282 | 282 |
/// Erase more keys from the map. It called by the observer notifier |
283 |
/// and it overrides the erase() member function of the observer base. |
|
283 |
/// and it overrides the erase() member function of the observer base. |
|
284 | 284 |
virtual void erase(const std::vector<Key>& keys) { |
285 | 285 |
for (int i = 0; i < int(keys.size()); ++i) { |
286 |
int id = Parent::notifier()->id(keys[i]); |
|
287 |
allocator.destroy(&(values[id])); |
|
286 |
int id = Parent::notifier()->id(keys[i]); |
|
287 |
allocator.destroy(&(values[id])); |
|
288 | 288 |
} |
289 | 289 |
} |
290 | 290 |
|
291 | 291 |
/// \brief Buildes the map. |
292 |
/// |
|
292 |
/// |
|
293 | 293 |
/// It buildes the map. It called by the observer notifier |
294 |
/// and it overrides the build() member function of the observer base. |
|
294 |
/// and it overrides the build() member function of the observer base. |
|
295 | 295 |
virtual void build() { |
296 | 296 |
Notifier* nf = Parent::notifier(); |
297 | 297 |
allocate_memory(); |
298 | 298 |
Item it; |
299 | 299 |
for (nf->first(it); it != INVALID; nf->next(it)) { |
300 |
int id = nf->id(it);; |
|
301 |
allocator.construct(&(values[id]), Value()); |
|
302 |
|
|
300 |
int id = nf->id(it);; |
|
301 |
allocator.construct(&(values[id]), Value()); |
|
302 |
} |
|
303 | 303 |
} |
304 | 304 |
|
305 | 305 |
/// \brief Clear the map. |
306 | 306 |
/// |
307 | 307 |
/// It erase all items from the map. It called by the observer notifier |
308 |
/// and it overrides the clear() member function of the observer base. |
|
309 |
virtual void clear() { |
|
308 |
/// and it overrides the clear() member function of the observer base. |
|
309 |
virtual void clear() { |
|
310 | 310 |
Notifier* nf = Parent::notifier(); |
311 | 311 |
if (capacity != 0) { |
312 |
Item it; |
|
313 |
for (nf->first(it); it != INVALID; nf->next(it)) { |
|
314 |
int id = nf->id(it); |
|
315 |
allocator.destroy(&(values[id])); |
|
316 |
} |
|
317 |
allocator.deallocate(values, capacity); |
|
318 |
|
|
312 |
Item it; |
|
313 |
for (nf->first(it); it != INVALID; nf->next(it)) { |
|
314 |
int id = nf->id(it); |
|
315 |
allocator.destroy(&(values[id])); |
|
316 |
} |
|
317 |
allocator.deallocate(values, capacity); |
|
318 |
capacity = 0; |
|
319 | 319 |
} |
320 | 320 |
} |
321 | 321 |
|
322 | 322 |
private: |
323 |
|
|
323 |
|
|
324 | 324 |
void allocate_memory() { |
325 | 325 |
int max_id = Parent::notifier()->maxId(); |
326 | 326 |
if (max_id == -1) { |
327 |
capacity = 0; |
|
328 |
values = 0; |
|
329 |
|
|
327 |
capacity = 0; |
|
328 |
values = 0; |
|
329 |
return; |
|
330 | 330 |
} |
331 | 331 |
capacity = 1; |
332 | 332 |
while (capacity <= max_id) { |
333 |
|
|
333 |
capacity <<= 1; |
|
334 | 334 |
} |
335 |
values = allocator.allocate(capacity); |
|
336 |
} |
|
335 |
values = allocator.allocate(capacity); |
|
336 |
} |
|
337 | 337 |
|
338 | 338 |
int capacity; |
339 | 339 |
Value* values; |
340 | 340 |
Allocator allocator; |
341 | 341 |
|
342 |
}; |
|
342 |
}; |
|
343 | 343 |
|
344 | 344 |
} |
345 | 345 |
|
346 |
#endif |
|
346 |
#endif |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -63,14 +63,14 @@ |
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); |
|
70 | 70 |
} |
71 | 71 |
bool operator<(const Arc &that) const { |
72 |
return forward<that.forward || |
|
73 |
(!(that.forward<forward) && Edge(*this)<Edge(that)); |
|
72 |
return forward<that.forward || |
|
73 |
(!(that.forward<forward) && Edge(*this)<Edge(that)); |
|
74 | 74 |
} |
75 | 75 |
}; |
76 | 76 |
|
... | ... |
@@ -117,59 +117,59 @@ |
117 | 117 |
|
118 | 118 |
void next(Arc &e) const { |
119 | 119 |
if( e.forward ) { |
120 |
|
|
120 |
e.forward = false; |
|
121 | 121 |
} |
122 | 122 |
else { |
123 |
Parent::next(e); |
|
124 |
e.forward = true; |
|
123 |
Parent::next(e); |
|
124 |
e.forward = true; |
|
125 | 125 |
} |
126 | 126 |
} |
127 | 127 |
|
128 | 128 |
void firstOut(Arc &e, const Node &n) const { |
129 | 129 |
Parent::firstIn(e,n); |
130 | 130 |
if( Edge(e) != INVALID ) { |
131 |
|
|
131 |
e.forward = false; |
|
132 | 132 |
} |
133 | 133 |
else { |
134 |
Parent::firstOut(e,n); |
|
135 |
e.forward = true; |
|
134 |
Parent::firstOut(e,n); |
|
135 |
e.forward = true; |
|
136 | 136 |
} |
137 | 137 |
} |
138 | 138 |
void nextOut(Arc &e) const { |
139 | 139 |
if( ! e.forward ) { |
140 |
Node n = Parent::target(e); |
|
141 |
Parent::nextIn(e); |
|
142 |
if( Edge(e) == INVALID ) { |
|
143 |
Parent::firstOut(e, n); |
|
144 |
e.forward = true; |
|
145 |
} |
|
140 |
Node n = Parent::target(e); |
|
141 |
Parent::nextIn(e); |
|
142 |
if( Edge(e) == INVALID ) { |
|
143 |
Parent::firstOut(e, n); |
|
144 |
e.forward = true; |
|
145 |
} |
|
146 | 146 |
} |
147 | 147 |
else { |
148 |
|
|
148 |
Parent::nextOut(e); |
|
149 | 149 |
} |
150 | 150 |
} |
151 | 151 |
|
152 | 152 |
void firstIn(Arc &e, const Node &n) const { |
153 | 153 |
Parent::firstOut(e,n); |
154 | 154 |
if( Edge(e) != INVALID ) { |
155 |
|
|
155 |
e.forward = false; |
|
156 | 156 |
} |
157 | 157 |
else { |
158 |
Parent::firstIn(e,n); |
|
159 |
e.forward = true; |
|
158 |
Parent::firstIn(e,n); |
|
159 |
e.forward = true; |
|
160 | 160 |
} |
161 | 161 |
} |
162 | 162 |
void nextIn(Arc &e) const { |
163 | 163 |
if( ! e.forward ) { |
164 |
Node n = Parent::source(e); |
|
165 |
Parent::nextOut(e); |
|
166 |
if( Edge(e) == INVALID ) { |
|
167 |
Parent::firstIn(e, n); |
|
168 |
e.forward = true; |
|
169 |
} |
|
164 |
Node n = Parent::source(e); |
|
165 |
Parent::nextOut(e); |
|
166 |
if( Edge(e) == INVALID ) { |
|
167 |
Parent::firstIn(e, n); |
|
168 |
e.forward = true; |
|
169 |
} |
|
170 | 170 |
} |
171 | 171 |
else { |
172 |
|
|
172 |
Parent::nextIn(e); |
|
173 | 173 |
} |
174 | 174 |
} |
175 | 175 |
|
... | ... |
@@ -183,13 +183,13 @@ |
183 | 183 |
|
184 | 184 |
void nextInc(Edge &e, bool &d) const { |
185 | 185 |
if (d) { |
186 |
Node s = Parent::source(e); |
|
187 |
Parent::nextOut(e); |
|
188 |
if (e != INVALID) return; |
|
189 |
d = false; |
|
190 |
|
|
186 |
Node s = Parent::source(e); |
|
187 |
Parent::nextOut(e); |
|
188 |
if (e != INVALID) return; |
|
189 |
d = false; |
|
190 |
Parent::firstIn(e, s); |
|
191 | 191 |
} else { |
192 |
|
|
192 |
Parent::nextIn(e); |
|
193 | 193 |
} |
194 | 194 |
} |
195 | 195 |
|
... | ... |
@@ -240,18 +240,18 @@ |
240 | 240 |
|
241 | 241 |
Arc findArc(Node s, Node t, Arc p = INVALID) const { |
242 | 242 |
if (p == INVALID) { |
243 |
Edge arc = Parent::findArc(s, t); |
|
244 |
if (arc != INVALID) return direct(arc, true); |
|
245 |
arc = Parent::findArc(t, s); |
|
246 |
if (arc != INVALID) return direct(arc, false); |
|
243 |
Edge arc = Parent::findArc(s, t); |
|
244 |
if (arc != INVALID) return direct(arc, true); |
|
245 |
arc = Parent::findArc(t, s); |
|
246 |
if (arc != INVALID) return direct(arc, false); |
|
247 | 247 |
} else if (direction(p)) { |
248 |
Edge arc = Parent::findArc(s, t, p); |
|
249 |
if (arc != INVALID) return direct(arc, true); |
|
250 |
arc = Parent::findArc(t, s); |
|
251 |
if (arc != INVALID) return direct(arc, false); |
|
248 |
Edge arc = Parent::findArc(s, t, p); |
|
249 |
if (arc != INVALID) return direct(arc, true); |
|
250 |
arc = Parent::findArc(t, s); |
|
251 |
if (arc != INVALID) return direct(arc, false); |
|
252 | 252 |
} else { |
253 |
Edge arc = Parent::findArc(t, s, p); |
|
254 |
if (arc != INVALID) return direct(arc, false); |
|
253 |
Edge arc = Parent::findArc(t, s, p); |
|
254 |
if (arc != INVALID) return direct(arc, false); |
|
255 | 255 |
} |
256 | 256 |
return INVALID; |
257 | 257 |
} |
... | ... |
@@ -267,10 +267,10 @@ |
267 | 267 |
Edge arc = Parent::findArc(s, t, p); |
268 | 268 |
if (arc != INVALID) return arc; |
269 | 269 |
arc = Parent::findArc(t, s); |
270 |
if (arc != INVALID) return arc; |
|
270 |
if (arc != INVALID) return arc; |
|
271 | 271 |
} else { |
272 | 272 |
Edge arc = Parent::findArc(t, s, p); |
273 |
if (arc != INVALID) return arc; |
|
273 |
if (arc != INVALID) return arc; |
|
274 | 274 |
} |
275 | 275 |
} else { |
276 | 276 |
return Parent::findArc(s, t, p); |
... | ... |
@@ -299,12 +299,12 @@ |
299 | 299 |
public: |
300 | 300 |
Red() {} |
301 | 301 |
Red(const Node& node) : Node(node) { |
302 |
LEMON_ASSERT(Parent::red(node) || node == INVALID, |
|
303 |
typename Parent::NodeSetError()); |
|
302 |
LEMON_ASSERT(Parent::red(node) || node == INVALID, |
|
303 |
typename Parent::NodeSetError()); |
|
304 | 304 |
} |
305 | 305 |
Red& operator=(const Node& node) { |
306 |
LEMON_ASSERT(Parent::red(node) || node == INVALID, |
|
307 |
typename Parent::NodeSetError()); |
|
306 |
LEMON_ASSERT(Parent::red(node) || node == INVALID, |
|
307 |
typename Parent::NodeSetError()); |
|
308 | 308 |
Node::operator=(node); |
309 | 309 |
return *this; |
310 | 310 |
} |
... | ... |
@@ -331,12 +331,12 @@ |
331 | 331 |
public: |
332 | 332 |
Blue() {} |
333 | 333 |
Blue(const Node& node) : Node(node) { |
334 |
LEMON_ASSERT(Parent::blue(node) || node == INVALID, |
|
335 |
typename Parent::NodeSetError()); |
|
334 |
LEMON_ASSERT(Parent::blue(node) || node == INVALID, |
|
335 |
typename Parent::NodeSetError()); |
|
336 | 336 |
} |
337 | 337 |
Blue& operator=(const Node& node) { |
338 |
LEMON_ASSERT(Parent::blue(node) || node == INVALID, |
|
339 |
typename Parent::NodeSetError()); |
|
338 |
LEMON_ASSERT(Parent::blue(node) || node == INVALID, |
|
339 |
typename Parent::NodeSetError()); |
|
340 | 340 |
Node::operator=(node); |
341 | 341 |
return *this; |
342 | 342 |
} |
... | ... |
@@ -353,7 +353,7 @@ |
353 | 353 |
void next(Blue& node) const { |
354 | 354 |
Parent::nextBlue(static_cast<Node&>(node)); |
355 | 355 |
} |
356 |
|
|
356 |
|
|
357 | 357 |
int id(const Blue& node) const { |
358 | 358 |
return Parent::redId(node); |
359 | 359 |
} |
... | ... |
@@ -367,19 +367,19 @@ |
367 | 367 |
|
368 | 368 |
void firstInc(Edge& arc, bool& dir, const Node& node) const { |
369 | 369 |
if (Parent::red(node)) { |
370 |
Parent::firstFromRed(arc, node); |
|
371 |
dir = true; |
|
370 |
Parent::firstFromRed(arc, node); |
|
371 |
dir = true; |
|
372 | 372 |
} else { |
373 |
Parent::firstFromBlue(arc, node); |
|
374 |
dir = static_cast<Edge&>(arc) == INVALID; |
|
373 |
Parent::firstFromBlue(arc, node); |
|
374 |
dir = static_cast<Edge&>(arc) == INVALID; |
|
375 | 375 |
} |
376 | 376 |
} |
377 | 377 |
void nextInc(Edge& arc, bool& dir) const { |
378 | 378 |
if (dir) { |
379 |
|
|
379 |
Parent::nextFromRed(arc); |
|
380 | 380 |
} else { |
381 |
Parent::nextFromBlue(arc); |
|
382 |
if (arc == INVALID) dir = true; |
|
381 |
Parent::nextFromBlue(arc); |
|
382 |
if (arc == INVALID) dir = true; |
|
383 | 383 |
} |
384 | 384 |
} |
385 | 385 |
|
... | ... |
@@ -389,20 +389,20 @@ |
389 | 389 |
bool forward; |
390 | 390 |
|
391 | 391 |
Arc(const Edge& arc, bool _forward) |
392 |
|
|
392 |
: Edge(arc), forward(_forward) {} |
|
393 | 393 |
|
394 | 394 |
public: |
395 | 395 |
Arc() {} |
396 | 396 |
Arc (Invalid) : Edge(INVALID), forward(true) {} |
397 | 397 |
bool operator==(const Arc& i) const { |
398 |
|
|
398 |
return Edge::operator==(i) && forward == i.forward; |
|
399 | 399 |
} |
400 | 400 |
bool operator!=(const Arc& i) const { |
401 |
|
|
401 |
return Edge::operator!=(i) || forward != i.forward; |
|
402 | 402 |
} |
403 | 403 |
bool operator<(const Arc& i) const { |
404 |
return Edge::operator<(i) || |
|
405 |
(!(i.forward<forward) && Edge(*this)<Edge(i)); |
|
404 |
return Edge::operator<(i) || |
|
405 |
(!(i.forward<forward) && Edge(*this)<Edge(i)); |
|
406 | 406 |
} |
407 | 407 |
}; |
408 | 408 |
|
... | ... |
@@ -413,44 +413,44 @@ |
413 | 413 |
|
414 | 414 |
void next(Arc& arc) const { |
415 | 415 |
if (!arc.forward) { |
416 |
|
|
416 |
Parent::next(static_cast<Edge&>(arc)); |
|
417 | 417 |
} |
418 | 418 |
arc.forward = !arc.forward; |
419 | 419 |
} |
420 | 420 |
|
421 | 421 |
void firstOut(Arc& arc, const Node& node) const { |
422 | 422 |
if (Parent::red(node)) { |
423 |
Parent::firstFromRed(arc, node); |
|
424 |
arc.forward = true; |
|
423 |
Parent::firstFromRed(arc, node); |
|
424 |
arc.forward = true; |
|
425 | 425 |
} else { |
426 |
Parent::firstFromBlue(arc, node); |
|
427 |
arc.forward = static_cast<Edge&>(arc) == INVALID; |
|
426 |
Parent::firstFromBlue(arc, node); |
|
427 |
arc.forward = static_cast<Edge&>(arc) == INVALID; |
|
428 | 428 |
} |
429 | 429 |
} |
430 | 430 |
void nextOut(Arc& arc) const { |
431 | 431 |
if (arc.forward) { |
432 |
|
|
432 |
Parent::nextFromRed(arc); |
|
433 | 433 |
} else { |
434 |
|
|
434 |
Parent::nextFromBlue(arc); |
|
435 | 435 |
arc.forward = static_cast<Edge&>(arc) == INVALID; |
436 | 436 |
} |
437 | 437 |
} |
438 | 438 |
|
439 | 439 |
void firstIn(Arc& arc, const Node& node) const { |
440 | 440 |
if (Parent::blue(node)) { |
441 |
Parent::firstFromBlue(arc, node); |
|
442 |
arc.forward = true; |
|
441 |
Parent::firstFromBlue(arc, node); |
|
442 |
arc.forward = true; |
|
443 | 443 |
} else { |
444 |
Parent::firstFromRed(arc, node); |
|
445 |
arc.forward = static_cast<Edge&>(arc) == INVALID; |
|
444 |
Parent::firstFromRed(arc, node); |
|
445 |
arc.forward = static_cast<Edge&>(arc) == INVALID; |
|
446 | 446 |
} |
447 | 447 |
} |
448 | 448 |
void nextIn(Arc& arc) const { |
449 | 449 |
if (arc.forward) { |
450 |
|
|
450 |
Parent::nextFromBlue(arc); |
|
451 | 451 |
} else { |
452 |
Parent::nextFromRed(arc); |
|
453 |
arc.forward = static_cast<Edge&>(arc) == INVALID; |
|
452 |
Parent::nextFromRed(arc); |
|
453 |
arc.forward = static_cast<Edge&>(arc) == INVALID; |
|
454 | 454 |
} |
455 | 455 |
} |
456 | 456 |
|
... | ... |
@@ -462,7 +462,7 @@ |
462 | 462 |
} |
463 | 463 |
|
464 | 464 |
int id(const Arc& arc) const { |
465 |
return (Parent::id(static_cast<const Edge&>(arc)) << 1) + |
|
465 |
return (Parent::id(static_cast<const Edge&>(arc)) << 1) + |
|
466 | 466 |
(arc.forward ? 0 : 1); |
467 | 467 |
} |
468 | 468 |
Arc arcFromId(int ix) const { |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -44,7 +44,7 @@ |
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); |
... | ... |
@@ -54,7 +54,7 @@ |
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); |
... | ... |
@@ -87,7 +87,7 @@ |
87 | 87 |
Point r(conv(p2,p3,t)); |
88 | 88 |
return Bezier2(p1,q,conv(q,r,t)); |
89 | 89 |
} |
90 |
|
|
90 |
|
|
91 | 91 |
Bezier2 after(double t) const |
92 | 92 |
{ |
93 | 93 |
Point q(conv(p1,p2,t)); |
... | ... |
@@ -110,16 +110,16 @@ |
110 | 110 |
Bezier3() {} |
111 | 111 |
Bezier3(Point _p1, Point _p2, Point _p3, Point _p4) |
112 | 112 |
: p1(_p1), p2(_p2), p3(_p3), p4(_p4) {} |
113 |
Bezier3(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,1.0/3.0)), |
|
114 |
p3(conv(b.p1,b.p2,2.0/3.0)), p4(b.p2) {} |
|
113 |
Bezier3(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,1.0/3.0)), |
|
114 |
p3(conv(b.p1,b.p2,2.0/3.0)), p4(b.p2) {} |
|
115 | 115 |
Bezier3(const Bezier2 &b) : p1(b.p1), p2(conv(b.p1,b.p2,2.0/3.0)), |
116 |
p3(conv(b.p2,b.p3,1.0/3.0)), p4(b.p3) {} |
|
117 |
|
|
118 |
|
|
116 |
p3(conv(b.p2,b.p3,1.0/3.0)), p4(b.p3) {} |
|
117 |
|
|
118 |
Point operator()(double t) const |
|
119 | 119 |
{ |
120 | 120 |
// return Bezier2(conv(p1,p2,t),conv(p2,p3,t),conv(p3,p4,t))(t); |
121 | 121 |
return ((1-t)*(1-t)*(1-t))*p1+(3*t*(1-t)*(1-t))*p2+ |
122 |
|
|
122 |
(3*t*t*(1-t))*p3+(t*t*t)*p4; |
|
123 | 123 |
} |
124 | 124 |
Bezier3 before(double t) const |
125 | 125 |
{ |
... | ... |
@@ -131,7 +131,7 @@ |
131 | 131 |
Point c(conv(a,b,t)); |
132 | 132 |
return Bezier3(p1,p,a,c); |
133 | 133 |
} |
134 |
|
|
134 |
|
|
135 | 135 |
Bezier3 after(double t) const |
136 | 136 |
{ |
137 | 137 |
Point p(conv(p1,p2,t)); |
... | ... |
@@ -146,13 +146,13 @@ |
146 | 146 |
Bezier3 operator()(double a,double b) const { return before(b).after(a/b); } |
147 | 147 |
Bezier2 grad() const { return Bezier2(3.0*(p2-p1),3.0*(p3-p2),3.0*(p4-p3)); } |
148 | 148 |
Bezier2 norm() const { return Bezier2(3.0*rot90(p2-p1), |
149 |
3.0*rot90(p3-p2), |
|
150 |
3.0*rot90(p4-p3)); } |
|
149 |
3.0*rot90(p3-p2), |
|
150 |
3.0*rot90(p4-p3)); } |
|
151 | 151 |
Point grad(double t) const { return grad()(t); } |
152 | 152 |
Point norm(double t) const { return rot90(grad(t)); } |
153 | 153 |
|
154 | 154 |
template<class R,class F,class S,class D> |
155 |
R recSplit(F &_f,const S &_s,D _d) const |
|
155 |
R recSplit(F &_f,const S &_s,D _d) const |
|
156 | 156 |
{ |
157 | 157 |
const Point a=(p1+p2)/2; |
158 | 158 |
const Point b=(p2+p3)/2; |
... | ... |
@@ -164,7 +164,7 @@ |
164 | 164 |
R f2=_f(Bezier3(e,d,c,p4),_d); |
165 | 165 |
return _s(f1,f2); |
166 | 166 |
} |
167 |
|
|
167 |
|
|
168 | 168 |
}; |
169 | 169 |
|
170 | 170 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -29,8 +29,8 @@ |
29 | 29 |
///\brief Graph maps that construct and destruct their elements dynamically. |
30 | 30 |
|
31 | 31 |
namespace lemon { |
32 |
|
|
33 |
|
|
32 |
|
|
33 |
|
|
34 | 34 |
//#ifndef LEMON_USE_DEBUG_MAP |
35 | 35 |
|
36 | 36 |
template <typename _Graph, typename _Item, typename _Value> |
... | ... |
@@ -140,28 +140,28 @@ |
140 | 140 |
typedef VectorMap<_Graph, _Item, _Ptr*> Map; |
141 | 141 |
}; |
142 | 142 |
|
143 |
// #else |
|
143 |
// #else |
|
144 | 144 |
|
145 | 145 |
// template <typename _Graph, typename _Item, typename _Value> |
146 | 146 |
// struct DefaultMapSelector { |
147 | 147 |
// typedef DebugMap<_Graph, _Item, _Value> Map; |
148 | 148 |
// }; |
149 | 149 |
|
150 |
// #endif |
|
150 |
// #endif |
|
151 | 151 |
|
152 | 152 |
/// \e |
153 | 153 |
template <typename _Graph, typename _Item, typename _Value> |
154 |
class DefaultMap |
|
154 |
class DefaultMap |
|
155 | 155 |
: public DefaultMapSelector<_Graph, _Item, _Value>::Map { |
156 | 156 |
public: |
157 | 157 |
typedef typename DefaultMapSelector<_Graph, _Item, _Value>::Map Parent; |
158 | 158 |
typedef DefaultMap<_Graph, _Item, _Value> Map; |
159 |
|
|
159 |
|
|
160 | 160 |
typedef typename Parent::Graph Graph; |
161 | 161 |
typedef typename Parent::Value Value; |
162 | 162 |
|
163 | 163 |
explicit DefaultMap(const Graph& graph) : Parent(graph) {} |
164 |
DefaultMap(const Graph& graph, const Value& value) |
|
164 |
DefaultMap(const Graph& graph, const Value& value) |
|
165 | 165 |
: Parent(graph, value) {} |
166 | 166 |
|
167 | 167 |
DefaultMap& operator=(const DefaultMap& cmap) { |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -66,11 +66,11 @@ |
66 | 66 |
|
67 | 67 |
Node oppositeNode(const Node &node, const Arc &arc) const { |
68 | 68 |
if (node == Parent::source(arc)) |
69 |
|
|
69 |
return Parent::target(arc); |
|
70 | 70 |
else if(node == Parent::target(arc)) |
71 |
|
|
71 |
return Parent::source(arc); |
|
72 | 72 |
else |
73 |
|
|
73 |
return INVALID; |
|
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
// Alterable extension |
... | ... |
@@ -89,12 +89,12 @@ |
89 | 89 |
NodeNotifier& notifier(Node) const { |
90 | 90 |
return node_notifier; |
91 | 91 |
} |
92 |
|
|
92 |
|
|
93 | 93 |
ArcNotifier& notifier(Arc) const { |
94 | 94 |
return arc_notifier; |
95 | 95 |
} |
96 | 96 |
|
97 |
class NodeIt : public Node { |
|
97 |
class NodeIt : public Node { |
|
98 | 98 |
const Digraph* _digraph; |
99 | 99 |
public: |
100 | 100 |
|
... | ... |
@@ -103,21 +103,21 @@ |
103 | 103 |
NodeIt(Invalid i) : Node(i) { } |
104 | 104 |
|
105 | 105 |
explicit NodeIt(const Digraph& digraph) : _digraph(&digraph) { |
106 |
|
|
106 |
_digraph->first(static_cast<Node&>(*this)); |
|
107 | 107 |
} |
108 | 108 |
|
109 |
NodeIt(const Digraph& digraph, const Node& node) |
|
110 |
: Node(node), _digraph(&digraph) {} |
|
109 |
NodeIt(const Digraph& digraph, const Node& node) |
|
110 |
: Node(node), _digraph(&digraph) {} |
|
111 | 111 |
|
112 |
NodeIt& operator++() { |
|
113 |
_digraph->next(*this); |
|
114 |
|
|
112 |
NodeIt& operator++() { |
|
113 |
_digraph->next(*this); |
|
114 |
return *this; |
|
115 | 115 |
} |
116 | 116 |
|
117 | 117 |
}; |
118 | 118 |
|
119 | 119 |
|
120 |
class ArcIt : public Arc { |
|
120 |
class ArcIt : public Arc { |
|
121 | 121 |
const Digraph* _digraph; |
122 | 122 |
public: |
123 | 123 |
|
... | ... |
@@ -126,21 +126,21 @@ |
126 | 126 |
ArcIt(Invalid i) : Arc(i) { } |
127 | 127 |
|
128 | 128 |
explicit ArcIt(const Digraph& digraph) : _digraph(&digraph) { |
129 |
|
|
129 |
_digraph->first(static_cast<Arc&>(*this)); |
|
130 | 130 |
} |
131 | 131 |
|
132 |
ArcIt(const Digraph& digraph, const Arc& arc) : |
|
133 |
Arc(arc), _digraph(&digraph) { } |
|
132 |
ArcIt(const Digraph& digraph, const Arc& arc) : |
|
133 |
Arc(arc), _digraph(&digraph) { } |
|
134 | 134 |
|
135 |
ArcIt& operator++() { |
|
136 |
_digraph->next(*this); |
|
137 |
|
|
135 |
ArcIt& operator++() { |
|
136 |
_digraph->next(*this); |
|
137 |
return *this; |
|
138 | 138 |
} |
139 | 139 |
|
140 | 140 |
}; |
141 | 141 |
|
142 | 142 |
|
143 |
class OutArcIt : public Arc { |
|
143 |
class OutArcIt : public Arc { |
|
144 | 144 |
const Digraph* _digraph; |
145 | 145 |
public: |
146 | 146 |
|
... | ... |
@@ -148,23 +148,23 @@ |
148 | 148 |
|
149 | 149 |
OutArcIt(Invalid i) : Arc(i) { } |
150 | 150 |
|
151 |
OutArcIt(const Digraph& digraph, const Node& node) |
|
152 |
: _digraph(&digraph) { |
|
153 |
|
|
151 |
OutArcIt(const Digraph& digraph, const Node& node) |
|
152 |
: _digraph(&digraph) { |
|
153 |
_digraph->firstOut(*this, node); |
|
154 | 154 |
} |
155 | 155 |
|
156 |
OutArcIt(const Digraph& digraph, const Arc& arc) |
|
157 |
: Arc(arc), _digraph(&digraph) {} |
|
156 |
OutArcIt(const Digraph& digraph, const Arc& arc) |
|
157 |
: Arc(arc), _digraph(&digraph) {} |
|
158 | 158 |
|
159 |
OutArcIt& operator++() { |
|
160 |
_digraph->nextOut(*this); |
|
161 |
|
|
159 |
OutArcIt& operator++() { |
|
160 |
_digraph->nextOut(*this); |
|
161 |
return *this; |
|
162 | 162 |
} |
163 | 163 |
|
164 | 164 |
}; |
165 | 165 |
|
166 | 166 |
|
167 |
class InArcIt : public Arc { |
|
167 |
class InArcIt : public Arc { |
|
168 | 168 |
const Digraph* _digraph; |
169 | 169 |
public: |
170 | 170 |
|
... | ... |
@@ -172,17 +172,17 @@ |
172 | 172 |
|
173 | 173 |
InArcIt(Invalid i) : Arc(i) { } |
174 | 174 |
|
175 |
InArcIt(const Digraph& digraph, const Node& node) |
|
176 |
: _digraph(&digraph) { |
|
177 |
|
|
175 |
InArcIt(const Digraph& digraph, const Node& node) |
|
176 |
: _digraph(&digraph) { |
|
177 |
_digraph->firstIn(*this, node); |
|
178 | 178 |
} |
179 | 179 |
|
180 |
InArcIt(const Digraph& digraph, const Arc& arc) : |
|
181 |
Arc(arc), _digraph(&digraph) {} |
|
180 |
InArcIt(const Digraph& digraph, const Arc& arc) : |
|
181 |
Arc(arc), _digraph(&digraph) {} |
|
182 | 182 |
|
183 |
InArcIt& operator++() { |
|
184 |
_digraph->nextIn(*this); |
|
185 |
|
|
183 |
InArcIt& operator++() { |
|
184 |
_digraph->nextIn(*this); |
|
185 |
return *this; |
|
186 | 186 |
} |
187 | 187 |
|
188 | 188 |
}; |
... | ... |
@@ -215,51 +215,51 @@ |
215 | 215 |
return Parent::source(arc); |
216 | 216 |
} |
217 | 217 |
|
218 |
|
|
218 |
|
|
219 | 219 |
template <typename _Value> |
220 |
class NodeMap |
|
220 |
class NodeMap |
|
221 | 221 |
: public MapExtender<DefaultMap<Digraph, Node, _Value> > { |
222 | 222 |
public: |
223 | 223 |
typedef DigraphExtender Digraph; |
224 | 224 |
typedef MapExtender<DefaultMap<Digraph, Node, _Value> > Parent; |
225 | 225 |
|
226 |
explicit NodeMap(const Digraph& digraph) |
|
227 |
: Parent(digraph) {} |
|
228 |
NodeMap(const Digraph& digraph, const _Value& value) |
|
229 |
: Parent(digraph, value) {} |
|
226 |
explicit NodeMap(const Digraph& digraph) |
|
227 |
: Parent(digraph) {} |
|
228 |
NodeMap(const Digraph& digraph, const _Value& value) |
|
229 |
: Parent(digraph, value) {} |
|
230 | 230 |
|
231 | 231 |
NodeMap& operator=(const NodeMap& cmap) { |
232 |
|
|
232 |
return operator=<NodeMap>(cmap); |
|
233 | 233 |
} |
234 | 234 |
|
235 | 235 |
template <typename CMap> |
236 | 236 |
NodeMap& operator=(const CMap& cmap) { |
237 | 237 |
Parent::operator=(cmap); |
238 |
|
|
238 |
return *this; |
|
239 | 239 |
} |
240 | 240 |
|
241 | 241 |
}; |
242 | 242 |
|
243 | 243 |
template <typename _Value> |
244 |
class ArcMap |
|
244 |
class ArcMap |
|
245 | 245 |
: public MapExtender<DefaultMap<Digraph, Arc, _Value> > { |
246 | 246 |
public: |
247 | 247 |
typedef DigraphExtender Digraph; |
248 | 248 |
typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent; |
249 | 249 |
|
250 |
explicit ArcMap(const Digraph& digraph) |
|
251 |
: Parent(digraph) {} |
|
252 |
ArcMap(const Digraph& digraph, const _Value& value) |
|
253 |
: Parent(digraph, value) {} |
|
250 |
explicit ArcMap(const Digraph& digraph) |
|
251 |
: Parent(digraph) {} |
|
252 |
ArcMap(const Digraph& digraph, const _Value& value) |
|
253 |
: Parent(digraph, value) {} |
|
254 | 254 |
|
255 | 255 |
ArcMap& operator=(const ArcMap& cmap) { |
256 |
|
|
256 |
return operator=<ArcMap>(cmap); |
|
257 | 257 |
} |
258 | 258 |
|
259 | 259 |
template <typename CMap> |
260 | 260 |
ArcMap& operator=(const CMap& cmap) { |
261 | 261 |
Parent::operator=(cmap); |
262 |
|
|
262 |
return *this; |
|
263 | 263 |
} |
264 | 264 |
}; |
265 | 265 |
|
... | ... |
@@ -269,7 +269,7 @@ |
269 | 269 |
notifier(Node()).add(node); |
270 | 270 |
return node; |
271 | 271 |
} |
272 |
|
|
272 |
|
|
273 | 273 |
Arc addArc(const Node& from, const Node& to) { |
274 | 274 |
Arc arc = Parent::addArc(from, to); |
275 | 275 |
notifier(Arc()).add(arc); |
... | ... |
@@ -293,20 +293,20 @@ |
293 | 293 |
Arc arc; |
294 | 294 |
Parent::firstOut(arc, node); |
295 | 295 |
while (arc != INVALID ) { |
296 |
erase(arc); |
|
297 |
Parent::firstOut(arc, node); |
|
298 |
|
|
296 |
erase(arc); |
|
297 |
Parent::firstOut(arc, node); |
|
298 |
} |
|
299 | 299 |
|
300 | 300 |
Parent::firstIn(arc, node); |
301 | 301 |
while (arc != INVALID ) { |
302 |
erase(arc); |
|
303 |
Parent::firstIn(arc, node); |
|
302 |
erase(arc); |
|
303 |
Parent::firstIn(arc, node); |
|
304 | 304 |
} |
305 | 305 |
|
306 | 306 |
notifier(Node()).erase(node); |
307 | 307 |
Parent::erase(node); |
308 | 308 |
} |
309 |
|
|
309 |
|
|
310 | 310 |
void erase(const Arc& arc) { |
311 | 311 |
notifier(Arc()).erase(arc); |
312 | 312 |
Parent::erase(arc); |
... | ... |
@@ -315,8 +315,8 @@ |
315 | 315 |
DigraphExtender() { |
316 | 316 |
node_notifier.setContainer(*this); |
317 | 317 |
arc_notifier.setContainer(*this); |
318 |
} |
|
319 |
|
|
318 |
} |
|
319 |
|
|
320 | 320 |
|
321 | 321 |
~DigraphExtender() { |
322 | 322 |
arc_notifier.clear(); |
... | ... |
@@ -327,10 +327,10 @@ |
327 | 327 |
/// \ingroup _graphbits |
328 | 328 |
/// |
329 | 329 |
/// \brief Extender for the Graphs |
330 |
template <typename Base> |
|
330 |
template <typename Base> |
|
331 | 331 |
class GraphExtender : public Base { |
332 | 332 |
public: |
333 |
|
|
333 |
|
|
334 | 334 |
typedef Base Parent; |
335 | 335 |
typedef GraphExtender Graph; |
336 | 336 |
|
... | ... |
@@ -340,7 +340,7 @@ |
340 | 340 |
typedef typename Parent::Arc Arc; |
341 | 341 |
typedef typename Parent::Edge Edge; |
342 | 342 |
|
343 |
// Graph extension |
|
343 |
// Graph extension |
|
344 | 344 |
|
345 | 345 |
int maxId(Node) const { |
346 | 346 |
return Parent::maxNodeId(); |
... | ... |
@@ -368,11 +368,11 @@ |
368 | 368 |
|
369 | 369 |
Node oppositeNode(const Node &n, const Edge &e) const { |
370 | 370 |
if( n == Parent::u(e)) |
371 |
|
|
371 |
return Parent::v(e); |
|
372 | 372 |
else if( n == Parent::v(e)) |
373 |
|
|
373 |
return Parent::u(e); |
|
374 | 374 |
else |
375 |
|
|
375 |
return INVALID; |
|
376 | 376 |
} |
377 | 377 |
|
378 | 378 |
Arc oppositeArc(const Arc &arc) const { |
... | ... |
@@ -402,7 +402,7 @@ |
402 | 402 |
NodeNotifier& notifier(Node) const { |
403 | 403 |
return node_notifier; |
404 | 404 |
} |
405 |
|
|
405 |
|
|
406 | 406 |
ArcNotifier& notifier(Arc) const { |
407 | 407 |
return arc_notifier; |
408 | 408 |
} |
... | ... |
@@ -413,7 +413,7 @@ |
413 | 413 |
|
414 | 414 |
|
415 | 415 |
|
416 |
class NodeIt : public Node { |
|
416 |
class NodeIt : public Node { |
|
417 | 417 |
const Graph* _graph; |
418 | 418 |
public: |
419 | 419 |
|
... | ... |
@@ -422,21 +422,21 @@ |
422 | 422 |
NodeIt(Invalid i) : Node(i) { } |
423 | 423 |
|
424 | 424 |
explicit NodeIt(const Graph& graph) : _graph(&graph) { |
425 |
|
|
425 |
_graph->first(static_cast<Node&>(*this)); |
|
426 | 426 |
} |
427 | 427 |
|
428 |
NodeIt(const Graph& graph, const Node& node) |
|
429 |
: Node(node), _graph(&graph) {} |
|
428 |
NodeIt(const Graph& graph, const Node& node) |
|
429 |
: Node(node), _graph(&graph) {} |
|
430 | 430 |
|
431 |
NodeIt& operator++() { |
|
432 |
_graph->next(*this); |
|
433 |
|
|
431 |
NodeIt& operator++() { |
|
432 |
_graph->next(*this); |
|
433 |
return *this; |
|
434 | 434 |
} |
435 | 435 |
|
436 | 436 |
}; |
437 | 437 |
|
438 | 438 |
|
439 |
class ArcIt : public Arc { |
|
439 |
class ArcIt : public Arc { |
|
440 | 440 |
const Graph* _graph; |
441 | 441 |
public: |
442 | 442 |
|
... | ... |
@@ -445,21 +445,21 @@ |
445 | 445 |
ArcIt(Invalid i) : Arc(i) { } |
446 | 446 |
|
447 | 447 |
explicit ArcIt(const Graph& graph) : _graph(&graph) { |
448 |
|
|
448 |
_graph->first(static_cast<Arc&>(*this)); |
|
449 | 449 |
} |
450 | 450 |
|
451 |
ArcIt(const Graph& graph, const Arc& arc) : |
|
452 |
Arc(arc), _graph(&graph) { } |
|
451 |
ArcIt(const Graph& graph, const Arc& arc) : |
|
452 |
Arc(arc), _graph(&graph) { } |
|
453 | 453 |
|
454 |
ArcIt& operator++() { |
|
455 |
_graph->next(*this); |
|
456 |
|
|
454 |
ArcIt& operator++() { |
|
455 |
_graph->next(*this); |
|
456 |
return *this; |
|
457 | 457 |
} |
458 | 458 |
|
459 | 459 |
}; |
460 | 460 |
|
461 | 461 |
|
462 |
class OutArcIt : public Arc { |
|
462 |
class OutArcIt : public Arc { |
|
463 | 463 |
const Graph* _graph; |
464 | 464 |
public: |
465 | 465 |
|
... | ... |
@@ -467,23 +467,23 @@ |
467 | 467 |
|
468 | 468 |
OutArcIt(Invalid i) : Arc(i) { } |
469 | 469 |
|
470 |
OutArcIt(const Graph& graph, const Node& node) |
|
471 |
: _graph(&graph) { |
|
472 |
|
|
470 |
OutArcIt(const Graph& graph, const Node& node) |
|
471 |
: _graph(&graph) { |
|
472 |
_graph->firstOut(*this, node); |
|
473 | 473 |
} |
474 | 474 |
|
475 |
OutArcIt(const Graph& graph, const Arc& arc) |
|
476 |
: Arc(arc), _graph(&graph) {} |
|
475 |
OutArcIt(const Graph& graph, const Arc& arc) |
|
476 |
: Arc(arc), _graph(&graph) {} |
|
477 | 477 |
|
478 |
OutArcIt& operator++() { |
|
479 |
_graph->nextOut(*this); |
|
480 |
|
|
478 |
OutArcIt& operator++() { |
|
479 |
_graph->nextOut(*this); |
|
480 |
return *this; |
|
481 | 481 |
} |
482 | 482 |
|
483 | 483 |
}; |
484 | 484 |
|
485 | 485 |
|
486 |
class InArcIt : public Arc { |
|
486 |
class InArcIt : public Arc { |
|
487 | 487 |
const Graph* _graph; |
488 | 488 |
public: |
489 | 489 |
|
... | ... |
@@ -491,23 +491,23 @@ |
491 | 491 |
|
492 | 492 |
InArcIt(Invalid i) : Arc(i) { } |
493 | 493 |
|
494 |
InArcIt(const Graph& graph, const Node& node) |
|
495 |
: _graph(&graph) { |
|
496 |
|
|
494 |
InArcIt(const Graph& graph, const Node& node) |
|
495 |
: _graph(&graph) { |
|
496 |
_graph->firstIn(*this, node); |
|
497 | 497 |
} |
498 | 498 |
|
499 |
InArcIt(const Graph& graph, const Arc& arc) : |
|
500 |
Arc(arc), _graph(&graph) {} |
|
499 |
InArcIt(const Graph& graph, const Arc& arc) : |
|
500 |
Arc(arc), _graph(&graph) {} |
|
501 | 501 |
|
502 |
InArcIt& operator++() { |
|
503 |
_graph->nextIn(*this); |
|
504 |
|
|
502 |
InArcIt& operator++() { |
|
503 |
_graph->nextIn(*this); |
|
504 |
return *this; |
|
505 | 505 |
} |
506 | 506 |
|
507 | 507 |
}; |
508 | 508 |
|
509 | 509 |
|
510 |
class EdgeIt : public Parent::Edge { |
|
510 |
class EdgeIt : public Parent::Edge { |
|
511 | 511 |
const Graph* _graph; |
512 | 512 |
public: |
513 | 513 |
|
... | ... |
@@ -516,15 +516,15 @@ |
516 | 516 |
EdgeIt(Invalid i) : Edge(i) { } |
517 | 517 |
|
518 | 518 |
explicit EdgeIt(const Graph& graph) : _graph(&graph) { |
519 |
|
|
519 |
_graph->first(static_cast<Edge&>(*this)); |
|
520 | 520 |
} |
521 | 521 |
|
522 |
EdgeIt(const Graph& graph, const Edge& edge) : |
|
523 |
Edge(edge), _graph(&graph) { } |
|
522 |
EdgeIt(const Graph& graph, const Edge& edge) : |
|
523 |
Edge(edge), _graph(&graph) { } |
|
524 | 524 |
|
525 |
EdgeIt& operator++() { |
|
526 |
_graph->next(*this); |
|
527 |
|
|
525 |
EdgeIt& operator++() { |
|
526 |
_graph->next(*this); |
|
527 |
return *this; |
|
528 | 528 |
} |
529 | 529 |
|
530 | 530 |
}; |
... | ... |
@@ -540,17 +540,17 @@ |
540 | 540 |
IncEdgeIt(Invalid i) : Edge(i), _direction(false) { } |
541 | 541 |
|
542 | 542 |
IncEdgeIt(const Graph& graph, const Node &node) : _graph(&graph) { |
543 |
|
|
543 |
_graph->firstInc(*this, _direction, node); |
|
544 | 544 |
} |
545 | 545 |
|
546 | 546 |
IncEdgeIt(const Graph& graph, const Edge &edge, const Node &node) |
547 |
: _graph(&graph), Edge(edge) { |
|
548 |
_direction = (_graph->source(edge) == node); |
|
547 |
: _graph(&graph), Edge(edge) { |
|
548 |
_direction = (_graph->source(edge) == node); |
|
549 | 549 |
} |
550 | 550 |
|
551 | 551 |
IncEdgeIt& operator++() { |
552 |
_graph->nextInc(*this, _direction); |
|
553 |
return *this; |
|
552 |
_graph->nextInc(*this, _direction); |
|
553 |
return *this; |
|
554 | 554 |
} |
555 | 555 |
}; |
556 | 556 |
|
... | ... |
@@ -598,74 +598,74 @@ |
598 | 598 |
// Mappable extension |
599 | 599 |
|
600 | 600 |
template <typename _Value> |
601 |
class NodeMap |
|
601 |
class NodeMap |
|
602 | 602 |
: public MapExtender<DefaultMap<Graph, Node, _Value> > { |
603 | 603 |
public: |
604 | 604 |
typedef GraphExtender Graph; |
605 | 605 |
typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent; |
606 | 606 |
|
607 |
NodeMap(const Graph& graph) |
|
608 |
: Parent(graph) {} |
|
609 |
NodeMap(const Graph& graph, const _Value& value) |
|
610 |
: Parent(graph, value) {} |
|
607 |
NodeMap(const Graph& graph) |
|
608 |
: Parent(graph) {} |
|
609 |
NodeMap(const Graph& graph, const _Value& value) |
|
610 |
: Parent(graph, value) {} |
|
611 | 611 |
|
612 | 612 |
NodeMap& operator=(const NodeMap& cmap) { |
613 |
|
|
613 |
return operator=<NodeMap>(cmap); |
|
614 | 614 |
} |
615 | 615 |
|
616 | 616 |
template <typename CMap> |
617 | 617 |
NodeMap& operator=(const CMap& cmap) { |
618 | 618 |
Parent::operator=(cmap); |
619 |
|
|
619 |
return *this; |
|
620 | 620 |
} |
621 | 621 |
|
622 | 622 |
}; |
623 | 623 |
|
624 | 624 |
template <typename _Value> |
625 |
class ArcMap |
|
625 |
class ArcMap |
|
626 | 626 |
: public MapExtender<DefaultMap<Graph, Arc, _Value> > { |
627 | 627 |
public: |
628 | 628 |
typedef GraphExtender Graph; |
629 | 629 |
typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent; |
630 | 630 |
|
631 |
ArcMap(const Graph& graph) |
|
632 |
: Parent(graph) {} |
|
633 |
ArcMap(const Graph& graph, const _Value& value) |
|
634 |
: Parent(graph, value) {} |
|
631 |
ArcMap(const Graph& graph) |
|
632 |
: Parent(graph) {} |
|
633 |
ArcMap(const Graph& graph, const _Value& value) |
|
634 |
: Parent(graph, value) {} |
|
635 | 635 |
|
636 | 636 |
ArcMap& operator=(const ArcMap& cmap) { |
637 |
|
|
637 |
return operator=<ArcMap>(cmap); |
|
638 | 638 |
} |
639 | 639 |
|
640 | 640 |
template <typename CMap> |
641 | 641 |
ArcMap& operator=(const CMap& cmap) { |
642 | 642 |
Parent::operator=(cmap); |
643 |
|
|
643 |
return *this; |
|
644 | 644 |
} |
645 | 645 |
}; |
646 | 646 |
|
647 | 647 |
|
648 | 648 |
template <typename _Value> |
649 |
class EdgeMap |
|
649 |
class EdgeMap |
|
650 | 650 |
: public MapExtender<DefaultMap<Graph, Edge, _Value> > { |
651 | 651 |
public: |
652 | 652 |
typedef GraphExtender Graph; |
653 | 653 |
typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent; |
654 | 654 |
|
655 |
EdgeMap(const Graph& graph) |
|
656 |
: Parent(graph) {} |
|
655 |
EdgeMap(const Graph& graph) |
|
656 |
: Parent(graph) {} |
|
657 | 657 |
|
658 |
EdgeMap(const Graph& graph, const _Value& value) |
|
659 |
: Parent(graph, value) {} |
|
658 |
EdgeMap(const Graph& graph, const _Value& value) |
|
659 |
: Parent(graph, value) {} |
|
660 | 660 |
|
661 | 661 |
EdgeMap& operator=(const EdgeMap& cmap) { |
662 |
|
|
662 |
return operator=<EdgeMap>(cmap); |
|
663 | 663 |
} |
664 | 664 |
|
665 | 665 |
template <typename CMap> |
666 | 666 |
EdgeMap& operator=(const CMap& cmap) { |
667 | 667 |
Parent::operator=(cmap); |
668 |
|
|
668 |
return *this; |
|
669 | 669 |
} |
670 | 670 |
|
671 | 671 |
}; |
... | ... |
@@ -683,11 +683,11 @@ |
683 | 683 |
notifier(Edge()).add(edge); |
684 | 684 |
std::vector<Arc> ev; |
685 | 685 |
ev.push_back(Parent::direct(edge, true)); |
686 |
ev.push_back(Parent::direct(edge, false)); |
|
686 |
ev.push_back(Parent::direct(edge, false)); |
|
687 | 687 |
notifier(Arc()).add(ev); |
688 | 688 |
return edge; |
689 | 689 |
} |
690 |
|
|
690 |
|
|
691 | 691 |
void clear() { |
692 | 692 |
notifier(Arc()).clear(); |
693 | 693 |
notifier(Edge()).clear(); |
... | ... |
@@ -696,7 +696,7 @@ |
696 | 696 |
} |
697 | 697 |
|
698 | 698 |
template <typename Graph, typename NodeRefMap, typename EdgeRefMap> |
699 |
void build(const Graph& graph, NodeRefMap& nodeRef, |
|
699 |
void build(const Graph& graph, NodeRefMap& nodeRef, |
|
700 | 700 |
EdgeRefMap& edgeRef) { |
701 | 701 |
Parent::build(graph, nodeRef, edgeRef); |
702 | 702 |
notifier(Node()).build(); |
... | ... |
@@ -708,14 +708,14 @@ |
708 | 708 |
Arc arc; |
709 | 709 |
Parent::firstOut(arc, node); |
710 | 710 |
while (arc != INVALID ) { |
711 |
erase(arc); |
|
712 |
Parent::firstOut(arc, node); |
|
713 |
|
|
711 |
erase(arc); |
|
712 |
Parent::firstOut(arc, node); |
|
713 |
} |
|
714 | 714 |
|
715 | 715 |
Parent::firstIn(arc, node); |
716 | 716 |
while (arc != INVALID ) { |
717 |
erase(arc); |
|
718 |
Parent::firstIn(arc, node); |
|
717 |
erase(arc); |
|
718 |
Parent::firstIn(arc, node); |
|
719 | 719 |
} |
720 | 720 |
|
721 | 721 |
notifier(Node()).erase(node); |
... | ... |
@@ -725,23 +725,23 @@ |
725 | 725 |
void erase(const Edge& edge) { |
726 | 726 |
std::vector<Arc> av; |
727 | 727 |
av.push_back(Parent::direct(edge, true)); |
728 |
av.push_back(Parent::direct(edge, false)); |
|
728 |
av.push_back(Parent::direct(edge, false)); |
|
729 | 729 |
notifier(Arc()).erase(av); |
730 | 730 |
notifier(Edge()).erase(edge); |
731 | 731 |
Parent::erase(edge); |
732 | 732 |
} |
733 | 733 |
|
734 | 734 |
GraphExtender() { |
735 |
node_notifier.setContainer(*this); |
|
735 |
node_notifier.setContainer(*this); |
|
736 | 736 |
arc_notifier.setContainer(*this); |
737 | 737 |
edge_notifier.setContainer(*this); |
738 |
} |
|
738 |
} |
|
739 | 739 |
|
740 | 740 |
~GraphExtender() { |
741 | 741 |
edge_notifier.clear(); |
742 | 742 |
arc_notifier.clear(); |
743 |
node_notifier.clear(); |
|
744 |
} |
|
743 |
node_notifier.clear(); |
|
744 |
} |
|
745 | 745 |
|
746 | 746 |
}; |
747 | 747 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -34,7 +34,7 @@ |
34 | 34 |
bool operator!=(Invalid) { return false; } |
35 | 35 |
bool operator< (Invalid) { return false; } |
36 | 36 |
}; |
37 |
|
|
37 |
|
|
38 | 38 |
/// \brief Invalid iterators. |
39 | 39 |
/// |
40 | 40 |
/// \ref Invalid is a global type that converts to each iterator |
... | ... |
@@ -52,4 +52,4 @@ |
52 | 52 |
} //namespace lemon |
53 | 53 |
|
54 | 54 |
#endif |
55 |
|
|
55 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -32,7 +32,7 @@ |
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 { |
... | ... |
@@ -56,10 +56,10 @@ |
56 | 56 |
|
57 | 57 |
public: |
58 | 58 |
|
59 |
MapExtender(const Graph& graph) |
|
59 |
MapExtender(const Graph& graph) |
|
60 | 60 |
: Parent(graph) {} |
61 | 61 |
|
62 |
MapExtender(const Graph& graph, const Value& value) |
|
62 |
MapExtender(const Graph& graph, const Value& value) |
|
63 | 63 |
: Parent(graph, value) {} |
64 | 64 |
|
65 | 65 |
MapExtender& operator=(const MapExtender& cmap) { |
... | ... |
@@ -70,14 +70,14 @@ |
70 | 70 |
MapExtender& operator=(const CMap& cmap) { |
71 | 71 |
Parent::operator=(cmap); |
72 | 72 |
return *this; |
73 |
} |
|
73 |
} |
|
74 | 74 |
|
75 | 75 |
class MapIt : public Item { |
76 | 76 |
public: |
77 |
|
|
77 |
|
|
78 | 78 |
typedef Item Parent; |
79 | 79 |
typedef typename Map::Value Value; |
80 |
|
|
80 |
|
|
81 | 81 |
MapIt() {} |
82 | 82 |
|
83 | 83 |
MapIt(Invalid i) : Parent(i) { } |
... | ... |
@@ -86,29 +86,29 @@ |
86 | 86 |
map.notifier()->first(*this); |
87 | 87 |
} |
88 | 88 |
|
89 |
MapIt(const Map& _map, const Item& item) |
|
90 |
: Parent(item), map(_map) {} |
|
89 |
MapIt(const Map& _map, const Item& item) |
|
90 |
: Parent(item), map(_map) {} |
|
91 | 91 |
|
92 |
MapIt& operator++() { |
|
93 |
map.notifier()->next(*this); |
|
94 |
|
|
92 |
MapIt& operator++() { |
|
93 |
map.notifier()->next(*this); |
|
94 |
return *this; |
|
95 | 95 |
} |
96 |
|
|
96 |
|
|
97 | 97 |
typename MapTraits<Map>::ConstReturnValue operator*() const { |
98 |
|
|
98 |
return map[*this]; |
|
99 | 99 |
} |
100 | 100 |
|
101 | 101 |
typename MapTraits<Map>::ReturnValue operator*() { |
102 |
|
|
102 |
return map[*this]; |
|
103 | 103 |
} |
104 |
|
|
104 |
|
|
105 | 105 |
void set(const Value& value) { |
106 |
|
|
106 |
map.set(*this, value); |
|
107 | 107 |
} |
108 |
|
|
108 |
|
|
109 | 109 |
protected: |
110 | 110 |
Map& map; |
111 |
|
|
111 |
|
|
112 | 112 |
}; |
113 | 113 |
|
114 | 114 |
class ConstMapIt : public Item { |
... | ... |
@@ -117,7 +117,7 @@ |
117 | 117 |
typedef Item Parent; |
118 | 118 |
|
119 | 119 |
typedef typename Map::Value Value; |
120 |
|
|
120 |
|
|
121 | 121 |
ConstMapIt() {} |
122 | 122 |
|
123 | 123 |
ConstMapIt(Invalid i) : Parent(i) { } |
... | ... |
@@ -126,16 +126,16 @@ |
126 | 126 |
map.notifier()->first(*this); |
127 | 127 |
} |
128 | 128 |
|
129 |
ConstMapIt(const Map& _map, const Item& item) |
|
130 |
: Parent(item), map(_map) {} |
|
129 |
ConstMapIt(const Map& _map, const Item& item) |
|
130 |
: Parent(item), map(_map) {} |
|
131 | 131 |
|
132 |
ConstMapIt& operator++() { |
|
133 |
map.notifier()->next(*this); |
|
134 |
|
|
132 |
ConstMapIt& operator++() { |
|
133 |
map.notifier()->next(*this); |
|
134 |
return *this; |
|
135 | 135 |
} |
136 | 136 |
|
137 | 137 |
typename MapTraits<Map>::ConstReturnValue operator*() const { |
138 |
|
|
138 |
return map[*this]; |
|
139 | 139 |
} |
140 | 140 |
|
141 | 141 |
protected: |
... | ... |
@@ -144,9 +144,9 @@ |
144 | 144 |
|
145 | 145 |
class ItemIt : public Item { |
146 | 146 |
public: |
147 |
|
|
147 |
|
|
148 | 148 |
typedef Item Parent; |
149 |
|
|
149 |
|
|
150 | 150 |
ItemIt() {} |
151 | 151 |
|
152 | 152 |
ItemIt(Invalid i) : Parent(i) { } |
... | ... |
@@ -155,22 +155,22 @@ |
155 | 155 |
map.notifier()->first(*this); |
156 | 156 |
} |
157 | 157 |
|
158 |
ItemIt(const Map& _map, const Item& item) |
|
159 |
: Parent(item), map(_map) {} |
|
158 |
ItemIt(const Map& _map, const Item& item) |
|
159 |
: Parent(item), map(_map) {} |
|
160 | 160 |
|
161 |
ItemIt& operator++() { |
|
162 |
map.notifier()->next(*this); |
|
163 |
|
|
161 |
ItemIt& operator++() { |
|
162 |
map.notifier()->next(*this); |
|
163 |
return *this; |
|
164 | 164 |
} |
165 | 165 |
|
166 | 166 |
protected: |
167 | 167 |
const Map& map; |
168 |
|
|
168 |
|
|
169 | 169 |
}; |
170 | 170 |
}; |
171 | 171 |
|
172 | 172 |
/// \ingroup graphbits |
173 |
/// |
|
173 |
/// |
|
174 | 174 |
/// \brief Extender for maps which use a subset of the items. |
175 | 175 |
template <typename _Graph, typename _Map> |
176 | 176 |
class SubMapExtender : public _Map { |
... | ... |
@@ -194,10 +194,10 @@ |
194 | 194 |
|
195 | 195 |
public: |
196 | 196 |
|
197 |
SubMapExtender(const Graph& _graph) |
|
197 |
SubMapExtender(const Graph& _graph) |
|
198 | 198 |
: Parent(_graph), graph(_graph) {} |
199 | 199 |
|
200 |
SubMapExtender(const Graph& _graph, const Value& _value) |
|
200 |
SubMapExtender(const Graph& _graph, const Value& _value) |
|
201 | 201 |
: Parent(_graph, _value), graph(_graph) {} |
202 | 202 |
|
203 | 203 |
SubMapExtender& operator=(const SubMapExtender& cmap) { |
... | ... |
@@ -212,14 +212,14 @@ |
212 | 212 |
Parent::set(it, cmap[it]); |
213 | 213 |
} |
214 | 214 |
return *this; |
215 |
} |
|
215 |
} |
|
216 | 216 |
|
217 | 217 |
class MapIt : public Item { |
218 | 218 |
public: |
219 |
|
|
219 |
|
|
220 | 220 |
typedef Item Parent; |
221 | 221 |
typedef typename Map::Value Value; |
222 |
|
|
222 |
|
|
223 | 223 |
MapIt() {} |
224 | 224 |
|
225 | 225 |
MapIt(Invalid i) : Parent(i) { } |
... | ... |
@@ -228,29 +228,29 @@ |
228 | 228 |
map.graph.first(*this); |
229 | 229 |
} |
230 | 230 |
|
231 |
MapIt(const Map& _map, const Item& item) |
|
232 |
: Parent(item), map(_map) {} |
|
231 |
MapIt(const Map& _map, const Item& item) |
|
232 |
: Parent(item), map(_map) {} |
|
233 | 233 |
|
234 |
MapIt& operator++() { |
|
235 |
map.graph.next(*this); |
|
236 |
|
|
234 |
MapIt& operator++() { |
|
235 |
map.graph.next(*this); |
|
236 |
return *this; |
|
237 | 237 |
} |
238 |
|
|
238 |
|
|
239 | 239 |
typename MapTraits<Map>::ConstReturnValue operator*() const { |
240 |
|
|
240 |
return map[*this]; |
|
241 | 241 |
} |
242 | 242 |
|
243 | 243 |
typename MapTraits<Map>::ReturnValue operator*() { |
244 |
|
|
244 |
return map[*this]; |
|
245 | 245 |
} |
246 |
|
|
246 |
|
|
247 | 247 |
void set(const Value& value) { |
248 |
|
|
248 |
map.set(*this, value); |
|
249 | 249 |
} |
250 |
|
|
250 |
|
|
251 | 251 |
protected: |
252 | 252 |
Map& map; |
253 |
|
|
253 |
|
|
254 | 254 |
}; |
255 | 255 |
|
256 | 256 |
class ConstMapIt : public Item { |
... | ... |
@@ -259,7 +259,7 @@ |
259 | 259 |
typedef Item Parent; |
260 | 260 |
|
261 | 261 |
typedef typename Map::Value Value; |
262 |
|
|
262 |
|
|
263 | 263 |
ConstMapIt() {} |
264 | 264 |
|
265 | 265 |
ConstMapIt(Invalid i) : Parent(i) { } |
... | ... |
@@ -268,16 +268,16 @@ |
268 | 268 |
map.graph.first(*this); |
269 | 269 |
} |
270 | 270 |
|
271 |
ConstMapIt(const Map& _map, const Item& item) |
|
272 |
: Parent(item), map(_map) {} |
|
271 |
ConstMapIt(const Map& _map, const Item& item) |
|
272 |
: Parent(item), map(_map) {} |
|
273 | 273 |
|
274 |
ConstMapIt& operator++() { |
|
275 |
map.graph.next(*this); |
|
276 |
|
|
274 |
ConstMapIt& operator++() { |
|
275 |
map.graph.next(*this); |
|
276 |
return *this; |
|
277 | 277 |
} |
278 | 278 |
|
279 | 279 |
typename MapTraits<Map>::ConstReturnValue operator*() const { |
280 |
|
|
280 |
return map[*this]; |
|
281 | 281 |
} |
282 | 282 |
|
283 | 283 |
protected: |
... | ... |
@@ -286,9 +286,9 @@ |
286 | 286 |
|
287 | 287 |
class ItemIt : public Item { |
288 | 288 |
public: |
289 |
|
|
289 |
|
|
290 | 290 |
typedef Item Parent; |
291 |
|
|
291 |
|
|
292 | 292 |
ItemIt() {} |
293 | 293 |
|
294 | 294 |
ItemIt(Invalid i) : Parent(i) { } |
... | ... |
@@ -297,23 +297,23 @@ |
297 | 297 |
map.graph.first(*this); |
298 | 298 |
} |
299 | 299 |
|
300 |
ItemIt(const Map& _map, const Item& item) |
|
301 |
: Parent(item), map(_map) {} |
|
300 |
ItemIt(const Map& _map, const Item& item) |
|
301 |
: Parent(item), map(_map) {} |
|
302 | 302 |
|
303 |
ItemIt& operator++() { |
|
304 |
map.graph.next(*this); |
|
305 |
|
|
303 |
ItemIt& operator++() { |
|
304 |
map.graph.next(*this); |
|
305 |
return *this; |
|
306 | 306 |
} |
307 | 307 |
|
308 | 308 |
protected: |
309 | 309 |
const Map& map; |
310 |
|
|
310 |
|
|
311 | 311 |
}; |
312 |
|
|
312 |
|
|
313 | 313 |
private: |
314 | 314 |
|
315 | 315 |
const Graph& graph; |
316 |
|
|
316 |
|
|
317 | 317 |
}; |
318 | 318 |
|
319 | 319 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -53,7 +53,7 @@ |
53 | 53 |
public: |
54 | 54 |
RevArcIt() {} |
55 | 55 |
RevArcIt(Invalid) : path(0), current(INVALID) {} |
56 |
RevArcIt(const PredMapPath& _path) |
|
56 |
RevArcIt(const PredMapPath& _path) |
|
57 | 57 |
: path(&_path), current(_path.target) { |
58 | 58 |
if (path->predMap[current] == INVALID) current = INVALID; |
59 | 59 |
} |
... | ... |
@@ -68,18 +68,18 @@ |
68 | 68 |
return *this; |
69 | 69 |
} |
70 | 70 |
|
71 |
bool operator==(const RevArcIt& e) const { |
|
72 |
return current == e.current; |
|
71 |
bool operator==(const RevArcIt& e) const { |
|
72 |
return current == e.current; |
|
73 | 73 |
} |
74 | 74 |
|
75 | 75 |
bool operator!=(const RevArcIt& e) const { |
76 |
return current != e.current; |
|
76 |
return current != e.current; |
|
77 | 77 |
} |
78 | 78 |
|
79 |
bool operator<(const RevArcIt& e) const { |
|
80 |
return current < e.current; |
|
79 |
bool operator<(const RevArcIt& e) const { |
|
80 |
return current < e.current; |
|
81 | 81 |
} |
82 |
|
|
82 |
|
|
83 | 83 |
private: |
84 | 84 |
const PredMapPath* path; |
85 | 85 |
typename Digraph::Node current; |
... | ... |
@@ -101,11 +101,11 @@ |
101 | 101 |
typedef typename Digraph::Arc Arc; |
102 | 102 |
typedef _PredMatrixMap PredMatrixMap; |
103 | 103 |
|
104 |
PredMatrixMapPath(const Digraph& _digraph, |
|
104 |
PredMatrixMapPath(const Digraph& _digraph, |
|
105 | 105 |
const PredMatrixMap& _predMatrixMap, |
106 |
typename Digraph::Node _source, |
|
106 |
typename Digraph::Node _source, |
|
107 | 107 |
typename Digraph::Node _target) |
108 |
: digraph(_digraph), predMatrixMap(_predMatrixMap), |
|
108 |
: digraph(_digraph), predMatrixMap(_predMatrixMap), |
|
109 | 109 |
source(_source), target(_target) {} |
110 | 110 |
|
111 | 111 |
int length() const { |
... | ... |
@@ -127,9 +127,9 @@ |
127 | 127 |
public: |
128 | 128 |
RevArcIt() {} |
129 | 129 |
RevArcIt(Invalid) : path(0), current(INVALID) {} |
130 |
RevArcIt(const PredMatrixMapPath& _path) |
|
130 |
RevArcIt(const PredMatrixMapPath& _path) |
|
131 | 131 |
: path(&_path), current(_path.target) { |
132 |
if (path->predMatrixMap(path->source, current) == INVALID) |
|
132 |
if (path->predMatrixMap(path->source, current) == INVALID) |
|
133 | 133 |
current = INVALID; |
134 | 134 |
} |
135 | 135 |
|
... | ... |
@@ -138,25 +138,25 @@ |
138 | 138 |
} |
139 | 139 |
|
140 | 140 |
RevArcIt& operator++() { |
141 |
current = |
|
141 |
current = |
|
142 | 142 |
path->digraph.source(path->predMatrixMap(path->source, current)); |
143 |
if (path->predMatrixMap(path->source, current) == INVALID) |
|
143 |
if (path->predMatrixMap(path->source, current) == INVALID) |
|
144 | 144 |
current = INVALID; |
145 | 145 |
return *this; |
146 | 146 |
} |
147 | 147 |
|
148 |
bool operator==(const RevArcIt& e) const { |
|
149 |
return current == e.current; |
|
148 |
bool operator==(const RevArcIt& e) const { |
|
149 |
return current == e.current; |
|
150 | 150 |
} |
151 | 151 |
|
152 | 152 |
bool operator!=(const RevArcIt& e) const { |
153 |
return current != e.current; |
|
153 |
return current != e.current; |
|
154 | 154 |
} |
155 | 155 |
|
156 |
bool operator<(const RevArcIt& e) const { |
|
157 |
return current < e.current; |
|
156 |
bool operator<(const RevArcIt& e) const { |
|
157 |
return current < e.current; |
|
158 | 158 |
} |
159 |
|
|
159 |
|
|
160 | 160 |
private: |
161 | 161 |
const PredMatrixMapPath* path; |
162 | 162 |
typename Digraph::Node current; |
1 |
|
|
2 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
3 | 2 |
* |
4 |
* 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. |
|
5 | 4 |
* |
6 | 5 |
* Copyright (C) 2003-2008 |
7 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -29,7 +28,7 @@ |
29 | 28 |
namespace lemon { |
30 | 29 |
template <typename _Graph, typename _Item> |
31 | 30 |
class ItemSetTraits {}; |
32 |
|
|
31 |
|
|
33 | 32 |
|
34 | 33 |
template <typename Graph, typename Enable = void> |
35 | 34 |
struct NodeNotifierIndicator { |
... | ... |
@@ -37,16 +36,16 @@ |
37 | 36 |
}; |
38 | 37 |
template <typename Graph> |
39 | 38 |
struct NodeNotifierIndicator< |
40 |
Graph, |
|
39 |
Graph, |
|
41 | 40 |
typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type |
42 |
> { |
|
41 |
> { |
|
43 | 42 |
typedef typename Graph::NodeNotifier Type; |
44 | 43 |
}; |
45 | 44 |
|
46 | 45 |
template <typename _Graph> |
47 | 46 |
class ItemSetTraits<_Graph, typename _Graph::Node> { |
48 | 47 |
public: |
49 |
|
|
48 |
|
|
50 | 49 |
typedef _Graph Graph; |
51 | 50 |
|
52 | 51 |
typedef typename Graph::Node Item; |
... | ... |
@@ -57,13 +56,13 @@ |
57 | 56 |
template <typename _Value> |
58 | 57 |
class Map : public Graph::template NodeMap<_Value> { |
59 | 58 |
public: |
60 |
typedef typename Graph::template NodeMap<_Value> Parent; |
|
61 |
typedef typename Graph::template NodeMap<_Value> Type; |
|
59 |
typedef typename Graph::template NodeMap<_Value> Parent; |
|
60 |
typedef typename Graph::template NodeMap<_Value> Type; |
|
62 | 61 |
typedef typename Parent::Value Value; |
63 | 62 |
|
64 | 63 |
Map(const Graph& _digraph) : Parent(_digraph) {} |
65 |
Map(const Graph& _digraph, const Value& _value) |
|
66 |
: Parent(_digraph, _value) {} |
|
64 |
Map(const Graph& _digraph, const Value& _value) |
|
65 |
: Parent(_digraph, _value) {} |
|
67 | 66 |
|
68 | 67 |
}; |
69 | 68 |
|
... | ... |
@@ -75,16 +74,16 @@ |
75 | 74 |
}; |
76 | 75 |
template <typename Graph> |
77 | 76 |
struct ArcNotifierIndicator< |
78 |
Graph, |
|
77 |
Graph, |
|
79 | 78 |
typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type |
80 |
> { |
|
79 |
> { |
|
81 | 80 |
typedef typename Graph::ArcNotifier Type; |
82 | 81 |
}; |
83 | 82 |
|
84 | 83 |
template <typename _Graph> |
85 | 84 |
class ItemSetTraits<_Graph, typename _Graph::Arc> { |
86 | 85 |
public: |
87 |
|
|
86 |
|
|
88 | 87 |
typedef _Graph Graph; |
89 | 88 |
|
90 | 89 |
typedef typename Graph::Arc Item; |
... | ... |
@@ -95,13 +94,13 @@ |
95 | 94 |
template <typename _Value> |
96 | 95 |
class Map : public Graph::template ArcMap<_Value> { |
97 | 96 |
public: |
98 |
typedef typename Graph::template ArcMap<_Value> Parent; |
|
99 |
typedef typename Graph::template ArcMap<_Value> Type; |
|
97 |
typedef typename Graph::template ArcMap<_Value> Parent; |
|
98 |
typedef typename Graph::template ArcMap<_Value> Type; |
|
100 | 99 |
typedef typename Parent::Value Value; |
101 | 100 |
|
102 | 101 |
Map(const Graph& _digraph) : Parent(_digraph) {} |
103 |
Map(const Graph& _digraph, const Value& _value) |
|
104 |
: Parent(_digraph, _value) {} |
|
102 |
Map(const Graph& _digraph, const Value& _value) |
|
103 |
: Parent(_digraph, _value) {} |
|
105 | 104 |
}; |
106 | 105 |
|
107 | 106 |
}; |
... | ... |
@@ -112,16 +111,16 @@ |
112 | 111 |
}; |
113 | 112 |
template <typename Graph> |
114 | 113 |
struct EdgeNotifierIndicator< |
115 |
Graph, |
|
114 |
Graph, |
|
116 | 115 |
typename enable_if<typename Graph::EdgeNotifier::Notifier, void>::type |
117 |
> { |
|
116 |
> { |
|
118 | 117 |
typedef typename Graph::EdgeNotifier Type; |
119 | 118 |
}; |
120 | 119 |
|
121 | 120 |
template <typename _Graph> |
122 | 121 |
class ItemSetTraits<_Graph, typename _Graph::Edge> { |
123 | 122 |
public: |
124 |
|
|
123 |
|
|
125 | 124 |
typedef _Graph Graph; |
126 | 125 |
|
127 | 126 |
typedef typename Graph::Edge Item; |
... | ... |
@@ -132,13 +131,13 @@ |
132 | 131 |
template <typename _Value> |
133 | 132 |
class Map : public Graph::template EdgeMap<_Value> { |
134 | 133 |
public: |
135 |
typedef typename Graph::template EdgeMap<_Value> Parent; |
|
136 |
typedef typename Graph::template EdgeMap<_Value> Type; |
|
134 |
typedef typename Graph::template EdgeMap<_Value> Parent; |
|
135 |
typedef typename Graph::template EdgeMap<_Value> Type; |
|
137 | 136 |
typedef typename Parent::Value Value; |
138 | 137 |
|
139 | 138 |
Map(const Graph& _digraph) : Parent(_digraph) {} |
140 |
Map(const Graph& _digraph, const Value& _value) |
|
141 |
: Parent(_digraph, _value) {} |
|
139 |
Map(const Graph& _digraph, const Value& _value) |
|
140 |
: Parent(_digraph, _value) {} |
|
142 | 141 |
}; |
143 | 142 |
|
144 | 143 |
}; |
... | ... |
@@ -156,17 +155,17 @@ |
156 | 155 |
|
157 | 156 |
template <typename Map> |
158 | 157 |
struct MapTraits< |
159 |
Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > |
|
158 |
Map, typename enable_if<typename Map::ReferenceMapTag, void>::type > |
|
160 | 159 |
{ |
161 | 160 |
typedef True ReferenceMapTag; |
162 |
|
|
161 |
|
|
163 | 162 |
typedef typename Map::Key Key; |
164 | 163 |
typedef typename Map::Value Value; |
165 | 164 |
|
166 | 165 |
typedef typename Map::ConstReference ConstReturnValue; |
167 | 166 |
typedef typename Map::Reference ReturnValue; |
168 | 167 |
|
169 |
typedef typename Map::ConstReference ConstReference; |
|
168 |
typedef typename Map::ConstReference ConstReference; |
|
170 | 169 |
typedef typename Map::Reference Reference; |
171 | 170 |
}; |
172 | 171 |
|
... | ... |
@@ -184,11 +183,11 @@ |
184 | 183 |
|
185 | 184 |
template <typename MatrixMap> |
186 | 185 |
struct MatrixMapTraits< |
187 |
MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, |
|
188 |
void>::type > |
|
186 |
MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag, |
|
187 |
void>::type > |
|
189 | 188 |
{ |
190 | 189 |
typedef True ReferenceMapTag; |
191 |
|
|
190 |
|
|
192 | 191 |
typedef typename MatrixMap::FirstKey FirstKey; |
193 | 192 |
typedef typename MatrixMap::SecondKey SecondKey; |
194 | 193 |
typedef typename MatrixMap::Value Value; |
... | ... |
@@ -196,7 +195,7 @@ |
196 | 195 |
typedef typename MatrixMap::ConstReference ConstReturnValue; |
197 | 196 |
typedef typename MatrixMap::Reference ReturnValue; |
198 | 197 |
|
199 |
typedef typename MatrixMap::ConstReference ConstReference; |
|
198 |
typedef typename MatrixMap::ConstReference ConstReference; |
|
200 | 199 |
typedef typename MatrixMap::Reference Reference; |
201 | 200 |
}; |
202 | 201 |
|
... | ... |
@@ -209,7 +208,7 @@ |
209 | 208 |
|
210 | 209 |
template <typename Graph> |
211 | 210 |
struct NodeNumTagIndicator< |
212 |
Graph, |
|
211 |
Graph, |
|
213 | 212 |
typename enable_if<typename Graph::NodeNumTag, void>::type |
214 | 213 |
> { |
215 | 214 |
static const bool value = true; |
... | ... |
@@ -222,7 +221,7 @@ |
222 | 221 |
|
223 | 222 |
template <typename Graph> |
224 | 223 |
struct EdgeNumTagIndicator< |
225 |
Graph, |
|
224 |
Graph, |
|
226 | 225 |
typename enable_if<typename Graph::EdgeNumTag, void>::type |
227 | 226 |
> { |
228 | 227 |
static const bool value = true; |
... | ... |
@@ -235,7 +234,7 @@ |
235 | 234 |
|
236 | 235 |
template <typename Graph> |
237 | 236 |
struct FindEdgeTagIndicator< |
238 |
Graph, |
|
237 |
Graph, |
|
239 | 238 |
typename enable_if<typename Graph::FindEdgeTag, void>::type |
240 | 239 |
> { |
241 | 240 |
static const bool value = true; |
... | ... |
@@ -248,7 +247,7 @@ |
248 | 247 |
|
249 | 248 |
template <typename Graph> |
250 | 249 |
struct UndirectedTagIndicator< |
251 |
Graph, |
|
250 |
Graph, |
|
252 | 251 |
typename enable_if<typename Graph::UndirectedTag, void>::type |
253 | 252 |
> { |
254 | 253 |
static const bool value = true; |
... | ... |
@@ -261,7 +260,7 @@ |
261 | 260 |
|
262 | 261 |
template <typename Graph> |
263 | 262 |
struct BuildTagIndicator< |
264 |
Graph, |
|
263 |
Graph, |
|
265 | 264 |
typename enable_if<typename Graph::BuildTag, void>::type |
266 | 265 |
> { |
267 | 266 |
static const bool value = true; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -83,13 +83,13 @@ |
83 | 83 |
template<int T> struct dummy { dummy(int) {} }; |
84 | 84 |
|
85 | 85 |
/**************** enable_if from BOOST ****************/ |
86 |
|
|
86 |
|
|
87 | 87 |
template <typename Type, typename T = void> |
88 | 88 |
struct exists { |
89 | 89 |
typedef T type; |
90 | 90 |
}; |
91 | 91 |
|
92 |
|
|
92 |
|
|
93 | 93 |
template <bool B, class T = void> |
94 | 94 |
struct enable_if_c { |
95 | 95 |
typedef T type; |
... | ... |
@@ -98,7 +98,7 @@ |
98 | 98 |
template <class T> |
99 | 99 |
struct enable_if_c<false, T> {}; |
100 | 100 |
|
101 |
template <class Cond, class T = void> |
|
101 |
template <class Cond, class T = void> |
|
102 | 102 |
struct enable_if : public enable_if_c<Cond::value, T> {}; |
103 | 103 |
|
104 | 104 |
template <bool B, class T> |
... | ... |
@@ -109,7 +109,7 @@ |
109 | 109 |
template <class T> |
110 | 110 |
struct lazy_enable_if_c<false, T> {}; |
111 | 111 |
|
112 |
template <class Cond, class T> |
|
112 |
template <class Cond, class T> |
|
113 | 113 |
struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {}; |
114 | 114 |
|
115 | 115 |
|
... | ... |
@@ -121,7 +121,7 @@ |
121 | 121 |
template <class T> |
122 | 122 |
struct disable_if_c<true, T> {}; |
123 | 123 |
|
124 |
template <class Cond, class T = void> |
|
124 |
template <class Cond, class T = void> |
|
125 | 125 |
struct disable_if : public disable_if_c<Cond::value, T> {}; |
126 | 126 |
|
127 | 127 |
template <bool B, class T> |
... | ... |
@@ -132,7 +132,7 @@ |
132 | 132 |
template <class T> |
133 | 133 |
struct lazy_disable_if_c<true, T> {}; |
134 | 134 |
|
135 |
template <class Cond, class T> |
|
135 |
template <class Cond, class T> |
|
136 | 136 |
struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {}; |
137 | 137 |
|
138 | 138 |
} // namespace lemon |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -49,16 +49,16 @@ |
49 | 49 |
/// \tparam _Value The value type of the map. |
50 | 50 |
/// \todo Fix the doc: there is _Graph parameter instead of _Notifier. |
51 | 51 |
template <typename _Graph, typename _Item, typename _Value> |
52 |
class VectorMap |
|
52 |
class VectorMap |
|
53 | 53 |
: public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { |
54 | 54 |
private: |
55 |
|
|
55 |
|
|
56 | 56 |
/// The container type of the map. |
57 |
typedef std::vector<_Value> Container; |
|
57 |
typedef std::vector<_Value> Container; |
|
58 | 58 |
|
59 | 59 |
public: |
60 | 60 |
|
61 |
/// The graph type of the map. |
|
61 |
/// The graph type of the map. |
|
62 | 62 |
typedef _Graph Graph; |
63 | 63 |
/// The item type of the map. |
64 | 64 |
typedef _Item Item; |
... | ... |
@@ -93,9 +93,9 @@ |
93 | 93 |
container.resize(Parent::notifier()->maxId() + 1); |
94 | 94 |
} |
95 | 95 |
|
96 |
/// \brief Constructor uses given value to initialize the map. |
|
96 |
/// \brief Constructor uses given value to initialize the map. |
|
97 | 97 |
/// |
98 |
/// It constructs a map uses a given value to initialize the map. |
|
98 |
/// It constructs a map uses a given value to initialize the map. |
|
99 | 99 |
/// It adds all the items of the graph to the map. |
100 | 100 |
VectorMap(const Graph& graph, const Value& value) { |
101 | 101 |
Parent::attach(graph.notifier(Item())); |
... | ... |
@@ -107,18 +107,18 @@ |
107 | 107 |
/// Copy constructor. |
108 | 108 |
VectorMap(const VectorMap& _copy) : Parent() { |
109 | 109 |
if (_copy.attached()) { |
110 |
Parent::attach(*_copy.notifier()); |
|
111 |
container = _copy.container; |
|
110 |
Parent::attach(*_copy.notifier()); |
|
111 |
container = _copy.container; |
|
112 | 112 |
} |
113 | 113 |
} |
114 | 114 |
|
115 | 115 |
/// \brief Assign operator. |
116 | 116 |
/// |
117 | 117 |
/// This operator assigns for each item in the map the |
118 |
/// value mapped to the same item in the copied map. |
|
118 |
/// value mapped to the same item in the copied map. |
|
119 | 119 |
/// The parameter map should be indiced with the same |
120 | 120 |
/// itemset because this assign operator does not change |
121 |
/// the container of the map. |
|
121 |
/// the container of the map. |
|
122 | 122 |
VectorMap& operator=(const VectorMap& cmap) { |
123 | 123 |
return operator=<VectorMap>(cmap); |
124 | 124 |
} |
... | ... |
@@ -129,7 +129,7 @@ |
129 | 129 |
/// The given parameter should be conform to the ReadMap |
130 | 130 |
/// concecpt and could be indiced by the current item set of |
131 | 131 |
/// the NodeMap. In this case the value for each item |
132 |
/// is assigned by the value of the given ReadMap. |
|
132 |
/// is assigned by the value of the given ReadMap. |
|
133 | 133 |
template <typename CMap> |
134 | 134 |
VectorMap& operator=(const CMap& cmap) { |
135 | 135 |
checkConcept<concepts::ReadMap<Key, _Value>, CMap>(); |
... | ... |
@@ -140,21 +140,21 @@ |
140 | 140 |
} |
141 | 141 |
return *this; |
142 | 142 |
} |
143 |
|
|
143 |
|
|
144 | 144 |
public: |
145 | 145 |
|
146 | 146 |
/// \brief The subcript operator. |
147 | 147 |
/// |
148 | 148 |
/// The subscript operator. The map can be subscripted by the |
149 |
/// actual items of the graph. |
|
149 |
/// actual items of the graph. |
|
150 | 150 |
Reference operator[](const Key& key) { |
151 | 151 |
return container[Parent::notifier()->id(key)]; |
152 |
} |
|
153 |
|
|
152 |
} |
|
153 |
|
|
154 | 154 |
/// \brief The const subcript operator. |
155 | 155 |
/// |
156 | 156 |
/// The const subscript operator. The map can be subscripted by the |
157 |
/// actual items of the graph. |
|
157 |
/// actual items of the graph. |
|
158 | 158 |
ConstReference operator[](const Key& key) const { |
159 | 159 |
return container[Parent::notifier()->id(key)]; |
160 | 160 |
} |
... | ... |
@@ -170,20 +170,20 @@ |
170 | 170 |
protected: |
171 | 171 |
|
172 | 172 |
/// \brief Adds a new key to the map. |
173 |
/// |
|
173 |
/// |
|
174 | 174 |
/// It adds a new key to the map. It called by the observer notifier |
175 |
/// and it overrides the add() member function of the observer base. |
|
175 |
/// and it overrides the add() member function of the observer base. |
|
176 | 176 |
virtual void add(const Key& key) { |
177 | 177 |
int id = Parent::notifier()->id(key); |
178 | 178 |
if (id >= int(container.size())) { |
179 |
|
|
179 |
container.resize(id + 1); |
|
180 | 180 |
} |
181 | 181 |
} |
182 | 182 |
|
183 | 183 |
/// \brief Adds more new keys to the map. |
184 |
/// |
|
184 |
/// |
|
185 | 185 |
/// It adds more new keys to the map. It called by the observer notifier |
186 |
/// and it overrides the add() member function of the observer base. |
|
186 |
/// and it overrides the add() member function of the observer base. |
|
187 | 187 |
virtual void add(const std::vector<Key>& keys) { |
188 | 188 |
int max = container.size() - 1; |
189 | 189 |
for (int i = 0; i < int(keys.size()); ++i) { |
... | ... |
@@ -198,7 +198,7 @@ |
198 | 198 |
/// \brief Erase a key from the map. |
199 | 199 |
/// |
200 | 200 |
/// Erase a key from the map. It called by the observer notifier |
201 |
/// and it overrides the erase() member function of the observer base. |
|
201 |
/// and it overrides the erase() member function of the observer base. |
|
202 | 202 |
virtual void erase(const Key& key) { |
203 | 203 |
container[Parent::notifier()->id(key)] = Value(); |
204 | 204 |
} |
... | ... |
@@ -206,18 +206,18 @@ |
206 | 206 |
/// \brief Erase more keys from the map. |
207 | 207 |
/// |
208 | 208 |
/// Erase more keys from the map. It called by the observer notifier |
209 |
/// and it overrides the erase() member function of the observer base. |
|
209 |
/// and it overrides the erase() member function of the observer base. |
|
210 | 210 |
virtual void erase(const std::vector<Key>& keys) { |
211 | 211 |
for (int i = 0; i < int(keys.size()); ++i) { |
212 |
|
|
212 |
container[Parent::notifier()->id(keys[i])] = Value(); |
|
213 | 213 |
} |
214 | 214 |
} |
215 |
|
|
215 |
|
|
216 | 216 |
/// \brief Buildes the map. |
217 |
/// |
|
217 |
/// |
|
218 | 218 |
/// It buildes the map. It called by the observer notifier |
219 | 219 |
/// and it overrides the build() member function of the observer base. |
220 |
virtual void build() { |
|
220 |
virtual void build() { |
|
221 | 221 |
int size = Parent::notifier()->maxId() + 1; |
222 | 222 |
container.reserve(size); |
223 | 223 |
container.resize(size); |
... | ... |
@@ -226,13 +226,13 @@ |
226 | 226 |
/// \brief Clear the map. |
227 | 227 |
/// |
228 | 228 |
/// It erase all items from the map. It called by the observer notifier |
229 |
/// and it overrides the clear() member function of the observer base. |
|
230 |
virtual void clear() { |
|
229 |
/// and it overrides the clear() member function of the observer base. |
|
230 |
virtual void clear() { |
|
231 | 231 |
container.clear(); |
232 | 232 |
} |
233 |
|
|
233 |
|
|
234 | 234 |
private: |
235 |
|
|
235 |
|
|
236 | 236 |
Container container; |
237 | 237 |
|
238 | 238 |
}; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -24,7 +24,7 @@ |
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); |
... | ... |
@@ -40,5 +40,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 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -62,7 +62,7 @@ |
62 | 62 |
}; |
63 | 63 |
|
64 | 64 |
/// White color constant |
65 |
extern const Color WHITE; |
|
65 |
extern const Color WHITE; |
|
66 | 66 |
/// Black color constant |
67 | 67 |
extern const Color BLACK; |
68 | 68 |
/// Red color constant |
... | ... |
@@ -130,14 +130,14 @@ |
130 | 130 |
colors.push_back(Color(1,1,0)); |
131 | 131 |
colors.push_back(Color(1,0,1)); |
132 | 132 |
colors.push_back(Color(0,1,1)); |
133 |
|
|
133 |
|
|
134 | 134 |
colors.push_back(Color(.5,0,0)); |
135 | 135 |
colors.push_back(Color(0,.5,0)); |
136 | 136 |
colors.push_back(Color(0,0,.5)); |
137 | 137 |
colors.push_back(Color(.5,.5,0)); |
138 | 138 |
colors.push_back(Color(.5,0,.5)); |
139 | 139 |
colors.push_back(Color(0,.5,.5)); |
140 |
|
|
140 |
|
|
141 | 141 |
colors.push_back(Color(.5,.5,.5)); |
142 | 142 |
colors.push_back(Color(1,.5,.5)); |
143 | 143 |
colors.push_back(Color(.5,1,.5)); |
... | ... |
@@ -145,7 +145,7 @@ |
145 | 145 |
colors.push_back(Color(1,1,.5)); |
146 | 146 |
colors.push_back(Color(1,.5,1)); |
147 | 147 |
colors.push_back(Color(.5,1,1)); |
148 |
|
|
148 |
|
|
149 | 149 |
colors.push_back(Color(1,.5,0)); |
150 | 150 |
colors.push_back(Color(.5,1,0)); |
151 | 151 |
colors.push_back(Color(1,0,.5)); |
... | ... |
@@ -171,7 +171,7 @@ |
171 | 171 |
colors[i%colors.size()]=c; |
172 | 172 |
} |
173 | 173 |
///Adds a new color to the end of the color list. |
174 |
void add(const Color &c) |
|
174 |
void add(const Color &c) |
|
175 | 175 |
{ |
176 | 176 |
colors.push_back(c); |
177 | 177 |
} |
... | ... |
@@ -186,7 +186,7 @@ |
186 | 186 |
|
187 | 187 |
///Returns a \ref Color which is as different from the given parameter |
188 | 188 |
///as it is possible. |
189 |
inline Color distantColor(const Color &c) |
|
189 |
inline Color distantColor(const Color &c) |
|
190 | 190 |
{ |
191 | 191 |
return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0); |
192 | 192 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -36,7 +36,7 @@ |
36 | 36 |
///\file |
37 | 37 |
///\brief Basic utilities for concept checking. |
38 | 38 |
/// |
39 |
///\todo Are we still using BOOST concept checking utility? |
|
39 |
///\todo Are we still using BOOST concept checking utility? |
|
40 | 40 |
///Is the BOOST copyright notice necessary? |
41 | 41 |
|
42 | 42 |
#ifndef LEMON_CONCEPT_CHECK_H |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -46,13 +46,13 @@ |
46 | 46 |
class Digraph { |
47 | 47 |
private: |
48 | 48 |
///Digraphs are \e not copy constructible. Use DigraphCopy() instead. |
49 |
|
|
49 |
|
|
50 | 50 |
///Digraphs are \e not copy constructible. Use DigraphCopy() instead. |
51 | 51 |
/// |
52 | 52 |
Digraph(const Digraph &) {}; |
53 | 53 |
///\brief Assignment of \ref Digraph "Digraph"s to another ones are |
54 | 54 |
///\e not allowed. Use DigraphCopy() instead. |
55 |
|
|
55 |
|
|
56 | 56 |
///Assignment of \ref Digraph "Digraph"s to another ones are |
57 | 57 |
///\e not allowed. Use DigraphCopy() instead. |
58 | 58 |
|
... | ... |
@@ -95,23 +95,23 @@ |
95 | 95 |
bool operator==(Node) const { return true; } |
96 | 96 |
|
97 | 97 |
/// Inequality operator |
98 |
|
|
98 |
|
|
99 | 99 |
/// \sa operator==(Node n) |
100 | 100 |
/// |
101 | 101 |
bool operator!=(Node) const { return true; } |
102 | 102 |
|
103 |
/// Artificial ordering operator. |
|
104 |
|
|
105 |
/// To allow the use of digraph descriptors as key type in std::map or |
|
106 |
/// similar associative container we require this. |
|
107 |
/// |
|
108 |
/// \note This operator only have to define some strict ordering of |
|
109 |
/// the items; this order has nothing to do with the iteration |
|
110 |
/// ordering of the items. |
|
111 |
|
|
103 |
/// Artificial ordering operator. |
|
104 |
|
|
105 |
/// To allow the use of digraph descriptors as key type in std::map or |
|
106 |
/// similar associative container we require this. |
|
107 |
/// |
|
108 |
/// \note This operator only have to define some strict ordering of |
|
109 |
/// the items; this order has nothing to do with the iteration |
|
110 |
/// ordering of the items. |
|
111 |
bool operator<(Node) const { return false; } |
|
112 | 112 |
|
113 | 113 |
}; |
114 |
|
|
114 |
|
|
115 | 115 |
/// This iterator goes through each node. |
116 | 116 |
|
117 | 117 |
/// This iterator goes through each node. |
... | ... |
@@ -129,7 +129,7 @@ |
129 | 129 |
/// to an undefined value. |
130 | 130 |
NodeIt() { } |
131 | 131 |
/// Copy constructor. |
132 |
|
|
132 |
|
|
133 | 133 |
/// Copy constructor. |
134 | 134 |
/// |
135 | 135 |
NodeIt(const NodeIt& n) : Node(n) { } |
... | ... |
@@ -145,9 +145,9 @@ |
145 | 145 |
NodeIt(const Digraph&) { } |
146 | 146 |
/// Node -> NodeIt conversion. |
147 | 147 |
|
148 |
/// Sets the iterator to the node of \c the digraph pointed by |
|
149 |
/// the trivial iterator. |
|
150 |
/// |
|
148 |
/// Sets the iterator to the node of \c the digraph pointed by |
|
149 |
/// the trivial iterator. |
|
150 |
/// This feature necessitates that each time we |
|
151 | 151 |
/// iterate the arc-set, the iteration order is the same. |
152 | 152 |
NodeIt(const Digraph&, const Node&) { } |
153 | 153 |
/// Next node. |
... | ... |
@@ -156,8 +156,8 @@ |
156 | 156 |
/// |
157 | 157 |
NodeIt& operator++() { return *this; } |
158 | 158 |
}; |
159 |
|
|
160 |
|
|
159 |
|
|
160 |
|
|
161 | 161 |
/// Class for identifying an arc of the digraph |
162 | 162 |
|
163 | 163 |
/// This class identifies an arc of the digraph. It also serves |
... | ... |
@@ -191,17 +191,17 @@ |
191 | 191 |
/// |
192 | 192 |
bool operator!=(Arc) const { return true; } |
193 | 193 |
|
194 |
/// Artificial ordering operator. |
|
195 |
|
|
196 |
/// To allow the use of digraph descriptors as key type in std::map or |
|
197 |
/// similar associative container we require this. |
|
198 |
/// |
|
199 |
/// \note This operator only have to define some strict ordering of |
|
200 |
/// the items; this order has nothing to do with the iteration |
|
201 |
/// ordering of the items. |
|
202 |
|
|
194 |
/// Artificial ordering operator. |
|
195 |
|
|
196 |
/// To allow the use of digraph descriptors as key type in std::map or |
|
197 |
/// similar associative container we require this. |
|
198 |
/// |
|
199 |
/// \note This operator only have to define some strict ordering of |
|
200 |
/// the items; this order has nothing to do with the iteration |
|
201 |
/// ordering of the items. |
|
202 |
bool operator<(Arc) const { return false; } |
|
203 | 203 |
}; |
204 |
|
|
204 |
|
|
205 | 205 |
/// This iterator goes trough the outgoing arcs of a node. |
206 | 206 |
|
207 | 207 |
/// This iterator goes trough the \e outgoing arcs of a certain node |
... | ... |
@@ -213,7 +213,7 @@ |
213 | 213 |
/// int count=0; |
214 | 214 |
/// for (Digraph::OutArcIt e(g, n); e!=INVALID; ++e) ++count; |
215 | 215 |
///\endcode |
216 |
|
|
216 |
|
|
217 | 217 |
class OutArcIt : public Arc { |
218 | 218 |
public: |
219 | 219 |
/// Default constructor |
... | ... |
@@ -232,19 +232,19 @@ |
232 | 232 |
/// |
233 | 233 |
OutArcIt(Invalid) { } |
234 | 234 |
/// This constructor sets the iterator to the first outgoing arc. |
235 |
|
|
235 |
|
|
236 | 236 |
/// This constructor sets the iterator to the first outgoing arc of |
237 | 237 |
/// the node. |
238 | 238 |
OutArcIt(const Digraph&, const Node&) { } |
239 | 239 |
/// Arc -> OutArcIt conversion |
240 | 240 |
|
241 | 241 |
/// Sets the iterator to the value of the trivial iterator. |
242 |
|
|
242 |
/// This feature necessitates that each time we |
|
243 | 243 |
/// iterate the arc-set, the iteration order is the same. |
244 | 244 |
OutArcIt(const Digraph&, const Arc&) { } |
245 | 245 |
///Next outgoing arc |
246 |
|
|
247 |
/// Assign the iterator to the next |
|
246 |
|
|
247 |
/// Assign the iterator to the next |
|
248 | 248 |
/// outgoing arc of the corresponding node. |
249 | 249 |
OutArcIt& operator++() { return *this; } |
250 | 250 |
}; |
... | ... |
@@ -279,14 +279,14 @@ |
279 | 279 |
/// |
280 | 280 |
InArcIt(Invalid) { } |
281 | 281 |
/// This constructor sets the iterator to first incoming arc. |
282 |
|
|
282 |
|
|
283 | 283 |
/// This constructor set the iterator to the first incoming arc of |
284 | 284 |
/// the node. |
285 | 285 |
InArcIt(const Digraph&, const Node&) { } |
286 | 286 |
/// Arc -> InArcIt conversion |
287 | 287 |
|
288 | 288 |
/// Sets the iterator to the value of the trivial iterator \c e. |
289 |
/// This feature necessitates that each time we |
|
289 |
/// This feature necessitates that each time we |
|
290 | 290 |
/// iterate the arc-set, the iteration order is the same. |
291 | 291 |
InArcIt(const Digraph&, const Arc&) { } |
292 | 292 |
/// Next incoming arc |
... | ... |
@@ -322,18 +322,18 @@ |
322 | 322 |
/// |
323 | 323 |
ArcIt(Invalid) { } |
324 | 324 |
/// This constructor sets the iterator to the first arc. |
325 |
|
|
325 |
|
|
326 | 326 |
/// This constructor sets the iterator to the first arc of \c g. |
327 | 327 |
///@param g the digraph |
328 | 328 |
ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); } |
329 | 329 |
/// Arc -> ArcIt conversion |
330 | 330 |
|
331 | 331 |
/// Sets the iterator to the value of the trivial iterator \c e. |
332 |
/// This feature necessitates that each time we |
|
332 |
/// This feature necessitates that each time we |
|
333 | 333 |
/// iterate the arc-set, the iteration order is the same. |
334 |
ArcIt(const Digraph&, const Arc&) { } |
|
334 |
ArcIt(const Digraph&, const Arc&) { } |
|
335 | 335 |
///Next arc |
336 |
|
|
336 |
|
|
337 | 337 |
/// Assign the iterator to the next arc. |
338 | 338 |
ArcIt& operator++() { return *this; } |
339 | 339 |
}; |
... | ... |
@@ -349,26 +349,26 @@ |
349 | 349 |
Node source(Arc) const { return INVALID; } |
350 | 350 |
|
351 | 351 |
/// \brief Returns the ID of the node. |
352 |
int id(Node) const { return -1; } |
|
352 |
int id(Node) const { return -1; } |
|
353 | 353 |
|
354 | 354 |
/// \brief Returns the ID of the arc. |
355 |
int id(Arc) const { return -1; } |
|
355 |
int id(Arc) const { return -1; } |
|
356 | 356 |
|
357 | 357 |
/// \brief Returns the node with the given ID. |
358 | 358 |
/// |
359 | 359 |
/// \pre The argument should be a valid node ID in the graph. |
360 |
Node nodeFromId(int) const { return INVALID; } |
|
360 |
Node nodeFromId(int) const { return INVALID; } |
|
361 | 361 |
|
362 | 362 |
/// \brief Returns the arc with the given ID. |
363 | 363 |
/// |
364 | 364 |
/// \pre The argument should be a valid arc ID in the graph. |
365 |
Arc arcFromId(int) const { return INVALID; } |
|
365 |
Arc arcFromId(int) const { return INVALID; } |
|
366 | 366 |
|
367 | 367 |
/// \brief Returns an upper bound on the node IDs. |
368 |
int maxNodeId() const { return -1; } |
|
368 |
int maxNodeId() const { return -1; } |
|
369 | 369 |
|
370 | 370 |
/// \brief Returns an upper bound on the arc IDs. |
371 |
int maxArcId() const { return -1; } |
|
371 |
int maxArcId() const { return -1; } |
|
372 | 372 |
|
373 | 373 |
void first(Node&) const {} |
374 | 374 |
void next(Node&) const {} |
... | ... |
@@ -389,9 +389,9 @@ |
389 | 389 |
Arc fromId(int, Arc) const { return INVALID; } |
390 | 390 |
|
391 | 391 |
// Dummy parameter. |
392 |
int maxId(Node) const { return -1; } |
|
392 |
int maxId(Node) const { return -1; } |
|
393 | 393 |
// Dummy parameter. |
394 |
int maxId(Arc) const { return -1; } |
|
394 |
int maxId(Arc) const { return -1; } |
|
395 | 395 |
|
396 | 396 |
/// \brief The base node of the iterator. |
397 | 397 |
/// |
... | ... |
@@ -423,10 +423,10 @@ |
423 | 423 |
Node oppositeNode(const Node&, const Arc&) const { return INVALID; } |
424 | 424 |
|
425 | 425 |
/// \brief Read write map of the nodes to type \c T. |
426 |
/// |
|
426 |
/// |
|
427 | 427 |
/// ReadWrite map of the nodes to type \c T. |
428 | 428 |
/// \sa Reference |
429 |
template<class T> |
|
429 |
template<class T> |
|
430 | 430 |
class NodeMap : public ReadWriteMap< Node, T > { |
431 | 431 |
public: |
432 | 432 |
|
... | ... |
@@ -439,9 +439,9 @@ |
439 | 439 |
NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } |
440 | 440 |
///Assignment operator |
441 | 441 |
template <typename CMap> |
442 |
NodeMap& operator=(const CMap&) { |
|
442 |
NodeMap& operator=(const CMap&) { |
|
443 | 443 |
checkConcept<ReadMap<Node, T>, CMap>(); |
444 |
return *this; |
|
444 |
return *this; |
|
445 | 445 |
} |
446 | 446 |
}; |
447 | 447 |
|
... | ... |
@@ -449,7 +449,7 @@ |
449 | 449 |
/// |
450 | 450 |
/// Reference map of the arcs to type \c T. |
451 | 451 |
/// \sa Reference |
452 |
template<class T> |
|
452 |
template<class T> |
|
453 | 453 |
class ArcMap : public ReadWriteMap<Arc,T> { |
454 | 454 |
public: |
455 | 455 |
|
... | ... |
@@ -461,9 +461,9 @@ |
461 | 461 |
ArcMap(const ArcMap& em) : ReadWriteMap<Arc,T>(em) { } |
462 | 462 |
///Assignment operator |
463 | 463 |
template <typename CMap> |
464 |
ArcMap& operator=(const CMap&) { |
|
464 |
ArcMap& operator=(const CMap&) { |
|
465 | 465 |
checkConcept<ReadMap<Arc, T>, CMap>(); |
466 |
return *this; |
|
466 |
return *this; |
|
467 | 467 |
} |
468 | 468 |
}; |
469 | 469 |
|
... | ... |
@@ -471,14 +471,14 @@ |
471 | 471 |
struct Constraints { |
472 | 472 |
void constraints() { |
473 | 473 |
checkConcept<IterableDigraphComponent<>, _Digraph>(); |
474 |
|
|
474 |
checkConcept<IDableDigraphComponent<>, _Digraph>(); |
|
475 | 475 |
checkConcept<MappableDigraphComponent<>, _Digraph>(); |
476 | 476 |
} |
477 | 477 |
}; |
478 | 478 |
|
479 | 479 |
}; |
480 |
|
|
481 |
} //namespace concepts |
|
480 |
|
|
481 |
} //namespace concepts |
|
482 | 482 |
} //namespace lemon |
483 | 483 |
|
484 | 484 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -65,23 +65,23 @@ |
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 |
/// to Edge. |
|
68 |
/// to Edge. |
|
69 | 69 |
class Graph { |
70 | 70 |
public: |
71 | 71 |
/// \brief The undirected graph should be tagged by the |
72 | 72 |
/// UndirectedTag. |
73 | 73 |
/// |
74 | 74 |
/// The undirected graph should be tagged by the UndirectedTag. This |
75 |
/// tag helps the enable_if technics to make compile time |
|
76 |
/// specializations for undirected graphs. |
|
75 |
/// tag helps the enable_if technics to make compile time |
|
76 |
/// specializations for undirected graphs. |
|
77 | 77 |
typedef True UndirectedTag; |
78 | 78 |
|
79 |
/// \brief The base type of node iterators, |
|
79 |
/// \brief The base type of node iterators, |
|
80 | 80 |
/// or in other words, the trivial node iterator. |
81 | 81 |
/// |
82 | 82 |
/// This is the base type of each node iterator, |
83 | 83 |
/// thus each kind of node iterator converts to this. |
84 |
/// More precisely each kind of node iterator should be inherited |
|
84 |
/// More precisely each kind of node iterator should be inherited |
|
85 | 85 |
/// from the trivial node iterator. |
86 | 86 |
class Node { |
87 | 87 |
public: |
... | ... |
@@ -108,23 +108,23 @@ |
108 | 108 |
bool operator==(Node) const { return true; } |
109 | 109 |
|
110 | 110 |
/// Inequality operator |
111 |
|
|
111 |
|
|
112 | 112 |
/// \sa operator==(Node n) |
113 | 113 |
/// |
114 | 114 |
bool operator!=(Node) const { return true; } |
115 | 115 |
|
116 |
/// Artificial ordering operator. |
|
117 |
|
|
118 |
/// To allow the use of graph descriptors as key type in std::map or |
|
119 |
/// similar associative container we require this. |
|
120 |
/// |
|
121 |
/// \note This operator only have to define some strict ordering of |
|
122 |
/// the items; this order has nothing to do with the iteration |
|
123 |
/// ordering of the items. |
|
124 |
|
|
116 |
/// Artificial ordering operator. |
|
117 |
|
|
118 |
/// To allow the use of graph descriptors as key type in std::map or |
|
119 |
/// similar associative container we require this. |
|
120 |
/// |
|
121 |
/// \note This operator only have to define some strict ordering of |
|
122 |
/// the items; this order has nothing to do with the iteration |
|
123 |
/// ordering of the items. |
|
124 |
bool operator<(Node) const { return false; } |
|
125 | 125 |
|
126 | 126 |
}; |
127 |
|
|
127 |
|
|
128 | 128 |
/// This iterator goes through each node. |
129 | 129 |
|
130 | 130 |
/// This iterator goes through each node. |
... | ... |
@@ -142,7 +142,7 @@ |
142 | 142 |
/// to an undefined value. |
143 | 143 |
NodeIt() { } |
144 | 144 |
/// Copy constructor. |
145 |
|
|
145 |
|
|
146 | 146 |
/// Copy constructor. |
147 | 147 |
/// |
148 | 148 |
NodeIt(const NodeIt& n) : Node(n) { } |
... | ... |
@@ -158,9 +158,9 @@ |
158 | 158 |
NodeIt(const Graph&) { } |
159 | 159 |
/// Node -> NodeIt conversion. |
160 | 160 |
|
161 |
/// Sets the iterator to the node of \c the graph pointed by |
|
162 |
/// the trivial iterator. |
|
163 |
/// |
|
161 |
/// Sets the iterator to the node of \c the graph pointed by |
|
162 |
/// the trivial iterator. |
|
163 |
/// This feature necessitates that each time we |
|
164 | 164 |
/// iterate the arc-set, the iteration order is the same. |
165 | 165 |
NodeIt(const Graph&, const Node&) { } |
166 | 166 |
/// Next node. |
... | ... |
@@ -169,8 +169,8 @@ |
169 | 169 |
/// |
170 | 170 |
NodeIt& operator++() { return *this; } |
171 | 171 |
}; |
172 |
|
|
173 |
|
|
172 |
|
|
173 |
|
|
174 | 174 |
/// The base type of the edge iterators. |
175 | 175 |
|
176 | 176 |
/// The base type of the edge iterators. |
... | ... |
@@ -203,15 +203,15 @@ |
203 | 203 |
/// |
204 | 204 |
bool operator!=(Edge) const { return true; } |
205 | 205 |
|
206 |
/// Artificial ordering operator. |
|
207 |
|
|
208 |
/// To allow the use of graph descriptors as key type in std::map or |
|
209 |
/// similar associative container we require this. |
|
210 |
/// |
|
211 |
/// \note This operator only have to define some strict ordering of |
|
212 |
/// the items; this order has nothing to do with the iteration |
|
213 |
/// ordering of the items. |
|
214 |
|
|
206 |
/// Artificial ordering operator. |
|
207 |
|
|
208 |
/// To allow the use of graph descriptors as key type in std::map or |
|
209 |
/// similar associative container we require this. |
|
210 |
/// |
|
211 |
/// \note This operator only have to define some strict ordering of |
|
212 |
/// the items; this order has nothing to do with the iteration |
|
213 |
/// ordering of the items. |
|
214 |
bool operator<(Edge) const { return false; } |
|
215 | 215 |
}; |
216 | 216 |
|
217 | 217 |
/// This iterator goes through each edge. |
... | ... |
@@ -241,32 +241,32 @@ |
241 | 241 |
/// |
242 | 242 |
EdgeIt(Invalid) { } |
243 | 243 |
/// This constructor sets the iterator to the first edge. |
244 |
|
|
244 |
|
|
245 | 245 |
/// This constructor sets the iterator to the first edge. |
246 | 246 |
EdgeIt(const Graph&) { } |
247 | 247 |
/// Edge -> EdgeIt conversion |
248 | 248 |
|
249 | 249 |
/// Sets the iterator to the value of the trivial iterator. |
250 | 250 |
/// This feature necessitates that each time we |
251 |
/// iterate the edge-set, the iteration order is the |
|
252 |
/// same. |
|
253 |
|
|
251 |
/// iterate the edge-set, the iteration order is the |
|
252 |
/// same. |
|
253 |
EdgeIt(const Graph&, const Edge&) { } |
|
254 | 254 |
/// Next edge |
255 |
|
|
255 |
|
|
256 | 256 |
/// Assign the iterator to the next edge. |
257 | 257 |
EdgeIt& operator++() { return *this; } |
258 | 258 |
}; |
259 | 259 |
|
260 |
/// \brief This iterator goes trough the incident undirected |
|
260 |
/// \brief This iterator goes trough the incident undirected |
|
261 | 261 |
/// arcs of a node. |
262 | 262 |
/// |
263 | 263 |
/// This iterator goes trough the incident edges |
264 |
/// of a certain node of a graph. You should assume that the |
|
264 |
/// of a certain node of a graph. You should assume that the |
|
265 | 265 |
/// loop arcs will be iterated twice. |
266 |
/// |
|
266 |
/// |
|
267 | 267 |
/// Its usage is quite simple, for example you can compute the |
268 | 268 |
/// degree (i.e. count the number of incident arcs of a node \c n |
269 |
/// in graph \c g of type \c Graph as follows. |
|
269 |
/// in graph \c g of type \c Graph as follows. |
|
270 | 270 |
/// |
271 | 271 |
///\code |
272 | 272 |
/// int count=0; |
... | ... |
@@ -290,20 +290,20 @@ |
290 | 290 |
/// |
291 | 291 |
IncEdgeIt(Invalid) { } |
292 | 292 |
/// This constructor sets the iterator to first incident arc. |
293 |
|
|
293 |
|
|
294 | 294 |
/// This constructor set the iterator to the first incident arc of |
295 | 295 |
/// the node. |
296 | 296 |
IncEdgeIt(const Graph&, const Node&) { } |
297 | 297 |
/// Edge -> IncEdgeIt conversion |
298 | 298 |
|
299 | 299 |
/// Sets the iterator to the value of the trivial iterator \c e. |
300 |
/// This feature necessitates that each time we |
|
300 |
/// This feature necessitates that each time we |
|
301 | 301 |
/// iterate the arc-set, the iteration order is the same. |
302 | 302 |
IncEdgeIt(const Graph&, const Edge&) { } |
303 | 303 |
/// Next incident arc |
304 | 304 |
|
305 | 305 |
/// Assign the iterator to the next incident arc |
306 |
|
|
306 |
/// of the corresponding node. |
|
307 | 307 |
IncEdgeIt& operator++() { return *this; } |
308 | 308 |
}; |
309 | 309 |
|
... | ... |
@@ -340,17 +340,17 @@ |
340 | 340 |
/// |
341 | 341 |
bool operator!=(Arc) const { return true; } |
342 | 342 |
|
343 |
/// Artificial ordering operator. |
|
344 |
|
|
345 |
/// To allow the use of graph descriptors as key type in std::map or |
|
346 |
/// similar associative container we require this. |
|
347 |
/// |
|
348 |
/// \note This operator only have to define some strict ordering of |
|
349 |
/// the items; this order has nothing to do with the iteration |
|
350 |
/// ordering of the items. |
|
351 |
bool operator<(Arc) const { return false; } |
|
352 |
|
|
353 |
|
|
343 |
/// Artificial ordering operator. |
|
344 |
|
|
345 |
/// To allow the use of graph descriptors as key type in std::map or |
|
346 |
/// similar associative container we require this. |
|
347 |
/// |
|
348 |
/// \note This operator only have to define some strict ordering of |
|
349 |
/// the items; this order has nothing to do with the iteration |
|
350 |
/// ordering of the items. |
|
351 |
bool operator<(Arc) const { return false; } |
|
352 |
|
|
353 |
}; |
|
354 | 354 |
/// This iterator goes through each directed arc. |
355 | 355 |
|
356 | 356 |
/// This iterator goes through each arc of a graph. |
... | ... |
@@ -378,22 +378,22 @@ |
378 | 378 |
/// |
379 | 379 |
ArcIt(Invalid) { } |
380 | 380 |
/// This constructor sets the iterator to the first arc. |
381 |
|
|
381 |
|
|
382 | 382 |
/// This constructor sets the iterator to the first arc of \c g. |
383 | 383 |
///@param g the graph |
384 | 384 |
ArcIt(const Graph &g) { ignore_unused_variable_warning(g); } |
385 | 385 |
/// Arc -> ArcIt conversion |
386 | 386 |
|
387 | 387 |
/// Sets the iterator to the value of the trivial iterator \c e. |
388 |
/// This feature necessitates that each time we |
|
388 |
/// This feature necessitates that each time we |
|
389 | 389 |
/// iterate the arc-set, the iteration order is the same. |
390 |
ArcIt(const Graph&, const Arc&) { } |
|
390 |
ArcIt(const Graph&, const Arc&) { } |
|
391 | 391 |
///Next arc |
392 |
|
|
392 |
|
|
393 | 393 |
/// Assign the iterator to the next arc. |
394 | 394 |
ArcIt& operator++() { return *this; } |
395 | 395 |
}; |
396 |
|
|
396 |
|
|
397 | 397 |
/// This iterator goes trough the outgoing directed arcs of a node. |
398 | 398 |
|
399 | 399 |
/// This iterator goes trough the \e outgoing arcs of a certain node |
... | ... |
@@ -405,7 +405,7 @@ |
405 | 405 |
/// int count=0; |
406 | 406 |
/// for (Graph::OutArcIt e(g, n); e!=INVALID; ++e) ++count; |
407 | 407 |
///\endcode |
408 |
|
|
408 |
|
|
409 | 409 |
class OutArcIt : public Arc { |
410 | 410 |
public: |
411 | 411 |
/// Default constructor |
... | ... |
@@ -424,24 +424,24 @@ |
424 | 424 |
/// |
425 | 425 |
OutArcIt(Invalid) { } |
426 | 426 |
/// This constructor sets the iterator to the first outgoing arc. |
427 |
|
|
427 |
|
|
428 | 428 |
/// This constructor sets the iterator to the first outgoing arc of |
429 | 429 |
/// the node. |
430 | 430 |
///@param n the node |
431 | 431 |
///@param g the graph |
432 | 432 |
OutArcIt(const Graph& n, const Node& g) { |
433 |
ignore_unused_variable_warning(n); |
|
434 |
ignore_unused_variable_warning(g); |
|
435 |
|
|
433 |
ignore_unused_variable_warning(n); |
|
434 |
ignore_unused_variable_warning(g); |
|
435 |
} |
|
436 | 436 |
/// Arc -> OutArcIt conversion |
437 | 437 |
|
438 | 438 |
/// Sets the iterator to the value of the trivial iterator. |
439 |
|
|
439 |
/// This feature necessitates that each time we |
|
440 | 440 |
/// iterate the arc-set, the iteration order is the same. |
441 | 441 |
OutArcIt(const Graph&, const Arc&) { } |
442 | 442 |
///Next outgoing arc |
443 |
|
|
444 |
/// Assign the iterator to the next |
|
443 |
|
|
444 |
/// Assign the iterator to the next |
|
445 | 445 |
/// outgoing arc of the corresponding node. |
446 | 446 |
OutArcIt& operator++() { return *this; } |
447 | 447 |
}; |
... | ... |
@@ -476,19 +476,19 @@ |
476 | 476 |
/// |
477 | 477 |
InArcIt(Invalid) { } |
478 | 478 |
/// This constructor sets the iterator to first incoming arc. |
479 |
|
|
479 |
|
|
480 | 480 |
/// This constructor set the iterator to the first incoming arc of |
481 | 481 |
/// the node. |
482 | 482 |
///@param n the node |
483 | 483 |
///@param g the graph |
484 |
InArcIt(const Graph& g, const Node& n) { |
|
485 |
ignore_unused_variable_warning(n); |
|
486 |
ignore_unused_variable_warning(g); |
|
487 |
} |
|
484 |
InArcIt(const Graph& g, const Node& n) { |
|
485 |
ignore_unused_variable_warning(n); |
|
486 |
ignore_unused_variable_warning(g); |
|
487 |
} |
|
488 | 488 |
/// Arc -> InArcIt conversion |
489 | 489 |
|
490 | 490 |
/// Sets the iterator to the value of the trivial iterator \c e. |
491 |
/// This feature necessitates that each time we |
|
491 |
/// This feature necessitates that each time we |
|
492 | 492 |
/// iterate the arc-set, the iteration order is the same. |
493 | 493 |
InArcIt(const Graph&, const Arc&) { } |
494 | 494 |
/// Next incoming arc |
... | ... |
@@ -499,10 +499,10 @@ |
499 | 499 |
}; |
500 | 500 |
|
501 | 501 |
/// \brief Read write map of the nodes to type \c T. |
502 |
/// |
|
502 |
/// |
|
503 | 503 |
/// ReadWrite map of the nodes to type \c T. |
504 | 504 |
/// \sa Reference |
505 |
template<class T> |
|
505 |
template<class T> |
|
506 | 506 |
class NodeMap : public ReadWriteMap< Node, T > |
507 | 507 |
{ |
508 | 508 |
public: |
... | ... |
@@ -516,9 +516,9 @@ |
516 | 516 |
NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { } |
517 | 517 |
///Assignment operator |
518 | 518 |
template <typename CMap> |
519 |
NodeMap& operator=(const CMap&) { |
|
519 |
NodeMap& operator=(const CMap&) { |
|
520 | 520 |
checkConcept<ReadMap<Node, T>, CMap>(); |
521 |
return *this; |
|
521 |
return *this; |
|
522 | 522 |
} |
523 | 523 |
}; |
524 | 524 |
|
... | ... |
@@ -526,7 +526,7 @@ |
526 | 526 |
/// |
527 | 527 |
/// Reference map of the directed arcs to type \c T. |
528 | 528 |
/// \sa Reference |
529 |
template<class T> |
|
529 |
template<class T> |
|
530 | 530 |
class ArcMap : public ReadWriteMap<Arc,T> |
531 | 531 |
{ |
532 | 532 |
public: |
... | ... |
@@ -539,9 +539,9 @@ |
539 | 539 |
ArcMap(const ArcMap& em) : ReadWriteMap<Arc,T>(em) { } |
540 | 540 |
///Assignment operator |
541 | 541 |
template <typename CMap> |
542 |
ArcMap& operator=(const CMap&) { |
|
542 |
ArcMap& operator=(const CMap&) { |
|
543 | 543 |
checkConcept<ReadMap<Arc, T>, CMap>(); |
544 |
return *this; |
|
544 |
return *this; |
|
545 | 545 |
} |
546 | 546 |
}; |
547 | 547 |
|
... | ... |
@@ -549,7 +549,7 @@ |
549 | 549 |
|
550 | 550 |
/// Reference map of the arcs to type \c T. |
551 | 551 |
/// \sa Reference |
552 |
template<class T> |
|
552 |
template<class T> |
|
553 | 553 |
class EdgeMap : public ReadWriteMap<Edge,T> |
554 | 554 |
{ |
555 | 555 |
public: |
... | ... |
@@ -562,9 +562,9 @@ |
562 | 562 |
EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) {} |
563 | 563 |
///Assignment operator |
564 | 564 |
template <typename CMap> |
565 |
EdgeMap& operator=(const CMap&) { |
|
565 |
EdgeMap& operator=(const CMap&) { |
|
566 | 566 |
checkConcept<ReadMap<Edge, T>, CMap>(); |
567 |
return *this; |
|
567 |
return *this; |
|
568 | 568 |
} |
569 | 569 |
}; |
570 | 570 |
|
... | ... |
@@ -573,7 +573,7 @@ |
573 | 573 |
/// Direct the given edge. The returned arc source |
574 | 574 |
/// will be the given node. |
575 | 575 |
Arc direct(const Edge&, const Node&) const { |
576 |
|
|
576 |
return INVALID; |
|
577 | 577 |
} |
578 | 578 |
|
579 | 579 |
/// \brief Direct the given edge. |
... | ... |
@@ -583,7 +583,7 @@ |
583 | 583 |
/// from the bool parameter. The source of the edge and |
584 | 584 |
/// the directed arc is the same when the given bool is true. |
585 | 585 |
Arc direct(const Edge&, bool) const { |
586 |
|
|
586 |
return INVALID; |
|
587 | 587 |
} |
588 | 588 |
|
589 | 589 |
/// \brief Returns true if the arc has default orientation. |
... | ... |
@@ -625,37 +625,37 @@ |
625 | 625 |
Node target(Arc) const { return INVALID; } |
626 | 626 |
|
627 | 627 |
/// \brief Returns the id of the node. |
628 |
int id(Node) const { return -1; } |
|
628 |
int id(Node) const { return -1; } |
|
629 | 629 |
|
630 | 630 |
/// \brief Returns the id of the edge. |
631 |
int id(Edge) const { return -1; } |
|
631 |
int id(Edge) const { return -1; } |
|
632 | 632 |
|
633 | 633 |
/// \brief Returns the id of the arc. |
634 |
int id(Arc) const { return -1; } |
|
634 |
int id(Arc) const { return -1; } |
|
635 | 635 |
|
636 | 636 |
/// \brief Returns the node with the given id. |
637 | 637 |
/// |
638 | 638 |
/// \pre The argument should be a valid node id in the graph. |
639 |
Node nodeFromId(int) const { return INVALID; } |
|
639 |
Node nodeFromId(int) const { return INVALID; } |
|
640 | 640 |
|
641 | 641 |
/// \brief Returns the edge with the given id. |
642 | 642 |
/// |
643 | 643 |
/// \pre The argument should be a valid edge id in the graph. |
644 |
Edge edgeFromId(int) const { return INVALID; } |
|
644 |
Edge edgeFromId(int) const { return INVALID; } |
|
645 | 645 |
|
646 | 646 |
/// \brief Returns the arc with the given id. |
647 | 647 |
/// |
648 | 648 |
/// \pre The argument should be a valid arc id in the graph. |
649 |
Arc arcFromId(int) const { return INVALID; } |
|
649 |
Arc arcFromId(int) const { return INVALID; } |
|
650 | 650 |
|
651 | 651 |
/// \brief Returns an upper bound on the node IDs. |
652 |
int maxNodeId() const { return -1; } |
|
652 |
int maxNodeId() const { return -1; } |
|
653 | 653 |
|
654 | 654 |
/// \brief Returns an upper bound on the edge IDs. |
655 |
int maxEdgeId() const { return -1; } |
|
655 |
int maxEdgeId() const { return -1; } |
|
656 | 656 |
|
657 | 657 |
/// \brief Returns an upper bound on the arc IDs. |
658 |
int maxArcId() const { return -1; } |
|
658 |
int maxArcId() const { return -1; } |
|
659 | 659 |
|
660 | 660 |
void first(Node&) const {} |
661 | 661 |
void next(Node&) const {} |
... | ... |
@@ -683,61 +683,61 @@ |
683 | 683 |
Arc fromId(int, Arc) const { return INVALID; } |
684 | 684 |
|
685 | 685 |
// Dummy parameter. |
686 |
int maxId(Node) const { return -1; } |
|
686 |
int maxId(Node) const { return -1; } |
|
687 | 687 |
// Dummy parameter. |
688 |
int maxId(Edge) const { return -1; } |
|
688 |
int maxId(Edge) const { return -1; } |
|
689 | 689 |
// Dummy parameter. |
690 |
int maxId(Arc) const { return -1; } |
|
690 |
int maxId(Arc) const { return -1; } |
|
691 | 691 |
|
692 | 692 |
/// \brief Base node of the iterator |
693 | 693 |
/// |
694 | 694 |
/// Returns the base node (the source in this case) of the iterator |
695 | 695 |
Node baseNode(OutArcIt e) const { |
696 |
|
|
696 |
return source(e); |
|
697 | 697 |
} |
698 | 698 |
/// \brief Running node of the iterator |
699 | 699 |
/// |
700 | 700 |
/// Returns the running node (the target in this case) of the |
701 | 701 |
/// iterator |
702 | 702 |
Node runningNode(OutArcIt e) const { |
703 |
|
|
703 |
return target(e); |
|
704 | 704 |
} |
705 | 705 |
|
706 | 706 |
/// \brief Base node of the iterator |
707 | 707 |
/// |
708 | 708 |
/// Returns the base node (the target in this case) of the iterator |
709 | 709 |
Node baseNode(InArcIt e) const { |
710 |
|
|
710 |
return target(e); |
|
711 | 711 |
} |
712 | 712 |
/// \brief Running node of the iterator |
713 | 713 |
/// |
714 | 714 |
/// Returns the running node (the source in this case) of the |
715 | 715 |
/// iterator |
716 | 716 |
Node runningNode(InArcIt e) const { |
717 |
|
|
717 |
return source(e); |
|
718 | 718 |
} |
719 | 719 |
|
720 | 720 |
/// \brief Base node of the iterator |
721 | 721 |
/// |
722 | 722 |
/// Returns the base node of the iterator |
723 | 723 |
Node baseNode(IncEdgeIt) const { |
724 |
|
|
724 |
return INVALID; |
|
725 | 725 |
} |
726 |
|
|
726 |
|
|
727 | 727 |
/// \brief Running node of the iterator |
728 | 728 |
/// |
729 | 729 |
/// Returns the running node of the iterator |
730 | 730 |
Node runningNode(IncEdgeIt) const { |
731 |
|
|
731 |
return INVALID; |
|
732 | 732 |
} |
733 | 733 |
|
734 | 734 |
template <typename _Graph> |
735 | 735 |
struct Constraints { |
736 |
void constraints() { |
|
737 |
checkConcept<IterableGraphComponent<>, _Graph>(); |
|
738 |
checkConcept<IDableGraphComponent<>, _Graph>(); |
|
739 |
checkConcept<MappableGraphComponent<>, _Graph>(); |
|
740 |
|
|
736 |
void constraints() { |
|
737 |
checkConcept<IterableGraphComponent<>, _Graph>(); |
|
738 |
checkConcept<IDableGraphComponent<>, _Graph>(); |
|
739 |
checkConcept<MappableGraphComponent<>, _Graph>(); |
|
740 |
} |
|
741 | 741 |
}; |
742 | 742 |
|
743 | 743 |
}; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -49,7 +49,7 @@ |
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. |
... | ... |
@@ -66,7 +66,7 @@ |
66 | 66 |
GraphItem(Invalid) {} |
67 | 67 |
/// \brief Assign operator for nodes. |
68 | 68 |
/// |
69 |
/// The nodes are assignable. |
|
69 |
/// The nodes are assignable. |
|
70 | 70 |
/// |
71 | 71 |
GraphItem& operator=(GraphItem const&) { return *this; } |
72 | 72 |
/// \brief Equality operator. |
... | ... |
@@ -92,27 +92,27 @@ |
92 | 92 |
|
93 | 93 |
template<typename _GraphItem> |
94 | 94 |
struct Constraints { |
95 |
void constraints() { |
|
96 |
_GraphItem i1; |
|
97 |
_GraphItem i2 = i1; |
|
98 |
_GraphItem i3 = INVALID; |
|
99 |
|
|
100 |
i1 = i2 = i3; |
|
95 |
void constraints() { |
|
96 |
_GraphItem i1; |
|
97 |
_GraphItem i2 = i1; |
|
98 |
_GraphItem i3 = INVALID; |
|
101 | 99 |
|
102 |
bool b; |
|
103 |
// b = (ia == ib) && (ia != ib) && (ia < ib); |
|
104 |
b = (ia == ib) && (ia != ib); |
|
105 |
b = (ia == INVALID) && (ib != INVALID); |
|
100 |
i1 = i2 = i3; |
|
101 |
|
|
102 |
bool b; |
|
103 |
// b = (ia == ib) && (ia != ib) && (ia < ib); |
|
104 |
b = (ia == ib) && (ia != ib); |
|
105 |
b = (ia == INVALID) && (ib != INVALID); |
|
106 | 106 |
b = (ia < ib); |
107 |
|
|
107 |
} |
|
108 | 108 |
|
109 |
const _GraphItem &ia; |
|
110 |
const _GraphItem &ib; |
|
109 |
const _GraphItem &ia; |
|
110 |
const _GraphItem &ib; |
|
111 | 111 |
}; |
112 | 112 |
}; |
113 | 113 |
|
114 | 114 |
/// \brief An empty base directed graph class. |
115 |
/// |
|
115 |
/// |
|
116 | 116 |
/// This class provides the minimal set of features needed for a |
117 | 117 |
/// directed graph structure. All digraph concepts have to be |
118 | 118 |
/// conform to this base directed graph. It just provides types |
... | ... |
@@ -122,16 +122,16 @@ |
122 | 122 |
public: |
123 | 123 |
|
124 | 124 |
typedef BaseDigraphComponent Digraph; |
125 |
|
|
125 |
|
|
126 | 126 |
/// \brief Node class of the digraph. |
127 | 127 |
/// |
128 |
/// This class represents the Nodes of the digraph. |
|
128 |
/// This class represents the Nodes of the digraph. |
|
129 | 129 |
/// |
130 | 130 |
typedef GraphItem<'n'> Node; |
131 | 131 |
|
132 | 132 |
/// \brief Arc class of the digraph. |
133 | 133 |
/// |
134 |
/// This class represents the Arcs of the digraph. |
|
134 |
/// This class represents the Arcs of the digraph. |
|
135 | 135 |
/// |
136 | 136 |
typedef GraphItem<'e'> Arc; |
137 | 137 |
|
... | ... |
@@ -156,27 +156,27 @@ |
156 | 156 |
|
157 | 157 |
template <typename _Digraph> |
158 | 158 |
struct Constraints { |
159 |
typedef typename _Digraph::Node Node; |
|
160 |
typedef typename _Digraph::Arc Arc; |
|
161 |
|
|
162 |
void constraints() { |
|
163 |
checkConcept<GraphItem<'n'>, Node>(); |
|
164 |
checkConcept<GraphItem<'a'>, Arc>(); |
|
165 |
{ |
|
166 |
Node n; |
|
167 |
Arc e(INVALID); |
|
168 |
n = digraph.source(e); |
|
169 |
|
|
159 |
typedef typename _Digraph::Node Node; |
|
160 |
typedef typename _Digraph::Arc Arc; |
|
161 |
|
|
162 |
void constraints() { |
|
163 |
checkConcept<GraphItem<'n'>, Node>(); |
|
164 |
checkConcept<GraphItem<'a'>, Arc>(); |
|
165 |
{ |
|
166 |
Node n; |
|
167 |
Arc e(INVALID); |
|
168 |
n = digraph.source(e); |
|
169 |
n = digraph.target(e); |
|
170 | 170 |
n = digraph.oppositeNode(n, e); |
171 |
} |
|
172 |
} |
|
173 |
|
|
174 |
const _Digraph& digraph; |
|
171 |
} |
|
172 |
} |
|
173 |
|
|
174 |
const _Digraph& digraph; |
|
175 | 175 |
}; |
176 | 176 |
}; |
177 | 177 |
|
178 | 178 |
/// \brief An empty base undirected graph class. |
179 |
/// |
|
179 |
/// |
|
180 | 180 |
/// This class provides the minimal set of features needed for an |
181 | 181 |
/// undirected graph structure. All undirected graph concepts have |
182 | 182 |
/// to be conform to this base graph. It just provides types for |
... | ... |
@@ -199,7 +199,7 @@ |
199 | 199 |
public: |
200 | 200 |
typedef GraphItem<'u'> Parent; |
201 | 201 |
/// \brief Default constructor. |
202 |
/// |
|
202 |
/// |
|
203 | 203 |
/// \warning The default constructor is not required to set |
204 | 204 |
/// the item to some well-defined value. So you should consider it |
205 | 205 |
/// as uninitialized. |
... | ... |
@@ -217,12 +217,12 @@ |
217 | 217 |
/// \brief Converter from arc to edge. |
218 | 218 |
/// |
219 | 219 |
/// Besides the core graph item functionality each arc should |
220 |
/// be convertible to the represented edge. |
|
220 |
/// be convertible to the represented edge. |
|
221 | 221 |
Edge(const Arc&) {} |
222 | 222 |
/// \brief Assign arc to edge. |
223 | 223 |
/// |
224 | 224 |
/// Besides the core graph item functionality each arc should |
225 |
/// be convertible to the represented edge. |
|
225 |
/// be convertible to the represented edge. |
|
226 | 226 |
Edge& operator=(const Arc&) { return *this; } |
227 | 227 |
}; |
228 | 228 |
|
... | ... |
@@ -237,13 +237,13 @@ |
237 | 237 |
/// |
238 | 238 |
/// Returns the directed arc from its direction and the |
239 | 239 |
/// represented edge. |
240 |
Arc direct(const Edge&, bool) const { return INVALID;} |
|
240 |
Arc direct(const Edge&, bool) const { return INVALID;} |
|
241 | 241 |
|
242 | 242 |
/// \brief Returns the directed arc. |
243 | 243 |
/// |
244 | 244 |
/// Returns the directed arc from its source and the |
245 | 245 |
/// represented edge. |
246 |
Arc direct(const Edge&, const Node&) const { return INVALID;} |
|
246 |
Arc direct(const Edge&, const Node&) const { return INVALID;} |
|
247 | 247 |
|
248 | 248 |
/// \brief Returns the opposite arc. |
249 | 249 |
/// |
... | ... |
@@ -260,38 +260,38 @@ |
260 | 260 |
/// |
261 | 261 |
/// Gives back the other ending of an edge. |
262 | 262 |
Node v(const Edge&) const { return INVALID;} |
263 |
|
|
263 |
|
|
264 | 264 |
template <typename _Graph> |
265 | 265 |
struct Constraints { |
266 |
typedef typename _Graph::Node Node; |
|
267 |
typedef typename _Graph::Arc Arc; |
|
268 |
typedef typename _Graph::Edge Edge; |
|
269 |
|
|
270 |
|
|
266 |
typedef typename _Graph::Node Node; |
|
267 |
typedef typename _Graph::Arc Arc; |
|
268 |
typedef typename _Graph::Edge Edge; |
|
269 |
|
|
270 |
void constraints() { |
|
271 | 271 |
checkConcept<BaseDigraphComponent, _Graph>(); |
272 |
checkConcept<GraphItem<'u'>, Edge>(); |
|
273 |
{ |
|
274 |
Node n; |
|
275 |
Edge ue(INVALID); |
|
272 |
checkConcept<GraphItem<'u'>, Edge>(); |
|
273 |
{ |
|
274 |
Node n; |
|
275 |
Edge ue(INVALID); |
|
276 | 276 |
Arc e; |
277 |
n = graph.u(ue); |
|
278 |
n = graph.v(ue); |
|
277 |
n = graph.u(ue); |
|
278 |
n = graph.v(ue); |
|
279 | 279 |
e = graph.direct(ue, true); |
280 | 280 |
e = graph.direct(ue, n); |
281 | 281 |
e = graph.oppositeArc(e); |
282 | 282 |
ue = e; |
283 | 283 |
bool d = graph.direction(e); |
284 | 284 |
ignore_unused_variable_warning(d); |
285 |
} |
|
286 |
} |
|
287 |
|
|
288 |
const _Graph& graph; |
|
285 |
} |
|
286 |
} |
|
287 |
|
|
288 |
const _Graph& graph; |
|
289 | 289 |
}; |
290 | 290 |
|
291 | 291 |
}; |
292 | 292 |
|
293 | 293 |
/// \brief An empty idable base digraph class. |
294 |
/// |
|
294 |
/// |
|
295 | 295 |
/// This class provides beside the core digraph features |
296 | 296 |
/// core id functions for the digraph structure. |
297 | 297 |
/// The most of the base digraphs should be conform to this concept. |
... | ... |
@@ -304,9 +304,9 @@ |
304 | 304 |
typedef typename Base::Node Node; |
305 | 305 |
typedef typename Base::Arc Arc; |
306 | 306 |
|
307 |
/// \brief Gives back an unique integer id for the Node. |
|
307 |
/// \brief Gives back an unique integer id for the Node. |
|
308 | 308 |
/// |
309 |
/// Gives back an unique integer id for the Node. |
|
309 |
/// Gives back an unique integer id for the Node. |
|
310 | 310 |
/// |
311 | 311 |
int id(const Node&) const { return -1;} |
312 | 312 |
|
... | ... |
@@ -314,12 +314,12 @@ |
314 | 314 |
/// |
315 | 315 |
/// Gives back the node by the unique id. |
316 | 316 |
/// If the digraph does not contain node with the given id |
317 |
/// then the result of the function is undetermined. |
|
317 |
/// then the result of the function is undetermined. |
|
318 | 318 |
Node nodeFromId(int) const { return INVALID;} |
319 | 319 |
|
320 |
/// \brief Gives back an unique integer id for the Arc. |
|
320 |
/// \brief Gives back an unique integer id for the Arc. |
|
321 | 321 |
/// |
322 |
/// Gives back an unique integer id for the Arc. |
|
322 |
/// Gives back an unique integer id for the Arc. |
|
323 | 323 |
/// |
324 | 324 |
int id(const Arc&) const { return -1;} |
325 | 325 |
|
... | ... |
@@ -327,7 +327,7 @@ |
327 | 327 |
/// |
328 | 328 |
/// Gives back the arc by the unique id. |
329 | 329 |
/// If the digraph does not contain arc with the given id |
330 |
/// then the result of the function is undetermined. |
|
330 |
/// then the result of the function is undetermined. |
|
331 | 331 |
Arc arcFromId(int) const { return INVALID;} |
332 | 332 |
|
333 | 333 |
/// \brief Gives back an integer greater or equal to the maximum |
... | ... |
@@ -347,29 +347,29 @@ |
347 | 347 |
template <typename _Digraph> |
348 | 348 |
struct Constraints { |
349 | 349 |
|
350 |
void constraints() { |
|
351 |
checkConcept<Base, _Digraph >(); |
|
352 |
typename _Digraph::Node node; |
|
353 |
int nid = digraph.id(node); |
|
354 |
nid = digraph.id(node); |
|
355 |
node = digraph.nodeFromId(nid); |
|
356 |
typename _Digraph::Arc arc; |
|
357 |
int eid = digraph.id(arc); |
|
358 |
eid = digraph.id(arc); |
|
359 |
arc = digraph.arcFromId(eid); |
|
350 |
void constraints() { |
|
351 |
checkConcept<Base, _Digraph >(); |
|
352 |
typename _Digraph::Node node; |
|
353 |
int nid = digraph.id(node); |
|
354 |
nid = digraph.id(node); |
|
355 |
node = digraph.nodeFromId(nid); |
|
356 |
typename _Digraph::Arc arc; |
|
357 |
int eid = digraph.id(arc); |
|
358 |
eid = digraph.id(arc); |
|
359 |
arc = digraph.arcFromId(eid); |
|
360 | 360 |
|
361 |
nid = digraph.maxNodeId(); |
|
362 |
ignore_unused_variable_warning(nid); |
|
363 |
eid = digraph.maxArcId(); |
|
364 |
ignore_unused_variable_warning(eid); |
|
365 |
|
|
361 |
nid = digraph.maxNodeId(); |
|
362 |
ignore_unused_variable_warning(nid); |
|
363 |
eid = digraph.maxArcId(); |
|
364 |
ignore_unused_variable_warning(eid); |
|
365 |
} |
|
366 | 366 |
|
367 |
|
|
367 |
const _Digraph& digraph; |
|
368 | 368 |
}; |
369 | 369 |
}; |
370 | 370 |
|
371 | 371 |
/// \brief An empty idable base undirected graph class. |
372 |
/// |
|
372 |
/// |
|
373 | 373 |
/// This class provides beside the core undirected graph features |
374 | 374 |
/// core id functions for the undirected graph structure. The |
375 | 375 |
/// most of the base undirected graphs should be conform to this |
... | ... |
@@ -383,9 +383,9 @@ |
383 | 383 |
|
384 | 384 |
using IDableDigraphComponent<_Base>::id; |
385 | 385 |
|
386 |
/// \brief Gives back an unique integer id for the Edge. |
|
386 |
/// \brief Gives back an unique integer id for the Edge. |
|
387 | 387 |
/// |
388 |
/// Gives back an unique integer id for the Edge. |
|
388 |
/// Gives back an unique integer id for the Edge. |
|
389 | 389 |
/// |
390 | 390 |
int id(const Edge&) const { return -1;} |
391 | 391 |
|
... | ... |
@@ -406,18 +406,18 @@ |
406 | 406 |
template <typename _Graph> |
407 | 407 |
struct Constraints { |
408 | 408 |
|
409 |
void constraints() { |
|
410 |
checkConcept<Base, _Graph >(); |
|
411 |
checkConcept<IDableDigraphComponent<Base>, _Graph >(); |
|
412 |
typename _Graph::Edge edge; |
|
413 |
int ueid = graph.id(edge); |
|
414 |
ueid = graph.id(edge); |
|
415 |
edge = graph.edgeFromId(ueid); |
|
416 |
ueid = graph.maxEdgeId(); |
|
417 |
ignore_unused_variable_warning(ueid); |
|
418 |
} |
|
409 |
void constraints() { |
|
410 |
checkConcept<Base, _Graph >(); |
|
411 |
checkConcept<IDableDigraphComponent<Base>, _Graph >(); |
|
412 |
typename _Graph::Edge edge; |
|
413 |
int ueid = graph.id(edge); |
|
414 |
ueid = graph.id(edge); |
|
415 |
edge = graph.edgeFromId(ueid); |
|
416 |
ueid = graph.maxEdgeId(); |
|
417 |
ignore_unused_variable_warning(ueid); |
|
418 |
} |
|
419 | 419 |
|
420 |
|
|
420 |
const _Graph& graph; |
|
421 | 421 |
}; |
422 | 422 |
}; |
423 | 423 |
|
... | ... |
@@ -450,52 +450,52 @@ |
450 | 450 |
GraphItemIt(Invalid) {} |
451 | 451 |
/// \brief Assign operator for items. |
452 | 452 |
/// |
453 |
/// The items are assignable. |
|
453 |
/// The items are assignable. |
|
454 | 454 |
/// |
455 |
GraphItemIt& operator=(const GraphItemIt&) { return *this; } |
|
455 |
GraphItemIt& operator=(const GraphItemIt&) { return *this; } |
|
456 | 456 |
/// \brief Next item. |
457 |
/// |
|
457 |
/// |
|
458 | 458 |
/// Assign the iterator to the next item. |
459 | 459 |
/// |
460 | 460 |
GraphItemIt& operator++() { return *this; } |
461 | 461 |
/// \brief Equality operator |
462 |
/// |
|
462 |
/// |
|
463 | 463 |
/// Two iterators are equal if and only if they point to the |
464 | 464 |
/// same object or both are invalid. |
465 | 465 |
bool operator==(const GraphItemIt&) const { return true;} |
466 | 466 |
/// \brief Inequality operator |
467 |
/// |
|
467 |
/// |
|
468 | 468 |
/// \sa operator==(Node n) |
469 | 469 |
/// |
470 | 470 |
bool operator!=(const GraphItemIt&) const { return true;} |
471 |
|
|
471 |
|
|
472 | 472 |
template<typename _GraphItemIt> |
473 | 473 |
struct Constraints { |
474 |
void constraints() { |
|
475 |
_GraphItemIt it1(g); |
|
476 |
|
|
474 |
void constraints() { |
|
475 |
_GraphItemIt it1(g); |
|
476 |
_GraphItemIt it2; |
|
477 | 477 |
|
478 |
it2 = ++it1; |
|
479 |
++it2 = it1; |
|
480 |
|
|
478 |
it2 = ++it1; |
|
479 |
++it2 = it1; |
|
480 |
++(++it1); |
|
481 | 481 |
|
482 |
_Item bi = it1; |
|
483 |
bi = it2; |
|
484 |
} |
|
485 |
_Graph& g; |
|
482 |
_Item bi = it1; |
|
483 |
bi = it2; |
|
484 |
} |
|
485 |
_Graph& g; |
|
486 | 486 |
}; |
487 | 487 |
}; |
488 | 488 |
|
489 | 489 |
/// \brief Skeleton class for graph InArcIt and OutArcIt |
490 | 490 |
/// |
491 | 491 |
/// \note Because InArcIt and OutArcIt may not inherit from the same |
492 |
/// base class, the _selector is a additional template parameter. For |
|
493 |
/// InArcIt you should instantiate it with character 'i' and for |
|
492 |
/// base class, the _selector is a additional template parameter. For |
|
493 |
/// InArcIt you should instantiate it with character 'i' and for |
|
494 | 494 |
/// OutArcIt with 'o'. |
495 | 495 |
template <typename _Graph, |
496 |
typename _Item = typename _Graph::Arc, |
|
497 |
typename _Base = typename _Graph::Node, |
|
498 |
|
|
496 |
typename _Item = typename _Graph::Arc, |
|
497 |
typename _Base = typename _Graph::Node, |
|
498 |
char _selector = '0'> |
|
499 | 499 |
class GraphIncIt : public _Item { |
500 | 500 |
public: |
501 | 501 |
/// \brief Default constructor. |
... | ... |
@@ -508,10 +508,10 @@ |
508 | 508 |
/// Copy constructor. |
509 | 509 |
/// |
510 | 510 |
GraphIncIt(GraphIncIt const& gi) : _Item(gi) {} |
511 |
/// \brief Sets the iterator to the first arc incoming into or outgoing |
|
511 |
/// \brief Sets the iterator to the first arc incoming into or outgoing |
|
512 | 512 |
/// from the node. |
513 | 513 |
/// |
514 |
/// Sets the iterator to the first arc incoming into or outgoing |
|
514 |
/// Sets the iterator to the first arc incoming into or outgoing |
|
515 | 515 |
/// from the node. |
516 | 516 |
/// |
517 | 517 |
explicit GraphIncIt(const _Graph&, const _Base&) {} |
... | ... |
@@ -522,9 +522,9 @@ |
522 | 522 |
GraphIncIt(Invalid) {} |
523 | 523 |
/// \brief Assign operator for iterators. |
524 | 524 |
/// |
525 |
/// The iterators are assignable. |
|
525 |
/// The iterators are assignable. |
|
526 | 526 |
/// |
527 |
GraphIncIt& operator=(GraphIncIt const&) { return *this; } |
|
527 |
GraphIncIt& operator=(GraphIncIt const&) { return *this; } |
|
528 | 528 |
/// \brief Next item. |
529 | 529 |
/// |
530 | 530 |
/// Assign the iterator to the next item. |
... | ... |
@@ -545,23 +545,23 @@ |
545 | 545 |
|
546 | 546 |
template <typename _GraphIncIt> |
547 | 547 |
struct Constraints { |
548 |
void constraints() { |
|
549 |
checkConcept<GraphItem<_selector>, _GraphIncIt>(); |
|
550 |
_GraphIncIt it1(graph, node); |
|
551 |
_GraphIncIt it2; |
|
548 |
void constraints() { |
|
549 |
checkConcept<GraphItem<_selector>, _GraphIncIt>(); |
|
550 |
_GraphIncIt it1(graph, node); |
|
551 |
_GraphIncIt it2; |
|
552 | 552 |
|
553 |
it2 = ++it1; |
|
554 |
++it2 = it1; |
|
555 |
++(++it1); |
|
556 |
_Item e = it1; |
|
557 |
|
|
553 |
it2 = ++it1; |
|
554 |
++it2 = it1; |
|
555 |
++(++it1); |
|
556 |
_Item e = it1; |
|
557 |
e = it2; |
|
558 | 558 |
|
559 |
|
|
559 |
} |
|
560 | 560 |
|
561 |
_Item arc; |
|
562 |
_Base node; |
|
563 |
_Graph graph; |
|
564 |
_GraphIncIt it; |
|
561 |
_Item arc; |
|
562 |
_Base node; |
|
563 |
_Graph graph; |
|
564 |
_GraphIncIt it; |
|
565 | 565 |
}; |
566 | 566 |
}; |
567 | 567 |
|
... | ... |
@@ -575,7 +575,7 @@ |
575 | 575 |
class IterableDigraphComponent : public _Base { |
576 | 576 |
|
577 | 577 |
public: |
578 |
|
|
578 |
|
|
579 | 579 |
typedef _Base Base; |
580 | 580 |
typedef typename Base::Node Node; |
581 | 581 |
typedef typename Base::Arc Arc; |
... | ... |
@@ -583,33 +583,33 @@ |
583 | 583 |
typedef IterableDigraphComponent Digraph; |
584 | 584 |
|
585 | 585 |
/// \name Base iteration |
586 |
/// |
|
586 |
/// |
|
587 | 587 |
/// This interface provides functions for iteration on digraph items |
588 | 588 |
/// |
589 |
/// @{ |
|
589 |
/// @{ |
|
590 | 590 |
|
591 | 591 |
/// \brief Gives back the first node in the iterating order. |
592 |
/// |
|
592 |
/// |
|
593 | 593 |
/// Gives back the first node in the iterating order. |
594 |
/// |
|
594 |
/// |
|
595 | 595 |
void first(Node&) const {} |
596 | 596 |
|
597 | 597 |
/// \brief Gives back the next node in the iterating order. |
598 | 598 |
/// |
599 | 599 |
/// Gives back the next node in the iterating order. |
600 |
/// |
|
600 |
/// |
|
601 | 601 |
void next(Node&) const {} |
602 | 602 |
|
603 | 603 |
/// \brief Gives back the first arc in the iterating order. |
604 | 604 |
/// |
605 | 605 |
/// Gives back the first arc in the iterating order. |
606 |
/// |
|
606 |
/// |
|
607 | 607 |
void first(Arc&) const {} |
608 | 608 |
|
609 | 609 |
/// \brief Gives back the next arc in the iterating order. |
610 | 610 |
/// |
611 | 611 |
/// Gives back the next arc in the iterating order. |
612 |
/// |
|
612 |
/// |
|
613 | 613 |
void next(Arc&) const {} |
614 | 614 |
|
615 | 615 |
|
... | ... |
@@ -617,7 +617,7 @@ |
617 | 617 |
/// node. |
618 | 618 |
/// |
619 | 619 |
/// Gives back the first of the arcs point to the given node. |
620 |
/// |
|
620 |
/// |
|
621 | 621 |
void firstIn(Arc&, const Node&) const {} |
622 | 622 |
|
623 | 623 |
/// \brief Gives back the next of the arcs points to the given |
... | ... |
@@ -629,22 +629,22 @@ |
629 | 629 |
|
630 | 630 |
/// \brief Gives back the first of the arcs start from the |
631 | 631 |
/// given node. |
632 |
/// |
|
632 |
/// |
|
633 | 633 |
/// Gives back the first of the arcs start from the given node. |
634 |
/// |
|
634 |
/// |
|
635 | 635 |
void firstOut(Arc&, const Node&) const {} |
636 | 636 |
|
637 | 637 |
/// \brief Gives back the next of the arcs start from the given |
638 | 638 |
/// node. |
639 | 639 |
/// |
640 | 640 |
/// Gives back the next of the arcs start from the given node. |
641 |
/// |
|
641 |
/// |
|
642 | 642 |
void nextOut(Arc&) const {} |
643 | 643 |
|
644 | 644 |
/// @} |
645 | 645 |
|
646 | 646 |
/// \name Class based iteration |
647 |
/// |
|
647 |
/// |
|
648 | 648 |
/// This interface provides functions for iteration on digraph items |
649 | 649 |
/// |
650 | 650 |
/// @{ |
... | ... |
@@ -699,13 +699,13 @@ |
699 | 699 |
|
700 | 700 |
/// @} |
701 | 701 |
|
702 |
template <typename _Digraph> |
|
702 |
template <typename _Digraph> |
|
703 | 703 |
struct Constraints { |
704 |
void constraints() { |
|
705 |
checkConcept<Base, _Digraph>(); |
|
704 |
void constraints() { |
|
705 |
checkConcept<Base, _Digraph>(); |
|
706 | 706 |
|
707 | 707 |
{ |
708 |
typename _Digraph::Node node(INVALID); |
|
708 |
typename _Digraph::Node node(INVALID); |
|
709 | 709 |
typename _Digraph::Arc arc(INVALID); |
710 | 710 |
{ |
711 | 711 |
digraph.first(node); |
... | ... |
@@ -723,16 +723,16 @@ |
723 | 723 |
digraph.firstOut(arc, node); |
724 | 724 |
digraph.nextOut(arc); |
725 | 725 |
} |
726 |
} |
|
726 |
} |
|
727 | 727 |
|
728 | 728 |
{ |
729 | 729 |
checkConcept<GraphItemIt<_Digraph, typename _Digraph::Arc>, |
730 | 730 |
typename _Digraph::ArcIt >(); |
731 | 731 |
checkConcept<GraphItemIt<_Digraph, typename _Digraph::Node>, |
732 | 732 |
typename _Digraph::NodeIt >(); |
733 |
checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, |
|
733 |
checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, |
|
734 | 734 |
typename _Digraph::Node, 'i'>, typename _Digraph::InArcIt>(); |
735 |
checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, |
|
735 |
checkConcept<GraphIncIt<_Digraph, typename _Digraph::Arc, |
|
736 | 736 |
typename _Digraph::Node, 'o'>, typename _Digraph::OutArcIt>(); |
737 | 737 |
|
738 | 738 |
typename _Digraph::Node n; |
... | ... |
@@ -745,9 +745,9 @@ |
745 | 745 |
ignore_unused_variable_warning(n); |
746 | 746 |
} |
747 | 747 |
} |
748 |
|
|
749 |
const _Digraph& digraph; |
|
750 |
|
|
748 |
|
|
749 |
const _Digraph& digraph; |
|
750 |
|
|
751 | 751 |
}; |
752 | 752 |
}; |
753 | 753 |
|
... | ... |
@@ -765,13 +765,13 @@ |
765 | 765 |
typedef typename Base::Arc Arc; |
766 | 766 |
typedef typename Base::Edge Edge; |
767 | 767 |
|
768 |
|
|
768 |
|
|
769 | 769 |
typedef IterableGraphComponent Graph; |
770 | 770 |
|
771 | 771 |
/// \name Base iteration |
772 |
/// |
|
772 |
/// |
|
773 | 773 |
/// This interface provides functions for iteration on graph items |
774 |
/// @{ |
|
774 |
/// @{ |
|
775 | 775 |
|
776 | 776 |
using IterableDigraphComponent<_Base>::first; |
777 | 777 |
using IterableDigraphComponent<_Base>::next; |
... | ... |
@@ -780,14 +780,14 @@ |
780 | 780 |
/// order. |
781 | 781 |
/// |
782 | 782 |
/// Gives back the first edge in the iterating order. |
783 |
/// |
|
783 |
/// |
|
784 | 784 |
void first(Edge&) const {} |
785 | 785 |
|
786 | 786 |
/// \brief Gives back the next edge in the iterating |
787 | 787 |
/// order. |
788 | 788 |
/// |
789 | 789 |
/// Gives back the next edge in the iterating order. |
790 |
/// |
|
790 |
/// |
|
791 | 791 |
void next(Edge&) const {} |
792 | 792 |
|
793 | 793 |
|
... | ... |
@@ -814,7 +814,7 @@ |
814 | 814 |
/// @} |
815 | 815 |
|
816 | 816 |
/// \name Class based iteration |
817 |
/// |
|
817 |
/// |
|
818 | 818 |
/// This interface provides functions for iteration on graph items |
819 | 819 |
/// |
820 | 820 |
/// @{ |
... | ... |
@@ -841,10 +841,10 @@ |
841 | 841 |
|
842 | 842 |
/// @} |
843 | 843 |
|
844 |
template <typename _Graph> |
|
844 |
template <typename _Graph> |
|
845 | 845 |
struct Constraints { |
846 |
void constraints() { |
|
847 |
checkConcept<IterableDigraphComponent<Base>, _Graph>(); |
|
846 |
void constraints() { |
|
847 |
checkConcept<IterableDigraphComponent<Base>, _Graph>(); |
|
848 | 848 |
|
849 | 849 |
{ |
850 | 850 |
typename _Graph::Node node(INVALID); |
... | ... |
@@ -858,29 +858,29 @@ |
858 | 858 |
graph.firstInc(edge, dir, node); |
859 | 859 |
graph.nextInc(edge, dir); |
860 | 860 |
} |
861 |
|
|
862 |
} |
|
863 |
|
|
861 |
|
|
862 |
} |
|
863 |
|
|
864 | 864 |
{ |
865 | 865 |
checkConcept<GraphItemIt<_Graph, typename _Graph::Edge>, |
866 | 866 |
typename _Graph::EdgeIt >(); |
867 |
checkConcept<GraphIncIt<_Graph, typename _Graph::Edge, |
|
867 |
checkConcept<GraphIncIt<_Graph, typename _Graph::Edge, |
|
868 | 868 |
typename _Graph::Node, 'u'>, typename _Graph::IncEdgeIt>(); |
869 |
|
|
869 |
|
|
870 | 870 |
typename _Graph::Node n; |
871 | 871 |
typename _Graph::IncEdgeIt ueit(INVALID); |
872 | 872 |
n = graph.baseNode(ueit); |
873 | 873 |
n = graph.runningNode(ueit); |
874 | 874 |
} |
875 | 875 |
} |
876 |
|
|
877 |
const _Graph& graph; |
|
878 |
|
|
876 |
|
|
877 |
const _Graph& graph; |
|
878 |
|
|
879 | 879 |
}; |
880 | 880 |
}; |
881 | 881 |
|
882 | 882 |
/// \brief An empty alteration notifier digraph class. |
883 |
/// |
|
883 |
/// |
|
884 | 884 |
/// This class provides beside the core digraph features alteration |
885 | 885 |
/// notifier interface for the digraph structure. This implements |
886 | 886 |
/// an observer-notifier pattern for each digraph item. More |
... | ... |
@@ -897,48 +897,48 @@ |
897 | 897 |
|
898 | 898 |
|
899 | 899 |
/// The node observer registry. |
900 |
typedef AlterationNotifier<AlterableDigraphComponent, Node> |
|
900 |
typedef AlterationNotifier<AlterableDigraphComponent, Node> |
|
901 | 901 |
NodeNotifier; |
902 | 902 |
/// The arc observer registry. |
903 |
typedef AlterationNotifier<AlterableDigraphComponent, Arc> |
|
903 |
typedef AlterationNotifier<AlterableDigraphComponent, Arc> |
|
904 | 904 |
ArcNotifier; |
905 |
|
|
905 |
|
|
906 | 906 |
/// \brief Gives back the node alteration notifier. |
907 | 907 |
/// |
908 | 908 |
/// Gives back the node alteration notifier. |
909 | 909 |
NodeNotifier& notifier(Node) const { |
910 |
|
|
910 |
return NodeNotifier(); |
|
911 | 911 |
} |
912 |
|
|
912 |
|
|
913 | 913 |
/// \brief Gives back the arc alteration notifier. |
914 | 914 |
/// |
915 | 915 |
/// Gives back the arc alteration notifier. |
916 | 916 |
ArcNotifier& notifier(Arc) const { |
917 |
|
|
917 |
return ArcNotifier(); |
|
918 | 918 |
} |
919 | 919 |
|
920 |
template <typename _Digraph> |
|
920 |
template <typename _Digraph> |
|
921 | 921 |
struct Constraints { |
922 |
void constraints() { |
|
923 |
checkConcept<Base, _Digraph>(); |
|
924 |
|
|
922 |
void constraints() { |
|
923 |
checkConcept<Base, _Digraph>(); |
|
924 |
typename _Digraph::NodeNotifier& nn |
|
925 | 925 |
= digraph.notifier(typename _Digraph::Node()); |
926 | 926 |
|
927 |
typename _Digraph::ArcNotifier& en |
|
927 |
typename _Digraph::ArcNotifier& en |
|
928 | 928 |
= digraph.notifier(typename _Digraph::Arc()); |
929 |
|
|
929 |
|
|
930 | 930 |
ignore_unused_variable_warning(nn); |
931 | 931 |
ignore_unused_variable_warning(en); |
932 |
} |
|
933 |
|
|
934 |
const _Digraph& digraph; |
|
935 |
|
|
932 |
} |
|
933 |
|
|
934 |
const _Digraph& digraph; |
|
935 |
|
|
936 | 936 |
}; |
937 |
|
|
937 |
|
|
938 | 938 |
}; |
939 | 939 |
|
940 | 940 |
/// \brief An empty alteration notifier undirected graph class. |
941 |
/// |
|
941 |
/// |
|
942 | 942 |
/// This class provides beside the core graph features alteration |
943 | 943 |
/// notifier interface for the graph structure. This implements |
944 | 944 |
/// an observer-notifier pattern for each graph item. More |
... | ... |
@@ -954,33 +954,33 @@ |
954 | 954 |
|
955 | 955 |
|
956 | 956 |
/// The arc observer registry. |
957 |
typedef AlterationNotifier<AlterableGraphComponent, Edge> |
|
957 |
typedef AlterationNotifier<AlterableGraphComponent, Edge> |
|
958 | 958 |
EdgeNotifier; |
959 |
|
|
959 |
|
|
960 | 960 |
/// \brief Gives back the arc alteration notifier. |
961 | 961 |
/// |
962 | 962 |
/// Gives back the arc alteration notifier. |
963 | 963 |
EdgeNotifier& notifier(Edge) const { |
964 |
|
|
964 |
return EdgeNotifier(); |
|
965 | 965 |
} |
966 | 966 |
|
967 |
template <typename _Graph> |
|
967 |
template <typename _Graph> |
|
968 | 968 |
struct Constraints { |
969 |
void constraints() { |
|
970 |
checkConcept<AlterableGraphComponent<Base>, _Graph>(); |
|
971 |
|
|
969 |
void constraints() { |
|
970 |
checkConcept<AlterableGraphComponent<Base>, _Graph>(); |
|
971 |
typename _Graph::EdgeNotifier& uen |
|
972 | 972 |
= graph.notifier(typename _Graph::Edge()); |
973 | 973 |
ignore_unused_variable_warning(uen); |
974 |
} |
|
975 |
|
|
976 |
const _Graph& graph; |
|
977 |
|
|
974 |
} |
|
975 |
|
|
976 |
const _Graph& graph; |
|
977 |
|
|
978 | 978 |
}; |
979 |
|
|
979 |
|
|
980 | 980 |
}; |
981 | 981 |
|
982 | 982 |
/// \brief Class describing the concept of graph maps |
983 |
/// |
|
983 |
/// |
|
984 | 984 |
/// This class describes the common interface of the graph maps |
985 | 985 |
/// (NodeMap, ArcMap), that is \ref maps-page "maps" which can be used to |
986 | 986 |
/// associate data to graph descriptors (nodes or arcs). |
... | ... |
@@ -1009,39 +1009,39 @@ |
1009 | 1009 |
/// |
1010 | 1010 |
/// Copy Constructor. |
1011 | 1011 |
GraphMap(const GraphMap&) : Parent() {} |
1012 |
|
|
1012 |
|
|
1013 | 1013 |
/// \brief Assign operator. |
1014 | 1014 |
/// |
1015 | 1015 |
/// Assign operator. It does not mofify the underlying graph, |
1016 | 1016 |
/// it just iterates on the current item set and set the map |
1017 |
/// with the value returned by the assigned map. |
|
1017 |
/// with the value returned by the assigned map. |
|
1018 | 1018 |
template <typename CMap> |
1019 |
GraphMap& operator=(const CMap&) { |
|
1019 |
GraphMap& operator=(const CMap&) { |
|
1020 | 1020 |
checkConcept<ReadMap<Key, Value>, CMap>(); |
1021 | 1021 |
return *this; |
1022 | 1022 |
} |
1023 | 1023 |
|
1024 | 1024 |
template<typename _Map> |
1025 | 1025 |
struct Constraints { |
1026 |
void constraints() { |
|
1027 |
checkConcept<ReadWriteMap<Key, Value>, _Map >(); |
|
1028 |
// Construction with a graph parameter |
|
1029 |
_Map a(g); |
|
1030 |
// Constructor with a graph and a default value parameter |
|
1031 |
_Map a2(g,t); |
|
1032 |
// Copy constructor. |
|
1033 |
_Map b(c); |
|
1034 |
|
|
1026 |
void constraints() { |
|
1027 |
checkConcept<ReadWriteMap<Key, Value>, _Map >(); |
|
1028 |
// Construction with a graph parameter |
|
1029 |
_Map a(g); |
|
1030 |
// Constructor with a graph and a default value parameter |
|
1031 |
_Map a2(g,t); |
|
1032 |
// Copy constructor. |
|
1033 |
_Map b(c); |
|
1034 |
|
|
1035 | 1035 |
ReadMap<Key, Value> cmap; |
1036 | 1036 |
b = cmap; |
1037 | 1037 |
|
1038 |
ignore_unused_variable_warning(a2); |
|
1039 |
ignore_unused_variable_warning(b); |
|
1040 |
|
|
1038 |
ignore_unused_variable_warning(a2); |
|
1039 |
ignore_unused_variable_warning(b); |
|
1040 |
} |
|
1041 | 1041 |
|
1042 |
const _Map &c; |
|
1043 |
const Graph &g; |
|
1044 |
|
|
1042 |
const _Map &c; |
|
1043 |
const Graph &g; |
|
1044 |
const typename GraphMap::Value &t; |
|
1045 | 1045 |
}; |
1046 | 1046 |
|
1047 | 1047 |
}; |
... | ... |
@@ -1070,28 +1070,28 @@ |
1070 | 1070 |
public: |
1071 | 1071 |
typedef GraphMap<MappableDigraphComponent, Node, _Value> Parent; |
1072 | 1072 |
|
1073 |
/// \brief Construct a new map. |
|
1074 |
/// |
|
1075 |
/// Construct a new map for the digraph. |
|
1076 |
explicit NodeMap(const MappableDigraphComponent& digraph) |
|
1073 |
/// \brief Construct a new map. |
|
1074 |
/// |
|
1075 |
/// Construct a new map for the digraph. |
|
1076 |
explicit NodeMap(const MappableDigraphComponent& digraph) |
|
1077 | 1077 |
: Parent(digraph) {} |
1078 | 1078 |
|
1079 |
/// \brief Construct a new map with default value. |
|
1080 |
/// |
|
1081 |
/// Construct a new map for the digraph and initalise the values. |
|
1082 |
NodeMap(const MappableDigraphComponent& digraph, const _Value& value) |
|
1079 |
/// \brief Construct a new map with default value. |
|
1080 |
/// |
|
1081 |
/// Construct a new map for the digraph and initalise the values. |
|
1082 |
NodeMap(const MappableDigraphComponent& digraph, const _Value& value) |
|
1083 | 1083 |
: Parent(digraph, value) {} |
1084 | 1084 |
|
1085 |
/// \brief Copy constructor. |
|
1086 |
/// |
|
1087 |
/// Copy Constructor. |
|
1088 |
NodeMap(const NodeMap& nm) : Parent(nm) {} |
|
1085 |
/// \brief Copy constructor. |
|
1086 |
/// |
|
1087 |
/// Copy Constructor. |
|
1088 |
NodeMap(const NodeMap& nm) : Parent(nm) {} |
|
1089 | 1089 |
|
1090 |
/// \brief Assign operator. |
|
1091 |
/// |
|
1092 |
|
|
1090 |
/// \brief Assign operator. |
|
1091 |
/// |
|
1092 |
/// Assign operator. |
|
1093 | 1093 |
template <typename CMap> |
1094 |
NodeMap& operator=(const CMap&) { |
|
1094 |
NodeMap& operator=(const CMap&) { |
|
1095 | 1095 |
checkConcept<ReadMap<Node, _Value>, CMap>(); |
1096 | 1096 |
return *this; |
1097 | 1097 |
} |
... | ... |
@@ -1107,28 +1107,28 @@ |
1107 | 1107 |
public: |
1108 | 1108 |
typedef GraphMap<MappableDigraphComponent, Arc, _Value> Parent; |
1109 | 1109 |
|
1110 |
/// \brief Construct a new map. |
|
1111 |
/// |
|
1112 |
/// Construct a new map for the digraph. |
|
1113 |
explicit ArcMap(const MappableDigraphComponent& digraph) |
|
1110 |
/// \brief Construct a new map. |
|
1111 |
/// |
|
1112 |
/// Construct a new map for the digraph. |
|
1113 |
explicit ArcMap(const MappableDigraphComponent& digraph) |
|
1114 | 1114 |
: Parent(digraph) {} |
1115 | 1115 |
|
1116 |
/// \brief Construct a new map with default value. |
|
1117 |
/// |
|
1118 |
/// Construct a new map for the digraph and initalise the values. |
|
1119 |
ArcMap(const MappableDigraphComponent& digraph, const _Value& value) |
|
1116 |
/// \brief Construct a new map with default value. |
|
1117 |
/// |
|
1118 |
/// Construct a new map for the digraph and initalise the values. |
|
1119 |
ArcMap(const MappableDigraphComponent& digraph, const _Value& value) |
|
1120 | 1120 |
: Parent(digraph, value) {} |
1121 | 1121 |
|
1122 |
/// \brief Copy constructor. |
|
1123 |
/// |
|
1124 |
/// Copy Constructor. |
|
1125 |
ArcMap(const ArcMap& nm) : Parent(nm) {} |
|
1122 |
/// \brief Copy constructor. |
|
1123 |
/// |
|
1124 |
/// Copy Constructor. |
|
1125 |
ArcMap(const ArcMap& nm) : Parent(nm) {} |
|
1126 | 1126 |
|
1127 |
/// \brief Assign operator. |
|
1128 |
/// |
|
1129 |
|
|
1127 |
/// \brief Assign operator. |
|
1128 |
/// |
|
1129 |
/// Assign operator. |
|
1130 | 1130 |
template <typename CMap> |
1131 |
ArcMap& operator=(const CMap&) { |
|
1131 |
ArcMap& operator=(const CMap&) { |
|
1132 | 1132 |
checkConcept<ReadMap<Arc, _Value>, CMap>(); |
1133 | 1133 |
return *this; |
1134 | 1134 |
} |
... | ... |
@@ -1139,44 +1139,44 @@ |
1139 | 1139 |
template <typename _Digraph> |
1140 | 1140 |
struct Constraints { |
1141 | 1141 |
|
1142 |
struct Dummy { |
|
1143 |
int value; |
|
1144 |
Dummy() : value(0) {} |
|
1145 |
Dummy(int _v) : value(_v) {} |
|
1146 |
|
|
1142 |
struct Dummy { |
|
1143 |
int value; |
|
1144 |
Dummy() : value(0) {} |
|
1145 |
Dummy(int _v) : value(_v) {} |
|
1146 |
}; |
|
1147 | 1147 |
|
1148 |
void constraints() { |
|
1149 |
checkConcept<Base, _Digraph>(); |
|
1150 |
{ // int map test |
|
1151 |
typedef typename _Digraph::template NodeMap<int> IntNodeMap; |
|
1152 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>, |
|
1153 |
IntNodeMap >(); |
|
1154 |
} { // bool map test |
|
1155 |
typedef typename _Digraph::template NodeMap<bool> BoolNodeMap; |
|
1156 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>, |
|
1157 |
BoolNodeMap >(); |
|
1158 |
} { // Dummy map test |
|
1159 |
typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap; |
|
1160 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>, |
|
1161 |
DummyNodeMap >(); |
|
1162 |
|
|
1148 |
void constraints() { |
|
1149 |
checkConcept<Base, _Digraph>(); |
|
1150 |
{ // int map test |
|
1151 |
typedef typename _Digraph::template NodeMap<int> IntNodeMap; |
|
1152 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Node, int>, |
|
1153 |
IntNodeMap >(); |
|
1154 |
} { // bool map test |
|
1155 |
typedef typename _Digraph::template NodeMap<bool> BoolNodeMap; |
|
1156 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Node, bool>, |
|
1157 |
BoolNodeMap >(); |
|
1158 |
} { // Dummy map test |
|
1159 |
typedef typename _Digraph::template NodeMap<Dummy> DummyNodeMap; |
|
1160 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Node, Dummy>, |
|
1161 |
DummyNodeMap >(); |
|
1162 |
} |
|
1163 | 1163 |
|
1164 |
{ // int map test |
|
1165 |
typedef typename _Digraph::template ArcMap<int> IntArcMap; |
|
1166 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>, |
|
1167 |
IntArcMap >(); |
|
1168 |
} { // bool map test |
|
1169 |
typedef typename _Digraph::template ArcMap<bool> BoolArcMap; |
|
1170 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>, |
|
1171 |
BoolArcMap >(); |
|
1172 |
} { // Dummy map test |
|
1173 |
typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap; |
|
1174 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>, |
|
1175 |
DummyArcMap >(); |
|
1176 |
} |
|
1177 |
} |
|
1164 |
{ // int map test |
|
1165 |
typedef typename _Digraph::template ArcMap<int> IntArcMap; |
|
1166 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, int>, |
|
1167 |
IntArcMap >(); |
|
1168 |
} { // bool map test |
|
1169 |
typedef typename _Digraph::template ArcMap<bool> BoolArcMap; |
|
1170 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, bool>, |
|
1171 |
BoolArcMap >(); |
|
1172 |
} { // Dummy map test |
|
1173 |
typedef typename _Digraph::template ArcMap<Dummy> DummyArcMap; |
|
1174 |
checkConcept<GraphMap<_Digraph, typename _Digraph::Arc, Dummy>, |
|
1175 |
DummyArcMap >(); |
|
1176 |
} |
|
1177 |
} |
|
1178 | 1178 |
|
1179 |
|
|
1179 |
_Digraph& digraph; |
|
1180 | 1180 |
}; |
1181 | 1181 |
}; |
1182 | 1182 |
|
... | ... |
@@ -1199,32 +1199,32 @@ |
1199 | 1199 |
/// ReadWrite map of the edges. |
1200 | 1200 |
/// |
1201 | 1201 |
template <typename _Value> |
1202 |
class EdgeMap : public GraphMap<Graph, Edge, _Value> { |
|
1202 |
class EdgeMap : public GraphMap<Graph, Edge, _Value> { |
|
1203 | 1203 |
public: |
1204 | 1204 |
typedef GraphMap<MappableGraphComponent, Edge, _Value> Parent; |
1205 | 1205 |
|
1206 |
/// \brief Construct a new map. |
|
1207 |
/// |
|
1208 |
/// Construct a new map for the graph. |
|
1209 |
explicit EdgeMap(const MappableGraphComponent& graph) |
|
1206 |
/// \brief Construct a new map. |
|
1207 |
/// |
|
1208 |
/// Construct a new map for the graph. |
|
1209 |
explicit EdgeMap(const MappableGraphComponent& graph) |
|
1210 | 1210 |
: Parent(graph) {} |
1211 | 1211 |
|
1212 |
/// \brief Construct a new map with default value. |
|
1213 |
/// |
|
1214 |
/// Construct a new map for the graph and initalise the values. |
|
1215 |
EdgeMap(const MappableGraphComponent& graph, const _Value& value) |
|
1212 |
/// \brief Construct a new map with default value. |
|
1213 |
/// |
|
1214 |
/// Construct a new map for the graph and initalise the values. |
|
1215 |
EdgeMap(const MappableGraphComponent& graph, const _Value& value) |
|
1216 | 1216 |
: Parent(graph, value) {} |
1217 | 1217 |
|
1218 |
/// \brief Copy constructor. |
|
1219 |
/// |
|
1220 |
/// Copy Constructor. |
|
1221 |
EdgeMap(const EdgeMap& nm) : Parent(nm) {} |
|
1218 |
/// \brief Copy constructor. |
|
1219 |
/// |
|
1220 |
/// Copy Constructor. |
|
1221 |
EdgeMap(const EdgeMap& nm) : Parent(nm) {} |
|
1222 | 1222 |
|
1223 |
/// \brief Assign operator. |
|
1224 |
/// |
|
1225 |
|
|
1223 |
/// \brief Assign operator. |
|
1224 |
/// |
|
1225 |
/// Assign operator. |
|
1226 | 1226 |
template <typename CMap> |
1227 |
EdgeMap& operator=(const CMap&) { |
|
1227 |
EdgeMap& operator=(const CMap&) { |
|
1228 | 1228 |
checkConcept<ReadMap<Edge, _Value>, CMap>(); |
1229 | 1229 |
return *this; |
1230 | 1230 |
} |
... | ... |
@@ -1235,31 +1235,31 @@ |
1235 | 1235 |
template <typename _Graph> |
1236 | 1236 |
struct Constraints { |
1237 | 1237 |
|
1238 |
struct Dummy { |
|
1239 |
int value; |
|
1240 |
Dummy() : value(0) {} |
|
1241 |
Dummy(int _v) : value(_v) {} |
|
1242 |
|
|
1238 |
struct Dummy { |
|
1239 |
int value; |
|
1240 |
Dummy() : value(0) {} |
|
1241 |
Dummy(int _v) : value(_v) {} |
|
1242 |
}; |
|
1243 | 1243 |
|
1244 |
void constraints() { |
|
1245 |
checkConcept<MappableGraphComponent<Base>, _Graph>(); |
|
1244 |
void constraints() { |
|
1245 |
checkConcept<MappableGraphComponent<Base>, _Graph>(); |
|
1246 | 1246 |
|
1247 |
{ // int map test |
|
1248 |
typedef typename _Graph::template EdgeMap<int> IntEdgeMap; |
|
1249 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>, |
|
1250 |
IntEdgeMap >(); |
|
1251 |
} { // bool map test |
|
1252 |
typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap; |
|
1253 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>, |
|
1254 |
BoolEdgeMap >(); |
|
1255 |
} { // Dummy map test |
|
1256 |
typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap; |
|
1257 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>, |
|
1258 |
DummyEdgeMap >(); |
|
1259 |
} |
|
1260 |
} |
|
1247 |
{ // int map test |
|
1248 |
typedef typename _Graph::template EdgeMap<int> IntEdgeMap; |
|
1249 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, int>, |
|
1250 |
IntEdgeMap >(); |
|
1251 |
} { // bool map test |
|
1252 |
typedef typename _Graph::template EdgeMap<bool> BoolEdgeMap; |
|
1253 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, bool>, |
|
1254 |
BoolEdgeMap >(); |
|
1255 |
} { // Dummy map test |
|
1256 |
typedef typename _Graph::template EdgeMap<Dummy> DummyEdgeMap; |
|
1257 |
checkConcept<GraphMap<_Graph, typename _Graph::Edge, Dummy>, |
|
1258 |
DummyEdgeMap >(); |
|
1259 |
} |
|
1260 |
} |
|
1261 | 1261 |
|
1262 |
|
|
1262 |
_Graph& graph; |
|
1263 | 1263 |
}; |
1264 | 1264 |
}; |
1265 | 1265 |
|
... | ... |
@@ -1282,28 +1282,28 @@ |
1282 | 1282 |
/// Adds a new node to the digraph. |
1283 | 1283 |
/// |
1284 | 1284 |
Node addNode() { |
1285 |
|
|
1285 |
return INVALID; |
|
1286 | 1286 |
} |
1287 |
|
|
1287 |
|
|
1288 | 1288 |
/// \brief Adds a new arc connects the given two nodes. |
1289 | 1289 |
/// |
1290 | 1290 |
/// Adds a new arc connects the the given two nodes. |
1291 | 1291 |
Arc addArc(const Node&, const Node&) { |
1292 |
|
|
1292 |
return INVALID; |
|
1293 | 1293 |
} |
1294 | 1294 |
|
1295 | 1295 |
template <typename _Digraph> |
1296 | 1296 |
struct Constraints { |
1297 |
|
|
1297 |
void constraints() { |
|
1298 | 1298 |
checkConcept<Base, _Digraph>(); |
1299 |
typename _Digraph::Node node_a, node_b; |
|
1300 |
node_a = digraph.addNode(); |
|
1301 |
node_b = digraph.addNode(); |
|
1302 |
typename _Digraph::Arc arc; |
|
1303 |
arc = digraph.addArc(node_a, node_b); |
|
1304 |
} |
|
1299 |
typename _Digraph::Node node_a, node_b; |
|
1300 |
node_a = digraph.addNode(); |
|
1301 |
node_b = digraph.addNode(); |
|
1302 |
typename _Digraph::Arc arc; |
|
1303 |
arc = digraph.addArc(node_a, node_b); |
|
1304 |
} |
|
1305 | 1305 |
|
1306 |
|
|
1306 |
_Digraph& digraph; |
|
1307 | 1307 |
}; |
1308 | 1308 |
}; |
1309 | 1309 |
|
... | ... |
@@ -1327,33 +1327,33 @@ |
1327 | 1327 |
/// Adds a new node to the graph. |
1328 | 1328 |
/// |
1329 | 1329 |
Node addNode() { |
1330 |
|
|
1330 |
return INVALID; |
|
1331 | 1331 |
} |
1332 |
|
|
1332 |
|
|
1333 | 1333 |
/// \brief Adds a new arc connects the given two nodes. |
1334 | 1334 |
/// |
1335 | 1335 |
/// Adds a new arc connects the the given two nodes. |
1336 | 1336 |
Edge addArc(const Node&, const Node&) { |
1337 |
|
|
1337 |
return INVALID; |
|
1338 | 1338 |
} |
1339 | 1339 |
|
1340 | 1340 |
template <typename _Graph> |
1341 | 1341 |
struct Constraints { |
1342 |
void constraints() { |
|
1343 |
checkConcept<Base, _Graph>(); |
|
1344 |
typename _Graph::Node node_a, node_b; |
|
1345 |
node_a = graph.addNode(); |
|
1346 |
node_b = graph.addNode(); |
|
1347 |
typename _Graph::Edge edge; |
|
1348 |
edge = graph.addEdge(node_a, node_b); |
|
1349 |
} |
|
1342 |
void constraints() { |
|
1343 |
checkConcept<Base, _Graph>(); |
|
1344 |
typename _Graph::Node node_a, node_b; |
|
1345 |
node_a = graph.addNode(); |
|
1346 |
node_b = graph.addNode(); |
|
1347 |
typename _Graph::Edge edge; |
|
1348 |
edge = graph.addEdge(node_a, node_b); |
|
1349 |
} |
|
1350 | 1350 |
|
1351 |
|
|
1351 |
_Graph& graph; |
|
1352 | 1352 |
}; |
1353 | 1353 |
}; |
1354 | 1354 |
|
1355 | 1355 |
/// \brief An empty erasable digraph class. |
1356 |
/// |
|
1356 |
/// |
|
1357 | 1357 |
/// This class provides beside the core digraph features core erase |
1358 | 1358 |
/// functions for the digraph structure. The main difference between |
1359 | 1359 |
/// the base and this interface is that the digraph alterations |
... | ... |
@@ -1368,9 +1368,9 @@ |
1368 | 1368 |
|
1369 | 1369 |
/// \brief Erase a node from the digraph. |
1370 | 1370 |
/// |
1371 |
/// Erase a node from the digraph. This function should |
|
1371 |
/// Erase a node from the digraph. This function should |
|
1372 | 1372 |
/// erase all arcs connecting to the node. |
1373 |
void erase(const Node&) {} |
|
1373 |
void erase(const Node&) {} |
|
1374 | 1374 |
|
1375 | 1375 |
/// \brief Erase an arc from the digraph. |
1376 | 1376 |
/// |
... | ... |
@@ -1380,20 +1380,20 @@ |
1380 | 1380 |
|
1381 | 1381 |
template <typename _Digraph> |
1382 | 1382 |
struct Constraints { |
1383 |
|
|
1383 |
void constraints() { |
|
1384 | 1384 |
checkConcept<Base, _Digraph>(); |
1385 |
typename _Digraph::Node node; |
|
1386 |
digraph.erase(node); |
|
1387 |
typename _Digraph::Arc arc; |
|
1388 |
digraph.erase(arc); |
|
1389 |
|
|
1385 |
typename _Digraph::Node node; |
|
1386 |
digraph.erase(node); |
|
1387 |
typename _Digraph::Arc arc; |
|
1388 |
digraph.erase(arc); |
|
1389 |
} |
|
1390 | 1390 |
|
1391 |
|
|
1391 |
_Digraph& digraph; |
|
1392 | 1392 |
}; |
1393 | 1393 |
}; |
1394 | 1394 |
|
1395 | 1395 |
/// \brief An empty erasable base undirected graph class. |
1396 |
/// |
|
1396 |
/// |
|
1397 | 1397 |
/// This class provides beside the core undirected graph features |
1398 | 1398 |
/// core erase functions for the undirceted graph structure. The |
1399 | 1399 |
/// main difference between the base and this interface is that |
... | ... |
@@ -1410,7 +1410,7 @@ |
1410 | 1410 |
/// |
1411 | 1411 |
/// Erase a node from the graph. This function should erase |
1412 | 1412 |
/// arcs connecting to the node. |
1413 |
void erase(const Node&) {} |
|
1413 |
void erase(const Node&) {} |
|
1414 | 1414 |
|
1415 | 1415 |
/// \brief Erase an arc from the graph. |
1416 | 1416 |
/// |
... | ... |
@@ -1420,15 +1420,15 @@ |
1420 | 1420 |
|
1421 | 1421 |
template <typename _Graph> |
1422 | 1422 |
struct Constraints { |
1423 |
|
|
1423 |
void constraints() { |
|
1424 | 1424 |
checkConcept<Base, _Graph>(); |
1425 |
typename _Graph::Node node; |
|
1426 |
graph.erase(node); |
|
1427 |
typename _Graph::Edge edge; |
|
1428 |
graph.erase(edge); |
|
1429 |
|
|
1425 |
typename _Graph::Node node; |
|
1426 |
graph.erase(node); |
|
1427 |
typename _Graph::Edge edge; |
|
1428 |
graph.erase(edge); |
|
1429 |
} |
|
1430 | 1430 |
|
1431 |
|
|
1431 |
_Graph& graph; |
|
1432 | 1432 |
}; |
1433 | 1433 |
}; |
1434 | 1434 |
|
... | ... |
@@ -1448,16 +1448,16 @@ |
1448 | 1448 |
/// |
1449 | 1449 |
/// Erase all nodes and arcs from the digraph. |
1450 | 1450 |
/// |
1451 |
void clear() {} |
|
1451 |
void clear() {} |
|
1452 | 1452 |
|
1453 | 1453 |
template <typename _Digraph> |
1454 | 1454 |
struct Constraints { |
1455 |
|
|
1455 |
void constraints() { |
|
1456 | 1456 |
checkConcept<Base, _Digraph>(); |
1457 |
digraph.clear(); |
|
1458 |
} |
|
1457 |
digraph.clear(); |
|
1458 |
} |
|
1459 | 1459 |
|
1460 |
|
|
1460 |
_Digraph digraph; |
|
1461 | 1461 |
}; |
1462 | 1462 |
}; |
1463 | 1463 |
|
... | ... |
@@ -1475,11 +1475,11 @@ |
1475 | 1475 |
|
1476 | 1476 |
template <typename _Graph> |
1477 | 1477 |
struct Constraints { |
1478 |
|
|
1478 |
void constraints() { |
|
1479 | 1479 |
checkConcept<ClearableGraphComponent<Base>, _Graph>(); |
1480 |
|
|
1480 |
} |
|
1481 | 1481 |
|
1482 |
|
|
1482 |
_Graph graph; |
|
1483 | 1483 |
}; |
1484 | 1484 |
}; |
1485 | 1485 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 | 4 |
* |
5 | 5 |
* Copyright (C) 2003-2008 |
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
... | ... |
@@ -52,14 +52,14 @@ |
52 | 52 |
/// from the point of view of the heap, but may be useful for |
53 | 53 |
/// the user. |
54 | 54 |
/// |
55 |
/// The \c ItemIntMap must be initialized in such a way, that it |
|
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 |
IN_HEAP = 0, |
|
59 |
PRE_HEAP = -1, |
|
60 |
|
|
58 |
IN_HEAP = 0, |
|
59 |
PRE_HEAP = -1, |
|
60 |
POST_HEAP = -2 |
|
61 | 61 |
}; |
62 |
|
|
62 |
|
|
63 | 63 |
/// \brief The constructor. |
64 | 64 |
/// |
65 | 65 |
/// The constructor. |
... | ... |
@@ -85,8 +85,8 @@ |
85 | 85 |
void clear(); |
86 | 86 |
|
87 | 87 |
/// \brief Inserts an item into the heap with the given priority. |
88 |
/// |
|
89 |
/// Inserts the given item into the heap with the given priority. |
|
88 |
/// |
|
89 |
/// Inserts the given item into the heap with the given priority. |
|
90 | 90 |
/// \param i The item to insert. |
91 | 91 |
/// \param p The priority of the item. |
92 | 92 |
void push(const Item &i, const Prio &p) {} |
... | ... |
@@ -112,12 +112,12 @@ |
112 | 112 |
/// \brief Removes an item from the heap. |
113 | 113 |
/// |
114 | 114 |
/// Removes the given item from the heap if it is already stored. |
115 |
/// \param i The item to delete. |
|
115 |
/// \param i The item to delete. |
|
116 | 116 |
void erase(const Item &i) {} |
117 | 117 |
|
118 | 118 |
/// \brief The priority of an item. |
119 | 119 |
/// |
120 |
/// Returns the priority of the given item. |
|
120 |
/// Returns the priority of the given item. |
|
121 | 121 |
/// \pre \c i must be in the heap. |
122 | 122 |
/// \param i The item. |
123 | 123 |
Prio operator[](const Item &i) const {} |
... | ... |
@@ -133,7 +133,7 @@ |
133 | 133 |
/// \param i The item. |
134 | 134 |
/// \param p The priority. |
135 | 135 |
void set(const Item &i, const Prio &p) {} |
136 |
|
|
136 |
|
|
137 | 137 |
/// \brief Decreases the priority of an item to the given value. |
138 | 138 |
/// |
139 | 139 |
/// Decreases the priority of an item to the given value. |
... | ... |
@@ -174,69 +174,69 @@ |
174 | 174 |
template <typename _Heap> |
175 | 175 |
struct Constraints { |
176 | 176 |
public: |
177 |
void constraints() { |
|
178 |
typedef typename _Heap::Item OwnItem; |
|
179 |
typedef typename _Heap::Prio OwnPrio; |
|
180 |
typedef typename _Heap::State OwnState; |
|
177 |
void constraints() { |
|
178 |
typedef typename _Heap::Item OwnItem; |
|
179 |
typedef typename _Heap::Prio OwnPrio; |
|
180 |
typedef typename _Heap::State OwnState; |
|
181 | 181 |
|
182 |
Item item; |
|
183 |
Prio prio; |
|
184 |
item=Item(); |
|
185 |
prio=Prio(); |
|
186 |
ignore_unused_variable_warning(item); |
|
187 |
ignore_unused_variable_warning(prio); |
|
182 |
Item item; |
|
183 |
Prio prio; |
|
184 |
item=Item(); |
|
185 |
prio=Prio(); |
|
186 |
ignore_unused_variable_warning(item); |
|
187 |
ignore_unused_variable_warning(prio); |
|
188 | 188 |
|
189 |
OwnItem own_item; |
|
190 |
OwnPrio own_prio; |
|
191 |
OwnState own_state; |
|
192 |
own_item=Item(); |
|
193 |
own_prio=Prio(); |
|
194 |
ignore_unused_variable_warning(own_item); |
|
195 |
ignore_unused_variable_warning(own_prio); |
|
196 |
ignore_unused_variable_warning(own_state); |
|
189 |
OwnItem own_item; |
|
190 |
OwnPrio own_prio; |
|
191 |
OwnState own_state; |
|
192 |
own_item=Item(); |
|
193 |
own_prio=Prio(); |
|
194 |
ignore_unused_variable_warning(own_item); |
|
195 |
ignore_unused_variable_warning(own_prio); |
|
196 |
ignore_unused_variable_warning(own_state); |
|
197 | 197 |
|
198 |
_Heap heap1(map); |
|
199 |
_Heap heap2 = heap1; |
|
200 |
ignore_unused_variable_warning(heap1); |
|
201 |
ignore_unused_variable_warning(heap2); |
|
202 |
|
|
203 |
int s = heap.size(); |
|
204 |
ignore_unused_variable_warning(s); |
|
205 |
bool e = heap.empty(); |
|
206 |
|
|
198 |
_Heap heap1(map); |
|
199 |
_Heap heap2 = heap1; |
|
200 |
ignore_unused_variable_warning(heap1); |
|
201 |
ignore_unused_variable_warning(heap2); |
|
207 | 202 |
|
208 |
prio = heap.prio(); |
|
209 |
item = heap.top(); |
|
210 |
prio = heap[item]; |
|
211 |
own_prio = heap.prio(); |
|
212 |
own_item = heap.top(); |
|
213 |
own_prio = heap[own_item]; |
|
203 |
int s = heap.size(); |
|
204 |
ignore_unused_variable_warning(s); |
|
205 |
bool e = heap.empty(); |
|
206 |
ignore_unused_variable_warning(e); |
|
214 | 207 |
|
215 |
heap.push(item, prio); |
|
216 |
heap.push(own_item, own_prio); |
|
217 |
|
|
208 |
prio = heap.prio(); |
|
209 |
item = heap.top(); |
|
210 |
prio = heap[item]; |
|
211 |
own_prio = heap.prio(); |
|
212 |
own_item = heap.top(); |
|
213 |
own_prio = heap[own_item]; |
|
218 | 214 |
|
219 |
heap.set(item, prio); |
|
220 |
heap.decrease(item, prio); |
|
221 |
heap.increase(item, prio); |
|
222 |
heap.set(own_item, own_prio); |
|
223 |
heap.decrease(own_item, own_prio); |
|
224 |
heap.increase(own_item, own_prio); |
|
215 |
heap.push(item, prio); |
|
216 |
heap.push(own_item, own_prio); |
|
217 |
heap.pop(); |
|
225 | 218 |
|
226 |
heap.erase(item); |
|
227 |
heap.erase(own_item); |
|
228 |
|
|
219 |
heap.set(item, prio); |
|
220 |
heap.decrease(item, prio); |
|
221 |
heap.increase(item, prio); |
|
222 |
heap.set(own_item, own_prio); |
|
223 |
heap.decrease(own_item, own_prio); |
|
224 |
heap.increase(own_item, own_prio); |
|
229 | 225 |
|
230 |
own_state = heap.state(own_item); |
|
231 |
heap.state(own_item, own_state); |
|
226 |
heap.erase(item); |
|
227 |
heap.erase(own_item); |
|
228 |
heap.clear(); |
|
232 | 229 |
|
233 |
own_state = _Heap::PRE_HEAP; |
|
234 |
own_state = _Heap::IN_HEAP; |
|
235 |
own_state = _Heap::POST_HEAP; |
|
236 |
} |
|
230 |
own_state = heap.state(own_item); |
|
231 |
heap.state(own_item, own_state); |
|
237 | 232 |
|
238 |
_Heap& heap; |
|
239 |
ItemIntMap& map; |
|
233 |
own_state = _Heap::PRE_HEAP; |
|
234 |
own_state = _Heap::IN_HEAP; |
|
235 |
own_state = _Heap::POST_HEAP; |
|
236 |
} |
|
237 |
|
|
238 |
_Heap& heap; |
|
239 |
ItemIntMap& map; |
|
240 | 240 |
}; |
241 | 241 |
}; |
242 | 242 |
Changeset was too big and was cut off... Show full diff
0 comments (0 inline)