diff --git a/index/example/benchmark_experimental.cpp b/index/example/benchmark_experimental.cpp index e84637d0c..f9673307a 100644 --- a/index/example/benchmark_experimental.cpp +++ b/index/example/benchmark_experimental.cpp @@ -35,11 +35,14 @@ void mycopy(I1 first, I2 last, O o) *o = *first; } +//#define BOOST_GEOMETRY_INDEX_BENCHMARK_DEBUG + int main() { typedef boost::chrono::thread_clock clock_t; typedef boost::chrono::duration dur_t; +#ifndef BOOST_GEOMETRY_INDEX_BENCHMARK_DEBUG size_t values_count = 1000000; size_t queries_count = 100000; size_t nearest_queries_count = 10000; @@ -47,9 +50,19 @@ int main() size_t path_queries_count = 2000; size_t path_queries_count2 = 10000; unsigned path_values_count = 10; +#else + size_t values_count = 1000; + size_t queries_count = 1; + size_t nearest_queries_count = 1; + unsigned neighbours_count = 10; + size_t path_queries_count = 1; + size_t path_queries_count2 = 1; + unsigned path_values_count = 10; +#endif float max_val = static_cast(values_count / 2); std::vector< std::pair > coords; + std::vector values; //randomize values { @@ -63,39 +76,62 @@ int main() std::cout << "randomizing data\n"; for ( size_t i = 0 ; i < values_count ; ++i ) { - coords.push_back(std::make_pair(rnd(), rnd())); + float x = rnd(); + float y = rnd(); + coords.push_back(std::make_pair(x, y)); + values.push_back(B(P(x - 0.5f, y - 0.5f), P(x + 0.5f, y + 0.5f))); } std::cout << "randomized\n"; } - typedef bgi::rtree > RT; + //typedef bgi::rtree > RT; //typedef bgi::rtree > RT; - //typedef bgi::rtree > RT; + typedef bgi::rtree > RT; std::cout << "sizeof rtree: " << sizeof(RT) << std::endl; for (;;) { + std::vector result; + result.reserve(100); + B result_one; + + // packing test + { + clock_t::time_point start = clock_t::now(); + + RT t(values.begin(), values.end()); + + dur_t time = clock_t::now() - start; + std::cout << time << " - pack " << values_count << '\n'; + + { + clock_t::time_point start = clock_t::now(); + size_t temp = 0; + for (size_t i = 0 ; i < queries_count ; ++i ) + { + float x = coords[i].first; + float y = coords[i].second; + result.clear(); + t.query(bgi::intersects(B(P(x - 10, y - 10), P(x + 10, y + 10))), std::back_inserter(result)); + temp += result.size(); + } + dur_t time = clock_t::now() - start; + std::cout << time << " - query(B) " << queries_count << " found " << temp << '\n'; + } + } + RT t; // inserting test { clock_t::time_point start = clock_t::now(); - for (size_t i = 0 ; i < values_count ; ++i ) - { - float x = coords[i].first; - float y = coords[i].second; - B b(P(x - 0.5f, y - 0.5f), P(x + 0.5f, y + 0.5f)); - - t.insert(b); - } + t.insert(values); dur_t time = clock_t::now() - start; std::cout << time << " - insert " << values_count << '\n'; } - std::vector result; - result.reserve(100); - B result_one; + { clock_t::time_point start = clock_t::now(); diff --git a/index/example/glut_vis.cpp b/index/example/glut_vis.cpp index f1d16755c..3c6bda5aa 100644 --- a/index/example/glut_vis.cpp +++ b/index/example/glut_vis.cpp @@ -622,6 +622,36 @@ void keyboard(unsigned char key, int /*x*/, int /*y*/) glutPostRedisplay(); } + else if ( current_line == "bulk" ) + { + vect.clear(); + + for ( size_t i = 0 ; i < 35 ; ++i ) + { + float x = ( rand() % 100 ); + float y = ( rand() % 100 ); + float w = ( rand() % 2 ) + 1; + float h = ( rand() % 2 ) + 1; + + B b(P(x - w, y - h),P(x + w, y + h)); + vect.push_back(b); + + std::cout << "inserted: "; + bgi::detail::utilities::print_indexable(std::cout, b); + std::cout << '\n'; + } + + RTree t2(vect); + t = boost::move(t2); + + std::cout << ( bgi::detail::rtree::utilities::are_boxes_ok(t) ? "boxes OK\n" : "WRONG BOXES!\n" ); + std::cout << ( bgi::detail::rtree::utilities::are_levels_ok(t) ? "levels OK\n" : "WRONG LEVELS!\n" ); + std::cout << "\n"; + + search_valid = false; + + glutPostRedisplay(); + } else { if ( current_line == "knn" ) diff --git a/index/test/movable.hpp b/index/test/movable.hpp index 3076865a5..c1dd278e7 100644 --- a/index/test/movable.hpp +++ b/index/test/movable.hpp @@ -1,15 +1,15 @@ -////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2009. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at +// Boost.Geometry.Index varray +// Unit Test + +// Copyright (c) 2009 Ion Gaztanaga +// Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -// -// See http://www.boost.org/libs/move for documentation. -// -////////////////////////////////////////////////////////////////////////////// -#ifndef BOOST_MOVE_TEST_MOVABLE_HPP -#define BOOST_MOVE_TEST_MOVABLE_HPP + +#ifndef BOOST_GEOMETRY_INDEX_TEST_MOVABLE_HPP +#define BOOST_GEOMETRY_INDEX_TEST_MOVABLE_HPP //[movable_definition //header file "movable.hpp" @@ -39,10 +39,10 @@ public: class copy_movable { BOOST_COPYABLE_AND_MOVABLE(copy_movable) - int value_; + size_t value_; public: - copy_movable(int value = 1) : value_(value){} + copy_movable(size_t value = 1) : value_(value){} //Move constructor and assignment copy_movable(BOOST_RV_REF(copy_movable) m) @@ -89,4 +89,4 @@ struct has_nothrow_move } //namespace boost{ //] -#endif //BOOST_MOVE_TEST_MOVABLE_HPP +#endif //BOOST_GEOMETRY_INDEX_TEST_MOVABLE_HPP diff --git a/index/test/varray.cpp b/index/test/varray.cpp index e79afbfb2..7952be2ff 100644 --- a/index/test/varray.cpp +++ b/index/test/varray.cpp @@ -659,98 +659,98 @@ int test_main(int, char* []) { BOOST_CHECK(counting_value::count() == 0); - test_ctor_ndc(); + test_ctor_ndc(); test_ctor_ndc(); test_ctor_ndc(); BOOST_CHECK(counting_value::count() == 0); test_ctor_ndc(); test_ctor_ndc(); - test_ctor_nc(5); + test_ctor_nc(5); test_ctor_nc(5); test_ctor_nc(5); BOOST_CHECK(counting_value::count() == 0); test_ctor_nc(5); test_ctor_nc(5); - test_ctor_nd(5, 1); + test_ctor_nd(5, 1); test_ctor_nd(5, value_nd(1)); test_ctor_nd(5, counting_value(1)); BOOST_CHECK(counting_value::count() == 0); test_ctor_nd(5, shptr_value(1)); test_ctor_nd(5, produce()); - test_resize_nc(5); + test_resize_nc(5); test_resize_nc(5); test_resize_nc(5); BOOST_CHECK(counting_value::count() == 0); test_resize_nc(5); test_resize_nc(5); - test_resize_nd(5, 1); + test_resize_nd(5, 1); test_resize_nd(5, value_nd(1)); test_resize_nd(5, counting_value(1)); BOOST_CHECK(counting_value::count() == 0); test_resize_nd(5, shptr_value(1)); test_resize_nd(5, produce()); - test_push_back_nd(); + test_push_back_nd(); test_push_back_nd(); test_push_back_nd(); BOOST_CHECK(counting_value::count() == 0); test_push_back_nd(); test_push_back_nd(); - test_pop_back_nd(); + test_pop_back_nd(); test_pop_back_nd(); test_pop_back_nd(); BOOST_CHECK(counting_value::count() == 0); test_pop_back_nd(); test_pop_back_nd(); - test_copy_and_assign_nd(1); + test_copy_and_assign_nd(1); test_copy_and_assign_nd(value_nd(1)); test_copy_and_assign_nd(counting_value(1)); BOOST_CHECK(counting_value::count() == 0); test_copy_and_assign_nd(shptr_value(1)); test_copy_and_assign_nd(produce()); - test_iterators_nd(); + test_iterators_nd(); test_iterators_nd(); test_iterators_nd(); BOOST_CHECK(counting_value::count() == 0); test_iterators_nd(); test_iterators_nd(); - test_erase_nd(); + test_erase_nd(); test_erase_nd(); test_erase_nd(); BOOST_CHECK(counting_value::count() == 0); test_erase_nd(); test_erase_nd(); - test_insert_nd(50); + test_insert_nd(50); test_insert_nd(value_nd(50)); test_insert_nd(counting_value(50)); BOOST_CHECK(counting_value::count() == 0); test_insert_nd(shptr_value(50)); test_insert_nd(produce()); - test_capacity_0_nd(); + test_capacity_0_nd(); test_capacity_0_nd(); test_capacity_0_nd(); BOOST_CHECK(counting_value::count() == 0); test_capacity_0_nd(); test_capacity_0_nd(); - test_exceptions_nd(); + test_exceptions_nd(); test_exceptions_nd(); test_exceptions_nd(); BOOST_CHECK(counting_value::count() == 0); test_exceptions_nd(); test_exceptions_nd(); - test_swap_and_move_nd(); + test_swap_and_move_nd(); test_swap_and_move_nd(); test_swap_and_move_nd(); BOOST_CHECK(counting_value::count() == 0); @@ -763,7 +763,7 @@ int test_main(int, char* []) test_emplace_2p(); BOOST_CHECK(counting_value::count() == 0); - test_sv_elem(50); + test_sv_elem(50); test_sv_elem(value_nd(50)); test_sv_elem(counting_value(50)); BOOST_CHECK(counting_value::count() == 0); diff --git a/index/test/varray_test.hpp b/index/test/varray_test.hpp index e901bcde2..4136db7fc 100644 --- a/index/test/varray_test.hpp +++ b/index/test/varray_test.hpp @@ -19,38 +19,38 @@ class value_ndc { public: - explicit value_ndc(int a) : aa(a) {} + explicit value_ndc(size_t a) : aa(a) {} ~value_ndc() {} bool operator==(value_ndc const& v) const { return aa == v.aa; } bool operator<(value_ndc const& v) const { return aa < v.aa; } private: value_ndc(value_ndc const&) {} value_ndc & operator=(value_ndc const&) { return *this; } - int aa; + size_t aa; }; class value_nd { public: - explicit value_nd(int a) : aa(a) {} + explicit value_nd(size_t a) : aa(a) {} ~value_nd() {} bool operator==(value_nd const& v) const { return aa == v.aa; } bool operator<(value_nd const& v) const { return aa < v.aa; } private: - int aa; + size_t aa; }; class value_nc { public: - explicit value_nc(int a = 0) : aa(a) {} + explicit value_nc(size_t a = 0) : aa(a) {} ~value_nc() {} bool operator==(value_nc const& v) const { return aa == v.aa; } bool operator<(value_nc const& v) const { return aa < v.aa; } private: value_nc(value_nc const&) {} value_nc & operator=(value_ndc const&) { return *this; } - int aa; + size_t aa; }; class counting_value @@ -58,7 +58,7 @@ class counting_value BOOST_COPYABLE_AND_MOVABLE(counting_value) public: - explicit counting_value(int a = 0, int b = 0) : aa(a), bb(b) { ++c(); } + explicit counting_value(size_t a = 0, size_t b = 0) : aa(a), bb(b) { ++c(); } counting_value(counting_value const& v) : aa(v.aa), bb(v.bb) { ++c(); } counting_value(BOOST_RV_REF(counting_value) p) : aa(p.aa), bb(p.bb) { p.aa = 0; p.bb = 0; ++c(); } // Move constructor counting_value& operator=(BOOST_RV_REF(counting_value) p) { aa = p.aa; p.aa = 0; bb = p.bb; p.bb = 0; return *this; } // Move assignment @@ -70,7 +70,7 @@ public: private: static size_t & c() { static size_t co = 0; return co; } - int aa, bb; + size_t aa, bb; }; namespace boost { @@ -85,13 +85,13 @@ struct has_nothrow_move class shptr_value { - typedef boost::shared_ptr Ptr; + typedef boost::shared_ptr Ptr; public: - explicit shptr_value(int a = 0) : m_ptr(new int(a)) {} + explicit shptr_value(size_t a = 0) : m_ptr(new size_t(a)) {} bool operator==(shptr_value const& v) const { return *m_ptr == *(v.m_ptr); } bool operator<(shptr_value const& v) const { return *m_ptr < *(v.m_ptr); } private: - boost::shared_ptr m_ptr; + boost::shared_ptr m_ptr; }; #endif // BOOST_GEOMETRY_INDEX_TEST_VARRAY_TEST_HPP