2
0
mirror of https://github.com/boostorg/graph.git synced 2026-02-09 11:12:28 +00:00

Fix handling of overflow in shortest-path algorithms

[SVN r37814]
This commit is contained in:
Douglas Gregor
2007-05-29 16:53:05 +00:00
parent 3125c8577d
commit 45d0f1331b
2 changed files with 9 additions and 8 deletions

View File

@@ -76,6 +76,10 @@ September 27, 2000.
<h2>Changes by version</h2>
<a name="by-version">
<ul>
<a name="1.34.1"></a><li>Version 1.34.1</br><b>Bug Fixes</b><br>
<ul>
<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>
</ul>
<a name="1.34.0"></a><li>Version 1.34.0<br><b>New algorithms and components</b>
<ul>
<li><a href="maximum_matching.html"><tt>edmonds_maximum_cardinality_matching</tt></a>, from Aaron Windsor.</li>

View File

@@ -22,16 +22,13 @@ namespace boost {
template <class T>
struct closed_plus
{
// std::abs just isn't portable :(
template <class X>
inline X my_abs(const X& x) const { return x < 0 ? -x : x; }
T operator()(const T& a, const T& b) const {
using namespace std;
T inf = (numeric_limits<T>::max)();
if (b > 0 && my_abs(inf - a) < b)
return inf;
return a + b;
T zero(0);
T result = a + b;
if (result < zero && a >= zero && b >= zero)
return (numeric_limits<T>::max)();
return result;
}
};