Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69112 - in sandbox-branches/geometry/index_080_nhch: boost/geometry/extensions/index/rtree tests
From: adam.wulkiewicz_at_[hidden]
Date: 2011-02-20 20:02:34


Author: awulkiew
Date: 2011-02-20 20:02:31 EST (Sun, 20 Feb 2011)
New Revision: 69112
URL: http://svn.boost.org/trac/boost/changeset/69112

Log:
execution time tests added
Text files modified:
   sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree.hpp | 15 ++++--
   sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_internal_node.hpp | 31 +++++++------
   sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_leaf.hpp | 19 ++++----
   sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_node.hpp | 3
   sandbox-branches/geometry/index_080_nhch/tests/rtree_filters.hpp | 2
   sandbox-branches/geometry/index_080_nhch/tests/rtree_native.hpp | 86 +++++++++++++++++++++++++++++----------
   6 files changed, 102 insertions(+), 54 deletions(-)

Modified: sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree.hpp (original)
+++ sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree.hpp 2011-02-20 20:02:31 EST (Sun, 20 Feb 2011)
@@ -324,13 +324,16 @@
     /**
      * \brief Print Rtree (mainly for debug)
      */
- inline void print()
+ // awulkiew - print() method changed to operator<<
+ friend std::ostream & operator<<(std::ostream &os, rtree &r)
     {
- std::cerr << "===================================" << std::endl;
- std::cerr << " Min/Max: " << m_min_elems_per_node << " / " << m_max_elems_per_node << std::endl;
- std::cerr << "Leaves: " << m_root->get_leaves().size() << std::endl;
- m_root->print(m_translator);
- std::cerr << "===================================" << std::endl;
+ os << "===================================" << std::endl;
+ os << " Min/Max: " << r.m_min_elems_per_node << " / " << r.m_max_elems_per_node << std::endl;
+ os << "Leaves: " << r.m_root->get_leaves().size() << std::endl;
+ r.m_root->print(os, r.m_translator);
+ os << "===================================" << std::endl;
+
+ return os;
     }
 
 private:

Modified: sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_internal_node.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_internal_node.hpp (original)
+++ sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_internal_node.hpp 2011-02-20 20:02:31 EST (Sun, 20 Feb 2011)
@@ -181,35 +181,36 @@
     /**
      * \brief Print Rtree subtree (mainly for debug)
      */
- virtual void print(Translator const& tr) const
+ // awulkiew - ostream parameter added
+ virtual void print(std::ostream &os, Translator const& tr) const
     {
- std::cerr << " --> Node --------" << std::endl;
- std::cerr << " Address: " << this << std::endl;
- std::cerr << " Level: " << this->get_level() << std::endl;
- std::cerr << " Size: " << m_nodes.size() << std::endl;
- std::cerr << " | ";
+ os << " --> Node --------" << std::endl;
+ os << " Address: " << this << std::endl;
+ os << " Level: " << this->get_level() << std::endl;
+ os << " Size: " << m_nodes.size() << std::endl;
+ os << " | ";
         for(typename node_map::const_iterator it = m_nodes.begin(); it != m_nodes.end(); ++it)
         {
             if (this != it->second->get_parent().get())
             {
- std::cerr << "ERROR - " << this << " is not " << it->second->get_parent().get() << " ";
+ os << "ERROR - " << this << " is not " << it->second->get_parent().get() << " ";
             }
 
- std::cerr << "( " << geometry::get<min_corner, 0>(it->first) << " , "
+ os << "( " << geometry::get<min_corner, 0>(it->first) << " , "
                 << geometry::get<min_corner, 1>(it->first) << " ) x ";
- std::cerr << "( " << geometry::get<max_corner, 0>(it->first) << " , "
+ os << "( " << geometry::get<max_corner, 0>(it->first) << " , "
                 << geometry::get<max_corner, 1>(it->first) << " )";
- std::cerr << " | ";
+ os << " | ";
         }
- std::cerr << std::endl;
- std::cerr << " --< Node --------" << std::endl;
+ os << std::endl;
+ os << " --< Node --------" << std::endl;
 
         // print child nodes
- std::cerr << " Children: " << std::endl;
+ os << " Children: " << std::endl;
         for (typename node_map::const_iterator it = m_nodes.begin();
- it != m_nodes.end(); ++it)
+ it != m_nodes.end(); ++it)
         {
- it->second->print(tr);
+ it->second->print(os, tr);
         }
     }
 

