From 50287eff67bd2ccc3a739f2d4af8a71eccc0f0e6 Mon Sep 17 00:00:00 2001 From: reinterpretcat Date: Mon, 23 Sep 2024 00:43:52 +0200 Subject: [PATCH] Apply minor refactorings --- rosomaxa/src/algorithms/gsom/network.rs | 2 +- rosomaxa/src/termination/min_variation.rs | 2 +- vrp-core/src/construction/clustering/dbscan/mod.rs | 2 +- vrp-core/src/construction/clustering/vicinity/estimations.rs | 2 +- vrp-core/src/construction/heuristics/metrics.rs | 2 +- vrp-core/src/models/problem/jobs.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rosomaxa/src/algorithms/gsom/network.rs b/rosomaxa/src/algorithms/gsom/network.rs index ad7ffb97e..9ba795b39 100644 --- a/rosomaxa/src/algorithms/gsom/network.rs +++ b/rosomaxa/src/algorithms/gsom/network.rs @@ -122,7 +122,7 @@ where pub fn smooth(&mut self, rebalance_count: usize) { (0..rebalance_count).for_each(|_| { let mut data = self.nodes.iter_mut().flat_map(|(_, node)| node.storage.drain(0..)).collect::>(); - data.sort_by(compare_input); + data.sort_unstable_by(compare_input); data.dedup_by(|a, b| compare_input(a, b) == Ordering::Equal); data.shuffle(&mut self.random.get_rng()); diff --git a/rosomaxa/src/termination/min_variation.rs b/rosomaxa/src/termination/min_variation.rs index 357723454..14f604881 100644 --- a/rosomaxa/src/termination/min_variation.rs +++ b/rosomaxa/src/termination/min_variation.rs @@ -96,7 +96,7 @@ where result }); - values.sort_by(|(a, _), (b, _)| a.cmp(b)); + values.sort_unstable_by(|(a, _), (b, _)| a.cmp(b)); } if *period > elapsed_time || values.len() < 2 { diff --git a/vrp-core/src/construction/clustering/dbscan/mod.rs b/vrp-core/src/construction/clustering/dbscan/mod.rs index 9229b5f4a..7a8da65f8 100644 --- a/vrp-core/src/construction/clustering/dbscan/mod.rs +++ b/vrp-core/src/construction/clustering/dbscan/mod.rs @@ -74,7 +74,7 @@ fn get_average_costs(problem: &Problem, min_points: usize) -> Vec { costs.iter_mut().for_each(|cost| *cost /= problem.fleet.profiles.len() as Float); // sort all distances in ascending order - costs.sort_by(compare_floats_refs); + costs.sort_unstable_by(compare_floats_refs); costs.dedup_by(|a, b| compare_floats(*a, *b) == Ordering::Equal); costs diff --git a/vrp-core/src/construction/clustering/vicinity/estimations.rs b/vrp-core/src/construction/clustering/vicinity/estimations.rs index 4f36f8726..9ec5bb7a0 100644 --- a/vrp-core/src/construction/clustering/vicinity/estimations.rs +++ b/vrp-core/src/construction/clustering/vicinity/estimations.rs @@ -51,7 +51,7 @@ pub(crate) fn get_clusters( } }); - cluster_estimates.sort_by(|(a_job, (_, a_can)), (b_job, (_, b_can))| { + cluster_estimates.sort_unstable_by(|(a_job, (_, a_can)), (b_job, (_, b_can))| { (config.building.ordering_global_fn)((b_job, b_can), (a_job, a_can)) }); diff --git a/vrp-core/src/construction/heuristics/metrics.rs b/vrp-core/src/construction/heuristics/metrics.rs index 6025669c2..981df54a5 100644 --- a/vrp-core/src/construction/heuristics/metrics.rs +++ b/vrp-core/src/construction/heuristics/metrics.rs @@ -242,7 +242,7 @@ pub fn group_routes_by_proximity(insertion_ctx: &InsertionContext) -> RouteProxi }) .collect::>(); - route_distances.sort_by(|(_, a_distance), (_, b_distance)| match (a_distance, b_distance) { + route_distances.sort_unstable_by(|(_, a_distance), (_, b_distance)| match (a_distance, b_distance) { (Some(a_distance), Some(b_distance)) => compare_floats(*a_distance, *b_distance), (Some(_), None) => Ordering::Less, _ => Ordering::Greater, diff --git a/vrp-core/src/models/problem/jobs.rs b/vrp-core/src/models/problem/jobs.rs index 02d215e14..de0b57555 100644 --- a/vrp-core/src/models/problem/jobs.rs +++ b/vrp-core/src/models/problem/jobs.rs @@ -331,7 +331,7 @@ fn create_index( .filter(|j| **j != *job) .map(|j| (j.clone(), get_cost_between_jobs(profile, avg_costs, transport, job, j))) .collect(); - sorted_job_costs.sort_by(|(_, a), (_, b)| compare_floats_f32_refs(a, b)); + sorted_job_costs.sort_unstable_by(|(_, a), (_, b)| compare_floats_f32_refs(a, b)); sorted_job_costs.truncate(MAX_NEIGHBOURS); sorted_job_costs.shrink_to_fit();