feat(autorouter/multilayer_reconfigurator): Add reconfiguration trigger here too

This commit is contained in:
Mikolaj Wielgus 2025-11-04 15:29:15 +01:00
parent e1774ce6d9
commit 9345d5de8a
3 changed files with 50 additions and 30 deletions

View File

@ -74,24 +74,23 @@ impl MultilayerAutorouteReconfigurator {
preconfiguration,
options,
)?,
reconfiguration_trigger: SmaRateReconfigurationTrigger::new(10, 0.5, 0.1),
reconfiguration_trigger: SmaRateReconfigurationTrigger::new(20, 0.5, 0.1),
reconfigurer,
options,
})
}
fn reconfigure<M: AccessMesadata>(
fn reconfigure(
&mut self,
autorouter: &mut Autorouter<M>,
autorouter: &mut Autorouter<impl AccessMesadata>,
) -> Result<ControlFlow<Option<BoardEdit>, MultilayerReconfiguratorStatus>, AutorouterError>
{
// Reset the reconfiguration trigger.
self.reconfiguration_trigger = SmaRateReconfigurationTrigger::new(10, 0.5, 0.1);
self.reconfiguration_trigger = SmaRateReconfigurationTrigger::new(20, 1.0, 0.1);
loop {
let configuration = match self.reconfigurer.next_configuration(autorouter) {
None => return Ok(ControlFlow::Break(None)),
Some(configuration) => configuration,
let Some(configuration) = self.reconfigurer.next_configuration(autorouter) else {
return Ok(ControlFlow::Break(None));
};
match self.stepper.reconfigure(autorouter, configuration) {
@ -141,7 +140,7 @@ impl<M: AccessMesadata> Step<Autorouter<M>, Option<BoardEdit>, MultilayerReconfi
Err(err) => {
self.reconfigurer
.process_planar_result(autorouter, Err(err.clone()));
Err(err)
self.reconfigure(autorouter)
}
}
}

View File

@ -24,7 +24,10 @@ use crate::{
drawing::graph::PrimitiveIndex,
geometry::primitive::PrimitiveShape,
router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper},
stepper::{Abort, EstimateProgress, LinearScale, ReconfiguratorStatus, Reconfigure, Step},
stepper::{
Abort, EstimateProgress, LinearScale, ReconfiguratorStatus, Reconfigure,
SmaRateReconfigurationTrigger, Step,
},
};
pub type PlanarAutorouteReconfiguratorStatus =
@ -32,6 +35,7 @@ pub type PlanarAutorouteReconfiguratorStatus =
pub struct PlanarAutorouteReconfigurator {
stepper: PlanarAutorouteExecutionStepper,
reconfiguration_trigger: SmaRateReconfigurationTrigger,
reconfigurer: PlanarAutorouteReconfigurer,
options: PlanarAutorouteOptions,
}
@ -61,11 +65,39 @@ impl PlanarAutorouteReconfigurator {
Ok(Self {
stepper: PlanarAutorouteExecutionStepper::new(autorouter, preconfiguration, options)?,
reconfiguration_trigger: SmaRateReconfigurationTrigger::new(5, 0.5, 0.1),
// Note: I assume here that the first permutation is the same as the original order.
reconfigurer,
options,
})
}
fn reconfigure(
&mut self,
autorouter: &mut Autorouter<impl AccessMesadata>,
) -> Result<ControlFlow<Option<BoardEdit>, PlanarAutorouteReconfiguratorStatus>, AutorouterError>
{
self.reconfiguration_trigger = SmaRateReconfigurationTrigger::new(5, 0.5, 0.1);
loop {
let Some(configuration) = self
.reconfigurer
.next_configuration(autorouter, &self.stepper)
else {
return Ok(ControlFlow::Break(None));
};
match self.stepper.reconfigure(autorouter, configuration) {
Ok(result) => {
return Ok(ControlFlow::Continue(ReconfiguratorStatus::Reconfigured(
result,
)))
}
Err(AutorouterError::NothingToUndoForReconfiguration) => continue,
Err(err) => return Err(err),
}
}
}
}
impl<M: AccessMesadata> Step<Autorouter<M>, Option<BoardEdit>, PlanarAutorouteReconfiguratorStatus>
@ -78,6 +110,13 @@ impl<M: AccessMesadata> Step<Autorouter<M>, Option<BoardEdit>, PlanarAutorouteRe
autorouter: &mut Autorouter<M>,
) -> Result<ControlFlow<Option<BoardEdit>, PlanarAutorouteReconfiguratorStatus>, AutorouterError>
{
if !self
.reconfiguration_trigger
.update(*self.estimate_progress().value() as f64)
{
return self.reconfigure(autorouter);
}
match self.stepper.step(autorouter) {
Ok(ControlFlow::Break(maybe_edit)) => Ok(ControlFlow::Break(maybe_edit)),
Ok(ControlFlow::Continue(status)) => {
@ -87,25 +126,7 @@ impl<M: AccessMesadata> Step<Autorouter<M>, Option<BoardEdit>, PlanarAutorouteRe
if !self.options.permutate {
return Err(err);
}
loop {
let Some(configuration) = self
.reconfigurer
.next_configuration(autorouter, &self.stepper)
else {
return Ok(ControlFlow::Break(None));
};
match self.stepper.reconfigure(autorouter, configuration) {
Ok(result) => {
return Ok(ControlFlow::Continue(ReconfiguratorStatus::Reconfigured(
result,
)))
}
Err(AutorouterError::NothingToUndoForReconfiguration) => continue,
Err(err) => return Err(err),
}
}
self.reconfigure(autorouter)
}
}
}

View File

@ -19,7 +19,7 @@ use crate::autorouter::{
pub trait MakeNextPlanarAutorouteConfiguration {
fn next_configuration(
&mut self,
autorouter: &mut Autorouter<impl AccessMesadata>,
autorouter: &Autorouter<impl AccessMesadata>,
stepper: &PlanarAutorouteExecutionStepper,
) -> Option<PlanarAutorouteConfiguration>;
}
@ -78,7 +78,7 @@ impl SccPermutationsPlanarAutorouteReconfigurer {
impl MakeNextPlanarAutorouteConfiguration for SccPermutationsPlanarAutorouteReconfigurer {
fn next_configuration(
&mut self,
autorouter: &mut Autorouter<impl AccessMesadata>,
autorouter: &Autorouter<impl AccessMesadata>,
_stepper: &PlanarAutorouteExecutionStepper,
) -> Option<PlanarAutorouteConfiguration> {
let scc_permutation = self.sccs_permutations_iter.next()?;