Skip to content

Commit

Permalink
WIP: Tests for 3 and 100 dimensional data.
Browse files Browse the repository at this point in the history
There is a FIXME that remains and then it should hopefully be done.
  • Loading branch information
André Nusser committed Dec 12, 2024
1 parent 10e45a7 commit 7e8cc90
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 22 deletions.
98 changes: 77 additions & 21 deletions Frechet_distance/test/Frechet_distance/Frechet_distance_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel_with_sqrt.h>
#include <CGAL/Epeck_d.h>
#include <CGAL/Epick_d.h>
#include <CGAL/Real_timer.h>
#include <CGAL/Dimension.h>

#include <algorithm>
#include <cassert>
Expand All @@ -15,21 +18,17 @@
#include <string>
#include <vector>

template <class TestKernel>
template <class TestKernel, class TestTraits, class TestPoint>
struct Test_struct
{

//
// helpers
//
using Test_distance_t = double;

using TestTraits = CGAL::Frechet_distance_traits_2<TestKernel>;
using TestPoint = typename TestKernel::Point_2;
using TestCurve = std::vector<TestPoint>;
using TestCurves = std::vector<TestCurve>;


struct FrechetDistanceQuery {
std::size_t id1, id2;
Test_distance_t distance;
Expand Down Expand Up @@ -151,9 +150,21 @@ template<bool force_filtering=false>
static double testFrechetDistance()
{
std::string curve_directory = "./data/curves/";
// std::vector<std::string> datasets = {"sigspatial", "OV"};
std::vector<std::string> datasets = { "sigspatial" };
std::string query_directory = "./data/queries/";
std::vector<std::string> datasets;

auto const dimension = CGAL::Ambient_dimension<TestPoint, TestKernel>::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 + "/");
Expand All @@ -173,6 +184,7 @@ static double testFrechetDistance()
! CGAL::is_Frechet_distance_larger<TestTraits, force_filtering>(
curves[query.id1], curves[query.id2], query.distance);
timer.stop();

if (decision != query.decision) {
std::cout << "Wrong decision on query." << std::endl;
exit(- 1);
Expand Down Expand Up @@ -216,7 +228,6 @@ static double testFrechetDistanceNearNeighborsDS()

};


int main(int argc, char** argv)
{
std::set<int> test_set;
Expand All @@ -225,46 +236,91 @@ int main(int argc, char** argv)

if (test_set.empty() || test_set.count(0))
{
using SCD = CGAL::Simple_cartesian<double>;
using Kernel = CGAL::Simple_cartesian<double>;
using Traits = CGAL::Frechet_distance_traits_2<Kernel>;
using Point = Kernel::Point_2;
std::cout <<"Simple_cartesian<double>\n";
double t1=Test_struct<SCD>::testFrechetDistanceNearNeighborsDS();
double t2=Test_struct<SCD>::testFrechetDistance();
double t1=Test_struct<Kernel, Traits, Point>::testFrechetDistanceNearNeighborsDS();
double t2=Test_struct<Kernel, Traits, Point>::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<Kernel>;
using Point = Kernel::Point_2;
std::cout <<"CGAL::Epick\n";
double t1=Test_struct<CGAL::Epick>::testFrechetDistanceNearNeighborsDS();
double t2=Test_struct<CGAL::Epick>::testFrechetDistance();
double t1=Test_struct<Kernel, Traits, Point>::testFrechetDistanceNearNeighborsDS();
double t2=Test_struct<Kernel, Traits, Point>::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<Kernel>;
using Point = Kernel::Point_2;
std::cout <<"CGAL::Epeck\n";
double t1=Test_struct<CGAL::Epeck>::testFrechetDistanceNearNeighborsDS();
double t2=Test_struct<CGAL::Epeck>::testFrechetDistance();
double t1=Test_struct<Kernel, Traits, Point>::testFrechetDistanceNearNeighborsDS();
double t2=Test_struct<Kernel, Traits, Point>::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<Kernel>;
using Point = Kernel::Point_2;
std::cout <<"Exact_predicates_exact_constructions_kernel_with_sqrt (force filtering)\n";
double t1=Test_struct<Epeck_sqrt>::testFrechetDistanceNearNeighborsDS();
double t2=Test_struct<Epeck_sqrt>::testFrechetDistance<true>();
double t1=Test_struct<Kernel, Traits, Point>::testFrechetDistanceNearNeighborsDS();
double t2=Test_struct<Kernel, Traits, Point>::testFrechetDistance<true>();
std::cout << t1 << " " << t2 << "\n";
}

if (test_set.empty() || test_set.count(4))
{
using SCE = CGAL::Simple_cartesian<CGAL::Exact_rational>;
using Kernel = CGAL::Simple_cartesian<CGAL::Exact_rational>;
using Traits = CGAL::Frechet_distance_traits_2<Kernel>;
using Point = Kernel::Point_2;
std::cout <<"Simple_cartesian<Exact_rational> (force filtering)\n";
double t1=Test_struct<SCE>::testFrechetDistanceNearNeighborsDS();
double t2=Test_struct<SCE>::testFrechetDistance<true>();
double t1=Test_struct<Kernel, Traits, Point>::testFrechetDistanceNearNeighborsDS();
double t2=Test_struct<Kernel, Traits, Point>::testFrechetDistance<true>();
std::cout << t1 << " " << t2 << "\n";
}

if (test_set.empty() || test_set.count(5))
{
using Kernel = CGAL::Simple_cartesian<double>;
using Traits = CGAL::Frechet_distance_traits_3<Kernel>;
using Point = Kernel::Point_3;
std::cout <<"Simple_cartesian<double> in 3D\n";
double t1=Test_struct<Kernel, Traits, Point>::testFrechetDistance();
std::cout << t1 << "\n";
}

// FIXME: CGAL::Ambient_dimension<TestPoint, TestKernel>::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<CGAL::Dimension_tag<100>>;
// using Traits = CGAL::Frechet_distance_traits_d<Kernel>;
// using Point = Kernel::Point_d;
// std::cout <<"CGAL::Epick_d\n";
// double t1=Test_struct<Kernel, Traits, Point>::testFrechetDistance();
// std::cout << t1 << "\n";
// }
//
// if (test_set.empty() || test_set.count(7))
// {
// using Kernel = CGAL::Epeck_d<CGAL::Dimension_tag<100>>;
// using Traits = CGAL::Frechet_distance_traits_d<Kernel>;
// using Point = Kernel::Point_d;
// std::cout <<"CGAL::Epeck_d\n";
// double t1=Test_struct<Kernel, Traits, Point>::testFrechetDistance();
// std::cout << t1 << "\n";
// }

return 0;
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7e8cc90

Please sign in to comment.