From 467674743fb638ea56713aecc719a80505b82a17 Mon Sep 17 00:00:00 2001 From: Lia Lenckowski Date: Wed, 27 Nov 2024 22:26:38 +0100 Subject: fix: 2-opt no longer crashes in debug builds due to an underflow --- Cargo.lock | 2 +- src/tsp_approx.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 827a9aa..23f8ba3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -516,7 +516,7 @@ checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "embeddings-sort" -version = "0.3.0" +version = "0.3.1" dependencies = [ "ahash", "anyhow", diff --git a/src/tsp_approx.rs b/src/tsp_approx.rs index 2c6cbf9..e3448a1 100644 --- a/src/tsp_approx.rs +++ b/src/tsp_approx.rs @@ -292,7 +292,7 @@ fn refine_2_opt(dist_cache: &DistCache, tour: Vec) -> (bool, Vec) let mut tour: Vec<_> = tour .into_iter() .enumerate() - .map(|(i, v)| (i - 1, v, i + 1)) + .map(|(i, v)| (i.wrapping_sub(1), v, i + 1)) .collect(); let n = tour.len(); // fix boundary -- cgit v1.2.3-70-g09d2