mirror of https://codeberg.org/topola/topola.git
feat(autorouter/presorter): Make presorter parametrizable
This commit is contained in:
parent
c120a43d04
commit
6930f2fb1d
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
autoroute::{AutorouteContinueStatus, AutorouteExecutionStepper},
|
autoroute::{AutorouteContinueStatus, AutorouteExecutionStepper},
|
||||||
invoker::GetDebugOverlayData,
|
invoker::GetDebugOverlayData,
|
||||||
permuter::{PermuteRatlines, RatlinesPermuter},
|
permuter::{PermuteRatlines, RatlinesPermuter},
|
||||||
presorter::{PresortRatlines, SccIntersectionsAndLengthPresorter},
|
presorter::{PresortParams, PresortRatlines, SccIntersectionsAndLengthPresorter},
|
||||||
ratline::RatlineIndex,
|
ratline::RatlineIndex,
|
||||||
Autorouter, AutorouterError, AutorouterOptions,
|
Autorouter, AutorouterError, AutorouterOptions,
|
||||||
},
|
},
|
||||||
|
|
@ -34,7 +34,14 @@ impl AutorouteExecutionPermutator {
|
||||||
ratlines: Vec<RatlineIndex>,
|
ratlines: Vec<RatlineIndex>,
|
||||||
options: AutorouterOptions,
|
options: AutorouterOptions,
|
||||||
) -> Result<Self, AutorouterError> {
|
) -> 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 initially_sorted_ratlines = presorter.presort_ratlines(autorouter, &ratlines);
|
||||||
/*let permuter = RatlinesPermuter::SccPermutations(SccPermutationsRatlinePermuter::new(
|
/*let permuter = RatlinesPermuter::SccPermutations(SccPermutationsRatlinePermuter::new(
|
||||||
autorouter, ratlines, presorter, &options,
|
autorouter, ratlines, presorter, &options,
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
use std::cmp::Ordering;
|
|
||||||
|
|
||||||
use derive_getters::{Dissolve, Getters};
|
use derive_getters::{Dissolve, Getters};
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
use petgraph::algo::tarjan_scc;
|
use petgraph::algo::tarjan_scc;
|
||||||
|
|
@ -11,6 +9,11 @@ use specctra_core::mesadata::AccessMesadata;
|
||||||
|
|
||||||
use crate::autorouter::{ratline::RatlineIndex, scc::Scc, Autorouter};
|
use crate::autorouter::{ratline::RatlineIndex, scc::Scc, Autorouter};
|
||||||
|
|
||||||
|
pub struct PresortParams {
|
||||||
|
pub intersector_count_weight: f64,
|
||||||
|
pub length_weight: f64,
|
||||||
|
}
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
pub trait PresortRatlines {
|
pub trait PresortRatlines {
|
||||||
fn presort_ratlines(
|
fn presort_ratlines(
|
||||||
|
|
@ -34,6 +37,7 @@ impl SccIntersectionsAndLengthPresorter {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
autorouter: &mut Autorouter<impl AccessMesadata>,
|
autorouter: &mut Autorouter<impl AccessMesadata>,
|
||||||
ratlines: &[RatlineIndex],
|
ratlines: &[RatlineIndex],
|
||||||
|
params: &PresortParams,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// FIXME: Unnecessary copy.
|
// FIXME: Unnecessary copy.
|
||||||
let mut filtered_ratsnest = autorouter.ratsnest().graph().clone();
|
let mut filtered_ratsnest = autorouter.ratsnest().graph().clone();
|
||||||
|
|
@ -45,19 +49,16 @@ impl SccIntersectionsAndLengthPresorter {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
sccs.sort_unstable_by(|a, b| {
|
sccs.sort_unstable_by(|a, b| {
|
||||||
let primary_ordering = a.intersector_count().cmp(&b.intersector_count());
|
Self::scc_score(params, a).total_cmp(&Self::scc_score(params, b))
|
||||||
|
|
||||||
if primary_ordering != Ordering::Equal {
|
|
||||||
primary_ordering
|
|
||||||
} else {
|
|
||||||
let secondary_ordering = a.length().total_cmp(&b.length());
|
|
||||||
|
|
||||||
secondary_ordering
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Self { sccs }
|
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 {
|
impl PresortRatlines for SccIntersectionsAndLengthPresorter {
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ use crate::{
|
||||||
pub struct Scc {
|
pub struct Scc {
|
||||||
node_indices: Vec<NodeIndex<usize>>,
|
node_indices: Vec<NodeIndex<usize>>,
|
||||||
|
|
||||||
length: f64,
|
|
||||||
intersector_count: usize,
|
intersector_count: usize,
|
||||||
|
length: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scc {
|
impl Scc {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue