From ae445f481e9ae96b41d15ff22592f40ef5432302 Mon Sep 17 00:00:00 2001 From: Lia Lenckowski Date: Wed, 20 Sep 2023 12:59:18 +0200 Subject: algorithm selection, big perfect matching performance improvement --- src/main.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index b9df0a9..9a3078a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,13 @@ enum Embedder { Content, } +#[derive(Debug, Clone, Copy, clap::ValueEnum)] +enum TspAlg { + MstDfs, + Christofides, + ChristofidesRefined, +} + #[derive(Debug, Parser)] struct Args { /// Characteristic to sort by @@ -52,6 +59,10 @@ struct Args { #[arg(short = 'b', long)] benchmark: bool, + /// Algorithm for TSP approximation. Leave as default if unsure. + #[arg(long, default_value = "christofides")] + tsp_approx: TspAlg, + images: Vec, } @@ -109,12 +120,16 @@ where .collect(); // TODO only run e.embeds if !missing_embeds_indices.is_empty(); this allows // for optimizations in the ai embedde (move pip to ::embeds() instead of ::new()) - let missing_embeds = e.embeds( - &missing_embeds_indices - .iter() - .map(|i| args.images[*i].clone()) - .collect::>(), - )?; + let missing_embeds = if missing_embeds_indices.is_empty() { + Vec::new() + } else { + e.embeds( + &missing_embeds_indices + .iter() + .map(|i| args.images[*i].clone()) + .collect::>(), + )? + }; for (idx, emb) in missing_embeds_indices .into_iter() @@ -125,7 +140,7 @@ where } let embeds: Vec<_> = embeds.into_iter().map(|e| e.unwrap()).collect(); - let (tsp_path, total_dist) = tsp(&embeds); + let (tsp_path, total_dist) = tsp(&embeds, &args.tsp_approx); Ok(( tsp_path.iter().map(|i| args.images[*i].clone()).collect(), -- cgit v1.2.3-70-g09d2