From ef0f799cc1c47b91e94b9a9ee6520fa315f46983 Mon Sep 17 00:00:00 2001 From: NicolaiDybro Date: Thu, 5 Nov 2026 20:41:18 +0100 Subject: [PATCH] Uniform point selection --- README.md | 4 ++-- engine/CMakeLists.txt | 1 + engine/configs/geolife.json | 2 +- .../backend/engine/selection/selector.hpp | 2 +- .../backend/engine/selection/uniform.hpp | 13 +++++++++++++ engine/src/selection/selector.cpp | 3 +++ engine/src/selection/uniform.cpp | 18 ++++++++++++++++++ .../tests/selectors/simplify_database_test.cpp | 3 ++- 8 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 engine/include/backend/engine/selection/uniform.hpp create mode 100644 engine/src/selection/uniform.cpp diff --git a/README.md b/README.md index 4cae730..3dd028b 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ and it then falls back to its default. [engine/configs/geolife.json](engine/conf | `seed` | Seed for all random sampling | | `budget_shares` | Point budgets to test, as a share of all points (`0.01` = 1%) | | `split` | `type` (`Random` or `Time`) and `query_percentage` held out for queries | -| `algorithms` | Simplification algorithms to run: `RDP`, `SED` | +| `algorithms` | Simplification algorithms to run: `RDP`, `SED`, `UNIFORM` | | `knn` | `k` and `query_count` (`0` = every trajectory in the query split) | | `range` | Box size (m), time window (s) and sampling limits for range queries | | `where_at` | Probes per trajectory and max time gap (s) between points to probe | @@ -101,7 +101,7 @@ engine/ Simplification and evaluation ├── core/ Trajectory database, projection, interpolation ├── io/ Parquet loading ├── split/ Train/query split -├── selection/ Simplification algorithms (RDP, SED) +├── selection/ Simplification algorithms (RDP, SED, UNIFORM) ├── allocation/ Distributing the point budget across trajectories ├── query/ Query workload generation (kNN, range, where-at) ├── evaluator/ Scoring simplified data against the original diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index fdeab7d..a492dd9 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -19,6 +19,7 @@ add_library(engine src/pipeline/pipeline.cpp src/selection/rdp.cpp src/selection/sed.cpp + src/selection/uniform.cpp src/selection/selector.cpp src/split/split.cpp src/allocation/budget_allocator.cpp diff --git a/engine/configs/geolife.json b/engine/configs/geolife.json index 29e6d8a..1ae5484 100644 --- a/engine/configs/geolife.json +++ b/engine/configs/geolife.json @@ -8,7 +8,7 @@ "type": "Random", "query_percentage": 0.15 }, - "algorithms": ["RDP", "SED"], + "algorithms": ["RDP", "SED", "UNIFORM"], "knn": { "k": 10, "query_count": 0 diff --git a/engine/include/backend/engine/selection/selector.hpp b/engine/include/backend/engine/selection/selector.hpp index 7d67325..2a50919 100644 --- a/engine/include/backend/engine/selection/selector.hpp +++ b/engine/include/backend/engine/selection/selector.hpp @@ -8,7 +8,7 @@ namespace selection { -enum class AlgorithmType { RDP, SED }; +enum class AlgorithmType { RDP, SED, UNIFORM }; std::vector simplify_trajectory(const core::TrajectoryView &, AlgorithmType, std::size_t); diff --git a/engine/include/backend/engine/selection/uniform.hpp b/engine/include/backend/engine/selection/uniform.hpp new file mode 100644 index 0000000..f4acd3a --- /dev/null +++ b/engine/include/backend/engine/selection/uniform.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "backend/engine/core/trajectory_db.hpp" + +#include +#include + +namespace selection::uniform { + +std::vector simplify(const core::TrajectoryView &trajectory, + std::size_t points_to_keep); + +} // namespace selection::uniform diff --git a/engine/src/selection/selector.cpp b/engine/src/selection/selector.cpp index 24cb742..10d080d 100644 --- a/engine/src/selection/selector.cpp +++ b/engine/src/selection/selector.cpp @@ -3,6 +3,7 @@ #include "backend/engine/core/parallel.hpp" #include "backend/engine/selection/rdp.hpp" #include "backend/engine/selection/sed.hpp" +#include "backend/engine/selection/uniform.hpp" #include #include @@ -17,6 +18,8 @@ std::vector simplify_trajectory(const core::TrajectoryView &traject return rdp::simplify(trajectory, points_to_keep); case AlgorithmType::SED: return sed::simplify(trajectory, points_to_keep); + case AlgorithmType::UNIFORM: + return uniform::simplify(trajectory, points_to_keep); } throw std::invalid_argument("simplify_trajectory: unknown algorithm"); diff --git a/engine/src/selection/uniform.cpp b/engine/src/selection/uniform.cpp new file mode 100644 index 0000000..f33346e --- /dev/null +++ b/engine/src/selection/uniform.cpp @@ -0,0 +1,18 @@ +#include "backend/engine/selection/uniform.hpp" + +#include + +namespace selection::uniform { + +std::vector simplify(const core::TrajectoryView &trajectory, + std::size_t points_to_keep) { + const std::size_t n = trajectory.size(); + const std::size_t k = std::min(std::max(points_to_keep, 2), n); + + std::vector indices(k); + for (std::size_t i = 0; i < k; ++i) + indices[i] = k == 1 ? 0 : i * (n - 1) / (k - 1); + return indices; +} + +} // namespace selection::uniform diff --git a/engine/tests/selectors/simplify_database_test.cpp b/engine/tests/selectors/simplify_database_test.cpp index 255cf28..7040719 100644 --- a/engine/tests/selectors/simplify_database_test.cpp +++ b/engine/tests/selectors/simplify_database_test.cpp @@ -35,7 +35,8 @@ core::TrajectoryDb make_random_db(const std::vector &sizes) { } constexpr selection::AlgorithmType kAlgorithms[] = {selection::AlgorithmType::RDP, - selection::AlgorithmType::SED}; + selection::AlgorithmType::SED, + selection::AlgorithmType::UNIFORM}; } // namespace