From 7e8cc907433b99556284b570b37df581fe9b651f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Thu, 12 Dec 2024 18:11:09 +0100 Subject: [PATCH] WIP: Tests for 3 and 100 dimensional data. There is a FIXME that remains and then it should hopefully be done. --- .../Frechet_distance_test.cpp | 98 +++++++++++++++---- .../data/queries/generated_100d.txt | 90 +++++++++++++++++ .../data/queries/generated_3d.txt | 90 +++++++++++++++++ .../data/scripts/create_queries.py | 2 +- 4 files changed, 258 insertions(+), 22 deletions(-) create mode 100644 Frechet_distance/test/Frechet_distance/data/queries/generated_100d.txt create mode 100644 Frechet_distance/test/Frechet_distance/data/queries/generated_3d.txt diff --git a/Frechet_distance/test/Frechet_distance/Frechet_distance_test.cpp b/Frechet_distance/test/Frechet_distance/Frechet_distance_test.cpp index 713d7a114a44..b8bbb2323d46 100644 --- a/Frechet_distance/test/Frechet_distance/Frechet_distance_test.cpp +++ b/Frechet_distance/test/Frechet_distance/Frechet_distance_test.cpp @@ -5,7 +5,10 @@ #include #include #include +#include +#include #include +#include #include #include @@ -15,7 +18,7 @@ #include #include -template +template struct Test_struct { @@ -23,13 +26,9 @@ struct Test_struct // helpers // using Test_distance_t = double; - -using TestTraits = CGAL::Frechet_distance_traits_2; -using TestPoint = typename TestKernel::Point_2; using TestCurve = std::vector; using TestCurves = std::vector; - struct FrechetDistanceQuery { std::size_t id1, id2; Test_distance_t distance; @@ -151,9 +150,21 @@ template static double testFrechetDistance() { std::string curve_directory = "./data/curves/"; - // std::vector datasets = {"sigspatial", "OV"}; - std::vector datasets = { "sigspatial" }; std::string query_directory = "./data/queries/"; + std::vector datasets; + + auto const dimension = CGAL::Ambient_dimension::value; + if (dimension == 2) { + // datasets = {"sigspatial", "OV"}; + datasets = { "sigspatial" }; + } + else if (dimension == 3) { + datasets = { "generated_3d" }; + } + else if (dimension == 100) { + datasets = { "generated_100d" }; + } + CGAL::Real_timer timer; for (auto const& dataset : datasets) { auto curves = readCurves(curve_directory + dataset + "/"); @@ -173,6 +184,7 @@ static double testFrechetDistance() ! CGAL::is_Frechet_distance_larger( curves[query.id1], curves[query.id2], query.distance); timer.stop(); + if (decision != query.decision) { std::cout << "Wrong decision on query." << std::endl; exit(- 1); @@ -216,7 +228,6 @@ static double testFrechetDistanceNearNeighborsDS() }; - int main(int argc, char** argv) { std::set test_set; @@ -225,46 +236,91 @@ int main(int argc, char** argv) if (test_set.empty() || test_set.count(0)) { - using SCD = CGAL::Simple_cartesian; + using Kernel = CGAL::Simple_cartesian; + using Traits = CGAL::Frechet_distance_traits_2; + using Point = Kernel::Point_2; std::cout <<"Simple_cartesian\n"; - double t1=Test_struct::testFrechetDistanceNearNeighborsDS(); - double t2=Test_struct::testFrechetDistance(); + double t1=Test_struct::testFrechetDistanceNearNeighborsDS(); + double t2=Test_struct::testFrechetDistance(); std::cout << t1 << " " << t2 << "\n"; } if (test_set.empty() || test_set.count(1)) { + using Kernel = CGAL::Epick; + using Traits = CGAL::Frechet_distance_traits_2; + using Point = Kernel::Point_2; std::cout <<"CGAL::Epick\n"; - double t1=Test_struct::testFrechetDistanceNearNeighborsDS(); - double t2=Test_struct::testFrechetDistance(); + double t1=Test_struct::testFrechetDistanceNearNeighborsDS(); + double t2=Test_struct::testFrechetDistance(); std::cout << t1 << " " << t2 << "\n"; } if (test_set.empty() || test_set.count(2)) { + using Kernel = CGAL::Epeck; + using Traits = CGAL::Frechet_distance_traits_2; + using Point = Kernel::Point_2; std::cout <<"CGAL::Epeck\n"; - double t1=Test_struct::testFrechetDistanceNearNeighborsDS(); - double t2=Test_struct::testFrechetDistance(); + double t1=Test_struct::testFrechetDistanceNearNeighborsDS(); + double t2=Test_struct::testFrechetDistance(); std::cout << t1 << " " << t2 << "\n"; } if (test_set.empty() || test_set.count(3)) { - using Epeck_sqrt = CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt; + using Kernel = CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt; + using Traits = CGAL::Frechet_distance_traits_2; + using Point = Kernel::Point_2; std::cout <<"Exact_predicates_exact_constructions_kernel_with_sqrt (force filtering)\n"; - double t1=Test_struct::testFrechetDistanceNearNeighborsDS(); - double t2=Test_struct::testFrechetDistance(); + double t1=Test_struct::testFrechetDistanceNearNeighborsDS(); + double t2=Test_struct::testFrechetDistance(); std::cout << t1 << " " << t2 << "\n"; } if (test_set.empty() || test_set.count(4)) { - using SCE = CGAL::Simple_cartesian; + using Kernel = CGAL::Simple_cartesian; + using Traits = CGAL::Frechet_distance_traits_2; + using Point = Kernel::Point_2; std::cout <<"Simple_cartesian (force filtering)\n"; - double t1=Test_struct::testFrechetDistanceNearNeighborsDS(); - double t2=Test_struct::testFrechetDistance(); + double t1=Test_struct::testFrechetDistanceNearNeighborsDS(); + double t2=Test_struct::testFrechetDistance(); std::cout << t1 << " " << t2 << "\n"; } + if (test_set.empty() || test_set.count(5)) + { + using Kernel = CGAL::Simple_cartesian; + using Traits = CGAL::Frechet_distance_traits_3; + using Point = Kernel::Point_3; + std::cout <<"Simple_cartesian in 3D\n"; + double t1=Test_struct::testFrechetDistance(); + std::cout << t1 << "\n"; + } + + // FIXME: CGAL::Ambient_dimension::value not defined for Epick_d and Epeck_d + // How do I get the dimension for any kernel? + + // if (test_set.empty() || test_set.count(6)) + // { + // using Kernel = CGAL::Epick_d>; + // using Traits = CGAL::Frechet_distance_traits_d; + // using Point = Kernel::Point_d; + // std::cout <<"CGAL::Epick_d\n"; + // double t1=Test_struct::testFrechetDistance(); + // std::cout << t1 << "\n"; + // } + // + // if (test_set.empty() || test_set.count(7)) + // { + // using Kernel = CGAL::Epeck_d>; + // using Traits = CGAL::Frechet_distance_traits_d; + // using Point = Kernel::Point_d; + // std::cout <<"CGAL::Epeck_d\n"; + // double t1=Test_struct::testFrechetDistance(); + // std::cout << t1 << "\n"; + // } + return 0; } diff --git a/Frechet_distance/test/Frechet_distance/data/queries/generated_100d.txt b/Frechet_distance/test/Frechet_distance/data/queries/generated_100d.txt new file mode 100644 index 000000000000..58fc2d52bde9 --- /dev/null +++ b/Frechet_distance/test/Frechet_distance/data/queries/generated_100d.txt @@ -0,0 +1,90 @@ +0 1 54.60852705684005 1 +1 0 54.60852705284005 0 +0 2 53.42754226723013 1 +2 0 53.42754226323013 0 +0 3 57.85406876379627 1 +3 0 57.85406875979627 0 +0 4 51.80576158849383 1 +4 0 51.80576158449383 0 +0 5 51.64304415859679 1 +5 0 51.64304415459679 0 +0 6 54.86654876491408 1 +6 0 54.86654876091408 0 +0 7 51.13818965967115 1 +7 0 51.13818965567115 0 +0 8 57.53958841215654 1 +8 0 57.53958840815654 0 +0 9 61.56241116067319 1 +9 0 61.56241115667319 0 +1 2 57.05667580407672 1 +2 1 57.05667580007672 0 +1 3 55.222310902876124 1 +3 1 55.222310898876124 0 +1 4 59.97293508500102 1 +4 1 59.97293508100102 0 +1 5 58.06531437645447 1 +5 1 58.065314372454466 0 +1 6 59.74143773397376 1 +6 1 59.74143772997376 0 +1 7 62.77703730157179 1 +7 1 62.77703729757179 0 +1 8 62.69136407458546 1 +8 1 62.69136407058546 0 +1 9 61.785994213088465 1 +9 1 61.785994209088464 0 +2 3 57.86209019548365 1 +3 2 57.86209019148365 0 +2 4 56.86946019656948 1 +4 2 56.86946019256948 0 +2 5 53.87505625011203 1 +5 2 53.87505624611203 0 +2 6 58.46516152075575 1 +6 2 58.46516151675575 0 +2 7 57.20987005008295 1 +7 2 57.20987004608295 0 +2 8 59.23325129318406 1 +8 2 59.23325128918406 0 +2 9 62.404419893165326 1 +9 2 62.404419889165325 0 +3 4 54.3056041105886 1 +4 3 54.305604106588596 0 +3 5 52.10705090347374 1 +5 3 52.10705089947374 0 +3 6 53.527817516961434 1 +6 3 53.527817512961434 0 +3 7 53.15746851659217 1 +7 3 53.15746851259217 0 +3 8 57.473624874242894 1 +8 3 57.473624870242894 0 +3 9 54.13931896111341 1 +9 3 54.13931895711341 0 +4 5 51.9569110049215 1 +5 4 51.9569110009215 0 +4 6 60.20505047591897 1 +6 4 60.20505047191897 0 +4 7 54.82864423568963 1 +7 4 54.82864423168963 0 +4 8 58.55013869947121 1 +8 4 58.55013869547121 0 +4 9 59.393704141608374 1 +9 4 59.393704137608374 0 +5 6 56.0836818779594 1 +6 5 56.0836818739594 0 +5 7 52.6823432953052 1 +7 5 52.6823432913052 0 +5 8 57.43506158736297 1 +8 5 57.43506158336297 0 +5 9 58.57419031180712 1 +9 5 58.57419030780712 0 +6 7 55.9537039079347 1 +7 6 55.9537039039347 0 +6 8 59.37359200852071 1 +8 6 59.37359200452071 0 +6 9 60.8261116290451 1 +9 6 60.8261116250451 0 +7 8 57.67323246618296 1 +8 7 57.67323246218296 0 +7 9 56.19826252043955 1 +9 7 56.19826251643955 0 +8 9 64.21808545013847 1 +9 8 64.21808544613849 0 diff --git a/Frechet_distance/test/Frechet_distance/data/queries/generated_3d.txt b/Frechet_distance/test/Frechet_distance/data/queries/generated_3d.txt new file mode 100644 index 000000000000..bcc477d9ac7a --- /dev/null +++ b/Frechet_distance/test/Frechet_distance/data/queries/generated_3d.txt @@ -0,0 +1,90 @@ +0 1 23.739932496204332 1 +1 0 23.739932492204332 0 +0 2 11.867215172922883 1 +2 0 11.867215168922883 0 +0 3 10.337626186909043 1 +3 0 10.337626182909043 0 +0 4 15.594451939591893 1 +4 0 15.594451935591893 0 +0 5 18.701732594495226 1 +5 0 18.701732590495226 0 +0 6 13.5624286169771 1 +6 0 13.562428612977099 0 +0 7 18.34514602050944 1 +7 0 18.34514601650944 0 +0 8 7.883463379504051 1 +8 0 7.883463375504051 0 +0 9 15.246800967601196 1 +9 0 15.246800963601196 0 +1 2 16.601956209189954 1 +2 1 16.601956205189953 0 +1 3 20.147861260270478 1 +3 1 20.147861256270478 0 +1 4 13.287296733965082 1 +4 1 13.287296729965082 0 +1 5 20.5462302022121 1 +5 1 20.5462301982121 0 +1 6 29.66052166542632 1 +6 1 29.66052166142632 0 +1 7 24.76366609643071 1 +7 1 24.76366609243071 0 +1 8 27.058190809915097 1 +8 1 27.058190805915096 0 +1 9 17.15448217453084 1 +9 1 17.15448217053084 0 +2 3 10.72625176468103 1 +3 2 10.726251760681029 0 +2 4 15.623723152364027 1 +4 2 15.623723148364027 0 +2 5 17.552592568998325 1 +5 2 17.552592564998324 0 +2 6 16.285896792838845 1 +6 2 16.285896788838844 0 +2 7 19.542498785608696 1 +7 2 19.542498781608696 0 +2 8 14.630077010871966 1 +8 2 14.630077006871966 0 +2 9 15.844782389073675 1 +9 2 15.844782385073675 0 +3 4 12.47339041576954 1 +4 3 12.47339041176954 0 +3 5 18.45219430164012 1 +5 3 18.45219429764012 0 +3 6 15.64707208604751 1 +6 3 15.64707208204751 0 +3 7 16.808137055143643 1 +7 3 16.808137051143643 0 +3 8 11.897177602534502 1 +8 3 11.897177598534501 0 +3 9 15.605151777397484 1 +9 3 15.605151773397484 0 +4 5 20.948219677440015 1 +5 4 20.948219673440015 0 +4 6 21.700626366629606 1 +6 4 21.700626362629606 0 +4 7 23.958217003967892 1 +7 4 23.958216999967892 0 +4 8 18.71746268945578 1 +8 4 18.71746268545578 0 +4 9 10.7102531264285 1 +9 4 10.7102531224285 0 +5 6 16.84679818105388 1 +6 5 16.84679817705388 0 +5 7 23.600864202530676 1 +7 5 23.600864198530676 0 +5 8 20.931271289249135 1 +8 5 20.931271285249135 0 +5 9 19.655548946041325 1 +9 5 19.655548942041325 0 +6 7 15.835704334361006 1 +7 6 15.835704330361006 0 +6 8 16.520383513810977 1 +8 6 16.520383509810976 0 +6 9 23.359930266746712 1 +9 6 23.359930262746712 0 +7 8 19.976803220777366 1 +8 7 19.976803216777366 0 +7 9 26.318500289580992 1 +9 7 26.318500285580992 0 +8 9 19.076478575990024 1 +9 8 19.076478571990023 0 diff --git a/Frechet_distance/test/Frechet_distance/data/scripts/create_queries.py b/Frechet_distance/test/Frechet_distance/data/scripts/create_queries.py index 3db80277cd0d..021bc16fc278 100644 --- a/Frechet_distance/test/Frechet_distance/data/scripts/create_queries.py +++ b/Frechet_distance/test/Frechet_distance/data/scripts/create_queries.py @@ -30,7 +30,7 @@ def write_queries(queries, d): file.write(f'{q[1]} {q[0]} {q[2]-2*eps} 0\n') def frechet_distance(curve1, curve2): - args = ('build/Compute_classical_Frechet_distance_{d}', curve1, curve2) + args = (f'build/Compute_classical_Frechet_distance_{d}', curve1, curve2) popen = subprocess.Popen(args, stdout=subprocess.PIPE) popen.wait() output = popen.stdout.read()