Ticket #1009: bellman-ford-neg-cycle.patch

File bellman-ford-neg-cycle.patch, 2.9 KB (added by Douglas Gregor, 15 years ago)

Fix handling of overflow

  • index.htm

    RCS file: /cvsroot/boost/boost/index.htm,v
    retrieving revision 1.266.2.21
    diff -u -r1.266.2.21 index.htm
     
    341341                              <tt>vis.initialize_vertex</tt> for each vertex
    342342                              during initialization.</li>
    343343
     344                              <li><a
     345                              href="libs/graph/doc/bellman_ford_shortest.html"><tt>bellman_ford_shortest_paths</tt></a>:
     346                              fixed a bug where certain negative
     347                              cycles were not correctly detected.</li>
     348
    344349                              <li><b>Note:</b> the name of the
    345350                              compiled library for the <a
    346351                              href="libs/graph/doc/read_graphviz.html">GraphViz
     
    350355                              conventions.</li>
    351356
    352357                              <li>See the <a href=
    353                               "libs/graph/doc/history.html#1.34.0">complete
     358                              "libs/graph/doc/history.html#1.34.1">complete
    354359                              revision history</a> for more information.</li>
    355360                            </ul>
    356361                          </li>
  • libs/graph/doc/history.html

    RCS file: /cvsroot/boost/boost/libs/graph/doc/history.html,v
    retrieving revision 1.35.2.3
    diff -u -r1.35.2.3 history.html
     
    7676<h2>Changes by version</h2>
    7777<a name="by-version">
    7878<ul>
     79  <a name="1.34.1"></a><li>Version 1.34.1</br><b>Bug Fixes</b><br>
     80  <ul>
     81     <li><a href="bellman_ford_shortest.html"><tt>bellman_ford_shortest_paths</tt></a>: fixed a bug where certain negative cycles were not correctly detected.</li>
     82  </ul>
    7983  <a name="1.34.0"></a><li>Version 1.34.0<br><b>New algorithms and components</b>
    8084    <ul>
    8185      <li><a href="maximum_matching.html"><tt>edmonds_maximum_cardinality_matching</tt></a>, from Aaron Windsor.</li>
  • boost/graph/relax.hpp

    RCS file: /cvsroot/boost/boost/boost/graph/relax.hpp,v
    retrieving revision 1.25
    diff -u -r1.25 relax.hpp
     
    2222    template <class T>
    2323    struct closed_plus
    2424    {
    25       // std::abs just isn't portable :(
    26       template <class X>
    27       inline X my_abs(const X& x) const { return x < 0 ? -x : x; }
    28 
    2925      T operator()(const T& a, const T& b) const {
    3026        using namespace std;
    31         T inf = (numeric_limits<T>::max)();
    32         if (b > 0 && my_abs(inf - a) < b)
    33           return inf;
    34         return a + b;
     27        T zero(0);
     28        T result = a + b;
     29        if (result < zero && a >= zero && b >= zero)
     30          return (numeric_limits<T>::max)();
     31        return result;
    3532      }
    3633    };
    3734