Retry column jogs with relaxed straight spacing

This commit is contained in:
Jan Petykiewicz 2026-11-30 11:41:46 -08:00
commit d94f121ed2
3 changed files with 51 additions and 21 deletions

View file

@ -477,7 +477,7 @@ class _AutomaticRun:
if target != len(problem.nets) or problem.initial_paths: if target != len(problem.nets) or problem.initial_paths:
return False return False
with self._time("plan", planner="column-jogs"): with self._time("plan", planner="column-jogs"):
for seeds in islice(column_jog_candidates(problem, options.search), 8): for seeds in column_jog_candidates(problem, options.search, limit_per_pass=8):
trial = self._verify(replace(problem, initial_paths=seeds), "column-jogs") trial = self._verify(replace(problem, initial_paths=seeds), "column-jogs")
if len(trial.valid_costs) == target: if len(trial.valid_costs) == target:
trials.append(trial) trials.append(trial)

View file

@ -664,7 +664,7 @@ def _jog_schedules(
def _jog_seeds( def _jog_seeds(
tracks: tuple[_Track, ...], rows: tuple[Profile, ...], moves: tuple[JogPivots, ...], radius: int, search: SearchOptions tracks: tuple[_Track, ...], rows: tuple[Profile, ...], moves: tuple[JogPivots, ...], radius: int, minimum: float,
) -> dict[str, PathSeed] | None: ) -> dict[str, PathSeed] | None:
seeds = {} seeds = {}
for i, track in enumerate(tracks): for i, track in enumerate(tracks):
@ -677,10 +677,7 @@ def _jog_seeds(
if track.westbound: if track.westbound:
points.reverse() points.reverse()
seed, end = compile_waypoints(tuple(points), track.net.start, radius) seed, end = compile_waypoints(tuple(points), track.net.start, radius)
if end != track.net.target or any( if end != track.net.target or any(isinstance(move, StraightSeed) and move.length < minimum for move in seed.segments):
isinstance(move, StraightSeed) and move.length < search.min_straight_length
for move in seed.segments
):
return None return None
seeds[track.net.net_id] = seed seeds[track.net.net_id] = seed
return seeds return seeds
@ -691,27 +688,19 @@ def _column_jog_schedules(
layout: _ColumnLayout, layout: _ColumnLayout,
radii: list[int], radii: list[int],
minimum: float, minimum: float,
profiles_for_slack: Callable[[int], list[list[Profile]]],
) -> Iterator[tuple[int, tuple[Profile, ...], tuple[JogPivots, ...]]]: ) -> Iterator[tuple[int, tuple[Profile, ...], tuple[JogPivots, ...]]]:
columns, widths, preferences = layout.columns, layout.widths, layout.preferences
launch, arrival = layout.launch, layout.arrival
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):
# Modulus one allows any integer track level, independent of the profiles = profiles_for_slack(slack)
# set of exact S-bend spans.
interior = [
_column_profiles(problem, column, widths, (0,) * len(widths), desired, slack, slack, 1, combinations_limit=8192)
for column, desired in zip(columns, preferences, strict=True)
]
for radius in radii: for radius in radii:
schedules = _jog_schedules( schedules = _jog_schedules(profiles, windows, layout.widths, problem.clearance, radius, minimum)
[[launch], *interior, [arrival]], windows, widths, problem.clearance, radius, minimum
)
for _, rows, moves in schedules: for _, rows, moves in schedules:
yield radius, rows, moves yield radius, rows, moves
def column_jog_candidates(problem: RoutingProblem, search: SearchOptions) -> Iterator[dict[str, PathSeed]]: def column_jog_candidates(problem: RoutingProblem, search: SearchOptions, *, limit_per_pass: int | None = None) -> Iterator[dict[str, PathSeed]]:
"""Allocate tracks through ordered apertures using staggered 90-degree jogs.""" """Allocate tracks through ordered apertures using staggered 90-degree jogs."""
if problem.initial_paths: if problem.initial_paths:
return return
@ -721,7 +710,28 @@ def column_jog_candidates(problem: RoutingProblem, search: SearchOptions) -> Ite
layout = _column_layout(problem) layout = _column_layout(problem)
if layout is None: if layout is None:
return return
for radius, rows, moves in _column_jog_schedules(problem, layout, radii, search.min_straight_length): @cache
seeds = _jog_seeds(layout.tracks, rows, moves, radius, search) def profiles_for_slack(slack: int) -> list[list[Profile]]:
if seeds is not None: widths = layout.widths
# Modulus one allows any integer track level.
interior = [
_column_profiles(problem, column, widths, (0,) * len(widths), desired, slack, slack, 1, combinations_limit=8192)
for column, desired in zip(layout.columns, layout.preferences, strict=True)
]
return [[layout.launch], *interior, [layout.arrival]]
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):
seeds = _jog_seeds(layout.tracks, rows, moves, radius, minimum)
if seeds is None:
continue
signature = tuple(seeds.items())
if signature in seen:
continue
seen.add(signature)
yield seeds yield seeds
for minimum in dict.fromkeys((search.min_straight_length, 0.0)):
yield from islice(seed_pass(minimum), limit_per_pass)

View file

@ -324,3 +324,23 @@ def test_column_jog_seeds_can_use_straights_longer_than_the_lattice_scan() -> No
for result in run.results_by_net.values(): for result in run.results_by_net.values():
assert result.is_valid assert result.is_valid
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)
@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))
problem = RoutingProblem((0, 0, 1010, 180), nets, (box(980, 0, 990, 10),), clearance=0)
options = RoutingOptions(
search=SearchOptions(node_limit=1, bend_radii=(10,), sbend_radii=(), min_straight_length=5),
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 run.metrics.nodes_expanded == 0
for result in run.results_by_net.values():
assert result.is_valid
lengths = [move.length for move in result.as_seed().segments if isinstance(move, StraightSeed)]
assert any(length < options.search.min_straight_length for length in lengths) is needs_short_straights