0
14
0
6
3
6
3
14
11
19
10
44
22
... | ... |
@@ -60,65 +60,66 @@ |
60 | 60 |
The source code files use the same style and they have '.cc' extension. |
61 | 61 |
|
62 | 62 |
\code |
63 | 63 |
source_code.cc |
64 | 64 |
\endcode |
65 | 65 |
|
66 | 66 |
\subsection cs-class Classes and other types |
67 | 67 |
|
68 | 68 |
The name of a class or any type should look like the following. |
69 | 69 |
|
70 | 70 |
\code |
71 | 71 |
AllWordsCapitalizedWithoutUnderscores |
72 | 72 |
\endcode |
73 | 73 |
|
74 | 74 |
\subsection cs-func Methods and other functions |
75 | 75 |
|
76 | 76 |
The name of a function should look like the following. |
77 | 77 |
|
78 | 78 |
\code |
79 | 79 |
firstWordLowerCaseRestCapitalizedWithoutUnderscores |
80 | 80 |
\endcode |
81 | 81 |
|
82 | 82 |
\subsection cs-funcs Constants, Macros |
83 | 83 |
|
84 | 84 |
The names of constants and macros should look like the following. |
85 | 85 |
|
86 | 86 |
\code |
87 | 87 |
ALL_UPPER_CASE_WITH_UNDERSCORES |
88 | 88 |
\endcode |
89 | 89 |
|
90 | 90 |
\subsection cs-loc-var Class and instance member variables, auto variables |
91 | 91 |
|
92 |
The names of class and instance member variables and auto variables |
|
92 |
The names of class and instance member variables and auto variables |
|
93 |
(=variables used locally in methods) should look like the following. |
|
93 | 94 |
|
94 | 95 |
\code |
95 | 96 |
all_lower_case_with_underscores |
96 | 97 |
\endcode |
97 | 98 |
|
98 | 99 |
\subsection pri-loc-var Private member variables |
99 | 100 |
|
100 | 101 |
Private member variables should start with underscore |
101 | 102 |
|
102 | 103 |
\code |
103 | 104 |
_start_with_underscores |
104 | 105 |
\endcode |
105 | 106 |
|
106 | 107 |
\subsection cs-excep Exceptions |
107 | 108 |
|
108 | 109 |
When writing exceptions please comply the following naming conventions. |
109 | 110 |
|
110 | 111 |
\code |
111 | 112 |
ClassNameEndsWithException |
112 | 113 |
\endcode |
113 | 114 |
|
114 | 115 |
or |
115 | 116 |
|
116 | 117 |
\code |
117 | 118 |
ClassNameEndsWithError |
118 | 119 |
\endcode |
119 | 120 |
|
120 | 121 |
\section header-template Template Header File |
121 | 122 |
|
122 | 123 |
Each LEMON header file should look like this: |
123 | 124 |
|
124 | 125 |
\include template.h |
... | ... |
@@ -198,138 +198,141 @@ |
198 | 198 |
/** |
199 | 199 |
@defgroup search Graph Search |
200 | 200 |
@ingroup algs |
201 | 201 |
\brief Common graph search algorithms. |
202 | 202 |
|
203 | 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 |
|
207 | 207 |
/** |
208 | 208 |
@defgroup shortest_path Shortest Path algorithms |
209 | 209 |
@ingroup algs |
210 | 210 |
\brief Algorithms for finding shortest paths. |
211 | 211 |
|
212 | 212 |
This group describes the algorithms for finding shortest paths in graphs. |
213 | 213 |
*/ |
214 | 214 |
|
215 | 215 |
/** |
216 | 216 |
@defgroup max_flow Maximum Flow algorithms |
217 | 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 |
221 | 221 |
feasible circulations. |
222 | 222 |
|
223 | 223 |
The maximum flow problem is to find a flow between a single source and |
224 | 224 |
a single target that is maximum. Formally, there is a \f$G=(V,A)\f$ |
225 | 225 |
directed graph, an \f$c_a:A\rightarrow\mathbf{R}^+_0\f$ capacity |
226 | 226 |
function and given \f$s, t \in V\f$ source and target node. The |
227 | 227 |
maximum flow is the \f$f_a\f$ solution of the next optimization problem: |
228 | 228 |
|
229 | 229 |
\f[ 0 \le f_a \le c_a \f] |
230 |
\f[ \sum_{v\in\delta^{-}(u)}f_{vu}=\sum_{v\in\delta^{+}(u)}f_{uv} |
|
230 |
\f[ \sum_{v\in\delta^{-}(u)}f_{vu}=\sum_{v\in\delta^{+}(u)}f_{uv} |
|
231 |
\qquad \forall u \in V \setminus \{s,t\}\f] |
|
231 | 232 |
\f[ \max \sum_{v\in\delta^{+}(s)}f_{uv} - \sum_{v\in\delta^{-}(s)}f_{vu}\f] |
232 | 233 |
|
233 | 234 |
LEMON contains several algorithms for solving maximum flow problems: |
234 | 235 |
- \ref lemon::EdmondsKarp "Edmonds-Karp" |
235 | 236 |
- \ref lemon::Preflow "Goldberg's Preflow algorithm" |
236 | 237 |
- \ref lemon::DinitzSleatorTarjan "Dinitz's blocking flow algorithm with dynamic trees" |
237 | 238 |
- \ref lemon::GoldbergTarjan "Preflow algorithm with dynamic trees" |
238 | 239 |
|
239 | 240 |
In most cases the \ref lemon::Preflow "Preflow" algorithm provides the |
240 | 241 |
fastest method to compute the maximum flow. All impelementations |
241 | 242 |
provides functions to query the minimum cut, which is the dual linear |
242 | 243 |
programming problem of the maximum flow. |
243 | 244 |
|
244 | 245 |
*/ |
245 | 246 |
|
246 | 247 |
/** |
247 | 248 |
@defgroup min_cost_flow Minimum Cost Flow algorithms |
248 | 249 |
@ingroup algs |
249 | 250 |
|
250 | 251 |
\brief Algorithms for finding minimum cost flows and circulations. |
251 | 252 |
|
252 | 253 |
This group describes the algorithms for finding minimum cost flows and |
253 | 254 |
circulations. |
254 | 255 |
*/ |
255 | 256 |
|
256 | 257 |
/** |
257 | 258 |
@defgroup min_cut Minimum Cut algorithms |
258 | 259 |
@ingroup algs |
259 | 260 |
|
260 | 261 |
\brief Algorithms for finding minimum cut in graphs. |
261 | 262 |
|
262 | 263 |
This group describes the algorithms for finding minimum cut in graphs. |
263 | 264 |
|
264 | 265 |
The minimum cut problem is to find a non-empty and non-complete |
265 | 266 |
\f$X\f$ subset of the vertices with minimum overall capacity on |
266 | 267 |
outgoing arcs. Formally, there is \f$G=(V,A)\f$ directed graph, an |
267 | 268 |
\f$c_a:A\rightarrow\mathbf{R}^+_0\f$ capacity function. The minimum |
268 | 269 |
cut is the \f$X\f$ solution of the next optimization problem: |
269 | 270 |
|
270 |
\f[ \min_{X \subset V, X\not\in \{\emptyset, V\}} |
|
271 |
\f[ \min_{X \subset V, X\not\in \{\emptyset, V\}} |
|
272 |
\sum_{uv\in A, u\in X, v\not\in X}c_{uv}\f] |
|
271 | 273 |
|
272 | 274 |
LEMON contains several algorithms related to minimum cut problems: |
273 | 275 |
|
274 | 276 |
- \ref lemon::HaoOrlin "Hao-Orlin algorithm" to calculate minimum cut |
275 | 277 |
in directed graphs |
276 | 278 |
- \ref lemon::NagamochiIbaraki "Nagamochi-Ibaraki algorithm" to |
277 | 279 |
calculate minimum cut in undirected graphs |
278 | 280 |
- \ref lemon::GomoryHuTree "Gomory-Hu tree computation" to calculate all |
279 | 281 |
pairs minimum cut in undirected graphs |
280 | 282 |
|
281 | 283 |
If you want to find minimum cut just between two distinict nodes, |
282 | 284 |
please see the \ref max_flow "Maximum Flow page". |
283 | 285 |
|
284 | 286 |
*/ |
285 | 287 |
|
286 | 288 |
/** |
287 | 289 |
@defgroup graph_prop Connectivity and other graph properties |
288 | 290 |
@ingroup algs |
289 | 291 |
\brief Algorithms for discovering the graph properties |
290 | 292 |
|
291 | 293 |
This group describes the algorithms for discovering the graph properties |
292 | 294 |
like connectivity, bipartiteness, euler property, simplicity etc. |
293 | 295 |
|
294 | 296 |
\image html edge_biconnected_components.png |
295 | 297 |
\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth |
296 | 298 |
*/ |
297 | 299 |
|
298 | 300 |
/** |
299 | 301 |
@defgroup planar Planarity embedding and drawing |
300 | 302 |
@ingroup algs |
301 | 303 |
\brief Algorithms for planarity checking, embedding and drawing |
302 | 304 |
|
303 |
This group describes the algorithms for planarity checking, |
|
305 |
This group describes the algorithms for planarity checking, |
|
306 |
embedding and drawing. |
|
304 | 307 |
|
305 | 308 |
\image html planar.png |
306 | 309 |
\image latex planar.eps "Plane graph" width=\textwidth |
307 | 310 |
*/ |
308 | 311 |
|
309 | 312 |
/** |
310 | 313 |
@defgroup matching Matching algorithms |
311 | 314 |
@ingroup algs |
312 | 315 |
\brief Algorithms for finding matchings in graphs and bipartite graphs. |
313 | 316 |
|
314 | 317 |
This group contains algorithm objects and functions to calculate |
315 | 318 |
matchings in graphs and bipartite graphs. The general matching problem is |
316 | 319 |
finding a subset of the arcs which does not shares common endpoints. |
317 | 320 |
|
318 | 321 |
There are several different algorithms for calculate matchings in |
319 | 322 |
graphs. The matching problems in bipartite graphs are generally |
320 | 323 |
easier than in general graphs. The goal of the matching optimization |
321 | 324 |
can be the finding maximum cardinality, maximum weight or minimum cost |
322 | 325 |
matching. The search can be constrained to find perfect or |
323 | 326 |
maximum cardinality matching. |
324 | 327 |
|
325 | 328 |
Lemon contains the next algorithms: |
326 | 329 |
- \ref lemon::MaxBipartiteMatching "MaxBipartiteMatching" Hopcroft-Karp |
327 | 330 |
augmenting path algorithm for calculate maximum cardinality matching in |
328 | 331 |
bipartite graphs |
329 | 332 |
- \ref lemon::PrBipartiteMatching "PrBipartiteMatching" Push-Relabel |
330 | 333 |
algorithm for calculate maximum cardinality matching in bipartite graphs |
331 | 334 |
- \ref lemon::MaxWeightedBipartiteMatching "MaxWeightedBipartiteMatching" |
332 | 335 |
Successive shortest path algorithm for calculate maximum weighted matching |
333 | 336 |
and maximum weighted bipartite matching in bipartite graph |
334 | 337 |
- \ref lemon::MinCostMaxBipartiteMatching "MinCostMaxBipartiteMatching" |
335 | 338 |
Successive shortest path algorithm for calculate minimum cost maximum |
... | ... |
@@ -448,65 +451,66 @@ |
448 | 451 |
|
449 | 452 |
/** |
450 | 453 |
@defgroup graphbits Tools for Graph Implementation |
451 | 454 |
@ingroup utils |
452 | 455 |
\brief Tools to make it easier to create graphs. |
453 | 456 |
|
454 | 457 |
This group describes the tools that makes it easier to create graphs and |
455 | 458 |
the maps that dynamically update with the graph changes. |
456 | 459 |
*/ |
457 | 460 |
|
458 | 461 |
/** |
459 | 462 |
@defgroup exceptions Exceptions |
460 | 463 |
@ingroup utils |
461 | 464 |
\brief Exceptions defined in LEMON. |
462 | 465 |
|
463 | 466 |
This group describes the exceptions defined in LEMON. |
464 | 467 |
*/ |
465 | 468 |
|
466 | 469 |
/** |
467 | 470 |
@defgroup io_group Input-Output |
468 | 471 |
\brief Graph Input-Output methods |
469 | 472 |
|
470 | 473 |
This group describes the tools for importing and exporting graphs |
471 | 474 |
and graph related data. Now it supports the LEMON format, the |
472 | 475 |
\c DIMACS format and the encapsulated postscript (EPS) format. |
473 | 476 |
*/ |
474 | 477 |
|
475 | 478 |
/** |
476 | 479 |
@defgroup lemon_io Lemon Input-Output |
477 | 480 |
@ingroup io_group |
478 | 481 |
\brief Reading and writing \ref lgf-format "Lemon Graph Format". |
479 | 482 |
|
480 |
This group describes methods for reading and writing |
|
483 |
This group describes methods for reading and writing |
|
484 |
\ref lgf-format "Lemon Graph Format". |
|
481 | 485 |
*/ |
482 | 486 |
|
483 | 487 |
/** |
484 | 488 |
@defgroup eps_io Postscript exporting |
485 | 489 |
@ingroup io_group |
486 | 490 |
\brief General \c EPS drawer and graph exporter |
487 | 491 |
|
488 | 492 |
This group describes general \c EPS drawing methods and special |
489 | 493 |
graph exporting tools. |
490 | 494 |
*/ |
491 | 495 |
|
492 | 496 |
|
493 | 497 |
/** |
494 | 498 |
@defgroup concept Concepts |
495 | 499 |
\brief Skeleton classes and concept checking classes |
496 | 500 |
|
497 | 501 |
This group describes the data/algorithm skeletons and concept checking |
498 | 502 |
classes implemented in LEMON. |
499 | 503 |
|
500 | 504 |
The purpose of the classes in this group is fourfold. |
501 | 505 |
|
502 | 506 |
- These classes contain the documentations of the concepts. In order |
503 | 507 |
to avoid document multiplications, an implementation of a concept |
504 | 508 |
simply refers to the corresponding concept class. |
505 | 509 |
|
506 | 510 |
- These classes declare every functions, <tt>typedef</tt>s etc. an |
507 | 511 |
implementation of the concepts should provide, however completely |
508 | 512 |
without implementations and real data structures behind the |
509 | 513 |
interface. On the other hand they should provide nothing else. All |
510 | 514 |
the algorithms working on a data structure meeting a certain concept |
511 | 515 |
should compile with these classes. (Though it will not run properly, |
512 | 516 |
of course.) In this way it is easily to check if an algorithm |
... | ... |
@@ -366,74 +366,74 @@ |
366 | 366 |
break; |
367 | 367 |
case DOUBLE: |
368 | 368 |
std::cerr << " floating point"; |
369 | 369 |
break; |
370 | 370 |
default: |
371 | 371 |
break; |
372 | 372 |
} |
373 | 373 |
std::cerr << " value\n\n"; |
374 | 374 |
showHelp(); |
375 | 375 |
} |
376 | 376 |
|
377 | 377 |
|
378 | 378 |
void ArgParser::checkMandatories() |
379 | 379 |
{ |
380 | 380 |
bool ok=true; |
381 | 381 |
for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) |
382 | 382 |
if(i->second.mandatory&&!i->second.set) |
383 | 383 |
{ |
384 | 384 |
if(ok) |
385 | 385 |
std::cerr << _command_name |
386 | 386 |
<< ": The following mandatory arguments are missing.\n"; |
387 | 387 |
ok=false; |
388 | 388 |
showHelp(i); |
389 | 389 |
} |
390 | 390 |
for(Groups::iterator i=_groups.begin();i!=_groups.end();++i) |
391 | 391 |
if(i->second.mandatory||i->second.only_one) |
392 | 392 |
{ |
393 | 393 |
int set=0; |
394 | 394 |
for(GroupData::Opts::iterator o=i->second.opts.begin(); |
395 | 395 |
o!=i->second.opts.end();++o) |
396 | 396 |
if(_opts.find(*o)->second.set) ++set; |
397 | 397 |
if(i->second.mandatory&&!set) { |
398 |
std::cerr << _command_name |
|
399 |
<< ": At least one of the following arguments is mandatory.\n"; |
|
398 |
std::cerr << _command_name << |
|
399 |
": At least one of the following arguments is mandatory.\n"; |
|
400 | 400 |
ok=false; |
401 | 401 |
for(GroupData::Opts::iterator o=i->second.opts.begin(); |
402 | 402 |
o!=i->second.opts.end();++o) |
403 | 403 |
showHelp(_opts.find(*o)); |
404 | 404 |
} |
405 | 405 |
if(i->second.only_one&&set>1) { |
406 |
std::cerr << _command_name |
|
407 |
<< ": At most one of the following arguments can be given.\n"; |
|
406 |
std::cerr << _command_name << |
|
407 |
": At most one of the following arguments can be given.\n"; |
|
408 | 408 |
ok=false; |
409 | 409 |
for(GroupData::Opts::iterator o=i->second.opts.begin(); |
410 | 410 |
o!=i->second.opts.end();++o) |
411 | 411 |
showHelp(_opts.find(*o)); |
412 | 412 |
} |
413 | 413 |
} |
414 | 414 |
if(!ok) { |
415 | 415 |
std::cerr << "\nType '" << _command_name << |
416 | 416 |
" --help' to obtain a short summary on the usage.\n\n"; |
417 | 417 |
exit(1); |
418 | 418 |
} |
419 | 419 |
} |
420 | 420 |
|
421 | 421 |
ArgParser &ArgParser::parse() |
422 | 422 |
{ |
423 | 423 |
for(int ar=1; ar<_argc; ++ar) { |
424 | 424 |
std::string arg(_argv[ar]); |
425 | 425 |
if (arg[0] != '-' || arg.size() == 1) { |
426 | 426 |
_file_args.push_back(arg); |
427 | 427 |
} |
428 | 428 |
else { |
429 | 429 |
Opts::iterator i = _opts.find(arg.substr(1)); |
430 | 430 |
if(i==_opts.end()) unknownOpt(arg); |
431 | 431 |
else { |
432 | 432 |
if(i->second.syn) i=_opts.find(i->second.help); |
433 | 433 |
ParData &p(i->second); |
434 | 434 |
if (p.type==BOOL) *p.bool_p=true; |
435 | 435 |
else if (p.type==FUNC) p.func_p.p(p.func_p.data); |
436 | 436 |
else if(++ar==_argc) requiresValue(arg, p.type); |
437 | 437 |
else { |
438 | 438 |
std::string val(_argv[ar]); |
439 | 439 |
std::istringstream vals(val); |
... | ... |
@@ -122,139 +122,140 @@ |
122 | 122 |
/// expression that must be convertible to \c bool. If it is \c |
123 | 123 |
/// false, then an assertion is raised. The concrete behaviour depends |
124 | 124 |
/// on the settings of the assertion system. \param msg A <tt>const |
125 | 125 |
/// char*</tt> parameter, which can be used to provide information |
126 | 126 |
/// about the circumstances of the failed assertion. |
127 | 127 |
/// |
128 | 128 |
/// The assertions are enabled in the default behaviour. |
129 | 129 |
/// You can disable them with the following code: |
130 | 130 |
/// \code |
131 | 131 |
/// #define LEMON_DISABLE_ASSERTS |
132 | 132 |
/// \endcode |
133 | 133 |
/// or with compilation parameters: |
134 | 134 |
/// \code |
135 | 135 |
/// g++ -DLEMON_DISABLE_ASSERTS |
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 | 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. |
148 | 148 |
/// - \c LEMON_ASSERT_ABORT This mode is similar to the \c |
149 | 149 |
/// LEMON_ASSERT_LOG, but it aborts the program. It is the default |
150 | 150 |
/// behaviour. |
151 | 151 |
/// - \c LEMON_ASSERT_CUSTOM The user can define own assertion handler |
152 | 152 |
/// function. |
153 | 153 |
/// \code |
154 |
/// void custom_assert_handler(const char* file, int line, const char* function, |
|
155 |
/// const char* message, const char* assertion); |
|
154 |
/// void custom_assert_handler(const char* file, int line, |
|
155 |
/// const char* function, const char* message, |
|
156 |
/// const char* assertion); |
|
156 | 157 |
/// \endcode |
157 | 158 |
/// The name of the function should be defined as the \c |
158 | 159 |
/// LEMON_CUSTOM_ASSERT_HANDLER macro name. |
159 | 160 |
/// \code |
160 | 161 |
/// #define LEMON_CUSTOM_ASSERT_HANDLER custom_assert_handler |
161 | 162 |
/// \endcode |
162 | 163 |
/// Whenever an assertion is occured, the custom assertion |
163 | 164 |
/// handler is called with appropiate parameters. |
164 | 165 |
/// |
165 | 166 |
/// The assertion mode can also be changed within one compilation unit. |
166 | 167 |
/// If the macros are redefined with other settings and the |
167 | 168 |
/// \ref lemon/assert.h "assert.h" file is reincluded, then the |
168 | 169 |
/// behaviour is changed appropiately to the new settings. |
169 | 170 |
# define LEMON_ASSERT(exp, msg) \ |
170 | 171 |
(static_cast<void> (!!(exp) ? 0 : ( \ |
171 | 172 |
LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ |
172 | 173 |
LEMON_FUNCTION_NAME, \ |
173 | 174 |
::lemon::_assert_bits::cstringify(msg), #exp), 0))) |
174 | 175 |
|
175 | 176 |
/// \ingroup exceptions |
176 | 177 |
/// |
177 | 178 |
/// \brief Macro for mark not yet implemented features. |
178 | 179 |
/// |
179 | 180 |
/// Macro for mark not yet implemented features and outstanding bugs. |
180 | 181 |
/// It is close to be the shortcut of the following code: |
181 | 182 |
/// \code |
182 | 183 |
/// LEMON_ASSERT(false, msg); |
183 | 184 |
/// \endcode |
184 | 185 |
/// |
185 | 186 |
/// \see LEMON_ASSERT |
186 | 187 |
# define LEMON_FIXME(msg) \ |
187 | 188 |
(LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \ |
188 |
::lemon::_assert_bits::cstringify(msg), |
|
189 |
::lemon::_assert_bits::cstringify(msg), \ |
|
189 | 190 |
static_cast<const char*>(0))) |
190 | 191 |
|
191 | 192 |
/// \ingroup exceptions |
192 | 193 |
/// |
193 | 194 |
/// \brief Macro for internal assertions |
194 | 195 |
/// |
195 | 196 |
/// Macro for internal assertions, it is used in the library to check |
196 | 197 |
/// the consistency of results of algorithms, several pre- and |
197 | 198 |
/// postconditions and invariants. The checking is disabled by |
198 | 199 |
/// default, but it can be turned on with the macro \c |
199 | 200 |
/// LEMON_ENABLE_DEBUG. |
200 | 201 |
/// \code |
201 | 202 |
/// #define LEMON_ENABLE_DEBUG |
202 | 203 |
/// \endcode |
203 | 204 |
/// or with compilation parameters: |
204 | 205 |
/// \code |
205 | 206 |
/// g++ -DLEMON_ENABLE_DEBUG |
206 | 207 |
/// make CXXFLAGS='-DLEMON_ENABLE_DEBUG' |
207 | 208 |
/// \endcode |
208 | 209 |
/// |
209 | 210 |
/// This macro works like the \c LEMON_ASSERT macro, therefore the |
210 | 211 |
/// current behaviour depends on the settings of \c LEMON_ASSERT |
211 | 212 |
/// macro. |
212 | 213 |
/// |
213 | 214 |
/// \see LEMON_ASSERT |
214 | 215 |
# define LEMON_DEBUG(exp, msg) \ |
215 | 216 |
(static_cast<void> (!!(exp) ? 0 : ( \ |
216 | 217 |
LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ |
217 | 218 |
LEMON_FUNCTION_NAME, \ |
218 | 219 |
::lemon::_assert_bits::cstringify(msg), #exp), 0))) |
219 | 220 |
|
220 | 221 |
#else |
221 | 222 |
|
222 | 223 |
# ifndef LEMON_ASSERT_HANDLER |
223 | 224 |
# define LEMON_ASSERT(exp, msg) (static_cast<void>(0)) |
224 | 225 |
# define LEMON_FIXME(msg) (static_cast<void>(0)) |
225 | 226 |
# define LEMON_DEBUG(exp, msg) (static_cast<void>(0)) |
226 | 227 |
# else |
227 | 228 |
# define LEMON_ASSERT(exp, msg) \ |
228 | 229 |
(static_cast<void> (!!(exp) ? 0 : ( \ |
229 | 230 |
LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ |
230 | 231 |
LEMON_FUNCTION_NAME, \ |
231 | 232 |
::lemon::_assert_bits::cstringify(msg), \ |
232 | 233 |
#exp), 0))) |
233 | 234 |
# define LEMON_FIXME(msg) \ |
234 | 235 |
(LEMON_ASSERT_HANDLER(__FILE__, __LINE__, LEMON_FUNCTION_NAME, \ |
235 | 236 |
::lemon::_assert_bits::cstringify(msg), \ |
236 | 237 |
static_cast<const char*>(0))) |
237 | 238 |
|
238 | 239 |
# if LEMON_ENABLE_DEBUG |
239 | 240 |
# define LEMON_DEBUG(exp, msg) |
240 | 241 |
(static_cast<void> (!!(exp) ? 0 : ( \ |
241 | 242 |
LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \ |
242 | 243 |
LEMON_FUNCTION_NAME, \ |
243 |
::lemon::_assert_bits::cstringify(msg), |
|
244 |
::lemon::_assert_bits::cstringify(msg), \ |
|
244 | 245 |
#exp), 0))) |
245 | 246 |
# else |
246 | 247 |
# define LEMON_DEBUG(exp, msg) (static_cast<void>(0)) |
247 | 248 |
# endif |
248 | 249 |
# endif |
249 | 250 |
|
250 | 251 |
#endif |
251 | 252 |
|
252 | 253 |
#ifdef DOXYGEN |
253 | 254 |
|
254 | 255 |
|
255 | 256 |
#else |
256 | 257 |
|
257 | 258 |
|
258 | 259 |
#endif |
259 | 260 |
|
260 | 261 |
... | ... |
@@ -74,65 +74,66 @@ |
74 | 74 |
#ifdef DOXYGEN |
75 | 75 |
static ProcessedMap *createProcessedMap(const GR &g) |
76 | 76 |
#else |
77 | 77 |
static ProcessedMap *createProcessedMap(const GR &) |
78 | 78 |
#endif |
79 | 79 |
{ |
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 | 89 |
|
90 | 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) |
94 | 94 |
{ |
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 | 104 |
|
105 | 105 |
///This function instantiates a \ref DistMap. |
106 |
///\param G is the digraph, to which we would like to define |
|
106 |
///\param G is the digraph, to which we would like to define |
|
107 |
///the \ref DistMap |
|
107 | 108 |
static DistMap *createDistMap(const GR &G) |
108 | 109 |
{ |
109 | 110 |
return new DistMap(G); |
110 | 111 |
} |
111 | 112 |
}; |
112 | 113 |
|
113 | 114 |
///%BFS algorithm class. |
114 | 115 |
|
115 | 116 |
///\ingroup search |
116 | 117 |
///This class provides an efficient implementation of the %BFS algorithm. |
117 | 118 |
/// |
118 | 119 |
///\tparam GR The digraph type the algorithm runs on. The default value is |
119 | 120 |
///\ref ListDigraph. The value of GR is not used directly by Bfs, it |
120 | 121 |
///is only passed to \ref BfsDefaultTraits. |
121 | 122 |
///\tparam TR Traits class to set various data types used by the algorithm. |
122 | 123 |
///The default traits class is |
123 | 124 |
///\ref BfsDefaultTraits "BfsDefaultTraits<GR>". |
124 | 125 |
///See \ref BfsDefaultTraits for the documentation of |
125 | 126 |
///a Bfs traits class. |
126 | 127 |
|
127 | 128 |
#ifdef DOXYGEN |
128 | 129 |
template <typename GR, |
129 | 130 |
typename TR> |
130 | 131 |
#else |
131 | 132 |
template <typename GR=ListDigraph, |
132 | 133 |
typename TR=BfsDefaultTraits<GR> > |
133 | 134 |
#endif |
134 | 135 |
class Bfs { |
135 | 136 |
public: |
136 | 137 |
/** |
137 | 138 |
* \brief \ref Exception for uninitialized parameters. |
138 | 139 |
* |
... | ... |
@@ -796,65 +797,66 @@ |
796 | 797 |
#ifdef DOXYGEN |
797 | 798 |
static ProcessedMap *createProcessedMap(const GR &g) |
798 | 799 |
#else |
799 | 800 |
static ProcessedMap *createProcessedMap(const GR &) |
800 | 801 |
#endif |
801 | 802 |
{ |
802 | 803 |
return new ProcessedMap(); |
803 | 804 |
} |
804 | 805 |
///The type of the map that indicates which nodes are reached. |
805 | 806 |
|
806 | 807 |
///The type of the map that indicates which nodes are reached. |
807 | 808 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
808 | 809 |
///\todo named parameter to set this type, function to read and write. |
809 | 810 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
810 | 811 |
///Instantiates a ReachedMap. |
811 | 812 |
|
812 | 813 |
///This function instantiates a \ref ReachedMap. |
813 | 814 |
///\param G is the digraph, to which |
814 | 815 |
///we would like to define the \ref ReachedMap. |
815 | 816 |
static ReachedMap *createReachedMap(const GR &G) |
816 | 817 |
{ |
817 | 818 |
return new ReachedMap(G); |
818 | 819 |
} |
819 | 820 |
///The type of the map that stores the dists of the nodes. |
820 | 821 |
|
821 | 822 |
///The type of the map that stores the dists of the nodes. |
822 | 823 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
823 | 824 |
/// |
824 | 825 |
typedef NullMap<typename Digraph::Node,int> DistMap; |
825 | 826 |
///Instantiates a DistMap. |
826 | 827 |
|
827 | 828 |
///This function instantiates a \ref DistMap. |
828 |
///\param g is the digraph, to which we would like to define |
|
829 |
///\param g is the digraph, to which we would like to define |
|
830 |
///the \ref DistMap |
|
829 | 831 |
#ifdef DOXYGEN |
830 | 832 |
static DistMap *createDistMap(const GR &g) |
831 | 833 |
#else |
832 | 834 |
static DistMap *createDistMap(const GR &) |
833 | 835 |
#endif |
834 | 836 |
{ |
835 | 837 |
return new DistMap(); |
836 | 838 |
} |
837 | 839 |
}; |
838 | 840 |
|
839 | 841 |
/// Default traits used by \ref BfsWizard |
840 | 842 |
|
841 | 843 |
/// To make it easier to use Bfs algorithm |
842 | 844 |
///we have created a wizard class. |
843 | 845 |
/// This \ref BfsWizard class needs default traits, |
844 | 846 |
///as well as the \ref Bfs class. |
845 | 847 |
/// The \ref BfsWizardBase is a class to be the default traits of the |
846 | 848 |
/// \ref BfsWizard class. |
847 | 849 |
template<class GR> |
848 | 850 |
class BfsWizardBase : public BfsWizardDefaultTraits<GR> |
849 | 851 |
{ |
850 | 852 |
|
851 | 853 |
typedef BfsWizardDefaultTraits<GR> Base; |
852 | 854 |
protected: |
853 | 855 |
/// Type of the nodes in the digraph. |
854 | 856 |
typedef typename Base::Digraph::Node Node; |
855 | 857 |
|
856 | 858 |
/// Pointer to the underlying digraph. |
857 | 859 |
void *_g; |
858 | 860 |
///Pointer to the map of reached nodes. |
859 | 861 |
void *_reached; |
860 | 862 |
///Pointer to the map of processed nodes. |
... | ... |
@@ -1170,65 +1172,66 @@ |
1170 | 1172 |
/// \brief The digraph type the algorithm runs on. |
1171 | 1173 |
typedef _Digraph Digraph; |
1172 | 1174 |
|
1173 | 1175 |
/// \brief The type of the map that indicates which nodes are reached. |
1174 | 1176 |
/// |
1175 | 1177 |
/// The type of the map that indicates which nodes are reached. |
1176 | 1178 |
/// It must meet the \ref concepts::WriteMap "WriteMap" concept. |
1177 | 1179 |
/// \todo named parameter to set this type, function to read and write. |
1178 | 1180 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
1179 | 1181 |
|
1180 | 1182 |
/// \brief Instantiates a ReachedMap. |
1181 | 1183 |
/// |
1182 | 1184 |
/// This function instantiates a \ref ReachedMap. |
1183 | 1185 |
/// \param digraph is the digraph, to which |
1184 | 1186 |
/// we would like to define the \ref ReachedMap. |
1185 | 1187 |
static ReachedMap *createReachedMap(const Digraph &digraph) { |
1186 | 1188 |
return new ReachedMap(digraph); |
1187 | 1189 |
} |
1188 | 1190 |
|
1189 | 1191 |
}; |
1190 | 1192 |
|
1191 | 1193 |
/// \ingroup search |
1192 | 1194 |
/// |
1193 | 1195 |
/// \brief %BFS Visit algorithm class. |
1194 | 1196 |
/// |
1195 | 1197 |
/// This class provides an efficient implementation of the %BFS algorithm |
1196 | 1198 |
/// with visitor interface. |
1197 | 1199 |
/// |
1198 | 1200 |
/// The %BfsVisit class provides an alternative interface to the Bfs |
1199 | 1201 |
/// class. It works with callback mechanism, the BfsVisit object calls |
1200 | 1202 |
/// on every bfs event the \c Visitor class member functions. |
1201 | 1203 |
/// |
1202 |
/// \tparam _Digraph The digraph type the algorithm runs on. |
|
1204 |
/// \tparam _Digraph The digraph type the algorithm runs on. |
|
1205 |
/// The default value is |
|
1203 | 1206 |
/// \ref ListDigraph. The value of _Digraph is not used directly by Bfs, it |
1204 | 1207 |
/// is only passed to \ref BfsDefaultTraits. |
1205 | 1208 |
/// \tparam _Visitor The Visitor object for the algorithm. The |
1206 | 1209 |
/// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty Visitor which |
1207 | 1210 |
/// does not observe the Bfs events. If you want to observe the bfs |
1208 | 1211 |
/// events you should implement your own Visitor class. |
1209 | 1212 |
/// \tparam _Traits Traits class to set various data types used by the |
1210 | 1213 |
/// algorithm. The default traits class is |
1211 | 1214 |
/// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<_Digraph>". |
1212 | 1215 |
/// See \ref BfsVisitDefaultTraits for the documentation of |
1213 | 1216 |
/// a Bfs visit traits class. |
1214 | 1217 |
#ifdef DOXYGEN |
1215 | 1218 |
template <typename _Digraph, typename _Visitor, typename _Traits> |
1216 | 1219 |
#else |
1217 | 1220 |
template <typename _Digraph = ListDigraph, |
1218 | 1221 |
typename _Visitor = BfsVisitor<_Digraph>, |
1219 | 1222 |
typename _Traits = BfsDefaultTraits<_Digraph> > |
1220 | 1223 |
#endif |
1221 | 1224 |
class BfsVisit { |
1222 | 1225 |
public: |
1223 | 1226 |
|
1224 | 1227 |
/// \brief \ref Exception for uninitialized parameters. |
1225 | 1228 |
/// |
1226 | 1229 |
/// This error represents problems in the initialization |
1227 | 1230 |
/// of the parameters of the algorithms. |
1228 | 1231 |
class UninitializedParameter : public lemon::UninitializedParameter { |
1229 | 1232 |
public: |
1230 | 1233 |
virtual const char* what() const throw() |
1231 | 1234 |
{ |
1232 | 1235 |
return "lemon::BfsVisit::UninitializedParameter"; |
1233 | 1236 |
} |
1234 | 1237 |
}; |
... | ... |
@@ -14,176 +14,180 @@ |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
18 | 18 |
|
19 | 19 |
#ifndef LEMON_CONCEPT_MAPS_H |
20 | 20 |
#define LEMON_CONCEPT_MAPS_H |
21 | 21 |
|
22 | 22 |
#include <lemon/bits/utility.h> |
23 | 23 |
#include <lemon/concept_check.h> |
24 | 24 |
|
25 | 25 |
///\ingroup concept |
26 | 26 |
///\file |
27 | 27 |
///\brief The concept of maps. |
28 | 28 |
|
29 | 29 |
namespace lemon { |
30 | 30 |
|
31 | 31 |
namespace concepts { |
32 | 32 |
|
33 | 33 |
/// \addtogroup concept |
34 | 34 |
/// @{ |
35 | 35 |
|
36 | 36 |
/// Readable map concept |
37 | 37 |
|
38 | 38 |
/// Readable map concept. |
39 | 39 |
/// |
40 | 40 |
template<typename K, typename T> |
41 | 41 |
class ReadMap |
42 | 42 |
{ |
43 | 43 |
public: |
44 | 44 |
/// The key type of the map. |
45 | 45 |
typedef K Key; |
46 |
/// The value type of the map. |
|
46 |
/// \brief The value type of the map. |
|
47 |
/// (The type of objects associated with the keys). |
|
47 | 48 |
typedef T Value; |
48 | 49 |
|
49 | 50 |
/// Returns the value associated with the given key. |
50 | 51 |
Value operator[](const Key &) const { |
51 | 52 |
return *static_cast<Value *>(0); |
52 | 53 |
} |
53 | 54 |
|
54 | 55 |
template<typename _ReadMap> |
55 | 56 |
struct Constraints { |
56 | 57 |
void constraints() { |
57 | 58 |
Value val = m[key]; |
58 | 59 |
val = m[key]; |
59 | 60 |
typename _ReadMap::Value own_val = m[own_key]; |
60 | 61 |
own_val = m[own_key]; |
61 | 62 |
|
62 | 63 |
ignore_unused_variable_warning(key); |
63 | 64 |
ignore_unused_variable_warning(val); |
64 | 65 |
ignore_unused_variable_warning(own_key); |
65 | 66 |
ignore_unused_variable_warning(own_val); |
66 | 67 |
} |
67 | 68 |
const Key& key; |
68 | 69 |
const typename _ReadMap::Key& own_key; |
69 | 70 |
const _ReadMap& m; |
70 | 71 |
}; |
71 | 72 |
|
72 | 73 |
}; |
73 | 74 |
|
74 | 75 |
|
75 | 76 |
/// Writable map concept |
76 | 77 |
|
77 | 78 |
/// Writable map concept. |
78 | 79 |
/// |
79 | 80 |
template<typename K, typename T> |
80 | 81 |
class WriteMap |
81 | 82 |
{ |
82 | 83 |
public: |
83 | 84 |
/// The key type of the map. |
84 | 85 |
typedef K Key; |
85 |
/// The value type of the map. |
|
86 |
/// \brief The value type of the map. |
|
87 |
/// (The type of objects associated with the keys). |
|
86 | 88 |
typedef T Value; |
87 | 89 |
|
88 | 90 |
/// Sets the value associated with the given key. |
89 | 91 |
void set(const Key &, const Value &) {} |
90 | 92 |
|
91 | 93 |
/// Default constructor. |
92 | 94 |
WriteMap() {} |
93 | 95 |
|
94 | 96 |
template <typename _WriteMap> |
95 | 97 |
struct Constraints { |
96 | 98 |
void constraints() { |
97 | 99 |
m.set(key, val); |
98 | 100 |
m.set(own_key, own_val); |
99 | 101 |
|
100 | 102 |
ignore_unused_variable_warning(key); |
101 | 103 |
ignore_unused_variable_warning(val); |
102 | 104 |
ignore_unused_variable_warning(own_key); |
103 | 105 |
ignore_unused_variable_warning(own_val); |
104 | 106 |
} |
105 | 107 |
const Key& key; |
106 | 108 |
const Value& val; |
107 | 109 |
const typename _WriteMap::Key& own_key; |
108 | 110 |
const typename _WriteMap::Value& own_val; |
109 | 111 |
_WriteMap& m; |
110 | 112 |
}; |
111 | 113 |
}; |
112 | 114 |
|
113 | 115 |
/// Read/writable map concept |
114 | 116 |
|
115 | 117 |
/// Read/writable map concept. |
116 | 118 |
/// |
117 | 119 |
template<typename K, typename T> |
118 | 120 |
class ReadWriteMap : public ReadMap<K,T>, |
119 | 121 |
public WriteMap<K,T> |
120 | 122 |
{ |
121 | 123 |
public: |
122 | 124 |
/// The key type of the map. |
123 | 125 |
typedef K Key; |
124 |
/// The value type of the map. |
|
126 |
/// \brief The value type of the map. |
|
127 |
/// (The type of objects associated with the keys). |
|
125 | 128 |
typedef T Value; |
126 | 129 |
|
127 | 130 |
/// Returns the value associated with the given key. |
128 | 131 |
Value operator[](const Key &) const { |
129 | 132 |
return *static_cast<Value *>(0); |
130 | 133 |
} |
131 | 134 |
|
132 | 135 |
/// Sets the value associated with the given key. |
133 | 136 |
void set(const Key &, const Value &) {} |
134 | 137 |
|
135 | 138 |
template<typename _ReadWriteMap> |
136 | 139 |
struct Constraints { |
137 | 140 |
void constraints() { |
138 | 141 |
checkConcept<ReadMap<K, T>, _ReadWriteMap >(); |
139 | 142 |
checkConcept<WriteMap<K, T>, _ReadWriteMap >(); |
140 | 143 |
} |
141 | 144 |
}; |
142 | 145 |
}; |
143 | 146 |
|
144 | 147 |
|
145 | 148 |
/// Dereferable map concept |
146 | 149 |
|
147 | 150 |
/// Dereferable map concept. |
148 | 151 |
/// |
149 | 152 |
template<typename K, typename T, typename R, typename CR> |
150 | 153 |
class ReferenceMap : public ReadWriteMap<K,T> |
151 | 154 |
{ |
152 | 155 |
public: |
153 | 156 |
/// Tag for reference maps. |
154 | 157 |
typedef True ReferenceMapTag; |
155 | 158 |
/// The key type of the map. |
156 | 159 |
typedef K Key; |
157 |
/// The value type of the map. |
|
160 |
/// \brief The value type of the map. |
|
161 |
/// (The type of objects associated with the keys). |
|
158 | 162 |
typedef T Value; |
159 | 163 |
/// The reference type of the map. |
160 | 164 |
typedef R Reference; |
161 | 165 |
/// The const reference type of the map. |
162 | 166 |
typedef CR ConstReference; |
163 | 167 |
|
164 | 168 |
public: |
165 | 169 |
|
166 | 170 |
/// Returns a reference to the value associated with the given key. |
167 | 171 |
Reference operator[](const Key &) { |
168 | 172 |
return *static_cast<Value *>(0); |
169 | 173 |
} |
170 | 174 |
|
171 | 175 |
/// Returns a const reference to the value associated with the given key. |
172 | 176 |
ConstReference operator[](const Key &) const { |
173 | 177 |
return *static_cast<Value *>(0); |
174 | 178 |
} |
175 | 179 |
|
176 | 180 |
/// Sets the value associated with the given key. |
177 | 181 |
void set(const Key &k,const Value &t) { operator[](k)=t; } |
178 | 182 |
|
179 | 183 |
template<typename _ReferenceMap> |
180 | 184 |
struct Constraints { |
181 | 185 |
void constraints() { |
182 | 186 |
checkConcept<ReadWriteMap<K, T>, _ReferenceMap >(); |
183 | 187 |
ref = m[key]; |
184 | 188 |
m[key] = val; |
185 | 189 |
m[key] = ref; |
186 | 190 |
m[key] = cref; |
187 | 191 |
own_ref = m[own_key]; |
188 | 192 |
m[own_key] = own_val; |
189 | 193 |
m[own_key] = own_ref; |
... | ... |
@@ -76,65 +76,66 @@ |
76 | 76 |
#ifdef DOXYGEN |
77 | 77 |
static ProcessedMap *createProcessedMap(const GR &g) |
78 | 78 |
#else |
79 | 79 |
static ProcessedMap *createProcessedMap(const GR &) |
80 | 80 |
#endif |
81 | 81 |
{ |
82 | 82 |
return new ProcessedMap(); |
83 | 83 |
} |
84 | 84 |
///The type of the map that indicates which nodes are reached. |
85 | 85 |
|
86 | 86 |
///The type of the map that indicates which nodes are reached. |
87 | 87 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
88 | 88 |
///\todo named parameter to set this type, function to read and write. |
89 | 89 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
90 | 90 |
///Instantiates a ReachedMap. |
91 | 91 |
|
92 | 92 |
///This function instantiates a \ref ReachedMap. |
93 | 93 |
///\param G is the digraph, to which |
94 | 94 |
///we would like to define the \ref ReachedMap. |
95 | 95 |
static ReachedMap *createReachedMap(const GR &G) |
96 | 96 |
{ |
97 | 97 |
return new ReachedMap(G); |
98 | 98 |
} |
99 | 99 |
///The type of the map that stores the dists of the nodes. |
100 | 100 |
|
101 | 101 |
///The type of the map that stores the dists of the nodes. |
102 | 102 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
103 | 103 |
/// |
104 | 104 |
typedef typename Digraph::template NodeMap<int> DistMap; |
105 | 105 |
///Instantiates a DistMap. |
106 | 106 |
|
107 | 107 |
///This function instantiates a \ref DistMap. |
108 |
///\param G is the digraph, to which we would like to define |
|
108 |
///\param G is the digraph, to which we would like to define |
|
109 |
///the \ref DistMap |
|
109 | 110 |
static DistMap *createDistMap(const GR &G) |
110 | 111 |
{ |
111 | 112 |
return new DistMap(G); |
112 | 113 |
} |
113 | 114 |
}; |
114 | 115 |
|
115 | 116 |
///%DFS algorithm class. |
116 | 117 |
|
117 | 118 |
///\ingroup search |
118 | 119 |
///This class provides an efficient implementation of the %DFS algorithm. |
119 | 120 |
/// |
120 | 121 |
///\tparam GR The digraph type the algorithm runs on. The default value is |
121 | 122 |
///\ref ListDigraph. The value of GR is not used directly by Dfs, it |
122 | 123 |
///is only passed to \ref DfsDefaultTraits. |
123 | 124 |
///\tparam TR Traits class to set various data types used by the algorithm. |
124 | 125 |
///The default traits class is |
125 | 126 |
///\ref DfsDefaultTraits "DfsDefaultTraits<GR>". |
126 | 127 |
///See \ref DfsDefaultTraits for the documentation of |
127 | 128 |
///a Dfs traits class. |
128 | 129 |
#ifdef DOXYGEN |
129 | 130 |
template <typename GR, |
130 | 131 |
typename TR> |
131 | 132 |
#else |
132 | 133 |
template <typename GR=ListDigraph, |
133 | 134 |
typename TR=DfsDefaultTraits<GR> > |
134 | 135 |
#endif |
135 | 136 |
class Dfs { |
136 | 137 |
public: |
137 | 138 |
/** |
138 | 139 |
* \brief \ref Exception for uninitialized parameters. |
139 | 140 |
* |
140 | 141 |
* This error represents problems in the initialization |
... | ... |
@@ -779,65 +780,66 @@ |
779 | 780 |
#ifdef DOXYGEN |
780 | 781 |
static ProcessedMap *createProcessedMap(const GR &g) |
781 | 782 |
#else |
782 | 783 |
static ProcessedMap *createProcessedMap(const GR &) |
783 | 784 |
#endif |
784 | 785 |
{ |
785 | 786 |
return new ProcessedMap(); |
786 | 787 |
} |
787 | 788 |
///The type of the map that indicates which nodes are reached. |
788 | 789 |
|
789 | 790 |
///The type of the map that indicates which nodes are reached. |
790 | 791 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
791 | 792 |
///\todo named parameter to set this type, function to read and write. |
792 | 793 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
793 | 794 |
///Instantiates a ReachedMap. |
794 | 795 |
|
795 | 796 |
///This function instantiates a \ref ReachedMap. |
796 | 797 |
///\param G is the digraph, to which |
797 | 798 |
///we would like to define the \ref ReachedMap. |
798 | 799 |
static ReachedMap *createReachedMap(const GR &G) |
799 | 800 |
{ |
800 | 801 |
return new ReachedMap(G); |
801 | 802 |
} |
802 | 803 |
///The type of the map that stores the dists of the nodes. |
803 | 804 |
|
804 | 805 |
///The type of the map that stores the dists of the nodes. |
805 | 806 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
806 | 807 |
/// |
807 | 808 |
typedef NullMap<typename Digraph::Node,int> DistMap; |
808 | 809 |
///Instantiates a DistMap. |
809 | 810 |
|
810 | 811 |
///This function instantiates a \ref DistMap. |
811 |
///\param g is the digraph, to which we would like to define |
|
812 |
///\param g is the digraph, to which we would like to define |
|
813 |
///the \ref DistMap |
|
812 | 814 |
#ifdef DOXYGEN |
813 | 815 |
static DistMap *createDistMap(const GR &g) |
814 | 816 |
#else |
815 | 817 |
static DistMap *createDistMap(const GR &) |
816 | 818 |
#endif |
817 | 819 |
{ |
818 | 820 |
return new DistMap(); |
819 | 821 |
} |
820 | 822 |
}; |
821 | 823 |
|
822 | 824 |
/// Default traits used by \ref DfsWizard |
823 | 825 |
|
824 | 826 |
/// To make it easier to use Dfs algorithm |
825 | 827 |
///we have created a wizard class. |
826 | 828 |
/// This \ref DfsWizard class needs default traits, |
827 | 829 |
///as well as the \ref Dfs class. |
828 | 830 |
/// The \ref DfsWizardBase is a class to be the default traits of the |
829 | 831 |
/// \ref DfsWizard class. |
830 | 832 |
template<class GR> |
831 | 833 |
class DfsWizardBase : public DfsWizardDefaultTraits<GR> |
832 | 834 |
{ |
833 | 835 |
|
834 | 836 |
typedef DfsWizardDefaultTraits<GR> Base; |
835 | 837 |
protected: |
836 | 838 |
/// Type of the nodes in the digraph. |
837 | 839 |
typedef typename Base::Digraph::Node Node; |
838 | 840 |
|
839 | 841 |
/// Pointer to the underlying digraph. |
840 | 842 |
void *_g; |
841 | 843 |
///Pointer to the map of reached nodes. |
842 | 844 |
void *_reached; |
843 | 845 |
///Pointer to the map of processed nodes. |
... | ... |
@@ -1164,65 +1166,66 @@ |
1164 | 1166 |
|
1165 | 1167 |
/// \brief The digraph type the algorithm runs on. |
1166 | 1168 |
typedef _Digraph Digraph; |
1167 | 1169 |
|
1168 | 1170 |
/// \brief The type of the map that indicates which nodes are reached. |
1169 | 1171 |
/// |
1170 | 1172 |
/// The type of the map that indicates which nodes are reached. |
1171 | 1173 |
/// It must meet the \ref concepts::WriteMap "WriteMap" concept. |
1172 | 1174 |
/// \todo named parameter to set this type, function to read and write. |
1173 | 1175 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
1174 | 1176 |
|
1175 | 1177 |
/// \brief Instantiates a ReachedMap. |
1176 | 1178 |
/// |
1177 | 1179 |
/// This function instantiates a \ref ReachedMap. |
1178 | 1180 |
/// \param digraph is the digraph, to which |
1179 | 1181 |
/// we would like to define the \ref ReachedMap. |
1180 | 1182 |
static ReachedMap *createReachedMap(const Digraph &digraph) { |
1181 | 1183 |
return new ReachedMap(digraph); |
1182 | 1184 |
} |
1183 | 1185 |
|
1184 | 1186 |
}; |
1185 | 1187 |
|
1186 | 1188 |
/// %DFS Visit algorithm class. |
1187 | 1189 |
|
1188 | 1190 |
/// \ingroup search |
1189 | 1191 |
/// This class provides an efficient implementation of the %DFS algorithm |
1190 | 1192 |
/// with visitor interface. |
1191 | 1193 |
/// |
1192 | 1194 |
/// The %DfsVisit class provides an alternative interface to the Dfs |
1193 | 1195 |
/// class. It works with callback mechanism, the DfsVisit object calls |
1194 | 1196 |
/// on every dfs event the \c Visitor class member functions. |
1195 | 1197 |
/// |
1196 |
/// \tparam _Digraph The digraph type the algorithm runs on. |
|
1198 |
/// \tparam _Digraph The digraph type the algorithm runs on. |
|
1199 |
/// The default value is |
|
1197 | 1200 |
/// \ref ListDigraph. The value of _Digraph is not used directly by Dfs, it |
1198 | 1201 |
/// is only passed to \ref DfsDefaultTraits. |
1199 | 1202 |
/// \tparam _Visitor The Visitor object for the algorithm. The |
1200 | 1203 |
/// \ref DfsVisitor "DfsVisitor<_Digraph>" is an empty Visitor which |
1201 | 1204 |
/// does not observe the Dfs events. If you want to observe the dfs |
1202 | 1205 |
/// events you should implement your own Visitor class. |
1203 | 1206 |
/// \tparam _Traits Traits class to set various data types used by the |
1204 | 1207 |
/// algorithm. The default traits class is |
1205 | 1208 |
/// \ref DfsVisitDefaultTraits "DfsVisitDefaultTraits<_Digraph>". |
1206 | 1209 |
/// See \ref DfsVisitDefaultTraits for the documentation of |
1207 | 1210 |
/// a Dfs visit traits class. |
1208 | 1211 |
/// |
1209 | 1212 |
/// \author Jacint Szabo, Alpar Juttner and Balazs Dezso |
1210 | 1213 |
#ifdef DOXYGEN |
1211 | 1214 |
template <typename _Digraph, typename _Visitor, typename _Traits> |
1212 | 1215 |
#else |
1213 | 1216 |
template <typename _Digraph = ListDigraph, |
1214 | 1217 |
typename _Visitor = DfsVisitor<_Digraph>, |
1215 | 1218 |
typename _Traits = DfsDefaultTraits<_Digraph> > |
1216 | 1219 |
#endif |
1217 | 1220 |
class DfsVisit { |
1218 | 1221 |
public: |
1219 | 1222 |
|
1220 | 1223 |
/// \brief \ref Exception for uninitialized parameters. |
1221 | 1224 |
/// |
1222 | 1225 |
/// This error represents problems in the initialization |
1223 | 1226 |
/// of the parameters of the algorithms. |
1224 | 1227 |
class UninitializedParameter : public lemon::UninitializedParameter { |
1225 | 1228 |
public: |
1226 | 1229 |
virtual const char* what() const throw() |
1227 | 1230 |
{ |
1228 | 1231 |
return "lemon::DfsVisit::UninitializedParameter"; |
... | ... |
@@ -144,65 +144,66 @@ |
144 | 144 |
|
145 | 145 |
///The type of the map that stores whether a nodes is processed. |
146 | 146 |
|
147 | 147 |
///The type of the map that stores whether a nodes is processed. |
148 | 148 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
149 | 149 |
///By default it is a NullMap. |
150 | 150 |
///\todo If it is set to a real map, |
151 | 151 |
///Dijkstra::processed() should read this. |
152 | 152 |
///\todo named parameter to set this type, function to read and write. |
153 | 153 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
154 | 154 |
///Instantiates a ProcessedMap. |
155 | 155 |
|
156 | 156 |
///This function instantiates a \c ProcessedMap. |
157 | 157 |
///\param g is the digraph, to which |
158 | 158 |
///we would like to define the \c ProcessedMap |
159 | 159 |
#ifdef DOXYGEN |
160 | 160 |
static ProcessedMap *createProcessedMap(const GR &g) |
161 | 161 |
#else |
162 | 162 |
static ProcessedMap *createProcessedMap(const GR &) |
163 | 163 |
#endif |
164 | 164 |
{ |
165 | 165 |
return new ProcessedMap(); |
166 | 166 |
} |
167 | 167 |
///The type of the map that stores the dists of the nodes. |
168 | 168 |
|
169 | 169 |
///The type of the map that stores the dists of the nodes. |
170 | 170 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
171 | 171 |
/// |
172 | 172 |
typedef typename Digraph::template NodeMap<typename LM::Value> DistMap; |
173 | 173 |
///Instantiates a DistMap. |
174 | 174 |
|
175 | 175 |
///This function instantiates a \ref DistMap. |
176 |
///\param G is the digraph, to which we would like to define |
|
176 |
///\param G is the digraph, to which we would like to define |
|
177 |
///the \ref DistMap |
|
177 | 178 |
static DistMap *createDistMap(const GR &G) |
178 | 179 |
{ |
179 | 180 |
return new DistMap(G); |
180 | 181 |
} |
181 | 182 |
}; |
182 | 183 |
|
183 | 184 |
///%Dijkstra algorithm class. |
184 | 185 |
|
185 | 186 |
/// \ingroup shortest_path |
186 | 187 |
///This class provides an efficient implementation of %Dijkstra algorithm. |
187 | 188 |
///The arc lengths are passed to the algorithm using a |
188 | 189 |
///\ref concepts::ReadMap "ReadMap", |
189 | 190 |
///so it is easy to change it to any kind of length. |
190 | 191 |
/// |
191 | 192 |
///The type of the length is determined by the |
192 | 193 |
///\ref concepts::ReadMap::Value "Value" of the length map. |
193 | 194 |
/// |
194 | 195 |
///It is also possible to change the underlying priority heap. |
195 | 196 |
/// |
196 | 197 |
///\tparam GR The digraph type the algorithm runs on. The default value |
197 | 198 |
///is \ref ListDigraph. The value of GR is not used directly by |
198 | 199 |
///Dijkstra, it is only passed to \ref DijkstraDefaultTraits. |
199 | 200 |
///\tparam LM This read-only ArcMap determines the lengths of the |
200 | 201 |
///arcs. It is read once for each arc, so the map may involve in |
201 | 202 |
///relatively time consuming process to compute the arc length if |
202 | 203 |
///it is necessary. The default map type is \ref |
203 | 204 |
///concepts::Digraph::ArcMap "Digraph::ArcMap<int>". The value |
204 | 205 |
///of LM is not used directly by Dijkstra, it is only passed to \ref |
205 | 206 |
///DijkstraDefaultTraits. |
206 | 207 |
///\tparam TR Traits class to set |
207 | 208 |
///various data types used by the algorithm. The default traits |
208 | 209 |
///class is \ref DijkstraDefaultTraits |
... | ... |
@@ -307,170 +308,171 @@ |
307 | 308 |
if (!_heap_cross_ref) { |
308 | 309 |
local_heap_cross_ref = true; |
309 | 310 |
_heap_cross_ref = Traits::createHeapCrossRef(*G); |
310 | 311 |
} |
311 | 312 |
if (!_heap) { |
312 | 313 |
local_heap = true; |
313 | 314 |
_heap = Traits::createHeap(*_heap_cross_ref); |
314 | 315 |
} |
315 | 316 |
} |
316 | 317 |
|
317 | 318 |
public : |
318 | 319 |
|
319 | 320 |
typedef Dijkstra Create; |
320 | 321 |
|
321 | 322 |
///\name Named template parameters |
322 | 323 |
|
323 | 324 |
///@{ |
324 | 325 |
|
325 | 326 |
template <class T> |
326 | 327 |
struct DefPredMapTraits : public Traits { |
327 | 328 |
typedef T PredMap; |
328 | 329 |
static PredMap *createPredMap(const Digraph &) |
329 | 330 |
{ |
330 | 331 |
throw UninitializedParameter(); |
331 | 332 |
} |
332 | 333 |
}; |
333 | 334 |
///\ref named-templ-param "Named parameter" for setting PredMap type |
334 | 335 |
|
335 | 336 |
///\ref named-templ-param "Named parameter" for setting PredMap type |
336 | 337 |
/// |
337 | 338 |
template <class T> |
338 | 339 |
struct DefPredMap |
339 |
: public Dijkstra< Digraph, LengthMap, DefPredMapTraits<T> > { |
|
340 |
typedef Dijkstra< Digraph, LengthMap, DefPredMapTraits<T> > Create; |
|
340 |
: public Dijkstra< Digraph, LengthMap, DefPredMapTraits<T> > { |
|
341 |
typedef Dijkstra< Digraph, LengthMap, DefPredMapTraits<T> > Create; |
|
341 | 342 |
}; |
342 | 343 |
|
343 | 344 |
template <class T> |
344 | 345 |
struct DefDistMapTraits : public Traits { |
345 | 346 |
typedef T DistMap; |
346 | 347 |
static DistMap *createDistMap(const Digraph &) |
347 | 348 |
{ |
348 | 349 |
throw UninitializedParameter(); |
349 | 350 |
} |
350 | 351 |
}; |
351 | 352 |
///\ref named-templ-param "Named parameter" for setting DistMap type |
352 | 353 |
|
353 | 354 |
///\ref named-templ-param "Named parameter" for setting DistMap type |
354 | 355 |
/// |
355 | 356 |
template <class T> |
356 | 357 |
struct DefDistMap |
357 | 358 |
: public Dijkstra< Digraph, LengthMap, DefDistMapTraits<T> > { |
358 | 359 |
typedef Dijkstra< Digraph, LengthMap, DefDistMapTraits<T> > Create; |
359 | 360 |
}; |
360 | 361 |
|
361 | 362 |
template <class T> |
362 | 363 |
struct DefProcessedMapTraits : public Traits { |
363 | 364 |
typedef T ProcessedMap; |
364 | 365 |
static ProcessedMap *createProcessedMap(const Digraph &G) |
365 | 366 |
{ |
366 | 367 |
throw UninitializedParameter(); |
367 | 368 |
} |
368 | 369 |
}; |
369 | 370 |
///\ref named-templ-param "Named parameter" for setting ProcessedMap type |
370 | 371 |
|
371 | 372 |
///\ref named-templ-param "Named parameter" for setting ProcessedMap type |
372 | 373 |
/// |
373 | 374 |
template <class T> |
374 | 375 |
struct DefProcessedMap |
375 |
: public Dijkstra< Digraph, LengthMap, DefProcessedMapTraits<T> > { |
|
376 |
typedef Dijkstra< Digraph, LengthMap, DefProcessedMapTraits<T> > Create; |
|
376 |
: public Dijkstra< Digraph, LengthMap, DefProcessedMapTraits<T> > { |
|
377 |
typedef Dijkstra< Digraph, LengthMap, DefProcessedMapTraits<T> > Create; |
|
377 | 378 |
}; |
378 | 379 |
|
379 | 380 |
struct DefDigraphProcessedMapTraits : public Traits { |
380 | 381 |
typedef typename Digraph::template NodeMap<bool> ProcessedMap; |
381 | 382 |
static ProcessedMap *createProcessedMap(const Digraph &G) |
382 | 383 |
{ |
383 | 384 |
return new ProcessedMap(G); |
384 | 385 |
} |
385 | 386 |
}; |
386 | 387 |
///\brief \ref named-templ-param "Named parameter" |
387 | 388 |
///for setting the ProcessedMap type to be Digraph::NodeMap<bool>. |
388 | 389 |
/// |
389 | 390 |
///\ref named-templ-param "Named parameter" |
390 | 391 |
///for setting the ProcessedMap type to be Digraph::NodeMap<bool>. |
391 | 392 |
///If you don't set it explicitely, it will be automatically allocated. |
392 | 393 |
template <class T> |
393 | 394 |
struct DefProcessedMapToBeDefaultMap |
394 | 395 |
: public Dijkstra< Digraph, LengthMap, DefDigraphProcessedMapTraits> { |
395 |
typedef Dijkstra< Digraph, LengthMap, DefDigraphProcessedMapTraits> |
|
396 |
typedef Dijkstra< Digraph, LengthMap, DefDigraphProcessedMapTraits> |
|
397 |
Create; |
|
396 | 398 |
}; |
397 | 399 |
|
398 | 400 |
template <class H, class CR> |
399 | 401 |
struct DefHeapTraits : public Traits { |
400 | 402 |
typedef CR HeapCrossRef; |
401 | 403 |
typedef H Heap; |
402 | 404 |
static HeapCrossRef *createHeapCrossRef(const Digraph &) { |
403 | 405 |
throw UninitializedParameter(); |
404 | 406 |
} |
405 | 407 |
static Heap *createHeap(HeapCrossRef &) |
406 | 408 |
{ |
407 | 409 |
throw UninitializedParameter(); |
408 | 410 |
} |
409 | 411 |
}; |
410 | 412 |
///\brief \ref named-templ-param "Named parameter" for setting |
411 | 413 |
///heap and cross reference type |
412 | 414 |
/// |
413 | 415 |
///\ref named-templ-param "Named parameter" for setting heap and cross |
414 | 416 |
///reference type |
415 | 417 |
/// |
416 | 418 |
template <class H, class CR = typename Digraph::template NodeMap<int> > |
417 | 419 |
struct DefHeap |
418 |
: public Dijkstra< Digraph, LengthMap, DefHeapTraits<H, CR> > { |
|
419 |
typedef Dijkstra< Digraph, LengthMap, DefHeapTraits<H, CR> > Create; |
|
420 |
: public Dijkstra< Digraph, LengthMap, DefHeapTraits<H, CR> > { |
|
421 |
typedef Dijkstra< Digraph, LengthMap, DefHeapTraits<H, CR> > Create; |
|
420 | 422 |
}; |
421 | 423 |
|
422 | 424 |
template <class H, class CR> |
423 | 425 |
struct DefStandardHeapTraits : public Traits { |
424 | 426 |
typedef CR HeapCrossRef; |
425 | 427 |
typedef H Heap; |
426 | 428 |
static HeapCrossRef *createHeapCrossRef(const Digraph &G) { |
427 | 429 |
return new HeapCrossRef(G); |
428 | 430 |
} |
429 | 431 |
static Heap *createHeap(HeapCrossRef &R) |
430 | 432 |
{ |
431 | 433 |
return new Heap(R); |
432 | 434 |
} |
433 | 435 |
}; |
434 | 436 |
///\brief \ref named-templ-param "Named parameter" for setting |
435 | 437 |
///heap and cross reference type with automatic allocation |
436 | 438 |
/// |
437 | 439 |
///\ref named-templ-param "Named parameter" for setting heap and cross |
438 | 440 |
///reference type. It can allocate the heap and the cross reference |
439 | 441 |
///object if the cross reference's constructor waits for the digraph as |
440 | 442 |
///parameter and the heap's constructor waits for the cross reference. |
441 | 443 |
template <class H, class CR = typename Digraph::template NodeMap<int> > |
442 | 444 |
struct DefStandardHeap |
443 |
: public Dijkstra< Digraph, LengthMap, DefStandardHeapTraits<H, CR> > { |
|
444 |
typedef Dijkstra< Digraph, LengthMap, DefStandardHeapTraits<H, CR> > |
|
445 |
: public Dijkstra< Digraph, LengthMap, DefStandardHeapTraits<H, CR> > { |
|
446 |
typedef Dijkstra< Digraph, LengthMap, DefStandardHeapTraits<H, CR> > |
|
445 | 447 |
Create; |
446 | 448 |
}; |
447 | 449 |
|
448 | 450 |
template <class T> |
449 | 451 |
struct DefOperationTraitsTraits : public Traits { |
450 | 452 |
typedef T OperationTraits; |
451 | 453 |
}; |
452 | 454 |
|
453 | 455 |
/// \brief \ref named-templ-param "Named parameter" for setting |
454 | 456 |
/// OperationTraits type |
455 | 457 |
/// |
456 | 458 |
/// \ref named-templ-param "Named parameter" for setting OperationTraits |
457 | 459 |
/// type |
458 | 460 |
template <class T> |
459 | 461 |
struct DefOperationTraits |
460 | 462 |
: public Dijkstra<Digraph, LengthMap, DefOperationTraitsTraits<T> > { |
461 | 463 |
typedef Dijkstra<Digraph, LengthMap, DefOperationTraitsTraits<T> > |
462 | 464 |
Create; |
463 | 465 |
}; |
464 | 466 |
|
465 | 467 |
///@} |
466 | 468 |
|
467 | 469 |
|
468 | 470 |
protected: |
469 | 471 |
|
470 | 472 |
Dijkstra() {} |
471 | 473 |
|
472 | 474 |
public: |
473 | 475 |
|
474 | 476 |
///Constructor. |
475 | 477 |
|
476 | 478 |
///\param _G the digraph the algorithm will run on. |
... | ... |
@@ -947,65 +949,66 @@ |
947 | 949 |
} |
948 | 950 |
///The type of the map that stores whether a nodes is processed. |
949 | 951 |
|
950 | 952 |
///The type of the map that stores whether a nodes is processed. |
951 | 953 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
952 | 954 |
///By default it is a NullMap. |
953 | 955 |
///\todo If it is set to a real map, |
954 | 956 |
///Dijkstra::processed() should read this. |
955 | 957 |
///\todo named parameter to set this type, function to read and write. |
956 | 958 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
957 | 959 |
///Instantiates a ProcessedMap. |
958 | 960 |
|
959 | 961 |
///This function instantiates a \ref ProcessedMap. |
960 | 962 |
///\param g is the digraph, to which |
961 | 963 |
///we would like to define the \ref ProcessedMap |
962 | 964 |
#ifdef DOXYGEN |
963 | 965 |
static ProcessedMap *createProcessedMap(const GR &g) |
964 | 966 |
#else |
965 | 967 |
static ProcessedMap *createProcessedMap(const GR &) |
966 | 968 |
#endif |
967 | 969 |
{ |
968 | 970 |
return new ProcessedMap(); |
969 | 971 |
} |
970 | 972 |
///The type of the map that stores the dists of the nodes. |
971 | 973 |
|
972 | 974 |
///The type of the map that stores the dists of the nodes. |
973 | 975 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
974 | 976 |
/// |
975 | 977 |
typedef NullMap<typename Digraph::Node,typename LM::Value> DistMap; |
976 | 978 |
///Instantiates a DistMap. |
977 | 979 |
|
978 | 980 |
///This function instantiates a \ref DistMap. |
979 |
///\param g is the digraph, to which we would like to define |
|
981 |
///\param g is the digraph, to which we would like to define |
|
982 |
///the \ref DistMap |
|
980 | 983 |
#ifdef DOXYGEN |
981 | 984 |
static DistMap *createDistMap(const GR &g) |
982 | 985 |
#else |
983 | 986 |
static DistMap *createDistMap(const GR &) |
984 | 987 |
#endif |
985 | 988 |
{ |
986 | 989 |
return new DistMap(); |
987 | 990 |
} |
988 | 991 |
}; |
989 | 992 |
|
990 | 993 |
/// Default traits used by \ref DijkstraWizard |
991 | 994 |
|
992 | 995 |
/// To make it easier to use Dijkstra algorithm |
993 | 996 |
///we have created a wizard class. |
994 | 997 |
/// This \ref DijkstraWizard class needs default traits, |
995 | 998 |
///as well as the \ref Dijkstra class. |
996 | 999 |
/// The \ref DijkstraWizardBase is a class to be the default traits of the |
997 | 1000 |
/// \ref DijkstraWizard class. |
998 | 1001 |
/// \todo More named parameters are required... |
999 | 1002 |
template<class GR,class LM> |
1000 | 1003 |
class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LM> |
1001 | 1004 |
{ |
1002 | 1005 |
|
1003 | 1006 |
typedef DijkstraWizardDefaultTraits<GR,LM> Base; |
1004 | 1007 |
protected: |
1005 | 1008 |
/// Type of the nodes in the digraph. |
1006 | 1009 |
typedef typename Base::Digraph::Node Node; |
1007 | 1010 |
|
1008 | 1011 |
/// Pointer to the underlying digraph. |
1009 | 1012 |
void *_g; |
1010 | 1013 |
/// Pointer to the length map |
1011 | 1014 |
void *_length; |
... | ... |
@@ -113,65 +113,66 @@ |
113 | 113 |
|
114 | 114 |
bool _showNodePsText; |
115 | 115 |
ConstMap<typename Graph::Node,bool > _nodePsTexts; |
116 | 116 |
char *_nodePsTextsPreamble; |
117 | 117 |
|
118 | 118 |
bool _undirected; |
119 | 119 |
|
120 | 120 |
bool _pleaseRemoveOsStream; |
121 | 121 |
|
122 | 122 |
bool _scaleToA4; |
123 | 123 |
|
124 | 124 |
std::string _title; |
125 | 125 |
std::string _copyright; |
126 | 126 |
|
127 | 127 |
enum NodeTextColorType |
128 | 128 |
{ DIST_COL=0, DIST_BW=1, CUST_COL=2, SAME_COL=3 } _nodeTextColorType; |
129 | 129 |
ConstMap<typename Graph::Node,Color > _nodeTextColors; |
130 | 130 |
|
131 | 131 |
bool _autoNodeScale; |
132 | 132 |
bool _autoArcWidthScale; |
133 | 133 |
|
134 | 134 |
bool _absoluteNodeSizes; |
135 | 135 |
bool _absoluteArcWidths; |
136 | 136 |
|
137 | 137 |
bool _negY; |
138 | 138 |
|
139 | 139 |
bool _preScale; |
140 | 140 |
///Constructor |
141 | 141 |
|
142 | 142 |
///Constructor |
143 | 143 |
///\param _g Reference to the graph to be printed. |
144 | 144 |
///\param _os Reference to the output stream. |
145 |
///\param _os Reference to the output stream. |
|
145 |
///\param _os Reference to the output stream. |
|
146 |
///By default it is <tt>std::cout</tt>. |
|
146 | 147 |
///\param _pros If it is \c true, then the \c ostream referenced by \c _os |
147 | 148 |
///will be explicitly deallocated by the destructor. |
148 | 149 |
DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout, |
149 | 150 |
bool _pros=false) : |
150 | 151 |
g(_g), os(_os), |
151 | 152 |
_coords(dim2::Point<double>(1,1)), _nodeSizes(1), _nodeShapes(0), |
152 | 153 |
_nodeColors(WHITE), _arcColors(BLACK), |
153 | 154 |
_arcWidths(1.0), _arcWidthScale(0.003), |
154 | 155 |
_nodeScale(.01), _xBorder(10), _yBorder(10), _scale(1.0), |
155 | 156 |
_nodeBorderQuotient(.1), |
156 | 157 |
_drawArrows(false), _arrowLength(1), _arrowWidth(0.3), |
157 | 158 |
_showNodes(true), _showArcs(true), |
158 | 159 |
_enableParallel(false), _parArcDist(1), |
159 | 160 |
_showNodeText(false), _nodeTexts(false), _nodeTextSize(1), |
160 | 161 |
_showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0), |
161 | 162 |
_undirected(lemon::UndirectedTagIndicator<G>::value), |
162 | 163 |
_pleaseRemoveOsStream(_pros), _scaleToA4(false), |
163 | 164 |
_nodeTextColorType(SAME_COL), _nodeTextColors(BLACK), |
164 | 165 |
_autoNodeScale(false), |
165 | 166 |
_autoArcWidthScale(false), |
166 | 167 |
_absoluteNodeSizes(false), |
167 | 168 |
_absoluteArcWidths(false), |
168 | 169 |
_negY(false), |
169 | 170 |
_preScale(true) |
170 | 171 |
{} |
171 | 172 |
}; |
172 | 173 |
|
173 | 174 |
///Auxiliary class to implement the named parameters of \ref graphToEps() |
174 | 175 |
|
175 | 176 |
///Auxiliary class to implement the named parameters of \ref graphToEps(). |
176 | 177 |
/// |
177 | 178 |
///For detailed examples see the \ref graph_to_eps_demo.cc demo file. |
... | ... |
@@ -752,222 +753,230 @@ |
752 | 753 |
break; |
753 | 754 |
case FEMALE: |
754 | 755 |
bb.add(p+mycoords[n]); |
755 | 756 |
bb.add(dim2::Point<double>(-ns,-3.01*ns)+mycoords[n]); |
756 | 757 |
break; |
757 | 758 |
} |
758 | 759 |
} |
759 | 760 |
if (bb.empty()) { |
760 | 761 |
bb = dim2::BoundingBox<double>(dim2::Point<double>(0,0)); |
761 | 762 |
} |
762 | 763 |
|
763 | 764 |
if(_scaleToA4) |
764 | 765 |
os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n"; |
765 | 766 |
else { |
766 | 767 |
if(_preScale) { |
767 | 768 |
//Rescale so that BoundingBox won't be neither to big nor too small. |
768 | 769 |
while(bb.height()*_scale>1000||bb.width()*_scale>1000) _scale/=10; |
769 | 770 |
while(bb.height()*_scale<100||bb.width()*_scale<100) _scale*=10; |
770 | 771 |
} |
771 | 772 |
|
772 | 773 |
os << "%%BoundingBox: " |
773 | 774 |
<< int(floor(bb.left() * _scale - _xBorder)) << ' ' |
774 | 775 |
<< int(floor(bb.bottom() * _scale - _yBorder)) << ' ' |
775 | 776 |
<< int(ceil(bb.right() * _scale + _xBorder)) << ' ' |
776 | 777 |
<< int(ceil(bb.top() * _scale + _yBorder)) << '\n'; |
777 | 778 |
} |
778 | 779 |
|
779 | 780 |
os << "%%EndComments\n"; |
780 | 781 |
|
781 | 782 |
//x1 y1 x2 y2 x3 y3 cr cg cb w |
782 | 783 |
os << "/lb { setlinewidth setrgbcolor newpath moveto\n" |
783 | 784 |
<< " 4 2 roll 1 index 1 index curveto stroke } bind def\n"; |
784 |
os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke } |
|
785 |
os << "/l { setlinewidth setrgbcolor newpath moveto lineto stroke }" |
|
786 |
<< " bind def\n"; |
|
785 | 787 |
//x y r |
786 |
os << "/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } |
|
788 |
os << "/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath }" |
|
789 |
<< " bind def\n"; |
|
787 | 790 |
//x y r |
788 | 791 |
os << "/sq { newpath 2 index 1 index add 2 index 2 index add moveto\n" |
789 | 792 |
<< " 2 index 1 index sub 2 index 2 index add lineto\n" |
790 | 793 |
<< " 2 index 1 index sub 2 index 2 index sub lineto\n" |
791 | 794 |
<< " 2 index 1 index add 2 index 2 index sub lineto\n" |
792 | 795 |
<< " closepath pop pop pop} bind def\n"; |
793 | 796 |
//x y r |
794 | 797 |
os << "/di { newpath 2 index 1 index add 2 index moveto\n" |
795 | 798 |
<< " 2 index 2 index 2 index add lineto\n" |
796 | 799 |
<< " 2 index 1 index sub 2 index lineto\n" |
797 | 800 |
<< " 2 index 2 index 2 index sub lineto\n" |
798 | 801 |
<< " closepath pop pop pop} bind def\n"; |
799 | 802 |
// x y r cr cg cb |
800 | 803 |
os << "/nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill\n" |
801 | 804 |
<< " setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n" |
802 | 805 |
<< " } bind def\n"; |
803 | 806 |
os << "/nsq { 0 0 0 setrgbcolor 5 index 5 index 5 index sq fill\n" |
804 | 807 |
<< " setrgbcolor " << 1+_nodeBorderQuotient << " div sq fill\n" |
805 | 808 |
<< " } bind def\n"; |
806 | 809 |
os << "/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill\n" |
807 | 810 |
<< " setrgbcolor " << 1+_nodeBorderQuotient << " div di fill\n" |
808 | 811 |
<< " } bind def\n"; |
809 | 812 |
os << "/nfemale { 0 0 0 setrgbcolor 3 index " |
810 | 813 |
<< _nodeBorderQuotient/(1+_nodeBorderQuotient) |
811 | 814 |
<< " 1.5 mul mul setlinewidth\n" |
812 | 815 |
<< " newpath 5 index 5 index moveto " |
813 | 816 |
<< "5 index 5 index 5 index 3.01 mul sub\n" |
814 |
<< " lineto 5 index 4 index .7 mul sub 5 index 5 index 2.2 mul sub moveto\n" |
|
815 |
<< " 5 index 4 index .7 mul add 5 index 5 index 2.2 mul sub lineto stroke\n" |
|
817 |
<< " lineto 5 index 4 index .7 mul sub 5 index 5 index 2.2 mul sub" |
|
818 |
<< " moveto\n" |
|
819 |
<< " 5 index 4 index .7 mul add 5 index 5 index 2.2 mul sub lineto " |
|
820 |
<< "stroke\n" |
|
816 | 821 |
<< " 5 index 5 index 5 index c fill\n" |
817 | 822 |
<< " setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n" |
818 | 823 |
<< " } bind def\n"; |
819 | 824 |
os << "/nmale {\n" |
820 | 825 |
<< " 0 0 0 setrgbcolor 3 index " |
821 | 826 |
<< _nodeBorderQuotient/(1+_nodeBorderQuotient) |
822 | 827 |
<<" 1.5 mul mul setlinewidth\n" |
823 | 828 |
<< " newpath 5 index 5 index moveto\n" |
824 | 829 |
<< " 5 index 4 index 1 mul 1.5 mul add\n" |
825 | 830 |
<< " 5 index 5 index 3 sqrt 1.5 mul mul add\n" |
826 | 831 |
<< " 1 index 1 index lineto\n" |
827 | 832 |
<< " 1 index 1 index 7 index sub moveto\n" |
828 | 833 |
<< " 1 index 1 index lineto\n" |
829 |
<< " exch 5 index 3 sqrt .5 mul mul sub exch 5 index .5 mul sub |
|
834 |
<< " exch 5 index 3 sqrt .5 mul mul sub exch 5 index .5 mul sub" |
|
835 |
<< " lineto\n" |
|
830 | 836 |
<< " stroke\n" |
831 | 837 |
<< " 5 index 5 index 5 index c fill\n" |
832 | 838 |
<< " setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n" |
833 | 839 |
<< " } bind def\n"; |
834 | 840 |
|
835 | 841 |
|
836 | 842 |
os << "/arrl " << _arrowLength << " def\n"; |
837 | 843 |
os << "/arrw " << _arrowWidth << " def\n"; |
838 | 844 |
// l dx_norm dy_norm |
839 | 845 |
os << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n"; |
840 | 846 |
//len w dx_norm dy_norm x1 y1 cr cg cb |
841 |
os << "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx |
|
847 |
os << "/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx " |
|
848 |
<< "exch def\n" |
|
842 | 849 |
<< " /w exch def /len exch def\n" |
843 |
// |
|
850 |
//<< "0.1 setlinewidth x1 y1 moveto dx len mul dy len mul rlineto stroke" |
|
844 | 851 |
<< " newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto\n" |
845 | 852 |
<< " len w sub arrl sub dx dy lrl\n" |
846 | 853 |
<< " arrw dy dx neg lrl\n" |
847 | 854 |
<< " dx arrl w add mul dy w 2 div arrw add mul sub\n" |
848 | 855 |
<< " dy arrl w add mul dx w 2 div arrw add mul add rlineto\n" |
849 | 856 |
<< " dx arrl w add mul neg dy w 2 div arrw add mul sub\n" |
850 | 857 |
<< " dy arrl w add mul neg dx w 2 div arrw add mul add rlineto\n" |
851 | 858 |
<< " arrw dy dx neg lrl\n" |
852 | 859 |
<< " len w sub arrl sub neg dx dy lrl\n" |
853 | 860 |
<< " closepath fill } bind def\n"; |
854 | 861 |
os << "/cshow { 2 index 2 index moveto dup stringwidth pop\n" |
855 | 862 |
<< " neg 2 div fosi .35 mul neg rmoveto show pop pop} def\n"; |
856 | 863 |
|
857 | 864 |
os << "\ngsave\n"; |
858 | 865 |
if(_scaleToA4) |
859 | 866 |
if(bb.height()>bb.width()) { |
860 | 867 |
double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.height(), |
861 | 868 |
(A4WIDTH-2*A4BORDER)/bb.width()); |
862 | 869 |
os << ((A4WIDTH -2*A4BORDER)-sc*bb.width())/2 + A4BORDER << ' ' |
863 | 870 |
<< ((A4HEIGHT-2*A4BORDER)-sc*bb.height())/2 + A4BORDER |
864 | 871 |
<< " translate\n" |
865 | 872 |
<< sc << " dup scale\n" |
866 | 873 |
<< -bb.left() << ' ' << -bb.bottom() << " translate\n"; |
867 | 874 |
} |
868 | 875 |
else { |
869 | 876 |
//\todo Verify centering |
870 | 877 |
double sc= std::min((A4HEIGHT-2*A4BORDER)/bb.width(), |
871 | 878 |
(A4WIDTH-2*A4BORDER)/bb.height()); |
872 | 879 |
os << ((A4WIDTH -2*A4BORDER)-sc*bb.height())/2 + A4BORDER << ' ' |
873 | 880 |
<< ((A4HEIGHT-2*A4BORDER)-sc*bb.width())/2 + A4BORDER |
874 | 881 |
<< " translate\n" |
875 | 882 |
<< sc << " dup scale\n90 rotate\n" |
876 | 883 |
<< -bb.left() << ' ' << -bb.top() << " translate\n"; |
877 | 884 |
} |
878 | 885 |
else if(_scale!=1.0) os << _scale << " dup scale\n"; |
879 | 886 |
|
880 | 887 |
if(_showArcs) { |
881 | 888 |
os << "%Arcs:\ngsave\n"; |
882 | 889 |
if(_enableParallel) { |
883 | 890 |
std::vector<Arc> el; |
884 | 891 |
for(ArcIt e(g);e!=INVALID;++e) |
885 | 892 |
if((!_undirected||g.source(e)<g.target(e))&&_arcWidths[e]>0 |
886 | 893 |
&&g.source(e)!=g.target(e)) |
887 | 894 |
el.push_back(e); |
888 | 895 |
std::sort(el.begin(),el.end(),arcLess(g)); |
889 | 896 |
|
890 | 897 |
typename std::vector<Arc>::iterator j; |
891 | 898 |
for(typename std::vector<Arc>::iterator i=el.begin();i!=el.end();i=j) { |
892 | 899 |
for(j=i+1;j!=el.end()&&isParallel(*i,*j);++j) ; |
893 | 900 |
|
894 | 901 |
double sw=0; |
895 | 902 |
for(typename std::vector<Arc>::iterator e=i;e!=j;++e) |
896 | 903 |
sw+=_arcWidths[*e]*_arcWidthScale+_parArcDist; |
897 | 904 |
sw-=_parArcDist; |
898 | 905 |
sw/=-2.0; |
899 | 906 |
dim2::Point<double> |
900 | 907 |
dvec(mycoords[g.target(*i)]-mycoords[g.source(*i)]); |
901 | 908 |
double l=std::sqrt(dvec.normSquare()); |
902 | 909 |
//\todo better 'epsilon' would be nice here. |
903 | 910 |
dim2::Point<double> d(dvec/std::max(l,EPSILON)); |
904 | 911 |
dim2::Point<double> m; |
905 |
// m=dim2::Point<double>(mycoords[g.target(*i)]+ |
|
912 |
// m=dim2::Point<double>(mycoords[g.target(*i)]+ |
|
913 |
// mycoords[g.source(*i)])/2.0; |
|
906 | 914 |
|
907 | 915 |
// m=dim2::Point<double>(mycoords[g.source(*i)])+ |
908 | 916 |
// dvec*(double(_nodeSizes[g.source(*i)])/ |
909 | 917 |
// (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)])); |
910 | 918 |
|
911 | 919 |
m=dim2::Point<double>(mycoords[g.source(*i)])+ |
912 | 920 |
d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0; |
913 | 921 |
|
914 | 922 |
for(typename std::vector<Arc>::iterator e=i;e!=j;++e) { |
915 | 923 |
sw+=_arcWidths[*e]*_arcWidthScale/2.0; |
916 | 924 |
dim2::Point<double> mm=m+rot90(d)*sw/.75; |
917 | 925 |
if(_drawArrows) { |
918 | 926 |
int node_shape; |
919 | 927 |
dim2::Point<double> s=mycoords[g.source(*e)]; |
920 | 928 |
dim2::Point<double> t=mycoords[g.target(*e)]; |
921 | 929 |
double rn=_nodeSizes[g.target(*e)]*_nodeScale; |
922 | 930 |
node_shape=_nodeShapes[g.target(*e)]; |
923 | 931 |
dim2::Bezier3 bez(s,mm,mm,t); |
924 | 932 |
double t1=0,t2=1; |
925 | 933 |
for(int ii=0;ii<INTERPOL_PREC;++ii) |
926 | 934 |
if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t2=(t1+t2)/2; |
927 | 935 |
else t1=(t1+t2)/2; |
928 | 936 |
dim2::Point<double> apoint=bez((t1+t2)/2); |
929 | 937 |
rn = _arrowLength+_arcWidths[*e]*_arcWidthScale; |
930 | 938 |
rn*=rn; |
931 | 939 |
t2=(t1+t2)/2;t1=0; |
932 | 940 |
for(int ii=0;ii<INTERPOL_PREC;++ii) |
933 | 941 |
if((bez((t1+t2)/2)-apoint).normSquare()>rn) t1=(t1+t2)/2; |
934 | 942 |
else t2=(t1+t2)/2; |
935 | 943 |
dim2::Point<double> linend=bez((t1+t2)/2); |
936 | 944 |
bez=bez.before((t1+t2)/2); |
937 | 945 |
// rn=_nodeSizes[g.source(*e)]*_nodeScale; |
938 | 946 |
// node_shape=_nodeShapes[g.source(*e)]; |
939 | 947 |
// t1=0;t2=1; |
940 | 948 |
// for(int i=0;i<INTERPOL_PREC;++i) |
941 |
// if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) |
|
949 |
// if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) |
|
950 |
// t1=(t1+t2)/2; |
|
942 | 951 |
// else t2=(t1+t2)/2; |
943 | 952 |
// bez=bez.after((t1+t2)/2); |
944 | 953 |
os << _arcWidths[*e]*_arcWidthScale << " setlinewidth " |
945 | 954 |
<< _arcColors[*e].red() << ' ' |
946 | 955 |
<< _arcColors[*e].green() << ' ' |
947 | 956 |
<< _arcColors[*e].blue() << " setrgbcolor newpath\n" |
948 | 957 |
<< bez.p1.x << ' ' << bez.p1.y << " moveto\n" |
949 | 958 |
<< bez.p2.x << ' ' << bez.p2.y << ' ' |
950 | 959 |
<< bez.p3.x << ' ' << bez.p3.y << ' ' |
951 | 960 |
<< bez.p4.x << ' ' << bez.p4.y << " curveto stroke\n"; |
952 | 961 |
dim2::Point<double> dd(rot90(linend-apoint)); |
953 | 962 |
dd*=(.5*_arcWidths[*e]*_arcWidthScale+_arrowWidth)/ |
954 | 963 |
std::sqrt(dd.normSquare()); |
955 | 964 |
os << "newpath " << psOut(apoint) << " moveto " |
956 | 965 |
<< psOut(linend+dd) << " lineto " |
957 | 966 |
<< psOut(linend-dd) << " lineto closepath fill\n"; |
958 | 967 |
} |
959 | 968 |
else { |
960 | 969 |
os << mycoords[g.source(*e)].x << ' ' |
961 | 970 |
<< mycoords[g.source(*e)].y << ' ' |
962 | 971 |
<< mm.x << ' ' << mm.y << ' ' |
963 | 972 |
<< mycoords[g.target(*e)].x << ' ' |
964 | 973 |
<< mycoords[g.target(*e)].y << ' ' |
965 | 974 |
<< _arcColors[*e].red() << ' ' |
966 | 975 |
<< _arcColors[*e].green() << ' ' |
967 | 976 |
<< _arcColors[*e].blue() << ' ' |
968 | 977 |
<< _arcWidths[*e]*_arcWidthScale << " lb\n"; |
969 | 978 |
} |
970 | 979 |
sw+=_arcWidths[*e]*_arcWidthScale/2.0+_parArcDist; |
971 | 980 |
} |
972 | 981 |
} |
973 | 982 |
} |
... | ... |
@@ -415,65 +415,66 @@ |
415 | 415 |
/// converted to the value type of the map. If the functor is not set, |
416 | 416 |
/// then a default conversion will be used. One map can be read into |
417 | 417 |
/// multiple map objects at the same time. The \c attribute(), \c |
418 | 418 |
/// node() and \c arc() functions are used to add attribute reading |
419 | 419 |
/// rules. |
420 | 420 |
/// |
421 | 421 |
///\code |
422 | 422 |
/// DigraphReader<Digraph>(std::cin, digraph). |
423 | 423 |
/// nodeMap("coordinates", coord_map). |
424 | 424 |
/// arcMap("capacity", cap_map). |
425 | 425 |
/// node("source", src). |
426 | 426 |
/// node("target", trg). |
427 | 427 |
/// attribute("caption", caption). |
428 | 428 |
/// run(); |
429 | 429 |
///\endcode |
430 | 430 |
/// |
431 | 431 |
/// By default the reader uses the first section in the file of the |
432 | 432 |
/// proper type. If a section has an optional name, then it can be |
433 | 433 |
/// selected for reading by giving an optional name parameter to the |
434 | 434 |
/// \c nodes(), \c arcs() or \c attributes() functions. |
435 | 435 |
/// |
436 | 436 |
/// The \c useNodes() and \c useArcs() functions are used to tell the reader |
437 | 437 |
/// that the nodes or arcs should not be constructed (added to the |
438 | 438 |
/// graph) during the reading, but instead the label map of the items |
439 | 439 |
/// are given as a parameter of these functions. An |
440 | 440 |
/// application of these functions is multipass reading, which is |
441 | 441 |
/// important if two \c \@arcs sections must be read from the |
442 | 442 |
/// file. In this case the first phase would read the node set and one |
443 | 443 |
/// of the arc sets, while the second phase would read the second arc |
444 | 444 |
/// set into an \e ArcSet class (\c SmartArcSet or \c ListArcSet). |
445 | 445 |
/// The previously read label node map should be passed to the \c |
446 | 446 |
/// useNodes() functions. Another application of multipass reading when |
447 |
/// paths are given as a node map or an arc map. |
|
447 |
/// paths are given as a node map or an arc map. |
|
448 |
/// It is impossible to read this in |
|
448 | 449 |
/// a single pass, because the arcs are not constructed when the node |
449 | 450 |
/// maps are read. |
450 | 451 |
template <typename _Digraph> |
451 | 452 |
class DigraphReader { |
452 | 453 |
public: |
453 | 454 |
|
454 | 455 |
typedef _Digraph Digraph; |
455 | 456 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
456 | 457 |
|
457 | 458 |
private: |
458 | 459 |
|
459 | 460 |
|
460 | 461 |
std::istream* _is; |
461 | 462 |
bool local_is; |
462 | 463 |
|
463 | 464 |
Digraph& _digraph; |
464 | 465 |
|
465 | 466 |
std::string _nodes_caption; |
466 | 467 |
std::string _arcs_caption; |
467 | 468 |
std::string _attributes_caption; |
468 | 469 |
|
469 | 470 |
typedef std::map<std::string, Node> NodeIndex; |
470 | 471 |
NodeIndex _node_index; |
471 | 472 |
typedef std::map<std::string, Arc> ArcIndex; |
472 | 473 |
ArcIndex _arc_index; |
473 | 474 |
|
474 | 475 |
typedef std::vector<std::pair<std::string, |
475 | 476 |
_reader_bits::MapStorageBase<Node>*> > NodeMaps; |
476 | 477 |
NodeMaps _node_maps; |
477 | 478 |
|
478 | 479 |
typedef std::vector<std::pair<std::string, |
479 | 480 |
_reader_bits::MapStorageBase<Arc>*> >ArcMaps; |
... | ... |
@@ -285,65 +285,66 @@ |
285 | 285 |
///\warning Depending on the operation system and its actual configuration |
286 | 286 |
///the time counters have a certain (10ms on a typical Linux system) |
287 | 287 |
///granularity. |
288 | 288 |
///Therefore this tool is not appropriate to measure very short times. |
289 | 289 |
///Also, if you start and stop the timer very frequently, it could lead to |
290 | 290 |
///distorted results. |
291 | 291 |
/// |
292 | 292 |
///\note If you want to measure the running time of the execution of a certain |
293 | 293 |
///function, consider the usage of \ref TimeReport instead. |
294 | 294 |
/// |
295 | 295 |
///\todo This shouldn't be Unix (Linux) specific. |
296 | 296 |
///\sa TimeReport |
297 | 297 |
class Timer |
298 | 298 |
{ |
299 | 299 |
int _running; //Timer is running iff _running>0; (_running>=0 always holds) |
300 | 300 |
TimeStamp start_time; //This is the relativ start-time if the timer |
301 | 301 |
//is _running, the collected _running time otherwise. |
302 | 302 |
|
303 | 303 |
void _reset() {if(_running) start_time.stamp(); else start_time.reset();} |
304 | 304 |
|
305 | 305 |
public: |
306 | 306 |
///Constructor. |
307 | 307 |
|
308 | 308 |
///\param run indicates whether or not the timer starts immediately. |
309 | 309 |
/// |
310 | 310 |
Timer(bool run=true) :_running(run) {_reset();} |
311 | 311 |
|
312 | 312 |
///\name Control the state of the timer |
313 | 313 |
///Basically a Timer can be either running or stopped, |
314 | 314 |
///but it provides a bit finer control on the execution. |
315 | 315 |
///The \ref Timer also counts the number of \ref start() |
316 | 316 |
///executions, and is stops only after the same amount (or more) |
317 |
///\ref stop() "stop()"s. This can be useful e.g. to compute |
|
317 |
///\ref stop() "stop()"s. This can be useful e.g. to compute |
|
318 |
///the running time |
|
318 | 319 |
///of recursive functions. |
319 | 320 |
/// |
320 | 321 |
|
321 | 322 |
///@{ |
322 | 323 |
|
323 | 324 |
///Reset and stop the time counters |
324 | 325 |
|
325 | 326 |
///This function resets and stops the time counters |
326 | 327 |
///\sa restart() |
327 | 328 |
void reset() |
328 | 329 |
{ |
329 | 330 |
_running=0; |
330 | 331 |
_reset(); |
331 | 332 |
} |
332 | 333 |
|
333 | 334 |
///Start the time counters |
334 | 335 |
|
335 | 336 |
///This function starts the time counters. |
336 | 337 |
/// |
337 | 338 |
///If the timer is started more than ones, it will remain running |
338 | 339 |
///until the same amount of \ref stop() is called. |
339 | 340 |
///\sa stop() |
340 | 341 |
void start() |
341 | 342 |
{ |
342 | 343 |
if(_running) _running++; |
343 | 344 |
else { |
344 | 345 |
_running=1; |
345 | 346 |
TimeStamp t; |
346 | 347 |
t.stamp(); |
347 | 348 |
start_time=t-start_time; |
348 | 349 |
} |
349 | 350 |
} |
... | ... |
@@ -81,58 +81,61 @@ |
81 | 81 |
void checkDijkstra() { |
82 | 82 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
83 | 83 |
typedef typename Digraph::template ArcMap<int> LengthMap; |
84 | 84 |
|
85 | 85 |
Digraph G; |
86 | 86 |
Node s, t; |
87 | 87 |
LengthMap length(G); |
88 | 88 |
PetStruct<Digraph> ps = addPetersen(G, 5); |
89 | 89 |
|
90 | 90 |
for(int i=0;i<5;i++) { |
91 | 91 |
length[ps.outcir[i]]=4; |
92 | 92 |
length[ps.incir[i]]=1; |
93 | 93 |
length[ps.chords[i]]=10; |
94 | 94 |
} |
95 | 95 |
s=ps.outer[0]; |
96 | 96 |
t=ps.inner[1]; |
97 | 97 |
|
98 | 98 |
Dijkstra<Digraph, LengthMap> |
99 | 99 |
dijkstra_test(G, length); |
100 | 100 |
dijkstra_test.run(s); |
101 | 101 |
|
102 | 102 |
check(dijkstra_test.dist(t)==13,"Dijkstra found a wrong path."); |
103 | 103 |
|
104 | 104 |
Path<Digraph> p = dijkstra_test.path(t); |
105 | 105 |
check(p.length()==4,"getPath() found a wrong path."); |
106 | 106 |
check(checkPath(G, p),"path() found a wrong path."); |
107 | 107 |
check(pathSource(G, p) == s,"path() found a wrong path."); |
108 | 108 |
check(pathTarget(G, p) == t,"path() found a wrong path."); |
109 | 109 |
|
110 | 110 |
for(ArcIt e(G); e!=INVALID; ++e) { |
111 | 111 |
Node u=G.source(e); |
112 | 112 |
Node v=G.target(e); |
113 |
check( !dijkstra_test.reached(u) || (dijkstra_test.dist(v) - dijkstra_test.dist(u) <= length[e]), |
|
114 |
"dist(target)-dist(source)-arc_length= " << dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e]); |
|
113 |
check( !dijkstra_test.reached(u) || |
|
114 |
(dijkstra_test.dist(v) - dijkstra_test.dist(u) <= length[e]), |
|
115 |
"dist(target)-dist(source)-arc_length= " << |
|
116 |
dijkstra_test.dist(v) - dijkstra_test.dist(u) - length[e]); |
|
115 | 117 |
} |
116 | 118 |
|
117 | 119 |
for(NodeIt v(G); v!=INVALID; ++v){ |
118 | 120 |
check(dijkstra_test.reached(v),"Each node should be reached."); |
119 | 121 |
if ( dijkstra_test.predArc(v)!=INVALID ) { |
120 | 122 |
Arc e=dijkstra_test.predArc(v); |
121 | 123 |
Node u=G.source(e); |
122 | 124 |
check(u==dijkstra_test.predNode(v),"Wrong tree."); |
123 | 125 |
check(dijkstra_test.dist(v) - dijkstra_test.dist(u) == length[e], |
124 |
"Wrong distance! Difference: " << |
|
126 |
"Wrong distance! Difference: " << |
|
127 |
std::abs(dijkstra_test.dist(v)-dijkstra_test.dist(u)-length[e])); |
|
125 | 128 |
} |
126 | 129 |
} |
127 | 130 |
|
128 | 131 |
{ |
129 | 132 |
NullMap<Node,Arc> myPredMap; |
130 | 133 |
dijkstra(G,length).predMap(myPredMap).run(s); |
131 | 134 |
} |
132 | 135 |
} |
133 | 136 |
|
134 | 137 |
int main() { |
135 | 138 |
checkDijkstra<ListDigraph>(); |
136 | 139 |
checkDijkstra<SmartDigraph>(); |
137 | 140 |
return 0; |
138 | 141 |
} |
... | ... |
@@ -63,96 +63,100 @@ |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
{ |
66 | 66 |
int num = 5; |
67 | 67 |
Digraph fg; |
68 | 68 |
std::vector<Node> nodes; |
69 | 69 |
for (int i = 0; i < num; ++i) { |
70 | 70 |
nodes.push_back(fg.addNode()); |
71 | 71 |
} |
72 | 72 |
for (int i = 0; i < num * num; ++i) { |
73 | 73 |
fg.addArc(nodes[i / num], nodes[i % num]); |
74 | 74 |
} |
75 | 75 |
check(countNodes(fg) == num, "Wrong node number."); |
76 | 76 |
check(countArcs(fg) == num*num, "Wrong arc number."); |
77 | 77 |
for (NodeIt src(fg); src != INVALID; ++src) { |
78 | 78 |
for (NodeIt trg(fg); trg != INVALID; ++trg) { |
79 | 79 |
ConArcIt<Digraph> con(fg, src, trg); |
80 | 80 |
check(con != INVALID, "There is no connecting arc."); |
81 | 81 |
check(fg.source(con) == src, "Wrong source."); |
82 | 82 |
check(fg.target(con) == trg, "Wrong target."); |
83 | 83 |
check(++con == INVALID, "There is more connecting arc."); |
84 | 84 |
} |
85 | 85 |
} |
86 | 86 |
ArcLookUp<Digraph> al1(fg); |
87 | 87 |
DynArcLookUp<Digraph> al2(fg); |
88 | 88 |
AllArcLookUp<Digraph> al3(fg); |
89 | 89 |
for (NodeIt src(fg); src != INVALID; ++src) { |
90 | 90 |
for (NodeIt trg(fg); trg != INVALID; ++trg) { |
91 | 91 |
Arc con1 = al1(src, trg); |
92 | 92 |
Arc con2 = al2(src, trg); |
93 | 93 |
Arc con3 = al3(src, trg); |
94 | 94 |
Arc con4 = findArc(fg, src, trg); |
95 |
check(con1 == con2 && con2 == con3 && con3 == con4, |
|
95 |
check(con1 == con2 && con2 == con3 && con3 == con4, |
|
96 |
"Different results.") |
|
96 | 97 |
check(con1 != INVALID, "There is no connecting arc."); |
97 | 98 |
check(fg.source(con1) == src, "Wrong source."); |
98 | 99 |
check(fg.target(con1) == trg, "Wrong target."); |
99 |
check(al3(src, trg, con3) == INVALID, "There is more connecting arc."); |
|
100 |
check(findArc(fg, src, trg, con4) == INVALID, "There is more connecting arc."); |
|
100 |
check(al3(src, trg, con3) == INVALID, |
|
101 |
"There is more connecting arc."); |
|
102 |
check(findArc(fg, src, trg, con4) == INVALID, |
|
103 |
"There is more connecting arc."); |
|
101 | 104 |
} |
102 | 105 |
} |
103 | 106 |
} |
104 | 107 |
} |
105 | 108 |
|
106 | 109 |
template <typename Graph> |
107 | 110 |
void checkFindEdges() { |
108 | 111 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
109 | 112 |
Graph graph; |
110 | 113 |
for (int i = 0; i < 10; ++i) { |
111 | 114 |
graph.addNode(); |
112 | 115 |
} |
113 | 116 |
DescriptorMap<Graph, Node> nodes(graph); |
114 | 117 |
typename DescriptorMap<Graph, Node>::InverseMap invNodes(nodes); |
115 | 118 |
for (int i = 0; i < 100; ++i) { |
116 | 119 |
int src = rnd[invNodes.size()]; |
117 | 120 |
int trg = rnd[invNodes.size()]; |
118 | 121 |
graph.addEdge(invNodes[src], invNodes[trg]); |
119 | 122 |
} |
120 | 123 |
typename Graph::template EdgeMap<int> found(graph, 0); |
121 | 124 |
DescriptorMap<Graph, Edge> edges(graph); |
122 | 125 |
for (NodeIt src(graph); src != INVALID; ++src) { |
123 | 126 |
for (NodeIt trg(graph); trg != INVALID; ++trg) { |
124 | 127 |
for (ConEdgeIt<Graph> con(graph, src, trg); con != INVALID; ++con) { |
125 | 128 |
check( (graph.u(con) == src && graph.v(con) == trg) || |
126 |
(graph.v(con) == src && graph.u(con) == trg), |
|
129 |
(graph.v(con) == src && graph.u(con) == trg), |
|
130 |
"Wrong end nodes."); |
|
127 | 131 |
++found[con]; |
128 | 132 |
check(found[con] <= 2, "The edge found more than twice."); |
129 | 133 |
} |
130 | 134 |
} |
131 | 135 |
} |
132 | 136 |
for (EdgeIt it(graph); it != INVALID; ++it) { |
133 | 137 |
check( (graph.u(it) != graph.v(it) && found[it] == 2) || |
134 | 138 |
(graph.u(it) == graph.v(it) && found[it] == 1), |
135 | 139 |
"The edge is not found correctly."); |
136 | 140 |
} |
137 | 141 |
} |
138 | 142 |
|
139 | 143 |
template <class Digraph> |
140 | 144 |
void checkDeg() |
141 | 145 |
{ |
142 | 146 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
143 | 147 |
|
144 | 148 |
const int nodeNum = 10; |
145 | 149 |
const int arcNum = 100; |
146 | 150 |
Digraph digraph; |
147 | 151 |
InDegMap<Digraph> inDeg(digraph); |
148 | 152 |
OutDegMap<Digraph> outDeg(digraph); |
149 | 153 |
std::vector<Node> nodes(nodeNum); |
150 | 154 |
for (int i = 0; i < nodeNum; ++i) { |
151 | 155 |
nodes[i] = digraph.addNode(); |
152 | 156 |
} |
153 | 157 |
std::vector<Arc> arcs(arcNum); |
154 | 158 |
for (int i = 0; i < arcNum; ++i) { |
155 | 159 |
arcs[i] = digraph.addArc(nodes[rnd[nodeNum]], nodes[rnd[nodeNum]]); |
156 | 160 |
} |
157 | 161 |
for (int i = 0; i < nodeNum; ++i) { |
158 | 162 |
check(inDeg[nodes[i]] == countInArcs(digraph, nodes[i]), |
... | ... |
@@ -74,258 +74,280 @@ |
74 | 74 |
|
75 | 75 |
// NullMap |
76 | 76 |
{ |
77 | 77 |
checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >(); |
78 | 78 |
NullMap<A,B> map1; |
79 | 79 |
NullMap<A,B> map2 = map1; |
80 | 80 |
map1 = nullMap<A,B>(); |
81 | 81 |
} |
82 | 82 |
|
83 | 83 |
// ConstMap |
84 | 84 |
{ |
85 | 85 |
checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >(); |
86 | 86 |
checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >(); |
87 | 87 |
ConstMap<A,B> map1; |
88 | 88 |
ConstMap<A,B> map2 = B(); |
89 | 89 |
ConstMap<A,B> map3 = map1; |
90 | 90 |
map1 = constMap<A>(B()); |
91 | 91 |
map1 = constMap<A,B>(); |
92 | 92 |
map1.setAll(B()); |
93 | 93 |
ConstMap<A,C> map4(C(1)); |
94 | 94 |
ConstMap<A,C> map5 = map4; |
95 | 95 |
map4 = constMap<A>(C(2)); |
96 | 96 |
map4.setAll(C(3)); |
97 | 97 |
|
98 | 98 |
checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >(); |
99 | 99 |
check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap"); |
100 | 100 |
|
101 | 101 |
checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >(); |
102 | 102 |
ConstMap<A,Const<int,10> > map6; |
103 | 103 |
ConstMap<A,Const<int,10> > map7 = map6; |
104 | 104 |
map6 = constMap<A,int,10>(); |
105 | 105 |
map7 = constMap<A,Const<int,10> >(); |
106 |
check(map6[A()] == 10 && map7[A()] == 10, |
|
106 |
check(map6[A()] == 10 && map7[A()] == 10, |
|
107 |
"Something is wrong with ConstMap"); |
|
107 | 108 |
} |
108 | 109 |
|
109 | 110 |
// IdentityMap |
110 | 111 |
{ |
111 | 112 |
checkConcept<ReadMap<A,A>, IdentityMap<A> >(); |
112 | 113 |
IdentityMap<A> map1; |
113 | 114 |
IdentityMap<A> map2 = map1; |
114 | 115 |
map1 = identityMap<A>(); |
115 | 116 |
|
116 | 117 |
checkConcept<ReadMap<double,double>, IdentityMap<double> >(); |
117 |
check(identityMap<double>()[1.0] == 1.0 && |
|
118 |
check(identityMap<double>()[1.0] == 1.0 && |
|
119 |
identityMap<double>()[3.14] == 3.14, |
|
118 | 120 |
"Something is wrong with IdentityMap"); |
119 | 121 |
} |
120 | 122 |
|
121 | 123 |
// RangeMap |
122 | 124 |
{ |
123 | 125 |
checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >(); |
124 | 126 |
RangeMap<B> map1; |
125 | 127 |
RangeMap<B> map2(10); |
126 | 128 |
RangeMap<B> map3(10,B()); |
127 | 129 |
RangeMap<B> map4 = map1; |
128 | 130 |
RangeMap<B> map5 = rangeMap<B>(); |
129 | 131 |
RangeMap<B> map6 = rangeMap<B>(10); |
130 | 132 |
RangeMap<B> map7 = rangeMap(10,B()); |
131 | 133 |
|
132 | 134 |
checkConcept< ReferenceMap<int, double, double&, const double&>, |
133 | 135 |
RangeMap<double> >(); |
134 | 136 |
std::vector<double> v(10, 0); |
135 | 137 |
v[5] = 100; |
136 | 138 |
RangeMap<double> map8(v); |
137 | 139 |
RangeMap<double> map9 = rangeMap(v); |
138 | 140 |
check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100, |
139 | 141 |
"Something is wrong with RangeMap"); |
140 | 142 |
} |
141 | 143 |
|
142 | 144 |
// SparseMap |
143 | 145 |
{ |
144 | 146 |
checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >(); |
145 | 147 |
SparseMap<A,B> map1; |
146 | 148 |
SparseMap<A,B> map2 = B(); |
147 | 149 |
SparseMap<A,B> map3 = sparseMap<A,B>(); |
148 | 150 |
SparseMap<A,B> map4 = sparseMap<A>(B()); |
149 | 151 |
|
150 | 152 |
checkConcept< ReferenceMap<double, int, int&, const int&>, |
151 | 153 |
SparseMap<double, int> >(); |
152 | 154 |
std::map<double, int> m; |
153 | 155 |
SparseMap<double, int> map5(m); |
154 | 156 |
SparseMap<double, int> map6(m,10); |
155 | 157 |
SparseMap<double, int> map7 = sparseMap(m); |
156 | 158 |
SparseMap<double, int> map8 = sparseMap(m,10); |
157 | 159 |
|
158 |
check(map5[1.0] == 0 && map5[3.14] == 0 && |
|
160 |
check(map5[1.0] == 0 && map5[3.14] == 0 && |
|
161 |
map6[1.0] == 10 && map6[3.14] == 10, |
|
159 | 162 |
"Something is wrong with SparseMap"); |
160 | 163 |
map5[1.0] = map6[3.14] = 100; |
161 |
check(map5[1.0] == 100 && map5[3.14] == 0 && |
|
164 |
check(map5[1.0] == 100 && map5[3.14] == 0 && |
|
165 |
map6[1.0] == 10 && map6[3.14] == 100, |
|
162 | 166 |
"Something is wrong with SparseMap"); |
163 | 167 |
} |
164 | 168 |
|
165 | 169 |
// ComposeMap |
166 | 170 |
{ |
167 | 171 |
typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap; |
168 | 172 |
checkConcept<ReadMap<B,double>, CompMap>(); |
169 | 173 |
CompMap map1(DoubleMap(),ReadMap<B,A>()); |
170 | 174 |
CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>()); |
171 | 175 |
|
172 | 176 |
SparseMap<double, bool> m1(false); m1[3.14] = true; |
173 | 177 |
RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14; |
174 |
check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1], |
|
178 |
check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1], |
|
179 |
"Something is wrong with ComposeMap") |
|
175 | 180 |
} |
176 | 181 |
|
177 | 182 |
// CombineMap |
178 | 183 |
{ |
179 | 184 |
typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap; |
180 | 185 |
checkConcept<ReadMap<A,double>, CombMap>(); |
181 | 186 |
CombMap map1(DoubleMap(), DoubleMap()); |
182 | 187 |
CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>()); |
183 | 188 |
|
184 | 189 |
check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3, |
185 | 190 |
"Something is wrong with CombineMap"); |
186 | 191 |
} |
187 | 192 |
|
188 | 193 |
// FunctorToMap, MapToFunctor |
189 | 194 |
{ |
190 | 195 |
checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >(); |
191 | 196 |
checkConcept<ReadMap<A,B>, FunctorToMap<F> >(); |
192 | 197 |
FunctorToMap<F> map1; |
193 | 198 |
FunctorToMap<F> map2(F()); |
194 | 199 |
B b = functorToMap(F())[A()]; |
195 | 200 |
|
196 | 201 |
checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >(); |
197 | 202 |
MapToFunctor<ReadMap<A,B> > map(ReadMap<A,B>()); |
198 | 203 |
|
199 |
check(functorToMap(&func)[A()] == 3, "Something is wrong with FunctorToMap"); |
|
200 |
check(mapToFunctor(constMap<A,int>(2))(A()) == 2, "Something is wrong with MapToFunctor"); |
|
201 |
check( |
|
204 |
check(functorToMap(&func)[A()] == 3, |
|
205 |
"Something is wrong with FunctorToMap"); |
|
206 |
check(mapToFunctor(constMap<A,int>(2))(A()) == 2, |
|
207 |
"Something is wrong with MapToFunctor"); |
|
208 |
check(mapToFunctor(functorToMap(&func))(A()) == 3 && |
|
209 |
mapToFunctor(functorToMap(&func))[A()] == 3, |
|
202 | 210 |
"Something is wrong with FunctorToMap or MapToFunctor"); |
203 | 211 |
check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2, |
204 | 212 |
"Something is wrong with FunctorToMap or MapToFunctor"); |
205 | 213 |
} |
206 | 214 |
|
207 | 215 |
// ConvertMap |
208 | 216 |
{ |
209 |
checkConcept<ReadMap<double,double>, |
|
217 |
checkConcept<ReadMap<double,double>, |
|
218 |
ConvertMap<ReadMap<double, int>, double> >(); |
|
210 | 219 |
ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true)); |
211 | 220 |
ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false)); |
212 | 221 |
} |
213 | 222 |
|
214 | 223 |
// ForkMap |
215 | 224 |
{ |
216 | 225 |
checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >(); |
217 | 226 |
|
218 | 227 |
typedef RangeMap<double> RM; |
219 | 228 |
typedef SparseMap<int, double> SM; |
220 | 229 |
RM m1(10, -1); |
221 | 230 |
SM m2(-1); |
222 | 231 |
checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >(); |
223 | 232 |
checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >(); |
224 | 233 |
ForkMap<RM, SM> map1(m1,m2); |
225 | 234 |
ForkMap<SM, RM> map2 = forkMap(m2,m1); |
226 | 235 |
map2.set(5, 10); |
227 |
check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 && |
|
236 |
check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 && |
|
237 |
m2[5] == 10 && map2[1] == -1 && map2[5] == 10, |
|
228 | 238 |
"Something is wrong with ForkMap"); |
229 | 239 |
} |
230 | 240 |
|
231 | 241 |
// Arithmetic maps: |
232 | 242 |
// - AddMap, SubMap, MulMap, DivMap |
233 | 243 |
// - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap |
234 | 244 |
// - NegMap, NegWriteMap, AbsMap |
235 | 245 |
{ |
236 | 246 |
checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >(); |
237 | 247 |
checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >(); |
238 | 248 |
checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >(); |
239 | 249 |
checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >(); |
240 | 250 |
|
241 | 251 |
ConstMap<int, double> c1(1.0), c2(3.14); |
242 | 252 |
IdentityMap<int> im; |
243 | 253 |
ConvertMap<IdentityMap<int>, double> id(im); |
244 |
check(addMap(c1,id)[0] == 1.0 && addMap(c1,id)[10] == 11.0, "Something is wrong with AddMap"); |
|
245 |
check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0, "Something is wrong with SubMap"); |
|
246 |
check(mulMap(id,c2)[0] == 0 && mulMap(id,c2)[2] == 6.28, "Something is wrong with MulMap"); |
|
247 |
check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2] == 1.57, "Something is wrong with DivMap"); |
|
254 |
check(addMap(c1,id)[0] == 1.0 && addMap(c1,id)[10] == 11.0, |
|
255 |
"Something is wrong with AddMap"); |
|
256 |
check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0, |
|
257 |
"Something is wrong with SubMap"); |
|
258 |
check(mulMap(id,c2)[0] == 0 && mulMap(id,c2)[2] == 6.28, |
|
259 |
"Something is wrong with MulMap"); |
|
260 |
check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2] == 1.57, |
|
261 |
"Something is wrong with DivMap"); |
|
248 | 262 |
|
249 | 263 |
checkConcept<DoubleMap, ShiftMap<DoubleMap> >(); |
250 | 264 |
checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >(); |
251 | 265 |
checkConcept<DoubleMap, ScaleMap<DoubleMap> >(); |
252 | 266 |
checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >(); |
253 | 267 |
checkConcept<DoubleMap, NegMap<DoubleMap> >(); |
254 | 268 |
checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >(); |
255 | 269 |
checkConcept<DoubleMap, AbsMap<DoubleMap> >(); |
256 | 270 |
|
257 | 271 |
check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0, |
258 | 272 |
"Something is wrong with ShiftMap"); |
259 |
check(shiftWriteMap(id, 2.0)[1] == 3.0 && |
|
273 |
check(shiftWriteMap(id, 2.0)[1] == 3.0 && |
|
274 |
shiftWriteMap(id, 2.0)[10] == 12.0, |
|
260 | 275 |
"Something is wrong with ShiftWriteMap"); |
261 | 276 |
check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0, |
262 | 277 |
"Something is wrong with ScaleMap"); |
263 |
check(scaleWriteMap(id, 2.0)[1] == 2.0 && |
|
278 |
check(scaleWriteMap(id, 2.0)[1] == 2.0 && |
|
279 |
scaleWriteMap(id, 2.0)[10] == 20.0, |
|
264 | 280 |
"Something is wrong with ScaleWriteMap"); |
265 | 281 |
check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0, |
266 | 282 |
"Something is wrong with NegMap"); |
267 | 283 |
check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0, |
268 | 284 |
"Something is wrong with NegWriteMap"); |
269 | 285 |
check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0, |
270 | 286 |
"Something is wrong with AbsMap"); |
271 | 287 |
} |
272 | 288 |
|
273 | 289 |
// Logical maps: |
274 | 290 |
// - TrueMap, FalseMap |
275 | 291 |
// - AndMap, OrMap |
276 | 292 |
// - NotMap, NotWriteMap |
277 | 293 |
// - EqualMap, LessMap |
278 | 294 |
{ |
279 | 295 |
checkConcept<BoolMap, TrueMap<A> >(); |
280 | 296 |
checkConcept<BoolMap, FalseMap<A> >(); |
281 | 297 |
checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >(); |
282 | 298 |
checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >(); |
283 | 299 |
checkConcept<BoolMap, NotMap<BoolMap> >(); |
284 | 300 |
checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >(); |
285 | 301 |
checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >(); |
286 | 302 |
checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >(); |
287 | 303 |
|
288 | 304 |
TrueMap<int> tm; |
289 | 305 |
FalseMap<int> fm; |
290 | 306 |
RangeMap<bool> rm(2); |
291 | 307 |
rm[0] = true; rm[1] = false; |
292 |
check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] && |
|
308 |
check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] && |
|
309 |
!andMap(fm,rm)[0] && !andMap(fm,rm)[1], |
|
293 | 310 |
"Something is wrong with AndMap"); |
294 |
check(orMap(tm,rm)[0] && orMap(tm,rm)[1] && |
|
311 |
check(orMap(tm,rm)[0] && orMap(tm,rm)[1] && |
|
312 |
orMap(fm,rm)[0] && !orMap(fm,rm)[1], |
|
295 | 313 |
"Something is wrong with OrMap"); |
296 |
check(!notMap(rm)[0] && notMap(rm)[1], "Something is wrong with NotMap"); |
|
297 |
check(!notWriteMap(rm)[0] && notWriteMap(rm)[1], "Something is wrong with NotWriteMap"); |
|
314 |
check(!notMap(rm)[0] && notMap(rm)[1], |
|
315 |
"Something is wrong with NotMap"); |
|
316 |
check(!notWriteMap(rm)[0] && notWriteMap(rm)[1], |
|
317 |
"Something is wrong with NotWriteMap"); |
|
298 | 318 |
|
299 | 319 |
ConstMap<int, double> cm(2.0); |
300 | 320 |
IdentityMap<int> im; |
301 | 321 |
ConvertMap<IdentityMap<int>, double> id(im); |
302 | 322 |
check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3], |
303 | 323 |
"Something is wrong with LessMap"); |
304 | 324 |
check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3], |
305 | 325 |
"Something is wrong with EqualMap"); |
306 | 326 |
} |
307 | 327 |
|
308 | 328 |
// LoggerBoolMap |
309 | 329 |
{ |
310 | 330 |
typedef std::vector<int> vec; |
311 | 331 |
vec v1; |
312 | 332 |
vec v2(10); |
313 |
LoggerBoolMap<std::back_insert_iterator<vec> > |
|
333 |
LoggerBoolMap<std::back_insert_iterator<vec> > |
|
334 |
map1(std::back_inserter(v1)); |
|
314 | 335 |
LoggerBoolMap<vec::iterator> map2(v2.begin()); |
315 | 336 |
map1.set(10, false); |
316 | 337 |
map1.set(20, true); map2.set(20, true); |
317 | 338 |
map1.set(30, false); map2.set(40, false); |
318 | 339 |
map1.set(50, true); map2.set(50, true); |
319 | 340 |
map1.set(60, true); map2.set(60, true); |
320 | 341 |
check(v1.size() == 3 && v2.size() == 10 && |
321 |
v1[0]==20 && v1[1]==50 && v1[2]==60 && |
|
342 |
v1[0]==20 && v1[1]==50 && v1[2]==60 && |
|
343 |
v2[0]==20 && v2[1]==50 && v2[2]==60, |
|
322 | 344 |
"Something is wrong with LoggerBoolMap"); |
323 | 345 |
|
324 | 346 |
int i = 0; |
325 | 347 |
for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin(); |
326 | 348 |
it != map2.end(); ++it ) |
327 | 349 |
check(v1[i++] == *it, "Something is wrong with LoggerBoolMap"); |
328 | 350 |
} |
329 | 351 |
|
330 | 352 |
return 0; |
331 | 353 |
} |
0 comments (0 inline)