gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Doc improvements is some files.
0 5 0
default
5 files changed with 69 insertions and 75 deletions:
↑ Collapse diff ↑
Ignore white space 48 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
///\file
20
///\brief Some basic non inline function and static global data.
20
///\brief Some basic non-inline functions and static global data.
21 21

	
22 22
#include<lemon/tolerance.h>
23 23
#include<lemon/bits/invalid.h>
24 24
namespace lemon {
25 25

	
26 26
  float Tolerance<float>::def_epsilon = 1e-4;
27 27
  double Tolerance<double>::def_epsilon = 1e-10;
28 28
  long double Tolerance<long double>::def_epsilon = 1e-14;
29 29

	
30 30
#ifndef LEMON_ONLY_TEMPLATES
31 31
  const Invalid INVALID = Invalid();
32 32
#endif
33 33

	
34 34
} //namespace lemon
Ignore white space 48 line context
... ...
@@ -5,48 +5,49 @@
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_BITS_INVALID_H
20 20
#define LEMON_BITS_INVALID_H
21 21

	
22 22
///\file
23 23
///\brief Definition of INVALID.
24 24

	
25 25
namespace lemon {
26 26

	
27 27
  /// \brief Dummy type to make it easier to create invalid iterators.
28 28
  ///
29
  /// Dummy type to make it easier to create invalid iterators.
29 30
  /// See \ref INVALID for the usage.
30 31
  struct Invalid {
31 32
  public:
32 33
    bool operator==(Invalid) { return true;  }
33 34
    bool operator!=(Invalid) { return false; }
34 35
    bool operator< (Invalid) { return false; }
35 36
  };
36 37
  
37 38
  /// \brief Invalid iterators.
38 39
  ///
39 40
  /// \ref Invalid is a global type that converts to each iterator
40 41
  /// in such a way that the value of the target iterator will be invalid.
41 42

	
42 43
  //Some people didn't like this:
43 44
  //const Invalid &INVALID = *(Invalid *)0;
44 45

	
45 46
#ifdef LEMON_ONLY_TEMPLATES
46 47
  const Invalid INVALID = Invalid();
47 48
#else
48 49
  extern const Invalid INVALID;
49 50
#endif
50 51

	
51 52
} //namespace lemon
52 53

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

	
19 19
#ifndef LEMON_DIM2_H
20 20
#define LEMON_DIM2_H
21 21

	
22 22
#include <iostream>
23 23
#include <lemon/bits/utility.h>
24 24

	
25 25
///\ingroup misc
26 26
///\file
27 27
///\brief A simple two dimensional vector and a bounding box implementation 
28 28
///
29 29
/// The class \ref lemon::dim2::Point "dim2::Point" implements
30
///a two dimensional vector with the usual
31
/// operations.
30
/// a two dimensional vector with the usual operations.
32 31
///
33 32
/// The class \ref lemon::dim2::BoundingBox "dim2::BoundingBox"
34 33
/// can be used to determine
35 34
/// the rectangular bounding box of a set of
36 35
/// \ref lemon::dim2::Point "dim2::Point"'s.
37 36

	
38 37
namespace lemon {
39 38

	
40 39
  ///Tools for handling two dimensional coordinates
41 40

	
42 41
  ///This namespace is a storage of several
43 42
  ///tools for handling two dimensional coordinates
44 43
  namespace dim2 {
45 44

	
46 45
  /// \addtogroup misc
47 46
  /// @{
48 47

	
49 48
  /// A simple two dimensional vector (plainvector) implementation
50 49

	
51 50
  /// A simple two dimensional vector (plainvector) implementation
52
  ///with the usual vector
53
  /// operators.
54
  ///
51
  /// with the usual vector operations.
55 52
  template<typename T>
56 53
    class Point {
57 54

	
58 55
    public:
59 56

	
60 57
      typedef T Value;
61 58

	
62 59
      ///First coordinate
63 60
      T x;
64 61
      ///Second coordinate
65 62
      T y;     
66 63
      
67 64
      ///Default constructor
68 65
      Point() {}
69 66

	
70 67
      ///Construct an instance from coordinates
71 68
      Point(T a, T b) : x(a), y(b) { }
72 69

	
73
      ///The dimension of the vector.
70
      ///Returns the dimension of the vector (i.e. returns 2).
74 71

	
75 72
      ///The dimension of the vector.
76 73
      ///This function always returns 2. 
77 74
      int size() const { return 2; }
78 75

	
79 76
      ///Subscripting operator
80 77

	
81 78
      ///\c p[0] is \c p.x and \c p[1] is \c p.y
82 79
      ///
83 80
      T& operator[](int idx) { return idx == 0 ? x : y; }
84 81

	
85 82
      ///Const subscripting operator
86 83

	
87 84
      ///\c p[0] is \c p.x and \c p[1] is \c p.y
88 85
      ///
89 86
      const T& operator[](int idx) const { return idx == 0 ? x : y; }
90 87

	
91 88
      ///Conversion constructor
92 89
      template<class TT> Point(const Point<TT> &p) : x(p.x), y(p.y) {}
93 90

	
94 91
      ///Give back the square of the norm of the vector
95 92
      T normSquare() const {
96 93
        return x*x+y*y;
97 94
      }
98 95
  
99
      ///Increment the left hand side by u
96
      ///Increment the left hand side by \c u
100 97
      Point<T>& operator +=(const Point<T>& u) {
101 98
        x += u.x;
102 99
        y += u.y;
103 100
        return *this;
104 101
      }
105 102
  
106
      ///Decrement the left hand side by u
103
      ///Decrement the left hand side by \c u
107 104
      Point<T>& operator -=(const Point<T>& u) {
108 105
        x -= u.x;
109 106
        y -= u.y;
110 107
        return *this;
111 108
      }
112 109

	
113 110
      ///Multiply the left hand side with a scalar
114 111
      Point<T>& operator *=(const T &u) {
115 112
        x *= u;
116 113
        y *= u;
117 114
        return *this;
118 115
      }
119 116

	
120 117
      ///Divide the left hand side by a scalar
121 118
      Point<T>& operator /=(const T &u) {
122 119
        x /= u;
123 120
        y /= u;
124 121
        return *this;
125 122
      }
126 123
  
127 124
      ///Return the scalar product of two vectors
128 125
      T operator *(const Point<T>& u) const {
129 126
        return x*u.x+y*u.y;
130 127
      }
... ...
@@ -294,118 +291,119 @@
294 291
	_empty = false;
295 292
      }
296 293
      
297 294
      ///Construct an instance from four numbers
298 295

	
299 296
      ///Construct an instance from four numbers.
300 297
      ///\param l The left side of the box.
301 298
      ///\param b The bottom of the box.
302 299
      ///\param r The right side of the box.
303 300
      ///\param t The top of the box.
304 301
      ///\warning The left side must be no more than the right side and
305 302
      ///bottom must be no more than the top. 
306 303
      BoundingBox(T l,T b,T r,T t)
307 304
      {
308 305
	bottom_left=Point<T>(l,b);
309 306
	top_right=Point<T>(r,t);
310 307
	_empty = false;
311 308
      }
312 309
      
313 310
      ///Return \c true if the bounding box is empty.
314 311
      
315 312
      ///Return \c true if the bounding box is empty (i.e. return \c false
316 313
      ///if at least one point was added to the box or the coordinates of
317 314
      ///the box were set).
315
      ///
318 316
      ///The coordinates of an empty bounding box are not defined. 
319 317
      bool empty() const {
320 318
        return _empty;
321 319
      }
322 320
      
323 321
      ///Make the BoundingBox empty
324 322
      void clear() {
325 323
        _empty=1;
326 324
      }
327 325

	
328
      ///Give back the bottom left corner
326
      ///Give back the bottom left corner of the box
329 327

	
330
      ///Give back the bottom left corner.
328
      ///Give back the bottom left corner of the box.
331 329
      ///If the bounding box is empty, then the return value is not defined.
332 330
      Point<T> bottomLeft() const {
333 331
        return bottom_left;
334 332
      }
335 333

	
336
      ///Set the bottom left corner
334
      ///Set the bottom left corner of the box
337 335

	
338
      ///Set the bottom left corner.
336
      ///Set the bottom left corner of the box.
339 337
      ///It should only be used for non-empty box.
340 338
      void bottomLeft(Point<T> p) {
341 339
	bottom_left = p;
342 340
      }
343 341

	
344
      ///Give back the top right corner
342
      ///Give back the top right corner of the box
345 343

	
346
      ///Give back the top right corner.
344
      ///Give back the top right corner of the box.
347 345
      ///If the bounding box is empty, then the return value is not defined.
348 346
      Point<T> topRight() const {
349 347
        return top_right;
350 348
      }
351 349

	
352
      ///Set the top right corner
350
      ///Set the top right corner of the box
353 351

	
354
      ///Set the top right corner.
352
      ///Set the top right corner of the box.
355 353
      ///It should only be used for non-empty box.
356 354
      void topRight(Point<T> p) {
357 355
	top_right = p;
358 356
      }
359 357

	
360
      ///Give back the bottom right corner
358
      ///Give back the bottom right corner of the box
361 359

	
362
      ///Give back the bottom right corner.
360
      ///Give back the bottom right corner of the box.
363 361
      ///If the bounding box is empty, then the return value is not defined.
364 362
      Point<T> bottomRight() const {
365 363
        return Point<T>(top_right.x,bottom_left.y);
366 364
      }
367 365

	
368
      ///Set the bottom right corner
366
      ///Set the bottom right corner of the box
369 367

	
370
      ///Set the bottom right corner.
368
      ///Set the bottom right corner of the box.
371 369
      ///It should only be used for non-empty box.
372 370
      void bottomRight(Point<T> p) {
373 371
	top_right.x = p.x;
374 372
	bottom_left.y = p.y;
375 373
      }
376 374
 
377
      ///Give back the top left corner
375
      ///Give back the top left corner of the box
378 376

	
379
      ///Give back the top left corner.
377
      ///Give back the top left corner of the box.
380 378
      ///If the bounding box is empty, then the return value is not defined.
381 379
      Point<T> topLeft() const {
382 380
        return Point<T>(bottom_left.x,top_right.y);
383 381
      }
384 382

	
385
      ///Set the top left corner
383
      ///Set the top left corner of the box
386 384

	
387
      ///Set the top left corner.
385
      ///Set the top left corner of the box.
388 386
      ///It should only be used for non-empty box.
389 387
      void topLeft(Point<T> p) {
390 388
	top_right.y = p.y;
391 389
	bottom_left.x = p.x;
392 390
      }
393 391

	
394 392
      ///Give back the bottom of the box
395 393

	
396 394
      ///Give back the bottom of the box.
397 395
      ///If the bounding box is empty, then the return value is not defined.
398 396
      T bottom() const {
399 397
        return bottom_left.y;
400 398
      }
401 399

	
402 400
      ///Set the bottom of the box
403 401

	
404 402
      ///Set the bottom of the box.
405 403
      ///It should only be used for non-empty box.
406 404
      void bottom(T t) {
407 405
	bottom_left.y = t;
408 406
      }
409 407

	
410 408
      ///Give back the top of the box
411 409

	
... ...
@@ -512,190 +510,189 @@
512 510
      }
513 511
  
514 512
      ///Intersection of two bounding boxes
515 513

	
516 514
      ///Intersection of two bounding boxes.
517 515
      ///
518 516
      BoundingBox operator&(const BoundingBox& u) const {
519 517
        BoundingBox b;
520 518
        if (this->_empty || u._empty) {
521 519
	  b._empty = true;
522 520
	} else {
523 521
	  b.bottom_left.x = std::max(this->bottom_left.x,u.bottom_left.x);
524 522
	  b.bottom_left.y = std::max(this->bottom_left.y,u.bottom_left.y);
525 523
	  b.top_right.x = std::min(this->top_right.x,u.top_right.x);
526 524
	  b.top_right.y = std::min(this->top_right.y,u.top_right.y);
527 525
	  b._empty = b.bottom_left.x > b.top_right.x ||
528 526
	             b.bottom_left.y > b.top_right.y;
529 527
	} 
530 528
        return b;
531 529
      }
532 530

	
533 531
    };//class Boundingbox
