diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index 32ea0a0..14c0d3e 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -13,7 +13,7 @@ use thiserror::Error; use crate::{ autorouter::{ multilayer_autoroute::{MultilayerAutorouteExecutionStepper, MultilayerAutorouteOptions}, - planar_reconfigurator::PlanarAutorouteExecutionReconfigurator, + planar_reconfigurator::PlanarAutorouteReconfigurator, planner::Planner, ratsnests::Ratsnests, }, @@ -137,8 +137,8 @@ impl Autorouter { &mut self, selection: &PinSelection, options: PlanarAutorouteOptions, - ) -> Result { - PlanarAutorouteExecutionReconfigurator::new( + ) -> Result { + PlanarAutorouteReconfigurator::new( self, self.selected_planar_ratlines(selection, options.principal_layer), options, diff --git a/src/autorouter/execution.rs b/src/autorouter/execution.rs index aa4a133..211e5d6 100644 --- a/src/autorouter/execution.rs +++ b/src/autorouter/execution.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; use crate::{ autorouter::{ multilayer_autoroute::{MultilayerAutorouteExecutionStepper, MultilayerAutorouteOptions}, - planar_reconfigurator::PlanarAutorouteExecutionReconfigurator, + planar_reconfigurator::PlanarAutorouteReconfigurator, }, board::{edit::BoardEdit, AccessMesadata}, layout::via::ViaWeight, @@ -50,7 +50,7 @@ pub enum Command { #[enum_dispatch(GetDebugOverlayData)] pub enum ExecutionStepper { MultilayerAutoroute(MultilayerAutorouteExecutionStepper), - PlanarAutoroute(PlanarAutorouteExecutionReconfigurator), + PlanarAutoroute(PlanarAutorouteReconfigurator), TopoAutoroute(ng::AutorouteExecutionStepper), PlaceVia(PlaceViaExecutionStepper), RemoveBands(RemoveBandsExecutionStepper), diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index e51bd7f..d6d0ba1 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -34,7 +34,7 @@ use super::{ measure_length::MeasureLengthExecutionStepper, multilayer_autoroute::MultilayerAutorouteExecutionStepper, place_via::PlaceViaExecutionStepper, - planar_reconfigurator::PlanarAutorouteExecutionReconfigurator, + planar_reconfigurator::PlanarAutorouteReconfigurator, remove_bands::RemoveBandsExecutionStepper, Autorouter, AutorouterError, }; diff --git a/src/autorouter/multilayer_autoroute.rs b/src/autorouter/multilayer_autoroute.rs index 22641ca..326258b 100644 --- a/src/autorouter/multilayer_autoroute.rs +++ b/src/autorouter/multilayer_autoroute.rs @@ -12,7 +12,7 @@ use crate::{ anterouter::{Anterouter, AnterouterOptions, AnterouterPlan}, invoker::GetDebugOverlayData, planar_autoroute::PlanarAutorouteContinueStatus, - planar_reconfigurator::PlanarAutorouteExecutionReconfigurator, + planar_reconfigurator::{PlanarAutorouteReconfigurator, PlanarReconfiguratorStatus}, ratline::RatlineUid, Autorouter, AutorouterError, PlanarAutorouteOptions, }, @@ -30,8 +30,10 @@ pub struct MultilayerAutorouteOptions { } pub struct MultilayerAutorouteExecutionStepper { - planar: PlanarAutorouteExecutionReconfigurator, + planar: PlanarAutorouteReconfigurator, anteroute_edit: BoardEdit, + // TODO: Obviously, we need something more sophisticated here. + planar_autoroute_reconfiguration_count: u64, } impl MultilayerAutorouteExecutionStepper { @@ -46,18 +48,14 @@ impl MultilayerAutorouteExecutionStepper { assigner.anteroute(autorouter, &mut anteroute_edit, &options.anterouter); Ok(Self { - planar: PlanarAutorouteExecutionReconfigurator::new( - autorouter, - ratlines, - options.planar, - )?, + planar: PlanarAutorouteReconfigurator::new(autorouter, ratlines, options.planar)?, anteroute_edit, + planar_autoroute_reconfiguration_count: 0, }) } } -impl - Step, Option, ReconfiguratorStatus<(), PlanarAutorouteContinueStatus>> +impl Step, Option, PlanarReconfiguratorStatus> for MultilayerAutorouteExecutionStepper { type Error = AutorouterError; @@ -65,16 +63,19 @@ impl fn step( &mut self, autorouter: &mut Autorouter, - ) -> Result< - ControlFlow, ReconfiguratorStatus<(), PlanarAutorouteContinueStatus>>, - AutorouterError, - > { + ) -> Result, PlanarReconfiguratorStatus>, AutorouterError> { match self.planar.step(autorouter) { Ok(ControlFlow::Break(Some(edit))) => { self.anteroute_edit.merge(edit); // FIXME: Unnecessary large clone. Ok(ControlFlow::Break(Some(self.anteroute_edit.clone()))) } + Ok(ControlFlow::Continue(ReconfiguratorStatus::Reconfigured(result))) => { + self.planar_autoroute_reconfiguration_count += 1; + Ok(ControlFlow::Continue(ReconfiguratorStatus::Reconfigured( + result, + ))) + } x => x, } } diff --git a/src/autorouter/planar_autoroute.rs b/src/autorouter/planar_autoroute.rs index f762424..a72be3f 100644 --- a/src/autorouter/planar_autoroute.rs +++ b/src/autorouter/planar_autoroute.rs @@ -29,6 +29,19 @@ use super::{ PlanarAutorouteOptions, }; +pub struct PlanarAutorouteConfiguration { + pub ratlines: Vec, +} + +pub struct PlanarAutorouteCosts { + pub lengths: Vec, +} + +pub struct PlanarAutorouteConfigurationResult { + pub configuration: PlanarAutorouteConfiguration, + pub costs: PlanarAutorouteCosts, +} + /// Represents the current status of the autoroute operation. pub enum PlanarAutorouteContinueStatus { /// The autoroute is currently running and in progress. @@ -237,13 +250,13 @@ impl Abort> for PlanarAutorouteExecutionStepper impl Reconfigure> for PlanarAutorouteExecutionStepper { type Configuration = Vec; - type Output = Result<(), AutorouterError>; + type Output = Result; fn reconfigure( &mut self, autorouter: &mut Autorouter, permutation: Vec, - ) -> Result<(), AutorouterError> { + ) -> Result { let Some(new_index) = permutation .iter() .zip(self.ratlines.iter()) @@ -251,10 +264,18 @@ impl Reconfigure> for PlanarAutorouteExecutionS else { return Err(AutorouterError::NothingToUndoForReconfiguration); }; - self.ratlines = permutation; + + let result = PlanarAutorouteConfigurationResult { + configuration: PlanarAutorouteConfiguration { + ratlines: std::mem::replace(&mut self.ratlines, permutation), + }, + costs: PlanarAutorouteCosts { + lengths: vec![], // TODO. + }, + }; self.backtrace_to_index(autorouter, new_index)?; - Ok(()) + Ok(result) } } diff --git a/src/autorouter/planar_reconfigurator.rs b/src/autorouter/planar_reconfigurator.rs index 111f270..f062972 100644 --- a/src/autorouter/planar_reconfigurator.rs +++ b/src/autorouter/planar_reconfigurator.rs @@ -9,7 +9,10 @@ use specctra_core::mesadata::AccessMesadata; use crate::{ autorouter::{ invoker::GetDebugOverlayData, - planar_autoroute::{PlanarAutorouteContinueStatus, PlanarAutorouteExecutionStepper}, + planar_autoroute::{ + PlanarAutorouteConfigurationResult, PlanarAutorouteContinueStatus, + PlanarAutorouteExecutionStepper, + }, planar_reconfigurer::{PermuteRatlines, PlanarReconfigurer}, presorter::{PresortParams, PresortRatlines, SccIntersectionsAndLengthPresorter}, ratline::RatlineUid, @@ -21,14 +24,16 @@ use crate::{ router::{navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper}, stepper::{Abort, EstimateProgress, ReconfiguratorStatus, Reconfigure, Step}, }; +pub type PlanarReconfiguratorStatus = + ReconfiguratorStatus; -pub struct PlanarAutorouteExecutionReconfigurator { +pub struct PlanarAutorouteReconfigurator { stepper: PlanarAutorouteExecutionStepper, reconfigurer: PlanarReconfigurer, options: PlanarAutorouteOptions, } -impl PlanarAutorouteExecutionReconfigurator { +impl PlanarAutorouteReconfigurator { pub fn new( autorouter: &mut Autorouter, ratlines: Vec, @@ -62,19 +67,15 @@ impl PlanarAutorouteExecutionReconfigurator { } } -impl - Step, Option, ReconfiguratorStatus<(), PlanarAutorouteContinueStatus>> - for PlanarAutorouteExecutionReconfigurator +impl Step, Option, PlanarReconfiguratorStatus> + for PlanarAutorouteReconfigurator { type Error = AutorouterError; fn step( &mut self, autorouter: &mut Autorouter, - ) -> Result< - ControlFlow, ReconfiguratorStatus<(), PlanarAutorouteContinueStatus>>, - AutorouterError, - > { + ) -> Result, PlanarReconfiguratorStatus>, AutorouterError> { match self.stepper.step(autorouter) { Ok(ControlFlow::Break(maybe_edit)) => Ok(ControlFlow::Break(maybe_edit)), Ok(ControlFlow::Continue(status)) => { @@ -94,28 +95,28 @@ impl }; match self.stepper.reconfigure(autorouter, permutation) { - Ok(()) => break, + Ok(result) => { + return Ok(ControlFlow::Continue(ReconfiguratorStatus::Reconfigured( + result, + ))) + } Err(AutorouterError::NothingToUndoForReconfiguration) => continue, Err(err) => return Err(err), } } - - Ok(ControlFlow::Continue( - ReconfiguratorStatus::Reconfigured(()), - )) } } } } -impl Abort> for PlanarAutorouteExecutionReconfigurator { +impl Abort> for PlanarAutorouteReconfigurator { fn abort(&mut self, autorouter: &mut Autorouter) { //self.permutations_iter.all(|_| true); // Why did I add this code here??? self.stepper.abort(autorouter); } } -impl EstimateProgress for PlanarAutorouteExecutionReconfigurator { +impl EstimateProgress for PlanarAutorouteReconfigurator { type Value = f64; fn estimate_progress_value(&self) -> f64 { @@ -129,7 +130,7 @@ impl EstimateProgress for PlanarAutorouteExecutionReconfigurator { } } -impl GetDebugOverlayData for PlanarAutorouteExecutionReconfigurator { +impl GetDebugOverlayData for PlanarAutorouteReconfigurator { fn maybe_thetastar(&self) -> Option<&ThetastarStepper> { self.stepper.maybe_thetastar() }