diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 15 | ||||
-rw-r--r-- | src/tsp_approx.rs | 9 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index 45621cf..3055768 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,9 +67,14 @@ struct Args { tsp_approx: TspBaseAlg, /// Number of 2-Opt refinement steps. Has quickly diminishing returns - #[arg(short = 'r', default_value = "3")] + #[arg(short = 'r', default_value = "5")] refine: usize, + /// Don't try to improve result by rotating the output path such that less emphasis is put on + /// the similarity of the first and last image + #[arg(long)] + no_rotate: bool, + /// Ignore failed embeddings #[arg(short = 'i', long)] ignore_errors: bool, @@ -174,7 +179,13 @@ where }) .unzip(); - let (tsp_path, total_dist) = tsp(&embeds, &args.tsp_approx, args.refine, &args.hash_seed); + let (tsp_path, total_dist) = tsp( + &embeds, + &args.tsp_approx, + args.refine, + !args.no_rotate, + &args.hash_seed, + ); Ok(( tsp_path.iter().map(|i| images[*i].clone()).collect(), diff --git a/src/tsp_approx.rs b/src/tsp_approx.rs index a23a726..3ce2bd5 100644 --- a/src/tsp_approx.rs +++ b/src/tsp_approx.rs @@ -413,6 +413,7 @@ pub(crate) fn tsp<M>( embeds: &[M], alg: &TspBaseAlg, refinements: usize, + rotate: bool, hash_seed: &Option<u64>, ) -> (Vec<usize>, f64) where @@ -441,7 +442,9 @@ where }; for _ in 0..refinements { - rotate_towards_optimum(&dc, &mut tour); + if rotate { + rotate_towards_optimum(&dc, &mut tour); + } let res = refine_2_opt(&dc, tour); tour = res.1; if !res.0 { @@ -449,7 +452,9 @@ where } } - rotate_towards_optimum(&dc, &mut tour); + if rotate { + rotate_towards_optimum(&dc, &mut tour); + } let mut total_dist = 0.; for i in 0..tour.len() - 1 { |