534 532

	
535 533

	
536
  ///Map of x-coordinates of a Point map
534
  ///Map of x-coordinates of a \ref Point "Point"-map
537 535

	
538 536
  ///\ingroup maps
539
  ///Map of x-coordinates of a \ref dim2::Point "Point"-map.
537
  ///Map of x-coordinates of a \ref Point "Point"-map.
540 538
  ///
541 539
  template<class M>
542 540
  class XMap 
543 541
  {
544 542
    M& _map;
545 543
  public:
546 544

	
547 545
    typedef typename M::Value::Value Value;
548 546
    typedef typename M::Key Key;
549 547
    ///\e
550 548
    XMap(M& map) : _map(map) {}
551 549
    Value operator[](Key k) const {return _map[k].x;}
552 550
    void set(Key k,Value v) {_map.set(k,typename M::Value(v,_map[k].y));}
553 551
  };
554 552
    
555 553
  ///Returns an \ref XMap class
556 554

	
557 555
  ///This function just returns an \ref XMap class.
558 556
  ///
559 557
  ///\ingroup maps
560 558
  ///\relates XMap
561 559
  template<class M> 
562 560
  inline XMap<M> xMap(M &m) 
563 561
  {
564 562
    return XMap<M>(m);
565 563
  }
566 564

	
567 565
  template<class M> 
