|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83969 - in trunk/libs/geometry: example/index test/index/rtree
From: adam.wulkiewicz_at_[hidden]
Date: 2013-04-19 18:31:44
Author: awulkiew
Date: 2013-04-19 18:31:43 EDT (Fri, 19 Apr 2013)
New Revision: 83969
URL: http://svn.boost.org/trac/boost/changeset/83969
Log:
geometry.index: test - added test for experimental nearest query iterator, examples - added experimental nearest query iterator to benchmark.
Text files modified:
trunk/libs/geometry/example/index/benchmark.cpp | 31 ++++++++++++++++++++++--
trunk/libs/geometry/test/index/rtree/test_rtree.hpp | 50 +++++++++++++++++++++++++--------------
2 files changed, 60 insertions(+), 21 deletions(-)
Modified: trunk/libs/geometry/example/index/benchmark.cpp
==============================================================================
--- trunk/libs/geometry/example/index/benchmark.cpp (original)
+++ trunk/libs/geometry/example/index/benchmark.cpp 2013-04-19 18:31:43 EDT (Fri, 19 Apr 2013)
@@ -25,6 +25,8 @@
size_t values_count = 1000000;
size_t queries_count = 100000;
+ size_t nearest_queries_count = 10000;
+ unsigned neighbours_count = 10;
std::vector< std::pair<float, float> > coords;
@@ -143,17 +145,40 @@
{
clock_t::time_point start = clock_t::now();
size_t temp = 0;
- for (size_t i = 0 ; i < queries_count / 1 ; ++i )
+ for (size_t i = 0 ; i < nearest_queries_count ; ++i )
{
float x = coords[i].first + 100;
float y = coords[i].second + 100;
result.clear();
- temp += t.query(bgi::nearest(P(x, y), 5), std::back_inserter(result));
+ temp += t.query(bgi::nearest(P(x, y), neighbours_count), std::back_inserter(result));
}
dur_t time = clock_t::now() - start;
- std::cout << time << " - query(nearest(P, 5)) " << (queries_count / 10) << " found " << temp << '\n';
+ std::cout << time << " - query(nearest(P, " << neighbours_count << ")) " << nearest_queries_count << " found " << temp << '\n';
}
+#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
+ {
+ clock_t::time_point start = clock_t::now();
+ size_t temp = 0;
+ for (size_t i = 0 ; i < nearest_queries_count ; ++i )
+ {
+ float x = coords[i].first + 100;
+ float y = coords[i].second + 100;
+ result.clear();
+ if ( i == 3 )
+ {
+ int a = 10;
+ }
+ std::copy(t.qbegin(bgi::nearest(P(x, y), neighbours_count)),
+ t.qend(bgi::nearest(P(x, y), neighbours_count)),
+ std::back_inserter(result));
+ temp += result.size();
+ }
+ dur_t time = clock_t::now() - start;
+ std::cout << time << " - nearest_iterator(P, " << neighbours_count << ")) " << nearest_queries_count << " found " << temp << '\n';
+ }
+#endif
+
{
clock_t::time_point start = clock_t::now();
for (size_t i = 0 ; i < values_count / 10 ; ++i )
Modified: trunk/libs/geometry/test/index/rtree/test_rtree.hpp
==============================================================================
--- trunk/libs/geometry/test/index/rtree/test_rtree.hpp (original)
+++ trunk/libs/geometry/test/index/rtree/test_rtree.hpp 2013-04-19 18:31:43 EDT (Fri, 19 Apr 2013)
@@ -860,6 +860,28 @@
}
};
+template <typename Rtree, typename Value, typename Point, typename Distance>
+void compare_nearest_outputs(Rtree const& rtree, std::vector<Value> const& output, std::vector<Value> const& expected_output, Point const& pt, Distance greatest_distance)
+{
+ // check output
+ bool are_sizes_ok = (expected_output.size() == output.size());
+ BOOST_CHECK( are_sizes_ok );
+ if ( are_sizes_ok )
+ {
+ BOOST_FOREACH(Value const& v, output)
+ {
+ // TODO - perform explicit check here?
+ // should all objects which are closest be checked and should exactly the same be found?
+
+ if ( find(rtree, expected_output.begin(), expected_output.end(), v) == expected_output.end() )
+ {
+ Distance d = bgi::detail::comparable_distance_near(pt, rtree.indexable_get()(v));
+ BOOST_CHECK(d == greatest_distance);
+ }
+ }
+ }
+}
+
template <typename Rtree, typename Value, typename Point>
void nearest_query_k(Rtree const& rtree, std::vector<Value> const& input, Point const& pt, unsigned int k)
{
@@ -887,9 +909,9 @@
// caluclate biggest distance
std::sort(test_output.begin(), test_output.end(), NearestKLess<Rtree, Point>());
- D biggest_d = 0;
+ D greatest_distance = 0;
if ( !test_output.empty() )
- biggest_d = test_output.back().first;
+ greatest_distance = test_output.back().first;
// transform test output to vector of values
std::vector<Value> expected_output(test_output.size(), generate::value_default<Value>::apply());
@@ -900,22 +922,7 @@
rtree.query(bgi::nearest(pt, k), std::back_inserter(output));
// check output
- bool are_sizes_ok = (expected_output.size() == output.size());
- BOOST_CHECK( are_sizes_ok );
- if ( are_sizes_ok )
- {
- BOOST_FOREACH(Value const& v, output)
- {
- // TODO - perform explicit check here?
- // should all objects which are closest be checked and should exactly the same be found?
-
- if ( find(rtree, expected_output.begin(), expected_output.end(), v) == expected_output.end() )
- {
- D d = bgi::detail::comparable_distance_near(pt, rtree.indexable_get()(v));
- BOOST_CHECK(d == biggest_d);
- }
- }
- }
+ compare_nearest_outputs(rtree, output, expected_output, pt, greatest_distance);
exactly_the_same_outputs(rtree, output, rtree | bgi::adaptors::queried(bgi::nearest(pt, k)));
@@ -924,6 +931,13 @@
output2.resize(found_count, generate::value_default<Value>::apply());
exactly_the_same_outputs(rtree, output, output2);
+
+#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
+ std::vector<Value> output3;
+ std::copy(rtree.qbegin(bgi::nearest(pt, k)), rtree.qend(bgi::nearest(pt, k)), std::back_inserter(output3));
+
+ compare_nearest_outputs(rtree, output3, expected_output, pt, greatest_distance);
+#endif
}
// rtree nearest not found
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