Modified: sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_leaf.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_leaf.hpp (original)
+++ sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_leaf.hpp 2011-02-20 20:02:31 EST (Sun, 20 Feb 2011)
@@ -191,30 +191,31 @@
     /**
     * \brief Print leaf (mainly for debug)
     */
- virtual void print(Translator const& tr) const
+ // awulkiew - ostream parameter added
+ virtual void print(std::ostream &os, Translator const& tr) const
     {
- std::cerr << "\t" << " --> Leaf --------" << std::endl;
- std::cerr << "\t" << " Size: " << m_nodes.size() << std::endl;
+ os << "\t" << " --> Leaf --------" << std::endl;
+ os << "\t" << " Size: " << m_nodes.size() << std::endl;
         for (typename leaf_map::const_iterator it = m_nodes.begin();
- it != m_nodes.end(); ++it)
+ it != m_nodes.end(); ++it)
         {
             // TODO: awulkiew - implement object specific behaviour - display boxes or points
             Box box;
             detail::convert_to_box(tr(*it), box);
 
- std::cerr << "\t" << " | ";
- std::cerr << "( " << geometry::get<min_corner, 0>
+ os << "\t" << " | ";
+ os << "( " << geometry::get<min_corner, 0>
                 (box) << " , " << geometry::get<min_corner, 1>
                 (box) << " ) x ";
- std::cerr << "( " << geometry::get<max_corner, 0>
+ os << "( " << geometry::get<max_corner, 0>
                 (box) << " , " << geometry::get<max_corner, 1>
                 (box) << " )";
             // awulkiew - commented
             //std::cerr << " -> ";
             //std::cerr << it->second;
- std::cerr << " | " << std::endl;;
+ os << " | " << std::endl;;
         }
- std::cerr << "\t" << " --< Leaf --------" << std::endl;
+ os << "\t" << " --< Leaf --------" << std::endl;
     }
 
     // awulkiew - leaf only virtual methods

Modified: sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_node.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_node.hpp (original)
+++ sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_node.hpp 2011-02-20 20:02:31 EST (Sun, 20 Feb 2011)
@@ -138,7 +138,8 @@
     /**
      * \brief Print Rtree subtree (mainly for debug)
      */
- virtual void print(Translator const& tr) const
+ // awulkiew - ostream parameter added
+ virtual void print(std::ostream &, Translator const& tr) const
     {
         // TODO: mloskot - define & use GGL exception
         throw std::logic_error("shouldn't be here");

Modified: sandbox-branches/geometry/index_080_nhch/tests/rtree_filters.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_nhch/tests/rtree_filters.hpp (original)
+++ sandbox-branches/geometry/index_080_nhch/tests/rtree_filters.hpp 2011-02-20 20:02:31 EST (Sun, 20 Feb 2011)
@@ -42,7 +42,7 @@
         t.insert(B(P(2, 2), P(3, 3)));
         t.insert(B(P(4, 4), P(5, 5)));
         t.insert(B(P(6, 6), P(7, 7)));
- t.print();
+ std::cerr << t;
 
         std::deque<B> res = t.find(B(P(2.5f, 2.5f), P(4.5f, 4.5f)));
         tests_rtree_filters_hpp_print_range(res);

Modified: sandbox-branches/geometry/index_080_nhch/tests/rtree_native.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_nhch/tests/rtree_native.hpp (original)
+++ sandbox-branches/geometry/index_080_nhch/tests/rtree_native.hpp 2011-02-20 20:02:31 EST (Sun, 20 Feb 2011)
@@ -13,6 +13,8 @@
 
 #include <map>
 
+#include <boost/timer.hpp>
+
 void tests_rtree_native_hpp()
 {
         std::cout << "tests\rtree_native.hpp\n";
@@ -27,16 +29,16 @@
         t.insert(B(P(2, 2), P(3, 3)));
         t.insert(B(P(4, 4), P(5, 5)));
         t.insert(B(P(6, 6), P(7, 7)));
- t.print();
+ std::cerr << t;
 
         // error
         t.remove_in(B(P(-1, -1), P(2, 2)));
         // ok
         t.remove_in(B(P(0, 0), P(1, 1)));
- t.print();
+ std::cerr << t;
 
         t.remove(B(P(6, 6), P(7, 7)));
- t.print();
+ std::cerr << t;
     }
 
     std::cout << "-------------------------------------------------\n";
@@ -52,16 +54,16 @@
         t.insert(P(2, 2));
         t.insert(P(4, 4));
         t.insert(P(6, 6));
- t.print();
+ std::cerr << t;
 
         // error
         t.remove_in(B(P(-1, -1), P(1, 1)));
         // ok
         t.remove_in(B(P(0, 0), P(0, 0)));
- t.print();
+ std::cerr << t;
 
         t.remove(P(6, 6));
- t.print();
+ std::cerr << t;
     }
 
     std::cout << "-------------------------------------------------\n";