568 566
  inline XMap<M> xMap(const M &m) 
569 567
  {
570 568
    return XMap<M>(m);
571 569
  }
572 570

	
573
  ///Constant (read only) version of XMap
571
  ///Constant (read only) version of \ref XMap
574 572

	
575 573
  ///\ingroup maps
576 574
  ///Constant (read only) version of \ref XMap
577 575
  ///
578 576
  template<class M>
579 577
  class ConstXMap 
580 578
  {
581 579
    const M& _map;
582 580
  public:
583 581

	
584 582
    typedef typename M::Value::Value Value;
585 583
    typedef typename M::Key Key;
586 584
    ///\e
587 585
    ConstXMap(const M &map) : _map(map) {}
588 586
    Value operator[](Key k) const {return _map[k].x;}
589 587
  };
590 588
    
591 589
  ///Returns a \ref ConstXMap class
592 590

	
593 591
  ///This function just returns a \ref ConstXMap class.
594 592
  ///
595 593
  ///\ingroup maps
596 594
  ///\relates ConstXMap
597 595
  template<class M> 
598 596
  inline ConstXMap<M> xMap(const M &m) 
599 597
  {
600 598
    return ConstXMap<M>(m);
601 599
  }
602 600

	
603
  ///Map of y-coordinates of a Point map
