From c9d99c2c1f76c03187af2f0cb76e3a67eb6a54c5 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Tue, 6 Aug 2024 15:43:25 +0200 Subject: [PATCH] autorouter: sort by pairwise total detour lengths before autorouting --- src/autorouter/autorouter.rs | 19 ++++++++++++------- src/autorouter/invoker.rs | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index a9c72d6..28cfab3 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -88,20 +88,25 @@ impl Autorouter { todo!(); } - pub fn compare(&mut self, selection: &PinSelection) -> Result { - self.compare_ratlines(self.selected_ratlines(selection)) - } - - fn compare_ratlines( + pub fn compare_detours( &mut self, - ratlines: Vec>, + selection: &PinSelection, ) -> Result { + let ratlines = self.selected_ratlines(selection); let ratline1 = *ratlines .get(0) .ok_or(AutorouterError::NeedExactlyTwoRatlines)?; let ratline2 = *ratlines .get(1) .ok_or(AutorouterError::NeedExactlyTwoRatlines)?; + self.compare_detours_ratlines(ratline1, ratline2) + } + + pub(super) fn compare_detours_ratlines( + &mut self, + ratline1: EdgeIndex, + ratline2: EdgeIndex, + ) -> Result { CompareDetours::new(self, ratline1, ratline2) } @@ -136,7 +141,7 @@ impl Autorouter { (source_dot, target_dot) } - fn selected_ratlines(&self, selection: &PinSelection) -> Vec> { + pub(super) fn selected_ratlines(&self, selection: &PinSelection) -> Vec> { self.ratsnest .graph() .edge_indices() diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index fe79172..e472226 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -240,9 +240,18 @@ impl Invoker { #[debug_requires(self.ongoing_command.is_none())] fn dispatch_command(&mut self, command: &Command) -> Result { match command { - Command::Autoroute(selection) => Ok::(Execute::Autoroute( - self.autorouter.autoroute(selection)?, - )), + Command::Autoroute(selection) => { + let mut ratlines = self.autorouter.selected_ratlines(selection); + ratlines.sort_unstable_by(|a, b| { + let mut compare_detours = + self.autorouter.compare_detours_ratlines(*a, *b).unwrap(); + let (al, bl) = compare_detours.finish(&mut self.autorouter).unwrap(); + PartialOrd::partial_cmp(&al, &bl).unwrap() + }); + Ok::(Execute::Autoroute( + self.autorouter.autoroute_ratlines(ratlines)?, + )) + } Command::PlaceVia(weight) => { Ok::(Execute::PlaceVia(self.autorouter.place_via(*weight)?)) } @@ -250,7 +259,7 @@ impl Invoker { self.autorouter.remove_bands(selection)?, )), Command::CompareDetours(selection) => Ok::( - Execute::CompareDetours(self.autorouter.compare(selection)?), + Execute::CompareDetours(self.autorouter.compare_detours(selection)?), ), } }