diff --git a/src/autorouter/permutator.rs b/src/autorouter/permutator.rs index d45ece4..fd7bdf8 100644 --- a/src/autorouter/permutator.rs +++ b/src/autorouter/permutator.rs @@ -11,7 +11,7 @@ use crate::{ autoroute::{AutorouteContinueStatus, AutorouteExecutionStepper}, invoker::GetDebugOverlayData, permuter::{PermuteRatlines, RatlinesPermuter}, - presorter::{PresortRatlines, SccIntersectionsAndLengthPresorter}, + presorter::{PresortParams, PresortRatlines, SccIntersectionsAndLengthPresorter}, ratline::RatlineIndex, Autorouter, AutorouterError, AutorouterOptions, }, @@ -34,7 +34,14 @@ impl AutorouteExecutionPermutator { ratlines: Vec, options: AutorouterOptions, ) -> Result { - let presorter = SccIntersectionsAndLengthPresorter::new(autorouter, &ratlines); + let presorter = SccIntersectionsAndLengthPresorter::new( + autorouter, + &ratlines, + &PresortParams { + intersector_count_weight: 1.0, + length_weight: 0.001, + }, + ); let initially_sorted_ratlines = presorter.presort_ratlines(autorouter, &ratlines); /*let permuter = RatlinesPermuter::SccPermutations(SccPermutationsRatlinePermuter::new( autorouter, ratlines, presorter, &options, diff --git a/src/autorouter/presorter.rs b/src/autorouter/presorter.rs index c16a59d..fb0da51 100644 --- a/src/autorouter/presorter.rs +++ b/src/autorouter/presorter.rs @@ -2,8 +2,6 @@ // // SPDX-License-Identifier: MIT -use std::cmp::Ordering; - use derive_getters::{Dissolve, Getters}; use enum_dispatch::enum_dispatch; use petgraph::algo::tarjan_scc; @@ -11,6 +9,11 @@ use specctra_core::mesadata::AccessMesadata; use crate::autorouter::{ratline::RatlineIndex, scc::Scc, Autorouter}; +pub struct PresortParams { + pub intersector_count_weight: f64, + pub length_weight: f64, +} + #[enum_dispatch] pub trait PresortRatlines { fn presort_ratlines( @@ -34,6 +37,7 @@ impl SccIntersectionsAndLengthPresorter { pub fn new( autorouter: &mut Autorouter, ratlines: &[RatlineIndex], + params: &PresortParams, ) -> Self { // FIXME: Unnecessary copy. let mut filtered_ratsnest = autorouter.ratsnest().graph().clone(); @@ -45,19 +49,16 @@ impl SccIntersectionsAndLengthPresorter { .collect(); sccs.sort_unstable_by(|a, b| { - let primary_ordering = a.intersector_count().cmp(&b.intersector_count()); - - if primary_ordering != Ordering::Equal { - primary_ordering - } else { - let secondary_ordering = a.length().total_cmp(&b.length()); - - secondary_ordering - } + Self::scc_score(params, a).total_cmp(&Self::scc_score(params, b)) }); Self { sccs } } + + fn scc_score(params: &PresortParams, scc: &Scc) -> f64 { + params.intersector_count_weight * *scc.intersector_count() as f64 + + params.length_weight * scc.length() + } } impl PresortRatlines for SccIntersectionsAndLengthPresorter { diff --git a/src/autorouter/scc.rs b/src/autorouter/scc.rs index 3219ed2..833e002 100644 --- a/src/autorouter/scc.rs +++ b/src/autorouter/scc.rs @@ -20,8 +20,8 @@ use crate::{ pub struct Scc { node_indices: Vec>, - length: f64, intersector_count: usize, + length: f64, } impl Scc {