Fix prim_minimum_spanning_tree throwing negative_edge exception
This commit is contained in:
parent
0ddee7cee5
commit
281cdc1134
|
@ -0,0 +1,31 @@
|
|||
Index: /trunk/boost/graph/dijkstra_shortest_paths.hpp
|
||||
===================================================================
|
||||
--- /trunk/boost/graph/dijkstra_shortest_paths.hpp (revision 85386)
|
||||
+++ /trunk/boost/graph/dijkstra_shortest_paths.hpp (revision 85387)
|
||||
@@ -163,5 +163,5 @@
|
||||
// Test for negative-weight edges:
|
||||
//
|
||||
- // Reasons that simpler comparisons do not work:
|
||||
+ // Reasons that other comparisons do not work:
|
||||
//
|
||||
// m_compare(e_weight, D(0)):
|
||||
@@ -180,14 +180,13 @@
|
||||
// and return a distance.
|
||||
|
||||
- D source_dist = get(m_distance, source(e, g));
|
||||
- W e_weight = get(m_weight, e);
|
||||
+ // W e_weight = get(m_weight, e);
|
||||
// sd_plus_ew = source_dist + e_weight.
|
||||
- D sd_plus_ew = m_combine(source_dist, e_weight);
|
||||
+ // D sd_plus_ew = m_combine(source_dist, e_weight);
|
||||
// sd_plus_2ew = source_dist + 2 * e_weight.
|
||||
- D sd_plus_2ew = m_combine(sd_plus_ew, e_weight);
|
||||
+ // D sd_plus_2ew = m_combine(sd_plus_ew, e_weight);
|
||||
// The test here is equivalent to e_weight < 0 if m_combine has a
|
||||
// cancellation law, but always returns false when m_combine is a
|
||||
- // projection operator or is idempotent.
|
||||
- if (m_compare(sd_plus_2ew, sd_plus_ew))
|
||||
+ // projection operator.
|
||||
+ if (m_compare(m_combine(m_zero, get(m_weight, e)), m_zero))
|
||||
boost::throw_exception(negative_edge());
|
||||
// End of test for negative-weight edges.
|
|
@ -0,0 +1,53 @@
|
|||
Index: /trunk/boost/graph/dijkstra_shortest_paths.hpp
|
||||
===================================================================
|
||||
--- /trunk/boost/graph/dijkstra_shortest_paths.hpp (revision 85348)
|
||||
+++ /trunk/boost/graph/dijkstra_shortest_paths.hpp (revision 85386)
|
||||
@@ -119,4 +119,5 @@
|
||||
{
|
||||
typedef typename property_traits<DistanceMap>::value_type D;
|
||||
+ typedef typename property_traits<WeightMap>::value_type W;
|
||||
|
||||
dijkstra_bfs_visitor(UniformCostVisitor vis, UpdatableQueue& Q,
|
||||
@@ -160,11 +161,38 @@
|
||||
template <class Edge, class Graph>
|
||||
void examine_edge(Edge e, Graph& g) {
|
||||
- // Comparison needs to be more complicated because distance and weight
|
||||
- // types may not be the same; see bug 8398
|
||||
- // (https://svn.boost.org/trac/boost/ticket/8398)
|
||||
+ // Test for negative-weight edges:
|
||||
+ //
|
||||
+ // Reasons that simpler comparisons do not work:
|
||||
+ //
|
||||
+ // m_compare(e_weight, D(0)):
|
||||
+ // m_compare only needs to work on distances, not weights, and those
|
||||
+ // types do not need to be the same (bug 8398,
|
||||
+ // https://svn.boost.org/trac/boost/ticket/8398).
|
||||
+ // m_compare(m_combine(source_dist, e_weight), source_dist):
|
||||
+ // if m_combine is project2nd (as in prim_minimum_spanning_tree),
|
||||
+ // this test will claim that the edge weight is negative whenever
|
||||
+ // the edge weight is less than source_dist, even if both of those
|
||||
+ // are positive (bug 9012,
|
||||
+ // https://svn.boost.org/trac/boost/ticket/9012).
|
||||
+ // m_compare(m_combine(e_weight, source_dist), source_dist):
|
||||
+ // would fix project2nd issue, but documentation only requires that
|
||||
+ // m_combine be able to take a distance and a weight (in that order)
|
||||
+ // and return a distance.
|
||||
+
|
||||
D source_dist = get(m_distance, source(e, g));
|
||||
- if (m_compare(m_combine(source_dist, get(m_weight, e)), source_dist))
|
||||
+ W e_weight = get(m_weight, e);
|
||||
+ // sd_plus_ew = source_dist + e_weight.
|
||||
+ D sd_plus_ew = m_combine(source_dist, e_weight);
|
||||
+ // sd_plus_2ew = source_dist + 2 * e_weight.
|
||||
+ D sd_plus_2ew = m_combine(sd_plus_ew, e_weight);
|
||||
+ // The test here is equivalent to e_weight < 0 if m_combine has a
|
||||
+ // cancellation law, but always returns false when m_combine is a
|
||||
+ // projection operator or is idempotent.
|
||||
+ if (m_compare(sd_plus_2ew, sd_plus_ew))
|
||||
boost::throw_exception(negative_edge());
|
||||
+ // End of test for negative-weight edges.
|
||||
+
|
||||
m_vis.examine_edge(e, g);
|
||||
+
|
||||
}
|
||||
template <class Edge, class Graph>
|
14
boost.spec
14
boost.spec
|
@ -36,7 +36,7 @@ Name: boost
|
|||
Summary: The free peer-reviewed portable C++ source libraries
|
||||
Version: 1.54.0
|
||||
%define version_enc 1_54_0
|
||||
Release: 10%{?dist}
|
||||
Release: 11%{?dist}
|
||||
License: Boost and MIT and Python
|
||||
|
||||
%define toplev_dirname %{name}_%{version_enc}
|
||||
|
@ -201,6 +201,10 @@ Patch55: boost-1.54.0-interprocess-atomic_cas32-ppc.patch
|
|||
# https://bugzilla.redhat.com/show_bug.cgi?id=1159960
|
||||
Patch56: boost-1.54.0-smart_ptr-shared_ptr_at.patch
|
||||
|
||||
# https://bugzilla.redhat.com/show_bug.cgi?id=1115124
|
||||
Patch57: boost-1.55.0-graph-dijkstra_shortest_paths.patch
|
||||
Patch58: boost-1.55.0-graph-dijkstra_shortest_paths-2.patch
|
||||
|
||||
%bcond_with tests
|
||||
%bcond_with docs_generated
|
||||
|
||||
|
@ -692,6 +696,8 @@ a number of significant features and is now developed independently
|
|||
%patch54 -p1
|
||||
%patch55 -p1
|
||||
%patch56 -p1
|
||||
%patch57 -p2
|
||||
%patch58 -p2
|
||||
|
||||
# At least python2_version needs to be a macro so that it's visible in
|
||||
# %%install as well.
|
||||
|
@ -1283,6 +1289,12 @@ rm -rf $RPM_BUILD_ROOT
|
|||
%{_mandir}/man1/bjam.1*
|
||||
|
||||
%changelog
|
||||
* Tue Jan 13 2015 Petr Machata <pmachata@redhat.com> - 1.54.0-11
|
||||
- Apply upstream fix for dijkstra_bfs_visitor from Boost.Graph to not
|
||||
misinterpret edge weights.
|
||||
(boost-1.55.0-graph-dijkstra_shortest_paths.patch,
|
||||
boost-1.55.0-graph-dijkstra_shortest_paths-2.patch)
|
||||
|
||||
* Wed Nov 12 2014 Petr Machata <pmachata@redhat.com> - 1.54.0-10
|
||||
- Fix boost::shared_ptr<T>::operator[], which was ill-formed for
|
||||
non-array T's. (boost-1.54.0-smart_ptr-shared_ptr_at.patch)
|
||||
|
|
Loading…
Reference in New Issue