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 --- src/tsp_approx.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') 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