From 63290266dacba34eeb2641652deb336b31efd484 Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Sun, 19 May 2002 15:42:14 +0000 Subject: [PATCH] added optimization of stopping as soon as relaxation is done (thanks Herve for the suggestion!) [SVN r13977] --- include/boost/graph/bellman_ford_shortest_paths.hpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/include/boost/graph/bellman_ford_shortest_paths.hpp b/include/boost/graph/bellman_ford_shortest_paths.hpp index f0d516a1..174f38b8 100644 --- a/include/boost/graph/bellman_ford_shortest_paths.hpp +++ b/include/boost/graph/bellman_ford_shortest_paths.hpp @@ -67,7 +67,7 @@ namespace boost { class bellman_visitor { public: bellman_visitor() { } - bellman_visitor(Visitors vis = Visitors()) : m_vis(vis) { } + bellman_visitor(Visitors vis) : m_vis(vis) { } template void examine_edge(Edge u, Graph& g) { @@ -122,14 +122,19 @@ namespace boost { typename GTraits::edge_iterator i, end; - for (Size k = 0; k < N; ++k) + for (Size k = 0; k < N; ++k) { + bool at_least_one_edge_relaxed = false; for (tie(i, end) = edges(g); i != end; ++i) { v.examine_edge(*i, g); - if (relax(*i, g, weight, pred, distance, combine, compare)) + if (relax(*i, g, weight, pred, distance, combine, compare)) { + at_least_one_edge_relaxed = true; v.edge_relaxed(*i, g); - else + } else v.edge_not_relaxed(*i, g); } + if (!at_least_one_edge_relaxed) + break; + } for (tie(i, end) = edges(g); i != end; ++i) if (compare(combine(get(distance, source(*i, g)),