gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Merge
0 2 0
merge default
0 files changed with 24 insertions and 24 deletions:
↑ Collapse diff ↑
Ignore white space 196608 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5 5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

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

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

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

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

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

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

	
60 60
/**
61 61
@defgroup semi_adaptors Semi-Adaptor Classes for Graphs
62 62
@ingroup graphs
63 63
\brief Graph types between real graphs and graph adaptors.
64 64

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

	
70 70
/**
71 71
@defgroup maps Maps 
72 72
@ingroup datas
73 73
\brief Map structures implemented in LEMON.
74 74

	
75 75
This group describes the map structures implemented in LEMON.
76 76

	
77 77
LEMON provides several special purpose maps that e.g. combine
78 78
new maps from existing ones.
79 79
*/
80 80

	
81 81
/**
82 82
@defgroup graph_maps Graph Maps 
83 83
@ingroup maps
84 84
\brief Special Graph-Related Maps.
85 85

	
86 86
This group describes maps that are specifically designed to assign
87 87
values to the nodes and edges of graphs.
88 88
*/
89 89

	
90 90

	
91 91
/**
92 92
\defgroup map_adaptors Map Adaptors
93 93
\ingroup maps
94 94
\brief Tools to create new maps from existing ones
95 95

	
96 96
This group describes map adaptors that are used to create "implicit"
97 97
maps from other maps.
98 98

	
99 99
Most of them are \ref lemon::concepts::ReadMap "ReadMap"s. They can
100 100
make arithmetic operations between one or two maps (negation, scaling,
101 101
addition, multiplication etc.) or e.g. convert a map to another one
102 102
of different Value type.
103 103

	
104 104
The typical usage of this classes is passing implicit maps to
105 105
algorithms.  If a function type algorithm is called then the function
106 106
type map adaptors can be used comfortable. For example let's see the
107 107
usage of map adaptors with the \c graphToEps() function:
108 108
\code
109 109
  Color nodeColor(int deg) {
110 110
    if (deg >= 2) {
111 111
      return Color(0.5, 0.0, 0.5);
112 112
    } else if (deg == 1) {
113 113
      return Color(1.0, 0.5, 1.0);
114 114
    } else {
115 115
      return Color(0.0, 0.0, 0.0);
116 116
    }
117 117
  }
118 118
  
119 119
  Graph::NodeMap<int> degree_map(graph);
120 120
  
121 121
  graphToEps(graph, "graph.eps")
122 122
    .coords(coords).scaleToA4().undirected()
123 123
    .nodeColors(composeMap(functorMap(nodeColor), degree_map)) 
124 124
    .run();
125 125
\endcode 
126 126
The \c functorMap() function makes an \c int to \c Color map from the
127 127
\e nodeColor() function. The \c composeMap() compose the \e degree_map
128 128
and the previous created map. The composed map is proper function to
129 129
get color of each node.
130 130

	
131 131
The usage with class type algorithms is little bit harder. In this
132 132
case the function type map adaptors can not be used, because the
133 133
function map adaptors give back temporary objects.
134 134
\code
135 135
  Graph graph;
136 136
  
137 137
  typedef Graph::EdgeMap<double> DoubleEdgeMap;
138 138
  DoubleEdgeMap length(graph);
139 139
  DoubleEdgeMap speed(graph);
140 140
  
141 141
  typedef DivMap<DoubleEdgeMap, DoubleEdgeMap> TimeMap;
142 142
  
143 143
  TimeMap time(length, speed);
144 144
  
145 145
  Dijkstra<Graph, TimeMap> dijkstra(graph, time);
146 146
  dijkstra.run(source, target);
147 147
\endcode
148 148

	
149 149
We have a length map and a maximum speed map on a graph. The minimum
150 150
time to pass the edge can be calculated as the division of the two
151 151
maps which can be done implicitly with the \c DivMap template
152 152
class. We use the implicit minimum time map as the length map of the
153 153
\c Dijkstra algorithm.
154 154
*/
155 155

	
156 156
/**
157 157
@defgroup matrices Matrices 
158 158
@ingroup datas
159 159
\brief Two dimensional data storages implemented in LEMON.
160 160

	
161 161
This group describes two dimensional data storages implemented in LEMON.
162 162
*/
163 163

	
164 164
/**
165 165
@defgroup paths Path Structures
166 166
@ingroup datas
167 167
\brief Path structures implemented in LEMON.
168 168

	
169 169
This group describes the path structures implemented in LEMON.
170 170

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

	
177 177
\sa lemon::concepts::Path
178 178

	
179 179
*/
180 180

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

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

	
190 190

	
191 191
/**
192 192
@defgroup algs Algorithms
193 193
\brief This group describes the several algorithms
194 194
implemented in LEMON.
195 195

	
196 196
This group describes the several algorithms
197 197
implemented in LEMON.
198 198
*/
199 199

	
200 200
/**
201 201
@defgroup search Graph Search
202 202
@ingroup algs
203 203
\brief Common graph search algorithms.
204 204

	
205 205
This group describes the common graph search algorithms like 
206 206
Breadth-first search (Bfs) and Depth-first search (Dfs).
207 207
*/
208 208

	
209 209
/**
210 210
@defgroup shortest_path Shortest Path algorithms
211 211
@ingroup algs
212 212
\brief Algorithms for finding shortest paths.
213 213

	
214 214
This group describes the algorithms for finding shortest paths in graphs.
215 215
*/
216 216

	
217 217
/** 
218 218
@defgroup max_flow Maximum Flow algorithms 
219 219
@ingroup algs 
220 220
\brief Algorithms for finding maximum flows.
221 221

	
222 222
This group describes the algorithms for finding maximum flows and
223 223
feasible circulations.
224 224

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

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

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

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

	
246 246
*/
247 247

	
248 248
/**
249 249
@defgroup min_cost_flow Minimum Cost Flow algorithms
250 250
@ingroup algs
251 251

	
252 252
\brief Algorithms for finding minimum cost flows and circulations.
253 253

	
254 254
This group describes the algorithms for finding minimum cost flows and
255 255
circulations.  
256 256
*/
257 257

	
258 258
/**
259 259
@defgroup min_cut Minimum Cut algorithms 
260 260
@ingroup algs 
261 261

	
262 262
\brief Algorithms for finding minimum cut in graphs.
263 263

	
264 264
This group describes the algorithms for finding minimum cut in graphs.
265 265

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

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

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

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

	
283 283
If you want to find minimum cut just between two distinict nodes,
284 284
please see the \ref max_flow "Maximum Flow page".
285 285

	
286 286
*/
287 287

	
288 288
/**
289 289
@defgroup graph_prop Connectivity and other graph properties
290 290
@ingroup algs
291 291
\brief Algorithms for discovering the graph properties
292 292

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

	
296 296
\image html edge_biconnected_components.png
297 297
\image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth
298 298
*/
299 299

	
300 300
/**
301 301
@defgroup planar Planarity embedding and drawing
302 302
@ingroup algs
303 303
\brief Algorithms for planarity checking, embedding and drawing
304 304

	
305 305
This group describes the algorithms for planarity checking, embedding and drawing.
306 306

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

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

	
316 316
This group contains algorithm objects and functions to calculate
317 317
matchings in graphs and bipartite graphs. The general matching problem is
318 318
finding a subset of the edges which does not shares common endpoints.
319 319
 
320 320
There are several different algorithms for calculate matchings in
321 321
graphs.  The matching problems in bipartite graphs are generally
322 322
easier than in general graphs. The goal of the matching optimization
323 323
can be the finding maximum cardinality, maximum weight or minimum cost
324 324
matching. The search can be constrained to find perfect or
325 325
maximum cardinality matching.
326 326

	
327 327
Lemon contains the next algorithms:
328 328
- \ref lemon::MaxBipartiteMatching "MaxBipartiteMatching" Hopcroft-Karp 
329 329
  augmenting path algorithm for calculate maximum cardinality matching in 
330 330
  bipartite graphs
331 331
- \ref lemon::PrBipartiteMatching "PrBipartiteMatching" Push-Relabel 
332 332
  algorithm for calculate maximum cardinality matching in bipartite graphs 
333 333
- \ref lemon::MaxWeightedBipartiteMatching "MaxWeightedBipartiteMatching" 
334 334
  Successive shortest path algorithm for calculate maximum weighted matching 
335 335
  and maximum weighted bipartite matching in bipartite graph
336 336
- \ref lemon::MinCostMaxBipartiteMatching "MinCostMaxBipartiteMatching" 
337 337
  Successive shortest path algorithm for calculate minimum cost maximum 
338 338
  matching in bipartite graph
339 339
- \ref lemon::MaxMatching "MaxMatching" Edmond's blossom shrinking algorithm
340 340
  for calculate maximum cardinality matching in general graph
341 341
- \ref lemon::MaxWeightedMatching "MaxWeightedMatching" Edmond's blossom
342 342
  shrinking algorithm for calculate maximum weighted matching in general
343 343
  graph
344 344
- \ref lemon::MaxWeightedPerfectMatching "MaxWeightedPerfectMatching"
345 345
  Edmond's blossom shrinking algorithm for calculate maximum weighted
346 346
  perfect matching in general graph
347 347

	
348 348
\image html bipartite_matching.png
349 349
\image latex bipartite_matching.eps "Bipartite Matching" width=\textwidth
350 350

	
351 351
*/
352 352

	
353 353
/**
354 354
@defgroup spantree Minimum Spanning Tree algorithms
355 355
@ingroup algs
356 356
\brief Algorithms for finding a minimum cost spanning tree in a graph.
357 357

	
358 358
This group describes the algorithms for finding a minimum cost spanning
359 359
tree in a graph
360 360
*/
361 361

	
362 362

	
363 363
/**
364 364
@defgroup auxalg Auxiliary algorithms
365 365
@ingroup algs
366 366
\brief Auxiliary algorithms implemented in LEMON.
367 367

	
368 368
This group describes some algorithms implemented in LEMON
369 369
in order to make it easier to implement complex algorithms.
370 370
*/
371 371

	
372 372
/**
373 373
@defgroup approx Approximation algorithms
374 374
\brief Approximation algorithms.
375 375

	
376 376
This group describes the approximation and heuristic algorithms
377 377
implemented in LEMON.
378 378
*/
379 379

	
380 380
/**
381 381
@defgroup gen_opt_group General Optimization Tools
382 382
\brief This group describes some general optimization frameworks
383 383
implemented in LEMON.
384 384

	
385 385
This group describes some general optimization frameworks
386 386
implemented in LEMON.
387 387

	
388 388
*/
389 389

	
390 390
/**
391 391
@defgroup lp_group Lp and Mip solvers
392 392
@ingroup gen_opt_group
393 393
\brief Lp and Mip solver interfaces for LEMON.
394 394

	
395 395
This group describes Lp and Mip solver interfaces for LEMON. The
396 396
various LP solvers could be used in the same manner with this
397 397
interface.
398 398

	
399 399
*/
400 400

	
401 401
/** 
402 402
@defgroup lp_utils Tools for Lp and Mip solvers 
403 403
@ingroup lp_group
404 404
\brief Helper tools to the Lp and Mip solvers.
405 405

	
406 406
This group adds some helper tools to general optimization framework
407 407
implemented in LEMON.
408 408
*/
409 409

	
410 410
/**
411 411
@defgroup metah Metaheuristics
412 412
@ingroup gen_opt_group
413 413
\brief Metaheuristics for LEMON library.
414 414

	
415 415
This group describes some metaheuristic optimization tools.
416 416
*/
417 417

	
418 418
/**
419 419
@defgroup utils Tools and Utilities 
420 420
\brief Tools and utilities for programming in LEMON
421 421

	
422 422
Tools and utilities for programming in LEMON.
423 423
*/
424 424

	
425 425
/**
426 426
@defgroup gutils Basic Graph Utilities
427 427
@ingroup utils
428 428
\brief Simple basic graph utilities.
429 429

	
430 430
This group describes some simple basic graph utilities.
431 431
*/
432 432

	
433 433
/**
434 434
@defgroup misc Miscellaneous Tools
435 435
@ingroup utils
436 436
\brief Tools for development, debugging and testing.
437 437

	
438 438
This group describes several useful tools for development,
439 439
debugging and testing.
440 440
*/
441 441

	
442 442
/**
443 443
@defgroup timecount Time measuring and Counting
444 444
@ingroup misc
445 445
\brief Simple tools for measuring the performance of algorithms.
446 446

	
447 447
This group describes simple tools for measuring the performance
448 448
of algorithms.
449 449
*/
450 450

	
451 451
/**
452 452
@defgroup graphbits Tools for Graph Implementation
453 453
@ingroup utils
454 454
\brief Tools to make it easier to create graphs.
455 455

	
456 456
This group describes the tools that makes it easier to create graphs and
457 457
the maps that dynamically update with the graph changes.
458 458
*/
459 459

	
460 460
/**
461 461
@defgroup exceptions Exceptions
462 462
@ingroup utils
463 463
\brief Exceptions defined in LEMON.
464 464

	
465 465
This group describes the exceptions defined in LEMON.
466 466
*/
467 467

	
468 468
/**
469 469
@defgroup io_group Input-Output
470 470
\brief Graph Input-Output methods
471 471

	
472 472
This group describes the tools for importing and exporting graphs 
473 473
and graph related data. Now it supports the LEMON format, the
474 474
\c DIMACS format and the encapsulated postscript (EPS) format.
475 475
*/
476 476

	
477 477
/**
478 478
@defgroup lemon_io Lemon Input-Output
479 479
@ingroup io_group
480 480
\brief Reading and writing LEMON format
481 481

	
482 482
This group describes methods for reading and writing LEMON format. 
483 483
You can find more about this format on the \ref graph-io-page "Graph Input-Output"
484 484
tutorial pages.
485 485
*/
486 486

	
487 487
/**
488 488
@defgroup section_io Section readers and writers
489 489
@ingroup lemon_io
490
\brief Section readers and writers for lemon Input-Output.
490
\brief Section readers and writers for LEMON Input-Output.
491 491

	
492
This group describes section readers and writers that can be attached to
493
\ref LemonReader and \ref LemonWriter.
492
This group describes section reader and writer classes that can be 
493
attached to \ref LemonReader and \ref LemonWriter.
494 494
*/
495 495

	
496 496
/**
497
@defgroup item_io Item Readers and Writers
497
@defgroup item_io Item readers and writers
498 498
@ingroup lemon_io
499
\brief Item readers and writers for lemon Input-Output.
499
\brief Item readers and writers for LEMON Input-Output.
500 500

	
501
The Input-Output classes can handle more data type by example
502
as map or attribute value. Each of these should be written and
503
read some way. The module make possible to do this.  
501
This group describes reader and writer classes for various data types
502
(e.g. map or attribute values). These classes can be attached to
503
\ref LemonReader and \ref LemonWriter.
504 504
*/
505 505

	
506 506
/**
507 507
@defgroup eps_io Postscript exporting
508 508
@ingroup io_group
509 509
\brief General \c EPS drawer and graph exporter
510 510

	
511 511
This group describes general \c EPS drawing methods and special
512 512
graph exporting tools. 
513 513
*/
514 514

	
515 515

	
516 516
/**
517 517
@defgroup concept Concepts
518 518
\brief Skeleton classes and concept checking classes
519 519

	
520 520
This group describes the data/algorithm skeletons and concept checking
521 521
classes implemented in LEMON.
522 522

	
523 523
The purpose of the classes in this group is fourfold.
524 524
 
525 525
- These classes contain the documentations of the concepts. In order
526 526
  to avoid document multiplications, an implementation of a concept
527 527
  simply refers to the corresponding concept class.
528 528

	
529 529
- These classes declare every functions, <tt>typedef</tt>s etc. an
530 530
  implementation of the concepts should provide, however completely
531 531
  without implementations and real data structures behind the
532 532
  interface. On the other hand they should provide nothing else. All
533 533
  the algorithms working on a data structure meeting a certain concept
534 534
  should compile with these classes. (Though it will not run properly,
535 535
  of course.) In this way it is easily to check if an algorithm
536 536
  doesn't use any extra feature of a certain implementation.
537 537

	
538 538
- The concept descriptor classes also provide a <em>checker class</em>
539 539
  that makes it possible to check whether a certain implementation of a
540 540
  concept indeed provides all the required features.
541 541

	
542 542
- Finally, They can serve as a skeleton of a new implementation of a concept.
543 543

	
544 544
*/
545 545

	
546 546

	
547 547
/**
548 548
@defgroup graph_concepts Graph Structure Concepts
549 549
@ingroup concept
550 550
\brief Skeleton and concept checking classes for graph structures
551 551

	
552 552
This group describes the skeletons and concept checking classes of LEMON's
553 553
graph structures and helper classes used to implement these.
554 554
*/
555 555

	
556 556
/* --- Unused group
557 557
@defgroup experimental Experimental Structures and Algorithms
558 558
This group describes some Experimental structures and algorithms.
559 559
The stuff here is subject to change.
560 560
*/
561 561

	
562 562
/**
563 563
\anchor demoprograms
564 564

	
565 565
@defgroup demos Demo programs
566 566

	
567 567
Some demo programs are listed here. Their full source codes can be found in
568 568
the \c demo subdirectory of the source tree.
569 569

	
570 570
It order to compile them, use <tt>--enable-demo</tt> configure option when
571 571
build the library.
572 572
*/
573 573

	
574 574
/**
575 575
@defgroup tools Standalone utility applications
576 576

	
577 577
Some utility applications are listed here. 
578 578

	
579 579
The standard compilation procedure (<tt>./configure;make</tt>) will compile
580 580
them, as well. 
581 581
*/
582 582

	
Ignore white space 196608 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5 5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_TOLERANCE_H
20 20
#define LEMON_TOLERANCE_H
21 21

	
22 22
///\ingroup misc
23 23
///\file
24 24
///\brief A basic tool to handle the anomalies of calculation with
25 25
///floating point numbers.
26 26
///
27 27
///\todo It should be in a module like "Basic tools"
28 28

	
29 29

	
30 30
namespace lemon {
31 31

	
32 32
  /// \addtogroup misc
33 33
  /// @{
34 34
  
35 35
  ///\brief A class to provide a basic way to
36 36
  ///handle the comparison of numbers that are obtained
37 37
  ///as a result of a probably inexact computation.
38 38
  ///
39 39
  ///\ref Tolerance is a class to provide a basic way to
40 40
  ///handle the comparison of numbers that are obtained
41 41
  ///as a result of a probably inexact computation.
42 42
  ///
43
  ///This is an abstract class, it should be specialized for all numerical
44
  ///data types. These specialized classes like \ref Tolerance<double>
45
  ///may offer additional tuning parameters.
43
  ///This is an abstract class, it should be specialized for all 
44
  ///numerical data types. These specialized classes like 
45
  ///Tolerance<double> may offer additional tuning parameters.
46 46
  ///
47 47
  ///\sa Tolerance<float>
48 48
  ///\sa Tolerance<double>
49 49
  ///\sa Tolerance<long double>
50 50
  ///\sa Tolerance<int>
51 51
  ///\sa Tolerance<long long int>
52 52
  ///\sa Tolerance<unsigned int>
53 53
  ///\sa Tolerance<unsigned long long int>
54 54

	
55 55
  template<class T>
56 56
  class Tolerance
57 57
  {
58 58
  public:
59 59
    typedef T Value;
60 60

	
61 61
    ///\name Comparisons
62 62
    ///The concept is that these bool functions return \c true only if
63 63
    ///the related comparisons hold even if some numerical error appeared
64 64
    ///during the computations.
65 65

	
66 66
    ///@{
67 67

	
68 68
    ///Returns \c true if \c a is \e surely strictly less than \c b
69 69
    static bool less(Value a,Value b) {return false;}
70 70
    ///Returns \c true if \c a is \e surely different from \c b
71 71
    static bool different(Value a,Value b) {return false;}
72 72
    ///Returns \c true if \c a is \e surely positive
73 73
    static bool positive(Value a) {return false;}
74 74
    ///Returns \c true if \c a is \e surely negative
75 75
    static bool negative(Value a) {return false;}
76 76
    ///Returns \c true if \c a is \e surely non-zero
77 77
    static bool nonZero(Value a) {return false;}
78 78

	
79 79
    ///@}
80 80

	
81 81
    ///Returns the zero value.
82 82
    static Value zero() {return T();}
83 83

	
84 84
    //   static bool finite(Value a) {}
85 85
    //   static Value big() {}
86 86
    //   static Value negativeBig() {}
87 87
  };
88 88

	
89 89

	
90 90
  ///Float specialization of Tolerance.
91 91

	
92 92
  ///Float specialization of Tolerance.
93 93
  ///\sa Tolerance
94 94
  ///\relates Tolerance
95 95
  template<>
96 96
  class Tolerance<float>
97 97
  {
98 98
    static float def_epsilon;
99 99
    float _epsilon;
100 100
  public:
101 101
    ///\e
102 102
    typedef float Value;
103 103

	
104 104
    ///Constructor setting the epsilon tolerance to the default value.
105 105
    Tolerance() : _epsilon(def_epsilon) {}
106 106
    ///Constructor setting the epsilon tolerance to the given value.
107 107
    Tolerance(float e) : _epsilon(e) {}
108 108

	
109 109
    ///Returns the epsilon value.
110 110
    Value epsilon() const {return _epsilon;}
111 111
    ///Sets the epsilon value.
112 112
    void epsilon(Value e) {_epsilon=e;}
113 113

	
114 114
    ///Returns the default epsilon value.
115 115
    static Value defaultEpsilon() {return def_epsilon;}
116 116
    ///Sets the default epsilon value.
117 117
    static void defaultEpsilon(Value e) {def_epsilon=e;}
118 118

	
119 119
    ///\name Comparisons
120
    ///See \ref Tolerance for more details.
120
    ///See \ref lemon::Tolerance "Tolerance" for more details.
121 121

	
122 122
    ///@{
123 123

	
124 124
    ///Returns \c true if \c a is \e surely strictly less than \c b
125 125
    bool less(Value a,Value b) const {return a+_epsilon<b;}
126 126
    ///Returns \c true if \c a is \e surely different from \c b
127 127
    bool different(Value a,Value b) const { return less(a,b)||less(b,a); }
128 128
    ///Returns \c true if \c a is \e surely positive
129 129
    bool positive(Value a) const { return _epsilon<a; }
130 130
    ///Returns \c true if \c a is \e surely negative
131 131
    bool negative(Value a) const { return -_epsilon>a; }
132 132
    ///Returns \c true if \c a is \e surely non-zero
133 133
    bool nonZero(Value a) const { return positive(a)||negative(a); }
134 134

	
135 135
    ///@}
136 136

	
137 137
    ///Returns zero
138 138
    static Value zero() {return 0;}
139 139
  };
140 140

	
141 141
  ///Double specialization of Tolerance.
142 142

	
143 143
  ///Double specialization of Tolerance.
144 144
  ///\sa Tolerance
145 145
  ///\relates Tolerance
146 146
  template<>
147 147
  class Tolerance<double>
148 148
  {
149 149
    static double def_epsilon;
150 150
    double _epsilon;
151 151
  public:
152 152
    ///\e
153 153
    typedef double Value;
154 154

	
155 155
    ///Constructor setting the epsilon tolerance to the default value.
156 156
    Tolerance() : _epsilon(def_epsilon) {}
157 157
    ///Constructor setting the epsilon tolerance to the given value.
158 158
    Tolerance(double e) : _epsilon(e) {}
159 159

	
160 160
    ///Returns the epsilon value.
161 161
    Value epsilon() const {return _epsilon;}
162 162
    ///Sets the epsilon value.
163 163
    void epsilon(Value e) {_epsilon=e;}
164 164

	
165 165
    ///Returns the default epsilon value.
166 166
    static Value defaultEpsilon() {return def_epsilon;}
167 167
    ///Sets the default epsilon value.
168 168
    static void defaultEpsilon(Value e) {def_epsilon=e;}
169 169

	
170 170
    ///\name Comparisons
171
    ///See \ref Tolerance for more details.
171
    ///See \ref lemon::Tolerance "Tolerance" for more details.
172 172

	
173 173
    ///@{
174 174

	
175 175
    ///Returns \c true if \c a is \e surely strictly less than \c b
176 176
    bool less(Value a,Value b) const {return a+_epsilon<b;}
177 177
    ///Returns \c true if \c a is \e surely different from \c b
178 178
    bool different(Value a,Value b) const { return less(a,b)||less(b,a); }
179 179
    ///Returns \c true if \c a is \e surely positive
180 180
    bool positive(Value a) const { return _epsilon<a; }
181 181
    ///Returns \c true if \c a is \e surely negative
182 182
    bool negative(Value a) const { return -_epsilon>a; }
183 183
    ///Returns \c true if \c a is \e surely non-zero
184 184
    bool nonZero(Value a) const { return positive(a)||negative(a); }
185 185

	
186 186
    ///@}
187 187

	
188 188
    ///Returns zero
189 189
    static Value zero() {return 0;}
190 190
  };
191 191

	
192 192
  ///Long double specialization of Tolerance.
193 193

	
194 194
  ///Long double specialization of Tolerance.
195 195
  ///\sa Tolerance
196 196
  ///\relates Tolerance
197 197
  template<>
198 198
  class Tolerance<long double>
199 199
  {
200 200
    static long double def_epsilon;
201 201
    long double _epsilon;
202 202
  public:
203 203
    ///\e
204 204
    typedef long double Value;
205 205

	
206 206
    ///Constructor setting the epsilon tolerance to the default value.
207 207
    Tolerance() : _epsilon(def_epsilon) {}
208 208
    ///Constructor setting the epsilon tolerance to the given value.
209 209
    Tolerance(long double e) : _epsilon(e) {}
210 210

	
211 211
    ///Returns the epsilon value.
212 212
    Value epsilon() const {return _epsilon;}
213 213
    ///Sets the epsilon value.
214 214
    void epsilon(Value e) {_epsilon=e;}
215 215

	
216 216
    ///Returns the default epsilon value.
217 217
    static Value defaultEpsilon() {return def_epsilon;}
218 218
    ///Sets the default epsilon value.
219 219
    static void defaultEpsilon(Value e) {def_epsilon=e;}
220 220

	
221 221
    ///\name Comparisons
222
    ///See \ref Tolerance for more details.
222
    ///See \ref lemon::Tolerance "Tolerance" for more details.
223 223

	
224 224
    ///@{
225 225

	
226 226
    ///Returns \c true if \c a is \e surely strictly less than \c b
227 227
    bool less(Value a,Value b) const {return a+_epsilon<b;}
228 228
    ///Returns \c true if \c a is \e surely different from \c b
229 229
    bool different(Value a,Value b) const { return less(a,b)||less(b,a); }
230 230
    ///Returns \c true if \c a is \e surely positive
231 231
    bool positive(Value a) const { return _epsilon<a; }
232 232
    ///Returns \c true if \c a is \e surely negative
233 233
    bool negative(Value a) const { return -_epsilon>a; }
234 234
    ///Returns \c true if \c a is \e surely non-zero
235 235
    bool nonZero(Value a) const { return positive(a)||negative(a); }
236 236

	
237 237
    ///@}
238 238

	
239 239
    ///Returns zero
240 240
    static Value zero() {return 0;}
241 241
  };
242 242

	
243 243
  ///Integer specialization of Tolerance.
244 244

	
245 245
  ///Integer specialization of Tolerance.
246 246
  ///\sa Tolerance
247 247
  template<>
248 248
  class Tolerance<int>
249 249
  {
250 250
  public:
251 251
    ///\e
252 252
    typedef int Value;
253 253

	
254 254
    ///\name Comparisons
255
    ///See \ref Tolerance for more details.
255
    ///See \ref lemon::Tolerance "Tolerance" for more details.
256 256

	
257 257
    ///@{
258 258

	
259 259
    ///Returns \c true if \c a is \e surely strictly less than \c b
260 260
    static bool less(Value a,Value b) { return a<b;}
261 261
    ///Returns \c true if \c a is \e surely different from \c b
262 262
    static bool different(Value a,Value b) { return a!=b; }
263 263
    ///Returns \c true if \c a is \e surely positive
264 264
    static bool positive(Value a) { return 0<a; }
265 265
    ///Returns \c true if \c a is \e surely negative
266 266
    static bool negative(Value a) { return 0>a; }
267 267
    ///Returns \c true if \c a is \e surely non-zero
268 268
    static bool nonZero(Value a) { return a!=0; }
269 269

	
270 270
    ///@}
271 271

	
272 272
    ///Returns zero
273 273
    static Value zero() {return 0;}
274 274
  };
275 275

	
276 276
  ///Unsigned integer specialization of Tolerance.
277 277

	
278
  ///Unsigned integer specialization of \ref Tolerance.
278
  ///Unsigned integer specialization of Tolerance.
279 279
  ///\sa Tolerance
280 280
  template<>
281 281
  class Tolerance<unsigned int>
282 282
  {
283 283
  public:
284 284
    ///\e
285 285
    typedef unsigned int Value;
286 286

	
287 287
    ///\name Comparisons
288
    ///See \ref Tolerance for more details.
288
    ///See \ref lemon::Tolerance "Tolerance" for more details.
289 289

	
290 290
    ///@{
291 291

	
292 292
    ///Returns \c true if \c a is \e surely strictly less than \c b
293 293
    static bool less(Value a,Value b) { return a<b;}
294 294
    ///Returns \c true if \c a is \e surely different from \c b
295 295
    static bool different(Value a,Value b) { return a!=b; }
296 296
    ///Returns \c true if \c a is \e surely positive
297 297
    static bool positive(Value a) { return 0<a; }
298 298
    ///Returns \c true if \c a is \e surely negative
299 299
    static bool negative(Value) { return false; }
300 300
    ///Returns \c true if \c a is \e surely non-zero
301 301
    static bool nonZero(Value a) { return a!=0; }
302 302

	
303 303
    ///@}
304 304

	
305 305
    ///Returns zero
306 306
    static Value zero() {return 0;}
307 307
  };
308 308
  
309 309

	
310 310
  ///Long integer specialization of Tolerance.
311 311

	
312 312
  ///Long integer specialization of Tolerance.
313 313
  ///\sa Tolerance
314 314
  template<>
315 315
  class Tolerance<long int>
316 316
  {
317 317
  public:
318 318
    ///\e
319 319
    typedef long int Value;
320 320

	
321 321
    ///\name Comparisons
322
    ///See \ref Tolerance for more details.
322
    ///See \ref lemon::Tolerance "Tolerance" for more details.
323 323

	
324 324
    ///@{
325 325

	
326 326
    ///Returns \c true if \c a is \e surely strictly less than \c b
327 327
    static bool less(Value a,Value b) { return a<b;}
328 328
    ///Returns \c true if \c a is \e surely different from \c b
329 329
    static bool different(Value a,Value b) { return a!=b; }
330 330
    ///Returns \c true if \c a is \e surely positive
331 331
    static bool positive(Value a) { return 0<a; }
332 332
    ///Returns \c true if \c a is \e surely negative
333 333
    static bool negative(Value a) { return 0>a; }
334 334
    ///Returns \c true if \c a is \e surely non-zero
335 335
    static bool nonZero(Value a) { return a!=0;}
336 336

	
337 337
    ///@}
338 338

	
339 339
    ///Returns zero
340 340
    static Value zero() {return 0;}
341 341
  };
342 342

	
343 343
  ///Unsigned long integer specialization of Tolerance.
344 344

	
345
  ///Unsigned long integer specialization of \ref Tolerance.
345
  ///Unsigned long integer specialization of Tolerance.
346 346
  ///\sa Tolerance
347 347
  template<>
348 348
  class Tolerance<unsigned long int>
349 349
  {
350 350
  public:
351 351
    ///\e
352 352
    typedef unsigned long int Value;
353 353

	
354 354
    ///\name Comparisons
355
    ///See \ref Tolerance for more details.
355
    ///See \ref lemon::Tolerance "Tolerance" for more details.
356 356

	
357 357
    ///@{
358 358

	
359 359
    ///Returns \c true if \c a is \e surely strictly less than \c b
360 360
    static bool less(Value a,Value b) { return a<b;}
361 361
    ///Returns \c true if \c a is \e surely different from \c b
362 362
    static bool different(Value a,Value b) { return a!=b; }
363 363
    ///Returns \c true if \c a is \e surely positive
364 364
    static bool positive(Value a) { return 0<a; }
365 365
    ///Returns \c true if \c a is \e surely negative
366 366
    static bool negative(Value) { return false; }
367 367
    ///Returns \c true if \c a is \e surely non-zero
368 368
    static bool nonZero(Value a) { return a!=0;}
369 369

	
370 370
    ///@}
371 371

	
372 372
    ///Returns zero
373 373
    static Value zero() {return 0;}
374 374
  };
375 375

	
376 376
#if defined __GNUC__ && !defined __STRICT_ANSI__
377 377

	
378 378
  ///Long long integer specialization of Tolerance.
379 379

	
380
  ///Long long integer specialization of \ref Tolerance.
380
  ///Long long integer specialization of Tolerance.
381 381
  ///\warning This class (more exactly, type <tt>long long</tt>)
382 382
  ///is not ansi compatible.
383 383
  ///\sa Tolerance
384 384
  template<>
385 385
  class Tolerance<long long int>
386 386
  {
387 387
  public:
388 388
    ///\e
389 389
    typedef long long int Value;
390 390

	
391 391
    ///\name Comparisons
392
    ///See \ref Tolerance for more details.
392
    ///See \ref lemon::Tolerance "Tolerance" for more details.
393 393

	
394 394
    ///@{
395 395

	
396 396
    ///Returns \c true if \c a is \e surely strictly less than \c b
397 397
    static bool less(Value a,Value b) { return a<b;}
398 398
    ///Returns \c true if \c a is \e surely different from \c b
399 399
    static bool different(Value a,Value b) { return a!=b; }
400 400
    ///Returns \c true if \c a is \e surely positive
401 401
    static bool positive(Value a) { return 0<a; }
402 402
    ///Returns \c true if \c a is \e surely negative
403 403
    static bool negative(Value a) { return 0>a; }
404 404
    ///Returns \c true if \c a is \e surely non-zero
405 405
    static bool nonZero(Value a) { return a!=0;}
406 406

	
407 407
    ///@}
408 408

	
409 409
    ///Returns zero
410 410
    static Value zero() {return 0;}
411 411
  };
412 412

	
413 413
  ///Unsigned long long integer specialization of Tolerance.
414 414

	
415
  ///Unsigned long long integer specialization of \ref Tolerance.
415
  ///Unsigned long long integer specialization of Tolerance.
416 416
  ///\warning This class (more exactly, type <tt>unsigned long long</tt>)
417 417
  ///is not ansi compatible.
418 418
  ///\sa Tolerance
419 419
  template<>
420 420
  class Tolerance<unsigned long long int>
421 421
  {
422 422
  public:
423 423
    ///\e
424 424
    typedef unsigned long long int Value;
425 425

	
426 426
    ///\name Comparisons
427
    ///See \ref Tolerance for more details.
427
    ///See \ref lemon::Tolerance "Tolerance" for more details.
428 428

	
429 429
    ///@{
430 430

	
431 431
    ///Returns \c true if \c a is \e surely strictly less than \c b
432 432
    static bool less(Value a,Value b) { return a<b;}
433 433
    ///Returns \c true if \c a is \e surely different from \c b
434 434
    static bool different(Value a,Value b) { return a!=b; }
435 435
    ///Returns \c true if \c a is \e surely positive
436 436
    static bool positive(Value a) { return 0<a; }
437 437
    ///Returns \c true if \c a is \e surely negative
438 438
    static bool negative(Value) { return false; }
439 439
    ///Returns \c true if \c a is \e surely non-zero
440 440
    static bool nonZero(Value a) { return a!=0;}
441 441

	
442 442
    ///@}
443 443

	
444 444
    ///Returns zero
445 445
    static Value zero() {return 0;}
446 446
  };
447 447

	
448 448
#endif
449 449

	
450 450
  /// @}
451 451

	
452 452
} //namespace lemon
453 453

	
454 454
#endif //LEMON_TOLERANCE_H
0 comments (0 inline)