Skip refinement setup for paths with too few bends

This commit is contained in:
Jan Petykiewicz 2026-11-27 00:45:28 -08:00
commit a4c76f3a68
3 changed files with 30 additions and 10 deletions

View file

@ -1068,7 +1068,7 @@ class PathFinder:
for net_id in state.ordered_net_ids:
result = state.results.get(net_id)
if not result or not result.path or result.outcome in {"colliding", "partial", "unroutable"}:
if not result or not result.is_valid or not self.refiner.has_refinement_bends(result.path):
continue
net = state.net_specs[net_id]
self.metrics.total_refine_path_calls += 1

View file

@ -313,6 +313,10 @@ class PathRefiner:
return None
return best_path, best_candidate_cost
@staticmethod
def has_refinement_bends(path: Sequence[ComponentResult]) -> bool:
return len(path) >= 4 and sum(component.move_type == "bend90" for component in path) >= 4
def refine_path(
self,
net_id: str,
@ -320,16 +324,10 @@ class PathRefiner:
net_width: float,
path: Sequence[ComponentResult],
) -> list[ComponentResult]:
if not path:
if not self.has_refinement_bends(path):
return list(path)
path = list(path)
bend_count = sum(1 for comp in path if comp.move_type == "bend90")
if bend_count < 4:
return path
best_path = path
best_path = list(path)
best_cost = self.score_path(start, path)
remaining = self.context.options.refinement.max_windows_per_net
incumbent_valid = None

View file

@ -1,4 +1,6 @@
from inire import RoutingOptions, RoutingProblem, SearchOptions
import pytest
from inire import CongestionOptions, RoutingOptions, RoutingProblem, SearchOptions, TopologyOptions, route
from inire.geometry.collision import RoutingWorld
from inire.geometry.components import Bend90
from inire.geometry.primitives import Port
@ -47,6 +49,26 @@ def test_arc_resolution_sagitta() -> None:
assert pts_fine > pts_coarse
@pytest.mark.parametrize(("offset", "move_type"), [(0, "straight"), (5, "sbend")])
def test_refinement_leaves_simple_paths_installed(offset: int, move_type: str) -> None:
problem = RoutingProblem(
bounds=(0, 0, 120, 120),
nets=(NetSpec("out", Port(10, 50, 0), Port(110, 50 + offset, 0)),),
)
options = RoutingOptions(
search=SearchOptions(bend_radii=(10.0,), sbend_radii=(10.0,)),
congestion=CongestionOptions(warm_start_enabled=False),
topology=TopologyOptions(mode="off"),
)
run = route(problem, options=options)
assert run.results_by_net["out"].is_valid
assert run.results_by_net["out"].path[-1].move_type == move_type
assert run.metrics.refine_path_calls == 0
assert run.metrics.dynamic_path_objects_removed == 0
def test_locked_routes() -> None:
engine = RoutingWorld(clearance=2.0)
danger_map = DangerMap(bounds=(0, -50, 100, 50))