Skip to content

Commit

Permalink
initial test
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Mar 25, 2024
1 parent 8662d36 commit 22ab83e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/src/assets/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,5 @@ export const SORT_BY = [
'Geohash',
'LatLon',
'PointCount',
'Hilbert',
] as const
15 changes: 15 additions & 0 deletions server/algorithms/src/routing/hilbert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use super::sorting::SortS2;
use crate::s2;
use model::api::single_vec::SingleVec;

pub fn run(points: SingleVec) -> SingleVec {
let mut l15_map: Vec<(u64, SingleVec)> = s2::create_cell_map(&points, 15).into_iter().collect();
l15_map.sort_by(|a, b| a.0.cmp(&b.0));
let mut result = vec![];

for (_, mut points) in l15_map {
points.sort_s2_mut();
result.append(&mut points);
}
result
}
2 changes: 2 additions & 0 deletions server/algorithms/src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
utils,
};

mod hilbert;
mod join;
pub mod sorting;
// pub mod vrp;
Expand All @@ -29,6 +30,7 @@ pub fn main(
SortBy::GeoHash => clusters.sort_geohash(),
SortBy::S2Cell => clusters.sort_s2(),
SortBy::Random => clusters.sort_random(),
SortBy::Hilbert => hilbert::run(clusters),
SortBy::Unset => clusters,
SortBy::Custom(plugin) => {
let clusters = clusters.sort_s2();
Expand Down
2 changes: 2 additions & 0 deletions server/model/src/api/sort_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub enum SortBy {
Random,
S2Cell,
LatLon,
Hilbert,
Custom(String),
}

Expand Down Expand Up @@ -42,6 +43,7 @@ impl<'de> Deserialize<'de> for SortBy {
"s2" | "s2cell" => Ok(SortBy::S2Cell),
"latlon" => Ok(SortBy::LatLon),
"" | "none" | "unset" => Ok(SortBy::Unset),
"hilbert" => Ok(SortBy::Hilbert),
// This is for backwards compatibility since the custom below would end up with a value of "TSP"
"tsp" => Ok(SortBy::Custom("tsp".to_string())),
_ => Ok(SortBy::Custom(s)),
Expand Down

0 comments on commit 22ab83e

Please sign in to comment.