mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-09 23:24:02 +00:00
geometry.index: test - added test for experimental nearest query iterator, examples - added experimental nearest query iterator to benchmark.
[SVN r83969]
This commit is contained in:
parent
6307d5b3a4
commit
fde5135bd9
@ -25,6 +25,8 @@ int main()
|
||||
|
||||
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 @@ int main()
|
||||
{
|
||||
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 )
|
||||
|
@ -860,6 +860,28 @@ struct NearestKTransform
|
||||
}
|
||||
};
|
||||
|
||||
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 @@ void nearest_query_k(Rtree const& rtree, std::vector<Value> const& input, Point
|
||||
|
||||
// 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 @@ void nearest_query_k(Rtree const& rtree, std::vector<Value> const& input, Point
|
||||
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 @@ void nearest_query_k(Rtree const& rtree, std::vector<Value> const& input, Point
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user