feat(autorouter/presorter): Make presorter parametrizable

This commit is contained in:
Mikolaj Wielgus 2025-09-25 17:27:25 +02:00
parent c120a43d04
commit 6930f2fb1d
3 changed files with 22 additions and 14 deletions

View File

@ -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<RatlineIndex>,
options: AutorouterOptions,
) -> Result<Self, AutorouterError> {
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,

View File

@ -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<impl AccessMesadata>,
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 {

View File

@ -20,8 +20,8 @@ use crate::{
pub struct Scc {
node_indices: Vec<NodeIndex<usize>>,
length: f64,
intersector_count: usize,
length: f64,
}
impl Scc {