From b6480ded62c1f26a2556081df231eff6525437d4 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 30 Nov 2026 13:07:21 -0800 Subject: [PATCH] Keep tracks straight when a column jog radius cannot fit them --- inire/router/_columns.py | 24 ++++++++++++++++++---- inire/tests/test_columns.py | 41 ++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/inire/router/_columns.py b/inire/router/_columns.py index e29ac2e..6cfecbc 100644 --- a/inire/router/_columns.py +++ b/inire/router/_columns.py @@ -12,7 +12,7 @@ from typing import TYPE_CHECKING 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.sbend import ExactSBendScanLimitError, exact_sbend_spans from inire.model import resolve_bend_geometry @@ -689,12 +689,27 @@ def _column_jog_schedules( radii: list[int], minimum: float, profiles_for_slack: Callable[[int], list[list[Profile]]], + *, + circular: bool, ) -> 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)) for slack in (1, 0): profiles = profiles_for_slack(slack) - for radius in radii: - schedules = _jog_schedules(profiles, windows, layout.widths, problem.clearance, radius, minimum) + for radius, straight_rows in radius_choices: + 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: yield radius, rows, moves @@ -710,6 +725,7 @@ def column_jog_candidates(problem: RoutingProblem, search: SearchOptions, *, lim layout = _column_layout(problem) if layout is None: return + circular = bend90_uses_circular_geometry(*resolve_bend_geometry(search)) @cache def profiles_for_slack(slack: int) -> list[list[Profile]]: widths = layout.widths @@ -723,7 +739,7 @@ def column_jog_candidates(problem: RoutingProblem, search: SearchOptions, *, lim seen: set[tuple[tuple[str, PathSeed], ...]] = set() 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) if seeds is None: continue diff --git a/inire/tests/test_columns.py b/inire/tests/test_columns.py index 519b9f8..1b5454b 100644 --- a/inire/tests/test_columns.py +++ b/inire/tests/test_columns.py @@ -4,7 +4,8 @@ import pytest from shapely.geometry import box 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.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) +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)]) 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))