From ba2d4c67ad8806a8ff3a82f5a3ad845d0f91c8ba Mon Sep 17 00:00:00 2001 From: Olivier Devillers Date: Thu, 5 May 2011 07:28:18 +0000 Subject: [PATCH] bug for very high dim --- .../Spatial_sorting/spatial_sorting.tex | 16 ++++++--- .../include/CGAL/Hilbert_sort_median_d.h | 12 +++---- .../test/Spatial_sorting/test_hilbert.cpp | 33 +++++++++++++++++++ 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/Spatial_sorting/doc_tex/Spatial_sorting/spatial_sorting.tex b/Spatial_sorting/doc_tex/Spatial_sorting/spatial_sorting.tex index 807db95b739..d50fd33d795 100644 --- a/Spatial_sorting/doc_tex/Spatial_sorting/spatial_sorting.tex +++ b/Spatial_sorting/doc_tex/Spatial_sorting/spatial_sorting.tex @@ -23,7 +23,7 @@ to be able to combine the good randomized complexity and the good effects of locality \cite{acr-icb-03}. -The only predicates used by this package are comparisons between coordinates, +The predicates used by this package are comparisons between coordinates, thus there is no robustness issues involved here, for example to choose the arithmetic of the kernel. @@ -129,10 +129,16 @@ similar manner and we get also a suitable ordering of the points \cgal\ provides Hilbert sorting for points in 2D, 3D and higher dimensions, in the middle and the median policies. -The median policy seems interesting in practice and his invariant to -scaling, while the middle policy is easier to analyze. Most -theoretical results are using the middle policy -\cite{acr-icb-03,other-references}.. +The middle policy is easier to analyze, and is interesting in practice +for well distributed set of points in small dimension (if the number +of points is really smaller than $2^d$). +The median policy should be prefered for high dimension or if +the point set distribution is not regular (or unknown). +Since the median policy cannot be much worse than the middle +policy, while the converse can happen, the median policy is the +default behavior. +Most theoretical results are using the middle policy +\cite{acr-icb-03,other-references}. This other example illustrates the use of the two different policies diff --git a/Spatial_sorting/include/CGAL/Hilbert_sort_median_d.h b/Spatial_sorting/include/CGAL/Hilbert_sort_median_d.h index 37e6a648fb1..922562945b5 100644 --- a/Spatial_sorting/include/CGAL/Hilbert_sort_median_d.h +++ b/Spatial_sorting/include/CGAL/Hilbert_sort_median_d.h @@ -90,7 +90,6 @@ public: } } - std::vector places(nb_splits +1); std::vector dir (nb_splits +1); places[0]=begin; @@ -144,16 +143,15 @@ public: two_to_dim = 1; Starting_position start(_dimension); - + int N=end-begin;N*=2; + for (int i=0; i<_dimension; ++i) start[i]=false; // we start below in all coordinates for (int i=0; i<_dimension; ++i) { - start[i]=false; // we start below in all coordinates two_to_dim *= 2; // compute 2^_dimension - if (two_to_dim*2 <= 0) { - CGAL_assertion(end-begin < two_to_dim);//too many points in such dim - break; - } + N/=2; + if (N==0) break; // not many points, this number of dimension is enough } + // we start with direction 0; sort (begin, end, start, 0); } diff --git a/Spatial_sorting/test/Spatial_sorting/test_hilbert.cpp b/Spatial_sorting/test/Spatial_sorting/test_hilbert.cpp index 7364d547d77..a174c694faf 100644 --- a/Spatial_sorting/test/Spatial_sorting/test_hilbert.cpp +++ b/Spatial_sorting/test/Spatial_sorting/test_hilbert.cpp @@ -342,6 +342,39 @@ int main () std::cout << "no points lost." << std::endl; } + { + int dim = 10; + std::cout << "Testing "< v; + v.reserve (nb_points_d); + + CGAL::Random_points_in_cube_d gen (dim, 1.0, random); + + for (int i = 0; i < nb_points_d; ++i) + v.push_back (*gen++); + + std::cout << "done." << std::endl; + + std::vector v2 (v); + + std::cout << " Sorting points ... " << std::flush; + + cost.reset();cost.start(); + CGAL::hilbert_sort (v.begin(), v.end(), + CGAL::Hilbert_sort_middle_policy()); + cost.stop(); + + std::cout << "done in "<