601
  ///Map of y-coordinates of a \ref Point "Point"-map
604 602
    
605 603
  ///\ingroup maps
606 604
  ///Map of y-coordinates of a \ref Point "Point"-map.
607 605
  ///
608 606
  template<class M>
609 607
  class YMap 
610 608
  {
611 609
    M& _map;
612 610
  public:
613 611

	
614 612
    typedef typename M::Value::Value Value;
615 613
    typedef typename M::Key Key;
616 614
    ///\e
617 615
    YMap(M& map) : _map(map) {}
618 616
    Value operator[](Key k) const {return _map[k].y;}
619 617
    void set(Key k,Value v) {_map.set(k,typename M::Value(_map[k].x,v));}
620 618
  };
621 619

	
622 620
  ///Returns a \ref YMap class
623 621

	
624 622
  ///This function just returns a \ref YMap class.
625 623
  ///
626 624
  ///\ingroup maps
627 625
  ///\relates YMap
628 626
  template<class M> 
629 627
  inline YMap<M> yMap(M &m) 
630 628
  {
631 629
    return YMap<M>(m);
632 630
  }
633 631

	
634 632
  template<class M> 
635 633
  inline YMap<M> yMap(const M &m) 
636 634
  {
637 635
    return YMap<M>(m);
638 636
  }
639 637

	
640
  ///Constant (read only) version of YMap
638
  ///Constant (read only) version of \ref YMap
641 639

	
642 640
  ///\ingroup maps
643 641
  ///Constant (read only) version of \ref YMap
644 642
  ///
645 643
  template<class M>
646 644
  class ConstYMap 
647 645
  {
648 646
    const M& _map;
649 647
  public:
650 648

	
651 649
    typedef typename M::Value::Value Value;
652 650
    typedef typename M::Key Key;
653 651
    ///\e
654 652
    ConstYMap(const M &map) : _map(map) {}
655 653
    Value operator[](Key k) const {return _map[k].y;}
656 654
  };
657 655
    
658 656
  ///Returns a \ref ConstYMap class
659 657

	
660 658
  ///This function just returns a \ref ConstYMap class.
661 659
  ///
662 660
  ///\ingroup maps
663 661
  ///\relates ConstYMap
664 662
  template<class M> 
665 663
  inline ConstYMap<M> yMap(const M &m) 
