Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53806 - trunk/boost/graph
From: jewillco_at_[hidden]
Date: 2009-06-11 22:02:08


Author: jewillco
Date: 2009-06-11 22:02:07 EDT (Thu, 11 Jun 2009)
New Revision: 53806
URL: http://svn.boost.org/trac/boost/changeset/53806

Log:
Fixed asserts and probability updates to handle floating point rounding errors better; refs #3134
Text files modified:
   trunk/boost/graph/rmat_graph_generator.hpp | 14 +++++++++-----
   1 files changed, 9 insertions(+), 5 deletions(-)

Modified: trunk/boost/graph/rmat_graph_generator.hpp
==============================================================================
--- trunk/boost/graph/rmat_graph_generator.hpp (original)
+++ trunk/boost/graph/rmat_graph_generator.hpp 2009-06-11 22:02:07 EDT (Thu, 11 Jun 2009)
@@ -20,6 +20,7 @@
 #include <boost/graph/graph_traits.hpp>
 #include <boost/type_traits/is_base_and_derived.hpp>
 #include <boost/type_traits/is_same.hpp>
+#include <boost/test/floating_point_comparison.hpp>
 
 using boost::shared_ptr;
 using boost::uniform_01;
@@ -103,7 +104,10 @@
     
     double S = a + b + c + d;
     
- a /= S; b /= S; c /= S; d /= S;
+ a /= S; b /= S; c /= S;
+ // d /= S;
+ // Ensure all values add up to 1, regardless of floating point errors
+ d = 1. - a - b - c;
   }
 
   return std::make_pair(u, v);
@@ -150,7 +154,7 @@
     {
       this->gen.reset(new uniform_01<RandomGenerator>(gen));
 
- assert(a + b + c + d == 1);
+ assert(boost::test_tools::check_is_close(a + b + c + d, 1., boost::test_tools::fraction_tolerance(1.e-5)));
 
       if (permute_vertices)
         generate_permutation_vector(gen, vertexPermutation, n);
@@ -260,7 +264,7 @@
         values(sort_pair<vertices_size_type>()), done(false)
               
     {
- assert(a + b + c + d == 1);
+ assert(boost::test_tools::check_is_close(a + b + c + d, 1., boost::test_tools::fraction_tolerance(1.e-5)));
 
       this->gen.reset(new uniform_01<RandomGenerator>(gen));
 
@@ -361,7 +365,7 @@
       : gen(), done(false)
               
     {
- assert(a + b + c + d == 1);
+ assert(boost::test_tools::check_is_close(a + b + c + d, 1., boost::test_tools::fraction_tolerance(1.e-5)));
 
       this->gen.reset(new uniform_01<RandomGenerator>(gen));
 
@@ -474,7 +478,7 @@
         values(sort_pair<vertices_size_type>()), done(false)
               
     {
- assert(a + b + c + d == 1);
+ assert(boost::test_tools::check_is_close(a + b + c + d, 1., boost::test_tools::fraction_tolerance(1.e-5)));
 
       this->gen.reset(new uniform_01<RandomGenerator>(gen));
       


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk