Use snapped S-bend spans in local planning

This commit is contained in:
Jan Petykiewicz 2026-11-30 09:25:08 -08:00
commit b541632dde
2 changed files with 28 additions and 8 deletions

View file

@ -3,7 +3,7 @@
from __future__ import annotations
from itertools import islice
from math import isfinite, sqrt
from math import isfinite
from typing import TYPE_CHECKING
from shapely import union_all
@ -12,7 +12,7 @@ from shapely.geometry import box
from inire.constants import TOLERANCE_LINEAR
from inire.geometry.collision import RoutingWorld
from inire.geometry.primitives import port_local_coordinates
from inire.geometry.sbend import exact_sbend_spans
from inire.geometry.sbend import exact_sbend_spans, sbend_grid_span
from inire.model import resolve_bend_geometry
from inire.results import RoutingResult
from inire.router._seed_materialization import materialize_path_seed
@ -178,13 +178,12 @@ def _shift_seeds(forward: int, offset: int, search: SearchOptions) -> Iterator[P
for radius in search.sbend_radii:
if not isfinite(radius) or not 0 < abs(offset) < 2 * radius:
continue
# The physical arc must meet the snapped straight at the join.
exact = sqrt(abs(offset) * (4 * radius - abs(offset)))
if not isfinite(exact):
try:
span = sbend_grid_span(offset, radius)
except (ValueError, OverflowError):
continue
span = round(exact)
spare = forward - span
if spare < 0 or abs(exact - span) > 1e-9:
if spare < 0:
continue
placements = {i * spare // 8 for i in range(9)}
for lead in sorted(placements, key=lambda distance: (abs(2 * distance - spare), distance)):
@ -194,7 +193,7 @@ def _shift_seeds(forward: int, offset: int, search: SearchOptions) -> Iterator[P
def short_shift_seed_set(problem: RoutingProblem, search: SearchOptions, score: Scorer) -> dict[str, PathSeed] | None:
"""Fit exact-span links between fixed ports across both axes of a layout."""
"""Fit links between fixed ports across both axes of a layout."""
if problem.initial_paths or len(problem.nets) < 3 or len({net.start.r % 180 for net in problem.nets}) < 2:
return None
if any(net.start.r != net.target.r for net in problem.nets):

View file

@ -0,0 +1,21 @@
from inire import CongestionOptions, NetSpec, Port, RefinementOptions, RoutingOptions, RoutingProblem, SBendSeed, SearchOptions, route
def test_local_sbend_planner_uses_the_snapped_span() -> None:
east = NetSpec("east", Port(10, 10, 0), Port(24, 15, 0))
north = NetSpec("north", Port(70, 10, 90), Port(65, 24, 90))
line = NetSpec("line", Port(10, 40, 0), Port(40, 40, 0))
problem = RoutingProblem((0, 0, 100, 100), (east, north, line), clearance=0)
options = RoutingOptions(
search=SearchOptions(node_limit=1, bend_radii=(), sbend_radii=(10,)),
congestion=CongestionOptions(max_iterations=1, warm_start_enabled=False),
refinement=RefinementOptions(enabled=False),
)
run = route(problem, options=options)
assert all(result.is_valid for result in run.results_by_net.values())
assert run.automatic.selected_planner == "local-sbend"
assert run.metrics.nodes_expanded == 0
for net in (east, north):
assert run.results_by_net[net.net_id].as_seed().segments == (SBendSeed(5, 10),)