From 8af08a537ef4fa513b5446eb121129cb9c486eb4 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Thu, 26 Nov 2026 15:25:21 -0800 Subject: [PATCH] Prefer bend-ended windows in default path refinement --- DOCS.md | 4 ++-- docs/topological-routing.md | 2 ++ inire/model.py | 2 +- inire/router/refiner.py | 37 +++++++++++++++++++++---------------- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/DOCS.md b/DOCS.md index ab4c133..35c7b8e 100644 --- a/DOCS.md +++ b/DOCS.md @@ -121,9 +121,9 @@ Use `RoutingProblem.initial_paths` to provide semantic per-net seeds. Seeds are | :-- | :-- | :-- | | `enabled` | `True` | Enable post-route refinement. | | `objective` | `None` | Optional override objective for refinement. `None` reuses the search objective. | -| `max_windows_per_net` | `24` | Maximum candidate windows attempted per net, shared across improvement rounds. Use `1` for a faster pass or `None` to remove the window limit. | +| `max_windows_per_net` | `4` | Maximum candidate windows attempted per net, shared across improvement rounds. Use `1` for a faster pass or `None` to remove the window limit. | -The refiner scores candidate moves from their ports and lengths before building polygons. When the incumbent is valid in the current collision world, it verifies the replacement window against obstacles, other nets, and the unchanged parts of its own path. The router verifies the final layout in full. +With a finite limit greater than one, the refiner tries windows with a bend at each end first, then those with one bend at an end, and finally the rest. Within each group it tries the longest windows first. A limit of one and unlimited refinement use longest-first ordering across all windows. The refiner scores candidate moves from their ports and lengths before building polygons. When the incumbent is valid in the current collision world, it verifies the replacement window against obstacles, other nets, and the unchanged parts of its own path. The router verifies the final layout in full. ## Topological Routing diff --git a/docs/topological-routing.md b/docs/topological-routing.md index 99ff81c..c198567 100644 --- a/docs/topological-routing.md +++ b/docs/topological-routing.md @@ -323,6 +323,8 @@ With public defaults, the earlier runs on the alternating doglegs, width-key pas Before the new fallbacks, the proposed four-window refinement order and guarded 500-node first pass matched the original stress baseline at the matched budget. On the seeded return-shelf diagnostic, bend-first ordering found the same cost improvement on its first window that the prior order found on its second, with different geometry. +Four bend-first windows are now the default. A full comparison against the 24-window longest-first baseline matched verified IDs, bounds, and both per-net costs on all 67 boards in both profiles. Fixed-heading Terminal-Bench used different geometry at the same scores. Single-window and unlimited refinement keep longest-first ordering. + ### External and fallback benchmarks `--case external` runs six fixed-placement problems from two public sources. The fixtures preserve net IDs and device locations, with optical ports snapped to a 0.1 µm lattice and expressed relative to the imported board. Device boxes become obstacles with outward access cutouts at the selected ports. The timed runs start from empty initial paths. The converted inputs are checked into the repo so benchmark runs work offline. [Fixture data](../inire/tests/data/external_routing_benchmarks.json) diff --git a/inire/model.py b/inire/model.py index 24fbc69..9310ad6 100644 --- a/inire/model.py +++ b/inire/model.py @@ -101,7 +101,7 @@ class CongestionOptions: class RefinementOptions: enabled: bool = True objective: ObjectiveWeights | None = None - max_windows_per_net: int | None = 24 + max_windows_per_net: int | None = 4 def __post_init__(self) -> None: limit = self.max_windows_per_net diff --git a/inire/router/refiner.py b/inire/router/refiner.py index baf3f94..3ddd698 100644 --- a/inire/router/refiner.py +++ b/inire/router/refiner.py @@ -2,7 +2,7 @@ from __future__ import annotations import math from dataclasses import dataclass -from itertools import chain +from itertools import accumulate, chain from typing import TYPE_CHECKING, Any from inire.geometry.component_overlap import components_overlap @@ -264,22 +264,27 @@ class PathRefiner: def _iter_refinement_windows(self, start: Port, path: Sequence[ComponentResult]) -> Iterator[tuple[int, int]]: ports = self._path_ports(start, path) min_radius = min(self.context.options.search.bend_radii, default=0.0) + bends = [component.move_type == "bend90" for component in path] + bend_counts = tuple(accumulate(bends, initial=0)) + limit = self.context.options.refinement.max_windows_per_net + # Keep the original order for a single attempt and for unlimited refinement. + edge_counts = (2, 1, 0) if limit is not None and limit > 1 else (None,) - for window_size in range(len(path), 0, -1): - for start_idx in range(len(path) - window_size + 1): - end_idx = start_idx + window_size - window = path[start_idx:end_idx] - bend_count = sum(1 for comp in window if comp.move_type == "bend90") - if bend_count < 4: - continue - window_start = ports[start_idx] - window_end = ports[end_idx] - if window_start.r != window_end.r: - continue - local_dx, _ = self._to_local(window_start, window_end) - if local_dx < 4.0 * min_radius - 0.01: - continue - yield start_idx, end_idx + for edge_count in edge_counts: + for window_size in range(len(path), 3, -1): + for start_idx in range(len(path) - window_size + 1): + end_idx = start_idx + window_size + if bend_counts[end_idx] - bend_counts[start_idx] < 4: + continue + if edge_count is not None and bends[start_idx] + bends[end_idx - 1] != edge_count: + continue + window_start = ports[start_idx] + window_end = ports[end_idx] + if window_start.r != window_end.r: + continue + local_dx, _ = self._to_local(window_start, window_end) + if local_dx >= 4.0 * min_radius - 0.01: + yield start_idx, end_idx def _try_refine_window( self,