@@ -78,16 +80,16 @@
         t.insert(V(B(P(2, 2), P(3, 3)), 1));
         t.insert(V(B(P(4, 4), P(5, 5)), 2));
         t.insert(V(B(P(6, 6), P(7, 7)), 3));
- t.print();
+ std::cerr << t;
 
         // error
         t.remove_in(B(P(0, 0), P(2, 1)));
         // ok
         t.remove_in(B(P(0, 0), P(1, 1)));
- t.print();
+ std::cerr << t;
 
         t.remove(V(B(P(6, 6), P(7, 7)), 3));
- t.print();
+ std::cerr << t;
     }
 
     std::cout << "-------------------------------------------------\n";
@@ -110,16 +112,16 @@
         t.insert(v2);
         t.insert(v3);
         t.insert(v4);
- t.print();
+ std::cerr << t;
 
         // error
         t.remove_in(B(P(0, 0), P(2, 1)));
         // ok
         t.remove_in(B(P(0, 0), P(1, 1)));
- t.print();
+ std::cerr << t;
 
         t.remove(v4);
- t.print();
+ std::cerr << t;
     }
 
     std::cout << "-------------------------------------------------\n";
@@ -144,16 +146,16 @@
         t.insert(vit++);
         t.insert(vit++);
         t.insert(vit);
- t.print();
+ std::cerr << t;
 
         // error
         t.remove_in(B(P(0, 0), P(2, 1)));
         // ok
         t.remove_in(B(P(0, 0), P(1, 1)));
- t.print();
+ std::cerr << t;
 
         t.remove(m.find(3));
- t.print();
+ std::cerr << t;
     }
 
     std::cout << "-------------------------------------------------\n";
@@ -179,16 +181,16 @@
         t.insert(1);
         t.insert(2);
         t.insert(3);
- t.print();
+ std::cerr << t;
 
         // error
         t.remove_in(B(P(0, 0), P(2, 1)));
         // ok
         t.remove_in(B(P(0, 0), P(1, 1)));
- t.print();
+ std::cerr << t;
 
         t.remove(3);
- t.print();
+ std::cerr << t;
     }
 
     {
@@ -198,10 +200,50 @@
         boost::geometry::index::rtree<B>::rtree_leaf l;
         boost::geometry::index::rtree<B>::rtree_internal_node n;
 
- std::cout << sizeof(boost::shared_ptr<int>) << '\n';
- std::cout << sizeof(std::vector<int>) << '\n';
- std::cout << sizeof(n) << '\n';
- std::cout << sizeof(l) << '\n';
+ std::cout << "shared ptr size: " << sizeof(boost::shared_ptr<int>) << '\n';
+ std::cout << "vector size: " << sizeof(std::vector<int>) << '\n';
+ std::cout << "internal node size: " << sizeof(n) << '\n';
+ std::cout << "leaf size: " << sizeof(l) << '\n';
+ }
+
+ {
+ typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+ typedef boost::geometry::model::box<P> B;
+
+ // randomize boxes
+ const size_t n = 10000;
+ std::vector<B> v(n);
+ for ( size_t i = 0 ; i < n ; ++i )
+ {
+ float x = ( rand() % 100000 ) / 1000.0f;
+ float y = ( rand() % 100000 ) / 1000.0f;
+ float w = ::fabs(( rand() % 100000 ) / 100000.0f);
+ float h = ::fabs((rand() % 100000 ) / 100000.0f);
+ v[i] = B(P(x - w, y - h),P(x + w, y + h));
+ }
+
+ boost::geometry::index::rtree<B> t(5, 1);
+
+ std::cout << "inserting time test...\n";
+
+ boost::timer tim;
+
+ BOOST_FOREACH(B &b, v)
+ {
+ t.insert(b);
+ }
+
+ std::cout << "time: " << tim.elapsed() << "s\n";
+ std::cout << "removing time test...\n";
+
+ tim.restart();
+
+ BOOST_FOREACH(B &b, v)
+ {
+ t.remove(b);
+ }
+
+ std::cout << "time: " << tim.elapsed() << "s\n";
     }
 
     // ERROR!


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