Verify route continuity and simplify automatic search setup

This commit is contained in:
Jan Petykiewicz 2026-11-27 15:21:37 -08:00
commit def1e4ea1d

View file

@ -11,6 +11,7 @@ from typing import TYPE_CHECKING
from shapely.geometry import box
from inire.geometry.primitives import Port
from inire.geometry.components import bend_fits_width
from inire.geometry.sbend import exact_sbend_spans
from inire.model import resolve_bend_geometry
from inire.router._waypoints import XY, compile_waypoints
@ -110,16 +111,13 @@ def ordered_bundle_terminal_headings(problem: RoutingProblem) -> RoutingProblem:
return replace(problem, nets=nets)
def _exact_offsets(radius: int) -> tuple[int, ...]:
return tuple(exact_sbend_spans(radius))
def _assign_shifts(
layout: _Layout,
radius: int,
margin: float,
pitch: int,
floor_lane: int,
search: SearchOptions,
) -> tuple[dict[str, list[_Shift]], int]:
short, lower, upper = layout.short, layout.lower, layout.upper
middle, *ascending, shelf = upper
@ -159,9 +157,11 @@ def _assign_shifts(
# final shelf that can reach its destination with an exact lattice S-bend.
first_top = ceil(last_upper[3] + margin + 0.1)
top_lanes = [first_top + i * pitch for i in range(len(ascending))]
offsets = _exact_offsets(radius)
offsets = tuple(exact_sbend_spans(radius))
shelf_options = [
int(shelf.target.y) + offset for offset in offsets if top_lanes[-1] + pitch <= shelf.target.y + offset <= shelf_launch - 2 * radius
int(shelf.target.y) + offset
for offset in offsets
if search.allows_sbend_offset(-offset) and top_lanes[-1] + pitch <= shelf.target.y + offset <= shelf_launch - 2 * radius
]
if not shelf_options:
raise ValueError("The north shelf has no exact S-bend to the outer eastbound target")
@ -176,7 +176,7 @@ def _assign_shifts(
middle_rise = side_rise + (len(ascending) - 1) * stagger
middle_floor = tower_lanes[-1] + pitch if tower_lanes else tower_floor
if middle_y < middle_floor:
shift = next((d for d in offsets if middle_y + d >= middle_floor), None)
shift = next((d for d in offsets if search.allows_sbend_offset(d) and middle_y + d >= middle_floor), None)
if shift is None:
raise ValueError("The middle track cannot rise above the tower with a lattice S-bend")
shifts[middle.net_id].append(_Shift(middle_rise, middle_y + shift, sbend=True))
@ -222,8 +222,8 @@ def plan_ordered_bundle(problem: RoutingProblem, search: SearchOptions, *, infer
raise ValueError("Bundle routing needs a common integer radius for circular bends and S-bends")
radius = int(bend)
width = problem.nets[0].width
if not isfinite(width) or width <= 0:
raise ValueError("Bundle routing requires a positive waveguide width")
if not bend_fits_width(radius, width):
raise ValueError("Bundle bend radius must be at least half the net width")
margin = width / 2 + problem.clearance
pitch = ceil(width + problem.clearance) + 1
floor_lane = ceil(problem.bounds[1] + width / 2)
@ -232,7 +232,7 @@ def plan_ordered_bundle(problem: RoutingProblem, search: SearchOptions, *, infer
# destination and of the first barrier, so the bundle launches east.
problem = _eastbound_launches(problem)
layout = _identify_layout(problem, margin)
shifts, launch = _assign_shifts(layout, radius, margin, pitch, floor_lane)
shifts, launch = _assign_shifts(layout, radius, margin, pitch, floor_lane, search)
seeds = {}
updated_nets = []