666 664
  {
667 665
    return ConstYMap<M>(m);
668 666
  }
669 667

	
670 668

	
671
    ///\brief Map of the normSquare()
672
    ///of a Point map
673
    ///
674
    ///Map of the \ref Point::normSquare() "normSquare()"
675
    ///of a \ref Point "Point"-map.
676
    ///\ingroup maps
677
    ///
669
  ///\brief Map of the \ref Point::normSquare() "normSquare()"
670
  ///of a \ref Point "Point"-map
671
  ///
672
  ///Map of the \ref Point::normSquare() "normSquare()"
673
  ///of a \ref Point "Point"-map.
674
  ///\ingroup maps
678 675
  template<class M>
679 676
  class NormSquareMap 
680 677
  {
681 678
    const M& _map;
682 679
  public:
683 680

	
684 681
    typedef typename M::Value::Value Value;
685 682
    typedef typename M::Key Key;
686 683
    ///\e
687 684
    NormSquareMap(const M &map) : _map(map) {}
688 685
    Value operator[](Key k) const {return _map[k].normSquare();}
689 686
  };
690 687
    
691 688
  ///Returns a \ref NormSquareMap class
692 689

	
693 690
  ///This function just returns a \ref NormSquareMap class.
694 691
  ///
695 692
  ///\ingroup maps
696 693
  ///\relates NormSquareMap
697 694
  template<class M> 
698 695
  inline NormSquareMap<M> normSquareMap(const M &m) 
699 696
  {
700 697
    return NormSquareMap<M>(m);
701 698
  }
Ignore white space 48 line context
... ...
@@ -489,116 +489,116 @@
489 489
  /// method. And to get random number from the whole range of an
490 490
  /// integer type you can use the argumentless \c integer() or \c
491 491
  /// uinteger() functions. After all you can get random bool with
492 492
  /// equal chance of true and false or given probability of true
493 493
  /// result with the \c boolean() member functions.
494 494
  ///
495 495
  ///\code
496 496
  /// // The commented code is identical to the other
497 497
  /// double a = rnd();                     // [0.0, 1.0)
498 498
  /// // double a = rnd.real();             // [0.0, 1.0)
499 499
  /// double b = rnd(100.0);                // [0.0, 100.0)
500 500
  /// // double b = rnd.real(100.0);        // [0.0, 100.0)
501 501
  /// double c = rnd(1.0, 2.0);             // [1.0, 2.0)
502 502
  /// // double c = rnd.real(1.0, 2.0);     // [1.0, 2.0)
503 503
  /// int d = rnd[100000];                  // 0..99999
504 504
  /// // int d = rnd.integer(100000);       // 0..99999
505 505
  /// int e = rnd[6] + 1;                   // 1..6
506 506
  /// // int e = rnd.integer(1, 1 + 6);     // 1..6
507 507
  /// int b = rnd.uinteger<int>();          // 0 .. 2^31 - 1
508 508
  /// int c = rnd.integer<int>();           // - 2^31 .. 2^31 - 1
509 509
  /// bool g = rnd.boolean();               // P(g = true) = 0.5
510 510
  /// bool h = rnd.boolean(0.8);            // P(h = true) = 0.8
511 511
  ///\endcode
512 512
  ///
513
  /// The lemon provides a global instance of the random number
513
  /// LEMON provides a global instance of the random number
514 514
  /// generator which name is \ref lemon::rnd "rnd". Usually it is a
515 515
  /// good programming convenience to use this global generator to get
516 516
  /// random numbers.
