Keep tracks straight when a column jog radius cannot fit them

This commit is contained in:
Jan Petykiewicz 2026-11-30 13:07:21 -08:00
commit b6480ded62
2 changed files with 60 additions and 5 deletions

View file

@ -12,7 +12,7 @@ from typing import TYPE_CHECKING
from shapely.geometry import LineString from shapely.geometry import LineString
from inire.geometry.components import bend_fits_width from inire.geometry.components import bend90_uses_circular_geometry, bend_fits_width
from inire.geometry.intervals import Gap, open_intervals from inire.geometry.intervals import Gap, open_intervals
from inire.geometry.sbend import ExactSBendScanLimitError, exact_sbend_spans from inire.geometry.sbend import ExactSBendScanLimitError, exact_sbend_spans
from inire.model import resolve_bend_geometry from inire.model import resolve_bend_geometry
@ -689,12 +689,27 @@ def _column_jog_schedules(
radii: list[int], radii: list[int],
minimum: float, minimum: float,
profiles_for_slack: Callable[[int], list[list[Profile]]], profiles_for_slack: Callable[[int], list[list[Profile]]],
*,
circular: bool,
) -> Iterator[tuple[int, tuple[Profile, ...], tuple[JogPivots, ...]]]: ) -> Iterator[tuple[int, tuple[Profile, ...], tuple[JogPivots, ...]]]:
radius_choices = []
for radius in radii:
# Tracks that cannot bend must stay on their launch rows in every column.
straight_rows = tuple((i, layout.launch[i]) for i, width in enumerate(layout.widths) if circular and not bend_fits_width(radius, width))
if all(layout.arrival[i] == y for i, y in straight_rows):
radius_choices.append((radius, straight_rows))
if not radius_choices:
return
windows = tuple((after, before) for (_, after), (before, _) in pairwise(layout.spans)) windows = tuple((after, before) for (_, after), (before, _) in pairwise(layout.spans))
for slack in (1, 0): for slack in (1, 0):
profiles = profiles_for_slack(slack) profiles = profiles_for_slack(slack)
for radius in radii: for radius, straight_rows in radius_choices:
schedules = _jog_schedules(profiles, windows, layout.widths, problem.clearance, radius, minimum) eligible = profiles
if straight_rows:
eligible = [[row for row in rows if all(row[i] == y for i, y in straight_rows)] for rows in profiles]
if not all(eligible):
continue
schedules = _jog_schedules(eligible, windows, layout.widths, problem.clearance, radius, minimum)
for _, rows, moves in schedules: for _, rows, moves in schedules:
yield radius, rows, moves yield radius, rows, moves
@ -710,6 +725,7 @@ def column_jog_candidates(problem: RoutingProblem, search: SearchOptions, *, lim
layout = _column_layout(problem) layout = _column_layout(problem)
if layout is None: if layout is None:
return return
circular = bend90_uses_circular_geometry(*resolve_bend_geometry(search))
@cache @cache
def profiles_for_slack(slack: int) -> list[list[Profile]]: def profiles_for_slack(slack: int) -> list[list[Profile]]:
widths = layout.widths widths = layout.widths
@ -723,7 +739,7 @@ def column_jog_candidates(problem: RoutingProblem, search: SearchOptions, *, lim
seen: set[tuple[tuple[str, PathSeed], ...]] = set() seen: set[tuple[tuple[str, PathSeed], ...]] = set()
def seed_pass(minimum: float) -> Iterator[dict[str, PathSeed]]: def seed_pass(minimum: float) -> Iterator[dict[str, PathSeed]]:
for radius, rows, moves in _column_jog_schedules(problem, layout, radii, minimum, profiles_for_slack): for radius, rows, moves in _column_jog_schedules(problem, layout, radii, minimum, profiles_for_slack, circular=circular):
seeds = _jog_seeds(layout.tracks, rows, moves, radius, minimum) seeds = _jog_seeds(layout.tracks, rows, moves, radius, minimum)
if seeds is None: if seeds is None:
continue continue

View file

@ -4,7 +4,8 @@ import pytest
from shapely.geometry import box from shapely.geometry import box
from inire import ( from inire import (
CongestionOptions, NetSpec, Port, RefinementOptions, RoutingOptions, RoutingProblem, SBendSeed, SearchOptions, StraightSeed, route, Bend90Seed, CongestionOptions, NetSpec, Port, RefinementOptions, RoutingOptions, RoutingProblem, SBendSeed, SearchOptions, StraightSeed,
route,
) )
from inire.geometry import sbend from inire.geometry import sbend
from inire.geometry.sbend import exact_sbend_spans from inire.geometry.sbend import exact_sbend_spans
@ -326,6 +327,44 @@ def test_column_jog_seeds_can_use_straights_longer_than_the_lattice_scan() -> No
assert any(isinstance(move, StraightSeed) and move.length > 40 for move in result.as_seed().segments) assert any(isinstance(move, StraightSeed) and move.length > 40 for move in result.as_seed().segments)
def test_column_jogs_skip_radii_too_small_for_a_shifting_track() -> None:
wide = NetSpec("wide", Port(5, 60, 0), Port(405, 160, 0), width=30)
narrow = tuple(NetSpec(str(y), Port(5, y, 0), Port(405, y + 100, 0)) for y in (200, 340))
problem = RoutingProblem((0, 0, 420, 470), (wide, *narrow), (box(170, 0, 190, 20),), clearance=0)
options = RoutingOptions(
search=SearchOptions(node_limit=1, bend_radii=(8, 9, 10, 11, 12, 13, 14, 20), sbend_radii=()),
congestion=CongestionOptions(max_iterations=1, warm_start_enabled=False),
refinement=RefinementOptions(enabled=False),
)
run = route(problem, options=options)
assert run.automatic.selected_planner == "column-jogs"
assert all(result.is_valid for result in run.results_by_net.values())
segments = run.results_by_net[wide.net_id].as_seed().segments
assert {move.radius for move in segments if isinstance(move, Bend90Seed)} == {20}
def test_column_jogs_allow_wide_straight_tracks_alongside_smaller_bends() -> None:
wide = NetSpec("wide", Port(5, 30, 0), Port(405, 30, 0), width=30)
narrow = tuple(NetSpec(str(y), Port(5, y, 0), Port(405, y + 50, 0)) for y in (90, 170))
problem = RoutingProblem((0, 0, 420, 240), (wide, *narrow), (box(170, 0, 190, 10),), clearance=0)
options = RoutingOptions(
search=SearchOptions(node_limit=1, bend_radii=(10,), sbend_radii=()),
congestion=CongestionOptions(max_iterations=1, warm_start_enabled=False),
refinement=RefinementOptions(enabled=False),
)
run = route(problem, options=options)
assert run.automatic.selected_planner == "column-jogs"
assert all(result.is_valid for result in run.results_by_net.values())
assert all(isinstance(move, StraightSeed) for move in run.results_by_net[wide.net_id].as_seed().segments)
for net in narrow:
segments = run.results_by_net[net.net_id].as_seed().segments
assert {move.radius for move in segments if isinstance(move, Bend90Seed)} == {10}
@pytest.mark.parametrize(("shift", "needs_short_straights"), [(23, True), (27, False)]) @pytest.mark.parametrize(("shift", "needs_short_straights"), [(23, True), (27, False)])
def test_column_jogs_prefer_the_lattice_minimum_but_can_relax_it(shift, needs_short_straights) -> None: def test_column_jogs_prefer_the_lattice_minimum_but_can_relax_it(shift, needs_short_straights) -> None:
nets = tuple(NetSpec(str(y), Port(5, y, 0), Port(1000, y + shift, 0)) for y in (30, 85, 140)) nets = tuple(NetSpec(str(y), Port(5, y, 0), Port(1000, y + shift, 0)) for y in (30, 85, 140))