From 917a01238d286cb6d0f05fe46cf933e83cbf460b Mon Sep 17 00:00:00 2001 From: Dennis Rohde Date: Thu, 26 Jan 2023 13:31:49 +0100 Subject: [PATCH] bugfix 2 approximate simplification --- setup.py | 2 +- src/simplification.cpp | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index 5f6a793..165b6dd 100644 --- a/setup.py +++ b/setup.py @@ -80,7 +80,7 @@ def build_extension(self, ext): setup( name='Fred-Frechet', - version='1.10.5', + version='1.10.6', author='Dennis Rohde', author_email='dennis.rohde@tu-dortmund.de', description='A fast, scalable and light-weight C++ Fréchet distance library, exposed to python and focused on (k,l)-clustering of polygonal curves.', diff --git a/src/simplification.cpp b/src/simplification.cpp index 1bbb228..b039ab0 100644 --- a/src/simplification.cpp +++ b/src/simplification.cpp @@ -11,11 +11,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include "simplification.hpp" Curve Simplification::approximate_minimum_link_simplification(const Curve &pcurve, const distance_t epsilon) { - if (Config::verbosity > 1) py::print("ASIMPL: computing approximate minimum link simplification"); + if (Config::verbosity > 1) py::print("ASIMPL: computing approximate minimum link simplification for curve of complexity ", pcurve.complexity()); Curve &curve = const_cast(pcurve); const curve_size_t complexity = curve.complexity(); - curve_size_t i = 0, j = 0; + curve_size_t i = 0, j = 0, low, mid, high; Curve simplification(curve.dimensions()), segment(2, curve.dimensions()); simplification.push_back(curve.front()); @@ -28,7 +28,7 @@ Curve Simplification::approximate_minimum_link_simplification(const Curve &pcurv j = 0; distance = 0; - if (Config::verbosity > 1) py::print("ASIMPL: computing maximum shortcut starting at ", i); + if (Config::verbosity > 1) py::print("ASIMPL: computing maximum length shortcut starting at ", i); if (Config::verbosity > 1) py::print("ASIMPL: exponential error search"); @@ -44,14 +44,13 @@ Curve Simplification::approximate_minimum_link_simplification(const Curve &pcurv distance = Frechet::Continuous::distance(curve, segment).value; } - curve_size_t low, mid, high; - - low = j == 1 ? 0 : std::pow(2, j - 1); + low = std::pow(2, j - 1); high = std::min(static_cast(std::pow(2, j)), complexity - i - 1); - if (Config::verbosity > 1) py::print("ASIMPL: binary error search"); + if (Config::verbosity > 1) py::print("ASIMPL: binary error search for low = ", low, " and high = ", high); + while (low < high) { - mid = std::ceil((low + high) / 2.); + mid = std::ceil(low + (high - low) * .5); curve.reset_subcurve(); segment[1] = curve[i + mid]; @@ -59,12 +58,16 @@ Curve Simplification::approximate_minimum_link_simplification(const Curve &pcurv distance = Frechet::Continuous::distance(curve, segment).value; - if (distance <= epsilon) low = mid; - else high = mid - 1; + if (distance > epsilon) high = mid - 1; + else low = mid; } + if (Config::verbosity > 1) py::print("ASIMPL: shortcutting from ", i, " to ", i+low); + i += low; + curve.reset_subcurve(); + simplification.push_back(curve[i]); } return simplification;