refactor(autorouter/autorouter): Rename permut{e,er,ate,ator} to reconfigur{e,er,ate,ator}

Since, in more general cases, we don't only reorder, but also change
values of some parameters.
This commit is contained in:
Mikolaj Wielgus 2025-10-18 15:58:31 +02:00
parent 212a63aa57
commit f96728fbe0
9 changed files with 50 additions and 45 deletions

View File

@ -13,7 +13,7 @@ use thiserror::Error;
use crate::{ use crate::{
autorouter::{ autorouter::{
multilayer_autoroute::{MultilayerAutorouteExecutionStepper, MultilayerAutorouteOptions}, multilayer_autoroute::{MultilayerAutorouteExecutionStepper, MultilayerAutorouteOptions},
planar_permutator::PlanarAutorouteExecutionPermutator, planar_reconfigurator::PlanarAutorouteExecutionReconfigurator,
planner::Planner, planner::Planner,
ratsnests::Ratsnests, ratsnests::Ratsnests,
}, },
@ -69,7 +69,7 @@ pub enum AutorouterError {
#[error("need exactly two ratlines")] #[error("need exactly two ratlines")]
NeedExactlyTwoRatlines, NeedExactlyTwoRatlines,
#[error("nothing to undo for permutation")] #[error("nothing to undo for permutation")]
NothingToUndoForPermutation, NothingToUndoForReconfiguration,
} }
#[derive(Getters)] #[derive(Getters)]
@ -137,8 +137,8 @@ impl<M: AccessMesadata> Autorouter<M> {
&mut self, &mut self,
selection: &PinSelection, selection: &PinSelection,
options: PlanarAutorouteOptions, options: PlanarAutorouteOptions,
) -> Result<PlanarAutorouteExecutionPermutator, AutorouterError> { ) -> Result<PlanarAutorouteExecutionReconfigurator, AutorouterError> {
PlanarAutorouteExecutionPermutator::new( PlanarAutorouteExecutionReconfigurator::new(
self, self,
self.selected_planar_ratlines(selection, options.principal_layer), self.selected_planar_ratlines(selection, options.principal_layer),
options, options,

View File

@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
use crate::{ use crate::{
autorouter::{ autorouter::{
multilayer_autoroute::{MultilayerAutorouteExecutionStepper, MultilayerAutorouteOptions}, multilayer_autoroute::{MultilayerAutorouteExecutionStepper, MultilayerAutorouteOptions},
planar_permutator::PlanarAutorouteExecutionPermutator, planar_reconfigurator::PlanarAutorouteExecutionReconfigurator,
}, },
board::{edit::BoardEdit, AccessMesadata}, board::{edit::BoardEdit, AccessMesadata},
layout::via::ViaWeight, layout::via::ViaWeight,
@ -50,7 +50,7 @@ pub enum Command {
#[enum_dispatch(GetDebugOverlayData)] #[enum_dispatch(GetDebugOverlayData)]
pub enum ExecutionStepper<M> { pub enum ExecutionStepper<M> {
MultilayerAutoroute(MultilayerAutorouteExecutionStepper), MultilayerAutoroute(MultilayerAutorouteExecutionStepper),
PlanarAutoroute(PlanarAutorouteExecutionPermutator), PlanarAutoroute(PlanarAutorouteExecutionReconfigurator),
TopoAutoroute(ng::AutorouteExecutionStepper<M>), TopoAutoroute(ng::AutorouteExecutionStepper<M>),
PlaceVia(PlaceViaExecutionStepper), PlaceVia(PlaceViaExecutionStepper),
RemoveBands(RemoveBandsExecutionStepper), RemoveBands(RemoveBandsExecutionStepper),

View File

@ -34,7 +34,7 @@ use super::{
measure_length::MeasureLengthExecutionStepper, measure_length::MeasureLengthExecutionStepper,
multilayer_autoroute::MultilayerAutorouteExecutionStepper, multilayer_autoroute::MultilayerAutorouteExecutionStepper,
place_via::PlaceViaExecutionStepper, place_via::PlaceViaExecutionStepper,
planar_permutator::PlanarAutorouteExecutionPermutator, planar_reconfigurator::PlanarAutorouteExecutionReconfigurator,
remove_bands::RemoveBandsExecutionStepper, remove_bands::RemoveBandsExecutionStepper,
Autorouter, AutorouterError, Autorouter, AutorouterError,
}; };

View File

@ -14,8 +14,8 @@ pub mod measure_length;
pub mod multilayer_autoroute; pub mod multilayer_autoroute;
pub mod place_via; pub mod place_via;
pub mod planar_autoroute; pub mod planar_autoroute;
pub mod planar_permutator; pub mod planar_reconfigurator;
pub mod planar_permuter; pub mod planar_reconfigurer;
pub mod planner; pub mod planner;
pub mod pointroute; pub mod pointroute;
pub mod presorter; pub mod presorter;

View File

@ -12,7 +12,7 @@ use crate::{
anterouter::{Anterouter, AnterouterOptions, AnterouterPlan}, anterouter::{Anterouter, AnterouterOptions, AnterouterPlan},
invoker::GetDebugOverlayData, invoker::GetDebugOverlayData,
planar_autoroute::PlanarAutorouteContinueStatus, planar_autoroute::PlanarAutorouteContinueStatus,
planar_permutator::PlanarAutorouteExecutionPermutator, planar_reconfigurator::PlanarAutorouteExecutionReconfigurator,
ratline::RatlineUid, ratline::RatlineUid,
Autorouter, AutorouterError, PlanarAutorouteOptions, Autorouter, AutorouterError, PlanarAutorouteOptions,
}, },
@ -30,7 +30,7 @@ pub struct MultilayerAutorouteOptions {
} }
pub struct MultilayerAutorouteExecutionStepper { pub struct MultilayerAutorouteExecutionStepper {
planar: PlanarAutorouteExecutionPermutator, planar: PlanarAutorouteExecutionReconfigurator,
anteroute_edit: BoardEdit, anteroute_edit: BoardEdit,
} }
@ -46,7 +46,11 @@ impl MultilayerAutorouteExecutionStepper {
assigner.anteroute(autorouter, &mut anteroute_edit, &options.anterouter); assigner.anteroute(autorouter, &mut anteroute_edit, &options.anterouter);
Ok(Self { Ok(Self {
planar: PlanarAutorouteExecutionPermutator::new(autorouter, ratlines, options.planar)?, planar: PlanarAutorouteExecutionReconfigurator::new(
autorouter,
ratlines,
options.planar,
)?,
anteroute_edit, anteroute_edit,
}) })
} }

View File

@ -21,7 +21,7 @@ use crate::{
router::{ router::{
navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper, RouteStepper, Router, navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper, RouteStepper, Router,
}, },
stepper::{Abort, EstimateProgress, Permutate, Step}, stepper::{Abort, EstimateProgress, Reconfigure, Step},
}; };
use super::{ use super::{
@ -95,7 +95,7 @@ impl PlanarAutorouteExecutionStepper {
index: usize, index: usize,
) -> Result<(), AutorouterError> { ) -> Result<(), AutorouterError> {
if index >= self.board_data_edits.len() { if index >= self.board_data_edits.len() {
return Err(AutorouterError::NothingToUndoForPermutation); return Err(AutorouterError::NothingToUndoForReconfiguration);
} }
self.dissolve_route_stepper_and_push_layout_edit(); self.dissolve_route_stepper_and_push_layout_edit();
@ -235,11 +235,11 @@ impl<M: AccessMesadata> Abort<Autorouter<M>> for PlanarAutorouteExecutionStepper
} }
} }
impl<M: AccessMesadata> Permutate<Autorouter<M>> for PlanarAutorouteExecutionStepper { impl<M: AccessMesadata> Reconfigure<Autorouter<M>> for PlanarAutorouteExecutionStepper {
type Index = RatlineUid; type Index = RatlineUid;
type Output = Result<(), AutorouterError>; type Output = Result<(), AutorouterError>;
fn permutate( fn reconfigure(
&mut self, &mut self,
autorouter: &mut Autorouter<M>, autorouter: &mut Autorouter<M>,
permutation: Vec<RatlineUid>, permutation: Vec<RatlineUid>,
@ -249,7 +249,7 @@ impl<M: AccessMesadata> Permutate<Autorouter<M>> for PlanarAutorouteExecutionSte
.zip(self.ratlines.iter()) .zip(self.ratlines.iter())
.position(|(permuted, original)| *permuted != *original) .position(|(permuted, original)| *permuted != *original)
else { else {
return Err(AutorouterError::NothingToUndoForPermutation); return Err(AutorouterError::NothingToUndoForReconfiguration);
}; };
self.ratlines = permutation; self.ratlines = permutation;

View File

@ -10,7 +10,7 @@ use crate::{
autorouter::{ autorouter::{
invoker::GetDebugOverlayData, invoker::GetDebugOverlayData,
planar_autoroute::{PlanarAutorouteContinueStatus, PlanarAutorouteExecutionStepper}, planar_autoroute::{PlanarAutorouteContinueStatus, PlanarAutorouteExecutionStepper},
planar_permuter::{PermuteRatlines, RatlinePermuter}, planar_reconfigurer::{PermuteRatlines, PlanarReconfigurer},
presorter::{PresortParams, PresortRatlines, SccIntersectionsAndLengthPresorter}, presorter::{PresortParams, PresortRatlines, SccIntersectionsAndLengthPresorter},
ratline::RatlineUid, ratline::RatlineUid,
Autorouter, AutorouterError, PlanarAutorouteOptions, Autorouter, AutorouterError, PlanarAutorouteOptions,
@ -19,16 +19,16 @@ use crate::{
drawing::graph::PrimitiveIndex, drawing::graph::PrimitiveIndex,
geometry::primitive::PrimitiveShape, geometry::primitive::PrimitiveShape,
router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper}, router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper},
stepper::{Abort, EstimateProgress, Permutate, Step}, stepper::{Abort, EstimateProgress, Reconfigure, Step},
}; };
pub struct PlanarAutorouteExecutionPermutator { pub struct PlanarAutorouteExecutionReconfigurator {
stepper: PlanarAutorouteExecutionStepper, stepper: PlanarAutorouteExecutionStepper,
permuter: RatlinePermuter, reconfigurer: PlanarReconfigurer,
options: PlanarAutorouteOptions, options: PlanarAutorouteOptions,
} }
impl PlanarAutorouteExecutionPermutator { impl PlanarAutorouteExecutionReconfigurator {
pub fn new( pub fn new(
autorouter: &mut Autorouter<impl AccessMesadata>, autorouter: &mut Autorouter<impl AccessMesadata>,
ratlines: Vec<RatlineUid>, ratlines: Vec<RatlineUid>,
@ -47,7 +47,7 @@ impl PlanarAutorouteExecutionPermutator {
/*let permuter = RatlinesPermuter::SccPermutations(SccPermutationsRatlinePermuter::new( /*let permuter = RatlinesPermuter::SccPermutations(SccPermutationsRatlinePermuter::new(
autorouter, ratlines, presorter, &options, autorouter, ratlines, presorter, &options,
));*/ ));*/
let permuter = RatlinePermuter::new(autorouter, ratlines, presorter, &options); let reconfigurer = PlanarReconfigurer::new(autorouter, ratlines, presorter, &options);
Ok(Self { Ok(Self {
stepper: PlanarAutorouteExecutionStepper::new( stepper: PlanarAutorouteExecutionStepper::new(
@ -56,14 +56,14 @@ impl PlanarAutorouteExecutionPermutator {
options, options,
)?, )?,
// Note: I assume here that the first permutation is the same as the original order. // Note: I assume here that the first permutation is the same as the original order.
permuter, reconfigurer,
options, options,
}) })
} }
} }
impl<M: AccessMesadata> Step<Autorouter<M>, Option<BoardEdit>, PlanarAutorouteContinueStatus> impl<M: AccessMesadata> Step<Autorouter<M>, Option<BoardEdit>, PlanarAutorouteContinueStatus>
for PlanarAutorouteExecutionPermutator for PlanarAutorouteExecutionReconfigurator
{ {
type Error = AutorouterError; type Error = AutorouterError;
@ -80,15 +80,16 @@ impl<M: AccessMesadata> Step<Autorouter<M>, Option<BoardEdit>, PlanarAutorouteCo
} }
loop { loop {
let Some(permutation) = let Some(permutation) = self
self.permuter.permute_ratlines(autorouter, &self.stepper) .reconfigurer
.permute_ratlines(autorouter, &self.stepper)
else { else {
return Ok(ControlFlow::Break(None)); return Ok(ControlFlow::Break(None));
}; };
match self.stepper.permutate(autorouter, permutation) { match self.stepper.reconfigure(autorouter, permutation) {
Ok(()) => break, Ok(()) => break,
Err(AutorouterError::NothingToUndoForPermutation) => continue, Err(AutorouterError::NothingToUndoForReconfiguration) => continue,
Err(err) => return Err(err), Err(err) => return Err(err),
} }
} }
@ -99,14 +100,14 @@ impl<M: AccessMesadata> Step<Autorouter<M>, Option<BoardEdit>, PlanarAutorouteCo
} }
} }
impl<M: AccessMesadata> Abort<Autorouter<M>> for PlanarAutorouteExecutionPermutator { impl<M: AccessMesadata> Abort<Autorouter<M>> for PlanarAutorouteExecutionReconfigurator {
fn abort(&mut self, autorouter: &mut Autorouter<M>) { fn abort(&mut self, autorouter: &mut Autorouter<M>) {
//self.permutations_iter.all(|_| true); // Why did I add this code here??? //self.permutations_iter.all(|_| true); // Why did I add this code here???
self.stepper.abort(autorouter); self.stepper.abort(autorouter);
} }
} }
impl EstimateProgress for PlanarAutorouteExecutionPermutator { impl EstimateProgress for PlanarAutorouteExecutionReconfigurator {
type Value = f64; type Value = f64;
fn estimate_progress_value(&self) -> f64 { fn estimate_progress_value(&self) -> f64 {
@ -120,7 +121,7 @@ impl EstimateProgress for PlanarAutorouteExecutionPermutator {
} }
} }
impl GetDebugOverlayData for PlanarAutorouteExecutionPermutator { impl GetDebugOverlayData for PlanarAutorouteExecutionReconfigurator {
fn maybe_thetastar(&self) -> Option<&ThetastarStepper<Navmesh, f64>> { fn maybe_thetastar(&self) -> Option<&ThetastarStepper<Navmesh, f64>> {
self.stepper.maybe_thetastar() self.stepper.maybe_thetastar()
} }

View File

@ -29,19 +29,19 @@ pub trait PermuteRatlines {
} }
#[enum_dispatch(PermuteRatlines)] #[enum_dispatch(PermuteRatlines)]
pub enum RatlinePermuter { pub enum PlanarReconfigurer {
RatlineCuts(RatlineCutsRatlinePermuter), RatlineCuts(RatlineCutsPlanarReconfigurer),
SccPermutations(SccPermutationsRatlinePermuter), SccPermutations(SccPermutationsPlanarReconfigurer),
} }
impl RatlinePermuter { impl PlanarReconfigurer {
pub fn new( pub fn new(
autorouter: &mut Autorouter<impl AccessMesadata>, autorouter: &mut Autorouter<impl AccessMesadata>,
ratlines: Vec<RatlineUid>, ratlines: Vec<RatlineUid>,
presorter: SccIntersectionsAndLengthPresorter, presorter: SccIntersectionsAndLengthPresorter,
options: &PlanarAutorouteOptions, options: &PlanarAutorouteOptions,
) -> Self { ) -> Self {
RatlinePermuter::SccPermutations(SccPermutationsRatlinePermuter::new( PlanarReconfigurer::SccPermutations(SccPermutationsPlanarReconfigurer::new(
autorouter, ratlines, presorter, options, autorouter, ratlines, presorter, options,
)) ))
/*RatlinesPermuter::RatlineCuts(RatlineCutsRatlinePermuter::new( /*RatlinesPermuter::RatlineCuts(RatlineCutsRatlinePermuter::new(
@ -50,12 +50,12 @@ impl RatlinePermuter {
} }
} }
pub struct SccPermutationsRatlinePermuter { pub struct SccPermutationsPlanarReconfigurer {
sccs_permutations_iter: Skip<Permutations<std::vec::IntoIter<Scc>>>, sccs_permutations_iter: Skip<Permutations<std::vec::IntoIter<Scc>>>,
original_ratlines: Vec<RatlineUid>, original_ratlines: Vec<RatlineUid>,
} }
impl SccPermutationsRatlinePermuter { impl SccPermutationsPlanarReconfigurer {
pub fn new( pub fn new(
_autorouter: &mut Autorouter<impl AccessMesadata>, _autorouter: &mut Autorouter<impl AccessMesadata>,
ratlines: Vec<RatlineUid>, ratlines: Vec<RatlineUid>,
@ -74,7 +74,7 @@ impl SccPermutationsRatlinePermuter {
} }
} }
impl PermuteRatlines for SccPermutationsRatlinePermuter { impl PermuteRatlines for SccPermutationsPlanarReconfigurer {
fn permute_ratlines( fn permute_ratlines(
&mut self, &mut self,
autorouter: &mut Autorouter<impl AccessMesadata>, autorouter: &mut Autorouter<impl AccessMesadata>,
@ -111,11 +111,11 @@ impl PermuteRatlines for SccPermutationsRatlinePermuter {
} }
} }
pub struct RatlineCutsRatlinePermuter { pub struct RatlineCutsPlanarReconfigurer {
//sccs: Vec<Vec<NodeIndex<usize>>>, //sccs: Vec<Vec<NodeIndex<usize>>>,
} }
impl RatlineCutsRatlinePermuter { impl RatlineCutsPlanarReconfigurer {
pub fn new( pub fn new(
_autorouter: &mut Autorouter<impl AccessMesadata>, _autorouter: &mut Autorouter<impl AccessMesadata>,
_ratlines: Vec<RatlineUid>, _ratlines: Vec<RatlineUid>,
@ -129,7 +129,7 @@ impl RatlineCutsRatlinePermuter {
} }
} }
impl PermuteRatlines for RatlineCutsRatlinePermuter { impl PermuteRatlines for RatlineCutsPlanarReconfigurer {
fn permute_ratlines( fn permute_ratlines(
&mut self, &mut self,
autorouter: &mut Autorouter<impl AccessMesadata>, autorouter: &mut Autorouter<impl AccessMesadata>,

View File

@ -54,11 +54,11 @@ pub trait Abort<Ctx> {
} }
/// Some steppers may be permuted from their initial order. /// Some steppers may be permuted from their initial order.
pub trait Permutate<Ctx> { pub trait Reconfigure<Ctx> {
type Index; type Index;
type Output; type Output;
fn permutate(&mut self, context: &mut Ctx, ordering: Vec<Self::Index>) -> Self::Output; fn reconfigure(&mut self, context: &mut Ctx, ordering: Vec<Self::Index>) -> Self::Output;
} }
/// Steppers that can receive discrete events and act on them implement this /// Steppers that can receive discrete events and act on them implement this