COIN-OR::LEMON - Graph Library

Ticket #360: 360-34380851fc86.patch

File 360-34380851fc86.patch, 4.0 KB (added by Peter Kovacs, 15 years ago)
  • lemon/bellman_ford.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1268870913 -3600
    # Node ID 34380851fc86c9d55e0b7a7a289501b5ef00f745
    # Parent  141f9c0db4a3892de5feca4ebdbc8776191567cd
    Undo the changes of [a6eb9698c321] (#360, #51)
    
    The introduced solution for using tolerance technique in BellmanFord
    class turned out to be invalid, since it cannot be used for floating
    point types for which it should be.
    
    diff --git a/lemon/bellman_ford.h b/lemon/bellman_ford.h
    a b  
    2828#include <lemon/core.h>
    2929#include <lemon/error.h>
    3030#include <lemon/maps.h>
    31 #include <lemon/tolerance.h>
    3231#include <lemon/path.h>
    3332
    3433#include <limits>
     
    4241  /// The default implementation is based on the \c numeric_limits class.
    4342  /// If the numeric type does not have infinity value, then the maximum
    4443  /// value is used as extremal infinity value.
    45   ///
    46   /// \see BellmanFordToleranceOperationTraits
    4744  template <
    4845    typename V,
    4946    bool has_inf = std::numeric_limits<V>::has_infinity>
     
    8784    }
    8885  };
    8986
    90   /// \brief Operation traits for the BellmanFord algorithm class
    91   /// using tolerance.
    92   ///
    93   /// This operation traits class defines all computational operations
    94   /// and constants that are used in the Bellman-Ford algorithm.
    95   /// The only difference between this implementation and
    96   /// \ref BellmanFordDefaultOperationTraits is that this class uses
    97   /// the \ref Tolerance "tolerance technique" in its \ref less()
    98   /// function.
    99   ///
    100   /// \tparam V The value type.
    101   /// \tparam eps The epsilon value for the \ref less() function.
    102   /// By default, it is the epsilon value used by \ref Tolerance
    103   /// "Tolerance<V>".
    104   ///
    105   /// \see BellmanFordDefaultOperationTraits
    106 #ifdef DOXYGEN
    107   template <typename V, V eps>
    108 #else
    109   template <
    110     typename V,
    111     V eps = Tolerance<V>::def_epsilon>
    112 #endif
    113   struct BellmanFordToleranceOperationTraits {
    114     /// \brief Value type for the algorithm.
    115     typedef V Value;
    116     /// \brief Gives back the zero value of the type.
    117     static Value zero() {
    118       return static_cast<Value>(0);
    119     }
    120     /// \brief Gives back the positive infinity value of the type.
    121     static Value infinity() {
    122       return std::numeric_limits<Value>::infinity();
    123     }
    124     /// \brief Gives back the sum of the given two elements.
    125     static Value plus(const Value& left, const Value& right) {
    126       return left + right;
    127     }
    128     /// \brief Gives back \c true only if the first value is less than
    129     /// the second.
    130     static bool less(const Value& left, const Value& right) {
    131       return left + eps < right;
    132     }
    133   };
    134 
    13587  /// \brief Default traits class of BellmanFord class.
    13688  ///
    13789  /// Default traits class of BellmanFord class.
     
    155107    ///
    156108    /// It defines the used operations and the infinity value for the
    157109    /// given \c Value type.
    158     /// \see BellmanFordDefaultOperationTraits,
    159     /// BellmanFordToleranceOperationTraits
     110    /// \see BellmanFordDefaultOperationTraits
    160111    typedef BellmanFordDefaultOperationTraits<Value> OperationTraits;
    161112
    162113    /// \brief The type of the map that stores the last arcs of the
     
    886837    ///
    887838    /// It defines the used operations and the infinity value for the
    888839    /// given \c Value type.
    889     /// \see BellmanFordDefaultOperationTraits,
    890     /// BellmanFordToleranceOperationTraits
     840    /// \see BellmanFordDefaultOperationTraits
    891841    typedef BellmanFordDefaultOperationTraits<Value> OperationTraits;
    892842
    893843    /// \brief The type of the map that stores the last
  • test/bellman_ford_test.cc

    diff --git a/test/bellman_ford_test.cc b/test/bellman_ford_test.cc
    a b  
    104104    BF::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
    105105      ::SetDistMap<concepts::ReadWriteMap<Node,Value> >
    106106      ::SetOperationTraits<BellmanFordDefaultOperationTraits<Value> >
    107       ::SetOperationTraits<BellmanFordToleranceOperationTraits<Value, 0> >
    108107      ::Create bf_test(gr,length);
    109108
    110109    LengthMap length_map;