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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -54,11 +54,11 @@ pub trait Abort<Ctx> {
}
/// Some steppers may be permuted from their initial order.
pub trait Permutate<Ctx> {
pub trait Reconfigure<Ctx> {
type Index;
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