517 517
  class Random {
518 518
  private:
519 519

	
520 520
    // Architecture word
521 521
    typedef unsigned long Word;
522 522
    
523 523
    _random_bits::RandomCore<Word> core;
524 524
    _random_bits::BoolProducer<Word> bool_producer;
525 525
    
526 526

	
527 527
  public:
528 528

	
529
    /// \brief Constructor
529
    /// \brief Default constructor
530 530
    ///
531 531
    /// Constructor with constant seeding.
532 532
    Random() { core.initState(); }
533 533

	
534
    /// \brief Constructor
534
    /// \brief Constructor with seed
535 535
    ///
536 536
    /// Constructor with seed. The current number type will be converted
537 537
    /// to the architecture word type.
538 538
    template <typename Number>
539 539
    Random(Number seed) { 
540 540
      _random_bits::Initializer<Number, Word>::init(core, seed);
541 541
    }
542 542

	
543
    /// \brief Constructor
543
    /// \brief Constructor with array seeding
544 544
    ///
545 545
    /// Constructor with array seeding. The given range should contain
546 546
    /// any number type and the numbers will be converted to the
547 547
    /// architecture word type.
548 548
    template <typename Iterator>
549 549
    Random(Iterator begin, Iterator end) { 
550 550
      typedef typename std::iterator_traits<Iterator>::value_type Number;
551 551
      _random_bits::Initializer<Number, Word>::init(core, begin, end);
552 552
    }
553 553

	
554 554
    /// \brief Copy constructor
555 555
    ///
556 556
    /// Copy constructor. The generated sequence will be identical to
557 557
    /// the other sequence. It can be used to save the current state
558 558
    /// of the generator and later use it to generate the same
559 559
    /// sequence.
560 560
    Random(const Random& other) {
561 561
      core.copyState(other.core);
562 562
    }
563 563

	
564 564
    /// \brief Assign operator
565 565
    ///
566 566
    /// Assign operator. The generated sequence will be identical to
567 567
    /// the other sequence. It can be used to save the current state
568 568
    /// of the generator and later use it to generate the same
569 569
    /// sequence.
570 570
    Random& operator=(const Random& other) {
571 571
      if (&other != this) {
572 572
        core.copyState(other.core);
573 573
      }
574 574
      return *this;
575 575
    }
576 576

	
577 577
    /// \brief Returns a random real number from the range [0, 1)
578 578
    ///
579 579
    /// It returns a random real number from the range [0, 1). The
580
    /// default Number type is double.
580
    /// default Number type is \c double.
581 581
    template <typename Number>
582 582
    Number real() {
583 583
      return _random_bits::RealConversion<Number, Word>::convert(core);
584 584
    }
585 585

	
586 586
    double real() {
587 587
      return real<double>();
588 588
    }
589 589

	
590 590
    /// \brief Returns a random real number the range [0, b)
591 591
    ///
592 592
    /// It returns a random real number from the range [0, b).
593 593
    template <typename Number>
594 594
    Number real(Number b) { 
595 595
      return real<Number>() * b; 
596 596
    }
597 597

	
598 598
    /// \brief Returns a random real number from the range [a, b)
599 599
    ///
600 600
    /// It returns a random real number from the range [a, b).
601 601
    template <typename Number>
602 602
    Number real(Number a, Number b) { 
603 603
      return real<Number>() * (b - a) + a; 
604 604
    }
... ...
@@ -632,85 +632,85 @@
632 632
    template <typename Number>
633 633
    Number integer(Number b) {
634 634
      return _random_bits::Mapping<Number, Word>::map(core, b);
635 635
    }
636 636

	
637 637
    /// \brief Returns a random integer from a range
638 638
    ///
639 639
    /// It returns a random integer from the range {a, a + 1, ..., b - 1}.
640 640
    template <typename Number>
641 641
    Number integer(Number a, Number b) {
642 642
      return _random_bits::Mapping<Number, Word>::map(core, b - a) + a;
643 643
    }
644 644

	
645 645
    /// \brief Returns a random integer from a range
646 646
    ///
647 647
    /// It returns a random integer from the range {0, 1, ..., b - 1}.
648 648
    template <typename Number>
649 649
    Number operator[](Number b) {
650 650
      return _random_bits::Mapping<Number, Word>::map(core, b);
651 651
    }
652 652

	
653 653
    /// \brief Returns a random non-negative integer
654 654
    ///
655 655
    /// It returns a random non-negative integer uniformly from the
656
    /// whole range of the current \c Number type.  The default result
657
    /// type of this function is unsigned int.
656
    /// whole range of the current \c Number type. The default result
657
    /// type of this function is <tt>unsigned int</tt>.
658 658
    template <typename Number>
659 659
    Number uinteger() {
660 660
      return _random_bits::IntConversion<Number, Word>::convert(core);
661 661
    }
662 662

	
663 663
    unsigned int uinteger() {
664 664
      return uinteger<unsigned int>();
665 665
    }
666 666

	
667 667
    /// \brief Returns a random integer
668 668
    ///
669 669
    /// It returns a random integer uniformly from the whole range of
670 670
    /// the current \c Number type. The default result type of this
671
    /// function is int.
671
    /// function is \c int.
672 672
    template <typename Number>
673 673
    Number integer() {
674 674
      static const int nb = std::numeric_limits<Number>::digits + 
675 675
        (std::numeric_limits<Number>::is_signed ? 1 : 0);
676 676
      return _random_bits::IntConversion<Number, Word, nb>::convert(core);
677 677
    }
678 678

	
679 679
    int integer() {
680 680
      return integer<int>();
681 681
    }
682 682
    
683 683
    /// \brief Returns a random bool
684 684
    ///
685 685
    /// It returns a random bool. The generator holds a buffer for
686 686
    /// random bits. Every time when it become empty the generator makes
687 687
    /// a new random word and fill the buffer up.
688 688
    bool boolean() {
689 689
      return bool_producer.convert(core);
690 690
    }
691 691

	
692
    ///\name Nonuniform distributions
692
    ///\name Non-uniform distributions
693 693
    ///
694 694
    
695 695
    ///@{
696 696
    
697 697
    /// \brief Returns a random bool
698 698
    ///
699 699
    /// It returns a random bool with given probability of true result.
700 700
    bool boolean(double p) {
701 701
      return operator()() < p;
702 702
    }
703 703

	
704 704
    /// Standard Gauss distribution
705 705

	
706 706
    /// Standard Gauss distribution.
707 707
    /// \note The Cartesian form of the Box-Muller
708 708
    /// transformation is used to generate a random normal distribution.
709 709
    /// \todo Consider using the "ziggurat" method instead.
710 710
    double gauss() 
711 711
    {
712 712
      double V1,V2,S;
713 713
      do {
714 714
	V1=2*real<double>()-1;
715 715
	V2=2*real<double>()-1;
716 716
	S=V1*V1+V2*V2;
Ignore white space 48 line context
... ...
@@ -15,369 +15,365 @@
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
  ///Tolerance is a class to provide a basic way to
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 43
  ///This is an abstract class, it should be specialized for all numerical
44
  ///data types. These specialized classes like Tolerance<double>
44
  ///data types. These specialized classes like \ref Tolerance<double>
45 45
  ///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
#if defined __GNUC__ && !defined __STRICT_ANSI__  
52 51
  ///\sa Tolerance<long long int>
53
#endif
54 52
  ///\sa Tolerance<unsigned int>
55
#if defined __GNUC__ && !defined __STRICT_ANSI__  
56 53
  ///\sa Tolerance<unsigned long long int>
57
#endif
58 54

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

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

	
70 66
    ///@{
71 67

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

	
83 79
    ///@}
84 80

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

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

	
93 89

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

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

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

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

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

	
123 119
    ///\name Comparisons
124
    ///See class Tolerance for more details.
120
    ///See \ref Tolerance for more details.
125 121

	
126 122
    ///@{
127 123

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

	
139 135
    ///@}
140 136

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

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

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

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

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

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

	
174 170
    ///\name Comparisons
175
    ///See class Tolerance for more details.
171
    ///See \ref Tolerance for more details.
176 172

	
177 173
    ///@{
178 174

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

	
190 186
    ///@}
191 187

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

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

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

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

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

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

	
225 221
    ///\name Comparisons
226
    ///See class Tolerance for more details.
222
    ///See \ref Tolerance for more details.
227 223

	
228 224
    ///@{
229 225

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

	
241 237
    ///@}
242 238

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

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

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

	
258 254
    ///\name Comparisons
259
    ///See Tolerance for more details.
255
    ///See \ref Tolerance for more details.
260 256

	
261 257
    ///@{
262 258

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

	
274 270
    ///@}
275 271

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

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

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

	
291 287
    ///\name Comparisons
292
    ///See Tolerance for more details.
288
    ///See \ref Tolerance for more details.
293 289

	
294 290
    ///@{
295 291

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

	
307 303
    ///@}
308 304

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

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

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

	
325 321
    ///\name Comparisons
326
    ///See Tolerance for more details.
322
    ///See \ref Tolerance for more details.
327 323

	
328 324
    ///@{
329 325

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

	
341 337
    ///@}
342 338

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

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

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

	
358 354
    ///\name Comparisons
359
    ///See Tolerance for more details.
355
    ///See \ref Tolerance for more details.
360 356

	
361 357
    ///@{
362 358

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

	
374 370
    ///@}
375 371

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

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

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

	
0 comments (0 inline)